From 38069ca31026372d4f655cc23d38f58a0b8af8e0 Mon Sep 17 00:00:00 2001 From: samepant Date: Tue, 24 Sep 2024 10:09:49 -0400 Subject: [PATCH] add file input for publishing data --- packages/evm/tasks/enclave.ts | 40 +++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/packages/evm/tasks/enclave.ts b/packages/evm/tasks/enclave.ts index 7ddb6965..7d92f5fd 100644 --- a/packages/evm/tasks/enclave.ts +++ b/packages/evm/tasks/enclave.ts @@ -1,3 +1,4 @@ +import fs from "fs"; import { task, types } from "hardhat/config"; import type { TaskArguments } from "hardhat/types"; @@ -220,7 +221,8 @@ task("e3:activate", "Activate an E3 program") task("e3:publishInput", "Publish input for an E3 program") .addParam("e3Id", "Id of the E3 program") - .addParam("data", "data to publish") + .addOptionalParam("data", "data to publish") + .addOptionalParam("dataFile", "file containing data to publish") .setAction(async function (taskArguments: TaskArguments, hre) { const enclave = await hre.deployments.get("Enclave"); @@ -229,10 +231,14 @@ task("e3:publishInput", "Publish input for an E3 program") enclave.address, ); - const tx = await enclaveContract.publishInput( - taskArguments.e3Id, - taskArguments.data, - ); + let data = taskArguments.data; + + if (taskArguments.dataFile) { + const file = fs.readFileSync(taskArguments.dataFile); + data = file.toString(); + } + + const tx = await enclaveContract.publishInput(taskArguments.e3Id, data); console.log("Publishing input... ", tx.hash); await tx.wait(); @@ -242,7 +248,8 @@ task("e3:publishInput", "Publish input for an E3 program") task("e3:publishCiphertext", "Publish ciphertext output for an E3 program") .addParam("e3Id", "Id of the E3 program") - .addParam("data", "data to publish") + .addOptionalParam("data", "data to publish") + .addOptionalParam("dataFile", "file containing data to publish") .addParam("proof", "proof to publish") .setAction(async function (taskArguments: TaskArguments, hre) { const enclave = await hre.deployments.get("Enclave"); @@ -252,9 +259,16 @@ task("e3:publishCiphertext", "Publish ciphertext output for an E3 program") enclave.address, ); + let data = taskArguments.data; + + if (taskArguments.dataFile) { + const file = fs.readFileSync(taskArguments.dataFile); + data = file.toString(); + } + const tx = await enclaveContract.publishCiphertextOutput( taskArguments.e3Id, - taskArguments.data, + data, taskArguments.proof, ); @@ -266,7 +280,8 @@ task("e3:publishCiphertext", "Publish ciphertext output for an E3 program") task("e3:publishPlaintext", "Publish plaintext output for an E3 program") .addParam("e3Id", "Id of the E3 program") - .addParam("data", "data to publish") + .addOptionalParam("data", "data to publish") + .addOptionalParam("dataFile", "file containing data to publish") .addParam("proof", "proof to publish") .setAction(async function (taskArguments: TaskArguments, hre) { const enclave = await hre.deployments.get("Enclave"); @@ -276,9 +291,16 @@ task("e3:publishPlaintext", "Publish plaintext output for an E3 program") enclave.address, ); + let data = taskArguments.data; + + if (taskArguments.dataFile) { + const file = fs.readFileSync(taskArguments.dataFile); + data = file.toString(); + } + const tx = await enclaveContract.publishPlaintextOutput( taskArguments.e3Id, - taskArguments.data, + data, taskArguments.proof, );