internal/ethapi, les: use slices package for sorting (#27492)

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Dan Laine
2023-06-19 11:33:48 +02:00
committed by GitHub
co-authored by Felix Lange
parent a848212709
commit 87e510d963
3 changed files with 22 additions and 56 deletions
+3 -10
View File
@@ -17,7 +17,6 @@
package ethapi
import (
"bytes"
"context"
"crypto/ecdsa"
"encoding/json"
@@ -25,7 +24,6 @@ import (
"hash"
"math/big"
"reflect"
"sort"
"testing"
"time"
@@ -48,6 +46,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"
)
func TestTransaction_RoundTripRpcJSON(t *testing.T) {
@@ -649,19 +648,13 @@ type Account struct {
addr common.Address
}
type Accounts []Account
func (a Accounts) Len() int { return len(a) }
func (a Accounts) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Accounts) Less(i, j int) bool { return bytes.Compare(a[i].addr.Bytes(), a[j].addr.Bytes()) < 0 }
func newAccounts(n int) (accounts Accounts) {
func newAccounts(n int) (accounts []Account) {
for i := 0; i < n; i++ {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
accounts = append(accounts, Account{key: key, addr: addr})
}
sort.Sort(accounts)
slices.SortFunc(accounts, func(a, b Account) bool { return a.addr.Less(b.addr) })
return accounts
}