From 09cae94533b9797a72fd0e30140e98f3d8aa46c5 Mon Sep 17 00:00:00 2001 From: Scott Piriou <30843220+pscott@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:57:52 +0100 Subject: [PATCH] add more context on error; update readme and fix CI --- .github/workflows/lint.yml | 2 +- README.md | 7 +++---- src/verify.ts | 26 ++++++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 49ff8fe..2c98c9d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,4 +15,4 @@ jobs: cache: "yarn" - run: yarn --frozen-lockfile - run: yarn lint - - run: yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b \ No newline at end of file + - run: yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b -n sepolia \ No newline at end of file diff --git a/README.md b/README.md index ebaad6a..19cba3d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ yarn Screenshot 2024-11-05 at 14 38 22 - 5. Verify it ```sh @@ -40,19 +39,19 @@ yarn verify Screenshot 2024-11-05 at 14 40 30 - ## Example For testing purposes, we have a transaction that we have never broadcast, this way you can try it yourself. ```sh -yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b +yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b --network sepolia ``` ## What's going on under the hood? What this simple script does is fairly simple: + 1. First we use the code in `./src/index.ts` to parse the command and transform the hash to its hexadecimal format. 2. In `./src/verify.ts` we then query `https://mana.box` to get the information related to the hash that was given as input. 3. Next we display the information on your screen. -4. Finally, we hash all this information and checks that it corresponds to the hash given as input. If it does, we display a little check mark. \ No newline at end of file +4. Finally, we hash all this information and checks that it corresponds to the hash given as input. If it does, we display a little check mark. diff --git a/src/verify.ts b/src/verify.ts index b1139cb..15fe7d3 100644 --- a/src/verify.ts +++ b/src/verify.ts @@ -60,16 +60,22 @@ export async function verify(expectedHash: string, url: string, network: string) console.log(`Type: \`${json.type}\``); console.log(`Sender: \`${json.sender}\``); console.dir(json.data, { depth: null }); - if (type === 'vote') { - console.log('Authenticating vote...'); - console.log('Sender: ', json.sender); - computedHash = await ethTxClient.getVoteHash(json.sender, json.data); - } else if (type === 'propose') { - computedHash = await ethTxClient.getProposeHash(json.sender, json.data); - } else if (type === 'updateproposal') { - computedHash = await ethTxClient.getUpdateProposalHash(json.sender, json.data); - } else { - console.error('Invalid type specified. Use "vote", "proposal", or "updateProposal".'); + try { + if (type === 'vote') { + console.log('Authenticating vote...'); + console.log('Sender: ', json.sender); + computedHash = await ethTxClient.getVoteHash(json.sender, json.data); + } else if (type === 'propose') { + computedHash = await ethTxClient.getProposeHash(json.sender, json.data); + } else if (type === 'updateproposal') { + computedHash = await ethTxClient.getUpdateProposalHash(json.sender, json.data); + } else { + console.error('Invalid type specified. Use "vote", "proposal", or "updateProposal".'); + process.exit(1); + } + } catch (error) { + console.log(error); + console.error('\n❌ Error verifying hash. Are you sure you are using the correct network?\n'); process.exit(1); }