add --block-notify to monerod and --tx-notify to monero-wallet-{cli,rpc}

Those take a command line of the form "A [B]", with A being the
name (and optional path, if not in the caller's CWD, but fully
qualified path is recommended, avoids possible security issues)
to a program, and optional arguments. Any occurence of the two
character string "%s" will be replaced by the hash of the block
or transaction which triggered the notification.

Tokenization is barebones. If you want things like pipes, calls
to paths with spaces, etc, then use a script (though exec time
will suffer).

block-notify is called when a new block is added onto the chain.

tx-notify is called when a new transaction happens with the
wallet as source and/or destination.

It is the notification program's responsibility to determine what
to do in those cases.

Note that this is asynchronous, so it is very possible that:
- the notification programs will be run out of order
- several events happen before the notification for the first one

A Windows port would be nice if someone wants to make one.
This commit is contained in:
moneromooo-monero 2018-09-03 14:19:15 +00:00
parent 8bf5a00564
commit 7340300460
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
10 changed files with 300 additions and 0 deletions

View file

@ -52,6 +52,7 @@
#include "cryptonote_core.h"
#include "ringct/rctSigs.h"
#include "common/perf_timer.h"
#include "common/notify.h"
#if defined(PER_BLOCK_CHECKPOINT)
#include "blocks/blocks.h"
#endif
@ -3552,6 +3553,10 @@ leave:
get_difficulty_for_next_block(); // just to cache it
invalidate_block_template_cache();
std::shared_ptr<tools::Notify> block_notify = m_block_notify;
if (block_notify)
block_notify->notify(epee::string_tools::pod_to_hex(id).c_str());
return true;
}
//------------------------------------------------------------------