Created
August 8, 2022 19:17
-
-
Save fassko/53cc162659806ca324a7884f74ad7364 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.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //SPDX-License-Identifier: Unlicense | |
| pragma solidity ^0.8.0; | |
| import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol"; | |
| import "hardhat/console.sol"; | |
| // 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db,0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB,0x617F2E2fD72FD9D5503197092aC168c91465E7f2 | |
| enum ShipmentStatus { | |
| InUkraine, // Registered in Ukraine | |
| LeftUkraine, // Navigating in Black Sea | |
| ArrivedInTurkey, // Arrived in Turkey | |
| LeftTurkey, // Left Turkey | |
| ArrivedInDestinationCountry // Arrived to the destination country | |
| } | |
| struct Shipment { | |
| string destination; | |
| ShipmentStatus status; | |
| } | |
| contract GrainExport is Ownable { | |
| address private ukraine; | |
| address private russia; | |
| address private turkey; | |
| address private un; | |
| bool private ukraineSigned; | |
| bool private russiaSigned; | |
| bool private turkeySigned; | |
| bool private unSigned; | |
| uint256 private currentShipmentId; | |
| mapping(uint256 => Shipment) shipments; | |
| event SignedByUkraine(); | |
| event SignedByRussia(); | |
| event SignedByTurkey(); | |
| event SignedByUN(); | |
| event AgreementSigned(); | |
| event ShipmentCreated(uint256 shipmentId); | |
| event ShipmentLeftUkraine(uint256 shipmentId); | |
| event ShipmentArrivedInTurkey(uint256 shipmentId); | |
| event ShipmentExamined(uint256 shipmentId); | |
| event ShipmentArrivedInDestination(uint256 shipmentId, string destination); | |
| modifier agreementSigned() { | |
| // require(ukraineSigned, "Ukraine not signed"); | |
| // require(russiaSigned, "Russia not signed"); | |
| // require(turkeySigned, "Turkey not signed"); | |
| // require(unSigned, "United Nations not signed"); | |
| _; | |
| } | |
| constructor(address _ukraine, address _russia, address _turkey, address _un) { | |
| ukraine = _ukraine; | |
| russia = _russia; | |
| turkey = _turkey; | |
| un = _un; | |
| } | |
| function sign() external { | |
| console.log("Signer address", msg.sender); | |
| require(msg.sender == ukraine || msg.sender == russia || msg.sender == turkey || msg.sender == un, "Unknown signer"); | |
| if (msg.sender == ukraine) { | |
| ukraineSigned = true; | |
| emit SignedByUkraine(); | |
| } | |
| if (msg.sender == russia) { | |
| russiaSigned = true; | |
| emit SignedByRussia(); | |
| } | |
| if (msg.sender == turkey) { | |
| turkeySigned = true; | |
| emit SignedByTurkey(); | |
| } | |
| if (msg.sender == un) { | |
| unSigned = true; | |
| emit SignedByUN(); | |
| } | |
| if (ukraineSigned && russiaSigned && turkeySigned && unSigned) { | |
| emit AgreementSigned(); | |
| } | |
| } | |
| // -- Shipment -- // | |
| function getShipment(uint256 shipmentId) external view returns(Shipment memory) { | |
| return shipments[shipmentId]; | |
| } | |
| function createShipment(string memory _destination) external agreementSigned { | |
| require(msg.sender == ukraine, "Caller is not Ukraine"); | |
| currentShipmentId++; | |
| shipments[currentShipmentId] = Shipment(_destination, ShipmentStatus.InUkraine); | |
| console.log("Shipment created", currentShipmentId); | |
| emit ShipmentCreated(currentShipmentId); | |
| } | |
| function leftUkraine(uint256 shipmentId) external agreementSigned { | |
| require(msg.sender == ukraine, "Caller is not Ukraine"); | |
| shipments[shipmentId].status = ShipmentStatus.LeftUkraine; | |
| console.log("Shipment left Ukraine", shipmentId); | |
| emit ShipmentLeftUkraine(shipmentId); | |
| } | |
| function arrivesInTurkey(uint256 shipmentId) external agreementSigned { | |
| require(msg.sender == turkey, "Caller is not Turkey"); | |
| shipments[shipmentId].status = ShipmentStatus.ArrivedInTurkey; | |
| console.log("Shipment arrived in Turkey", shipmentId); | |
| emit ShipmentArrivedInTurkey(shipmentId); | |
| } | |
| function examined(uint256 shipmentId) external agreementSigned { | |
| require(msg.sender == turkey, "Caller is not Turkey"); | |
| shipments[shipmentId].status = ShipmentStatus.LeftTurkey; | |
| console.log("Shipment examined", shipmentId); | |
| emit ShipmentExamined(shipmentId); | |
| } | |
| function arrivedInDestination(uint256 shipmentId) external agreementSigned { | |
| require(msg.sender == un, "Caller is not United Nations"); | |
| shipments[shipmentId].status = ShipmentStatus.ArrivedInDestinationCountry; | |
| console.log("Shipment", shipmentId, "arrived in", shipments[shipmentId].destination); | |
| emit ShipmentArrivedInDestination(shipmentId, shipments[shipmentId].destination); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment