func CopyHeader(h *Header) *Header {
	cpy := *h
	if cpy.Time = new(big.Int); h.Time != nil {
		cpy.Time.Set(h.Time)
	}
	if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
		cpy.Difficulty.Set(h.Difficulty)
	}
	if cpy.Number = new(big.Int); h.Number != nil {
		cpy.Number.Set(h.Number)
	}
	if cpy.GasLimit = new(big.Int); h.GasLimit != nil {
		cpy.GasLimit.Set(h.GasLimit)
	}
	if cpy.GasUsed = new(big.Int); h.GasUsed != nil {
		cpy.GasUsed.Set(h.GasUsed)
	}
	if len(h.Extra) > 0 {
		cpy.Extra = make([]byte, len(h.Extra))
		copy(cpy.Extra, h.Extra)
	}
	return &cpy
}
CopyHeader creates a deep copy of a block header to prevent side effects from
modifying a header variable.
package types
import (
	"encoding/binary"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"math/big"
	"sort"
	"sync/atomic"
	"time"
	"github.com/Baptist-Publication/chorus-module/lib/eth/common"
	"github.com/Baptist-Publication/chorus-module/lib/eth/common/hexutil"
	"github.com/Baptist-Publication/chorus-module/lib/eth/crypto/sha3"
	"github.com/Baptist-Publication/chorus-module/lib/eth/rlp"
)
var (
	EmptyRootHash  = DeriveSha(Transactions{})
	EmptyUncleHash = CalcUncleHash(nil)
)
var (
	errMissingHeaderMixDigest = errors.New("missing mixHash in JSON block header")
	errMissingHeaderFields    = errors.New("missing required JSON block header fields")
	errBadNonceSize           = errors.New("invalid block nonce size, want 8 bytes")
)
type BlockNonce [8]byte
func EncodeNonce(i uint64) BlockNonce {
	var n BlockNonce
	binary.BigEndian.PutUint64(n[:], i)
	return n
}
func (n BlockNonce) Uint64() uint64 {
	return binary.BigEndian.Uint64(n[:])
}
func (n BlockNonce) MarshalJSON() ([]byte, error) {
	return hexutil.Bytes(n[:]).MarshalJSON()
}
func (n *BlockNonce) UnmarshalJSON(input []byte) error {
	return hexutil.UnmarshalJSON("BlockNonce", input, n[:])
}
type Header struct {
	ParentHash  common.Hash     
	UncleHash   common.Hash     
	Coinbase    common.Address  
	Root        common.Hash     
	TxHash      common.Hash     
	ReceiptHash common.Hash     
	Bloom       Bloom           
	Difficulty  *big.Int        
	Number      *big.Int        
	GasLimit    *big.Int        
	GasUsed     *big.Int        
	Time        *big.Int        
	Extra       []byte          
	MixDigest   common.Hash     
	Nonce       BlockNonce
}
type jsonHeader struct {
	ParentHash  *common.Hash    `json:"parentHash"`
	UncleHash   *common.Hash    `json:"sha3Uncles"`
	Coinbase    *common.Address `json:"miner"`
	Root        *common.Hash    `json:"stateRoot"`
	TxHash      *common.Hash    `json:"transactionsRoot"`
	ReceiptHash *common.Hash    `json:"receiptsRoot"`
	Bloom       *Bloom          `json:"logsBloom"`
	Difficulty  *hexutil.Big    `json:"difficulty"`
	Number      *hexutil.Big    `json:"number"`
	GasLimit    *hexutil.Big    `json:"gasLimit"`
	GasUsed     *hexutil.Big    `json:"gasUsed"`
	Time        *hexutil.Big    `json:"timestamp"`
	Extra       *hexutil.Bytes  `json:"extraData"`
	MixDigest   *common.Hash    `json:"mixHash"`
	Nonce       *BlockNonce     `json:"nonce"`
}
func (h *Header) Hash() common.Hash {
	return rlpHash(h)
}
func (h *Header) HashNoNonce() common.Hash {
	return rlpHash([]interface{}{
		h.ParentHash,
		h.UncleHash,
		h.Coinbase,
		h.Root,
		h.TxHash,
		h.ReceiptHash,
		h.Bloom,
		h.Difficulty,
		h.Number,
		h.GasLimit,
		h.GasUsed,
		h.Time,
		h.Extra,
	})
}
func (h *Header) MarshalJSON() ([]byte, error) {
	return json.Marshal(&jsonHeader{
		ParentHash:  &h.ParentHash,
		UncleHash:   &h.UncleHash,
		Coinbase:    &h.Coinbase,
		Root:        &h.Root,
		TxHash:      &h.TxHash,
		ReceiptHash: &h.ReceiptHash,
		Bloom:       &h.Bloom,
		Difficulty:  (*hexutil.Big)(h.Difficulty),
		Number:      (*hexutil.Big)(h.Number),
		GasLimit:    (*hexutil.Big)(h.GasLimit),
		GasUsed:     (*hexutil.Big)(h.GasUsed),
		Time:        (*hexutil.Big)(h.Time),
		Extra:       (*hexutil.Bytes)(&h.Extra),
		MixDigest:   &h.MixDigest,
		Nonce:       &h.Nonce,
	})
}
func (h *Header) UnmarshalJSON(input []byte) error {
	var dec jsonHeader
	if err := json.Unmarshal(input, &dec); err != nil {
		return err
	}
	if dec.MixDigest == nil {
		return errMissingHeaderMixDigest
	}
	if dec.ParentHash == nil || dec.UncleHash == nil || dec.Coinbase == nil ||
		dec.Root == nil || dec.TxHash == nil || dec.ReceiptHash == nil ||
		dec.Bloom == nil || dec.Difficulty == nil || dec.Number == nil ||
		dec.GasLimit == nil || dec.GasUsed == nil || dec.Time == nil ||
		dec.Extra == nil || dec.Nonce == nil {
		return errMissingHeaderFields
	}
	h.ParentHash = *dec.ParentHash
	h.UncleHash = *dec.UncleHash
	h.Coinbase = *dec.Coinbase
	h.Root = *dec.Root
	h.TxHash = *dec.TxHash
	h.ReceiptHash = *dec.ReceiptHash
	h.Bloom = *dec.Bloom
	h.Difficulty = (*big.Int)(dec.Difficulty)
	h.Number = (*big.Int)(dec.Number)
	h.GasLimit = (*big.Int)(dec.GasLimit)
	h.GasUsed = (*big.Int)(dec.GasUsed)
	h.Time = (*big.Int)(dec.Time)
	h.Extra = *dec.Extra
	h.MixDigest = *dec.MixDigest
	h.Nonce = *dec.Nonce
	return nil
}
func rlpHash(x interface{}) (h common.Hash) {
	hw := sha3.NewKeccak256()
	rlp.Encode(hw, x)
	hw.Sum(h[:0])
	return h
}
type Body struct {
	Transactions []*Transaction
	Uncles       []*Header
}
type Block struct {
	header       *Header
	uncles       []*Header
	transactions Transactions
	hash atomic.Value
	size atomic.Value
	td *big.Int
	ReceivedAt   time.Time
	ReceivedFrom interface{}
}
func (b *Block) DeprecatedTd() *big.Int {
	return b.td
}
type StorageBlock Block
type extblock struct {
	Header *Header
	Txs    []*Transaction
	Uncles []*Header
}
type storageblock struct {
	Header *Header
	Txs    []*Transaction
	Uncles []*Header
	TD     *big.Int
}
func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt) *Block {
	b := &Block{header: CopyHeader(header), td: new(big.Int)}
	if len(txs) == 0 {
		b.header.TxHash = EmptyRootHash
	} else {
		b.header.TxHash = DeriveSha(Transactions(txs))
		b.transactions = make(Transactions, len(txs))
		copy(b.transactions, txs)
	}
	if len(receipts) == 0 {
		b.header.ReceiptHash = EmptyRootHash
	} else {
		b.header.ReceiptHash = DeriveSha(Receipts(receipts))
		b.header.Bloom = CreateBloom(receipts)
	}
	if len(uncles) == 0 {
		b.header.UncleHash = EmptyUncleHash
	} else {
		b.header.UncleHash = CalcUncleHash(uncles)
		b.uncles = make([]*Header, len(uncles))
		for i := range uncles {
			b.uncles[i] = CopyHeader(uncles[i])
		}
	}
	return b
}
func NewBlockWithHeader(header *Header) *Block {
	return &Block{header: CopyHeader(header)}
}