Skip to content

Commit 38e061e

Browse files
author
Braydon Fuller
committed
address: include options to trim transaction results
1 parent 967445c commit 38e061e

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

lib/addresses.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,13 @@ AddressController.prototype.multitxs = function(req, res, next) {
183183
return self.common.handleErrors(err, res);
184184
}
185185

186-
self.transformAddressHistoryForMultiTxs(result.items, function(err, items) {
186+
var transformOptions = {
187+
noAsm: req.query.noAsm ? true : false,
188+
noScriptSig: req.query.noScriptSig ? true : false,
189+
noSpent: req.query.noSpent ? true : false
190+
};
191+
192+
self.transformAddressHistoryForMultiTxs(result.items, transformOptions, function(err, items) {
187193
if (err) {
188194
return self.common.handleErrors(err, res);
189195
}
@@ -198,7 +204,7 @@ AddressController.prototype.multitxs = function(req, res, next) {
198204
});
199205
};
200206

201-
AddressController.prototype.transformAddressHistoryForMultiTxs = function(txinfos, callback) {
207+
AddressController.prototype.transformAddressHistoryForMultiTxs = function(txinfos, options, callback) {
202208
var self = this;
203209

204210
var items = txinfos.map(function(txinfo) {
@@ -210,7 +216,7 @@ AddressController.prototype.transformAddressHistoryForMultiTxs = function(txinfo
210216
async.map(
211217
items,
212218
function(item, next) {
213-
self.txController.transformTransaction(item, next);
219+
self.txController.transformTransaction(item, options, next);
214220
},
215221
callback
216222
);

lib/transactions.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ TxController.prototype.transaction = function(req, res, next) {
4444
});
4545
};
4646

47-
TxController.prototype.transformTransaction = function(transaction, callback) {
47+
TxController.prototype.transformTransaction = function(transaction, options, callback) {
48+
if (_.isFunction(options)) {
49+
callback = options;
50+
options = {};
51+
}
4852
$.checkArgument(_.isFunction(callback));
4953

5054
var confirmations = 0;
@@ -67,10 +71,10 @@ TxController.prototype.transformTransaction = function(transaction, callback) {
6771
}
6872
];
6973
} else {
70-
transformed.vin = transaction.inputs.map(this.transformInput.bind(this));
74+
transformed.vin = transaction.inputs.map(this.transformInput.bind(this, options));
7175
}
7276

73-
transformed.vout = transaction.outputs.map(this.transformOutput.bind(this));
77+
transformed.vout = transaction.outputs.map(this.transformOutput.bind(this, options));
7478

7579
transformed.blockhash = transaction.blockHash;
7680
transformed.blockheight = transaction.height;
@@ -96,19 +100,22 @@ TxController.prototype.transformTransaction = function(transaction, callback) {
96100
callback(null, transformed);
97101
};
98102

99-
TxController.prototype.transformInput = function(input, index) {
103+
TxController.prototype.transformInput = function(options, input, index) {
100104
// Input scripts are validated and can be assumed to be valid
101105
var transformed = {
102106
txid: input.prevTxId,
103107
vout: input.outputIndex,
104-
scriptSig: {
105-
asm: input.scriptAsm,
106-
hex: input.script
107-
},
108108
sequence: input.sequence,
109109
n: index
110110
};
111111

112+
if (!options.noScriptSig) {
113+
transformed.scriptSig = {
114+
asm: options.noAsm ? undefined : input.scriptAsm,
115+
hex: input.script
116+
};
117+
}
118+
112119
transformed.addr = input.address;
113120
transformed.valueSat = input.satoshis;
114121
transformed.value = input.satoshis / 1e8;
@@ -120,21 +127,24 @@ TxController.prototype.transformInput = function(input, index) {
120127
return transformed;
121128
};
122129

123-
TxController.prototype.transformOutput = function(output, index) {
130+
TxController.prototype.transformOutput = function(options, output, index) {
124131
var transformed = {
125132
value: (output.satoshis / 1e8).toFixed(8),
126133
n: index,
127134
scriptPubKey: {
128135
hex: output.script,
129-
asm: output.scriptAsm
136+
asm: options.noAsm ? undefined : output.scriptAsm
130137
//reqSigs: null, // TODO
131-
},
132-
spentTxId: output.spentTxId || null,
133-
spentIndex: _.isUndefined(output.spentIndex) ? null : output.spentIndex,
134-
spentHeight: output.spentHeight || null
138+
}
135139
//spentTs: undefined // TODO
136140
};
137141

142+
if (!options.noSpent) {
143+
transformed.spentTxId = output.spentTxId || null;
144+
transformed.spentIndex = _.isUndefined(output.spentIndex) ? null : output.spentIndex;
145+
transformed.spentHeight = output.spentHeight || null;
146+
}
147+
138148
if (output.address) {
139149
transformed.scriptPubKey.addresses = [output.address];
140150
var address = bitcore.Address(output.address); //TODO return type from bitcore-node

0 commit comments

Comments
 (0)