forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
operation_tx.go
64 lines (53 loc) · 1.52 KB
/
operation_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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/snow"
"github.com/MetalBlockchain/metalgo/utils/set"
"github.com/MetalBlockchain/metalgo/vms/components/avax"
"github.com/MetalBlockchain/metalgo/vms/secp256k1fx"
)
var (
_ UnsignedTx = (*OperationTx)(nil)
_ secp256k1fx.UnsignedTx = (*OperationTx)(nil)
)
// OperationTx is a transaction with no credentials.
type OperationTx struct {
BaseTx `serialize:"true"`
Ops []*Operation `serialize:"true" json:"operations"`
}
func (t *OperationTx) InitCtx(ctx *snow.Context) {
for _, op := range t.Ops {
op.Op.InitCtx(ctx)
}
t.BaseTx.InitCtx(ctx)
}
// Operations track which ops this transaction is performing. The returned array
// should not be modified.
func (t *OperationTx) Operations() []*Operation {
return t.Ops
}
func (t *OperationTx) InputUTXOs() []*avax.UTXOID {
utxos := t.BaseTx.InputUTXOs()
for _, op := range t.Ops {
utxos = append(utxos, op.UTXOIDs...)
}
return utxos
}
func (t *OperationTx) InputIDs() set.Set[ids.ID] {
inputs := t.BaseTx.InputIDs()
for _, op := range t.Ops {
for _, utxo := range op.UTXOIDs {
inputs.Add(utxo.InputID())
}
}
return inputs
}
// NumCredentials returns the number of expected credentials
func (t *OperationTx) NumCredentials() int {
return t.BaseTx.NumCredentials() + len(t.Ops)
}
func (t *OperationTx) Visit(v Visitor) error {
return v.OperationTx(t)
}