Module encoding

Module encoding 

Source
Expand description

Fuel ABI encoding primitives for O2 Exchange.

Implements the exact byte layouts from the O2 integration guide:

  • u64 big-endian encoding
  • Function selectors (NOT hash-based: u64(len) + utf8(name))
  • Identity encoding (discriminant + 32-byte address)
  • Option encoding (None = u64(0), Some = u64(1) + data)
  • OrderArgs struct encoding (tightly packed enum variants)
  • Session signing bytes
  • Action signing bytes

Structs§

CallArg
A low-level contract call used in action signing.

Enums§

OrderTypeEncoding
Order type variants for encoding.

Constants§

GAS_MAX
Gas value: always u64::MAX. The API overrides with its own value.

Functions§

action_to_call
Convert a high-level Action to a low-level CallArg and JSON representation.
build_actions_signing_bytes
Build the signing bytes for session actions (Section 4.7 Step 2).
build_session_signing_bytes
Build the signing bytes for set_session (Section 4.6 Step 3).
build_withdraw_signing_bytes
Build the signing bytes for a withdrawal.
cancel_order_to_call
Convert a CancelOrder action to a low-level CallArg.
create_order_to_call
Convert a high-level CreateOrder action to a low-level CallArg.
encode_identity
Encode a Fuel Identity enum: u64(discriminant) + 32-byte address. discriminant: 0 = Address, 1 = ContractId
encode_option_call_data
Encode Option for call_data in action signing bytes. None -> u64(0) Some -> u64(1) + u64(len(data)) + data
encode_option_none
Encode Option::None: u64(0).
encode_option_some
Encode Option::Some(data): u64(1) + data.
encode_order_args
Encode OrderArgs struct for CreateOrder call_data. Layout: u64(price) + u64(quantity) + order_type_encoding (tightly packed)
function_selector
Encode a Fuel ABI function selector: u64_be(len(name)) + utf8(name). These are NOT hash-based like Solidity selectors.
register_referer_to_call
Convert a RegisterReferer action to a low-level CallArg.
settle_balance_to_call
Convert a SettleBalance action to a low-level CallArg. to is the destination identity (discriminant, address).
u64_be
Encode a u64 value as 8 bytes big-endian.