-
Notifications
You must be signed in to change notification settings - Fork 661
/
base_tx.go
71 lines (62 loc) · 1.59 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
68
69
70
71
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package avm
import (
"errors"
"github.com/ava-labs/gecko/database"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow"
"github.com/ava-labs/gecko/utils/codec"
"github.com/ava-labs/gecko/vms/components/avax"
"github.com/ava-labs/gecko/vms/components/verify"
)
var (
errNilTx = errors.New("nil tx is not valid")
)
// BaseTx is the basis of all transactions.
type BaseTx struct {
avax.BaseTx `serialize:"true"`
}
// SyntacticVerify that this transaction is well-formed.
func (t *BaseTx) SyntacticVerify(
ctx *snow.Context,
c codec.Codec,
txFeeAssetID ids.ID,
txFee uint64,
_ int,
) error {
if t == nil {
return errNilTx
}
if err := t.MetadataVerify(ctx); err != nil {
return err
}
return avax.VerifyTx(
txFee,
txFeeAssetID,
[][]*avax.TransferableInput{t.Ins},
[][]*avax.TransferableOutput{t.Outs},
c,
)
}
// SemanticVerify that this transaction is valid to be spent.
func (t *BaseTx) SemanticVerify(vm *VM, tx UnsignedTx, creds []verify.Verifiable) error {
for i, in := range t.Ins {
cred := creds[i]
if err := vm.verifyTransfer(tx, in, cred); err != nil {
return err
}
}
for _, out := range t.Outs {
fxIndex, err := vm.getFx(out.Out)
if err != nil {
return err
}
if assetID := out.AssetID(); !vm.verifyFxUsage(fxIndex, assetID) {
return errIncompatibleFx
}
}
return nil
}
// ExecuteWithSideEffects writes the batch with any additional side effects
func (t *BaseTx) ExecuteWithSideEffects(_ *VM, batch database.Batch) error { return batch.Write() }