-
Notifications
You must be signed in to change notification settings - Fork 665
/
base_tx.go
49 lines (44 loc) · 1.28 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
package platformvm
import (
"fmt"
"github.com/ava-labs/avalanchego/codec"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/vms/components/avax"
)
// BaseTx contains fields common to many transaction types. It should be
// embedded in transaction implementations.
type BaseTx struct {
avax.BaseTx `serialize:"true" json:"inputs"`
// true iff this transaction has already passed syntactic verification
syntacticallyVerified bool
}
// Verify returns nil iff this tx is well formed
func (tx *BaseTx) Verify(ctx *snow.Context, c codec.Manager) error {
switch {
case tx == nil:
return errNilTx
case tx.syntacticallyVerified: // already passed syntactic verification
return nil
}
if err := tx.MetadataVerify(ctx); err != nil {
return fmt.Errorf("metadata failed verification: %w", err)
}
for _, out := range tx.Outs {
if err := out.Verify(); err != nil {
return fmt.Errorf("output failed verification: %w", err)
}
}
for _, in := range tx.Ins {
if err := in.Verify(); err != nil {
return fmt.Errorf("input failed verification: %w", err)
}
}
switch {
case !avax.IsSortedTransferableOutputs(tx.Outs, c):
return errOutputsNotSorted
case !avax.IsSortedAndUniqueTransferableInputs(tx.Ins):
return errInputsNotSortedUnique
default:
return nil
}
}