Skip to content

Commit

Permalink
Merge pull request #4 from rarimo/feat/whitelist
Browse files Browse the repository at this point in the history
moved isAddressInWhitelist
  • Loading branch information
Zaptoss authored Aug 6, 2024
2 parents 56d6d4a + 31c5cd6 commit 653bb46
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions internal/service/handlers/voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ func Voting(w http.ResponseWriter, r *http.Request) {
)

log := Log(r).WithFields(logan.F{
"user-agent": r.Header.Get("User-Agent"),
"calldata": calldata,
"destination": destination,
"proposal_id": proposalID,
"proposol_state_contract": RelayerConfig(r).Address,
"user-agent": r.Header.Get("User-Agent"),
"calldata": calldata,
"destination": destination,
"proposal_id": proposalID,
})
log.Debug("voting request")

Expand All @@ -74,9 +73,6 @@ func Voting(w http.ResponseWriter, r *http.Request) {
return
}

RelayerConfig(r).LockNonce()
defer RelayerConfig(r).UnlockNonce()

proposalBigID := big.NewInt(proposalID)

session, err := proposalsstate.NewProposalsStateCaller(RelayerConfig(r).Address, RelayerConfig(r).RPC)
Expand All @@ -95,7 +91,17 @@ func Voting(w http.ResponseWriter, r *http.Request) {
return
}

if !isAddressInWhitelist(votingAddress, proposalConfig.VotingWhitelist) {
log.Error("Address not in voting whitelist")
ape.RenderErr(w, problems.Forbidden())
return
}

defer RelayerConfig(r).UnlockNonce()
RelayerConfig(r).LockNonce()

err = confGas(r, &txd, &votingAddress)

if err != nil {
log.WithError(err).Error("Failed to configure gas and gasPrice")
// `errors.Is` is not working for rpc errors, they passed as a string without additional wrapping
Expand All @@ -111,12 +117,6 @@ func Voting(w http.ResponseWriter, r *http.Request) {
return
}

if !isAddressInWhitelist(votingAddress, proposalConfig.VotingWhitelist) {
log.Error("Address not in voting whitelist")
ape.RenderErr(w, problems.Forbidden())
return
}

tx, err := sendTx(r, &txd, &votingAddress)
if err != nil {
log.WithError(err).Error("failed to send tx")
Expand Down

0 comments on commit 653bb46

Please sign in to comment.