Class: Solace::Composers::SystemProgramTransferComposer
- Defined in:
- lib/solace/composers/system_program_transfer_composer.rb
Overview
Composer for creating a system program transfer instruction.
This composer resolves and orders the required accounts for a ‘Transfer` instruction, sets up their access permissions, and delegates construction to the appropriate instruction builder (`Instructions::SystemProgram::TransferInstruction`).
It is used for transferring lamports from one account to another.
Required accounts:
-
From: source account (writable, signer)
-
To: destination account (writable, non-signer)
-
Program: System program (readonly, non-signer)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#build_instruction(account_context) ⇒ Solace::Instruction
Build instruction with resolved account indices.
-
#from ⇒ String
Extracts the from address from the params.
-
#lamports ⇒ Integer
Returns the lamports to transfer.
-
#setup_accounts ⇒ void
Setup accounts required for transfer instruction Called automatically during initialization.
-
#system_program ⇒ String
Returns the system program id.
-
#to ⇒ String
Extracts the to address from the params.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Solace::Composers::Base
Instance Method Details
#build_instruction(account_context) ⇒ Solace::Instruction
Build instruction with resolved account indices
70 71 72 73 74 75 76 77 |
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 70 def build_instruction(account_context) Instructions::SystemProgram::TransferInstruction.build( lamports: lamports, to_index: account_context.index_of(to), from_index: account_context.index_of(from), program_index: account_context.index_of(system_program) ) end |
#from ⇒ String
Extracts the from address from the params
38 39 40 |
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 38 def from params[:from].is_a?(String) ? params[:from] : params[:from].address end |
#lamports ⇒ Integer
Returns the lamports to transfer
52 53 54 |
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 52 def lamports params[:lamports] end |
#setup_accounts ⇒ void
This method returns an undefined value.
Setup accounts required for transfer instruction Called automatically during initialization
60 61 62 63 64 |
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 60 def setup_accounts account_context.add_writable_signer(from) account_context.add_writable_nonsigner(to) account_context.add_readonly_nonsigner(system_program) end |
#system_program ⇒ String
Returns the system program id
45 46 47 |
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 45 def system_program Solace::Constants::SYSTEM_PROGRAM_ID end |
#to ⇒ String
Extracts the to address from the params
31 32 33 |
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 31 def to params[:to].is_a?(String) ? params[:to] : params[:to].address end |