rename method.
This commit is contained in:
parent
bba94d4aaa
commit
3ee5137851
16
lib/bcoin.js
16
lib/bcoin.js
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
var Environment = require('./bcoin/env');
|
||||
var networks = {};
|
||||
var env = {};
|
||||
|
||||
/**
|
||||
* Create a new Environment. Note that this will
|
||||
@ -18,7 +18,7 @@ var networks = {};
|
||||
* @returns {Environment}
|
||||
*/
|
||||
|
||||
module.exports = function BCoin(options) {
|
||||
function BCoin(options) {
|
||||
var network = 'main';
|
||||
|
||||
if (options) {
|
||||
@ -28,10 +28,12 @@ module.exports = function BCoin(options) {
|
||||
network = options;
|
||||
}
|
||||
|
||||
if (!networks[network])
|
||||
networks[network] = new Environment(options);
|
||||
if (!env[network])
|
||||
env[network] = new Environment(options);
|
||||
|
||||
return networks[network];
|
||||
};
|
||||
return env[network];
|
||||
}
|
||||
|
||||
module.exports.env = Environment;
|
||||
BCoin.env = Environment;
|
||||
|
||||
module.exports = BCoin;
|
||||
|
||||
@ -1310,12 +1310,7 @@ ChainDB.prototype.getFullBlock = function getFullBlock(hash, callback) {
|
||||
if (!block)
|
||||
return callback();
|
||||
|
||||
return self.fillHistory(block.txs, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
return callback(null, block);
|
||||
});
|
||||
return self.fillHistoryBlock(block, callback);
|
||||
});
|
||||
};
|
||||
|
||||
@ -1342,15 +1337,7 @@ ChainDB.prototype._ensureHistory = function _ensureHistory(hash, callback) {
|
||||
if (hash instanceof bcoin.block)
|
||||
return utils.asyncify(callback)(null, hash);
|
||||
|
||||
return this.getBlock(hash, function(err, block) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!block)
|
||||
return callback();
|
||||
|
||||
return self.fillUndoBlock(block, callback);
|
||||
});
|
||||
return this.getFullBlock(hash, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1389,42 +1376,6 @@ ChainDB.prototype.fillBlock = function fillBlock(block, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Fill a block with coins (historical).
|
||||
* @param {Block} block
|
||||
* @param {Function} callback - Returns [Error, {@link Block}].
|
||||
*/
|
||||
|
||||
ChainDB.prototype.fillHistoryBlock = function fillHistoryBlock(block, callback) {
|
||||
return this.fillHistory(block.txs, function(err) {
|
||||
var coins, i, tx, hash, j, input, key;
|
||||
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
coins = {};
|
||||
|
||||
for (i = 0; i < block.txs.length; i++) {
|
||||
tx = block.txs[i];
|
||||
hash = tx.hash('hex');
|
||||
|
||||
for (j = 0; j < tx.inputs.length; j++) {
|
||||
input = tx.inputs[j];
|
||||
key = input.prevout.hash + '/' + input.prevout.index;
|
||||
if (!input.coin && coins[key]) {
|
||||
input.coin = coins[key];
|
||||
delete coins[key];
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < tx.outputs.length; j++)
|
||||
coins[hash + '/' + j] = bcoin.coin(tx, j);
|
||||
}
|
||||
|
||||
return callback(null, block);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get coins necessary to be resurrected during a reorg.
|
||||
* @param {Hash} hash
|
||||
@ -1463,7 +1414,7 @@ ChainDB.prototype.getUndoCoins = function getUndoCoins(hash, callback) {
|
||||
* @param {Function} callback - Returns [Error, {@link Block}].
|
||||
*/
|
||||
|
||||
ChainDB.prototype.fillUndoBlock = function fillUndoBlock(block, callback) {
|
||||
ChainDB.prototype.fillHistoryBlock = function fillHistoryBlock(block, callback) {
|
||||
var i, j, k, tx, input;
|
||||
|
||||
return this.getUndoCoins(block.hash('hex'), function(err, coins) {
|
||||
|
||||
@ -121,9 +121,7 @@ function Environment(options) {
|
||||
this._ensured = false;
|
||||
this._debug = null;
|
||||
|
||||
this.isBrowser =
|
||||
(typeof process !== 'undefined' && process.browser)
|
||||
|| typeof window !== 'undefined';
|
||||
this.isBrowser = utils.isBrowser;
|
||||
|
||||
this.prefix = options.prefix
|
||||
|| process.env.BCOIN_PREFIX
|
||||
@ -261,9 +259,9 @@ Environment.prototype.debug = function debug() {
|
||||
|
||||
if (this.isBrowser) {
|
||||
if (this.debugLogs) {
|
||||
msg = typeof args[0] === 'object'
|
||||
? args[0]
|
||||
: utils.format(args, false).slice(0, -1);
|
||||
msg = typeof args[0] !== 'object'
|
||||
? utils.format(args, false)
|
||||
: args[0];
|
||||
console.error(msg);
|
||||
}
|
||||
return;
|
||||
@ -271,7 +269,7 @@ Environment.prototype.debug = function debug() {
|
||||
|
||||
if (this.debugLogs) {
|
||||
msg = utils.format(args, true);
|
||||
process.stderr.write(msg);
|
||||
process.stderr.write(msg + '\n');
|
||||
}
|
||||
|
||||
if (this.debugFile) {
|
||||
@ -280,7 +278,7 @@ Environment.prototype.debug = function debug() {
|
||||
this._debug = fs.createWriteStream(this.debugFile, { flags: 'a' });
|
||||
}
|
||||
msg = utils.format(args, false);
|
||||
this._debug.write(process.pid + ': ' + msg);
|
||||
this._debug.write(process.pid + ': ' + msg + '\n');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -951,7 +951,7 @@ utils.array2ip = function array2ip(ip, version) {
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
utils._inspect = function _inspect(obj, color) {
|
||||
utils.inspectify = function inspectify(obj, color) {
|
||||
return typeof obj !== 'string'
|
||||
? util.inspect(obj, null, 20, color !== false)
|
||||
: obj;
|
||||
@ -966,12 +966,12 @@ utils._inspect = function _inspect(obj, color) {
|
||||
|
||||
utils.format = function format(args, color) {
|
||||
color = color
|
||||
? (process.stdout ? process.stdout.isTTY : true)
|
||||
? (process.stdout ? process.stdout.isTTY : false)
|
||||
: false;
|
||||
|
||||
return typeof args[0] === 'object'
|
||||
? utils._inspect(args[0], color) + '\n'
|
||||
: util.format.apply(util, args) + '\n';
|
||||
? utils.inspectify(args[0], color)
|
||||
: util.format.apply(util, args);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -985,15 +985,15 @@ utils.print = function print() {
|
||||
var msg;
|
||||
|
||||
if (utils.isBrowser) {
|
||||
msg = typeof args[0] === 'object'
|
||||
? args[0]
|
||||
: utils.format(args, false).slice(0, -1);
|
||||
msg = typeof args[0] !== 'object'
|
||||
? utils.format(args, false)
|
||||
: args[0];
|
||||
console.log(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
msg = utils.format(args, true);
|
||||
process.stdout.write(msg);
|
||||
process.stdout.write(msg + '\n');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1007,15 +1007,15 @@ utils.error = function error() {
|
||||
var msg;
|
||||
|
||||
if (utils.isBrowser) {
|
||||
msg = typeof args[0] === 'object'
|
||||
? args[0]
|
||||
: utils.format(args, false).slice(0, -1);
|
||||
msg = typeof args[0] !== 'object'
|
||||
? utils.format(args, false)
|
||||
: args[0];
|
||||
console.error(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
msg = utils.format(args, true);
|
||||
process.stderr.write(msg);
|
||||
process.stderr.write(msg + '\n');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -170,7 +170,7 @@ describe('TX', function() {
|
||||
tx: tx,
|
||||
flags: flags,
|
||||
comments: tx.hasCoins()
|
||||
? utils._inspect(tx.inputs[0].coin.script, false).slice(0, -1)
|
||||
? utils.inspectify(tx.inputs[0].coin.script, false)
|
||||
: 'coinbase',
|
||||
data: data
|
||||
};
|
||||
|
||||
@ -563,5 +563,6 @@ describe('Wallet', function() {
|
||||
|
||||
it('should cleanup', function(cb) {
|
||||
constants.tx.COINBASE_MATURITY = 100;
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user