ar-io / arns-service

Koa microservice that leverages Warp to support the ArNS Portal and ar.io observers.
https://api.arns.app
GNU Affero General Public License v3.0
19 stars 4 forks source link

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

Closed dtfiedler closed 5 months ago

dtfiedler commented 5 months ago

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"
  }
}