<p>A transaction can only be confirmed by a new block being added to the chain. And since that happens on average every ten minutes, it would work just as well to be notified when a block is discovered (and/or the chain is reorganized). You can then check any transactions you care about.</p>

<p>One way to be notified if the chain is changed in any way is with my native long polling patch. This should apply pretty cleanly to any recent version of the client (but is based on 0.4.0):</p>

<pre><code>diff -u orig/init.cpp new/init.cpp
--- orig/init.cpp   2011-09-25 08:29:53.935505617 -0700
+++ new/init.cpp    2011-09-25 08:48:13.667215990 -0700
@@ -199,6 +200,7 @@
             "  -rpcport=&lt;port&gt;  \t\t  " + _("Listen for JSON-RPC connections on &lt;port&gt; (default: 8332)\n") +
             "  -rpcallowip=&lt;ip&gt; \t\t  " + _("Allow JSON-RPC connections from specified IP address\n") +
             "  -rpcconnect=&lt;ip&gt; \t  "   + _("Send commands to node running on &lt;ip&gt; (default: 127.0.0.1)\n") +
+            "  -pollpidfile=&lt;f&gt; \t  "   + _("Support long polling\n") +
             "  -keypool=&lt;n&gt;     \t  "   + _("Set key pool size to &lt;n&gt; (default: 100)\n") +
             "  -rescan          \t  "   + _("Rescan the block chain for missing wallet transactions\n");

diff -u orig/main.cpp new/main.cpp
--- orig/main.cpp   2011-09-25 08:29:53.937505613 -0700
+++ new/main.cpp    2011-09-25 08:48:13.667215990 -0700
@@ -1118,6 +1118,7 @@
 bool CBlock::SetBestChain(CTxDB&amp; txdb, CBlockIndex* pindexNew)
 {
     uint256 hash = GetHash();
+    bool lp = false;

     txdb.TxnBegin();
     if (pindexGenesisBlock == NULL &amp;&amp; hash == hashGenesisBlock)
@@ -1160,6 +1161,7 @@
     // Update best block in wallet (so we can detect restored wallets)
     if (!IsInitialBlockDownload())
     {
+        lp = true;
         const CBlockLocator locator(pindexNew);
         ::SetBestChain(locator);
     }
@@ -1173,6 +1175,23 @@
     nTransactionsUpdated++;
     printf("SetBestChain: new best=%s  height=%d  work=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBest

+    if (lp)
+    {
+        // Support long polling
+        string lp_pid = mapArgs["-pollpidfile"];
+        if(lp_pid != "")
+        {
+            FILE *pidFile = fopen(lp_pid.c_str(), "r");
+            if(pidFile!=NULL)
+            {
+                int pid=0;
+                if ((fscanf(pidFile, "%d", &amp;pid) == 1) &amp;&amp; (pid &gt; 1))
+                    kill((pid_t) pid, SIGUSR1);
+                fclose(pidFile);
+            }
+        }
+    }
+
     return true;
 }
</code></pre>

<p>To use it, just start <code>bitcoin</code> or <code>bitcoind</code> with a command line argument of<br><code>-pollpidfile=/path/to/some/file</code>. Then write your monitor process' PID to that file. You will receive a <code>SIGUSR1</code> on any block chain change.</p>

CC BY-SA 3.0
2011-10-04T02:28:54.390Z
2011-10-04T02:41:22.467Z
2011-10-04T02:41:22.467Z
David Schwartz
<p>Is there a way to be notified by bitcoind via the CLI that some incoming transaction has been confirmed?</p>

CC BY-SA 3.0
2011-10-03T21:32:35.607Z
there was a patch for that somewhere out there, but i don't recall where exactly so i'll leave it for someone else to find. :)
nanotube
<transactions><bitcoind>
Push notification of incoming transaction
Mascarpone
# Push notification of incoming transaction

(Asked by: username_0 on 2011-10-03)

Is there a way to be notified by bitcoind via the CLI that some incoming transaction has been confirmed?

**Tags:** transactions, bitcoind

> **Comments:**
> **username_1**: there was a patch for that somewhere out there, but i don't recall where exactly so i'll leave it for someone else to find. :)  

---

## 1 answers

### Answer by username_2 on 2011-10-04. Score: 13 | Accepted answer

A transaction can only be confirmed by a new block being added to the chain. And since that happens on average every ten minutes, it would work just as well to be notified when a block is discovered (and/or the chain is reorganized). You can then check any transactions you care about.

One way to be notified if the chain is changed in any way is with my native long polling patch. This should apply pretty cleanly to any recent version of the client (but is based on 0.4.0):

```
diff -u orig/init.cpp new/init.cpp
--- orig/init.cpp   2011-09-25 08:29:53.935505617 -0700
+++ new/init.cpp    2011-09-25 08:48:13.667215990 -0700
@@ -199,6 +200,7 @@
             "  -rpcport=<port>  \t\t  " + _("Listen for JSON-RPC connections on <port> (default: 8332)\n") +
             "  -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") +
+            "  -pollpidfile=<f> \t  "   + _("Support long polling\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 -u orig/main.cpp new/main.cpp
--- orig/main.cpp   2011-09-25 08:29:53.937505613 -0700
+++ new/main.cpp    2011-09-25 08:48:13.667215990 -0700
@@ -1118,6 +1118,7 @@
 bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
 {
     uint256 hash = GetHash();
+    bool lp = false;

     txdb.TxnBegin();
     if (pindexGenesisBlock == NULL && hash == hashGenesisBlock)
@@ -1160,6 +1161,7 @@
     // Update best block in wallet (so we can detect restored wallets)
     if (!IsInitialBlockDownload())
     {
+        lp = true;
         const CBlockLocator locator(pindexNew);
         ::SetBestChain(locator);
     }
@@ -1173,6 +1175,23 @@
     nTransactionsUpdated++;
     printf("SetBestChain: new best=%s  height=%d  work=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBest

+    if (lp)
+    {
+        // Support long polling
+        string lp_pid = mapArgs["-pollpidfile"];
+        if(lp_pid != "")
+        {
+            FILE *pidFile = fopen(lp_pid.c_str(), "r");
+            if(pidFile!=NULL)
+            {
+                int pid=0;
+                if ((fscanf(pidFile, "%d", &pid) == 1) && (pid > 1))
+                    kill((pid_t) pid, SIGUSR1);
+                fclose(pidFile);
+            }
+        }
+    }
+
     return true;
 }

```

To use it, just start `bitcoin` or `bitcoind` with a command line argument of  
`-pollpidfile=/path/to/some/file`. Then write your monitor process' PID to that file. You will receive a `SIGUSR1` on any block chain change.


---

