address: include options to trim transaction results
This commit is contained in:
parent
967445c14f
commit
38e061e0c5
@ -183,7 +183,13 @@ AddressController.prototype.multitxs = function(req, res, next) {
|
|||||||
return self.common.handleErrors(err, res);
|
return self.common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.transformAddressHistoryForMultiTxs(result.items, function(err, items) {
|
var transformOptions = {
|
||||||
|
noAsm: req.query.noAsm ? true : false,
|
||||||
|
noScriptSig: req.query.noScriptSig ? true : false,
|
||||||
|
noSpent: req.query.noSpent ? true : false
|
||||||
|
};
|
||||||
|
|
||||||
|
self.transformAddressHistoryForMultiTxs(result.items, transformOptions, function(err, items) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return self.common.handleErrors(err, res);
|
return self.common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
@ -198,7 +204,7 @@ AddressController.prototype.multitxs = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressController.prototype.transformAddressHistoryForMultiTxs = function(txinfos, callback) {
|
AddressController.prototype.transformAddressHistoryForMultiTxs = function(txinfos, options, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var items = txinfos.map(function(txinfo) {
|
var items = txinfos.map(function(txinfo) {
|
||||||
@ -210,7 +216,7 @@ AddressController.prototype.transformAddressHistoryForMultiTxs = function(txinfo
|
|||||||
async.map(
|
async.map(
|
||||||
items,
|
items,
|
||||||
function(item, next) {
|
function(item, next) {
|
||||||
self.txController.transformTransaction(item, next);
|
self.txController.transformTransaction(item, options, next);
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
|
|||||||
@ -44,7 +44,11 @@ TxController.prototype.transaction = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
TxController.prototype.transformTransaction = function(transaction, callback) {
|
TxController.prototype.transformTransaction = function(transaction, options, callback) {
|
||||||
|
if (_.isFunction(options)) {
|
||||||
|
callback = options;
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
$.checkArgument(_.isFunction(callback));
|
$.checkArgument(_.isFunction(callback));
|
||||||
|
|
||||||
var confirmations = 0;
|
var confirmations = 0;
|
||||||
@ -67,10 +71,10 @@ TxController.prototype.transformTransaction = function(transaction, callback) {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
transformed.vin = transaction.inputs.map(this.transformInput.bind(this));
|
transformed.vin = transaction.inputs.map(this.transformInput.bind(this, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
transformed.vout = transaction.outputs.map(this.transformOutput.bind(this));
|
transformed.vout = transaction.outputs.map(this.transformOutput.bind(this, options));
|
||||||
|
|
||||||
transformed.blockhash = transaction.blockHash;
|
transformed.blockhash = transaction.blockHash;
|
||||||
transformed.blockheight = transaction.height;
|
transformed.blockheight = transaction.height;
|
||||||
@ -96,19 +100,22 @@ TxController.prototype.transformTransaction = function(transaction, callback) {
|
|||||||
callback(null, transformed);
|
callback(null, transformed);
|
||||||
};
|
};
|
||||||
|
|
||||||
TxController.prototype.transformInput = function(input, index) {
|
TxController.prototype.transformInput = function(options, input, index) {
|
||||||
// Input scripts are validated and can be assumed to be valid
|
// Input scripts are validated and can be assumed to be valid
|
||||||
var transformed = {
|
var transformed = {
|
||||||
txid: input.prevTxId,
|
txid: input.prevTxId,
|
||||||
vout: input.outputIndex,
|
vout: input.outputIndex,
|
||||||
scriptSig: {
|
|
||||||
asm: input.scriptAsm,
|
|
||||||
hex: input.script
|
|
||||||
},
|
|
||||||
sequence: input.sequence,
|
sequence: input.sequence,
|
||||||
n: index
|
n: index
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!options.noScriptSig) {
|
||||||
|
transformed.scriptSig = {
|
||||||
|
asm: options.noAsm ? undefined : input.scriptAsm,
|
||||||
|
hex: input.script
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
transformed.addr = input.address;
|
transformed.addr = input.address;
|
||||||
transformed.valueSat = input.satoshis;
|
transformed.valueSat = input.satoshis;
|
||||||
transformed.value = input.satoshis / 1e8;
|
transformed.value = input.satoshis / 1e8;
|
||||||
@ -120,21 +127,24 @@ TxController.prototype.transformInput = function(input, index) {
|
|||||||
return transformed;
|
return transformed;
|
||||||
};
|
};
|
||||||
|
|
||||||
TxController.prototype.transformOutput = function(output, index) {
|
TxController.prototype.transformOutput = function(options, output, index) {
|
||||||
var transformed = {
|
var transformed = {
|
||||||
value: (output.satoshis / 1e8).toFixed(8),
|
value: (output.satoshis / 1e8).toFixed(8),
|
||||||
n: index,
|
n: index,
|
||||||
scriptPubKey: {
|
scriptPubKey: {
|
||||||
hex: output.script,
|
hex: output.script,
|
||||||
asm: output.scriptAsm
|
asm: options.noAsm ? undefined : output.scriptAsm
|
||||||
//reqSigs: null, // TODO
|
//reqSigs: null, // TODO
|
||||||
},
|
}
|
||||||
spentTxId: output.spentTxId || null,
|
|
||||||
spentIndex: _.isUndefined(output.spentIndex) ? null : output.spentIndex,
|
|
||||||
spentHeight: output.spentHeight || null
|
|
||||||
//spentTs: undefined // TODO
|
//spentTs: undefined // TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!options.noSpent) {
|
||||||
|
transformed.spentTxId = output.spentTxId || null;
|
||||||
|
transformed.spentIndex = _.isUndefined(output.spentIndex) ? null : output.spentIndex;
|
||||||
|
transformed.spentHeight = output.spentHeight || null;
|
||||||
|
}
|
||||||
|
|
||||||
if (output.address) {
|
if (output.address) {
|
||||||
transformed.scriptPubKey.addresses = [output.address];
|
transformed.scriptPubKey.addresses = [output.address];
|
||||||
var address = bitcore.Address(output.address); //TODO return type from bitcore-node
|
var address = bitcore.Address(output.address); //TODO return type from bitcore-node
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user