output hex values instead of numbers

This commit is contained in:
Chris Ziogas 2024-05-30 14:42:38 +03:00
parent b07ef33e95
commit e4a2c82af2
No known key found for this signature in database
GPG key ID: 2329CF479E36E2DA
4 changed files with 156 additions and 42 deletions

View file

@ -28,6 +28,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
@ -43,15 +44,15 @@ import (
)
type supplyInfoIssuance struct {
GenesisAlloc *big.Int `json:"genesisAlloc,omitempty"`
Reward *big.Int `json:"reward"`
Withdrawals *big.Int `json:"withdrawals"`
GenesisAlloc *hexutil.Big `json:"genesisAlloc,omitempty"`
Reward *hexutil.Big `json:"reward"`
Withdrawals *hexutil.Big `json:"withdrawals"`
}
type supplyInfoBurn struct {
EIP1559 *big.Int `json:"1559"`
Blob *big.Int `json:"blob"`
Misc *big.Int `json:"misc"`
EIP1559 *hexutil.Big `json:"1559"`
Blob *hexutil.Big `json:"blob"`
Misc *hexutil.Big `json:"misc"`
}
type supplyInfo struct {
@ -87,14 +88,14 @@ func TestSupplyGenesisAlloc(t *testing.T) {
expected := supplyInfo{
Issuance: &supplyInfoIssuance{
GenesisAlloc: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
Reward: common.Big0,
Withdrawals: common.Big0,
GenesisAlloc: (*hexutil.Big)(new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))),
Reward: (*hexutil.Big)(common.Big0),
Withdrawals: (*hexutil.Big)(common.Big0),
},
Burn: &supplyInfoBurn{
EIP1559: common.Big0,
Blob: common.Big0,
Misc: common.Big0,
EIP1559: (*hexutil.Big)(common.Big0),
Blob: (*hexutil.Big)(common.Big0),
Misc: (*hexutil.Big)(common.Big0),
},
Number: 0,
Hash: common.HexToHash("0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca"),
@ -122,13 +123,13 @@ func TestSupplyRewards(t *testing.T) {
expected := supplyInfo{
Issuance: &supplyInfoIssuance{
Reward: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
Withdrawals: common.Big0,
Reward: (*hexutil.Big)(new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))),
Withdrawals: (*hexutil.Big)(common.Big0),
},
Burn: &supplyInfoBurn{
EIP1559: common.Big0,
Blob: common.Big0,
Misc: common.Big0,
EIP1559: (*hexutil.Big)(common.Big0),
Blob: (*hexutil.Big)(common.Big0),
Misc: (*hexutil.Big)(common.Big0),
},
Number: 1,
Hash: common.HexToHash("0xcbb08370505be503dafedc4e96d139ea27aba3cbc580148568b8a307b3f51052"),
@ -192,13 +193,13 @@ func TestSupplyEip1559Burn(t *testing.T) {
burn = new(big.Int).Mul(big.NewInt(21000), head.BaseFee)
expected = supplyInfo{
Issuance: &supplyInfoIssuance{
Reward: reward,
Withdrawals: common.Big0,
Reward: (*hexutil.Big)(reward),
Withdrawals: (*hexutil.Big)(common.Big0),
},
Burn: &supplyInfoBurn{
EIP1559: burn,
Blob: common.Big0,
Misc: common.Big0,
EIP1559: (*hexutil.Big)(burn),
Blob: (*hexutil.Big)(common.Big0),
Misc: (*hexutil.Big)(common.Big0),
},
Number: 1,
Hash: head.Hash(),
@ -237,13 +238,13 @@ func TestSupplyWithdrawals(t *testing.T) {
head = chain.CurrentBlock()
expected = supplyInfo{
Issuance: &supplyInfoIssuance{
Reward: common.Big0,
Withdrawals: big.NewInt(1337000000000),
Reward: (*hexutil.Big)(common.Big0),
Withdrawals: (*hexutil.Big)(big.NewInt(1337000000000)),
},
Burn: &supplyInfoBurn{
EIP1559: common.Big0,
Blob: common.Big0,
Misc: common.Big0,
EIP1559: (*hexutil.Big)(common.Big0),
Blob: (*hexutil.Big)(common.Big0),
Misc: (*hexutil.Big)(common.Big0),
},
Number: 1,
Hash: head.Hash(),
@ -338,13 +339,13 @@ func TestSupplySelfdestruct(t *testing.T) {
// Check live trace output
expected := supplyInfo{
Issuance: &supplyInfoIssuance{
Reward: common.Big0,
Withdrawals: common.Big0,
Reward: (*hexutil.Big)(common.Big0),
Withdrawals: (*hexutil.Big)(common.Big0),
},
Burn: &supplyInfoBurn{
EIP1559: big.NewInt(55289500000000),
Blob: common.Big0,
Misc: big.NewInt(5000000000),
EIP1559: (*hexutil.Big)(big.NewInt(55289500000000)),
Blob: (*hexutil.Big)(common.Big0),
Misc: (*hexutil.Big)(big.NewInt(5000000000)),
},
Number: 1,
Hash: head.Hash(),
@ -384,13 +385,13 @@ func TestSupplySelfdestruct(t *testing.T) {
head = postCancunChain.CurrentBlock()
expected = supplyInfo{
Issuance: &supplyInfoIssuance{
Reward: common.Big0,
Withdrawals: common.Big0,
Reward: (*hexutil.Big)(common.Big0),
Withdrawals: (*hexutil.Big)(common.Big0),
},
Burn: &supplyInfoBurn{
EIP1559: big.NewInt(55289500000000),
Blob: common.Big0,
Misc: common.Big0,
EIP1559: (*hexutil.Big)(big.NewInt(55289500000000)),
Blob: (*hexutil.Big)(common.Big0),
Misc: (*hexutil.Big)(common.Big0),
},
Number: 1,
Hash: head.Hash(),
@ -535,13 +536,13 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) {
expected := supplyInfo{
Issuance: &supplyInfoIssuance{
Reward: common.Big0,
Withdrawals: common.Big0,
Reward: (*hexutil.Big)(common.Big0),
Withdrawals: (*hexutil.Big)(common.Big0),
},
Burn: &supplyInfoBurn{
EIP1559: new(big.Int).Mul(block.BaseFee(), big.NewInt(int64(block.GasUsed()))),
Blob: common.Big0,
Misc: eth5, // 5ETH burned from contract B
EIP1559: (*hexutil.Big)(new(big.Int).Mul(block.BaseFee(), big.NewInt(int64(block.GasUsed())))),
Blob: (*hexutil.Big)(common.Big0),
Misc: (*hexutil.Big)(eth5), // 5ETH burned from contract B
},
Number: 1,
Hash: block.Hash(),

View file

@ -0,0 +1,49 @@
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package live
import (
"encoding/json"
"math/big"
"github.com/ethereum/go-ethereum/common/hexutil"
)
var _ = (*supplyInfoBurnMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (s supplyInfoBurn) MarshalJSON() ([]byte, error) {
type supplyInfoBurn struct {
EIP1559 *hexutil.Big `json:"1559"`
Blob *hexutil.Big `json:"blob"`
Misc *hexutil.Big `json:"misc"`
}
var enc supplyInfoBurn
enc.EIP1559 = (*hexutil.Big)(s.EIP1559)
enc.Blob = (*hexutil.Big)(s.Blob)
enc.Misc = (*hexutil.Big)(s.Misc)
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (s *supplyInfoBurn) UnmarshalJSON(input []byte) error {
type supplyInfoBurn struct {
EIP1559 *hexutil.Big `json:"1559"`
Blob *hexutil.Big `json:"blob"`
Misc *hexutil.Big `json:"misc"`
}
var dec supplyInfoBurn
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.EIP1559 != nil {
s.EIP1559 = (*big.Int)(dec.EIP1559)
}
if dec.Blob != nil {
s.Blob = (*big.Int)(dec.Blob)
}
if dec.Misc != nil {
s.Misc = (*big.Int)(dec.Misc)
}
return nil
}

View file

@ -0,0 +1,49 @@
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package live
import (
"encoding/json"
"math/big"
"github.com/ethereum/go-ethereum/common/hexutil"
)
var _ = (*supplyInfoIssuanceMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (s supplyInfoIssuance) MarshalJSON() ([]byte, error) {
type supplyInfoIssuance struct {
GenesisAlloc *hexutil.Big `json:"genesisAlloc,omitempty"`
Reward *hexutil.Big `json:"reward"`
Withdrawals *hexutil.Big `json:"withdrawals"`
}
var enc supplyInfoIssuance
enc.GenesisAlloc = (*hexutil.Big)(s.GenesisAlloc)
enc.Reward = (*hexutil.Big)(s.Reward)
enc.Withdrawals = (*hexutil.Big)(s.Withdrawals)
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (s *supplyInfoIssuance) UnmarshalJSON(input []byte) error {
type supplyInfoIssuance struct {
GenesisAlloc *hexutil.Big `json:"genesisAlloc,omitempty"`
Reward *hexutil.Big `json:"reward"`
Withdrawals *hexutil.Big `json:"withdrawals"`
}
var dec supplyInfoIssuance
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.GenesisAlloc != nil {
s.GenesisAlloc = (*big.Int)(dec.GenesisAlloc)
}
if dec.Reward != nil {
s.Reward = (*big.Int)(dec.Reward)
}
if dec.Withdrawals != nil {
s.Withdrawals = (*big.Int)(dec.Withdrawals)
}
return nil
}

View file

@ -8,6 +8,7 @@ import (
"path/filepath"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
@ -27,12 +28,26 @@ type supplyInfoIssuance struct {
Withdrawals *big.Int `json:"withdrawals"`
}
//go:generate go run github.com/fjl/gencodec -type supplyInfoIssuance -field-override supplyInfoIssuanceMarshaling -out gen_supplyinfoissuance.go
type supplyInfoIssuanceMarshaling struct {
GenesisAlloc *hexutil.Big
Reward *hexutil.Big
Withdrawals *hexutil.Big
}
type supplyInfoBurn struct {
EIP1559 *big.Int `json:"1559"`
Blob *big.Int `json:"blob"`
Misc *big.Int `json:"misc"`
}
//go:generate go run github.com/fjl/gencodec -type supplyInfoBurn -field-override supplyInfoBurnMarshaling -out gen_supplyinfoburn.go
type supplyInfoBurnMarshaling struct {
EIP1559 *hexutil.Big
Blob *hexutil.Big
Misc *hexutil.Big
}
type supplyInfo struct {
Issuance *supplyInfoIssuance `json:"issuance"`
Burn *supplyInfoBurn `json:"burn"`