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