Skip to content

Commit

Permalink
Merge branch 'main' of github.com:vocdoni/vocdoni-node into f/order_t…
Browse files Browse the repository at this point in the history
…ransactions
  • Loading branch information
p4u committed Oct 10, 2023
2 parents b072fdb + a2f259f commit 44e7e7d
Show file tree
Hide file tree
Showing 72 changed files with 802 additions and 903 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
# staticcheck provides a github action, use it (https://staticcheck.io/docs/running-staticcheck/ci/github-actions/)
# or use golangci-lint (github action) with staticcheck as enabled linter
run: |
curl -L https://github.com/dominikh/go-tools/releases/download/2023.1.2/staticcheck_linux_amd64.tar.gz | tar -xzf -
curl -L https://github.com/dominikh/go-tools/releases/download/2023.1.6/staticcheck_linux_amd64.tar.gz | tar -xzf -
- name: Run staticcheck
run: |
./staticcheck/staticcheck ./... 2> staticcheck/stderr
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
- name: Run compose script
env:
TESTSUITE_BUILD_TAG: ${{ github.sha }}
COMPOSE_PROJECT_NAME: testsuite_${{ github.run_id }} # unique name for docker-compose (needed for concurrent job runs)
COMPOSE_PROJECT_NAME: testsuite_${{ github.run_id }} # unique name for docker compose (needed for concurrent job runs)
COMPOSE_DVOTE_PORT_MAPPING: "9090" # this binds gateway0 to a random available port on docker host (needed for concurrent job runs)
COMPOSE_HOST_PATH: ${{ github.workspace }}/dockerfiles/testsuite
LOG_PANIC_ON_INVALIDCHARS: true # check that log lines contains no invalid chars (evidence of format mismatch)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ For running vocdoni-node in gateway mode, 8 GiB of ram memory is recommended (4

#### Compile and run

Compile from source in a golang environment (Go>1.20 required):
Compile from source in a golang environment (Go>1.21 required):

```bash
git clone https://github.com/vocdoni/vocdoni-node.git
Expand All @@ -55,13 +55,13 @@ go build ./cmd/node

#### Docker

You can run vocdoni node as a standalone container with docker-compose (recommended).
You can run vocdoni node as a standalone container with docker compose (recommended).
It is recommended to also start `watchtower` to automatically update the container when a new version is released.

```bash
cd dockerfiles/vocdoninode
cp env.example env
docker-compose -f docker-compose.yml -f docker-compose.watchtower.yml up -d
COMPOSE_PROFILES=watchtower docker compose up -d
```

All data will be stored in the shared volume `run` and the API will be available at `http://127.0.0.1:9090/v2`.
Expand All @@ -71,7 +71,7 @@ If the computer has the port 443 available and mapped to a public IP, you might
To stop the container:

```bash
docker-compose -f docker-compose.yml -f docker-compose.watchtower.yml down
docker compose down
```

