aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-02-22 08:47:04 -0800
committerGavin Andresen <gavinandresen@gmail.com>2013-02-22 08:47:04 -0800
commit49e332f6fc4ecc5f631d590ca7d2e69e1db327e1 (patch)
tree07f07ceb2eccbe643ceb969d764de51af2cf119c /src
parent123acb9a1b7f710f0d5265fe2ba7939a1caec334 (diff)
parentcae686d31e18a68826ef61931ae8379fe9461d7b (diff)
downloadbitcoin-49e332f6fc4ecc5f631d590ca7d2e69e1db327e1.tar.xz
Merge pull request #1974 from kjj2/walletnotify
Add -walletnotify to call an external script on wallet transactions
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp1
-rw-r--r--src/wallet.cpp11
2 files changed, 12 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 1be25203c1..64f91a349f 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -300,6 +300,7 @@ std::string HelpMessage()
" -rpcallowip=<ip> " + _("Allow JSON-RPC connections from specified IP address") + "\n" +
" -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n" +
" -blocknotify=<cmd> " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n" +
+ " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n" +
" -upgradewallet " + _("Upgrade wallet to latest format") + "\n" +
" -keypool=<n> " + _("Set key pool size to <n> (default: 100)") + "\n" +
" -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" +
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 2317ac31ac..3892e4b801 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -8,6 +8,7 @@
#include "crypter.h"
#include "ui_interface.h"
#include "base58.h"
+#include <boost/algorithm/string/replace.hpp>
using namespace std;
@@ -476,6 +477,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;
}