Skip to content

Instantly share code, notes, and snippets.

@emurmotol
Created July 4, 2018 09:57
Show Gist options
  • Save emurmotol/384e933a59f4aec754d5dac9622cb078 to your computer and use it in GitHub Desktop.
Save emurmotol/384e933a59f4aec754d5dac9622cb078 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=
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;
}
}
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;
}
function anonym() { returns (uint o_sum, uint o_product)
returns arithmetics(2, 4);
}
}
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