Skip to content

Instantly share code, notes, and snippets.

@rezendi
Created January 5, 2018 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezendi/b11b8c13f15c622b3ae52d5c54ccefaf to your computer and use it in GitHub Desktop.
Save rezendi/b11b8c13f15c622b3ae52d5c54ccefaf to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.18;
contract MyPrize {
struct Prize {
uint id;
address owner; // current owner
bytes10 geohash; // current unclaimed location
string metadata; // probably a URL pointing to the full metadata
uint placedAt; // block count when it was placed
}
mapping (uint => Prize) public prizes;
// Constructor
function MyPrize() public {
for (uint i=1; i <= 10; i++) {
Prize memory prize = Prize({id: i, owner: msg.sender, geohash: "", metadata: "", placedAt: 0});
prizes[i] = prize;
}
}
function placePrize (uint prizeId, bytes10 geohash, string _metadata) public {
var prize = prizes[prizeId];
require (prize.id != 0);
require (geohash != bytes10(""));
require (prize.owner == address(0) || msg.sender == prize.owner);
prize.owner = address(0);
prize.geohash = geohash;
prize.metadata = _metadata;
prize.placedAt = block.number;
}
function claimPrize (uint prizeId, bytes10 geohash) public {
var prize = prizes[prizeId];
require (prize.id != 0);
require (geohash != bytes10("") && prize.geohash == geohash);
require (block.number - prize.placedAt > 1000);
prize.owner = msg.sender;
prize.geohash = "";
prize.metadata = "";
prize.placedAt = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment