forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.go
67 lines (51 loc) · 1.25 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package spchainvm
import (
"errors"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow"
"github.com/ava-labs/gecko/utils/crypto"
)
var (
errInvalidNil = errors.New("nil is invalid")
)
// Block is a group of transactions
type Block struct {
id ids.ID
parentID ids.ID
txs []*Tx
bytes []byte
}
// ID of this operation
func (b *Block) ID() ids.ID { return b.id }
// ParentID of this operation
func (b *Block) ParentID() ids.ID { return b.parentID }
// Txs contained in the operation
func (b *Block) Txs() []*Tx { return b.txs }
// Bytes of this transaction
func (b *Block) Bytes() []byte { return b.bytes }
func (b *Block) startVerify(ctx *snow.Context, factory *crypto.FactorySECP256K1R) {
if b != nil {
for _, tx := range b.txs {
tx.startVerify(ctx, factory)
}
}
}
func (b *Block) verify(ctx *snow.Context, factory *crypto.FactorySECP256K1R) error {
switch {
case b == nil:
return errInvalidNil
case b.id.IsZero():
return errInvalidID
case b.parentID.IsZero():
return errInvalidID
}
b.startVerify(ctx, factory)
for _, tx := range b.txs {
if err := tx.verify(ctx, factory); err != nil {
return err
}
}
return nil
}