Skip to content

Instantly share code, notes, and snippets.

Created May 31, 2014 13:50
Show Gist options
  • Save anonymous/0a11de38f25234d3af75 to your computer and use it in GitHub Desktop.
Save anonymous/0a11de38f25234d3af75 to your computer and use it in GitHub Desktop.
slimcoin walletnotify
diff --git a/src/init.cpp b/src/init.cpp
index c97c8f4..117aa64 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -639,6 +639,7 @@ std::string HelpMessage()
" -rpcallowip=<ip> \t\t " + _("Allow JSON-RPC connections from specified IP address") + "\n" +
" -rpcconnect=<ip> \t " + _("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 \t " + _("Upgrade wallet to latest format") + "\n" +
" -keypool=<n> \t " + _("Set key pool size to <n> (default: 100)") + "\n" +
" -rescan \t " + _("Rescan the block chain for missing wallet transactions") + "\n" +
diff --git a/src/main.cpp b/src/main.cpp
index a710e70..7a5e1ec 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1764,13 +1764,6 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew)
}
-static void runCommand(std::string strCommand)
-{
- int nErr = ::system(strCommand.c_str());
- if(nErr)
- printf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr);
-}
-
// Called from inside SetBestChain: attaches a block to the new best chain being built
bool CBlock::SetBestChainInner(CTxDB& txdb, CBlockIndex *pindexNew)
{
diff --git a/src/util.cpp b/src/util.cpp
index 7d5ea9a..04d5fd5 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -1395,3 +1395,10 @@ void LeaveCritical()
}
#endif /* DEBUG_LOCKORDER */
+void runCommand(std::string strCommand)
+{
+int nErr = ::system(strCommand.c_str());
+ if (nErr)
+ printf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr);
+}
+
diff --git a/src/util.h b/src/util.h
index 3393e92..188b9d6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -199,6 +199,7 @@ int64 GetAdjustedTime();
std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
void AddTimeData(const CNetAddr& ip, int64 nTime);
+void runCommand(std::string strCommand);
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 2a44f6f..1ce23ae 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -10,6 +10,7 @@
#include "crypter.h"
#include "ui_interface.h"
#include "kernel.h"
+#include <boost/algorithm/string/replace.hpp>
using namespace std;
@@ -393,6 +394,16 @@ bool CWallet::AddToWallet(const CWalletTx &wtxIn, bool fBurnTx)
// since AddToWallet is called directly for self-originating transactions, check for consumption of own coins
WalletUpdateSpent(wtx);
+
+ // 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
+ }
+
}
// Refresh UI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment