-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort entries in StellarSDK.xdr.ScVal.scvMap(...) #1131
Comments
This is generated code and so we can't exactly control how "helpful" its behavior is. If you're coding at this level, unfortunately you've just gotta know exactly what you're doing. Per your link, this code: const milestonesScVal = milestones.map(milestone => {
return StellarSDK.xdr.ScVal.scvMap([[
new StellarSDK.xdr.ScMapEntry({
key: StellarSDK.xdr.ScVal.scvSymbol(“description”),
val: StellarSDK.xdr.ScVal.scvString(milestone.description)
}),
new StellarSDK.xdr.ScMapEntry({
key: StellarSDK.xdr.ScVal.scvSymbol(“status”),
val: StellarSDK.xdr.ScVal.scvString(milestone.status)
}),
new StellarSDK.xdr.ScMapEntry({
key: StellarSDK.xdr.ScVal.scvSymbol(“flag”),
val: StellarSDK.xdr.ScVal.scvBool(false)
})
]);
}); Could instead be written as const milestonesScVal = milestones.map(milestone => {
return nativeToScVal({
description: milestone.description,
status: milestone.status,
flag: false
}, {
type: {
description: [ "symbol", "string" ],
status: [ "symbol", "string" ],
flag: [ "symbol" ]
}
})
}); And the map keys will be sorted correctly. We built helpers for a reason :D |
Someone might want to build with the xdr types though, as we saw reported in Discord, which is reasonable. Could we add |
Not there because the I'd again argue that if they are digging so deep into the codebase that they're building structures from scratch, they should understand the ordering requirement. Especially since maps aren't strongly typed, so there are plenty of non-trivial sorting cases that an algorithm can't resolve. Or just... use the helpers 😆 Anyway, I added best-effort sorting in stellar/js-stellar-base#787. |
According to this report:
https://discord.com/channels/897514728459468821/1183574303921418250/1321262080061476935
the
StellarSDK.xdr.ScVal.scvMap(...)
function currently does not sort the entries in the map.The network requires them to be sorted, and as @Shaptic pointed out there are some functions that do sort the entries appropriately, but not this one it seems.
The text was updated successfully, but these errors were encountered: