Skip to content

Commit

Permalink
Bug/api bugs (#76)
Browse files Browse the repository at this point in the history
* API endpoints resources path renamed to plural
* API endpoints timeouts defined on single file
* `.env` renamed to `example.env` and `.env` excluded from git
* Unused database tables removed
* Panic during census creation, when the desired strategy has not any tokens fixed
* API endpoints result attributes name as 'xxId' or 'id' renamed to 'ID' and `tag` to `tags`
* Debug API endpoints removed
* API docs updated
  • Loading branch information
lucasmenendez authored Sep 19, 2023
1 parent 109ec3a commit a900bb1
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 418 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode
.env
.env
.trash/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,25 @@ docker compose up -d
```sh
curl -X POST \
--json '{"id": "0xFE67A4450907459c3e1FFf623aA927dD4e28c67a", "type": "erc20", "chainID": 1}' \
http://localhost:7788/api/token
http://localhost:7788/api/tokens
```
2. Wait to that the API service completes the token sync. It could take up to 10-20 minutes, even more, based on the number of holders and transactions. You can check the token sync status getting the token info:
```sh
curl -X GET \
http://localhost:7788/api/token/0xFE67A4450907459c3e1FFf623aA927dD4e28c67a
http://localhost:7788/api/tokens/0xFE67A4450907459c3e1FFf623aA927dD4e28c67a
```
3. When the API ends, and the token reaches `synced` status (`token.status.synced = true`), its time to create a new census based on the default token strategy. This strategy is created during the token registration and just contains the holders of this token. To create the census with token holders, you need to know the `token.defaultStrategy` (from token info endpoint):
```sh
curl -X POST \
--json '{"strategyId": <strategyId>, "anonymous": true}" \
http://localhost:7788/api/census
http://localhost:7788/api/censuses
```
4. The last request will return a `queueId` which identifies the census creation and publication processes on the API queue. It will be completed in background. We can check if the task is done, it raised an error or was succesfully completed:
```sh
curl -X GET \
http://localhost:7788/census/queue/<queueId>
http://localhost:7788/censuses/queue/<queueId>
```
You can check and run the example using the [`example.sh` file](./example.sh):
Expand Down
118 changes: 60 additions & 58 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Show information about the API service.

## Tokens

### GET `/token`
### GET `/tokens`
List of already added tokens.

- 📥 response:
Expand All @@ -37,18 +37,19 @@ List of already added tokens.
{
"tokens": [
{
"id": "0x1234",
"ID": "0x1234",
"name": "Wrapped Aragon Network Token",
"type": "erc20|erc721|erc777|erc1155|nation3|wANT",
"startBlock": 123456,
"symbol": "wANT",
"tag": "testTag1,testTag2"
"tags": "testTag1,testTag2",
"chainID": 1
}
]
}
```

> If `tag` is empty, it will be ommited.
> If `tags` is empty, it will be ommited.
- ⚠️ errors:

Expand All @@ -58,7 +59,7 @@ List of already added tokens.
| 500 | `error getting tokens information` | 5005 |
| 500 | `error encoding tokens` | 5011 |

### GET `/token/types`
### GET `/tokens/types`
List the supported token types.

- 📥 response:
Expand All @@ -78,21 +79,21 @@ List the supported token types.
|:---:|:---|:---:|
| 500 | `error encoding supported tokens types` | 5012 |

### POST `/token`
### POST `/tokens`
Triggers a new scan for the provided token, starting from the defined block.

- 📤 request:

```json
{
"id": "0x1234",
"ID": "0x1234",
"type": "erc20|erc721|erc777|erc1155|nation3|wANT",
"tag": "testTag1,testTag2",
"tags": "testTag1,testTag2",
"chainID": 1
}
```

> `tag` attribute is *optional*.
> `tags` attribute is *optional*.
- ⚠️ errors:

Expand All @@ -105,14 +106,14 @@ Triggers a new scan for the provided token, starting from the defined block.
| 500 | `error getting token information` | 5004 |
| 500 | `error initialising web3 client` | 5019 |

### GET `/token/{tokenID}`
### GET `/tokens/{tokenID}`
Returns the information about the token referenced by the provided ID.

- 📥 response:

```json
{
"id": "0x1324",
"ID": "0x1324",
"type": "erc20",
"decimals": 18,
"startBlock": 123456,
Expand All @@ -125,28 +126,30 @@ Returns the information about the token referenced by the provided ID.
"progress": 87
},
"defaultStrategy": 1,
"tag": "testTag1,testTag2",
"tags": "testTag1,testTag2",
"chainID": 1
}
```

> If `tag` is empty, it will be ommited.
> If `tags` is empty, it will be ommited.
- ⚠️ errors:

| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 404 | `no token found` | 4003 |
| 500 | `error getting token information` | 5004 |
| 500 | `error initialising web3 client` | 5018 |
| 500 | `error encoding token` | 5010 |
| 500 | `chain ID provided not supported` | 5013 |
| 500 | `error initialising web3 client` | 5019 |
| 500 | `error getting number of token holders` | 5020 |
| 500 | `error getting last block number from web3 endpoint` | 5021 |
| 500 | `error encoding tokens` | 5011 |

**MVP Warn**: If `defaultStrategy` is `0`, no strategy (neither the dummy strategy) is associated to the given token.

## Strategies

### POST `/strategy`
### POST `/strategies`
Stores a new strategy based on the defined combination of tokens provided, these tokens must be registered previously.

- 📤 request:
Expand All @@ -155,19 +158,19 @@ Stores a new strategy based on the defined combination of tokens provided, these
{
"tokens": [
{
"id": "0x1324",
"ID": "0x1324",
"name": "wANT",
"minBalance": "10000",
"method": "0x8230"
},
{
"id": "0x5678",
"ID": "0x5678",
"name": "USDC",
"minBalance": "20000",
"method": "0x3241"
},
{
"id": "0x9da2",
"ID": "0x9da2",
"name": "ANT",
"minBalance": "1",
"method": "0x9db1"
Expand All @@ -181,7 +184,7 @@ Stores a new strategy based on the defined combination of tokens provided, these

```json
{
"strategyId": 1
"strategyID": 1
}
```

Expand All @@ -193,7 +196,7 @@ Stores a new strategy based on the defined combination of tokens provided, these
| 500 | `error getting strategies information` | 5008 |
| 500 | `error encoding strategies` | 5016 |

### GET `/strategy`
### GET `/strategies`
Returns the ID's list of the strategies registered.

- 📥 response:
Expand All @@ -212,7 +215,7 @@ Returns the ID's list of the strategies registered.
| 500 | `error getting strategies information` | 5008 |
| 500 | `error encoding strategies` | 5016 |

### GET `/strategy/{strategyId}`
### GET `/strategies/{strategyID}`
Returns the information of the strategy related to the provided ID.

- 📥 response:
Expand All @@ -222,19 +225,19 @@ Returns the information of the strategy related to the provided ID.
"id": 2,
"tokens": [
{
"id": "0x1324",
"ID": "0x1324",
"name": "wANT",
"minBalance": "10000",
"method": "0x8230"
},
{
"id": "0x5678",
"ID": "0x5678",
"name": "USDC",
"minBalance": "20000",
"method": "0x3241"
},
{
"id": "0x9da2",
"ID": "0x9da2",
"name": "ANT",
"minBalance": "1",
"method": "0x9db1"
Expand All @@ -248,13 +251,13 @@ Returns the information of the strategy related to the provided ID.

| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 204 | `-` | 4002 |
| 400 | `malformed strategy ID, it must be an integer` | 4002 |
| 404 | `no strategy found with the ID provided` | 4005 |
| 500 | `error getting tokens information` | 5005 |
| 500 | `error getting strategy information` | 5007 |
| 500 | `error encoding strategy` | 5015 |

### GET `/strategy/token/{tokenID}`
### GET `/strategies/token/{tokenID}`
Returns ID's of the already created strategies including the `tokenAddress` provided.

- 📥 response:
Expand All @@ -273,36 +276,16 @@ Returns ID's of the already created strategies including the `tokenAddress` prov
| 500 | `error getting strategies information` | 5008 |
| 500 | `error encoding strategies` | 5016 |

### GET `/census/strategy/{strategyId}`
Returns a list of censusID for the strategy provided.

- 📥 response:

```json
{
"censuses": [ 3, 5 ]
}
```

- ⚠️ errors:

| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 204 | `-` | 4007 |
| 404 | `census not found` | 4006 |
| 500 | `error getting census information` | 5009 |
| 500 | `error encoding censuses` | 5018 |

## Censuses

### POST `/census`
### POST `/censuses`
Request the creation of a new census with the strategy provided for the `blockNumber` provided and returns the census ID.

- 📤 request:

```json
{
"strategyId": 1,
"strategyID": 1,
"blockNumber": 123456,
"anonymous": false
}
Expand All @@ -312,7 +295,7 @@ Request the creation of a new census with the strategy provided for the `blockNu

```json
{
"queueId": "0123456789abcdef0123456789abcdef01234567"
"queueID": "0123456789abcdef0123456789abcdef01234567"
}
```

Expand All @@ -321,21 +304,20 @@ Request the creation of a new census with the strategy provided for the `blockNu
| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 400 | `malformed strategy ID, it must be an integer` | 4002 |
| 500 | `error encoding strategy holders` | 5014 |
| 500 | `error encoding census` | 5017 |

