当前位置: 首页>>代码示例>>C#>>正文


C# Chain.ToEnumerable方法代码示例

本文整理汇总了C#中Chain.ToEnumerable方法的典型用法代码示例。如果您正苦于以下问题:C# Chain.ToEnumerable方法的具体用法?C# Chain.ToEnumerable怎么用?C# Chain.ToEnumerable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chain的用法示例。


在下文中一共展示了Chain.ToEnumerable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public void Process(Chain mainChain, IBlockProvider blockProvider)
        {
            bool newChain = false;
            if(!Chain.Initialized)
            {
                newChain = true;

                var firstBlock = mainChain.GetBlock(StartHeight);
                Chain.Initialize(firstBlock.Header, StartHeight);
            }
            var forkBlock = mainChain.FindFork(Chain);
            if(forkBlock.HashBlock != Chain.Tip.HashBlock)
            {
                Chain.SetTip(Chain.GetBlock(forkBlock.Height));
                foreach(var e in Account.GetInChain(Chain, false)
                                            .Where(e => e.Reason != AccountEntryReason.ChainBlockChanged))
                {
                    var neutralized = e.Neutralize();
                    Account.PushAccountEntry(neutralized);
                }
            }

            var unprocessedBlocks = mainChain.ToEnumerable(true)
                                       .TakeWhile(block => block != forkBlock)
                                       .Concat(newChain ? new ChainedBlock[] { forkBlock } : new ChainedBlock[0])
                                       .Reverse().ToArray();
            foreach(var block in unprocessedBlocks)
            {
                List<byte[]> searchedData = new List<byte[]>();
                Scanner.GetScannedPushData(searchedData);
                foreach(var unspent in Account.Unspent)
                {
                    searchedData.Add(unspent.OutPoint.ToBytes());
                }

                var fullBlock = blockProvider.GetBlock(block.HashBlock, searchedData);
                if(fullBlock != null)
                {
                    foreach(var spent in Scanner.FindSpent(fullBlock, Account.Unspent))
                    {
                        var entry = new AccountEntry(AccountEntryReason.Outcome,
                                                    block.HashBlock,
                                                    spent, -spent.TxOut.Value);
                        Account.PushAccountEntry(entry);
                    }
                    foreach(var coins in Scanner.ScanCoins(fullBlock, (int)block.Height))
                    {
                        int i = 0;
                        foreach(var output in coins.Coins.Outputs)
                        {
                            if(!output.IsNull)
                            {
                                var entry = new AccountEntry(AccountEntryReason.Income, block.HashBlock,
                                                    new Spendable(new OutPoint(coins.TxId, i), output), output.Value);
                                Account.PushAccountEntry(entry);
                            }
                            i++;
                        }
                    }
                }
                Chain.GetOrAdd(block.Header);
            }
        }
开发者ID:royosherove,项目名称:NBitcoin,代码行数:63,代码来源:ScanState.cs

