Created
July 2, 2018 14:32
-
-
Save maxaleks/7be13f80511e7135661a4c2fff1ffcf9 to your computer and use it in GitHub Desktop.
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
Game { | |
Gold gold; | |
Details details; | |
buyDetailForEther(type) payable { | |
uint256 price = details.getPrice(type); | |
gold.buyGoldRemote(msg.value, price); | |
address(gold).transfer(msg.value); // transfer ether to Gold contract | |
details.buyDetail(msg.sender, type); | |
gold.transfer(details, price); // transfer gold to Details contract | |
} | |
} | |
Gold { // erc20 | |
mapping(address => uint256) ownedTokens; | |
uint256 price; | |
buyGoldRemote(sender, etherValue, amount) onlyGame { // onlyGame - modificator, that allows call this method only by Game | |
require(amount * price <= etherValue); | |
ownedTokens[msg.sender] += amount; // msg.sender == Game | |
} | |
} | |
Details { // erc721 | |
// there some logic from erc721 standard | |
uint256[] prices; | |
struct Detail { | |
uint8 type; | |
} | |
buyDetail(sender, type) onlyGame { | |
Detail detail = Detail(type); | |
ownedTokens[sender].push(detail); | |
} | |
getDetailPrice(type) { | |
return prices[type]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment