@@ -44,7 +44,11 @@ TxController.prototype.transaction = function(req, res, next) {
44
44
} ) ;
45
45
} ;
46
46
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
+ }
48
52
$ . checkArgument ( _ . isFunction ( callback ) ) ;
49
53
50
54
var confirmations = 0 ;
@@ -67,10 +71,10 @@ TxController.prototype.transformTransaction = function(transaction, callback) {
67
71
}
68
72
] ;
69
73
} else {
70
- transformed . vin = transaction . inputs . map ( this . transformInput . bind ( this ) ) ;
74
+ transformed . vin = transaction . inputs . map ( this . transformInput . bind ( this , options ) ) ;
71
75
}
72
76
73
- transformed . vout = transaction . outputs . map ( this . transformOutput . bind ( this ) ) ;
77
+ transformed . vout = transaction . outputs . map ( this . transformOutput . bind ( this , options ) ) ;
74
78
75
79
transformed . blockhash = transaction . blockHash ;
76
80
transformed . blockheight = transaction . height ;
@@ -96,19 +100,24 @@ TxController.prototype.transformTransaction = function(transaction, callback) {
96
100
callback ( null , transformed ) ;
97
101
} ;
98
102
99
- TxController . prototype . transformInput = function ( input , index ) {
103
+ TxController . prototype . transformInput = function ( options , input , index ) {
100
104
// Input scripts are validated and can be assumed to be valid
101
105
var transformed = {
102
106
txid : input . prevTxId ,
103
107
vout : input . outputIndex ,
104
- scriptSig : {
105
- asm : input . scriptAsm ,
106
- hex : input . script
107
- } ,
108
108
sequence : input . sequence ,
109
109
n : index
110
110
} ;
111
111
112
+ if ( ! options . noScriptSig ) {
113
+ transformed . scriptSig = {
114
+ hex : input . script
115
+ } ;
116
+ if ( ! options . noAsm ) {
117
+ transformed . scriptSig . asm = input . scriptAsm ;
118
+ }
119
+ }
120
+
112
121
transformed . addr = input . address ;
113
122
transformed . valueSat = input . satoshis ;
114
123
transformed . value = input . satoshis / 1e8 ;
@@ -120,21 +129,25 @@ TxController.prototype.transformInput = function(input, index) {
120
129
return transformed ;
121
130
} ;
122
131
123
- TxController . prototype . transformOutput = function ( output , index ) {
132
+ TxController . prototype . transformOutput = function ( options , output , index ) {
124
133
var transformed = {
125
134
value : ( output . satoshis / 1e8 ) . toFixed ( 8 ) ,
126
135
n : index ,
127
136
scriptPubKey : {
128
- hex : output . script ,
129
- asm : output . scriptAsm
130
- //reqSigs: null, // TODO
131
- } ,
132
- spentTxId : output . spentTxId || null ,
133
- spentIndex : _ . isUndefined ( output . spentIndex ) ? null : output . spentIndex ,
134
- spentHeight : output . spentHeight || null
135
- //spentTs: undefined // TODO
137
+ hex : output . script
138
+ }
136
139
} ;
137
140
141
+ if ( ! options . noAsm ) {
142
+ transformed . scriptPubKey . asm = output . scriptAsm ;
143
+ }
144
+
145
+ if ( ! options . noSpent ) {
146
+ transformed . spentTxId = output . spentTxId || null ;
147
+ transformed . spentIndex = _ . isUndefined ( output . spentIndex ) ? null : output . spentIndex ;
148
+ transformed . spentHeight = output . spentHeight || null ;
149
+ }
150
+
138
151
if ( output . address ) {
139
152
transformed . scriptPubKey . addresses = [ output . address ] ;
140
153
var address = bitcore . Address ( output . address ) ; //TODO return type from bitcore-node
0 commit comments