Skip to content

Commit

Permalink
refactor: rework #245 taking advantage from #268
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Nov 29, 2024
1 parent 41f1bb8 commit 1a90ca0
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 26 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ Response:
};
address: string;
txHash: string;
txCbor?: string;
}[];
txids?: string[]; // List of transaction ids, available with details set to "txids"
};
Expand Down Expand Up @@ -832,6 +831,7 @@ Event:
asset_mint_or_burn_count: number;
redeemer_count: number;
valid_contract: boolean;
cbor?: string;
};
txUtxos: {
hash: string;
Expand Down Expand Up @@ -864,7 +864,6 @@ Event:
data_hash: string | null;
}[];
};
txCbor?: string;
}[];
}
```
Expand Down
1 change: 0 additions & 1 deletion src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export const onBlock = async (
txData: enhancedTx.txData,
txUtxos: enhancedTx.txUtxos,
txHash: enhancedTx.txData.hash,
txCbor: enhancedTx.txCbor,
});
}
}
Expand Down
1 change: 0 additions & 1 deletion src/types/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export interface TxNotification {
txHash: string;
txData: TransformedTransaction;
txUtxos: TransformedTransactionUtxo;
txCbor?: string;
}

export interface BalanceHistoryData {
Expand Down
1 change: 0 additions & 1 deletion src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export interface TxIdsToTransactionsResponse {
txData: TransformedTransaction;
address: string;
txHash: string;
txCbor?: string;
}

export interface TransformedTransactionUtxo {
Expand Down
18 changes: 3 additions & 15 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,15 @@ export interface GetTransactionsDetails {

export const getTransactionsWithDetails = async (
txs: GetTransactionsDetails[],
): Promise<Pick<TxIdsToTransactionsResponse, 'txData' | 'txUtxos' | 'txCbor'>[]> => {
const txsData = await Promise.all(txs.map(({ txId }) => fetchTransactionData(txId)));
): Promise<Pick<TxIdsToTransactionsResponse, 'txData' | 'txUtxos'>[]> => {
const txsData = await Promise.all(txs.map(({ txId, cbor }) => fetchTransactionData(txId, cbor)));
const txsUtxo = await Promise.all(
txs.map(({ txId }) =>
limiter(() => blockfrostAPI.txsUtxos(txId).then(data => transformTransactionUtxo(data))),
),
);
const txsCbors = await Promise.all(
txs.map(({ txId, cbor }) =>
cbor
? limiter(() => blockfrostAPI.txsCbor(txId).then(data => data.cbor))
: // eslint-disable-next-line unicorn/no-useless-undefined
Promise.resolve<undefined>(undefined),
),
);

return txs.map((_tx, index) => ({
txData: txsData[index],
txUtxos: txsUtxo[index],
txCbor: txsCbors[index],
}));
return txs.map((_tx, index) => ({ txData: txsData[index], txUtxos: txsUtxo[index] }));
};

export const transformTransactionData = async (
Expand Down
8 changes: 2 additions & 6 deletions test/unit/fixtures/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export const onBlock = [
asset_mint_or_burn_count: 1,
redeemer_count: 4,
valid_contract: true,
cbor: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
},
txUtxos: {
hash: '4d5beb45fe37b44b46f839811a3d3a1ac4a20911850740867a64f77d09372d0b',
Expand Down Expand Up @@ -354,9 +355,6 @@ export const onBlock = [
},
],
},
txCbor: {
cbor: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
},
},
],
},
Expand Down Expand Up @@ -438,6 +436,7 @@ export const onBlock = [
asset_mint_or_burn_count: 1,
redeemer_count: 4,
valid_contract: true,
cbor: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
},
txUtxos: {
hash: '4d5beb45fe37b44b46f839811a3d3a1ac4a20911850740867a64f77d09372d0b',
Expand Down Expand Up @@ -612,9 +611,6 @@ export const onBlock = [
],
},
txHash: '4d5beb45fe37b44b46f839811a3d3a1ac4a20911850740867a64f77d09372d0b',
txCbor: {
cbor: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
},
},
],
},
Expand Down

0 comments on commit 1a90ca0

Please sign in to comment.