Class: SolanaRuby::TransactionHelpers::TokenAccount
- Inherits:
-
Object
- Object
- SolanaRuby::TransactionHelpers::TokenAccount
- Defined in:
- lib/solana_ruby/transaction_helpers/token_account.rb
Constant Summary collapse
- ASSOCIATED_TOKEN_PROGRAM_ID =
Associated Token Program ID
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'.freeze
- TOKEN_PROGRAM_ID =
Token Program ID
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'.freeze
Class Method Summary collapse
- .add_signers(keys, owner_or_authority, multi_signers) ⇒ Object
- .get_associated_token_address(mint, payer) ⇒ Object
Class Method Details
.add_signers(keys, owner_or_authority, multi_signers) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/solana_ruby/transaction_helpers/token_account.rb', line 29 def self.add_signers(keys, , multi_signers) if multi_signers.is_a?(Array) && multi_signers.any? keys.push({ pubkey: , is_signer: false, is_writable: false }) multi_signers.each do |signer| pubkey = signer.is_a?(String) ? signer : signer.public_key keys.push({ pubkey: pubkey, is_signer: true, is_writable: false }) end else keys.push({ pubkey: , is_signer: true, is_writable: false }) end keys end |
.get_associated_token_address(mint, payer) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/solana_ruby/transaction_helpers/token_account.rb', line 10 def self.get_associated_token_address(mint, payer) mint_bytes = Base58.base58_to_binary(mint, :bitcoin) payer_bytes = Base58.base58_to_binary(payer, :bitcoin) associated_program_bytes = Base58.base58_to_binary(ASSOCIATED_TOKEN_PROGRAM_ID, :bitcoin) # Derive associated token account PDA seeds = [ payer_bytes, Base58.base58_to_binary(TOKEN_PROGRAM_ID, :bitcoin), mint_bytes ] # Attempt to find the first valid off-curve PDA associated_token_account_pubkey = find_program_address(seeds, associated_program_bytes) # Return the computed Base58 PDA string Base58.binary_to_base58(associated_token_account_pubkey, :bitcoin) end |