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) }