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

Implement ixnotify #747

Closed
wants to merge 1 commit 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 @@ -558,6 +558,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageGroup(_("InstantX options:"));
strUsage += HelpMessageOpt("-enableinstantx=<n>", strprintf(_("Enable instantx, show confirmations for locked transactions (0-1, default: %u)"), fEnableInstantX));
strUsage += HelpMessageOpt("-instantxdepth=<n>", strprintf(_("Show N confirmations for a successfully locked transaction (0-9999, default: %u)"), nInstantXDepth));
strUsage += HelpMessageOpt("-ixnotify=<cmd>", _("Execute command when a wallet IX transaction is successfully locked (%s in cmd is replaced by TxID)"));


strUsage += HelpMessageGroup(_("Node relay options:"));
Expand Down
15 changes: 14 additions & 1 deletion src/instantx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#include "masternode-sync.h"
#include "masternodeman.h"
#include "spork.h"

#include <boost/algorithm/string/replace.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>

using namespace std;
using namespace boost;
Expand Down Expand Up @@ -362,7 +365,8 @@ bool ProcessConsensusVote(CNode* pnode, CConsensusVote& ctx)

LogPrint("instantx", "InstantX::ProcessConsensusVote - Transaction Lock Votes %d - %s !\n", (*i).second.CountSignatures(), ctx.GetHash().ToString());

if((*i).second.CountSignatures() >= INSTANTX_SIGNATURES_REQUIRED){
int nSignatures = (*i).second.CountSignatures();
if(nSignatures >= INSTANTX_SIGNATURES_REQUIRED){
LogPrint("instantx", "InstantX::ProcessConsensusVote - Transaction Lock Is Complete %s !\n", (*i).second.GetHash().ToString());

CTransaction& tx = mapTxLockReq[ctx.txHash];
Expand All @@ -372,6 +376,15 @@ bool ProcessConsensusVote(CNode* pnode, CConsensusVote& ctx)
if(pwalletMain){
if(pwalletMain->UpdatedTransaction((*i).second.txHash)){
nCompleteTXLocks++;
if(nSignatures == INSTANTX_SIGNATURES_REQUIRED) {
// notify external script once threshold is reached
std::string strCmd = GetArg("-ixnotify", "");
if ( !strCmd.empty())
{
boost::replace_all(strCmd, "%s", ctx.txHash.GetHex());
boost::thread t(runCommand, strCmd); // thread runs free

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From experience, there's oddness if this runs from any other thread than init.cpp. Have you tested it? You should try sleeping for a minute in a target script, I think it will halt the daemon.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will try smth like that, thanks

}
}
}
}
#endif
Expand Down