Skip to content
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

Helper function to parse the return value #208

Open
DOBEN opened this issue Sep 4, 2024 · 0 comments
Open

Helper function to parse the return value #208

DOBEN opened this issue Sep 4, 2024 · 0 comments
Labels
good first issue Good for newcomers [Type] Task An additional feature or improvement.

Comments

@DOBEN
Copy link
Member

DOBEN commented 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 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();
@DOBEN DOBEN added the [Type] Task An additional feature or improvement. label Sep 4, 2024
@DOBEN 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
@limemloh limemloh added the good first issue Good for newcomers label Sep 5, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers [Type] Task An additional feature or improvement.
Projects
None yet
Development

No branches or pull requests

2 participants