github.com/MetalBlockchain/metalgo@v1.11.9/vms/example/xsvm/block/block.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package block 5 6 import ( 7 "time" 8 9 "github.com/MetalBlockchain/metalgo/ids" 10 "github.com/MetalBlockchain/metalgo/utils/hashing" 11 "github.com/MetalBlockchain/metalgo/vms/example/xsvm/tx" 12 ) 13 14 // Stateless blocks are blocks as they are marshalled/unmarshalled and sent over 15 // the p2p network. The stateful blocks which can be executed are built from 16 // Stateless blocks. 17 type Stateless struct { 18 ParentID ids.ID `serialize:"true" json:"parentID"` 19 Timestamp int64 `serialize:"true" json:"timestamp"` 20 Height uint64 `serialize:"true" json:"height"` 21 Txs []*tx.Tx `serialize:"true" json:"txs"` 22 } 23 24 func (b *Stateless) Time() time.Time { 25 return time.Unix(b.Timestamp, 0) 26 } 27 28 func (b *Stateless) ID() (ids.ID, error) { 29 bytes, err := Codec.Marshal(CodecVersion, b) 30 return hashing.ComputeHash256Array(bytes), err 31 } 32 33 func Parse(bytes []byte) (*Stateless, error) { 34 blk := &Stateless{} 35 _, err := Codec.Unmarshal(bytes, blk) 36 return blk, err 37 }