public bool TryUpdate(SmartTransaction tx)
    {
        var hash = tx.GetHash();

        lock (Lock)
        {
            // Do Contains first, because it's fast.
            if (ConfirmedStore.TryUpdate(tx))
            {
                return(true);
            }
            else if (tx.Confirmed && MempoolStore.TryRemove(hash, out var originalTx))
            {
                originalTx.TryUpdate(tx);
                ConfirmedStore.TryAddOrUpdate(originalTx);
                return(true);
            }
            else if (MempoolStore.TryUpdate(tx))
            {
                return(true);
            }
        }

        return(false);
    }
 private void EnsureConsistency()
 {
     lock (Lock)
     {
         var mempoolTransactions = MempoolStore.GetTransactionHashes();
         foreach (var hash in mempoolTransactions)
         {
             // Contains is fast, so do this first.
             if (ConfirmedStore.Contains(hash) &&
                 MempoolStore.TryRemove(hash, out var uTx))
             {
                 ConfirmedStore.TryAddOrUpdate(uTx);
             }
         }
     }
 }
    private void AddOrUpdateNoLock(SmartTransaction tx)
    {
        var hash = tx.GetHash();

        if (tx.Confirmed)
        {
            if (MempoolStore.TryRemove(hash, out var found))
            {
                found.TryUpdate(tx);
                ConfirmedStore.TryAddOrUpdate(found);
            }
            else
            {
                ConfirmedStore.TryAddOrUpdate(tx);
            }
        }
        else
        {
            if (!ConfirmedStore.TryUpdate(tx))
            {
                MempoolStore.TryAddOrUpdate(tx);
            }
        }
    }