Class: Solace::Instructions::SystemProgram::CreateAccountInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/instructions/system_program/create_account_instruction.rb

Constant Summary collapse

INSTRUCTION_INDEX =

!@const INSTRUCTION_INDEX

Instruction index for SystemProgram::CreateAccount
This is the same across all Solana clusters

Returns:

  • (Array<Integer>)
[0, 0, 0, 0].freeze

Class Method Summary collapse

Class Method Details

.build(space:, lamports:, owner: Solace::Constants::SYSTEM_PROGRAM_ID, from_index:, new_account_index:, system_program_index: 2) ⇒ Solace::Instruction

Builds a SystemProgram::CreateAccount instruction

Parameters:

  • space (Integer)

    Number of bytes to allocate for the new account

  • lamports (Integer)

    Amount of lamports to fund the new account

  • owner (String) (defaults to: Solace::Constants::SYSTEM_PROGRAM_ID)

    The program_id of the owner of the new account

  • from_index (Integer)

    Index of the funding account (payer) in the transaction’s accounts

  • new_account_index (Integer)

    Index of the new account to create in the transaction’s accounts

  • system_program_index (Integer) (defaults to: 2)

    Index of the system program in the transaction’s accounts (default: 2)

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/solace/instructions/system_program/create_account_instruction.rb', line 22

def self.build(
  space:,
  lamports:,
  owner: Solace::Constants::SYSTEM_PROGRAM_ID,
  from_index:,
  new_account_index:,
  system_program_index: 2
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = system_program_index
    ix.accounts = [from_index, ]
    ix.data = data(lamports, space, owner)
  end
end

.data(lamports, space, owner) ⇒ Array

Builds the data for a SystemProgram::CreateAccount instruction

The BufferLayout is:

- [Instruction Index (4 bytes)]
- [Lamports (8 bytes)]
- [Space (8 bytes)]
- [Owner (32 bytes)]

Parameters:

  • lamports (Integer)

    Amount of lamports to fund the new account

  • space (Integer)

    Number of bytes to allocate for the new account

  • owner (String)

    The program_id of the owner of the new account

Returns:

  • (Array)

    4-byte instruction index + 8-byte lamports + 8-byte space + 32-byte owner



49
50
51
52
53
54
# File 'lib/solace/instructions/system_program/create_account_instruction.rb', line 49

def self.data(lamports, space, owner)
  INSTRUCTION_INDEX +
    Solace::Utils::Codecs.encode_le_u64(lamports).bytes +
    Solace::Utils::Codecs.encode_le_u64(space).bytes +
    Solace::Utils::Codecs.base58_to_bytes(owner)
end