Tools and asset management

Transaction confirmation count updates

Network transactions are considered open as long as the confirmation threshold has not been reached.

Because backends do not actively report the progress of confirmation status, we poll the backend for all network transactions (deposits, broadcasts) until the confirmation threshold has been reached. For example, bitcoind gives you a walletnotify only for 0 and 1 confirmations. block.io does not have any confirmation hooks, but you can subcribe to chain.so real-time API to receive 0 confirmations notificatoin to an address.

cryptoassets.core.tools.confirmationupdate.update_confirmations() polls the backend. It will scan all transactions where confirmation threshold has not been reached and then ask the backend of more transaction details. Eventually all open incoming transactions exceed the confirmation threshold and we can stop polling them.

The poller is set up in cryptoassets.core.service.main.Service.

More information about walletnotify behavior

cryptoassets.core.tools.confirmationupdate.get_open_network_transactions(session, NetworkTransaction, confirmation_threshold)[source]

Get list of transaction_type, txid of transactions we need to check.

cryptoassets.core.tools.confirmationupdate.update_confirmations(transaction_updater, confirmation_threshold)[source]

Periodically rescan all open transactions for one particular cryptocurrency.

We try to keep transaction conflicts in minimum by not batching too many backend operations per each database session.

Parameters:
Returns:

Number of txupdate events fired

Broadcasting outgoing transactions

Broadcast outgoing transactions.

Broadcaster is responsible for the following things

  • Check that there hasn’t been any interrupted broadcats before
  • Make sure there can be one and only one attempt to broadcast at any moment - so we don’t have double broadcast problems
  • Scan database for outgoing external transactions
  • Merge and allocate these transactions to outgoing broadcasts
  • If there are any unbroadcasted broadcasts, mark them scheduled for broadcast and attempt to broadcast them
class cryptoassets.core.tools.broadcast.Broadcaster(wallet, conflict_resolver, backend)[source]

Create and send transactions to the cryptoasset networks.

get_wallet(session)[source]

Get a wallet instance within db transaction.

get_broadcast(session, broadcast_id)[source]

Get a wallet instance within db transaction.

collect_for_broadcast()[source]
Returns:Number of outgoing transactions collected for a broadcast
check_interrupted_broadcasts()[source]

Check that there aren’t any broadcasts which where opened, but never closed.

Returns:List Open broadcast ids or empty list if all good
send_broadcasts()[source]

Pick up any unbroadcasted broadcasts and attempt to send them.

Carefully do broadcasts within managed transactions, so that if something goes wrong we have a clear audit trail where it failed. Then one can manually check the blockchain if our transaction got there and close the broadcast by hand.

Returns:tuple (broadcasted network transaction count, total charged network fees)
do_broadcasts()[source]

Collect new outgoing transactions for a broadcast and send out all existing and new outgoing transactions.

Rescan receiving addresses

Scan all receiving addresses to see if we have missed any incoming transactions.

Importing existing wallet

Import existing wallet balance to the accounting.

If you have a wallet in some service and you wish to use it with cryptoassets.core, you need to tell cryptoassets.core what to do with the existing balance in the wallet, from the time before the wallet was managed by cryptoassets.core.

This is especially useful for testing. To run unit tests you need to have some cryptocurrency balance somewhere. You have known backends which you configure the unit tests to connect to. These backends have default wallets and there is some balance on these wallets, so unit tests can perform withdraw tests.

cryptoassets.core.tools.walletimport.create_import_transaction(amount, account)[source]

Put wallet extra coins, for which we do not know the owner, on a specific account.

Execute inside transaction manager.

Parameters:
  • amount (Decimal) – How many extra coins to account
  • account – Account instance where to put coins
cryptoassets.core.tools.walletimport.import_unaccounted_balance(backend, wallet, account)[source]

Creates a new transaction which will put all assets in the wallet on a new account.