Skip to content

Commit f56b642

Browse files
authored
feat: api added (#1)
1 parent 7d198e8 commit f56b642

File tree

13 files changed

+425
-30
lines changed

13 files changed

+425
-30
lines changed

.github/workflows/lint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
golangci:
10+
name: Run golangci-lint
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 10
13+
steps:
14+
- uses: actions/setup-go@v5
15+
with:
16+
go-version: "1.22"
17+
check-latest: true
18+
- uses: actions/checkout@v4
19+
- uses: technote-space/get-diff-action@v6.1.2
20+
with:
21+
PATTERNS: |
22+
**/**.go
23+
go.mod
24+
go.sum
25+
- uses: golangci/golangci-lint-action@v4.0.0
26+
with:
27+
version: latest
28+
args: --timeout 10m
29+
github-token: ${{ secrets.github_token }}
30+
# Check only if there are differences in the source code
31+
if: "env.GIT_DIFF"

.golangci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
run:
2+
tests: true
3+
timeout: 5m
4+
concurrency: 4
5+
6+
linters:
7+
enable:
8+
- dogsled
9+
- errcheck
10+
- goconst
11+
- gocritic
12+
- gofumpt
13+
- revive
14+
- gosec
15+
- gosimple
16+
- govet
17+
- ineffassign
18+
# - lll TODO: enable
19+
- misspell
20+
- nakedret
21+
- prealloc
22+
- exportloopref
23+
- staticcheck
24+
- stylecheck
25+
- typecheck
26+
- unconvert
27+
- unparam
28+
- unused
29+
- nolintlint
30+
- asciicheck
31+
- exportloopref
32+
- gofumpt
33+
34+
linters-settings:
35+
dogsled:
36+
max-blank-identifiers: 3
37+
golint:
38+
min-confidence: 0
39+
maligned:
40+
suggest-new: true
41+
misspell:
42+
locale: US
43+
nolintlint:
44+
allow-unused: false
45+
allow-leading-space: true
46+
require-explanation: false
47+
require-specific: false
48+
gofumpt:
49+
lang-version: "1.22"

README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ Config Example:
1717
"cosmosapi": "localhost:1317",
1818
"cosmosrpc": "localhost:26656",
1919
"pruneoffset": 100,
20-
"refreshduration": "5s"
20+
"refreshduration": "5s",
21+
"apimaxlimit": 100
2122
}
2223
```
2324

2425
- `Pruneoffset` is the value of your node pruned settings. The program will use the information from the latest height - pruneoffset to index the chain
2526
- `Refreshduration` is the time the program will wait until pulling new blocks values
27+
- `APIMaxLimit` is the max range allowed by the api, if the range if bigger than the one set, the query will overwrite the `end` value
28+
29+
## Run
30+
31+
- Clone the repo
32+
- Create the `config.json` file in the root of the repo
33+
- Run `make run`
2634

2735
## Database
2836

@@ -36,3 +44,80 @@ make generate
3644
```
3745

3846
_NOTE: you need `sqlc` to generate the files, run `make install-deps` if you need it_
47+
48+
## Queries:
49+
50+
### Request all the validators info by block height
51+
52+
- Request
53+
54+
```sh
55+
curl "http://localhost:42069/api?start=7313145"
56+
```
57+
58+
_NOTE: optional parameter `end` to set a rangeof blocks_
59+
60+
- Response
61+
62+
```json
63+
{
64+
"values": [
65+
{
66+
"ID": 3337,
67+
"Height": 7313145,
68+
"ValidatorID": 20,
69+
"Missed": 0,
70+
"ID_2": 20,
71+
"OperatorAddress": "ethmvaloper1kdtjxywfvwq94jsst2uyshwkel6dwdv5vlf4l2",
72+
"Pubkey": "TP8Ncm5KUUT3bQgN5SsQADVtPEwaW7O0MY5yX+ztJuE=",
73+
"ValidatorAddress": "ethmvalcons1qwcmnlr2kwuunpmh0s4pshrgz5zqd9m7ljs8lu",
74+
"Moniker": "evmOS",
75+
"Indentity": ""
76+
},
77+
{
78+
"ID": 3338,
79+
"Height": 7313145,
80+
"ValidatorID": 13,
81+
"Missed": 2,
82+
"ID_2": 13,
83+
"OperatorAddress": "ethmvaloper1weh6nan3p8cpg7hsfke8teksjnf5pdl8ve97ny",
84+
"Pubkey": "LxQKOI9n5enbjflu802ZL77lyYLHuejIu9o3FXQ3EOc=",
85+
"ValidatorAddress": "ethmvalcons1qkxa6u5tdr820pv9kjc5rlf8p0r7qqr25fenyw",
86+
"Moniker": "peersyst-node-3",
87+
"Indentity": "14329789E9E20C43"
88+
},
89+
...
90+
]
91+
}
92+
```
93+
94+
### Request all one validators info by block height
95+
96+
- Request
97+
98+
```sh
99+
curl "http://localhost:42069/api?start=7313145&validator=ethmvaloper1weh6nan3p8cpg7hsfke8teksjnf5pdl8ve97ny"
100+
```
101+
102+
_NOTE: optional parameter `end` to set a rangeof blocks_
103+
104+
- Response
105+
106+
```json
107+
{
108+
"values": [
109+
{
110+
"ID": 3338,
111+
"Height": 7313145,
112+
"ValidatorID": 13,
113+
"Missed": 2,
114+
"ID_2": 13,
115+
"OperatorAddress": "ethmvaloper1weh6nan3p8cpg7hsfke8teksjnf5pdl8ve97ny",
116+
"Pubkey": "LxQKOI9n5enbjflu802ZL77lyYLHuejIu9o3FXQ3EOc=",
117+
"ValidatorAddress": "ethmvalcons1qkxa6u5tdr820pv9kjc5rlf8p0r7qqr25fenyw",
118+
"Moniker": "peersyst-node-3",
119+
"Indentity": "14329789E9E20C43"
120+
}
121+
]
122+
}
123+
```

cmd/status/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package main
22

33
import (
4-
_ "github.com/mattn/go-sqlite3"
5-
64
"context"
75
"flag"
86
"fmt"
97
"os"
108
"os/signal"
119
"syscall"
1210

11+
_ "github.com/mattn/go-sqlite3"
12+
1313
"github.com/evmos/validator-status/pkg/config"
1414
"github.com/evmos/validator-status/pkg/database"
1515
"github.com/evmos/validator-status/pkg/logger"

pkg/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ type Config struct {
1111
CosmosAPI string `json:"cosmosapi"`
1212
CosmosRPC string `json:"cosmosrpc"`
1313
PruneOffset int `json:"pruneoffset"`
14+
APIMaxLimit int `json:"apimaxlimit"`
1415
}

pkg/cosmos/missed_blocks.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ type MissedBlockResponse struct {
2626
func (c *Cosmos) getMissedBlocksByHeight(height string) (MissedBlockResponse, error) {
2727
// NOTE: assumes that we do not need pagination
2828
reqGo, err := http.NewRequest("GET", c.apiURL+"/cosmos/slashing/v1beta1/signing_infos", nil)
29+
if err != nil {
30+
return MissedBlockResponse{}, fmt.Errorf("error creating the request %s", err.Error())
31+
}
2932
reqGo.Header.Set("x-cosmos-block-height", height)
3033

3134
resp, err := http.DefaultClient.Do(reqGo)
35+
if err != nil {
36+
return MissedBlockResponse{}, fmt.Errorf("error making the request %s", err.Error())
37+
}
3238
if resp.StatusCode != http.StatusOK {
3339
return MissedBlockResponse{}, fmt.Errorf("status code %d", resp.StatusCode)
3440
}

pkg/cosmos/validators.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,16 @@ type ValidatorsResponse struct {
3232

3333
func (c *Cosmos) getValidators(height string) (ValidatorsResponse, error) {
3434
reqGo, err := http.NewRequest("GET", c.apiURL+"/cosmos/staking/v1beta1/validators", nil)
35+
if err != nil {
36+
return ValidatorsResponse{}, fmt.Errorf("error creating the request %s", err.Error())
37+
}
38+
3539
reqGo.Header.Set("x-cosmos-block-height", height)
3640

3741
resp, err := http.DefaultClient.Do(reqGo)
42+
if err != nil {
43+
return ValidatorsResponse{}, fmt.Errorf("error making the request %s", err.Error())
44+
}
3845
if resp.StatusCode != http.StatusOK {
3946
return ValidatorsResponse{}, fmt.Errorf("status code %d", resp.StatusCode)
4047
}

pkg/database/query.sql.go

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)