rpc: refactor.

This commit is contained in:
Christopher Jeffrey 2016-11-18 15:00:56 -08:00
parent 814c18437d
commit 9ae91af2a8
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1176,7 +1176,7 @@ RPC.prototype.gettxout = co(function* gettxout(args) {
return null;
return {
bestblock: utils.revHex(this.chain.tip.hash),
bestblock: this.chain.tip.rhash,
confirmations: coin.getConfirmations(this.chain.height),
value: +utils.btc(coin.value),
scriptPubKey: this._scriptToJSON(coin.script, true),
@ -1187,7 +1187,7 @@ RPC.prototype.gettxout = co(function* gettxout(args) {
RPC.prototype.gettxoutproof = co(function* gettxoutproof(args) {
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))
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.');
txids = toArray(args[0]);
block = args[1];
hash = args[1];
if (!txids || txids.length === 0)
throw new RPCError('Invalid parameter.');
if (block) {
block = toHash(block);
if (!block)
if (hash) {
hash = toHash(hash);
if (!hash)
throw new RPCError('Invalid parameter.');
}
for (i = 0; i < txids.length; i++) {
hash = toHash(txids[i]);
txid = toHash(txids[i]);
if (!hash)
if (!txid)
throw new RPCError('Invalid parameter.');
if (uniq[hash])
if (uniq[txid])
throw new RPCError('Duplicate txid.');
uniq[hash] = true;
txids[i] = hash;
last = hash;
uniq[txid] = true;
txids[i] = txid;
}
if (hash) {
block = yield this.chain.db.getBlock(hash);
} else if (this.chain.options.indexTX) {
tx = yield this.chain.db.getTX(last);
tx = yield this.chain.db.getTX(txid);
if (!tx)
return;
block = yield this.chain.db.getBlock(tx.block);
} else {
coins = yield this.chain.db.getCoins(last);
coins = yield this.chain.db.getCoins(txid);
if (!coins)
return;
block = yield this.chain.db.getBlock(coins.height);