-
Notifications
You must be signed in to change notification settings - Fork 671
/
atomic_block.go
51 lines (42 loc) · 1.27 KB
/
atomic_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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package blocks
import (
"fmt"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
var _ Block = &ApricotAtomicBlock{}
// ApricotAtomicBlock being accepted results in the atomic transaction contained
// in the block to be accepted and committed to the chain.
type ApricotAtomicBlock struct {
CommonBlock `serialize:"true"`
Tx *txs.Tx `serialize:"true" json:"tx"`
}
func (b *ApricotAtomicBlock) initialize(bytes []byte) error {
b.CommonBlock.initialize(bytes)
if err := b.Tx.Sign(txs.Codec, nil); err != nil {
return fmt.Errorf("failed to initialize tx: %w", err)
}
return nil
}
func (b *ApricotAtomicBlock) InitCtx(ctx *snow.Context) {
b.Tx.Unsigned.InitCtx(ctx)
}
func (b *ApricotAtomicBlock) Txs() []*txs.Tx { return []*txs.Tx{b.Tx} }
func (b *ApricotAtomicBlock) Visit(v Visitor) error { return v.ApricotAtomicBlock(b) }
func NewApricotAtomicBlock(
parentID ids.ID,
height uint64,
tx *txs.Tx,
) (*ApricotAtomicBlock, error) {
blk := &ApricotAtomicBlock{
CommonBlock: CommonBlock{
PrntID: parentID,
Hght: height,
},
Tx: tx,
}
return blk, initialize(blk)
}