IPN Solution & Confirmations

(Sexual) #1

Looking to get some insight in how people would setup a instant payment notification system with payment forwarding. I don’t necessarily think my method will be very efficient at quite a large scale (~1000 payments a day)

Pseudocode of my idea so far:

this.hdPrivateKey = new bitcore.HDPrivateKey(this.node.network);
var address = this.hdPrivateKey.derive(this.addressIndex).privateKey.toAddress();

// save address and amount needed, etc to database


this.bus.on('bitcoind/rawtransaction', this.transactionHandler.bind(this));
this.bus.on('bitcoind/hashblock', this.blockHandler.bind(this));

transactionHandler = function(callback) {
  this.node.services.bitcoind.getTxInfo(callback, function(err, tx) {
     // save tx id where address = the above address saved

blockHandler = function(callback) {
  this.node.services.bitcoind.getBlockOverview(callback, function(err, blockOverview) {
    // search database for each transaction in block and check confirmations via height?
    // If it reaches 2 confirmations mark as paid and forward 99% of the bitcoin to a specified address whilst taking a 1 % fee
    // take bitcoin's fee into account aswell via raw transaction