cdk-rs
cdk-rs copied to clipboard
Multiple arguments passed as a single tuple in canister-to-canister calls
This issue documents one problem that we've observed while developing BigMap with the rust-cdk
.
In that code we wrote, we're making put
update calls from the index
canister to the data bucket
canisters. The put
update call has two arguments fn put (key: Vec<u8>, value: Vec<u8>)
- which is likely the source of problems.
Invoking the put
function from the user works as expected, e.g. with the dfx canister call
command - so all good so far.
However, when the put
function is invoked from the index
canister, argument parsing fails. By trial and error, I have found that when the index
canister invokes data_canister.put(key, value)
, the data canister instead receives the arguments as fn put((key, value))
, i.e., the arguments are not unpacked at the destination canister.
The following work-around works. I've added another method which is invoked from the index canister, and this method receives the argument tuple, unpacks it, and invokes the regular put
function.
#[update]
fn put_from_index(key_value: (Key, Val)) -> bool {
let (key, value) = key_value;
put(key, value)
}
The sample code which demonstrates this is here: https://github.com/dfinity/bigmap-rs/blob/eefec72442898264ce6d7198b041bb9a64b4128c/src/bigmap_data.rs#L72
Is this still an issue with the latest CDK version?
Great question @adamspofford-dfinity -- no idea! :) I haven't worked on Rust BigMap in quite a while and not a lot of other code makes inter-canister calls. Possibly the OpenChat folks do it. But it shouldn't be hard to reproduce with two canisters.