rpc: refactor.
This commit is contained in:
parent
814c18437d
commit
9ae91af2a8
@ -1176,7 +1176,7 @@ RPC.prototype.gettxout = co(function* gettxout(args) {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bestblock: utils.revHex(this.chain.tip.hash),
|
bestblock: this.chain.tip.rhash,
|
||||||
confirmations: coin.getConfirmations(this.chain.height),
|
confirmations: coin.getConfirmations(this.chain.height),
|
||||||
value: +utils.btc(coin.value),
|
value: +utils.btc(coin.value),
|
||||||
scriptPubKey: this._scriptToJSON(coin.script, true),
|
scriptPubKey: this._scriptToJSON(coin.script, true),
|
||||||
@ -1187,7 +1187,7 @@ RPC.prototype.gettxout = co(function* gettxout(args) {
|
|||||||
|
|
||||||
RPC.prototype.gettxoutproof = co(function* gettxoutproof(args) {
|
RPC.prototype.gettxoutproof = co(function* gettxoutproof(args) {
|
||||||
var uniq = {};
|
var uniq = {};
|
||||||
var i, txids, block, hash, last, tx, coins;
|
var i, txids, block, hash, txid, tx, coins;
|
||||||
|
|
||||||
if (args.help || (args.length !== 1 && args.length !== 2))
|
if (args.help || (args.length !== 1 && args.length !== 2))
|
||||||
throw new RPCError('gettxoutproof ["txid",...] ( blockhash )');
|
throw new RPCError('gettxoutproof ["txid",...] ( blockhash )');
|
||||||
@ -1199,40 +1199,39 @@ RPC.prototype.gettxoutproof = co(function* gettxoutproof(args) {
|
|||||||
throw new RPCError('Cannot get coins when pruned.');
|
throw new RPCError('Cannot get coins when pruned.');
|
||||||
|
|
||||||
txids = toArray(args[0]);
|
txids = toArray(args[0]);
|
||||||
block = args[1];
|
hash = args[1];
|
||||||
|
|
||||||
if (!txids || txids.length === 0)
|
if (!txids || txids.length === 0)
|
||||||
throw new RPCError('Invalid parameter.');
|
throw new RPCError('Invalid parameter.');
|
||||||
|
|
||||||
if (block) {
|
if (hash) {
|
||||||
block = toHash(block);
|
hash = toHash(hash);
|
||||||
if (!block)
|
if (!hash)
|
||||||
throw new RPCError('Invalid parameter.');
|
throw new RPCError('Invalid parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < txids.length; i++) {
|
for (i = 0; i < txids.length; i++) {
|
||||||
hash = toHash(txids[i]);
|
txid = toHash(txids[i]);
|
||||||
|
|
||||||
if (!hash)
|
if (!txid)
|
||||||
throw new RPCError('Invalid parameter.');
|
throw new RPCError('Invalid parameter.');
|
||||||
|
|
||||||
if (uniq[hash])
|
if (uniq[txid])
|
||||||
throw new RPCError('Duplicate txid.');
|
throw new RPCError('Duplicate txid.');
|
||||||
|
|
||||||
uniq[hash] = true;
|
uniq[txid] = true;
|
||||||
txids[i] = hash;
|
txids[i] = txid;
|
||||||
last = hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hash) {
|
if (hash) {
|
||||||
block = yield this.chain.db.getBlock(hash);
|
block = yield this.chain.db.getBlock(hash);
|
||||||
} else if (this.chain.options.indexTX) {
|
} else if (this.chain.options.indexTX) {
|
||||||
tx = yield this.chain.db.getTX(last);
|
tx = yield this.chain.db.getTX(txid);
|
||||||
if (!tx)
|
if (!tx)
|
||||||
return;
|
return;
|
||||||
block = yield this.chain.db.getBlock(tx.block);
|
block = yield this.chain.db.getBlock(tx.block);
|
||||||
} else {
|
} else {
|
||||||
coins = yield this.chain.db.getCoins(last);
|
coins = yield this.chain.db.getCoins(txid);
|
||||||
if (!coins)
|
if (!coins)
|
||||||
return;
|
return;
|
||||||
block = yield this.chain.db.getBlock(coins.height);
|
block = yield this.chain.db.getBlock(coins.height);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user