Skip to content

Commit

Permalink
contracts/chequebook: fix two contract issues (ethereum#15086)
Browse files Browse the repository at this point in the history
This patch fixes the following issues:

* The contract executes send() when it does not have enough balance.
* The contract always sends a total amount of zero.
  • Loading branch information
derekchiang authored and fjl committed Sep 25, 2017
1 parent 9feec51 commit d6a6180
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions contracts/chequebook/contract/chequebook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ contract chequebook is mortal {
if(owner != ecrecover(hash, sig_v, sig_r, sig_s)) return;
// Attempt sending the difference between the cumulative amount on the cheque
// and the cumulative amount on the last cashed cheque to beneficiary.
if (amount - sent[beneficiary] >= this.balance) {
uint256 diff = amount - sent[beneficiary];
if (diff <= this.balance) {
// update the cumulative amount before sending
sent[beneficiary] = amount;
if (!beneficiary.send(amount - sent[beneficiary])) {
if (!beneficiary.send(diff)) {
// Upon failure to execute send, revert everything
throw;
}
Expand Down

0 comments on commit d6a6180

Please sign in to comment.