calculateAverage(uint256 a, uint256 b) returns (uint256 c): This function takes in two uint256 and returns their average.
getBit(uint256 num, uint position) returns (uint8): This function retrieves the bit (0 or 1) at the specified position, counting from right towards left in the binary representation of num. The counting of position is expected to start from 1. If the specified position exceeds the position of the last bit with a value of 1 in the binary representation, the function reverts.
sendEth(address to) payable: This function sends the received amount of ETH to to. The function is expected to work even if the to is the solution contract address but not if to is the sender.
A shipment service is having trouble tracking orders, which is causing issues for customers. To make things better, they are moving their database to a smart contract-based blockchain solution. This will make the process more transparent and efficient, and help with order management.
Process:
Here
The smart contract must contain the following public functions:
shipWithPin(address customerAddress, uint pin) public: his function can only be accessed by the owner (warehouse manager) and is used to mark an order as dispatched. The owner provides the customer's address and a four-digit OTP (pin) between 999 and 10,000 to verify the order.
acceptOrder(uint pin) public returns (): This function can only be accessed by the customer. After receiving the shipment at their address, the customer can mark the order as accepted by entering the OTP (pin) provided to them.
checkStatus(address customerAddress) public returns (string): This function can only be accessed by the customer. The owner can also access this function, and can view the status of any customer. After receiving the shipment at their address, the customer can mark the order as accepted by entering the OTP (pin) provided to them.
totalCompletedDeliveries(address customerAddress) public returns (uint):This function enables customers to determine the number of successfully completed deliveries to their specific address. By providing their address, customers can retrieve the total count of completed deliveries. The owner can also use this function to check the number of successfully completed deliveries for any address.
Implement the required smart contract to help the shipment service migrate the database.
Example 1