diff --git a/Cargo.toml b/Cargo.toml index fe0ec31..81d78ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "2" -members = ["ping-pong", "ping-pong/meta", "ping-pong/interactor"] +members = ["ping-pong", "ping-pong/meta"] diff --git a/ping-pong/meta/Cargo.toml b/ping-pong/meta/Cargo.toml index 5ee62a7..a106cb4 100644 --- a/ping-pong/meta/Cargo.toml +++ b/ping-pong/meta/Cargo.toml @@ -10,4 +10,3 @@ path = ".." [dependencies.multiversx-sc-meta-lib] version = "0.54.6" -default-features = false diff --git a/ping-pong/src/ping_pong.rs b/ping-pong/src/ping_pong.rs index 09f9b35..edf576d 100644 --- a/ping-pong/src/ping_pong.rs +++ b/ping-pong/src/ping_pong.rs @@ -36,36 +36,37 @@ pub trait PingPong { &self, ping_amount: &BigUint, duration_in_seconds: u64, - opt_activation_timestamp: Option, - max_funds: OptionalValue, + opt_token_id: OptionalValue, ) { - self.ping_amount().set(ping_amount); - let activation_timestamp = - opt_activation_timestamp.unwrap_or_else(|| self.blockchain().get_block_timestamp()); - let deadline = activation_timestamp + duration_in_seconds; - self.deadline().set(deadline); - self.activation_timestamp().set(activation_timestamp); - self.max_funds().set(max_funds.into_option()); + require!(ping_amount > 0, "Ping amount cannot be set to zero"); + self.ping_amount().set(&ping_amount); + + require!( + duration_in_seconds > 0, + "Duration in seconds cannot be set to zero" + ); + self.duration_in_seconds().set(duration_in_seconds); + + let token_id = match opt_token_id { + OptionalValue::Some(t) => t, + OptionalValue::None => EgldOrEsdtTokenIdentifier::egld(), + }; + self.accepted_payment_token_id().set(&token_id); } #[upgrade] - fn upgrade( - &self, - ping_amount: &BigUint, - duration_in_seconds: u64, - opt_activation_timestamp: Option, - max_funds: OptionalValue, - ) { + fn upgrade(&self, ping_amount: BigUint, duration_in_seconds: u64) { self.init( ping_amount, duration_in_seconds, - opt_activation_timestamp, - max_funds, + OptionalValue::Some(self.accepted_payment_token_id().get()), ) } - /// User sends some EGLD to be locked in the contract for a period of time. - #[payable("EGLD")] + // endpoints + + /// User sends some tokens to be locked in the contract for a period of time. + #[payable("*")] #[endpoint] fn ping(&self) { let payment = self.call_value().egld_value(); diff --git a/ping-pong/wasm/src/lib.rs b/ping-pong/wasm/src/lib.rs index 5929539..ead752a 100644 --- a/ping-pong/wasm/src/lib.rs +++ b/ping-pong/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 11 +// Endpoints: 9 // Async Callback (empty): 1 -// Total number of exported functions: 14 +// Total number of exported functions: 12 #![no_std] @@ -20,6 +20,7 @@ multiversx_sc_wasm_adapter::endpoints! { ( init => init upgrade => upgrade + upgrade => upgrade ping => ping pong => pong pongAll => pong_all