forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
base_tx.go
67 lines (55 loc) · 1.21 KB
/
base_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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"github.com/MetalBlockchain/metalgo/codec"
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/snow"
"github.com/MetalBlockchain/metalgo/vms/components/avax"
"github.com/MetalBlockchain/metalgo/vms/secp256k1fx"
)
var (
_ UnsignedTx = (*BaseTx)(nil)
_ secp256k1fx.UnsignedTx = (*BaseTx)(nil)
)
// BaseTx is the basis of all transactions.
type BaseTx struct {
avax.BaseTx `serialize:"true"`
bytes []byte
}
func (t *BaseTx) InitCtx(ctx *snow.Context) {
for _, out := range t.Outs {
out.InitCtx(ctx)
}
}
func (t *BaseTx) SetBytes(bytes []byte) {
t.bytes = bytes
}
func (t *BaseTx) Bytes() []byte {
return t.bytes
}
func (t *BaseTx) SyntacticVerify(
ctx *snow.Context,
c codec.Manager,
txFeeAssetID ids.ID,
txFee uint64,
_ uint64,
_ int,
) error {
if t == nil {
return errNilTx
}
if err := t.BaseTx.Verify(ctx); err != nil {
return err
}
return avax.VerifyTx(
txFee,
txFeeAssetID,
[][]*avax.TransferableInput{t.Ins},
[][]*avax.TransferableOutput{t.Outs},
c,
)
}
func (t *BaseTx) Visit(v Visitor) error {
return v.BaseTx(t)
}