{"version":3,"file":"RpcInterface.mjs","sources":["../../src/RpcInterface.ts"],"sourcesContent":["import type { PublicKey } from '@metaplex-foundation/umi-public-keys';\nimport type { MaybeRpcAccount, RpcAccount } from './Account';\nimport { SolAmount } from './Amount';\nimport type { Cluster } from './Cluster';\nimport { DateTime } from './DateTime';\nimport type { GenericAbortSignal } from './GenericAbortSignal';\nimport type {\n  Blockhash,\n  BlockhashWithExpiryBlockHeight,\n  Transaction,\n  TransactionError,\n  TransactionSignature,\n  TransactionStatus,\n  TransactionVersion,\n  TransactionWithMeta,\n} from './Transaction';\nimport { InterfaceImplementationMissingError } from './errors';\n\n/**\n * Defines the interface for an RPC client.\n * It allows us to interact with the Solana blockchain.\n *\n * @category Context and Interfaces\n */\nexport interface RpcInterface {\n  /** The RPC endpoint used by the client. */\n  getEndpoint(): string;\n\n  /** The Solana cluster of the RPC being used. */\n  getCluster(): Cluster;\n\n  /**\n   * Fetch a raw account at the given address.\n   *\n   * @param publicKey The public key of the account to fetch.\n   * @param options The options to use when fetching the account.\n   * @returns A raw account that may or may not exist.\n   */\n  getAccount(\n    publicKey: PublicKey,\n    options?: RpcGetAccountOptions\n  ): Promise<MaybeRpcAccount>;\n\n  /**\n   * Fetch multiple raw accounts at the given addresses.\n   *\n   * @param publicKey The public keys of the accounts to fetch.\n   * @param options The options to use when fetching multiple accounts.\n   * @returns An array of raw accounts that may or may not exist.\n   */\n  getAccounts(\n    publicKeys: PublicKey[],\n    options?: RpcGetAccountsOptions\n  ): Promise<MaybeRpcAccount[]>;\n\n  /**\n   * Fetch multiple raw accounts from a program.\n   *\n   * @param programId The public key of the program to fetch accounts from.\n   * @param options The options to use when fetching program accounts.\n   * @returns An array of raw accounts.\n   */\n  getProgramAccounts(\n    programId: PublicKey,\n    options?: RpcGetProgramAccountsOptions\n  ): Promise<RpcAccount[]>;\n\n  /**\n   * Fetch the estimated production time of a block.\n   *\n   * @param slot The slot to get the estimated production time for.\n   * @param options The options to use when getting the block time of a slot.\n   * @returns The estimated production time of the block in Unix time.\n   */\n  getBlockTime(\n    slot: number,\n    options?: RpcGetBlockTimeOptions\n  ): Promise<DateTime | null>;\n\n  /**\n   * Fetch the balance of an account.\n   *\n   * @param publicKey The public key of the account.\n   * @param options The options to use when fetching an account's balance.\n   * @returns An amount of SOL.\n   */\n  getBalance(\n    publicKey: PublicKey,\n    options?: RpcGetBalanceOptions\n  ): Promise<SolAmount>;\n\n  /**\n   * Get the genesis hash.\n   *\n   * @returns The genesis hash.\n   */\n  getGenesisHash(): Promise<string>;\n\n  /**\n   * Get the amount of rent-exempt SOL required to create an account of the given size.\n   *\n   * @param bytes The size of the account in bytes.\n   * @param options The options to use when fetching the rent exempt amount.\n   * @returns An amount of SOL.\n   */\n  getRent(bytes: number, options?: RpcGetRentOptions): Promise<SolAmount>;\n\n  /**\n   * Fetch the recent slot.\n   *\n   * @param options The options to use when fetching the recent slot.\n   * @returns The recent slot.\n   */\n  getSlot(options?: RpcGetSlotOptions): Promise<number>;\n\n  /**\n   * Fetch the latest blockhash.\n   *\n   * @param options The options to use when fetching the latest blockhash.\n   * @returns The latest blockhash and its block height.\n   */\n  getLatestBlockhash(\n    options?: RpcGetLatestBlockhashOptions\n  ): Promise<BlockhashWithExpiryBlockHeight>;\n\n  /**\n   * Fetch a transaction by its signature.\n   *\n   * @param signature The signature of the transaction to fetch.\n   * @param options The options to use when fetching transactions.\n   * @returns A transaction with its metadata or `null` if the transaction was not found.\n   */\n  getTransaction(\n    signature: TransactionSignature,\n    options?: RpcGetTransactionOptions\n  ): Promise<(TransactionWithMeta & RpcGetTransactionResponseOther) | null>;\n\n  /**\n   * Fetch transaction commitments from an array of signatures.\n   *\n   * @param signatures The signatures of all transactions we want to fetch commitments for.\n   * @param options The options to use when fetching transaction commitments.\n   * @returns An array of transaction statuses in the same order as the signatures.\n   * If a transaction was not found, `null` will be returned instead.\n   */\n  getSignatureStatuses(\n    signatures: TransactionSignature[],\n    options?: RpcGetSignatureStatusesOptions\n  ): Promise<Array<TransactionStatus | null>>;\n\n  /**\n   * Whether or not an account at a given address exists.\n   *\n   * @param publicKey The public key of the account.\n   * @param options The options to use when checking if an account exists.\n   * @returns `true` if the account exists, `false` otherwise.\n   */\n  accountExists(\n    publicKey: PublicKey,\n    options?: RpcAccountExistsOptions\n  ): Promise<boolean>;\n\n  /**\n   * Send and confirm an airdrop transaction to the given address.\n   *\n   * @param publicKey The public key of the account to airdrop to.\n   * @param amount The amount of SOL to airdrop.\n   * @param options The options to use when airdropping SOL.\n   */\n  airdrop(\n    publicKey: PublicKey,\n    amount: SolAmount,\n    options?: RpcAirdropOptions\n  ): Promise<void>;\n\n  /**\n   * Send a custom RPC request to the node.\n   *\n   * @param method The method to call.\n   * @param params The parameters to pass to the method. Can be either:\n   *               - An array for positional parameters\n   *               - An object for named parameters\n   * @param options The options to use when sending a custom RPC request.\n   * @returns The generic result of the RPC call.\n   */\n  call<R, P extends any[] | Record<string, any> = any[]>(\n    method: string,\n    params?: P,\n    options?: RpcCallOptions\n  ): Promise<R>;\n\n  /**\n   * Send a transaction to the blockchain.\n   *\n   * @param transaction The transaction to send.\n   * @param options The options to use when sending a transaction.\n   * @returns The signature of the sent transaction.\n   */\n  sendTransaction(\n    transaction: Transaction,\n    options?: RpcSendTransactionOptions\n  ): Promise<TransactionSignature>;\n\n  /**\n   * Simulate a transaction.\n   *\n   * @param transaction The transaction to simulate.\n   * @param options The options to use when simulating a transaction.\n   * @returns The signature of the sent transaction.\n   */\n  simulateTransaction(\n    transaction: Transaction,\n    options?: RpcSimulateTransactionOptions\n  ): Promise<RpcSimulateTransactionResult>;\n\n  /**\n   * Confirm a sent transaction.\n   *\n   * @param signature The signature of the transaction to confirm.\n   * @param options The options to use when confirming a transaction.\n   * @returns The RPC response of the transaction confirmation.\n   */\n  confirmTransaction(\n    signature: TransactionSignature,\n    options: RpcConfirmTransactionOptions\n  ): Promise<RpcConfirmTransactionResult>;\n}\n\n/**\n * The various commitment levels when fetching data from the blockchain.\n * @category Rpc\n */\nexport type Commitment = 'processed' | 'confirmed' | 'finalized';\n\n/**\n * An object to request a slice of data starting\n * at `offset` and ending at `offset + length`.\n * @category Rpc\n */\nexport type RpcDataSlice = { offset: number; length: number };\n\n/**\n * Defines a filter to use when fetching program accounts.\n * @category Rpc\n */\nexport type RpcDataFilter = RpcDataFilterSize | RpcDataFilterMemcmp;\n\n/**\n * Defines a filter that selects accounts by size.\n * @category Rpc\n */\nexport type RpcDataFilterSize = { dataSize: number };\n\n/**\n * Defines a filter that selects accounts by comparing\n * the given bytes at the given offset.\n * @category Rpc\n */\nexport type RpcDataFilterMemcmp = {\n  memcmp: { offset: number; bytes: Uint8Array };\n};\n\n/**\n * Defines an RPC result that wraps the returned value\n * and provides the slot number as context.\n * @category Rpc\n */\nexport type RpcResultWithContext<Value> = {\n  context: { slot: number };\n  value: Value;\n};\n\n/**\n * Defines the common options re-used by all\n * the methods defines in the RPC interface.\n * @category Rpc\n */\nexport type RpcBaseOptions = {\n  /** An explicit RPC request identifier. */\n  id?: string;\n  /** An abort signal to prematurely cancel the request. */\n  signal?: GenericAbortSignal;\n  /** The commitment level to use when fetching data. */\n  commitment?: Commitment;\n  /** The minimum slot to use when fetching data. */\n  minContextSlot?: number;\n};\n\n/**\n * The options to use when fetching an account.\n * @category Rpc\n */\nexport type RpcGetAccountOptions = RpcBaseOptions & {\n  /** Select only a portion of the account's data. */\n  dataSlice?: RpcDataSlice;\n};\n\n/**\n * The options to use when fetching multiple accounts.\n * @category Rpc\n */\nexport type RpcGetAccountsOptions = RpcBaseOptions & {\n  /** For each account, select only a portion of their data. */\n  dataSlice?: RpcDataSlice;\n};\n\n/**\n * The options to use when fetching program accounts.\n * @category Rpc\n */\nexport type RpcGetProgramAccountsOptions = RpcBaseOptions & {\n  /** For each program account, select only a portion of their data. */\n  dataSlice?: RpcDataSlice;\n  /** A set of filters to narrow down the returned program accounts. Max 5 filters. */\n  filters?: RpcDataFilter[];\n};\n\n/**\n * The options to use when fetching a block.\n * @category Rpc\n */\nexport type RpcGetVersionedBlockOptions = RpcBaseOptions & {\n  /** The level of finality desired */\n  commitment?: Commitment;\n  maxSupportedTransactionVersion?: number;\n  rewards?: boolean;\n  transactionDetails?: 'accounts' | 'full' | 'none' | 'signatures';\n};\n\n/**\n * The options to use when getting the block time of a slot.\n * @category Rpc\n */\nexport type RpcGetBlockTimeOptions = RpcBaseOptions;\n\n/**\n * The options to use when fetching the balance of an account.\n * @category Rpc\n */\nexport type RpcGetBalanceOptions = RpcBaseOptions;\n\n/**\n * The options to use when fetching the rent exempt amount.\n * @category Rpc\n */\nexport type RpcGetRentOptions = RpcBaseOptions & {\n  /** @defaultValue `false` */\n  includesHeaderBytes?: boolean;\n};\n\n/**\n * The options to use when fetching the recent slot.\n * @category Rpc\n */\nexport type RpcGetSlotOptions = RpcBaseOptions;\n\n/**\n * The options to use when fetching the latest blockhash.\n * @category Rpc\n */\nexport type RpcGetLatestBlockhashOptions = RpcBaseOptions;\n\n/**\n * The options to use when fetching a transaction.\n * @category Rpc\n */\nexport type RpcGetTransactionOptions = RpcBaseOptions;\n\n/**\n * The other fields of getTransaction response.\n * @category Rpc\n */\nexport type RpcGetTransactionResponseOther = {\n  response: {\n    blockTime?: bigint;\n    slot: bigint;\n    version?: TransactionVersion;\n  };\n};\n\n/**\n * The options to use when fetching transaction statuses.\n * @category Rpc\n */\nexport type RpcGetSignatureStatusesOptions = RpcBaseOptions & {\n  /**\n   * Enable searching status history, not needed for recent transactions.\n   * @defaultValue `false`\n   */\n  searchTransactionHistory?: boolean;\n};\n\n/**\n * The options to use when checking if an account exists.\n * @category Rpc\n */\nexport type RpcAccountExistsOptions = RpcBaseOptions;\n\n/**\n * The options to use when airdropping SOL.\n * @category Rpc\n */\nexport type RpcAirdropOptions = Partial<RpcConfirmTransactionOptions>;\n\n/**\n * The options to use when sending a custom RPC request.\n * @category Rpc\n */\nexport type RpcCallOptions = RpcBaseOptions & {\n  /**\n   * By default, the RPC client pushes an additional `options`\n   * parameter to the RPC request when a commitment is specified.\n   * This `extra` parameter can be used to add more data to the\n   * `options` parameter.\n   */\n  extra?: object;\n};\n\n/**\n * The options to use when sending a transaction.\n * @category Rpc\n */\nexport type RpcSendTransactionOptions = RpcBaseOptions & {\n  /** Whether to skip the preflight check. */\n  skipPreflight?: boolean;\n  /** The commitment level to use for the preflight check. */\n  preflightCommitment?: Commitment;\n  /** The maximum number of retries to use. */\n  maxRetries?: number;\n};\n\n/**\n * The options to use when simulating a transaction.\n * @category Rpc\n */\nexport type RpcSimulateTransactionOptions = RpcBaseOptions & {\n  /** Optional parameter used to specify a list of base58-encoded account addresses to return post simulation state */\n  accounts?: PublicKey[];\n  /** Optional parameter used to enable signature verification before simulation */\n  verifySignatures?: boolean;\n  /** Optional parameter used to replace the transaction's recent blockhash with the latest blockhash */\n  replaceRecentBlockhash?: boolean;\n};\n\n/**\n * The options to use when confirming a transaction.\n * @category Rpc\n */\nexport type RpcConfirmTransactionOptions = RpcBaseOptions & {\n  /** The confirm strategy to use. */\n  strategy: RpcConfirmTransactionStrategy;\n};\n\n/**\n * Represents all the possible strategies to use when confirming a transaction.\n * @category Rpc\n */\nexport type RpcConfirmTransactionStrategy =\n  | {\n      type: 'blockhash';\n      blockhash: Blockhash;\n      lastValidBlockHeight: number;\n    }\n  | {\n      type: 'durableNonce';\n      minContextSlot: number;\n      nonceAccountPubkey: PublicKey;\n      nonceValue: string;\n    };\n\n/**\n * Defines the result of a transaction simulation.\n * @category Rpc\n */\nexport type RpcSimulateTransactionResult = {\n  err: TransactionError | null;\n  unitsConsumed?: number;\n  logs: Array<string> | null;\n  accounts?: Array<RpcSimulateTransactionAccountInfo | null> | null;\n  returnData?: RpcSimulateTransactionTransactionReturnData | null;\n  replacementBlockhash?: RpcSimulateTransactionReplacementBlockhash | null;\n};\n\n/**\n * Defines the result of a transaction simulation accounts info.\n * @category Rpc\n */\nexport type RpcSimulateTransactionAccountInfo = {\n  executable: boolean;\n  owner: string;\n  lamports: number;\n  data: string[];\n  rentEpoch?: number;\n};\n\n/**\n * Defines the result of a transaction confirmation.\n * @category Rpc\n */\nexport type RpcConfirmTransactionResult = RpcResultWithContext<{\n  err: TransactionError | null;\n}>;\n\n/**\n * Defines the Transaction Return Data from Simulate Transaction.\n * @category Rpc\n */\nexport type RpcSimulateTransactionTransactionReturnData = {\n  data: [string, 'base64'];\n  programId: string;\n};\n\n/**\n * Defines the replacement blockhash information returned when replaceRecentBlockhash is used.\n * @category Rpc\n */\nexport type RpcSimulateTransactionReplacementBlockhash = {\n  /** The replacement blockhash used for simulation */\n  blockhash: string;\n  /** The last valid block height for the replacement blockhash */\n  lastValidBlockHeight: bigint;\n};\n\n/**\n * An implementation of the {@link RpcInterface} that throws an error when called.\n * @category Rpc\n */\nexport function createNullRpc(): RpcInterface {\n  const errorHandler = () => {\n    throw new InterfaceImplementationMissingError('RpcInterface', 'rpc');\n  };\n  return {\n    getEndpoint: errorHandler,\n    getCluster: errorHandler,\n    getAccount: errorHandler,\n    getAccounts: errorHandler,\n    getProgramAccounts: errorHandler,\n    getBlockTime: errorHandler,\n    getBalance: errorHandler,\n    getRent: errorHandler,\n    getSlot: errorHandler,\n    getGenesisHash: errorHandler,\n    getLatestBlockhash: errorHandler,\n    getTransaction: errorHandler,\n    getSignatureStatuses: errorHandler,\n    accountExists: errorHandler,\n    airdrop: errorHandler,\n    call: errorHandler,\n    sendTransaction: errorHandler,\n    simulateTransaction: errorHandler,\n    confirmTransaction: errorHandler,\n  };\n}\n"],"names":["createNullRpc","errorHandler","InterfaceImplementationMissingError","getEndpoint","getCluster","getAccount","getAccounts","getProgramAccounts","getBlockTime","getBalance","getRent","getSlot","getGenesisHash","getLatestBlockhash","getTransaction","getSignatureStatuses","accountExists","airdrop","call","sendTransaction","simulateTransaction","confirmTransaction"],"mappings":";;AAkBA;AACA;AACA;AACA;AACA;AACA;;AAofA;AACA;AACA;AACA;AACO,SAASA,aAAa,GAAiB;EAC5C,MAAMC,YAAY,GAAG,MAAM;AACzB,IAAA,MAAM,IAAIC,mCAAmC,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;GACrE,CAAA;EACD,OAAO;AACLC,IAAAA,WAAW,EAAEF,YAAY;AACzBG,IAAAA,UAAU,EAAEH,YAAY;AACxBI,IAAAA,UAAU,EAAEJ,YAAY;AACxBK,IAAAA,WAAW,EAAEL,YAAY;AACzBM,IAAAA,kBAAkB,EAAEN,YAAY;AAChCO,IAAAA,YAAY,EAAEP,YAAY;AAC1BQ,IAAAA,UAAU,EAAER,YAAY;AACxBS,IAAAA,OAAO,EAAET,YAAY;AACrBU,IAAAA,OAAO,EAAEV,YAAY;AACrBW,IAAAA,cAAc,EAAEX,YAAY;AAC5BY,IAAAA,kBAAkB,EAAEZ,YAAY;AAChCa,IAAAA,cAAc,EAAEb,YAAY;AAC5Bc,IAAAA,oBAAoB,EAAEd,YAAY;AAClCe,IAAAA,aAAa,EAAEf,YAAY;AAC3BgB,IAAAA,OAAO,EAAEhB,YAAY;AACrBiB,IAAAA,IAAI,EAAEjB,YAAY;AAClBkB,IAAAA,eAAe,EAAElB,YAAY;AAC7BmB,IAAAA,mBAAmB,EAAEnB,YAAY;AACjCoB,IAAAA,kBAAkB,EAAEpB,YAAAA;GACrB,CAAA;AACH;;;;"}