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