ethapi: bubble up listaccounts error, remove extapi ref from private acct api

This commit is contained in:
Martin Holst Swende 2018-09-25 17:28:46 +02:00
parent 9e3f27fc18
commit b1da7dfece
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 11 additions and 15 deletions

View file

@ -191,21 +191,17 @@ func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI {
p := &PrivateAccountAPI{ p := &PrivateAccountAPI{
nonceLock: nonceLock, nonceLock: nonceLock,
b: b, b: b,
extapi: b.ExternalSigner(),
} }
return p return p
} }
// ListAccounts will return a list of addresses for accounts this node manages. // ListAccounts will return a list of addresses for accounts this node manages.
func (s *PrivateAccountAPI) ListAccounts() []common.Address { func (s *PrivateAccountAPI) ListAccounts() ([]common.Address, error) {
addresses := make([]common.Address, 0) // return [] instead of nil if empty if extapi := s.b.ExternalSigner(); extapi != nil {
if s.extapi != nil { return extapi.ListAccounts()
if accounts, err := s.extapi.ListAccounts(); err == nil {
return accounts
} }
return addresses // return [] instead of nil if empty
} return []common.Address{}, errors.New("external signer not configured")
return addresses
} }
// rawWallet is a JSON representation of an accounts.Wallet interface, with its // 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) { 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") return nil, errors.New("External API not initialized")
} }
res := SignTransactionResult{} res := SignTransactionResult{}
@ -1328,7 +1324,7 @@ func (api *ExternalSignerClient) SignTransaction(ctx context.Context, args SendT
return res.Tx, nil return res.Tx, nil
} }
func (api *ExternalSignerClient) ListAccounts() ([]common.Address, error) { func (api *ExternalSignerClient) ListAccounts() ([]common.Address, error) {
if api == nil{ if api == nil {
return []common.Address{}, errors.New("External API not initialized") return []common.Address{}, errors.New("External API not initialized")
} }
var res []common.Address var res []common.Address
@ -1338,7 +1334,7 @@ func (api *ExternalSignerClient) ListAccounts() ([]common.Address, error) {
return res, nil return res, nil
} }
func (api *ExternalSignerClient) NewAccount() (common.Address, error) { func (api *ExternalSignerClient) NewAccount() (common.Address, error) {
if api == nil{ if api == nil {
return common.Address{}, errors.New("External API not initialized") return common.Address{}, errors.New("External API not initialized")
} }
var res accounts.Account var res accounts.Account
@ -1349,7 +1345,7 @@ func (api *ExternalSignerClient) NewAccount() (common.Address, error) {
return res.Address, nil return res.Address, nil
} }
func (api *ExternalSignerClient) SignCliqueBlock(a common.Address, rlpBlock hexutil.Bytes) (hexutil.Bytes, error) { 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") return nil, errors.New("External API not initialized")
} }
var sig hexutil.Bytes var sig hexutil.Bytes

View file

@ -102,7 +102,7 @@ func GetAPIs(apiBackend Backend) []rpc.API {
Namespace: "debug", Namespace: "debug",
Version: "1.0", Version: "1.0",
Service: NewPrivateDebugAPI(apiBackend), Service: NewPrivateDebugAPI(apiBackend),
},{ }, {
Namespace: "personal", Namespace: "personal",
Version: "1.0", Version: "1.0",
Service: NewPrivateAccountAPI(apiBackend, nonceLock), Service: NewPrivateAccountAPI(apiBackend, nonceLock),