From 83d8f03c2338e865ce72f4e2d46d43a48530ab10 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Sat, 29 Sep 2018 22:18:08 +0200 Subject: Merge pull request #4333 73403004 add --block-notify to monerod and --tx-notify to monero-wallet-{cli,rpc} (moneromooo-monero) --- src/wallet/wallet2.cpp | 24 ++++++++++++++++++++++++ src/wallet/wallet2.h | 5 +++++ 2 files changed, 29 insertions(+) (limited to 'src/wallet') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a60874af9..299b4afeb 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -66,6 +66,7 @@ using namespace epee; #include "memwipe.h" #include "common/base58.h" #include "common/dns_utils.h" +#include "common/notify.h" #include "ringct/rctSigs.h" #include "ringdb.h" @@ -162,6 +163,7 @@ struct options { }; const command_line::arg_descriptor kdf_rounds = {"kdf-rounds", tools::wallet2::tr("Number of rounds for the key derivation function"), 1}; const command_line::arg_descriptor hw_device = {"hw-device", tools::wallet2::tr("HW device to use"), ""}; + const command_line::arg_descriptor tx_notify = { "tx-notify" , "Run a program for each new incoming transaction, '%s' will be replaced by the transaction hash" , "" }; }; void do_prepare_file_names(const std::string& file_path, std::string& keys_file, std::string& wallet_file) @@ -268,6 +270,17 @@ std::unique_ptr make_basic(const boost::program_options::variabl boost::filesystem::path ringdb_path = command_line::get_arg(vm, opts.shared_ringdb_dir); wallet->set_ring_database(ringdb_path.string()); wallet->device_name(device_name); + + try + { + if (!command_line::is_arg_defaulted(vm, opts.tx_notify)) + wallet->set_tx_notify(std::shared_ptr(new tools::Notify(command_line::get_arg(vm, opts.tx_notify).c_str()))); + } + catch (const std::exception &e) + { + MERROR("Failed to parse tx notify spec"); + } + return wallet; } @@ -838,6 +851,7 @@ void wallet2::init_options(boost::program_options::options_description& desc_par command_line::add_arg(desc_params, opts.shared_ringdb_dir); command_line::add_arg(desc_params, opts.kdf_rounds); command_line::add_arg(desc_params, opts.hw_device); + command_line::add_arg(desc_params, opts.tx_notify); } std::unique_ptr wallet2::make_from_json(const boost::program_options::variables_map& vm, bool unattended, const std::string& json_file, const std::function(const char *, bool)> &password_prompter) @@ -1328,6 +1342,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote std::vector outs; std::unordered_map tx_money_got_in_outs; // per receiving subaddress index crypto::public_key tx_pub_key = null_pkey; + bool notify = false; std::vector local_tx_extra_fields; if (tx_cache_data.tx_extra_fields.empty()) @@ -1567,6 +1582,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index); } total_received_1 += amount; + notify = true; } else if (m_transfers[kit->second].m_spent || m_transfers[kit->second].amount() >= tx_scan_info[o].amount) { @@ -1634,6 +1650,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index); } total_received_1 += extra_amount; + notify = true; } } } @@ -1794,6 +1811,13 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote LOG_PRINT_L2("Payment found in " << (pool ? "pool" : "block") << ": " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount); } } + + if (notify) + { + std::shared_ptr tx_notify = m_tx_notify; + if (tx_notify) + tx_notify->notify(epee::string_tools::pod_to_hex(txid).c_str()); + } } //---------------------------------------------------------------------------------------------------- void wallet2::process_unconfirmed(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index db1ac7e42..497dd486f 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -68,6 +68,7 @@ namespace tools { class ringdb; class wallet2; + class Notify; class wallet_keys_unlocker { @@ -1176,6 +1177,8 @@ namespace tools void change_password(const std::string &filename, const epee::wipeable_string &original_password, const epee::wipeable_string &new_password); + void set_tx_notify(const std::shared_ptr ¬ify) { m_tx_notify = notify; } + private: /*! * \brief Stores wallet information to wallet file. @@ -1353,6 +1356,8 @@ namespace tools boost::optional m_encrypt_keys_after_refresh; bool m_unattended; + + std::shared_ptr m_tx_notify; }; } BOOST_CLASS_VERSION(tools::wallet2, 25) -- cgit v1.2.3