Class: Solace::Composers::SystemProgramCreateAccountComposer

Inherits:
Base
  • Object
show all
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)

Examples:

Compose and build a create account instruction

composer = SystemProgramCreateAccountComposer.new(
  from: payer_address,
  new_account: ,
  owner: owner_address,
  lamports: 1000,
  space: 1024
)

See Also:

Since:

  • 0.1.0

Instance Attribute Summary

Attributes inherited from Base

#account_context, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize

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

Parameters:

Returns:

Since:

  • 0.1.0



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()
  Solace::Instructions::SystemProgram::CreateAccountInstruction.build(
    space: space,
    lamports: lamports,
    owner: owner,
    from_index: .index_of(from),
    new_account_index: .index_of(),
    system_program_index: .index_of(system_program)
  )
end

#fromString

Extracts the to address from the params

Returns:

  • (String)

    The from address

Since:

  • 0.1.0



33
34
35
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 33

def from
  params[:from].to_s
end

#lamportsInteger

Returns the lamports to transfer

Returns:

  • (Integer)

    The lamports to transfer

Since:

  • 0.1.0



61
62
63
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 61

def lamports
  params[:lamports]
end

#new_accountString

Extracts the new account address from the params

Returns:

  • (String)

    The new account address

Since:

  • 0.1.0



40
41
42
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 40

def 
  params[:new_account].to_s
end

#ownerString

Extracts the owner address from the params

Returns:

  • (String)

    The owner address

Since:

  • 0.1.0



54
55
56
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 54

def owner
  params[:owner].to_s
end

#setup_accountsvoid

This method returns an undefined value.

Setup accounts required for create account instruction Called automatically during initialization

Since:

  • 0.1.0



76
77
78
79
80
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 76

def setup_accounts
  .add_writable_signer(from)
  .add_writable_signer()
  .add_readonly_nonsigner(system_program)
end

#spaceInteger

Returns the space to allocate

Returns:

  • (Integer)

    The space to allocate

Since:

  • 0.1.0



68
69
70
# File 'lib/solace/composers/system_program_create_account_composer.rb', line 68

def space
  params[:space]
end

#system_programString

Returns the system program id

Returns:

  • (String)

    The system program id

Since:

  • 0.1.0



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