rename bitcoind to daemon
This commit is contained in:
parent
510f6e8607
commit
bb36f5f044
|
@ -7,21 +7,21 @@
|
|||
process.title = 'bitcoind.js';
|
||||
|
||||
/**
|
||||
* bitcoind
|
||||
* daemon
|
||||
*/
|
||||
|
||||
var bitcoind = require('../index.js').bitcoind({
|
||||
directory: '~/.bitcoin'
|
||||
var daemon = require('../index.js').daemon({
|
||||
directory: process.env.BITCOINDJS_DIR || '~/.bitcoin'
|
||||
});
|
||||
|
||||
bitcoind.on('error', function(err) {
|
||||
bitcoind.log('error="%s"', err.message);
|
||||
daemon.on('error', function(err) {
|
||||
daemon.log('error="%s"', err.message);
|
||||
});
|
||||
|
||||
bitcoind.on('ready', function(err, result) {
|
||||
daemon.on('ready', function(err, result) {
|
||||
console.log('Ready!');
|
||||
|
||||
bitcoind.getBlock('000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254', function(err, block) {
|
||||
daemon.getBlock('000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254', function(err, block) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ bitcoind.on('ready', function(err, result) {
|
|||
|
||||
});
|
||||
|
||||
bitcoind.on('open', function(status) {
|
||||
bitcoind.log('status="%s"', status);
|
||||
daemon.on('open', function(status) {
|
||||
daemon.log('status="%s"', status);
|
||||
});
|
||||
|
|
|
@ -9,17 +9,17 @@
|
|||
process.title = 'bitcoind.js';
|
||||
|
||||
/**
|
||||
* bitcoind
|
||||
* daemon
|
||||
*/
|
||||
|
||||
var bitcoind = require('../').bitcoind({
|
||||
var daemon = require('../').daemon({
|
||||
directory: process.env.BITCOINDJS_DIR || '~/.bitcoin'
|
||||
});
|
||||
|
||||
bitcoind.on('error', function(err) {
|
||||
bitcoind.log('error="%s"', err.message);
|
||||
daemon.on('error', function(err) {
|
||||
daemon.log('error="%s"', err.message);
|
||||
});
|
||||
|
||||
bitcoind.on('open', function(status) {
|
||||
bitcoind.log('status="%s"', status);
|
||||
daemon.on('open', function(status) {
|
||||
daemon.log('status="%s"', status);
|
||||
});
|
||||
|
|
|
@ -7,17 +7,17 @@
|
|||
process.title = 'bitcoind_stripped.js';
|
||||
|
||||
/**
|
||||
* bitcoind
|
||||
* daemon
|
||||
*/
|
||||
|
||||
var bitcoind = require('../index_stripped.js')({
|
||||
var daemon = require('../index_stripped.js')({
|
||||
directory: '~/.libbitcoind-example'
|
||||
});
|
||||
|
||||
bitcoind.on('error', function(err) {
|
||||
bitcoind.log('error="%s"', err.message);
|
||||
daemon.on('error', function(err) {
|
||||
daemon.log('error="%s"', err.message);
|
||||
});
|
||||
|
||||
bitcoind.on('open', function(status) {
|
||||
bitcoind.log('status="%s"', status);
|
||||
daemon.on('open', function(status) {
|
||||
daemon.log('status="%s"', status);
|
||||
});
|
||||
|
|
2
index.js
2
index.js
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {};
|
||||
module.exports.bitcoind = require('./lib/bitcoind');
|
||||
module.exports.daemon = require('./lib/daemon');
|
||||
module.exports.Node = require('./lib/node');
|
||||
module.exports.Block = require('./lib/block');
|
||||
module.exports.Chain = require('./lib/chain');
|
||||
|
|
|
@ -16,16 +16,16 @@ var tiny = require('tiny').json;
|
|||
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;
|
||||
|
||||
if (!(this instanceof Bitcoin)) {
|
||||
return new Bitcoin(options);
|
||||
if (!(this instanceof Daemon)) {
|
||||
return new Daemon(options);
|
||||
}
|
||||
|
||||
if (Object.keys(this.instances).length) {
|
||||
|
@ -54,7 +54,7 @@ function Bitcoin(options) {
|
|||
|
||||
this.datadir = this.options.datadir;
|
||||
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)) {
|
||||
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',
|
||||
peers: [
|
||||
// hardcoded peers
|
||||
]
|
||||
};
|
||||
|
||||
Bitcoin.testnet = {
|
||||
Daemon.testnet = {
|
||||
name: 'testnet',
|
||||
peers: [
|
||||
// hardcoded peers
|
||||
|
@ -121,30 +121,30 @@ Bitcoin.testnet = {
|
|||
};
|
||||
|
||||
// Make sure signal handlers are not overwritten
|
||||
Bitcoin._signalQueue = [];
|
||||
Bitcoin._processOn = process.on;
|
||||
Daemon._signalQueue = [];
|
||||
Daemon._processOn = process.on;
|
||||
process.addListener =
|
||||
process.on = function(name, listener) {
|
||||
if (~['SIGINT', 'SIGHUP', 'SIGQUIT'].indexOf(name.toUpperCase())) {
|
||||
if (!Bitcoin.global || !Bitcoin.global._started) {
|
||||
Bitcoin._signalQueue.push([name, listener]);
|
||||
if (!Daemon.global || !Daemon.global._started) {
|
||||
Daemon._signalQueue.push([name, listener]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return Bitcoin._processOn.apply(this, arguments);
|
||||
return Daemon._processOn.apply(this, arguments);
|
||||
};
|
||||
|
||||
Bitcoin.instances = {};
|
||||
Bitcoin.prototype.instances = Bitcoin.instances;
|
||||
Daemon.instances = {};
|
||||
Daemon.prototype.instances = Daemon.instances;
|
||||
|
||||
Bitcoin.__defineGetter__('global', function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
return Bitcoin.instances[Object.keys(Bitcoin.instances)[0]];
|
||||
Daemon.__defineGetter__('global', function() {
|
||||
if (daemon.stopping) return [];
|
||||
return Daemon.instances[Object.keys(Daemon.instances)[0]];
|
||||
});
|
||||
|
||||
Bitcoin.prototype.__defineGetter__('global', function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
return Bitcoin.global;
|
||||
Daemon.prototype.__defineGetter__('global', function() {
|
||||
if (daemon.stopping) return [];
|
||||
return Daemon.global;
|
||||
});
|
||||
|
||||
tiny.debug = function() {};
|
||||
|
@ -152,13 +152,13 @@ tiny.prototype.debug = function() {};
|
|||
tiny.error = function() {};
|
||||
tiny.prototype.error = function() {};
|
||||
|
||||
Bitcoin.db = tiny({
|
||||
Daemon.db = tiny({
|
||||
file: process.env.HOME + '/.bitcoindjs.db',
|
||||
saveIndex: false,
|
||||
initialCache: false
|
||||
});
|
||||
|
||||
Bitcoin.prototype.start = function(options, callback) {
|
||||
Daemon.prototype.start = function(options, callback) {
|
||||
var self = this;
|
||||
|
||||
if (!callback) {
|
||||
|
@ -212,8 +212,8 @@ Bitcoin.prototype.start = function(options, callback) {
|
|||
});
|
||||
|
||||
// Finally set signal handlers
|
||||
process.on = process.addListener = Bitcoin._processOn;
|
||||
Bitcoin._signalQueue.forEach(function(event) {
|
||||
process.on = process.addListener = Daemon._processOn;
|
||||
Daemon._signalQueue.forEach(function(event) {
|
||||
process.on(event[0], event[1]);
|
||||
});
|
||||
|
||||
|
@ -307,36 +307,36 @@ Bitcoin.prototype.start = function(options, callback) {
|
|||
}, 1000);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBlock = function(blockhash, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getBlock = function(blockhash, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getBlock(blockhash, function(err, block) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, block);
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBlockHeight = function(height, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getBlockHeight = function(height, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getBlock(+height, function(err, block) {
|
||||
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);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getChainWork = function(blockHash) {
|
||||
Daemon.prototype.getChainWork = function(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);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getTransactionWithBlock = function(txid, blockhash, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
|
||||
var self = this;
|
||||
var slow = true;
|
||||
|
@ -377,57 +377,57 @@ Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback)
|
|||
|
||||
return bitcoindjs.getBlock(tx.blockhash, function(err, block) {
|
||||
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);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.addMempoolUncheckedTransaction = function(txBuffer) {
|
||||
Daemon.prototype.addMempoolUncheckedTransaction = function(txBuffer) {
|
||||
return bitcoindjs.addMempoolUncheckedTransaction(txBuffer);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getInfo = function() {
|
||||
Daemon.prototype.getInfo = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoindjs.getInfo();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getPeerInfo = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getPeerInfo = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getPeerInfo();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getAddresses = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getAddresses = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getAddresses();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getProgress = function(callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getProgress = function(callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getProgress(callback);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.setGenerate = function(options) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.setGenerate = function(options) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.setGenerate(options || {});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getGenerate = function(options) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getGenerate = function(options) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getGenerate(options || {});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getMiningInfo = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getMiningInfo = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getMiningInfo();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoin.db.get('addr-tx/' + address, function(err, records) {
|
||||
Daemon.prototype.getAddrTransactions = function(address, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return daemon.db.get('addr-tx/' + address, function(err, records) {
|
||||
var options = {
|
||||
address: address,
|
||||
blockheight: (records || []).reduce(function(out, record) {
|
||||
|
@ -443,15 +443,15 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
|||
};
|
||||
return bitcoindjs.getAddrTransactions(options, function(err, addr) {
|
||||
if (err) return callback(err);
|
||||
addr = bitcoin.addr(addr);
|
||||
addr = daemon.addr(addr);
|
||||
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,
|
||||
blockhash: null,
|
||||
blockheight: null,
|
||||
blocktime: null
|
||||
}], function() {
|
||||
return callback(null, bitcoin.addr({
|
||||
return callback(null, daemon.addr({
|
||||
address: addr.address,
|
||||
tx: []
|
||||
}));
|
||||
|
@ -469,33 +469,33 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
|||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBestBlock = function(callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getBestBlock = function(callback) {
|
||||
if (daemon.stopping) return [];
|
||||
var hash = bitcoindjs.getBestBlock();
|
||||
return bitcoindjs.getBlock(hash, callback);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getChainHeight = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getChainHeight = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getChainHeight();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.__defineGetter__('chainHeight', function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.__defineGetter__('chainHeight', function() {
|
||||
if (daemon.stopping) return [];
|
||||
return this.getChainHeight();
|
||||
});
|
||||
|
||||
Bitcoin.prototype.getBlockByTxid =
|
||||
Bitcoin.prototype.getBlockByTx = function(txid, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoin.db.get('block-tx/' + txid, function(err, block) {
|
||||
Daemon.prototype.getBlockByTxid =
|
||||
Daemon.prototype.getBlockByTx = function(txid, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return daemon.db.get('block-tx/' + txid, function(err, block) {
|
||||
if (block) {
|
||||
return self.getBlock(block.hash, function(err, block) {
|
||||
if (err) return callback(err);
|
||||
|
@ -507,41 +507,41 @@ Bitcoin.prototype.getBlockByTx = function(txid, callback) {
|
|||
}
|
||||
return bitcoindjs.getBlockByTx(txid, function(err, block, tx_) {
|
||||
if (err) return callback(err);
|
||||
bitcoin.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP);
|
||||
return callback(null, bitcoin.block(block), bitcoin.tx(tx_));
|
||||
daemon.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP);
|
||||
return callback(null, daemon.block(block), daemon.tx(tx_));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBlocksByDate =
|
||||
Bitcoin.prototype.getBlocksByTime = function(options, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getBlocksByDate =
|
||||
Daemon.prototype.getBlocksByTime = function(options, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getBlocksByTime(options, function(err, blocks) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, blocks.map(function(block) {
|
||||
return bitcoin.block(block);
|
||||
return daemon.block(block);
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getFromTx = function(txid, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getFromTx = function(txid, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getFromTx(txid, function(err, txs) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, txs.map(function(tx) {
|
||||
return bitcoin.tx(tx)
|
||||
return daemon.tx(tx)
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getLastFileIndex = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getLastFileIndex = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getLastFileIndex();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.log =
|
||||
Bitcoin.prototype.info = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.log =
|
||||
Daemon.prototype.info = function() {
|
||||
if (daemon.stopping) return [];
|
||||
if (this.options.silent) return;
|
||||
if (typeof arguments[0] !== 'string') {
|
||||
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');
|
||||
};
|
||||
|
||||
Bitcoin.prototype.error = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.error = function() {
|
||||
if (daemon.stopping) return [];
|
||||
if (this.options.silent) return;
|
||||
if (typeof arguments[0] !== 'string') {
|
||||
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');
|
||||
};
|
||||
|
||||
Bitcoin.prototype.stop =
|
||||
Bitcoin.prototype.close = function(callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.stop =
|
||||
Daemon.prototype.close = function(callback) {
|
||||
if (daemon.stopping) return [];
|
||||
var self = this;
|
||||
return bitcoindjs.stop(function(err, status) {
|
||||
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();
|
||||
});
|
||||
|
||||
Bitcoin.prototype.__defineGetter__('stopped', function() {
|
||||
Daemon.prototype.__defineGetter__('stopped', function() {
|
||||
return bitcoindjs.stopped();
|
||||
});
|
||||
|
||||
Bitcoin.__defineGetter__('stopping', function() {
|
||||
Daemon.__defineGetter__('stopping', function() {
|
||||
return bitcoindjs.stopping() || bitcoindjs.stopped();
|
||||
});
|
||||
|
||||
Bitcoin.__defineGetter__('stopped', function() {
|
||||
Daemon.__defineGetter__('stopped', function() {
|
||||
return bitcoindjs.stopped();
|
||||
});
|
||||
|
||||
|
@ -610,7 +610,7 @@ function Block(data) {
|
|||
return data;
|
||||
}
|
||||
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
|
||||
var self = this;
|
||||
|
||||
|
@ -621,7 +621,7 @@ function Block(data) {
|
|||
});
|
||||
|
||||
this.tx = this.tx.map(function(tx) {
|
||||
return bitcoin.tx(tx);
|
||||
return daemon.tx(tx);
|
||||
});
|
||||
|
||||
if (!this.hex) {
|
||||
|
@ -638,17 +638,17 @@ Object.defineProperty(Block.prototype, '_blockFlag', {
|
|||
});
|
||||
|
||||
Block.isBlock = function(block) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return block._blockFlag === Block.prototype._blockFlag;
|
||||
};
|
||||
|
||||
Block.fromHex = function(hex) {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoin.block(bitcoindjs.blockFromHex(hex));
|
||||
if (daemon.stopping) return [];
|
||||
return daemon.block(bitcoindjs.blockFromHex(hex));
|
||||
};
|
||||
|
||||
Block.prototype.getHash = function(enc) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getBlockHex(this);
|
||||
if (!this.hash || this.hash !== data.hash) {
|
||||
this.hash = data.hash;
|
||||
|
@ -660,12 +660,12 @@ Block.prototype.getHash = function(enc) {
|
|||
};
|
||||
|
||||
Block.prototype.verify = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return this.verified = this.verified || bitcoindjs.verifyBlock(this);
|
||||
};
|
||||
|
||||
Block.prototype.toHex = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var hex = Block.toHex(this);
|
||||
if (!this.hex || this.hex !== hex) {
|
||||
this.hex = hex;
|
||||
|
@ -674,18 +674,18 @@ Block.prototype.toHex = function() {
|
|||
};
|
||||
|
||||
Block.toHex = function(block) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getBlockHex(block);
|
||||
return data.hex;
|
||||
};
|
||||
|
||||
Block.prototype.toBinary = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return Block.toBinary(this);
|
||||
};
|
||||
|
||||
Block.toBinary = function(block) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getBlockHex(block);
|
||||
return new Buffer(data.hex, 'hex');
|
||||
};
|
||||
|
@ -707,7 +707,7 @@ function Transaction(data) {
|
|||
return data;
|
||||
}
|
||||
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
|
||||
var self = this;
|
||||
|
||||
|
@ -732,34 +732,34 @@ Object.defineProperty(Transaction.prototype, '_txFlag', {
|
|||
|
||||
Transaction.isTransaction =
|
||||
Transaction.isTx = function(tx) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return tx._txFlag === Transaction.prototype._txFlag;
|
||||
};
|
||||
|
||||
Transaction.fromHex = function(hex) {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoin.tx(bitcoindjs.txFromHex(hex));
|
||||
if (daemon.stopping) return [];
|
||||
return daemon.tx(bitcoindjs.txFromHex(hex));
|
||||
};
|
||||
|
||||
Transaction.prototype.verify = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return this.verified = this.verified || bitcoindjs.verifyTransaction(this);
|
||||
};
|
||||
|
||||
Transaction.prototype.sign =
|
||||
Transaction.prototype.fill = function(options) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return Transaction.fill(this, options);
|
||||
};
|
||||
|
||||
Transaction.sign =
|
||||
Transaction.fill = function(tx, options) {
|
||||
if (bitcoin.stopping) return [];
|
||||
var isTx = bitcoin.tx.isTx(tx)
|
||||
if (daemon.stopping) return [];
|
||||
var isTx = daemon.tx.isTx(tx)
|
||||
, newTx;
|
||||
|
||||
if (!isTx) {
|
||||
tx = bitcoin.tx(tx);
|
||||
tx = daemon.tx(tx);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -776,7 +776,7 @@ Transaction.fill = function(tx, options) {
|
|||
};
|
||||
|
||||
Transaction.prototype.getHash = function(enc) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getTxHex(this);
|
||||
if (!this.txid || this.txid !== data.hash) {
|
||||
this.txid = data.hash;
|
||||
|
@ -788,12 +788,12 @@ Transaction.prototype.getHash = function(enc) {
|
|||
};
|
||||
|
||||
Transaction.prototype.isCoinbase = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return this.vin.length === 1 && this.vin[0].coinbase;
|
||||
};
|
||||
|
||||
Transaction.prototype.toHex = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var hex = Transaction.toHex(this);
|
||||
if (!this.hex || hex !== this.hex) {
|
||||
this.hex = hex;
|
||||
|
@ -802,24 +802,24 @@ Transaction.prototype.toHex = function() {
|
|||
};
|
||||
|
||||
Transaction.toHex = function(tx) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getTxHex(tx);
|
||||
return data.hex;
|
||||
};
|
||||
|
||||
Transaction.prototype.toBinary = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return Transaction.toBinary(this);
|
||||
};
|
||||
|
||||
Transaction.toBinary = function(tx) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getTxHex(tx);
|
||||
return new Buffer(data.hex, 'hex');
|
||||
};
|
||||
|
||||
Transaction.broadcast = function(tx, options, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
if (typeof tx === 'string') {
|
||||
tx = { hex: tx };
|
||||
}
|
||||
|
@ -840,25 +840,25 @@ Transaction.broadcast = function(tx, options, callback) {
|
|||
callback = utils.NOOP;
|
||||
}
|
||||
|
||||
if (!bitcoin.isTx(tx)) {
|
||||
tx = bitcoin.tx(tx);
|
||||
if (!daemon.isTx(tx)) {
|
||||
tx = daemon.tx(tx);
|
||||
}
|
||||
|
||||
return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash, tx) {
|
||||
if (err) {
|
||||
if (callback === utils.NOOP) {
|
||||
bitcoin.global.emit('error', err);
|
||||
daemon.global.emit('error', err);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
tx = bitcoin.tx(tx);
|
||||
bitcoin.global.emit('broadcast', tx);
|
||||
tx = daemon.tx(tx);
|
||||
daemon.global.emit('broadcast', tx);
|
||||
return callback(null, hash, tx);
|
||||
});
|
||||
};
|
||||
|
||||
Transaction.prototype.broadcast = function(options, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
options = null;
|
||||
|
@ -879,7 +879,7 @@ function Addresses(data) {
|
|||
return data;
|
||||
}
|
||||
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
|
||||
var self = this;
|
||||
|
||||
|
@ -900,7 +900,7 @@ Object.defineProperty(Transaction.prototype, '_addrFlag', {
|
|||
|
||||
Addresses.isAddresses =
|
||||
Addresses.isAddr = function(addr) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return addr._txFlag === Addresses.prototype._addrFlag;
|
||||
};
|
||||
|
||||
|
@ -911,7 +911,7 @@ Addresses.isAddr = function(addr) {
|
|||
var utils = {};
|
||||
|
||||
utils.forEach = function(obj, iter, done) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var pending = obj.length;
|
||||
if (!pending) return done();
|
||||
var next = function() {
|
||||
|
@ -928,11 +928,11 @@ utils.NOOP = function() {};
|
|||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = exports = bitcoin;
|
||||
module.exports = exports = daemon;
|
||||
|
||||
exports.Bitcoin = bitcoin;
|
||||
exports.bitcoin = bitcoin;
|
||||
exports.bitcoind = bitcoin;
|
||||
exports.Daemon = daemon;
|
||||
exports.daemon = daemon;
|
||||
exports.bitcoind = daemon;
|
||||
|
||||
exports.native = bitcoindjs;
|
||||
exports.bitcoindjs = bitcoindjs;
|
|
@ -16,16 +16,16 @@ var tiny = require('tiny').json;
|
|||
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;
|
||||
|
||||
if (!(this instanceof Bitcoin)) {
|
||||
return new Bitcoin(options);
|
||||
if (!(this instanceof Daemon)) {
|
||||
return new Daemon(options);
|
||||
}
|
||||
|
||||
if (Object.keys(this.instances).length) {
|
||||
|
@ -54,7 +54,7 @@ function Bitcoin(options) {
|
|||
|
||||
this.datadir = this.options.datadir;
|
||||
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)) {
|
||||
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',
|
||||
peers: [
|
||||
// hardcoded peers
|
||||
]
|
||||
};
|
||||
|
||||
Bitcoin.testnet = {
|
||||
Daemon.testnet = {
|
||||
name: 'testnet',
|
||||
peers: [
|
||||
// hardcoded peers
|
||||
|
@ -121,30 +121,30 @@ Bitcoin.testnet = {
|
|||
};
|
||||
|
||||
// Make sure signal handlers are not overwritten
|
||||
Bitcoin._signalQueue = [];
|
||||
Bitcoin._processOn = process.on;
|
||||
Daemon._signalQueue = [];
|
||||
Daemon._processOn = process.on;
|
||||
process.addListener =
|
||||
process.on = function(name, listener) {
|
||||
if (~['SIGINT', 'SIGHUP', 'SIGQUIT'].indexOf(name.toUpperCase())) {
|
||||
if (!Bitcoin.global || !Bitcoin.global._started) {
|
||||
Bitcoin._signalQueue.push([name, listener]);
|
||||
if (!Daemon.global || !Daemon.global._started) {
|
||||
Daemon._signalQueue.push([name, listener]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return Bitcoin._processOn.apply(this, arguments);
|
||||
return Daemon._processOn.apply(this, arguments);
|
||||
};
|
||||
|
||||
Bitcoin.instances = {};
|
||||
Bitcoin.prototype.instances = Bitcoin.instances;
|
||||
Daemon.instances = {};
|
||||
Daemon.prototype.instances = Daemon.instances;
|
||||
|
||||
Bitcoin.__defineGetter__('global', function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
return Bitcoin.instances[Object.keys(Bitcoin.instances)[0]];
|
||||
Daemon.__defineGetter__('global', function() {
|
||||
if (daemon.stopping) return [];
|
||||
return Daemon.instances[Object.keys(Daemon.instances)[0]];
|
||||
});
|
||||
|
||||
Bitcoin.prototype.__defineGetter__('global', function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
return Bitcoin.global;
|
||||
Daemon.prototype.__defineGetter__('global', function() {
|
||||
if (daemon.stopping) return [];
|
||||
return Daemon.global;
|
||||
});
|
||||
|
||||
tiny.debug = function() {};
|
||||
|
@ -152,13 +152,13 @@ tiny.prototype.debug = function() {};
|
|||
tiny.error = function() {};
|
||||
tiny.prototype.error = function() {};
|
||||
|
||||
Bitcoin.db = tiny({
|
||||
Daemon.db = tiny({
|
||||
file: process.env.HOME + '/.bitcoindjs.db',
|
||||
saveIndex: false,
|
||||
initialCache: false
|
||||
});
|
||||
|
||||
Bitcoin.prototype.start = function(options, callback) {
|
||||
Daemon.prototype.start = function(options, callback) {
|
||||
var self = this;
|
||||
|
||||
if (!callback) {
|
||||
|
@ -212,8 +212,8 @@ Bitcoin.prototype.start = function(options, callback) {
|
|||
});
|
||||
|
||||
// Finally set signal handlers
|
||||
process.on = process.addListener = Bitcoin._processOn;
|
||||
Bitcoin._signalQueue.forEach(function(event) {
|
||||
process.on = process.addListener = Daemon._processOn;
|
||||
Daemon._signalQueue.forEach(function(event) {
|
||||
process.on(event[0], event[1]);
|
||||
});
|
||||
|
||||
|
@ -303,25 +303,25 @@ Bitcoin.prototype.start = function(options, callback) {
|
|||
}, 1000);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBlock = function(blockhash, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getBlock = function(blockhash, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getBlock(blockhash, function(err, block) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, bitcoin.block(block));
|
||||
return callback(null, daemon.block(block));
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBlockHeight = function(height, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getBlockHeight = function(height, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getBlock(+height, function(err, block) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, bitcoin.block(block));
|
||||
return callback(null, daemon.block(block));
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getTransaction =
|
||||
Bitcoin.prototype.getTx = function(txid, blockhash, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getTransaction =
|
||||
Daemon.prototype.getTx = function(txid, blockhash, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
if (typeof txid === 'object' && txid) {
|
||||
var options = txid;
|
||||
callback = blockhash;
|
||||
|
@ -347,12 +347,12 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) {
|
|||
|
||||
return bitcoindjs.getTransaction(txid, blockhash, function(err, tx) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, bitcoin.tx(tx));
|
||||
return callback(null, daemon.tx(tx));
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getTransactionWithBlock = function(txid, blockhash, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
|
||||
var self = this;
|
||||
var slow = true;
|
||||
|
@ -393,49 +393,49 @@ Bitcoin.prototype.getTransactionWithBlock = function(txid, blockhash, callback)
|
|||
|
||||
return bitcoindjs.getBlock(tx.blockhash, function(err, block) {
|
||||
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() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getInfo = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getInfo();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getPeerInfo = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getPeerInfo = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getPeerInfo();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getAddresses = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getAddresses = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getAddresses();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getProgress = function(callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getProgress = function(callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getProgress(callback);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.setGenerate = function(options) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.setGenerate = function(options) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.setGenerate(options || {});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getGenerate = function(options) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getGenerate = function(options) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getGenerate(options || {});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getMiningInfo = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getMiningInfo = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getMiningInfo();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoin.db.get('addr-tx/' + address, function(err, records) {
|
||||
Daemon.prototype.getAddrTransactions = function(address, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return daemon.db.get('addr-tx/' + address, function(err, records) {
|
||||
var options = {
|
||||
address: address,
|
||||
blockheight: (records || []).reduce(function(out, record) {
|
||||
|
@ -451,15 +451,15 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
|||
};
|
||||
return bitcoindjs.getAddrTransactions(options, function(err, addr) {
|
||||
if (err) return callback(err);
|
||||
addr = bitcoin.addr(addr);
|
||||
addr = daemon.addr(addr);
|
||||
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,
|
||||
blockhash: null,
|
||||
blockheight: null,
|
||||
blocktime: null
|
||||
}], function() {
|
||||
return callback(null, bitcoin.addr({
|
||||
return callback(null, daemon.addr({
|
||||
address: addr.address,
|
||||
tx: []
|
||||
}));
|
||||
|
@ -477,33 +477,33 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
|||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBestBlock = function(callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getBestBlock = function(callback) {
|
||||
if (daemon.stopping) return [];
|
||||
var hash = bitcoindjs.getBestBlock();
|
||||
return bitcoindjs.getBlock(hash, callback);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getChainHeight = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getChainHeight = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getChainHeight();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.__defineGetter__('chainHeight', function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.__defineGetter__('chainHeight', function() {
|
||||
if (daemon.stopping) return [];
|
||||
return this.getChainHeight();
|
||||
});
|
||||
|
||||
Bitcoin.prototype.getBlockByTxid =
|
||||
Bitcoin.prototype.getBlockByTx = function(txid, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoin.db.get('block-tx/' + txid, function(err, block) {
|
||||
Daemon.prototype.getBlockByTxid =
|
||||
Daemon.prototype.getBlockByTx = function(txid, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return daemon.db.get('block-tx/' + txid, function(err, block) {
|
||||
if (block) {
|
||||
return self.getBlock(block.hash, function(err, block) {
|
||||
if (err) return callback(err);
|
||||
|
@ -515,41 +515,41 @@ Bitcoin.prototype.getBlockByTx = function(txid, callback) {
|
|||
}
|
||||
return bitcoindjs.getBlockByTx(txid, function(err, block, tx_) {
|
||||
if (err) return callback(err);
|
||||
bitcoin.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP);
|
||||
return callback(null, bitcoin.block(block), bitcoin.tx(tx_));
|
||||
daemon.db.set('block-tx/' + txid, { hash: block.hash }, utils.NOOP);
|
||||
return callback(null, daemon.block(block), daemon.tx(tx_));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBlocksByDate =
|
||||
Bitcoin.prototype.getBlocksByTime = function(options, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getBlocksByDate =
|
||||
Daemon.prototype.getBlocksByTime = function(options, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getBlocksByTime(options, function(err, blocks) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, blocks.map(function(block) {
|
||||
return bitcoin.block(block)
|
||||
return daemon.block(block)
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getFromTx = function(txid, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getFromTx = function(txid, callback) {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getFromTx(txid, function(err, txs) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, txs.map(function(tx) {
|
||||
return bitcoin.tx(tx)
|
||||
return daemon.tx(tx)
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getLastFileIndex = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.getLastFileIndex = function() {
|
||||
if (daemon.stopping) return [];
|
||||
return bitcoindjs.getLastFileIndex();
|
||||
};
|
||||
|
||||
Bitcoin.prototype.log =
|
||||
Bitcoin.prototype.info = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.log =
|
||||
Daemon.prototype.info = function() {
|
||||
if (daemon.stopping) return [];
|
||||
if (this.options.silent) return;
|
||||
if (typeof arguments[0] !== 'string') {
|
||||
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');
|
||||
};
|
||||
|
||||
Bitcoin.prototype.error = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.error = function() {
|
||||
if (daemon.stopping) return [];
|
||||
if (this.options.silent) return;
|
||||
if (typeof arguments[0] !== 'string') {
|
||||
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');
|
||||
};
|
||||
|
||||
Bitcoin.prototype.stop =
|
||||
Bitcoin.prototype.close = function(callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
Daemon.prototype.stop =
|
||||
Daemon.prototype.close = function(callback) {
|
||||
if (daemon.stopping) return [];
|
||||
var self = this;
|
||||
return bitcoindjs.stop(function(err, status) {
|
||||
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();
|
||||
});
|
||||
|
||||
Bitcoin.prototype.__defineGetter__('stopped', function() {
|
||||
Daemon.prototype.__defineGetter__('stopped', function() {
|
||||
return bitcoindjs.stopped();
|
||||
});
|
||||
|
||||
Bitcoin.__defineGetter__('stopping', function() {
|
||||
Daemon.__defineGetter__('stopping', function() {
|
||||
return bitcoindjs.stopping() || bitcoindjs.stopped();
|
||||
});
|
||||
|
||||
Bitcoin.__defineGetter__('stopped', function() {
|
||||
Daemon.__defineGetter__('stopped', function() {
|
||||
return bitcoindjs.stopped();
|
||||
});
|
||||
|
||||
|
@ -618,7 +618,7 @@ function Block(data) {
|
|||
return data;
|
||||
}
|
||||
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
|
||||
var self = this;
|
||||
|
||||
|
@ -629,7 +629,7 @@ function Block(data) {
|
|||
});
|
||||
|
||||
this.tx = this.tx.map(function(tx) {
|
||||
return bitcoin.tx(tx);
|
||||
return daemon.tx(tx);
|
||||
});
|
||||
|
||||
if (!this.hex) {
|
||||
|
@ -646,17 +646,17 @@ Object.defineProperty(Block.prototype, '_blockFlag', {
|
|||
});
|
||||
|
||||
Block.isBlock = function(block) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return block._blockFlag === Block.prototype._blockFlag;
|
||||
};
|
||||
|
||||
Block.fromHex = function(hex) {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoin.block(bitcoindjs.blockFromHex(hex));
|
||||
if (daemon.stopping) return [];
|
||||
return daemon.block(bitcoindjs.blockFromHex(hex));
|
||||
};
|
||||
|
||||
Block.prototype.getHash = function(enc) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getBlockHex(this);
|
||||
if (!this.hash || this.hash !== data.hash) {
|
||||
this.hash = data.hash;
|
||||
|
@ -668,12 +668,12 @@ Block.prototype.getHash = function(enc) {
|
|||
};
|
||||
|
||||
Block.prototype.verify = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return this.verified = this.verified || bitcoindjs.verifyBlock(this);
|
||||
};
|
||||
|
||||
Block.prototype.toHex = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var hex = Block.toHex(this);
|
||||
if (!this.hex || this.hex !== hex) {
|
||||
this.hex = hex;
|
||||
|
@ -682,18 +682,18 @@ Block.prototype.toHex = function() {
|
|||
};
|
||||
|
||||
Block.toHex = function(block) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getBlockHex(block);
|
||||
return data.hex;
|
||||
};
|
||||
|
||||
Block.prototype.toBinary = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return Block.toBinary(this);
|
||||
};
|
||||
|
||||
Block.toBinary = function(block) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getBlockHex(block);
|
||||
return new Buffer(data.hex, 'hex');
|
||||
};
|
||||
|
@ -715,7 +715,7 @@ function Transaction(data) {
|
|||
return data;
|
||||
}
|
||||
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
|
||||
var self = this;
|
||||
|
||||
|
@ -740,34 +740,34 @@ Object.defineProperty(Transaction.prototype, '_txFlag', {
|
|||
|
||||
Transaction.isTransaction =
|
||||
Transaction.isTx = function(tx) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return tx._txFlag === Transaction.prototype._txFlag;
|
||||
};
|
||||
|
||||
Transaction.fromHex = function(hex) {
|
||||
if (bitcoin.stopping) return [];
|
||||
return bitcoin.tx(bitcoindjs.txFromHex(hex));
|
||||
if (daemon.stopping) return [];
|
||||
return daemon.tx(bitcoindjs.txFromHex(hex));
|
||||
};
|
||||
|
||||
Transaction.prototype.verify = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return this.verified = this.verified || bitcoindjs.verifyTransaction(this);
|
||||
};
|
||||
|
||||
Transaction.prototype.sign =
|
||||
Transaction.prototype.fill = function(options) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return Transaction.fill(this, options);
|
||||
};
|
||||
|
||||
Transaction.sign =
|
||||
Transaction.fill = function(tx, options) {
|
||||
if (bitcoin.stopping) return [];
|
||||
var isTx = bitcoin.tx.isTx(tx)
|
||||
if (daemon.stopping) return [];
|
||||
var isTx = daemon.tx.isTx(tx)
|
||||
, newTx;
|
||||
|
||||
if (!isTx) {
|
||||
tx = bitcoin.tx(tx);
|
||||
tx = daemon.tx(tx);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -784,7 +784,7 @@ Transaction.fill = function(tx, options) {
|
|||
};
|
||||
|
||||
Transaction.prototype.getHash = function(enc) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getTxHex(this);
|
||||
if (!this.txid || this.txid !== data.hash) {
|
||||
this.txid = data.hash;
|
||||
|
@ -796,12 +796,12 @@ Transaction.prototype.getHash = function(enc) {
|
|||
};
|
||||
|
||||
Transaction.prototype.isCoinbase = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return this.vin.length === 1 && this.vin[0].coinbase;
|
||||
};
|
||||
|
||||
Transaction.prototype.toHex = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var hex = Transaction.toHex(this);
|
||||
if (!this.hex || hex !== this.hex) {
|
||||
this.hex = hex;
|
||||
|
@ -810,24 +810,24 @@ Transaction.prototype.toHex = function() {
|
|||
};
|
||||
|
||||
Transaction.toHex = function(tx) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getTxHex(tx);
|
||||
return data.hex;
|
||||
};
|
||||
|
||||
Transaction.prototype.toBinary = function() {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return Transaction.toBinary(this);
|
||||
};
|
||||
|
||||
Transaction.toBinary = function(tx) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var data = bitcoindjs.getTxHex(tx);
|
||||
return new Buffer(data.hex, 'hex');
|
||||
};
|
||||
|
||||
Transaction.broadcast = function(tx, options, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
if (typeof tx === 'string') {
|
||||
tx = { hex: tx };
|
||||
}
|
||||
|
@ -848,25 +848,25 @@ Transaction.broadcast = function(tx, options, callback) {
|
|||
callback = utils.NOOP;
|
||||
}
|
||||
|
||||
if (!bitcoin.isTx(tx)) {
|
||||
tx = bitcoin.tx(tx);
|
||||
if (!daemon.isTx(tx)) {
|
||||
tx = daemon.tx(tx);
|
||||
}
|
||||
|
||||
return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash, tx) {
|
||||
if (err) {
|
||||
if (callback === utils.NOOP) {
|
||||
bitcoin.global.emit('error', err);
|
||||
daemon.global.emit('error', err);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
tx = bitcoin.tx(tx);
|
||||
bitcoin.global.emit('broadcast', tx);
|
||||
tx = daemon.tx(tx);
|
||||
daemon.global.emit('broadcast', tx);
|
||||
return callback(null, hash, tx);
|
||||
});
|
||||
};
|
||||
|
||||
Transaction.prototype.broadcast = function(options, callback) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
options = null;
|
||||
|
@ -887,7 +887,7 @@ function Addresses(data) {
|
|||
return data;
|
||||
}
|
||||
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
|
||||
var self = this;
|
||||
|
||||
|
@ -908,7 +908,7 @@ Object.defineProperty(Transaction.prototype, '_addrFlag', {
|
|||
|
||||
Addresses.isAddresses =
|
||||
Addresses.isAddr = function(addr) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
return addr._txFlag === Addresses.prototype._addrFlag;
|
||||
};
|
||||
|
||||
|
@ -919,7 +919,7 @@ Addresses.isAddr = function(addr) {
|
|||
var utils = {};
|
||||
|
||||
utils.forEach = function(obj, iter, done) {
|
||||
if (bitcoin.stopping) return [];
|
||||
if (daemon.stopping) return [];
|
||||
var pending = obj.length;
|
||||
if (!pending) return done();
|
||||
var next = function() {
|
||||
|
@ -936,11 +936,11 @@ utils.NOOP = function() {};
|
|||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = exports = bitcoin;
|
||||
module.exports = exports = daemon;
|
||||
|
||||
exports.Bitcoin = bitcoin;
|
||||
exports.bitcoin = bitcoin;
|
||||
exports.bitcoind = bitcoin;
|
||||
exports.Daemon = daemon;
|
||||
exports.daemon = daemon;
|
||||
exports.bitcoind = daemon;
|
||||
|
||||
exports.native = bitcoindjs;
|
||||
exports.bitcoindjs = bitcoindjs;
|
|
@ -13,7 +13,7 @@ var bitcore = require('bitcore');
|
|||
var Networks = bitcore.Networks;
|
||||
var _ = bitcore.deps._;
|
||||
var genesis = require('./genesis.json');
|
||||
var bitcoind = require('./bitcoind');
|
||||
var daemon = require('./daemon');
|
||||
|
||||
function Node(config) {
|
||||
BaseNode.call(this, config);
|
||||
|
@ -56,7 +56,7 @@ Node.prototype._loadBitcoind = function(config) {
|
|||
}
|
||||
|
||||
// start the bitcoind daemon
|
||||
this.bitcoind = bitcoind(bitcoindConfig);
|
||||
this.bitcoind = daemon(bitcoindConfig);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue