Skip to content

Commit

Permalink
fix: update code to use imports properly
Browse files Browse the repository at this point in the history
Additionally, some code is refactored to simplify the usage of the SDK

Note: there is a build_index.sh script that must be run to build the artifacts needed to import. This script is temporary and should be replace by a CI job that publishes to npm.
  • Loading branch information
JayWhite2357 committed Nov 21, 2024
1 parent 2cc292d commit f5a6582
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 662 deletions.
36 changes: 21 additions & 15 deletions chainlink-functions/example/source.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
// Import the package
const SxTProofModule = await import("npm:sxt-chain-sdk");

// Extract the default export (SxTProof class)
const SxTProof = SxTProofModule.default;
const SxTSDK = await import(
"https://raw.githubusercontent.com/spaceandtimelabs/sxt-proof-of-sql-sdk/feat/import-sdk/chainlink-functions/source/index.js"
);

// Define test parameters
const queryString = 'SELECT SUM(BLOCK_NUMBER), COUNT(*) FROM ETHEREUM.BLOCKS';
const queryString = "SELECT SUM(BLOCK_NUMBER), COUNT(*) FROM ETHEREUM.BLOCKS";
const table = "ETHEREUM.BLOCKS";
// TODO: This is currently hardcoded. But, we need to make it dynamic.
const commitmentKey =
'0xca407206ec1ab726b2636c4b145ac28749505e273536fae35330b966dac69e86a4832a125c0464e066dd20add960efb518424c4f434b5320455448455245554d4a9e6f9b8d43f6ad008f8c291929dee201';
"0xca407206ec1ab726b2636c4b145ac28749505e273536fae35330b966dac69e86a4832a125c0464e066dd20add960efb518424c4f434b5320455448455245554d4a9e6f9b8d43f6ad008f8c291929dee201";

if (!secrets.apiKey) {
throw Error("Missing secret: apiKey");
throw Error("Missing secret: apiKey");
}

// Initialize the SxTProof instance
const proof = new SxTProof(queryString, commitmentKey, secrets.apiKey);
const proof = new SxTSDK.SxTClient(
"https://api.spaceandtime.dev/v1/prove",
"https://proxy.api.spaceandtime.dev/auth/apikey",
"https://rpc.testnet.sxt.network/",
secrets.apiKey,
);

try {
// Kick off the proof and await execution
const result = await proof.executeWorkflow();
console.log("Workflow completed successfully:", result);
return Functions.encodeString("Verified");
// Kick off the proof and await execution
const result = await proof.queryAndVerify(queryString, table, commitmentKey);
console.log("Workflow completed successfully:", result);
return Functions.encodeString("Verified");
} catch (error) {
console.log("Workflow failed: ", error);
return Functions.encodeString("Failed: ", error);
}
console.log("Workflow failed: ", error);
return Functions.encodeString("Failed: ", error);
}
6 changes: 6 additions & 0 deletions chainlink-functions/source/build_index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR

curl $1/sxt_proof_of_sql_sdk_wasm.js | cat - ./index_tail.js > ./index.js
curl $1/sxt_proof_of_sql_sdk_wasm_bg.wasm > ./sxt_proof_of_sql_sdk_wasm_bg.wasm
Loading

0 comments on commit f5a6582

Please sign in to comment.