Class: Solace::Transaction
- Inherits:
-
Object
- Object
- Solace::Transaction
- Includes:
- Concerns::BinarySerializable
- Defined in:
- lib/solace/transaction.rb
Overview
Class representing a Solana transaction
Transactions are the basic building blocks of Solana. They contain a message and an array of signatures. The message contains the instructions to be executed and the accounts that are used by the instructions. The signatures are the required signatures of the accounts that are used by the instructions. This class provides methods for signing, serializing, and deserializing transactions.
The BufferLayout is:
- Signatures (variable length)
- Version (1 byte if versioned)
- Message header (3 bytes)
- Account keys (variable length)
- Recent blockhash (32 bytes)
- Instructions (variable length)
- Address lookup table (variable length if versioned)
Constant Summary collapse
- SERIALIZER =
The serializer for the transaction
Solace::Serializers::TransactionSerializer
- DESERIALIZER =
The deserializer for the transaction
Solace::Serializers::TransactionDeserializer
- SIGNATURE_PLACEHOLDER =
Placeholder for a signature in the transaction
Solace::Utils::Codecs.base58_to_binary('1' * 64)
Instance Attribute Summary collapse
-
#message ⇒ Solace::Message
Message of the transaction.
-
#signatures ⇒ Array<String>
Signatures of the transaction (binary).
Class Method Summary collapse
-
.from(base64_tx) ⇒ Transaction
Deserialize a base64 encoded transaction into a Solace::Transaction object.
Instance Method Summary collapse
-
#initialize(signatures: [], message: Solace::Message.new) ⇒ Transaction
constructor
Initialize a new transaction.
-
#sign(*keypairs) ⇒ Array<String>
Sign the transaction.
-
#signature ⇒ String?
Returns the first signature of the transaction (signature of the transaction fee payer).
Methods included from Concerns::BinarySerializable
included, #serialize, #to_binary, #to_bytes, #to_io
Constructor Details
#initialize(signatures: [], message: Solace::Message.new) ⇒ Transaction
Initialize a new transaction
63 64 65 66 67 68 69 70 |
# File 'lib/solace/transaction.rb', line 63 def initialize( signatures: [], message: Solace::Message.new ) super() @signatures = signatures @message = end |
Instance Attribute Details
#message ⇒ Solace::Message
Returns Message of the transaction.
48 49 50 |
# File 'lib/solace/transaction.rb', line 48 def @message end |
#signatures ⇒ Array<String>
Returns Signatures of the transaction (binary).
45 46 47 |
# File 'lib/solace/transaction.rb', line 45 def signatures @signatures end |
Class Method Details
.from(base64_tx) ⇒ Transaction
Deserialize a base64 encoded transaction into a Solace::Transaction object
55 56 57 |
# File 'lib/solace/transaction.rb', line 55 def from(base64_tx) DESERIALIZER.new(Solace::Utils::Codecs.base64_to_bytestream(base64_tx)).call end |
Instance Method Details
#sign(*keypairs) ⇒ Array<String>
Sign the transaction
Calls sign_and_update_signatures for each keypair passed in.
86 87 88 |
# File 'lib/solace/transaction.rb', line 86 def sign(*keypairs) keypairs.map { |keypair| sign_and_update_signatures(keypair) } end |
#signature ⇒ String?
Returns the first signature of the transaction (signature of the transaction fee payer)
76 77 78 |
# File 'lib/solace/transaction.rb', line 76 def signature Utils::Codecs.binary_to_base58(signatures.first) unless signatures.empty? end |