/
backend_visitor.go
64 lines (54 loc) · 1.3 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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package x
import (
"context"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/avm/txs"
"github.com/ava-labs/avalanchego/vms/components/avax"
)
var _ txs.Visitor = (*backendVisitor)(nil)
// backendVisitor handles accepting of transactions for the backend
type backendVisitor struct {
b *backend
ctx context.Context
txID ids.ID
}
func (*backendVisitor) BaseTx(*txs.BaseTx) error {
return nil
}
func (*backendVisitor) CreateAssetTx(*txs.CreateAssetTx) error {
return nil
}
func (*backendVisitor) OperationTx(*txs.OperationTx) error {
return nil
}
func (b *backendVisitor) ImportTx(tx *txs.ImportTx) error {
for _, in := range tx.ImportedIns {
utxoID := in.UTXOID.InputID()
if err := b.b.RemoveUTXO(b.ctx, tx.SourceChain, utxoID); err != nil {
return err
}
}
return nil
}
func (b *backendVisitor) ExportTx(tx *txs.ExportTx) error {
for i, out := range tx.ExportedOuts {
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 nil
}