示例#1
0
        protected override void OnSaveTransaction(CoreTransaction tx, IEnumerable <WalletCoin> added, IEnumerable <WalletCoin> changed)
        {
            Transaction tx_changed = null;

            using (WalletDataContext ctx = new WalletDataContext(DbPath))
            {
                if (IsWalletTransaction(tx))
                {
                    tx_changed = ctx.Transactions.Add(new Transaction
                    {
                        Hash    = tx.Hash.ToArray(),
                        Type    = tx.Type,
                        RawData = tx.ToArray(),
                        Height  = null,
                        Time    = DateTime.Now
                    }).Entity;
                }
                OnCoinsChanged(ctx, added, changed, Enumerable.Empty <WalletCoin>());
                ctx.SaveChanges();
            }
            if (tx_changed != null)
            {
                TransactionsChanged?.Invoke(this, GetTransactionInfo(new[] { tx_changed }));
            }
        }
示例#2
0
 private static IEnumerable <TransactionInfo> GetTransactionInfo(IEnumerable <Transaction> transactions)
 {
     return(transactions.Select(p => new TransactionInfo
     {
         Transaction = CoreTransaction.DeserializeFrom(p.RawData),
         Height = p.Height,
         Time = p.Time
     }));
 }
示例#3
0
 public override IEnumerable <T> GetTransactions <T>()
 {
     using (WalletDataContext ctx = new WalletDataContext(DbPath))
     {
         IQueryable <Transaction> transactions = ctx.Transactions;
         if (typeof(T).GetTypeInfo().IsSubclassOf(typeof(CoreTransaction)))
         {
             TransactionType type = (TransactionType)Enum.Parse(typeof(TransactionType), typeof(T).Name);
             transactions = transactions.Where(p => p.Type == type);
         }
         return(transactions.Select(p => p.RawData).ToArray().Select(p => (T)CoreTransaction.DeserializeFrom(p)));
     }
 }
示例#4
0
        protected override void OnSaveTransaction(CoreTransaction tx,
                                                  IEnumerable <WalletCoin> added,
                                                  IEnumerable <WalletCoin> changed,
                                                  IEnumerable <JSWalletCoin> jsadded,
                                                  IEnumerable <JSWalletCoin> jschanged,
                                                  IEnumerable <JSWalletCoin> jsdeleted,
                                                  IEnumerable <JSWalletCoin> jswitnesschanged,
                                                  IEnumerable <RCTWalletCoin> rctadded,
                                                  IEnumerable <RCTWalletCoin> rctchanged,
                                                  IEnumerable <RCTWalletCoin> rctdeleted)
        {
            Transaction tx_changed = null;

            using (WalletDataContext ctx = new WalletDataContext(DbPath))
            {
                if (IsWalletTransaction(tx))
                {
                    tx_changed = ctx.Transactions.Add(new Transaction
                    {
                        Hash    = tx.Hash.ToArray(),
                        Type    = tx.Type,
                        RawData = tx.ToArray(),
                        Height  = null,
                        Time    = DateTime.Now
                    }).Entity;
                }
                OnCoinsChanged(ctx, added, changed, Enumerable.Empty <WalletCoin>(),
                               jsadded,
                               jschanged,
                               jsdeleted,
                               jswitnesschanged,
                               rctadded,
                               rctchanged,
                               rctdeleted);

                try
                {
                    ctx.SaveChanges();
                }
                catch (Exception ex)
                {
                    string str = ex.Message;
                }
            }
            if (tx_changed != null)
            {
                TransactionsChanged?.Invoke(this, GetTransactionInfo(new[] { tx_changed }));
            }
        }