aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-09-29 22:18:08 +0200
committerRiccardo Spagni <ric@spagni.net>2018-09-29 22:20:44 +0200
commit83d8f03c2338e865ce72f4e2d46d43a48530ab10 (patch)
treef828dcec6b4bf1c7fb2cbf88d8ac8e4168697643 /src/cryptonote_core
parentMerge pull request #4461 (diff)
downloadmonero-83d8f03c2338e865ce72f4e2d46d43a48530ab10.tar.xz
Merge pull request #4333
73403004 add --block-notify to monerod and --tx-notify to monero-wallet-{cli,rpc} (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp5
-rw-r--r--src/cryptonote_core/blockchain.h11
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp17
3 files changed, 33 insertions, 0 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 0e175cdbe..fb4dcef7c 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -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;
}
//------------------------------------------------------------------
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 50ceccd0f..ab66fac8b 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -55,6 +55,8 @@
#include "cryptonote_basic/hardfork.h"
#include "blockchain_db/blockchain_db.h"
+namespace tools { class Notify; }
+
namespace cryptonote
{
class tx_memory_pool;
@@ -706,6 +708,13 @@ namespace cryptonote
blockchain_db_sync_mode sync_mode, bool fast_sync);
/**
+ * @brief sets a block notify object to call for every new block
+ *
+ * @param notify the notify object to cal at every new block
+ */
+ void set_block_notify(const std::shared_ptr<tools::Notify> &notify) { m_block_notify = notify; }
+
+ /**
* @brief Put DB in safe sync mode
*/
void safesyncmode(const bool onoff);
@@ -1032,6 +1041,8 @@ namespace cryptonote
uint64_t m_btc_expected_reward;
bool m_btc_valid;
+ std::shared_ptr<tools::Notify> m_block_notify;
+
/**
* @brief collects the keys for all outputs being "spent" as an input
*
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 3e3d3c19c..69e3c708b 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -53,6 +53,7 @@ using namespace epee;
#include "ringct/rctTypes.h"
#include "blockchain_db/blockchain_db.h"
#include "ringct/rctSigs.h"
+#include "common/notify.h"
#include "version.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -167,6 +168,11 @@ namespace cryptonote
, "Set maximum txpool weight in bytes."
, DEFAULT_TXPOOL_MAX_WEIGHT
};
+ static const command_line::arg_descriptor<std::string> arg_block_notify = {
+ "block-notify"
+ , "Run a program for each new block, '%s' will be replaced by the block hash"
+ , ""
+ };
//-----------------------------------------------------------------------------------------------
core::core(i_cryptonote_protocol* pprotocol):
@@ -276,6 +282,7 @@ namespace cryptonote
command_line::add_arg(desc, arg_offline);
command_line::add_arg(desc, arg_disable_dns_checkpoints);
command_line::add_arg(desc, arg_max_txpool_weight);
+ command_line::add_arg(desc, arg_block_notify);
miner::init_options(desc);
BlockchainDB::init_options(desc);
@@ -545,6 +552,16 @@ namespace cryptonote
m_blockchain_storage.set_user_options(blocks_threads,
sync_on_blocks, sync_threshold, sync_mode, fast_sync);
+ try
+ {
+ if (!command_line::is_arg_defaulted(vm, arg_block_notify))
+ m_blockchain_storage.set_block_notify(std::shared_ptr<tools::Notify>(new tools::Notify(command_line::get_arg(vm, arg_block_notify).c_str())));
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to parse block notify spec");
+ }
+
const std::pair<uint8_t, uint64_t> regtest_hard_forks[3] = {std::make_pair(1, 0), std::make_pair(Blockchain::get_hard_fork_heights(MAINNET).back().version, 1), std::make_pair(0, 0)};
const cryptonote::test_options regtest_test_options = {
regtest_hard_forks