js-soroban-client icon indicating copy to clipboard operation
js-soroban-client copied to clipboard

Map keys should be sorted alphabetically as Rust expects

Open kalepail opened this issue 2 years ago • 3 comments

When an argument is or contains a Map Rust expects the keys to be alphabetically ordered but JS doesn't enforce that. This will cause unclear errors right now. Soroban client likely should perform a key sort behind the scenes in order to avoid this issue.

kalepail avatar Sep 12 '23 15:09 kalepail

@willemneal is this something you can incorporate (or needs to be incorporated?) into ContractSpec? I can look into doing this in parallel for nativeToScVal.

Shaptic avatar Oct 27 '23 17:10 Shaptic

Good question, I need to look at how the ContractSpec handle's maps, but I think it should be done there.

willemneal avatar Oct 27 '23 17:10 willemneal

I'm not sure this is the responsibility of the contract spec.

The contract spec doesn't have an opinion on how the Map val is ordered. It presents the fields in the order of code such that they can be regenerated in the same order.

Also, Maps are used irrespective of a contract type, and so the JS lib and every SDK needs to be able to support sorting a maps entries so they're valid. Map keys may be numbers, symbols, strings, bytes, anything really. ~This is going to be pretty challenging.~

leighmcculloch avatar Nov 08 '23 20:11 leighmcculloch