mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
swarm/services/chequebook: update chequebook for Solidity 4.3
- proper handling of failed send - added fallback function with additional logging for top-ups - added Solidity version pragma
This commit is contained in:
parent
4936bec6c9
commit
f2c5af1826
1 changed files with 17 additions and 5 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
import "mortal";
|
pragma solidity ^0.4.3;
|
||||||
|
|
||||||
|
import "mortal.sol" as mortal;
|
||||||
|
|
||||||
/// @title Chequebook for Ethereum micropayments
|
/// @title Chequebook for Ethereum micropayments
|
||||||
/// @author Daniel A. Nagy <daniel@ethdev.com>
|
/// @author Daniel A. Nagy <daniel@ethdev.com>
|
||||||
|
|
@ -9,6 +11,14 @@ contract chequebook is mortal {
|
||||||
/// @notice Overdraft event
|
/// @notice Overdraft event
|
||||||
event Overdraft(address deadbeat);
|
event Overdraft(address deadbeat);
|
||||||
|
|
||||||
|
/// @notice Deposit event
|
||||||
|
event Deposit(uint256 amount);
|
||||||
|
|
||||||
|
/// @notice Top up chequebook
|
||||||
|
function() payable {
|
||||||
|
Deposit(msg.value);
|
||||||
|
}
|
||||||
|
|
||||||
/// @notice Cash cheque
|
/// @notice Cash cheque
|
||||||
///
|
///
|
||||||
/// @param beneficiary beneficiary address
|
/// @param beneficiary beneficiary address
|
||||||
|
|
@ -28,16 +38,18 @@ contract chequebook is mortal {
|
||||||
// Attempt sending the difference between the cumulative amount on the cheque
|
// Attempt sending the difference between the cumulative amount on the cheque
|
||||||
// and the cumulative amount on the last cashed cheque to beneficiary.
|
// and the cumulative amount on the last cashed cheque to beneficiary.
|
||||||
if (amount - sent[beneficiary] >= this.balance) {
|
if (amount - sent[beneficiary] >= this.balance) {
|
||||||
if (beneficiary.send(amount - sent[beneficiary])) {
|
// update the cumulative amount before sending
|
||||||
// Upon success, update the cumulative amount.
|
sent[beneficiary] = amount;
|
||||||
sent[beneficiary] = amount;
|
if (!beneficiary.send(amount - sent[beneficiary])) {
|
||||||
|
// Upon failure to execute send, revert everything
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Upon failure, punish owner for writing a bounced cheque.
|
// Upon failure, punish owner for writing a bounced cheque.
|
||||||
// owner.sendToDebtorsPrison();
|
// owner.sendToDebtorsPrison();
|
||||||
Overdraft(owner);
|
Overdraft(owner);
|
||||||
// Compensate beneficiary.
|
// Compensate beneficiary.
|
||||||
suicide(beneficiary);
|
selfdestruct(beneficiary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue