Skip to content

Commit

Permalink
Merge pull request #271 from blockfrost/feat/GET_ACCOUNT_INFO_cbor
Browse files Browse the repository at this point in the history
feat: add optional CBOR representation to GET_ACCOUNT_INFO
  • Loading branch information
slowbackspace authored Dec 5, 2024
2 parents e83b7a4 + 4ebfd1e commit 212fe42
Show file tree
Hide file tree
Showing 11 changed files with 8,122 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,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
}
}
```
Expand Down Expand Up @@ -334,6 +335,7 @@ Response:
asset_mint_or_burn_count: number;
redeemer_count: number;
valid_contract: boolean;
cbor?: string;
};
address: string;
txHash: string;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"start": "yarn build && yarn node ./dist/src/server.js",
"start:profiler": "yarn build && NODE_ENV=production yarn node --prof ./dist/src/server.js",
"test-performance": "yarn build && yarn node ./dist/src/scripts/performance/index.js",
"test": "BLOCKFROST_PROJECT_ID='mainnet_none' vitest --config vitest.config.unit.ts",
"test": "BLOCKFROST_PROJECT_ID=mainnet_none vitest --config vitest.config.unit.ts",
"test:e2e": "vitest --config vitest.config.e2e.ts",
"coverage": "vitest run --coverage",
"type-check": "tsc --project tsconfig.json"
Expand Down
5 changes: 4 additions & 1 deletion src/methods/get-account-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const getAccountInfo = async (
details: Details,
page = 1,
pageSize = 25,
cbor?: boolean,
): Promise<Responses.AccountInfo> => {
let _addressesCount = 0;
const tStart = Date.now();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -155,8 +157,9 @@ export default async (
details: Details,
page = 1,
pageSize = 25,
cbor?: boolean,
): Promise<string> => {
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;
Expand Down
1 change: 1 addition & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ wss.on('connection', async (ws: Server.Ws) => {
params.details,
params.page,
params.pageSize,
params.cbor,
);

break;
Expand Down
1 change: 1 addition & 0 deletions src/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Messages = BaseMessage &
details: Details;
page?: number;
pageSize?: number;
cbor?: boolean;
};
}
| {
Expand Down
1 change: 1 addition & 0 deletions src/utils/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
Expand Down
9 changes: 5 additions & 4 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -42,6 +42,7 @@ export const txIdsToTransactions = async (
address: string;
txIds: string[];
}[],
cbor?: boolean,
): Promise<TxIdsToTransactionsResponse[]> => {
if (txIdsPerAddress.length === 0) {
return [];
Expand All @@ -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));
}
}

Expand Down
Loading

0 comments on commit 212fe42

Please sign in to comment.