Docs Solidity by example

This commit is contained in:
Leonardo Alt
2019-12-13 16:19:49 +01:00
parent c084f6462d
commit 7a2893842d
4 changed files with 75 additions and 86 deletions
+10 -9
View File
@@ -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.