Skip to content

Commit

Permalink
feat: remove notion of gnosis + try opening latest root file
Browse files Browse the repository at this point in the history
  • Loading branch information
yum0e committed Jul 26, 2023
1 parent adc3523 commit c2ea423
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
20 changes: 15 additions & 5 deletions front/script/register-root/fetch-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@ const path = require("path");

const latestRootFilePath = path.join(__dirname, "latest-root.txt");

const getLatestRoot = (): string => {
try {
return fs.readFileSync(latestRootFilePath, "utf-8") as string;
} catch (e: any) {
return "";
}
};

const fetchHub = async () => {
while (true) {
try {
const res = (await axios(
" https://hub.sismo.io/available-data/gnosis/hydra-s2?latest=true&isOnChain=true"
)) as { data: { items: [{ identifier: string }] } };
const root = res.data?.items?.[0].identifier;
const latestRootSaved = fs.readFileSync(latestRootFilePath, "utf-8") as string;

const latestRootSaved = getLatestRoot();

if (latestRootSaved !== root) {
fs.writeFileSync(latestRootFilePath, root);
console.log(`New latest root ${root} on Gnosis`);
fs.writeFileSync(latestRootFilePath, root, { flag: "w" });
console.log(`New latest root ${root} fetched.`);
}
} catch (e) {
console.error(
"Error while fetching the latest root on Gnosis network, you seem to have lost your internet connection."
"Error while fetching the latest root for Sismo Connect, you seem to have lost your internet connection."
);
}
await new Promise((resolve) => setTimeout(resolve, 10000));
Expand All @@ -27,4 +37,4 @@ const fetchHub = async () => {

fetchHub();

module.exports = { latestRootFilePath, path };
module.exports = { latestRootFilePath, path, getLatestRoot };
4 changes: 2 additions & 2 deletions front/script/register-root/register-root.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

lastRootOnGnosis=$1
lastRoot=$1

# remove 0x prefix and leading zeros on a hex string
remove_zeros() {
Expand All @@ -19,4 +19,4 @@ rootsRegistryContractOwner=0x$(echo $(cast call $availableRootsRegistryContractA
cast rpc anvil_impersonateAccount $rootsRegistryContractOwner

# register the root
cast send $availableRootsRegistryContractAddress 'registerRoot(uint256)' $lastRootOnGnosis --from $rootsRegistryContractOwner --unlocked
cast send $availableRootsRegistryContractAddress 'registerRoot(uint256)' $lastRoot --from $rootsRegistryContractOwner --unlocked
5 changes: 1 addition & 4 deletions front/script/register-root/register-root.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Script used to fetch the latest root sent on Gnosis
// and register it in the local fork chain

const { readFileSync } = require("fs");
const { spawnSync } = require("child_process");
const fetchHubExports = require("./fetch-hub");
Expand All @@ -20,7 +17,7 @@ const registerRoot = (root: string) => {
};

const main = async () => {
const root = readFileSync(fetchHubExports.latestRootFilePath, "utf-8") as string;
let root = fetchHubExports.getLatestRoot();
console.log(`Registering root ${root} on the local fork...`);
registerRoot(root === "" ? "0x" : root);
};
Expand Down

0 comments on commit c2ea423

Please sign in to comment.