common: remove function Big() for type Address (#19210)

This commit is contained in:
Daniel Liu 2024-12-11 18:46:00 +08:00
parent f19422e1c7
commit cd1ff5d322
3 changed files with 8 additions and 11 deletions

View file

@ -227,9 +227,6 @@ func (a Address) Str() string { return string(a[:]) }
// Bytes gets the string representation of the underlying address. // Bytes gets the string representation of the underlying address.
func (a Address) Bytes() []byte { return a[:] } 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. // Hash converts an address to a hash by left-padding it with zeros.
func (a Address) Hash() Hash { return BytesToHash(a[:]) } func (a Address) Hash() Hash { return BytesToHash(a[:]) }

View file

@ -118,8 +118,8 @@ func TestAddressUnmarshalJSON(t *testing.T) {
if test.ShouldErr { if test.ShouldErr {
t.Errorf("test #%d: expected error, got none", i) t.Errorf("test #%d: expected error, got none", i)
} }
if v.Big().Cmp(test.Output) != 0 { if got := new(big.Int).SetBytes(v.Bytes()); got.Cmp(test.Output) != 0 {
t.Errorf("test #%d: address mismatch: have %v, want %v", i, v.Big(), test.Output) t.Errorf("test #%d: address mismatch: have %v, want %v", i, got, test.Output)
} }
} }
} }

View file

@ -14,15 +14,14 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//go:build none
// +build none // +build none
/* /*
The mkalloc tool creates the genesis allocation constants in genesis_alloc.go 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. 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 package main
@ -52,7 +51,8 @@ func makelist(g *core.Genesis) allocList {
if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 { if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 {
panic(fmt.Sprintf("can't encode account %x", addr)) 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) sort.Sort(a)
return a return a