diff --git a/README.md b/README.md index eabb6179..873976ad 100644 --- a/README.md +++ b/README.md @@ -214,8 +214,9 @@ Input message: "params": { "descriptor": string; // account public key in hex (eg. 6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2) "details": 'basic' | 'tokens' | 'tokenBalances' |'txids' | 'txs'; - "page?": number; // optional, default 1 - "pageSize?": number; // optional, default 20 + "page"?: number; // optional, default 1 + "pageSize"?: number; // optional, default 20 + "cbor"?: boolean; // optional, get CBOR representation of transactions } } ``` @@ -330,6 +331,7 @@ Response: asset_mint_or_burn_count: number; redeemer_count: number; valid_contract: boolean; + cbor?: string; }; address: string; txHash: string; diff --git a/src/methods/get-account-info.ts b/src/methods/get-account-info.ts index 033c81e6..2c58179d 100644 --- a/src/methods/get-account-info.ts +++ b/src/methods/get-account-info.ts @@ -21,6 +21,7 @@ export const getAccountInfo = async ( details: Details, page = 1, pageSize = 25, + cbor?: boolean, ): Promise => { let _addressesCount = 0; const tStart = Date.now(); @@ -117,6 +118,7 @@ export const getAccountInfo = async ( // fetch full transaction objects and set account.history.transactions const txs = await txIdsToTransactions( requestedPageTxIds.map(item => ({ address: item.address, txIds: [item.tx_hash] })), + cbor, ); accountInfo.history.transactions = txs; @@ -155,8 +157,9 @@ export default async ( details: Details, page = 1, pageSize = 25, + cbor?: boolean, ): Promise => { - const data = await getAccountInfo(publicKey, details, page, pageSize); + const data = await getAccountInfo(publicKey, details, page, pageSize, cbor); const message = prepareMessage({ id, clientId, data }); return message; diff --git a/src/server.ts b/src/server.ts index f1d2fece..aaaedc10 100644 --- a/src/server.ts +++ b/src/server.ts @@ -242,6 +242,7 @@ wss.on('connection', async (ws: Server.Ws) => { params.details, params.page, params.pageSize, + params.cbor, ); break; diff --git a/src/types/message.ts b/src/types/message.ts index 050200db..3ce5ee46 100644 --- a/src/types/message.ts +++ b/src/types/message.ts @@ -14,6 +14,7 @@ export type Messages = BaseMessage & details: Details; page?: number; pageSize?: number; + cbor?: boolean; }; } | { diff --git a/src/utils/message.ts b/src/utils/message.ts index 6d8da68a..ab6dae6e 100644 --- a/src/utils/message.ts +++ b/src/utils/message.ts @@ -19,6 +19,7 @@ const schemas: { [k in Validators]: { properties: unknown; required?: string[] } details: { type: 'string', enum: Details }, page: { type: ['number', 'string', 'null'] }, pageSize: { type: ['number', 'string', 'null'] }, + cbor: { type: 'boolean' }, }, required: ['descriptor', 'details'], }, diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts index 2500b2fc..b2cde39e 100644 --- a/src/utils/transaction.ts +++ b/src/utils/transaction.ts @@ -19,10 +19,10 @@ export const sortTransactionsCmp = < b: T, ): number => b.block_height - a.block_height || b.index - a.index; -const fetchTxWithUtxo = async (txHash: string, address: string) => { +const fetchTxWithUtxo = async (txHash: string, address: string, cbor?: boolean) => { try { - const txUtxo = await blockfrostAPI.txsUtxos(txHash); - const txData = await fetchTransactionData(txHash); + const txUtxo = await limiter(() => blockfrostAPI.txsUtxos(txHash)); + const txData = await fetchTransactionData(txHash, cbor); const txUtxos = await transformTransactionUtxo(txUtxo); return { txData, txUtxos, address, txHash }; @@ -42,6 +42,7 @@ export const txIdsToTransactions = async ( address: string; txIds: string[]; }[], + cbor?: boolean, ): Promise => { if (txIdsPerAddress.length === 0) { return []; @@ -51,7 +52,7 @@ export const txIdsToTransactions = async ( for (const item of txIdsPerAddress) { for (const txId of item.txIds) { - promises.push(fetchTxWithUtxo(txId, item.address)); + promises.push(fetchTxWithUtxo(txId, item.address, cbor)); } }