2014-08-12 12:03:04 -07:00
|
|
|
/**
|
|
|
|
* bitcoind.js
|
|
|
|
* Copyright (c) 2014, BitPay (MIT License)
|
|
|
|
* A bitcoind node.js binding.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var net = require('net');
|
|
|
|
var EventEmitter = require('events').EventEmitter;
|
|
|
|
var bitcoindjs = require('../build/Release/bitcoindjs.node');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bitcoin
|
|
|
|
*/
|
|
|
|
|
2014-08-29 13:54:54 -07:00
|
|
|
function Bitcoin(options) {
|
2014-08-12 12:03:04 -07:00
|
|
|
var self = this;
|
|
|
|
|
2014-08-19 16:40:19 -07:00
|
|
|
if (!(this instanceof Bitcoin)) {
|
2014-08-29 13:54:54 -07:00
|
|
|
return new Bitcoin(options);
|
2014-08-12 12:03:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EventEmitter.call(this);
|
|
|
|
|
2014-08-29 13:54:54 -07:00
|
|
|
this.options = options;
|
|
|
|
|
|
|
|
bitcoindjs.start(function(err, status) {
|
|
|
|
if (err) {
|
|
|
|
self.emit('error', err);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-19 16:40:19 -07:00
|
|
|
self.emit('open', status);
|
2014-08-12 12:03:04 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Bitcoin.prototype.__proto__ = EventEmitter.prototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = exports = Bitcoin;
|
|
|
|
exports.Bitcoin = Bitcoin;
|
|
|
|
exports.native = bitcoindjs;
|