-
Notifications
You must be signed in to change notification settings - Fork 646
/
export_tx.go
78 lines (65 loc) · 1.79 KB
/
export_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
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"errors"
"github.com/ava-labs/avalanchego/codec"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)
var (
errNoExportOutputs = errors.New("no export outputs")
_ UnsignedTx = &ExportTx{}
_ secp256k1fx.UnsignedTx = &ExportTx{}
)
// ExportTx is a transaction that exports an asset to another blockchain.
type ExportTx struct {
BaseTx `serialize:"true"`
// Which chain to send the funds to
DestinationChain ids.ID `serialize:"true" json:"destinationChain"`
// The outputs this transaction is sending to the other chain
ExportedOuts []*avax.TransferableOutput `serialize:"true" json:"exportedOutputs"`
}
func (t *ExportTx) InitCtx(ctx *snow.Context) {
for _, out := range t.ExportedOuts {
out.InitCtx(ctx)
}
t.BaseTx.InitCtx(ctx)
}
func (t *ExportTx) SyntacticVerify(
ctx *snow.Context,
c codec.Manager,
txFeeAssetID ids.ID,
txFee uint64,
_ uint64,
_ int,
) error {
switch {
case t == nil:
return errNilTx
case len(t.ExportedOuts) == 0:
return errNoExportOutputs
}
// We don't call [t.BaseTx.SyntacticVerify] because the flow check performed
// here is more strict than the flow check performed in the [BaseTx].
// Therefore, we avoid performing a useless flow check by performing the
// other verifications here.
if err := t.BaseTx.BaseTx.Verify(ctx); err != nil {
return err
}
return avax.VerifyTx(
txFee,
txFeeAssetID,
[][]*avax.TransferableInput{t.Ins},
[][]*avax.TransferableOutput{
t.Outs,
t.ExportedOuts,
},
c,
)
}
func (t *ExportTx) Visit(v Visitor) error {
return v.ExportTx(t)
}