Ejemplo n.º 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 }));
            }
        }
Ejemplo n.º 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
     }));
 }
Ejemplo n.º 3
0
 public override IEnumerable <CoreTransaction> GetTransactions()
 {
     using (WalletDataContext ctx = new WalletDataContext(DbPath))
     {
         foreach (Transaction tx in ctx.Transactions)
         {
             yield return(CoreTransaction.DeserializeFrom(tx.RawData));
         }
     }
 }
Ejemplo n.º 4
0
        public override IEnumerable <T> GetTransactions <T>()
        {
            TransactionType type = (TransactionType)Enum.Parse(typeof(TransactionType), typeof(T).Name);

            using (WalletDataContext ctx = new WalletDataContext(DbPath))
            {
                foreach (Transaction tx in ctx.Transactions.Where(p => p.Type == type))
                {
                    yield return((T)CoreTransaction.DeserializeFrom(tx.RawData));
                }
            }
        }
Ejemplo n.º 5
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)));
     }
 }
Ejemplo n.º 6
0
 public override bool IsDoubleSpend(Transaction tx)
 {
     TransactionInput[] inputs = tx.GetAllInputs().ToArray();
     if (inputs.Length == 0) return false;
     lock (MemoryPool)
     {
         if (MemoryPool.Values.SelectMany(p => p.GetAllInputs()).Intersect(inputs).Count() > 0)
             return true;
     }
     ReadOptions options = new ReadOptions();
     using (options.Snapshot = db.GetSnapshot())
     {
         foreach (var group in inputs.GroupBy(p => p.PrevHash))
         {
             Slice value;
             if (!db.TryGet(options, SliceBuilder.Begin(DataEntryPrefix.IX_Unspent).Add(group.Key), out value))
                 return true;
             HashSet<ushort> unspents = new HashSet<ushort>(value.ToArray().GetUInt16Array());
             if (group.Any(p => !unspents.Contains(p.PrevIndex)))
                 return true;
         }
     }
     return false;
 }
Ejemplo n.º 7
0
 private void RemoteNode_TransactionReceived(object sender, Transaction tx)
 {
     if (Blockchain.Default == null) return;
     if (Blockchain.Default.ContainsTransaction(tx.Hash)) return;
     if (!Blockchain.Default.AddTransaction(tx)) return;
     RelayInternalAsync(tx).Void();
     if (NewInventory != null) NewInventory(this, tx);
 }
Ejemplo n.º 8
0
 private void LocalNode_NewTransaction(object sender, Transaction tx)
 {
     MemoryPool.TryAdd(tx.Hash, tx);
 }
Ejemplo n.º 9
0
 public virtual bool IsDoubleSpend(Transaction tx)
 {
     throw new NotSupportedException();
 }