Commit 54253aae authored by bas-vk's avatar bas-vk Committed by Péter Szilágyi

internal/ethapi: return empty arrays instead of null (#14374)

* internal/ethapi: return empty arrays instead of null

* internal/ethapi: minor comments to avoid future regressions
parent 09aabaea
...@@ -191,7 +191,7 @@ func NewPublicAccountAPI(am *accounts.Manager) *PublicAccountAPI { ...@@ -191,7 +191,7 @@ func NewPublicAccountAPI(am *accounts.Manager) *PublicAccountAPI {
// Accounts returns the collection of accounts this node manages // Accounts returns the collection of accounts this node manages
func (s *PublicAccountAPI) Accounts() []common.Address { func (s *PublicAccountAPI) Accounts() []common.Address {
var addresses []common.Address addresses := make([]common.Address, 0) // return [] instead of nil if empty
for _, wallet := range s.am.Wallets() { for _, wallet := range s.am.Wallets() {
for _, account := range wallet.Accounts() { for _, account := range wallet.Accounts() {
addresses = append(addresses, account.Address) addresses = append(addresses, account.Address)
...@@ -218,7 +218,7 @@ func NewPrivateAccountAPI(b Backend) *PrivateAccountAPI { ...@@ -218,7 +218,7 @@ func NewPrivateAccountAPI(b Backend) *PrivateAccountAPI {
// 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 {
var addresses []common.Address addresses := make([]common.Address, 0) // return [] instead of nil if empty
for _, wallet := range s.am.Wallets() { for _, wallet := range s.am.Wallets() {
for _, account := range wallet.Accounts() { for _, account := range wallet.Accounts() {
addresses = append(addresses, account.Address) addresses = append(addresses, account.Address)
...@@ -237,7 +237,7 @@ type rawWallet struct { ...@@ -237,7 +237,7 @@ type rawWallet struct {
// ListWallets will return a list of wallets this node manages. // ListWallets will return a list of wallets this node manages.
func (s *PrivateAccountAPI) ListWallets() []rawWallet { func (s *PrivateAccountAPI) ListWallets() []rawWallet {
var wallets []rawWallet wallets := make([]rawWallet, 0) // return [] instead of nil if empty
for _, wallet := range s.am.Wallets() { for _, wallet := range s.am.Wallets() {
wallets = append(wallets, rawWallet{ wallets = append(wallets, rawWallet{
URL: wallet.URL().String(), URL: wallet.URL().String(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment