more mempool work.
This commit is contained in:
parent
703a89cc59
commit
bba77b4150
@ -130,16 +130,7 @@ ChainBlock.prototype.free = function free() {
|
||||
};
|
||||
|
||||
ChainBlock.prototype.isMainChain = function isMainChain(callback) {
|
||||
var self = this;
|
||||
return this.chain.db.getHash(this.height, function(err, hash) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!hash)
|
||||
return callback(null, false);
|
||||
|
||||
return callback(null, self.hash === hash);
|
||||
});
|
||||
return this.chain.db.isMainChain(this, callback);
|
||||
};
|
||||
|
||||
ChainBlock.prototype.getAncestorByHeight = function getAncestorByHeight(height, callback) {
|
||||
|
||||
@ -484,6 +484,33 @@ ChainDB.prototype.getNextHash = function getNextHash(hash, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
ChainDB.prototype.isMainChain = function isMainChain(hash, callback) {
|
||||
var self = this;
|
||||
var query;
|
||||
|
||||
if (hash instanceof bcoin.chainblock) {
|
||||
query = hash.height;
|
||||
hash = hash.hash;
|
||||
} else {
|
||||
query = hash;
|
||||
}
|
||||
|
||||
return this.getHeight(query, function(err, height) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
return self.getHash(height, function(err, existing) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!existing)
|
||||
return callback(null, false);
|
||||
|
||||
return callback(null, hash === existing);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
ChainDB.prototype.reset = function reset(block, callback) {
|
||||
var self = this;
|
||||
var batch;
|
||||
@ -1020,6 +1047,15 @@ ChainDB.prototype.getTX = function getTX(hash, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
ChainDB.prototype.hasTX = function hasTX(hash, callback) {
|
||||
return this.getTX(hash, function(err, tx) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
return callback(null, tx != null);
|
||||
});
|
||||
};
|
||||
|
||||
ChainDB.prototype.getFullTX = function getFullTX(hash, callback) {
|
||||
var self = this;
|
||||
|
||||
|
||||
@ -369,31 +369,15 @@ Fullnode.prototype.getTXByAddress = function getTXByAddress(addresses, callback)
|
||||
};
|
||||
|
||||
Fullnode.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||
var self = this;
|
||||
|
||||
this.mempool.fillCoins(tx, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (tx.hasCoins())
|
||||
return callback(null, tx);
|
||||
|
||||
self.chain.db.fillCoins(tx, callback);
|
||||
});
|
||||
return this.mempool.fillAllCoins(tx, callback);
|
||||
};
|
||||
|
||||
Fullnode.prototype.fillTX = function fillTX(tx, callback) {
|
||||
var self = this;
|
||||
return this.mempool.fillAllTX(tx, callback);
|
||||
};
|
||||
|
||||
this.mempool.fillTX(tx, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (tx.hasCoins())
|
||||
return callback(null, tx);
|
||||
|
||||
self.chain.db.fillTX(tx, callback);
|
||||
});
|
||||
Fullnode.prototype.getConfidence = function getConfidence(tx, callback) {
|
||||
return this.mempool.getConfidence(tx, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -54,6 +54,9 @@ function getLocation(name) {
|
||||
}
|
||||
|
||||
function getBackend(backend) {
|
||||
if (bcoin.isBrowser)
|
||||
return require('level-js');
|
||||
|
||||
if (typeof backend !== 'string')
|
||||
backend = process.env.BCOIN_DB;
|
||||
|
||||
@ -66,14 +69,8 @@ function getBackend(backend) {
|
||||
else if (backend === 'memory')
|
||||
backend = 'memdown';
|
||||
|
||||
// Require directly for browserify
|
||||
if (backend === 'memdown')
|
||||
return require('memdown');
|
||||
|
||||
if (bcoin.isBrowser)
|
||||
return require('level-js');
|
||||
|
||||
bcoin.ensurePrefix();
|
||||
if (backend !== 'memdown')
|
||||
bcoin.ensurePrefix();
|
||||
|
||||
return require(backend);
|
||||
}
|
||||
@ -94,6 +91,22 @@ function destroy(name, backend, callback) {
|
||||
backend.destroy(file, callback);
|
||||
}
|
||||
|
||||
function repair(name, backend, callback) {
|
||||
var file = getLocation(name);
|
||||
|
||||
if (!callback) {
|
||||
callback = backend;
|
||||
backend = null;
|
||||
}
|
||||
|
||||
backend = getBackend(backend);
|
||||
|
||||
if (!backend.repair)
|
||||
return utils.asyncify(callback)(new Error('Cannot repair.'));
|
||||
|
||||
backend.repair(file, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* LowlevelUp
|
||||
*
|
||||
@ -204,5 +217,6 @@ LowlevelUp.prototype.approximateSize = function approximateSize(start, end, call
|
||||
exports = ldb;
|
||||
exports.LowlevelUp = LowlevelUp;
|
||||
exports.destroy = destroy;
|
||||
exports.repair = repair;
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -337,3 +337,12 @@ exports.thresholdStates = {
|
||||
ACTIVE: 3,
|
||||
FAILED: 4
|
||||
};
|
||||
|
||||
// bitcoinj style confidence calculation
|
||||
exports.confidence = {
|
||||
BUILDING: 1,
|
||||
PENDING: 2,
|
||||
DEAD: 4,
|
||||
INCONFLICT: 5,
|
||||
UNKNOWN: 0
|
||||
};
|
||||
|
||||
@ -30,19 +30,19 @@
|
||||
"dependencies": {
|
||||
"bn.js": "4.11.0",
|
||||
"elliptic": "6.2.3",
|
||||
"leveldown": "git://github.com/Level/leveldown.git#master",
|
||||
"memdown": "1.1.2"
|
||||
"leveldown": "git://github.com/Level/leveldown.git#master"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"secp256k1": "3.0.0",
|
||||
"socket.io": "1.45.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "13.0.0",
|
||||
"hash.js": "1.0.3",
|
||||
"level-js": "2.2.3",
|
||||
"browserify": "13.0.0",
|
||||
"uglify-js": "2.6.1",
|
||||
"memdown": "1.1.2",
|
||||
"mocha": "1.21.5",
|
||||
"uglify-js": "2.6.1",
|
||||
"v8-profiler": "5.6.0"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user