Class: Solace::Transaction

Inherits:
Object
  • Object
show all
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)]
- [ keys (variable length)]
- [Recent blockhash (32 bytes)]
- [Instructions (variable length)]
- [Address lookup table (variable length)] (if versioned)

Examples:

# Create a new transaction
tx = Solace::Transaction.new

# Add a message to the transaction
tx.message = Solace::Message.new(**message_params)

# Sign the transaction
tx.sign(payer_keypair)

Since:

  • 0.0.1

Constant Summary collapse

SERIALIZER =

Since:

  • 0.0.1

Solace::Serializers::TransactionSerializer
DESERIALIZER =

Since:

  • 0.0.1

Solace::Serializers::TransactionDeserializer
SIGNATURE_PLACEHOLDER =

Since:

  • 0.0.1

Solace::Utils::Codecs.base58_to_binary('1' * 64)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Since:

  • 0.0.1



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
  @message = message
end

Instance Attribute Details

#DESERIALIZERSolace::Serializers::TransactionDeserializer

Returns The deserializer for the transaction.

Returns:



41
# File 'lib/solace/transaction.rb', line 41

DESERIALIZER = Solace::Serializers::TransactionDeserializer

#messageSolace::Message

Returns Message of the transaction.

Returns:



53
54
55
# File 'lib/solace/transaction.rb', line 53

def message
  @message
end

#SERIALIZERSolace::Serializers::TransactionSerializer

Returns The serializer for the transaction.

Returns:



37
# File 'lib/solace/transaction.rb', line 37

SERIALIZER = Solace::Serializers::TransactionSerializer

#SIGNATURE_PLACEHOLDERString

Returns Placeholder for a signature in the transaction.

Returns:

  • (String)

    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)

#signaturesArray<String>

Returns Signatures of the transaction (binary).

Returns:

  • (Array<String>)

    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

Parameters:

  • base64_tx (String)

    The base64 encoded transaction

Returns:

Since:

  • 0.0.1



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.

Parameters:

  • keypairs (Array<Solace::Keypair>)

    The keypairs to sign the transaction with

Returns:

  • (Array<String>)

    The signatures of the transaction

Since:

  • 0.0.1



83
84
85
# File 'lib/solace/transaction.rb', line 83

def sign(*keypairs)
  keypairs.map { |keypair| sign_and_update_signatures(keypair) }
end