Module: Solana::Ruby::Kit::TransactionMessages

Extended by:
T::Sig
Defined in:
lib/solana/ruby/kit/transaction_messages/transaction_message.rb

Defined Under Namespace

Classes: BlockhashLifetimeConstraint, DurableNonceLifetimeConstraint, TransactionMessage

Constant Summary collapse

TransactionVersion =

Supported transaction versions. Mirrors TypeScript’s ‘TransactionVersion = ’legacy’ | 0 | 1`. Version 1 is defined but not yet supported by most tooling.

T.type_alias { T.any(Symbol, Integer) }
LEGACY_VERSION =
T.let(:legacy, Symbol)
V0_VERSION =
T.let(0, Integer)
V1_VERSION =
T.let(1, Integer)
MAX_SUPPORTED_TRANSACTION_VERSION =
T.let(1, Integer)
Lifetime =

Lifetime can be a blockhash constraint, a durable-nonce constraint, or nil.

T.type_alias { T.nilable(T.any(BlockhashLifetimeConstraint, DurableNonceLifetimeConstraint)) }

Class Method Summary collapse

Class Method Details

.append_instructions(message, instructions) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 127

def append_instructions(message, instructions)
  TransactionMessage.new(
    version:               message.version,
    instructions:          message.instructions + instructions,
    fee_payer:             message.fee_payer,
    lifetime_constraint:   message.lifetime_constraint,
    address_table_lookups: message.address_table_lookups
  )
end

.assert_blockhash_lifetime!(message) ⇒ Object



164
165
166
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 164

def assert_blockhash_lifetime!(message)
  Kernel.raise SolanaError.new(:SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME) unless blockhash_lifetime?(message)
end

.blockhash_lifetime?(message) ⇒ Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 152

def blockhash_lifetime?(message)
  message.lifetime_constraint.is_a?(BlockhashLifetimeConstraint)
end

.create_transaction_message(version:) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 65

def create_transaction_message(version:)
  TransactionMessage.new(
    version:               version,
    instructions:          [],
    fee_payer:             nil,
    lifetime_constraint:   nil,
    address_table_lookups: nil
  )
end

.durable_nonce_lifetime?(message) ⇒ Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 158

def durable_nonce_lifetime?(message)
  message.lifetime_constraint.is_a?(DurableNonceLifetimeConstraint)
end

.prepend_instructions(message, instructions) ⇒ Object



140
141
142
143
144
145
146
147
148
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 140

def prepend_instructions(message, instructions)
  TransactionMessage.new(
    version:               message.version,
    instructions:          instructions + message.instructions,
    fee_payer:             message.fee_payer,
    lifetime_constraint:   message.lifetime_constraint,
    address_table_lookups: message.address_table_lookups
  )
end

.set_blockhash_lifetime(constraint, message) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 93

def set_blockhash_lifetime(constraint, message)
  existing = message.lifetime_constraint
  if existing.is_a?(BlockhashLifetimeConstraint) &&
     existing.blockhash == constraint.blockhash &&
     existing.last_valid_block_height == constraint.last_valid_block_height
    return message
  end

  TransactionMessage.new(
    version:               message.version,
    instructions:          message.instructions,
    fee_payer:             message.fee_payer,
    lifetime_constraint:   constraint,
    address_table_lookups: message.address_table_lookups
  )
end

.set_durable_nonce_lifetime(constraint, message) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 113

def set_durable_nonce_lifetime(constraint, message)
  TransactionMessage.new(
    version:               message.version,
    instructions:          message.instructions,
    fee_payer:             message.fee_payer,
    lifetime_constraint:   constraint,
    address_table_lookups: message.address_table_lookups
  )
end

.set_fee_payer(fee_payer, message) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/solana/ruby/kit/transaction_messages/transaction_message.rb', line 78

def set_fee_payer(fee_payer, message)
  return message if message.fee_payer == fee_payer

  TransactionMessage.new(
    version:               message.version,
    instructions:          message.instructions,
    fee_payer:             fee_payer,
    lifetime_constraint:   message.lifetime_constraint,
    address_table_lookups: message.address_table_lookups
  )
end