Skip to content

Instantly share code, notes, and snippets.

@ac12644
Created October 3, 2022 22:58
Show Gist options
  • Save ac12644/df302b6ac1f06eadb4d47df1d93caf4b to your computer and use it in GitHub Desktop.
Save ac12644/df302b6ac1f06eadb4d47df1d93caf4b to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
// 9th step in supply chain process
function purchaseItemByRetailer(uint256 _productCode)
public
payable
onlyRetailer // check _msgSender() belongs to RetailerRole
forSaleByDistributor(_productCode)
paidEnough(items[_productCode].productPrice)
checkValue(_productCode, payable(_msgSender()))
{
address payable ownerAddressPayable = _make_payable(
items[_productCode].distributorID
);
ownerAddressPayable.transfer(items[_productCode].productPrice);
items[_productCode].ownerID = _msgSender();
items[_productCode].retailerID = _msgSender();
items[_productCode].itemState = State.PurchasedByRetailer;
itemsHistory[_productCode].DTR = block.number;
emit PurchasedByRetailer(_productCode);
}
// 10th step in supply chain process
function shippedItemByDistributor(uint256 _productCode)
public
onlyDistributor // check _msgSender() belongs to DistributorRole
purchasedByRetailer(_productCode)
verifyCaller(items[_productCode].distributorID) // check _msgSender() is distributorID
{
items[_productCode].itemState = State.ShippedByDistributor;
emit ShippedByDistributor(_productCode);
}
// 11th step in supply chain process
function receivedItemByRetailer(uint256 _productCode)
public
onlyRetailer // check _msgSender() belongs to RetailerRole
shippedByDistributor(_productCode)
verifyCaller(items[_productCode].ownerID) // check _msgSender() is ownerID
{
items[_productCode].itemState = State.ReceivedByRetailer;
emit ReceivedByRetailer(_productCode);
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment