From b1da7dfecea13d3bfe4841d5853726e33fa985f5 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 25 Sep 2018 17:28:46 +0200 Subject: [PATCH] ethapi: bubble up listaccounts error, remove extapi ref from private acct api --- internal/ethapi/api.go | 22 +++++++++------------- internal/ethapi/backend.go | 4 ++-- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index cccfbe8c7e..5400eb2c9c 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -191,21 +191,17 @@ func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI { p := &PrivateAccountAPI{ nonceLock: nonceLock, b: b, - extapi: b.ExternalSigner(), } return p } // ListAccounts will return a list of addresses for accounts this node manages. -func (s *PrivateAccountAPI) ListAccounts() []common.Address { - addresses := make([]common.Address, 0) // return [] instead of nil if empty - if s.extapi != nil { - if accounts, err := s.extapi.ListAccounts(); err == nil { - return accounts - } - return addresses +func (s *PrivateAccountAPI) ListAccounts() ([]common.Address, error) { + if extapi := s.b.ExternalSigner(); extapi != nil { + return extapi.ListAccounts() } - return addresses + // return [] instead of nil if empty + return []common.Address{}, errors.New("external signer not configured") } // rawWallet is a JSON representation of an accounts.Wallet interface, with its @@ -1318,7 +1314,7 @@ func NewExternalSigner(endpoint string) (*ExternalSignerClient, error) { } func (api *ExternalSignerClient) SignTransaction(ctx context.Context, args SendTxArgs) (*types.Transaction, error) { - if api == nil{ + if api == nil { return nil, errors.New("External API not initialized") } res := SignTransactionResult{} @@ -1328,7 +1324,7 @@ func (api *ExternalSignerClient) SignTransaction(ctx context.Context, args SendT return res.Tx, nil } func (api *ExternalSignerClient) ListAccounts() ([]common.Address, error) { - if api == nil{ + if api == nil { return []common.Address{}, errors.New("External API not initialized") } var res []common.Address @@ -1338,7 +1334,7 @@ func (api *ExternalSignerClient) ListAccounts() ([]common.Address, error) { return res, nil } func (api *ExternalSignerClient) NewAccount() (common.Address, error) { - if api == nil{ + if api == nil { return common.Address{}, errors.New("External API not initialized") } var res accounts.Account @@ -1349,7 +1345,7 @@ func (api *ExternalSignerClient) NewAccount() (common.Address, error) { return res.Address, nil } func (api *ExternalSignerClient) SignCliqueBlock(a common.Address, rlpBlock hexutil.Bytes) (hexutil.Bytes, error) { - if api == nil{ + if api == nil { return nil, errors.New("External API not initialized") } var sig hexutil.Bytes diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 8312a3a25f..f80e7c2857 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -43,7 +43,7 @@ type Backend interface { ChainDb() ethdb.Database EventMux() *event.TypeMux ExternalSigner() *ExternalSignerClient - + // BlockChain API SetHead(number uint64) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) @@ -102,7 +102,7 @@ func GetAPIs(apiBackend Backend) []rpc.API { Namespace: "debug", Version: "1.0", Service: NewPrivateDebugAPI(apiBackend), - },{ + }, { Namespace: "personal", Version: "1.0", Service: NewPrivateAccountAPI(apiBackend, nonceLock),