We accept payment in bitcoin: Part six. Nuances, again nuances

We accept payment in bitcoin: Part six. Nuances, again nuances

In the last part, we pointed out that it wouldn’t be a bad idea to find out about the fact of payment from bitcoind, instead of going through all the issued addresses.

Read the full series of articles for developers of a payment gateway for bitcoin here:

ACCEPT PAYMENT IN BITCOIN: PART ONE, THEORETICAL

WE ACCEPT PAYMENT IN BITCOIN: PART TWO. TOOLS AND PREPARATION

WE ACCEPT PAYMENT IN BITCOIN: PART THREE, YOUR TESTNET. WITH BLACKJACK

ACCEPT PAYMENT IN BITCOIN: PART FOURTH, CLOSER TO THE BUSINESS!

WE ACCEPT PAYMENT IN BITCOIN: PART FIVE, THERE ARE NUANCES


Firstly, by doing this we slow down the entire system, and with a large number of payments this becomes a serious problem. And secondly, “firstly” is quite enough.

I mentioned in the last article that bitcoind can still send notifications, although it does it in a somewhat unique way. Technically, when certain events occur, a system command (program) is launched, passing data as a command line argument. Offhand, there are three such events: alertnotify, blocknotify and walletnotify. We are interested in the last two.

In order to receive notifications, we need to specify the following in the bitcoin.conf configuration file:

walletnotify=command1 %s 
blocknotify=command2 %s 

What will this give us, and how does it work? For any transaction associated with our wallet, that is, with any address issued by our bitcoind, the command will be executed command1 specified for walletnotify, and the transaction hash will be substituted as the %s parameter. Of course, I would like to have both the address and the amount - but we have what we have. Having TxId, we can already obtain complete information about the transaction, including all addresses and amounts.

Now about the nuances. 

The command will be run a maximum of two times. Sometimes - alone. The first time is when receiving an unconfirmed transaction and adding it to the mempool. The second time is when the transaction is included in the block, that is, when the first confirmation is received. In some cases, the first notification may not arrive at all.. But what should we do if we want to consider the payment completed after the canonical six confirmations?

This is where blocknotify comes to our aid. The command2 command will be executed when each new signed block is added, and the hash of the block will be returned instead of the %s parameter. Next, we can either check all of our registered transactions for the number of confirmations (yes, such information in a transaction comes from bitcoind), or view each block to see if it contains transactions with our addresses (long, ineffective, but sometimes necessary)

How the software part that implements notifications will be implemented is entirely up to the developer. It could be a bash script, a C/C++ program, or PHP. The main thing is that your application can be launched from the command line.

You May Also Like

02018-06-16

We accept payment in bitcoin: Part four, closer to the point!

In previous articles, we looked at the general principles of organizing a bitcoin payment gateway, figured out the tools and necessary software, and even assembled our own pocket bitcoin network.

Development
02018-06-07

Apple publishes new rules on cryptocurrency apps

According to TechCrunch, a number of Apple developers recently joined forces to create the “Developers Union.” The union asked Apple to provide Apple Store users with the opportunity to download free trials of their applications. This is one of the first times that independent iOS developers are trying to fight back against Apple Store policies.

Development

Latest articles from Development category

Fresh video on our Channel