Last active
September 18, 2018 18:31
-
-
Save benzap/cd0df691306e1bbc2125bdce865cd395 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.25+commit.59dbf8f1.js&optimize=true&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.7; | |
contract ChefFactory { | |
event CreateChef(address _address); | |
struct Chef { | |
uint8 cooking_ability; // Personal Cooking Rating 1-10 | |
uint8 baddaboops; // Acquired Taste Rating 1-10 | |
} | |
Chef[] chef_listing; | |
mapping(address => uint) chef_mapping; | |
function createChef(address _address, uint8 _cooking_ability) internal { | |
require(chef_mapping[_address] == 0, "Chef for that address already exists."); | |
assert(_cooking_ability >= 1 && _cooking_ability <= 10); | |
Chef memory chef = Chef({ | |
cooking_ability: _cooking_ability, | |
baddaboops: 1 | |
}); | |
chef_listing.push(chef); | |
chef_mapping[_address] = chef_listing.length; | |
emit CreateChef(_address); | |
} | |
function hasChef(address _address) public view returns(bool) { | |
return chef_mapping[_address] != 0; | |
} | |
function getChef(address _address) public view returns (uint8, uint8) { | |
require(chef_mapping[_address] != 0, "Chef with given address does not exist."); | |
Chef memory chef = chef_listing[chef_mapping[_address]-1]; | |
return (chef.cooking_ability, chef.baddaboops); | |
} | |
function getCurrentChef() public view returns (uint8, uint8) { | |
return getChef(msg.sender); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.7; | |
import "./TasteLibrary.sol"; | |
contract CustomerFactory { | |
event CreateCustomer(address _address); | |
struct Customer { | |
Taste.TastePreference taste_preference; | |
} | |
Customer[] customer_listing; | |
mapping(address => uint) customer_mapping; | |
function createCustomer(address _address, Taste.TastePreference _pref) internal { | |
require(customer_mapping[_address] == 0, "Given address is already a customer."); | |
Customer memory customer = Customer({ | |
taste_preference: _pref | |
}); | |
customer_listing.push(customer); | |
customer_mapping[_address] = customer_listing.length; | |
emit CreateCustomer(_address); | |
} | |
function hasCustomer (address _address) public view returns(bool) { | |
return customer_mapping[_address] != 0; | |
} | |
function getCustomer (address _address) public view returns(Taste.TastePreference) { | |
require(customer_mapping[_address] != 0, "Given Customer does not exist"); | |
Customer memory customer = customer_listing[customer_mapping[_address]-1]; | |
return customer.taste_preference; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.7; | |
import "./TasteLibrary.sol"; | |
// Customers Open a bounty, multiple chefs can draft solutions | |
// TasteTesters test out drafts and rate them. | |
// Customer can then claim what they deem the 'best', | |
// and the Chef who is claimed is rewarded. | |
contract RecipeBountyFactory { | |
struct RecipeBounty { | |
string name; | |
string description; | |
uint256 reward; | |
} | |
RecipeBounty[] recipe_listing; | |
mapping(address => uint) recipe_mapping; | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.7; | |
import "./UserFactory.sol"; | |
import "./CustomerFactory.sol"; | |
import "./ChefFactory.sol"; | |
import "./TasteTesterFactory.sol"; | |
import "./TasteLibrary.sol"; | |
contract RecipeExchangeMediator is UserFactory, CustomerFactory, | |
ChefFactory, TasteTesterFactory | |
{ | |
modifier isRegisteredUser(address _address) { | |
require(user_mapping[_address] != 0, "User is not Registered."); | |
_; | |
} | |
function registerUser(string _name, string _email) public { | |
createUser(msg.sender, _name, _email); | |
} | |
function registerChef(uint8 _rating) public isRegisteredUser(msg.sender) { | |
createChef(msg.sender, _rating); | |
} | |
function registerCustomer(Taste.TastePreference _pref) public isRegisteredUser(msg.sender) { | |
createCustomer(msg.sender, _pref); | |
} | |
function registerTasteTester() public isRegisteredUser(msg.sender) { | |
createTasteTester(msg.sender); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.7; | |
library Taste { | |
enum TastePreference{BITTER, SWEET, SALTY, SAVOURY, SOUR, NONE} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.7; | |
import "./TasteLibrary.sol"; | |
contract TasteTesterFactory { | |
event CreateTasteTester(address _address); | |
struct TasteTester { | |
Taste.TastePreference taste_preference; | |
} | |
TasteTester[] tasteTester_listing; | |
mapping(address => uint) tasteTester_mapping; | |
function createTasteTester(address _address) internal { | |
require(tasteTester_mapping[_address] == 0, "TasteTester for account already exists."); | |
TasteTester memory tasteTester = TasteTester({ | |
taste_preference: Taste.TastePreference.NONE | |
}); | |
tasteTester_listing.push(tasteTester); | |
tasteTester_mapping[_address] = tasteTester_listing.length; | |
emit CreateTasteTester(_address); | |
} | |
function hasTasteTester(address _address) public view returns(bool) { | |
return tasteTester_mapping[_address] != 0; | |
} | |
function getTasteTester(address _address) public view returns(Taste.TastePreference) { | |
require(tasteTester_mapping[_address] != 0, "TasteTester does not exist."); | |
TasteTester memory tasteTester = tasteTester_listing[tasteTester_mapping[_address]-1]; | |
return tasteTester.taste_preference; | |
} | |
function getCurrentTasteTester() public view returns(Taste.TastePreference) { | |
return getTasteTester(msg.sender); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.7; | |
contract UserFactory { | |
event CreateUser(address _address); | |
struct User { | |
string name; | |
string email; | |
} | |
User[] user_listing; | |
mapping(address => uint) user_mapping; | |
function createUser(address _address, string _name, string _email) internal { | |
require(user_mapping[_address] == 0, "User with given address already exists."); | |
assert(bytes(_name).length > 0); | |
assert(bytes(_email).length > 0); | |
User memory user = User({ | |
name: _name, | |
email: _email | |
}); | |
user_listing.push(user); | |
user_mapping[_address] = user_listing.length; | |
emit CreateUser(_address); | |
} | |
function hasUser(address _address) public view returns (bool) { | |
return user_mapping[_address] != 0; | |
} | |
function getUser(address _address) public view returns (string, string) { | |
require(user_mapping[_address] != 0, "User with given address does not exist."); | |
User memory user = user_listing[user_mapping[_address]-1]; | |
return (user.name, user.email); | |
} | |
function getCurrentUser() public view returns (string, string) { | |
require(user_mapping[msg.sender] != 0, "Current user does not exist."); | |
return getUser(msg.sender); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment