refactor lib/bitcoind.js.
This commit is contained in:
parent
263bc2fa73
commit
0b07a7839b
@ -364,8 +364,8 @@ Bitcoin.prototype.start = function(options, callback) {
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getBlock = function(blockHash, callback) {
|
||||
return bitcoindjs.getBlock(blockHash, function(err, block) {
|
||||
Bitcoin.prototype.getBlock = function(blockhash, callback) {
|
||||
return bitcoindjs.getBlock(blockhash, function(err, block) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, bitcoin.block(block));
|
||||
});
|
||||
@ -379,35 +379,43 @@ Bitcoin.prototype.getBlockHeight = function(height, callback) {
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getTransaction =
|
||||
Bitcoin.prototype.getTx = function(txHash, blockHash, callback) {
|
||||
if (typeof blockHash === 'function') {
|
||||
callback = blockHash;
|
||||
blockHash = '';
|
||||
Bitcoin.prototype.getTx = function(txid, blockhash, callback) {
|
||||
var traverse = false;
|
||||
if (typeof txid === 'object') {
|
||||
var options = txid;
|
||||
callback = blockhash;
|
||||
txid = options.txid || options.tx || options.txhash || options.id || options.hash;
|
||||
blockhash = options.blockhash || options.block;
|
||||
traverse = options.traverse;
|
||||
}
|
||||
if (typeof blockHash !== 'string') {
|
||||
if (blockHash) {
|
||||
blockHash = blockHash.hash
|
||||
|| blockHash.blockhash
|
||||
|| (blockHash.getHash && blockHash.getHash())
|
||||
if (typeof blockhash === 'function') {
|
||||
callback = blockhash;
|
||||
blockhash = '';
|
||||
}
|
||||
if (typeof blockhash !== 'string') {
|
||||
if (blockhash) {
|
||||
blockhash = blockhash.hash
|
||||
|| blockhash.blockhash
|
||||
|| (blockhash.getHash && blockhash.getHash())
|
||||
|| '';
|
||||
} else {
|
||||
blockHash = '';
|
||||
blockhash = '';
|
||||
}
|
||||
}
|
||||
if (blockHash && typeof blockHash === 'string') {
|
||||
return bitcoindjs.getTransaction(txHash, blockHash, function(err, tx) {
|
||||
if (blockhash && typeof blockhash === 'string') {
|
||||
return bitcoindjs.getTransaction(txid, blockhash, traverse, function(err, tx) {
|
||||
if (err) return callback(err);
|
||||
bitcoin.db.set('tx-block/' + txHash,
|
||||
{ hash: blockHash }, utils.NOOP);
|
||||
bitcoin.db.set('tx-block/' + txid,
|
||||
{ hash: blockhash }, utils.NOOP);
|
||||
return callback(null, bitcoin.tx(tx));
|
||||
});
|
||||
}
|
||||
return bitcoin.db.get('tx-block/' + txHash, function(err, block) {
|
||||
return bitcoin.db.get('tx-block/' + txid, function(err, block) {
|
||||
// Will traverse blockchain if no block - slow:
|
||||
return bitcoinjs.getTransaction(txHash, block ? block.hash : '', function(err, tx) {
|
||||
return bitcoinjs.getTransaction(txid, block ? block.hash : '', traverse, function(err, tx) {
|
||||
if (err) return callback(err);
|
||||
if (!block) {
|
||||
bitcoin.db.set('tx-block/' + txHash,
|
||||
bitcoin.db.set('tx-block/' + txid,
|
||||
{ hash: tx.blockhash }, utils.NOOP);
|
||||
}
|
||||
return callback(null, bitcoin.tx(tx));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user