Skip to content

Adding API Endpoints

Pratham Rawat edited this page Mar 17, 2021 · 1 revision

The Tezos API structure can be seen in ingestor/src/main/resources/tezos.json.

Here are the contents of the file:

{
  "chain-version": "mainnet",
  "expected-block-time": "60s",
  "head-token": "head",
  "name": "tezos",
  "sources": [
    {
      "name": "block",
      "order": 0,
      "outputs": [
        {
          "name": "hash",
          "paths": [
            "hash"
          ],
          "type": "path-attribute"
        },
        {
          "name": "height",
          "paths": [
            "header.level"
          ],
          "type": "path-attribute"
        }
      ],
      "pattern": "chains/main/blocks/{height}",
      "aliases": [
        "chains/main/blocks/{hash}"
      ]
    },
    {
      "name": "operations",
      "order": 1,
      "outputs": [
        {
          "attributes": [
            "contract",
            "delegate",
            "baker"
          ],
          "name": "contracthash",
          "type": "leaf-attribute"
        },
        {
          "attributes": [
            "delegate"
          ],
          "name": "delegatehash",
          "type": "leaf-attribute"
        }
      ],
      "pattern": "chains/main/blocks/{hash}/operations",
      "aliases": [
        "chains/main/blocks/{height}/operations"
      ]
    },
    {
      "name": "contract",
      "order": 2,
      "outputs": [],
      "pattern": "chains/main/blocks/{hash}/context/contracts/{contracthash}",
      "aliases": [
        "chains/main/blocks/{height}/context/contracts/{contracthash}"
      ],
      "skip-on-failure": true
    },
    {
      "name": "delegate",
      "order": 3,
      "outputs": [],
      "pattern":"chains/main/blocks/{hash}/context/delegates/{delegatehash}",
      "skip-on-failure": true,
      "aliases": [
        "chains/main/blocks/{height}/context/delegates/{delegatehash}"
      ]
    },
    {
      "name": "baking_rights",
      "order": 4,
      "outputs": [
        {
          "attributes": [
            "level",
            "delegate",
            "priority",
            "estimated_time"
          ],
          "name": "baking_priority",
          "type": "leaf-attribute"
        }
      ],
      "pattern": "chains/main/blocks/{hash}/helpers/baking_rights",
      "skip-on-failure": true,
      "aliases": [
        "chains/main/blocks/{height}/helpers/baking_rights"
      ]
    },
    {
      "name": "endorsing_rights",
      "order": 5,
      "outputs": [],
      "pattern": "chains/main/blocks/{hash}/helpers/endorsing_rights",
      "skip-on-failure": true,
      "aliases": [
        "chains/main/blocks/{height}/helpers/endorsing_rights"
      ]
    },
    {
      "name": "ballot_list",
      "order": 6,
      "outputs": [],
      "pattern": "chains/main/blocks/{hash}/votes/ballot_list",
      "skip-on-failure": true,
      "aliases": [
        "chains/main/blocks/{height}/votes/ballot_list"
      ]
    },
    {
      "name": "current_proposal",
      "order": 7,
      "outputs": [],
      "pattern": "chains/main/blocks/{hash}/votes/current_proposal",
      "skip-on-failure": true,
      "aliases": [
        "chains/main/blocks/{height}/votes/current_proposal"
      ]
    },
    {
      "name": "current_quorum",
      "order": 8,
      "outputs": [],
      "pattern": "chains/main/blocks/{hash}/votes/current_quorum",
      "skip-on-failure": true,
      "aliases": [
        "chains/main/blocks/{height}/votes/current_quorum"
      ]
    },
    {
      "name": "listings",
      "order": 9,
      "outputs": [],
      "pattern": "chains/main/blocks/{hash}/votes/listings",
      "skip-on-failure": true,
      "aliases": [
        "chains/main/blocks/{height}/votes/listings"
      ]
    }
  ]
}

Additional queries can be added by appending more objects to the sources list, retaining the form seen.

Let's dissect a query for better understanding:

    {
      "name": "block",
      "order": 0,
      "outputs": [
        {
          "name": "hash",
          "paths": [
            "hash"
          ],
          "type": "path-attribute"
        },
        {
          "name": "height",
          "paths": [
            "header.level"
          ],
          "type": "path-attribute"
        }
      ],
      "pattern": "chains/main/blocks/{height}",
      "aliases": [
        "chains/main/blocks/{hash}"
      ]
    }
  • The name of the query is just an internal identifier.
  • The order defines the order in which the query will be called upon among the entire list of queries.
  • The outputs list stores variables which will be used to define further queries. Here, we define a height and hash attribute. These attributes are used within this same block query, as well as in the rest of the queries.
  • The pattern defines the query endpoint itself, using {} to escape the variables.
  • And finally, aliases is a list which contains different endpoints that will lead to the same data.

Going back to the outputs list:

  • name defines the internal identified, which is also the name used when referencing it as a variable.
  • type defines the way that this variable is used in this query. leaf-attribute means it will be stored as a query output, while path-attribute means that it will be used in the current path.

Judging by whether an attribute is defined as leaf or path, the data structure changes:

        {
          "name": "hash",
          "paths": [
            "hash"
          ],
          "type": "path-attribute"
        },
        {
          "attributes": [
            "contract",
            "delegate",
            "baker"
          ],
          "name": "contracthash",
          "type": "leaf-attribute"
        }
Clone this wiki locally