Class: Solace::Composers::SplTokenProgramCloseAccountComposer
- Defined in:
- lib/solace/composers/spl_token_program_close_account_composer.rb
Overview
Composer for creating a SPL Token Program CloseAccount instruction.
This composer resolves and orders the required accounts for a ‘CloseAccount` instruction, sets up their access permissions, and delegates construction to the appropriate instruction builder.
The CloseAccount instruction closes a token account and transfers remaining lamports to a destination account. The account must have a balance of zero tokens.
Required accounts:
-
Account: token account to close (writable, non-signer)
-
Destination: account to receive lamports (writable, non-signer)
-
Authority: account authority (non-writable, signer)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#account ⇒ String
Extracts the token account address from the params.
-
#authority ⇒ String
Extracts the authority address from the params.
-
#build_instruction(account_context) ⇒ Solace::Instruction
Build instruction with resolved account indices.
-
#destination ⇒ String
Extracts the destination address from the params.
-
#setup_accounts ⇒ void
Setup accounts required for close account instruction Called automatically during initialization.
-
#spl_token_program ⇒ String
Returns the spl token program id.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Solace::Composers::Base
Instance Method Details
#account ⇒ String
Extracts the token account address from the params
31 32 33 |
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 31 def account params[:account].to_s end |
#authority ⇒ String
Extracts the authority address from the params
45 46 47 |
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 45 def params[:authority].to_s end |
#build_instruction(account_context) ⇒ Solace::Instruction
Build instruction with resolved account indices
71 72 73 74 75 76 77 78 |
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 71 def build_instruction(account_context) Instructions::SplToken::CloseAccountInstruction.build( account_index: account_context.index_of(account), authority_index: account_context.index_of(), destination_index: account_context.index_of(destination), program_index: account_context.index_of(spl_token_program) ) end |
#destination ⇒ String
Extracts the destination address from the params
38 39 40 |
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 38 def destination params[:destination].to_s end |
#setup_accounts ⇒ void
This method returns an undefined value.
Setup accounts required for close account instruction Called automatically during initialization
60 61 62 63 64 65 |
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 60 def setup_accounts account_context.add_writable_nonsigner(account) account_context.add_writable_nonsigner(destination) account_context.add_readonly_signer() account_context.add_readonly_nonsigner(spl_token_program) end |
#spl_token_program ⇒ String
Returns the spl token program id
52 53 54 |
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 52 def spl_token_program Constants::TOKEN_PROGRAM_ID.to_s end |