Class: Solace::Serializers::TransactionSerializer

Inherits:
BaseSerializer show all
Defined in:
lib/solace/serializers/transaction_serializer.rb

Overview

Serializes a Solana transaction to a binary format.

Since:

  • 0.0.1

Constant Summary collapse

SIGNATURE_PLACEHOLDER =

Since:

  • 0.0.1

([0] * 64).pack('C*')

Instance Attribute Summary collapse

Attributes inherited from BaseSerializer

#record

Instance Method Summary collapse

Methods inherited from BaseSerializer

#call, #initialize

Constructor Details

This class inherits a constructor from Solace::Serializers::BaseSerializer

Instance Attribute Details

#SIGNATURE_PLACEHOLDERString

Returns Placeholder for a signature in the transaction.

Returns:

  • (String)

    Placeholder for a signature in the transaction



11
# File 'lib/solace/serializers/transaction_serializer.rb', line 11

SIGNATURE_PLACEHOLDER = ([0] * 64).pack('C*')

Instance Method Details

#encode_messageArray<Integer>

Encodes the message from the transaction

Returns:

  • (Array<Integer>)

    The bytes of the encoded message

Since:

  • 0.0.1



40
41
42
# File 'lib/solace/serializers/transaction_serializer.rb', line 40

def encode_message
  record.message.to_bytes
end

#encode_signaturesArray<Integer>

Encodes the signatures of the transaction

Iterates over the number sum number of signatures and either encodes or sets the placeholder for each expected index in the signatures array.

The BufferLayout is:

- [Number of signatures (compact u16)]
- [Signatures (variable length)]

Returns:

  • (Array<Integer>)

    The bytes of the encoded signatures

Since:

  • 0.0.1



32
33
34
35
# File 'lib/solace/serializers/transaction_serializer.rb', line 32

def encode_signatures
  Codecs.encode_compact_u16(record.message.num_required_signatures).bytes +
    index_signatures(record.message.num_required_signatures)
end