Skip to content

Commit

Permalink
fix(jsonrpc): preserve order in eth_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dessaya committed Sep 20, 2023
1 parent 8a43912 commit c630cf6
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/evm/jsonrpc/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"golang.org/x/exp/slices"
)

type AccountManager struct {
accounts map[common.Address]*ecdsa.PrivateKey
addrs []common.Address
}

func NewAccountManager(accounts []*ecdsa.PrivateKey) *AccountManager {
Expand All @@ -30,18 +32,13 @@ func (a *AccountManager) Add(keyPair *ecdsa.PrivateKey) {
return
}
a.accounts[addr] = keyPair
a.addrs = append(a.addrs, addr)
}

func (a *AccountManager) Get(addr common.Address) *ecdsa.PrivateKey {
return a.accounts[addr]
}

func (a *AccountManager) Addresses() []common.Address {
ret := make([]common.Address, len(a.accounts))
i := 0
for addr := range a.accounts {
ret[i] = addr
i++
}
return ret
return slices.Clone(a.addrs)
}

0 comments on commit c630cf6

Please sign in to comment.