Class: Solace::Composers::SystemProgramTransferComposer

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

Examples:

Compose and build a transfer instruction

composer = SystemProgramTransferComposer.new(
  from: from_address,
  to: to_address,
  lamports: 1_000_000
)

See Also:

Since:

  • 0.0.3

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.0.3



70
71
72
73
74
75
76
77
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 70

def build_instruction()
  Instructions::SystemProgram::TransferInstruction.build(
    lamports: lamports,
    to_index: .index_of(to),
    from_index: .index_of(from),
    program_index: .index_of(system_program)
  )
end

#fromString

Extracts the from address from the params

Returns:

  • (String)

    The from address

Since:

  • 0.0.3



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

#lamportsInteger

Returns the lamports to transfer

Returns:

  • (Integer)

    The lamports to transfer

Since:

  • 0.0.3



52
53
54
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 52

def lamports
  params[:lamports]
end

#setup_accountsvoid

This method returns an undefined value.

Setup accounts required for transfer instruction Called automatically during initialization

Since:

  • 0.0.3



60
61
62
63
64
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 60

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

#system_programString

Returns the system program id

Returns:

  • (String)

    The system program id

Since:

  • 0.0.3



45
46
47
# File 'lib/solace/composers/system_program_transfer_composer.rb', line 45

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end

#toString

Extracts the to address from the params

Returns:

  • (String)

    The to address

Since:

  • 0.0.3



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