Skip to content

Commit 7be89a7

Browse files
authored
Merge pull request #20339 from etclabscore/fix/cmd-puppeth-blocknonce-type
cmd/puppeth: x-spec nonce data type, use types.BlockNonce
2 parents c5b46a7 + 59177bc commit 7be89a7

1 file changed

Lines changed: 16 additions & 22 deletions

File tree

‎cmd/puppeth/genesis.go‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package main
1818

1919
import (
20-
"encoding/binary"
2120
"errors"
2221
"math"
2322
"math/big"
@@ -28,6 +27,7 @@ import (
2827
math2 "github.com/ethereum/go-ethereum/common/math"
2928
"github.com/ethereum/go-ethereum/consensus/ethash"
3029
"github.com/ethereum/go-ethereum/core"
30+
"github.com/ethereum/go-ethereum/core/types"
3131
"github.com/ethereum/go-ethereum/params"
3232
)
3333

@@ -60,14 +60,14 @@ type alethGenesisSpec struct {
6060
} `json:"params"`
6161

6262
Genesis struct {
63-
Nonce hexutil.Bytes `json:"nonce"`
64-
Difficulty *hexutil.Big `json:"difficulty"`
65-
MixHash common.Hash `json:"mixHash"`
66-
Author common.Address `json:"author"`
67-
Timestamp hexutil.Uint64 `json:"timestamp"`
68-
ParentHash common.Hash `json:"parentHash"`
69-
ExtraData hexutil.Bytes `json:"extraData"`
70-
GasLimit hexutil.Uint64 `json:"gasLimit"`
63+
Nonce types.BlockNonce `json:"nonce"`
64+
Difficulty *hexutil.Big `json:"difficulty"`
65+
MixHash common.Hash `json:"mixHash"`
66+
Author common.Address `json:"author"`
67+
Timestamp hexutil.Uint64 `json:"timestamp"`
68+
ParentHash common.Hash `json:"parentHash"`
69+
ExtraData hexutil.Bytes `json:"extraData"`
70+
GasLimit hexutil.Uint64 `json:"gasLimit"`
7171
} `json:"genesis"`
7272

7373
Accounts map[common.UnprefixedAddress]*alethGenesisSpecAccount `json:"accounts"`
@@ -146,9 +146,7 @@ func newAlethGenesisSpec(network string, genesis *core.Genesis) (*alethGenesisSp
146146
spec.Params.DurationLimit = (*math2.HexOrDecimal256)(params.DurationLimit)
147147
spec.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward)
148148

149-
spec.Genesis.Nonce = (hexutil.Bytes)(make([]byte, 8))
150-
binary.LittleEndian.PutUint64(spec.Genesis.Nonce[:], genesis.Nonce)
151-
149+
spec.Genesis.Nonce = types.EncodeNonce(genesis.Nonce)
152150
spec.Genesis.MixHash = genesis.Mixhash
153151
spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty)
154152
spec.Genesis.Author = genesis.Coinbase
@@ -278,8 +276,8 @@ type parityChainSpec struct {
278276
Genesis struct {
279277
Seal struct {
280278
Ethereum struct {
281-
Nonce hexutil.Bytes `json:"nonce"`
282-
MixHash hexutil.Bytes `json:"mixHash"`
279+
Nonce types.BlockNonce `json:"nonce"`
280+
MixHash hexutil.Bytes `json:"mixHash"`
283281
} `json:"ethereum"`
284282
} `json:"seal"`
285283

@@ -426,10 +424,8 @@ func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []strin
426424
// Disable this one
427425
spec.Params.EIP98Transition = math.MaxInt64
428426

429-
spec.Genesis.Seal.Ethereum.Nonce = (hexutil.Bytes)(make([]byte, 8))
430-
binary.LittleEndian.PutUint64(spec.Genesis.Seal.Ethereum.Nonce[:], genesis.Nonce)
431-
432-
spec.Genesis.Seal.Ethereum.MixHash = (hexutil.Bytes)(genesis.Mixhash[:])
427+
spec.Genesis.Seal.Ethereum.Nonce = types.EncodeNonce(genesis.Nonce)
428+
spec.Genesis.Seal.Ethereum.MixHash = (genesis.Mixhash[:])
433429
spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty)
434430
spec.Genesis.Author = genesis.Coinbase
435431
spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp)
@@ -597,7 +593,7 @@ func (spec *parityChainSpec) setIstanbul(num *big.Int) {
597593
// pyEthereumGenesisSpec represents the genesis specification format used by the
598594
// Python Ethereum implementation.
599595
type pyEthereumGenesisSpec struct {
600-
Nonce hexutil.Bytes `json:"nonce"`
596+
Nonce types.BlockNonce `json:"nonce"`
601597
Timestamp hexutil.Uint64 `json:"timestamp"`
602598
ExtraData hexutil.Bytes `json:"extraData"`
603599
GasLimit hexutil.Uint64 `json:"gasLimit"`
@@ -616,6 +612,7 @@ func newPyEthereumGenesisSpec(network string, genesis *core.Genesis) (*pyEthereu
616612
return nil, errors.New("unsupported consensus engine")
617613
}
618614
spec := &pyEthereumGenesisSpec{
615+
Nonce: types.EncodeNonce(genesis.Nonce),
619616
Timestamp: (hexutil.Uint64)(genesis.Timestamp),
620617
ExtraData: genesis.ExtraData,
621618
GasLimit: (hexutil.Uint64)(genesis.GasLimit),
@@ -625,8 +622,5 @@ func newPyEthereumGenesisSpec(network string, genesis *core.Genesis) (*pyEthereu
625622
Alloc: genesis.Alloc,
626623
ParentHash: genesis.ParentHash,
627624
}
628-
spec.Nonce = (hexutil.Bytes)(make([]byte, 8))
629-
binary.LittleEndian.PutUint64(spec.Nonce[:], genesis.Nonce)
630-
631625
return spec, nil
632626
}

0 commit comments

Comments
 (0)