def test_create_address_accounts(dbsession, eth_network_id, eth_service, eth_faux_address, eth_asset_id): """Check that we can cerate different accounts under an account.""" # Create ETH account with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) address = CryptoAddress(network=network, address=eth_address_to_bin(TEST_ADDRESS)) asset = dbsession.query(Asset).get(eth_asset_id) dbsession.flush() account = address.get_or_create_account(asset) account_id = account.id # We get it reflected back second time with transaction.manager: address = dbsession.query(CryptoAddress).one() asset = dbsession.query(Asset).get(eth_asset_id) account = address.get_or_create_account(asset) assert account.id == account_id # We cannot create double account for the same asset with pytest.raises(MultipleAssetAccountsPerAddress): with transaction.manager: address = dbsession.query(CryptoAddress).one() asset = dbsession.query(Asset).get(eth_asset_id) address.create_account(asset)
def test_create_address_accounts(dbsession, eth_network_id, eth_service, eth_faux_address, eth_asset_id): """Check that we can cerate different accounts under an account.""" # Create ETH account with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) address = CryptoAddress(network=network, address=eth_address_to_bin(TEST_ADDRESS)) asset = dbsession.query(Asset).get(eth_asset_id) dbsession.flush() account = address.get_or_create_account(asset) account_id = account.id # We get it reflected back second time with transaction.manager: address = dbsession.query(CryptoAddress).one() asset = dbsession.query(Asset).get(eth_asset_id) account = address.get_or_create_account(asset) assert account.id == account_id # We cannot create double account for the same asset with pytest.raises(MultipleAssetAccountsPerAddress): with transaction.manager: address = dbsession.query(CryptoAddress).one() asset = dbsession.query(Asset).get(eth_asset_id) address.create_account(asset)
def on_deposit(self, address: CryptoAddress, opid, log_data, log_entry) -> CryptoAddressDeposit: """Handle Hosted Wallet Deposit event. Create incoming holding account holding the ETH assets until we receive enough confirmations. """ op = CryptoAddressDeposit(address.network) # Get or create final account where we deposit the transaction asset = get_ether_asset(self.dbsession, network=address.network) crypto_account = address.get_or_create_account(asset) op.crypto_account = crypto_account op.external_address = eth_address_to_bin(log_data["from"]) # Create holding account that keeps the value until we receive N amount of confirmations acc = Account(asset=asset) self.dbsession.add(acc) self.dbsession.flush() value = wei_to_eth(log_data["value"]) acc.do_withdraw_or_deposit(value, "ETH deposit from {} in tx {}".format(log_data["from"], log_entry["transactionHash"])) op.holding_account = acc return op
def on_deposit(self, address: CryptoAddress, opid, log_data, log_entry) -> CryptoAddressDeposit: """Handle Hosted Wallet Deposit event. Create incoming holding account holding the ETH assets until we receive enough confirmations. """ op = CryptoAddressDeposit(address.network) # Get or create final account where we deposit the transaction asset = get_ether_asset(self.dbsession, network=address.network) crypto_account = address.get_or_create_account(asset) op.crypto_account = crypto_account op.external_address = eth_address_to_bin(log_data["from"]) # Create holding account that keeps the value until we receive N amount of confirmations acc = Account(asset=asset) self.dbsession.add(acc) self.dbsession.flush() value = wei_to_eth(log_data["value"]) acc.do_withdraw_or_deposit( value, "ETH deposit from {} in tx {}".format( log_data["from"], log_entry["transactionHash"])) op.holding_account = acc return op