diff --git a/bfa_client/src/bfa/node.go b/bfa_client/src/bfa/node.go index 09882ed187c87e7f64949bbbdd19c5ff8991aad7..f85b2fca82b111250c278ade0ac608fcfec5dcb0 100644 --- a/bfa_client/src/bfa/node.go +++ b/bfa_client/src/bfa/node.go @@ -2,7 +2,6 @@ package bfa import ( . "../util" - "fmt" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/p2p" @@ -55,6 +54,10 @@ func (node *Node) Call(result interface{}, method string, args ...interface{}) { Check((*rpc.Client)(node).Call(result, method, args...)) } +func (node *Node) CallWithError(result interface{}, method string, args ...interface{}) error { + return (*rpc.Client)(node).Call(result, method, args...) +} + func (node *Node) BlockNumber() int64 { var bn rpc.BlockNumber node.Call(&bn, "eth_blockNumber") @@ -87,22 +90,8 @@ func (node *Node) Balance(account common.Address) *big.Int { return node.BalanceAtBlock(account, -1) } -func (node *Node) Coinbase() (coinbase string, err error) { - defer func() { - if e := recover(); e != nil { - switch s := e.(type) { - case string: - err = fmt.Errorf(s) - case error: - err = s - default: - err = fmt.Errorf("unknown error while getting coinbase: %v", e) - } - } - }() - var address common.Address - node.Call(&address, "eth_coinbase") - coinbase = BytesToHex(address[:]) +func (node *Node) Coinbase() (address string, err error) { + err = node.CallWithError(&address, "eth_coinbase") return } @@ -190,7 +179,9 @@ func (node *Node) SealersAtBlock(blockNumber int64) (signers []string) { func (node *Node) IsSealer(address string) bool { if address == Self { - var err error + var ( + err error + ) if address, err = node.Coinbase(); err != nil { return false } @@ -200,7 +191,9 @@ func (node *Node) IsSealer(address string) bool { func (node *Node) IsSealerAtBlock(address string, blockNumber int64) bool { if address == Self { - var err error + var ( + err error + ) if address, err = node.Coinbase(); err != nil { return false }