Fix bug with null in vouts array.
This commit is contained in:
parent
a73cd731d9
commit
7b74045ff4
@ -142,18 +142,19 @@ TxController.prototype.transformInvTransaction = function(transaction) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var valueOut = 0;
|
var valueOut = 0;
|
||||||
var vout = transaction.outputs.map(function(output) {
|
var vout = [];
|
||||||
|
for (var i = 0; i < transaction.outputs.length; i++) {
|
||||||
|
var output = transaction.outputs[i];
|
||||||
valueOut += output.satoshis;
|
valueOut += output.satoshis;
|
||||||
|
|
||||||
if(output.script) {
|
if(output.script) {
|
||||||
var address = output.script.toAddress(self.node.network);
|
var address = output.script.toAddress(self.node.network);
|
||||||
if(address) {
|
if(address) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[address.toString()] = output.satoshis;
|
obj[address.toString()] = output.satoshis;
|
||||||
return obj;
|
vout.push(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
var transformed = {
|
var transformed = {
|
||||||
txid: transaction.hash,
|
txid: transaction.hash,
|
||||||
|
|||||||
@ -895,8 +895,31 @@ describe('Transactions', function() {
|
|||||||
|
|
||||||
var transactions = new TxController(node);
|
var transactions = new TxController(node);
|
||||||
|
|
||||||
|
var result = transactions.transformInvTransaction(tx);
|
||||||
|
should(result).eql(insight);
|
||||||
|
});
|
||||||
|
it('will not include null values in vout array', function() {
|
||||||
|
var insight = {
|
||||||
|
"txid": "716d54157c31e52c820494c6c2b8af1b64352049f4dcc80632aa15742a7f82c4",
|
||||||
|
"valueOut": 12.5002,
|
||||||
|
"vout": [
|
||||||
|
{
|
||||||
|
"n4eY3qiP9pi32MWC6FcJFHciSsfNiYFYgR": 12.5002 * 1e8
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
var rawTx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0403ebc108ffffffff04a0ca814a000000001976a914fdb9fb622b0db8d9121475a983288a0876f4de4888ac0000000000000000226a200000000000000000000000000000000000000000000000000000ffff0000000000000000000000001b6a1976a914fdb9fb622b0db8d9121475a983288a0876f4de4888ac0000000000000000326a303a791c8e85200500d89769b4f958e4db6b3ec388ddaa30233c4517d942d440c24ae903bff40d97ca06465fcf2714000000000000';
|
||||||
|
var tx = bitcore.Transaction().fromBuffer(new Buffer(rawTx, 'hex'));
|
||||||
|
|
||||||
|
var node = {
|
||||||
|
network: bitcore.Networks.testnet
|
||||||
|
};
|
||||||
|
|
||||||
|
var transactions = new TxController(node);
|
||||||
|
|
||||||
var result = transactions.transformInvTransaction(tx);
|
var result = transactions.transformInvTransaction(tx);
|
||||||
should(result).eql(insight);
|
should(result).eql(insight);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user