Skip to content

Commit

Permalink
Remove unnecessary abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNaif2018 committed Oct 12, 2021
1 parent 973c306 commit bc71375
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 89 deletions.
83 changes: 2 additions & 81 deletions bitcart/coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,12 @@


class Coin:
"""Coins should reimplement some methods,
and initialize coin-specific info.
Required information is:
coin_name str
friendly_name str
For more info see the docs.
"""

coin_name = "Base"
friendly_name = "Base"
coin_name: str
friendly_name: str
event_handlers: Dict[str, Callable]
xpub: Optional[str]

def __eq__(self, other: object) -> bool:
if not isinstance(other, Coin):
return NotImplemented
return (self.coin_name, self.xpub) == (other.coin_name, other.xpub)

async def help(self) -> list:
"""Get help
Returns a list of all available RPC methods
Raises:
NotImplementedError: Implement in your subclass
Returns:
list: RPC methods list
"""
raise NotImplementedError()

async def get_tx(self, tx: str) -> dict:
"""Get transaction information
Given tx hash of transaction, return full information as dictionary
Example:
>>> c.get_tx("54604b116b28124e31d2d20bbd4561e6f8398dca4b892080bffc8c87c27762ba")
{'partial': False, 'version': 2, 'segwit_ser': True, 'inputs': [{'prevout_hash': 'xxxx',...
Args:
tx (str): tx_hash
Raises:
NotImplementedError: Implement in your subclass
Returns:
dict: transaction info
"""
raise NotImplementedError()

async def get_address(self, address: str) -> list:
"""Get address history
This method should return list of transaction informations for specified address
Example:
>>> c.get_address("31smpLFzLnza6k8tJbVpxXiatGjiEQDmzc")
[{'tx_hash': '7854bdf4c4e27276ecc1fb8d666d6799a248f5e81bdd58b16432d1ddd1d4c332', 'height': 581878, 'tx': ...
Args:
address (str): address to get transactions for
Raises:
NotImplementedError: Override this method in subclass
Returns:
list: List of transactions
"""
raise NotImplementedError()

async def balance(self) -> dict:
"""Get balance of wallet
Example:
>>> self.balance()
{"confirmed": 0.00005, "unconfirmed": 0, "unmatured": 0}
Raises:
NotImplementedError: Implement in your subclass
Returns:
dict: It should return dict of balance statuses
"""
raise NotImplementedError()
47 changes: 47 additions & 0 deletions bitcart/coins/btc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,65 @@ async def spec(self) -> dict:
### High level interface ###

async def help(self) -> list:
"""Get help
Returns a list of all available RPC methods
Returns:
list: RPC methods list
"""
return await self.server.help() # type: ignore

async def get_tx(self, tx: str) -> dict: # pragma: no cover: see tests for explanation
"""Get transaction information
Given tx hash of transaction, return full information as dictionary
Example:
>>> c.get_tx("54604b116b28124e31d2d20bbd4561e6f8398dca4b892080bffc8c87c27762ba")
{'partial': False, 'version': 2, 'segwit_ser': True, 'inputs': [{'prevout_hash': 'xxxx',...
Args:
tx (str): tx_hash
Returns:
dict: transaction info
"""
return await self.server.get_transaction(tx) # type: ignore

async def get_address(self, address: str) -> list: # pragma: no cover
"""Get address history
This method should return list of transaction informations for specified address
Example:
>>> c.get_address("31smpLFzLnza6k8tJbVpxXiatGjiEQDmzc")
[{'tx_hash': '7854bdf4c4e27276ecc1fb8d666d6799a248f5e81bdd58b16432d1ddd1d4c332', 'height': 581878, 'tx': ...
Args:
address (str): address to get transactions for
Returns:
list: List of transactions
"""
out: list = await self.server.getaddresshistory(address)
for i in out:
i["tx"] = await self.get_tx(i["tx_hash"])
return out

async def balance(self) -> dict:
"""Get balance of wallet
Example:
>>> c.balance()
{"confirmed": 0.00005, "unconfirmed": 0, "unmatured": 0}
Returns:
dict: It should return dict of balance statuses
"""
data = await self.server.getbalance()
return {attr: convert_amount_type(data.get(attr, 0)) for attr in self.BALANCE_ATTRS}

Expand Down
8 changes: 0 additions & 8 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
API Reference
=============

Coin class
**********

.. autoclass:: bitcart.coin.Coin
:members:
:show-inheritance:
:undoc-members:

Implemented coins
*****************

Expand Down

0 comments on commit bc71375

Please sign in to comment.