Skip to content

Commit

Permalink
add voting back, use it as To parameter in /vote
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrynenko committed Apr 9, 2024
1 parent 448b1d9 commit ae0e389
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ post:
type: object
required:
- tx_data
- voting
- registration
properties:
tx_data:
type: string
voting:
type: string
registration:
type: string
responses:
Expand Down
26 changes: 4 additions & 22 deletions internal/service/api/handlers/vote.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handlers

import (
"math/big"
"net/http"
"strings"

Expand Down Expand Up @@ -34,6 +33,7 @@ func Vote(w http.ResponseWriter, r *http.Request) {
}

registration := common.HexToAddress(req.Data.Registration)
voting := common.HexToAddress(req.Data.Voting)

exists, err := VotingRegistry(r).IsPoolExistByProposer(&bind.CallOpts{}, NetworkConfig(r).Proposer, registration)
if err != nil {
Expand All @@ -60,7 +60,7 @@ func Vote(w http.ResponseWriter, r *http.Request) {

gas, err := EthClient(r).EstimateGas(r.Context(), ethereum.CallMsg{
From: crypto.PubkeyToAddress(NetworkConfig(r).PrivateKey.PublicKey),
To: &registration,
To: &voting,
GasPrice: gasPrice,
Data: dataBytes,
})
Expand All @@ -77,7 +77,7 @@ func Vote(w http.ResponseWriter, r *http.Request) {
Nonce: NetworkConfig(r).Nonce(),
Gas: gas,
GasPrice: gasPrice,
To: &registration,
To: &voting,
Data: dataBytes,
},
)
Expand All @@ -102,7 +102,7 @@ func Vote(w http.ResponseWriter, r *http.Request) {
Nonce: NetworkConfig(r).Nonce(),
Gas: gas,
GasPrice: gasPrice,
To: &registration,
To: &voting,
Data: dataBytes,
},
)
Expand Down Expand Up @@ -136,21 +136,3 @@ func Vote(w http.ResponseWriter, r *http.Request) {
},
})
}

func getVoteTxDataParams(r *http.Request, data []byte) (*big.Int, error) {
unpackResult, err := VotingVoteMethod(r).Inputs.Unpack(data[4:])
if err != nil {
return nil, errors.Wrap(err, "failed to unpack tx data")
}

if len(unpackResult) != 4 {
return nil, errors.Wrap(err, "unpack result is not valid")
}

nullifier, ok := unpackResult[1].([32]byte)
if !ok {
return nil, errors.New("failed to convert interface to [32]byte")
}

return new(big.Int).SetBytes(nullifier[:]), nil
}
3 changes: 3 additions & 0 deletions internal/service/api/requests/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type VoteRequestData struct {
TxData string `json:"tx_data"`
Voting string `json:"voting"`
Registration string `json:"registration"`
}

Expand All @@ -30,6 +31,8 @@ func NewVoteRequest(r *http.Request) (VoteRequest, error) {

func validateVoteRequest(r VoteRequest) error {
return validation.Errors{
"/data/voting": validation.Validate(
r.Data.Voting, validation.Required, validation.By(isAddressRule)),
"/data/registration": validation.Validate(
r.Data.Registration, validation.Required, validation.By(isAddressRule)),
}.Filter()
Expand Down

0 comments on commit ae0e389

Please sign in to comment.