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

Support for typed return values and output with custom types #24

Merged
merged 1 commit into from
Dec 23, 2021

Conversation

digorithm
Copy link
Member

This PR introduces decoded and type-safe output for contract calls.

It also adds support for structs as return values for contract calls.

Before this, contract calls through the SDK would just return a u64.

Now, we're fully leveraging the Tokenizable and Detokenize traits
that were designed earlier to decode the return values coming from
contract calls. For instance:

let response: bool = contract_instance.is_even(10).call().await.unwrap();

let my_struct = MyStruct { foo: 10, bar: true };
let response: MyStruct = contract_instance
                            .return_my_struct(my_struct)
                            .call()
                            .await
                            .unwrap();

It also adds support for structs as return values for contract calls.

Before this, contract calls through the SDK would just return a `u64`.

Now, we're fully leveraging the `Tokenizable` and `Detokenize` traits
that were designed earlier to decode the return values coming from
contract calls. For instance:

```Rust
let response: bool = contract_instance.is_even(10).call().await.unwrap();

let my_struct = MyStruct { foo: 10, bar: true };
let response: MyStruct = contract_instance
                            .return_my_struct(my_struct)
                            .call()
                            .await
                            .unwrap();
```
@digorithm digorithm marked this pull request as ready for review December 23, 2021 20:01
@digorithm digorithm merged commit 326984f into master Dec 23, 2021
@digorithm digorithm deleted the rodrigo/custom-output branch December 23, 2021 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants