Skip to content

Commit 54253aa

Browse files
bas-vkkaralabe
authored andcommitted
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
1 parent 09aabae commit 54253aa

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎internal/ethapi/api.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func NewPublicAccountAPI(am *accounts.Manager) *PublicAccountAPI {
191191

192192
// Accounts returns the collection of accounts this node manages
193193
func (s *PublicAccountAPI) Accounts() []common.Address {
194-
var addresses []common.Address
194+
addresses := make([]common.Address, 0) // return [] instead of nil if empty
195195
for _, wallet := range s.am.Wallets() {
196196
for _, account := range wallet.Accounts() {
197197
addresses = append(addresses, account.Address)
@@ -218,7 +218,7 @@ func NewPrivateAccountAPI(b Backend) *PrivateAccountAPI {
218218

219219
// ListAccounts will return a list of addresses for accounts this node manages.
220220
func (s *PrivateAccountAPI) ListAccounts() []common.Address {
221-
var addresses []common.Address
221+
addresses := make([]common.Address, 0) // return [] instead of nil if empty
222222
for _, wallet := range s.am.Wallets() {
223223
for _, account := range wallet.Accounts() {
224224
addresses = append(addresses, account.Address)
@@ -237,7 +237,7 @@ type rawWallet struct {
237237

238238
// ListWallets will return a list of wallets this node manages.
239239
func (s *PrivateAccountAPI) ListWallets() []rawWallet {
240-
var wallets []rawWallet
240+
wallets := make([]rawWallet, 0) // return [] instead of nil if empty
241241
for _, wallet := range s.am.Wallets() {
242242
wallets = append(wallets, rawWallet{
243243
URL: wallet.URL().String(),

0 commit comments

Comments
 (0)