Skip to content

Commit

Permalink
feat: update spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Atlasoin committed Oct 29, 2024
1 parent 5d49be3 commit 64a7446
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"@webisopen/ovm-contracts": "^1.1.0",
"@webisopen/ovm-contracts": "^1.2.0",
"@openzeppelin/contracts": "^5.0.2"
}
}
58 changes: 35 additions & 23 deletions src/Pi.sol
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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;
Expand All @@ -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
);
}

/**
Expand All @@ -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) {
Expand All @@ -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];
}

Expand All @@ -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));
}
}

0 comments on commit 64a7446

Please sign in to comment.