Skip to content

Commit

Permalink
Merge pull request #1818 from multiversx/run-async
Browse files Browse the repository at this point in the history
unified syntax - removed need for `prepare_async()`
  • Loading branch information
andrei-marinica authored Oct 14, 2024
2 parents f3b0cc7 + 168179d commit f2e5d28
Show file tree
Hide file tree
Showing 19 changed files with 247 additions and 50 deletions.
7 changes: 0 additions & 7 deletions contracts/examples/adder/interact/src/basic_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ impl AdderInteract {
.code(ADDER_CODE_PATH)
.code_metadata(CodeMetadata::UPGRADEABLE)
.returns(ReturnsNewBech32Address)
.prepare_async()
.run()
.await;

Expand Down Expand Up @@ -185,7 +184,6 @@ impl AdderInteract {
.from(&self.wallet_address)
.to(self.state.current_adder_address())
.egld(NumExpr("0,050000000000000000"))
.prepare_async()
.run()
.await;
}
Expand All @@ -198,7 +196,6 @@ impl AdderInteract {
.gas(6_000_000)
.typed(adder_proxy::AdderProxy)
.add(value)
.prepare_async()
.run()
.await;

Expand All @@ -213,7 +210,6 @@ impl AdderInteract {
.typed(adder_proxy::AdderProxy)
.sum()
.returns(ReturnsResultUnmanaged)
.prepare_async()
.run()
.await;

Expand All @@ -239,7 +235,6 @@ impl AdderInteract {
.code_metadata(CodeMetadata::UPGRADEABLE)
.code(ADDER_CODE_PATH)
.returns(ExpectError(code, msg))
.prepare_async()
.run()
.await;

Expand All @@ -255,7 +250,6 @@ impl AdderInteract {
.upgrade(new_value)
.code_metadata(CodeMetadata::UPGRADEABLE)
.code(ADDER_CODE_PATH)
.prepare_async()
.run()
.await;

Expand All @@ -266,7 +260,6 @@ impl AdderInteract {
.typed(adder_proxy::AdderProxy)
.sum()
.returns(ReturnsResultUnmanaged)
.prepare_async()
.run()
.await;

Expand Down
8 changes: 0 additions & 8 deletions contracts/examples/multisig/interact/src/multisig_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ impl MultisigInteract {
.code(&self.multisig_code)
.gas(NumExpr("100,000,000"))
.returns(ReturnsNewBech32Address)
.prepare_async()
.run()
.await;

Expand Down Expand Up @@ -202,7 +201,6 @@ impl MultisigInteract {
.from(&self.wallet_address)
.to(self.state.current_multisig_address())
.egld(BigUint::from(50_000_000_000_000_000u64)) // 0,05 or 5 * 10^16
.prepare_async()
.run()
.await;
}
Expand All @@ -220,7 +218,6 @@ impl MultisigInteract {
.gas(gas_expr)
.typed(multisig_proxy::MultisigProxy)
.perform_action_endpoint(action_id)
.prepare_async()
.run()
.await;

Expand Down Expand Up @@ -273,7 +270,6 @@ impl MultisigInteract {
.typed(multisig_proxy::MultisigProxy)
.quorum_reached(action_id)
.returns(ReturnsResult)
.prepare_async()
.run()
.await
}
Expand All @@ -285,7 +281,6 @@ impl MultisigInteract {
.typed(multisig_proxy::MultisigProxy)
.signed(signer, action_id)
.returns(ReturnsResult)
.prepare_async()
.run()
.await
}
Expand Down Expand Up @@ -340,7 +335,6 @@ impl MultisigInteract {
.gas(NumExpr("30,000,000"))
.typed(multisig_proxy::MultisigProxy)
.dns_register(dns_address, name)
.prepare_async()
.run()
.await;

Expand All @@ -355,7 +349,6 @@ impl MultisigInteract {
.typed(multisig_proxy::MultisigProxy)
.quorum()
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand All @@ -370,7 +363,6 @@ impl MultisigInteract {
.typed(multisig_proxy::MultisigProxy)
.num_board_members()
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl MultisigInteract {
.argument(&0u32),
)
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand All @@ -75,7 +74,6 @@ impl MultisigInteract {
.typed(multisig_proxy::MultisigProxy)
.perform_action_endpoint(action_id)
.returns(ReturnsNewTokenIdentifier)
.prepare_async()
.run()
.await;
self.collection_token_identifier = new_token_id.to_string();
Expand All @@ -102,7 +100,6 @@ impl MultisigInteract {
.argument(&COLLECTION_TICKER),
)
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand All @@ -127,7 +124,6 @@ impl MultisigInteract {
.typed(multisig_proxy::MultisigProxy)
.perform_action_endpoint(action_id)
.returns(ReturnsNewTokenIdentifier)
.prepare_async()
.run()
.await;
self.collection_token_identifier = new_token_id;
Expand Down Expand Up @@ -156,7 +152,6 @@ impl MultisigInteract {
.argument(&"ESDTRoleNFTCreate"),
)
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl MultisigInteract {
.typed(multisig_proxy::MultisigProxy)
.propose_async_call(&self.config.wegld_address, WRAP_AMOUNT, function_call)
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand All @@ -72,7 +71,6 @@ impl MultisigInteract {
.typed(wegld_proxy::EgldEsdtSwapProxy)
.wrapped_egld_token_id()
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand Down Expand Up @@ -104,7 +102,6 @@ impl MultisigInteract {
.typed(multisig_proxy::MultisigProxy)
.propose_async_call(normalized_to, 0u64, normalized_data)
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand Down
7 changes: 2 additions & 5 deletions contracts/examples/ping-pong-egld/dapp/src/interactor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use imports::{Address, Bech32Address, BytesValue};
use multiversx_sc_snippets_dapp::*;
use multiversx_sc_snippets_dapp::imports::*;
use serde::{Deserialize, Serialize};

const GATEWAY: &str = sdk::core::gateway::DEVNET_GATEWAY;
const GATEWAY: &str = multiversx_sc_snippets_dapp::sdk::core::gateway::DEVNET_GATEWAY;
const CONTRACT_ADDRESS: &str = "erd1qqqqqqqqqqqqqpgq6tqvj5f59xrgxwrtwy30elgpu7l4zrv6d8ssnjdwxq";
const PING_PONG_CODE: &[u8] = include_bytes!("../ping-pong-egld.wasm");

use multiversx_sc_snippets_dapp::imports::*;

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Config {
gateway: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::interactor::ContractInteract;
use multiversx_sc_snippets_dapp::imports::{
Bech32Address, BigUint, IgnoreValue, InteractorPrepareAsync, OptionalValue, ReturnsMessage,
ReturnsNewBech32Address, ReturnsStatus,
};
use multiversx_sc_snippets_dapp::imports::*;

use super::proxy;

Expand All @@ -29,7 +26,6 @@ pub async fn deploy_sc() -> Result<Bech32Address, String> {
.returns(ReturnsNewBech32Address)
.returns(ReturnsStatus)
.returns(ReturnsMessage)
.prepare_async()
.run()
.await;

Expand Down Expand Up @@ -57,7 +53,6 @@ pub async fn ping() -> Result<String, String> {
.typed(proxy::PingPongProxy)
.ping(_data)
.egld(BigUint::from(amount))
.prepare_async()
.run()
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl BasicFeaturesInteract {
.code(&self.code_expr)
.gas(NumExpr("4,000,000"))
.returns(ReturnsNewBech32Address)
.prepare_async()
.run()
.await;

Expand All @@ -103,7 +102,6 @@ impl BasicFeaturesInteract {
.gas(NumExpr("600,000,000"))
.typed(basic_features_proxy::BasicFeaturesProxy)
.store_bytes(value)
.prepare_async()
.run()
.await;

Expand All @@ -118,7 +116,6 @@ impl BasicFeaturesInteract {
.typed(basic_features_proxy::BasicFeaturesProxy)
.load_bytes()
.returns(ReturnsResult)
.prepare_async()
.run()
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ impl ComposabilityInteract {
.to(&root_addr)
.typed(forwarder_queue_proxy::ForwarderQueueProxy)
.forward_queued_calls()
.prepare_async()
.run()
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn write_deploy_method_impl(file: &mut File, init_abi: &EndpointAbi, name: &Stri
.init({})
.code(&self.contract_code)
.returns(ReturnsNewAddress)
.prepare_async()
.run()
.await;
let new_address_bech32 = bech32::encode(&new_address);
Expand Down Expand Up @@ -101,7 +101,7 @@ fn write_upgrade_endpoint_impl(file: &mut File, upgrade_abi: &EndpointAbi, name:
.code(&self.contract_code)
.code_metadata(CodeMetadata::UPGRADEABLE)
.returns(ReturnsNewAddress)
.prepare_async()
.run()
.await;
Expand Down Expand Up @@ -214,7 +214,7 @@ fn write_contract_call(file: &mut File, endpoint_abi: &EndpointAbi, name: &Strin
.typed(proxy::{}Proxy)
.{}({}){}
.returns(ReturnsResultUnmanaged)
.prepare_async()
.run()
.await;
Expand All @@ -237,7 +237,7 @@ fn write_contract_query(file: &mut File, endpoint_abi: &EndpointAbi, name: &Stri
.typed(proxy::{}Proxy)
.{}({})
.returns(ReturnsResultUnmanaged)
.prepare_async()
.run()
.await;
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets-base/src/interactor_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ mod interactor_query_step;

pub use interactor_exec_env::InteractorEnvExec;
pub use interactor_exec_step::InteractorExecStep;
pub use interactor_prepare_async::InteractorPrepareAsync;
pub use interactor_prepare_async::{InteractorPrepareAsync, InteractorRunAsync};
pub use interactor_query_env::InteractorEnvQuery;
pub use interactor_query_step::InteractorQueryStep;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,50 @@ use multiversx_sdk::gateway::GatewayAsyncService;

use crate::InteractorBase;

use super::{InteractorEnvExec, InteractorExecStep, InteractorPrepareAsync};
use super::{InteractorEnvExec, InteractorExecStep, InteractorPrepareAsync, InteractorRunAsync};

async fn run_async_call<'w, GatewayProxy, From, To, Payment, Gas, RH>(
tx: Tx<
InteractorEnvExec<'w, GatewayProxy>,
From,
To,
Payment,
Gas,
FunctionCall<StaticApi>,
RH,
>,
) -> <RH::ListReturns as NestedTupleFlatten>::Unpacked
where
GatewayProxy: GatewayAsyncService,
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
Payment: TxPayment<InteractorEnvExec<'w, GatewayProxy>>,
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
let mut step_wrapper = tx.tx_to_step();
step_wrapper.env.world.sc_call(&mut step_wrapper.step).await;
step_wrapper.process_result()
}

impl<'w, GatewayProxy, From, To, Payment, Gas, RH> InteractorRunAsync
for Tx<InteractorEnvExec<'w, GatewayProxy>, From, To, Payment, Gas, FunctionCall<StaticApi>, RH>
where
GatewayProxy: GatewayAsyncService,
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
Payment: TxPayment<InteractorEnvExec<'w, GatewayProxy>>,
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
type Result = <RH::ListReturns as NestedTupleFlatten>::Unpacked;

fn run(self) -> impl std::future::Future<Output = Self::Result> {
run_async_call(self)
}
}

impl<'w, GatewayProxy, From, To, Payment, Gas, RH> InteractorPrepareAsync
for Tx<InteractorEnvExec<'w, GatewayProxy>, From, To, Payment, Gas, FunctionCall<StaticApi>, RH>
Expand Down
Loading

0 comments on commit f2e5d28

Please sign in to comment.