package
0.1.3
Repository: https://github.com/vocdoni/census3.git
Documentation: pkg.go.dev

# README

API endpoints

Endpoints:


API Info

GET /info

Show information about the API service.

  • 📥 response:
{
    "supportedChains": [
        {
            "chainID": 5,
            "shortName": "gor",
            "name": "Goerli"
        },
        {
            "chainID": 137,
            "shortName": "matic",
            "name": "Polygon Mainnet"
        },
        {
            "chainID": 80001,
            "shortName": "maticmum",
            "name": "Mumbai"
        },
        {
            "chainID": 1,
            "shortName": "eth",
            "name": "Ethereum Mainnet"
        }
    ]
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
500error encoding API info5023

Tokens

GET /tokens

List of already added tokens.

Pagination URL params

URL keyDescriptionExample
pageSize(optional) Defines the number of results per page. By default, 100.?pageSize=2
nextCursor(optional) When is defined, it is used to get the page results, going forward. By default, "".?nextCursor=0x1234
prevCursor(optional) When is defined, it is used to get the page results, going backwards. By default, "".?prevCursor=0x1234

The maximus default page size is 10, but if you provide a page size of -1, the endpoint will return all the results, and it does not require to be paginated.

  • 📥 response:
{
    "tokens": [
        {
            "ID": "0x1324",
            "type": "erc20",
            "decimals": 18,
            "startBlock": 123456,
            "symbol": "$",
            "totalSupply": "21323",
            "name": "Amazing token",
            "synced": true|false,
            "defaultStrategy": 1,
            "tags": "testTag1,testTag2",
            "chainID": 1,
            "externalID": "",
            "chainAddress": "eth:0x1234",
            "iconURI": "http://...png"
        }
    ],
    "pagination": {
        "nextCursor": "",
        "prevCursor": "0x1234",
        "pageSize": 10
    }
}

If tags is empty, it will be ommited.

If externalID is empty, it will be ommited.

  • ⚠️ errors:
HTTP StatusMessageInternal error
204no tokens found4007
400malformed pagination params4022
500error getting tokens information5005
500error encoding tokens5011

GET /tokens/types

List the supported token types.

  • 📥 response:
{
    "supportedTypes": [
        "erc20", 
        "erc721", 
        "erc777", 
        "erc1155", 
        "nation3", 
        "wANT", 
        "poap"
    ]
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
500error encoding supported tokens types5012

POST /tokens

Creates a new token in the database to be scanned. It gets the token information from the provider associated to the token type defined. If the creation success the token will be scanned in the next scanner iteration. The scan process status can be checked getting the token information.

Important: When a token is created, the API also creates a simple strategy with just the holders of that token, which is assigned to it as defaultStrategy.

  • 📤 request:
{
    "ID": "0x1234",
    "type": "erc20|erc721|erc777|erc1155|nation3|wANT|poap",
    "tags": "testTag1,testTag2",
    "chainID": 1,
    "externalID": "" // id for external holders providers
}

tags attribute is optional.

externalID URL parameter is optional by default, but required for external provided tokens like POAPs.

  • ⚠️ errors:
 HTTP StatusMessageInternal error
400malformed token information4000
409token already created4009
400chain ID provided not supported4013
500the token cannot be created5000
500error getting token information5004
500error initialising web3 client5019

GET /tokens/{tokenID}?chainID={chainID}&externalID={externalID}

Returns the information about the token referenced by the provided ID and chain ID, the external ID is optional.

chainID URL parameter is mandatory.

externalID URL parameter is optional by default, but required for external provided tokens like POAPs.

  • 📥 response:
{
    "ID": "0x1324",
    "type": "erc20",
    "size": 120,
    "decimals": 18,
    "startBlock": 123456,
    "symbol": "$",
    "totalSupply": "21323",
    "name": "Amazing token",
    "status": {
        "atBlock": 12345,
        "synced": true|false,
        "progress": 87
    },
    "defaultStrategy": 1,
    "tags": "testTag1,testTag2",
    "chainID": 1,
    "externalID": "",
    "chainAddress": "eth:0x1234",
    "iconURI": "http://...png"
}

If tags is empty, it will be ommited.

If externalID is empty, it will be ommited.

  • ⚠️ errors:
HTTP StatusMessageInternal error
400malformed token information4001
400malformed chain ID4018
404no token found4003
500error getting token information5004
500error encoding token5010
500chain ID provided not supported5013
500error initialising web3 client5019
500error getting number of token holders5020
500error getting last block number from web3 endpoint5021

GET /tokens/{tokenID}/holders/{holderID}?chainID={chainID}&externalID={externalID}

Returns the holder balance if the holder ID is already registered in the database as a holder of the token ID and chain ID provided, the external ID is optional.

chainID URL parameter is mandatory.

externalID URL parameter is optional by default, but required for external provided tokens like POAPs.

  • 📥 response:
{
    "balance": "1234567890"
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
400malformed token information4001
400malformed chain ID4018
404no token found4003
404token holder not found for the token provided4023
500error getting token holders5006

Strategies

GET /strategies

Returns the ID's list of the strategies registered.

Pagination URL params

URL keyDescriptionExample
pageSize(optional) Defines the number of results per page. By default, 100.?pageSize=2
nextCursor(optional) When is defined, it is used to get the page results, going forward. By default, "".?nextCursor=3
prevCursor(optional) When is defined, it is used to get the page results, going backwards. By default, "".?prevCursor=1

The maximus default page size is 10, but if you provide a page size of -1, the endpoint will return all the results, and it does not require to be paginated

  • 📥 response:
{
    "strategies": [
        {
            "ID": 1,
            "alias": "default MON strategy",
            "predicate": "MON",
            "uri": "ipfs://...",
            "tokens": {
                "MON": {
                    "ID": "0x1234",
                    "chainID": 5,
                    "chainAddress": "gor:0x1234",
                    "externalID": "mon_id_on_external_holder_provider"
                }
            }
        },
        {
            "ID": 2,
            "alias": "default ANT strategy",
            "predicate": "ANT",
            "uri": "ipfs://...",
            "tokens": {
                "ANT": {
                    "ID": "0x1234",
                    "chainID": 1,
                    "chainAddress": "eth:0x1234" 
                }
            }
        },
        {
            "ID": 3,
            "alias": "default USDC strategy",
            "predicate": "USDC",
            "uri": "ipfs://...",
            "tokens": {
                "USDC": {
                    "ID": "0x1234",
                    "chainID": 1,
                    "chainAddress": "eth:0x1234"
                }
            }
        },
        {
            "ID": 4,
            "alias": "strategy_alias",
            "predicate": "MON AND (ANT OR USDC)",
            "uri": "ipfs://...",
            "tokens": {
                "MON": {
                    "ID": "0x1234",
                    "chainID": 5,
                    "chainAddress": "gor:0x1234",
                    "externalID": "mon_id_on_external_holder_provider"
                },
                "ANT": {
                    "ID": "0x1234",
                    "chainID": 1,
                    "chainAddress": "eth:0x1234",
                    "minBalance": "1"
                },
                "USDC": {
                    "ID": "0x1234",
                    "chainID": 1,
                    "chainAddress": "eth:0x1234"
                }
            }
        }
    ],
    "pagination": {
        "nextCursor": "",
        "prevCursor": "1",
        "pageSize": 10
    }
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
204-4008
400malformed pagination params4022
500error getting strategies information5008
500error encoding strategies5016

POST /strategies

Stores a new strategy based on the defined combination of tokens provided, these tokens must be registered previously.

  • 📤 request:
    {
        "alias": "test_strategy",
        "predicate": "(wANT OR ANT) AND USDC",
        "tokens": {
            "wANT": {
                "ID": "0x1324",
                "chainID": 1,
                "minBalance": "10000"
            },
            "ANT": {
                "ID": "0x1324",
                "chainID": 5,
            },
            "USDC": {
                "ID": "0x1324",
                "chainID": 1,
                "minBalance": "50"
            },
        }
    }
  • 📥 response:
{
    "strategyID": 1
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
404no token found4003
400malformed strategy provided4014
400the predicate provided is not valid4015
400the predicate includes tokens that are not included in the request4016
500error encoding strategy info5015
500error creating strategy5025

POST /strategies/import/{cid}

Imports a strategy from IPFS downloading it with the cid provided in background. The strategy import will fail if the strategy tokens are not previously created in the database.

  • 📥 response:
{
    "queueID": "0123456789abcdef0123456789abcdef01234567"
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
400malformed strategy provided4014
500error encoding strategy info5015

GET /strategies/import/queue/{queueID}

Returns the information of the strategy that are in the creation queue.

  • 📥 response:
{
    "done": true,
    "error": {
        "code": 0,
        "error": "error message or null"
    },
    "strategy": { /* <same_get_strategy_response> */ }
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
404strategy not found4006
400malformed queue ID4011
500error getting strategy information5009
500error encoding queue item5022
  • ⚠️ possible error values inside the body:

The request could response OK 200 and at the same time includes an error because it is an error of the enqueued process and not of the request processing).

GET /strategies/{strategyID}

Returns the information of the strategy related to the provided ID.

  • 📥 response:
{
    "ID": 4,
    "alias": "strategy_alias",
    "predicate": "MON AND (ANT OR USDC)",
    "uri": "ipfs://...",
    "tokens": {
        "MON": {
            "ID": "0x1234",
            "chainID": 5,
            "chainAddress": "gor:0x1234",
            "externalID": "mon_id_on_external_holder_provider"
        },
        "ANT": {
            "ID": "0x1234",
            "chainID": 1,
            "chainAddress": "eth:0x1234",
            "minBalance": "1"
        },
        "USDC": {
            "ID": "0x1234",
            "chainID": 1,
            "chainAddress": "eth:0x1234"
        }
    }
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
400malformed strategy ID, it must be an integer4002
404no strategy found with the ID provided4005
500error getting tokens information5005
500error getting strategy information5007
500error encoding strategy info5015

GET /strategies/{strategyID}/estimation?anonymous={true|false}

Enqueue the estimation of size and time (in milliseconds) to create the census generated for the provided strategy. It also calculates the accuracy of the resulting census, it could be different to 100% if the census will be anonymous.

  • 📥 response:
{
    "queueID": "0123456789abcdef0123456789abcdef01234567",
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
400malformed strategy ID, it must be an integer4002
500error encoding strategy info5015

GET /strategies/{strategyID}/estimation/queue/{queueID}

Returns the estimation of size and time (in milliseconds) to create the census generated for the strategy related to the queue ID.

  • 📥 response:
{
    "done": true,
    "error": {
        "code": 0,
        "error": "error message or null"
    },
    "estimation": {
        "size": 15000,
        "timeToCreateCensus": 10900,
        "accuracy": 100.0,
    }
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
404no strategy found with the ID provided4005
400malformed queue ID4020
500error encoding queue item5022
  • ⚠️ possible error values inside the body:

The request could response OK 200 and at the same time includes an error because it is an error of the enqueued process and not of the request processing).

HTTP StatusMessageInternal error
404no strategy found with the ID provided4005
400the predicate provided is not valid4015
204strategy has not registered holders4017
500error getting strategy information5007
500error evaluating strategy predicate5026

GET /strategies/{strategyID}/holders

Returns the list of holders with their balances for a strategy. This endpoint only works with single token strategies like default ones.

Pagination URL params

URL keyDescriptionExample
pageSize(optional) Defines the number of results per page. By default, 1000.?pageSize=2
nextCursor(optional) When is defined, it is used to get the page results, going forward. By default, "".?nextCursor=0x1234
prevCursor(optional) When is defined, it is used to get the page results, going backwards. By default, "".?prevCursor=0x1234
  • 📥 response:
{
    "holders": {
        "0x1": "1",
        "0x2": "2",
        "0x3": "3",
        "0x4": "4",
        "0x...": "1000",
    },
    "pagination": {
        "nextCursor": "0x5",
        "prevCursor": "0x1",
        "pageSize": 5
    }
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
400malformed strategy ID, it must be an integer4002
404no token holders found4004
404no strategy found with the ID provided4005
400malformed pagination params4022
500error encoding token holders5013
500error getting strategy holders5030

GET /strategies/token/{tokenID}?chainID={chainID}&externalID={externalID}

Returns strategies registered that includes the token provided for the chain also provided, the external token id is an optional parameter.

externalID URL parameter is optional by default, but required for external provided tokens like POAPs.

  • 📥 response:
{
    "strategies": [
        {
            "ID": 1,
            "alias": "default MON strategy",
            "predicate": "MON",
            "tokens": {
                "MON": {
                    "ID": "0x1234",
                    "chainID": 5,
                    "chainAddress": "gor:0x1234"
                }
            }
        },
        {
            "ID": 4,
            "alias": "strategy_alias",
            "predicate": "MON AND (ANT OR USDC)",
            "tokens": {
                "MON": {
                    "ID": "0x1234",
                    "chainID": 5,
                    "chainAddress": "gor:0x1234",
                    "externalID": "mon_id_on_external_holder_provider"
                },
                "ANT": {
                    "ID": "0x1234",
                    "chainID": 1,
                    "chainAddress": "eth:0x1234",
                    "minBalance": "1"
                },
                "USDC": {
                    "ID": "0x1234",
                    "chainID": 1,
                    "chainAddress": "eth:0x1234"
                }
            }
        }
    ]
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
204-4008
500error getting strategies information5008
500error encoding strategies5016

POST /strategies/predicate/validate

Returns if the provided strategy predicate is valid and well-formatted. If the predicate is valid the handler returns a parsed version of the predicate as a JSON.

  • 📤 request:
{
    "predicate": "DAI AND (ANT OR ETH)"
}
  • 📥 response:
{
    "result": {
        "childs": {
            "operator": "AND",
            "tokens": [
                {
                    "literal": "DAI"
                },
                {
                    "childs": {
                        "operator": "OR",
                        "tokens": [
                            {
                                "literal": "ANT"
                            },
                            {
                                "literal": "ETH"
                            }
                        ]
                    }
                }
            ]
        }
    }
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
400malformed strategy provided4014
400the predicate provided is not valid4015
500error encoding validated strategy predicate5024

GET /strategies/predicate/operators

Returns the list of supported operators to build strategy predicates.

  • 📥 response:
{
    "operators": [
        {
            "description": "logical operator that returns the common token holders between symbols with fixed balance to 1",
            "tag": "AND"
        },
        {
            "description": "logical operator that returns the token holders of both symbols with fixed balance to 1",
            "tag": "OR"
        }
    ]
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
500error encoding supported strategy predicate operators5027

Censuses

POST /censuses

Request the creation of a new census with the strategy provided and returns the census ID.

  • 📤 request:
{
    "strategyID": 1,
    "anonymous": false
}
  • 📥 response:
{
    "queueID": "0123456789abcdef0123456789abcdef01234567"
}
  • ⚠️ errors :
HTTP StatusMessageInternal error
400malformed strategy ID, it must be an integer4002
500error encoding census5017

GET /censuses/{censusID}

Returns the information of the snapshots related to the provided ID.

  • 📥 response:
{ 
    "ID": 2,
    "strategyID": 1,
    "merkleRoot": "e3cb8941e25dcdb36fc21acbe5f6c5a42e0d4f89839ae94952f0ebbd9acd04ac",
    "uri": "ipfs://Qma....",
    "size": 1000,
    "weight": "200000000000000000000",
    "anonymous": true,
    "accuracy": 100.0
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
400malformed census ID, it must be a integer4001
404census not found4006
500error getting census information5009
500error encoding census5017

GET /censuses/queue/{queueID}

Returns the information of the census that are in the creation queue.

  • 📥 response:
{
    "done": true,
    "error": {
        "code": 0,
        "error": "error message or null"
    },
    "census": { /* <same_get_census_response> */ }
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
404census not found4006
400malformed queue ID4011
500error getting census information5009
500error encoding queue item5022
  • ⚠️ possible error values inside the body:

The request could response OK 200 and at the same time includes an error because it is an error of the enqueued process and not of the request processing).

HTTP StatusMessageInternal error
404no token holders found4004
404no strategy found with the ID provided4005
400no tokens found for the strategy provided4010
409census already exists4012
400the predicate provided is not valid4015
204strategy has not registered holders4017
500error creating the census tree on the census database5001
500error evaluating strategy predicate5026

GET /censuses/strategy/{strategyID}

Returns a list of censuses previously created for the strategy provided.

  • 📥 response:
{
    "censuses": [ 
        { 
            "ID": 1,
            "strategyID": 1,
            "merkleRoot": "e3cb8941e25dcdb36fc21acbe5f6c5a42e0d4f89839ae94952f0ebbd9acd04ac",
            "uri": "ipfs://Qma....",
            "size": 1000,
            "weight": "200000000000000000000",
            "anonymous": true,
            "accuracy": 100.0
        }
    ]
}
  • ⚠️ errors:
HTTP StatusMessageInternal error
204-4007
400malformed census ID, it must be a integer4001
404census not found4006
500error getting census information5009
500error encoding censuses5018