github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/cmd/puppeth/genesis.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:32</date> 10 //</624450069038370816> 11 12 13 package main 14 15 import ( 16 "encoding/binary" 17 "errors" 18 "math" 19 "math/big" 20 "strings" 21 22 "github.com/ethereum/go-ethereum/common" 23 "github.com/ethereum/go-ethereum/common/hexutil" 24 math2 "github.com/ethereum/go-ethereum/common/math" 25 "github.com/ethereum/go-ethereum/consensus/ethash" 26 "github.com/ethereum/go-ethereum/core" 27 "github.com/ethereum/go-ethereum/params" 28 ) 29 30 //alethgenesspec表示 31 //C++ EthUUM实现。 32 type alethGenesisSpec struct { 33 SealEngine string `json:"sealEngine"` 34 Params struct { 35 AccountStartNonce math2.HexOrDecimal64 `json:"accountStartNonce"` 36 MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"` 37 HomesteadForkBlock hexutil.Uint64 `json:"homesteadForkBlock"` 38 DaoHardforkBlock math2.HexOrDecimal64 `json:"daoHardforkBlock"` 39 EIP150ForkBlock hexutil.Uint64 `json:"EIP150ForkBlock"` 40 EIP158ForkBlock hexutil.Uint64 `json:"EIP158ForkBlock"` 41 ByzantiumForkBlock hexutil.Uint64 `json:"byzantiumForkBlock"` 42 ConstantinopleForkBlock hexutil.Uint64 `json:"constantinopleForkBlock"` 43 MinGasLimit hexutil.Uint64 `json:"minGasLimit"` 44 MaxGasLimit hexutil.Uint64 `json:"maxGasLimit"` 45 TieBreakingGas bool `json:"tieBreakingGas"` 46 GasLimitBoundDivisor math2.HexOrDecimal64 `json:"gasLimitBoundDivisor"` 47 MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` 48 DifficultyBoundDivisor *math2.HexOrDecimal256 `json:"difficultyBoundDivisor"` 49 DurationLimit *math2.HexOrDecimal256 `json:"durationLimit"` 50 BlockReward *hexutil.Big `json:"blockReward"` 51 NetworkID hexutil.Uint64 `json:"networkID"` 52 ChainID hexutil.Uint64 `json:"chainID"` 53 AllowFutureBlocks bool `json:"allowFutureBlocks"` 54 } `json:"params"` 55 56 Genesis struct { 57 Nonce hexutil.Bytes `json:"nonce"` 58 Difficulty *hexutil.Big `json:"difficulty"` 59 MixHash common.Hash `json:"mixHash"` 60 Author common.Address `json:"author"` 61 Timestamp hexutil.Uint64 `json:"timestamp"` 62 ParentHash common.Hash `json:"parentHash"` 63 ExtraData hexutil.Bytes `json:"extraData"` 64 GasLimit hexutil.Uint64 `json:"gasLimit"` 65 } `json:"genesis"` 66 67 Accounts map[common.UnprefixedAddress]*alethGenesisSpecAccount `json:"accounts"` 68 } 69 70 //alethgenesspeccount是预先准备好的genesis帐户和/或预编译的 71 //合同定义。 72 type alethGenesisSpecAccount struct { 73 Balance *math2.HexOrDecimal256 `json:"balance"` 74 Nonce uint64 `json:"nonce,omitempty"` 75 Precompiled *alethGenesisSpecBuiltin `json:"precompiled,omitempty"` 76 } 77 78 //alethgenesspecbuiltin是预编译的合同定义。 79 type alethGenesisSpecBuiltin struct { 80 Name string `json:"name,omitempty"` 81 StartingBlock hexutil.Uint64 `json:"startingBlock,omitempty"` 82 Linear *alethGenesisSpecLinearPricing `json:"linear,omitempty"` 83 } 84 85 type alethGenesisSpecLinearPricing struct { 86 Base uint64 `json:"base"` 87 Word uint64 `json:"word"` 88 } 89 90 //newalethgenesspec将go-ethereum genesis块转换为aleth特定的块。 91 //链规范格式。 92 func newAlethGenesisSpec(network string, genesis *core.Genesis) (*alethGenesisSpec, error) { 93 //Go Ethereum和Aleth之间目前仅支持ethash 94 if genesis.Config.Ethash == nil { 95 return nil, errors.New("unsupported consensus engine") 96 } 97 //以aleth格式重新构造链规范 98 spec := &alethGenesisSpec{ 99 SealEngine: "Ethash", 100 } 101 //一些默认值 102 spec.Params.AccountStartNonce = 0 103 spec.Params.TieBreakingGas = false 104 spec.Params.AllowFutureBlocks = false 105 spec.Params.DaoHardforkBlock = 0 106 107 spec.Params.HomesteadForkBlock = (hexutil.Uint64)(genesis.Config.HomesteadBlock.Uint64()) 108 spec.Params.EIP150ForkBlock = (hexutil.Uint64)(genesis.Config.EIP150Block.Uint64()) 109 spec.Params.EIP158ForkBlock = (hexutil.Uint64)(genesis.Config.EIP158Block.Uint64()) 110 111 // 112 if num := genesis.Config.ByzantiumBlock; num != nil { 113 spec.setByzantium(num) 114 } 115 //君士坦丁堡 116 if num := genesis.Config.ConstantinopleBlock; num != nil { 117 spec.setConstantinople(num) 118 } 119 120 spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) 121 spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) 122 spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) 123 spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit) 124 spec.Params.MaxGasLimit = (hexutil.Uint64)(math.MaxInt64) 125 spec.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) 126 spec.Params.DifficultyBoundDivisor = (*math2.HexOrDecimal256)(params.DifficultyBoundDivisor) 127 spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor) 128 spec.Params.DurationLimit = (*math2.HexOrDecimal256)(params.DurationLimit) 129 spec.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward) 130 131 spec.Genesis.Nonce = (hexutil.Bytes)(make([]byte, 8)) 132 binary.LittleEndian.PutUint64(spec.Genesis.Nonce[:], genesis.Nonce) 133 134 spec.Genesis.MixHash = genesis.Mixhash 135 spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty) 136 spec.Genesis.Author = genesis.Coinbase 137 spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp) 138 spec.Genesis.ParentHash = genesis.ParentHash 139 spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData) 140 spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit) 141 142 for address, account := range genesis.Alloc { 143 spec.setAccount(address, account) 144 } 145 146 spec.setPrecompile(1, &alethGenesisSpecBuiltin{Name: "ecrecover", 147 Linear: &alethGenesisSpecLinearPricing{Base: 3000}}) 148 spec.setPrecompile(2, &alethGenesisSpecBuiltin{Name: "sha256", 149 Linear: &alethGenesisSpecLinearPricing{Base: 60, Word: 12}}) 150 spec.setPrecompile(3, &alethGenesisSpecBuiltin{Name: "ripemd160", 151 Linear: &alethGenesisSpecLinearPricing{Base: 600, Word: 120}}) 152 spec.setPrecompile(4, &alethGenesisSpecBuiltin{Name: "identity", 153 Linear: &alethGenesisSpecLinearPricing{Base: 15, Word: 3}}) 154 if genesis.Config.ByzantiumBlock != nil { 155 spec.setPrecompile(5, &alethGenesisSpecBuiltin{Name: "modexp", 156 StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64())}) 157 spec.setPrecompile(6, &alethGenesisSpecBuiltin{Name: "alt_bn128_G1_add", 158 StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()), 159 Linear: &alethGenesisSpecLinearPricing{Base: 500}}) 160 spec.setPrecompile(7, &alethGenesisSpecBuiltin{Name: "alt_bn128_G1_mul", 161 StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()), 162 Linear: &alethGenesisSpecLinearPricing{Base: 40000}}) 163 spec.setPrecompile(8, &alethGenesisSpecBuiltin{Name: "alt_bn128_pairing_product", 164 StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64())}) 165 } 166 return spec, nil 167 } 168 169 func (spec *alethGenesisSpec) setPrecompile(address byte, data *alethGenesisSpecBuiltin) { 170 if spec.Accounts == nil { 171 spec.Accounts = make(map[common.UnprefixedAddress]*alethGenesisSpecAccount) 172 } 173 addr := common.UnprefixedAddress(common.BytesToAddress([]byte{address})) 174 if _, exist := spec.Accounts[addr]; !exist { 175 spec.Accounts[addr] = &alethGenesisSpecAccount{} 176 } 177 spec.Accounts[addr].Precompiled = data 178 } 179 180 func (spec *alethGenesisSpec) setAccount(address common.Address, account core.GenesisAccount) { 181 if spec.Accounts == nil { 182 spec.Accounts = make(map[common.UnprefixedAddress]*alethGenesisSpecAccount) 183 } 184 185 a, exist := spec.Accounts[common.UnprefixedAddress(address)] 186 if !exist { 187 a = &alethGenesisSpecAccount{} 188 spec.Accounts[common.UnprefixedAddress(address)] = a 189 } 190 a.Balance = (*math2.HexOrDecimal256)(account.Balance) 191 a.Nonce = account.Nonce 192 193 } 194 195 func (spec *alethGenesisSpec) setByzantium(num *big.Int) { 196 spec.Params.ByzantiumForkBlock = hexutil.Uint64(num.Uint64()) 197 } 198 199 func (spec *alethGenesisSpec) setConstantinople(num *big.Int) { 200 spec.Params.ConstantinopleForkBlock = hexutil.Uint64(num.Uint64()) 201 } 202 203 //paritychainspec是奇偶校验使用的链规范格式。 204 type parityChainSpec struct { 205 Name string `json:"name"` 206 Datadir string `json:"dataDir"` 207 Engine struct { 208 Ethash struct { 209 Params struct { 210 MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` 211 DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"` 212 DurationLimit *hexutil.Big `json:"durationLimit"` 213 BlockReward map[string]string `json:"blockReward"` 214 DifficultyBombDelays map[string]string `json:"difficultyBombDelays"` 215 HomesteadTransition hexutil.Uint64 `json:"homesteadTransition"` 216 EIP100bTransition hexutil.Uint64 `json:"eip100bTransition"` 217 } `json:"params"` 218 } `json:"Ethash"` 219 } `json:"engine"` 220 221 Params struct { 222 AccountStartNonce hexutil.Uint64 `json:"accountStartNonce"` 223 MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"` 224 MinGasLimit hexutil.Uint64 `json:"minGasLimit"` 225 GasLimitBoundDivisor math2.HexOrDecimal64 `json:"gasLimitBoundDivisor"` 226 NetworkID hexutil.Uint64 `json:"networkID"` 227 ChainID hexutil.Uint64 `json:"chainID"` 228 MaxCodeSize hexutil.Uint64 `json:"maxCodeSize"` 229 MaxCodeSizeTransition hexutil.Uint64 `json:"maxCodeSizeTransition"` 230 EIP98Transition hexutil.Uint64 `json:"eip98Transition"` 231 EIP150Transition hexutil.Uint64 `json:"eip150Transition"` 232 EIP160Transition hexutil.Uint64 `json:"eip160Transition"` 233 EIP161abcTransition hexutil.Uint64 `json:"eip161abcTransition"` 234 EIP161dTransition hexutil.Uint64 `json:"eip161dTransition"` 235 EIP155Transition hexutil.Uint64 `json:"eip155Transition"` 236 EIP140Transition hexutil.Uint64 `json:"eip140Transition"` 237 EIP211Transition hexutil.Uint64 `json:"eip211Transition"` 238 EIP214Transition hexutil.Uint64 `json:"eip214Transition"` 239 EIP658Transition hexutil.Uint64 `json:"eip658Transition"` 240 EIP145Transition hexutil.Uint64 `json:"eip145Transition"` 241 EIP1014Transition hexutil.Uint64 `json:"eip1014Transition"` 242 EIP1052Transition hexutil.Uint64 `json:"eip1052Transition"` 243 EIP1283Transition hexutil.Uint64 `json:"eip1283Transition"` 244 } `json:"params"` 245 246 Genesis struct { 247 Seal struct { 248 Ethereum struct { 249 Nonce hexutil.Bytes `json:"nonce"` 250 MixHash hexutil.Bytes `json:"mixHash"` 251 } `json:"ethereum"` 252 } `json:"seal"` 253 254 Difficulty *hexutil.Big `json:"difficulty"` 255 Author common.Address `json:"author"` 256 Timestamp hexutil.Uint64 `json:"timestamp"` 257 ParentHash common.Hash `json:"parentHash"` 258 ExtraData hexutil.Bytes `json:"extraData"` 259 GasLimit hexutil.Uint64 `json:"gasLimit"` 260 } `json:"genesis"` 261 262 Nodes []string `json:"nodes"` 263 Accounts map[common.UnprefixedAddress]*parityChainSpecAccount `json:"accounts"` 264 } 265 266 //ParityChainspeccount是预先准备好的Genesis帐户和/或预编译的 267 //合同定义。 268 type parityChainSpecAccount struct { 269 Balance math2.HexOrDecimal256 `json:"balance"` 270 Nonce math2.HexOrDecimal64 `json:"nonce,omitempty"` 271 Builtin *parityChainSpecBuiltin `json:"builtin,omitempty"` 272 } 273 274 //paritychainspeccuiltin是预编译的合同定义。 275 type parityChainSpecBuiltin struct { 276 Name string `json:"name,omitempty"` 277 ActivateAt math2.HexOrDecimal64 `json:"activate_at,omitempty"` 278 Pricing *parityChainSpecPricing `json:"pricing,omitempty"` 279 } 280 281 //ParityChainSecPricing表示内置的不同定价模型 282 //合同可能会宣传使用。 283 type parityChainSpecPricing struct { 284 Linear *parityChainSpecLinearPricing `json:"linear,omitempty"` 285 ModExp *parityChainSpecModExpPricing `json:"modexp,omitempty"` 286 AltBnPairing *parityChainSpecAltBnPairingPricing `json:"alt_bn128_pairing,omitempty"` 287 } 288 289 type parityChainSpecLinearPricing struct { 290 Base uint64 `json:"base"` 291 Word uint64 `json:"word"` 292 } 293 294 type parityChainSpecModExpPricing struct { 295 Divisor uint64 `json:"divisor"` 296 } 297 298 type parityChainSpecAltBnPairingPricing struct { 299 Base uint64 `json:"base"` 300 Pair uint64 `json:"pair"` 301 } 302 303 //NewParityChainspec将Go-Ethereum Genesis块转换为特定于奇偶校验的块。 304 //链规范格式。 305 func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []string) (*parityChainSpec, error) { 306 //在go-ethereum和parity之间,目前只支持ethash。 307 if genesis.Config.Ethash == nil { 308 return nil, errors.New("unsupported consensus engine") 309 } 310 //以奇偶校验格式重新构造链规范 311 spec := &parityChainSpec{ 312 Name: network, 313 Nodes: bootnodes, 314 Datadir: strings.ToLower(network), 315 } 316 spec.Engine.Ethash.Params.BlockReward = make(map[string]string) 317 spec.Engine.Ethash.Params.DifficultyBombDelays = make(map[string]string) 318 //边疆 319 spec.Engine.Ethash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) 320 spec.Engine.Ethash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor) 321 spec.Engine.Ethash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit) 322 spec.Engine.Ethash.Params.BlockReward["0x0"] = hexutil.EncodeBig(ethash.FrontierBlockReward) 323 324 //家宅 325 spec.Engine.Ethash.Params.HomesteadTransition = hexutil.Uint64(genesis.Config.HomesteadBlock.Uint64()) 326 327 //橘子哨子:150 328 //https://github.com/ethereum/eips/blob/master/eips/eip-608.md网站 329 spec.Params.EIP150Transition = hexutil.Uint64(genesis.Config.EIP150Block.Uint64()) 330 331 //假龙:155、160、161、170 332 //https://github.com/ethereum/eips/blob/master/eips/eip-607.md网站 333 spec.Params.EIP155Transition = hexutil.Uint64(genesis.Config.EIP155Block.Uint64()) 334 spec.Params.EIP160Transition = hexutil.Uint64(genesis.Config.EIP155Block.Uint64()) 335 spec.Params.EIP161abcTransition = hexutil.Uint64(genesis.Config.EIP158Block.Uint64()) 336 spec.Params.EIP161dTransition = hexutil.Uint64(genesis.Config.EIP158Block.Uint64()) 337 338 //拜占庭 339 if num := genesis.Config.ByzantiumBlock; num != nil { 340 spec.setByzantium(num) 341 } 342 //君士坦丁堡 343 if num := genesis.Config.ConstantinopleBlock; num != nil { 344 spec.setConstantinople(num) 345 } 346 spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) 347 spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit) 348 spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor) 349 spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) 350 spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) 351 spec.Params.MaxCodeSize = params.MaxCodeSize 352 //Geth已将其设置为零 353 spec.Params.MaxCodeSizeTransition = 0 354 355 //禁用这个 356 spec.Params.EIP98Transition = math.MaxInt64 357 358 spec.Genesis.Seal.Ethereum.Nonce = (hexutil.Bytes)(make([]byte, 8)) 359 binary.LittleEndian.PutUint64(spec.Genesis.Seal.Ethereum.Nonce[:], genesis.Nonce) 360 361 spec.Genesis.Seal.Ethereum.MixHash = (hexutil.Bytes)(genesis.Mixhash[:]) 362 spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty) 363 spec.Genesis.Author = genesis.Coinbase 364 spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp) 365 spec.Genesis.ParentHash = genesis.ParentHash 366 spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData) 367 spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit) 368 369 spec.Accounts = make(map[common.UnprefixedAddress]*parityChainSpecAccount) 370 for address, account := range genesis.Alloc { 371 bal := math2.HexOrDecimal256(*account.Balance) 372 373 spec.Accounts[common.UnprefixedAddress(address)] = &parityChainSpecAccount{ 374 Balance: bal, 375 Nonce: math2.HexOrDecimal64(account.Nonce), 376 } 377 } 378 spec.setPrecompile(1, &parityChainSpecBuiltin{Name: "ecrecover", 379 Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 3000}}}) 380 381 spec.setPrecompile(2, &parityChainSpecBuiltin{ 382 Name: "sha256", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 60, Word: 12}}, 383 }) 384 spec.setPrecompile(3, &parityChainSpecBuiltin{ 385 Name: "ripemd160", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 600, Word: 120}}, 386 }) 387 spec.setPrecompile(4, &parityChainSpecBuiltin{ 388 Name: "identity", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 15, Word: 3}}, 389 }) 390 if genesis.Config.ByzantiumBlock != nil { 391 blnum := math2.HexOrDecimal64(genesis.Config.ByzantiumBlock.Uint64()) 392 spec.setPrecompile(5, &parityChainSpecBuiltin{ 393 Name: "modexp", ActivateAt: blnum, Pricing: &parityChainSpecPricing{ModExp: &parityChainSpecModExpPricing{Divisor: 20}}, 394 }) 395 spec.setPrecompile(6, &parityChainSpecBuiltin{ 396 Name: "alt_bn128_add", ActivateAt: blnum, Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 500}}, 397 }) 398 spec.setPrecompile(7, &parityChainSpecBuiltin{ 399 Name: "alt_bn128_mul", ActivateAt: blnum, Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 40000}}, 400 }) 401 spec.setPrecompile(8, &parityChainSpecBuiltin{ 402 Name: "alt_bn128_pairing", ActivateAt: blnum, Pricing: &parityChainSpecPricing{AltBnPairing: &parityChainSpecAltBnPairingPricing{Base: 100000, Pair: 80000}}, 403 }) 404 } 405 return spec, nil 406 } 407 408 func (spec *parityChainSpec) setPrecompile(address byte, data *parityChainSpecBuiltin) { 409 if spec.Accounts == nil { 410 spec.Accounts = make(map[common.UnprefixedAddress]*parityChainSpecAccount) 411 } 412 a := common.UnprefixedAddress(common.BytesToAddress([]byte{address})) 413 if _, exist := spec.Accounts[a]; !exist { 414 spec.Accounts[a] = &parityChainSpecAccount{} 415 } 416 spec.Accounts[a].Builtin = data 417 } 418 419 func (spec *parityChainSpec) setByzantium(num *big.Int) { 420 spec.Engine.Ethash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(ethash.ByzantiumBlockReward) 421 spec.Engine.Ethash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(3000000) 422 n := hexutil.Uint64(num.Uint64()) 423 spec.Engine.Ethash.Params.EIP100bTransition = n 424 spec.Params.EIP140Transition = n 425 spec.Params.EIP211Transition = n 426 spec.Params.EIP214Transition = n 427 spec.Params.EIP658Transition = n 428 } 429 430 func (spec *parityChainSpec) setConstantinople(num *big.Int) { 431 spec.Engine.Ethash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(ethash.ConstantinopleBlockReward) 432 spec.Engine.Ethash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(2000000) 433 n := hexutil.Uint64(num.Uint64()) 434 spec.Params.EIP145Transition = n 435 spec.Params.EIP1014Transition = n 436 spec.Params.EIP1052Transition = n 437 spec.Params.EIP1283Transition = n 438 } 439 440 //pyethereumgeneisspec表示 441 //python-ethereum实现。 442 type pyEthereumGenesisSpec struct { 443 Nonce hexutil.Bytes `json:"nonce"` 444 Timestamp hexutil.Uint64 `json:"timestamp"` 445 ExtraData hexutil.Bytes `json:"extraData"` 446 GasLimit hexutil.Uint64 `json:"gasLimit"` 447 Difficulty *hexutil.Big `json:"difficulty"` 448 Mixhash common.Hash `json:"mixhash"` 449 Coinbase common.Address `json:"coinbase"` 450 Alloc core.GenesisAlloc `json:"alloc"` 451 ParentHash common.Hash `json:"parentHash"` 452 } 453 454 //Newpyethereumgeneisspec将Go-Ethereum Genesis块转换为特定于奇偶校验的块。 455 //链规范格式。 456 func newPyEthereumGenesisSpec(network string, genesis *core.Genesis) (*pyEthereumGenesisSpec, error) { 457 //Go以太坊和Pyetereum目前仅支持ethash 458 if genesis.Config.Ethash == nil { 459 return nil, errors.New("unsupported consensus engine") 460 } 461 spec := &pyEthereumGenesisSpec{ 462 Timestamp: (hexutil.Uint64)(genesis.Timestamp), 463 ExtraData: genesis.ExtraData, 464 GasLimit: (hexutil.Uint64)(genesis.GasLimit), 465 Difficulty: (*hexutil.Big)(genesis.Difficulty), 466 Mixhash: genesis.Mixhash, 467 Coinbase: genesis.Coinbase, 468 Alloc: genesis.Alloc, 469 ParentHash: genesis.ParentHash, 470 } 471 spec.Nonce = (hexutil.Bytes)(make([]byte, 8)) 472 binary.LittleEndian.PutUint64(spec.Nonce[:], genesis.Nonce) 473 474 return spec, nil 475 } 476