Created
July 4, 2018 09:59
-
-
Save emurmotol/8011a4c5d1aaea0edffca5b3769acdfe to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
/* | |
Simple escrow contract that mediates disputes using a trusted arbiter | |
*/ | |
contract Escrow { | |
enum State {AWAITING_PAYMENT, AWAITING_DELIVERY, COMPLETE, REFUNDED} | |
State public currentState; | |
modifier buyerOnly() { require(msg.sender == buyer || msg.sender == arbiter); _; } | |
modifier sellerOnly() { require(msg.sender == seller || msg.sender == arbiter); _; } | |
modifier inState(State expectedState) { require(currentState == expectedState); _; } | |
address public buyer; | |
address public seller; | |
address public arbiter; | |
function Escrow(address _buyer, address _seller, address _arbiter){ | |
buyer = _buyer; | |
seller = _seller; | |
arbiter = _arbiter; | |
} | |
function confirmPayment() buyerOnly inState(State.AWAITING_PAYMENT) payable { | |
currentState = State.AWAITING_DELIVERY; | |
} | |
function confirmDelivery() buyerOnly inState(State.AWAITING_DELIVERY) { | |
seller.send(this.balance); | |
currentState = State.COMPLETE; | |
} | |
function refundBuyer() sellerOnly inState(State.AWAITING_DELIVERY) { | |
buyer.send(this.balance); | |
currentState = State.REFUNDED; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.16; | |
contract Simple { | |
function arithmetics(uint _a, uint _b) | |
public | |
pure | |
returns (uint o_sum, uint o_product) | |
{ | |
o_sum = _a + _b; | |
o_product = _a * _b; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract SimpleStorage { | |
uint storedData; | |
function set(uint x) public { | |
storedData = x; | |
} | |
function get() public view returns (uint) { | |
return storedData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment