Created
August 21, 2021 18:20
-
-
Save gokulstevee/e4ee8f5d8ae72b99552caf4d99fb2ef2 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.0+commit.26b70077.js&optimize=false&runs=200&gist=
This file contains hidden or 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
pragma solidity ^0.6.0; | |
contract ItemManager{ | |
enum ItemState {CREATED, PAID, DELIVERED} | |
struct ItemArray{ | |
string _itemName; | |
uint _itemPrice; | |
ItemState _state; | |
} | |
mapping(uint => ItemArray) items; | |
uint itemIndex; | |
event createItem(uint _itemIndex, string _itemName, ItemState _state); | |
function create(string memory _itemName, uint _price) public{ | |
items[itemIndex]._itemName = _itemName; | |
items[itemIndex]._itemPrice = _price; | |
items[itemIndex]._state = ItemState.CREATED; | |
emit createItem(itemIndex, items[itemIndex]._itemName, items[itemIndex]._state); | |
itemIndex++; | |
} | |
event payItem(uint _itemIndex, string _itemName, ItemState _state); | |
function pay(uint _itemIndex) payable public{ | |
require(items[_itemIndex]._state == ItemState.CREATED, "The Item is on process"); | |
require(items[_itemIndex]._itemPrice == msg.value, "Not enough amount"); | |
items[_itemIndex]._state = ItemState.PAID; | |
emit payItem(_itemIndex, items[_itemIndex]._itemName, items[_itemIndex]._state); | |
} | |
event deliverItem(uint _itemIndex, string _itemName, ItemState _state); | |
function deliver(uint _itemIndex) public{ | |
require(items[_itemIndex]._state == ItemState.PAID, "This item has not been paid"); | |
items[_itemIndex]._state = ItemState.DELIVERED; | |
emit deliverItem(_itemIndex, items[_itemIndex]._itemName, items[_itemIndex]._state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment