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