aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-09-03 14:19:15 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-09-29 08:44:18 +0000
commit734030046055f521a73e59b50fa2a16f48e34c8d (patch)
tree7f7f8b4d50b8a0138c3c22d39d447ca0a85d45b1 /src/wallet
parentMerge pull request #4423 (diff)
downloadmonero-734030046055f521a73e59b50fa2a16f48e34c8d.tar.xz
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.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.cpp24
-rw-r--r--src/wallet/wallet2.h5
2 files changed, 29 insertions, 0 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 75178845a..4e1b0ccad 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<uint64_t> kdf_rounds = {"kdf-rounds", tools::wallet2::tr("Number of rounds for the key derivation function"), 1};
const command_line::arg_descriptor<std::string> hw_device = {"hw-device", tools::wallet2::tr("HW device to use"), ""};
+ const command_line::arg_descriptor<std::string> 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<tools::wallet2> 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<tools::Notify>(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> wallet2::make_from_json(const boost::program_options::variables_map& vm, bool unattended, const std::string& json_file, const std::function<boost::optional<tools::password_container>(const char *, bool)> &password_prompter)
@@ -1328,6 +1342,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
std::vector<size_t> outs;
std::unordered_map<cryptonote::subaddress_index, uint64_t> tx_money_got_in_outs; // per receiving subaddress index
crypto::public_key tx_pub_key = null_pkey;
+ bool notify = false;
std::vector<tx_extra_field> 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;
}
}
}
@@ -1790,6 +1807,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<tools::Notify> 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 acbc09c36..d38e92ca9 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<tools::Notify> &notify) { m_tx_notify = notify; }
+
private:
/*!
* \brief Stores wallet information to wallet file.
@@ -1353,6 +1356,8 @@ namespace tools
boost::optional<epee::wipeable_string> m_encrypt_keys_after_refresh;
bool m_unattended;
+
+ std::shared_ptr<tools::Notify> m_tx_notify;
};
}
BOOST_CLASS_VERSION(tools::wallet2, 25)