pragma solidity ^0.4.18;
contract CryptoVideoGameItem {
address contractCreator = 0xC15d9f97aC926a6A29A681f5c19e2b56fd208f00;
address devFeeAddress = 0xC15d9f97aC926a6A29A681f5c19e2b56fd208f00;
address cryptoVideoGames = 0xdEc14D8f4DA25108Fd0d32Bf2DeCD9538564D069;
struct VideoGameItem {
string videoGameItemName;
address ownerAddress;
uint256 currentPrice;
uint parentVideoGame;
}
VideoGameItem[] videoGameItems;
modifier onlyContractCreator() {
require (msg.sender == contractCreator);
_;
}
bool isPaused;
/*
We use the following functions to pause and unpause the game.
*/
function pauseGame() public onlyContractCreator {
isPaused = true;
}
function unPauseGame() public onlyContractCreator {
isPaused = false;
}
function GetGamestatus() public view returns(bool) {
return(isPaused);
}
/*
This function allows users to purchase Video Game Item.
The price is automatically multiplied by 2 after each purchase.
Users can purchase multiple video game Items.
*/
function purchaseVideoGameItem(uint _videoGameItemId) public payable {
require(msg.value >= videoGameItems[_videoGameItemId].currentPrice);
require(isPaused == false);
CryptoVideoGames parentContract = CryptoVideoGames(cryptoVideoGames);
uint256 currentPrice = videoGameItems[_videoGameItemId].currentPrice;
uint256 excess = msg.value - currentPrice;
// Calculate the 10% value
uint256 devFee = (currentPrice / 10);
uint256 parentOwnerFee = (currentPrice / 10);
address parentOwner = parentContract.getVideoGameOwner(videoGameItems[_videoGameItemId].parentVideoGame);
address newOwner = msg.sender;
// Calculate the video game owner commission on this sale & transfer the commission to the owner.
uint256 commissionOwner = currentPrice - devFee - parentOwnerFee; // => 80%
videoGameItems[_videoGameItemId].ownerAddress.transfer(commissionOwner);
// Transfer the 10% commission to the developer
devFeeAddress.transfer(devFee); // => 10%
parentOwner.transfer(parentOwnerFee); // => 10%
newOwner.transfer(excess);
// Update the video game owner and set the new price
videoGameItems[_videoGameItemId].ownerAddress = newOwner;
videoGameItems[_videoGameItemId].currentPrice = mul(videoGameItems[_videoGameItemId].currentPrice, 2);
}
/*
This function can be used by the owner of a video game item to modify the price of its video game item.
He can make the price lesser than the current price only.
*/
function modifyCurrentVideoGameItemPrice(uint _videoGameItemId, uint256 _newPrice) public {
require(_newPrice > 0);
require(videoGameItems[_videoGameItemId].ownerAddress == msg.sender);
require(_newPrice < videoGameItems[_videoGameItemId].currentPrice);
videoGameItems[_videoGameItemId].currentPrice = _newPrice;
}
// This function will return all of the details of the Video Game Item
function getVideoGameItemDetails(uint _videoGameItemId) public view returns (
string videoGameItemName,
address ownerAddress,
uint256 currentPrice,
uint parentVideoGame
) {
VideoGameItem memory _videoGameItem = videoGameItems[_videoGameItemId];
videoGameItemName = _videoGameItem.videoGameItemName;
ownerAddress = _videoGameItem.ownerAddress;
currentPrice = _videoGameItem.currentPrice;
parentVideoGame = _videoGameItem.parentVideoGame;
}
// This function will return only the price of a specific Video Game Item
function getVideoGameItemCurrentPrice(uint _videoGameItemId) public view returns(uint256) {
return(videoGameItems[_videoGameItemId].currentPrice);
}
// This function will return only the owner address of a specific Video Game
function getVideoGameItemOwner(uint _videoGameItemId) public view returns(address) {
return(videoGameItems[_videoGameItemId].ownerAddress);
}
/**
@dev Multiplies two numbers, throws on overflow. => From the SafeMath library
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
@dev Integer division of two numbers, truncating the quotient. => From the SafeMath library
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
// This function will be used to add a new video game by the contract creator
function addVideoGameItem(string videoGameItemName, address ownerAddress, uint256 currentPrice, uint parentVideoGame) public onlyContractCreator {
videoGameItems.push(VideoGameItem(videoGameItemName,ownerAddress,currentPrice, parentVideoGame));
}
}
contract CryptoVideoGames {
// This function will return only the owner address of a specific Video Game
function getVideoGameOwner(uint _videoGameId) public view returns(address) {
}
}
{
"compilationTarget": {
"CryptoVideoGameItem.sol": "CryptoVideoGameItem"
},
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"constant":true,"inputs":[],"name":"GetGamestatus","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_videoGameItemId","type":"uint256"}],"name":"getVideoGameItemCurrentPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_videoGameItemId","type":"uint256"}],"name":"getVideoGameItemOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_videoGameItemId","type":"uint256"}],"name":"purchaseVideoGameItem","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"pauseGame","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"videoGameItemName","type":"string"},{"name":"ownerAddress","type":"address"},{"name":"currentPrice","type":"uint256"},{"name":"parentVideoGame","type":"uint256"}],"name":"addVideoGameItem","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_videoGameItemId","type":"uint256"},{"name":"_newPrice","type":"uint256"}],"name":"modifyCurrentVideoGameItemPrice","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_videoGameItemId","type":"uint256"}],"name":"getVideoGameItemDetails","outputs":[{"name":"videoGameItemName","type":"string"},{"name":"ownerAddress","type":"address"},{"name":"currentPrice","type":"uint256"},{"name":"parentVideoGame","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unPauseGame","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]