示例#1
0
        public IRpcMethodResult GetBlockChainInfo()
        {
            try
            {
                var result = new GetBlockChainInfoOM();
                var info   = Startup.GetLatestBlockChainInfoFunc();

                result.isRunning               = info.IsP2PRunning;
                result.connections             = info.ConnectionCount;
                result.localLastBlockHeight    = info.LastBlockHeightInCurrentNode;
                result.localLastBlockTime      = info.LastBlockTimeInCurrentNode;
                result.tempBlockCount          = info.TempBlockCount;
                result.remoteLatestBlockHeight = info.LatestBlockHeightInNetwork;
                result.timeOffset              = info.LatestBlockTimeInNetwork - info.LastBlockTimeInCurrentNode;

                if (info.LastBlockTimeInCurrentNode <= 0 || info.LatestBlockTimeInNetwork <= 0)
                {
                    result.timeOffset = -1;
                }


                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
示例#2
0
        public IRpcMethodResult GetBlockChainInfo()
        {
            try
            {
                var result = new GetBlockChainInfoOM();
                var info   = Startup.GetLatestBlockChainInfoFunc();

                result.isRunning               = info.IsP2PRunning;
                result.connections             = info.ConnectionCount;
                result.localLastBlockHeight    = info.LastBlockHeightInCurrentNode;
                result.localLastBlockTime      = info.LastBlockTimeInCurrentNode;
                result.tempBlockCount          = info.TempBlockCount;
                result.TempBlockHeights        = info.TempBlockHeights;
                result.remoteLatestBlockHeight = info.LatestBlockHeightInNetwork;
                result.timeOffset              = info.LatestBlockTimeInNetwork - info.LastBlockTimeInCurrentNode;
                result.SyncTasks               = new List <DTO.SyncTaskItem>();

                if (info.SyncTasks != null)
                {
                    foreach (var item in info.SyncTasks)
                    {
                        var newItem = new DTO.SyncTaskItem();
                        newItem.IP        = item.IP;
                        newItem.Port      = item.Port;
                        newItem.StartTime = Time.GetLocalDateTime(item.StartTime);
                        newItem.Status    = item.Status;
                        newItem.Heights   = item.Heights;

                        result.SyncTasks.Add(newItem);
                    }
                }

                if (info.LastBlockTimeInCurrentNode <= 0 || info.LatestBlockTimeInNetwork <= 0)
                {
                    result.timeOffset = -1;
                }


                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }