예제 #1
0
        public BlockchainInfoModel GetBlockchainInfo()
        {
            var blockchainInfo = new BlockchainInfoModel
            {
                Chain                  = this.Network?.Name,
                Blocks                 = (uint)(this.ChainState?.ConsensusTip?.Height ?? 0),
                Headers                = (uint)(this.ChainIndexer?.Height ?? 0),
                BestBlockHash          = this.ChainState?.ConsensusTip?.HashBlock,
                Difficulty             = this.GetNetworkDifficulty()?.Difficulty ?? 0.0,
                MedianTime             = this.ChainState?.ConsensusTip?.GetMedianTimePast().ToUnixTimeSeconds() ?? 0,
                VerificationProgress   = 0.0,
                IsInitialBlockDownload = this.ibdState?.IsInitialBlockDownload() ?? true,
                Chainwork              = this.ChainState?.ConsensusTip?.ChainWork,
                IsPruned               = false
            };

            if (blockchainInfo.Headers > 0)
            {
                blockchainInfo.VerificationProgress = (double)blockchainInfo.Blocks / blockchainInfo.Headers;
            }

            return(blockchainInfo);
        }
예제 #2
0
        public BlockchainInfoModel GetBlockchainInfo()
        {
            var blockchainInfo = new BlockchainInfoModel
            {
                Chain                  = this.Network?.Name,
                Blocks                 = (uint)(this.ChainState?.ConsensusTip?.Height ?? 0),
                Headers                = (uint)(this.ChainIndexer?.Height ?? 0),
                BestBlockHash          = this.ChainState?.ConsensusTip?.HashBlock,
                Difficulty             = this.GetNetworkDifficulty()?.Difficulty ?? 0.0,
                MedianTime             = this.ChainState?.ConsensusTip?.GetMedianTimePast().ToUnixTimeSeconds() ?? 0,
                VerificationProgress   = 0.0,
                IsInitialBlockDownload = this.ibdState?.IsInitialBlockDownload() ?? true,
                Chainwork              = this.ChainState?.ConsensusTip?.ChainWork,
                IsPruned               = false
            };

            if (blockchainInfo.Headers > 0)
            {
                blockchainInfo.VerificationProgress = (double)blockchainInfo.Blocks / blockchainInfo.Headers;
            }

            // softfork deployments
            blockchainInfo.SoftForks = new List <SoftForks>();

            foreach (var consensusBuriedDeployment in Enum.GetValues(typeof(BuriedDeployments)))
            {
                bool active = this.ChainIndexer.Height >= this.Network.Consensus.BuriedDeployments[(BuriedDeployments)consensusBuriedDeployment];
                blockchainInfo.SoftForks.Add(new SoftForks
                {
                    Id      = consensusBuriedDeployment.ToString().ToLower(),
                    Version = (int)consensusBuriedDeployment + 2, // hack to get the deployment number similar to bitcoin core without changing the enums
                    Status  = new SoftForksStatus {
                        Status = active
                    }
                });
            }

            // softforkbip9 deployments
            blockchainInfo.SoftForksBip9 = new Dictionary <string, SoftForksBip9>();

            ConsensusRuleEngine ruleEngine = (ConsensusRuleEngine)this.ConsensusManager.ConsensusRules;

            ThresholdState[]           thresholdStates = ruleEngine.NodeDeployments.BIP9.GetStates(this.ChainIndexer.Tip.Previous);
            List <ThresholdStateModel> metrics         = ruleEngine.NodeDeployments.BIP9.GetThresholdStateMetrics(this.ChainIndexer.Tip.Previous, thresholdStates);

            foreach (ThresholdStateModel metric in metrics.Where(m => !m.DeploymentName.ToLower().Contains("test"))) // to remove the test dummy
            {
                // TODO: Deployment timeout may not be implemented yet

                // Deployments with timeout value of 0 are hidden.
                // A timeout value of 0 guarantees a softfork will never be activated.
                // This is used when softfork codes are merged without specifying the deployment schedule.
                if (metric.TimeTimeOut?.Ticks > 0)
                {
                    blockchainInfo.SoftForksBip9.Add(metric.DeploymentName, this.CreateSoftForksBip9(metric, thresholdStates[metric.DeploymentIndex]));
                }
            }

            // TODO: Implement blockchainInfo.warnings
            return(blockchainInfo);
        }