github.com/core-coin/go-core/v2@v2.1.9/tests/gen_btheader.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package tests 4 5 import ( 6 "encoding/json" 7 "math/big" 8 9 "github.com/core-coin/go-core/v2/common" 10 "github.com/core-coin/go-core/v2/common/hexutil" 11 "github.com/core-coin/go-core/v2/common/math" 12 "github.com/core-coin/go-core/v2/core/types" 13 ) 14 15 var _ = (*btHeaderMarshaling)(nil) 16 17 // MarshalJSON marshals as JSON. 18 func (b btHeader) MarshalJSON() ([]byte, error) { 19 type btHeader struct { 20 Bloom types.Bloom 21 Coinbase common.Address 22 Nonce types.BlockNonce 23 Number *math.HexOrDecimal256 24 Hash common.Hash 25 ParentHash common.Hash 26 ReceiptTrie common.Hash 27 StateRoot common.Hash 28 TransactionsTrie common.Hash 29 UncleHash common.Hash 30 ExtraData hexutil.Bytes 31 Difficulty *math.HexOrDecimal256 32 EnergyLimit math.HexOrDecimal64 33 EnergyUsed math.HexOrDecimal64 34 Timestamp math.HexOrDecimal64 35 } 36 var enc btHeader 37 enc.Bloom = b.Bloom 38 enc.Coinbase = b.Coinbase 39 enc.Nonce = b.Nonce 40 enc.Number = (*math.HexOrDecimal256)(b.Number) 41 enc.Hash = b.Hash 42 enc.ParentHash = b.ParentHash 43 enc.ReceiptTrie = b.ReceiptTrie 44 enc.StateRoot = b.StateRoot 45 enc.TransactionsTrie = b.TransactionsTrie 46 enc.UncleHash = b.UncleHash 47 enc.ExtraData = b.ExtraData 48 enc.Difficulty = (*math.HexOrDecimal256)(b.Difficulty) 49 enc.EnergyLimit = math.HexOrDecimal64(b.EnergyLimit) 50 enc.EnergyUsed = math.HexOrDecimal64(b.EnergyUsed) 51 enc.Timestamp = math.HexOrDecimal64(b.Timestamp) 52 return json.Marshal(&enc) 53 } 54 55 // UnmarshalJSON unmarshals from JSON. 56 func (b *btHeader) UnmarshalJSON(input []byte) error { 57 type btHeader struct { 58 Bloom *types.Bloom 59 Coinbase *common.Address 60 Nonce *types.BlockNonce 61 Number *math.HexOrDecimal256 62 Hash *common.Hash 63 ParentHash *common.Hash 64 ReceiptTrie *common.Hash 65 StateRoot *common.Hash 66 TransactionsTrie *common.Hash 67 UncleHash *common.Hash 68 ExtraData *hexutil.Bytes 69 Difficulty *math.HexOrDecimal256 70 EnergyLimit *math.HexOrDecimal64 71 EnergyUsed *math.HexOrDecimal64 72 Timestamp *math.HexOrDecimal64 73 } 74 var dec btHeader 75 if err := json.Unmarshal(input, &dec); err != nil { 76 return err 77 } 78 if dec.Bloom != nil { 79 b.Bloom = *dec.Bloom 80 } 81 if dec.Coinbase != nil { 82 b.Coinbase = *dec.Coinbase 83 } 84 if dec.Nonce != nil { 85 b.Nonce = *dec.Nonce 86 } 87 if dec.Number != nil { 88 b.Number = (*big.Int)(dec.Number) 89 } 90 if dec.Hash != nil { 91 b.Hash = *dec.Hash 92 } 93 if dec.ParentHash != nil { 94 b.ParentHash = *dec.ParentHash 95 } 96 if dec.ReceiptTrie != nil { 97 b.ReceiptTrie = *dec.ReceiptTrie 98 } 99 if dec.StateRoot != nil { 100 b.StateRoot = *dec.StateRoot 101 } 102 if dec.TransactionsTrie != nil { 103 b.TransactionsTrie = *dec.TransactionsTrie 104 } 105 if dec.UncleHash != nil { 106 b.UncleHash = *dec.UncleHash 107 } 108 if dec.ExtraData != nil { 109 b.ExtraData = *dec.ExtraData 110 } 111 if dec.Difficulty != nil { 112 b.Difficulty = (*big.Int)(dec.Difficulty) 113 } 114 if dec.EnergyLimit != nil { 115 b.EnergyLimit = uint64(*dec.EnergyLimit) 116 } 117 if dec.EnergyUsed != nil { 118 b.EnergyUsed = uint64(*dec.EnergyUsed) 119 } 120 if dec.Timestamp != nil { 121 b.Timestamp = uint64(*dec.Timestamp) 122 } 123 return nil 124 }