コード例 #1
0
        /// <inheritdoc />
        public Task <ChainedHeader> LoadAsync(ChainedHeader genesisHeader)
        {
            Task <ChainedHeader> task = Task.Run(() =>
            {
                lock (this.lockObj)
                {
                    ChainedHeader tip = null;

                    ChainData data = this.chainStore.GetChainData(0);

                    if (data == null)
                    {
                        genesisHeader.SetChainStore(this.chainStore);
                        return(genesisHeader);
                    }

                    Guard.Assert(data.Hash == genesisHeader.HashBlock); // can't swap networks

                    int index = 0;
                    while (true)
                    {
                        data = this.chainStore.GetChainData((index));

                        if (data == null)
                        {
                            break;
                        }

                        tip = new ChainedHeader(data.Hash, data.Work, tip);
                        if (tip.Height == 0)
                        {
                            tip.SetChainStore(this.chainStore);
                        }
                        index++;
                    }

                    if (tip == null)
                    {
                        genesisHeader.SetChainStore(this.chainStore);
                        tip = genesisHeader;
                    }

                    this.locator = tip.GetLocator();
                    return(tip);
                }
            });

            return(task);
        }
コード例 #2
0
        /// <inheritdoc />
        public Task <ChainedHeader> LoadAsync(ChainedHeader genesisHeader)
        {
            Task <ChainedHeader> task = Task.Run(() =>
            {
                lock (this.lockObj)
                {
                    ChainedHeader tip = null;

                    ChainData data = this.chainStore.GetChainData(0);

                    if (data == null)
                    {
                        genesisHeader.SetChainStore(this.chainStore);
                        return(genesisHeader);
                    }

                    Guard.Assert(data.Hash == genesisHeader.HashBlock); // can't swap networks

                    var list = this.chainStore.GetChainData();

                    foreach (var chainedData in list)
                    {
                        // Create a new ChainedHeader with reference to previous. This will build a large object graph of all headers.
                        tip = new ChainedHeader(chainedData.Hash, chainedData.Work, tip);

                        if (tip.Height == 0)
                        {
                            tip.SetChainStore(this.chainStore);
                        }
                    }

                    if (tip == null)
                    {
                        genesisHeader.SetChainStore(this.chainStore);
                        tip = genesisHeader;
                    }

                    this.locator = tip.GetLocator();
                    return(tip);
                }
            });

            return(task);
        }