write static method
Writes an OZSmartAccountAuthPayload to its XdrSCVal representation.
Builds the outer map with exactly two entries in alphabetical
insertion order (context_rule_ids, then signers), matching the
Soroban Rust #[contracttype] derive ordering for the contract's
AuthPayload struct. Inner signer entries are sorted in the Soroban
host's ScMap key order (semantic content order), matching how the
contract materializes the signers map.
Implementation
static XdrSCVal write(OZSmartAccountAuthPayload payload) {
// Build signer map entries, wrapping each raw signature byte array in
// an XdrSCVal.forBytes value.
final signerEntries = <XdrSCMapEntry>[];
for (final entry in payload.signers.entries) {
signerEntries.add(
XdrSCMapEntry(
entry.key.toScVal(),
XdrSCVal.forBytes(entry.value),
),
);
}
// Sort signer entries in the Soroban host's ScMap key order (semantic
// content order, not the length-major XDR-byte order), matching how the
// contract materializes the signers map.
signerEntries.sort((a, b) => compareScValHostOrder(a.key, b.key));
final signersMapScVal = XdrSCVal.forMap(signerEntries);
final ruleIdsVec = payload.contextRuleIds
.map((id) => XdrSCVal.forU32(id))
.toList(growable: false);
final contextRuleIdsScVal = XdrSCVal.forVec(ruleIdsVec);
// Outer struct map keys insert in alphabetical order to match the
// Soroban Rust `#[contracttype]` derive convention. Inner dynamic-map
// keys are sorted above into the host's ScMap key order.
return XdrSCVal.forMap([
XdrSCMapEntry(
XdrSCVal.forSymbol('context_rule_ids'),
contextRuleIdsScVal,
),
XdrSCMapEntry(
XdrSCVal.forSymbol('signers'),
signersMapScVal,
),
]);
}