github.com/MetalBlockchain/metalgo@v1.11.9/vms/avm/txs/operation_tx.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package txs
     5  
     6  import (
     7  	"github.com/MetalBlockchain/metalgo/ids"
     8  	"github.com/MetalBlockchain/metalgo/snow"
     9  	"github.com/MetalBlockchain/metalgo/utils/set"
    10  	"github.com/MetalBlockchain/metalgo/vms/components/avax"
    11  	"github.com/MetalBlockchain/metalgo/vms/secp256k1fx"
    12  )
    13  
    14  var (
    15  	_ UnsignedTx             = (*OperationTx)(nil)
    16  	_ secp256k1fx.UnsignedTx = (*OperationTx)(nil)
    17  )
    18  
    19  // OperationTx is a transaction with no credentials.
    20  type OperationTx struct {
    21  	BaseTx `serialize:"true"`
    22  
    23  	Ops []*Operation `serialize:"true" json:"operations"`
    24  }
    25  
    26  func (t *OperationTx) InitCtx(ctx *snow.Context) {
    27  	for _, op := range t.Ops {
    28  		op.Op.InitCtx(ctx)
    29  	}
    30  	t.BaseTx.InitCtx(ctx)
    31  }
    32  
    33  // Operations track which ops this transaction is performing. The returned array
    34  // should not be modified.
    35  func (t *OperationTx) Operations() []*Operation {
    36  	return t.Ops
    37  }
    38  
    39  func (t *OperationTx) InputUTXOs() []*avax.UTXOID {
    40  	utxos := t.BaseTx.InputUTXOs()
    41  	for _, op := range t.Ops {
    42  		utxos = append(utxos, op.UTXOIDs...)
    43  	}
    44  	return utxos
    45  }
    46  
    47  func (t *OperationTx) InputIDs() set.Set[ids.ID] {
    48  	inputs := t.BaseTx.InputIDs()
    49  	for _, op := range t.Ops {
    50  		for _, utxo := range op.UTXOIDs {
    51  			inputs.Add(utxo.InputID())
    52  		}
    53  	}
    54  	return inputs
    55  }
    56  
    57  // NumCredentials returns the number of expected credentials
    58  func (t *OperationTx) NumCredentials() int {
    59  	return t.BaseTx.NumCredentials() + len(t.Ops)
    60  }
    61  
    62  func (t *OperationTx) Visit(v Visitor) error {
    63  	return v.OperationTx(t)
    64  }