Module: SolanaRuby::HttpMethods::AccountMethods

Defined in:
lib/solana_ruby/http_methods/account_methods.rb

Overview

Account Related HTTP Methods

Constant Summary collapse

ENCODING_JSON_OPTIONS =
{ encoding: "jsonParsed", commitment: "finalized" }.freeze
FINALIZED_OPTIONS =
{ commitment: "finalized" }.freeze
ENCODING_BASE58_OPTIONS =
{ encoding: "base58" }.freeze

Instance Method Summary collapse

Instance Method Details

#get_account_info(pubkey) ⇒ Object



11
12
13
14
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 11

def (pubkey)
   = (pubkey)
  ["value"]
end

#get_account_info_and_context(pubkey, options = {}) ⇒ Object



20
21
22
23
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 20

def (pubkey, options = {})
   = request("getAccountInfo", [pubkey, options])
  ["result"]
end

#get_largest_accounts(options = ENCODING_BASE58_OPTIONS.merge(FINALIZED_OPTIONS)) ⇒ Object



40
41
42
43
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 40

def get_largest_accounts(options = ENCODING_BASE58_OPTIONS.merge(FINALIZED_OPTIONS))
   = request("getLargestAccounts", [options])
  ["result"]
end

#get_multiple_account_info(pubkeys, options = ENCODING_BASE58_OPTIONS) ⇒ Object



25
26
27
28
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 25

def (pubkeys, options = ENCODING_BASE58_OPTIONS)
  accounts_info = (pubkeys, options)
  accounts_info["value"]
end

#get_multiple_account_info_and_context(pubkeys, options = ENCODING_BASE58_OPTIONS) ⇒ Object



30
31
32
33
34
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 30

def (pubkeys, options = ENCODING_BASE58_OPTIONS)
  params = [pubkeys, options]
  accounts_info = request("getMultipleAccounts", params)
  accounts_info["result"]
end

#get_multiple_parsed_accounts(pubkeys, options = ENCODING_JSON_OPTIONS) ⇒ Object



36
37
38
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 36

def get_multiple_parsed_accounts(pubkeys, options = ENCODING_JSON_OPTIONS)
  (pubkeys, options)
end

#get_nonce(pubkey) ⇒ Object



83
84
85
86
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 83

def get_nonce(pubkey)
  nonce_info = get_nonce_and_context(pubkey)
  nonce_info[:value]
end

#get_nonce_and_context(pubkey) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 66

def get_nonce_and_context(pubkey)
   = (pubkey)
  unless ["value"]["owner"] == "11111111111111111111111111111111"
    raise "Provided account is not a nonce account"
  end

  data = ["value"]["data"][0]
  raise "Nonce account data is empty" if data.nil? || data.empty?

  decoded_data = Base64.decode64(data)
  nonce_info = (decoded_data)
  {
    context: ["context"],
    value: nonce_info
  }
end

#get_parsed_account_info(pubkey, options = ENCODING_JSON_OPTIONS) ⇒ Object



16
17
18
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 16

def (pubkey, options = ENCODING_JSON_OPTIONS)
  (pubkey, options)
end

#get_parsed_program_accounts(program_id, options = ENCODING_JSON_OPTIONS) ⇒ Object



51
52
53
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 51

def get_parsed_program_accounts(program_id, options = ENCODING_JSON_OPTIONS)
  get_program_accounts(program_id, options)
end

#get_parsed_token_accounts_by_owner(owner_pubkey, filters = {}, options = ENCODING_JSON_OPTIONS) ⇒ Object



60
61
62
63
64
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 60

def get_parsed_token_accounts_by_owner(owner_pubkey, filters = {}, options = ENCODING_JSON_OPTIONS)
  params = [owner_pubkey, filters, options]
  parsed_token_accounts = request("getTokenAccountsByOwner", params)
  parsed_token_accounts["result"]
end

#get_program_accounts(program_id, options = FINALIZED_OPTIONS) ⇒ Object



45
46
47
48
49
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 45

def get_program_accounts(program_id, options = FINALIZED_OPTIONS)
  params = [program_id, options]
   = request("getProgramAccounts", params)
  ["result"]
end

#get_vote_accounts(options = FINALIZED_OPTIONS) ⇒ Object



55
56
57
58
# File 'lib/solana_ruby/http_methods/account_methods.rb', line 55

def get_vote_accounts(options = FINALIZED_OPTIONS)
   = request("getVoteAccounts", [options])
  ["result"]
end