예제 #1
0
        void LinkUTXO()
        {
            HashDictionary <List <Consensus.Types.Output> > txOutputs;
            HashDictionary <Consensus.Types.Transaction>    txs;

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

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

            foreach (var tx in _Txs)
            {
                if (txs.ContainsKey(tx.Key))
                {
                    foreach (var output in txOutputs[tx.Key])
                    {
                        var outputHash = Consensus.Merkle.outputHasher.Invoke(output);

                        //Add(outputHash, new GraphNode(GraphNodeTypeEnum.Output), utxoSet);
                    }
                }
            }
        }
예제 #2
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();
        }
예제 #3
0
        protected bool CheckUTXOCOntains(Types.Output output)
        {
            var utxos = new GetUTXOSetAction().Publish().Result;

            foreach (var item in utxos.Item1)
            {
                if (item.Value.Contains(output))
                {
                    return(true);
                }
            }

            return(false);
        }
        bool CheckUtxsSetContains(Types.Transaction tx)
        {
            var txHash = Merkle.transactionHasher.Invoke(tx);
            var utxos  = new GetUTXOSetAction().Publish().Result;

            if (utxos.Item2.ContainsKey(txHash))
            {
                foreach (var output in tx.outputs)
                {
                    if (utxos.Item1[txHash].Contains(output))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }