Commodity

Git Source

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

NameTypeDescription
_manufacturerAddraddressThe address of the manufacturer creating the batch.
_descriptionbytes32A brief description of the batch.
_rawAddraddress[]An array of addresses representing the raw materials used in the batch.
_quantityuint256The quantity of commodity in the batch.
_transporterAddraddress[]An array of addresses representing the transporters involved in the shipment.
_receiverAddraddressThe address of the receiver of the batch.
RcvrTypeuint256An 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

NameTypeDescription
_manufacturerAddraddressThe address of the manufacturer.
_descriptionbytes32A brief description of the commodity batch.
_rawAddraddress[]An array of addresses representing the raw materials used in the batch.
_quantityuint256The quantity of commodity in the batch.
_transporterAddraddress[]An array of addresses representing the transporters involved in the shipment.
_distributoraddressThe address of the distributor.
_finalConsumeraddressThe address of the finalConsumer.

getWDC

Returns the addresses of the wholesaler, distributor, and finalConsumer.

function getWDC() public view returns (address[3] memory WDP);

Returns

NameTypeDescription
WDPaddress[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

NameTypeDescription
<none>uint256A 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

NameTypeDescription
_transporterAddraddressThe 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

NameTypeDescription
_transporterAddraddressThe 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

NameTypeDescription
_receiverAddraddressThe address of the receiver (either wholesaler or distributor).

Returns

NameTypeDescription
<none>uint256A 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

NameTypeDescription
receiveraddressThe address of the distributor.
senderaddressThe 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

NameTypeDescription
receiveraddressThe 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

NameTypeDescription
receiveraddressThe address of the finalConsumer.
senderaddressThe 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

NameTypeDescription
receiveraddressThe 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
}