diff --git a/src/Pi.sol b/src/Pi.sol index eabaa5f..cc093f9 100644 --- a/src/Pi.sol +++ b/src/Pi.sol @@ -1,5 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; + import {OVMClient} from "@webisopen/ovm-contracts/src/OVMClient.sol"; import {ExecMode, Requirement, Specification} from "@webisopen/ovm-contracts/src/libraries/DataTypes.sol"; @@ -15,10 +16,7 @@ contract Pi is OVMClient { * @param OVMTaskAddress The address of the OVMTask contract. * @param admin The address of the admin. */ - constructor( - address OVMTaskAddress, - address admin - ) OVMClient(OVMTaskAddress, admin) { + constructor(address OVMTaskAddress, address admin) OVMClient(OVMTaskAddress, admin) { // set specification Specification memory spec; spec.name = "kallypi"; @@ -26,19 +24,12 @@ contract Pi is OVMClient { spec.description = "Calculate PI"; spec.environment = "python:3.7"; spec.repository = "https://github.com/kallydev/kallypi"; - spec - .repoTag = "0xb6a6502fa480fd1fb5bf95c1fb1366bcbc335a08356c2a97daf6bc44e9cc0253"; + spec.repoTag = "0xb6a6502fa480fd1fb5bf95c1fb1366bcbc335a08356c2a97daf6bc44e9cc0253"; spec.license = "WTFPL"; spec.entrypoint = "src/main.py"; - spec.requirement = Requirement({ - ram: "256mb", - disk: "5mb", - timeout: 600, - cpu: 1, - gpu: false - }); - spec - .apiABIs = '[{"request":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"},"getResponse":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"}}]'; + spec.requirement = Requirement({ram: "256mb", disk: "5mb", timeout: 600, cpu: 1, gpu: false}); + spec.apiABIs = + '[{"request":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"},"getResponse":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"}}]'; spec.royalty = 5; spec.execMode = ExecMode.JIT; @@ -50,17 +41,10 @@ contract Pi is OVMClient { * @param numDigits The number of digits to calculate for PI. * @return requestId The ID of the request returned by the OVMTasks contract. */ - function sendRequest( - uint256 numDigits - ) external payable returns (bytes32 requestId) { + function sendRequest(uint256 numDigits) external payable returns (bytes32 requestId) { // encode the data bytes memory data = abi.encode(numDigits); - requestId = _sendRequest( - msg.sender, - msg.value, - REQ_DETERMINISTIC, - data - ); + requestId = _sendRequest(msg.sender, msg.value, REQ_DETERMINISTIC, data); } /** @@ -69,10 +53,12 @@ contract Pi is OVMClient { * @param requestId The ID of the request. * @param data The response data to be set. */ - function setResponse( - bytes32 requestId, - bytes calldata data - ) external override recordResponse(requestId) onlyOVMTask { + function setResponse(bytes32 requestId, bytes calldata data) + external + override + recordResponse(requestId) + onlyOVMTask + { // parse and save the data fulfilled by the OVMTasks contract (bool success, string memory strPI) = _parseData(data); if (success) { @@ -87,9 +73,7 @@ contract Pi is OVMClient { * @param requestId The ID of the request. * @return The response data as a string in our pi calculation case. */ - function getResponse( - bytes32 requestId - ) external view returns (string memory) { + function getResponse(bytes32 requestId) external view returns (string memory) { return _responseData[requestId]; } @@ -99,9 +83,7 @@ contract Pi is OVMClient { * @return A tuple containing a boolean value indicating the success of the task execution * and a string representing the parsed data. */ - function _parseData( - bytes calldata data - ) internal pure returns (bool, string memory) { + function _parseData(bytes calldata data) internal pure returns (bool, string memory) { return abi.decode(data, (bool, string)); } }