Skip to content

Commit

Permalink
using types.HexBytes for merkle root on api
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Sep 29, 2023
1 parent 00a6e06 commit 9afe68e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions api/censuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.vocdoni.io/dvote/httprouter"
api "go.vocdoni.io/dvote/httprouter/apirest"
"go.vocdoni.io/dvote/log"
"go.vocdoni.io/dvote/types"
)

func (capi *census3API) initCensusHandlers() error {
Expand Down Expand Up @@ -59,7 +60,7 @@ func (capi *census3API) getCensus(msg *api.APIdata, ctx *httprouter.HTTPContext)
res, err := json.Marshal(GetCensusResponse{
CensusID: censusID,
StrategyID: currentCensus.StrategyID,
MerkleRoot: common.Bytes2Hex(currentCensus.MerkleRoot),
MerkleRoot: types.HexBytes(currentCensus.MerkleRoot),
URI: "ipfs://" + currentCensus.Uri.String,
Size: currentCensus.Size,
Weight: new(big.Int).SetBytes(censusWeight).String(),
Expand Down Expand Up @@ -305,7 +306,7 @@ func (capi *census3API) enqueueCensus(msg *api.APIdata, ctx *httprouter.HTTPCont
queueCensus.Census = &GetCensusResponse{
CensusID: currentCensus.ID,
StrategyID: currentCensus.StrategyID,
MerkleRoot: common.Bytes2Hex(currentCensus.MerkleRoot),
MerkleRoot: types.HexBytes(currentCensus.MerkleRoot),
URI: "ipfs://" + currentCensus.Uri.String,
Size: currentCensus.Size,
Weight: censusWeight.String(),
Expand Down Expand Up @@ -355,7 +356,7 @@ func (capi *census3API) getStrategyCensuses(msg *api.APIdata, ctx *httprouter.HT
censuses.Censuses = append(censuses.Censuses, &GetCensusResponse{
CensusID: censusInfo.ID,
StrategyID: censusInfo.StrategyID,
MerkleRoot: common.Bytes2Hex(censusInfo.MerkleRoot),
MerkleRoot: types.HexBytes(censusInfo.MerkleRoot),
URI: "ipfs://" + censusInfo.Uri.String,
Size: censusInfo.Size,
Weight: censusWeight.String(),
Expand Down
16 changes: 9 additions & 7 deletions api/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package api

import "go.vocdoni.io/dvote/types"

type SupportedChain struct {
ChainID uint64 `json:"chainID"`
ShortName string `json:"shortName"`
Expand Down Expand Up @@ -71,13 +73,13 @@ type CreateCensusResponse struct {
}

type GetCensusResponse struct {
CensusID uint64 `json:"ID"`
StrategyID uint64 `json:"strategyID"`
MerkleRoot string `json:"merkleRoot"`
URI string `json:"uri"`
Size uint64 `json:"size"`
Weight string `json:"weight"`
Anonymous bool `json:"anonymous"`
CensusID uint64 `json:"ID"`
StrategyID uint64 `json:"strategyID"`
MerkleRoot types.HexBytes `json:"merkleRoot"`
URI string `json:"uri"`
Size uint64 `json:"size"`
Weight string `json:"weight"`
Anonymous bool `json:"anonymous"`
}

type GetCensusesResponse struct {
Expand Down

0 comments on commit 9afe68e

Please sign in to comment.