pragma solidity ^0.4.23; contract Shop { address owner = msg.sender; mapping (uint => Item) public items; //Items in the shop mapping (address => Item) public itemsOwned; mapping(address => uint) public balances; //Will represent the balances of a buyer //What an object item possesses struct Item{ string name; uint ID; uint price; uint quantity; //Add in other stuff like categories if needed later } //Basic modifier indicating that an owner can only use certain things modifier onlyOwner() { require(msg.sender == owner); _; } function setItem(string name, uint ID, uint price, uint quantity) public onlyOwner{ uint unitPrice = 1 ether; items[ID] = Item(name, ID, price, quantity); } function buy(uint ID) public payable { //Make sure the amount sent to buy item is correct //Is this a sufficient check to see if buyer has enough money? require(msg.value >= items[ID].price); itemsOwned[ID] = msg.sender; //How to reduce balance of the buyer who purchases the item??? } function getBuyers() public view returns (address[16]) { return buyers; } //Withdraw function function withdrawFunds() public { address payee = msg.sender; uint payment = balances[payee]; //Check if payment is positive require(payment > 0); balances[payee] = 0; //Move funds require(payee.send(payment)); } //Retrieve balance of a seller function balanceOf(address seller) public view returns (uint) { return balances[seller]; } }
0.4.18