Class: Solace::TransactionComposer

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/transaction_composer.rb

Overview

Composes multi-instruction transactions with automatic account management

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:) ⇒ TransactionComposer

Initialize the composer

Parameters:



24
25
26
27
28
# File 'lib/solace/transaction_composer.rb', line 24

def initialize(connection:)
  @connection = connection
  @instruction_composers = []
  @context = Utils::AccountContext.new
end

Instance Attribute Details

#connectionSolace::Connection

Returns The connection to the Solana cluster.

Returns:



9
10
11
# File 'lib/solace/transaction_composer.rb', line 9

def connection
  @connection
end

#contextUtils::AccountContext

Returns The account registry.

Returns:



14
15
16
# File 'lib/solace/transaction_composer.rb', line 14

def context
  @context
end

#instruction_composersArray<Composers::Base>

Returns The instruction composers.

Returns:



19
20
21
# File 'lib/solace/transaction_composer.rb', line 19

def instruction_composers
  @instruction_composers
end

Instance Method Details

#add_instruction(composer) ⇒ TransactionComposer

Add an instruction composer to the transaction

Parameters:

Returns:



34
35
36
37
38
# File 'lib/solace/transaction_composer.rb', line 34

def add_instruction(composer)
  merge_accounts(composer.)
  instruction_composers << composer
  self
end

#compose_transactionSolace::Transaction

Compose the final transaction

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/solace/transaction_composer.rb', line 52

def compose_transaction
  context.compile

  message = Solace::Message.new(
    header: context.header,
    accounts: context.accounts,
    instructions: build_instructions,
    recent_blockhash: connection.get_latest_blockhash,
  )
  
  Solace::Transaction.new(message: message)
end

#set_fee_payer(pubkey) ⇒ TransactionComposer

Set the fee payer for the transaction

Parameters:

Returns:



44
45
46
47
# File 'lib/solace/transaction_composer.rb', line 44

def set_fee_payer(pubkey)
  context.set_fee_payer(pubkey)
  self
end