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

Multi-call #399

Merged
merged 18 commits into from
Jun 28, 2022
Merged

Multi-call #399

merged 18 commits into from
Jun 28, 2022

Conversation

MujkicA
Copy link
Contributor

@MujkicA MujkicA commented Jun 16, 2022

Closes #211

This PR introduces the MultiContractCallHandler for bundling contract calls into a single transaction. It provides a similar interface to ContractCallHandler.

let call_handler_1 = contract_instance.initialize_counter(42);
let call_handler_2 = contract_instance.get_array([42; 2].to_vec());

let mut multi_call_handler = MultiContractCallHandler::new(wallet.clone());

multi_call_handler
    .add_call(call_handler_1)
    .add_call(call_handler_2);

let (counter, array): (u64, Vec<u64>) = multi_call_handler.call().await.unwrap().values;

Alternatively, the response can be fetched like this if we want to have access to receipts and logs in the MultiCallResponse:

let response = multi_call_handler.call::<(u64, Vec<u64>)>().await.unwrap();

The harness is extended with a test for the regular work flow and one for the script workflow (exposes script). Another test is added to script.rs for verifying that script data i built correctly.

@MujkicA MujkicA marked this pull request as draft June 16, 2022 00:24
@MujkicA MujkicA self-assigned this Jun 16, 2022
@MujkicA MujkicA added the enhancement New feature or request label Jun 16, 2022
}

/// Call contract methods on the node, in a state-modifying manner.
pub async fn call<D: Tokenizable + Debug>(&self) -> Result<MultiCallResponse<D>, Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may look simple, but this line took us days of debugging and redesign to get right 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the trick with bundling the output tokens of all the separate calls into a Token::Tupple so that the generic D effectively covers multiple types to avoid the need for dynamic dispatch

@MujkicA MujkicA marked this pull request as ready for review June 24, 2022 18:24
@MujkicA MujkicA requested a review from adlerjohn June 24, 2022 18:24
Copy link
Contributor

@adlerjohn adlerjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

docs/src/getting-started/basics.md Outdated Show resolved Hide resolved
Copy link
Contributor

@segfault-magnet segfault-magnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever I see somebody do something smart I wonder 'would I have thought of that?'

Let's just say I've been doing a lot of wondering :D

Great work.

packages/fuels-contract/src/contract.rs Outdated Show resolved Hide resolved
packages/fuels-contract/src/contract.rs Show resolved Hide resolved
packages/fuels-contract/src/script.rs Outdated Show resolved Hide resolved
packages/fuels-contract/src/script.rs Outdated Show resolved Hide resolved
packages/fuels-contract/src/script.rs Show resolved Hide resolved
Copy link
Member

@digorithm digorithm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- great work!

@MujkicA MujkicA merged commit a730d6a into master Jun 28, 2022
@MujkicA MujkicA deleted the ahmedm/multi-call branch June 28, 2022 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Introduce API for bundling many contract calls in a single transaction
4 participants