Merge pull request #7313 from ethereum/chriseth-patch-1

[DOCS] Protection to not lose money.
This commit is contained in:
chriseth 2019-08-28 20:21:43 +02:00 committed by GitHub
commit a82fbf7322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,15 +41,11 @@ become the new richest.
mostSent = msg.value;
}
function becomeRichest() public payable returns (bool) {
if (msg.value > mostSent) {
function becomeRichest() public payable {
require(msg.value > mostSent, "Not enough money sent.");
pendingWithdrawals[richest] += msg.value;
richest = msg.sender;
mostSent = msg.value;
return true;
} else {
return false;
}
}
function withdraw() public {
@ -76,16 +72,12 @@ This is as opposed to the more intuitive sending pattern:
mostSent = msg.value;
}
function becomeRichest() public payable returns (bool) {
if (msg.value > mostSent) {
function becomeRichest() public payable {
require(msg.value > mostSent, "Not enough money sent.");
// This line can cause problems (explained below).
richest.transfer(msg.value);
richest = msg.sender;
mostSent = msg.value;
return true;
} else {
return false;
}
}
}