### GET `/census/{censusId}`
### GET `/censuses/{censusID}`
Returns the information of the snapshots related to the provided ID.

- 📥 response:
```json
{
"censusId": 2,
"strategyId": 1,
"censusID": 2,
"strategyID": 1,
"merkleRoot": "e3cb8941e25dcdb36fc21acbe5f6c5a42e0d4f89839ae94952f0ebbd9acd04ac",
"uri": "ipfs://Qma....",
"size": 1000,
"weight": "200000000000000000000",
"chainId": 1,
"anonymous": true
}
```
Expand All @@ -344,13 +326,12 @@ Returns the information of the snapshots related to the provided ID.

| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 204 | `-` | 4007 |
| 400 | `malformed census ID, it must be a integer` | 4001 |
| 404 | `census not found` | 4006 |
| 500 | `error getting census information` | 5009 |
| 500 | `error encoding census` | 5017 |

### GET `/census/queue/{queueId}`
### GET `/census/queue/{queueID}`
Returns the information of the census that are in the creation queue.

- 📥 response:
Expand All @@ -369,7 +350,28 @@ Returns the information of the census that are in the creation queue.

| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 400 | `malformed queue ID` | 4010 |
| 404 | `census not found` | 4006 |
| 400 | `malformed queue ID` | 4011 |
| 500 | `error getting census information` | 5009 |
| 500 | `error encoding census queue item` | 5022 |

### GET `/census/strategy/{strategyID}`
Returns a list of censusID for the strategy provided.

- 📥 response:

```json
{
"censuses": [ 3, 5 ]
}
```

- ⚠️ errors:

| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 204 | `-` | 4007 |
| 400 | `malformed census ID, it must be a integer` | 4001 |
| 404 | `census not found` | 4006 |
| 500 | `error getting census information` | 5009 |
| 500 | `error encoding censuses` | 5018 |
4 changes: 0 additions & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func Init(db *db.DB, conf Census3APIConf) error {
if err := newAPI.initStrategiesHandlers(); err != nil {
return err
}
// TODO: Only for the MVP, remove it.
if err := newAPI.initDebugHandlers(); err != nil {
return err
}
return nil
}

Expand Down
Loading

0 comments on commit a900bb1

Please sign in to comment.