mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-13 11:36:37 +00:00
cmd/devp2p/internal/ethtest: using slices.SortFunc to simplify the code (#31012)
Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
parent
f460f019e9
commit
8752785a98
1 changed files with 3 additions and 22 deletions
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -41,6 +40,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Chain is a lightweight blockchain-like store which can read a hivechain
|
// Chain is a lightweight blockchain-like store which can read a hivechain
|
||||||
|
|
@ -166,11 +166,8 @@ func (c *Chain) RootAt(height int) common.Hash {
|
||||||
// GetSender returns the address associated with account at the index in the
|
// GetSender returns the address associated with account at the index in the
|
||||||
// pre-funded accounts list.
|
// pre-funded accounts list.
|
||||||
func (c *Chain) GetSender(idx int) (common.Address, uint64) {
|
func (c *Chain) GetSender(idx int) (common.Address, uint64) {
|
||||||
var accounts Addresses
|
accounts := maps.Keys(c.senders)
|
||||||
for addr := range c.senders {
|
slices.SortFunc(accounts, common.Address.Cmp)
|
||||||
accounts = append(accounts, addr)
|
|
||||||
}
|
|
||||||
sort.Sort(accounts)
|
|
||||||
addr := accounts[idx]
|
addr := accounts[idx]
|
||||||
return addr, c.senders[addr].Nonce
|
return addr, c.senders[addr].Nonce
|
||||||
}
|
}
|
||||||
|
|
@ -260,22 +257,6 @@ func loadGenesis(genesisFile string) (core.Genesis, error) {
|
||||||
return gen, nil
|
return gen, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Addresses []common.Address
|
|
||||||
|
|
||||||
func (a Addresses) Len() int {
|
|
||||||
return len(a)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a Addresses) Less(i, j int) bool {
|
|
||||||
return bytes.Compare(a[i][:], a[j][:]) < 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a Addresses) Swap(i, j int) {
|
|
||||||
tmp := a[i]
|
|
||||||
a[i] = a[j]
|
|
||||||
a[j] = tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
func blocksFromFile(chainfile string, gblock *types.Block) ([]*types.Block, error) {
|
func blocksFromFile(chainfile string, gblock *types.Block) ([]*types.Block, error) {
|
||||||
// Load chain.rlp.
|
// Load chain.rlp.
|
||||||
fh, err := os.Open(chainfile)
|
fh, err := os.Open(chainfile)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue