soroban-cli
soroban-cli copied to clipboard
CLI parsing error for a relatively basic custom `Vec` type
Given this function interface:
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MinerColorAmount(
pub Address,
pub u32,
pub u32,
);
pub fn colors_transfer(env: &Env, from: Address, to: Address, colors: Vec<MinerColorAmount>)
You would think, and the correct CLI invocation is:
soroban contract invoke --id $contract_id --source $user1_sk --network Futurenet -- colors_transfer --from $user1_pk --to $user2_pk --colors '[["'$user1_pk'", 0, 1]]'
(focus primarily on the --colors
)
However the -h
help flag says it's looking for:
$ soroban contract invoke --id 069023b865700a7aa0b4092f375129acdb396f276a615ff0625985dff314a2c6 -- colors_transfer -h
...
--colors <Array<{ 0: Address, 1: u32, 2: u32 }>>
Example:
--colors '[ { "0": "GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4", "1": 1, "2": 1 } ]'
...
Using an indexed object here vs an array won't work and will throw when submitting. Seems that there is some type mismatching going on which I also believe is affecting the typescript binding which currently is generating a broken method for this function.
What's the error when using the help's suggestion?
@willemneal
$ soroban contract invoke --id 069023b865700a7aa0b4092f375129acdb396f276a615ff0625985dff314a2c6 --source SBQOVS7GB4XL3XDFS5IB6OJDQBJ46U3JBX4XU36OUTGOFNMMKJ3SXQPW -- colors_transfer --to GC5HBZMF4QX475QYOJ7XB5VZZZH3DP6N6X2ENJBD7OY7VTZ265YLHAZR --from GCV7OMN4YBEP7RQTKZNE5UP22QKGFXUYMJMSNY564CKODR3HGLY5KJXE --colors '[ { "0": "GC5HBZMF4QX475QYOJ7XB5VZZZH3DP6N6X2ENJBD7OY7VTZ265YLHAZR", "1": 0, "2": 1 } ]'
error: transaction simulation failed: HostError
Value: Status(VmError(TrapUnreachable))
Debug events (newest first):
0: "Debug TrapUnreachable"
Backtrace (newest first):
0: soroban_env_host::host::err_helper::<impl soroban_env_host::host::Host>::err
1: soroban_env_host::host::Host::with_frame
2: soroban_env_host::host::Host::call_n_internal
3: soroban_env_host::host::Host::invoke_functions
4: preflight::preflight_invoke_hf_op_or_maybe_panic
5: preflight_invoke_hf_op
6: _cgo_d46d261efae2_Cfunc_preflight_invoke_hf_op
at /tmp/go-build/cgo-gcc-prolog:79:11
7: runtime.asmcgocall
at ./runtime/asm_amd64.s:848
The example usage has string keys. Does that work for you?
...I used string keys. Or am I not understanding what you're asking?
This works
--colors '[["GC5HBZMF4QX475QYOJ7XB5VZZZH3DP6N6X2ENJBD7OY7VTZ265YLHAZR", 0, 1]]'
This doesn't
--colors '[ { "0": "GC5HBZMF4QX475QYOJ7XB5VZZZH3DP6N6X2ENJBD7OY7VTZ265YLHAZR", "1": 0, "2": 1 } ]'
-h
is suggesting what doesn't work.
fwiw this also carries over to the typescript bindings where:
async function colors_transfer() {
let res = await ColorglyphSDK.colors_transfer({
from: ME,
to: THEM,
colors: [{0: ME, 1: 0, 2: 1}, {0: ME, 1: 16777215, 2: 1}],
}, {signAndSend: true, fee: 1_000_000})
console.log(res);
}
is what's expected but results in error
Error: preflight simulation results do not contain same count of HostFunctions that InvokeHostFunctionOp in the transaction has.
because this:
async function colors_transfer() {
let res = await ColorglyphSDK.colors_transfer({
from: ME,
to: THEM,
colors: [[ME, 0, 1], [ME, 16777215, 1]]
}, {signAndSend: true, fee: 1_000_000})
console.log(res);
}
is what works (but the typescript binding won't accept as it's expecting a Map not a Vec)
Here's the XDR from the Map (broken) version
AAAAAgAAAACaOa49v1utcAcVhF4gSuFrF4yePG1PeQt6B767/Nr7MQAPQkAACU57AAAAEwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAAAAEAAAAAAAAABQAAAA0AAAAgBpAjuGVwCnqgtAkvN1EprNs5bydqYV/wYlmF3/MUosYAAAAPAAAAD2NvbG9yc190cmFuc2ZlcgAAAAATAAAAAAAAAACaOa49v1utcAcVhF4gSuFrF4yePG1PeQt6B767/Nr7MQAAABMAAAAAAAAAACVPkyOPAT7L8Hr9byV0nh/8Wb1lf0IR9VNF4Qro/4w6AAAAEAAAAAEAAAACAAAAEQAAAAEAAAADAAAADwAAAAEwAAAAAAAAEwAAAAAAAAAAmjmuPb9brXAHFYReIErhaxeMnjxtT3kLege+u/za+zEAAAAPAAAAATEAAAAAAAADAAAAAAAAAA8AAAABMgAAAAAAAAMAAAABAAAAEQAAAAEAAAADAAAADwAAAAEwAAAAAAAAEwAAAAAAAAAAmjmuPb9brXAHFYReIErhaxeMnjxtT3kLege+u/za+zEAAAAPAAAAATEAAAAAAAADAP///wAAAA8AAAABMgAAAAAAAAMAAAABAAAAAAAAAAAAAAAA
Here's the XDR from the Vec (working)
AAAAAgAAAACaOa49v1utcAcVhF4gSuFrF4yePG1PeQt6B767/Nr7MQAPQkAACU57AAAAEwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAAAAEAAAAAAAAABQAAAA0AAAAgBpAjuGVwCnqgtAkvN1EprNs5bydqYV/wYlmF3/MUosYAAAAPAAAAD2NvbG9yc190cmFuc2ZlcgAAAAATAAAAAAAAAACaOa49v1utcAcVhF4gSuFrF4yePG1PeQt6B767/Nr7MQAAABMAAAAAAAAAACVPkyOPAT7L8Hr9byV0nh/8Wb1lf0IR9VNF4Qro/4w6AAAAEAAAAAEAAAACAAAAEAAAAAEAAAADAAAAEwAAAAAAAAAAmjmuPb9brXAHFYReIErhaxeMnjxtT3kLege+u/za+zEAAAADAAAAAAAAAAMAAAABAAAAEAAAAAEAAAADAAAAEwAAAAAAAAAAmjmuPb9brXAHFYReIErhaxeMnjxtT3kLege+u/za+zEAAAADAP///wAAAAMAAAABAAAAAAAAAAAAAAAA
(notice one has key names and the other doesn't) Obvious and clear what the issue is now I hope. Named struct values vs unnamed struct values.
Fixed the bad example input here https://github.com/stellar/soroban-tools/pull/731/
Next on to the bindings generation.
Bindings generation is now working!
What remaining work needs to be done here?