-
Notifications
You must be signed in to change notification settings - Fork 649
/
builder.go
57 lines (51 loc) · 1.39 KB
/
builder.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vertex
import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/consensus/avalanche"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
"github.com/ava-labs/avalanchego/utils/hashing"
)
// Builder builds a vertex given a set of parentIDs and transactions.
type Builder interface {
// Build a new vertex from the contents of a vertex
BuildVtx(
epoch uint32,
parentIDs []ids.ID,
txs []snowstorm.Tx,
restrictions []ids.ID,
) (avalanche.Vertex, error)
}
// Build a new stateless vertex from the contents of a vertex
func Build(
chainID ids.ID,
height uint64,
epoch uint32,
parentIDs []ids.ID,
txs [][]byte,
restrictions []ids.ID,
) (StatelessVertex, error) {
ids.SortIDs(parentIDs)
SortHashOf(txs)
ids.SortIDs(restrictions)
innerVtx := innerStatelessVertex{
Version: noEpochTransitionsCodecVersion,
ChainID: chainID,
Height: height,
Epoch: epoch,
ParentIDs: parentIDs,
Txs: txs,
Restrictions: restrictions,
}
if err := innerVtx.Verify(); err != nil {
return nil, err
}
vtxBytes, err := c.Marshal(innerVtx.Version, innerVtx)
vtx := statelessVertex{
innerStatelessVertex: innerVtx,
id: hashing.ComputeHash256Array(vtxBytes),
bytes: vtxBytes,
}
return vtx, err
}