Implement eth_accounts (#100)

This commit is contained in:
Austin Abell 2019-09-18 09:58:48 -04:00 committed by GitHub
parent 1b5c33cf33
commit 02047bf8bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import (
"math/big"
"github.com/cosmos/cosmos-sdk/client/context"
emintkeys "github.com/cosmos/ethermint/keys"
"github.com/cosmos/ethermint/version"
"github.com/cosmos/ethermint/x/evm/types"
"github.com/ethereum/go-ethereum/common"
@ -58,8 +59,24 @@ func (e *PublicEthAPI) GasPrice() *hexutil.Big {
}
// Accounts returns the list of accounts available to this node.
func (e *PublicEthAPI) Accounts() []common.Address {
return nil
func (e *PublicEthAPI) Accounts() ([]common.Address, error) {
addresses := make([]common.Address, 0) // return [] instead of nil if empty
keybase, err := emintkeys.NewKeyBaseFromHomeFlag()
if err != nil {
return addresses, err
}
infos, err := keybase.List()
if err != nil {
return addresses, err
}
for _, info := range infos {
addressBytes := info.GetPubKey().Address().Bytes()
addresses = append(addresses, common.BytesToAddress(addressBytes))
}
return addresses, nil
}
// BlockNumber returns the current block number.