Created
October 3, 2022 23:06
-
-
Save ac12644/34ff99f49f844c8d046fa49eedbbd0b2 to your computer and use it in GitHub Desktop.
This file contains 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
... | |
// 12th step in supply chain process | |
function sellItemByRetailer(uint256 _productCode, uint256 _price) | |
public | |
onlyRetailer // check _msgSender() belongs to RetailerRole | |
receivedByRetailer(_productCode) | |
verifyCaller(items[_productCode].ownerID) // check _msgSender() is ownerID | |
{ | |
items[_productCode].itemState = State.ForSaleByRetailer; | |
items[_productCode].productPrice = _price; | |
emit ForSaleByRetailer(_productCode); | |
} | |
// 13th step in supply chain process | |
function purchaseItemByConsumer(uint256 _productCode) | |
public | |
payable | |
onlyConsumer // check _msgSender() belongs to ConsumerRole | |
forSaleByRetailer(_productCode) | |
paidEnough(items[_productCode].productPrice) | |
checkValue(_productCode, payable(_msgSender())) | |
{ | |
items[_productCode].consumerID = _msgSender(); | |
address payable ownerAddressPayable = _make_payable( | |
items[_productCode].retailerID | |
); | |
ownerAddressPayable.transfer(items[_productCode].productPrice); | |
items[_productCode].ownerID = _msgSender(); | |
items[_productCode].consumerID = _msgSender(); | |
items[_productCode].itemState = State.PurchasedByConsumer; | |
itemsHistory[_productCode].RTC = block.number; | |
emit PurchasedByConsumer(_productCode); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment