Module: Solana::Ruby::Kit::Rpc::Api::GetProgramAccounts
- Extended by:
- T::Sig
- Included in:
- Client
- Defined in:
- lib/solana/ruby/kit/rpc/api/get_program_accounts.rb
Overview
Fetch all accounts owned by a program. Mirrors TypeScript’s GetProgramAccountsApi.getProgramAccounts.
Returns an Array of { pubkey:, account: AccountInfoWithBase64Data }.
Instance Method Summary collapse
Instance Method Details
#get_program_accounts(program_id, encoding: 'base64', filters: [], commitment: nil, min_context_slot: nil, with_context: false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/solana/ruby/kit/rpc/api/get_program_accounts.rb', line 24 def get_program_accounts( program_id, encoding: 'base64', filters: [], commitment: nil, min_context_slot: nil, with_context: false ) config = { 'encoding' => encoding, 'withContext' => with_context } config['filters'] = filters unless filters.empty? config['commitment'] = commitment.to_s if commitment config['minContextSlot'] = min_context_slot if min_context_slot result = transport.request('getProgramAccounts', [program_id, config]) # withContext wraps result in {context:, value:} accounts = with_context ? result['value'] : result Kernel.Array(accounts).map do |item| account_raw = item['account'] { pubkey: item['pubkey'], account: RpcTypes::AccountInfoWithBase64Data.new( executable: account_raw['executable'], lamports: Kernel.Integer(account_raw['lamports']), owner: account_raw['owner'], space: Kernel.Integer(account_raw.fetch('space', 0)), rent_epoch: Kernel.Integer(account_raw.fetch('rentEpoch', 0)), data: Kernel.Array(account_raw['data']) ) } end end |