Skip to content

Version 0.3.0 Asyncio

Compare
Choose a tag to compare
@MrNaif2018 MrNaif2018 released this 20 Aug 13:16
579d052

Version 0.3.0 Asyncio:
This version adds new events-based API to get updates.
To register a callback function, use add_event_handler(events, func) function or @on decorator
Example:

@btc.on("new_transaction")
async def handler(event, tx):
    print(event)
    print(tx)
    print(await btc.get_tx(tx))
btc.poll_updates()

The following code would print

new_transaction
some_tx_hash
dict of tx hash data

On each transaction in your wallet.
btc.on or add_event_handler can also accept a list of events, for example:

async def handler(event, **kwargs):
    print(event, kwargs)

Getting updates is the same, via btc.poll_updates().
There are two kinds of events for now:
new_block which gets emitted on every new block, passing height argument to callback function
new_transaction which gets emitted on every new transaction passing tx argument as tx_hash of new transaction to callback_function.
Callback function, as with old notify api can be either sync or async.
Old @btc.notify api is removed.