package Ġjp . co . sor am its u . runtime Ċ Ċ import Ġjp . co . sor am its u . common . utils . Suspend able Property Ċ import Ġjp . co . sor am its u . core . updater . Global Scope Updater Ċ import Ġjp . co . sor am its u . core . updater . Subscription Builder Ċ import Ġjp . co . sor am its u . core . updater . Updater Ċ import Ġjp . co . sor am its u . fe ar less _ utils . runtime . Runtime Snapshot Ċ import Ġjp . co . sor am its u . fe ar less _ utils . ws rpc . Socket Service Ċ import Ġjp . co . sor am its u . fe ar less _ utils . ws rpc . request . runtime . chain . runtime Version Change Ċ import Ġjp . co . sor am its u . fe ar less _ utils . ws rpc . subscription Flow Ċ import Ġjp . co . sor am its u . feature _ account _ api . domain . interfaces . Account Repository Ċ import Ġjp . co . sor am its u . runtime . ext . runtime Cache Name Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . flow . Flow Ċ import Ġkotlinx . coroutines . flow . catch Ċ import Ġkotlinx . coroutines . flow . distinct Until Changed Ċ import Ġkotlinx . coroutines . flow . flow On Ċ import Ġkotlinx . coroutines . flow . map Ċ Ċ type alias ĠRuntime Update Retry Ġ= Ġsuspend Ġ() Ġ-> ĠRuntime Pre paration Status Ċ Ċ sealed Ġclass ĠRuntime Pre paration Status Ġ: ĠUp dater . Side Effect Ġ{ ĊĠĠĠ Ġobject ĠOk Ġ: ĠRuntime Pre paration Status () ĊĊĠĠĠ Ġobject ĠOut dated Ġ: ĠRuntime Pre paration Status () ĊĊĠĠĠ Ġclass ĠError ( val Ġretry : ĠRuntime Update Retry ) Ġ: ĠRuntime Pre paration Status () Ċ } Ċ Ċ class ĠRuntime Updater ( ĊĠĠĠ Ġprivate Ġval Ġruntime Constructor : ĠRuntime Constructor , ĊĠĠĠ Ġprivate Ġval Ġsocket Service : ĠSocket Service , ĊĠĠĠ Ġprivate Ġval Ġaccount Repository : ĠAccount Repository , ĊĠĠĠ Ġprivate Ġval Ġruntime Pre pop ulator : ĠRuntime Pre pop ulator , ĊĠĠĠ Ġprivate Ġval Ġruntime Property : ĠS uspend able Property < Runtime Snapshot > Ċ ) Ġ: ĠGlobal Scope Updater Ġ{ ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġlisten For Updates ( ĊĠĠĠĠĠĠĠ Ġstorage Subscription Builder : ĠSubscription Builder ĊĠĠĠ Ġ): ĠFlow < Runtime Pre paration Status > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġsocket Service . subscription Flow ( Subscribe Runtime Version Request ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . runtime Version Change (). spec Version Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. distinct Until Changed () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġperform Update ( it ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. catch Ġ{ Ġemit ( error Status ()) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. flow On ( Dispatch ers . Default ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġinit From Cache () Ġ{ ĊĠĠĠĠĠĠĠ Ġruntime Property . invalidate () ĊĊĠĠĠĠĠĠĠ Ġruntime Pre pop ulator . maybe Pre populate Cache () ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrun Catch ing Ġ{ Ġruntime Constructor . construct From Cache ( getCurrent Network Name ()) Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġruntime Ġ= Ġresult . get OrNull () Ġ?: Ġreturn ĊĊĠĠĠĠĠĠĠ Ġruntime Property . set ( runtime ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// Ġcannot Ġuse Ġdefault Ġparameter Ġbecause Ġof Ġthe Ġbug Ġin Ġthe Ġcompiler Ġ( https :// yout rack . jetbrains . com / issue / KT - 4 4 8 4 9 ) ĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġperform Update () Ġ= Ġperform Update ( null ) ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġperform Update ( new Runtime Version : ĠInt ?) Ġ= Ġtry Ġ{ ĊĠĠĠĠĠĠĠ Ġruntime Property . invalidate () ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġif Ġ( new Runtime Version Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġruntime Constructor . construct Runtime ( new Runtime Version , ĠgetCurrent Network Name ()) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġruntime Constructor . construct Runtime ( getCurrent Network Name ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġruntime Property . set ( result . runtime ) ĊĊĠĠĠĠĠĠĠ Ġget Pre paration Status ( result ) ĊĠĠĠ Ġ} Ġcatch Ġ(_ : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠ Ġerror Status () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġerror Status (): ĠRuntime Pre paration Status . Error Ġ= ĠRuntime Pre paration Status . Error (:: perform Update ) ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun ĠgetCurrent Network Name (): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnetwork Type Ġ= Ġaccount Repository . getSelected Node (). network Type ĊĊĠĠĠĠĠĠĠ Ġreturn Ġnetwork Type . runtime Cache Name () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Pre paration Status ( construct ed : ĠRuntime Constructor . Construct ed ) Ġ= Ġif Ġ( construct ed . isNew est ) Ġ{ ĊĠĠĠĠĠĠĠ ĠRuntime Pre paration Status . Ok ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ ĠRuntime Pre paration Status . Out dated ĊĠĠĠ Ġ} Ċ }