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 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 =
Solace::Serializers::TransactionSerializer
- DESERIALIZER =
Solace::Serializers::TransactionDeserializer
- SIGNATURE_PLACEHOLDER =
Solace::Utils::Codecs.base58_to_binary('1' * 64)
Instance Attribute Summary collapse
-
#DESERIALIZER ⇒ Solace::Serializers::TransactionDeserializer
The deserializer for the transaction.
-
#message ⇒ Solace::Message
Message of the transaction.
-
#SERIALIZER ⇒ Solace::Serializers::TransactionSerializer
The serializer for the transaction.
-
#SIGNATURE_PLACEHOLDER ⇒ String
Placeholder for a signature in the transaction.
-
#signatures ⇒ Array<String>
Signatures of the transaction (binary).
Class Method Summary collapse
-
.from(base64_tx) ⇒ Solace::Transaction
Deserialize a base64 encoded transaction into a Solace::Transaction object.
Instance Method Summary collapse
-
#initialize(signatures: [], message: Solace::Message.new) ⇒ Solace::Transaction
constructor
Initialize a new transaction.
-
#sign(*keypairs) ⇒ Array<String>
Sign the transaction.
Methods included from Concerns::BinarySerializable
included, #serialize, #to_binary, #to_bytes, #to_io
Constructor Details
#initialize(signatures: [], message: Solace::Message.new) ⇒ Solace::Transaction
Initialize a new transaction
68 69 70 71 72 73 74 75 |
# File 'lib/solace/transaction.rb', line 68 def initialize( signatures: [], message: Solace::Message.new ) super() @signatures = signatures = end |
Instance Attribute Details
#DESERIALIZER ⇒ Solace::Serializers::TransactionDeserializer
Returns The deserializer for the transaction.
41 |
# File 'lib/solace/transaction.rb', line 41 DESERIALIZER = Solace::Serializers::TransactionDeserializer |
#message ⇒ Solace::Message
Returns Message of the transaction.
53 54 55 |
# File 'lib/solace/transaction.rb', line 53 def end |
#SERIALIZER ⇒ Solace::Serializers::TransactionSerializer
Returns The serializer for the transaction.
37 |
# File 'lib/solace/transaction.rb', line 37 SERIALIZER = Solace::Serializers::TransactionSerializer |
#SIGNATURE_PLACEHOLDER ⇒ String
Returns Placeholder for a signature in the transaction.
45 |
# File 'lib/solace/transaction.rb', line 45 SIGNATURE_PLACEHOLDER = Solace::Utils::Codecs.base58_to_binary('1' * 64) |
#signatures ⇒ Array<String>
Returns Signatures of the transaction (binary).
49 50 51 |
# File 'lib/solace/transaction.rb', line 49 def signatures @signatures end |
Class Method Details
.from(base64_tx) ⇒ Solace::Transaction
Deserialize a base64 encoded transaction into a Solace::Transaction object
60 61 62 |
# File 'lib/solace/transaction.rb', line 60 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.
83 84 85 |
# File 'lib/solace/transaction.rb', line 83 def sign(*keypairs) keypairs.map { |keypair| sign_and_update_signatures(keypair) } end |