lint.
This commit is contained in:
parent
8edebc8bb5
commit
2e37b1e7ad
41
.jshintrc
Normal file
41
.jshintrc
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"bitwise": false,
|
||||||
|
"curly": false,
|
||||||
|
"eqeqeq": true,
|
||||||
|
"freeze": true,
|
||||||
|
"latedef": "nofunc",
|
||||||
|
"maxparams": 7,
|
||||||
|
"noarg": true,
|
||||||
|
"shadow": "inner",
|
||||||
|
"undef": true,
|
||||||
|
"unused": true,
|
||||||
|
|
||||||
|
"boss": true,
|
||||||
|
"expr": true,
|
||||||
|
"eqnull": true,
|
||||||
|
"evil": true,
|
||||||
|
"loopfunc": true,
|
||||||
|
"proto": true,
|
||||||
|
"supernew": true,
|
||||||
|
|
||||||
|
"-W018": true,
|
||||||
|
"-W064": true,
|
||||||
|
"-W086": true,
|
||||||
|
"+W032": true,
|
||||||
|
|
||||||
|
"browser": false,
|
||||||
|
"browserify": false,
|
||||||
|
"node": true,
|
||||||
|
"nonstandard": true,
|
||||||
|
"typed": true,
|
||||||
|
"worker": false,
|
||||||
|
|
||||||
|
"camelcase": false,
|
||||||
|
"indent": 2,
|
||||||
|
"maxlen": 110,
|
||||||
|
"newcap": true,
|
||||||
|
"quotmark": "single",
|
||||||
|
|
||||||
|
"laxbreak": true,
|
||||||
|
"laxcomma": true
|
||||||
|
}
|
||||||
31
lib/bcoin.js
31
lib/bcoin.js
@ -5,14 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = exports;
|
var bcoin = exports;
|
||||||
var assert = require('assert');
|
var utils = require('./bcoin/utils');
|
||||||
|
var assert = utils.assert;
|
||||||
|
|
||||||
bcoin.isBrowser =
|
bcoin.isBrowser =
|
||||||
(typeof process !== 'undefined' && process.browser)
|
(typeof process !== 'undefined' && process.browser)
|
||||||
|| typeof window !== 'undefined';
|
|| typeof window !== 'undefined';
|
||||||
|
|
||||||
bcoin.prefix = process.env.BCOIN_PREFIX || process.env.HOME + '/.bcoin';
|
bcoin.prefix = process.env.BCOIN_PREFIX || process.env.HOME + '/.bcoin';
|
||||||
bcoin.debug = +process.env.BCOIN_DEBUG === 1;
|
bcoin.debugLogs = +process.env.BCOIN_DEBUG === 1;
|
||||||
bcoin.debugFile = +process.env.BCOIN_DEBUGFILE !== 0;
|
bcoin.debugFile = +process.env.BCOIN_DEBUGFILE !== 0;
|
||||||
bcoin.profile = +process.env.BCOIN_PROFILE === 1;
|
bcoin.profile = +process.env.BCOIN_PROFILE === 1;
|
||||||
bcoin.fresh = +process.env.BCOIN_FRESH === 1;
|
bcoin.fresh = +process.env.BCOIN_FRESH === 1;
|
||||||
@ -47,6 +48,26 @@ bcoin.rimraf = function rimraf(file) {
|
|||||||
bcoin.cp.execFileSync('rm', ['-rf', file], { stdio: 'ignore' });
|
bcoin.cp.execFileSync('rm', ['-rf', file], { stdio: 'ignore' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bcoin.debug = function debug() {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
var msg;
|
||||||
|
|
||||||
|
if (bcoin.debugLogs) {
|
||||||
|
msg = utils.format(args, true);
|
||||||
|
process.stdout.write(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bcoin.debugFile && bcoin.fs) {
|
||||||
|
if (!bcoin._debug) {
|
||||||
|
bcoin.ensurePrefix();
|
||||||
|
bcoin._debug = bcoin.fs.createWriteStream(
|
||||||
|
bcoin.prefix + '/debug.log', { flags: 'a' });
|
||||||
|
}
|
||||||
|
msg = utils.format(args, false);
|
||||||
|
bcoin._debug.write(process.pid + ': ' + msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
bcoin.bn = require('bn.js');
|
bcoin.bn = require('bn.js');
|
||||||
bcoin.elliptic = require('elliptic');
|
bcoin.elliptic = require('elliptic');
|
||||||
|
|
||||||
@ -58,8 +79,7 @@ if (!bcoin.isBrowser) {
|
|||||||
try {
|
try {
|
||||||
bcoin.secp256k1 = require('secp' + '256k1');
|
bcoin.secp256k1 = require('secp' + '256k1');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
utils.debug('Warning: secp256k1 not found.'
|
;
|
||||||
+ ' Full block validation will be slow.');
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bcoin.hash = require('hash.js');
|
bcoin.hash = require('hash.js');
|
||||||
@ -71,7 +91,8 @@ bcoin.ecdsa.signature = require('elliptic/lib/elliptic/ec/signature');
|
|||||||
assert(!bcoin.ecdsa.keypair);
|
assert(!bcoin.ecdsa.keypair);
|
||||||
bcoin.ecdsa.keypair = require('elliptic/lib/elliptic/ec/key');
|
bcoin.ecdsa.keypair = require('elliptic/lib/elliptic/ec/key');
|
||||||
|
|
||||||
bcoin.utils = require('./bcoin/utils');
|
bcoin.utils = utils;
|
||||||
|
bcoin.utils.debug = bcoin.debug;
|
||||||
bcoin.profiler = require('./bcoin/profiler');
|
bcoin.profiler = require('./bcoin/profiler');
|
||||||
bcoin.ec = require('./bcoin/ec');
|
bcoin.ec = require('./bcoin/ec');
|
||||||
bcoin.lru = require('./bcoin/lru');
|
bcoin.lru = require('./bcoin/lru');
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
@ -16,8 +15,6 @@ var network = bcoin.protocol.network;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function AbstractBlock(data) {
|
function AbstractBlock(data) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!(this instanceof AbstractBlock))
|
if (!(this instanceof AbstractBlock))
|
||||||
return new AbstractBlock(data);
|
return new AbstractBlock(data);
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
@ -23,8 +21,6 @@ function Address(options) {
|
|||||||
if (options instanceof Address)
|
if (options instanceof Address)
|
||||||
return options;
|
return options;
|
||||||
|
|
||||||
EventEmitter.call(this);
|
|
||||||
|
|
||||||
if (!options)
|
if (!options)
|
||||||
options = {};
|
options = {};
|
||||||
|
|
||||||
@ -59,8 +55,6 @@ function Address(options) {
|
|||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(Address, EventEmitter);
|
|
||||||
|
|
||||||
Address.prototype.getID = function getID() {
|
Address.prototype.getID = function getID() {
|
||||||
return this.getKeyAddress();
|
return this.getKeyAddress();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -366,9 +366,9 @@ Block.prototype.toCompact = function toCompact() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Block.fromCompact = function fromCompact(buf) {
|
Block.fromCompact = function fromCompact(buf) {
|
||||||
var tx, txCount, i;
|
|
||||||
var off = 0;
|
var off = 0;
|
||||||
var hashes = [];
|
var hashes = [];
|
||||||
|
var i;
|
||||||
|
|
||||||
var version = utils.read32(buf, 0);
|
var version = utils.read32(buf, 0);
|
||||||
var prevBlock = buf.slice(4, 36);
|
var prevBlock = buf.slice(4, 36);
|
||||||
|
|||||||
@ -1,98 +0,0 @@
|
|||||||
/**
|
|
||||||
* bn.js - signed big numbers for bcoin
|
|
||||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
|
||||||
* https://github.com/indutny/bcoin
|
|
||||||
*/
|
|
||||||
|
|
||||||
var bn = require('bn.js');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Signed Big Numbers
|
|
||||||
*/
|
|
||||||
|
|
||||||
function bn2(number, signed, base, endian) {
|
|
||||||
if (!(this instanceof bn2))
|
|
||||||
return new bn2(number, signed, base, endian);
|
|
||||||
|
|
||||||
if (typeof signed !== 'boolean') {
|
|
||||||
endian = base;
|
|
||||||
base = signed;
|
|
||||||
signed = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.__signed = !!signed;
|
|
||||||
|
|
||||||
return bn.call(this, number, base, endian);
|
|
||||||
}
|
|
||||||
|
|
||||||
bn2.prototype.__proto__ = bn.prototype;
|
|
||||||
|
|
||||||
bn2.prototype._initArray = function _initArray(number, base, endian) {
|
|
||||||
var i = 0;
|
|
||||||
var ret;
|
|
||||||
|
|
||||||
if (!this.__signed)
|
|
||||||
return bn.prototype._initArray.apply(this, arguments);
|
|
||||||
|
|
||||||
if (endian === 'le')
|
|
||||||
i = number.length - 1;
|
|
||||||
|
|
||||||
// If we are signed, do (~num + 1) to get
|
|
||||||
// the positive counterpart and set bn's
|
|
||||||
// negative flag.
|
|
||||||
if (number[i] & 0x80) {
|
|
||||||
if (isNegZero(number, endian)) {
|
|
||||||
ret = this._initNumber(0, 10, endian);
|
|
||||||
} else {
|
|
||||||
ret = bn.prototype._initArray.apply(this, arguments);
|
|
||||||
this.inotn(64).iaddn(1).ineg();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ret = bn.prototype._initArray.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
};
|
|
||||||
|
|
||||||
bn2.prototype.toArray = function toArray(endian, length) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!this.__signed)
|
|
||||||
return bn.prototype.toArray.apply(self, arguments);
|
|
||||||
|
|
||||||
// Convert the number to the
|
|
||||||
// negative byte representation.
|
|
||||||
if (self.isNeg()) {
|
|
||||||
if (self.cmpn(0) === 0)
|
|
||||||
self = new bn(0);
|
|
||||||
else
|
|
||||||
self = self.neg().notn(64).addn(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return bn.prototype.toArray.apply(self, arguments);
|
|
||||||
};
|
|
||||||
|
|
||||||
bn2.signed = function signed(number, base, endian) {
|
|
||||||
return new bn2(number, true, base, endian);
|
|
||||||
};
|
|
||||||
|
|
||||||
function isNegZero(number, endian) {
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
if (endian === 'le')
|
|
||||||
i = number.length - 1;
|
|
||||||
|
|
||||||
if (number[i] & 0x80) {
|
|
||||||
number = number.slice();
|
|
||||||
number[i] &= ~0x80;
|
|
||||||
return new bn(number, endian).cmpn(0) === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expose
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = bn2;
|
|
||||||
@ -28,9 +28,6 @@ function Chain(node, options) {
|
|||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
if (this.options.debug)
|
|
||||||
bcoin.debug = this.options.debug;
|
|
||||||
|
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.mempool = node.mempool;
|
this.mempool = node.mempool;
|
||||||
@ -68,7 +65,7 @@ Chain.prototype._init = function _init() {
|
|||||||
|
|
||||||
// Hook into events for debugging
|
// Hook into events for debugging
|
||||||
this.on('block', function(block, entry, peer) {
|
this.on('block', function(block, entry, peer) {
|
||||||
var host = peer ? peer.host : 'unknown';
|
// var host = peer ? peer.host : 'unknown';
|
||||||
// utils.debug('Block %s (%d) added to chain (%s)',
|
// utils.debug('Block %s (%d) added to chain (%s)',
|
||||||
// utils.revHex(entry.hash), entry.height, host);
|
// utils.revHex(entry.hash), entry.height, host);
|
||||||
});
|
});
|
||||||
@ -287,7 +284,7 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
stream.on('data', function(data) {
|
stream.on('data', function(data) {
|
||||||
var blocks = [];
|
var blocks = [];
|
||||||
var need = 80 - buf.size;
|
var need = 80 - buf.size;
|
||||||
var i, lastEntry;
|
var lastEntry;
|
||||||
|
|
||||||
while (data.length >= need) {
|
while (data.length >= need) {
|
||||||
buf.data.push(data.slice(0, need));
|
buf.data.push(data.slice(0, need));
|
||||||
@ -405,8 +402,8 @@ Chain.prototype._verifyContext = function _verifyContext(block, prev, callback)
|
|||||||
Chain.prototype._verify = function _verify(block, prev, callback) {
|
Chain.prototype._verify = function _verify(block, prev, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var flags = constants.flags.MANDATORY_VERIFY_FLAGS;
|
var flags = constants.flags.MANDATORY_VERIFY_FLAGS;
|
||||||
var height, ts, i, tx, cb, coinbaseHeight;
|
var height, ts, i, tx, coinbaseHeight;
|
||||||
var locktimeMedian, segwit, check;
|
var medianTime, locktimeMedian, segwit;
|
||||||
|
|
||||||
function done(err, result) {
|
function done(err, result) {
|
||||||
prev.free();
|
prev.free();
|
||||||
@ -591,7 +588,6 @@ Chain.prototype._checkDuplicates = function _checkDuplicates(block, prev, callba
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callback) {
|
Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callback) {
|
||||||
var self = this;
|
|
||||||
var height = prev.height + 1;
|
var height = prev.height + 1;
|
||||||
var scriptCheck = true;
|
var scriptCheck = true;
|
||||||
|
|
||||||
@ -609,7 +605,7 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.db.fillBlock(block, function(err) {
|
this.db.fillBlock(block, function(err) {
|
||||||
var i, j, input, hash;
|
var i, j, input, tx, hash;
|
||||||
var sigops = 0;
|
var sigops = 0;
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
@ -683,7 +679,7 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype._checkReward = function _checkReward(block) {
|
Chain.prototype._checkReward = function _checkReward(block) {
|
||||||
var claimed, actual;
|
var i, claimed, actual;
|
||||||
|
|
||||||
claimed = block.txs[0].getOutputValue();
|
claimed = block.txs[0].getOutputValue();
|
||||||
actual = bcoin.block.reward(block.height);
|
actual = bcoin.block.reward(block.height);
|
||||||
@ -750,7 +746,7 @@ Chain.prototype._findFork = function _findFork(fork, longer, callback) {
|
|||||||
})();
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype._reorganize = function _reorganize(entry, callback) {
|
Chain.prototype._reorganize = function _reorganize(entry, block, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return this._findFork(this.tip, entry, function(err, fork) {
|
return this._findFork(this.tip, entry, function(err, fork) {
|
||||||
@ -859,7 +855,7 @@ Chain.prototype._setBestChain = function _setBestChain(entry, block, callback) {
|
|||||||
} else if (entry.prevBlock === this.tip.hash) {
|
} else if (entry.prevBlock === this.tip.hash) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
self._reorganize(entry, done);
|
self._reorganize(entry, block, done);
|
||||||
}
|
}
|
||||||
|
|
||||||
function done(err) {
|
function done(err) {
|
||||||
@ -880,7 +876,6 @@ Chain.prototype._setBestChain = function _setBestChain(entry, block, callback) {
|
|||||||
|
|
||||||
Chain.prototype.reset = function reset(height, callback, force) {
|
Chain.prototype.reset = function reset(height, callback, force) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var chainHeight;
|
|
||||||
|
|
||||||
var unlock = this._lock(reset, [height, callback], force);
|
var unlock = this._lock(reset, [height, callback], force);
|
||||||
if (!unlock)
|
if (!unlock)
|
||||||
@ -956,7 +951,7 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
|
|||||||
(function next(block) {
|
(function next(block) {
|
||||||
var hash = block.hash('hex');
|
var hash = block.hash('hex');
|
||||||
var prevHash = block.prevBlock;
|
var prevHash = block.prevBlock;
|
||||||
var height, checkpoint, prev, orphan;
|
var height, checkpoint, orphan;
|
||||||
|
|
||||||
// We already have this block.
|
// We already have this block.
|
||||||
self.db.has(hash, function(err, existing) {
|
self.db.has(hash, function(err, existing) {
|
||||||
@ -1223,7 +1218,7 @@ Chain.prototype.pruneOrphans = function pruneOrphans(peer) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var best, last;
|
var best, last;
|
||||||
|
|
||||||
best = Object.keys(this.orphan.map).reduce(function(best, prevBlock, i) {
|
best = Object.keys(this.orphan.map).reduce(function(best, prevBlock) {
|
||||||
var orphan = self.orphan.map[prevBlock];
|
var orphan = self.orphan.map[prevBlock];
|
||||||
var height = orphan.getCoinbaseHeight();
|
var height = orphan.getCoinbaseHeight();
|
||||||
|
|
||||||
@ -1446,7 +1441,7 @@ Chain.prototype.getHashRange = function getHashRange(start, end, callback, force
|
|||||||
return done(err);
|
return done(err);
|
||||||
|
|
||||||
self.byTime(end, function(err, end) {
|
self.byTime(end, function(err, end) {
|
||||||
var hashes, i;
|
var hashes;
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return done(err);
|
return done(err);
|
||||||
@ -1562,7 +1557,6 @@ Chain.prototype.getLocator = function getLocator(start, callback, force) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
|
Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
|
||||||
var self = this;
|
|
||||||
var root;
|
var root;
|
||||||
|
|
||||||
if (Buffer.isBuffer(hash))
|
if (Buffer.isBuffer(hash))
|
||||||
@ -1595,8 +1589,8 @@ Chain.prototype.getCurrentTarget = function getCurrentTarget(callback) {
|
|||||||
Chain.prototype.getTargetAsync = function getTarget(last, block, callback) {
|
Chain.prototype.getTargetAsync = function getTarget(last, block, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var powLimit = utils.toCompact(network.powLimit);
|
var powLimit = utils.toCompact(network.powLimit);
|
||||||
var ts, first;
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
var ts;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
@ -1837,6 +1831,7 @@ Chain.prototype.getState = function getState(prev, block, id, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.computeBlockVersion = function computeBlockVersion(prev, callback) {
|
Chain.prototype.computeBlockVersion = function computeBlockVersion(prev, callback) {
|
||||||
|
var self = this;
|
||||||
var version = 0;
|
var version = 0;
|
||||||
|
|
||||||
utils.forEachSerial(Object.keys(network.deployments), function(id, next) {
|
utils.forEachSerial(Object.keys(network.deployments), function(id, next) {
|
||||||
|
|||||||
@ -12,7 +12,6 @@ var constants = bcoin.protocol.constants;
|
|||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var fs = bcoin.fs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ChainBlock
|
* ChainBlock
|
||||||
@ -83,7 +82,6 @@ ChainBlock.prototype.alloc = function alloc(max, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainBlock.prototype.getAncestors = function getAncestors(max, callback) {
|
ChainBlock.prototype.getAncestors = function getAncestors(max, callback) {
|
||||||
var self = this;
|
|
||||||
var entry = this;
|
var entry = this;
|
||||||
var ancestors = this.ancestors.slice();
|
var ancestors = this.ancestors.slice();
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
@ -210,7 +209,6 @@ ChainDB.prototype.getHash = function getHash(height, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype.dump = function dump(callback) {
|
ChainDB.prototype.dump = function dump(callback) {
|
||||||
var self = this;
|
|
||||||
var records = {};
|
var records = {};
|
||||||
|
|
||||||
var iter = this.db.db.iterator({
|
var iter = this.db.db.iterator({
|
||||||
@ -325,7 +323,7 @@ ChainDB.prototype._getEntry = function _getEntry(hash, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype.get = function get(height, callback, force) {
|
ChainDB.prototype.get = function get(height, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
@ -500,10 +498,10 @@ ChainDB.prototype.reset = function reset(block, callback) {
|
|||||||
|
|
||||||
(function next(err, tip) {
|
(function next(err, tip) {
|
||||||
if (err)
|
if (err)
|
||||||
return done(err);
|
return callback(err);
|
||||||
|
|
||||||
if (!tip)
|
if (!tip)
|
||||||
return done();
|
return callback();
|
||||||
|
|
||||||
batch = self.batch();
|
batch = self.batch();
|
||||||
|
|
||||||
@ -557,7 +555,7 @@ ChainDB.prototype.saveBlock = function saveBlock(block, batch, callback) {
|
|||||||
|
|
||||||
// batch.put('b/b/' + block.hash('hex'), block.toCompact());
|
// batch.put('b/b/' + block.hash('hex'), block.toCompact());
|
||||||
|
|
||||||
// block.txs.forEach(function(tx, i) {
|
// block.txs.forEach(function(tx) {
|
||||||
// batch.put('t/t/' + tx.hash('hex'), tx.toExtended());
|
// batch.put('t/t/' + tx.hash('hex'), tx.toExtended());
|
||||||
// });
|
// });
|
||||||
|
|
||||||
@ -579,7 +577,7 @@ ChainDB.prototype.removeBlock = function removeBlock(hash, batch, callback) {
|
|||||||
|
|
||||||
batch.del('b/b/' + block.hash('hex'));
|
batch.del('b/b/' + block.hash('hex'));
|
||||||
|
|
||||||
block.txs.forEach(function(tx, i) {
|
block.txs.forEach(function(tx) {
|
||||||
batch.del('t/t/' + tx.hash('hex'));
|
batch.del('t/t/' + tx.hash('hex'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -604,7 +602,7 @@ ChainDB.prototype.connectBlock = function connectBlock(block, batch, callback) {
|
|||||||
if (!block)
|
if (!block)
|
||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
block.txs.forEach(function(tx, i) {
|
block.txs.forEach(function(tx) {
|
||||||
var hash = tx.hash('hex');
|
var hash = tx.hash('hex');
|
||||||
var uniq = {};
|
var uniq = {};
|
||||||
|
|
||||||
@ -676,12 +674,12 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(hash, batch, callba
|
|||||||
if (typeof hash === 'string')
|
if (typeof hash === 'string')
|
||||||
assert(block.hash('hex') === hash);
|
assert(block.hash('hex') === hash);
|
||||||
|
|
||||||
block.txs.forEach(function(tx, i) {
|
block.txs.forEach(function(tx) {
|
||||||
var hash = tx.hash('hex');
|
var hash = tx.hash('hex');
|
||||||
var uniq = {};
|
var uniq = {};
|
||||||
|
|
||||||
tx.inputs.forEach(function(input) {
|
tx.inputs.forEach(function(input) {
|
||||||
var coin, address;
|
var address;
|
||||||
|
|
||||||
if (input.isCoinbase())
|
if (input.isCoinbase())
|
||||||
return;
|
return;
|
||||||
@ -906,7 +904,6 @@ ChainDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, opti
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype.getCoin = function getCoin(hash, index, callback) {
|
ChainDB.prototype.getCoin = function getCoin(hash, index, callback) {
|
||||||
var self = this;
|
|
||||||
var id = 'u/t/' + hash + '/' + index;
|
var id = 'u/t/' + hash + '/' + index;
|
||||||
var coin;
|
var coin;
|
||||||
|
|
||||||
@ -984,6 +981,9 @@ ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, options, c
|
|||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
if (err)
|
||||||
|
return callback(err);
|
||||||
|
|
||||||
utils.forEach(hashes, function(hash, next) {
|
utils.forEach(hashes, function(hash, next) {
|
||||||
self.getTX(hash, function(err, tx) {
|
self.getTX(hash, function(err, tx) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -1101,8 +1101,6 @@ ChainDB.prototype._getTXBlock = function _getTXBlock(hash, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype.fillBlock = function fillBlock(block, callback) {
|
ChainDB.prototype.fillBlock = function fillBlock(block, callback) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
return this.fillCoin(block.txs, function(err) {
|
return this.fillCoin(block.txs, function(err) {
|
||||||
var coins, i, tx, hash, j, input, id;
|
var coins, i, tx, hash, j, input, id;
|
||||||
|
|
||||||
@ -1133,8 +1131,6 @@ ChainDB.prototype.fillBlock = function fillBlock(block, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype.fillTXBlock = function fillTXBlock(block, callback) {
|
ChainDB.prototype.fillTXBlock = function fillTXBlock(block, callback) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
return this.fillTX(block.txs, function(err) {
|
return this.fillTX(block.txs, function(err) {
|
||||||
var coins, i, tx, hash, j, input, id;
|
var coins, i, tx, hash, j, input, id;
|
||||||
|
|
||||||
@ -1264,7 +1260,6 @@ ChainDB.prototype.isSpentTX = function isSpentTX(hash, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
|
ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
|
||||||
var self = this;
|
|
||||||
var futureHeight;
|
var futureHeight;
|
||||||
|
|
||||||
if (this.options.spv)
|
if (this.options.spv)
|
||||||
@ -1281,7 +1276,7 @@ ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
|
|||||||
|
|
||||||
batch.put('b/q/' + futureHeight, block.hash());
|
batch.put('b/q/' + futureHeight, block.hash());
|
||||||
|
|
||||||
block.txs.forEach(function(tx, i) {
|
block.txs.forEach(function(tx) {
|
||||||
tx.inputs.forEach(function(input) {
|
tx.inputs.forEach(function(input) {
|
||||||
if (input.isCoinbase())
|
if (input.isCoinbase())
|
||||||
return;
|
return;
|
||||||
@ -1343,7 +1338,6 @@ ChainDB.prototype._pruneQueue = function _pruneQueue(block, batch, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype._pruneCoinQueue = function _pruneQueue(block, batch, callback) {
|
ChainDB.prototype._pruneCoinQueue = function _pruneQueue(block, batch, callback) {
|
||||||
var self = this;
|
|
||||||
var iter = this.db.db.iterator({
|
var iter = this.db.db.iterator({
|
||||||
gte: 'u/q/' + pad32(block.height),
|
gte: 'u/q/' + pad32(block.height),
|
||||||
lte: 'u/q/' + pad32(block.height) + '~',
|
lte: 'u/q/' + pad32(block.height) + '~',
|
||||||
|
|||||||
@ -16,8 +16,6 @@ var network = bcoin.protocol.network;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function CompactBlock(data) {
|
function CompactBlock(data) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!(this instanceof CompactBlock))
|
if (!(this instanceof CompactBlock))
|
||||||
return new CompactBlock(data);
|
return new CompactBlock(data);
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var levelup = require('levelup');
|
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
@ -23,6 +22,8 @@ var NULL_CHUNK = new Buffer([0xff, 0xff, 0xff, 0xff]);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function DataStore(db, options) {
|
function DataStore(db, options) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (!(this instanceof DataStore))
|
if (!(this instanceof DataStore))
|
||||||
return new DataStore(db, options);
|
return new DataStore(db, options);
|
||||||
|
|
||||||
@ -196,7 +197,6 @@ DataStore.prototype.getLastIndex = function getLastIndex(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
DataStore.prototype.close = function close(callback) {
|
DataStore.prototype.close = function close(callback) {
|
||||||
var self = this;
|
|
||||||
return callback();
|
return callback();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -603,7 +603,7 @@ DataStore.prototype.read = function read(fd, offset, size, callback) {
|
|||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
assert(!(offset < 0 || offset == null))
|
assert(!(offset < 0 || offset == null));
|
||||||
|
|
||||||
data = new Buffer(size);
|
data = new Buffer(size);
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var elliptic = require('elliptic');
|
var elliptic = require('elliptic');
|
||||||
var bn = require('bn.js');
|
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var ec = exports;
|
var ec = exports;
|
||||||
|
|||||||
@ -10,7 +10,6 @@ var constants = bcoin.protocol.constants;
|
|||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var fs = bcoin.fs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fullnode
|
* Fullnode
|
||||||
@ -202,7 +201,6 @@ Fullnode.prototype.getFullBlock = function getFullBlock(hash, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Fullnode.prototype.getCoin = function getCoin(hash, index, callback) {
|
Fullnode.prototype.getCoin = function getCoin(hash, index, callback) {
|
||||||
var self = this;
|
|
||||||
var coin;
|
var coin;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
@ -246,7 +244,6 @@ Fullnode.prototype.getCoinByAddress = function getCoinByAddress(addresses, callb
|
|||||||
};
|
};
|
||||||
|
|
||||||
Fullnode.prototype.getTX = function getTX(hash, callback) {
|
Fullnode.prototype.getTX = function getTX(hash, callback) {
|
||||||
var self = this;
|
|
||||||
var tx;
|
var tx;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
@ -267,8 +264,6 @@ Fullnode.prototype.getTX = function getTX(hash, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Fullnode.prototype.isSpent = function isSpent(hash, index, callback) {
|
Fullnode.prototype.isSpent = function isSpent(hash, index, callback) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
if (this.mempool.isSpent(hash, index))
|
if (this.mempool.isSpent(hash, index))
|
||||||
@ -278,7 +273,6 @@ Fullnode.prototype.isSpent = function isSpent(hash, index, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Fullnode.prototype.getTXByAddress = function getTXByAddress(addresses, callback) {
|
Fullnode.prototype.getTXByAddress = function getTXByAddress(addresses, callback) {
|
||||||
var self = this;
|
|
||||||
var mempool;
|
var mempool;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|||||||
@ -52,14 +52,11 @@
|
|||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
var bn = require('bn.js');
|
||||||
var elliptic = require('elliptic');
|
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
|
||||||
|
|
||||||
var english = require('../../etc/english.json');
|
var english = require('../../etc/english.json');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,7 +78,7 @@ function HDSeed(options) {
|
|||||||
assert(this.bits % 8 === 0);
|
assert(this.bits % 8 === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
HDSeed.prototype.createSeed = function createSeed(passphrase) {
|
HDSeed.prototype.createSeed = function createSeed() {
|
||||||
if (this.seed)
|
if (this.seed)
|
||||||
return this.seed;
|
return this.seed;
|
||||||
|
|
||||||
@ -411,7 +408,7 @@ HDPrivateKey.prototype.scan45 = function scan45(options, txByAddress, callback)
|
|||||||
if (chainConstant === 0)
|
if (chainConstant === 0)
|
||||||
cosigners[cosignerIndex] = { addressDepth: addressIndex - gap };
|
cosigners[cosignerIndex] = { addressDepth: addressIndex - gap };
|
||||||
else
|
else
|
||||||
cosigners[cosginerIndex].changeDepth = addressIndex - gap;
|
cosigners[cosignerIndex].changeDepth = addressIndex - gap;
|
||||||
|
|
||||||
if (total === 0) {
|
if (total === 0) {
|
||||||
if (chainConstant === 0)
|
if (chainConstant === 0)
|
||||||
@ -426,7 +423,7 @@ HDPrivateKey.prototype.scan45 = function scan45(options, txByAddress, callback)
|
|||||||
})(0);
|
})(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
HDPrivateKey.prototype.derivePurpose45 = function derivePurpose45(options) {
|
HDPrivateKey.prototype.derivePurpose45 = function derivePurpose45() {
|
||||||
var child;
|
var child;
|
||||||
|
|
||||||
if (this instanceof HDPublicKey) {
|
if (this instanceof HDPublicKey) {
|
||||||
@ -476,13 +473,13 @@ HDPrivateKey.prototype.deriveCosignerAddress = function deriveCosignerAddress(co
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
HDPrivateKey.prototype.isPurpose45 = function isPurpose45(options) {
|
HDPrivateKey.prototype.isPurpose45 = function isPurpose45() {
|
||||||
if (utils.readU8(this.depth) !== 1)
|
if (utils.readU8(this.depth) !== 1)
|
||||||
return false;
|
return false;
|
||||||
return utils.readU32BE(this.childIndex) === constants.hd.hardened + 45;
|
return utils.readU32BE(this.childIndex) === constants.hd.hardened + 45;
|
||||||
};
|
};
|
||||||
|
|
||||||
HDPrivateKey.prototype.isAccount44 = function isAccount44(options) {
|
HDPrivateKey.prototype.isAccount44 = function isAccount44() {
|
||||||
if (utils.readU32BE(this.childIndex) < constants.hd.hardened)
|
if (utils.readU32BE(this.childIndex) < constants.hd.hardened)
|
||||||
return false;
|
return false;
|
||||||
return utils.readU8(this.depth) === 3;
|
return utils.readU8(this.depth) === 3;
|
||||||
@ -827,14 +824,14 @@ HDPrivateKey.isValidPath = function isValidPath(path, hardened) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
HDPrivateKey.prototype.derivePath = function derivePath(path) {
|
HDPrivateKey.prototype.derivePath = function derivePath(path) {
|
||||||
var indexes, child;
|
var indexes;
|
||||||
|
|
||||||
if (!HDPrivateKey.isValidPath(path))
|
if (!HDPrivateKey.isValidPath(path))
|
||||||
throw new Error('invalid path');
|
throw new Error('invalid path');
|
||||||
|
|
||||||
indexes = HDPrivateKey._getIndexes(path);
|
indexes = HDPrivateKey._getIndexes(path);
|
||||||
|
|
||||||
return indexes.reduce(function(prev, index, i) {
|
return indexes.reduce(function(prev, index) {
|
||||||
return prev.derive(index);
|
return prev.derive(index);
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
@ -23,7 +22,7 @@ function Headers(data) {
|
|||||||
|
|
||||||
bcoin.abstractblock.call(this, data);
|
bcoin.abstractblock.call(this, data);
|
||||||
|
|
||||||
this.type = 'headers'
|
this.type = 'headers';
|
||||||
|
|
||||||
if (!this._raw)
|
if (!this._raw)
|
||||||
this._raw = this.render();
|
this._raw = this.render();
|
||||||
|
|||||||
@ -82,11 +82,11 @@ Client.prototype.unlistenWallet = function unlistenWallet(id) {
|
|||||||
this.socket.leave(id);
|
this.socket.leave(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.listenAll = function listenAll(id) {
|
Client.prototype.listenAll = function listenAll() {
|
||||||
this.listenWallet('!all');
|
this.listenWallet('!all');
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.unlistenAll = function unlistenAll(id) {
|
Client.prototype.unlistenAll = function unlistenAll() {
|
||||||
this.unlistenWallet('!all');
|
this.unlistenWallet('!all');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -206,6 +206,7 @@ Client.prototype.getWalletBalance = function getBalance(id, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.getWalletLast = function getLast(id, limit, callback) {
|
Client.prototype.getWalletLast = function getLast(id, limit, callback) {
|
||||||
|
var options = { limit: limit };
|
||||||
return this._get('/wallet/' + id + '/tx/last', options, function(err, body) {
|
return this._get('/wallet/' + id + '/tx/last', options, function(err, body) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@ -262,8 +263,6 @@ Client.prototype.getWalletCoin = function getCoin(id, hash, index, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.syncWallet = function syncWallet(id, options, callback) {
|
Client.prototype.syncWallet = function syncWallet(id, options, callback) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
var body = {
|
var body = {
|
||||||
receiveDepth: options.receiveDepth,
|
receiveDepth: options.receiveDepth,
|
||||||
changeDepth: options.changeDepth
|
changeDepth: options.changeDepth
|
||||||
@ -356,7 +355,7 @@ Client.prototype.broadcast = function broadcast(tx, callback) {
|
|||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
return this._post('/broadcast', body, function(err, body) {
|
return this._post('/broadcast', body, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
return callback();
|
return callback();
|
||||||
|
|||||||
@ -13,8 +13,6 @@ var utils = bcoin.utils;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function HTTPServer(options) {
|
function HTTPServer(options) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!(this instanceof HTTPServer))
|
if (!(this instanceof HTTPServer))
|
||||||
return new HTTPServer(options);
|
return new HTTPServer(options);
|
||||||
|
|
||||||
@ -50,6 +48,8 @@ HTTPServer.prototype._init = function _init() {
|
|||||||
|
|
||||||
this.server.on('connection', function(socket) {
|
this.server.on('connection', function(socket) {
|
||||||
socket.on('error', function(err) {
|
socket.on('error', function(err) {
|
||||||
|
self.emit('error', err);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
@ -112,6 +111,7 @@ Provider.prototype.fillCoin = function fillCoin(tx, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Provider.prototype.sync = function sync(wallet, address) {
|
Provider.prototype.sync = function sync(wallet, address) {
|
||||||
|
var self = this;
|
||||||
return this.client.syncWallet(this.id, wallet, function(err) {
|
return this.client.syncWallet(this.id, wallet, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
self.emit('error', err);
|
self.emit('error', err);
|
||||||
@ -122,4 +122,4 @@ Provider.prototype.sync = function sync(wallet, address) {
|
|||||||
* Expose
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = WalletDB;
|
module.exports = Provider;
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var Stream = require('stream').Stream;
|
var Stream = require('stream').Stream;
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
// Spoof by default
|
// Spoof by default
|
||||||
var USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1)'
|
var USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1)'
|
||||||
@ -15,7 +16,6 @@ var USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1)'
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function request(options, callback, stream) {
|
function request(options, callback, stream) {
|
||||||
var StringDecoder = require('string_decoder').StringDecoder;
|
|
||||||
var qs = require('querystring');
|
var qs = require('querystring');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ function request(options, callback, stream) {
|
|||||||
var json = options.json;
|
var json = options.json;
|
||||||
var form = options.form;
|
var form = options.form;
|
||||||
var type = options.type;
|
var type = options.type;
|
||||||
var http, req, stream, opt;
|
var http, req, opt;
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
return request._buffer(options, callback);
|
return request._buffer(options, callback);
|
||||||
@ -203,6 +203,8 @@ function request(options, callback, stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request._buffer = function(options, callback) {
|
request._buffer = function(options, callback) {
|
||||||
|
var qs = require('querystring');
|
||||||
|
var StringDecoder = require('string_decoder').StringDecoder;
|
||||||
var stream = request(options);
|
var stream = request(options);
|
||||||
var total = 0;
|
var total = 0;
|
||||||
var called = false;
|
var called = false;
|
||||||
|
|||||||
@ -17,8 +17,6 @@ var assert = utils.assert;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function NodeServer(node, options) {
|
function NodeServer(node, options) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!options)
|
if (!options)
|
||||||
options = {};
|
options = {};
|
||||||
|
|
||||||
@ -254,9 +252,6 @@ NodeServer.prototype._init = function _init() {
|
|||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
if (!json)
|
|
||||||
return send(404);
|
|
||||||
|
|
||||||
send(200, { success: true });
|
send(200, { success: true });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -267,7 +262,7 @@ NodeServer.prototype._init = function _init() {
|
|||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
if (!coins.length)
|
if (!balance)
|
||||||
return send(404);
|
return send(404);
|
||||||
|
|
||||||
send(200, { balance: utils.btc(balance) });
|
send(200, { balance: utils.btc(balance) });
|
||||||
@ -380,6 +375,8 @@ NodeServer.prototype._init = function _init() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
NodeServer.prototype._initIO = function _initIO() {
|
NodeServer.prototype._initIO = function _initIO() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (!this.server.io)
|
if (!this.server.io)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
* https://github.com/indutny/bcoin
|
* https://github.com/indutny/bcoin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var bn = require('bn.js');
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
@ -70,7 +69,7 @@ Input.prototype.getType = function getType() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Input.prototype.getRedeem = function getRedeem() {
|
Input.prototype.getRedeem = function getRedeem() {
|
||||||
var type;
|
var type, redeem;
|
||||||
|
|
||||||
if (this.isCoinbase())
|
if (this.isCoinbase())
|
||||||
return;
|
return;
|
||||||
@ -137,7 +136,7 @@ Input.prototype.isFinal = function isFinal() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Input.prototype.getLocktime = function getLocktime() {
|
Input.prototype.getLocktime = function getLocktime() {
|
||||||
var output, redeem, lock, type;
|
var output, redeem;
|
||||||
|
|
||||||
assert(this.output);
|
assert(this.output);
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
@ -91,7 +90,6 @@ KeyPair.prototype.toSecret = function toSecret() {
|
|||||||
KeyPair.toSecret = function toSecret(privateKey, compressed) {
|
KeyPair.toSecret = function toSecret(privateKey, compressed) {
|
||||||
var buf = new Buffer(1 + privateKey.length + (compressed ? 1 : 0) + 4);
|
var buf = new Buffer(1 + privateKey.length + (compressed ? 1 : 0) + 4);
|
||||||
var off = 0;
|
var off = 0;
|
||||||
var chk;
|
|
||||||
|
|
||||||
off += utils.writeU8(buf, network.prefixes.privkey, 0);
|
off += utils.writeU8(buf, network.prefixes.privkey, 0);
|
||||||
off += utils.copy(privateKey, buf, off);
|
off += utils.copy(privateKey, buf, off);
|
||||||
|
|||||||
@ -218,7 +218,7 @@ LRU.prototype._removeList = function removeList(item) {
|
|||||||
if (item === this.head)
|
if (item === this.head)
|
||||||
this.head = item.next;
|
this.head = item.next;
|
||||||
|
|
||||||
if (item == this.tail)
|
if (item === this.tail)
|
||||||
this.tail = item.prev || this.head;
|
this.tail = item.prev || this.head;
|
||||||
|
|
||||||
if (!this.head)
|
if (!this.head)
|
||||||
|
|||||||
@ -12,7 +12,6 @@ var constants = bcoin.protocol.constants;
|
|||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var fs = bcoin.fs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mempool
|
* Mempool
|
||||||
@ -171,7 +170,7 @@ Mempool.prototype.fillTX = function fillTX(tx) {
|
|||||||
return total === tx.inputs.length;
|
return total === tx.inputs.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
Mempool.prototype.getAll = function getAll(hash) {
|
Mempool.prototype.getAll = function getAll() {
|
||||||
return Object.keys(this.txs).map(function(key) {
|
return Object.keys(this.txs).map(function(key) {
|
||||||
return this.txs[key];
|
return this.txs[key];
|
||||||
}, this);
|
}, this);
|
||||||
@ -215,7 +214,7 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback) {
|
|||||||
this._lockTX(tx);
|
this._lockTX(tx);
|
||||||
|
|
||||||
this.chain.fillCoin(tx, function(err) {
|
this.chain.fillCoin(tx, function(err) {
|
||||||
var i, input, dup, height, ts, priority;
|
var i, input, output, dup, height, ts, priority;
|
||||||
|
|
||||||
self._unlockTX(tx);
|
self._unlockTX(tx);
|
||||||
|
|
||||||
@ -402,7 +401,7 @@ Mempool.prototype._unlockTX = function _unlockTX(tx) {
|
|||||||
Mempool.prototype.remove =
|
Mempool.prototype.remove =
|
||||||
Mempool.prototype.removeTX = function removeTX(hash, callback) {
|
Mempool.prototype.removeTX = function removeTX(hash, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var tx, input, id;
|
var tx, input, id, i;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
@ -21,7 +20,7 @@ function MerkleBlock(data) {
|
|||||||
|
|
||||||
bcoin.abstractblock.call(this, data);
|
bcoin.abstractblock.call(this, data);
|
||||||
|
|
||||||
this.type = 'merkleblock'
|
this.type = 'merkleblock';
|
||||||
|
|
||||||
this.hashes = (data.hashes || []).map(function(hash) {
|
this.hashes = (data.hashes || []).map(function(hash) {
|
||||||
return utils.toHex(hash);
|
return utils.toHex(hash);
|
||||||
@ -51,7 +50,6 @@ MerkleBlock.prototype.hasTX = function hasTX(hash) {
|
|||||||
MerkleBlock.prototype._verifyPartial = function _verifyPartial() {
|
MerkleBlock.prototype._verifyPartial = function _verifyPartial() {
|
||||||
var height = 0;
|
var height = 0;
|
||||||
var tx = [];
|
var tx = [];
|
||||||
var i = 0;
|
|
||||||
var j = 0;
|
var j = 0;
|
||||||
var hashes = this.hashes;
|
var hashes = this.hashes;
|
||||||
var flags = this.flags;
|
var flags = this.flags;
|
||||||
|
|||||||
@ -199,7 +199,7 @@ Miner.prototype.addTX = function addTX(tx) {
|
|||||||
this.updateMerkle();
|
this.updateMerkle();
|
||||||
};
|
};
|
||||||
|
|
||||||
Miner.prototype.createBlock = function createBlock(tx) {
|
Miner.prototype.createBlock = function createBlock() {
|
||||||
var ts, target, coinbase, headers, block;
|
var ts, target, coinbase, headers, block;
|
||||||
|
|
||||||
ts = Math.max(utils.now(), this.last.ts + 1);
|
ts = Math.max(utils.now(), this.last.ts + 1);
|
||||||
@ -292,7 +292,7 @@ Miner.prototype.iterate = function iterate() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.timeout = setTimeout(function() {
|
this.timeout = setTimeout(function() {
|
||||||
var hash;
|
var hash, res;
|
||||||
|
|
||||||
// Try to find a block: do one iteration of extraNonce
|
// Try to find a block: do one iteration of extraNonce
|
||||||
if (!self.findNonce())
|
if (!self.findNonce())
|
||||||
|
|||||||
@ -72,7 +72,7 @@ MTX.prototype.hash = function hash(enc) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MTX.prototype.witnessHash = function witnessHash(enc) {
|
MTX.prototype.witnessHash = function witnessHash(enc) {
|
||||||
var raw, hash;
|
var hash;
|
||||||
|
|
||||||
if (this.isCoinbase()) {
|
if (this.isCoinbase()) {
|
||||||
return enc === 'hex'
|
return enc === 'hex'
|
||||||
@ -121,7 +121,7 @@ MTX.prototype.getVirtualSize = function getVirtualSize() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MTX.prototype.addInput = function addInput(options, index) {
|
MTX.prototype.addInput = function addInput(options, index) {
|
||||||
var input, i;
|
var input;
|
||||||
|
|
||||||
if (options instanceof MTX)
|
if (options instanceof MTX)
|
||||||
options = bcoin.coin(options, index);
|
options = bcoin.coin(options, index);
|
||||||
@ -776,7 +776,6 @@ MTX.prototype.maxSize = function maxSize(maxM, maxN) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MTX.prototype.selectCoins = function selectCoins(unspent, options) {
|
MTX.prototype.selectCoins = function selectCoins(unspent, options) {
|
||||||
var self = this;
|
|
||||||
var tx = this.clone();
|
var tx = this.clone();
|
||||||
var outputValue = tx.getOutputValue();
|
var outputValue = tx.getOutputValue();
|
||||||
var totalkb = 1;
|
var totalkb = 1;
|
||||||
@ -803,7 +802,7 @@ MTX.prototype.selectCoins = function selectCoins(unspent, options) {
|
|||||||
});
|
});
|
||||||
} else if (options.selection === 'random' || options.selection === 'all') {
|
} else if (options.selection === 'random' || options.selection === 'all') {
|
||||||
// Random unspents
|
// Random unspents
|
||||||
unspent = unspent.slice().sort(function(a, b) {
|
unspent = unspent.slice().sort(function() {
|
||||||
return Math.random() > 0.5 ? 1 : -1;
|
return Math.random() > 0.5 ? 1 : -1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,12 +6,10 @@
|
|||||||
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var fs = bcoin.fs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node
|
* Node
|
||||||
@ -29,7 +27,7 @@ function Node(options) {
|
|||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
if (this.options.debug != null)
|
if (this.options.debug != null)
|
||||||
bcoin.debug = this.options.debug;
|
bcoin.debugLogs = this.options.debug;
|
||||||
|
|
||||||
if (this.options.debugFile != null)
|
if (this.options.debugFile != null)
|
||||||
bcoin.debugFile = this.options.debugFile;
|
bcoin.debugFile = this.options.debugFile;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ function Output(options, tx) {
|
|||||||
// For safety: do not allow usage of
|
// For safety: do not allow usage of
|
||||||
// Numbers, do not allow negative values.
|
// Numbers, do not allow negative values.
|
||||||
assert(typeof value !== 'number');
|
assert(typeof value !== 'number');
|
||||||
assert(!this.value.isNeg())
|
assert(!this.value.isNeg());
|
||||||
assert(this.value.bitLength() <= 63);
|
assert(this.value.bitLength() <= 63);
|
||||||
assert(!(this.value.toArray('be', 8)[0] & 0x80));
|
assert(!(this.value.toArray('be', 8)[0] & 0x80));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,8 +18,6 @@ var network = bcoin.protocol.network;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function Peer(pool, options) {
|
function Peer(pool, options) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!(this instanceof Peer))
|
if (!(this instanceof Peer))
|
||||||
return new Peer(pool, options);
|
return new Peer(pool, options);
|
||||||
|
|
||||||
@ -181,7 +179,7 @@ Peer.prototype._init = function init() {
|
|||||||
|
|
||||||
Peer.prototype.createSocket = function createSocket(port, host) {
|
Peer.prototype.createSocket = function createSocket(port, host) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var net, socket;
|
var socket;
|
||||||
|
|
||||||
assert(port != null);
|
assert(port != null);
|
||||||
assert(host);
|
assert(host);
|
||||||
@ -299,8 +297,6 @@ Peer.prototype.destroy = function destroy() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype._write = function write(chunk) {
|
Peer.prototype._write = function write(chunk) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -597,17 +593,17 @@ Peer.prototype._handleGetAddr = function handleGetAddr() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype._handleInv = function handleInv(items) {
|
Peer.prototype._handleInv = function handleInv(items) {
|
||||||
var req, i, block, hash;
|
var blocks, txs;
|
||||||
|
|
||||||
this.emit('inv', items);
|
this.emit('inv', items);
|
||||||
|
|
||||||
// Always request advertised TXs
|
// Always request advertised TXs
|
||||||
var txs = items.filter(function(item) {
|
txs = items.filter(function(item) {
|
||||||
return item.type === 'tx';
|
return item.type === 'tx';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Emit new blocks to schedule them between multiple peers
|
// Emit new blocks to schedule them between multiple peers
|
||||||
var blocks = items.filter(function(item) {
|
blocks = items.filter(function(item) {
|
||||||
return item.type === 'block';
|
return item.type === 'block';
|
||||||
}, this).map(function(item) {
|
}, this).map(function(item) {
|
||||||
return item.hash;
|
return item.hash;
|
||||||
|
|||||||
@ -18,7 +18,6 @@ var constants = bcoin.protocol.constants;
|
|||||||
|
|
||||||
function Pool(node, options) {
|
function Pool(node, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var Chain;
|
|
||||||
|
|
||||||
if (!(this instanceof Pool))
|
if (!(this instanceof Pool))
|
||||||
return new Pool(node, options);
|
return new Pool(node, options);
|
||||||
@ -201,8 +200,6 @@ Pool.prototype._init = function _init() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.chain.on('orphan', function(block, data, peer) {
|
this.chain.on('orphan', function(block, data, peer) {
|
||||||
var host = peer ? peer.host : 'unknown';
|
|
||||||
|
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -231,8 +228,6 @@ Pool.prototype._init = function _init() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.getBlocks = function getBlocks(peer, top, stop, callback) {
|
Pool.prototype.getBlocks = function getBlocks(peer, top, stop, callback) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
this.chain.getLocator(top, function(err, locator) {
|
this.chain.getLocator(top, function(err, locator) {
|
||||||
@ -283,8 +278,6 @@ Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan, callbac
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.getHeaders = function getHeaders(peer, top, stop, callback) {
|
Pool.prototype.getHeaders = function getHeaders(peer, top, stop, callback) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
this.chain.getLocator(top, function(err, locator) {
|
this.chain.getLocator(top, function(err, locator) {
|
||||||
@ -566,7 +559,7 @@ Pool.prototype._handleHeaders = function _handleHeaders(headers, peer, callback)
|
|||||||
this._startInterval();
|
this._startInterval();
|
||||||
|
|
||||||
utils.forEachSerial(headers, function(header, next) {
|
utils.forEachSerial(headers, function(header, next) {
|
||||||
hash = header.hash('hex');
|
var hash = header.hash('hex');
|
||||||
|
|
||||||
if (last && header.prevBlock !== last)
|
if (last && header.prevBlock !== last)
|
||||||
return next(new Error('Bad header chain.'));
|
return next(new Error('Bad header chain.'));
|
||||||
@ -754,9 +747,6 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype._load = function _load() {
|
Pool.prototype._load = function _load() {
|
||||||
var self = this;
|
|
||||||
var next;
|
|
||||||
|
|
||||||
if (!this.syncing)
|
if (!this.syncing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -904,6 +894,7 @@ Pool.prototype._handleTX = function _handleTX(tx, peer, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype._addLeech = function _addLeech(socket) {
|
Pool.prototype._addLeech = function _addLeech(socket) {
|
||||||
|
var self = this;
|
||||||
var peer;
|
var peer;
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
@ -927,8 +918,6 @@ Pool.prototype._addLeech = function _addLeech(socket) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
peer.once('ack', function() {
|
peer.once('ack', function() {
|
||||||
var i;
|
|
||||||
|
|
||||||
if (self.destroyed)
|
if (self.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1201,7 +1190,7 @@ Pool.prototype.unwatch = function unwatch(id) {
|
|||||||
// See "Filter matching algorithm":
|
// See "Filter matching algorithm":
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki
|
||||||
Pool.prototype.isWatched = function(tx, bloom) {
|
Pool.prototype.isWatched = function(tx, bloom) {
|
||||||
var i, input, output;
|
var i, prev, input, output;
|
||||||
|
|
||||||
if (!bloom)
|
if (!bloom)
|
||||||
bloom = this.bloom;
|
bloom = this.bloom;
|
||||||
@ -1314,7 +1303,6 @@ Pool.prototype.unwatchWallet = function unwatchWallet(wallet) {
|
|||||||
|
|
||||||
Pool.prototype.searchWallet = function(wallet, callback) {
|
Pool.prototype.searchWallet = function(wallet, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var wallet;
|
|
||||||
|
|
||||||
assert(!this.loading);
|
assert(!this.loading);
|
||||||
|
|
||||||
@ -1560,7 +1548,7 @@ Pool.prototype._sendRequests = function _sendRequests(peer) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.fulfill = function fulfill(hash) {
|
Pool.prototype.fulfill = function fulfill(hash) {
|
||||||
var hash;
|
var item;
|
||||||
|
|
||||||
if (Buffer.isBuffer(hash))
|
if (Buffer.isBuffer(hash))
|
||||||
hash = utils.toHex(hash);
|
hash = utils.toHex(hash);
|
||||||
@ -1848,7 +1836,7 @@ Pool.prototype.addSeed = function addSeed(seed) {
|
|||||||
|
|
||||||
this.seeds.push({
|
this.seeds.push({
|
||||||
host: seed.host,
|
host: seed.host,
|
||||||
port: seed.port
|
port: seed.port || bcoin.protocol.network.port
|
||||||
});
|
});
|
||||||
|
|
||||||
this.hosts[seed.host] = true;
|
this.hosts[seed.host] = true;
|
||||||
@ -1857,6 +1845,8 @@ Pool.prototype.addSeed = function addSeed(seed) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.removeSeed = function removeSeed(seed) {
|
Pool.prototype.removeSeed = function removeSeed(seed) {
|
||||||
|
var i;
|
||||||
|
|
||||||
seed = utils.parseHost(seed);
|
seed = utils.parseHost(seed);
|
||||||
|
|
||||||
if (this.hosts[seed.host] == null)
|
if (this.hosts[seed.host] == null)
|
||||||
|
|||||||
@ -168,7 +168,7 @@ exports.snapshot = function snapshot(name, callback) {
|
|||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bcoin.debug) {
|
if (bcoin.debugLogs) {
|
||||||
mem = process.memoryUsage();
|
mem = process.memoryUsage();
|
||||||
utils.debug('Memory: rss=%dmb, js-heap=%d/%dmb native-heap=%dmb',
|
utils.debug('Memory: rss=%dmb, js-heap=%d/%dmb native-heap=%dmb',
|
||||||
utils.mb(mem.rss),
|
utils.mb(mem.rss),
|
||||||
|
|||||||
@ -4,9 +4,7 @@
|
|||||||
* https://github.com/indutny/bcoin
|
* https://github.com/indutny/bcoin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = require('../../bcoin');
|
|
||||||
var bn = require('bn.js');
|
var bn = require('bn.js');
|
||||||
var utils = bcoin.utils;
|
|
||||||
|
|
||||||
exports.minVersion = 70001;
|
exports.minVersion = 70001;
|
||||||
exports.version = 70002;
|
exports.version = 70002;
|
||||||
|
|||||||
@ -192,7 +192,6 @@ Framer.address = function address(data, full, writer) {
|
|||||||
|
|
||||||
Framer.version = function version(options, writer) {
|
Framer.version = function version(options, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
var i, remote, local;
|
|
||||||
|
|
||||||
if (!options.agent)
|
if (!options.agent)
|
||||||
options.agent = new Buffer(constants.userAgent, 'ascii');
|
options.agent = new Buffer(constants.userAgent, 'ascii');
|
||||||
@ -231,8 +230,7 @@ Framer.verack = function verack() {
|
|||||||
|
|
||||||
Framer._inv = function _inv(items, writer) {
|
Framer._inv = function _inv(items, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
var i, hash;
|
var i;
|
||||||
var off = 0;
|
|
||||||
|
|
||||||
assert(items.length <= 50000);
|
assert(items.length <= 50000);
|
||||||
|
|
||||||
@ -430,6 +428,7 @@ Framer.btx = function _tx(tx) {
|
|||||||
|
|
||||||
Framer.tx = function _tx(tx, writer) {
|
Framer.tx = function _tx(tx, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
|
var i;
|
||||||
|
|
||||||
p.write32(tx.version);
|
p.write32(tx.version);
|
||||||
|
|
||||||
@ -482,6 +481,7 @@ Framer.output = function _output(output, writer) {
|
|||||||
Framer.witnessTX = function _witnessTX(tx, writer) {
|
Framer.witnessTX = function _witnessTX(tx, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
var witnessSize = 0;
|
var witnessSize = 0;
|
||||||
|
var i;
|
||||||
|
|
||||||
p.write32(tx.version);
|
p.write32(tx.version);
|
||||||
p.writeU8(0);
|
p.writeU8(0);
|
||||||
@ -518,11 +518,12 @@ Framer.witnessBlockSize = function witnessBlockSize(block) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Framer.witnessTXSize = function witnessTXSize(tx) {
|
Framer.witnessTXSize = function witnessTXSize(tx) {
|
||||||
return Framer.witnessTXSize(block, new BufferWriter())._witnessSize;
|
return Framer.witnessTXSize(tx, new BufferWriter())._witnessSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
Framer.witness = function _witness(witness, writer) {
|
Framer.witness = function _witness(witness, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
|
var i;
|
||||||
|
|
||||||
p.writeUIntv(witness.items.length);
|
p.writeUIntv(witness.items.length);
|
||||||
|
|
||||||
@ -545,6 +546,7 @@ Framer.witnessBlock = function _witnessBlock(block, writer) {
|
|||||||
|
|
||||||
Framer.renderTX = function renderTX(tx, useWitness, writer) {
|
Framer.renderTX = function renderTX(tx, useWitness, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
|
var witnessSize;
|
||||||
|
|
||||||
if (tx._raw) {
|
if (tx._raw) {
|
||||||
if (!useWitness && bcoin.protocol.parser.isWitnessTX(tx._raw)) {
|
if (!useWitness && bcoin.protocol.parser.isWitnessTX(tx._raw)) {
|
||||||
@ -573,7 +575,7 @@ Framer.renderTX = function renderTX(tx, useWitness, writer) {
|
|||||||
Framer._block = function _block(block, useWitness, writer) {
|
Framer._block = function _block(block, useWitness, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
var witnessSize = 0;
|
var witnessSize = 0;
|
||||||
var i, tx;
|
var i;
|
||||||
|
|
||||||
p.write32(block.version);
|
p.write32(block.version);
|
||||||
p.writeHash(block.prevBlock);
|
p.writeHash(block.prevBlock);
|
||||||
@ -598,6 +600,7 @@ Framer._block = function _block(block, useWitness, writer) {
|
|||||||
|
|
||||||
Framer.merkleBlock = function _merkleBlock(block, writer) {
|
Framer.merkleBlock = function _merkleBlock(block, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
|
var i;
|
||||||
|
|
||||||
p.write32(block.version);
|
p.write32(block.version);
|
||||||
p.writeHash(block.prevBlock);
|
p.writeHash(block.prevBlock);
|
||||||
@ -622,7 +625,6 @@ Framer.merkleBlock = function _merkleBlock(block, writer) {
|
|||||||
|
|
||||||
Framer.headers = function _headers(block, writer) {
|
Framer.headers = function _headers(block, writer) {
|
||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
var i;
|
|
||||||
|
|
||||||
p.write32(block.version);
|
p.write32(block.version);
|
||||||
p.writeHash(block.prevBlock);
|
p.writeHash(block.prevBlock);
|
||||||
@ -642,7 +644,7 @@ Framer.reject = function reject(details, writer) {
|
|||||||
var p = new BufferWriter(writer);
|
var p = new BufferWriter(writer);
|
||||||
|
|
||||||
p.writeVarString(details.message || '', 'ascii');
|
p.writeVarString(details.message || '', 'ascii');
|
||||||
p.writeU8(ccode, off);
|
p.writeU8(detals.ccode || constants.reject.malformed);
|
||||||
p.writeVarString(details.reason || '', 'ascii');
|
p.writeVarString(details.reason || '', 'ascii');
|
||||||
if (details.data)
|
if (details.data)
|
||||||
p.writeBytes(details.data);
|
p.writeBytes(details.data);
|
||||||
@ -694,7 +696,7 @@ function BufferWriter(options) {
|
|||||||
BufferWriter.prototype.render = function render() {
|
BufferWriter.prototype.render = function render() {
|
||||||
var data = new Buffer(this.written);
|
var data = new Buffer(this.written);
|
||||||
var off = 0;
|
var off = 0;
|
||||||
var i;
|
var i, item;
|
||||||
|
|
||||||
for (i = 0; i < this.data.length; i++) {
|
for (i = 0; i < this.data.length; i++) {
|
||||||
item = this.data[i];
|
item = this.data[i];
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var bn = require('bn.js');
|
|
||||||
|
|
||||||
var bcoin = require('../../bcoin');
|
var bcoin = require('../../bcoin');
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
@ -355,7 +354,7 @@ Parser.parseBlock = function parseBlock(p) {
|
|||||||
Parser.parseBlockCompact = function parseBlockCompact(p) {
|
Parser.parseBlockCompact = function parseBlockCompact(p) {
|
||||||
var height = -1;
|
var height = -1;
|
||||||
var version, prevBlock, merkleRoot, ts, bits, nonce;
|
var version, prevBlock, merkleRoot, ts, bits, nonce;
|
||||||
var i, totalTX, tx;
|
var totalTX;
|
||||||
var inCount, input, raw;
|
var inCount, input, raw;
|
||||||
|
|
||||||
p = new BufferReader(p);
|
p = new BufferReader(p);
|
||||||
@ -601,7 +600,7 @@ Parser.parseWitnessTX = function parseWitnessTX(p) {
|
|||||||
|
|
||||||
Parser.parseWitness = function parseWitness(p) {
|
Parser.parseWitness = function parseWitness(p) {
|
||||||
var witness = [];
|
var witness = [];
|
||||||
var chunkCount, item, i;
|
var chunkCount, i;
|
||||||
|
|
||||||
p = new BufferReader(p);
|
p = new BufferReader(p);
|
||||||
p.start();
|
p.start();
|
||||||
|
|||||||
@ -141,7 +141,7 @@ Stack.prototype.__defineSetter__('length', function(value) {
|
|||||||
return this.items.length = value;
|
return this.items.length = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
Stack.prototype.getRedeem = function getRedeem(item) {
|
Stack.prototype.getRedeem = function getRedeem() {
|
||||||
var redeem = Script.getRedeem(this.items);
|
var redeem = Script.getRedeem(this.items);
|
||||||
if (!redeem)
|
if (!redeem)
|
||||||
return;
|
return;
|
||||||
@ -175,7 +175,7 @@ Stack.prototype.splice = function splice(i, remove, insert) {
|
|||||||
return this.items.splice(i, remove, insert);
|
return this.items.splice(i, remove, insert);
|
||||||
};
|
};
|
||||||
|
|
||||||
Stack.prototype.pop = function pop(item) {
|
Stack.prototype.pop = function pop() {
|
||||||
return this.items.pop();
|
return this.items.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -262,15 +262,17 @@ Stack.prototype.over = function over() {
|
|||||||
this.push(this.top(-2));
|
this.push(this.top(-2));
|
||||||
};
|
};
|
||||||
|
|
||||||
Stack.prototype.pick = function pick() {
|
Stack.prototype.pick = function pick(flags) {
|
||||||
return this._pickroll('pick');
|
return this._pickroll('pick', flags);
|
||||||
};
|
};
|
||||||
|
|
||||||
Stack.prototype.roll = function roll() {
|
Stack.prototype.roll = function roll(flags) {
|
||||||
return this._pickroll('roll');
|
return this._pickroll('roll', flags);
|
||||||
};
|
};
|
||||||
|
|
||||||
Stack.prototype._pickroll = function pickroll(op) {
|
Stack.prototype._pickroll = function pickroll(op, flags) {
|
||||||
|
var val, n;
|
||||||
|
|
||||||
if (this.length < 2)
|
if (this.length < 2)
|
||||||
throw new Error('Bad stack length.');
|
throw new Error('Bad stack length.');
|
||||||
|
|
||||||
@ -470,16 +472,16 @@ Script.prototype._next = function _next(to, code, ip) {
|
|||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Script.prototype.execute = function execute(stack, tx, index, flags, version, recurse) {
|
Script.prototype.execute = function execute(stack, tx, index, flags, version) {
|
||||||
try {
|
try {
|
||||||
return this._execute(stack, tx, index, flags, version, recurse);
|
return this._execute(stack, tx, index, flags, version);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
utils.debug('Script error: %s.', e.message);
|
utils.debug('Script error: %s.', e.message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Script.prototype._execute = function _execute(stack, tx, index, flags, version, recurse) {
|
Script.prototype._execute = function _execute(stack, tx, index, flags, version) {
|
||||||
var code = this.code.slice();
|
var code = this.code.slice();
|
||||||
var ip = 0;
|
var ip = 0;
|
||||||
var lastSep = -1;
|
var lastSep = -1;
|
||||||
@ -622,11 +624,11 @@ Script.prototype._execute = function _execute(stack, tx, index, flags, version,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'pick': {
|
case 'pick': {
|
||||||
stack.pick();
|
stack.pick(flags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'roll': {
|
case 'roll': {
|
||||||
stack.roll();
|
stack.roll(flags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'rot': {
|
case 'rot': {
|
||||||
@ -1051,7 +1053,7 @@ Script.checkLocktime = function checkLocktime(locktime, tx, i) {
|
|||||||
if (locktime > tx.locktime)
|
if (locktime > tx.locktime)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (tx.inputs[index].sequence === 0xffffffff)
|
if (tx.inputs[i].sequence === 0xffffffff)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1202,7 +1204,7 @@ Script.checkPush = function checkPush(value, flags) {
|
|||||||
if (!value.pushdata)
|
if (!value.pushdata)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
op = value.pushdata.opcode
|
op = value.pushdata.opcode;
|
||||||
|
|
||||||
if (!op)
|
if (!op)
|
||||||
op = value.pushdata.len;
|
op = value.pushdata.len;
|
||||||
@ -1431,7 +1433,7 @@ Script.prototype.getAddress = function getAddress() {
|
|||||||
return bcoin.address.compileData(this.code[0], 'pubkeyhash');
|
return bcoin.address.compileData(this.code[0], 'pubkeyhash');
|
||||||
|
|
||||||
if (this.isPubkeyhash())
|
if (this.isPubkeyhash())
|
||||||
return bcoin.address.compileHash(this.code[2], 'pubkeyhash')
|
return bcoin.address.compileHash(this.code[2], 'pubkeyhash');
|
||||||
|
|
||||||
// Convert bare multisig to scripthash address
|
// Convert bare multisig to scripthash address
|
||||||
if (this.isMultisig())
|
if (this.isMultisig())
|
||||||
@ -1745,7 +1747,7 @@ Script.isMultisigInput = function isMultisigInput(code, keys, isWitness) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isWitness) {
|
if (isWitness) {
|
||||||
if (!script.isDummy(code[0]))
|
if (!Script.isDummy(code[0]))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (code[0] !== 0)
|
if (code[0] !== 0)
|
||||||
@ -2065,6 +2067,8 @@ Script.isSignatureEncoding = function isSignatureEncoding(sig) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Script.isHashType = function isHashType(sig) {
|
Script.isHashType = function isHashType(sig) {
|
||||||
|
var type;
|
||||||
|
|
||||||
if (!Buffer.isBuffer(sig))
|
if (!Buffer.isBuffer(sig))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -2349,7 +2353,7 @@ Script.verify = function verify(input, witness, output, tx, i, flags) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Script.verifyProgram = function verifyProgram(witness, output, tx, i, flags) {
|
Script.verifyProgram = function verifyProgram(witness, output, tx, i, flags) {
|
||||||
var program, witnessScript, redeem, stack, j;
|
var program, witnessScript, redeem, stack, j, res;
|
||||||
|
|
||||||
assert((flags & constants.flags.VERIFY_WITNESS) !== 0);
|
assert((flags & constants.flags.VERIFY_WITNESS) !== 0);
|
||||||
assert(output.isWitnessProgram());
|
assert(output.isWitnessProgram());
|
||||||
|
|||||||
@ -5,12 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var fs = bcoin.fs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SPVNode
|
* SPVNode
|
||||||
|
|||||||
@ -15,8 +15,6 @@ var EventEmitter = require('events').EventEmitter;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function TXPool(wallet, txs) {
|
function TXPool(wallet, txs) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!(this instanceof TXPool))
|
if (!(this instanceof TXPool))
|
||||||
return new TXPool(wallet, txs);
|
return new TXPool(wallet, txs);
|
||||||
|
|
||||||
@ -59,7 +57,7 @@ TXPool.prototype.populate = function populate(txs) {
|
|||||||
TXPool.prototype.add = function add(tx, noWrite) {
|
TXPool.prototype.add = function add(tx, noWrite) {
|
||||||
var hash = tx.hash('hex');
|
var hash = tx.hash('hex');
|
||||||
var updated = false;
|
var updated = false;
|
||||||
var i, j, input, output, coin, unspent, index, orphan;
|
var i, j, input, output, coin, unspent, orphan;
|
||||||
var key, orphans, some;
|
var key, orphans, some;
|
||||||
|
|
||||||
this._wallet.fillPrevout(tx);
|
this._wallet.fillPrevout(tx);
|
||||||
@ -245,7 +243,7 @@ TXPool.prototype._removeTX = function _removeTX(tx, noWrite) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TXPool.prototype.removeTX = function removeTX(hash) {
|
TXPool.prototype.removeTX = function removeTX(hash) {
|
||||||
var tx, input, prev, updated;
|
var tx, input, updated, i, key;
|
||||||
|
|
||||||
if (hash.hash)
|
if (hash.hash)
|
||||||
hash = hash('hex');
|
hash = hash('hex');
|
||||||
@ -266,6 +264,7 @@ TXPool.prototype.removeTX = function removeTX(hash) {
|
|||||||
|
|
||||||
this._removeInput(input);
|
this._removeInput(input);
|
||||||
|
|
||||||
|
key = input.prevout.hash + '/' + input.prevout.index;
|
||||||
this._unspent[key] = input.output;
|
this._unspent[key] = input.output;
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
@ -301,7 +300,7 @@ TXPool.prototype.unconfirm = function unconfirm(hash) {
|
|||||||
if (this._unspent[key])
|
if (this._unspent[key])
|
||||||
this._unspent[key].height = -1;
|
this._unspent[key].height = -1;
|
||||||
}, this);
|
}, this);
|
||||||
this._storeTX(hash, tx, noWrite);
|
this._storeTX(hash, tx);
|
||||||
this._lastTs = Math.max(tx.ts, this._lastTs);
|
this._lastTs = Math.max(tx.ts, this._lastTs);
|
||||||
this._lastHeight = Math.max(tx.height, this._lastHeight);
|
this._lastHeight = Math.max(tx.height, this._lastHeight);
|
||||||
this.emit('update', this._lastTs, this._lastHeight, tx);
|
this.emit('update', this._lastTs, this._lastHeight, tx);
|
||||||
|
|||||||
@ -214,7 +214,7 @@ TX.prototype.signatureHashV0 = function signatureHashV0(index, s, type) {
|
|||||||
if (typeof type === 'string')
|
if (typeof type === 'string')
|
||||||
type = constants.hashType[type];
|
type = constants.hashType[type];
|
||||||
|
|
||||||
assert(index >= 0 && index < copy.inputs.length)
|
assert(index >= 0 && index < copy.inputs.length);
|
||||||
assert(s instanceof bcoin.script);
|
assert(s instanceof bcoin.script);
|
||||||
|
|
||||||
// Disable this for now. We allow null hash types
|
// Disable this for now. We allow null hash types
|
||||||
@ -290,7 +290,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, s, type) {
|
|||||||
if (typeof type === 'string')
|
if (typeof type === 'string')
|
||||||
type = constants.hashType[type];
|
type = constants.hashType[type];
|
||||||
|
|
||||||
assert(index >= 0 && index < this.inputs.length)
|
assert(index >= 0 && index < this.inputs.length);
|
||||||
assert(s instanceof bcoin.script);
|
assert(s instanceof bcoin.script);
|
||||||
|
|
||||||
if (!(type & constants.hashType.anyonecanpay)) {
|
if (!(type & constants.hashType.anyonecanpay)) {
|
||||||
@ -446,8 +446,6 @@ TX.prototype.getOutputValue = function getOutputValue() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TX.prototype.getFunds = function getFunds(side) {
|
TX.prototype.getFunds = function getFunds(side) {
|
||||||
var acc = new bn(0);
|
|
||||||
|
|
||||||
if (side === 'in' || side === 'input')
|
if (side === 'in' || side === 'input')
|
||||||
return this.getInputValue();
|
return this.getInputValue();
|
||||||
|
|
||||||
@ -585,7 +583,7 @@ TX.prototype.fillPrevout = function fillPrevout(txs, unspent) {
|
|||||||
txs = [txs];
|
txs = [txs];
|
||||||
unspent = null;
|
unspent = null;
|
||||||
} else if (txs instanceof bcoin.coin) {
|
} else if (txs instanceof bcoin.coin) {
|
||||||
unspent = [tx];
|
unspent = [txs];
|
||||||
txs = null;
|
txs = null;
|
||||||
} else if (txs instanceof bcoin.txpool) {
|
} else if (txs instanceof bcoin.txpool) {
|
||||||
unspent = txs._unspent;
|
unspent = txs._unspent;
|
||||||
@ -901,7 +899,7 @@ TX.prototype.getHeight = function getHeight() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TX.prototype.getConfirmations = function getConfirmations(height) {
|
TX.prototype.getConfirmations = function getConfirmations(height) {
|
||||||
var top, height;
|
var top;
|
||||||
|
|
||||||
if (height == null) {
|
if (height == null) {
|
||||||
if (!this.chain)
|
if (!this.chain)
|
||||||
@ -928,14 +926,18 @@ TX.prototype.getValue = function getValue() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TX.prototype.hasType = function hasType(type) {
|
TX.prototype.hasType = function hasType(type) {
|
||||||
for (var i = 0; i < this.inputs.length; i++) {
|
var i;
|
||||||
if (this.inputs[i].getInputType() === type)
|
|
||||||
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
|
if (this.inputs[i].getType() === type)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (var i = 0; i < this.outputs.length; i++) {
|
|
||||||
|
for (i = 0; i < this.outputs.length; i++) {
|
||||||
if (this.outputs[i].getType() === type)
|
if (this.outputs[i].getType() === type)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -17,8 +17,6 @@ var pad32 = utils.pad32;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function TXPool(prefix, db, options) {
|
function TXPool(prefix, db, options) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!(this instanceof TXPool))
|
if (!(this instanceof TXPool))
|
||||||
return new TXPool(prefix, db, options);
|
return new TXPool(prefix, db, options);
|
||||||
|
|
||||||
@ -74,7 +72,6 @@ TXPool.prototype._lock = function _lock(func, args, force) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TXPool.prototype.getMap = function getMap(tx, callback) {
|
TXPool.prototype.getMap = function getMap(tx, callback) {
|
||||||
var self = this;
|
|
||||||
var input = tx.getInputAddresses();
|
var input = tx.getInputAddresses();
|
||||||
var output = tx.getOutputAddresses();
|
var output = tx.getOutputAddresses();
|
||||||
var addresses = utils.uniqs(input.concat(output));
|
var addresses = utils.uniqs(input.concat(output));
|
||||||
@ -180,7 +177,6 @@ TXPool.prototype.mapAddresses = function mapAddresses(address, callback) {
|
|||||||
|
|
||||||
TXPool.prototype._addOrphan = function add(key, hash, index, callback) {
|
TXPool.prototype._addOrphan = function add(key, hash, index, callback) {
|
||||||
var prefix = this.prefix + '/';
|
var prefix = this.prefix + '/';
|
||||||
var self = this;
|
|
||||||
var orphans;
|
var orphans;
|
||||||
|
|
||||||
this.db.get(prefix + 'o/' + key, function(err, buf) {
|
this.db.get(prefix + 'o/' + key, function(err, buf) {
|
||||||
@ -225,7 +221,7 @@ TXPool.prototype._getOrphans = function _getOrphans(key, callback) {
|
|||||||
utils.forEach(orphans, function(orphan, next) {
|
utils.forEach(orphans, function(orphan, next) {
|
||||||
self.getTX(orphan.hash, function(err, tx) {
|
self.getTX(orphan.hash, function(err, tx) {
|
||||||
if (err)
|
if (err)
|
||||||
return done(err);
|
return next(err);
|
||||||
|
|
||||||
orphan.tx = tx;
|
orphan.tx = tx;
|
||||||
|
|
||||||
@ -414,7 +410,7 @@ TXPool.prototype._add = function add(tx, map, callback, force) {
|
|||||||
return finish();
|
return finish();
|
||||||
|
|
||||||
// Add input to orphan
|
// Add input to orphan
|
||||||
utils.forEachSerial(orphans, function(orphan, next, j) {
|
utils.forEachSerial(orphans, function(orphan, next) {
|
||||||
if (some)
|
if (some)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
@ -655,7 +651,7 @@ TXPool.prototype._remove = function remove(tx, map, callback) {
|
|||||||
|
|
||||||
this.fillTX(tx, function(err) {
|
this.fillTX(tx, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return callback(err);
|
||||||
|
|
||||||
tx.inputs.forEach(function(input) {
|
tx.inputs.forEach(function(input) {
|
||||||
var address = input.getAddress();
|
var address = input.getAddress();
|
||||||
@ -781,9 +777,6 @@ TXPool.prototype._unconfirm = function unconfirm(tx, map, callback) {
|
|||||||
if (!coin)
|
if (!coin)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
if (!address || !map[address].length)
|
|
||||||
return next();
|
|
||||||
|
|
||||||
coin.height = tx.height;
|
coin.height = tx.height;
|
||||||
|
|
||||||
batch.put(prefix + 'u/t/' + hash + '/' + i, coin.toExtended());
|
batch.put(prefix + 'u/t/' + hash + '/' + i, coin.toExtended());
|
||||||
@ -997,7 +990,6 @@ TXPool.prototype.getCoinIDs = function getCoinIDs(address, callback) {
|
|||||||
|
|
||||||
TXPool.prototype.getHeightRangeHashes = function getHeightRangeHashes(address, options, callback) {
|
TXPool.prototype.getHeightRangeHashes = function getHeightRangeHashes(address, options, callback) {
|
||||||
var prefix = this.prefix + '/';
|
var prefix = this.prefix + '/';
|
||||||
var self = this;
|
|
||||||
var txs = [];
|
var txs = [];
|
||||||
var iter;
|
var iter;
|
||||||
|
|
||||||
@ -1050,7 +1042,6 @@ TXPool.prototype.getHeightHashes = function getHeightHashes(height, callback) {
|
|||||||
|
|
||||||
TXPool.prototype.getRangeHashes = function getRangeHashes(address, options, callback) {
|
TXPool.prototype.getRangeHashes = function getRangeHashes(address, options, callback) {
|
||||||
var prefix = this.prefix + '/';
|
var prefix = this.prefix + '/';
|
||||||
var self = this;
|
|
||||||
var txs = [];
|
var txs = [];
|
||||||
var iter;
|
var iter;
|
||||||
|
|
||||||
@ -1187,6 +1178,7 @@ TXPool.prototype.getLastTime = function getLastTime(address, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TXPool.prototype.getPendingByAddress = function getPendingByAddress(address, callback) {
|
TXPool.prototype.getPendingByAddress = function getPendingByAddress(address, callback) {
|
||||||
|
var self = this;
|
||||||
var txs = [];
|
var txs = [];
|
||||||
|
|
||||||
return this.getPendingHashes(address, function(err, hashes) {
|
return this.getPendingHashes(address, function(err, hashes) {
|
||||||
|
|||||||
@ -6,14 +6,26 @@
|
|||||||
|
|
||||||
var utils = exports;
|
var utils = exports;
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
|
||||||
var bn = require('bn.js');
|
var bn = require('bn.js');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
var crypto, hash;
|
||||||
|
|
||||||
|
utils.isBrowser =
|
||||||
|
(typeof process !== 'undefined' && process.browser)
|
||||||
|
|| typeof window !== 'undefined';
|
||||||
|
|
||||||
|
if (!utils.isBrowser) {
|
||||||
|
crypto = require('cry' + 'pto');
|
||||||
|
} else {
|
||||||
|
hash = require('hash.js');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utils
|
* Utils
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
utils.nop = function() {};
|
||||||
|
|
||||||
utils.slice = function slice(buf, start, end) {
|
utils.slice = function slice(buf, start, end) {
|
||||||
var clone;
|
var clone;
|
||||||
|
|
||||||
@ -190,10 +202,10 @@ utils.isBase58 = function isBase58(msg) {
|
|||||||
utils.ripemd160 = function ripemd160(data, enc) {
|
utils.ripemd160 = function ripemd160(data, enc) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
if (!bcoin.crypto)
|
if (!crypto)
|
||||||
return new Buffer(bcoin.hash.ripemd160().update(data, enc).digest());
|
return new Buffer(hash.ripemd160().update(data, enc).digest());
|
||||||
|
|
||||||
result = bcoin.crypto.createHash('ripemd160').update(data, enc).digest();
|
result = crypto.createHash('ripemd160').update(data, enc).digest();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -201,10 +213,10 @@ utils.ripemd160 = function ripemd160(data, enc) {
|
|||||||
utils.sha1 = function sha1(data, enc) {
|
utils.sha1 = function sha1(data, enc) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
if (!bcoin.crypto)
|
if (!crypto)
|
||||||
return new Buffer(bcoin.hash.sha1().update(data, enc).digest());
|
return new Buffer(hash.sha1().update(data, enc).digest());
|
||||||
|
|
||||||
result = bcoin.crypto.createHash('sha1').update(data, enc).digest();
|
result = crypto.createHash('sha1').update(data, enc).digest();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -220,10 +232,10 @@ utils.checksum = function checksum(data, enc) {
|
|||||||
utils.sha256 = function sha256(data, enc) {
|
utils.sha256 = function sha256(data, enc) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
if (!bcoin.crypto)
|
if (!crypto)
|
||||||
return new Buffer(bcoin.hash.sha256().update(data, enc).digest());
|
return new Buffer(hash.sha256().update(data, enc).digest());
|
||||||
|
|
||||||
result = bcoin.crypto.createHash('sha256').update(data, enc).digest();
|
result = crypto.createHash('sha256').update(data, enc).digest();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -235,12 +247,12 @@ utils.dsha256 = function dsha256(data, enc) {
|
|||||||
utils.sha512hmac = function sha512hmac(data, salt) {
|
utils.sha512hmac = function sha512hmac(data, salt) {
|
||||||
var hmac, result;
|
var hmac, result;
|
||||||
|
|
||||||
if (!bcoin.crypto) {
|
if (!crypto) {
|
||||||
hmac = bcoin.hash.hmac(hash.sha512, salt);
|
hmac = hash.hmac(hash.sha512, salt);
|
||||||
return new Buffer(hmac.update(data).digest());
|
return new Buffer(hmac.update(data).digest());
|
||||||
}
|
}
|
||||||
|
|
||||||
hmac = bcoin.crypto.createHmac('sha512', salt);
|
hmac = crypto.createHmac('sha512', salt);
|
||||||
result = hmac.update(data).digest();
|
result = hmac.update(data).digest();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -251,7 +263,7 @@ utils.salt = 'bcoin:';
|
|||||||
utils.encrypt = function encrypt(data, passphrase) {
|
utils.encrypt = function encrypt(data, passphrase) {
|
||||||
var cipher, out;
|
var cipher, out;
|
||||||
|
|
||||||
if (!bcoin.crypto)
|
if (!crypto)
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
if (data[0] === ':')
|
if (data[0] === ':')
|
||||||
@ -260,7 +272,7 @@ utils.encrypt = function encrypt(data, passphrase) {
|
|||||||
if (!passphrase)
|
if (!passphrase)
|
||||||
throw new Error('No passphrase.');
|
throw new Error('No passphrase.');
|
||||||
|
|
||||||
cipher = bcoin.crypto.createCipher('aes-256-cbc', passphrase);
|
cipher = crypto.createCipher('aes-256-cbc', passphrase);
|
||||||
|
|
||||||
out = '';
|
out = '';
|
||||||
out += cipher.update(utils.salt + data, 'utf8', 'hex');
|
out += cipher.update(utils.salt + data, 'utf8', 'hex');
|
||||||
@ -272,7 +284,7 @@ utils.encrypt = function encrypt(data, passphrase) {
|
|||||||
utils.decrypt = function decrypt(data, passphrase) {
|
utils.decrypt = function decrypt(data, passphrase) {
|
||||||
var decipher, out;
|
var decipher, out;
|
||||||
|
|
||||||
if (!bcoin.crypto)
|
if (!crypto)
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
if (data[0] !== ':')
|
if (data[0] !== ':')
|
||||||
@ -283,7 +295,7 @@ utils.decrypt = function decrypt(data, passphrase) {
|
|||||||
|
|
||||||
data = data.substring(1);
|
data = data.substring(1);
|
||||||
|
|
||||||
decipher = bcoin.crypto.createDecipher('aes-256-cbc', passphrase);
|
decipher = crypto.createDecipher('aes-256-cbc', passphrase);
|
||||||
|
|
||||||
out = '';
|
out = '';
|
||||||
out += decipher.update(data, 'hex', 'utf8');
|
out += decipher.update(data, 'hex', 'utf8');
|
||||||
@ -427,8 +439,6 @@ utils.asyncify = function asyncify(callback) {
|
|||||||
return asyncifyFn;
|
return asyncifyFn;
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.nop = function() {};
|
|
||||||
|
|
||||||
utils.ensure = function ensure(callback) {
|
utils.ensure = function ensure(callback) {
|
||||||
if (!callback)
|
if (!callback)
|
||||||
return utils.nop;
|
return utils.nop;
|
||||||
@ -586,7 +596,7 @@ utils.parseHost = function parseHost(addr) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
host: parts[0].replace(/[\[\]]/g, ''),
|
host: parts[0].replace(/[\[\]]/g, ''),
|
||||||
port: +parts[1] || bcoin.protocol.network.port
|
port: +parts[1] || 0
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -782,25 +792,7 @@ utils.print = function print() {
|
|||||||
return process.stdout.write(utils.format(args, true));
|
return process.stdout.write(utils.format(args, true));
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.debug = function debug() {
|
utils.debug = utils.nop;
|
||||||
var args = Array.prototype.slice.call(arguments);
|
|
||||||
var msg;
|
|
||||||
|
|
||||||
if (bcoin.debug) {
|
|
||||||
msg = utils.format(args, true);
|
|
||||||
process.stdout.write(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bcoin.debugFile && bcoin.fs) {
|
|
||||||
if (!bcoin._debug) {
|
|
||||||
bcoin.ensurePrefix();
|
|
||||||
bcoin._debug = bcoin.fs.createWriteStream(
|
|
||||||
bcoin.prefix + '/debug.log', { flags: 'a' });
|
|
||||||
}
|
|
||||||
msg = utils.format(args, false);
|
|
||||||
bcoin._debug.write(process.pid + ': ' + msg);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
utils.merge = function merge(target) {
|
utils.merge = function merge(target) {
|
||||||
var args = Array.prototype.slice.call(arguments, 1);
|
var args = Array.prototype.slice.call(arguments, 1);
|
||||||
@ -1419,6 +1411,7 @@ utils.sizeIntv = function sizeIntv(num) {
|
|||||||
|
|
||||||
utils.cmp = function(a, b) {
|
utils.cmp = function(a, b) {
|
||||||
var len = Math.min(a.length, b.length);
|
var len = Math.min(a.length, b.length);
|
||||||
|
var i;
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (a[i] < b[i])
|
if (a[i] < b[i])
|
||||||
@ -1480,7 +1473,7 @@ utils.forRange = function forRange(from, to, iter, callback) {
|
|||||||
|
|
||||||
utils.forEach = function forEach(arr, iter, callback) {
|
utils.forEach = function forEach(arr, iter, callback) {
|
||||||
var pending = arr.length;
|
var pending = arr.length;
|
||||||
var i, error;
|
var error;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
@ -1550,7 +1543,7 @@ utils.forEachSerial = function forEachSerial(arr, iter, callback) {
|
|||||||
utils.every = function every(arr, iter, callback) {
|
utils.every = function every(arr, iter, callback) {
|
||||||
var pending = arr.length;
|
var pending = arr.length;
|
||||||
var result = true;
|
var result = true;
|
||||||
var i, error;
|
var error;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
|
|||||||
@ -5,22 +5,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var fs = bcoin.fs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wallet
|
* Wallet
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Wallet(options) {
|
function Wallet(options) {
|
||||||
var self = this;
|
|
||||||
var key, receiving;
|
|
||||||
|
|
||||||
if (!(this instanceof Wallet))
|
if (!(this instanceof Wallet))
|
||||||
return new Wallet(options);
|
return new Wallet(options);
|
||||||
|
|
||||||
@ -102,8 +97,7 @@ utils.inherits(Wallet, EventEmitter);
|
|||||||
|
|
||||||
Wallet.prototype._init = function _init() {
|
Wallet.prototype._init = function _init() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var options = this.options;
|
var i;
|
||||||
var addr, i;
|
|
||||||
|
|
||||||
assert(!this._initialized);
|
assert(!this._initialized);
|
||||||
this._initialized = true;
|
this._initialized = true;
|
||||||
@ -169,7 +163,7 @@ Wallet.prototype.destroy = function destroy() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.addKey = function addKey(key) {
|
Wallet.prototype.addKey = function addKey(key) {
|
||||||
var has, i;
|
var has;
|
||||||
|
|
||||||
if (key instanceof bcoin.wallet) {
|
if (key instanceof bcoin.wallet) {
|
||||||
assert(key.derivation === this.derivation);
|
assert(key.derivation === this.derivation);
|
||||||
@ -245,7 +239,9 @@ Wallet.prototype.removeKey = function removeKey(key) {
|
|||||||
this.keys.splice(index, 1);
|
this.keys.splice(index, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype._finalizeKeys = function _finalizeKeys(key) {
|
Wallet.prototype._finalizeKeys = function _finalizeKeys() {
|
||||||
|
var i;
|
||||||
|
|
||||||
assert(!this._keysFinalized);
|
assert(!this._keysFinalized);
|
||||||
this._keysFinalized = true;
|
this._keysFinalized = true;
|
||||||
|
|
||||||
|
|||||||
@ -7,12 +7,10 @@
|
|||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var bn = require('bn.js');
|
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var fs = bcoin.fs;
|
|
||||||
var DUMMY = new Buffer([]);
|
var DUMMY = new Buffer([]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,8 +18,6 @@ var DUMMY = new Buffer([]);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function WalletDB(node, options) {
|
function WalletDB(node, options) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!(this instanceof WalletDB))
|
if (!(this instanceof WalletDB))
|
||||||
return new WalletDB(node, options);
|
return new WalletDB(node, options);
|
||||||
|
|
||||||
@ -46,7 +42,6 @@ utils.inherits(WalletDB, EventEmitter);
|
|||||||
WalletDB._db = {};
|
WalletDB._db = {};
|
||||||
|
|
||||||
WalletDB.prototype.dump = function dump(callback) {
|
WalletDB.prototype.dump = function dump(callback) {
|
||||||
var self = this;
|
|
||||||
var records = {};
|
var records = {};
|
||||||
|
|
||||||
var iter = this.db.db.iterator({
|
var iter = this.db.db.iterator({
|
||||||
@ -280,7 +275,6 @@ WalletDB.prototype.removeJSON = function removeJSON(id, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype._getDB = function _getDB(id, callback) {
|
WalletDB.prototype._getDB = function _getDB(id, callback) {
|
||||||
var self = this;
|
|
||||||
var key;
|
var key;
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
@ -371,9 +365,6 @@ WalletDB.prototype.get = function get(id, passphrase, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.save = function save(options, callback) {
|
WalletDB.prototype.save = function save(options, callback) {
|
||||||
var self = this;
|
|
||||||
var passphrase = options.passphrase;
|
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
if (options instanceof bcoin.wallet)
|
if (options instanceof bcoin.wallet)
|
||||||
@ -383,8 +374,6 @@ WalletDB.prototype.save = function save(options, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.remove = function remove(id, callback) {
|
WalletDB.prototype.remove = function remove(id, callback) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
if (id instanceof bcoin.wallet) {
|
if (id instanceof bcoin.wallet) {
|
||||||
@ -397,7 +386,6 @@ WalletDB.prototype.remove = function remove(id, callback) {
|
|||||||
|
|
||||||
WalletDB.prototype.create = function create(options, callback) {
|
WalletDB.prototype.create = function create(options, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var passphrase = options.passphrase;
|
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
@ -494,43 +482,36 @@ WalletDB.prototype.getCoin = function getCoin(hash, index, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.getAll = function getAll(id, callback) {
|
WalletDB.prototype.getAll = function getAll(id, callback) {
|
||||||
var self = this;
|
|
||||||
id = id.id || id;
|
id = id.id || id;
|
||||||
return this.tx.getAllByAddress(id, callback);
|
return this.tx.getAllByAddress(id, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.getCoins = function getCoins(id, callback) {
|
WalletDB.prototype.getCoins = function getCoins(id, callback) {
|
||||||
var self = this;
|
|
||||||
id = id.id || id;
|
id = id.id || id;
|
||||||
return this.tx.getCoinsByAddress(id, callback);
|
return this.tx.getCoinsByAddress(id, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.getPending = function getPending(id, callback) {
|
WalletDB.prototype.getPending = function getPending(id, callback) {
|
||||||
var self = this;
|
|
||||||
id = id.id || id;
|
id = id.id || id;
|
||||||
return this.tx.getPendingByAddress(id, callback);
|
return this.tx.getPendingByAddress(id, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.getBalance = function getBalance(id, callback) {
|
WalletDB.prototype.getBalance = function getBalance(id, callback) {
|
||||||
var self = this;
|
|
||||||
id = id.id || id;
|
id = id.id || id;
|
||||||
return this.tx.getBalanceByAddress(id, callback);
|
return this.tx.getBalanceByAddress(id, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.getLastTime = function getLastTime(id, callback) {
|
WalletDB.prototype.getLastTime = function getLastTime(id, callback) {
|
||||||
var self = this;
|
|
||||||
id = id.id || id;
|
id = id.id || id;
|
||||||
return this.tx.getLastTime(id, callback);
|
return this.tx.getLastTime(id, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.getLast = function getLast(id, limit, callback) {
|
WalletDB.prototype.getLast = function getLast(id, limit, callback) {
|
||||||
var self = this;
|
|
||||||
id = id.id || id;
|
id = id.id || id;
|
||||||
return this.tx.getLast(id, limit, callback);
|
return this.tx.getLast(id, limit, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.getRange = function getRange(id, options, callback) {
|
WalletDB.prototype.getRange = function getRange(id, options, callback) {
|
||||||
var self = this;
|
|
||||||
id = id.id || id;
|
id = id.id || id;
|
||||||
return this.tx.getRange(id, options, callback);
|
return this.tx.getRange(id, options, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user