Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/async census creation #70

Merged
merged 18 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4367700
now the API support to create anonymous census with a new parameter …
lucasmenendez Aug 28, 2023
4b66aab
now when the user tries to create a new census, it is included into t…
lucasmenendez Aug 29, 2023
cfe47c9
upgrading dependencies and solving linter issues
lucasmenendez Aug 29, 2023
7108bc0
new queue for track ongoin censuses, new endpoint to get the status o…
lucasmenendez Aug 30, 2023
86902f0
some comments and code reorganization
lucasmenendez Aug 30, 2023
3a998dd
new API spec and response keys formats standarization
lucasmenendez Aug 30, 2023
a88d03f
purge queue processes when they are finished and someone checks them
lucasmenendez Aug 31, 2023
05a3873
merging main and census queue response flatted
lucasmenendez Aug 31, 2023
2f7a546
rollback some dependencies updates with issues
lucasmenendez Aug 31, 2023
99df946
fixing missing error on queue censuses
lucasmenendez Sep 1, 2023
e61318c
new queue map attribute to store metadata, now when the user request …
lucasmenendez Sep 1, 2023
5785455
fixing tests
lucasmenendez Sep 1, 2023
43eee43
comments fixes
lucasmenendez Sep 4, 2023
84c5788
Merge branch 'main' into feature/async_census_creation
lucasmenendez Sep 5, 2023
1a9106b
replace error logs with error responses
lucasmenendez Sep 6, 2023
0fbf3ce
Merge branch 'main' into feature/async_census_creation
lucasmenendez Sep 6, 2023
29aa177
data race test based on go test timeout flag
lucasmenendez Sep 6, 2023
b8e3baa
Merge branch 'main' into feature/async_census_creation
lucasmenendez Sep 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
run:
go: '1.20'
issues:
max-same-issues: 0
exclude-use-default: false
Expand All @@ -16,4 +18,4 @@ linters:

linters-settings:
lll:
line-length: 130
line-length: 130
34 changes: 28 additions & 6 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Triggers a new scan for the provided token, starting from the defined block.
| 409 | `token already created` | 4009 |
| 500 | `the token cannot be created` | 5000 |
| 500 | `error getting token information` | 5004 |
| 500 | `error initialising web3 client` | 5018 |
| 500 | `error initialising web3 client` | 5019 |

### GET `/token/{tokenID}`
Returns the information about the token referenced by the provided ID.
Expand Down Expand Up @@ -290,7 +290,7 @@ Returns a list of censusID for the strategy provided.
| 204 | `-` | 4007 |
| 404 | `census not found` | 4006 |
| 500 | `error getting census information` | 5009 |
| 500 | `error encoding cenuses` | 5018 |
| 500 | `error encoding censuses` | 5018 |

## Censuses

Expand All @@ -311,17 +311,15 @@ Request the creation of a new census with the strategy provided for the `blockNu

```json
{
"censusId": 12
"queueId": "0123456789abcdef0123456789abcdef01234567"
}
```

- ⚠️ errors :

| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 400 | `malformed strategy ID, it must be a integer` | 4002 |
| 404 | `no strategy found with the ID provided` | 4005 |
| 500 | `error creating the census tree on the census database` | 5001 |
| 400 | `malformed strategy ID, it must be an integer` | 4002 |
| 500 | `error encoding strategy holders` | 5014 |

### GET `/census/{censusId}`
Expand Down Expand Up @@ -350,3 +348,27 @@ Returns the information of the snapshots related to the provided ID.
| 404 | `census not found` | 4006 |
| 500 | `error getting census information` | 5009 |
| 500 | `error encoding census` | 5017 |

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

- 📥 response:
```json
{
"done": true,
"error": {
"code": 0,
"err": "error message or null"
},
"census": { /* <same_get_census_response> */ }
}
```

- ⚠️ errors:

| HTTP Status | Message | Internal error |
|:---:|:---|:---:|
| 400 | `malformed queue ID` | 4010 |
| 404 | `census not found` | 4006 |
| 500 | `error getting census information` | 5009 |
| 500 | `error encoding census queue item` | 5022 |
11 changes: 6 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/vocdoni/census3/census"
"github.com/vocdoni/census3/db"
"github.com/vocdoni/census3/queue"
"go.vocdoni.io/dvote/httprouter"
api "go.vocdoni.io/dvote/httprouter/apirest"
"go.vocdoni.io/dvote/log"
Expand All @@ -23,14 +24,16 @@ type census3API struct {
db *db.DB
endpoint *api.API
censusDB *census.CensusDB
queue *queue.BackgroundQueue
w3p map[int64]string
}

func Init(db *db.DB, conf Census3APIConf) error {
newAPI := &census3API{
conf: conf,
db: db,
w3p: conf.Web3Providers,
conf: conf,
db: db,
w3p: conf.Web3Providers,
queue: queue.NewBackgroundQueue(),
}
// get the current chainID
log.Infow("starting API", "chainID-web3Providers", conf.Web3Providers)
Expand Down Expand Up @@ -79,13 +82,11 @@ func (capi *census3API) getAPIInfo(msg *api.APIdata, ctx *httprouter.HTTPContext
for chainID := range capi.w3p {
chainIDs = append(chainIDs, chainID)
}

info := map[string]any{"chainIDs": chainIDs}
res, err := json.Marshal(info)
if err != nil {
log.Errorw(err, "error encoding api info")
return ErrEncodeAPIInfo
}

return ctx.Send(res, api.HTTPstatusOK)
}
Loading
Loading