Skip to content

Commit

Permalink
update test & fix token fee
Browse files Browse the repository at this point in the history
  • Loading branch information
alyn509 committed Sep 19, 2023
1 parent e5501b6 commit 4b30eb5
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
}
},
"str:fee": "10",
"str:feeToken": "str:EGLD",
"str:collectedFees": "10"
},
"code": "file:../output/digital-cash.wasm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
}
},
"str:fee": "10",
"str:feeToken": "str:EGLD",
"str:collectedFees": "10"
},
"code": "file:../output/digital-cash.wasm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
"1-value": "biguint:1,000"
}
},
"str:fee": "10"
"str:fee": "10",
"str:feeToken": "str:EGLD"
},
"code": "file:../output/digital-cash.wasm"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
}
},
"str:fee": "10",
"str:feeToken": "str:EGLD",
"str:collectedFees": "30"
},
"code": "file:../output/digital-cash.wasm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
}
},
"str:fee": "10",
"str:feeToken": "str:EGLD",
"str:collectedFees": "40"
},
"code": "file:../output/digital-cash.wasm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@
"1-value": "biguint:1,000"
}
},
"str:fee": "10"
"str:fee": "10",
"str:feeToken": "str:EGLD"
},
"code": "file:../output/digital-cash.wasm"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"from": "address:digital_cash_owner_address",
"contractCode": "file:../output/digital-cash.wasm",
"arguments": [
"10"
"10",
"str:EGLD"
],
"gasLimit": "5,000,000",
"gasPrice": "0"
Expand All @@ -63,7 +64,8 @@
"nonce": "0",
"balance": "0",
"storage": {
"str:fee": "10"
"str:fee": "10",
"str:feeToken": "str:EGLD"
},
"code": "file:../output/digital-cash.wasm"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@
"1-value": "biguint:1,000"
}
},
"str:fee": "10"
"str:fee": "10",
"str:feeToken": "str:EGLD"
},
"code": "file:../output/digital-cash.wasm"
},
Expand Down Expand Up @@ -226,7 +227,7 @@
"address:digital_cash_owner_address": {
"nonce": "1",
"balance": "0",
"storage": {}
"storage": "*"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"1-value": "biguint:1,000"
}
},
"str:fee": "10"
"str:fee": "10",
"str:feeToken": "str:EGLD"
},
"code": "file:../output/digital-cash.wasm"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"1-value": "biguint:1,000"
}
},
"str:fee": "10"
"str:fee": "10",
"str:feeToken": "str:EGLD"
},
"code": "file:../output/digital-cash.wasm"
},
Expand Down Expand Up @@ -193,7 +194,8 @@
"1-value": "biguint:1,000"
}
},
"str:fee": "10"
"str:fee": "10",
"str:feeToken": "str:EGLD"
},
"code": "file:../output/digital-cash.wasm"
},
Expand Down
12 changes: 7 additions & 5 deletions contracts/examples/digital-cash/src/digital_cash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ static CANNOT_DEPOSIT_FUNDS_ERR_MSG: &[u8] =
#[multiversx_sc::contract]
pub trait DigitalCash {
#[init]
fn init(&self, fee: BigUint, coin: TokenIdentifier) {
fn init(&self, fee: BigUint, token: EgldOrEsdtTokenIdentifier) {
self.fee().set(fee);
self.fee_token().set(coin);
self.fee_token().set(token);
}

// endpoints
Expand Down Expand Up @@ -80,7 +80,8 @@ pub trait DigitalCash {
if accepted_fee_token == EgldOrEsdtTokenIdentifier::egld() {
egld_funds += deposit.fees.value;
} else {
let esdt_fee = EsdtTokenPayment::new(accepted_fee_token, 0, deposit.fees.value);
let esdt_fee_token = accepted_fee_token.unwrap_esdt();
let esdt_fee = EsdtTokenPayment::new(esdt_fee_token, 0, deposit.fees.value);
esdt_funds.push(esdt_fee);
}

Expand Down Expand Up @@ -229,8 +230,9 @@ pub trait DigitalCash {
if accepted_fee_token == EgldOrEsdtTokenIdentifier::egld() {
self.send().direct_egld(address, fee_amount);
} else {
let esdt_fee_token = accepted_fee_token.unwrap_esdt();
self.send()
.direct_esdt(address, &accepted_fee_token, 0, fee_amount);
.direct_esdt(address, &esdt_fee_token, 0, fee_amount);
}
}

Expand Down Expand Up @@ -300,7 +302,7 @@ pub trait DigitalCash {
fn fee(&self) -> SingleValueMapper<BigUint>;

#[storage_mapper("feeToken")]
fn fee_token(&self) -> SingleValueMapper<TokenIdentifier>;
fn fee_token(&self) -> SingleValueMapper<EgldOrEsdtTokenIdentifier>;

#[storage_mapper("collectedFees")]
fn collected_fees(&self) -> SingleValueMapper<BigUint>;
Expand Down
4 changes: 3 additions & 1 deletion contracts/examples/digital-cash/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
// Total number of exported functions: 10

#![no_std]
#![allow(internal_features)]

// Configuration that works with rustc < 1.73.0.
// TODO: Recommended rustc version: 1.73.0 or newer.
#![feature(lang_items)]

multiversx_sc_wasm_adapter::allocator!();
Expand Down

0 comments on commit 4b30eb5

Please sign in to comment.