github.com/ebakus/go-ebakus@v1.0.5-0.20200520105415-dbccef9ec421/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/ebakus/go-ebakus/common" 10 "github.com/ebakus/go-ebakus/common/hexutil" 11 "github.com/ebakus/go-ebakus/common/math" 12 "github.com/ebakus/go-ebakus/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 Number *math.HexOrDecimal256 23 Hash common.Hash 24 ParentHash common.Hash 25 ReceiptTrie common.Hash 26 StateRoot common.Hash 27 TransactionsTrie common.Hash 28 UncleHash common.Hash 29 ExtraData hexutil.Bytes 30 Difficulty *math.HexOrDecimal256 31 GasLimit math.HexOrDecimal64 32 GasUsed math.HexOrDecimal64 33 Timestamp math.HexOrDecimal64 34 } 35 var enc btHeader 36 enc.Bloom = b.Bloom 37 enc.Coinbase = b.Coinbase 38 enc.Number = (*math.HexOrDecimal256)(b.Number) 39 enc.Hash = b.Hash 40 enc.ParentHash = b.ParentHash 41 enc.ReceiptTrie = b.ReceiptTrie 42 enc.StateRoot = b.StateRoot 43 enc.TransactionsTrie = b.TransactionsTrie 44 enc.UncleHash = b.UncleHash 45 enc.ExtraData = b.ExtraData 46 enc.Difficulty = (*math.HexOrDecimal256)(b.Difficulty) 47 enc.GasLimit = math.HexOrDecimal64(b.GasLimit) 48 enc.GasUsed = math.HexOrDecimal64(b.GasUsed) 49 enc.Timestamp = math.HexOrDecimal64(b.Timestamp) 50 return json.Marshal(&enc) 51 } 52 53 // UnmarshalJSON unmarshals from JSON. 54 func (b *btHeader) UnmarshalJSON(input []byte) error { 55 type btHeader struct { 56 Bloom *types.Bloom 57 Coinbase *common.Address 58 Number *math.HexOrDecimal256 59 Hash *common.Hash 60 ParentHash *common.Hash 61 ReceiptTrie *common.Hash 62 StateRoot *common.Hash 63 TransactionsTrie *common.Hash 64 UncleHash *common.Hash 65 ExtraData hexutil.Bytes 66 Difficulty *math.HexOrDecimal256 67 GasLimit *math.HexOrDecimal64 68 GasUsed *math.HexOrDecimal64 69 Timestamp *math.HexOrDecimal64 70 } 71 var dec btHeader 72 if err := json.Unmarshal(input, &dec); err != nil { 73 return err 74 } 75 if dec.Bloom != nil { 76 b.Bloom = *dec.Bloom 77 } 78 if dec.Coinbase != nil { 79 b.Coinbase = *dec.Coinbase 80 } 81 if dec.Number != nil { 82 b.Number = (*big.Int)(dec.Number) 83 } 84 if dec.Hash != nil { 85 b.Hash = *dec.Hash 86 } 87 if dec.ParentHash != nil { 88 b.ParentHash = *dec.ParentHash 89 } 90 if dec.ReceiptTrie != nil { 91 b.ReceiptTrie = *dec.ReceiptTrie 92 } 93 if dec.StateRoot != nil { 94 b.StateRoot = *dec.StateRoot 95 } 96 if dec.TransactionsTrie != nil { 97 b.TransactionsTrie = *dec.TransactionsTrie 98 } 99 if dec.UncleHash != nil { 100 b.UncleHash = *dec.UncleHash 101 } 102 if dec.ExtraData != nil { 103 b.ExtraData = dec.ExtraData 104 } 105 if dec.Difficulty != nil { 106 b.Difficulty = (*big.Int)(dec.Difficulty) 107 } 108 if dec.GasLimit != nil { 109 b.GasLimit = uint64(*dec.GasLimit) 110 } 111 if dec.GasUsed != nil { 112 b.GasUsed = uint64(*dec.GasUsed) 113 } 114 if dec.Timestamp != nil { 115 b.Timestamp = uint64(*dec.Timestamp) 116 } 117 return nil 118 }