diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-11-10 17:19:51 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-11-10 17:19:51 +0800 |
commit | b31cc71ff6415a02864482980d08f5998cd5e086 (patch) | |
tree | 79cf328339b8bbbea65c8256012cdc293285318f /contracts/chequebook/contract/chequebook.sol | |
parent | febfea7af2a01acd9c8fbd4cf72ce9710704c964 (diff) | |
download | dexon-b31cc71ff6415a02864482980d08f5998cd5e086.tar.gz dexon-b31cc71ff6415a02864482980d08f5998cd5e086.tar.zst dexon-b31cc71ff6415a02864482980d08f5998cd5e086.zip |
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).
Diffstat (limited to 'contracts/chequebook/contract/chequebook.sol')
-rw-r--r-- | contracts/chequebook/contract/chequebook.sol | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/contracts/chequebook/contract/chequebook.sol b/contracts/chequebook/contract/chequebook.sol index 845ba464b..8d6e85d11 100644 --- a/contracts/chequebook/contract/chequebook.sol +++ b/contracts/chequebook/contract/chequebook.sol @@ -1,7 +1,9 @@ -import "mortal"; +pragma solidity ^0.4.18; + +import "https://github.com/ethereum/solidity/std/mortal.sol"; /// @title Chequebook for Ethereum micropayments -/// @author Daniel A. Nagy <daniel@ethdev.com> +/// @author Daniel A. Nagy <daniel@ethereum.org> contract chequebook is mortal { // Cumulative paid amount in wei to each beneficiary mapping (address => uint256) public sent; @@ -21,26 +23,23 @@ contract chequebook is mortal { uint8 sig_v, bytes32 sig_r, bytes32 sig_s) { // Check if the cheque is old. // Only cheques that are more recent than the last cashed one are considered. - if(amount <= sent[beneficiary]) return; + require(amount > sent[beneficiary]); // Check the digital signature of the cheque. - bytes32 hash = sha3(address(this), beneficiary, amount); - if(owner != ecrecover(hash, sig_v, sig_r, sig_s)) return; + bytes32 hash = keccak256(address(this), beneficiary, amount); + require(owner == ecrecover(hash, sig_v, sig_r, sig_s)); // Attempt sending the difference between the cumulative amount on the cheque // and the cumulative amount on the last cashed cheque to beneficiary. uint256 diff = amount - sent[beneficiary]; if (diff <= this.balance) { // update the cumulative amount before sending sent[beneficiary] = amount; - if (!beneficiary.send(diff)) { - // Upon failure to execute send, revert everything - throw; - } + beneficiary.transfer(diff); } else { // Upon failure, punish owner for writing a bounced cheque. // owner.sendToDebtorsPrison(); Overdraft(owner); // Compensate beneficiary. - suicide(beneficiary); + selfdestruct(beneficiary); } } } |