Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

smart-contracts/setting dynamic amount to the external function 🥑 #28

Merged
merged 1 commit into from
Nov 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions smart-contracts/contracts/CoinFlip.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract CoinFlip is VRFV2WrapperConsumerBase {
event CoinFlipResult(unit256 requestId, bool didWin);
// check each user status
struct CoinFlipStatus {
uint stakedAmount;
uint256 fees;
uint256 randomWord;
address player;
Expand All @@ -33,7 +34,7 @@ contract CoinFlip is VRFV2WrapperConsumerBase {
address constant vrfWrapperAddress = 0x99aFAf084eBA697E584501b8Ed2c0B37Dd136693;

//entry fee [update on function on the frontend later on]
uint128 constant entryFees = 0.01 ether;
// uint128 constant entryFees = 0.01 ether;

// gas limit to spare in LINK
uint32 constant callbackGasLimit = 1_000_000;
Expand All @@ -49,12 +50,13 @@ contract CoinFlip is VRFV2WrapperConsumerBase {

}
// flip function
function flip(CoinFlipSelection choice)
function flip(CoinFlipSelection choice, uint amount)
external
payable
returns (uint256) {

// if user already pays the entry fee or staking fee
require(msg.value == entryFees, "Entry Fees not sent");
require(msg.value == amount, "Entry Fees not sent");

// then request randomness
uint256 requestId = requestRandomness(
Expand All @@ -65,6 +67,7 @@ contract CoinFlip is VRFV2WrapperConsumerBase {

// update coinflipstatus with the requestId
statuses[requestId] = CoinFlipStatus({
stakedAmount: amount
fees : VRF_V2_WRAPPER.calculateRequestPrice(callbackGasLimit),
randomWord : 0;
player : msg.sender;
Expand Down Expand Up @@ -99,7 +102,7 @@ contract CoinFlip is VRFV2WrapperConsumerBase {
// pay *2 of staked amount if user win
if (statuses[requestId].choice == result) {
statuses[request].didWin = true;
payable(statuses[requestId].player).transfer(entryFees * 2);
payable(statuses[requestId].player).transfer(statuses[requestId].stakedAmount * 2);
}
emit CoinFlipResult(requestId, statuses[requestId].didWin);

Expand Down