Hive Coin Handler¶
Module contents¶
Hive Coin Handler
This python module is a Coin Handler for Privex’s CryptoToken Converter, designed to handle all required functionality for both receiving and sending tokens on the Hive network.
It will automatically handle any payments.models.Coin
which has it’s type set to hivebase
Coin object settings:
For each
payments.models.Coin
you intend to use with this handler, you should configure it as such:
Coin Key Description coin_type This should be set to Hive Network (or compatible fork)
(db value: hivebase)our_account This should be set to the username of the account you want to use for receiving/sending setting_json A JSON string for optional extra config (see below) Extra JSON (Handler Custom) config options:
rpcs
- A JSON list<str> of RPC nodes to use, with a full HTTP/HTTPS URL. If this is not specified, Beem will automatically try to use the best available RPC node for the Hive network.pass_store
- Generally you do not need to touch this. It controls where Beem will look for the wallet password. It defaults toenvironment
Example JSON custom config:
{ "rpcs": [ "https://steemd.privex.io", "https://api.steemit.com", "https://api.steem.house" ], "pass_store": "environment" }
Copyright:
+===================================================+
| © 2019 Privex Inc. |
| https://www.privex.io |
+===================================================+
| |
| CryptoToken Converter |
| |
| Core Developer(s): |
| |
| (+) Chris (@someguy123) [Privex] |
| |
+===================================================+
-
payments.coin_handlers.Hive.
reload
()[source]¶ Reload’s the
provides
property for the loader and manager from the DB.By default, since new Hive forks are constantly being created, our classes can provide for any
models.Coin
by scanning for coins with the typehivebase
. This saves us from hard coding specific coin symbols.
Submodules¶
HiveLoader module¶
-
class
payments.coin_handlers.Hive.HiveLoader.
HiveLoader
(symbols)[source]¶ Bases:
payments.coin_handlers.base.BaseLoader.BaseLoader
,payments.coin_handlers.Hive.HiveMixin.HiveMixin
-
clean_tx
(tx: dict, symbol: str, account: str, memo: str = None, memo_case: bool = False) → Optional[dict][source]¶ Filters an individual transaction. See
clean_txs()
for info
-
clean_txs
(symbol: str, transactions: Iterable[dict], account: str = None) → Generator[dict, None, None][source]¶ Filters a list of transactions transactions as required, yields dict’s conforming with
models.Deposit
- Filters out transactions that are not marked as ‘receive’
- Filters out mining transactions
- Filters by address if account is specified
- Filters out transactions that don’t have enough confirms, and are not reported as ‘trusted’
Parameters: - symbol – Symbol of coin being cleaned
- transactions – A
list<dict>
or generator producing dict’s - account – If not None, only return TXs sent to this address.
Return Generator<dict>: A generator outputting dictionaries formatted as below
Output Format:
{ txid:str, coin:str (symbol), vout:int, tx_timestamp:datetime, address:str, amount:Decimal }
-
list_txs
(batch=0) → Generator[dict, None, None][source]¶ The list_txs function processes the transaction data from
load()
, as well as handling any pagination, if it’s required (e.g. only retrieve batch transactions at a time from the data source)It should first check that
load()
has been ran if it’s required, if the data required has not been loaded, it should call self.load()To prevent memory leaks, this must be a generator function.
Below is an example of a generator function body, it loads batch transactions from the full transaction list, pretends to processes them into txs, yields them, then loads another batch after the calling function has iterated over the current txs
>>> t = self.transactions # All transactions >>> b = batch >>> finished = False >>> offset = 0 >>> # To save memory, process 100 transactions per iteration, and yield them (generator) >>> while not finished: >>> txs = [] # Processed transactions >>> # If there are less remaining TXs than batch size, get remaining txs and finish. >>> if (len(t) - offset) < batch: >>> finished = True >>> # Do some sort-of processing on the tx to make it conform to `Deposit`, then append to txs >>> for tx in t[offset:offset + batch]: >>> txs.append(tx) >>> offset += b >>> for tx in txs: >>> yield tx >>> # At this point, the current batch is exhausted. Destroy the tx array to save memory. >>> del txs
Parameters: batch (int) – Amount of transactions to process/load per each batch Returns Generator: A generator returning dictionaries that can be imported into models.Deposit
Dict format:
{txid:str, coin:str (symbol), vout:int, tx_timestamp:datetime, address:str, from_account:str, to_account:str, memo:str, amount:Decimal}
vout
is optional. One of either {from_account, to_account, memo} OR {address} must be included.
-
load
(tx_count=10000)[source]¶ The load function should prepare your loader, by either importing all of the data required for filtering, or setting up a generator for the
list_txs()
method to load them paginated.It does NOT return anything, it simply creates any connections required, sets up generator functions if required for paginating the data, and/or pre-loads the first batch of transaction data.
Parameters: tx_count – The total amount of transactions that should be loaded PER SYMBOL, most recent first. Returns: None
-
provides
¶ This attribute is automatically generated by scanning for
models.Coin
s with the typesteembase
. This saves us from hard coding specific coin symbols. See __init__.py for populating code.
-
settings
¶ To ensure we always get fresh settings from the DB after a reload
-
HiveManager module¶
-
class
payments.coin_handlers.Hive.HiveManager.
HiveManager
(symbol: str)[source]¶ Bases:
payments.coin_handlers.base.BaseManager.BaseManager
,payments.coin_handlers.Hive.HiveMixin.HiveMixin
-
address_valid
(address) → bool[source]¶ If an account exists on Steem, will return True. Otherwise False.
Parameters: address – Steem account to check existence of Return bool: True if account exists, False if it doesn’t
-
balance
(address: str = None, memo: str = None, memo_case: bool = False) → decimal.Decimal[source]¶ Get token balance for a given Steem account, if memo is given - get total symbol amt received with this memo.
Parameters: - address – Steem account to get balance for, if not set, uses self.coin.our_account
- memo – If not None, get total self.symbol received with this memo.
- memo_case – Case sensitive memo search
Returns: Decimal(balance)
-
get_deposit
() → tuple[source]¶ Returns the deposit account for this symbol
Return tuple: A tuple containing (‘account’, receiving_account). The memo must be generated by the calling function.
-
health
() → Tuple[str, tuple, tuple][source]¶ Return health data for the passed symbol.
Health data will include: ‘Symbol’, ‘Status’, ‘Coin Name’, ‘API Node’, ‘Head Block’, ‘Block Time’, ‘RPC Version’, ‘Our Account’, ‘Our Balance’ (all strings)
Return tuple health_data: (manager_name:str, headings:list/tuple, health_data:list/tuple,)
-
health_test
() → bool[source]¶ Check if our Steem node works or not, by requesting basic information such as the current block + time, and checking if our sending/receiving account exists on Steem.
Return bool: True if Steem appears to be working, False if it seems to be broken.
-
provides
¶ This attribute is automatically generated by scanning for
models.Coin
s with the typesteembase
. This saves us from hard coding specific coin symbols. See __init__.py for populating code.
-
send
(amount: decimal.Decimal, address: str, from_address: str = None, memo=None, trigger_data=None) → dict[source]¶ Send a supported currency to a given address/account, optionally specifying a memo if supported
Example - send 1.23 STEEM from @someguy123 to @privex with memo ‘hello’
>>> s = SteemManager('STEEM') >>> s.send(from_address='someguy123', address='privex', amount=Decimal('1.23'), memo='hello')
Parameters: - amount (Decimal) – Amount of currency to send, as a Decimal()
- address – Account to send the currency to
- from_address – Account to send the currency from
- memo – Memo to send currency with
Raises: - AttributeError – When both from_address and self.coin.our_account are blank.
- ArithmeticError – When the amount is lower than the lowest amount allowed by the asset’s precision
- AuthorityMissing – Cannot send because we don’t have authority to (missing key etc.)
- AccountNotFound – The requested account doesn’t exist
- NotEnoughBalance – The account from_address does not have enough balance to send this amount.
Return dict: Result Information
Format:
{ txid:str - Transaction ID - None if not known, coin:str - Symbol that was sent, amount:Decimal - The amount that was sent (after fees), fee:Decimal - TX Fee that was taken from the amount, from:str - The account/address the coins were sent from, send_type:str - Should be statically set to "send" }
-
HiveMixin module¶
-
class
payments.coin_handlers.Hive.HiveMixin.
HiveMixin
(*args, **kwargs)[source]¶ Bases:
payments.coin_handlers.base.SettingsMixin.SettingsMixin
HiveMixin - Shared code between SteemManager and SteemLoader
Designed for the Steem Network with SBD and STEEM support. May or may not work with other Graphene coins.
Copyright:
+===================================================+ | © 2019 Privex Inc. | | https://www.privex.io | +===================================================+ | | | CryptoToken Converter | | | | Core Developer(s): | | | | (+) Chris (@someguy123) [Privex] | | | +===================================================+
For additional settings, please see the module docstring in
coin_handlers.Steem
-
asset
¶ Easy reference to the BSteem Asset object for our current symbol
-
find_steem_tx
(tx_data, last_blocks=15) → Optional[dict][source]¶ Used internally to get the transaction ID after a transaction has been broadcasted
Parameters: Return dict: Transaction data from the blockchain {transaction_id, ref_block_num, ref_block_prefix, expiration, operations, extensions, signatures, block_num, transaction_num}
Return None: If the transaction wasn’t found, None will be returned.
-
get_rpc
(symbol: str) → beem.steem.Steem[source]¶ Returns a Steem instance for querying data and sending TXs. By default, uses the BSteem shared_steem_instance.
If a custom RPC list is specified in the Coin “custom json” settings, a new instance will be returned with the RPCs specified in the json.
Parameters: symbol – Coin symbol to get BSteem RPC instance for Return beem.steem.Steem: An instance of beem.steem.Steem
for querying
-
precision
¶
-
rpc
¶
-