github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/powchain/types/eth1_types.go (about)

     1  package types
     2  
     3  import (
     4  	"errors"
     5  	"math/big"
     6  
     7  	"github.com/ethereum/go-ethereum/common"
     8  	gethTypes "github.com/ethereum/go-ethereum/core/types"
     9  	"github.com/prysmaticlabs/prysm/shared/bytesutil"
    10  )
    11  
    12  // HeaderInfo specifies the block header information in the ETH 1.0 chain.
    13  type HeaderInfo struct {
    14  	Number *big.Int
    15  	Hash   common.Hash
    16  	Time   uint64
    17  }
    18  
    19  // HeaderToHeaderInfo converts an eth1 header to a header metadata type.
    20  func HeaderToHeaderInfo(hdr *gethTypes.Header) (*HeaderInfo, error) {
    21  	if hdr.Number == nil {
    22  		// A nil number will panic when calling *big.Int.Set(...)
    23  		return nil, errors.New("cannot convert block header with nil block number")
    24  	}
    25  
    26  	return &HeaderInfo{
    27  		Hash:   hdr.Hash(),
    28  		Number: new(big.Int).Set(hdr.Number),
    29  		Time:   hdr.Time,
    30  	}, nil
    31  }
    32  
    33  // Copy sends out a copy of the current header info.
    34  func (h *HeaderInfo) Copy() *HeaderInfo {
    35  	return &HeaderInfo{
    36  		Hash:   bytesutil.ToBytes32(h.Hash[:]),
    37  		Number: new(big.Int).Set(h.Number),
    38  		Time:   h.Time,
    39  	}
    40  }