From cd1ff5d3227fea17c492d267c921e530a43c3076 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Wed, 11 Dec 2024 18:46:00 +0800 Subject: [PATCH] common: remove function Big() for type Address (#19210) --- common/types.go | 3 --- common/types_test.go | 4 ++-- core/mkalloc.go | 12 ++++++------ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/common/types.go b/common/types.go index a33fe35bcc..e2dd3b4b2d 100644 --- a/common/types.go +++ b/common/types.go @@ -227,9 +227,6 @@ func (a Address) Str() string { return string(a[:]) } // Bytes gets the string representation of the underlying address. func (a Address) Bytes() []byte { return a[:] } -// Big converts an address to a big integer. -func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) } - // Hash converts an address to a hash by left-padding it with zeros. func (a Address) Hash() Hash { return BytesToHash(a[:]) } diff --git a/common/types_test.go b/common/types_test.go index 7c2822854a..ea0fb22d24 100644 --- a/common/types_test.go +++ b/common/types_test.go @@ -118,8 +118,8 @@ func TestAddressUnmarshalJSON(t *testing.T) { if test.ShouldErr { t.Errorf("test #%d: expected error, got none", i) } - if v.Big().Cmp(test.Output) != 0 { - t.Errorf("test #%d: address mismatch: have %v, want %v", i, v.Big(), test.Output) + if got := new(big.Int).SetBytes(v.Bytes()); got.Cmp(test.Output) != 0 { + t.Errorf("test #%d: address mismatch: have %v, want %v", i, got, test.Output) } } } diff --git a/core/mkalloc.go b/core/mkalloc.go index 6bc4e55d89..6c8a5d0ee5 100644 --- a/core/mkalloc.go +++ b/core/mkalloc.go @@ -14,15 +14,14 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build none // +build none /* +The mkalloc tool creates the genesis allocation constants in genesis_alloc.go +It outputs a const declaration that contains an RLP-encoded list of (address, balance) tuples. - The mkalloc tool creates the genesis allocation constants in genesis_alloc.go - It outputs a const declaration that contains an RLP-encoded list of (address, balance) tuples. - - go run mkalloc.go genesis.json - + go run mkalloc.go genesis.json */ package main @@ -52,7 +51,8 @@ func makelist(g *core.Genesis) allocList { if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 { panic(fmt.Sprintf("can't encode account %x", addr)) } - a = append(a, allocItem{addr.Big(), account.Balance}) + bigAddr := new(big.Int).SetBytes(addr.Bytes()) + a = append(a, allocItem{bigAddr, account.Balance}) } sort.Sort(a) return a