Skip to content

Commit b31cc71

Browse files
axicfjl
authored andcommitted
contracts/chequebook: update for latest Solidity (#15425)
This changes behaviour: before if the owner/amount didn't match, it resulted in a successful execution without doing anything; now it results in a failed execution using the revert opcode (remainder gas is not consumed).
1 parent febfea7 commit b31cc71

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

‎contracts/chequebook/contract/chequebook.sol‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import "mortal";
1+
pragma solidity ^0.4.18;
2+
3+
import "https://github.com/ethereum/solidity/std/mortal.sol";
24

35
/// @title Chequebook for Ethereum micropayments
4-
/// @author Daniel A. Nagy <daniel@ethdev.com>
6+
/// @author Daniel A. Nagy <daniel@ethereum.org>
57
contract chequebook is mortal {
68
// Cumulative paid amount in wei to each beneficiary
79
mapping (address => uint256) public sent;
@@ -21,26 +23,23 @@ contract chequebook is mortal {
2123
uint8 sig_v, bytes32 sig_r, bytes32 sig_s) {
2224
// Check if the cheque is old.
2325
// Only cheques that are more recent than the last cashed one are considered.
24-
if(amount <= sent[beneficiary]) return;
26+
require(amount > sent[beneficiary]);
2527
// Check the digital signature of the cheque.
26-
bytes32 hash = sha3(address(this), beneficiary, amount);
27-
if(owner != ecrecover(hash, sig_v, sig_r, sig_s)) return;
28+
bytes32 hash = keccak256(address(this), beneficiary, amount);
29+
require(owner == ecrecover(hash, sig_v, sig_r, sig_s));
2830
// Attempt sending the difference between the cumulative amount on the cheque
2931
// and the cumulative amount on the last cashed cheque to beneficiary.
3032
uint256 diff = amount - sent[beneficiary];
3133
if (diff <= this.balance) {
3234
// update the cumulative amount before sending
3335
sent[beneficiary] = amount;
34-
if (!beneficiary.send(diff)) {
35-
// Upon failure to execute send, revert everything
36-
throw;
37-
}
36+
beneficiary.transfer(diff);
3837
} else {
3938
// Upon failure, punish owner for writing a bounced cheque.
4039
// owner.sendToDebtorsPrison();
4140
Overdraft(owner);
4241
// Compensate beneficiary.
43-
suicide(beneficiary);
42+
selfdestruct(beneficiary);
4443
}
4544
}
4645
}

0 commit comments

Comments
 (0)