Esempio n. 1
0
        public async Task <bool> EnsurePreviousLoadedAsync(OrderedBalanceChange change)
        {
            if (!NeedLoading(change))
            {
                return(true);
            }
            var transactions =
                await GetTransactionsAsync(false, ColoredBalance, change.SpentOutpoints.Select(s => s.Hash).ToArray()).ConfigureAwait(false);

            CoinCollection result = new CoinCollection();

            for (int i = 0; i < transactions.Length; i++)
            {
                var outpoint = change.SpentOutpoints[i];
                if (outpoint.IsNull)
                {
                    continue;
                }
                var prev = transactions[i];
                if (prev == null)
                {
                    return(false);
                }
                if (ColoredBalance && prev.ColoredTransaction == null)
                {
                    return(false);
                }
                result.Add(new Coin(outpoint, prev.Transaction.Outputs[change.SpentOutpoints[i].N]));
            }
            change.SpentCoins = result;


            if (ColoredBalance && change.ColoredBalanceChangeEntry == null)
            {
                var thisTransaction = await GetTransactionAsync(false, ColoredBalance, change.TransactionId).ConfigureAwait(false);

                if (thisTransaction.ColoredTransaction == null)
                {
                    return(false);
                }
                change.ColoredBalanceChangeEntry = new ColoredBalanceChangeEntry(change, thisTransaction.ColoredTransaction);
            }

            var entity     = change.ToEntity();
            var spentCoins = Helper.GetEntityProperty(entity, "b");
            var coloredTx  = ColoredBalance ? entity.Properties["g"].BinaryValue : null;

            entity.Properties.Clear();
            if (coloredTx != null)
            {
                entity.Properties.Add("g", new EntityProperty(coloredTx));
            }
            Helper.SetEntityProperty(entity, "b", spentCoins);
            Configuration.GetBalanceTable().Execute(TableOperation.Merge(entity));
            change.AddRedeemInfo();
            return(true);
        }
Esempio n. 2
0
 private bool NeedLoading(OrderedBalanceChange change)
 {
     if (change.SpentCoins != null)
     {
         if (change.ColoredBalanceChangeEntry != null || !ColoredBalance)
         {
             change.AddRedeemInfo();
             return(false);
         }
     }
     return(true);
 }