Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity 0.5.10;
- contract FashionChecker {
- address owner;//address of the owner
- uint price;//price of a check
- struct Item {
- string name;
- string brand;
- string store;
- }
- mapping(string => bool)isgenuine;//keeps track if an article is registered
- mapping(string => Item)codetoitem;//key is the code of the article and the value is the item info
- mapping(address => string)storename;//key is address and returns as value the name of the store
- mapping(string => address)storeaddress;//key is name and returns as value the address of the store
- mapping(address => bool)isstore;//key is the address, if the address is registered the value will be true, else is false
- constructor () public payable {
- owner = msg.sender;
- }
- //requires that the function is called by the owner
- modifier onlyOwner() {
- require(msg.sender == owner);
- _;
- }
- //requires that the function is called by a store
- modifier onlyStore() {
- require(isstore[msg.sender] == true);
- _;
- }
- //returns true if the user is the owner and false otherwise
- function checkIfOwner() public view returns (bool) {
- return msg.sender == owner;
- }
- //returns true if the user has a store address and false otherwise
- function checkIfStore() public view returns (bool){
- return isstore[msg.sender];
- }
- //owner only function that registers the address of a store
- function addStore(address _storeaddr, string memory _storename) public onlyOwner {
- require(isstore[_storeaddr] == false);
- isstore[_storeaddr] = true;
- storename[_storeaddr] = _storename;
- storeaddress[_storename] = _storeaddr;
- }
- //owner only function that sets the price of a check
- function addCost(uint _price) public onlyOwner {
- price = _price * 1000000000000000000;
- }
- //returns the cost of a check
- function getCost() public view returns (uint) {
- return price;
- }
- //only owner removes an address of a store as registered
- function RemoveStore(string memory _storename) public onlyOwner {
- address addr = storeaddress[_storename];
- require(isstore[addr] == true);
- isstore[addr] = false;
- }
- //only store function that registers an item
- function addItem(string memory _code, string memory _name, string memory _brand) public onlyStore {
- Item memory item = Item(_name, _brand, storename[msg.sender]);
- codetoitem[_code] = item;
- isgenuine[_code] = true;
- }
- //checks if an item is registered
- function checkItem(string memory _code) public view returns (bool) {
- return isgenuine[_code];
- }
- //returns information about the item
- function returnItemInfo(string memory _code) public payable returns (string memory, string memory, string memory){
- require(msg.value == price);
- return (codetoitem[_code].name, codetoitem[_code].brand, codetoitem[_code].store);
- }
- //only owner, returns the balance of the contract
- function checkBalance() public view onlyOwner returns (uint){
- return address(this).balance;
- }
- //withdraw function for the owner to receive the money from the contract
- function withdraw() public payable onlyOwner {
- msg.sender.transfer(address(this).balance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement