Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ArslanKathia/6c2b432fc6dfa493d70774c3d3ff9b67 to your computer and use it in GitHub Desktop.
Save ArslanKathia/6c2b432fc6dfa493d70774c3d3ff9b67 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.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HealthSupplyChain{
address public manufacturer;
address public distributor;
address public recipient;
uint public shipmentDate;
uint public deliveryDate;
uint public quantity;
bool public delivered;
event ShipmentCreated(address indexed manufacturer,address indexed distributor,uint indexed shipmentDate,uint quantity);
event ShipmentDelivered(address indexed distributor,address indexed recipient,uint indexed deliveryDate,uint quantity,bool isDelivered);
constructor(){
manufacturer = msg.sender;
}
modifier onlyManufacturer(){
require(msg.sender == manufacturer,"Only Manufacturer create the shipment");
_;
}
modifier onlyDistributor(){
require(msg.sender== distributor,"Only Distributor create delivery of shipment");
_;
}
function createShipment(address _distributor,uint _shipmentDate,uint _quantity) public onlyManufacturer{
distributor = _distributor;
shipmentDate = _shipmentDate;
quantity = _quantity;
emit ShipmentCreated(manufacturer,distributor,shipmentDate,quantity);
}
function deliverShipment(address _recipient,uint _deliveryDate,uint _quantity) public onlyDistributor{
require(shipmentDate>0,"Shipment has not created yet!");
recipient = _recipient;
deliveryDate = _deliveryDate;
quantity = _quantity;
delivered = true;
emit ShipmentDelivered(distributor,recipient,deliveryDate,quantity,delivered);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment