Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Feature Request: Add JSDocs to each Backend Function #91

Open
ZeroSums opened this issue Oct 16, 2024 · 0 comments
Open

Feature Request: Add JSDocs to each Backend Function #91

ZeroSums opened this issue Oct 16, 2024 · 0 comments
Assignees
Labels
backend Backend Issue enhancement New feature or request v2
Milestone

Comments

@ZeroSums
Copy link
Contributor

Add JSDocs for each Function in /backend.

This will be a v2 addition - do NOT create a PR with this feature under the V1 branch(s)

I've already added some in V1 for a working example:

/**
 * Confirms a transaction with exponential backoff in case of rate limits or temporary network errors.
 * Retries a set number of times before throwing an error.
 *
 * @param {Rpc} connection - The RPC connection object used for interacting with Solana.
 * @param {string} signature - The transaction signature to confirm.
 * @param {number} [maxRetries=10] - The maximum number of retries.
 * @returns {Promise<void>} - Resolves when the transaction is confirmed or throws if retries are exhausted.
 * @throws {Error} If the transaction cannot be confirmed after maximum retries.
 */
async function confirmTransactionWithBackoff(
    connection: Rpc,
    signature: string,
    maxRetries: number = 10
): Promise<void> {
  let retries = 0;
  let delay = 2000; // Start with 2 seconds
  while (retries < maxRetries) {
    try {
      const result = await connection.confirmTransaction(signature);
      if (result && result.value && result.value.err === null) {
        return; // Transaction confirmed successfully
      }
    } catch (error: any) {
      if (error.code !== -32601 && error.code !== 429) {
        throw error; // Re-throw unexpected errors
      }
      console.log(`Rate limit hit or method not found, retrying in ${delay / 1000} seconds...`);
    }
    await new Promise(resolve => setTimeout(resolve, delay));
    delay *= 2; // Exponential backoff
    retries++;
  }
  throw new Error("Transaction confirmation failed after maximum retries.");
}
@ZeroSums ZeroSums added enhancement New feature or request backend Backend Issue v2 labels Oct 16, 2024
@ZeroSums ZeroSums added this to the v2 milestone Oct 16, 2024
@ZeroSums ZeroSums self-assigned this Oct 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backend Backend Issue enhancement New feature or request v2
Projects
None yet
Development

No branches or pull requests

1 participant