#### Connecting
Expand Down
2 changes: 1 addition & 1 deletion api/censuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (a *API) censusAddHandler(msg *apirest.APIdata, ctx *httprouter.HTTPContext
// censusTypeHandler
//
// @Summary Get type of census
// @Description Get the type of a census
// @Description Get the census type
// @Tags Censuses
// @Accept json
// @Produce json
Expand Down
2 changes: 1 addition & 1 deletion api/elections.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (a *API) electionFullListHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCo
}
list = append(list, a.electionSummary(e))
}
// wrap list in a struct to consistently return list in a object, return empty
// wrap list in a struct to consistently return list in an object, return empty
// object if the list does not contains any result
data, err := json.Marshal(struct {
Elections []ElectionSummary `json:"elections"`
Expand Down
2 changes: 1 addition & 1 deletion api/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
FaucetHandler = "faucet"
)

// FaucetAPI is an httprouter/apirest handler for the faucet.
// FaucetAPI is a httprouter/apirest handler for the faucet.
// It generates a signed package that can be used to request tokens from the faucet.
type FaucetAPI struct {
signingKey *ethereum.SignKeys
Expand Down
6 changes: 2 additions & 4 deletions api/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (a *API) walletSignAndSendTx(stx *models.SignedTx, wallet *ethereum.SignKey
// walletAddHandler
//
// @Summary Add account
// @Description Add a new account to the local store. It return a token used to manage this account on the future.
// @Description Add a new account to the local store. It returns a token used to manage this account on the future.
// @Tags Wallet
// @Accept json
// @Produce json
Expand Down Expand Up @@ -392,9 +392,7 @@ func (a *API) walletElectionHandler(msg *apirest.APIdata, ctx *httprouter.HTTPCo

maxChoiceValue := 0
for _, question := range description.Questions {
if len(question.Choices) > maxChoiceValue {
maxChoiceValue = len(question.Choices)
}
maxChoiceValue = max(maxChoiceValue, len(question.Choices))
metaQuestion := Question{
Choices: []ChoiceMetadata{},
Description: question.Description,
Expand Down
2 changes: 1 addition & 1 deletion apiclient/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (c *HTTPclient) DelSIK() (types.HexBytes, error) {
}

// RegisterSIKForVote function performs the free RegisterSIKTx to the vochain
// helping to non registered accounts to vote in a on going election, but only
// helping to non registered accounts to vote in an ongoing election, but only
// if the account is in the election census. The function returns the hash of
// the sent transaction, and requires the election ID. The census proof and the
// secret are optional. If no proof is provided, it will be generated.
Expand Down
4 changes: 1 addition & 3 deletions apiclient/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ func (c *HTTPclient) NewElection(description *api.ElectionDescription) (types.He

maxChoiceValue := 0
for _, question := range description.Questions {
if len(question.Choices) > maxChoiceValue {
maxChoiceValue = len(question.Choices)
}
maxChoiceValue = max(maxChoiceValue, len(question.Choices))
metaQuestion := api.Question{
Choices: []api.ChoiceMetadata{},
Description: question.Description,
Expand Down
26 changes: 13 additions & 13 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ func main() {

}

func accountIsSet(c *vocdoniCLI) bool {
func accountIsSet(c *VocdoniCLI) bool {
return c.currentAccount >= 0
}

func accountHandler(c *vocdoniCLI) error {
func accountHandler(c *VocdoniCLI) error {
accountAddNewStr := "-> import an account (from hexadecimal private key)"
accountGenerateStr := "-> generate a new account"
p := ui.Select{
Expand Down Expand Up @@ -193,7 +193,7 @@ func accountHandler(c *vocdoniCLI) error {
return nil
}

func accountSet(c *vocdoniCLI) error {
func accountSet(c *VocdoniCLI) error {
p := ui.Prompt{
Label: "Account private key",
}
Expand All @@ -212,7 +212,7 @@ func accountSet(c *vocdoniCLI) error {
return c.setAPIaccount(key, memo)
}

func accountGen(c *vocdoniCLI) error {
func accountGen(c *VocdoniCLI) error {
p := ui.Prompt{
Label: "Account memo note",
}
Expand All @@ -225,7 +225,7 @@ func accountGen(c *vocdoniCLI) error {
return c.setAPIaccount(key, memo)
}

func accountInfo(c *vocdoniCLI) error {
func accountInfo(c *VocdoniCLI) error {
acc, err := c.api.Account("")
if err != nil {
return err
Expand All @@ -243,7 +243,7 @@ func accountInfo(c *vocdoniCLI) error {
if acc.Metadata != nil {
accMetadata, err := json.MarshalIndent(acc.Metadata, "", " ")
if err != nil {
log.Debug("account metadta cannot be unmarshal")
log.Debug("account metadata cannot be unmarshal")
} else {
fmt.Printf("%s:\n%s\n", keysPrint.Sprintf(" ➥ metadata"), valuesPrint.Sprintf("%s", accMetadata))
}
Expand All @@ -252,7 +252,7 @@ func accountInfo(c *vocdoniCLI) error {
return nil
}

func networkInfo(cli *vocdoniCLI) error {
func networkInfo(cli *VocdoniCLI) error {
info, err := cli.api.ChainInfo()
if err != nil {
return err
Expand All @@ -265,7 +265,7 @@ func networkInfo(cli *vocdoniCLI) error {
return nil
}

func bootStrapAccount(cli *vocdoniCLI) error {
func bootStrapAccount(cli *VocdoniCLI) error {
var faucetPkg *models.FaucetPackage
p := ui.Prompt{
Label: "Do you have a faucet package? [y,n]",
Expand Down Expand Up @@ -322,7 +322,7 @@ func bootStrapAccount(cli *vocdoniCLI) error {
return nil
}

func transfer(cli *vocdoniCLI) error {
func transfer(cli *VocdoniCLI) error {
s := ui.Select{
Label: "Select a destination account",
Items: append(cli.listAccounts(), "to external account"),
Expand Down Expand Up @@ -397,10 +397,10 @@ func transfer(cli *vocdoniCLI) error {
return nil
}

func hostHandler(cli *vocdoniCLI) error {
func hostHandler(cli *VocdoniCLI) error {
validateFunc := func(url string) error {
log.Debugf("performing ping test to %s", url)
_, err := http.NewRequest("GET", url+"/ping", nil)
_, err := http.NewRequest("GET", url+"/ping", http.NoBody)
return err
}
p := ui.Prompt{
Expand Down Expand Up @@ -431,7 +431,7 @@ func hostHandler(cli *vocdoniCLI) error {
return cli.setAuthToken(token)
}

func accountSetMetadata(cli *vocdoniCLI) error {
func accountSetMetadata(cli *VocdoniCLI) error {
currentAccount, err := cli.api.Account("")
if err != nil {
return err
Expand Down Expand Up @@ -515,7 +515,7 @@ func accountSetMetadata(cli *vocdoniCLI) error {

}

func electionHandler(cli *vocdoniCLI) error {
func electionHandler(cli *VocdoniCLI) error {
infoPrint.Printf("preparing the election template...\n")
description := api.ElectionDescription{
Title: map[string]string{"default": "election title"},
Expand Down
26 changes: 13 additions & 13 deletions cmd/cli/vocdonicli.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Account struct {
PublicKey types.HexBytes `json:"pubKey"`
}

type vocdoniCLI struct {
type VocdoniCLI struct {
filepath string
config *Config
api *apiclient.HTTPclient
Expand All @@ -63,7 +63,7 @@ type vocdoniCLI struct {
currentAccount int
}

func NewVocdoniCLI(configFile, host string) (*vocdoniCLI, error) {
func NewVocdoniCLI(configFile, host string) (*VocdoniCLI, error) {
cfg := Config{}
if err := cfg.Load(configFile); err != nil {
return nil, err
Expand Down Expand Up @@ -101,7 +101,7 @@ func NewVocdoniCLI(configFile, host string) (*vocdoniCLI, error) {
return nil, err
}
}
return &vocdoniCLI{
return &VocdoniCLI{
filepath: configFile,
config: &cfg,
api: api,
Expand All @@ -110,7 +110,7 @@ func NewVocdoniCLI(configFile, host string) (*vocdoniCLI, error) {
}, nil
}

func (v *vocdoniCLI) setHost(host string) error {
func (v *VocdoniCLI) setHost(host string) error {
u, err := url.Parse(host)
if err != nil {
return err
Expand All @@ -127,7 +127,7 @@ func (v *vocdoniCLI) setHost(host string) error {
return v.save()
}

func (v *vocdoniCLI) setAuthToken(token string) error {
func (v *VocdoniCLI) setAuthToken(token string) error {
t, err := uuid.Parse(token)
if err != nil {
return err
Expand All @@ -137,7 +137,7 @@ func (v *vocdoniCLI) setAuthToken(token string) error {
return v.save()
}

func (v *vocdoniCLI) useAccount(index int) error {
func (v *VocdoniCLI) useAccount(index int) error {
if index >= len(v.config.Accounts) {
return fmt.Errorf("account %d does not exist", index)
}
Expand All @@ -149,21 +149,21 @@ func (v *vocdoniCLI) useAccount(index int) error {
return v.api.SetAccount(v.config.Accounts[index].PrivKey.String())
}

func (v *vocdoniCLI) getAccount(index int) (*Account, error) {
func (v *VocdoniCLI) getAccount(index int) (*Account, error) {
if index >= len(v.config.Accounts) {
return nil, fmt.Errorf("account %d does not exist", index)
}
return &v.config.Accounts[index], nil
}

func (v *vocdoniCLI) getCurrentAccount() *Account {
func (v *VocdoniCLI) getCurrentAccount() *Account {
if v.currentAccount < 0 {
return nil
}
return &v.config.Accounts[v.currentAccount]
}

func (v *vocdoniCLI) setAPIaccount(key, memo string) error {
func (v *VocdoniCLI) setAPIaccount(key, memo string) error {
if err := v.api.SetAccount(key); err != nil {
return err
}
Expand Down Expand Up @@ -198,20 +198,20 @@ func (v *vocdoniCLI) setAPIaccount(key, memo string) error {
}

// listAccounts list the memo notes of all stored accounts
func (v *vocdoniCLI) listAccounts() []string {
func (v *VocdoniCLI) listAccounts() []string {
accounts := []string{}
for _, a := range v.config.Accounts {
accounts = append(accounts, a.Memo)
}
return accounts
}

func (v *vocdoniCLI) transactionMined(txHash types.HexBytes) bool {
func (v *VocdoniCLI) transactionMined(txHash types.HexBytes) bool {
_, err := v.api.TransactionReference(txHash)
return err == nil
}

func (v *vocdoniCLI) waitForTransaction(txHash types.HexBytes) bool {
func (v *VocdoniCLI) waitForTransaction(txHash types.HexBytes) bool {
startTime := time.Now()
for time.Now().Before(startTime.Add(transactionConfirmationThreshold)) {
if v.transactionMined(txHash) {
Expand All @@ -222,6 +222,6 @@ func (v *vocdoniCLI) waitForTransaction(txHash types.HexBytes) bool {
return false
}

func (v *vocdoniCLI) save() error {
func (v *VocdoniCLI) save() error {
return v.config.Save(v.filepath)
}
Loading

0 comments on commit 44e7e7d

Please sign in to comment.