SteemEngine Coin Handler¶
Module contents¶
SteemEngine 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 SteemEngine network.
It will automatically handle any payments.models.Coin
which has it’s type set to steemengine
Global Settings
The following global settings are used by this handler (set within steemengine.settings.custom
). All of the below settings
can be specified with the same key inside of your .env
file to override the defaults.
Setting Description SENG_RPC_NODE
The hostname for the contract API server, e.g. api.steem-engine.com
SENG_RPC_URL
The URL for the contract API e.g. /rpc/contracts
SENG_HISTORY_NODE
The hostname for the history API server, e.g. api.steem-engine.com
SENG_HISTORY_URL
The URL for the history API e.g. accounts/history
SENG_NETWORK_ACCOUNT
The “network account” for SteemEngine, e.g. ssc-mainnet1
Coin object settings:
You can set the following JSON keys inside of a
Coin
’s “settings_json” field if you want to use an alternative SteemEngine RPC node, or history node just for that coin.
Coin Key Description rpc_node The hostname for the contract API server, e.g. api.steem-engine.com
rpc_url The URL for the contract API e.g. /rpc/contracts
history_node The hostname for the history API server, e.g. api.steem-engine.com
history_url The URL for the history API e.g. accounts/history
network_account The “network account” for SteemEngine, e.g. ssc-mainnet1
For example, placing the following JSON inside of
settings_json
for a certain coin, would result in the contract APIhttps://api.hive-engine.com/contracts
and history APIhttps://accounts.hive-engine.com/accountHistory
being used only for this particular coin, while coins without anysettings_json
overrides would continue using the globalSENG_RPC_NODE
etc.{ "rpc_node": "api.hive-engine.com", "rpc_url": "/contracts", "history_node": "accounts.hive-engine.com", "history_url": "accountHistory" }
Copyright:
+===================================================+
| © 2019 Privex Inc. |
| https://www.privex.io |
+===================================================+
| |
| CryptoToken Converter |
| |
| Core Developer(s): |
| |
| (+) Chris (@someguy123) [Privex] |
| |
+===================================================+
-
payments.coin_handlers.SteemEngine.
reload
()[source]¶ Reload’s the
provides
property for the loader and manager from the DB.By default, since new tokens are constantly being created for SteemEngine, our classes can provide for any
models.Coin
by scanning for coins with the typesteemengine
. This saves us from hard coding specific coin symbols.
Submodules¶
SteemEngineLoader module¶
Copyright:
+===================================================+
| © 2019 Privex Inc. |
| https://www.privex.io |
+===================================================+
| |
| CryptoToken Converter |
| |
| Core Developer(s): |
| |
| (+) Chris (@someguy123) [Privex] |
| |
+===================================================+
-
class
payments.coin_handlers.SteemEngine.SteemEngineLoader.
SteemEngineLoader
(symbols)[source]¶ Bases:
payments.coin_handlers.base.BaseLoader.BaseLoader
,payments.coin_handlers.SteemEngine.SteemEngineMixin.SteemEngineMixin
This class handles loading transactions for the SteemEngine network, and can support almost any token on SteemEngine.
Copyright:
+===================================================+ | © 2019 Privex Inc. | | https://www.privex.io | +===================================================+ | | | CryptoToken Converter | | | | Core Developer(s): | | | | (+) Chris (@someguy123) [Privex] | | | +===================================================+
-
clean_txs
(account: str, symbol: str, transactions: Iterable[privex.steemengine.objects.SETransaction]) → Generator[dict, None, None][source]¶ Filters a list of transactions by the receiving account, yields dict’s conforming with
payments.models.Deposit
Parameters: Returns: A generator yielding
dict
s conforming topayments.models.Deposit
-
list_txs
(batch=100) → Generator[dict, None, None][source]¶ Get transactions for all coins in self.coins where the ‘to’ field matches coin.our_account If
load()
hasn’t been ran already, it will automatically call self.load() :param batch: Amount of transactions to load per batch :return: Generator yielding dict’s that conform tomodels.Deposit
-
load
(tx_count=1000)[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
-
load_batch
(account, symbol, limit=100, offset=0, retry=0)[source]¶ Load SteemEngine transactions for account/symbol into self.transactions with automatic retry on error
-
provides
¶ This attribute is automatically generated by scanning for
models.Coin
s with the typesteemengine
. This saves us from hard coding specific coin symbols. See __init__.py for populating code.
-
SteemEngineManager module¶
Copyright:
+===================================================+
| © 2019 Privex Inc. |
| https://www.privex.io |
+===================================================+
| |
| CryptoToken Converter |
| |
| Core Developer(s): |
| |
| (+) Chris (@someguy123) [Privex] |
| |
+===================================================+
-
class
payments.coin_handlers.SteemEngine.SteemEngineManager.
SteemEngineManager
(symbol: str)[source]¶ Bases:
payments.coin_handlers.base.BaseManager.BaseManager
,payments.coin_handlers.SteemEngine.SteemEngineMixin.SteemEngineMixin
This class handles various operations for the SteemEngine network, and supports almost any token on SteemEngine.
It handles:
- Validating source/destination accounts
- Checking the balance for a given account, as well as the total amount received with a certain
memo
- Issuing tokens to users
- Sending tokens to users
Copyright:
+===================================================+ | © 2019 Privex Inc. | | https://www.privex.io | +===================================================+ | | | CryptoToken Converter | | | | Core Developer(s): | | | | (+) Chris (@someguy123) [Privex] | | | +===================================================+
-
address_valid
(address) → bool[source]¶ If an account (
address
param) exists on Steem, will return True. Otherwise False.
-
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, Current Block, Node Version, Wallet Balance, and number of p2p connections (all as strings)
Return tuple health_data: (manager_name:str, headings:list/tuple, health_data:list/tuple,)
-
health_test
() → bool[source]¶ Check if the SteemEngine API and Steem node works or not, by requesting basic information such as the token metadata, and checking if our sending/receiving account exists on Steem.
Return bool: True if SteemEngine and Steem appear to be working, False if either is broken.
-
issue
(amount: decimal.Decimal, address: str, memo: str = None, trigger_data=None) → dict[source]¶ Issue (create/print) tokens to a given address/account, optionally specifying a memo if supported
Example - Issue 5.10 SGTK to @privex
>>> s = SteemEngineManager('SGTK') >>> s.issue(address='privex', amount=Decimal('5.10'))
Parameters: - amount (Decimal) – Amount of tokens to issue, as a Decimal()
- address – Address or account to issue the tokens to
- memo – (ignored) Cannot issue tokens with a memo on SteemEngine
Raises: - IssuerKeyError – Cannot issue because we don’t have authority to (missing key etc.)
- IssueNotSupported – Class does not support issuing, or requested symbol cannot be issued.
- AccountNotFound – The requested account/address doesn’t exist
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 issued from, send_type:str - Should be statically set to "issue" }
-
provides
¶ This attribute is automatically generated by scanning for
models.Coin
s with the typesteemengine
. This saves us from hard coding specific coin symbols. See __init__.py for populating code.
-
send
(amount, address, memo=None, from_address=None, trigger_data=None) → dict[source]¶ Send tokens to a given address/account, optionally specifying a memo if supported
Example - send 1.23 SGTK from @someguy123 to @privex with memo ‘hello’
>>> s = SteemEngineManager('SGTK') >>> s.send(from_address='someguy123', address='privex', amount=Decimal('1.23'), memo='hello')
Parameters: - amount (Decimal) – Amount of tokens to send, as a Decimal()
- address – Account to send the tokens to
- from_address – Account to send the tokens from
- memo – Memo to send tokens with (if supported)
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 token’s precision
- AuthorityMissing – Cannot send because we don’t have authority to (missing key etc.)
- AccountNotFound – The requested account/address doesn’t exist
- TokenNotFound – When the requested token symbol does not 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" }
-
send_or_issue
(amount, address, memo=None, trigger_data=None) → dict[source]¶ Attempt to send an amount to an address/account, if not enough balance, attempt to issue it instead. You may override this method if needed.
Parameters: - amount (Decimal) – Amount of coins/tokens to send/issue, as a Decimal()
- address – Address or account to send/issue the coins/tokens to
- memo – Memo to send/issue coins/tokens with (if supported)
- trigger_data (dict) – Metadata related to this issue transaction (e.g. the deposit that triggered this)
Raises: - IssuerKeyError – Cannot issue because we don’t have authority to (missing key etc.)
- IssueNotSupported – Class does not support issuing, or requested symbol cannot be issued.
- AccountNotFound – The requested account/address doesn’t exist
Return dict: Result Information
Format:
dict { 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(s)/address(es) the coins were sent from. if more than one, comma separated. If it's not possible to determine easily, set this to None. send_type:str - Should be set to "send" if the coins were sent, or "issue" if the coins were issued. }
SteemEngineMixin module¶
Copyright:
+===================================================+
| © 2019 Privex Inc. |
| https://www.privex.io |
+===================================================+
| |
| CryptoToken Converter |
| |
| Core Developer(s): |
| |
| (+) Chris (@someguy123) [Privex] |
| |
+===================================================+
-
class
payments.coin_handlers.SteemEngine.SteemEngineMixin.
SteemEngineMixin
(*args, **kwargs)[source]¶ Bases:
payments.coin_handlers.base.SettingsMixin.SettingsMixin
-
eng_rpc
¶
-
get_rpc
(symbol: str) → privex.steemengine.SteemEngineToken.SteemEngineToken[source]¶ Returns a SteemEngineToken instance for querying data and sending TXs.
If a custom RPC config is specified in the Coin “custom json” settings, a new instance will be returned with the RPC config specified in the json.
Parameters: symbol – Coin symbol to get Beem RPC instance for Return beem.steem.Steem: An instance of beem.steem.Steem
for querying
-
-
payments.coin_handlers.SteemEngine.SteemEngineMixin.
mk_seng_rpc
(rpc_settings: dict = None, **kwargs) → privex.steemengine.SteemEngineToken.SteemEngineToken[source]¶ Get a
SteemEngineToken
instance using the default settings:>>> rpc = mk_seng_rpc()
Get a
SteemEngineToken
instance using dictionary settings (rpc_settings):>>> rpc2 = mk_seng_rpc({'rpc_node' : 'api.hive-engine.com','network_account' : 'ssc-testnet'})
Get a
SteemEngineToken
instance using individual kwarg settings:>>> rpc3 = mk_seng_rpc(rpc_node='api.hive-engine.com', network_account='ssc-testnet')
Parameters: - rpc_settings (dict) – Specify the settings as a dictionary (same keys as kwargs below)
- kwargs – Alternatively, specify the settings as keyword args
- rpc_node (str) – The hostname for the contract API server, e.g.
api.steem-engine.com
- rpc_url (str) – The URL for the contract API e.g.
/rpc/contracts
- history_node (str) – The hostname for the history API server, e.g.
api.steem-engine.com
- history_url (str) – The URL for the history API e.g.
accounts/history
- network_account (str) – The “network account” for SteemEngine, e.g.
ssc-mainnet1
- network (str) – Chain to run on (
steem
orhive
)
Return SteemEngineToken rpc: An instance of
SteemEngineToken