Skip to content

Commit 65c3159

Browse files
committed
updating comments and function documentation
1 parent d609844 commit 65c3159

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/lib/mina/fetch.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,30 @@ async function fetchEvents(
691691
});
692692
}
693693

694+
/**
695+
* Fetches account actions for a specified public key and token ID by performing a GraphQL query.
696+
*
697+
* @param accountInfo - An {@link ActionsQueryInputs} containing the public key, and optional query parameters for the actions query
698+
* @param graphqlEndpoint - The GraphQL endpoint to fetch from. Defaults to the configured Mina endpoint.
699+
*
700+
* @returns A promise that resolves to an object containing the final actions hash for the account, and a list of actions
701+
* @throws Will throw an error if the GraphQL endpoint is invalid or if the fetch request fails.
702+
*
703+
* @example
704+
* const accountInfo = { publicKey: 'B62qiwmXrWn7Cok5VhhB3KvCwyZ7NHHstFGbiU5n7m8s2RqqNW1p1wF' };
705+
* const acitonsList = await fetchAccount(accountInfo);
706+
* console.log(acitonsList);
707+
*/
694708
async function fetchActions(
695709
accountInfo: ActionsQueryInputs,
696710
graphqlEndpoint = networkConfig.archiveEndpoint
697-
) {
711+
): Promise<
712+
| {
713+
actions: string[][];
714+
hash: string;
715+
}[]
716+
| { error: FetchError }
717+
> {
698718
if (!graphqlEndpoint)
699719
throw Error(
700720
'fetchActions: Specified GraphQL endpoint is undefined. When using actions, you must set the archive node endpoint in Mina.Network(). Please ensure your Mina.Network() configuration includes an archive node endpoint.'
@@ -710,14 +730,25 @@ async function fetchActions(
710730
graphqlEndpoint,
711731
networkConfig.archiveFallbackEndpoints
712732
);
733+
// As of 2025-01-07, minascan is running a version of the node which supports `sequenceNumber` and `zkappAccountUpdateIds` fields
734+
// We could consider removing this fallback since no other nodes are widely used
713735
if (error) {
714-
// retry once without querying transaction info
736+
const originalError = error;
715737
[response, error] = await makeGraphqlRequest<ActionQueryResponse>(
716-
getActionsQuery(publicKey, actionStates, tokenId, undefined, true),
738+
getActionsQuery(
739+
publicKey,
740+
actionStates,
741+
tokenId,
742+
/* _filterOptions= */ undefined,
743+
/* retryWithoutTxInfo= */ true
744+
),
717745
graphqlEndpoint,
718746
networkConfig.archiveFallbackEndpoints
719747
);
720-
if (error) throw Error(error.statusText);
748+
if (error)
749+
throw Error(
750+
`ORIGINAL ERROR: ${originalError.statusText} \n\nRETRY ERROR: ${error.statusText}`
751+
);
721752
}
722753
let fetchedActions = response?.data.actions;
723754
if (fetchedActions === undefined) {
@@ -766,6 +797,8 @@ export function createActionsList(
766797
);
767798

768799
// DEPRECATED: In case the archive node is running an out-of-date version, best guess is to sort by the account update id
800+
// As of 2025-01-07, minascan is running a version of the node which supports `sequenceNumber` and `zkappAccountUpdateIds` fields
801+
// We could consider removing this fallback since no other nodes are widely used
769802
if (!actionData[0].transactionInfo) {
770803
actionData = actionData.sort((a1, a2) => {
771804
return Number(a1.accountUpdateId) - Number(a2.accountUpdateId);

0 commit comments

Comments
 (0)