From 59f12dcc52ef8bdc6e431c61a87db2dcdba668bb Mon Sep 17 00:00:00 2001 From: Diego Essaya Date: Wed, 20 Sep 2023 18:52:34 -0300 Subject: [PATCH] fix(jsonrpc): preserve order in eth_accounts --- packages/evm/jsonrpc/accounts.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/evm/jsonrpc/accounts.go b/packages/evm/jsonrpc/accounts.go index 01ccb6ee05..149d8b6d29 100644 --- a/packages/evm/jsonrpc/accounts.go +++ b/packages/evm/jsonrpc/accounts.go @@ -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 { @@ -30,6 +32,7 @@ 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 { @@ -37,11 +40,5 @@ func (a *AccountManager) Get(addr common.Address) *ecdsa.PrivateKey { } 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) }