Module: Solana::Ruby::Kit::Rpc::Api::GetTokenAccountsByOwner

Extended by:
T::Sig
Included in:
Client
Defined in:
lib/solana/ruby/kit/rpc/api/get_token_accounts_by_owner.rb

Overview

Fetch all SPL Token accounts by owner. filter must be one of:

{ 'mint' => mint_address }
{ 'programId' => program_id }

Instance Method Summary collapse

Instance Method Details

#get_token_accounts_by_owner(owner, filter, encoding: 'base64', commitment: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/solana/ruby/kit/rpc/api/get_token_accounts_by_owner.rb', line 22

def get_token_accounts_by_owner(owner, filter, encoding: 'base64', commitment: nil)
  config = { 'encoding' => encoding }
  config['commitment'] = commitment.to_s if commitment

  result = transport.request('getTokenAccountsByOwner', [owner, filter, config])
  slot   = Kernel.Integer(result['context']['slot'])
  value  = Kernel.Array(result['value']).map do |item|
    raw = item['account']
    {
      pubkey:  item['pubkey'],
      account: RpcTypes::AccountInfoWithBase64Data.new(
        executable: raw['executable'],
        lamports:   Kernel.Integer(raw['lamports']),
        owner:      raw['owner'],
        space:      Kernel.Integer(raw.fetch('space', 0)),
        rent_epoch: Kernel.Integer(raw.fetch('rentEpoch', 0)),
        data:       Kernel.Array(raw['data'])
      )
    }
  end

  RpcTypes::RpcContextualValue.new(slot: slot, value: value)
end