Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

feat(PE-5540): recursive state traversal endpoint #101

Merged
merged 4 commits into from
Feb 1, 2024

Conversation

dtfiedler
Copy link
Collaborator

@dtfiedler dtfiedler commented Jan 30, 2024

This allows for traversing nested objects of contract states. It is a separate endpoint to make it clear it is traversing state of a contract. To avoid unbound recursion (specifically for unknown contracts that could have a gnarly state), we set the max depth of the path to 3 params.

Examples:

observations/:epochStartHeight

curl http://localhost:3000/v1/contract/_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8/state/observations/1353206 | jq '.'
{
  "contractTxId": "_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8",
  "result": {
    "failureSummaries": {
      "NdZ3YRwMB2AMwwFYjKn1g88Y9nRybTo0qhS1ORq_E7g": [
        "M0WP8KSzCvKpzC-HPF1WcddLgGaL9J4DGi76iMnhrN4",
        "xN_aVln30LmoCffwmk5_kRkcyQZyZWy1o_TNtM_CTm0",
        "1H7WZIWhzwTH9FIcnuMqYkTsoyv1OTfGa_amvuYwrgo"
      ]
    },
    "reports": {
      "1H7WZIWhzwTH9FIcnuMqYkTsoyv1OTfGa_amvuYwrgo": "uDaaxpwivLuZR2KFDmcnlOIwyLc8a2DW2Uw6R60AeDY",
      "M0WP8KSzCvKpzC-HPF1WcddLgGaL9J4DGi76iMnhrN4": "10a3ZlqZTAbEl_t4dtkDFsiielkHSfM32G-0YUyeAr0",
      "xN_aVln30LmoCffwmk5_kRkcyQZyZWy1o_TNtM_CTm0": "4BRUUPDC6jhdCLfTtCs8BVr7Eam9uRccktQITVAgeac"
    }
  },
  "sortKey": "000001353765,0000000000000,b42b4698345a3e5499cd22df961d88c97bf731c63ddf4627b0183e924aefc4ee",
  "evaluationOptions": {
    "sourceType": "arweave"
  }
}

observations/:epochStartHeight/reports

curl http://localhost:3000/v1/contract/_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8/state/observations/1353206/reports | jq '.'
{
  "contractTxId": "_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8",
  "result": {
    "1H7WZIWhzwTH9FIcnuMqYkTsoyv1OTfGa_amvuYwrgo": "uDaaxpwivLuZR2KFDmcnlOIwyLc8a2DW2Uw6R60AeDY",
    "M0WP8KSzCvKpzC-HPF1WcddLgGaL9J4DGi76iMnhrN4": "10a3ZlqZTAbEl_t4dtkDFsiielkHSfM32G-0YUyeAr0",
    "xN_aVln30LmoCffwmk5_kRkcyQZyZWy1o_TNtM_CTm0": "4BRUUPDC6jhdCLfTtCs8BVr7Eam9uRccktQITVAgeac"
  },
  "sortKey": "000001353765,0000000000000,b42b4698345a3e5499cd22df961d88c97bf731c63ddf4627b0183e924aefc4ee",
  "evaluationOptions": {
    "sourceType": "arweave"
  }
}

gateways/:gatwayAddress

curl http://localhost:3000/v1/contract/_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8/state/gateways/1H7WZIWhzwTH9FIcnuMqYkTsoyv1OTfGa_amvuYwrgo | jq '.'
{
  "contractTxId": "_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8",
  "result": {
    "end": 0,
    "observerWallet": "1H7WZIWhzwTH9FIcnuMqYkTsoyv1OTfGa_amvuYwrgo",
    "operatorStake": 95048,
    "settings": {
      "fqdn": "permagate.io",
      "label": "Permagate",
      "note": "Owned and managed by @dtfiedler - if it breaks, find him.",
      "port": 443,
      "properties": "FH1aVetOoulPGqgYukj0VE0wIhDy90WiQoV3U2PeY44",
      "protocol": "https"
    },
    "start": 1252209,
    "stats": {
      "failedConsecutiveEpochs": 0,
      "passedEpochCount": 17,
      "submittedEpochCount": 2,
      "totalEpochParticipationCount": 25,
      "totalEpochsPrescribedCount": 21
    },
    "status": "joined",
    "vaults": {}
  },
  "sortKey": "000001353765,0000000000000,b42b4698345a3e5499cd22df961d88c97bf731c63ddf4627b0183e924aefc4ee",
  "evaluationOptions": {
    "sourceType": "arweave"
  }
}

gateways/:gatwayAddress/stats

curl http://localhost:3000/v1/contract/_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8/state/gateways/1H7WZIWhzwTH9FIcnuMqYkTsoyv1OTfGa_amvuYwrgo/stats | jq '.'
{
  "contractTxId": "_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8",
  "result": {
    "failedConsecutiveEpochs": 0,
    "passedEpochCount": 17,
    "submittedEpochCount": 2,
    "totalEpochParticipationCount": 25,
    "totalEpochsPrescribedCount": 21
  },
  "sortKey": "000001353765,0000000000000,b42b4698345a3e5499cd22df961d88c97bf731c63ddf4627b0183e924aefc4ee",
  "evaluationOptions": {
    "sourceType": "arweave"
  }
}

This allows for traversing nested objects, specifically on contract states. We should keep this in draft until we know that any consumers are not dependent on the reponse key
@dtfiedler dtfiedler changed the title feat(PE-5540): recursive object handler feat(PE-5540): recursive state traversal Jan 30, 2024
@dtfiedler dtfiedler changed the title feat(PE-5540): recursive state traversal feat(PE-5540): recursive state traversal endpoint Jan 30, 2024
@dtfiedler dtfiedler marked this pull request as ready for review January 30, 2024 23:25
@dtfiedler dtfiedler requested a review from a team as a code owner January 30, 2024 23:25
Comment on lines +338 to +340
deprecated: true
summary: Returns the field in the contract state for a given transaction id. For traversing contract state, use /contract/{contractTxId}/state/{nestedPath}
description: Returns the field in the contract state for a given transaction id. For traversing contract state, use /contract/{contractTxId}/state/{nestedPath}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just marking our existing one layer deep handler as deprecated in favor of the new one

@@ -17,7 +17,7 @@
"start:prod": "yarn build && node dist/app.js",
"build": "yarn clean && yarn && npx tsc --project ./tsconfig.json",
"clean": "rimraf [ node_modules dist cache ]",
"test:docker": "docker compose up --exit-code-from test-runner --build",
"test:docker": "docker compose --env-file=.env.test up --exit-code-from test-runner --build",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kunstmusik - per your request!

@fedellen fedellen self-requested a review January 31, 2024 16:12
object,
path,
}: {
object: any; // TODO: scope this to a type that can be traversed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: handle any or eslint squelch

Copy link
Contributor

@fedellen fedellen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the tests 🤩

@dtfiedler dtfiedler merged commit b63bdd2 into main Feb 1, 2024
6 checks passed
@dtfiedler dtfiedler deleted the PE-5540-recursive-fields-handler branch February 1, 2024 01:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants