Skip to content

Load network #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ PRIVATE_KEY_ATTESTER2=
PRIVATE_KEY_ATTESTER3=
PRIVATE_KEY_DEPLOYER=

PINATA_API_KEY=7824585a98fe36414d68
PINATA_SECRET_API_KEY=41a53a837879721969e73008d91180df30dbc66097c7f75f08cd5489176b43ea
IPFS_HOST=https://othentic.mypinata.cloud/ipfs/

OTHENTIC_BOOTSTRAP_ID=12D3KooWBNFG1QjuF3UKAKvqhdXcxh9iBmj88cM5eU2EK5Pa91KB
OTHENTIC_BOOTSTRAP_SEED=97a64de0fb18532d4ce56fb35b730aedec993032b533f783b04c9175d465d9bf
Expand All @@ -32,3 +29,6 @@ L2_CHAIN=
# ELASTIC_URL=
# ELASTIC_USERNAME=
# ELASTIC_PASSWORD=

LOAD_NETWORK_API_KEY=
BUNDLER_GATEWAY_HOST=
4 changes: 1 addition & 3 deletions Execution_Service/.env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
PINATA_API_KEY=
PINATA_SECRET_API_KEY=
IPFS_HOST=
OTHENTIC_CLIENT_RPC_ADDRESS=
PERFORMER_ADDRESS=
PRIVATE_KEY_PERFORMER=

ATTESTATION_CENTER_ADDRESS=
AVS_GOVERNANCE_ADDRESS=
LOAD_NETWORK_API_KEY=
101 changes: 101 additions & 0 deletions Execution_Service/package-lock.json

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

1 change: 1 addition & 0 deletions Execution_Service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@pinata/sdk": "^2.1.0",
"@types/axios": "^0.14.0",
"axios": "^1.1.3",
"bundler-upload-sdk": "^2.1.1",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"ethers": "^6.11.1",
Expand Down
20 changes: 0 additions & 20 deletions Execution_Service/src/dal.service.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
require('dotenv').config();
const pinataSDK = require("@pinata/sdk");
const { ethers } = require('ethers');
const { getSigningKey, sign } = require('./utils/mcl');

var pinataApiKey='';
var pinataSecretApiKey='';
var rpcBaseAddress='';
var performerAddress='';
var privateKey='';



function init() {
pinataApiKey = process.env.PINATA_API_KEY;
pinataSecretApiKey = process.env.PINATA_SECRET_API_KEY;
rpcBaseAddress = process.env.OTHENTIC_CLIENT_RPC_ADDRESS;
performerAddress = process.env.PERFORMER_ADDRESS;
privateKey = process.env.PRIVATE_KEY_PERFORMER;
Expand Down Expand Up @@ -49,22 +43,8 @@ async function sendTask(proofOfTask, data, taskDefinitionId) {
}
}

async function publishJSONToIpfs(data) {
var proofOfTask = '';
try {
const pinata = new pinataSDK(pinataApiKey, pinataSecretApiKey);
const response = await pinata.pinJSONToIPFS(data);
proofOfTask = response.IpfsHash;
console.log(`proofOfTask: ${proofOfTask}`);
}
catch (error) {
console.error("Error making API request to pinataSDK:", error);
}
return proofOfTask;
}

module.exports = {
init,
publishJSONToIpfs,
sendTask
}
40 changes: 40 additions & 0 deletions Execution_Service/src/loadnetwork.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require('dotenv').config();

let bundler;

async function init() {
if (!process.env.LOAD_NETWORK_API_KEY) {
throw new Error("Missing LOAD_NETWORK_API_KEY in environment variables.");
}

const { BundlerSDK } = await import('bundler-upload-sdk');
bundler = new BundlerSDK('https://upload.onchain.rs/', process.env.LOAD_NETWORK_API_KEY);
}

async function publishJSON(data) {
try {
if (!bundler) await init();

const buffer = Buffer.from(JSON.stringify(data), 'utf-8');
const txHash = await bundler.upload([
{
file: buffer,
tags: {
'content-type': 'application/json',
},
},
]);

console.log(`✅ Uploaded JSON. TxHash: ${txHash}`);
console.log(`🔗 View at: https://resolver.bot/bundle/${txHash}/0`);
return txHash;
} catch (error) {
console.error('❌ Failed to upload JSON:', error.message);
return '';
}
}

