Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrate to snapshot.js 0.8-beta with ofetch support #735

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Oct 28, 2023

Following #702, which was reverted for safety, but found out later that the revert reason was unrelated to the PR.

This PR:

  • update the snapshot.js SDK to 0.8-betam with ofetch support
  • refactor the vp operation to handle the new error handling (getVp now always return a JSON-RPC error)
  • Throw a more structured error when failing to get Vp

Before the update, error looks like:

{
  "errors": [
    {
      "message": "Unexpected error value: { code: 500, message: \"unauthorized\", data: { reason: null, code: \"CALL_EXCEPTION\", method: \"aggregate((address,bytes)[])\", data: \"0x\", errorArgs: null, errorName: null, errorSignature: null, address: \"0xcA11bde05977b3631167028862bE2a173976CA11\", args: [Array], transaction: [Object] } }",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "vp"
      ]
    }
  ],
  "data": {
    "vp": null
  }
}

After update, looks like:

{
  "errors": [
    {
      "message": "failed to get voting power",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "vp"
      ],
      "extensions": {
        "code": 500,
        "message": "unauthorized",
        "data": {
          "reason": null,
          "code": "CALL_EXCEPTION",
          "method": "aggregate((address,bytes)[])",
          "data": "0x",
          "errorArgs": null,
          "errorName": null,
          "errorSignature": null,
          "address": "0xcA11bde05977b3631167028862bE2a173976CA11",
          "args": [
            [
              [
                "0xc23f41519d7dfadf9eed53c00f08c06cd5cdde54",
                "0x70a08231000000000000000000000000be551154399b14c30a609d4517b5897a82bc7d47"
              ]
            ]
          ],
          "transaction": {
            "data": "0x252dba42000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000c23f41519d7dfadf9eed53c00f08c06cd5cdde540000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002470a08231000000000000000000000000be551154399b14c30a609d4517b5897a82bc7d4700000000000000000000000000000000000000000000000000000000",
            "to": "0xcA11bde05977b3631167028862bE2a173976CA11"
          }
        }
      }
    }
  ],
  "data": {
    "vp": null
  }
}

Tested with following query (on testnet):

query Vp {
  vp(voter: "0xbe551154399b14c30A609D4517b5897a82BC7D47", 
    space: "karate-combat-stage-1.eth", 
    proposal: "0xac90046be202be13a689ea22dd38fbe1ac09731a0c5cdb85229bb0615ca2c10b") {
    vp
    vp_by_strategy
    vp_state
  }
}

@wa0x6e wa0x6e requested a review from ChaituVR October 28, 2023 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant