major db and async object refactor.

This commit is contained in:
Christopher Jeffrey 2016-08-17 15:56:18 -07:00
parent 911e4f541e
commit 841cb290d8
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
19 changed files with 401 additions and 471 deletions

View File

@ -279,7 +279,7 @@ Chain.prototype.verifyContext = function verifyContext(block, prev, callback) {
// Expose the state globally.
self.state = state;
return callback(null, view);
callback(null, view);
});
});
});
@ -429,7 +429,7 @@ Chain.prototype.verify = function verify(block, prev, callback) {
}
}
return callback(null, state);
callback(null, state);
});
});
};
@ -529,7 +529,7 @@ Chain.prototype.getDeployments = function getDeployments(block, prev, ancestors,
self.logger.warning('CSV has been activated.');
}
return next();
next();
});
},
function(next) {
@ -547,14 +547,14 @@ Chain.prototype.getDeployments = function getDeployments(block, prev, ancestors,
self.logger.warning('Segwit has been activated.');
}
return next();
next();
});
}
], function(err) {
if (err)
return callback(err);
return callback(null, state);
callback(null, state);
});
};
@ -597,7 +597,7 @@ Chain.prototype.checkDuplicates = function checkDuplicates(block, prev, callback
if (entry && entry.hash === self.network.block.bip34hash)
return callback();
return self.findDuplicates(block, prev, callback);
self.findDuplicates(block, prev, callback);
});
};
@ -759,7 +759,7 @@ Chain.prototype.checkInputs = function checkInputs(block, prev, state, callback)
100));
}
return callback(null, view);
callback(null, view);
});
});
});
@ -842,7 +842,7 @@ Chain.prototype.reorganize = function reorganize(entry, block, callback) {
var self = this;
var tip = this.tip;
return this.findFork(tip, entry, function(err, fork) {
this.findFork(tip, entry, function(err, fork) {
if (err)
return callback(err);
@ -908,17 +908,17 @@ Chain.prototype.reorganize = function reorganize(entry, block, callback) {
}
}
return disconnect(function(err) {
disconnect(function(err) {
if (err)
return callback(err);
return reconnect(function(err) {
reconnect(function(err) {
if (err)
return callback(err);
self.emit('reorganize', block, tip.height, tip.hash);
return callback();
callback();
});
});
});
@ -952,7 +952,7 @@ Chain.prototype.disconnect = function disconnect(entry, callback) {
self.emit('tip', entry);
self.emit('disconnect', entry, block);
return callback();
callback();
});
});
};
@ -1007,7 +1007,7 @@ Chain.prototype.reconnect = function reconnect(entry, callback) {
self.emit('reconnect', entry, block);
self.emit('connect', entry, block);
return callback();
callback();
});
});
});
@ -1060,7 +1060,7 @@ Chain.prototype.setBestChain = function setBestChain(entry, block, prev, callbac
self.emit('tip', entry);
return callback();
callback();
});
});
}
@ -1084,7 +1084,7 @@ Chain.prototype.setBestChain = function setBestChain(entry, block, prev, callbac
// A higher fork has arrived.
// Time to reorganize the chain.
this.logger.warning('WARNING: Reorganizing chain.');
return this.reorganize(entry, block, done);
this.reorganize(entry, block, done);
};
/**
@ -1152,7 +1152,7 @@ Chain.prototype.resetTime = function resetTime(ts, callback, force) {
*/
Chain.prototype.onDrain = function onDrain(callback) {
return this.locker.onDrain(callback);
this.locker.onDrain(callback);
};
/**
@ -1548,7 +1548,7 @@ Chain.prototype.has = function has(hash, callback) {
if (hash === this.currentBlock)
return callback(null, true);
return this.hasBlock(hash, callback);
this.hasBlock(hash, callback);
};
/**
@ -1611,7 +1611,7 @@ Chain.prototype.byTime = function byTime(ts, callback) {
*/
Chain.prototype.hasBlock = function hasBlock(hash, callback) {
return this.db.has(hash, callback);
this.db.has(hash, callback);
};
/**
@ -1641,7 +1641,7 @@ Chain.prototype.hasPending = function hasPending(hash) {
*/
Chain.prototype.getEntry = function getEntry(hash, callback) {
return this.db.get(hash, callback);
this.db.get(hash, callback);
};
/**
@ -1780,7 +1780,7 @@ Chain.prototype.getLocator = function getLocator(start, callback, force) {
if (!entry)
return next();
return next(null, entry.hash);
next(null, entry.hash);
});
})(null, entry.hash);
});
@ -1817,7 +1817,7 @@ Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
Chain.prototype.getCurrentTarget = function getCurrentTarget(callback) {
if (!this.tip)
return callback(null, this.network.pow.bits);
return this.getTargetAsync(null, this.tip, callback);
this.getTargetAsync(null, this.tip, callback);
};
/**
@ -1836,11 +1836,11 @@ Chain.prototype.getTargetAsync = function getTargetAsync(block, prev, callback)
return utils.asyncify(callback)(null, this.getTarget(block, prev));
}
return prev.getAncestors(this.network.pow.retargetInterval, function(err, ancestors) {
prev.getAncestors(this.network.pow.retargetInterval, function(err, ancestors) {
if (err)
return callback(err);
return callback(null, self.getTarget(block, prev, ancestors));
callback(null, self.getTarget(block, prev, ancestors));
});
};
@ -1883,7 +1883,7 @@ Chain.prototype.getTarget = function getTarget(block, prev, ancestors) {
assert(first);
return this.retarget(prev, first);
this.retarget(prev, first);
};
/**
@ -1943,7 +1943,7 @@ Chain.prototype.findLocator = function findLocator(locator, callback) {
if (err)
return callback(err);
return callback(null, self.network.genesis.hash);
callback(null, self.network.genesis.hash);
});
};
@ -1965,7 +1965,7 @@ Chain.prototype.isActive = function isActive(prev, id, callback) {
if (err)
return callback(err);
return callback(null, state === constants.thresholdStates.ACTIVE);
callback(null, state === constants.thresholdStates.ACTIVE);
});
};
@ -2002,11 +2002,13 @@ Chain.prototype.getState = function getState(prev, id, callback) {
return prev.getAncestorByHeight(height, function(err, ancestor) {
if (err)
return callback(err);
if (ancestor) {
assert(ancestor.height === height);
assert(((ancestor.height + 1) % period) === 0);
}
return self.getState(ancestor, id, callback);
self.getState(ancestor, id, callback);
});
}
@ -2095,7 +2097,7 @@ Chain.prototype.getState = function getState(prev, id, callback) {
if (condition(entry))
count++;
return entry.getPrevious(next);
entry.getPrevious(next);
})(null, entry);
function doneCounting(err) {
@ -2156,7 +2158,7 @@ Chain.prototype.computeBlockVersion = function computeBlockVersion(prev, callbac
version |= constants.versionbits.TOP_BITS;
version >>>= 0;
return callback(null, version);
callback(null, version);
});
};
@ -2204,7 +2206,7 @@ Chain.prototype.checkFinal = function checkFinal(prev, tx, flags, callback) {
if (err)
return callback(err);
return callback(null, tx.isFinal(height, ts));
callback(null, tx.isFinal(height, ts));
}
// We can skip MTP if the locktime is height.
@ -2273,7 +2275,7 @@ Chain.prototype.getLocks = function getLocks(prev, tx, flags, callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, minHeight, minTime);
callback(null, minHeight, minTime);
});
};
@ -2299,7 +2301,7 @@ Chain.prototype.evalLocks = function evalLocks(prev, minHeight, minTime, callbac
if (minTime >= medianTime)
return callback(null, false);
return callback(null, true);
callback(null, true);
});
};

View File

@ -404,7 +404,7 @@ ChainDB.prototype.getHeight = function getHeight(hash, callback) {
if (height == null)
return callback(null, -1);
return callback(null, height);
callback(null, height);
});
};
@ -447,14 +447,14 @@ ChainDB.prototype.getHash = function getHash(height, callback) {
*/
ChainDB.prototype.getChainHeight = function getChainHeight(callback) {
return this.getTip(function(err, entry) {
this.getTip(function(err, entry) {
if (err)
return callback(err);
if (!entry)
return callback(null, -1);
return callback(null, entry.height);
callback(null, entry.height);
});
};
@ -483,18 +483,18 @@ ChainDB.prototype.getBoth = function getBoth(block, callback) {
if (hash == null)
height = -1;
return callback(null, hash, height);
callback(null, hash, height);
});
}
return this.getHeight(hash, function(err, height) {
this.getHeight(hash, function(err, height) {
if (err)
return callback(err);
if (height === -1)
hash = null;
return callback(null, hash, height);
callback(null, hash, height);
});
};
@ -511,7 +511,7 @@ ChainDB.prototype.getEntry = function getEntry(hash, callback) {
if (hash == null || hash < 0)
return utils.nextTick(callback);
return this.getHash(hash, function(err, hash) {
this.getHash(hash, function(err, hash) {
if (err)
return callback(err);
@ -523,7 +523,7 @@ ChainDB.prototype.getEntry = function getEntry(hash, callback) {
if (entry)
return callback(null, entry);
return self.db.fetch(layout.e(hash), function(data) {
self.db.fetch(layout.e(hash), function(data) {
return bcoin.chainentry.fromRaw(self.chain, data);
}, callback);
});
@ -538,7 +538,7 @@ ChainDB.prototype.getEntry = function getEntry(hash, callback) {
ChainDB.prototype.get = function get(hash, callback) {
var self = this;
return this.getEntry(hash, function(err, entry) {
this.getEntry(hash, function(err, entry) {
if (err)
return callback(err);
@ -550,7 +550,7 @@ ChainDB.prototype.get = function get(hash, callback) {
// don't add it to the height cache.
self.cacheHash.set(entry.hash, entry);
return callback(null, entry);
callback(null, entry);
});
};
@ -583,7 +583,7 @@ ChainDB.prototype.save = function save(entry, block, view, connect, callback) {
return this.saveBlock(block, view, batch, false, function(err) {
if (err)
return callback(err);
return batch.write(callback);
batch.write(callback);
});
}
@ -596,7 +596,7 @@ ChainDB.prototype.save = function save(entry, block, view, connect, callback) {
this.saveBlock(block, view, batch, true, function(err) {
if (err)
return callback(err);
return batch.write(callback);
batch.write(callback);
});
};
@ -607,7 +607,7 @@ ChainDB.prototype.save = function save(entry, block, view, connect, callback) {
ChainDB.prototype.getTip = function getTip(callback) {
var self = this;
return this.db.fetch(layout.R, function(data) {
this.db.fetch(layout.R, function(data) {
assert(data.length === 32, 'Database corruption.');
return data.toString('hex');
}, function(err, hash) {
@ -617,7 +617,7 @@ ChainDB.prototype.getTip = function getTip(callback) {
if (!hash)
return callback();
return self.get(hash, callback);
self.get(hash, callback);
});
};
@ -656,7 +656,7 @@ ChainDB.prototype.reconnect = function reconnect(entry, block, view, callback) {
batch.write(function(err) {
if (err)
return callback(err);
return callback(null, entry, block);
callback(null, entry, block);
});
});
};
@ -682,7 +682,7 @@ ChainDB.prototype.disconnect = function disconnect(entry, callback) {
return batch.write(function(err) {
if (err)
return callback(err);
return callback(null, entry, entry.toHeaders());
callback(null, entry, entry.toHeaders());
});
}
@ -700,7 +700,7 @@ ChainDB.prototype.disconnect = function disconnect(entry, callback) {
batch.write(function(err) {
if (err)
return callback(err);
return callback(null, entry, block);
callback(null, entry, block);
});
});
});
@ -739,18 +739,18 @@ ChainDB.prototype.isMainChain = function isMainChain(hash, callback) {
if (hash === this.chain.tip.hash || hash === this.network.genesis.hash)
return utils.asyncify(callback)(null, true);
return this.getHeight(query, function(err, height) {
this.getHeight(query, function(err, height) {
if (err)
return callback(err);
return self.getHash(height, function(err, existing) {
self.getHash(height, function(err, existing) {
if (err)
return callback(err);
if (!existing)
return callback(null, false);
return callback(null, hash === existing);
callback(null, hash === existing);
});
});
};
@ -826,10 +826,10 @@ ChainDB.prototype.has = function has(height, callback) {
if (height == null || height < 0)
return utils.asyncify(callback)(null, false);
return this.getBoth(height, function(err, hash, height) {
this.getBoth(height, function(err, hash, height) {
if (err)
return callback(err);
return callback(null, hash != null);
callback(null, hash != null);
});
};
@ -967,7 +967,7 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callb
this._pruneBlock(block, batch, function(err) {
if (err)
return callback(err);
return callback(null, block);
callback(null, block);
});
};
@ -1059,7 +1059,7 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(block, batch, callb
batch.del(layout.u(block.hash()));
return callback(null, block);
callback(null, block);
});
};
@ -1091,7 +1091,7 @@ ChainDB.prototype.fillCoins = function fillCoins(tx, callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, tx);
callback(null, tx);
});
};
@ -1123,7 +1123,7 @@ ChainDB.prototype.fillHistory = function fillHistory(tx, callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, tx);
callback(null, tx);
});
};
@ -1272,8 +1272,6 @@ ChainDB.prototype.scan = function scan(start, filter, iter, callback) {
*/
ChainDB.prototype.getTX = function getTX(hash, callback) {
var self = this;
if (!this.options.indexTX)
return utils.nextTick(callback);
@ -1291,12 +1289,12 @@ ChainDB.prototype.hasTX = function hasTX(hash, callback) {
if (!this.options.indexTX)
return utils.asyncify(callback)(null, false);
return this.db.has(layout.t(hash), callback);
this.db.has(layout.t(hash), callback);
};
/**
* Get all coins pertinent to an address.
* @param {Base58Address|Base58Address[]} addresses
* @param {Address[]} addresses
* @param {Function} callback - Returns [Error, {@link Coin}[]].
*/
@ -1316,7 +1314,7 @@ ChainDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, call
self.db.iterate({
gte: layout.C(hash, constants.ZERO_HASH, 0),
lte: layout.C(hash, constants.MAX_HASH, 0xffffffff),
transform: layout.Cc
parse: layout.Cc
}, function(err, keys) {
if (err)
return next(err);
@ -1329,14 +1327,14 @@ ChainDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, call
if (coin)
coins.push(coin);
return next();
next();
});
}, next);
});
}, function(err) {
if (err)
return callback(err);
return callback(null, coins);
callback(null, coins);
});
};
@ -1350,26 +1348,23 @@ ChainDB.prototype.getEntries = function getEntries(callback) {
this.db.iterate({
gte: layout.e(constants.ZERO_HASH),
lte: layout.e(constants.MAX_HASH),
keys: false,
values: true,
parse: function(data) {
return bcoin.chainentry.fromRaw(self.chain, data);
parse: function(key, value) {
return bcoin.chainentry.fromRaw(self.chain, value);
}
}, callback);
};
/**
* Get all transactions pertinent to an address.
* @param {Base58Address|Base58Address[]} addresses
* @param {Function} callback - Returns [Error, {@link TX}[]].
* Get all transaction hashes to an address.
* @param {Address[]} addresses
* @param {Function} callback - Returns [Error, {@link Hash}[]].
*/
ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, callback) {
ChainDB.prototype.getHashesByAddress = function getHashesByAddress(addresses, callback) {
var self = this;
var txs = [];
var have = {};
if (!Array.isArray(addresses))
addresses = [addresses];
var hashes = {};
utils.forEachSerial(addresses, function(address, next) {
var hash = bcoin.address.getHash(address);
@ -1377,27 +1372,50 @@ ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, callback)
if (!hash)
return next();
self.db.lookup({
self.db.iterate({
gte: layout.T(hash, constants.ZERO_HASH),
lte: layout.T(hash, constants.MAX_HASH),
transform: function(key) {
parse: function(key) {
var hash = layout.Tt(key);
if (have[hash])
return;
have[hash] = true;
return layout.t(hash);
},
parse: function(data, key) {
txs.push(bcoin.tx.fromRaw(data));
hashes[hash] = true;
}
}, next);
}, function(err) {
if (err)
return callback(err);
return callback(null, txs);
callback(null, Object.keys(hashes));
});
};
/**
* Get all transactions pertinent to an address.
* @param {Address[]} addresses
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, callback) {
var self = this;
var txs = [];
if (!Array.isArray(addresses))
addresses = [addresses];
this.getHashesByAddress(addresses, function(err, hashes) {
if (err)
return callback(err);
utils.forEachSerial(hashes, function(hash, next) {
self.getTX(hash, function(err, tx) {
if (err)
return next(err);
txs.push(tx);
next();
});
}, function(err) {
if (err)
return callback(err);
callback(null, txs);
});
});
};
@ -1413,18 +1431,18 @@ ChainDB.prototype.getFullTX = function getFullTX(hash, callback) {
if (!this.options.indexTX)
return utils.nextTick(callback);
return this.getTX(hash, function(err, tx) {
this.getTX(hash, function(err, tx) {
if (err)
return callback(err);
if (!tx)
return callback();
return self.fillHistory(tx, function(err) {
self.fillHistory(tx, function(err) {
if (err)
return callback(err);
return callback(null, tx);
callback(null, tx);
});
});
};
@ -1438,18 +1456,18 @@ ChainDB.prototype.getFullTX = function getFullTX(hash, callback) {
ChainDB.prototype.getFullBlock = function getFullBlock(hash, callback) {
var self = this;
return this.getBlock(hash, function(err, block) {
this.getBlock(hash, function(err, block) {
if (err)
return callback(err);
if (!block)
return callback();
return self.getUndoView(block, function(err, view) {
self.getUndoView(block, function(err, view) {
if (err)
return callback(err);
return callback(null, block);
callback(null, block);
});
});
};
@ -1478,7 +1496,7 @@ ChainDB.prototype.getCoinView = function getCoinView(block, callback) {
if (err)
return callback(err);
return callback(null, view);
callback(null, view);
});
};
@ -1489,7 +1507,7 @@ ChainDB.prototype.getCoinView = function getCoinView(block, callback) {
*/
ChainDB.prototype.getUndoCoins = function getUndoCoins(hash, callback) {
return this.db.fetch(layout.u(hash), function(data) {
this.db.fetch(layout.u(hash), function(data) {
var p = new BufferReader(data);
var coins = [];
@ -1512,11 +1530,11 @@ ChainDB.prototype.getUndoView = function getUndoView(block, callback) {
var self = this;
var i, j, k, tx, input, coin;
return this.getCoinView(block, function(err, view) {
this.getCoinView(block, function(err, view) {
if (err)
return callback(err);
return self.getUndoCoins(block.hash(), function(err, coins) {
self.getUndoCoins(block.hash(), function(err, coins) {
if (err)
return callback(err);
@ -1539,7 +1557,7 @@ ChainDB.prototype.getUndoView = function getUndoView(block, callback) {
}
}
return callback(null, view);
callback(null, view);
});
});
};
@ -1552,7 +1570,7 @@ ChainDB.prototype.getUndoView = function getUndoView(block, callback) {
ChainDB.prototype.getBlock = function getBlock(hash, callback) {
var self = this;
return this.getBoth(hash, function(err, hash, height) {
this.getBoth(hash, function(err, hash, height) {
if (err)
return callback(err);
@ -1619,7 +1637,7 @@ ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
batch.del(layout.b(hash));
batch.del(layout.u(hash));
return callback();
callback();
});
};

View File

@ -167,7 +167,7 @@ ChainEntry.prototype.getRetargetAncestors = function getRetargetAncestors(callba
var max = Math.max(majorityWindow, medianTimespan);
if ((this.height + 1) % powDiffInterval === 0 || allowMinDiff)
max = Math.max(max, powDiffInterval);
return this.getAncestors(max, callback);
this.getAncestors(max, callback);
};
/**
@ -226,7 +226,7 @@ ChainEntry.prototype.getAncestors = function getAncestors(max, callback) {
*/
ChainEntry.prototype.isMainChain = function isMainChain(callback) {
return this.chain.db.isMainChain(this, callback);
this.chain.db.isMainChain(this, callback);
};
/**
@ -251,7 +251,7 @@ ChainEntry.prototype.getAncestorByHeight = function getAncestorByHeight(height,
if (main)
return self.chain.db.get(height, callback);
return self.getAncestor(self.height - height, function(err, entry) {
self.getAncestor(self.height - height, function(err, entry) {
if (err)
return callback(err);
@ -260,7 +260,7 @@ ChainEntry.prototype.getAncestorByHeight = function getAncestorByHeight(height,
assert(entry.height === height);
return callback(null, entry);
callback(null, entry);
});
});
};
@ -275,14 +275,14 @@ ChainEntry.prototype.getAncestorByHeight = function getAncestorByHeight(height,
ChainEntry.prototype.getAncestor = function getAncestor(index, callback) {
assert(index >= 0);
return this.getAncestors(index + 1, function(err, ancestors) {
this.getAncestors(index + 1, function(err, ancestors) {
if (err)
return callback(err);
if (ancestors.length < index + 1)
return callback();
return callback(null, ancestors[index]);
callback(null, ancestors[index]);
});
};
@ -292,7 +292,7 @@ ChainEntry.prototype.getAncestor = function getAncestor(index, callback) {
*/
ChainEntry.prototype.getPrevious = function getPrevious(callback) {
return this.chain.db.get(this.prevBlock, callback);
this.chain.db.get(this.prevBlock, callback);
};
/**
@ -302,14 +302,14 @@ ChainEntry.prototype.getPrevious = function getPrevious(callback) {
ChainEntry.prototype.getNext = function getNext(callback) {
var self = this;
return this.chain.db.getNextHash(this.hash, function(err, hash) {
this.chain.db.getNextHash(this.hash, function(err, hash) {
if (err)
return callback(err);
if (!hash)
return callback();
return self.chain.db.get(hash, callback);
self.chain.db.get(hash, callback);
});
};
@ -343,11 +343,11 @@ ChainEntry.prototype.getMedianTimeAsync = function getMedianTimeAsync(callback)
var self = this;
var MEDIAN_TIMESPAN = constants.block.MEDIAN_TIMESPAN;
return this.getAncestors(MEDIAN_TIMESPAN, function(err, ancestors) {
this.getAncestors(MEDIAN_TIMESPAN, function(err, ancestors) {
if (err)
return callback(err);
return callback(null, self.getMedianTime(ancestors));
callback(null, self.getMedianTime(ancestors));
});
};
@ -359,7 +359,7 @@ ChainEntry.prototype.getMedianTimeAsync = function getMedianTimeAsync(callback)
*/
ChainEntry.prototype.isOutdated = function isOutdated(version, ancestors) {
return this.isSuperMajority(version,
this.isSuperMajority(version,
this.network.block.majorityRejectOutdated,
ancestors);
};
@ -372,7 +372,7 @@ ChainEntry.prototype.isOutdated = function isOutdated(version, ancestors) {
*/
ChainEntry.prototype.isOutdatedAsync = function isOutdatedAsync(version, callback) {
return this.isSuperMajorityAsync(version,
this.isSuperMajorityAsync(version,
this.network.block.majorityRejectOutdated,
callback);
};
@ -385,7 +385,7 @@ ChainEntry.prototype.isOutdatedAsync = function isOutdatedAsync(version, callbac
*/
ChainEntry.prototype.isUpgraded = function isUpgraded(version, ancestors) {
return this.isSuperMajority(version,
this.isSuperMajority(version,
this.network.block.majorityEnforceUpgrade,
ancestors);
};
@ -398,7 +398,7 @@ ChainEntry.prototype.isUpgraded = function isUpgraded(version, ancestors) {
*/
ChainEntry.prototype.isUpgradedAsync = function isUpgradedAsync(version, callback) {
return this.isSuperMajorityAsync(version,
this.isSuperMajorityAsync(version,
this.network.block.majorityEnforceUpgrade,
callback);
};
@ -438,11 +438,11 @@ ChainEntry.prototype.isSuperMajorityAsync = function isSuperMajorityAsync(versio
var self = this;
var majorityWindow = this.network.block.majorityWindow;
return this.getAncestors(majorityWindow, function(err, ancestors) {
this.getAncestors(majorityWindow, function(err, ancestors) {
if (err)
return callback(err);
return callback(null, self.isSuperMajority(version, required, ancestors));
callback(null, self.isSuperMajority(version, required, ancestors));
});
};

View File

@ -384,7 +384,7 @@ Fullnode.prototype.sendTX = function sendTX(item, wait, callback) {
return callback();
}
return self.pool.broadcast(item, callback);
self.pool.broadcast(item, callback);
});
};
@ -394,7 +394,7 @@ Fullnode.prototype.sendTX = function sendTX(item, wait, callback) {
*/
Fullnode.prototype.listen = function listen(callback) {
return this.pool.listen(callback);
this.pool.listen(callback);
};
/**
@ -438,7 +438,7 @@ Fullnode.prototype.createWallet = function createWallet(options, callback) {
self.logger.info('Loaded wallet with id=%s address=%s',
wallet.id, wallet.getAddress());
return callback(null, wallet);
callback(null, wallet);
});
};
@ -449,7 +449,7 @@ Fullnode.prototype.createWallet = function createWallet(options, callback) {
*/
Fullnode.prototype.getWallet = function getWallet(id, callback) {
return this.walletdb.get(id, callback);
this.walletdb.get(id, callback);
};
/**
@ -516,7 +516,7 @@ Fullnode.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, cal
coins.push(coin);
}
return callback(null, coins);
callback(null, coins);
});
};
@ -576,7 +576,7 @@ Fullnode.prototype.getTXByAddress = function getTXByAddress(addresses, callback)
if (err)
return callback(err);
return callback(null, mempool.concat(txs));
callback(null, mempool.concat(txs));
});
};
@ -588,7 +588,7 @@ Fullnode.prototype.getTXByAddress = function getTXByAddress(addresses, callback)
*/
Fullnode.prototype.fillCoins = function fillCoins(tx, callback) {
return this.mempool.fillAllCoins(tx, callback);
this.mempool.fillAllCoins(tx, callback);
};
/**
@ -599,7 +599,7 @@ Fullnode.prototype.fillCoins = function fillCoins(tx, callback) {
*/
Fullnode.prototype.fillHistory = function fillHistory(tx, callback) {
return this.mempool.fillAllHistory(tx, callback);
this.mempool.fillAllHistory(tx, callback);
};
/**
@ -609,7 +609,7 @@ Fullnode.prototype.fillHistory = function fillHistory(tx, callback) {
*/
Fullnode.prototype.getConfidence = function getConfidence(tx, callback) {
return this.mempool.getConfidence(tx, callback);
this.mempool.getConfidence(tx, callback);
};
/*

View File

@ -137,7 +137,7 @@ HTTPClient.prototype._close = function close(callback) {
this.socket.destroy();
this.socket = null;
return utils.nextTick(callback);
utils.nextTick(callback);
};
/**
@ -222,7 +222,7 @@ HTTPClient.prototype._request = function _request(method, endpoint, json, callba
*/
HTTPClient.prototype._get = function _get(endpoint, json, callback) {
return this._request('get', endpoint, json, callback);
this._request('get', endpoint, json, callback);
};
/**
@ -234,7 +234,7 @@ HTTPClient.prototype._get = function _get(endpoint, json, callback) {
*/
HTTPClient.prototype._post = function _post(endpoint, json, callback) {
return this._request('post', endpoint, json, callback);
this._request('post', endpoint, json, callback);
};
/**
@ -246,7 +246,7 @@ HTTPClient.prototype._post = function _post(endpoint, json, callback) {
*/
HTTPClient.prototype._put = function _put(endpoint, json, callback) {
return this._request('put', endpoint, json, callback);
this._request('put', endpoint, json, callback);
};
/**
@ -258,7 +258,7 @@ HTTPClient.prototype._put = function _put(endpoint, json, callback) {
*/
HTTPClient.prototype._del = function _del(endpoint, json, callback) {
return this._request('delete', endpoint, json, callback);
this._request('delete', endpoint, json, callback);
};
/**
@ -267,7 +267,7 @@ HTTPClient.prototype._del = function _del(endpoint, json, callback) {
*/
HTTPClient.prototype.getMempool = function getMempool(callback) {
return this._get('/mempool', callback);
this._get('/mempool', callback);
};
/**
@ -276,7 +276,7 @@ HTTPClient.prototype.getMempool = function getMempool(callback) {
*/
HTTPClient.prototype.getInfo = function getInfo(callback) {
return this._get('/', callback);
this._get('/', callback);
};
/**
@ -288,8 +288,7 @@ HTTPClient.prototype.getInfo = function getInfo(callback) {
HTTPClient.prototype.getCoinsByAddress = function getCoinsByAddress(address, callback) {
var body = { address: address };
return this._post('/coin/address', body, callback);
this._post('/coin/address', body, callback);
};
/**
@ -301,7 +300,7 @@ HTTPClient.prototype.getCoinsByAddress = function getCoinsByAddress(address, cal
*/
HTTPClient.prototype.getCoin = function getCoin(hash, index, callback) {
return this._get('/coin/' + hash + '/' + index, callback);
this._get('/coin/' + hash + '/' + index, callback);
};
/**
@ -314,7 +313,7 @@ HTTPClient.prototype.getCoin = function getCoin(hash, index, callback) {
HTTPClient.prototype.getTXByAddress = function getTXByAddress(address, callback) {
var body = { address: address };
return this._post('/tx/address', body, callback);
this._post('/tx/address', body, callback);
};
/**
@ -324,7 +323,7 @@ HTTPClient.prototype.getTXByAddress = function getTXByAddress(address, callback)
*/
HTTPClient.prototype.getTX = function getTX(hash, callback) {
return this._get('/tx/' + hash, callback);
this._get('/tx/' + hash, callback);
};
/**
@ -334,7 +333,7 @@ HTTPClient.prototype.getTX = function getTX(hash, callback) {
*/
HTTPClient.prototype.getBlock = function getBlock(hash, callback) {
return this._get('/block/' + hash, callback);
this._get('/block/' + hash, callback);
};
/**
@ -346,7 +345,7 @@ HTTPClient.prototype.getBlock = function getBlock(hash, callback) {
HTTPClient.prototype.broadcast = function broadcast(tx, callback) {
var body = { tx: toHex(tx) };
return this._post('/broadcast', body, callback);
this._post('/broadcast', body, callback);
};
/**
@ -397,7 +396,7 @@ HTTPClient.prototype.none = function none(callback) {
*/
HTTPClient.prototype.createWallet = function createWallet(options, callback) {
return this._post('/wallet', options, callback);
this._post('/wallet', options, callback);
};
/**
@ -408,7 +407,7 @@ HTTPClient.prototype.createWallet = function createWallet(options, callback) {
*/
HTTPClient.prototype.getWallet = function getWallet(id, callback) {
return this._get('/wallet/' + id, callback);
this._get('/wallet/' + id, callback);
};
/**
@ -427,7 +426,7 @@ HTTPClient.prototype.getHistory = function getHistory(id, account, callback) {
options = { account: account };
return this._get('/wallet/' + id + '/tx/history', options, callback);
this._get('/wallet/' + id + '/tx/history', options, callback);
};
/**
@ -446,7 +445,7 @@ HTTPClient.prototype.getCoins = function getCoins(id, account, callback) {
options = { account: account };
return this._get('/wallet/' + id + '/coin', options, callback);
this._get('/wallet/' + id + '/coin', options, callback);
};
/**
@ -465,7 +464,7 @@ HTTPClient.prototype.getUnconfirmed = function getUnconfirmed(id, account, callb
options = { account: account };
return this._get('/wallet/' + id + '/tx/unconfirmed', options, callback);
this._get('/wallet/' + id + '/tx/unconfirmed', options, callback);
};
/**
@ -484,7 +483,7 @@ HTTPClient.prototype.getBalance = function getBalance(id, account, callback) {
options = { account: account };
return this._get('/wallet/' + id + '/balance', options, callback);
this._get('/wallet/' + id + '/balance', options, callback);
};
/**
@ -504,7 +503,7 @@ HTTPClient.prototype.getLast = function getLast(id, account, limit, callback) {
options = { account: account, limit: limit };
return this._get('/wallet/' + id + '/tx/last', options, callback);
this._get('/wallet/' + id + '/tx/last', options, callback);
};
/**
@ -533,7 +532,7 @@ HTTPClient.prototype.getRange = function getRange(id, account, options, callback
reverse: options.reverse
};
return this._get('/wallet/' + id + '/tx/range', options, callback);
this._get('/wallet/' + id + '/tx/range', options, callback);
};
/**
@ -555,7 +554,7 @@ HTTPClient.prototype.getWalletTX = function getWalletTX(id, account, hash, callb
options = { account: account };
return this._get('/wallet/' + id + '/tx/' + hash, options, callback);
this._get('/wallet/' + id + '/tx/' + hash, options, callback);
};
/**
@ -581,7 +580,7 @@ HTTPClient.prototype.getWalletCoin = function getWalletCoin(id, account, hash, i
path = '/wallet/' + id + '/coin/' + hash + '/' + index;
return this._get(path, options, callback);
this._get(path, options, callback);
};
/**
@ -608,7 +607,7 @@ HTTPClient.prototype.send = function send(id, options, callback) {
};
});
return this._post('/wallet/' + id + '/send', options, callback);
this._post('/wallet/' + id + '/send', options, callback);
};
/**
@ -620,7 +619,7 @@ HTTPClient.prototype.send = function send(id, options, callback) {
HTTPClient.prototype.retoken = function retoken(id, passphrase, callback) {
var options = { passphrase: passphrase };
return this._post('/wallet/' + id + '/retoken', options, function(err, body) {
this._post('/wallet/' + id + '/retoken', options, function(err, body) {
if (err)
return callback(err);
@ -638,7 +637,7 @@ HTTPClient.prototype.retoken = function retoken(id, passphrase, callback) {
HTTPClient.prototype.setPassphrase = function setPassphrase(id, old, new_, callback) {
var options = { old: old, passphrase: new_ };
return this._post('/wallet/' + id + '/passphrase', options, callback);
this._post('/wallet/' + id + '/passphrase', options, callback);
};
/**
@ -662,7 +661,7 @@ HTTPClient.prototype.createTX = function createTX(id, options, callback) {
};
});
return this._post('/wallet/' + id + '/create', options, callback);
this._post('/wallet/' + id + '/create', options, callback);
};
/**
@ -687,7 +686,7 @@ HTTPClient.prototype.sign = function sign(id, tx, options, callback) {
body = utils.merge({}, options);
body.tx = toHex(tx);
return this._post('/wallet/' + id + '/sign', body, callback);
this._post('/wallet/' + id + '/sign', body, callback);
};
/**
@ -698,7 +697,7 @@ HTTPClient.prototype.sign = function sign(id, tx, options, callback) {
HTTPClient.prototype.fillCoins = function fillCoins(id, tx, callback) {
var body = { tx: toHex(tx) };
return this._post('/wallet/' + id + '/fill', body, callback);
this._post('/wallet/' + id + '/fill', body, callback);
};
/**
@ -724,7 +723,7 @@ HTTPClient.prototype.zap = function zap(id, account, age, callback) {
assert(utils.isNumber(age));
return this._post('/wallet/' + id + '/zap', body, callback);
this._post('/wallet/' + id + '/zap', body, callback);
};
/**
@ -748,7 +747,7 @@ HTTPClient.prototype.addKey = function addKey(id, account, key, callback) {
key = key.xpubkey || key;
options = { account: account, key: key };
return this._put('/wallet/' + id + '/key', options, callback);
this._put('/wallet/' + id + '/key', options, callback);
};
/**
@ -772,7 +771,7 @@ HTTPClient.prototype.removeKey = function removeKey(id, account, key, callback)
key = key.xpubkey || key;
options = { account: account, key: key };
return this._del('/wallet/' + id + '/key', options, callback);
this._del('/wallet/' + id + '/key', options, callback);
};
/**
@ -783,7 +782,7 @@ HTTPClient.prototype.removeKey = function removeKey(id, account, key, callback)
HTTPClient.prototype.getAccounts = function getAccounts(id, callback) {
var path = '/wallet/' + id + '/account';
return this._get(path, callback);
this._get(path, callback);
};
/**
@ -795,7 +794,7 @@ HTTPClient.prototype.getAccounts = function getAccounts(id, callback) {
HTTPClient.prototype.getAccount = function getAccount(id, account, callback) {
var path = '/wallet/' + id + '/account/' + account;
return this._get(path, callback);
this._get(path, callback);
};
/**
@ -821,7 +820,7 @@ HTTPClient.prototype.createAccount = function createAccount(id, options, callbac
path = '/wallet/' + id + '/account';
return this._post(path, options, callback);
this._post(path, options, callback);
};
/*

View File

@ -655,7 +655,7 @@ RPC.prototype._getBIP9Softforks = function _getBIP9Softforks(callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, forks);
callback(null, forks);
});
};
@ -770,7 +770,7 @@ RPC.prototype.getblock = function getblock(args, callback) {
if (!verbose)
return callback(null, block.toRaw().toString('hex'));
return self._blockToJSON(entry, block, false, callback);
self._blockToJSON(entry, block, false, callback);
});
});
};
@ -857,7 +857,7 @@ RPC.prototype.getblockhash = function getblockhash(args, callback) {
if (!entry)
return callback(new RPCError('Not found.'));
return callback(null, entry.rhash);
callback(null, entry.rhash);
});
};
@ -888,7 +888,7 @@ RPC.prototype.getblockheader = function getblockheader(args, callback) {
if (!verbose)
return callback(null, entry.toRaw().toString('hex', 0, 80));
return self._headerToJSON(entry, callback);
self._headerToJSON(entry, callback);
});
};
@ -902,7 +902,7 @@ RPC.prototype._headerToJSON = function _headerToJSON(entry, callback) {
if (err)
return callback(err);
return callback(null, {
callback(null, {
hash: utils.revHex(entry.hash),
confirmations: self.chain.height - entry.height + 1,
height: entry.height,
@ -932,7 +932,7 @@ RPC.prototype._blockToJSON = function _blockToJSON(entry, block, txDetails, call
if (err)
return callback(err);
return callback(null, {
callback(null, {
hash: utils.revHex(entry.hash),
confirmations: self.chain.height - entry.height + 1,
strippedsize: block.getBaseSize(),
@ -1134,7 +1134,7 @@ RPC.prototype.getrawmempool = function getrawmempool(args, callback) {
if (args.length > 0)
verbose = toBool(args[0], false);
return this.mempoolToJSON(verbose, callback);
this.mempoolToJSON(verbose, callback);
};
RPC.prototype.mempoolToJSON = function mempoolToJSON(verbose, callback) {
@ -1159,7 +1159,7 @@ RPC.prototype.mempoolToJSON = function mempoolToJSON(verbose, callback) {
hashes = this.mempool.getSnapshot();
return callback(null, hashes.map(utils.revHex));
callback(null, hashes.map(utils.revHex));
};
RPC.prototype._entryToJSON = function _entryToJSON(entry) {
@ -1391,7 +1391,7 @@ RPC.prototype.getblocktemplate = function getblocktemplate(args, callback) {
return callback(null, err.reason);
return callback(null, 'rejected');
}
return callback(null, null);
callback(null, null);
});
}
@ -1565,7 +1565,7 @@ RPC.prototype._createBlock = function _createBlock(callback) {
callback(null, attempt);
});
}
return callback(null, this.currentBlock);
callback(null, this.currentBlock);
};
RPC.prototype.getmininginfo = function getmininginfo(args, callback) {
@ -1615,7 +1615,7 @@ RPC.prototype.getnetworkhashps = function getnetworkhashps(args, callback) {
if (args.length > 1)
height = toNumber(args[1], -1);
return this._hashps(lookup, height, callback);
this._hashps(lookup, height, callback);
};
RPC.prototype.prioritisetransaction = function prioritisetransaction(args, callback) {
@ -1650,7 +1650,7 @@ RPC.prototype.prioritisetransaction = function prioritisetransaction(args, callb
if (entry.fees < 0)
entry.fees = 0;
return callback(null, true);
callback(null, true);
};
RPC.prototype.submitblock = function submitblock(args, callback) {
@ -1666,7 +1666,7 @@ RPC.prototype.submitblock = function submitblock(args, callback) {
this.chain.add(block, function(err, total) {
if (err)
return callback(null, 'rejected');
return callback(null, 'valid');
callback(null, 'valid');
});
};
@ -1677,7 +1677,7 @@ RPC.prototype._hashps = function _hashps(lookup, height, callback) {
function getPB(callback) {
if (height >= 0 && height < self.chain.tip.height)
return self.chain.db.get(height, callback);
return callback(null, self.chain.tip);
callback(null, self.chain.tip);
}
getPB(function(err, pb) {
@ -1723,7 +1723,7 @@ RPC.prototype._hashps = function _hashps(lookup, height, callback) {
timeDiff = maxTime - minTime;
ps = +workDiff.toString(10) / timeDiff;
return callback(null, ps);
callback(null, ps);
});
});
};
@ -1773,7 +1773,7 @@ RPC.prototype.generate = function generate(args, callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, hashes);
callback(null, hashes);
});
};
@ -1796,7 +1796,7 @@ RPC.prototype.generatetoaddress = function generatetoaddress(args, callback) {
if (err)
return callback(err);
self.miner.address = address;
return callback(null, hashes);
callback(null, hashes);
});
};
@ -2731,7 +2731,7 @@ RPC.prototype.getaccount = function getaccount(args, callback) {
if (!path)
return callback(null, '');
return callback(null, path.name);
callback(null, path.name);
});
};

View File

@ -954,7 +954,7 @@ HTTPServer.prototype._initIO = function _initIO() {
self.emit('websocket', socket);
return callback();
callback();
});
socket.emit('version', {
@ -993,7 +993,7 @@ HTTPServer.prototype._initIO = function _initIO() {
socket.join(id);
return callback();
callback();
});
});
@ -1006,7 +1006,7 @@ HTTPServer.prototype._initIO = function _initIO() {
socket.leave(id);
return callback();
callback();
});
socket.on('watch chain', function() {
@ -1164,7 +1164,7 @@ HTTPServer.prototype.del = function del(path, callback) {
HTTPServer.prototype.listen = function listen(port, host, callback) {
var self = this;
return this.server.listen(port, host, function(err, address) {
this.server.listen(port, host, function(err, address) {
if (err) {
if (callback)
return callback(err);

View File

@ -156,7 +156,7 @@ HTTPWallet.prototype.close = function close(callback) {
*/
HTTPWallet.prototype.getHistory = function getHistory(account, callback) {
return this.client.getHistory(this.id, account, callback);
this.client.getHistory(this.id, account, callback);
};
/**
@ -164,7 +164,7 @@ HTTPWallet.prototype.getHistory = function getHistory(account, callback) {
*/
HTTPWallet.prototype.getCoins = function getCoins(account, callback) {
return this.client.getCoins(this.id, account, callback);
this.client.getCoins(this.id, account, callback);
};
/**
@ -172,7 +172,7 @@ HTTPWallet.prototype.getCoins = function getCoins(account, callback) {
*/
HTTPWallet.prototype.getUnconfirmed = function getUnconfirmed(account, callback) {
return this.client.getUnconfirmed(this.id, account, callback);
this.client.getUnconfirmed(this.id, account, callback);
};
/**
@ -180,7 +180,7 @@ HTTPWallet.prototype.getUnconfirmed = function getUnconfirmed(account, callback)
*/
HTTPWallet.prototype.getBalance = function getBalance(account, callback) {
return this.client.getBalance(this.id, account, callback);
this.client.getBalance(this.id, account, callback);
};
/**
@ -188,7 +188,7 @@ HTTPWallet.prototype.getBalance = function getBalance(account, callback) {
*/
HTTPWallet.prototype.getLast = function getLast(account, limit, callback) {
return this.client.getLast(this.id, account, limit, callback);
this.client.getLast(this.id, account, limit, callback);
};
/**
@ -196,7 +196,7 @@ HTTPWallet.prototype.getLast = function getLast(account, limit, callback) {
*/
HTTPWallet.prototype.getRange = function getRange(account, options, callback) {
return this.client.getRange(this.id, account, options, callback);
this.client.getRange(this.id, account, options, callback);
};
/**
@ -204,7 +204,7 @@ HTTPWallet.prototype.getRange = function getRange(account, options, callback) {
*/
HTTPWallet.prototype.getTX = function getTX(account, hash, callback) {
return this.client.getWalletTX(this.id, account, hash, callback);
this.client.getWalletTX(this.id, account, hash, callback);
};
/**
@ -212,7 +212,7 @@ HTTPWallet.prototype.getTX = function getTX(account, hash, callback) {
*/
HTTPWallet.prototype.getCoin = function getCoin(account, hash, index, callback) {
return this.client.getWalletCoin(this.id, account, hash, index, callback);
this.client.getWalletCoin(this.id, account, hash, index, callback);
};
/**
@ -220,7 +220,7 @@ HTTPWallet.prototype.getCoin = function getCoin(account, hash, index, callback)
*/
HTTPWallet.prototype.zap = function zap(account, age, callback) {
return this.client.zap(this.id, account, age, callback);
this.client.zap(this.id, account, age, callback);
};
/**
@ -228,7 +228,7 @@ HTTPWallet.prototype.zap = function zap(account, age, callback) {
*/
HTTPWallet.prototype.createTX = function createTX(options, outputs, callback) {
return this.client.createTX(this.id, options, outputs, callback);
this.client.createTX(this.id, options, outputs, callback);
};
/**
@ -236,7 +236,7 @@ HTTPWallet.prototype.createTX = function createTX(options, outputs, callback) {
*/
HTTPWallet.prototype.send = function send(options, callback) {
return this.client.send(this.id, options, callback);
this.client.send(this.id, options, callback);
};
/**
@ -244,7 +244,7 @@ HTTPWallet.prototype.send = function send(options, callback) {
*/
HTTPWallet.prototype.sign = function sign(tx, options, callback) {
return this.client.sign(this.id, tx, options, callback);
this.client.sign(this.id, tx, options, callback);
};
/**
@ -252,7 +252,7 @@ HTTPWallet.prototype.sign = function sign(tx, options, callback) {
*/
HTTPWallet.prototype.fillCoins = function fillCoins(tx, callback) {
return this.client.fillCoins(tx, callback);
this.client.fillCoins(tx, callback);
};
/**
@ -260,7 +260,7 @@ HTTPWallet.prototype.fillCoins = function fillCoins(tx, callback) {
*/
HTTPWallet.prototype.getInfo = function getInfo(callback) {
return this.client.getWallet(this.id, callback);
this.client.getWallet(this.id, callback);
};
/**
@ -268,7 +268,7 @@ HTTPWallet.prototype.getInfo = function getInfo(callback) {
*/
HTTPWallet.prototype.getAccounts = function getAccounts(callback) {
return this.client.getAccounts(this.id, callback);
this.client.getAccounts(this.id, callback);
};
/**
@ -276,7 +276,7 @@ HTTPWallet.prototype.getAccounts = function getAccounts(callback) {
*/
HTTPWallet.prototype.getAccount = function getAccount(account, callback) {
return this.client.getAccount(this.id, account, callback);
this.client.getAccount(this.id, account, callback);
};
/**
@ -284,7 +284,7 @@ HTTPWallet.prototype.getAccount = function getAccount(account, callback) {
*/
HTTPWallet.prototype.createAccount = function createAccount(options, callback) {
return this.client.createAccount(this.id, options, callback);
this.client.createAccount(this.id, options, callback);
};
/**
@ -292,7 +292,7 @@ HTTPWallet.prototype.createAccount = function createAccount(options, callback) {
*/
HTTPWallet.prototype.setPassphrase = function setPassphrase(old, new_, callback) {
return this.client.setPassphrase(this.id, old, new_, callback);
this.client.setPassphrase(this.id, old, new_, callback);
};
/**
@ -301,7 +301,7 @@ HTTPWallet.prototype.setPassphrase = function setPassphrase(old, new_, callback)
HTTPWallet.prototype.retoken = function retoken(passphrase, callback) {
var self = this;
return this.client.retoken(this.id, passphrase, function(err, token) {
this.client.retoken(this.id, passphrase, function(err, token) {
if (err)
return callback(err);

View File

@ -121,7 +121,7 @@ LowlevelUp.prototype.get = function get(key, options, callback) {
options = {};
}
return this.binding.get(key, options, function(err, result) {
this.binding.get(key, options, function(err, result) {
if (err) {
if (isNotFound(err))
return callback();
@ -141,7 +141,7 @@ LowlevelUp.prototype.get = function get(key, options, callback) {
LowlevelUp.prototype.put = function put(key, value, options, callback) {
assert(this.loaded, 'Cannot use database before it is loaded.');
return this.binding.put(key, value, options, callback);
this.binding.put(key, value, options, callback);
};
/**
@ -153,7 +153,7 @@ LowlevelUp.prototype.put = function put(key, value, options, callback) {
LowlevelUp.prototype.del = function del(key, options, callback) {
assert(this.loaded, 'Cannot use database before it is loaded.');
return this.binding.del(key, options, callback);
this.binding.del(key, options, callback);
};
/**
@ -170,7 +170,7 @@ LowlevelUp.prototype.batch = function batch(ops, options, callback) {
if (!ops)
return this.binding.batch();
return this.binding.batch(ops, options, callback);
this.binding.batch(ops, options, callback);
};
/**
@ -208,7 +208,7 @@ LowlevelUp.prototype.getProperty = function getProperty(name) {
LowlevelUp.prototype.approximateSize = function approximateSize(start, end, callback) {
assert(this.loaded, 'Cannot use database before it is loaded.');
return this.binding.approximateSize(start, end, callback);
this.binding.approximateSize(start, end, callback);
};
/**
@ -218,7 +218,7 @@ LowlevelUp.prototype.approximateSize = function approximateSize(start, end, call
*/
LowlevelUp.prototype.has = function has(key, callback) {
return this.get(key, function(err, value) {
this.get(key, function(err, value) {
if (err)
return callback(err);
@ -235,7 +235,7 @@ LowlevelUp.prototype.has = function has(key, callback) {
*/
LowlevelUp.prototype.fetch = function fetch(key, parse, callback) {
return this.get(key, function(err, value) {
this.get(key, function(err, value) {
if (err)
return callback(err);
@ -266,17 +266,24 @@ LowlevelUp.prototype.each = function each(options, handler, callback) {
opt = {
gte: options.gte,
lte: options.lte,
keys: true,
keys: options.keys !== false,
values: options.values || false,
fillCache: options.fillCache || false,
keyAsBuffer: options.keyAsBuffer || this.bufferKeys,
keyAsBuffer: this.bufferKeys,
valueAsBuffer: true,
reverse: options.reverse || false
};
// Workaround for a leveldown
// bug I haven't fixed yet.
if (options.limit != null)
opt.limit = options.limit;
if (options.keyAsBuffer != null)
opt.keyAsBuffer = options.keyAsBuffer;
assert(opt.keys || opt.values, 'Keys and/or values must be chosen.');
iter = this.iterator(opt);
(function next(err, key) {
@ -289,8 +296,15 @@ LowlevelUp.prototype.each = function each(options, handler, callback) {
if (err === false)
return iter.end(callback);
if (err === true)
iter.seek(key);
if (err === true) {
try {
iter.seek(key);
} catch (e) {
return iter.end(function() {
callback(e);
});
}
}
iter.next(function(err, key, value) {
if (err) {
@ -299,7 +313,7 @@ LowlevelUp.prototype.each = function each(options, handler, callback) {
});
}
if (key === undefined)
if (key === undefined && value === undefined)
return iter.end(callback);
try {
@ -321,112 +335,16 @@ LowlevelUp.prototype.each = function each(options, handler, callback) {
LowlevelUp.prototype.iterate = function iterate(options, callback) {
var items = [];
var iter, opt;
opt = {
gte: options.gte,
lte: options.lte,
keys: true,
values: options.values || false,
fillCache: options.fillCache || false,
keyAsBuffer: options.keyAsBuffer || this.bufferKeys,
valueAsBuffer: true,
reverse: options.reverse || false
};
// Work around a bug in leveldown that
// I haven't fixed yet, where iterator
// treats limit=undefined as limit=0.
if (options.limit != null)
opt.limit = options.limit;
iter = this.iterator(opt);
(function next() {
iter.next(function(err, key, value) {
if (err) {
return iter.end(function() {
callback(err);
});
}
if (key === undefined) {
return iter.end(function(err) {
if (err)
return callback(err);
return callback(null, items);
});
}
if (options.values) {
if (options.parse) {
try {
value = options.parse(value, key);
} catch (e) {
return iter.end(function() {
return callback(e);
});
}
}
if (value)
items.push(value);
return next();
}
if (options.transform)
key = options.transform(key);
if (key)
items.push(key);
next();
});
})();
};
/**
* Collect all keys from iterator options.
* Proxy the keys to further lookups.
* @param {Object} options - Iterator options.
* @param {Function} callback - Returns [Error, Array].
*/
LowlevelUp.prototype.lookup = function lookup(options, callback) {
var self = this;
var items = [];
assert(!options.values, 'Cannot pass `values` into lookup.');
return this.iterate(options, function(err, keys) {
assert(typeof options.parse === 'function', 'Parse must be a function.');
this.each(options, function(key, value, next) {
var result = options.parse(key, value);
if (result)
items.push(result);
next();
}, function(err) {
if (err)
return callback(err);
utils.forEachSerial(keys, function(key, next) {
self.get(key, function(err, value) {
if (err)
return callback(err);
if (!value)
return next();
if (options.parse) {
try {
value = options.parse(value, key);
} catch (e) {
return callback(e);
}
}
if (value)
items.push(value);
next();
});
}, function(err) {
if (err)
return callback(err);
return callback(null, items);
});
callback(null, items);
});
};
@ -453,7 +371,7 @@ LowlevelUp.prototype.checkVersion = function checkVersion(key, version, callback
if (data !== version)
return callback(new Error(VERSION_ERROR));
return callback();
callback();
});
};

View File

@ -129,7 +129,7 @@ Mempool.prototype._open = function open(callback) {
*/
Mempool.prototype._close = function destroy(callback) {
return callback();
callback();
};
/**
@ -180,7 +180,7 @@ Mempool.prototype.addBlock = function addBlock(block, callback) {
if (this.fees)
this.fees.processBlock(block.height, entries, this.chain.isFull());
return callback();
callback();
};
/**
@ -218,7 +218,7 @@ Mempool.prototype.removeBlock = function removeBlock(block, callback, force) {
self.emit('unconfirmed', tx, block);
return next();
next();
}, true);
}, callback);
};
@ -633,7 +633,7 @@ Mempool.prototype.addTX = function addTX(tx, callback, force) {
0));
}
return callback();
callback();
}, true);
});
});
@ -914,7 +914,7 @@ Mempool.prototype.verify = function verify(entry, callback) {
});
}
return callback();
callback();
});
});
};
@ -1259,7 +1259,7 @@ Mempool.prototype.fillAllCoins = function fillAllCoins(tx, callback) {
if (err)
return callback(err);
return callback(null, tx);
callback(null, tx);
});
};
@ -1340,7 +1340,7 @@ Mempool.prototype.getConfidence = function getConfidence(hash, callback) {
if (result)
return callback(null, constants.confidence.BUILDING);
return callback(null, constants.confidence.DEAD);
callback(null, constants.confidence.DEAD);
});
}
@ -1351,7 +1351,7 @@ Mempool.prototype.getConfidence = function getConfidence(hash, callback) {
if (existing)
return callback(null, constants.confidence.BUILDING);
return callback(null, constants.confidence.UNKNOWN);
callback(null, constants.confidence.UNKNOWN);
});
};
@ -1801,8 +1801,8 @@ function AddressIndex(mempool) {
this.map = {};
}
AddressIndex.prototype.getCoins = function getCoins(hash) {
var items = this.map[hash];
AddressIndex.prototype.getCoins = function getCoins(address) {
var items = this.map[address];
var out = [];
var i, item, outpoint, coin;
@ -1820,8 +1820,8 @@ AddressIndex.prototype.getCoins = function getCoins(hash) {
return out;
};
AddressIndex.prototype.getTX = function getTX(hash) {
var items = this.map[hash];
AddressIndex.prototype.getTX = function getTX(address) {
var items = this.map[address];
var out = [];
var i, hash, tx;

View File

@ -147,7 +147,7 @@ Miner.prototype._open = function open(callback) {
*/
Miner.prototype._close = function close(callback) {
return utils.nextTick(callback);
utils.nextTick(callback);
};
/**
@ -287,7 +287,7 @@ Miner.prototype.createBlock = function createBlock(version, callback) {
attempt.addTX(tx);
}
return callback(null, attempt);
callback(null, attempt);
});
});
};
@ -635,7 +635,7 @@ MinerBlock.prototype.mine = function mine(callback) {
if (!self.findNonce())
return self.mine(callback);
return callback(null, self.block);
callback(null, self.block);
}, 100);
};

View File

@ -1051,7 +1051,7 @@ Peer.prototype.getUTXOs = function getUTXOs(outpoints, callback) {
if (err)
return callback(err);
return callback(null, coins);
callback(null, coins);
});
};
@ -1083,7 +1083,7 @@ Peer.prototype._getUTXOs = function _getUTXOs(outpoints, callback) {
}
}
return callback(null, payload.coins);
callback(null, payload.coins);
});
this.write(this.framer.getUTXOs({
@ -1132,6 +1132,11 @@ Peer.prototype._handleGetUTXOs = function _handleGetUTXOs(payload) {
var coin;
if (self.mempool && payload.mempool) {
if (self.mempool.isSpent(hash, index)) {
hits.push(0);
return next();
}
coin = self.mempool.getCoin(hash, index);
if (coin) {
@ -1139,11 +1144,6 @@ Peer.prototype._handleGetUTXOs = function _handleGetUTXOs(payload) {
coins.push(coin);
return next();
}
if (self.mempool.isSpent(hash, index)) {
hits.push(0);
return next();
}
}
self.chain.db.getCoin(hash, index, function(err, coin) {
@ -1480,7 +1480,7 @@ Peer.prototype._getItem = function _getItem(item, callback) {
if (this.chain.db.options.prune)
return callback();
return this.chain.db.getBlock(item.hash, callback);
this.chain.db.getBlock(item.hash, callback);
};
/**
@ -2333,7 +2333,7 @@ Peer.prototype.sync = function sync(callback) {
return this.getHeaders(tip, null, callback);
}
return this.getBlocks(null, null, callback);
this.getBlocks(null, null, callback);
};
/**

View File

@ -948,7 +948,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
block.rhash);
}
return callback();
callback();
});
};
@ -1273,7 +1273,7 @@ Pool.prototype._handleTX = function _handleTX(tx, peer, callback) {
self.emit('tx', tx, peer);
return callback();
callback();
});
};
@ -1501,7 +1501,7 @@ Pool.prototype.getData = function getData(peer, type, hash, options, callback) {
peer.queue.block.push(item);
return callback(null, false);
callback(null, false);
});
};
@ -1780,7 +1780,7 @@ Pool.prototype.fillCoins = function fillCoins(tx, callback) {
tx.fillCoins(coins);
return callback(null, tx);
callback(null, tx);
});
};
@ -2014,7 +2014,7 @@ Pool.prototype.getIP = function getIP(callback) {
if (IP.version(ip) === -1)
return self.getIP2(callback);
return callback(null, IP.normalize(ip));
callback(null, IP.normalize(ip));
});
};
@ -2044,7 +2044,7 @@ Pool.prototype.getIP2 = function getIP2(callback) {
if (!ip || IP.version(ip[1]) === -1)
return callback(new Error('Could not find IP.'));
return callback(null, IP.normalize(ip[1]));
callback(null, IP.normalize(ip[1]));
});
};

View File

@ -277,7 +277,7 @@ SPVNode.prototype.sendTX = function sendTX(item, wait, callback) {
return utils.nextTick(callback);
}
return this.pool.broadcast(item, callback);
this.pool.broadcast(item, callback);
};
/**
@ -321,7 +321,7 @@ SPVNode.prototype.createWallet = function createWallet(options, callback) {
self.logger.info('Loaded wallet with id=%s address=%s',
wallet.id, wallet.getAddress());
return callback(null, wallet);
callback(null, wallet);
});
};
@ -332,7 +332,7 @@ SPVNode.prototype.createWallet = function createWallet(options, callback) {
*/
SPVNode.prototype.getWallet = function getWallet(id, callback) {
return this.walletdb.get(id, callback);
this.walletdb.get(id, callback);
};
/*

View File

@ -285,7 +285,7 @@ TXDB.prototype.open = function open(callback) {
self.balance = balance;
return callback();
callback();
});
};
@ -431,7 +431,7 @@ TXDB.prototype.commit = function commit(callback) {
return callback(err);
}
self.current = null;
return callback();
callback();
});
};
@ -470,7 +470,7 @@ TXDB.prototype._addOrphan = function _addOrphan(prevout, spender, callback) {
self.put(key, p.render());
return callback();
callback();
});
};
@ -514,7 +514,7 @@ TXDB.prototype._getOrphans = function _getOrphans(hash, index, callback) {
if (err)
return callback(err);
return callback(null, items);
callback(null, items);
});
});
};
@ -608,7 +608,7 @@ TXDB.prototype._verify = function _verify(tx, info, callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, true);
callback(null, true);
});
};
@ -665,7 +665,7 @@ TXDB.prototype._resolveOrphans = function _resolveOrphans(tx, index, callback) {
// Just going to be added again outside.
self.balance.sub(coin);
return callback(null, false);
callback(null, false);
});
});
};
@ -817,7 +817,7 @@ TXDB.prototype.add = function add(tx, info, callback) {
if (tx.ts !== 0)
self.emit('confirmed', tx, info);
return callback(null, true, info);
callback(null, true, info);
});
});
});
@ -872,7 +872,7 @@ TXDB.prototype._removeConflict = function _removeConflict(hash, ref, callback) {
self._removeRecursive(tx, function(err, result, info) {
if (err)
return callback(err);
return callback(null, tx, info);
callback(null, tx, info);
});
});
};
@ -924,7 +924,7 @@ TXDB.prototype._removeRecursive = function _removeRecursive(tx, callback) {
self.commit(function(err) {
if (err)
return callback(err);
return callback(null, result, info);
callback(null, result, info);
});
});
});
@ -950,7 +950,7 @@ TXDB.prototype.isDoubleSpend = function isDoubleSpend(tx, callback) {
}, function(err, result) {
if (err)
return callback(err);
return callback(null, !result);
callback(null, !result);
});
};
@ -1064,7 +1064,7 @@ TXDB.prototype._confirm = function _confirm(tx, info, callback) {
self.emit('tx', tx, info);
self.emit('confirmed', tx, info);
return callback(null, true, info);
callback(null, true, info);
});
});
});
@ -1088,7 +1088,7 @@ TXDB.prototype.remove = function remove(hash, callback, force) {
if (err)
return callback(err);
return callback(null, !!result, info);
callback(null, !!result, info);
});
};
@ -1201,7 +1201,7 @@ TXDB.prototype._remove = function remove(tx, info, callback) {
self.emit('remove tx', tx, info);
return callback(null, true, info);
callback(null, true, info);
});
};
@ -1245,7 +1245,7 @@ TXDB.prototype.unconfirm = function unconfirm(hash, callback, force) {
self.commit(function(err) {
if (err)
return callback(err);
return callback(null, result, info);
callback(null, result, info);
});
});
});
@ -1311,7 +1311,7 @@ TXDB.prototype._unconfirm = function unconfirm(tx, info, callback, force) {
self.emit('unconfirmed', tx, info);
return callback(null, true, info);
callback(null, true, info);
});
};
@ -1439,7 +1439,7 @@ TXDB.prototype.getHistoryHashes = function getHistoryHashes(account, callback) {
lte: account != null
? layout.T(account, constants.HIGH_HASH)
: layout.t(constants.HIGH_HASH),
transform: function(key) {
parse: function(key) {
if (account != null) {
key = layout.Tt(key);
return key[1];
@ -1469,7 +1469,7 @@ TXDB.prototype.getUnconfirmedHashes = function getUnconfirmedHashes(account, cal
lte: account != null
? layout.P(account, constants.HIGH_HASH)
: layout.p(constants.HIGH_HASH),
transform: function(key) {
parse: function(key) {
if (account != null) {
key = layout.Pp(key);
return key[1];
@ -1499,7 +1499,7 @@ TXDB.prototype.getCoinHashes = function getCoinHashes(account, callback) {
lte: account != null
? layout.C(account, constants.HIGH_HASH, 0xffffffff)
: layout.c(constants.HIGH_HASH, 0xffffffff),
transform: function(key) {
parse: function(key) {
if (account != null) {
key = layout.Cc(key);
return [key[1], key[2]];
@ -1542,7 +1542,7 @@ TXDB.prototype.getHeightRangeHashes = function getHeightRangeHashes(account, opt
: layout.h(end, constants.HIGH_HASH),
limit: options.limit,
reverse: options.reverse,
transform: function(key) {
parse: function(key) {
if (account != null) {
key = layout.Hh(key);
return key[2];
@ -1560,7 +1560,7 @@ TXDB.prototype.getHeightRangeHashes = function getHeightRangeHashes(account, opt
*/
TXDB.prototype.getHeightHashes = function getHeightHashes(height, callback) {
return this.getHeightRangeHashes({ start: height, end: height }, callback);
this.getHeightRangeHashes({ start: height, end: height }, callback);
};
/**
@ -1594,7 +1594,7 @@ TXDB.prototype.getRangeHashes = function getRangeHashes(account, options, callba
: layout.m(end, constants.HIGH_HASH),
limit: options.limit,
reverse: options.reverse,
transform: function(key) {
parse: function(key) {
if (account != null) {
key = layout.Mm(key);
return key[2];
@ -1645,7 +1645,7 @@ TXDB.prototype.getRange = function getRange(account, options, callback) {
if (err)
return callback(err);
return callback(null, txs);
callback(null, txs);
});
});
};
@ -1692,9 +1692,10 @@ TXDB.prototype.getHistory = function getHistory(account, callback) {
this.iterate({
gte: layout.t(constants.NULL_HASH),
lte: layout.t(constants.HIGH_HASH),
keys: false,
values: true,
parse: function(data) {
return bcoin.tx.fromExtended(data);
parse: function(key, value) {
return bcoin.tx.fromExtended(value);
}
}, callback);
};
@ -1734,7 +1735,7 @@ TXDB.prototype.getAccountHistory = function getAccountHistory(account, callback)
if (err)
return callback(err);
return callback(null, sortTX(txs));
callback(null, sortTX(txs));
});
});
};
@ -1770,7 +1771,7 @@ TXDB.prototype.getLastTime = function getLastTime(account, callback) {
lastHeight = tx.height;
}
return callback(null, lastTs, lastHeight);
callback(null, lastTs, lastHeight);
});
};
@ -1809,7 +1810,7 @@ TXDB.prototype.getUnconfirmed = function getUnconfirmed(account, callback) {
if (err)
return callback(err);
return callback(null, sortTX(txs));
callback(null, sortTX(txs));
});
});
};
@ -1836,17 +1837,16 @@ TXDB.prototype.getCoins = function getCoins(account, callback) {
this.iterate({
gte: layout.c(constants.NULL_HASH, 0),
lte: layout.c(constants.HIGH_HASH, 0xffffffff),
keys: true,
values: true,
parse: function(data, key) {
parse: function(key, value) {
var parts = layout.cc(key);
var hash = parts[0];
var index = parts[1];
var coin = bcoin.coin.fromRaw(data);
var coin = bcoin.coin.fromRaw(value);
coin.hash = hash;
coin.index = index;
key = hash + index;
self.coinCache.set(key, data);
self.coinCache.set(key, value);
return coin;
}
}, callback);
@ -1882,7 +1882,7 @@ TXDB.prototype.getAccountCoins = function getCoins(account, callback) {
if (err)
return callback(err);
return callback(null, coins);
callback(null, coins);
});
});
};
@ -1894,7 +1894,7 @@ TXDB.prototype.getAccountCoins = function getCoins(account, callback) {
*/
TXDB.prototype.fillHistory = function fillHistory(tx, callback) {
var hash, index, coin, input;
var hash;
if (tx.isCoinbase()) {
callback = utils.asyncify(callback);
@ -1906,12 +1906,11 @@ TXDB.prototype.fillHistory = function fillHistory(tx, callback) {
this.iterate({
gte: layout.d(hash, 0),
lte: layout.d(hash, 0xffffffff),
keys: true,
values: true,
parse: function(value, key) {
index = layout.dd(key)[1];
coin = bcoin.coin.fromRaw(value);
input = tx.inputs[index];
parse: function(key, value) {
var index = layout.dd(key)[1];
var coin = bcoin.coin.fromRaw(value);
var input = tx.inputs[index];
coin.hash = input.prevout.hash;
coin.index = input.prevout.index;
input.coin = coin;
@ -1919,7 +1918,7 @@ TXDB.prototype.fillHistory = function fillHistory(tx, callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, tx);
callback(null, tx);
});
};
@ -1955,7 +1954,7 @@ TXDB.prototype.fillCoins = function fillCoins(tx, callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, tx);
callback(null, tx);
});
};
@ -2016,7 +2015,7 @@ TXDB.prototype.toDetails = function toDetails(tx, callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, out);
callback(null, out);
});
}
@ -2031,7 +2030,7 @@ TXDB.prototype.toDetails = function toDetails(tx, callback) {
if (!info)
return callback(new Error('Info not found.'));
return callback(null, info.toDetails());
callback(null, info.toDetails());
});
});
};
@ -2070,7 +2069,7 @@ TXDB.prototype.getCoin = function getCoin(hash, index, callback) {
}
this.fetch(layout.c(hash, index), function(data) {
coin = bcoin.coin.fromRaw(data);
var coin = bcoin.coin.fromRaw(data);
coin.hash = hash;
coin.index = index;
self.coinCache.set(key, data);
@ -2122,9 +2121,8 @@ TXDB.prototype.getBalance = function getBalance(account, callback) {
this.iterate({
gte: layout.c(constants.NULL_HASH, 0),
lte: layout.c(constants.HIGH_HASH, 0xffffffff),
keys: true,
values: true,
parse: function(data, key) {
parse: function(key, data) {
var parts = layout.cc(key);
var hash = parts[0];
var index = parts[1];
@ -2148,7 +2146,7 @@ TXDB.prototype.getBalance = function getBalance(account, callback) {
if (err)
return callback(err);
return callback(null, balance);
callback(null, balance);
});
};
@ -2215,7 +2213,7 @@ TXDB.prototype.getAccountBalance = function getBalance(account, callback) {
if (err)
return callback(err);
return callback(null, balance);
callback(null, balance);
});
});
};

View File

@ -270,7 +270,7 @@ Wallet.prototype.addKey = function addKey(account, key, callback) {
self.commit(function(err) {
if (err)
return callback(err);
return callback(null, result);
callback(null, result);
});
});
}, true);
@ -317,7 +317,7 @@ Wallet.prototype.removeKey = function removeKey(account, key, callback) {
self.commit(function(err) {
if (err)
return callback(err);
return callback(null, result);
callback(null, result);
});
});
}, true);
@ -396,7 +396,7 @@ Wallet.prototype.retoken = function retoken(passphrase, callback) {
self.commit(function(err) {
if (err)
return callback(err);
return callback(null, self.token);
callback(null, self.token);
});
});
};
@ -524,7 +524,7 @@ Wallet.prototype.createAccount = function createAccount(options, callback, force
self.commit(function(err) {
if (err)
return callback(err);
return callback(null, account);
callback(null, account);
});
});
});
@ -596,7 +596,7 @@ Wallet.prototype.getAccount = function getAccount(account, callback) {
account.wid = self.wid;
account.id = self.id;
return callback(null, account);
callback(null, account);
});
};
@ -679,7 +679,7 @@ Wallet.prototype.createAddress = function createAddress(account, change, callbac
self.commit(function(err) {
if (err)
return callback(err);
return callback(null, result);
callback(null, result);
});
});
}, true);
@ -757,7 +757,7 @@ Wallet.prototype.getPath = function getPath(address, callback) {
path.id = self.id;
return callback(null, path);
callback(null, path);
});
};
@ -785,7 +785,7 @@ Wallet.prototype.getPaths = function getPaths(account, callback) {
}
}
return callback(null, out);
callback(null, out);
});
});
};
@ -885,7 +885,7 @@ Wallet.prototype.fund = function fund(tx, options, callback, force) {
return callback(e);
}
return callback();
callback();
});
});
};
@ -948,7 +948,7 @@ Wallet.prototype.createTX = function createTX(options, callback, force) {
if (total === 0)
return callback(new Error('scriptInputs failed.'));
return callback(null, tx);
callback(null, tx);
});
}, force);
};
@ -992,7 +992,7 @@ Wallet.prototype.send = function send(options, callback) {
self.logger.debug('Sending wallet tx (%s): %s', self.id, tx.rhash);
self.db.emit('send', tx);
return callback(null, tx);
callback(null, tx);
});
});
}, true);
@ -1017,7 +1017,7 @@ Wallet.prototype.resend = function resend(callback) {
for (i = 0; i < txs.length; i++)
self.db.emit('send', txs[i]);
return callback();
callback();
});
};
@ -1048,13 +1048,13 @@ Wallet.prototype.deriveInputs = function deriveInputs(tx, callback) {
ring = account.deriveAddress(path.change, path.index);
rings.push(ring);
return next();
next();
});
}, function(err) {
if (err)
return callback(err);
return callback(null, rings);
callback(null, rings);
});
});
};
@ -1089,7 +1089,7 @@ Wallet.prototype.getKeyring = function getKeyring(address, callback) {
ring = account.deriveAddress(path.change, path.index);
return callback(null, ring);
callback(null, ring);
});
});
};
@ -1115,7 +1115,7 @@ Wallet.prototype.getInputPaths = function getInputPaths(tx, callback) {
if (path)
paths.push(path);
return next();
next();
});
}, function(err) {
if (err)
@ -1173,12 +1173,12 @@ Wallet.prototype.getOutputPaths = function getOutputPaths(tx, callback) {
if (path)
paths.push(path);
return next();
next();
});
}, function(err) {
if (err)
return callback(err);
return callback(null, paths);
callback(null, paths);
});
};
@ -1268,7 +1268,7 @@ Wallet.prototype.syncOutputDepth = function syncOutputDepth(info, callback) {
self.commit(function(err) {
if (err)
return callback(err);
return callback(null, receive);
callback(null, receive);
});
});
};
@ -1296,7 +1296,7 @@ Wallet.prototype.updateBalances = function updateBalances(callback) {
self.db.emit('balance', self.id, balance);
self.emit('balance', balance);
return callback();
callback();
});
};
@ -1352,7 +1352,7 @@ Wallet.prototype.getRedeem = function getRedeem(hash, callback) {
return callback(null, ring.program);
}
return callback(null, ring.script);
callback(null, ring.script);
});
});
};
@ -1379,7 +1379,7 @@ Wallet.prototype.scriptInputs = function scriptInputs(tx, callback) {
for (i = 0; i < rings.length; i++)
total += rings[i].scriptInputs(tx);
return callback(null, total);
callback(null, total);
});
};
@ -1694,7 +1694,7 @@ Wallet.prototype._getIndex = function _getIndex(account, errback, callback) {
if (index === -1)
return errback(new Error('Account not found.'));
return callback.call(self, index, errback);
callback.call(self, index, errback);
});
};
@ -2276,7 +2276,7 @@ Account.prototype.open = function open(callback) {
this.receiveAddress = this.deriveReceive(this.receiveDepth - 1);
this.changeAddress = this.deriveChange(this.changeDepth - 1);
return callback();
callback();
};
/**
@ -2404,7 +2404,7 @@ Account.prototype.addKey = function addKey(key, callback) {
if (err)
return callback(err);
return callback(null, result);
callback(null, result);
});
});
};
@ -2457,7 +2457,7 @@ Account.prototype.removeKey = function removeKey(key, callback) {
this.save();
return callback(null, result);
callback(null, result);
};
/**
@ -2511,7 +2511,7 @@ Account.prototype.createAddress = function createAddress(change, callback) {
self.save();
return callback(null, ring);
callback(null, ring);
});
};
@ -2627,7 +2627,7 @@ Account.prototype.setDepth = function setDepth(receiveDepth, changeDepth, callba
self.save();
return callback(null, receive, change);
callback(null, receive, change);
});
};
@ -2943,7 +2943,7 @@ MasterKey.prototype.unlock = function _unlock(passphrase, timeout, callback) {
self.start(timeout);
return callback(null, self.key);
callback(null, self.key);
});
};
@ -3043,7 +3043,7 @@ MasterKey.prototype.decrypt = function decrypt(passphrase, callback) {
self.iv = null;
self.ciphertext = null;
return callback();
callback();
});
};
@ -3084,7 +3084,7 @@ MasterKey.prototype.encrypt = function encrypt(passphrase, callback) {
self.iv = iv;
self.ciphertext = data;
return callback();
callback();
});
};

View File

@ -297,9 +297,7 @@ WalletDB.prototype.getDepth = function getDepth(callback) {
iter = this.db.iterator({
gte: layout.w(0),
lte: layout.w(0xffffffff),
reverse: true,
keys: true,
fillCache: false
reverse: true
});
iter.next(function(err, key, value) {
@ -390,9 +388,9 @@ WalletDB.prototype.loadFilter = function loadFilter(callback) {
this.db.iterate({
gte: layout.p(constants.NULL_HASH),
lte: layout.p(constants.HIGH_HASH),
transform: function(key) {
key = layout.pp(key);
self.filter.add(key, 'hex');
parse: function(key) {
var hash = layout.pp(key);
self.filter.add(hash, 'hex');
}
}, callback);
};
@ -428,7 +426,6 @@ WalletDB.prototype.dump = function dump(callback) {
this.db.each({
gte: ' ',
lte: '~',
keys: true,
values: true
}, function(key, value, next) {
records[key] = value;
@ -436,7 +433,7 @@ WalletDB.prototype.dump = function dump(callback) {
}, function(err) {
if (err)
return callback(err);
return callback(null, records);
callback(null, records);
});
};
@ -525,7 +522,7 @@ WalletDB.prototype.get = function get(wid, callback) {
if (err)
return callback(err);
return callback(null, wallet);
callback(null, wallet);
});
});
});
@ -599,7 +596,7 @@ WalletDB.prototype.auth = function auth(wid, token, callback) {
if (!utils.ccmp(token, wallet.token))
return callback(new Error('Authentication error.'));
return callback(null, wallet);
callback(null, wallet);
});
};
@ -654,7 +651,7 @@ WalletDB.prototype.create = function create(options, callback) {
self.logger.info('Created wallet %s.', wallet.id);
return callback(null, wallet);
callback(null, wallet);
});
});
};
@ -669,7 +666,7 @@ WalletDB.prototype.has = function has(id, callback) {
this.getWalletID(id, function(err, wid) {
if (err)
return callback(err);
return callback(null, wid != null);
callback(null, wid != null);
});
};
@ -721,7 +718,7 @@ WalletDB.prototype.getAccount = function getAccount(wid, name, callback) {
if (err)
return callback(err);
return callback(null, account);
callback(null, account);
});
});
});
@ -764,7 +761,7 @@ WalletDB.prototype.getAccounts = function getAccounts(wid, callback) {
gte: layout.i(wid, ''),
lte: layout.i(wid, MAX_POINT),
values: true,
parse: function(value, key) {
parse: function(key, value) {
var name = layout.ii(key)[1];
var index = value.readUInt32LE(0, true);
map[index] = name;
@ -781,7 +778,7 @@ WalletDB.prototype.getAccounts = function getAccounts(wid, callback) {
accounts[i] = map[i];
}
return callback(null, accounts);
callback(null, accounts);
});
};
@ -809,7 +806,7 @@ WalletDB.prototype.getAccountIndex = function getAccountIndex(wid, name, callbac
if (!index)
return callback(null, -1);
return callback(null, index.readUInt32LE(0, true));
callback(null, index.readUInt32LE(0, true));
});
};
@ -867,7 +864,7 @@ WalletDB.prototype.createAccount = function createAccount(options, callback) {
account.name,
account.accountIndex);
return callback(null, account);
callback(null, account);
});
});
};
@ -987,7 +984,7 @@ WalletDB.prototype.getAddressPaths = function getAddressPaths(hash, callback) {
self.pathCache.set(hash, paths);
return callback(null, paths);
callback(null, paths);
});
};
@ -1007,7 +1004,7 @@ WalletDB.prototype.hasAddress = function hasAddress(wid, hash, callback) {
if (!paths || !paths[wid])
return callback(null, false);
return callback(null, true);
callback(null, true);
});
};
@ -1026,9 +1023,8 @@ WalletDB.prototype.getAddressHashes = function getAddressHashes(wid, callback) {
this.db.iterate({
gte: layout.p(constants.NULL_HASH),
lte: layout.p(constants.HIGH_HASH),
keys: true,
values: true,
parse: function(value, key) {
parse: function(key, value) {
var paths = parsePaths(value);
if (wid && !paths[wid])
@ -1049,9 +1045,8 @@ WalletDB.prototype.getWalletPaths = function getWalletPaths(wid, callback) {
this.db.iterate({
gte: layout.p(constants.NULL_HASH),
lte: layout.p(constants.HIGH_HASH),
keys: true,
values: true,
parse: function(value, key) {
parse: function(key, value) {
var hash = layout.pp(key);
var paths = parsePaths(value, hash);
var path = paths[wid];
@ -1073,7 +1068,7 @@ WalletDB.prototype.getWallets = function getWallets(callback) {
this.db.iterate({
gte: layout.l(''),
lte: layout.l(MAX_POINT),
transform: function(key) {
parse: function(key) {
return layout.ll(key);
}
}, callback);
@ -1148,7 +1143,7 @@ WalletDB.prototype.mapWallets = function mapWallets(tx, callback) {
wallets = PathInfo.map(self, tx, table);
return callback(null, wallets);
callback(null, wallets);
});
};
@ -1173,7 +1168,7 @@ WalletDB.prototype.getPathInfo = function getPathInfo(wallet, tx, callback) {
info = new PathInfo(self, wallet.wid, tx, table);
info.id = wallet.id;
return callback(null, info);
callback(null, info);
});
};
@ -1210,7 +1205,7 @@ WalletDB.prototype.getTable = function getTable(hashes, callback) {
table[hash] = values;
count += values.length;
return next();
next();
});
}, function(err) {
if (err)
@ -1219,7 +1214,7 @@ WalletDB.prototype.getTable = function getTable(hashes, callback) {
if (count === 0)
return callback();
return callback(null, table);
callback(null, table);
});
};
@ -1273,7 +1268,7 @@ WalletDB.prototype.setTip = function setTip(hash, height, callback) {
self.tip = block.hash;
self.height = block.height;
return callback();
callback();
});
};
@ -1459,7 +1454,7 @@ WalletDB.prototype.removeBlock = function removeBlock(entry, callback, force) {
self.tip = block.hash;
self.height = block.height;
return callback();
callback();
});
});
});
@ -1515,7 +1510,7 @@ WalletDB.prototype.addTX = function addTX(tx, callback, force) {
}, function(err) {
if (err)
return callback(err);
return callback(null, wallets);
callback(null, wallets);
});
});
};
@ -1535,7 +1530,7 @@ WalletDB.prototype.getAddressPath = function getAddressPath(wid, hash, callback)
if (!paths || !paths[wid])
return callback();
return callback(null, paths[wid]);
callback(null, paths[wid]);
});
};

View File

@ -237,7 +237,7 @@ Workers.prototype.execute = function execute(method, args, timeout, callback) {
*/
Workers.prototype.verify = function verify(tx, flags, callback) {
return this.execute('verify', [tx, flags], -1, callback);
this.execute('verify', [tx, flags], -1, callback);
};
/**
@ -254,7 +254,7 @@ Workers.prototype.sign = function sign(rings, master, tx, index, type, callback)
var args = [rings, master, tx, index, type];
var i, input, sig, sigs, total;
return this.execute('sign', args, -1, function(err, result) {
this.execute('sign', args, -1, function(err, result) {
if (err)
return callback(err);
@ -268,7 +268,7 @@ Workers.prototype.sign = function sign(rings, master, tx, index, type, callback)
input.witness = sig[1];
}
return callback(null, total);
callback(null, total);
});
};
@ -279,7 +279,7 @@ Workers.prototype.sign = function sign(rings, master, tx, index, type, callback)
*/
Workers.prototype.mine = function mine(attempt, callback) {
return this.execute('mine', [attempt], -1, callback);
this.execute('mine', [attempt], -1, callback);
};
/**
@ -295,7 +295,7 @@ Workers.prototype.mine = function mine(attempt, callback) {
*/
Workers.prototype.scrypt = function scrypt(passwd, salt, N, r, p, len, callback) {
return this.execute('scrypt', [passwd, salt, N, r, p, len], -1, callback);
this.execute('scrypt', [passwd, salt, N, r, p, len], -1, callback);
};
/**

View File

@ -220,7 +220,7 @@ describe('Chain', function() {
it('should rescan for transactions', function(cb) {
var txs = [];
walletdb.getAddresses(function(err, hashes) {
walletdb.getAddressHashes(function(err, hashes) {
assert.ifError(err);
chain.db.scan(null, hashes, function(block, tx, next) {
txs = txs.concat(tx);