diff --git a/examples/demo/app/tests/gclient.rs b/examples/demo/app/tests/gclient.rs index 727cd99d..3dd2d24e 100644 --- a/examples/demo/app/tests/gclient.rs +++ b/examples/demo/app/tests/gclient.rs @@ -124,7 +124,7 @@ async fn ping_pong_works() { ping_call_payload, Some(gas_limit), 0, - GClientArgs, + GClientArgs::default(), ) .await .unwrap() diff --git a/rs/Cargo.toml b/rs/Cargo.toml index cd1404dd..5e00a5b8 100644 --- a/rs/Cargo.toml +++ b/rs/Cargo.toml @@ -34,6 +34,7 @@ gtest = { workspace = true, optional = true } [features] default = ["gstd"] debug = ["gstd?/debug"] +ethexe = ["gstd?/ethexe"] gclient = ["dep:gclient"] gstd = ["dep:gstd", "dep:gear-core", "dep:sails-macros"] gtest = ["dep:gtest"] diff --git a/rs/src/calls.rs b/rs/src/calls.rs index 3a606d9b..7dc959c7 100644 --- a/rs/src/calls.rs +++ b/rs/src/calls.rs @@ -7,10 +7,12 @@ use core::{future::Future, marker::PhantomData}; pub trait Action { type Args; + #[cfg(not(feature = "ethexe"))] fn with_gas_limit(self, gas_limit: GasUnit) -> Self; fn with_value(self, value: ValueUnit) -> Self; fn with_args(self, args: Self::Args) -> Self; + #[cfg(not(feature = "ethexe"))] fn gas_limit(&self) -> Option; fn value(&self) -> ValueUnit; fn args(&self) -> &Self::Args; @@ -124,7 +126,7 @@ pub trait Remoting { code_id: CodeId, salt: impl AsRef<[u8]>, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: Self::Args, ) -> Result)>>>; @@ -133,7 +135,7 @@ pub trait Remoting { self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: Self::Args, ) -> Result>>>; @@ -142,7 +144,7 @@ pub trait Remoting { self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: Self::Args, ) -> Result>; @@ -151,6 +153,7 @@ pub trait Remoting { pub struct RemotingAction { remoting: TRemoting, params: TActionIo::Params, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: TRemoting::Args, @@ -161,6 +164,7 @@ impl RemotingAction RemotingAction Action for RemotingAction { type Args = TRemoting::Args; + #[cfg(not(feature = "ethexe"))] fn with_gas_limit(self, gas_limit: GasUnit) -> Self { Self { gas_limit: Some(gas_limit), @@ -186,6 +191,7 @@ impl Action for RemotingAction Option { self.gas_limit } @@ -210,7 +216,14 @@ where let payload = TActionIo::encode_call(&self.params); let reply_future = self .remoting - .message(target, payload, self.gas_limit, self.value, self.args) + .message( + target, + payload, + #[cfg(not(feature = "ethexe"))] + self.gas_limit, + self.value, + self.args, + ) .await?; Ok(CallTicket::<_, TActionIo>::new(reply_future)) } @@ -233,6 +246,7 @@ where code_id, salt, payload, + #[cfg(not(feature = "ethexe"))] self.gas_limit, self.value, self.args, @@ -253,7 +267,14 @@ where let payload = TActionIo::encode_call(&self.params); let reply_bytes = self .remoting - .query(target, payload, self.gas_limit, self.value, self.args) + .query( + target, + payload, + #[cfg(not(feature = "ethexe"))] + self.gas_limit, + self.value, + self.args, + ) .await?; TActionIo::decode_reply(reply_bytes) } diff --git a/rs/src/gclient/calls.rs b/rs/src/gclient/calls.rs index fff166b8..c55d8eca 100644 --- a/rs/src/gclient/calls.rs +++ b/rs/src/gclient/calls.rs @@ -6,12 +6,24 @@ use crate::{ }; use core::future::Future; use futures::{stream, Stream, StreamExt}; -use gclient::metadata::runtime_types::gear_core::message::user::UserMessage as GenUserMessage; +use gclient::metadata::runtime_types::{ + gear_core::message::user::UserMessage as GenUserMessage, + pallet_gear_voucher::internal::VoucherId, +}; use gclient::{ext::sp_core::ByteArray, EventProcessor, GearApi}; use gear_core_errors::ReplyCode; #[derive(Debug, Default)] -pub struct GClientArgs; +pub struct GClientArgs { + voucher: Option<(VoucherId, bool)>, +} + +impl GClientArgs { + pub fn with_voucher(mut self, voucher_id: VoucherId, keep_alive: bool) -> Self { + self.voucher = Some((voucher_id, keep_alive)); + self + } +} #[derive(Clone)] pub struct GClientRemoting { @@ -37,12 +49,13 @@ impl Remoting for GClientRemoting { code_id: CodeId, salt: impl AsRef<[u8]>, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, _args: GClientArgs, ) -> Result)>>> { let api = self.api; // Calculate gas amount if it is not explicitly set + #[cfg(not(feature = "ethexe"))] let gas_limit = if let Some(gas_limit) = gas_limit { gas_limit } else { @@ -52,6 +65,8 @@ impl Remoting for GClientRemoting { .await?; gas_info.min_limit }; + #[cfg(feature = "ethexe")] + let gas_limit = 0; let mut listener = api.subscribe().await?; let (message_id, program_id, ..) = api @@ -69,12 +84,13 @@ impl Remoting for GClientRemoting { self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, - _args: GClientArgs, + args: GClientArgs, ) -> Result>>> { let api = self.api; // Calculate gas amount if it is not explicitly set + #[cfg(not(feature = "ethexe"))] let gas_limit = if let Some(gas_limit) = gas_limit { gas_limit } else { @@ -84,11 +100,19 @@ impl Remoting for GClientRemoting { .await?; gas_info.min_limit }; + #[cfg(feature = "ethexe")] + let gas_limit = 0; let mut listener = api.subscribe().await?; - let (message_id, ..) = api - .send_message_bytes(target, payload, gas_limit, value) - .await?; + let (message_id, ..) = if let Some((voucher_id, keep_alive)) = args.voucher { + api.send_message_bytes_with_voucher( + voucher_id, target, payload, gas_limit, value, keep_alive, + ) + .await? + } else { + api.send_message_bytes(target, payload, gas_limit, value) + .await? + }; Ok(async move { let (_, result, _) = listener.reply_bytes_on(message_id).await?; @@ -101,17 +125,20 @@ impl Remoting for GClientRemoting { self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, _args: GClientArgs, ) -> Result> { let api = self.api; // Get Max gas amount if it is not explicitly set + #[cfg(not(feature = "ethexe"))] let gas_limit = if let Some(gas_limit) = gas_limit { gas_limit } else { api.block_gas_limit()? }; + #[cfg(feature = "ethexe")] + let gas_limit = 0; let origin = H256::from_slice(api.account_id().as_slice()); let payload = payload.as_ref().to_vec(); diff --git a/rs/src/gstd/calls.rs b/rs/src/gstd/calls.rs index 34c6bb58..837ee407 100644 --- a/rs/src/gstd/calls.rs +++ b/rs/src/gstd/calls.rs @@ -5,10 +5,13 @@ use gstd::{msg, prog}; #[derive(Default)] pub struct GStdArgs { + #[cfg(not(feature = "ethexe"))] reply_deposit: Option, + #[cfg(not(feature = "ethexe"))] reply_hook: Option>, } +#[cfg(not(feature = "ethexe"))] impl GStdArgs { pub fn with_reply_deposit(mut self, reply_deposit: Option) -> Self { self.reply_deposit = reply_deposit; @@ -32,10 +35,11 @@ impl GStdRemoting { fn send_for_reply( target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, - args: GStdArgs, + #[allow(unused_variables)] args: GStdArgs, ) -> Result { + #[cfg(not(feature = "ethexe"))] let message_future = if let Some(gas_limit) = gas_limit { msg::send_bytes_with_gas_for_reply( target, @@ -52,11 +56,15 @@ impl GStdRemoting { args.reply_deposit.unwrap_or_default(), )? }; + #[cfg(feature = "ethexe")] + let message_future = msg::send_bytes_for_reply(target, payload, value)?; + + #[cfg(not(feature = "ethexe"))] if let Some(reply_hook) = args.reply_hook { - Ok(message_future.handle_reply(reply_hook)?) - } else { - Ok(message_future) + return Ok(message_future.handle_reply(reply_hook)?); } + + Ok(message_future) } } @@ -68,10 +76,11 @@ impl Remoting for GStdRemoting { code_id: CodeId, salt: impl AsRef<[u8]>, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, - args: GStdArgs, + #[allow(unused_variables)] args: GStdArgs, ) -> Result)>>> { + #[cfg(not(feature = "ethexe"))] let mut reply_future = if let Some(gas_limit) = gas_limit { prog::create_program_bytes_with_gas_for_reply( code_id, @@ -90,9 +99,14 @@ impl Remoting for GStdRemoting { args.reply_deposit.unwrap_or_default(), )? }; + #[cfg(feature = "ethexe")] + let reply_future = prog::create_program_bytes_for_reply(code_id, salt, payload, value)?; + + #[cfg(not(feature = "ethexe"))] if let Some(reply_hook) = args.reply_hook { reply_future = reply_future.handle_reply(reply_hook)?; } + let reply_future = reply_future.map(|result| result.map_err(Into::into)); Ok(reply_future) } @@ -101,11 +115,18 @@ impl Remoting for GStdRemoting { self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: GStdArgs, ) -> Result>>> { - let reply_future = GStdRemoting::send_for_reply(target, payload, gas_limit, value, args)?; + let reply_future = GStdRemoting::send_for_reply( + target, + payload, + #[cfg(not(feature = "ethexe"))] + gas_limit, + value, + args, + )?; let reply_future = reply_future.map(|result| result.map_err(Into::into)); Ok(reply_future) } @@ -114,11 +135,18 @@ impl Remoting for GStdRemoting { self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: GStdArgs, ) -> Result> { - let reply_future = GStdRemoting::send_for_reply(target, payload, gas_limit, value, args)?; + let reply_future = GStdRemoting::send_for_reply( + target, + payload, + #[cfg(not(feature = "ethexe"))] + gas_limit, + value, + args, + )?; let reply = reply_future.await?; Ok(reply) } diff --git a/rs/src/gstd/mod.rs b/rs/src/gstd/mod.rs index ecc1b06e..4da72b50 100644 --- a/rs/src/gstd/mod.rs +++ b/rs/src/gstd/mod.rs @@ -1,5 +1,8 @@ +#[cfg(not(feature = "ethexe"))] #[doc(hidden)] -pub use gstd::{async_init, async_main, handle_reply_with_hook, handle_signal, message_loop}; +pub use gstd::handle_signal; +#[doc(hidden)] +pub use gstd::{async_init, async_main, handle_reply_with_hook, message_loop}; pub use gstd::{debug, exec, msg}; pub use sails_macros::*; diff --git a/rs/src/gtest/calls.rs b/rs/src/gtest/calls.rs index 615e7e06..0f00c6e6 100644 --- a/rs/src/gtest/calls.rs +++ b/rs/src/gtest/calls.rs @@ -139,11 +139,14 @@ impl GTestRemoting { &self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: GTestArgs, ) -> Result { + #[cfg(not(feature = "ethexe"))] let gas_limit = gas_limit.unwrap_or(gtest::constants::GAS_ALLOWANCE); + #[cfg(feature = "ethexe")] + let gas_limit = gtest::constants::GAS_ALLOWANCE; let program = self .system .get_program(target.as_ref()) @@ -187,11 +190,14 @@ impl Remoting for GTestRemoting { code_id: CodeId, salt: impl AsRef<[u8]>, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: GTestArgs, ) -> Result)>>> { + #[cfg(not(feature = "ethexe"))] let gas_limit = gas_limit.unwrap_or(gtest::constants::GAS_ALLOWANCE); + #[cfg(feature = "ethexe")] + let gas_limit = gtest::constants::GAS_ALLOWANCE; let code = self .system .submitted_code(code_id) @@ -214,11 +220,18 @@ impl Remoting for GTestRemoting { self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: GTestArgs, ) -> Result>>> { - let message_id = self.send_message(target, payload, gas_limit, value, args)?; + let message_id = self.send_message( + target, + payload, + #[cfg(not(feature = "ethexe"))] + gas_limit, + value, + args, + )?; Ok(self.message_reply_from_next_block(message_id)) } @@ -226,11 +239,18 @@ impl Remoting for GTestRemoting { self, target: ActorId, payload: impl AsRef<[u8]>, - gas_limit: Option, + #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, args: GTestArgs, ) -> Result> { - let message_id = self.send_message(target, payload, gas_limit, value, args)?; + let message_id = self.send_message( + target, + payload, + #[cfg(not(feature = "ethexe"))] + gas_limit, + value, + args, + )?; self.message_reply_from_next_block(message_id).await } }