-
Notifications
You must be signed in to change notification settings - Fork 646
/
backend_visitor.go
116 lines (95 loc) · 2.74 KB
/
backend_visitor.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package p
import (
stdcontext "context"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
var _ txs.Visitor = (*backendVisitor)(nil)
// backendVisitor handles accepting of transactions for the backend
type backendVisitor struct {
b *backend
ctx stdcontext.Context
txID ids.ID
}
func (*backendVisitor) AdvanceTimeTx(*txs.AdvanceTimeTx) error {
return errUnsupportedTxType
}
func (*backendVisitor) RewardValidatorTx(*txs.RewardValidatorTx) error {
return errUnsupportedTxType
}
func (b *backendVisitor) AddValidatorTx(tx *txs.AddValidatorTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) AddSubnetValidatorTx(tx *txs.AddSubnetValidatorTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) AddDelegatorTx(tx *txs.AddDelegatorTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) CreateChainTx(tx *txs.CreateChainTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) CreateSubnetTx(tx *txs.CreateSubnetTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) RemoveSubnetValidatorTx(tx *txs.RemoveSubnetValidatorTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwnershipTx) error {
// TODO: Correctly track subnet owners in [getSubnetSigners]
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) BaseTx(tx *txs.BaseTx) error {
return b.baseTx(tx)
}
func (b *backendVisitor) ImportTx(tx *txs.ImportTx) error {
err := b.b.removeUTXOs(
b.ctx,
tx.SourceChain,
tx.InputUTXOs(),
)
if err != nil {
return err
}
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) ExportTx(tx *txs.ExportTx) error {
for i, out := range tx.ExportedOutputs {
err := b.b.AddUTXO(
b.ctx,
tx.DestinationChain,
&avax.UTXO{
UTXOID: avax.UTXOID{
TxID: b.txID,
OutputIndex: uint32(len(tx.Outs) + i),
},
Asset: avax.Asset{ID: out.AssetID()},
Out: out.Out,
},
)
if err != nil {
return err
}
}
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) TransformSubnetTx(tx *txs.TransformSubnetTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) AddPermissionlessValidatorTx(tx *txs.AddPermissionlessValidatorTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) AddPermissionlessDelegatorTx(tx *txs.AddPermissionlessDelegatorTx) error {
return b.baseTx(&tx.BaseTx)
}
func (b *backendVisitor) baseTx(tx *txs.BaseTx) error {
return b.b.removeUTXOs(
b.ctx,
constants.PlatformChainID,
tx.InputIDs(),
)
}