I need to watch for new transaction and blocks using services


(Shahid Shaikh) #1

Hey guys,

New to bitcore but very eager to learn.

I have downloaded the blockchain using testnet env and I wanna create a service which can listen for new transaction and blocks.

New to it to any pointer would help. From the docs, I found blockHandler() to the function to look for the changes.

Here is my code.

var inherits = require('util').inherits;
var EventEmitter = require('events').EventEmitter;

function MyService(options) {
  EventEmitter.call(this);
  this.node = options.node;
  this.log = this.node.log;
  this.log.info("I am called");
}
inherits(MyService, EventEmitter);

MyService.dependencies = ['bitcoind'];

MyService.prototype.start = function(callback) {
  this.log.info("***** Starting");
  setImmediate(callback);
};

MyService.prototype.stop = function(callback) {
  setImmediate(callback);
};

MyService.prototype.getAPIMethods = function() {
  return [];
};

MyService.prototype.getPublishEvents = function() {
  return [];
};

MyService.prototype.blockHandler = function(block, add, callback) {
  this.log.info('asdasdasdasdasdasd') 
  this.log.info("Block = ",block);
  this.log.info("address = ",add);
   setImmediate(callback);
}

module.exports = MyService;

Any help would be appreciated.