SPB Git

spb/os-vault Public

Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.

Swift 96% Shell 3.4% Makefile 0.6%
16.9 KB · 347 lines swift
Raw Blame History
1import Foundation23public protocol SolanaAPIClient {4    /// The endpoint that indicates the rpcpool address and network5    var endpoint: APIEndPoint { get }67    // MARK: -  API Methods89    /// Returns all information associated with the account of provided Pubkey10    /// - Parameters:11    ///  - account: Pubkey of account to query, as base-58 encoded string12    /// - Throws: APIClientError13    /// - Returns The result will be an BufferInfo14    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getaccountinfo15    ///16    func getAccountInfo<T: BufferLayout>(account: String) async throws -> BufferInfo<T>?1718    /// Returns all information associated with the account of provided Pubkey19    /// - Parameters:20    ///  - account: Pubkey of account to query, as base-58 encoded string21    /// - Throws: APIClientError22    /// - Returns The result will be an BufferInfo23    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getaccountinfo24    @available(*, deprecated, renamed: "getAccountInfo")25    func getAccountInfoThrowable<T: BufferLayout>(account: String) async throws -> BufferInfo<T>2627    /// Returns the balance of the account of provided Pubkey28    /// - Parameters:29    ///  - account: Pubkey of account to query, as base-58 encoded string30    ///  - commitment: Optional31    /// - Throws: APIClientError32    /// - Returns The result will be an UInt64 balance value33    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getbalance34    ///35    func getBalance(account: String, commitment: Commitment?) async throws -> UInt643637    /// Returns commitment for particular block38    /// - Parameters:39    ///  - block:  block, identified by Slot40    /// - Throws: APIClientError41    /// - Returns The result will be BlockCommitment42    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getblockcommitment43    ///44    func getBlockCommitment(block: UInt64) async throws -> BlockCommitment4546    /// Returns the estimated production time of a block47    /// - Parameters:48    ///  - block:  block, identified by Slot49    /// - Throws: APIClientError50    /// - Returns Estimated production date51    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getblocktime52    ///53    func getBlockTime(block: UInt64) async throws -> Date5455    /// Returns information about all the nodes participating in the cluster56    /// - Throws: APIClientError57    /// - Returns The result field will be an array of ClusterNodes58    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getclusternodes59    ///60    func getClusterNodes() async throws -> [ClusterNodes]6162    /// Returns the current block height of the node63    /// - Throws: APIClientError64    /// - Returns Current block height65    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getblockheight66    ///67    func getBlockHeight() async throws -> UInt646869    /// Returns a list of confirmed blocks starting at the given slot70    /// - Parameters:71    ///  - startSlot: start_slot, as u64 integer72    ///  - limit: as u64 integer73    /// - Throws: APIClientError74    /// - Returns The result field will be an array of u64 integers listing confirmed blocks starting at start_slot for75    /// up to limit blocks, inclusive76    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getconfirmedblockswithlimit77    ///78    func getConfirmedBlocksWithLimit(startSlot: UInt64, limit: UInt64) async throws -> [UInt64]7980    /// Returns identity and transaction information about a confirmed block in the ledger81    /// - Parameters:82    ///  - slot: slot, as u64 integer83    ///  - encoding: encoding for each returned Transaction, either "json", "jsonParsed", "base58" (slow), "base64"84    ///     If parameter not provided, the default encoding is "json".85    ///     "jsonParsed" encoding attempts to use program-specific instruction parsers to return more human-readable and86    /// explicit data in the transaction.message.instructions list.87    ///     If "jsonParsed" is requested but a parser cannot be found, the instruction falls back to regular JSON88    /// encoding (accounts, data, and programIdIndex fields)89    /// - Throws: APIClientError90    /// - Returns The result field will be an ConfirmedBlock object91    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getconfirmedblock92    ///93    func getConfirmedBlock(slot: UInt64, encoding: String) async throws -> ConfirmedBlock9495    /// Get all confirmed signature for an address96    /// - Parameters:97    ///   - account: address that involved in transactions98    ///   - startSlot: start slot99    ///   - endSlot: end slot100    /// - Returns: array of transactionSignatures101    func getConfirmedSignaturesForAddress(account: String, startSlot: UInt64, endSlot: UInt64) async throws -> [String]102103    /// Returns information about the current epoch104    /// - Parameters:105    ///  - commitment: Optional106    /// - Throws: APIClientError107    /// - Returns The result field will be an array of u64 integers listing confirmed blocks starting at start_slot for108    /// up to limit blocks, inclusive109    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getepochinfo110    ///111    func getEpochInfo(commitment: Commitment?) async throws -> EpochInfo112113    /// Returns a recent block hash from the ledger, a fee schedule that can be used to compute the cost of submitting a114    /// transaction using it, and the last slot in which the blockhash will be valid.115    /// - Parameters:116    ///  - commitment: Optional117    /// - Throws: APIClientError118    /// - Returns The result field will be an array of u64 integers listing confirmed blocks starting at start_slot for119    /// up to limit blocks, inclusive120    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getfees121    ///122    func getFees(commitment: Commitment?) async throws -> Fee123124    /// Returns minimum balance required to make account rent exempt125    /// - Parameters:126    ///  - dataLength: account data length127    ///  - commitment: Optional128    /// - Throws: APIClientError129    /// - Returns minimum lamports required in account130    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getminimumbalanceforrentexemption131    ///132    func getMinimumBalanceForRentExemption(dataLength: UInt64, commitment: Commitment?) async throws -> UInt64133134    /// Returns the statuses of a list of signatures. Unless the searchTransactionHistory configuration parameter is135    /// included,136    /// this method only searches the recent status cache of signatures,137    /// which retains statuses for all active slots plus MAX_RECENT_BLOCKHASHES rooted slots.138    /// - Parameters:139    ///  - signatures: An array of transaction signatures to confirm, as base-58 encoded strings140    ///  - configs: (optional) Configuration object141    /// - Throws: APIClientError142    /// - Returns minimum lamports required in account143    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturestatuses144    ///145    func getSignatureStatuses(signatures: [String], configs: RequestConfiguration?) async throws -> [SignatureStatus?]146    /// - SeeAlso getSignatureStatuses(signatures: , configs:) async throws -> [SignatureStatus?]147    func getSignatureStatus(signature: String, configs: RequestConfiguration?) async throws -> SignatureStatus148149    /// Returns the token balance of an SPL Token account150    /// - Parameters:151    ///  - pubkey: Pubkey of Token account to query, as base-58 encoded string152    ///  - commitment: Optional153    /// - Throws: APIClientError154    /// - Returns The result will be an TokenAccountBalance155    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountbalance156    ///157    func getTokenAccountBalance(pubkey: String, commitment: Commitment?) async throws -> TokenAccountBalance158159    /// Returns all SPL Token accounts by approved Delegate160    /// - Parameters:161    ///  - pubkey: Pubkey of account delegate to query, as base-58 encoded string162    ///  - mint: (optional) Pubkey of the specific token Mint to limit accounts to, as base-58 encoded string;163    ///  - programId: (optional)  Pubkey of the Token program ID that owns the accounts, as base-58 encoded string164    ///  - configs: (optional) Configuration object165    /// - Throws: APIClientError166    /// - Returns The result will be an array of TokenAccount<AccountInfo>167    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbydelegate168    ///169    func getTokenAccountsByDelegate<T: TokenAccountLayoutState>(170        pubkey: String,171        mint: String?,172        programId: String?,173        configs: RequestConfiguration?174    ) async throws -> [TokenAccount<T>]175176    /// Returns all SPL Token accounts by token owner177    /// - Parameters:178    ///  - pubkey: Pubkey of account owner to query, as base-58 encoded string179    ///  - params:Pubkey of the specific token Mint to limit accounts to, as base-58 encoded string; or Pubkey of the180    /// Token program ID that owns the accounts, as base-58 encoded string181    ///  - configs: (optional) RequestConfiguration182    /// - Throws: APIClientError183    /// - Returns The result will be an array of TokenAccount<AccountInfo>184    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbyowner185    ///186    func getTokenAccountsByOwner<T: TokenAccountLayoutState>(187        pubkey: String,188        params: OwnerInfoParams?,189        configs: RequestConfiguration?,190        decodingTo: T.Type191    ) async throws -> [TokenAccount<T>]192193    /// Returns the 20 largest accounts of a particular SPL Token type194    /// - Parameters:195    ///  - pubkey: Pubkey of token Mint to query, as base-58 encoded string196    ///  - commitment: (optional) Commitment197    /// - Throws: APIClientError198    /// - Returns The result will be an array of TokenAccount199    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#gettokenlargestaccounts200    ///201    func getTokenLargestAccounts(pubkey: String, commitment: Commitment?) async throws -> [TokenAmount]202203    /// Returns the total supply of an SPL Token type204    /// - Parameters:205    ///  - pubkey: Pubkey of token Mint to query, as base-58 encoded string206    ///  - commitment: (optional) Commitment207    /// - Throws: APIClientError208    /// - Returns The result will be a TokenAmount209    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#gettokensupply210    ///211    func getTokenSupply(pubkey: String, commitment: Commitment?) async throws -> TokenAmount212213    /// Returns the current solana versions running on the node214    /// - Throws: APIClientError215    /// - Returns The result field will be a Version216    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getversion217    ///218    func getVersion() async throws -> Version219220    /// Returns the account info and associated stake for all the voting accounts in the current bank221    /// - Parameters:222    ///  - commitment: (optional) Commitment223    /// - Throws: APIClientError224    /// - Returns The result field will be a VoteAccounts225    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getvoteaccounts226    ///227    func getVoteAccounts(commitment: Commitment?) async throws -> VoteAccounts228229    /// Returns the lowest slot that the node has information about in its ledger. This value may increase over time if230    /// the node is configured to purge older ledger data231    /// - Throws: APIClientError232    /// - Returns Minimum ledger slot233    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#minimumledgerslot234    ///235    func minimumLedgerSlot() async throws -> UInt64236    func requestAirdrop(account: String, lamports: UInt64, commitment: Commitment?) async throws -> String237238    /// Submits a signed transaction to the cluster for processing.239    /// This method does not alter the transaction in any way; it relays the transaction created by clients to the node240    /// as-is.241    /// - Parameters:242    ///  - transaction: fully-signed Transaction, as encoded string243    ///  - configs: Configuration object244    /// - Throws: APIClientError245    /// - Returns First Transaction Signature embedded in the transaction, as base-58 encoded string246    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#sendtransaction247    ///248    func sendTransaction(transaction: String, configs: RequestConfiguration) async throws -> TransactionID249250    /// Simulate sending a transaction251    /// - Parameters:252    ///  - serializedTransaction: fully-signed Transaction, as encoded string253    ///  - configs: Configuration object254    /// - Throws: APIClientError255    /// - Returns First Transaction Signature embedded in the transaction, as base-58 encoded string256    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#simulatetransaction257    ///258    func simulateTransaction(transaction: String, configs: RequestConfiguration) async throws -> SimulationResult259    func setLogFilter(filter: String) async throws -> String?260    func validatorExit() async throws -> Bool261262    /// Returns the account information for a list of Pubkeys263    /// - Parameters:264    ///  - pubkeys: An array of Pubkeys to query, as base-58 encoded strings265    /// - Throws: APIClientError266    /// - Returns The result will be an RpcResponse267    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getmultipleaccounts268    ///269    func getMultipleAccounts<T: BufferLayout>(pubkeys: [String], commitment: Commitment) async throws270        -> [BufferInfo<T>?]271272    /// Observe status of a sending transaction by periodically calling getSignatureStatuses273    /// - Parameters:274    ///  - signature: signature of the transaction, as base-58 encoded strings275    ///  - timeout: timeout (in seconds)276    ///  - delay: delay between requests277    /// - Throws: APIClientError278    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturestatuses279    ///280    func observeSignatureStatus(signature: String, timeout: Int, delay: Int) -> AsyncStream<PendingTransactionStatus>281282    /// Returns a recent block hash from the ledger, and a fee schedule that can be used to compute the cost of283    /// submitting a transaction using it.284    /// - Parameters:285    ///  - commitment: (optional) Commitment286    /// - Throws: APIClientError287    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getrecentblockhash288    ///289    func getRecentBlockhash(commitment: Commitment?) async throws -> String290291    /// Returns signatures for confirmed transactions that include the given address in their accountKeys list.292    /// Returns signatures backwards in time from the provided signature or most recent confirmed block293    /// - Parameters:294    ///  - address: account address as base-58 encoded string295    ///  - configs: (optional) Configuration object296    /// - Throws: APIClientError297    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getrecentblockhash298    ///299    func getSignaturesForAddress(address: String, configs: RequestConfiguration?) async throws -> [SignatureInfo]300301    /// Returns transaction details for a confirmed transaction302    /// - Parameters:303    ///   - signature: transaction signature304    ///   - commitment: "processed" is not supported. If parameter not provided, the default is "finalized".305    /// - Returns:306    /// - Throws:307    func getTransaction(signature: String, commitment: Commitment?) async throws -> TransactionInfo?308309    /// Generic methods for methods that is not on the list above310    /// - Parameters:311    ///   - method: name of the method312    ///   - params: the parameters313    /// - Returns: result of the request314    func request<Entity: Decodable>(method: String, params: [Encodable]) async throws -> Entity315316    // MARK: - Batch request317318    /// Perform a multiple requests at once319    /// - Parameter requests: the requests320    /// - Returns: the result of mutiple requests321    func batchRequest(with requests: [JSONRPCRequestEncoder.RequestType]) async throws322        -> [AnyResponse<JSONRPCRequestEncoder.RequestType.Entity>]323324    /// Perform a multiple same returning type requests at once325    ///326    /// - Experiment: Will be changed in future.327    /// - Parameter method: method name328    /// - Parameter params: params329    /// - Returns: the result of mutiple requests330    func batchRequest<Entity: Decodable>(method: String, params: [[Encodable]]) async throws -> [Entity?]331332    /// Returns a list of recent performance samples, in reverse slot order.333    /// Performance samples are taken every 60 seconds and include the number of transactions and slots that occur in a334    /// given time window.335    /// - Parameters:336    ///  - limit: number of samples to return (maximum 720)337    /// - Throws: APIClientError338    /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getrecentperformancesamples339    ///340    func getRecentPerformanceSamples(limit: [UInt]) async throws -> [PerfomanceSamples]341342    // TODO: full implement343    func getSlot() async throws -> UInt64344345    func getAddressLookupTable(accountKey: PublicKey) async throws -> AddressLookupTableAccount?346}347