From 7e030b5ab2d4eb66e18c22113427c45e14d34361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 24 Oct 2024 17:43:25 +0300 Subject: [PATCH] Fixes after review --- contracts/potlock/src/potlock_interactions.rs | 31 +++++++++---------- contracts/potlock/src/potlock_storage.rs | 4 +++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/contracts/potlock/src/potlock_interactions.rs b/contracts/potlock/src/potlock_interactions.rs index 15ebbd09..67596617 100644 --- a/contracts/potlock/src/potlock_interactions.rs +++ b/contracts/potlock/src/potlock_interactions.rs @@ -1,3 +1,5 @@ +use __wasm__endpoints__::fee_payment; + use crate::potlock_requirements; use crate::potlock_storage::{self, Pot, Project}; use crate::potlock_storage::{PotlockId, ProjectId}; @@ -14,7 +16,12 @@ pub trait PotlockInteractions: #[payable("*")] #[endpoint(addPot)] fn add_pot(&self, name: ManagedBuffer, description: ManagedBuffer) { - let payment_for_adding_pot = self.call_value().single_esdt(); + let fee_payment = self.call_value().single_esdt(); + + require!( + fee_payment().get() == fee_payment, + "Wrong payment for creating a pot!" + ); require!( self.fee_token_identifier().get() == payment_for_adding_pot.token_identifier, "Wrong token identifier for creating a pot!" @@ -48,7 +55,7 @@ pub trait PotlockInteractions: self.require_potlock_exists(potlock_id); self.require_potlock_is_active(potlock_id); - let payment = self.call_value().single_esdt(); + let (payment_token_id, payment_amount) = self.call_value().single_fungible_esdt(); let caller = self.blockchain().get_caller(); let mut donation_mapper = self.pot_donations(potlock_id); @@ -57,26 +64,18 @@ pub trait PotlockInteractions: if opt_payment.is_some() { let mut previous_payment = opt_payment.unwrap(); require!( - previous_payment.token_identifier == payment.token_identifier.clone(), + previous_payment.token_identifier == payment_token_id.clone(), "Already made a payment with a different TokenID" ); - previous_payment.amount += payment.amount; + previous_payment.amount += payment_amount; donation_mapper.insert(caller, previous_payment); } } else { - donation_mapper.insert(caller, payment); + donation_mapper.insert( + caller, + EsdtTokenPayment::new(payment_token_id, 0, payment_amount), + ); } - - // match donation_mapper.get(&caller) { - // Some(mut previous_payment) => { - // // let a = pot_donations.get(&caller).unwrap(); - // previous_payment.amount += payment.amount; - // pot_donations.insert(caller, previous_payment); - // } - // None => { - // self.pot_donations(potlock_id).insert(caller, payment); - // } - // } } #[payable("*")] diff --git a/contracts/potlock/src/potlock_storage.rs b/contracts/potlock/src/potlock_storage.rs index 19b71bdf..011d95aa 100644 --- a/contracts/potlock/src/potlock_storage.rs +++ b/contracts/potlock/src/potlock_storage.rs @@ -82,6 +82,10 @@ pub trait PotlockStorage { #[storage_mapper("feeAmount")] fn fee_amount(&self) -> SingleValueMapper; + #[view(getFeePayment)] + #[storage_mapper("feePayment")] + fn fee_payment(&self) -> SingleValueMapper; + #[view(getPotlocks)] #[storage_mapper("potlocks")] fn potlocks(&self) -> VecMapper>;