rename bitcoind to daemon

This commit is contained in:
Patrick Nagurny 2015-07-16 17:03:43 -04:00
parent 510f6e8607
commit bb36f5f044
7 changed files with 289 additions and 289 deletions

View File

@ -7,21 +7,21 @@
process.title = 'bitcoind.js'; process.title = 'bitcoind.js';
/** /**
* bitcoind * daemon
*/ */
var bitcoind = require('../index.js').bitcoind({ var daemon = require('../index.js').daemon({
directory: '~/.bitcoin' directory: process.env.BITCOINDJS_DIR || '~/.bitcoin'
}); });
bitcoind.on('error', function(err) { daemon.on('error', function(err) {
bitcoind.log('error="%s"', err.message); daemon.log('error="%s"', err.message);
}); });
bitcoind.on('ready', function(err, result) { daemon.on('ready', function(err, result) {
console.log('Ready!'); console.log('Ready!');
bitcoind.getBlock('000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254', function(err, block) { daemon.getBlock('000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254', function(err, block) {
if (err) { if (err) {
console.log(err); console.log(err);
} }
@ -30,6 +30,6 @@ bitcoind.on('ready', function(err, result) {
}); });
bitcoind.on('open', function(status) { daemon.on('open', function(status) {
bitcoind.log('status="%s"', status); daemon.log('status="%s"', status);
}); });

View File

@ -9,17 +9,17 @@
process.title = 'bitcoind.js'; process.title = 'bitcoind.js';
/** /**
* bitcoind * daemon
*/ */
var bitcoind = require('../').bitcoind({ var daemon = require('../').daemon({
directory: process.env.BITCOINDJS_DIR || '~/.bitcoin' directory: process.env.BITCOINDJS_DIR || '~/.bitcoin'
}); });
bitcoind.on('error', function(err) { daemon.on('error', function(err) {
bitcoind.log('error="%s"', err.message); daemon.log('error="%s"', err.message);
}); });
bitcoind.on('open', function(status) { daemon.on('open', function(status) {
bitcoind.log('status="%s"', status); daemon.log('status="%s"', status);
}); });

View File

@ -7,17 +7,17 @@
process.title = 'bitcoind_stripped.js'; process.title = 'bitcoind_stripped.js';
/** /**
* bitcoind * daemon
*/ */
var bitcoind = require('../index_stripped.js')({ var daemon = require('../index_stripped.js')({
directory: '~/.libbitcoind-example' directory: '~/.libbitcoind-example'
}); });
bitcoind.on('error', function(err) { daemon.on('error', function(err) {
bitcoind.log('error="%s"', err.message); daemon.log('error="%s"', err.message);
}); });
bitcoind.on('open', function(status) { daemon.on('open', function(status) {
bitcoind.log('status="%s"', status); daemon.log('status="%s"', status);
}); });

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
module.exports = {}; module.exports = {};
module.exports.bitcoind = require('./lib/bitcoind'); module.exports.daemon = require('./lib/daemon');
module.exports.Node = require('./lib/node'); module.exports.Node = require('./lib/node');
module.exports.Block = require('./lib/block'); module.exports.Block = require('./lib/block');
module.exports.Chain = require('./lib/chain'); module.exports.Chain = require('./lib/chain');

View File

@ -16,16 +16,16 @@ var tiny = require('tiny').json;
var setImmediate = global.setImmediate || process.nextTick.bind(process); var setImmediate = global.setImmediate || process.nextTick.bind(process);
/** /**
* Bitcoin * Daemon
*/ */
var bitcoin = Bitcoin; var daemon = Daemon;
function Bitcoin(options) { function Daemon(options) {
var self = this; var self = this;
if (!(this instanceof Bitcoin)) { if (!(this instanceof Daemon)) {
return new Bitcoin(options); return new Daemon(options);
} }
if (Object.keys(this.instances).length) { if (Object.keys(this.instances).length) {
@ -54,7 +54,7 @@ function Bitcoin(options) {
this.datadir = this.options.datadir; this.datadir = this.options.datadir;
this.config = this.datadir + '/bitcoin.conf'; this.config = this.datadir + '/bitcoin.conf';
this.network = Bitcoin[this.options.testnet ? 'testnet' : 'livenet']; this.network = Daemon[this.options.testnet ? 'testnet' : 'livenet'];
if (!fs.existsSync(this.datadir)) { if (!fs.existsSync(this.datadir)) {
mkdirp.sync(this.datadir); mkdirp.sync(this.datadir);
@ -104,16 +104,16 @@ function Bitcoin(options) {
}); });
} }
Bitcoin.prototype.__proto__ = EventEmitter.prototype; Daemon.prototype.__proto__ = EventEmitter.prototype;
Bitcoin.livenet = { Daemon.livenet = {
name: 'livenet', name: 'livenet',
peers: [ peers: [
// hardcoded peers // hardcoded peers
] ]
}; };
Bitcoin.testnet = { Daemon.testnet = {
name: 'testnet', name: 'testnet',
peers: [ peers: [
// hardcoded peers // hardcoded peers
@ -121,30 +121,30 @@ Bitcoin.testnet = {
}; };
// Make sure signal handlers are not overwritten // Make sure signal handlers are not overwritten
Bitcoin._signalQueue = []; Daemon._signalQueue = [];
Bitcoin._processOn = process.on; Daemon._processOn = process.on;
process.addListener = process.addListener =
process.on = function(name, listener) { process.on = function(name, listener) {
if (~['SIGINT', 'SIGHUP', 'SIGQUIT'].indexOf(name.toUpperCase())) { if (~['SIGINT', 'SIGHUP', 'SIGQUIT'].indexOf(name.toUpperCase())) {
if (!Bitcoin.global || !Bitcoin.global._started) { if (!Daemon.global || !Daemon.global._started) {
Bitcoin._signalQueue.push([name, listener]); Daemon._signalQueue.push([name, listener]);
return; return;
} }
} }
return Bitcoin._processOn.apply(this, arguments); return Daemon._processOn.apply(this, arguments);
}; };
Bitcoin.instances = {}; Daemon.instances = {};
Bitcoin.prototype.instances = Bitcoin.instances; Daemon.prototype.instances = Daemon.instances;
Bitcoin.__defineGetter__('global', function() { Daemon.__defineGetter__('global', function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Bitcoin.instances[Object.keys(Bitcoin.instances)[0]]; return Daemon.instances[Object.keys(Daemon.instances)[0]];
}); });
Bitcoin.prototype.__defineGetter__('global', function() { Daemon.prototype.__defineGetter__('global', function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Bitcoin.global; return Daemon.global;
}); });
tiny.debug = function() {}; tiny.debug = function() {};
@ -152,13 +152,13 @@ tiny.prototype.debug = function() {};
tiny.error = function() {}; tiny.error = function() {};
tiny.prototype.error = function() {}; tiny.prototype.error = function() {};
Bitcoin.db = tiny({ Daemon.db = tiny({
file: process.env.HOME + '/.bitcoindjs.db', file: process.env.HOME + '/.bitcoindjs.db',
saveIndex: false, saveIndex: false,
initialCache: false initialCache: false
}); });
Bitcoin.prototype.start = function(options, callback) { Daemon.prototype.start = function(options, callback) {
var self = this; var self = this;
if (!callback) { if (!callback) {
@ -212,8 +212,8 @@ Bitcoin.prototype.start = function(options, callback) {
}); });
// Finally set signal handlers // Finally set signal handlers
process.on = process.addListener = Bitcoin._processOn; process.on = process.addListener = Daemon._processOn;
Bitcoin._signalQueue.forEach(function(event) { Daemon._signalQueue.forEach(function(event) {
process.on(event[0], event[1]); process.on(event[0], event[1]);
}); });
@ -307,36 +307,36 @@ Bitcoin.prototype.start = function(options, callback) {
}, 1000); }, 1000);
}; };
Bitcoin.prototype.getBlock = function(blockhash, callback) { Daemon.prototype.getBlock = function(blockhash, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getBlock(blockhash, function(err, block) { return bitcoindjs.getBlock(blockhash, function(err, block) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, block); return callback(null, block);
}); });
}; };
Bitcoin.prototype.getBlockHeight = function(height, callback) { Daemon.prototype.getBlockHeight = function(height, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getBlock(+height, function(err, block) { return bitcoindjs.getBlock(+height, function(err, block) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, bitcoin.block(block)); return callback(null, daemon.block(block));
}); });
}; };
Bitcoin.prototype.isSpent = function(txid, outputIndex) { Daemon.prototype.isSpent = function(txid, outputIndex) {
return bitcoindjs.isSpent(txid, outputIndex); return bitcoindjs.isSpent(txid, outputIndex);
}; };
Bitcoin.prototype.getChainWork = function(blockHash) { Daemon.prototype.getChainWork = function(blockHash) {
return bitcoindjs.getChainWork(blockHash); return bitcoindjs.getChainWork(blockHash);
}; };
Bitcoin.prototype.getTransaction = function(txid, queryMempool, callback) { Daemon.prototype.getTransaction = function(txid, queryMempool, callback) {
return bitcoindjs.getTransaction(txid, queryMempool, callback); return bitcoindjs.getTransaction(txid, queryMempool, callback);
}; };
Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback) { Daemon.prototype.getTransactionWithBlock = function(txid, blockhash, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
var slow = true; var slow = true;
@ -377,57 +377,57 @@ Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback)
return bitcoindjs.getBlock(tx.blockhash, function(err, block) { return bitcoindjs.getBlock(tx.blockhash, function(err, block) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, bitcoin.tx(tx), bitcoin.block(block)); return callback(null, daemon.tx(tx), daemon.block(block));
}); });
}); });
}; };
Bitcoin.prototype.getMempoolOutputs = function(address) { Daemon.prototype.getMempoolOutputs = function(address) {
return bitcoindjs.getMempoolOutputs(address); return bitcoindjs.getMempoolOutputs(address);
}; };
Bitcoin.prototype.addMempoolUncheckedTransaction = function(txBuffer) { Daemon.prototype.addMempoolUncheckedTransaction = function(txBuffer) {
return bitcoindjs.addMempoolUncheckedTransaction(txBuffer); return bitcoindjs.addMempoolUncheckedTransaction(txBuffer);
}; };
Bitcoin.prototype.getInfo = function() { Daemon.prototype.getInfo = function() {
if (bitcoin.stopping) return []; if (bitcoin.stopping) return [];
return bitcoindjs.getInfo(); return bitcoindjs.getInfo();
}; };
Bitcoin.prototype.getPeerInfo = function() { Daemon.prototype.getPeerInfo = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getPeerInfo(); return bitcoindjs.getPeerInfo();
}; };
Bitcoin.prototype.getAddresses = function() { Daemon.prototype.getAddresses = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getAddresses(); return bitcoindjs.getAddresses();
}; };
Bitcoin.prototype.getProgress = function(callback) { Daemon.prototype.getProgress = function(callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getProgress(callback); return bitcoindjs.getProgress(callback);
}; };
Bitcoin.prototype.setGenerate = function(options) { Daemon.prototype.setGenerate = function(options) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.setGenerate(options || {}); return bitcoindjs.setGenerate(options || {});
}; };
Bitcoin.prototype.getGenerate = function(options) { Daemon.prototype.getGenerate = function(options) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getGenerate(options || {}); return bitcoindjs.getGenerate(options || {});
}; };
Bitcoin.prototype.getMiningInfo = function() { Daemon.prototype.getMiningInfo = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getMiningInfo(); return bitcoindjs.getMiningInfo();
}; };
Bitcoin.prototype.getAddrTransactions = function(address, callback) { Daemon.prototype.getAddrTransactions = function(address, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoin.db.get('addr-tx/' + address, function(err, records) { return daemon.db.get('addr-tx/' + address, function(err, records) {
var options = { var options = {
address: address, address: address,
blockheight: (records || []).reduce(function(out, record) { blockheight: (records || []).reduce(function(out, record) {
@ -443,15 +443,15 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
}; };
return bitcoindjs.getAddrTransactions(options, function(err, addr) { return bitcoindjs.getAddrTransactions(options, function(err, addr) {
if (err) return callback(err); if (err) return callback(err);
addr = bitcoin.addr(addr); addr = daemon.addr(addr);
if (addr.tx[0] && !addr.tx[0].vout[0]) { if (addr.tx[0] && !addr.tx[0].vout[0]) {
return bitcoin.db.set('addr-tx/' + address, [{ return daemon.db.set('addr-tx/' + address, [{
txid: null, txid: null,
blockhash: null, blockhash: null,
blockheight: null, blockheight: null,
blocktime: null blocktime: null
}], function() { }], function() {
return callback(null, bitcoin.addr({ return callback(null, daemon.addr({
address: addr.address, address: addr.address,
tx: [] tx: []
})); }));
@ -469,33 +469,33 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
blocktime: tx.blocktime blocktime: tx.blocktime
}); });
}); });
return bitcoin.db.set('addr-tx/' + address, set, function() { return daemon.db.set('addr-tx/' + address, set, function() {
return callback(null, addr); return callback(null, addr);
}); });
}); });
}); });
}; };
Bitcoin.prototype.getBestBlock = function(callback) { Daemon.prototype.getBestBlock = function(callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var hash = bitcoindjs.getBestBlock(); var hash = bitcoindjs.getBestBlock();
return bitcoindjs.getBlock(hash, callback); return bitcoindjs.getBlock(hash, callback);
}; };
Bitcoin.prototype.getChainHeight = function() { Daemon.prototype.getChainHeight = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getChainHeight(); return bitcoindjs.getChainHeight();
}; };
Bitcoin.prototype.__defineGetter__('chainHeight', function() { Daemon.prototype.__defineGetter__('chainHeight', function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return this.getChainHeight(); return this.getChainHeight();
}); });
Bitcoin.prototype.getBlockByTxid = Daemon.prototype.getBlockByTxid =
Bitcoin.prototype.getBlockByTx = function(txid, callback) { Daemon.prototype.getBlockByTx = function(txid, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoin.db.get('block-tx/' + txid, function(err, block) { return daemon.db.get('block-tx/' + txid, function(err, block) {
if (block) { if (block) {
return self.getBlock(block.hash, function(err, block) { return self.getBlock(block.hash, function(err, block) {
if (err) return callback(err); if (err) return callback(err);
@ -507,41 +507,41 @@ Bitcoin.prototype.getBlockByTx = function(txid, callback) {
} }
return bitcoindjs.getBlockByTx(txid, function(err, block, tx_) { return bitcoindjs.getBlockByTx(txid, function(err, block, tx_) {
if (err) return callback(err); if (err) return callback(err);
bitcoin.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP); daemon.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP);
return callback(null, bitcoin.block(block), bitcoin.tx(tx_)); return callback(null, daemon.block(block), daemon.tx(tx_));
}); });
}); });
}; };
Bitcoin.prototype.getBlocksByDate = Daemon.prototype.getBlocksByDate =
Bitcoin.prototype.getBlocksByTime = function(options, callback) { Daemon.prototype.getBlocksByTime = function(options, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getBlocksByTime(options, function(err, blocks) { return bitcoindjs.getBlocksByTime(options, function(err, blocks) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, blocks.map(function(block) { return callback(null, blocks.map(function(block) {
return bitcoin.block(block); return daemon.block(block);
})); }));
}); });
}; };
Bitcoin.prototype.getFromTx = function(txid, callback) { Daemon.prototype.getFromTx = function(txid, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getFromTx(txid, function(err, txs) { return bitcoindjs.getFromTx(txid, function(err, txs) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, txs.map(function(tx) { return callback(null, txs.map(function(tx) {
return bitcoin.tx(tx) return daemon.tx(tx)
})); }));
}); });
}; };
Bitcoin.prototype.getLastFileIndex = function() { Daemon.prototype.getLastFileIndex = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getLastFileIndex(); return bitcoindjs.getLastFileIndex();
}; };
Bitcoin.prototype.log = Daemon.prototype.log =
Bitcoin.prototype.info = function() { Daemon.prototype.info = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (this.options.silent) return; if (this.options.silent) return;
if (typeof arguments[0] !== 'string') { if (typeof arguments[0] !== 'string') {
var out = util.inspect(arguments[0], null, 20, true); var out = util.inspect(arguments[0], null, 20, true);
@ -551,8 +551,8 @@ Bitcoin.prototype.info = function() {
return process.stdout.write('bitcoind.js: ' + out + '\n'); return process.stdout.write('bitcoind.js: ' + out + '\n');
}; };
Bitcoin.prototype.error = function() { Daemon.prototype.error = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (this.options.silent) return; if (this.options.silent) return;
if (typeof arguments[0] !== 'string') { if (typeof arguments[0] !== 'string') {
var out = util.inspect(arguments[0], null, 20, true); var out = util.inspect(arguments[0], null, 20, true);
@ -562,9 +562,9 @@ Bitcoin.prototype.error = function() {
return process.stderr.write('bitcoind.js: ' + out + '\n'); return process.stderr.write('bitcoind.js: ' + out + '\n');
}; };
Bitcoin.prototype.stop = Daemon.prototype.stop =
Bitcoin.prototype.close = function(callback) { Daemon.prototype.close = function(callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
return bitcoindjs.stop(function(err, status) { return bitcoindjs.stop(function(err, status) {
if (err) { if (err) {
@ -577,19 +577,19 @@ Bitcoin.prototype.close = function(callback) {
}); });
}; };
Bitcoin.prototype.__defineGetter__('stopping', function() { Daemon.prototype.__defineGetter__('stopping', function() {
return bitcoindjs.stopping() || bitcoindjs.stopped(); return bitcoindjs.stopping() || bitcoindjs.stopped();
}); });
Bitcoin.prototype.__defineGetter__('stopped', function() { Daemon.prototype.__defineGetter__('stopped', function() {
return bitcoindjs.stopped(); return bitcoindjs.stopped();
}); });
Bitcoin.__defineGetter__('stopping', function() { Daemon.__defineGetter__('stopping', function() {
return bitcoindjs.stopping() || bitcoindjs.stopped(); return bitcoindjs.stopping() || bitcoindjs.stopped();
}); });
Bitcoin.__defineGetter__('stopped', function() { Daemon.__defineGetter__('stopped', function() {
return bitcoindjs.stopped(); return bitcoindjs.stopped();
}); });
@ -610,7 +610,7 @@ function Block(data) {
return data; return data;
} }
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
@ -621,7 +621,7 @@ function Block(data) {
}); });
this.tx = this.tx.map(function(tx) { this.tx = this.tx.map(function(tx) {
return bitcoin.tx(tx); return daemon.tx(tx);
}); });
if (!this.hex) { if (!this.hex) {
@ -638,17 +638,17 @@ Object.defineProperty(Block.prototype, '_blockFlag', {
}); });
Block.isBlock = function(block) { Block.isBlock = function(block) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return block._blockFlag === Block.prototype._blockFlag; return block._blockFlag === Block.prototype._blockFlag;
}; };
Block.fromHex = function(hex) { Block.fromHex = function(hex) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoin.block(bitcoindjs.blockFromHex(hex)); return daemon.block(bitcoindjs.blockFromHex(hex));
}; };
Block.prototype.getHash = function(enc) { Block.prototype.getHash = function(enc) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getBlockHex(this); var data = bitcoindjs.getBlockHex(this);
if (!this.hash || this.hash !== data.hash) { if (!this.hash || this.hash !== data.hash) {
this.hash = data.hash; this.hash = data.hash;
@ -660,12 +660,12 @@ Block.prototype.getHash = function(enc) {
}; };
Block.prototype.verify = function() { Block.prototype.verify = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return this.verified = this.verified || bitcoindjs.verifyBlock(this); return this.verified = this.verified || bitcoindjs.verifyBlock(this);
}; };
Block.prototype.toHex = function() { Block.prototype.toHex = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var hex = Block.toHex(this); var hex = Block.toHex(this);
if (!this.hex || this.hex !== hex) { if (!this.hex || this.hex !== hex) {
this.hex = hex; this.hex = hex;
@ -674,18 +674,18 @@ Block.prototype.toHex = function() {
}; };
Block.toHex = function(block) { Block.toHex = function(block) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getBlockHex(block); var data = bitcoindjs.getBlockHex(block);
return data.hex; return data.hex;
}; };
Block.prototype.toBinary = function() { Block.prototype.toBinary = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Block.toBinary(this); return Block.toBinary(this);
}; };
Block.toBinary = function(block) { Block.toBinary = function(block) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getBlockHex(block); var data = bitcoindjs.getBlockHex(block);
return new Buffer(data.hex, 'hex'); return new Buffer(data.hex, 'hex');
}; };
@ -707,7 +707,7 @@ function Transaction(data) {
return data; return data;
} }
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
@ -732,34 +732,34 @@ Object.defineProperty(Transaction.prototype, '_txFlag', {
Transaction.isTransaction = Transaction.isTransaction =
Transaction.isTx = function(tx) { Transaction.isTx = function(tx) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return tx._txFlag === Transaction.prototype._txFlag; return tx._txFlag === Transaction.prototype._txFlag;
}; };
Transaction.fromHex = function(hex) { Transaction.fromHex = function(hex) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoin.tx(bitcoindjs.txFromHex(hex)); return daemon.tx(bitcoindjs.txFromHex(hex));
}; };
Transaction.prototype.verify = function() { Transaction.prototype.verify = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return this.verified = this.verified || bitcoindjs.verifyTransaction(this); return this.verified = this.verified || bitcoindjs.verifyTransaction(this);
}; };
Transaction.prototype.sign = Transaction.prototype.sign =
Transaction.prototype.fill = function(options) { Transaction.prototype.fill = function(options) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Transaction.fill(this, options); return Transaction.fill(this, options);
}; };
Transaction.sign = Transaction.sign =
Transaction.fill = function(tx, options) { Transaction.fill = function(tx, options) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var isTx = bitcoin.tx.isTx(tx) var isTx = daemon.tx.isTx(tx)
, newTx; , newTx;
if (!isTx) { if (!isTx) {
tx = bitcoin.tx(tx); tx = daemon.tx(tx);
} }
try { try {
@ -776,7 +776,7 @@ Transaction.fill = function(tx, options) {
}; };
Transaction.prototype.getHash = function(enc) { Transaction.prototype.getHash = function(enc) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getTxHex(this); var data = bitcoindjs.getTxHex(this);
if (!this.txid || this.txid !== data.hash) { if (!this.txid || this.txid !== data.hash) {
this.txid = data.hash; this.txid = data.hash;
@ -788,12 +788,12 @@ Transaction.prototype.getHash = function(enc) {
}; };
Transaction.prototype.isCoinbase = function() { Transaction.prototype.isCoinbase = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return this.vin.length === 1 && this.vin[0].coinbase; return this.vin.length === 1 && this.vin[0].coinbase;
}; };
Transaction.prototype.toHex = function() { Transaction.prototype.toHex = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var hex = Transaction.toHex(this); var hex = Transaction.toHex(this);
if (!this.hex || hex !== this.hex) { if (!this.hex || hex !== this.hex) {
this.hex = hex; this.hex = hex;
@ -802,24 +802,24 @@ Transaction.prototype.toHex = function() {
}; };
Transaction.toHex = function(tx) { Transaction.toHex = function(tx) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getTxHex(tx); var data = bitcoindjs.getTxHex(tx);
return data.hex; return data.hex;
}; };
Transaction.prototype.toBinary = function() { Transaction.prototype.toBinary = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Transaction.toBinary(this); return Transaction.toBinary(this);
}; };
Transaction.toBinary = function(tx) { Transaction.toBinary = function(tx) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getTxHex(tx); var data = bitcoindjs.getTxHex(tx);
return new Buffer(data.hex, 'hex'); return new Buffer(data.hex, 'hex');
}; };
Transaction.broadcast = function(tx, options, callback) { Transaction.broadcast = function(tx, options, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (typeof tx === 'string') { if (typeof tx === 'string') {
tx = { hex: tx }; tx = { hex: tx };
} }
@ -840,25 +840,25 @@ Transaction.broadcast = function(tx, options, callback) {
callback = utils.NOOP; callback = utils.NOOP;
} }
if (!bitcoin.isTx(tx)) { if (!daemon.isTx(tx)) {
tx = bitcoin.tx(tx); tx = daemon.tx(tx);
} }
return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash, tx) { return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash, tx) {
if (err) { if (err) {
if (callback === utils.NOOP) { if (callback === utils.NOOP) {
bitcoin.global.emit('error', err); daemon.global.emit('error', err);
} }
return callback(err); return callback(err);
} }
tx = bitcoin.tx(tx); tx = daemon.tx(tx);
bitcoin.global.emit('broadcast', tx); daemon.global.emit('broadcast', tx);
return callback(null, hash, tx); return callback(null, hash, tx);
}); });
}; };
Transaction.prototype.broadcast = function(options, callback) { Transaction.prototype.broadcast = function(options, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (!callback) { if (!callback) {
callback = options; callback = options;
options = null; options = null;
@ -879,7 +879,7 @@ function Addresses(data) {
return data; return data;
} }
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
@ -900,7 +900,7 @@ Object.defineProperty(Transaction.prototype, '_addrFlag', {
Addresses.isAddresses = Addresses.isAddresses =
Addresses.isAddr = function(addr) { Addresses.isAddr = function(addr) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return addr._txFlag === Addresses.prototype._addrFlag; return addr._txFlag === Addresses.prototype._addrFlag;
}; };
@ -911,7 +911,7 @@ Addresses.isAddr = function(addr) {
var utils = {}; var utils = {};
utils.forEach = function(obj, iter, done) { utils.forEach = function(obj, iter, done) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var pending = obj.length; var pending = obj.length;
if (!pending) return done(); if (!pending) return done();
var next = function() { var next = function() {
@ -928,11 +928,11 @@ utils.NOOP = function() {};
* Expose * Expose
*/ */
module.exports = exports = bitcoin; module.exports = exports = daemon;
exports.Bitcoin = bitcoin; exports.Daemon = daemon;
exports.bitcoin = bitcoin; exports.daemon = daemon;
exports.bitcoind = bitcoin; exports.bitcoind = daemon;
exports.native = bitcoindjs; exports.native = bitcoindjs;
exports.bitcoindjs = bitcoindjs; exports.bitcoindjs = bitcoindjs;

View File

@ -16,16 +16,16 @@ var tiny = require('tiny').json;
var setImmediate = global.setImmediate || process.nextTick.bind(process); var setImmediate = global.setImmediate || process.nextTick.bind(process);
/** /**
* Bitcoin * Daemon
*/ */
var bitcoin = Bitcoin; var daemon = Daemon;
function Bitcoin(options) { function Daemon(options) {
var self = this; var self = this;
if (!(this instanceof Bitcoin)) { if (!(this instanceof Daemon)) {
return new Bitcoin(options); return new Daemon(options);
} }
if (Object.keys(this.instances).length) { if (Object.keys(this.instances).length) {
@ -54,7 +54,7 @@ function Bitcoin(options) {
this.datadir = this.options.datadir; this.datadir = this.options.datadir;
this.config = this.datadir + '/bitcoin.conf'; this.config = this.datadir + '/bitcoin.conf';
this.network = Bitcoin[this.options.testnet ? 'testnet' : 'livenet']; this.network = Daemon[this.options.testnet ? 'testnet' : 'livenet'];
if (!fs.existsSync(this.datadir)) { if (!fs.existsSync(this.datadir)) {
mkdirp.sync(this.datadir); mkdirp.sync(this.datadir);
@ -104,16 +104,16 @@ function Bitcoin(options) {
}); });
} }
Bitcoin.prototype.__proto__ = EventEmitter.prototype; Daemon.prototype.__proto__ = EventEmitter.prototype;
Bitcoin.livenet = { Daemon.livenet = {
name: 'livenet', name: 'livenet',
peers: [ peers: [
// hardcoded peers // hardcoded peers
] ]
}; };
Bitcoin.testnet = { Daemon.testnet = {
name: 'testnet', name: 'testnet',
peers: [ peers: [
// hardcoded peers // hardcoded peers
@ -121,30 +121,30 @@ Bitcoin.testnet = {
}; };
// Make sure signal handlers are not overwritten // Make sure signal handlers are not overwritten
Bitcoin._signalQueue = []; Daemon._signalQueue = [];
Bitcoin._processOn = process.on; Daemon._processOn = process.on;
process.addListener = process.addListener =
process.on = function(name, listener) { process.on = function(name, listener) {
if (~['SIGINT', 'SIGHUP', 'SIGQUIT'].indexOf(name.toUpperCase())) { if (~['SIGINT', 'SIGHUP', 'SIGQUIT'].indexOf(name.toUpperCase())) {
if (!Bitcoin.global || !Bitcoin.global._started) { if (!Daemon.global || !Daemon.global._started) {
Bitcoin._signalQueue.push([name, listener]); Daemon._signalQueue.push([name, listener]);
return; return;
} }
} }
return Bitcoin._processOn.apply(this, arguments); return Daemon._processOn.apply(this, arguments);
}; };
Bitcoin.instances = {}; Daemon.instances = {};
Bitcoin.prototype.instances = Bitcoin.instances; Daemon.prototype.instances = Daemon.instances;
Bitcoin.__defineGetter__('global', function() { Daemon.__defineGetter__('global', function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Bitcoin.instances[Object.keys(Bitcoin.instances)[0]]; return Daemon.instances[Object.keys(Daemon.instances)[0]];
}); });
Bitcoin.prototype.__defineGetter__('global', function() { Daemon.prototype.__defineGetter__('global', function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Bitcoin.global; return Daemon.global;
}); });
tiny.debug = function() {}; tiny.debug = function() {};
@ -152,13 +152,13 @@ tiny.prototype.debug = function() {};
tiny.error = function() {}; tiny.error = function() {};
tiny.prototype.error = function() {}; tiny.prototype.error = function() {};
Bitcoin.db = tiny({ Daemon.db = tiny({
file: process.env.HOME + '/.bitcoindjs.db', file: process.env.HOME + '/.bitcoindjs.db',
saveIndex: false, saveIndex: false,
initialCache: false initialCache: false
}); });
Bitcoin.prototype.start = function(options, callback) { Daemon.prototype.start = function(options, callback) {
var self = this; var self = this;
if (!callback) { if (!callback) {
@ -212,8 +212,8 @@ Bitcoin.prototype.start = function(options, callback) {
}); });
// Finally set signal handlers // Finally set signal handlers
process.on = process.addListener = Bitcoin._processOn; process.on = process.addListener = Daemon._processOn;
Bitcoin._signalQueue.forEach(function(event) { Daemon._signalQueue.forEach(function(event) {
process.on(event[0], event[1]); process.on(event[0], event[1]);
}); });
@ -303,25 +303,25 @@ Bitcoin.prototype.start = function(options, callback) {
}, 1000); }, 1000);
}; };
Bitcoin.prototype.getBlock = function(blockhash, callback) { Daemon.prototype.getBlock = function(blockhash, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getBlock(blockhash, function(err, block) { return bitcoindjs.getBlock(blockhash, function(err, block) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, bitcoin.block(block)); return callback(null, daemon.block(block));
}); });
}; };
Bitcoin.prototype.getBlockHeight = function(height, callback) { Daemon.prototype.getBlockHeight = function(height, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getBlock(+height, function(err, block) { return bitcoindjs.getBlock(+height, function(err, block) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, bitcoin.block(block)); return callback(null, daemon.block(block));
}); });
}; };
Bitcoin.prototype.getTransaction = Daemon.prototype.getTransaction =
Bitcoin.prototype.getTx = function(txid, blockhash, callback) { Daemon.prototype.getTx = function(txid, blockhash, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (typeof txid === 'object' && txid) { if (typeof txid === 'object' && txid) {
var options = txid; var options = txid;
callback = blockhash; callback = blockhash;
@ -347,12 +347,12 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) {
return bitcoindjs.getTransaction(txid, blockhash, function(err, tx) { return bitcoindjs.getTransaction(txid, blockhash, function(err, tx) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, bitcoin.tx(tx)); return callback(null, daemon.tx(tx));
}); });
}; };
Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback) { Daemon.prototype.getTransactionWithBlock = function(txid, blockhash, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
var slow = true; var slow = true;
@ -393,49 +393,49 @@ Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback)
return bitcoindjs.getBlock(tx.blockhash, function(err, block) { return bitcoindjs.getBlock(tx.blockhash, function(err, block) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, bitcoin.tx(tx), bitcoin.block(block)); return callback(null, daemon.tx(tx), daemon.block(block));
}); });
}); });
}; };
Bitcoin.prototype.getInfo = function() { Daemon.prototype.getInfo = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getInfo(); return bitcoindjs.getInfo();
}; };
Bitcoin.prototype.getPeerInfo = function() { Daemon.prototype.getPeerInfo = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getPeerInfo(); return bitcoindjs.getPeerInfo();
}; };
Bitcoin.prototype.getAddresses = function() { Daemon.prototype.getAddresses = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getAddresses(); return bitcoindjs.getAddresses();
}; };
Bitcoin.prototype.getProgress = function(callback) { Daemon.prototype.getProgress = function(callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getProgress(callback); return bitcoindjs.getProgress(callback);
}; };
Bitcoin.prototype.setGenerate = function(options) { Daemon.prototype.setGenerate = function(options) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.setGenerate(options || {}); return bitcoindjs.setGenerate(options || {});
}; };
Bitcoin.prototype.getGenerate = function(options) { Daemon.prototype.getGenerate = function(options) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getGenerate(options || {}); return bitcoindjs.getGenerate(options || {});
}; };
Bitcoin.prototype.getMiningInfo = function() { Daemon.prototype.getMiningInfo = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getMiningInfo(); return bitcoindjs.getMiningInfo();
}; };
Bitcoin.prototype.getAddrTransactions = function(address, callback) { Daemon.prototype.getAddrTransactions = function(address, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoin.db.get('addr-tx/' + address, function(err, records) { return daemon.db.get('addr-tx/' + address, function(err, records) {
var options = { var options = {
address: address, address: address,
blockheight: (records || []).reduce(function(out, record) { blockheight: (records || []).reduce(function(out, record) {
@ -451,15 +451,15 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
}; };
return bitcoindjs.getAddrTransactions(options, function(err, addr) { return bitcoindjs.getAddrTransactions(options, function(err, addr) {
if (err) return callback(err); if (err) return callback(err);
addr = bitcoin.addr(addr); addr = daemon.addr(addr);
if (addr.tx[0] && !addr.tx[0].vout[0]) { if (addr.tx[0] && !addr.tx[0].vout[0]) {
return bitcoin.db.set('addr-tx/' + address, [{ return daemon.db.set('addr-tx/' + address, [{
txid: null, txid: null,
blockhash: null, blockhash: null,
blockheight: null, blockheight: null,
blocktime: null blocktime: null
}], function() { }], function() {
return callback(null, bitcoin.addr({ return callback(null, daemon.addr({
address: addr.address, address: addr.address,
tx: [] tx: []
})); }));
@ -477,33 +477,33 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
blocktime: tx.blocktime blocktime: tx.blocktime
}); });
}); });
return bitcoin.db.set('addr-tx/' + address, set, function() { return daemon.db.set('addr-tx/' + address, set, function() {
return callback(null, addr); return callback(null, addr);
}); });
}); });
}); });
}; };
Bitcoin.prototype.getBestBlock = function(callback) { Daemon.prototype.getBestBlock = function(callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var hash = bitcoindjs.getBestBlock(); var hash = bitcoindjs.getBestBlock();
return bitcoindjs.getBlock(hash, callback); return bitcoindjs.getBlock(hash, callback);
}; };
Bitcoin.prototype.getChainHeight = function() { Daemon.prototype.getChainHeight = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getChainHeight(); return bitcoindjs.getChainHeight();
}; };
Bitcoin.prototype.__defineGetter__('chainHeight', function() { Daemon.prototype.__defineGetter__('chainHeight', function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return this.getChainHeight(); return this.getChainHeight();
}); });
Bitcoin.prototype.getBlockByTxid = Daemon.prototype.getBlockByTxid =
Bitcoin.prototype.getBlockByTx = function(txid, callback) { Daemon.prototype.getBlockByTx = function(txid, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoin.db.get('block-tx/' + txid, function(err, block) { return daemon.db.get('block-tx/' + txid, function(err, block) {
if (block) { if (block) {
return self.getBlock(block.hash, function(err, block) { return self.getBlock(block.hash, function(err, block) {
if (err) return callback(err); if (err) return callback(err);
@ -515,41 +515,41 @@ Bitcoin.prototype.getBlockByTx = function(txid, callback) {
} }
return bitcoindjs.getBlockByTx(txid, function(err, block, tx_) { return bitcoindjs.getBlockByTx(txid, function(err, block, tx_) {
if (err) return callback(err); if (err) return callback(err);
bitcoin.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP); daemon.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP);
return callback(null, bitcoin.block(block), bitcoin.tx(tx_)); return callback(null, daemon.block(block), daemon.tx(tx_));
}); });
}); });
}; };
Bitcoin.prototype.getBlocksByDate = Daemon.prototype.getBlocksByDate =
Bitcoin.prototype.getBlocksByTime = function(options, callback) { Daemon.prototype.getBlocksByTime = function(options, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getBlocksByTime(options, function(err, blocks) { return bitcoindjs.getBlocksByTime(options, function(err, blocks) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, blocks.map(function(block) { return callback(null, blocks.map(function(block) {
return bitcoin.block(block) return daemon.block(block)
})); }));
}); });
}; };
Bitcoin.prototype.getFromTx = function(txid, callback) { Daemon.prototype.getFromTx = function(txid, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getFromTx(txid, function(err, txs) { return bitcoindjs.getFromTx(txid, function(err, txs) {
if (err) return callback(err); if (err) return callback(err);
return callback(null, txs.map(function(tx) { return callback(null, txs.map(function(tx) {
return bitcoin.tx(tx) return daemon.tx(tx)
})); }));
}); });
}; };
Bitcoin.prototype.getLastFileIndex = function() { Daemon.prototype.getLastFileIndex = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoindjs.getLastFileIndex(); return bitcoindjs.getLastFileIndex();
}; };
Bitcoin.prototype.log = Daemon.prototype.log =
Bitcoin.prototype.info = function() { Daemon.prototype.info = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (this.options.silent) return; if (this.options.silent) return;
if (typeof arguments[0] !== 'string') { if (typeof arguments[0] !== 'string') {
var out = util.inspect(arguments[0], null, 20, true); var out = util.inspect(arguments[0], null, 20, true);
@ -559,8 +559,8 @@ Bitcoin.prototype.info = function() {
return process.stdout.write('bitcoind.js: ' + out + '\n'); return process.stdout.write('bitcoind.js: ' + out + '\n');
}; };
Bitcoin.prototype.error = function() { Daemon.prototype.error = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (this.options.silent) return; if (this.options.silent) return;
if (typeof arguments[0] !== 'string') { if (typeof arguments[0] !== 'string') {
var out = util.inspect(arguments[0], null, 20, true); var out = util.inspect(arguments[0], null, 20, true);
@ -570,9 +570,9 @@ Bitcoin.prototype.error = function() {
return process.stderr.write('bitcoind.js: ' + out + '\n'); return process.stderr.write('bitcoind.js: ' + out + '\n');
}; };
Bitcoin.prototype.stop = Daemon.prototype.stop =
Bitcoin.prototype.close = function(callback) { Daemon.prototype.close = function(callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
return bitcoindjs.stop(function(err, status) { return bitcoindjs.stop(function(err, status) {
if (err) { if (err) {
@ -585,19 +585,19 @@ Bitcoin.prototype.close = function(callback) {
}); });
}; };
Bitcoin.prototype.__defineGetter__('stopping', function() { Daemon.prototype.__defineGetter__('stopping', function() {
return bitcoindjs.stopping() || bitcoindjs.stopped(); return bitcoindjs.stopping() || bitcoindjs.stopped();
}); });
Bitcoin.prototype.__defineGetter__('stopped', function() { Daemon.prototype.__defineGetter__('stopped', function() {
return bitcoindjs.stopped(); return bitcoindjs.stopped();
}); });
Bitcoin.__defineGetter__('stopping', function() { Daemon.__defineGetter__('stopping', function() {
return bitcoindjs.stopping() || bitcoindjs.stopped(); return bitcoindjs.stopping() || bitcoindjs.stopped();
}); });
Bitcoin.__defineGetter__('stopped', function() { Daemon.__defineGetter__('stopped', function() {
return bitcoindjs.stopped(); return bitcoindjs.stopped();
}); });
@ -618,7 +618,7 @@ function Block(data) {
return data; return data;
} }
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
@ -629,7 +629,7 @@ function Block(data) {
}); });
this.tx = this.tx.map(function(tx) { this.tx = this.tx.map(function(tx) {
return bitcoin.tx(tx); return daemon.tx(tx);
}); });
if (!this.hex) { if (!this.hex) {
@ -646,17 +646,17 @@ Object.defineProperty(Block.prototype, '_blockFlag', {
}); });
Block.isBlock = function(block) { Block.isBlock = function(block) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return block._blockFlag === Block.prototype._blockFlag; return block._blockFlag === Block.prototype._blockFlag;
}; };
Block.fromHex = function(hex) { Block.fromHex = function(hex) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoin.block(bitcoindjs.blockFromHex(hex)); return daemon.block(bitcoindjs.blockFromHex(hex));
}; };
Block.prototype.getHash = function(enc) { Block.prototype.getHash = function(enc) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getBlockHex(this); var data = bitcoindjs.getBlockHex(this);
if (!this.hash || this.hash !== data.hash) { if (!this.hash || this.hash !== data.hash) {
this.hash = data.hash; this.hash = data.hash;
@ -668,12 +668,12 @@ Block.prototype.getHash = function(enc) {
}; };
Block.prototype.verify = function() { Block.prototype.verify = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return this.verified = this.verified || bitcoindjs.verifyBlock(this); return this.verified = this.verified || bitcoindjs.verifyBlock(this);
}; };
Block.prototype.toHex = function() { Block.prototype.toHex = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var hex = Block.toHex(this); var hex = Block.toHex(this);
if (!this.hex || this.hex !== hex) { if (!this.hex || this.hex !== hex) {
this.hex = hex; this.hex = hex;
@ -682,18 +682,18 @@ Block.prototype.toHex = function() {
}; };
Block.toHex = function(block) { Block.toHex = function(block) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getBlockHex(block); var data = bitcoindjs.getBlockHex(block);
return data.hex; return data.hex;
}; };
Block.prototype.toBinary = function() { Block.prototype.toBinary = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Block.toBinary(this); return Block.toBinary(this);
}; };
Block.toBinary = function(block) { Block.toBinary = function(block) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getBlockHex(block); var data = bitcoindjs.getBlockHex(block);
return new Buffer(data.hex, 'hex'); return new Buffer(data.hex, 'hex');
}; };
@ -715,7 +715,7 @@ function Transaction(data) {
return data; return data;
} }
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
@ -740,34 +740,34 @@ Object.defineProperty(Transaction.prototype, '_txFlag', {
Transaction.isTransaction = Transaction.isTransaction =
Transaction.isTx = function(tx) { Transaction.isTx = function(tx) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return tx._txFlag === Transaction.prototype._txFlag; return tx._txFlag === Transaction.prototype._txFlag;
}; };
Transaction.fromHex = function(hex) { Transaction.fromHex = function(hex) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return bitcoin.tx(bitcoindjs.txFromHex(hex)); return daemon.tx(bitcoindjs.txFromHex(hex));
}; };
Transaction.prototype.verify = function() { Transaction.prototype.verify = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return this.verified = this.verified || bitcoindjs.verifyTransaction(this); return this.verified = this.verified || bitcoindjs.verifyTransaction(this);
}; };
Transaction.prototype.sign = Transaction.prototype.sign =
Transaction.prototype.fill = function(options) { Transaction.prototype.fill = function(options) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Transaction.fill(this, options); return Transaction.fill(this, options);
}; };
Transaction.sign = Transaction.sign =
Transaction.fill = function(tx, options) { Transaction.fill = function(tx, options) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var isTx = bitcoin.tx.isTx(tx) var isTx = daemon.tx.isTx(tx)
, newTx; , newTx;
if (!isTx) { if (!isTx) {
tx = bitcoin.tx(tx); tx = daemon.tx(tx);
} }
try { try {
@ -784,7 +784,7 @@ Transaction.fill = function(tx, options) {
}; };
Transaction.prototype.getHash = function(enc) { Transaction.prototype.getHash = function(enc) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getTxHex(this); var data = bitcoindjs.getTxHex(this);
if (!this.txid || this.txid !== data.hash) { if (!this.txid || this.txid !== data.hash) {
this.txid = data.hash; this.txid = data.hash;
@ -796,12 +796,12 @@ Transaction.prototype.getHash = function(enc) {
}; };
Transaction.prototype.isCoinbase = function() { Transaction.prototype.isCoinbase = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return this.vin.length === 1 && this.vin[0].coinbase; return this.vin.length === 1 && this.vin[0].coinbase;
}; };
Transaction.prototype.toHex = function() { Transaction.prototype.toHex = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var hex = Transaction.toHex(this); var hex = Transaction.toHex(this);
if (!this.hex || hex !== this.hex) { if (!this.hex || hex !== this.hex) {
this.hex = hex; this.hex = hex;
@ -810,24 +810,24 @@ Transaction.prototype.toHex = function() {
}; };
Transaction.toHex = function(tx) { Transaction.toHex = function(tx) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getTxHex(tx); var data = bitcoindjs.getTxHex(tx);
return data.hex; return data.hex;
}; };
Transaction.prototype.toBinary = function() { Transaction.prototype.toBinary = function() {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return Transaction.toBinary(this); return Transaction.toBinary(this);
}; };
Transaction.toBinary = function(tx) { Transaction.toBinary = function(tx) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var data = bitcoindjs.getTxHex(tx); var data = bitcoindjs.getTxHex(tx);
return new Buffer(data.hex, 'hex'); return new Buffer(data.hex, 'hex');
}; };
Transaction.broadcast = function(tx, options, callback) { Transaction.broadcast = function(tx, options, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (typeof tx === 'string') { if (typeof tx === 'string') {
tx = { hex: tx }; tx = { hex: tx };
} }
@ -848,25 +848,25 @@ Transaction.broadcast = function(tx, options, callback) {
callback = utils.NOOP; callback = utils.NOOP;
} }
if (!bitcoin.isTx(tx)) { if (!daemon.isTx(tx)) {
tx = bitcoin.tx(tx); tx = daemon.tx(tx);
} }
return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash, tx) { return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash, tx) {
if (err) { if (err) {
if (callback === utils.NOOP) { if (callback === utils.NOOP) {
bitcoin.global.emit('error', err); daemon.global.emit('error', err);
} }
return callback(err); return callback(err);
} }
tx = bitcoin.tx(tx); tx = daemon.tx(tx);
bitcoin.global.emit('broadcast', tx); daemon.global.emit('broadcast', tx);
return callback(null, hash, tx); return callback(null, hash, tx);
}); });
}; };
Transaction.prototype.broadcast = function(options, callback) { Transaction.prototype.broadcast = function(options, callback) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
if (!callback) { if (!callback) {
callback = options; callback = options;
options = null; options = null;
@ -887,7 +887,7 @@ function Addresses(data) {
return data; return data;
} }
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var self = this; var self = this;
@ -908,7 +908,7 @@ Object.defineProperty(Transaction.prototype, '_addrFlag', {
Addresses.isAddresses = Addresses.isAddresses =
Addresses.isAddr = function(addr) { Addresses.isAddr = function(addr) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
return addr._txFlag === Addresses.prototype._addrFlag; return addr._txFlag === Addresses.prototype._addrFlag;
}; };
@ -919,7 +919,7 @@ Addresses.isAddr = function(addr) {
var utils = {}; var utils = {};
utils.forEach = function(obj, iter, done) { utils.forEach = function(obj, iter, done) {
if (bitcoin.stopping) return []; if (daemon.stopping) return [];
var pending = obj.length; var pending = obj.length;
if (!pending) return done(); if (!pending) return done();
var next = function() { var next = function() {
@ -936,11 +936,11 @@ utils.NOOP = function() {};
* Expose * Expose
*/ */
module.exports = exports = bitcoin; module.exports = exports = daemon;
exports.Bitcoin = bitcoin; exports.Daemon = daemon;
exports.bitcoin = bitcoin; exports.daemon = daemon;
exports.bitcoind = bitcoin; exports.bitcoind = daemon;
exports.native = bitcoindjs; exports.native = bitcoindjs;
exports.bitcoindjs = bitcoindjs; exports.bitcoindjs = bitcoindjs;

View File

@ -13,7 +13,7 @@ var bitcore = require('bitcore');
var Networks = bitcore.Networks; var Networks = bitcore.Networks;
var _ = bitcore.deps._; var _ = bitcore.deps._;
var genesis = require('./genesis.json'); var genesis = require('./genesis.json');
var bitcoind = require('./bitcoind'); var daemon = require('./daemon');
function Node(config) { function Node(config) {
BaseNode.call(this, config); BaseNode.call(this, config);
@ -56,7 +56,7 @@ Node.prototype._loadBitcoind = function(config) {
} }
// start the bitcoind daemon // start the bitcoind daemon
this.bitcoind = bitcoind(bitcoindConfig); this.bitcoind = daemon(bitcoindConfig);
}; };