Skip to content

Commit

Permalink
refactor: apply small code improvements
Browse files Browse the repository at this point in the history
This commit renames the internal reference to the LivepeerGovernor
contract and improves the proposalVote handler data type parsing
behavoir.
  • Loading branch information
rickstaa committed Nov 25, 2024
1 parent 92add81 commit 8dc634f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
28 changes: 14 additions & 14 deletions eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ type client struct {
transOpts bind.TransactOpts
transOptsMu sync.RWMutex

controllerAddr ethcommon.Address
tokenAddr ethcommon.Address
serviceRegistryAddr ethcommon.Address
bondingManagerAddr ethcommon.Address
ticketBrokerAddr ethcommon.Address
roundsManagerAddr ethcommon.Address
minterAddr ethcommon.Address
verifierAddr ethcommon.Address
faucetAddr ethcommon.Address
governorAddr ethcommon.Address
controllerAddr ethcommon.Address
tokenAddr ethcommon.Address
serviceRegistryAddr ethcommon.Address
bondingManagerAddr ethcommon.Address
ticketBrokerAddr ethcommon.Address
roundsManagerAddr ethcommon.Address
minterAddr ethcommon.Address
verifierAddr ethcommon.Address
faucetAddr ethcommon.Address
livepeerGovernorAddr ethcommon.Address

// Contracts
controller *contracts.Controller
Expand Down Expand Up @@ -330,22 +330,22 @@ func (c *client) setContracts(opts *bind.TransactOpts) error {

glog.V(common.SHORT).Infof("LivepeerTokenFaucet: %v", c.faucetAddr.Hex())

governorAddr, err := c.GetContract(crypto.Keccak256Hash([]byte("LivepeerGovernor")))
livepeerGovernorAddr, err := c.GetContract(crypto.Keccak256Hash([]byte("LivepeerGovernor")))
if err != nil {
glog.Errorf("Error getting Governor address: %v", err)
return err
}

c.governorAddr = governorAddr
c.livepeerGovernorAddr = livepeerGovernorAddr

governor, err := contracts.NewGovernor(governorAddr, c.backend)
governor, err := contracts.NewGovernor(livepeerGovernorAddr, c.backend)
if err != nil {
glog.Errorf("Error creating Governor binding: %v", err)
return err
}
c.livepeerGovernor = governor

glog.V(common.SHORT).Infof("LivepeerGovernor: %v", c.governorAddr.Hex())
glog.V(common.SHORT).Infof("LivepeerGovernor: %v", c.livepeerGovernorAddr.Hex())

return nil
}
Expand Down
11 changes: 6 additions & 5 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,12 +1291,12 @@ func proposalVoteHandler(client eth.LivepeerEthClient) http.Handler {
}

supportStr := r.FormValue("support")
support, err := strconv.Atoi(supportStr)
if err != nil {
support, ok := new(big.Int).SetString(supportStr, 10)
if !ok {
respond500(w, "support is not a valid integer value")
return
}
if !types.ProposalVoteChoice(support).IsValid() {
if !types.ProposalVoteChoice(int(support.Int64())).IsValid() {
respond500(w, "invalid support")
return
}
Expand All @@ -1305,10 +1305,11 @@ func proposalVoteHandler(client eth.LivepeerEthClient) http.Handler {

// submit tx
var tx *ethtypes.Transaction
var err error
if reason != "" {
tx, err = client.ProposalVoteWithReason(proposalID, uint8(support), reason)
tx, err = client.ProposalVoteWithReason(proposalID, uint8(support.Uint64()), reason)
} else {
tx, err = client.ProposalVote(proposalID, uint8(support))
tx, err = client.ProposalVote(proposalID, uint8(support.Uint64()))
}
if err != nil {
respond500(w, fmt.Sprintf("unable to submit proposal vote transaction err=%q", err))
Expand Down

0 comments on commit 8dc634f

Please sign in to comment.