Skip to content

Instantly share code, notes, and snippets.

@jonnydubowsky
Created April 15, 2018 18:20
Show Gist options
  • Save jonnydubowsky/beba52a19437539698f425fb4f1b0409 to your computer and use it in GitHub Desktop.
Save jonnydubowsky/beba52a19437539698f425fb4f1b0409 to your computer and use it in GitHub Desktop.
A port of the Foam ParkingDAO with a natural and social capital ecosystem services use case.
pragma solidity ^0.4.13;
/*
WiltonEcosystemServicesAuthority is the governing contract for EcosystemServicesDAO. It holds two important pieces of data--
the NaturalCapitalCSR, which is the crypto-spatial registry contract for all NaturalCapitalAnchors, and the user membership
list, which keeps track of all of the registered users of the DAO. It has the sole authority to extend these
two registries.
*/
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
import "./EcosystemServicesAnchor.sol";
import "./FoamCSR.sol";
import "./User.sol";
contract WiltonEcosystemServicesAuthority is Ownable {
FoamCSR public parkingCSR;
mapping(address => bool) public anchors;
mapping(address => bool) public users;
event RegisteredWiltonEcosystemServicesAnchor(address owner, address anchor, bytes8 geohash, bytes32 anchorId);
event RegisteredWiltonEcosystemServicesUser(address owner, address user);
// Decide whether or not to give the user EcosystemServices access to the zone. Mocked for now.
modifier shouldGiveAccess(bytes4 _zone) {
_;
}
modifier callerIsUser() {
require(users[msg.sender]);
_;
}
// Deploy a new WiltonEcosystemServices authority.
function EcosystemServicesAuthority(FoamCSR foamCSR) public Ownable() {
EcosystemServicesCSR = foamCSR;
}
// A function user to verify a WiltonEcosystemServicesAnchor, currently mocked.
function validateParkingAnchor(bytes8 /* _geohash */, bytes32 /* _anchorId */) internal pure returns(bool) {
return true;
}
// Deploy a WiltonEcosystemServicesAnchor at the given geohash with the given anchorId. Transfer ownership of the
// anchor to the sender of the transaction.
function registerEcosystemServicesAnchor(bytes8 _geohash, bytes32 _anchorId) public {
require(validateEcosystemServicesAnchor(_geohash, _anchorId));
EcosystemServicesAnchor anchor = new EcosystemServicesAnchor(_geohash, _anchorId);
EcosystemServicesCSR.register(anchor);
anchors[address(anchor)] = true;
RegisteredEcosystemServicesAnchor(msg.sender, address(anchor), _geohash, _anchorId);
anchor.transferOwnership(msg.sender);
}
function validateUserApplication(address /* _applicant */) internal pure returns(bool) {
return true;
}
// Create a new user and transer ownership of the account to the message sender.
function registerUser() public {
require(validateUserApplication(msg.sender));
User newUser = new User();
newUser.transferOwnership(msg.sender);
users[address(newUser)] = true;
RegisterEcosystemServicesUser(msg.sender, address(newUser));
}
// This function is called by a user when they want to add a zone to their listed of
// licensed zones.
function addZone(bytes4 _zone) public shouldGiveAccess(_zone) callerIsUser() {
User user = User(msg.sender);
user.addZone(_zone);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment