Class: Solace::Instructions::SplToken::TransferInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/instructions/spl_token/transfer_instruction.rb

Overview

A class to build the Transfer instruction for the SPL Token Program.

Constant Summary collapse

INSTRUCTION_INDEX =
[3].freeze

Class Method Summary collapse

Class Method Details

.build(amount:, owner_index:, source_index:, destination_index:, program_index:) ⇒ Solace::Instruction

Builds a Transfer instruction.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/solace/instructions/spl_token/transfer_instruction.rb', line 20

def self.build(
  amount:,
  owner_index:,
  source_index:,
  destination_index:,
  program_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts = [source_index, destination_index, owner_index]
    ix.data = data(amount)
  end
end

.data(amount) ⇒ Array<Integer>

Builds the data for a Transfer instruction.

The BufferLayout is:

- [Instruction Index (1 byte)]
- [Amount (8 bytes)]


42
43
44
# File 'lib/solace/instructions/spl_token/transfer_instruction.rb', line 42

def self.data(amount)
  INSTRUCTION_INDEX + Solace::Utils::Codecs.encode_le_u64(amount).bytes
end