forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_tx.go
103 lines (87 loc) · 2.44 KB
/
import_tx.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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"errors"
"github.com/dim4egster/qmallgo/codec"
"github.com/dim4egster/qmallgo/ids"
"github.com/dim4egster/qmallgo/snow"
"github.com/dim4egster/qmallgo/vms/components/avax"
"github.com/dim4egster/qmallgo/vms/secp256k1fx"
)
var (
errNoImportInputs = errors.New("no import inputs")
_ UnsignedTx = &ImportTx{}
_ secp256k1fx.UnsignedTx = &ImportTx{}
)
// ImportTx is a transaction that imports an asset from another blockchain.
type ImportTx struct {
BaseTx `serialize:"true"`
// Which chain to consume the funds from
SourceChain ids.ID `serialize:"true" json:"sourceChain"`
// The inputs to this transaction
ImportedIns []*avax.TransferableInput `serialize:"true" json:"importedInputs"`
}
// InputUTXOs track which UTXOs this transaction is consuming.
func (t *ImportTx) InputUTXOs() []*avax.UTXOID {
utxos := t.BaseTx.InputUTXOs()
for _, in := range t.ImportedIns {
in.Symbol = true
utxos = append(utxos, &in.UTXOID)
}
return utxos
}
// ConsumedAssetIDs returns the IDs of the assets this transaction consumes
func (t *ImportTx) ConsumedAssetIDs() ids.Set {
assets := t.BaseTx.AssetIDs()
for _, in := range t.ImportedIns {
assets.Add(in.AssetID())
}
return assets
}
// AssetIDs returns the IDs of the assets this transaction depends on
func (t *ImportTx) AssetIDs() ids.Set {
assets := t.BaseTx.AssetIDs()
for _, in := range t.ImportedIns {
assets.Add(in.AssetID())
}
return assets
}
// NumCredentials returns the number of expected credentials
func (t *ImportTx) NumCredentials() int {
return t.BaseTx.NumCredentials() + len(t.ImportedIns)
}
// SyntacticVerify that this import transaction is well-formed.
func (t *ImportTx) SyntacticVerify(
ctx *snow.Context,
c codec.Manager,
txFeeAssetID ids.ID,
txFee uint64,
_ uint64,
numFxs int,
) error {
switch {
case t == nil:
return errNilTx
case len(t.ImportedIns) == 0:
return errNoImportInputs
}
// We don't call [t.BaseTx.SyntacticVerify] because the flow check performed
// here is less strict than the flow check performed in the [BaseTx].
if err := t.BaseTx.BaseTx.Verify(ctx); err != nil {
return err
}
return avax.VerifyTx(
txFee,
txFeeAssetID,
[][]*avax.TransferableInput{
t.Ins,
t.ImportedIns,
},
[][]*avax.TransferableOutput{t.Outs},
c,
)
}
func (t *ImportTx) Visit(v Visitor) error {
return v.ImportTx(t)
}