Example #1
0
 private void UpdateToColoredCoins(CoinCollection collection, bool input)
 {
     if (collection == null)
     {
         return;
     }
     for (int i = 0; i < collection.Count; i++)
     {
         var coin = collection[i] as Coin;
         if (coin != null)
         {
             if (input)
             {
                 var txinIndex = SpentIndices[i];
                 var asset     = ColoredTransaction
                                 .Inputs
                                 .Where(_ => _.Index == (uint)txinIndex)
                                 .Select(_ => _.Asset)
                                 .FirstOrDefault();
                 if (asset != null)
                 {
                     collection[i] = coin.ToColoredCoin(asset);
                 }
             }
             else
             {
                 var asset = ColoredTransaction.GetColoredEntry(coin.Outpoint.N);
                 if (asset != null)
                 {
                     collection[i] = coin.ToColoredCoin(asset.Asset);
                 }
             }
         }
     }
 }
Example #2
0
 public ColoredBalanceChangeEntry(OrderedBalanceChange balanceChange, ColoredTransaction coloredTransaction)
 {
     _Colored = coloredTransaction;
     for (var i = 0; i < balanceChange.SpentIndices.Count; i++)
     {
         var spentIndex = balanceChange.SpentIndices[i];
         var entry      = coloredTransaction.Inputs.FirstOrDefault(o => o.Index == (uint)spentIndex);
         if (entry != null)
         {
             AddSpentCoin(entry.Asset, balanceChange.SpentCoins[(int)i]);
         }
         else
         {
             AddSpentCoin(null, balanceChange.SpentCoins[(int)i]);
         }
     }
     foreach (var coin in balanceChange.ReceivedCoins)
     {
         var entry = coloredTransaction.GetColoredEntry(coin.Outpoint.N);
         if (entry != null)
         {
             AddReceivedCoin(entry.Asset, coin, !coloredTransaction.Issuances.Contains(entry));
         }
         else
         {
             AddReceivedCoin(null, coin, false);
         }
     }
 }