rpc: fix tx json.
This commit is contained in:
parent
de55c82227
commit
6b639017d4
@ -9,7 +9,6 @@
|
|||||||
var bcoin = require('../env');
|
var bcoin = require('../env');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
var IP = require('../ip');
|
var IP = require('../ip');
|
||||||
var assert = utils.assert;
|
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
|
|
||||||
function RPC(node) {
|
function RPC(node) {
|
||||||
@ -2907,7 +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 self = this;
|
||||||
var receive, member, json;
|
var i, det, receive, member, sent, received, json;
|
||||||
|
|
||||||
this.walletdb.tx.toDetails(this.wallet.id, tx, function(err, details) {
|
this.walletdb.tx.toDetails(this.wallet.id, tx, function(err, details) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -2916,11 +2915,56 @@ RPC.prototype._toWalletTX = function _toWalletTX(tx, callback) {
|
|||||||
if (!details)
|
if (!details)
|
||||||
return callback(new RPCError('TX not found.'));
|
return callback(new RPCError('TX not found.'));
|
||||||
|
|
||||||
receive = details.isReceive();
|
det = [];
|
||||||
member = details.getMember();
|
sent = 0;
|
||||||
|
received = 0;
|
||||||
|
receive = true;
|
||||||
|
|
||||||
|
for (i = 0; i < details.inputs.length; i++) {
|
||||||
|
member = details.inputs[i];
|
||||||
|
if (member.path) {
|
||||||
|
receive = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < details.outputs.length; i++) {
|
||||||
|
member = details.outputs[i];
|
||||||
|
|
||||||
|
if (member.path) {
|
||||||
|
if (member.path.change === 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
det.push({
|
||||||
|
account: member.path.name,
|
||||||
|
address: member.address.toBase58(self.network),
|
||||||
|
category: 'receive',
|
||||||
|
amount: +utils.btc(member.value),
|
||||||
|
label: member.path.name,
|
||||||
|
vout: i
|
||||||
|
});
|
||||||
|
|
||||||
|
received += member.value;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
det.push({
|
||||||
|
account: '',
|
||||||
|
address: member.address
|
||||||
|
? member.address.toBase58(self.network)
|
||||||
|
: null,
|
||||||
|
category: 'send',
|
||||||
|
amount: -(+utils.btc(member.value)),
|
||||||
|
fee: -(+utils.btc(details.fee)),
|
||||||
|
vout: i
|
||||||
|
});
|
||||||
|
|
||||||
|
sent += member.value;
|
||||||
|
}
|
||||||
|
|
||||||
json = {
|
json = {
|
||||||
amount: +utils.btc(details.getValue()),
|
amount: +utils.btc(receive ? received : -sent),
|
||||||
confirmations: details.confirmations,
|
confirmations: details.confirmations,
|
||||||
blockhash: details.block ? utils.revHex(details.block) : null,
|
blockhash: details.block ? utils.revHex(details.block) : null,
|
||||||
blockindex: details.index,
|
blockindex: details.index,
|
||||||
@ -2930,14 +2974,7 @@ RPC.prototype._toWalletTX = function _toWalletTX(tx, callback) {
|
|||||||
time: details.ps,
|
time: details.ps,
|
||||||
timereceived: details.ps,
|
timereceived: details.ps,
|
||||||
'bip125-replaceable': 'no',
|
'bip125-replaceable': 'no',
|
||||||
details: [{
|
details: det,
|
||||||
account: member.path.name,
|
|
||||||
address: member.address.toBase58(self.network),
|
|
||||||
category: receive ? 'receive' : 'send',
|
|
||||||
amount: +utils.btc(member.value),
|
|
||||||
label: member.path.name,
|
|
||||||
vout: 0
|
|
||||||
}],
|
|
||||||
hex: details.tx.toRaw().toString('hex')
|
hex: details.tx.toRaw().toString('hex')
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3196,7 +3233,8 @@ 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 self = this;
|
||||||
var receive, member, json;
|
var i, receive, member, det, sent, received;
|
||||||
|
var sendMember, recMember, json;
|
||||||
|
|
||||||
this.walletdb.tx.toDetails(this.wallet.id, tx, function(err, details) {
|
this.walletdb.tx.toDetails(this.wallet.id, tx, function(err, details) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -3205,14 +3243,41 @@ RPC.prototype._toListTX = function _toListTX(tx, callback) {
|
|||||||
if (!details)
|
if (!details)
|
||||||
return callback(new RPCError('TX not found.'));
|
return callback(new RPCError('TX not found.'));
|
||||||
|
|
||||||
receive = details.isReceive();
|
det = [];
|
||||||
member = details.getMember();
|
sent = 0;
|
||||||
|
received = 0;
|
||||||
|
receive = true;
|
||||||
|
|
||||||
|
for (i = 0; i < details.inputs.length; i++) {
|
||||||
|
member = details.inputs[i];
|
||||||
|
if (member.path) {
|
||||||
|
receive = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < details.outputs.length; i++) {
|
||||||
|
member = details.outputs[i];
|
||||||
|
|
||||||
|
if (member.path) {
|
||||||
|
if (member.path.change === 1)
|
||||||
|
continue;
|
||||||
|
received += member.value;
|
||||||
|
recMember = member;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sent += member.value;
|
||||||
|
sendMember = member;
|
||||||
|
}
|
||||||
|
|
||||||
|
member = receive ? recMember : sendMember;
|
||||||
|
|
||||||
json = {
|
json = {
|
||||||
account: member.path.name,
|
account: member.path.name,
|
||||||
address: member.address.toBase58(self.network),
|
address: member.address.toBase58(self.network),
|
||||||
category: receive ? 'receive' : 'send',
|
category: receive ? 'receive' : 'send',
|
||||||
amount: +utils.btc(details.getValue()),
|
amount: +utils.btc(receive ? received : -sent),
|
||||||
label: member.path.name,
|
label: member.path.name,
|
||||||
vout: 0,
|
vout: 0,
|
||||||
confirmations: details.confirmations,
|
confirmations: details.confirmations,
|
||||||
|
|||||||
@ -837,7 +837,7 @@ TXDB.prototype.isSpent = function isSpent(hash, index, callback) {
|
|||||||
|
|
||||||
TXDB.prototype._confirm = function _confirm(tx, info, callback, force) {
|
TXDB.prototype._confirm = function _confirm(tx, info, callback, force) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var hash, batch, unlock, i, path, id;
|
var hash, batch, unlock, i, id;
|
||||||
|
|
||||||
unlock = this._lock(_confirm, [tx, info, callback], force);
|
unlock = this._lock(_confirm, [tx, info, callback], force);
|
||||||
|
|
||||||
@ -887,7 +887,8 @@ TXDB.prototype._confirm = function _confirm(tx, info, callback, force) {
|
|||||||
var key = hash + '/' + i;
|
var key = hash + '/' + i;
|
||||||
|
|
||||||
// Only update coins if this output is ours.
|
// Only update coins if this output is ours.
|
||||||
paths = info.getPaths(address);
|
if (!info.hasPaths(address))
|
||||||
|
return next();
|
||||||
|
|
||||||
self.getCoin(hash, i, function(err, coin) {
|
self.getCoin(hash, i, function(err, coin) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -1139,7 +1140,7 @@ TXDB.prototype.unconfirm = function unconfirm(hash, callback, force) {
|
|||||||
|
|
||||||
TXDB.prototype._unconfirm = function unconfirm(tx, info, callback, force) {
|
TXDB.prototype._unconfirm = function unconfirm(tx, info, callback, force) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var batch, unlock, hash, height, i, path, id;
|
var batch, unlock, hash, height, i, id;
|
||||||
|
|
||||||
unlock = this._lock(unconfirm, [tx, info, callback], force);
|
unlock = this._lock(unconfirm, [tx, info, callback], force);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user