Commodity
This contract represents a commodity in a supply chain.
It includes functions for managing the commodity's status and the parties involved in its shipment.
State Variables
Owner
address Owner;
description
bytes32 description;
rawMaterials
address[] rawMaterials;
transporters
address[] transporters;
manufacturer
address manufacturer;
wholesaler
address wholesaler;
distributor
address distributor;
finalConsumer
address finalConsumer;
quantity
uint256 quantity;
status
commodityStatus status;
txnContractAddress
address txnContractAddress;
Functions
constructor
Creates a new commodity batch.
constructor(
address _manufacturerAddr,
bytes32 _description,
address[] memory _rawAddr,
uint256 _quantity,
address[] memory _transporterAddr,
address _receiverAddr,
uint256 RcvrType
);
Parameters
Name | Type | Description |
---|---|---|
_manufacturerAddr | address | The address of the manufacturer creating the batch. |
_description | bytes32 | A brief description of the batch. |
_rawAddr | address[] | An array of addresses representing the raw materials used in the batch. |
_quantity | uint256 | The quantity of commodity in the batch. |
_transporterAddr | address[] | An array of addresses representing the transporters involved in the shipment. |
_receiverAddr | address | The address of the receiver of the batch. |
RcvrType | uint256 | An identifier for the type of receiver (1 for wholesaler, 2 for distributor). |
getCommodityInfo
Returns information about the commodity batch.
function getCommodityInfo()
public
view
returns (
address _manufacturerAddr,
bytes32 _description,
address[] memory _rawAddr,
uint256 _quantity,
address[] memory _transporterAddr,
address _distributor,
address _finalConsumer
);
Returns
Name | Type | Description |
---|---|---|
_manufacturerAddr | address | The address of the manufacturer. |
_description | bytes32 | A brief description of the commodity batch. |
_rawAddr | address[] | An array of addresses representing the raw materials used in the batch. |
_quantity | uint256 | The quantity of commodity in the batch. |
_transporterAddr | address[] | An array of addresses representing the transporters involved in the shipment. |
_distributor | address | The address of the distributor. |
_finalConsumer | address | The address of the finalConsumer. |
getWDC
Returns the addresses of the wholesaler, distributor, and finalConsumer.
function getWDC() public view returns (address[3] memory WDP);
Returns
Name | Type | Description |
---|---|---|
WDP | address[3] | An array of 3 addresses representing the wholesaler, distributor, and finalConsumer. |
getBatchIDStatus
Returns the current status of the commodity batch.
function getBatchIDStatus() public view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | A uint representing the current status of the commodity batch. |
pickCommodity
Updates the status of the commodity batch when it is picked up by a transporter.
function pickCommodity(address _transporterAddr) public;
Parameters
Name | Type | Description |
---|---|---|
_transporterAddr | address | The address of the transporter picking up the commodity. |
updateTransporterArray
Adds a transporter to the array of transporters involved in the shipment.
function updateTransporterArray(address _transporterAddr) public;
Parameters
Name | Type | Description |
---|---|---|
_transporterAddr | address | The address of the transporter to add. |
receivedCommodity
Updates the status of the commodity batch when it is received by a wholesaler or distributor.
function receivedCommodity(address _receiverAddr) public returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_receiverAddr | address | The address of the receiver (either wholesaler or distributor). |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | A uint representing the new status of the commodity batch. |
sendWtoD
Updates the distributor address and status of the commodity batch when it is sent from the wholesaler to the distributor.
function sendWtoD(address receiver, address sender) public;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address of the distributor. |
sender | address | The address of the wholesaler. |
receivedWtoD
Updates the status of the commodity batch when it is received by the distributor from the wholesaler.
function receivedWtoD(address receiver) public;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address of the distributor. |
sendDtoC
Updates the finalConsumer address and status of the commodity batch when it is sent from the distributor to the finalConsumer.
function sendDtoC(address receiver, address sender) public;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address of the finalConsumer. |
sender | address | The address of the distributor. |
receivedDtoC
Updates the status of the commodity batch when it is received by the finalConsumer from the distributor.
function receivedDtoC(address receiver) public;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address of the finalConsumer. |
Events
ShippmentUpdate
Emitted when there is an update to the shipment status.
event ShippmentUpdate(
address indexed BatchID, address indexed Shipper, address indexed Receiver, uint256 TransporterType, uint256 Status
);
Errors
UnAuthorised_PickUp
error UnAuthorised_PickUp();
Only_Wholesaler_or_Distributor_Authorised
error Only_Wholesaler_or_Distributor_Authorised();
Product_not_picked_up_yet
error Product_not_picked_up_yet();
Wholesaler_is_not_Authorised
error Wholesaler_is_not_Authorised();
Distributor_is_not_Authorised
error Distributor_is_not_Authorised();
FinalConsumer_is_not_Authorised
error FinalConsumer_is_not_Authorised();
Package_at_Manufacturer
error Package_at_Manufacturer();
Enums
commodityStatus
Represents the status of a commodity in the supply chain.
enum commodityStatus {
atManufacturer,
pickedForW,
pickedForD,
deliveredAtW,
deliveredAtD,
pickedForC,
deliveredAtC
}