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



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/mpp/methods/tempo/transaction.rb', line 114

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