github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/network/tx_verifier.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package network
     5  
     6  import (
     7  	"sync"
     8  
     9  	"github.com/MetalBlockchain/metalgo/vms/platformvm/txs"
    10  )
    11  
    12  var _ TxVerifier = (*LockedTxVerifier)(nil)
    13  
    14  type TxVerifier interface {
    15  	// VerifyTx verifies that the transaction should be issued into the mempool.
    16  	VerifyTx(tx *txs.Tx) error
    17  }
    18  
    19  type LockedTxVerifier struct {
    20  	lock       sync.Locker
    21  	txVerifier TxVerifier
    22  }
    23  
    24  func (l *LockedTxVerifier) VerifyTx(tx *txs.Tx) error {
    25  	l.lock.Lock()
    26  	defer l.lock.Unlock()
    27  
    28  	return l.txVerifier.VerifyTx(tx)
    29  }
    30  
    31  func NewLockedTxVerifier(lock sync.Locker, txVerifier TxVerifier) *LockedTxVerifier {
    32  	return &LockedTxVerifier{
    33  		lock:       lock,
    34  		txVerifier: txVerifier,
    35  	}
    36  }