You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A similar helper function would be useful in the SDK. Implementation the Read trait on the ReturnValue type could potentially already achieve a basic, yet rather difficult-to-discover way of parsing the bytes (https://doc.rust-lang.org/nightly/std/io/trait.Read.html).
A parse() or try_into() function (easier to discover) can then make use of the Read trait.
let return_value = invoke( .... );
let custom_type:CustomType = return_value.parse().unwrap();
or
let return_value = invoke( .... );
let custom_type:CustomType = return_value.try_into().unwrap();
The text was updated successfully, but these errors were encountered:
DOBEN
changed the title
Helper function to parse the return value from a smart contract invoke into a given Rust type
Helper function to parse the return value
Sep 4, 2024
Invoking a smart contract via the Rust SDK returns the raw bytes. Developers need to handle the conversion from bytes to the desired Rust type for now.
https://github.com/Concordium/concordium-rust-sdk/blob/main/src/types/smart_contracts.rs#L234
In the testing library, we provide a helper function to deserialize the return value into a given Rust type.
https://github.com/Concordium/concordium-rust-smart-contracts/blob/main/contract-testing/src/types.rs#L651
A similar helper function would be useful in the SDK. Implementation the
Read
trait on theReturnValue
type could potentially already achieve a basic, yet rather difficult-to-discover way of parsing the bytes (https://doc.rust-lang.org/nightly/std/io/trait.Read.html).A
parse()
ortry_into()
function (easier to discover) can then make use of theRead
trait.or
The text was updated successfully, but these errors were encountered: