github.com/ava-labs/avalanchego@v1.11.11/vms/platformvm/txs/executor/atomic_tx_executor.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package executor
     5  
     6  import (
     7  	"github.com/ava-labs/avalanchego/chains/atomic"
     8  	"github.com/ava-labs/avalanchego/ids"
     9  	"github.com/ava-labs/avalanchego/utils/set"
    10  	"github.com/ava-labs/avalanchego/vms/platformvm/state"
    11  	"github.com/ava-labs/avalanchego/vms/platformvm/txs"
    12  	"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
    13  )
    14  
    15  var _ txs.Visitor = (*AtomicTxExecutor)(nil)
    16  
    17  // atomicTxExecutor is used to execute atomic transactions pre-AP5. After AP5
    18  // the execution was moved to be performed inside of the standardTxExecutor.
    19  type AtomicTxExecutor struct {
    20  	// inputs, to be filled before visitor methods are called
    21  	*Backend
    22  	FeeCalculator fee.Calculator
    23  	ParentID      ids.ID
    24  	StateVersions state.Versions
    25  	Tx            *txs.Tx
    26  
    27  	// outputs of visitor execution
    28  	OnAccept       state.Diff
    29  	Inputs         set.Set[ids.ID]
    30  	AtomicRequests map[ids.ID]*atomic.Requests
    31  }
    32  
    33  func (*AtomicTxExecutor) AddValidatorTx(*txs.AddValidatorTx) error {
    34  	return ErrWrongTxType
    35  }
    36  
    37  func (*AtomicTxExecutor) AddSubnetValidatorTx(*txs.AddSubnetValidatorTx) error {
    38  	return ErrWrongTxType
    39  }
    40  
    41  func (*AtomicTxExecutor) AddDelegatorTx(*txs.AddDelegatorTx) error {
    42  	return ErrWrongTxType
    43  }
    44  
    45  func (*AtomicTxExecutor) CreateChainTx(*txs.CreateChainTx) error {
    46  	return ErrWrongTxType
    47  }
    48  
    49  func (*AtomicTxExecutor) CreateSubnetTx(*txs.CreateSubnetTx) error {
    50  	return ErrWrongTxType
    51  }
    52  
    53  func (*AtomicTxExecutor) AdvanceTimeTx(*txs.AdvanceTimeTx) error {
    54  	return ErrWrongTxType
    55  }
    56  
    57  func (*AtomicTxExecutor) RewardValidatorTx(*txs.RewardValidatorTx) error {
    58  	return ErrWrongTxType
    59  }
    60  
    61  func (*AtomicTxExecutor) RemoveSubnetValidatorTx(*txs.RemoveSubnetValidatorTx) error {
    62  	return ErrWrongTxType
    63  }
    64  
    65  func (*AtomicTxExecutor) TransformSubnetTx(*txs.TransformSubnetTx) error {
    66  	return ErrWrongTxType
    67  }
    68  
    69  func (*AtomicTxExecutor) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) error {
    70  	return ErrWrongTxType
    71  }
    72  
    73  func (*AtomicTxExecutor) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error {
    74  	return ErrWrongTxType
    75  }
    76  
    77  func (*AtomicTxExecutor) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDelegatorTx) error {
    78  	return ErrWrongTxType
    79  }
    80  
    81  func (*AtomicTxExecutor) BaseTx(*txs.BaseTx) error {
    82  	return ErrWrongTxType
    83  }
    84  
    85  func (e *AtomicTxExecutor) ImportTx(tx *txs.ImportTx) error {
    86  	return e.atomicTx(tx)
    87  }
    88  
    89  func (e *AtomicTxExecutor) ExportTx(tx *txs.ExportTx) error {
    90  	return e.atomicTx(tx)
    91  }
    92  
    93  func (e *AtomicTxExecutor) atomicTx(tx txs.UnsignedTx) error {
    94  	onAccept, err := state.NewDiff(
    95  		e.ParentID,
    96  		e.StateVersions,
    97  	)
    98  	if err != nil {
    99  		return err
   100  	}
   101  	e.OnAccept = onAccept
   102  
   103  	executor := StandardTxExecutor{
   104  		Backend:       e.Backend,
   105  		State:         e.OnAccept,
   106  		FeeCalculator: e.FeeCalculator,
   107  		Tx:            e.Tx,
   108  	}
   109  	err = tx.Visit(&executor)
   110  	e.Inputs = executor.Inputs
   111  	e.AtomicRequests = executor.AtomicRequests
   112  	return err
   113  }