예제 #1
0
        protected override async Task AfterMatch(TrackedTransaction tx, IReadOnlyCollection <KeyPathInformation> keyInfos)
        {
            await base.AfterMatch(tx, keyInfos);

            if (tx.TrackedSource is DerivationSchemeTrackedSource ts &&
                !ts.DerivationStrategy.Unblinded() &&
                tx.Transaction is ElementsTransaction elementsTransaction &&
                tx is ElementsTrackedTransaction elementsTracked)
            {
                var keys = keyInfos
                           .Select(kv => (KeyPath: kv.KeyPath,
                                          Address: kv.Address as BitcoinBlindedAddress,
                                          BlindingKey: NBXplorerNetworkProvider.LiquidNBXplorerNetwork.GenerateBlindingKey(ts.DerivationStrategy, kv.KeyPath)))
                           .Where(o => o.Address != null)
                           .Select(o => new UnblindTransactionBlindingAddressKey()
                {
                    Address     = o.Address,
                    BlindingKey = o.BlindingKey
                }).ToList();
                if (keys.Count != 0)
                {
                    var unblinded = await _rpcClient.UnblindTransaction(keys, elementsTransaction, Network.NBitcoinNetwork);

                    elementsTracked.Unblind(unblinded, true);
                }
            }
        }
예제 #2
0
        public static NewTransactionEvent SetMatch(this NewTransactionEvent evt, TrackedTransaction match)
        {
            evt.TrackedSource = match.TrackedSource;
            var derivation = (match.TrackedSource as DerivationSchemeTrackedSource)?.DerivationStrategy;

            evt.Outputs.AddRange(match.GetReceivedOutputs(evt.TrackedSource));
            evt.DerivationStrategy = derivation;
            return(evt);
        }
예제 #3
0
        public ApplyTransactionResult Apply(TrackedTransaction trackedTransaction)
        {
            var result = ApplyTransactionResult.Passed;
            var hash   = trackedTransaction.Key.TxId;

            foreach (var coin in trackedTransaction.ReceivedCoins)
            {
                if (UTXOByOutpoint.ContainsKey(coin.Outpoint))
                {
                    result = ApplyTransactionResult.Conflict;
                    Conflicts.Add(coin.Outpoint, hash);
                }
            }

            foreach (var spentOutpoint in trackedTransaction.SpentOutpoints)
            {
                if (_KnownInputs.Contains(spentOutpoint) ||
                    (!UTXOByOutpoint.ContainsKey(spentOutpoint) && SpentUTXOs.Contains(spentOutpoint)))
                {
                    result = ApplyTransactionResult.Conflict;
                    Conflicts.Add(spentOutpoint, hash);
                }
            }
            if (result == ApplyTransactionResult.Conflict)
            {
                return(result);
            }

            _TransactionTimes.Add(trackedTransaction.FirstSeen);

            foreach (var coin in trackedTransaction.ReceivedCoins)
            {
                UTXOByOutpoint.TryAdd(coin.Outpoint, coin);
            }

            if (trackedTransaction.ReceivedCoins.Count == 0 && trackedTransaction.Transaction != null)
            {
                UTXOByOutpoint.Prunable.Add(new Prunable()
                {
                    PrunedBy = hash, TransactionId = hash
                });
            }

            foreach (var spentOutpoint in trackedTransaction.SpentOutpoints)
            {
                if (UTXOByOutpoint.Remove(spentOutpoint, hash))
                {
                    SpentUTXOs.Add(spentOutpoint);
                }
                _KnownInputs.Add(spentOutpoint);
            }
            return(result);
        }
예제 #4
0
 public AnnotatedTransaction(TrackedTransaction tracked, ChainBase chain)
 {
     Record = tracked;
     if (tracked.BlockHash == null)
     {
         Type = AnnotatedTransactionType.Unconfirmed;
     }
     else
     {
         var block = chain.GetBlock(tracked.BlockHash);
         Type   = block == null ? AnnotatedTransactionType.Orphan : AnnotatedTransactionType.Confirmed;
         Height = block?.Height;
     }
 }
 public TransactionMatchData(TrackedTransaction trackedTransaction)
 {
     if (trackedTransaction == null)
     {
         throw new ArgumentNullException(nameof(trackedTransaction));
     }
     Key                 = trackedTransaction.Key;
     Transaction         = trackedTransaction.Transaction;
     FirstSeenTickCount  = trackedTransaction.FirstSeen.Ticks;
     TickCount           = trackedTransaction.Inserted.Ticks;
     KnownKeyPathMapping = trackedTransaction.KnownKeyPathMapping;
     if (trackedTransaction.Key.IsPruned)
     {
         _CoinsData = trackedTransaction.ReceivedCoins.Select(c => new CoinData(c.Outpoint.N, c.TxOut)).ToArray();
     }
 }
 public AnnotatedTransaction(TrackedTransaction tracked, SlimChain chain)
 {
     if (tracked == null)
     {
         throw new ArgumentNullException(nameof(tracked));
     }
     Record = tracked;
     if (tracked.BlockHash == null)
     {
         Type = AnnotatedTransactionType.Unconfirmed;
     }
     else
     {
         var block = chain?.GetBlock(tracked.BlockHash);
         Type   = block == null ? AnnotatedTransactionType.Orphan : AnnotatedTransactionType.Confirmed;
         Height = block?.Height;
     }
 }
예제 #7
0
        public ApplyTransactionResult Apply(TrackedTransaction trackedTransaction)
        {
            var result = ApplyTransactionResult.Passed;
            var hash   = trackedTransaction.Key.TxId;

            foreach (var coin in trackedTransaction.ReceivedCoins)
            {
                if (UTXOByOutpoint.ContainsKey(coin.Outpoint))
                {
                    result = ApplyTransactionResult.Conflict;
                }
            }

            foreach (var spentOutpoint in trackedTransaction.SpentOutpoints)
            {
                if (_KnownInputs.Contains(spentOutpoint) ||
                    (!UTXOByOutpoint.ContainsKey(spentOutpoint) && SpentUTXOs.Contains(spentOutpoint)))
                {
                    result = ApplyTransactionResult.Conflict;
                }
            }
            if (result == ApplyTransactionResult.Conflict)
            {
                return(result);
            }

            foreach (var coin in trackedTransaction.ReceivedCoins)
            {
                UTXOByOutpoint.TryAdd(coin.Outpoint, coin);
            }

            foreach (var spentOutpoint in trackedTransaction.SpentOutpoints)
            {
                if (UTXOByOutpoint.Remove(spentOutpoint))
                {
                    SpentUTXOs.Add(spentOutpoint);
                }
                _KnownInputs.Add(spentOutpoint);
            }
            return(result);
        }
예제 #8
0
 public AnnotatedTransaction(int?height, TrackedTransaction record, bool isMature)
 {
     this.Record   = record;
     this.Height   = height;
     this.IsMature = isMature;
 }