def payout_dividends(config: BoardCommmadConfiguration, transfer_amount): from sto.ethereum.utils import (get_contract_deployed_tx, create_web3, get_abi, broadcast as _broadcast) from sto.ethereum.txservice import EthereumStoredTXService from sto.models.implementation import BroadcastAccount, PreparedTransaction tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract') if not tx: raise Exception( 'PayoutContract not found. Call payout-deploy to deploy PayoutContract' ) web3 = create_web3(config.ethereum_node_url) service = EthereumStoredTXService(config.network, config.dbsession, web3, config.ethereum_private_key, config.ethereum_gas_price, config.ethereum_gas_limit, BroadcastAccount, PreparedTransaction) abi = get_abi(config.ethereum_abi_file) service.interact_with_contract( contract_name='PayoutContract', abi=abi, address=tx.contract_address, note='transferring amount: {0}'.format(transfer_amount), func_name='act', args={'amount': transfer_amount}) _broadcast(config)
def payout_deposit(config: BoardCommmadConfiguration): """ the private key here needs to belong to the customer who wants to fetch tokens """ from sto.ethereum.utils import (get_contract_deployed_tx, create_web3, get_abi, broadcast as _broadcast) from sto.ethereum.txservice import EthereumStoredTXService from sto.models.implementation import BroadcastAccount, PreparedTransaction tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract') if not tx: raise Exception( 'PayoutContract not found. Call payout-deploy to deploy PayoutContract' ) web3 = create_web3(config.ethereum_node_url) service = EthereumStoredTXService(config.network, config.dbsession, web3, config.ethereum_private_key, config.ethereum_gas_price, config.ethereum_gas_limit, BroadcastAccount, PreparedTransaction) abi = get_abi(config.ethereum_abi_file) service.interact_with_contract(contract_name='PayoutContract', abi=abi, address=tx.contract_address, note='calling fetchTokens', func_name='fetchTokens', args={}) _broadcast(config)
def broadcast(config: BoardCommmadConfiguration): """Broadcast waiting transactions. Send all management account transactions to Ethereum network. After a while, transactions are picked up by miners and included in the blockchain. """ from sto.ethereum.utils import broadcast as _broadcast _broadcast(config)
def payout_approve( config: BoardCommmadConfiguration, payout_token_address: str, payout_token_name: str, ): """ approve tokens to the payout contract """ from sto.ethereum.utils import (get_contract_deployed_tx, create_web3, get_abi, broadcast as _broadcast, priv_key_to_address) from sto.ethereum.txservice import EthereumStoredTXService from sto.models.implementation import BroadcastAccount, PreparedTransaction tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract') if not tx: raise Exception( 'PayoutContract not found. Call payout-deploy to deploy PayoutContract' ) if payout_token_name: tx = get_contract_deployed_tx(config.dbsession, payout_token_name) payout_token_address = tx.contract_address if payout_token_address is None: raise Exception(''' Either payout token is not deployed or --payout-token-address not provided ''') tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract') if not tx: raise Exception( 'PayoutContract not found. Call payout-deploy to deploy PayoutContract' ) payout_contract_address = tx.contract_address web3 = create_web3(config.ethereum_node_url) service = EthereumStoredTXService(config.network, config.dbsession, web3, config.ethereum_private_key, config.ethereum_gas_price, config.ethereum_gas_limit, BroadcastAccount, PreparedTransaction) abi = get_abi(config.ethereum_abi_file) payout_token_contract = web3.eth.contract( address=payout_token_address, abi=abi[payout_token_name]['abi']) service.interact_with_contract( payout_token_name, abi, payout_token_address, 'approving tokens', 'approve', args={ '_spender': payout_contract_address, '_value': payout_token_contract.functions.balanceOf( priv_key_to_address(config.ethereum_private_key)).call() }, use_bytecode=False) _broadcast(config)