-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update root on local fork automatically + fix chain bug (#18)
- Loading branch information
Showing
12 changed files
with
242 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
/.next | ||
/front/.next/ | ||
/out/ | ||
/front/script/register-root/latest-root.txt | ||
|
||
# production | ||
/build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const axios = require("axios"); | ||
const fs = require("fs"); | ||
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 = getLatestRoot(); | ||
|
||
if (latestRootSaved !== root) { | ||
fs.writeFileSync(latestRootFilePath, root, { flag: "w" }); | ||
console.log(`New latest root ${root} fetched.`); | ||
} | ||
} catch (e) { | ||
console.error( | ||
"Error while fetching the latest root for Sismo Connect, you seem to have lost your internet connection." | ||
); | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 10000)); | ||
} | ||
}; | ||
|
||
fetchHub(); | ||
|
||
module.exports = { latestRootFilePath, path, getLatestRoot }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
lastRoot=$1 | ||
|
||
# remove 0x prefix and leading zeros on a hex string | ||
remove_zeros() { | ||
awk '{sub(/^0x*/, "");}1' | awk '{sub(/^0*/, "");}1' | ||
} | ||
|
||
# get the available roots registry contract address | ||
# by calling the get function of the sismoConnectAddressesProvider contract | ||
availableRootsRegistryContractAddress=0x$(echo $(cast call 0x3Cd5334eB64ebBd4003b72022CC25465f1BFcEe6 "get(string)" "sismoConnectAvailableRootsRegistry") | remove_zeros) | ||
|
||
# get the owner of the roots registry contract | ||
# first remove the 0x prefix, then remove the leading zeros with awk | ||
rootsRegistryContractOwner=0x$(echo $(cast call $availableRootsRegistryContractAddress "owner()") | remove_zeros) | ||
|
||
# impersonate the owner of the roots registry contract | ||
cast rpc anvil_impersonateAccount $rootsRegistryContractOwner | ||
|
||
# register the root | ||
cast send $availableRootsRegistryContractAddress 'registerRoot(uint256)' $lastRoot --from $rootsRegistryContractOwner --unlocked |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { readFileSync } = require("fs"); | ||
const { spawnSync } = require("child_process"); | ||
const fetchHubExports = require("./fetch-hub"); | ||
|
||
const registerRoot = (root: string) => { | ||
const registerRootScriptPath = fetchHubExports.path.join(__dirname, "register-root.sh"); | ||
const child = spawnSync(`${registerRootScriptPath} ${root}`, { | ||
shell: true, | ||
}); | ||
|
||
if (child.status !== 0) { | ||
console.error(child.stderr.toString()); | ||
throw new Error("Error while registering root on the local fork"); | ||
} | ||
|
||
console.group(`Root ${root} successfully registered on the local fork`); | ||
}; | ||
|
||
const main = async () => { | ||
let root = fetchHubExports.getLatestRoot(); | ||
console.log(`Registering root ${root} on the local fork...`); | ||
registerRoot(root === "" ? "0x" : root); | ||
}; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.