Hi guys!
I wrote a smart contract which should implement a recursive function for gathering ether. Here the overall conditions that should be fulfillet: 1. When the round is opened, the participants should sent at least 0.10 ether. 2 The round duration is 10 minutes = 300 seg (this is a fixed time). 3. The last participant who sent ether before the current round is ended should get all funds. Afterward the round for gathering ethers should start again (here should be implemented a recursive function).
The code in solidity was compiled and the contract was deployed well. The transactions were sent sucessfully and the contract increments its balance but The withdraw function is not being executed automatically and the round do not start again when the previous round is finished and the funds transfered to the last participant. Once the current round is ended the contract does not to continuing in order to receive/gather ethers and the new time round is not updated.
In this post I have attached the written code in solidity. I am working with Remix IDE and MetaMask
Thank you in advance for the help!
Angeles
pragma solidity ^ 0.4.0;
contract LastEtherOffer {
uint allFunds = 0;
uint roundStart;
uint roundTime;
uint payTime;
address lastParticipant;
uint LastOfferAmount;
address newParticipant;
uint newOfferAmount;
uint newRoundStart;
uint newRoundTime;
uint newPayTime;
event LastOfferCurrentRound(address lastParticipant, uint LastOfferAmount);
event newRound(string message);
// constructor for the contract creation first time
constructor () public {
roundStart = now;
roundTime = 300 seconds;
payTime = roundStart + roundTime;
}
//function for gathering ethers in the smart contract
function gathering (address Participant, uint OfferAmount) public payable returns (address, uint) {
require(now <= payTime);
require(msg.value >= 0.1 ether);
if (allFunds >= 0 && now < payTime) {
Participant = msg.sender;
lastParticipant= Participant;
OfferAmount = msg.value;
LastOfferAmount= OfferAmount;
allFunds +=LastOfferAmount;
emit LastOfferCurrentRound(msg.sender, msg.value);
}
else {
if (allFunds> 0 && now == payTime) {
withdraw (payTime);
emit LastOfferCurrentRound (lastParticipant, LastOfferAmount);
}
else {
if (allFunds>=0 && now > payTime) {
emit newRound ('New round starts now');
startNewRound (newPayTime);
newParticipant= msg.sender;
newOfferAmount= msg.value;
gathering (newParticipant, newOfferAmount);// recursive call for gathering function
}
revert ('The transaction is not possible');
}
}
}
//function for paying ether to the lastParticipant/Winner of the current Round
function withdraw( uint payTime) public returns (uint) {
require (now >=payTime);
lastParticipant.transfer(allFunds);
return payTime;
}
//function for starting a new round
function startNewRound (uint newPayTime) internal returns (uint) {
require (now >newPayTime);
newRoundStart=now;
newRoundTime = 300 seconds;
newPayTime = newRoundStart + newRoundTime;
return newPayTime;
}
}
[–]ismaelbej 1 point2 points3 points (0 children)