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

Experiment to improve E2E call builder API #1669

Closed
wants to merge 4 commits into from

Conversation

ascjones
Copy link
Collaborator

@ascjones ascjones commented Feb 21, 2023

Playing around to see how we can simply remove the existing ugly callback API for building message calls. The requirements are:

  1. Absolutely changes and no breaking changes to the ink call builder codegen.
  2. Nice and clean API.

With this idea I have converted erc20 to the new syntax which removes the unergonomic callback. Thus we can now use call on the type returned from instantiate:

// instantiate
let mut erc20 = client
    .instantiate::<Erc20, _, _>(
        "erc20",
        &ink_e2e::bob(),
        constructor,
        0,
        None,
    )
    .await
    .expect("instantiate failed");

// build the call (no longer requires callback)
let transfer_from = erc20.call().transfer_from(
    bob_account.clone(),
    charlie_account.clone(),
    500_000_000u128,
);

/// invoke the call
client
  .call(&ink_e2e::charlie(), &transfer_from, 0, None)
  .await

To test this run e2e tests on the erc20 example.

Things to see whether we improve

  • remove requirement for explicit type hint on instantiate, see .instantiate::<Erc20, _, _> above
  • can we get around the requirement for mutable let mut contract ref to access messages with &mut self receivers.
  • can we avoid the addidional Clone impls added to the call builders (required because many call builder methods consume self)

@ascjones ascjones added the E-dont-merge A pull request that should not be merged. label Feb 21, 2023
@ascjones ascjones mentioned this pull request Feb 21, 2023
@ascjones
Copy link
Collaborator Author

ascjones commented Mar 1, 2023

@SkymanOne let me know if this PR is helpful or not, otherwise I can just close it.

@SkymanOne
Copy link
Contributor

@SkymanOne let me know if this PR is helpful or not, otherwise I can just close it.

I will come back to it after all my issues in cargo-contract are closed

@ascjones ascjones added the B-design Designing a new component, interface or functionality. label Mar 1, 2023
@HCastano HCastano closed this Apr 12, 2023
ascjones added a commit that referenced this pull request May 17, 2023
ascjones added a commit that referenced this pull request May 19, 2023
* Cherry picking changes from #1669

* Don't display verbose Debug message for module error.

* Initial conversion of erc20 to use new call

* Remove constraint from InstantiationResult

* Use 3.0.0 release

* Revert "Use 3.0.0 release"

This reverts commit e733996.

* Move instantiate generic parameter

* Update call-runtime example

* Update contract-terminate tests

* Update contract-transfer tests

* Custom allocator

* Custom environment

* e2e-call-runtime

* flipper

* lang-err-integration-tests, compiles but fails

* Don't debug log the entire dispatch error

* constructor-return-value

* contract-ref

* integration-flipper

* mapping-integration-tests

* multi-contract-caller

* set-code-hash

* wildcard-selector

* trait-dyn-cross-contract-calls

* Clippy

* Export CallBuilderFinal type alias

* CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-design Designing a new component, interface or functionality. E-dont-merge A pull request that should not be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants