Class: Solace::Composers::SystemProgramCreateAccountComposer
- Defined in:
- lib/solace/composers/system_program_create_account_composer.rb
Overview
Composer for creating an account using the system program.
This composer resolves and orders the required accounts for a ‘CreateAccount` instruction, sets up their access permissions, and delegates construction to the appropriate instruction builder (`Instructions::SystemProgram::CreateAccountInstruction`).
It is used for creating new accounts on the Solana blockchain.
Required accounts:
-
From: funding account (writable, signer)
-
Owner: owner program id (readonly, non-signer)
-
**New Account**: new account to create (writable, 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 to address from the params.
-
#lamports ⇒ Integer
Returns the lamports to transfer.
-
#new_account ⇒ String
Extracts the new account address from the params.
-
#owner ⇒ String
Extracts the owner address from the params.
-
#setup_accounts ⇒ void
Setup accounts required for create account instruction Called automatically during initialization.
-
#space ⇒ Integer
Returns the space to allocate.
-
#system_program ⇒ String
Returns the system program id.
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
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 86 def build_instruction(account_context) Solace::Instructions::SystemProgram::CreateAccountInstruction.build( space: space, lamports: lamports, owner: owner, from_index: account_context.index_of(from), new_account_index: account_context.index_of(new_account), system_program_index: account_context.index_of(system_program) ) end |
#from ⇒ String
Extracts the to address from the params
33 34 35 |
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 33 def from params[:from].to_s end |
#lamports ⇒ Integer
Returns the lamports to transfer
61 62 63 |
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 61 def lamports params[:lamports] end |
#new_account ⇒ String
Extracts the new account address from the params
40 41 42 |
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 40 def new_account params[:new_account].to_s end |
#owner ⇒ String
Extracts the owner address from the params
54 55 56 |
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 54 def owner params[:owner].to_s end |
#setup_accounts ⇒ void
This method returns an undefined value.
Setup accounts required for create account instruction Called automatically during initialization
76 77 78 79 80 |
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 76 def setup_accounts account_context.add_writable_signer(from) account_context.add_writable_signer(new_account) account_context.add_readonly_nonsigner(system_program) end |
#space ⇒ Integer
Returns the space to allocate
68 69 70 |
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 68 def space params[:space] end |
#system_program ⇒ String
Returns the system program id
47 48 49 |
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 47 def system_program Solace::Constants::SYSTEM_PROGRAM_ID.to_s end |