Example #1
0
        /// <summary>
        /// Imports wallet file
        /// </summary>
        public void Import(Key key)
        {
            _BlockChainListener.Pause();

            using (var context = _DBContext.GetTransactionContext())
            {
                _KeyStore.AddKey(context, System.Convert.ToBase64String(key.Private));
                context.Commit();
            }

            //TODO: store the key in DB?
            _Keys.Add(key);

            HashDictionary <List <Types.Output> > txOutputs;
            HashDictionary <Types.Transaction>    txs;

            var result = new GetUTXOSetAction()
            {
                Predicate = IsMatch
            }.Publish().Result;

            txOutputs = result.Item1;
            txs       = result.Item2;

            TxDeltaList.Clear();

            using (var dbTx = _DBContext.GetTransactionContext())
            {
                //dbTx.Transaction.SynchronizeTables(TxBalancesStore.INDEXES);
                _TxStore.Reset(dbTx);

                foreach (var item in txOutputs)
                {
                    var assetDeltas = new AssetDeltas();

                    foreach (var output in item.Value)
                    {
                        AddOutput(assetDeltas, output);
                    }

                    _TxStore.Put(dbTx, item.Key, txs[item.Key], assetDeltas, TxStateEnum.Confirmed);
                    TxDeltaList.Add(new TxDelta(TxStateEnum.Confirmed, item.Key, txs[item.Key], assetDeltas));
                }

                _BlockChain.memPool.TxPool.ToList().ForEach(t => HandleTx(dbTx, t.Key, t.Value, TxDeltaList, TxStateEnum.Unconfirmed));

                dbTx.Commit();
            }

            if (OnItems != null)
            {
                OnItems(TxDeltaList);
            }

            _BlockChainListener.Continue();
        }
Example #2
0
        void Populate()
        {
            _BlockChainListener.Pause();

            _TransactionQueue.Clear();

            lock (_BlockChain.memPool.TxPool)
            {
                foreach (var item in _BlockChain.memPool.TxPool)
                {
                    _TransactionQueue.Push(item.Value);
                }
            }

            MinerTrace.Information($"Populated, having {_TransactionQueue.Count} txs");

            RecalculateHeader();

            _BlockChainListener.Continue();
        }