ItemManager()
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
contract ItemManager {
enum itemState{
Created, Paid, Delivered //created - 0, paid -1,..
}
struct Item {
string id;
uint price;
itemState state;
}
// to create a dataframe structure
mapping(uint => Item) public item_list;
uint item_index;
function createItem(string memory _id, uint _price) public {
item_list[item_index].id = _id;
item_list[item_index].price = _price;
item_list[item_index].state = itemState.Created;
item_index++;
}
function triggerPayment(uint _index) public payable {
require(item_list[_index].price == msg.value, "please pay exact full amount");
require(item_list[_index].state == itemState.Created,"Item is not available");
item_list[_index].state = itemState.Paid; //update state to paid
}
function triggerDeliver(uint _index) public {
require(item_list[_index].state == itemState.Paid,"Item is not for delivery");
item_list[_index].state == itemState.Delivered;
}
}
struct & enum
mapping
function createItem()
Last updated