package Ġjp . co . sor am its u . runtime . multi Network Ċ Ċ import Ġjp . co . sor am its u . common . utils . diff ed Ċ import Ġjp . co . sor am its u . common . utils . in Background Ċ import Ġjp . co . sor am its u . common . utils . map List Ċ import Ġjp . co . sor am its u . core _ db . dao . Chain Dao Ċ import Ġjp . co . sor am its u . core _ db . model . chain . Chain Node Local Ċ import Ġjp . co . sor am its u . fe ar less _ utils . runtime . Runtime Snapshot Ċ import Ġjp . co . sor am its u . runtime . multi Network . chain . Chain Sync Service Ċ import Ġjp . co . sor am its u . runtime . multi Network . chain . map Chain Local To Chain Ċ import Ġjp . co . sor am its u . runtime . multi Network . chain . map Node Local To Node Ċ import Ġjp . co . sor am its u . runtime . multi Network . chain . model . Chain Ċ import Ġjp . co . sor am its u . runtime . multi Network . chain . model . Chain Id Ċ import Ġjp . co . sor am its u . runtime . multi Network . chain . model . NodeId Ċ import Ġjp . co . sor am its u . runtime . multi Network . connection . Chain Connection Ċ import Ġjp . co . sor am its u . runtime . multi Network . connection . Connection Pool Ċ import Ġjp . co . sor am its u . runtime . multi Network . runtime . Runtime Provider Ċ import Ġjp . co . sor am its u . runtime . multi Network . runtime . Runtime Provider Pool Ċ import Ġjp . co . sor am its u . runtime . multi Network . runtime . Runtime Subscription Pool Ċ import Ġjp . co . sor am its u . runtime . multi Network . runtime . Runtime Sync Service Ċ import Ġjp . co . sor am its u . runtime . multi Network . runtime . types . BaseType Synchron izer Ċ import Ġkotlinx . coroutines . Coroutine Scope Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . flow . Sharing Started Ċ import Ġkotlinx . coroutines . flow . distinct Until Changed Ċ import Ġkotlinx . coroutines . flow . filter Ċ import Ġkotlinx . coroutines . flow . first Ċ import Ġkotlinx . coroutines . flow . map Ċ import Ġkotlinx . coroutines . flow . share In Ċ import Ġkotlinx . coroutines . launch Ċ Ċ data Ġclass ĠChain Service ( ĊĠĠĠ Ġval Ġruntime Provider : ĠRuntime Provider , ĊĠĠĠ Ġval Ġconnection : ĠChain Connection Ċ ) Ċ Ċ class ĠChain Registry ( ĊĠĠĠ Ġprivate Ġval Ġruntime Provider Pool : ĠRuntime Provider Pool , ĊĠĠĠ Ġprivate Ġval Ġconnection Pool : ĠConnection Pool , ĊĠĠĠ Ġprivate Ġval Ġruntime Subscription Pool : ĠRuntime Subscription Pool , ĊĠĠĠ Ġprivate Ġval Ġchain Dao : ĠChain Dao , ĊĠĠĠ Ġprivate Ġval Ġchain Sync Service : ĠChain Sync Service , ĊĠĠĠ Ġprivate Ġval Ġbase Type Synchron izer : ĠBase Type Synchron izer , ĊĠĠĠ Ġprivate Ġval Ġruntime Sync Service : ĠRuntime Sync Service , Ċ ) Ġ: ĠCor outine Scope Ġby ĠCor outine Scope ( Dispatch ers . Default ) Ġ{ ĊĊĠĠĠ Ġval Ġcurrent Ch ains Ġ= Ġchain Dao . join Chain Info Flow () ĊĠĠĠĠĠĠĠ Ġ. map List (:: map Chain Local To Chain ) ĊĠĠĠĠĠĠĠ Ġ. diff ed () ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġ( removed , Ġadded Or Modified , Ġall ) Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġremoved . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġchain Id Ġ= Ġit . id ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġruntime Provider Pool . remove Runtime Provider ( chain Id ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġruntime Subscription Pool . remove Subscription ( chain Id ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġruntime Sync Service . unregister Chain ( chain Id ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġconnection Pool . remove Connection ( chain Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġadded Or Modified . forEach Ġ{ Ġchain Ġ-> ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġconnection Ġ= Ġconnection Pool . setup Connection ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġchain , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġon Selected Node Change Ġ= Ġ{ Ġchain Id , ĠnewNode Url Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlaunch Ġ{ Ġselect Node ( NodeId ( chain Id Ġto ĠnewNode Url )) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġruntime Provider Pool . setup Runtime Provider ( chain ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġruntime Sync Service . register Chain ( chain , Ġconnection ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġruntime Subscription Pool . setup Runtime Subscription ( chain , Ġconnection ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġall ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . isNotEmpty () Ġ} ĊĠĠĠĠĠĠĠ Ġ. distinct Until Changed () ĊĠĠĠĠĠĠĠ Ġ. in Background () ĊĠĠĠĠĠĠĠ Ġ. share In ( this , ĠSh aring Started . E ager ly , Ġreplay Ġ= Ġ 1 ) ĊĊĠĠĠ Ġval Ġchains ById Ġ= Ġcurrent Ch ains . map Ġ{ Ġchains Ġ-> Ġchains . associate By Ġ{ Ġit . id Ġ} Ġ} ĊĠĠĠĠĠĠĠ Ġ. in Background () ĊĠĠĠĠĠĠĠ Ġ. share In ( this , ĠSh aring Started . E ager ly , Ġreplay Ġ= Ġ 1 ) ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġlaunch Ġ{ Ġchain Sync Service . sync Up () Ġ} ĊĊĠĠĠĠĠĠĠ Ġbase Type Synchron izer . sync () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Connection ( chain Id : ĠString ) Ġ= Ġconnection Pool . getConnection ( chain Id ) ĊĊĠĠĠ Ġfun Ġget Runtime Provider ( chain Id : ĠString ): ĠRuntime Provider Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġruntime Provider Pool . get Runtime Provider ( chain Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Asset ( chain Id : ĠChain Id , Ġchain Asset Id : ĠString ) Ġ= Ġchains ById . replay Cache . last OrNull ()?. get ( chain Id )?. assets ?. first OrNull Ġ{ ĊĠĠĠĠĠĠĠ Ġit . id Ġ== Ġchain Asset Id ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġget Chain ( chain Id : ĠChain Id ) Ġ= Ġchains ById . first (). getValue ( chain Id ) ĊĊĠĠĠ Ġfun Ġnodes Flow ( chain Id : ĠString ) Ġ= Ġchain Dao . nodes Flow ( chain Id ) ĊĠĠĠĠĠĠĠ Ġ. map List (:: map Node Local To Node ) ĊĊĠĠĠ Ġsuspend Ġfun Ġselect Node ( id : ĠNode Id ) Ġ= Ġchain Dao . select Node ( id . chain Id , Ġid . node Url ) ĊĊĠĠĠ Ġsuspend Ġfun Ġadd Node ( chain Id : ĠChain Id , ĠnodeName : ĠString , Ġnode Url : ĠString ) Ġ= ĊĠĠĠĠĠĠĠ Ġchain Dao . insert Chain Node ( Chain Node Local ( chain Id , Ġnode Url , ĠnodeName , ĠisActive Ġ= Ġfalse , Ġis Default Ġ= Ġfalse )) ĊĊĠĠĠ Ġsuspend Ġfun Ġdelete Node ( id : ĠNode Id ) Ġ= Ġchain Dao . delete Node ( id . chain Id , Ġid . node Url ) ĊĊĠĠĠ Ġsuspend Ġfun ĠgetNode ( id : ĠNode Id ) Ġ= Ġmap Node Local To Node ( chain Dao . getNode ( id . chain Id , Ġid . node Url )) ĊĊĠĠĠ Ġsuspend Ġfun Ġupdate Node ( id : ĠNode Id , Ġname : ĠString , Ġurl : ĠString ) Ġ= Ġchain Dao . update Node ( id . chain Id , Ġid . node Url , Ġname , Ġurl ) Ċ } Ċ Ċ suspend Ġfun ĠChain Registry . chain With Asset ( chain Id : ĠChain Id , Ġasset Id : ĠString ): ĠPair < Chain , ĠChain . Asset > Ġ{ ĊĠĠĠ Ġval Ġchain Ġ= Ġchains ById . first (). getValue ( chain Id ) ĊĊĠĠĠ Ġreturn Ġchain Ġto Ġchain . assets ById . getValue ( asset Id ) Ċ } Ċ Ċ suspend Ġfun ĠChain Registry . get Runtime ( chain Id : ĠChain Id ): ĠRuntime Snapshot Ġ{ ĊĠĠĠ Ġreturn Ġget Runtime Provider ( chain Id ). get () Ċ } Ċ Ċ suspend Ġfun ĠChain Registry . get Socket ( chain Id : ĠChain Id ) Ġ= Ġget Connection ( chain Id ). socket Service Ċ Ċ fun ĠChain Registry . getService ( chain Id : ĠChain Id ) Ġ= ĠChain Service ( ĊĠĠĠ Ġruntime Provider Ġ= Ġget Runtime Provider ( chain Id ), ĊĠĠĠ Ġconnection Ġ= Ġget Connection ( chain Id ) Ċ ) Ċ