Bitcoin Forum
October 19, 2017, 12:40:37 AM *
News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Adding -walletlog option. Need some advice.  (Read 585 times)
btc4ever
Sr. Member
****
Offline Offline

Activity: 419


View Profile
July 26, 2013, 12:12:12 AM
 #1

My application needs to be notified of incoming transactions and confirmations.

I am aware of the new -walletnotify flag, but I view this as a farily heavyweight solution because using it requires forking a new process and then that process must make a jsonrpc call back to bitcoind in order to call gettransaction and finally get the needed information. And I have noticed that at times bitcoind is laggy responding to jsonrpc requests.

So my initial reasoning was that it would be much more efficient to just log the transaction in json from the same place that walletnotify processing occurs in bitcoind. inside CWallet::AddToWallet().

I have implemented a patch that does this. The first problem is that confirmations is always reported as 0. So my working theory is that perhaps the code is executing too early in the codepath, before the confirmation count field gets updated.

Also, it seems that for receives, the AddToWallet() function gets called twice, but for sends it gets called 3 times. Ideally, this logging feature would log up to N confirmations, so really it needs to be somewhere that gets called for each confirmation. any suggestions where?     ( Apparently this is a limitation for the -walletnotify feature as well. )

Here is example output from the log file for a received transaction:

[{"account":"","address":"AHBL4ezNrqdipSXknANkbGGKXfJtzvv7A6","category":"receive","amount":0.10000000,"confirmations":0,"txid":"3b69b0bcc907c22803fd32299324b38b6d5082ba55fd1a8eaebf5759f5330754","time":1374792299,"timereceived":1374792299}] [{"account":"","address":"AHBL4ezNrqdipSXknANkbGGKXfJtzvv7A6","category":"receive","amount":0.10000000,"confirmations":0,"txid":"3b69b0bcc907c22803fd32299324b38b6d5082ba55fd1a8eaebf5759f5330754","time":1374792299,"timereceived":1374792299}]

This is my first time diving into bitcoind code, and I am presently intending this patch just for my own private use. I know it is rough -- so please don't rake me over the coals too much. ;-) Here's the patch:


diff --git a/src/init.cpp b/src/init.cpp
index 3dce3cf..4bfdc65 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -354,0 +355 @@ std::string HelpMessage()
+        "  -walletlog=<file>     "  + _("Log to file when a wallet transaction changes. non-standard.") + "\n" +
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 872afae..364c992 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -12,0 +13,4 @@
+#include <boost/filesystem.hpp>
+#include "json/json_spirit_value.h"
+#include "json/json_spirit_writer_template.h"
+
@@ -13,0 +18 @@ using namespace std;
+using namespace json_spirit;
@@ -14,0 +20 @@ using namespace std;
+void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret);
@@ -496,0 +503,17 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
+        std::string strLog = GetArg("-walletlog", "");
+        if ( !strLog.empty() )
+        {
+            FILE* fh = fopen( strLog.c_str(), "a");
+            if( !fh ) {
+                printf("Unable to open wallet log file: %s", strLog.c_str() );
+            }
+            else {
+                Array ret;
+                ListTransactions(wtx, "*", 0, true, ret);
+               
+                string output = write_string(Value(ret), false) + "\n";
+                fputs( output.c_str(), fh );
+                fclose( fh );
+            }
+        }
+       

Psst!!  Wanna make bitcoin unstoppable? Why the Only Real Way to Buy Bitcoins Is on the Streets. Avoid banks and centralized exchanges.   Buy/Sell coins locally.  Meet other bitcoiners and develop your network.   Try localbitcoins.com or find or start a buttonwood / satoshi square in your area.  Pass it on!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1508373637
Hero Member
*
Offline Offline

Posts: 1508373637

View Profile Personal Message (Offline)

Ignore
1508373637
Reply with quote  #2

1508373637
Report to moderator
1508373637
Hero Member
*
Offline Offline

Posts: 1508373637

View Profile Personal Message (Offline)

Ignore
1508373637
Reply with quote  #2

1508373637
Report to moderator
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
July 26, 2013, 08:14:31 PM
 #2

I'm not sure that you'll actually gain much.

There is nothing internal to bitcoind that cares enough about confirmation count to give you an easy place to hook for that.

I strongly suggest that you split your problem into two parts.  The first is a lightweight program that accepts the input from -walletnotify and -blocknotify and dumps it into an asynchronous processing queue.  The second is either a cron job or a long running process that inspects that queue and can do slower things like making RPC calls back to bitcoind for more information.

As an aside, I've never seen a transaction that gave more than 2 hits it -walletnotify.  Can you tell me more about the send that you saw 3 notices for?

p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!