Skip to content

Commit

Permalink
go run mvdan.cc/[email protected] -w .
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Jun 20, 2024
1 parent b3a3ef2 commit 59aa664
Show file tree
Hide file tree
Showing 72 changed files with 527 additions and 313 deletions.
3 changes: 2 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func NewAPI(router *httprouter.HTTProuter, baseRoute, dataDir, dbType string) (*
// Attach takes a list of modules which are used by the handlers in order to interact with the system.
// Attach must be called before EnableHandlers.
func (a *API) Attach(vocdoniAPP *vochain.BaseApplication, vocdoniInfo *vochaininfo.VochainInfo,
indexer *indexer.Indexer, data data.Storage, censusdb *censusdb.CensusDB) {
indexer *indexer.Indexer, data data.Storage, censusdb *censusdb.CensusDB,
) {
a.vocapp = vocdoniAPP
a.vocinfo = vocdoniInfo
a.indexer = indexer
Expand Down
1 change: 0 additions & 1 deletion api/census_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func censusIDparse(censusID string) ([]byte, error) {
censusID = util.TrimHex(censusID)
if len(censusID) != censusIDsize*2 {
return nil, ErrCensusIDLengthInvalid.Withf("(%d != %d)", len(censusID), censusIDsize*2)

}
return hex.DecodeString(censusID)
}
Expand Down
12 changes: 8 additions & 4 deletions api/censusdb/censusdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ func NewCensusDB(db db.Database) *CensusDB {

// New creates a new census and adds it to the database.
func (c *CensusDB) New(censusID []byte, censusType models.Census_Type,
uri string, authToken *uuid.UUID, maxLevels int) (*CensusRef, error) {
uri string, authToken *uuid.UUID, maxLevels int,
) (*CensusRef, error) {
if c.Exists(censusID) {
return nil, ErrCensusAlreadyExists
}
tree, err := censustree.New(censustree.Options{Name: censusName(censusID),
ParentDB: c.db, MaxLevels: maxLevels, CensusType: censusType})
tree, err := censustree.New(censustree.Options{
Name: censusName(censusID),
ParentDB: c.db, MaxLevels: maxLevels, CensusType: censusType,
})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -274,7 +277,8 @@ func (c *CensusDB) importTreeCommon(censusID []byte, data []byte) error {

// addCensusRefToDB adds a censusRef to the database.
func (c *CensusDB) addCensusRefToDB(censusID []byte, authToken *uuid.UUID,
t models.Census_Type, uri string, maxLevels int) (*CensusRef, error) {
t models.Census_Type, uri string, maxLevels int,
) (*CensusRef, error) {
wtx := c.db.WriteTx()
defer wtx.Discard()
refData := bytes.Buffer{}
Expand Down
1 change: 0 additions & 1 deletion api/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ func (a *API) organizationCountHandler(_ *apirest.APIdata, ctx *httprouter.HTTPC
return err
}
return ctx.Send(data, apirest.HTTPstatusOK)

}

// chainInfoHandler
Expand Down
3 changes: 2 additions & 1 deletion api/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type FaucetAPI struct {
// The networks map defines the amount of tokens to send for each network. Networks not defined are
// considered invalid.
func AttachFaucetAPI(signingKey *ethereum.SignKeys, amount uint64,
api *apirest.API, pathPrefix string) error {
api *apirest.API, pathPrefix string,
) error {
f := &FaucetAPI{
signingKey: signingKey,
amount: amount,
Expand Down
3 changes: 2 additions & 1 deletion api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func convertKeysToCamelInner(val any) any {
// in this case we encode the organizationId the censusRoot and the results that will be translated in the EVM
// contract to the corresponding struct{address, bytes32, uint256[][]}
func encodeEVMResultsArgs(electionId common.Hash, organizationId common.Address, censusRoot common.Hash,
sourceContractAddress common.Address, results [][]*types.BigInt) (string, error) {
sourceContractAddress common.Address, results [][]*types.BigInt,
) (string, error) {
address, _ := abi.NewType("address", "", nil)
bytes32, _ := abi.NewType("bytes32", "", nil)
uint256SliceNested, _ := abi.NewType("uint256[][]", "", nil)
Expand Down
6 changes: 4 additions & 2 deletions api/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ func (a *API) walletCreateHandler(msg *apirest.APIdata, ctx *httprouter.HTTPCont
Account: wallet.Address().Bytes(),
FaucetPackage: nil,
},
}})
},
})
if err != nil {
return err
}
Expand Down Expand Up @@ -285,7 +286,8 @@ func (a *API) walletTransferHandler(msg *apirest.APIdata, ctx *httprouter.HTTPCo
To: dst.Bytes(),
Value: amount,
},
}})
},
})
if err != nil {
return err
}
Expand Down
15 changes: 8 additions & 7 deletions apiclient/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ var DefaultFaucetURLs = map[string]string{
"prod": "https://api-faucet.vocdoni.io/v2/open/claim/",
}

