Class: Solace::TransactionComposer
- Inherits:
-
Object
- Object
- Solace::TransactionComposer
- Defined in:
- lib/solace/transaction_composer.rb
Overview
Composes multi-instruction transactions with automatic account management
Instance Attribute Summary collapse
-
#connection ⇒ Solace::Connection
The connection to the Solana cluster.
-
#context ⇒ Utils::AccountContext
The account registry.
-
#instruction_composers ⇒ Array<Composers::Base>
The instruction composers.
Instance Method Summary collapse
-
#add_instruction(composer) ⇒ TransactionComposer
Add an instruction composer to the transaction.
-
#compose_transaction ⇒ Solace::Transaction
Compose the final transaction.
-
#initialize(connection:) ⇒ TransactionComposer
constructor
Initialize the composer.
-
#set_fee_payer(pubkey) ⇒ TransactionComposer
Set the fee payer for the transaction.
Constructor Details
#initialize(connection:) ⇒ TransactionComposer
Initialize the composer
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
#connection ⇒ Solace::Connection
Returns The connection to the Solana cluster.
9 10 11 |
# File 'lib/solace/transaction_composer.rb', line 9 def connection @connection end |
#context ⇒ Utils::AccountContext
Returns The account registry.
14 15 16 |
# File 'lib/solace/transaction_composer.rb', line 14 def context @context end |
#instruction_composers ⇒ Array<Composers::Base>
Returns The instruction composers.
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
34 35 36 37 38 |
# File 'lib/solace/transaction_composer.rb', line 34 def add_instruction(composer) merge_accounts(composer.account_context) instruction_composers << composer self end |
#compose_transaction ⇒ Solace::Transaction
Compose the final transaction
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 = Solace::Message.new( header: context.header, accounts: context.accounts, instructions: build_instructions, recent_blockhash: connection.get_latest_blockhash, ) Solace::Transaction.new(message: ) end |
#set_fee_payer(pubkey) ⇒ TransactionComposer
Set the fee payer for the transaction
44 45 46 47 |
# File 'lib/solace/transaction_composer.rb', line 44 def set_fee_payer(pubkey) context.set_fee_payer(pubkey) self end |