Skip to content

Commit

Permalink
pay fee and fund egld 1 transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
alyn509 committed Sep 19, 2023
1 parent fa52f7f commit 8a320aa
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion contracts/examples/digital-cash/src/pay_fee_and_fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{constants::*, helpers, storage};
pub trait PayFeeAndFund: storage::StorageModule + helpers::HelpersModule {
#[endpoint]
#[payable("*")]
fn pay_fee_and_fund(&self, address: ManagedAddress, valability: u64) {
fn pay_fee_and_fund_esdt(&self, address: ManagedAddress, valability: u64) {
let mut payments = self.call_value().all_esdt_transfers().clone_value();
let fee = EgldOrEsdtTokenPayment::from(payments.get(0));
let caller_address = self.blockchain().get_caller();
Expand All @@ -17,6 +17,20 @@ pub trait PayFeeAndFund: storage::StorageModule + helpers::HelpersModule {

self.make_fund(0u64.into(), payments, address, valability)
}
#[endpoint]
#[payable("EGLD")]
fn pay_fee_and_fund_egld(&self, address: ManagedAddress, valability: u64) {
let mut fund = self.call_value().egld_value().clone_value();
let fee_value = self.fee().get();
require!(fund > fee_value, "payment not covering fees");

fund -= fee_value.clone();
let fee = EgldOrEsdtTokenPayment::new(EgldOrEsdtTokenIdentifier::egld(), 0, fee_value);
let caller_address = self.blockchain().get_caller();
self.update_fees(caller_address, &address, fee);

self.make_fund(fund, ManagedVec::new(), address, valability);
}

#[endpoint]
#[payable("*")]
Expand Down

0 comments on commit 8a320aa

Please sign in to comment.