Skip to content

Commit

Permalink
refactored to include more information about censuses
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Sep 22, 2023
1 parent bdcd041 commit 21eff32
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
12 changes: 11 additions & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,17 @@ Returns a list of censusID for the strategy provided.

```json
{
"censuses": [ 3, 5 ]
"censuses": [
{
"censusID": 1,
"strategyID": 1,
"merkleRoot": "e3cb8941e25dcdb36fc21acbe5f6c5a42e0d4f89839ae94952f0ebbd9acd04ac",
"uri": "ipfs://Qma....",
"size": 1000,
"weight": "200000000000000000000",
"anonymous": true
}
]
}
```

Expand Down
18 changes: 16 additions & 2 deletions api/censuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,23 @@ func (capi *census3API) getStrategyCensuses(msg *api.APIdata, ctx *httprouter.HT
return ErrCantGetCensus.WithErr(err)
}
// parse and encode response
censuses := GetCensusesResponse{Censuses: []uint64{}}
censuses := GetCensusesResponse{Censuses: []*GetCensusResponse{}}
for _, censusInfo := range rows {
censuses.Censuses = append(censuses.Censuses, censusInfo.ID)
// get values for optional parameters
censusWeight := []byte{}
if censusInfo.Weight.Valid {
censusWeight = []byte(censusInfo.Weight.String)
}

censuses.Censuses = append(censuses.Censuses, &GetCensusResponse{
CensusID: censusInfo.ID,
StrategyID: censusInfo.StrategyID,
MerkleRoot: common.Bytes2Hex(censusInfo.MerkleRoot),
URI: "ipfs://" + censusInfo.Uri.String,
Size: censusInfo.Size,
Weight: new(big.Int).SetBytes(censusWeight).String(),
Anonymous: censusInfo.CensusType == uint64(census.AnonymousCensusType),
})
}
res, err := json.Marshal(censuses)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type GetCensusResponse struct {
}

type GetCensusesResponse struct {
Censuses []uint64 `json:"censuses"`
Censuses []*GetCensusResponse `json:"censuses"`
}

type CensusQueueResponse struct {
Expand Down

0 comments on commit 21eff32

Please sign in to comment.