compare Sc Val Host Order
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
SCValTypediscriminant.I32,I64,I128,I256andLedgerKeyNoncecompare numerically as signed integers.Bytes,String,SymbolandExecutableTagcompare by content, byte for byte (unsigned); the shorter value sorts first on a common prefix.Veccompares element-wise andMapentry-wise (key, then value), recursively; the shorter one sorts first on a common prefix. A null backing list counts as empty.ContractInstancecompares by executable (type, then payload, with an external-ref tag compared by content), then by storage: absent storage first, then entry-wise as aMap.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