compareScValHostOrder

Orders two SCValXdr values the way the Soroban host does.

The host rejects an SCV_MAP contract argument with InvalidInput unless its keys are strictly ascending in this order; Scv.toMap sorts map entries with it. Variable-length values compare by content because their XDR encoding starts with the length.

Ordering:

  • Values of different types compare by their SCValType discriminant.

  • I32, I64, I128, I256 and LedgerKeyNonce compare numerically as signed integers.

  • Bytes, String, Symbol and ExecutableTag compare by content, byte for byte (unsigned); the shorter value sorts first on a common prefix.

  • Vec compares element-wise and Map entry-wise (key, then value), recursively; the shorter one sorts first on a common prefix. A null backing list counts as empty.

  • ContractInstance compares by executable (type, then payload, with an external-ref tag compared by content), then by storage: absent storage first, then entry-wise as a Map.

  • The remaining types (Bool, Void, Error, U32, U64, Timepoint, Duration, U128, U256, Address, LedgerKeyContractInstance) have a fixed width within each union arm and encode only unsigned or non-negative fields, so their XDR encoding compares in host order.

Return

a negative number, zero, or a positive number as a sorts before, equal to, or after b