1+ import prettyMs from 'pretty-ms' ;
12import providers from '../providers.js' ;
23import { DockerStatusEnum } from '../enums/dockerStatus.js' ;
34import { ServiceStatusEnum } from '../enums/serviceStatus.js' ;
@@ -15,24 +16,35 @@ export default function getPlatformScopeFactory(
1516 createRpcClient ,
1617 getConnectionHost ,
1718) {
18- async function getMNSync ( config ) {
19+ async function getCoreInfo ( config ) {
1920 const rpcClient = createRpcClient ( {
2021 port : config . get ( 'core.rpc.port' ) ,
2122 user : 'dashmate' ,
2223 pass : config . get ( 'core.rpc.users.dashmate.password' ) ,
2324 host : await getConnectionHost ( config , 'core' , 'core.rpc.host' ) ,
2425 } ) ;
2526
27+ const [ mnSync , blockchainInfo ] = await Promise . all ( [
28+ rpcClient . mnsync ( 'status' ) ,
29+ rpcClient . getBlockchainInfo ( ) ,
30+ ] ) ;
31+
32+ const {
33+ result : {
34+ softforks : { mn_rr : mnRR } ,
35+ } ,
36+ } = blockchainInfo ;
37+
2638 const {
2739 result : {
2840 IsSynced : isSynced ,
2941 } ,
30- } = await rpcClient . mnsync ( 'status' ) ;
42+ } = mnSync ;
3143
32- return isSynced ;
44+ return { isSynced, mnRRSoftFork : mnRR } ;
3345 }
3446
35- async function getTenderdashInfo ( config , isCoreSynced ) {
47+ async function getTenderdashInfo ( config , isCoreSynced , mnRRSoftFork ) {
3648 const info = {
3749 p2pPortState : null ,
3850 httpPortState : null ,
@@ -63,7 +75,7 @@ export default function getPlatformScopeFactory(
6375 }
6476
6577 const dockerStatus = await determineStatus . docker ( dockerCompose , config , 'drive_tenderdash' ) ;
66- const serviceStatus = determineStatus . platform ( dockerStatus , isCoreSynced ) ;
78+ const serviceStatus = determineStatus . platform ( dockerStatus , isCoreSynced , mnRRSoftFork ) ;
6779
6880 info . dockerStatus = dockerStatus ;
6981 info . serviceStatus = serviceStatus ;
@@ -142,15 +154,15 @@ export default function getPlatformScopeFactory(
142154 return info ;
143155 }
144156
145- const getDriveInfo = async ( config , isCoreSynced ) => {
157+ const getDriveInfo = async ( config , isCoreSynced , mnRRSoftFork ) => {
146158 const info = {
147159 dockerStatus : null ,
148160 serviceStatus : null ,
149161 } ;
150162
151163 try {
152164 info . dockerStatus = await determineStatus . docker ( dockerCompose , config , 'drive_abci' ) ;
153- info . serviceStatus = determineStatus . platform ( info . dockerStatus , isCoreSynced ) ;
165+ info . serviceStatus = determineStatus . platform ( info . dockerStatus , isCoreSynced , mnRRSoftFork ) ;
154166
155167 if ( info . serviceStatus === ServiceStatusEnum . up ) {
156168 const driveEchoResult = await dockerCompose . execCommand (
@@ -194,6 +206,7 @@ export default function getPlatformScopeFactory(
194206 const rpcService = `${ rpcHost } :${ rpcPort } ` ;
195207
196208 const scope = {
209+ platformActivation : null ,
197210 coreIsSynced : null ,
198211 httpPort,
199212 httpService,
@@ -233,11 +246,14 @@ export default function getPlatformScopeFactory(
233246 }
234247 }
235248
249+ let coreInfo ;
250+
236251 try {
237- const coreIsSynced = await getMNSync ( config ) ;
238- scope . coreIsSynced = coreIsSynced ;
252+ coreInfo = await getCoreInfo ( config ) ;
239253
240- if ( ! coreIsSynced ) {
254+ scope . coreIsSynced = coreInfo . isSynced ;
255+
256+ if ( ! coreInfo . isSynced ) {
241257 if ( process . env . DEBUG ) {
242258 // eslint-disable-next-line no-console
243259 console . error ( 'Platform status is not available until masternode state is \'READY\'' ) ;
@@ -250,20 +266,34 @@ export default function getPlatformScopeFactory(
250266 }
251267 }
252268
253- const [ tenderdash , drive ] = await Promise . all ( [
254- getTenderdashInfo ( config , scope . coreIsSynced ) ,
255- getDriveInfo ( config , scope . coreIsSynced ) ,
256- ] ) ;
269+ if ( coreInfo ) {
270+ const { mnRRSoftFork } = coreInfo ;
257271
258- if ( tenderdash ) {
259- scope . tenderdash = tenderdash ;
272+ if ( mnRRSoftFork . active ) {
273+ scope . platformActivation = `Activated (at height ${ mnRRSoftFork . height } )` ;
274+ } else {
275+ const startTime = mnRRSoftFork . bip9 . start_time ;
260276
261- scope . httpPortState = tenderdash . httpPortState ;
262- scope . p2pPortState = tenderdash . p2pPortState ;
263- }
277+ const diff = ( new Date ( ) . getTime ( ) - startTime ) / 1000 ;
278+
279+ scope . platformActivation = `Waiting for activation (approximately in ${ prettyMs ( diff , { compact : true } ) } )` ;
280+ }
281+
282+ const [ tenderdash , drive ] = await Promise . all ( [
283+ getTenderdashInfo ( config , scope . coreIsSynced , coreInfo . mnRRSoftFork ) ,
284+ getDriveInfo ( config , scope . coreIsSynced , coreInfo . mnRRSoftFork ) ,
285+ ] ) ;
264286
265- if ( drive ) {
266- scope . drive = drive ;
287+ if ( tenderdash ) {
288+ scope . tenderdash = tenderdash ;
289+
290+ scope . httpPortState = tenderdash . httpPortState ;
291+ scope . p2pPortState = tenderdash . p2pPortState ;
292+ }
293+
294+ if ( drive ) {
295+ scope . drive = drive ;
296+ }
267297 }
268298
269299 return scope ;
0 commit comments