Where is the exact code part of the walletnotify function?

3

1

I'm new on the BTC project, so please spare me if I asked something newbies.

I downloaded the latest 0.92 BTC source code and trying to make a customize to the walletnotify function for myself while running the bitcoind. But when I search into the code, that triggered runCommand() at util.cpp and pew "End of the road".

I googled about this walletnotify function, but all I seemed are only the usage infos. So I think it's time to ask the question here but thinking the dead-end by myself.

Kaninchen

Posted 2014-06-23T06:21:13.623

Reputation: 33

A good place to start: https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L591

George Kimionis 2014-06-24T00:53:40.980

Instead of modifying the actual bitcoin code, which is often very error prone, it may be better to trigger some api request upon walletnotify.Loourr 2014-07-05T20:31:33.287

Answers

3

I don't know exactly what you are asking, but

wallet.cpp (from line 591)

    // 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
    }

runs a thread that executes the runCommand() function in util.cpp

wallet.cpp (from line 1335)

void runCommand(std::string strCommand)
{
    int nErr = ::system(strCommand.c_str());
    if (nErr)
        LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr);
}

and I think that is all code you need.

Jori

Posted 2014-06-23T06:21:13.623

Reputation: 1 522

I know this part when I do the search in the entire project. But what I don't get is when I typed the command "bitcoind -walletnotify", there should be have a function named like "walletnotify()" or something similar to send back these incoming transactions that hits the addresses in my wallet.

I'm trying to find this function and make some modify to its if conditions and return(or echo) form; – Kaninchen 2014-06-24T15:45:53.587

There is no walletnotify() function. All logic is in these two snippets.Jori 2014-06-24T19:32:38.443

Hmm, sad they didn't make it a function... Thanks and I'll ask again if I got more questions.Kaninchen 2014-06-25T07:15:47.600