Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added -txnotify to call a script when a transaction is received #2364

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
" -txnotify=<cmd> " + _("Execute command when any transaction changes (%s in cmd is replaced by TxID)") + "\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" +
Expand Down
22 changes: 21 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,14 @@ bool CTxMemPool::accept(CValidationState &state, CTransaction &tx, bool fCheckIn
EraseFromWallets(ptxOld->GetHash());
SyncWithWallets(hash, tx, NULL, true);

std::string strCmd = GetArg("-txnotify", "");

if (!IsInitialBlockDownload() && !strCmd.empty())
{
boost::replace_all(strCmd, "%s", hash.GetHex());
boost::thread t(runCommand, strCmd); // thread runs free
}

printf("CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n",
hash.ToString().substr(0,10).c_str(),
mapTx.size());
Expand Down Expand Up @@ -1717,10 +1725,22 @@ bool CBlock::ConnectBlock(CValidationState &state, CBlockIndex* pindex, CCoinsVi
// add this block to the view's block chain
assert(view.SetBestBlock(pindex));

// Watch for transactions paying to me

for (unsigned int i=0; i<vtx.size(); i++)
{
// Watch for transactions paying to me
SyncWithWallets(GetTxHash(i), vtx[i], this, true);

std::string strCmd = GetArg("-txnotify", "");

if (!IsInitialBlockDownload() && !strCmd.empty())
{
boost::replace_all(strCmd, "%s", GetTxHash(i).GetHex());
boost::thread t(runCommand, strCmd); // thread runs free
}

}

return true;
}

Expand Down