Skip to content

Commit

Permalink
eth: client setup cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Jan 7, 2021
1 parent 218123f commit 776a65a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
10 changes: 2 additions & 8 deletions cmd/devtool/devtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,13 @@ func ethSetup(ethAcctAddr, keystoreDir string, isBroadcaster bool) {
}
glog.Infof("Using controller address %s", ethController)

client, err := eth.NewClient(ethcommon.HexToAddress(ethAcctAddr), keystoreDir, backend,
ethcommon.HexToAddress(ethController), ethTxTimeout)
client, err := eth.NewClient(ethcommon.HexToAddress(ethAcctAddr), keystoreDir, passphrase, backend,
ethcommon.HexToAddress(ethController), ethTxTimeout, nil)
if err != nil {
glog.Errorf("Failed to create client: %v", err)
return
}

err = client.Setup(passphrase, uint64(0), nil)
if err != nil {
glog.Fatalf("Failed to setup client: %v", err)
return
}

if isBroadcaster {
amount := new(big.Int).Mul(big.NewInt(100), new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))

Expand Down
22 changes: 5 additions & 17 deletions eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var (
)

type LivepeerEthClient interface {
Setup(password string, gasLimit uint64, gasPrice *big.Int) error
Account() accounts.Account
Backend() (Backend, error)

Expand Down Expand Up @@ -164,6 +163,10 @@ func NewClient(accountAddr ethcommon.Address, keystoreDir, password string, eth
return nil, err
}

if err := am.Unlock(password); err != nil {
return nil, err
}

return &client{
accountManager: am,
backend: backend,
Expand All @@ -172,15 +175,6 @@ func NewClient(accountAddr ethcommon.Address, keystoreDir, password string, eth
}, nil
}

func (c *client) Setup(password string, gasLimit uint64, gasPrice *big.Int) error {
err := c.accountManager.Unlock(password)
if err != nil {
return err
}

return c.SetGasInfo(gasLimit, gasPrice)
}

func (c *client) setContracts(opts *bind.TransactOpts) error {
controller, err := contracts.NewController(c.controllerAddr, c.backend)
if err != nil {
Expand Down Expand Up @@ -579,13 +573,7 @@ func (c *client) Vote(pollAddr ethcommon.Address, choiceID *big.Int) (*types.Tra
return nil, err
}

gl, gp := c.GetGasInfo()
opts, err := c.accountManager.CreateTransactOpts(gl, gp)
if err != nil {
return nil, err
}

return poll.Vote(opts, choiceID)
return poll.Vote(nil, choiceID)
}

func (c *client) Reward() (*types.Transaction, error) {
Expand Down

0 comments on commit 776a65a

Please sign in to comment.