diff --git a/package-lock.json b/package-lock.json index 67d7897..a6e796b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "": { "dependencies": { "@openzeppelin/contracts": "^5.0.2", - "@webisopen/ovm-contracts": "^1.1.0" + "@webisopen/ovm-contracts": "^1.2.0" } }, "node_modules/@openzeppelin/contracts": { @@ -15,9 +15,9 @@ "integrity": "sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA==" }, "node_modules/@webisopen/ovm-contracts": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@webisopen/ovm-contracts/-/ovm-contracts-1.1.0.tgz", - "integrity": "sha512-ybYP2ahm6QAHFi4p0978lGMBJR1fQKrm5X2qlsC3HIDfjbzXAWC/V/99lhXUzaTrkoInrSxAOoYjSaawWwQZ/w==" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@webisopen/ovm-contracts/-/ovm-contracts-1.2.0.tgz", + "integrity": "sha512-5Zjn0+5TTQ1Eqa5wjqixcdrNZemY2X+79jycBwi1p13UFSEtJAkHoK5+hEqvJJVFo1fOwXO3Ke7v0Fmkp5c/Kg==" } }, "dependencies": { @@ -27,9 +27,9 @@ "integrity": "sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA==" }, "@webisopen/ovm-contracts": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@webisopen/ovm-contracts/-/ovm-contracts-1.1.0.tgz", - "integrity": "sha512-ybYP2ahm6QAHFi4p0978lGMBJR1fQKrm5X2qlsC3HIDfjbzXAWC/V/99lhXUzaTrkoInrSxAOoYjSaawWwQZ/w==" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@webisopen/ovm-contracts/-/ovm-contracts-1.2.0.tgz", + "integrity": "sha512-5Zjn0+5TTQ1Eqa5wjqixcdrNZemY2X+79jycBwi1p13UFSEtJAkHoK5+hEqvJJVFo1fOwXO3Ke7v0Fmkp5c/Kg==" } } } diff --git a/package.json b/package.json index 46f0f65..ae3bb4f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "@webisopen/ovm-contracts": "^1.1.0", + "@webisopen/ovm-contracts": "^1.2.0", "@openzeppelin/contracts": "^5.0.2" } } diff --git a/src/Pi.sol b/src/Pi.sol index ccf6f28..a924736 100644 --- a/src/Pi.sol +++ b/src/Pi.sol @@ -1,13 +1,8 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier:UNLICENSED pragma solidity ^0.8.13; import {OVMClient} from "@webisopen/ovm-contracts/src/OVMClient.sol"; -import { - Arch, - ExecMode, - Requirement, - Specification -} from "@webisopen/ovm-contracts/src/libraries/DataTypes.sol"; +import {Arch, ExecMode, Requirement, Specification} from "@webisopen/ovm-contracts/src/libraries/DataTypes.sol"; event ResponseParsed(bytes32 requestId, bool success, string strPI); @@ -21,21 +16,29 @@ 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 = "ovm-cal-pi"; spec.version = "1.0.0"; spec.description = "Calculate PI"; - spec.environment = "python:3.7"; + spec.environments = "python:3.7"; spec.repository = "https://github.com/webisopen/ovm-cal-pi"; spec.repoTag = "9231c80a6cba45c8ff9a1d3ba19e8596407e8850"; 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":"sendRequest","inputs":[{"name":"numDigits","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"stateMutability":"payable"},"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; spec.arch = Arch.ARM64; @@ -48,10 +51,17 @@ 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 + ); } /** @@ -60,12 +70,10 @@ 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) { @@ -80,7 +88,9 @@ 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]; } @@ -90,7 +100,9 @@ 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)); } }