def find_eth_balance(view, column, address: CryptoAddress): """Get link to a user admin show view from the user owned account.""" request = view.request # TODO: Expensive. Should do in get_query() dbsession = request.dbsession eth = get_ether_asset(dbsession) account = address.get_account(eth) if account: return format_asset_amount(account.account.get_balance(), account.account.asset.asset_class) else: return "-"
def find_eth_balance(view, column, address: CryptoAddress): """Get link to a user admin show view from the user owned account.""" request = view.request # TODO: Expensive. Should do in get_query() dbsession = request.dbsession eth = get_ether_asset(dbsession) account = address.get_account(eth) if account: return format_asset_amount(account.account.get_balance(), account.account.asset.asset_class) else: return "-"
def test_deposit_eth_account(dbsession, eth_network_id, eth_service, eth_asset_id): """Deposit Ethereums to an account.""" # Create ETH holding account under an address with transaction.manager: # First create the address which holds our account network = dbsession.query(AssetNetwork).get(eth_network_id) address = CryptoAddress(network=network, address=eth_address_to_bin(TEST_ADDRESS)) dbsession.add(address) dbsession.flush() # Create deposit op with transaction.manager: address = dbsession.query(CryptoAddress).one_or_none() asset = dbsession.query(Asset).get(eth_asset_id) txid = txid_to_bin(TEST_TXID) op = address.deposit(Decimal(10), asset, txid, bin_to_txid(txid)) dbsession.add(op) opid = op.id # Resolve deposit op success_op_count, failed_op_count = eth_service.run_waiting_operations() assert success_op_count == 1 assert failed_op_count == 0 with transaction.manager: op = dbsession.query(CryptoOperation).get(opid) op.resolve() # Force resolution regardless on confirmation count # Check balances are settled with transaction.manager: address = dbsession.query(CryptoAddress).one_or_none() asset = dbsession.query(Asset).get(eth_asset_id) account = address.get_account(asset) op = dbsession.query(CryptoOperation).one() assert account.account.get_balance() == Decimal(10) assert op.holding_account.get_balance() == 0 # Transaction label should be the Ethereum txid tx = account.account.transactions.one() assert tx.message == TEST_TXID
def test_deposit_eth_account(dbsession, eth_network_id, eth_service, eth_asset_id): """Deposit Ethereums to an account.""" # Create ETH holding account under an address with transaction.manager: # First create the address which holds our account network = dbsession.query(AssetNetwork).get(eth_network_id) address = CryptoAddress(network=network, address=eth_address_to_bin(TEST_ADDRESS)) dbsession.add(address) dbsession.flush() # Create deposit op with transaction.manager: address = dbsession.query(CryptoAddress).one_or_none() asset = dbsession.query(Asset).get(eth_asset_id) txid = txid_to_bin(TEST_TXID) op = address.deposit(Decimal(10), asset, txid, bin_to_txid(txid)) dbsession.add(op) opid = op.id # Resolve deposit op success_op_count, failed_op_count = eth_service.run_waiting_operations() assert success_op_count == 1 assert failed_op_count == 0 with transaction.manager: op = dbsession.query(CryptoOperation).get(opid) op.resolve() # Force resolution regardless on confirmation count # Check balances are settled with transaction.manager: address = dbsession.query(CryptoAddress).one_or_none() asset = dbsession.query(Asset).get(eth_asset_id) account = address.get_account(asset) op = dbsession.query(CryptoOperation).one() assert account.account.get_balance() == Decimal(10) assert op.holding_account.get_balance() == 0 # Transaction label should be the Ethereum txid tx = account.account.transactions.one() assert tx.message == TEST_TXID