From 77eabaa6e041aa8bfb0f5fc824811cff7abdfadf Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 30 Jul 2013 03:21:32 +0400 Subject: [PATCH] Add -walletnotify option This option provides an opportunity to call external script on new transactions --- src/init.cpp | 1 + src/qt/locale/bitcoin_en.ts | 5 +++++ src/qt/locale/bitcoin_ru.ts | 5 +++++ src/wallet.cpp | 11 +++++++++++ 4 files changed, 22 insertions(+), 0 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 199e3fa..bb87075 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -280,6 +280,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/qt/locale/bitcoin_en.ts b/src/qt/locale/bitcoin_en.ts index 9c804d2..3a94e5b 100644 --- a/src/qt/locale/bitcoin_en.ts +++ b/src/qt/locale/bitcoin_en.ts @@ -2494,6 +2494,11 @@ Address: %4 Execute command when the best block changes (%s in cmd is replaced by block hash) + + Execute command when a wallet transaction changes (%s in cmd is replaced by TxID) + Execute command when a wallet transaction changes (%s in cmd is replaced by TxID) + + Upgrade wallet to latest format Upgrade wallet to latest format diff --git a/src/qt/locale/bitcoin_ru.ts b/src/qt/locale/bitcoin_ru.ts index 5c2df8e..c183406 100644 --- a/src/qt/locale/bitcoin_ru.ts +++ b/src/qt/locale/bitcoin_ru.ts @@ -2507,6 +2507,11 @@ Address: %4 Выполнить команду, когда появляется новый блок (%s в команде заменяется на хэш блока) + + Execute command when a wallet transaction changes (%s in cmd is replaced by TxID) + Выполнить команду, когда получена новая транзакция (%s в команде заменяется на ID транзакции) + + Upgrade wallet to latest format Обновить бумажник до последнего формата diff --git a/src/wallet.cpp b/src/wallet.cpp index 9988577..7ddd67f 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -9,6 +9,7 @@ #include "ui_interface.h" #include "base58.h" #include "kernel.h" +#include using namespace std; extern int nStakeMaxAge; @@ -501,6 +502,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; } -- 1.7.1