github.com/koko1123/flow-go-1@v0.29.6/model/flow/block.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package flow 4 5 func Genesis(chainID ChainID) *Block { 6 7 // create the raw content for the genesis block 8 payload := Payload{ 9 Guarantees: nil, 10 Seals: nil, 11 } 12 13 // create the header 14 header := Header{ 15 ChainID: chainID, 16 ParentID: ZeroID, 17 Height: 0, 18 PayloadHash: payload.Hash(), 19 Timestamp: GenesisTime, 20 View: 0, 21 } 22 23 // combine to block 24 genesis := Block{ 25 Header: &header, 26 Payload: &payload, 27 } 28 29 return &genesis 30 } 31 32 // Block (currently) includes the header, the payload hashes as well as the 33 // payload contents. 34 type Block struct { 35 Header *Header 36 Payload *Payload 37 } 38 39 // SetPayload sets the payload and updates the payload hash. 40 func (b *Block) SetPayload(payload Payload) { 41 b.Payload = &payload 42 b.Header.PayloadHash = b.Payload.Hash() 43 } 44 45 // Valid will check whether the block is valid bottom-up. 46 func (b Block) Valid() bool { 47 return b.Header.PayloadHash == b.Payload.Hash() 48 } 49 50 // ID returns the ID of the header. 51 func (b Block) ID() Identifier { 52 return b.Header.ID() 53 } 54 55 // Checksum returns the checksum of the header. 56 func (b Block) Checksum() Identifier { 57 return b.Header.Checksum() 58 } 59 60 // BlockStatus represents the status of a block. 61 type BlockStatus int 62 63 const ( 64 // BlockStatusUnknown indicates that the block status is not known. 65 BlockStatusUnknown BlockStatus = iota 66 // BlockStatusFinalized is the status of a finalized block. 67 BlockStatusFinalized 68 // BlockStatusSealed is the status of a sealed block. 69 BlockStatusSealed 70 ) 71 72 // String returns the string representation of a transaction status. 73 func (s BlockStatus) String() string { 74 return [...]string{"BLOCK_UNKNOWN", "BLOCK_FINALIZED", "BLOCK_SEALED"}[s] 75 }