Skip to Content

solanaFetcher()

solanaFetcher(params): Promise<void>

Defined in: trackers/solanaTracker.ts:164 

A fetcher for initializePollingTracker from @tuwaio/pulsar-core that checks a Solana transaction once.

It sends getSignatureStatuses (with searchTransactionHistory on the first check of a run and past a blockhash’s lifetime, so transactions older than the node’s recent status cache are found after a page reload) to tx.rpcUrl, or to the public endpoint of the cluster in tx.chainId, through a client cached by createSolanaRPC from @tuwaio/orbit-solana. Until it has the fee, blockhash and instructions (from tx, or fetched on an earlier tick of the same tracking run and cached in memory for the tx object), it also sends getTransaction (commitment confirmed, maxSupportedTransactionVersion: 1, so legacy, version 0 and version 1 transactions are read). A getTransaction error is not thrown: the check goes on with the status alone and the details are asked again on the next tick.

  • Signature not found, with tx.lastValidBlockHeight (or the one signAndSendSolanaTx recorded for the signature in this page): sends getBlockHeight (commitment confirmed); once the height is more than 32 blocks above it, checks the signature once more and, still not found, calls onFailure and stops polling, with expired: true when this run saw the blockhash still valid (it can never land), false when it came back later and the node may just keep no old statuses.
  • Signature not found otherwise: keeps polling; one hour after localTimestamp calls onFailure() and stops polling.
  • Found: calls onIntervalTick with the status (confirmationStatus processed, confirmed or finalized, plus the details once getTransaction returns them), then: an on-chain error past processed calls onFailure with it right away; finalized with the details calls onSuccess. finalized without the details keeps polling for them and, on the 10th such check of the tx object (counted in memory), logs a warning and calls onSuccess without them. A transaction not finalized one hour after localTimestamp calls onFailure with its status; a finalized one never does.

Every terminal outcome stops polling with withoutRemoving: true, so the transaction is never removed.

  • Errors of getSignatureStatuses and getBlockHeight are thrown, so the polling tracker retries and gives up after maxRetries consecutive errors.

Parameters

params

PollingFetcherParams<SolanaSignatureStatusResponse, SolanaFetcherTx>

The fetcher parameters provided by initializePollingTracker.

Returns

Promise<void>

A promise that resolves when the check is done.

Throws

Error when tx.adapter is not OrbitAdapter.SOLANA, and any error of getSignatureStatuses or getBlockHeight.

Example

import { OrbitAdapter, SOLANA_CHAIN_IDS } from '@tuwaio/orbit-core'; import { initializePollingTracker } from '@tuwaio/pulsar-core'; import { solanaFetcher } from '@tuwaio/pulsar-solana'; initializePollingTracker({ tx: { adapter: OrbitAdapter.SOLANA, txKey: signature, chainId: SOLANA_CHAIN_IDS.devnet, localTimestamp: now, pending: true }, fetcher: solanaFetcher, onSuccess: (status) => console.log('Finalized in slot', status.slot), onFailure: (status) => console.error('Failed', status?.err), });
Last updated on