rpc: explicitly pass in height and network.

This commit is contained in:
Christopher Jeffrey 2016-08-10 20:59:49 -07:00
parent e872f5985c
commit 0eaa42bb42
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -769,6 +769,7 @@ RPC.prototype.getblock = function getblock(args, callback) {
}; };
RPC.prototype.txToJSON = function txToJSON(tx) { RPC.prototype.txToJSON = function txToJSON(tx) {
var self = this;
return { return {
txid: tx.txid, txid: tx.txid,
hash: tx.wtxid, hash: tx.wtxid,
@ -800,17 +801,17 @@ RPC.prototype.txToJSON = function txToJSON(tx) {
return { return {
value: +utils.btc(output.value), value: +utils.btc(output.value),
n: i, n: i,
scriptPubKey: scriptToJSON(output.script, true) scriptPubKey: self._scriptToJSON(output.script, true)
}; };
}), }),
blockhash: tx.block || null, blockhash: tx.block || null,
confirmations: tx.getConfirmations(), confirmations: tx.getConfirmations(this.chain.height),
time: tx.ts, time: tx.ts,
blocktime: tx.ts blocktime: tx.ts
}; };
}; };
function scriptToJSON(script, hex) { RPC.prototype._scriptToJSON = function scriptToJSON(script, hex) {
var out = {}; var out = {};
var type, address; var type, address;
@ -826,10 +827,10 @@ function scriptToJSON(script, hex) {
address = script.getAddress(); address = script.getAddress();
out.addresses = address ? [address.toBase58()] : []; out.addresses = address ? [address.toBase58(this.network)] : [];
return out; return out;
} };
RPC.prototype.getblockhash = function getblockhash(args, callback) { RPC.prototype.getblockhash = function getblockhash(args, callback) {
var height; var height;
@ -1097,7 +1098,7 @@ RPC.prototype.mempoolToJSON = function mempoolToJSON(verbose, callback) {
descendantcount: 0, descendantcount: 0,
descendantsize: entry.size, descendantsize: entry.size,
descendantfees: entry.fees, descendantfees: entry.fees,
depends: tx.getPrevout().map(utils.revHex) depends: []
}; };
next(); next();
@ -1147,9 +1148,9 @@ RPC.prototype.gettxout = function gettxout(args, callback) {
callback(null, { callback(null, {
bestblock: utils.revHex(self.chain.tip.hash), bestblock: utils.revHex(self.chain.tip.hash),
confirmations: coin.getConfirmations(), confirmations: coin.getConfirmations(self.chain.height),
value: +utils.btc(coin.value), value: +utils.btc(coin.value),
scriptPubKey: scriptToJSON(coin.script, true), scriptPubKey: self._scriptToJSON(coin.script, true),
version: coin.version, version: coin.version,
coinbase: coin.coinbase coinbase: coin.coinbase
}); });
@ -1834,7 +1835,7 @@ RPC.prototype.createrawtransaction = function createrawtransaction(args, callbac
} }
address = bcoin.address.fromBase58(key); address = bcoin.address.fromBase58(key);
b58 = address.toBase58(); b58 = address.toBase58(this.network);
if (addrs[b58]) if (addrs[b58])
return callback(new RPCError('Duplicate address')); return callback(new RPCError('Duplicate address'));
@ -1881,8 +1882,8 @@ RPC.prototype.decodescript = function decodescript(args, callback) {
hash = utils.hash160(script.toRaw()); hash = utils.hash160(script.toRaw());
address = bcoin.address.fromHash(hash, bcoin.script.types.SCRIPTHASH); address = bcoin.address.fromHash(hash, bcoin.script.types.SCRIPTHASH);
script = scriptToJSON(script); script = this._scriptToJSON(script);
script.p2sh = address.toBase58(); script.p2sh = address.toBase58(this.network);
callback(null, script); callback(null, script);
}; };
@ -2212,6 +2213,8 @@ RPC.prototype._createRedeem = function _createRedeem(args, callback) {
/* Utility functions */ /* Utility functions */
RPC.prototype.createmultisig = function createmultisig(args, callback) { RPC.prototype.createmultisig = function createmultisig(args, callback) {
var self = this;
if (args.help || args.length < 2 || args.length > 2) if (args.help || args.length < 2 || args.length > 2)
return callback(new RPCError('createmultisig nrequired ["key",...]')); return callback(new RPCError('createmultisig nrequired ["key",...]'));
@ -2220,7 +2223,7 @@ RPC.prototype.createmultisig = function createmultisig(args, callback) {
return callback(err); return callback(err);
callback(null, { callback(null, {
address: script.getAddress().toBase58(), address: script.getAddress().toBase58(self.network),
redeemScript: script.toJSON() redeemScript: script.toJSON()
}); });
}); });
@ -2258,12 +2261,13 @@ RPC.prototype.createwitnessaddress = function createwitnessaddress(args, callbac
program = this._scriptForWitness(script); program = this._scriptForWitness(script);
callback(null, { callback(null, {
address: program.getAddress().toBase58(), address: program.getAddress().toBase58(this.network),
witnessScript: program.toJSON() witnessScript: program.toJSON()
}); });
}; };
RPC.prototype.validateaddress = function validateaddress(args, callback) { RPC.prototype.validateaddress = function validateaddress(args, callback) {
var self = this;
var b58, address, json; var b58, address, json;
if (args.help || args.length !== 1) if (args.help || args.length !== 1)
@ -2285,7 +2289,7 @@ RPC.prototype.validateaddress = function validateaddress(args, callback) {
json = { json = {
isvalid: true, isvalid: true,
address: address.toBase58(), address: address.toBase58(self.network),
scriptPubKey: address.toScript().toJSON(), scriptPubKey: address.toScript().toJSON(),
ismine: ring ? true : false, ismine: ring ? true : false,
iswatchonly: false iswatchonly: false
@ -2902,6 +2906,7 @@ RPC.prototype.getreceivedbyaddress = function getreceivedbyaddress(args, callbac
}; };
RPC.prototype._toWalletTX = function _toWalletTX(tx, callback) { RPC.prototype._toWalletTX = function _toWalletTX(tx, callback) {
var self = this;
var receive, member, json; var receive, member, json;
this.walletdb.tx.getMap(tx, function(err, map) { this.walletdb.tx.getMap(tx, function(err, map) {
@ -2917,7 +2922,7 @@ RPC.prototype._toWalletTX = function _toWalletTX(tx, callback) {
json = { json = {
amount: +utils.btc(tx.getOutputValue()), amount: +utils.btc(tx.getOutputValue()),
confirmations: tx.getConfirmations(), confirmations: tx.getConfirmations(self.chain.height),
blockhash: tx.block ? utils.revHex(tx.block) : null, blockhash: tx.block ? utils.revHex(tx.block) : null,
blockindex: tx.index, blockindex: tx.index,
blocktime: tx.ts, blocktime: tx.ts,
@ -2928,7 +2933,7 @@ RPC.prototype._toWalletTX = function _toWalletTX(tx, callback) {
'bip125-replaceable': 'no', 'bip125-replaceable': 'no',
details: [{ details: [{
account: member.name, account: member.name,
address: member.paths[0].address.toBase58(), address: member.paths[0].address.toBase58(self.network),
category: receive ? 'receive' : 'send', category: receive ? 'receive' : 'send',
amount: +utils.btc(member.value), amount: +utils.btc(member.value),
label: member.name, label: member.name,
@ -3163,7 +3168,7 @@ RPC.prototype.listsinceblock = function listsinceblock(args, callback) {
if (tx.height < height) if (tx.height < height)
return next(); return next();
if (tx.getConfirmations() < conf) if (tx.getConfirmations(self.chain.height) < conf)
return next(); return next();
if (!highest || tx.height > highest) if (!highest || tx.height > highest)
@ -3191,6 +3196,7 @@ RPC.prototype.listsinceblock = function listsinceblock(args, callback) {
}; };
RPC.prototype._toListTX = function _toListTX(tx, callback) { RPC.prototype._toListTX = function _toListTX(tx, callback) {
var self = this;
var receive, member, json; var receive, member, json;
this.walletdb.tx.getMap(tx, function(err, map) { this.walletdb.tx.getMap(tx, function(err, map) {
@ -3206,12 +3212,12 @@ RPC.prototype._toListTX = function _toListTX(tx, callback) {
json = { json = {
account: member.name, account: member.name,
address: member.paths[0].address.toBase58(), address: member.paths[0].address.toBase58(self.network),
category: receive ? 'receive' : 'send', category: receive ? 'receive' : 'send',
amount: +utils.btc(member.value), amount: +utils.btc(member.value),
label: member.name, label: member.name,
vout: 0, vout: 0,
confirmations: tx.getConfirmations(), confirmations: tx.getConfirmations(self.chain.height),
blockhash: tx.block ? utils.revHex(tx.block) : null, blockhash: tx.block ? utils.revHex(tx.block) : null,
blockindex: tx.index, blockindex: tx.index,
blocktime: tx.ts, blocktime: tx.ts,
@ -3344,7 +3350,7 @@ RPC.prototype.listunspent = function listunspent(args, callback) {
out.push({ out.push({
txid: utils.revHex(coin.hash), txid: utils.revHex(coin.hash),
vout: coin.index, vout: coin.index,
address: address ? address.toBase58() : null, address: address ? address.toBase58(self.network) : null,
account: ring ? ring.name : undefined, account: ring ? ring.name : undefined,
redeemScript: ring && ring.script redeemScript: ring && ring.script
? ring.script.toJSON() ? ring.script.toJSON()