@@ -21,7 +21,6 @@ import {
2121 TransactionsByIdsArgs
2222} from '@cardano-sdk/core' ;
2323import { DB_MAX_SAFE_INTEGER } from '../DbSyncChainHistory/queries' ;
24- import { HydratedTxBody } from '@cardano-sdk/core/dist/cjs/Cardano' ;
2524import { Responses } from '@blockfrost/blockfrost-js' ;
2625import { Schemas } from '@blockfrost/blockfrost-js/lib/types/open-api' ;
2726import omit from 'lodash/omit.js' ;
@@ -232,23 +231,30 @@ export class BlockfrostChainHistoryProvider extends BlockfrostProvider implement
232231 // eslint-disable-next-line unicorn/consistent-function-scoping
233232 protected parseValidityInterval = ( num : string | null ) => Cardano . Slot ( Number . parseInt ( num || '' ) ) || undefined ;
234233
235- protected async fetchTransaction ( hash : Cardano . TransactionId ) : Promise < Cardano . HydratedTx > {
234+ protected async fetchTransaction ( txId : Cardano . TransactionId ) : Promise < Cardano . HydratedTx > {
236235 try {
237- const txContent = await this . blockfrost . txs ( hash . toString ( ) ) ;
236+ const txContent = await this . blockfrost . txs ( txId . toString ( ) ) ;
238237
239- const txFromCBOR = await this . fetchDetailsFromCBOR ( hash . toString ( ) ) ;
238+ const txFromCBOR = await this . fetchDetailsFromCBOR ( txId . toString ( ) ) ;
240239
241240 const [ certificatesFull , withdrawals , utxos , auxiliaryData ] = await Promise . all ( [
242241 txFromCBOR ? txFromCBOR . body . certificates : this . fetchCertificates ( txContent ) ,
243242 txFromCBOR ? txFromCBOR . body . withdrawals : this . fetchWithdrawals ( txContent ) ,
244- this . blockfrost . txsUtxos ( hash . toString ( ) ) as Promise < Schemas [ 'tx_content_utxo' ] > ,
245- txFromCBOR ? txFromCBOR . auxiliaryData : this . fetchJsonMetadataAsAuxiliaryData ( hash )
243+ this . blockfrost . txsUtxos ( txId . toString ( ) ) as Promise < Schemas [ 'tx_content_utxo' ] > ,
244+ txFromCBOR ? txFromCBOR . auxiliaryData : this . fetchJsonMetadataAsAuxiliaryData ( txId )
246245 ] ) ;
247246
248- const certificates = certificatesFull ?. map ( ( cert ) => omit ( cert , 'cert_index' ) as Cardano . Certificate ) ;
247+ const certificates = certificatesFull ?. map ( ( c ) => {
248+ const cert = omit ( c , 'cert_index' ) as Cardano . Certificate ;
249+ if ( cert . __typename === Cardano . CertificateType . PoolRegistration ) {
250+ cert . poolParameters . owners = [ ] ;
251+ cert . poolParameters . relays = [ ] ;
252+ }
253+ return cert ;
254+ } ) ;
249255
250256 // We can't use txFromCBOR.body.inputs since it misses HydratedTxIn.address
251- const { inputs, outputPromises, collaterals } = this . transactionUtxos ( utxos , hash ) ;
257+ const { inputs, outputPromises, collaterals } = this . transactionUtxos ( utxos , txId , txFromCBOR ?? undefined ) ;
252258 /*
253259 const inputs = BlockfrostToCore.inputsUtxos(utxos.inputs);
254260 const collaterals = BlockfrostToCore.colleteralsUtxos(utxos.inputs);
@@ -332,7 +338,7 @@ export class BlockfrostChainHistoryProvider extends BlockfrostProvider implement
332338 auxiliaryData,
333339 blockHeader,
334340 body,
335- id : hash ,
341+ id : txId ,
336342 index,
337343 inputSource,
338344 txSize,
@@ -343,19 +349,21 @@ export class BlockfrostChainHistoryProvider extends BlockfrostProvider implement
343349 }
344350 }
345351
346- private transactionUtxos ( utxoResponse : Responses [ 'tx_content_utxo' ] , _txHash : Cardano . TransactionId ) {
352+ private transactionUtxos (
353+ utxoResponse : Responses [ 'tx_content_utxo' ] ,
354+ _txId : Cardano . TransactionId ,
355+ txContent ?: Cardano . Tx
356+ ) {
347357 const collaterals = utxoResponse . inputs . filter ( ( input ) => input . collateral ) . map ( BlockfrostToCore . hydratedTxIn ) ;
348- const inputs = utxoResponse . inputs . filter ( ( input ) => ! input . collateral ) . map ( BlockfrostToCore . hydratedTxIn ) ;
358+ const inputs = utxoResponse . inputs
359+ . filter ( ( input ) => ! input . collateral && ! input . reference )
360+ . map ( BlockfrostToCore . hydratedTxIn ) ;
349361 const outputPromises : Promise < Cardano . TxOut > [ ] = utxoResponse . outputs
350- . filter ( ( input ) => ! input . collateral )
362+ . filter ( ( output ) => ! output . collateral )
351363 . map ( async ( output ) => {
352- if ( output . reference_script_hash ) {
353- return this . blockfrost
354- . scriptsCbor ( output . reference_script_hash )
355- . then ( ( response : Responses [ 'script_cbor' ] ) => BlockfrostToCore . txOut ( output , response ) ) ;
356- }
364+ const foundScript = txContent ?. body . outputs . find ( ( o ) => o . address === output . address ) ;
357365
358- return BlockfrostToCore . txOut ( output ) ;
366+ return BlockfrostToCore . txOut ( output , foundScript ) ;
359367 } ) ;
360368
361369 return { collaterals, inputs, outputPromises } ;
0 commit comments