Module: Mpp::Methods::Tempo::Transaction

Defined in:
lib/mpp/methods/tempo/transaction.rb

Defined Under Namespace

Classes: Call, SignedTransaction

Constant Summary collapse

TYPE_ID =
0x76
EMPTY_SIGNATURE =
"\x00".b
EMPTY_LIST =
[].freeze

Class Method Summary collapse

Class Method Details

.build_signed_transfer(account:, chain_id:, gas_limit:, gas_price:, nonce:, nonce_key:, currency:, transfer_data:, valid_before: nil, awaiting_fee_payer: false) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/mpp/methods/tempo/transaction.rb', line 171

def build_signed_transfer(account:, chain_id:, gas_limit:, gas_price:, nonce:, nonce_key:,
  currency:, transfer_data:, valid_before: nil, awaiting_fee_payer: false)
  tx = SignedTransaction.new(
    chain_id: chain_id,
    max_priority_fee_per_gas: gas_price,
    max_fee_per_gas: gas_price,
    gas_limit: gas_limit,
    calls: [Call.new(to: currency, value: 0, data: transfer_data)],
    access_list: EMPTY_LIST,
    nonce_key: nonce_key,
    nonce: nonce,
    valid_before: valid_before,
    valid_after: nil,
    fee_token: awaiting_fee_payer ? nil : currency,
    sender_signature: nil,
    fee_payer_signature: EMPTY_SIGNATURE,
    sender_address: .address,
    tempo_authorization_list: EMPTY_LIST,
    key_authorization: nil
  )

  signature = .sign_hash(tx.signature_hash)
  signed = tx.with(sender_signature: signature)
  raw = awaiting_fee_payer ? FeePayer.encode(signed) : signed.encoded_2718

  ["0x#{raw.unpack1("H*")}", chain_id]
end