-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemManager.sol
42 lines (35 loc) · 1.59 KB
/
ItemManager.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pragma solidity ^0.6.0;
import "./Ownable.sol";
import "./Item.sol";
contract ItemManager is Owneable {
struct S_Item {
Item _item;
ItemManager.SupplyChainSteps _step;
string _identifier;
}
mapping(uint => S_Item) public items;
uint index;
enum SupplyChainSteps {Created, Paid, Delivered}
event SupplyChainStep(uint _itemIndex, uint _step, address _address);
function createItem(string memory _identifier, uint _priceInWei) public onlyOwner{
Item item = new Item(this, _priceInWei, index);
items[index]._item = item;
items[index]._step = SupplyChainSteps.Created;
items[index]._identifier = _identifier;
emit SupplyChainStep(index, uint(items[index]._step), address(item));
index++;
}
function triggerPayment(uint _index) public payable {
Item item = items[_index]._item;
require(address(item) == msg.sender, "Only items are allowed to update themselves");
require(item.priceInWei() == msg.value, "Not fully paid yet");
require(items[_index]._step == SupplyChainSteps.Created, "Item is further in the supply chain");
items[_index]._step = SupplyChainSteps.Paid;
emit SupplyChainStep(_index, uint(items[_index]._step), address(item));
}
function triggerDelivery(uint _index) public onlyOwner {
require(items[_index]._step == SupplyChainSteps.Paid, "Item is further in the supply chain");
items[_index]._step = SupplyChainSteps.Delivered;
emit SupplyChainStep(_index, uint(items[_index]._step), address(items[_index]._item));
}
}