Example #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 }));
            }
        }
 protected virtual void OnTransactionsChanged()
 {
     if (ShouldNotify)
     {
         TransactionsChanged?.Invoke(this, EventArgs.Empty);
     }
 }
Example #3
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 }));
            }
        }
Example #4
0
 protected override void OnProcessNewBlock(Block block, IEnumerable <WalletCoin> added, IEnumerable <WalletCoin> changed, IEnumerable <WalletCoin> deleted)
 {
     Transaction[] tx_changed = null;
     using (WalletDataContext ctx = new WalletDataContext(DbPath))
     {
         foreach (CoreTransaction tx in block.Transactions.Where(p => IsWalletTransaction(p)))
         {
             Transaction db_tx = ctx.Transactions.FirstOrDefault(p => p.Hash.SequenceEqual(tx.Hash.ToArray()));
             if (db_tx == null)
             {
                 ctx.Transactions.Add(new Transaction
                 {
                     Hash    = tx.Hash.ToArray(),
                     Type    = tx.Type,
                     RawData = tx.ToArray(),
                     Height  = block.Height,
                     Time    = block.Timestamp.ToDateTime()
                 });
             }
             else
             {
                 db_tx.Height = block.Height;
             }
         }
         OnCoinsChanged(ctx, added, changed, deleted);
         if (block.Height == Blockchain.Default.Height || ctx.ChangeTracker.Entries().Any())
         {
             foreach (Transaction db_tx in ctx.Transactions.Where(p => !p.Height.HasValue))
             {
                 if (block.Transactions.Any(p => p.Hash == new UInt256(db_tx.Hash)))
                 {
                     db_tx.Height = block.Height;
                 }
             }
             ctx.Keys.First(p => p.Name == "Height").Value = BitConverter.GetBytes(WalletHeight);
             tx_changed = ctx.ChangeTracker.Entries <Transaction>().Where(p => p.State != EntityState.Unchanged).Select(p => p.Entity).ToArray();
             ctx.SaveChanges();
         }
     }
     if (tx_changed?.Length > 0)
     {
         TransactionsChanged?.Invoke(this, GetTransactionInfo(tx_changed));
     }
 }
Example #5
0
        protected override void OnProcessNewBlock(Block block,
                                                  IEnumerable <WalletCoin> added,
                                                  IEnumerable <WalletCoin> changed,
                                                  IEnumerable <WalletCoin> deleted,
                                                  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))
            {
                foreach (CoreTransaction tx in block.Transactions.Where(p => IsWalletTransaction(p)))
                {
                    Transaction db_tx = ctx.Transactions.FirstOrDefault(p => p.Hash.SequenceEqual(tx.Hash.ToArray()));
                    if (db_tx == null)
                    {
                        ctx.Transactions.Add(new Transaction
                        {
                            Hash    = tx.Hash.ToArray(),
                            Type    = tx.Type,
                            RawData = tx.ToArray(),
                            Height  = block.Index,
                            Time    = block.Timestamp.ToDateTime()
                        });
                    }
                    else
                    {
                        db_tx.Height = block.Index;
                    }

                    if (tx is RegisterMultiSignTransaction rtx)
                    {
                        RegisterContract(rtx.WalletValidatorList.ToArray(), rtx.ValidatorCount);
                    }
                }

                tx_changed = ctx.ChangeTracker.Entries <Transaction>().Where(p => p.State != EntityState.Unchanged).Select(p => p.Entity).ToArray();

                OnCoinsChanged(ctx, added, changed, deleted, jsadded, jschanged, jsdeleted, jswitnesschanged, rctadded, rctchanged, rctdeleted);
                if (block.Index == Blockchain.Default.Height || ctx.ChangeTracker.Entries().Any())
                {
                    foreach (Transaction db_tx in ctx.Transactions.Where(p => !p.Height.HasValue))
                    {
                        if (block.Transactions.Any(p => p.Hash == new UInt256(db_tx.Hash)))
                        {
                            db_tx.Height = block.Index;
                        }
                    }

                    ctx.Keys.First(p => p.Name == "Height").Value       = BitConverter.GetBytes(WalletHeight);
                    ctx.Keys.First(p => p.Name == "CmMerkleTree").Value = GetCmMerkleTreeInBytes();

                    try
                    {
                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        string str = ex.Message;
                    }
                }
            }
            if (tx_changed?.Length > 0)
            {
                TransactionsChanged?.Invoke(this, GetTransactionInfo(tx_changed));
            }
        }