Skip to content

Instantly share code, notes, and snippets.

View brynbellomy's full-sized avatar

Bryn Bellomy brynbellomy

  • Texas, Republic of
View GitHub Profile
@brynbellomy
brynbellomy / medium-auction-contract-withdraw.sol
Created June 29, 2017 21:16
medium-auction-contract-withdraw.sol
function withdraw()
onlyEndedOrCanceled
returns (bool success)
{
address withdrawalAccount;
uint withdrawalAmount;
if (canceled) {
// if the auction was canceled, everyone should simply be allowed to withdraw their funds
withdrawalAccount = msg.sender;
@brynbellomy
brynbellomy / medium-auction-contract-cancelAuction.sol
Created June 29, 2017 21:12
medium-auction-contract-cancelAuction.sol
function cancelAuction()
onlyOwner
onlyBeforeEnd
onlyNotCanceled
returns (bool success)
{
canceled = true;
LogCanceled();
return true;
}
@brynbellomy
brynbellomy / medium-auction-contract-storage-vars.sol
Created June 29, 2017 19:57
medium-auction-contract-storage-vars.sol
// static
address public owner;
uint public startBlock;
uint public endBlock;
string public ipfsHash;
uint public bidIncrement;
// state
bool public canceled;
address public highestBidder;
@brynbellomy
brynbellomy / medium-auction-contract-6.sol
Created June 29, 2017 19:08
medium-auction-contract-6.sol
function placeBid()
payable
onlyAfterStart
onlyBeforeEnd
onlyNotCanceled
onlyNotOwner
returns (bool success)
{
// reject payments of 0 ETH
if (msg.value == 0) throw;
@brynbellomy
brynbellomy / medium-auction-contract-5.sol
Created June 29, 2017 18:25
medium-auction-contract-5.sol
modifier onlyNotOwner {
if (msg.sender == owner) throw;
_;
}
modifier onlyAfterStart {
if (block.number < startBlock) throw;
_;
}
@brynbellomy
brynbellomy / medium-auction-contract-4.sol
Created June 29, 2017 18:23
medium-auction-contract-4.sol
modifier onlyRunning {
if (canceled) throw;
if (block.number < startBlock || block.number > endBlock) throw;
_;
}
@brynbellomy
brynbellomy / medium-auction-contract-3.sol
Created June 29, 2017 18:16
medium-auction-contract-3.sol
function placeBid()
onlyAfterStart
onlyBeforeEnd
onlyNotCanceled
onlyNotOwner
returns (bool success)
{
// ...
}
@brynbellomy
brynbellomy / medium-auction-contract-2.sol
Last active June 29, 2017 18:08
medium-auction-contract-2.sol
function Auction(address _owner, uint _bidIncrement, uint _startBlock, uint _endBlock, string _ipfsHash) {
if (_startBlock >= _endBlock) throw;
if (_startBlock < block.number) throw;
if (_owner == 0) throw;
owner = _owner;
bidIncrement = _bidIncrement;
startBlock = _startBlock;
endBlock = _endBlock;
ipfsHash = _ipfsHash;
@brynbellomy
brynbellomy / medium-auction-contract-1.sol
Last active June 29, 2017 19:51
medium-auction-contract-1.sol
contract Auction {
function placeBid() returns (bool success) {}
function withdraw() returns (bool success) {}
function cancelAuction() returns (bool success) {}
event LogBid(address bidder, uint bid, address highestBidder, uint highestBid, uint highestBindingBid);
event LogWithdrawal(address withdrawer, address withdrawalAccount, uint amount);
event LogCanceled();
}
@brynbellomy
brynbellomy / DavesWallet.sol
Created June 25, 2017 01:41
DavesWallet.sol
contract DavesWallet {
event GotSomeMoney(uint amount, uint balance);
function() payable {
GotSomeMoney(msg.value, this.balance);
}
}