mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 05:27:19 +00:00
5c2f1e0014
* core/types, core/vm, eth, tests: regenerate gencodec files * Makefile: update devtools target Install protoc-gen-go and print reminders about npm, solc and protoc. Also switch to github.com/kevinburke/go-bindata because it's more maintained. * contracts/ens: update contracts and regenerate with solidity v0.4.19 The newer upstream version of the FIFSRegistrar contract doesn't set the resolver anymore. The resolver is now deployed separately. * contracts/release: regenerate with solidity v0.4.19 * contracts/chequebook: fix fallback and regenerate with solidity v0.4.19 The contract didn't have a fallback function, payments would be rejected when compiled with newer solidity. References to 'mortal' and 'owned' use the local file system so we can compile without network access. * p2p/discv5: regenerate with recent stringer * cmd/faucet: regenerate * dashboard: regenerate * eth/tracers: regenerate * internal/jsre/deps: regenerate * dashboard: avoid sed -i because it's not portable * accounts/usbwallet/internal/trezor: fix go generate warnings
48 lines
1.9 KiB
Solidity
48 lines
1.9 KiB
Solidity
pragma solidity ^0.4.18;
|
|
|
|
import "./mortal.sol";
|
|
|
|
/// @title Chequebook for Ethereum micropayments
|
|
/// @author Daniel A. Nagy <daniel@ethereum.org>
|
|
contract chequebook is mortal {
|
|
// Cumulative paid amount in wei to each beneficiary
|
|
mapping (address => uint256) public sent;
|
|
|
|
/// @notice Overdraft event
|
|
event Overdraft(address deadbeat);
|
|
|
|
// Allow sending ether to the chequebook.
|
|
function() public payable { }
|
|
|
|
/// @notice Cash cheque
|
|
///
|
|
/// @param beneficiary beneficiary address
|
|
/// @param amount cumulative amount in wei
|
|
/// @param sig_v signature parameter v
|
|
/// @param sig_r signature parameter r
|
|
/// @param sig_s signature parameter s
|
|
/// The digital signature is calculated on the concatenated triplet of contract address, beneficiary address and cumulative amount
|
|
function cash(address beneficiary, uint256 amount, uint8 sig_v, bytes32 sig_r, bytes32 sig_s) public {
|
|
// Check if the cheque is old.
|
|
// Only cheques that are more recent than the last cashed one are considered.
|
|
require(amount > sent[beneficiary]);
|
|
// Check the digital signature of the cheque.
|
|
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;
|
|
beneficiary.transfer(diff);
|
|
} else {
|
|
// Upon failure, punish owner for writing a bounced cheque.
|
|
// owner.sendToDebtorsPrison();
|
|
Overdraft(owner);
|
|
// Compensate beneficiary.
|
|
selfdestruct(beneficiary);
|
|
}
|
|
}
|
|
}
|