mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Docs Solidity by example
This commit is contained in:
@@ -31,19 +31,11 @@ you can use state machine-like constructs inside a contract.
|
||||
uint public value;
|
||||
address payable public seller;
|
||||
address payable public buyer;
|
||||
|
||||
enum State { Created, Locked, Release, Inactive }
|
||||
// The state variable has a default value of the first member, `State.created`
|
||||
State public state;
|
||||
|
||||
// Ensure that `msg.value` is an even number.
|
||||
// Division will truncate if it is an odd number.
|
||||
// Check via multiplication that it wasn't an odd number.
|
||||
constructor() public payable {
|
||||
seller = msg.sender;
|
||||
value = msg.value / 2;
|
||||
require((2 * value) == msg.value, "Value has to be even.");
|
||||
}
|
||||
|
||||
modifier condition(bool _condition) {
|
||||
require(_condition);
|
||||
_;
|
||||
@@ -78,6 +70,15 @@ you can use state machine-like constructs inside a contract.
|
||||
event ItemReceived();
|
||||
event SellerRefunded();
|
||||
|
||||
// Ensure that `msg.value` is an even number.
|
||||
// Division will truncate if it is an odd number.
|
||||
// Check via multiplication that it wasn't an odd number.
|
||||
constructor() public payable {
|
||||
seller = msg.sender;
|
||||
value = msg.value / 2;
|
||||
require((2 * value) == msg.value, "Value has to be even.");
|
||||
}
|
||||
|
||||
/// Abort the purchase and reclaim the ether.
|
||||
/// Can only be called by the seller before
|
||||
/// the contract is locked.
|
||||
|
||||
Reference in New Issue
Block a user