Skip to content

Instantly share code, notes, and snippets.

@minimapletinytools
Created May 22, 2018 01:29
Show Gist options
  • Save minimapletinytools/d88c3c3a815b402964d8e5c4b76845d2 to your computer and use it in GitHub Desktop.
Save minimapletinytools/d88c3c3a815b402964d8e5c4b76845d2 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;
contract auction {
// An auction contract written in Solidity
// Can be deployed similarly to what is described at:
// https://dappsforbeginners.wordpress.com/tutorials/your-first-dapp/
// Initialization.
// Remembering bids from each address.
mapping (address => uint) bids;
// Also remembering the max_bid and the max_bidder to easily determine the winner.
uint max_bid = 0;
address max_bidder;
// Seller is always the creator of the contract.
address creator = msg.sender;
// When the auction is closed: 100 blocks after creation.
uint finish_block_id = block.number + 100;
// Interface bid().
function bid() returns (bool bid_made) {
// When the auction is over, go to the payout procedure.
if (block.number >= finish_block_id) {
withdraw();
return false;
}
// Otherwise, record the bid.
bids[msg.sender] += msg.value;
// Sometimes, the current bid is the maximal bid so far.
if (bids[msg.sender] > max_bid) {
max_bid = bids[msg.sender];
max_bidder = msg.sender;
}
return true;
}
// Interface withdraw(). Pays back to those who didn't win the
// auction. The winner's bid goes to the seller.
// returns the winner
function withdraw() returns (bool done, address winner) {
// Anything sent along the withdraw request shall be sent back.
uint payout = msg.value;
// If the auction is still going, withdrawal is not possible.
// That would require finding the second winner when the current winner cancels
// its bid.
if (block.number < finish_block_id) {
msg.sender.transfer(payout);
return (false, 0x0);
}
// The seller gets the winner's bid.
if (msg.sender == creator) {
payout += max_bid;
// But the next time, the seller will not get it.
max_bid = 0;
}
// The losing bidders get their own bids,
if (msg.sender != max_bidder) {
payout += bids[msg.sender];
// but not next time.
bids[msg.sender] = 0;
}
// The caller gets its payout.
msg.sender.transfer(payout);
return (true, max_bidder);
}
// The winner can be found by looking at the value of max_bidder variable.
// An invalid call gets a payback (provided sufficient gas).
function() public {
msg.sender.transfer(msg.value);
}
}
pragma solidity ^0.4.0;
import "./auction.sol";
contract LiterallyMinecraft {
uint constant kTotal = 10000000;
uint8[kTotal] public blocks;
bool[kTotal] public soldBlocks; // faster than searching through owners
mapping(uint => address) owners;
auction currentAuction;
/// Create a new LiterallyMinecraft
constructor() public {
// TODO start sale
initNextAuction();
}
function changeBlock(uint _block, uint8 _color) public {
require(owners[_block] == msg.sender);
blocks[_block] = _color;
}
// we aren't donig this yet
function pickNextBlock() internal {
bytes32 h = blockhash(block.number);
}
// buy the current block for sale
function initNextAuction() internal {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment