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
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
58 59 60 61 62 |
# File 'lib/solace/transaction_composer.rb', line 58 def initialize(connection:) @connection = connection @instruction_composers = [] @context = Utils::AccountContext.new end |
Instance Attribute Details
#connection ⇒ Object
45 46 47 |
# File 'lib/solace/transaction_composer.rb', line 45 def connection @connection end |
#context ⇒ Object
49 50 51 |
# File 'lib/solace/transaction_composer.rb', line 49 def context @context end |
#instruction_composers ⇒ Object
53 54 55 |
# File 'lib/solace/transaction_composer.rb', line 53 def instruction_composers @instruction_composers end |
Instance Method Details
#add_instruction(composer) ⇒ TransactionComposer
Add an instruction composer to the transaction
68 69 70 71 72 |
# File 'lib/solace/transaction_composer.rb', line 68 def add_instruction(composer) merge_accounts(composer.account_context) instruction_composers << composer self end |
#compose_transaction ⇒ Solace::Transaction
Compose the final transaction
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/solace/transaction_composer.rb', line 86 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
78 79 80 81 |
# File 'lib/solace/transaction_composer.rb', line 78 def set_fee_payer(pubkey) context.set_fee_payer(pubkey) self end |