module.exports = {
init,
publishJSON,
};
8 changes: 4 additions & 4 deletions Execution_Service/src/task.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const CustomError = require("./utils/validateError");
const CustomResponse = require("./utils/validateResponse");
const oracleService = require("./oracle.service");
const dalService = require("./dal.service");

const router = Router()
const loadNetworkService = require("./loadnetwork.service");

router.post("/execute", async (req, res) => {
console.log("Executing task");
Expand All @@ -16,10 +16,10 @@ router.post("/execute", async (req, res) => {

const result = await oracleService.getPrice("ETHUSDT");
result.price = req.body.fakePrice || result.price;
const cid = await dalService.publishJSONToIpfs(result);
const transactionHash = await loadNetworkService.publishJSON(result);
const data = "hello";
await dalService.sendTask(cid, data, taskDefinitionId);
return res.status(200).send(new CustomResponse({proofOfTask: cid, data: data, taskDefinitionId: taskDefinitionId}, "Task executed successfully"));
await dalService.sendTask(transactionHash, data, taskDefinitionId);
return res.status(200).send(new CustomResponse({proofOfTask: transactionHash, data: data, taskDefinitionId: taskDefinitionId}, "Task executed successfully"));
} catch (error) {
console.log(error)
return res.status(500).send(new CustomError("Something went wrong", {}));
Expand Down
47 changes: 47 additions & 0 deletions Execution_Service/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ buffer@^5.5.0, buffer@^5.6.0:
base64-js "^1.3.1"
ieee754 "^1.1.13"

bundler-upload-sdk@^2.1.1:
version "2.1.1"
resolved "https://registry.npmjs.org/bundler-upload-sdk/-/bundler-upload-sdk-2.1.1.tgz"
integrity sha512-BzBHTGA2YoMDDmdLl45j9Lq/MxhnJm85k/m6wy1By0M04ZkZEUbDrdPbZ45+WJA20iWU1Rb4oH2H3fNnVYuVRA==
dependencies:
form-data "^4.0.0"
node-fetch "^3.3.2"

[email protected]:
version "3.1.2"
resolved "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz"
Expand Down Expand Up @@ -282,6 +290,11 @@ cors@^2.8.5:
object-assign "^4"
vary "^1"

data-uri-to-buffer@^4.0.0:
version "4.0.1"
resolved "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz"
integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==

debug@^4:
version "4.3.4"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz"
Expand Down Expand Up @@ -421,6 +434,14 @@ express@^4.18.1:
utils-merge "1.0.1"
vary "~1.1.2"

fetch-blob@^3.1.2, fetch-blob@^3.1.4:
version "3.2.0"
resolved "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz"
integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==
dependencies:
node-domexception "^1.0.0"
web-streams-polyfill "^3.0.3"

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz"
Expand Down Expand Up @@ -464,6 +485,13 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

formdata-polyfill@^4.0.10:
version "4.0.10"
resolved "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz"
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
dependencies:
fetch-blob "^3.1.2"

[email protected]:
version "0.2.0"
resolved "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz"
Expand Down Expand Up @@ -784,6 +812,20 @@ [email protected]:
resolved "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz"
integrity sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==

node-domexception@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz"
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==

node-fetch@^3.3.2:
version "3.3.2"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz"
integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==
dependencies:
data-uri-to-buffer "^4.0.0"
fetch-blob "^3.1.4"
formdata-polyfill "^4.0.10"

nodemon@^3.1.0:
version "3.1.0"
resolved "https://registry.npmjs.org/nodemon/-/nodemon-3.1.0.tgz"
Expand Down Expand Up @@ -1082,6 +1124,11 @@ vary@^1, vary@~1.1.2:
resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==

web-streams-polyfill@^3.0.3:
version "3.3.3"
resolved "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz"
integrity sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==

[email protected]:
version "8.17.1"
resolved "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz"
Expand Down
Loading