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


C# Chain.SetTip方法代码示例

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


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

示例1: RunFullBlockTest

        public void RunFullBlockTest()
        {
            var generator = new FullBlockTestGenerator(Network.Main);

            ValidationState validation = new ValidationState(Network.Main);
            validation.CheckMerkleRoot = false;
            validation.CheckProofOfWork = false;

            var scan =
                new ScanState(new PubKeyHashScanner(generator.CoinbaseKey.PubKey.ID),
                        new Chain(),
                        new Account(),
                        0);
            scan.CheckDoubleSpend = true;

            var mainChain = new Chain(Network.Main);
            var indexed = new IndexedBlockStore(new InMemoryNoSqlRepository(), CreateBlockStore());
            indexed.Put(Network.Main.GetGenesis());
            foreach(var test in generator.GetBlocksToTest(true, true).list.OfType<BlockAndValidity>())
            {
                indexed.Put(test.block);
                mainChain.GetOrAdd(test.block.Header);
                Assert.True(scan.Process(mainChain, indexed) == test.connects);
                //if(!)
                //{
                //	Assert.True(test.throwsException);
                //}
                Assert.Equal(test.heightAfterBlock, scan.Chain.Height);
                Assert.Equal(test.hashChainTipAfterBlock, scan.Chain.Tip.HashBlock);
                mainChain.SetTip(scan.Chain.Tip);
            }
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:32,代码来源:FullBlockTestGenerator.cs

示例2: CanForkSidePartialChain

        public void CanForkSidePartialChain()
        {
            var block = TestUtils.CreateFakeBlock();
            Chain side = new Chain(block.Header, 10, new StreamObjectStream<ChainChange>());
            Chain main = new Chain(block.Header, 10, new StreamObjectStream<ChainChange>());
            AppendBlock(side, main);
            AppendBlock(side, main);
            var common = AppendBlock(side, main);
            var sideb = AppendBlock(side);
            var mainb1 = AppendBlock(main);
            var mainb2 = AppendBlock(main);
            var mainb3 = AppendBlock(main);
            Assert.Equal(common.HashBlock, side.SetTip(main.Tip).HashBlock);
            Assert.NotNull(side.GetBlock(mainb1.HashBlock));
            Assert.NotNull(side.GetBlock(mainb2.HashBlock));
            Assert.NotNull(side.GetBlock(mainb3.HashBlock));
            Assert.NotNull(side.GetBlock(common.HashBlock));
            Assert.Null(side.GetBlock(sideb.HashBlock));

            Assert.Equal(common.HashBlock, side.SetTip(sideb).HashBlock);
            Assert.Null(side.GetBlock(mainb1.HashBlock));
            Assert.Null(side.GetBlock(mainb2.HashBlock));
            Assert.Null(side.GetBlock(mainb3.HashBlock));
            Assert.NotNull(side.GetBlock(sideb.HashBlock));
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:25,代码来源:ChainTests.cs

示例3: CanForkSide

        public void CanForkSide()
        {
            Chain side = new Chain(Network.Main);
            Chain main = new Chain(Network.Main);
            AppendBlock(side, main);
            AppendBlock(side, main);
            var common = AppendBlock(side, main);
            var sideb = AppendBlock(side);
            var mainb1 = AppendBlock(main);
            var mainb2 = AppendBlock(main);
            var mainb3 = AppendBlock(main);
            Assert.Equal(common.HashBlock, side.SetTip(main.Tip).HashBlock);
            Assert.NotNull(side.GetBlock(mainb1.HashBlock));
            Assert.NotNull(side.GetBlock(mainb2.HashBlock));
            Assert.NotNull(side.GetBlock(mainb3.HashBlock));
            Assert.NotNull(side.GetBlock(common.HashBlock));
            Assert.Null(side.GetBlock(sideb.HashBlock));

            Assert.Equal(common.HashBlock, side.SetTip(sideb).HashBlock);
            Assert.Null(side.GetBlock(mainb1.HashBlock));
            Assert.Null(side.GetBlock(mainb2.HashBlock));
            Assert.Null(side.GetBlock(mainb3.HashBlock));
            Assert.NotNull(side.GetBlock(sideb.HashBlock));
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:24,代码来源:ChainTests.cs

示例4: CanForkBackwardPartialChain

        public void CanForkBackwardPartialChain()
        {
            Chain chain = new Chain(TestUtils.CreateFakeBlock().Header, 10, new StreamObjectStream<ChainChange>());
            AppendBlock(chain);
            AppendBlock(chain);
            var fork = AppendBlock(chain);

            //Test single block back fork
            var last = AppendBlock(chain);
            Assert.Equal(14, chain.Height);
            Assert.Equal(14, last.Height);
            Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
            Assert.Equal(fork.HashBlock, chain.SetTip(fork).HashBlock);
            Assert.Equal(13, chain.Height);
            Assert.Equal(13, fork.Height);
            Assert.Equal(fork.HashBlock, chain.Tip.HashBlock);
            Assert.Null(chain.GetBlock(last.HashBlock));
            Assert.NotNull(chain.GetBlock(fork.HashBlock));

            //Test 3 blocks back fork
            var b1 = AppendBlock(chain);
            var b2 = AppendBlock(chain);
            last = AppendBlock(chain);
            Assert.Equal(16, chain.Height);
            Assert.Equal(16, last.Height);
            Assert.Equal(last.HashBlock, chain.Tip.HashBlock);

            Assert.Equal(fork.HashBlock, chain.SetTip(fork).HashBlock);
            Assert.Equal(13, chain.Height);
            Assert.Equal(13, fork.Height);
            Assert.Equal(fork.HashBlock, chain.Tip.HashBlock);
            Assert.Null(chain.GetBlock(last.HashBlock));
            Assert.Null(chain.GetBlock(b1.HashBlock));
            Assert.Null(chain.GetBlock(b2.HashBlock));

            chain.SetTip(last);
            Assert.Equal(16, chain.Height);
            Assert.Equal(16, last.Height);
            Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:40,代码来源:ChainTests.cs

示例5: CanForkBackward

        public void CanForkBackward()
        {
            Chain chain = new Chain(Network.Main);
            AppendBlock(chain);
            AppendBlock(chain);
            var fork = AppendBlock(chain);

            //Test single block back fork
            var last = AppendBlock(chain);
            Assert.Equal(4, chain.Height);
            Assert.Equal(4, last.Height);
            Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
            Assert.Equal(fork.HashBlock, chain.SetTip(fork).HashBlock);
            Assert.Equal(3, chain.Height);
            Assert.Equal(3, fork.Height);
            Assert.Equal(fork.HashBlock, chain.Tip.HashBlock);
            Assert.Null(chain.GetBlock(last.HashBlock));
            Assert.NotNull(chain.GetBlock(fork.HashBlock));

            //Test 3 blocks back fork
            var b1 = AppendBlock(chain);
            var b2 = AppendBlock(chain);
            last = AppendBlock(chain);
            Assert.Equal(6, chain.Height);
            Assert.Equal(6, last.Height);
            Assert.Equal(last.HashBlock, chain.Tip.HashBlock);

            Assert.Equal(fork.HashBlock, chain.SetTip(fork).HashBlock);
            Assert.Equal(3, chain.Height);
            Assert.Equal(3, fork.Height);
            Assert.Equal(fork.HashBlock, chain.Tip.HashBlock);
            Assert.Null(chain.GetBlock(last.HashBlock));
            Assert.Null(chain.GetBlock(b1.HashBlock));
            Assert.Null(chain.GetBlock(b2.HashBlock));

            chain.SetTip(last);
            Assert.Equal(6, chain.Height);
            Assert.Equal(6, last.Height);
            Assert.Equal(last.HashBlock, chain.Tip.HashBlock);
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:40,代码来源:ChainTests.cs


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