Skip to content

Commit cb91346

Browse files
committed
temp
1 parent 7a5d28b commit cb91346

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

packages/cardano-services/src/ChainHistory/BlockrostChainHistoryProvider/BlockfrostChainHistoryProvider.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
TransactionsByIdsArgs
2222
} from '@cardano-sdk/core';
2323
import { DB_MAX_SAFE_INTEGER } from '../DbSyncChainHistory/queries';
24-
import { HydratedTxBody } from '@cardano-sdk/core/dist/cjs/Cardano';
2524
import { Responses } from '@blockfrost/blockfrost-js';
2625
import { Schemas } from '@blockfrost/blockfrost-js/lib/types/open-api';
2726
import 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 };

packages/cardano-services/src/util/BlockfrostProvider/BlockfrostToCore.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const BlockfrostToCore = {
9494
treasuryExpansion: blockfrost.tau.toString()
9595
}),
9696

97-
txOut: (blockfrost: BlockfrostOutput, _scriptCbor?: Responses['script_cbor']): Cardano.TxOut => {
97+
txOut: (blockfrost: BlockfrostOutput, txOutFromCbor?: Cardano.TxOut): Cardano.TxOut => {
9898
const value: Cardano.Value = {
9999
coins: BigInt(blockfrost.amount.find(({ unit }) => unit === 'lovelace')!.quantity)
100100
};
@@ -116,6 +116,7 @@ export const BlockfrostToCore = {
116116
txOut.datum = Serialization.PlutusData.fromCbor(HexBlob(blockfrost.inline_datum)).toCore();
117117
if (blockfrost.data_hash) txOut.datumHash = Hash32ByteBase16(blockfrost.data_hash);
118118

119+
if (txOutFromCbor?.scriptReference) txOut.scriptReference = txOutFromCbor.scriptReference;
119120
/*
120121
if (scriptCbor && scriptCbor.cbor) {
121122
try {
@@ -126,7 +127,7 @@ export const BlockfrostToCore = {
126127
}
127128
}
128129
*/
129-
130+
/*
130131
if (blockfrost.reference_script_hash) {
131132
try {
132133
txOut.scriptReference = Serialization.Script.fromCbor(HexBlob(blockfrost.reference_script_hash)).toCore();
@@ -135,6 +136,9 @@ export const BlockfrostToCore = {
135136
console.log('Error in BlockfrostToCore.txOut:', error);
136137
}
137138
}
139+
*/
140+
// if (txOut.scriptReference) delete txOut.scriptReference;
141+
// txOut.scriptReference = {} as Script;
138142
return txOut;
139143
}
140144
};

packages/core/src/Serialization/Certificates/PoolParams/PoolParams.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,10 @@ export class PoolParams {
194194
toCore(): Cardano.PoolParameters {
195195
const rewardAccountAddress = this.#rewardAccount.toAddress();
196196

197-
return {
197+
const poolParams: Cardano.PoolParameters = {
198198
cost: this.#cost,
199199
id: PoolId.fromKeyHash(this.#operator),
200200
margin: this.#margin.toCore(),
201-
metadataJson: this.#poolMetadata?.toCore(),
202201
owners: this.#poolOwners
203202
.toCore()
204203
.map((keyHash) => createRewardAccount(keyHash, rewardAccountAddress.getNetworkId())),
@@ -207,6 +206,10 @@ export class PoolParams {
207206
rewardAccount: this.#rewardAccount.toAddress().toBech32() as Cardano.RewardAccount,
208207
vrf: this.#vrfKeyHash
209208
};
209+
210+
if (this.#poolMetadata) poolParams.metadataJson = this.#poolMetadata.toCore();
211+
212+
return poolParams;
210213
}
211214

212215
/**

packages/core/test/Serialization/Transaction.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Crypto from '@cardano-sdk/crypto';
2+
import { Serialization } from '@cardano-sdk/core';
23
import { Transaction, TransactionBody, TxCBOR } from '../../src/Serialization';
34
import { babbageTx, tx as coreTx, signature, vkey } from './testData';
45

@@ -26,6 +27,15 @@ describe('Transaction', () => {
2627
expect(tx.toCore()).toEqual(babbageTx);
2728
});
2829

30+
it('correctly deserialize a CBOR transaction from Blockfrost', () => {
31+
const tx = Transaction.fromCbor(
32+
Serialization.TxCBOR(
33+
'84a300d90102818258209924ffd97ed5d05ea277a3bca36de2744bc6573c105360b597ffff47ba6fba38010182a300581d70a258f896dff1d01ac9a8bd0598304b933a8f3e9e0953938767178099011a05f5e10003d81859089a82025908955908920100003233223232323232332232323232323232323232332232323232322223232533532323232325335001101d13357389211e77726f6e67207573616765206f66207265666572656e636520696e7075740001c3232533500221533500221333573466e1c00800408007c407854cd4004840784078d40900114cd4c8d400488888888888802d40044c08526221533500115333533550222350012222002350022200115024213355023320015021001232153353235001222222222222300e00250052133550253200150233355025200100115026320013550272253350011502722135002225335333573466e3c00801c0940904d40b00044c01800c884c09526135001220023333573466e1cd55cea80224000466442466002006004646464646464646464646464646666ae68cdc39aab9d500c480008cccccccccccc88888888888848cccccccccccc00403403002c02802402001c01801401000c008cd405c060d5d0a80619a80b80c1aba1500b33501701935742a014666aa036eb94068d5d0a804999aa80dbae501a35742a01066a02e0446ae85401cccd5406c08dd69aba150063232323333573466e1cd55cea801240004664424660020060046464646666ae68cdc39aab9d5002480008cc8848cc00400c008cd40b5d69aba15002302e357426ae8940088c98c80c0cd5ce01901a01709aab9e5001137540026ae854008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a816bad35742a004605c6ae84d5d1280111931901819ab9c03203402e135573ca00226ea8004d5d09aba2500223263202c33573805c06005426aae7940044dd50009aba1500533501775c6ae854010ccd5406c07c8004d5d0a801999aa80dbae200135742a00460426ae84d5d1280111931901419ab9c02a02c026135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d55cf280089baa00135742a00860226ae84d5d1280211931900d19ab9c01c01e018375a00a6666ae68cdc39aab9d375400a9000100e11931900c19ab9c01a01c016101b132632017335738921035054350001b135573ca00226ea800448c88c008dd6000990009aa80d911999aab9f0012500a233500930043574200460066ae880080608c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8050cd5ce00b00c00909aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c8064cd5ce00d80e80b89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403666ae7007407c06406005c4d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201533573802e03202626ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355018223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301613574200222440042442446600200800624464646666ae68cdc3a800a400046a02e600a6ae84d55cf280191999ab9a3370ea00490011280b91931900819ab9c01201400e00d135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900819ab9c01201400e00d00c00b135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900619ab9c00e01000a135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8028cd5ce00600700409baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c804ccd5ce00a80b80880800780700680600589aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401866ae700380400280244d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200933573801601a00e00c26aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401466ae7003003802001c0184d55cea80089baa0012323333573466e1d40052002200623333573466e1d40092000200623263200633573801001400800626aae74dd5000a4c244004244002921035054310012333333357480024a00c4a00c4a00c46a00e6eb400894018008480044488c0080049400848488c00800c4488004448c8c00400488cc00cc008008004182581d60ccc07b8d66f0b6c8e01d6331c95fd2f23e5f789867006535e9e44ada1b000d142366c78ed7021a000414e5a100d901028182582059edaffa12c1d596a82a38cc8e985749c1b90f8dc817893fa488c07fbc050e8c5840bfd5c3214ad03c0a3d13da69bed35d912be25d4c6c2c7468688e69da8ecbbf3d9e088302bdd524443f1e1f03fb3d608ad606bf8188edb99bd7deeab7a6b27302f5f6'
34+
)
35+
);
36+
expect(tx.toCore().body.outputs).toEqual('');
37+
});
38+
2939
it('correctly deserialize a CBOR transaction that sets entropy protocol param to empty', () => {
3040
const tx = Transaction.fromCbor(TxCBOR(TX_SET_ENTROPY_TO_EMPTY));
3141

0 commit comments

Comments
 (0)