@@ -149,30 +149,48 @@ export class Client implements BitcoinClient {
149149 */
150150 getTransaction ( transactionHash : TransactionHash ) : Promise < Transaction > {
151151 return this . withElectrum < Transaction > ( async ( electrum : any ) => {
152- const transaction = await electrum . blockchain_transaction_get (
152+ // We cannot use `blockchain_transaction_get` with `verbose = true` argument
153+ // to get the the transaction details as Esplora/Electrs doesn't support verbose
154+ // transactions.
155+ // See: https://github.com/Blockstream/electrs/pull/36
156+ const rawTransaction = await electrum . blockchain_transaction_get (
153157 transactionHash . toString ( ) ,
154- true
158+ false
155159 )
156160
157- const inputs = transaction . vin . map (
161+ if ( ! rawTransaction ) {
162+ throw new Error ( `Transaction not found` )
163+ }
164+
165+ // Decode the raw transaction.
166+ const transaction = bcoin . TX . fromRaw ( rawTransaction , "hex" )
167+
168+ const inputs = transaction . inputs . map (
158169 ( input : any ) : TransactionInput => ( {
159- transactionHash : TransactionHash . from ( input . txid ) ,
160- outputIndex : input . vout ,
161- scriptSig : input . scriptSig ,
170+ transactionHash : TransactionHash . from ( input . prevout . hash ) . reverse ( ) ,
171+ outputIndex : input . prevout . index ,
172+ scriptSig : {
173+ asm : input . script . toASM ( true ) ,
174+ hex : input . script . toRaw ( ) . toString ( "hex" ) ,
175+ type : input . script . getType ( ) ,
176+ } ,
162177 } )
163178 )
164179
165- const outputs = transaction . vout . map (
166- ( output : any ) : TransactionOutput => ( {
167- outputIndex : output . n ,
168- // The `output.value` is in BTC so it must be converted to satoshis.
169- value : BigNumber . from ( ( parseFloat ( output . value ) * 1e8 ) . toFixed ( 0 ) ) ,
170- scriptPubKey : output . scriptPubKey ,
180+ const outputs = transaction . outputs . map (
181+ ( output : any , i : number ) : TransactionOutput => ( {
182+ outputIndex : i ,
183+ value : BigNumber . from ( output . value ) ,
184+ scriptPubKey : {
185+ asm : output . script . toASM ( true ) ,
186+ hex : output . script . toRaw ( ) . toString ( "hex" ) ,
187+ type : output . getType ( ) . toUpperCase ( ) ,
188+ } ,
171189 } )
172190 )
173191
174192 return {
175- transactionHash : TransactionHash . from ( transaction . txid ) ,
193+ transactionHash : TransactionHash . from ( transaction . hash ( ) ) . reverse ( ) ,
176194 inputs : inputs ,
177195 outputs : outputs ,
178196 }
0 commit comments