Supplier

Git Source

Author: Tinotenda Joe

This contract serves as a decentralized platform for suppliers to manage their raw materials in a supply chain protocol.

Following is just a simple explanation, consider implementing more complex logic in accordance with your needs.

State Variables

supplierRawMaterials

mapping(address => address[]) public supplierRawMaterials;

Functions

createRawMaterialPackage

Create a new raw material package

Constructor to set the initial storage

Ensure the proper access controls and error handling (if needed), add events to capture the important state changes TODO: Require checks can be added for inputs

function createRawMaterialPackage(
    bytes32 _description,
    uint256 _quantity,
    address _transporterAddr,
    address _manufacturerAddr
) public;

Parameters

NameTypeDescription
_descriptionbytes32the description of the raw material
_quantityuint256the quantity of the raw material
_transporterAddraddressthe address of the transporter
_manufacturerAddraddressthe address of the manufacturer

getNoOfPackagesOfSupplier

Get the number of packages of a supplier

This can be used to quickly check how many packages a supplier has TODO: Consider returning more detailed information about each package

function getNoOfPackagesOfSupplier() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256the number of packages of the supplier

getAllPackages

Get all packages of a supplier

Access controls can be added here to restrict this sensitive information TODO: Access Controls using OpenZeppelin's AccessControl.sol TODO: Consider returning more detailed information about each package

function getAllPackages() public view returns (address[] memory);

Returns

NameTypeDescription
<none>address[]an array of addresses of the packages of the supplier

Events

RawMaterialCreated

event RawMaterialCreated(address indexed rawMaterialAddress, address indexed supplier);