Class: SolanaRuby::TransactionInstruction
- Inherits:
-
Object
- Object
- SolanaRuby::TransactionInstruction
- Defined in:
- lib/solana_ruby/transaction_instruction.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#program_id ⇒ Object
Returns the value of attribute program_id.
Instance Method Summary collapse
-
#initialize(keys:, program_id:, data:) ⇒ TransactionInstruction
constructor
A new instance of TransactionInstruction.
- #serialize ⇒ Object
Constructor Details
#initialize(keys:, program_id:, data:) ⇒ TransactionInstruction
Returns a new instance of TransactionInstruction.
7 8 9 10 11 |
# File 'lib/solana_ruby/transaction_instruction.rb', line 7 def initialize(keys:, program_id:, data:) @keys = keys # Array of account metadata hashes @program_id = program_id # Program ID in Base58 @data = data # Binary data for the instruction end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/solana_ruby/transaction_instruction.rb', line 5 def data @data end |
#keys ⇒ Object
Returns the value of attribute keys.
5 6 7 |
# File 'lib/solana_ruby/transaction_instruction.rb', line 5 def keys @keys end |
#program_id ⇒ Object
Returns the value of attribute program_id.
5 6 7 |
# File 'lib/solana_ruby/transaction_instruction.rb', line 5 def program_id @program_id end |
Instance Method Details
#serialize ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/solana_ruby/transaction_instruction.rb', line 13 def serialize serialized_instruction = "" # Convert and serialize the program ID from Base58 to binary program_id_binary = Base58.base58_to_binary(@program_id) serialized_instruction << program_id_binary # Serialize the number of keys serialized_instruction << [@keys.length].pack("C") # Serialize each key (pubkey in binary, is_signer, is_writable flags) @keys.each do || # Convert public key to binary and serialize it pubkey_binary = Base58.base58_to_binary([:pubkey]) serialized_instruction << pubkey_binary # Serialize meta flags (is_signer and is_writable) = ([:is_signer] ? 1 : 0) | ([:is_writable] ? 2 : 0) serialized_instruction << [].pack("C") end # Serialize data length (encoded as a single byte, can adjust with C, S, and L accordingly if data is larger) serialized_instruction << [@data.length].pack("C") # Serialize the actual data in binary format serialized_instruction << @data serialized_instruction end |