示例2: Play

        public static void Play()
        {
            //1,132

            //NodeServer server = new NodeServer(Network.Main);
            //server.RegisterPeerTableRepository(new SqLitePeerTableRepository("PeerCachePlay"));
            //server.BuildChain(new StreamObjectStream<ChainChange>(File.Open("MainChain.dat", FileMode.OpenOrCreate)));

            var from = new DateTimeOffset(new DateTime(2012, 12, 1));
            var to = new DateTimeOffset(new DateTime(2013, 1, 20));

            var chain = new Chain(new StreamObjectStream<ChainChange>(File.Open("MainChain.dat", FileMode.OpenOrCreate)));
            var blocks =
                chain.ToEnumerable(false)
                    .SkipWhile(c => c.Header.BlockTime < from)
                    .TakeWhile(c => c.Header.BlockTime < to)
                    .ToArray();

            //index.ReIndex();
            //Console.WriteLine("");

            BlockStore store = new BlockStore("E:\\Bitcoin\\blocks", Network.Main);
            IndexedBlockStore index = new IndexedBlockStore(new SQLiteNoSqlRepository("PlayIndex"), store);
            var target = Money.Parse("1100");
            var margin = Money.Parse("1");
            var dest = Network.CreateFromBase58Data<BitcoinAddress>("1FrtkNXastDoMAaorowys27AKQERxgmZjY");
            var en = new CultureInfo("en-US");

            FileStream fs = File.Open("logs", FileMode.Create);
            var writer = new StreamWriter(fs);
            writer.WriteLine("time,height,txid,value");

            var lines = from header in blocks
                        let block = index.Get(header.HashBlock)
                        from tx in block.Transactions
                        from txout in tx.Outputs
                        //where txout.ScriptPubKey.GetDestination() == dest.ID
                        where target - margin < txout.Value && txout.Value < target + margin
                        select new
                        {
                            Block = block,
                            Height = header.Height,
                            Transaction = tx,
                            TxOut = txout
                        };
            foreach(var line in lines)
            {
                writer.WriteLine(
                    line.Block.Header.BlockTime.ToString(en) + "," +
                    line.Height + "," +
                    line.Transaction.GetHash() + "," +
                    line.TxOut.Value.ToString());
            }
            writer.Flush();
            Process.Start(@"E:\Chocolatey\lib\notepadplusplus.commandline.6.4.5\tools\notepad++.exe", "\"" + new FileInfo(fs.Name).FullName + "\"");

            //foreach(var b in blocks)
            //{
            //	var block = index.Get(b.HashBlock);
            //	foreach(var tx in block.Transactions)
            //	{
            //		foreach(var txout in tx.Outputs)
            //		{
            //			var pa = new PayToPubkeyHashTemplate()
            //					.ExtractScriptPubKeyParameters(txout.ScriptPubKey);
            //			if(pa != null && pa == dest.ID)
            //			{
            //				if(target - margin < txout.Value && txout.Value < target + margin)
            //				{
            //					writer.WriteLine(b.Header.BlockTime.ToString(en) + "," + b.Height + "," + tx.GetHash() + "," + txout.Value.ToString());
            //				}
            //			}
            //		}
            //	}

            //}

            //They were purchased anonymously at a restaurant halfway between Sandwich, IL, and Chicago, in Naperville, IL, about the second week of December, 2012. Taxing my memory, the total was 1,132 + x(single digit).xxx... and immediately put in a freshly created InstaWallet bitcoin wallet. A couple/three days later I split the three accounts up into 1,000, 132, and x.xxx... wallets, always using InstaWallet while in my possession. Hope that helps with your plans.

            //var txt = File.ReadAllText("data/difficultyhistory.csv");
            //var lines = txt.Split(new string[]{"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
            //StringBuilder builder = new StringBuilder();
            //foreach(var line in lines)
            //{
            //	var fields = line.Split(',');
            //	builder.AppendLine(fields[0] + "," + fields[2]);
            //}
            //File.WriteAllText("targethistory.csv",builder.ToString());
            ////PlaySplit();
            //var oo = new PubKey(TestUtils.ParseHex("02bbc9fccbe03de928fc66fcd176fbe69d3641677970c6f8d558aa72f72e35e0cb")).GetAddress(Network.TestNet);
            //RPCClient client = RPCClientTests.CreateRPCClient();

            ////https://tpfaucet.appspot.com/
            //var scan = new Key(TestUtils.ParseHex("cc411aab02edcd3bccf484a9ba5280d4a774e6f81eac8ebec9cb1c2e8f73020a"));
            //var addr = new BitcoinStealthAddress("waPYjXyrTrvXjZHmMGdqs9YTegpRDpx97H5G3xqLehkgyrrZKsxGCmnwKexpZjXTCskUWwYywdUvrZK7L2vejeVZSYHVns61gm8VfU", Network.TestNet);

            //var sender = new BitcoinSecret("cRjSUV1LqN2F8MsGnLE2JKfCP75kbWGFRroNQeXHC429jqVFgmW3", Network.TestNet);

            //using(var fs = File.Open("Data.txt", FileMode.Create))
            //{
//.........这里部分代码省略.........
开发者ID:nikropht,项目名称:NBitcoin,代码行数:101,代码来源:RepositoryTests.cs

示例3: Process

        public bool Process(Chain mainChain, IBlockProvider blockProvider)
        {
            var chain = Chain.Clone();
            var chainPosition = chain.Changes.Position;
            var account = Account.Clone();
            var accountPosition = account.Entries.Position;

            bool newChain = false;
            if(!chain.Initialized)
            {
                newChain = true;

                var firstBlock = mainChain.GetBlock(StartHeight);
                chain.Initialize(firstBlock.Header, StartHeight);
            }
            var forkBlock = mainChain.FindFork(chain);
            if(forkBlock.HashBlock != chain.Tip.HashBlock)
            {
                var subChain = chain.CreateSubChain(forkBlock, false, chain.Tip, true);
                chain.SetTip(chain.GetBlock(forkBlock.Height));
                foreach(var e in account.GetInChain(subChain, true)
                                        .Where(c => c.Reason != AccountEntryReason.Lock && c.Reason != AccountEntryReason.Unlock)
                                        .Reverse())
                {
                    var neutralized = e.Neutralize();
                    account.PushAccountEntry(neutralized);
                }
            }

            var unprocessedBlocks = mainChain.ToEnumerable(true)
                                       .TakeWhile(block => block != forkBlock)
                                       .Concat(newChain ? new ChainedBlock[] { forkBlock } : new ChainedBlock[0])
                                       .Reverse().ToArray();
            foreach(var block in unprocessedBlocks)
            {
                List<byte[]> searchedData = new List<byte[]>();
                Scanner.GetScannedPushData(searchedData);
                foreach(var unspent in account.Unspent)
                {
                    searchedData.Add(unspent.OutPoint.ToBytes());
                }

                var fullBlock = blockProvider.GetBlock(block.HashBlock, searchedData);
                if(fullBlock == null)
                    continue;

                List<Tuple<OutPoint, AccountEntry>> spents = new List<Tuple<OutPoint, AccountEntry>>();
                foreach(var spent in FindSpent(fullBlock, account.Unspent))
                {
                    var entry = new AccountEntry(AccountEntryReason.Outcome,
                                                block.HashBlock,
                                                spent, -spent.TxOut.Value);
                    spents.Add(Tuple.Create(entry.Spendable.OutPoint, entry));
                }

                if(CheckDoubleSpend)
                {
                    var spentsDico = spents.ToDictionary(t => t.Item1, t => t.Item2);
                    foreach(var spent in Scanner.FindSpent(fullBlock))
                    {
                        if(!spentsDico.ContainsKey(spent.PrevOut))
                            return false;
                    }
                }

                foreach(var spent in spents)
                {
                    if(account.PushAccountEntry(spent.Item2) == null)
                        return false;
                }

                foreach(var coins in Scanner.ScanCoins(fullBlock, (int)block.Height))
                {
                    int i = 0;
                    foreach(var output in coins.Coins.Outputs)
                    {
                        if(!output.IsNull)
                        {
                            var entry = new AccountEntry(AccountEntryReason.Income, block.HashBlock,
                                                new Spendable(new OutPoint(coins.TxId, i), output), output.Value);
                            if(account.PushAccountEntry(entry) == null)
                                return false;
                        }
                        i++;
                    }
                }

                chain.GetOrAdd(block.Header);
            }

            account.Entries.GoTo(accountPosition);
            Account.Entries.WriteNext(account.Entries);
            Account.Process();

            chain.Changes.GoTo(chainPosition);
            Chain.Changes.WriteNext(chain.Changes);
            Chain.Process();
            return true;
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:99,代码来源:ScanState.cs


注:本文中的Chain.ToEnumerable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。