Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. pragma solidity 0.5.10;
  2.  
  3. contract FashionChecker {
  4.  
  5. address owner;//address of the owner
  6. uint price;//price of a check
  7.  
  8. struct Item {
  9. string name;
  10. string brand;
  11. string store;
  12. }
  13.  
  14. mapping(string => bool)isgenuine;//keeps track if an article is registered
  15. mapping(string => Item)codetoitem;//key is the code of the article and the value is the item info
  16. mapping(address => string)storename;//key is address and returns as value the name of the store
  17. mapping(string => address)storeaddress;//key is name and returns as value the address of the store
  18. mapping(address => bool)isstore;//key is the address, if the address is registered the value will be true, else is false
  19.  
  20. constructor () public payable {
  21. owner = msg.sender;
  22. }
  23.  
  24. //requires that the function is called by the owner
  25. modifier onlyOwner() {
  26. require(msg.sender == owner);
  27. _;
  28. }
  29.  
  30. //requires that the function is called by a store
  31. modifier onlyStore() {
  32. require(isstore[msg.sender] == true);
  33. _;
  34. }
  35.  
  36. //returns true if the user is the owner and false otherwise
  37. function checkIfOwner() public view returns (bool) {
  38. return msg.sender == owner;
  39. }
  40.  
  41. //returns true if the user has a store address and false otherwise
  42. function checkIfStore() public view returns (bool){
  43. return isstore[msg.sender];
  44. }
  45.  
  46. //owner only function that registers the address of a store
  47. function addStore(address _storeaddr, string memory _storename) public onlyOwner {
  48. require(isstore[_storeaddr] == false);
  49. isstore[_storeaddr] = true;
  50. storename[_storeaddr] = _storename;
  51. storeaddress[_storename] = _storeaddr;
  52.  
  53. }
  54.  
  55. //owner only function that sets the price of a check
  56. function addCost(uint _price) public onlyOwner {
  57. price = _price * 1000000000000000000;
  58. }
  59.  
  60. //returns the cost of a check
  61. function getCost() public view returns (uint) {
  62. return price;
  63. }
  64.  
  65. //only owner removes an address of a store as registered
  66. function RemoveStore(string memory _storename) public onlyOwner {
  67. address addr = storeaddress[_storename];
  68. require(isstore[addr] == true);
  69. isstore[addr] = false;
  70. }
  71.  
  72. //only store function that registers an item
  73. function addItem(string memory _code, string memory _name, string memory _brand) public onlyStore {
  74. Item memory item = Item(_name, _brand, storename[msg.sender]);
  75. codetoitem[_code] = item;
  76. isgenuine[_code] = true;
  77. }
  78.  
  79. //checks if an item is registered
  80. function checkItem(string memory _code) public view returns (bool) {
  81. return isgenuine[_code];
  82. }
  83.  
  84. //returns information about the item
  85. function returnItemInfo(string memory _code) public payable returns (string memory, string memory, string memory){
  86. require(msg.value == price);
  87. return (codetoitem[_code].name, codetoitem[_code].brand, codetoitem[_code].store);
  88. }
  89.  
  90. //only owner, returns the balance of the contract
  91. function checkBalance() public view onlyOwner returns (uint){
  92. return address(this).balance;
  93. }
  94.  
  95. //withdraw function for the owner to receive the money from the contract
  96. function withdraw() public payable onlyOwner {
  97. msg.sender.transfer(address(this).balance);
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement