From cae686d31e18a68826ef61931ae8379fe9461d7b Mon Sep 17 00:00:00 2001 From: kjj2 Date: Sat, 3 Nov 2012 09:58:41 -0500 Subject: [PATCH] Add -walletnotify to call an external script on wallet transactions --- src/init.cpp | 1 + src/wallet.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index dc425da64..ec32b6209 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -276,6 +276,7 @@ std::string HelpMessage() " -rpcallowip= " + _("Allow JSON-RPC connections from specified IP address") + "\n" + " -rpcconnect= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n" + " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n" + + " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n" + " -upgradewallet " + _("Upgrade wallet to latest format") + "\n" + " -keypool= " + _("Set key pool size to (default: 100)") + "\n" + " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" + diff --git a/src/wallet.cpp b/src/wallet.cpp index 880f7aa8b..f9da100e2 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -8,6 +8,7 @@ #include "crypter.h" #include "ui_interface.h" #include "base58.h" +#include using namespace std; @@ -470,6 +471,16 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) // Notify UI of new or updated transaction NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED); + + // notify an external script when a wallet transaction comes in or is updated + std::string strCmd = GetArg("-walletnotify", ""); + + if ( !strCmd.empty()) + { + boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex()); + boost::thread t(runCommand, strCmd); // thread runs free + } + } return true; }