public static ChainIndexer Load(this ChainIndexer chainIndexer, byte[] chain)
 {
     using (var ms = new MemoryStream(chain))
     {
         return(chainIndexer.Load(ms));
     }
 }
Exemplo n.º 2
0
        public void CanCalculatePowCorrectly()
        {
            var chain = new ChainIndexer(KnownNetworks.Main);

            EnsureDownloaded("MainChain.dat", "https://aois.blob.core.windows.net/public/MainChain.dat");
            chain.Load(File.ReadAllBytes("MainChain.dat"));
            foreach (ChainedHeader block in chain.EnumerateAfter(chain.Genesis))
            {
                Target thisWork  = block.GetWorkRequired(KnownNetworks.Main);
                Target thisWork2 = block.Previous.GetNextWorkRequired(KnownNetworks.Main);
                Assert.Equal(thisWork, thisWork2);
                Assert.True(block.CheckProofOfWorkAndTarget(KnownNetworks.Main));
            }
        }
Exemplo n.º 3
0
        public void CanLoadAndSaveConcurrentChain()
        {
            var cchain = new ChainIndexer(this.network);
            var chain  = new ChainIndexer(this.network);

            this.AddBlock(chain);
            this.AddBlock(chain);
            this.AddBlock(chain);

            cchain.SetTip(chain.Tip);

            byte[] bytes = cchain.ToBytes();
            cchain = new ChainIndexer(this.network);
            cchain.Load(bytes);

            Assert.Equal(cchain.Tip, chain.Tip);
            Assert.NotNull(cchain.GetHeader(0));

            cchain = new ChainIndexer(this.networkTest);
            cchain.Load(cchain.ToBytes());
            Assert.NotNull(cchain.GetHeader(0));
        }
 public static ChainIndexer Load(this ChainIndexer chainIndexer, Stream stream)
 {
     return(chainIndexer.Load(new BitcoinStream(stream, false)));
 }