var (
// ErrAccountNotConfigured is returned when the client has not been configured with an account.
ErrAccountNotConfigured = fmt.Errorf("account not configured")
)
// ErrAccountNotConfigured is returned when the client has not been configured with an account.
var ErrAccountNotConfigured = fmt.Errorf("account not configured")

// Account returns the information about a Vocdoni account. If address is empty, it returns the information
// about the account associated with the client.
Expand Down Expand Up @@ -103,7 +101,8 @@ func (c *HTTPclient) TransferWithNonce(to common.Address, amount uint64, nonce u
To: to.Bytes(),
Value: amount,
},
}})
},
})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -143,7 +142,8 @@ func (c *HTTPclient) AccountBootstrap(faucetPkg *models.FaucetPackage, metadata
InfoURI: &metadataURI,
SIK: sik,
},
}})
},
})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -367,7 +367,8 @@ func (c *HTTPclient) DelSIK() (types.HexBytes, error) {
DelSIK: &models.SIKTx{
Txtype: models.TxType_DEL_ACCOUNT_SIK,
},
}})
},
})
if err != nil {
return nil, err
}
Expand Down
9 changes: 4 additions & 5 deletions apiclient/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
"google.golang.org/protobuf/proto"
)

var (
// ErrTransactionDoesNotExist is returned when the transaction does not exist
ErrTransactionDoesNotExist = fmt.Errorf("transaction does not exist")
)
// ErrTransactionDoesNotExist is returned when the transaction does not exist
var ErrTransactionDoesNotExist = fmt.Errorf("transaction does not exist")

