Event on mining

0 votes
Hi,

Do we get any event from multichain whenever a new block is mined on the blokchain? If yes, can it trigger any user-process(say maybe java code which inserts an entry into the node db) with the event?
asked Apr 14, 2016 by amanc

2 Answers

0 votes
As far as I know Multichain node and wallet applications are not designed to register event listeners/callbacks by external application. For that case even Bitcoind and other too doesn't provide listeners callback mechanism by default unless the code is modified for specific use case. The best which can be done on the Java app is to have a JSON/RPC call to the methods getblockcount periodically and perform custom operations. Also in the default configuration, blocks are added(will be added) in the 15 seconds interval, this makes it ideal for the external business application to query the block additions/etc at a time period more optimum suited to the application logic. Multichain will ensure that blocks are added in 15 seconds (or the defined time in params.dat) even if no user based transactions are performed in the time period.
answered Apr 14, 2016 by 7sigma
0 votes
Yes, you can use the -blocknotify feature of multichain.  This feature was introduced in bitcoin and is documented here (search for blocknotify)

https://en.bitcoin.it/wiki/Running_Bitcoin

You can configure blocknotify in the config file, so in multichain.conf you add something like this:

blocknotify=/home/simon/bin/blocknotify.sh %s

When a new block is mined, multichaind will run the blocknotify.sh script with the blockhash as an argument, replacing the %s placeholder.

A sample blocknotify.sh script might look like this:

#!/bin/sh
echo "new block: $@" >>/var/tmp/blocknotify.log

If you examine /var/tmp/blocknotify.log you should see something like:

new block: 0000fdfd653de77679c8ce3232c63fc9ca267af889f8671c779f00ff2fa7de2d
new block: 0000e774d6d7acb271d396dd7e2cdc898eda4eaff326178e4040856de9a3eb4f
new block: 0000e2437ec65725c7c49be6cbe0b180279a705b405f111c66897e919345c418
answered Apr 14, 2016 by simon
...