Skip to content

Instantly share code, notes, and snippets.

View ac12644's full-sized avatar
⛓️
one block at a time

Abhishek Chauhan ac12644

⛓️
one block at a time
View GitHub Profile
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/math/SafeMath.sol';
contract Fundraiser is Ownable {
using SafeMath for uint256;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
function addFarmer(address account) public onlyFarmer {
_addFarmer(account);
}
function renounceFarmer() public {
_removeFarmer(_msgSender());
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
// Define a function 'fetchItemBufferOne' that fetches the data
function fetchItemBufferOne(uint256 _productCode)
public
view
returns (
uint256 itemstockUnit,
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
// 12th step in supply chain process
function sellItemByRetailer(uint256 _productCode, uint256 _price)
public
onlyRetailer // check _msgSender() belongs to RetailerRole
receivedByRetailer(_productCode)
verifyCaller(items[_productCode].ownerID) // check _msgSender() is ownerID
// 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)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
// 6th step in supply chain process
function processedItemByDistributor(uint256 _productCode, uint256 slices)
public
onlyDistributor // check _msgSender() belongs to DistributorRole
receivedByDistributor(_productCode)
verifyCaller(items[_productCode].ownerID) // check _msgSender() is owner
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
// 4th step in supply chain process
function shippedItemByFarmer(uint256 _productCode)
public
payable
onlyFarmer // check _msgSender() belongs to FarmerRole
purchasedByDistributor(_productCode)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
//2nd step of suppply chain process
function sellItemByFarmer(uint256 _productCode, uint256 _price)
public
onlyFarmer // check _msgSender() belongs to farmerRole
producedByFarmer(_productCode) // check items state has been produced
verifyCaller(items[_productCode].ownerID) // check _msgSender() is owner
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
// 1st step in supply chain process
function produceItemByFarmer(
uint256 _productCode,
string memory _originFarmName,
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
...
//Item State Modifiers
modifier producedByFarmer(uint256 _productCode) {
require(items[_productCode].itemState == State.ProduceByFarmer);
_;
}