// ChainInfo returns some information about the chain, such as block height.
func (c *HTTPclient) ChainInfo() (*api.ChainInfo, error) {
Expand Down Expand Up @@ -123,7 +121,8 @@ func (c *HTTPclient) TransactionByHash(txHash types.HexBytes) (*models.Tx, error
// OrganizationsBySearchTermPaginated returns a paginated list of organizations
// that match the given search term.
func (c *HTTPclient) OrganizationsBySearchTermPaginated(
organizationID types.HexBytes, page int) ([]types.HexBytes, error) {
organizationID types.HexBytes, page int,
) ([]types.HexBytes, error) {
// make a post request to /chain/organizations/filter/page/<page> with the organizationID
// as the body and page as the url parameter
resp, code, err := c.Request(HTTPPOST,
Expand Down
6 changes: 4 additions & 2 deletions apiclient/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ func (c *HTTPclient) SetElectionStatus(electionID types.HexBytes, status string)
txb, err := proto.Marshal(&models.Tx{
Payload: &models.Tx_SetProcess{
SetProcess: &tx,
}})
},
})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -367,7 +368,8 @@ func (c *HTTPclient) ElectionResults(electionID types.HexBytes) (*api.ElectionRe
// POST /elections/filter/page/<page>
// Returns a list of elections filtered by the given parameters.
func (c *HTTPclient) ElectionFilterPaginated(organizationID types.HexBytes, electionID types.HexBytes,
status models.ProcessStatus, withResults bool, page int) (*[]api.ElectionSummary, error) {
status models.ProcessStatus, withResults bool, page int,
) (*[]api.ElectionSummary, error) {
body := struct {
OrganizationID types.HexBytes `json:"organizationId,omitempty"`
ElectionID types.HexBytes `json:"electionId,omitempty"`
Expand Down
1 change: 0 additions & 1 deletion benchmark/zk_census_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func zkCensusBenchmark(b *testing.B, cc, sc *testutil.TestHTTPclient, vapp *voch
qt.Assert(b, json.Unmarshal(resp, sikData), qt.IsNil)

genProofZk(b, electionID, admin, censusData, sikData)

}

func genProofZk(b *testing.B, electionID []byte, acc *ethereum.SignKeys, censusData, sikData *api.Census) {
Expand Down
2 changes: 1 addition & 1 deletion censustree/censustree.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func DeleteCensusTreeFromDatabase(kv db.Database, name string) (int, error) {
// New returns a new Tree, if there already is a Tree in the
// database, it will load it.
func New(opts Options) (*Tree, error) {
var maxLevels = opts.MaxLevels
maxLevels := opts.MaxLevels
if maxLevels > DefaultMaxLevels {
maxLevels = DefaultMaxLevels
}
Expand Down
30 changes: 20 additions & 10 deletions censustree/censustree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (

func TestImportWeighted(t *testing.T) {
db := metadb.NewTest(t)
censusTree, err := New(Options{Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B})
censusTree, err := New(Options{
Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B,
})
qt.Assert(t, err, qt.IsNil)

rnd := testutil.NewRandom(0)
Expand All @@ -46,8 +48,10 @@ func TestImportWeighted(t *testing.T) {
qt.Assert(t, err, qt.IsNil)

// import into a new tree
censusTree2, err := New(Options{Name: "test2", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B})
censusTree2, err := New(Options{
Name: "test2", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B,
})
qt.Assert(t, err, qt.IsNil)

err = censusTree2.ImportDump(dump)
Expand All @@ -74,8 +78,10 @@ func TestImportWeighted(t *testing.T) {

func TestWeightedProof(t *testing.T) {
db := metadb.NewTest(t)
censusTree, err := New(Options{Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_POSEIDON})
censusTree, err := New(Options{
Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_POSEIDON,
})
qt.Assert(t, err, qt.IsNil)

rnd := testutil.NewRandom(0)
Expand Down Expand Up @@ -111,8 +117,10 @@ func TestWeightedProof(t *testing.T) {

func TestGetCensusWeight(t *testing.T) {
db := metadb.NewTest(t)
tree, err := New(Options{Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B})
tree, err := New(Options{
Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B,
})
qt.Assert(t, err, qt.IsNil)

w, err := tree.GetCensusWeight()
Expand Down Expand Up @@ -196,8 +204,10 @@ func TestGetCensusWeight(t *testing.T) {
// dump the leaves & import them into a new empty tree, and check that
// the censusWeight is correctly recomputed
db2 := metadb.NewTest(t)
tree2, err := New(Options{Name: "test2", ParentDB: db2, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B})
tree2, err := New(Options{
Name: "test2", ParentDB: db2, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B,
})
qt.Assert(t, err, qt.IsNil)

dump, err := tree.Dump()
Expand Down
14 changes: 9 additions & 5 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func main() {
errorp.Println("unknown option or not yet implemented")
}
}

}

func accountIsSet(c *VocdoniCLI) bool {
Expand Down Expand Up @@ -626,16 +625,21 @@ func electionHandler(cli *VocdoniCLI) error {
VoteType: api.VoteType{MaxVoteOverwrites: 1},
ElectionType: api.ElectionType{Autostart: true, Interruptible: true},
Questions: []api.Question{
{Title: map[string]string{"default": "question title"},
{
Title: map[string]string{"default": "question title"},
Description: map[string]string{"default": "question description"},
Choices: []api.ChoiceMetadata{
{
Title: map[string]string{"default": "1 choice title"},
Value: 0},
Value: 0,
},
{
Title: map[string]string{"default": "2 choice title"},
Value: 1},
}}},
Value: 1,
},
},
},
},
Census: api.CensusTypeDescription{
Type: "weighted",
RootHash: make(types.HexBytes, 32),
Expand Down
3 changes: 2 additions & 1 deletion cmd/end2endtest/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ func checkTokenTransfersCount(api *apiclient.HTTPclient, address common.Address)
}

func ensureAccountExists(api *apiclient.HTTPclient,
faucetPkg *models.FaucetPackage) (*apipkg.Account, error) {
faucetPkg *models.FaucetPackage,
) (*apipkg.Account, error) {
for i := 0; i < retries; i++ {
acct, err := api.Account("")
if err != nil {
Expand Down
Loading

0 comments on commit 59aa664

Please sign in to comment.