package Ġnet . cord a . client . j fx . model Ċ Ċ import Ġjavafx . collections . FX Collections Ċ import Ġjavafx . collections . Observable List Ċ import Ġnet . cord a . client . j fx . utils . fold Ċ import Ġnet . cord a . client . j fx . utils . map Ċ import Ġnet . cord a . contracts . asset . Cash Ċ import Ġnet . cord a . core . contracts . Contract State Ċ import Ġnet . cord a . core . contracts . State And Ref Ċ import Ġnet . cord a . core . node . services . Vault Ċ import Ġrx . Observable Ċ Ċ data Ġclass ĠDiff < out ĠT Ġ: ĠContract State >( ĊĠĠĠĠĠĠĠ Ġval Ġadded : ĠCollection < State And Ref < T >>, ĊĠĠĠĠĠĠĠ Ġval Ġremoved : ĠCollection < State And Ref < T >> Ċ ) Ċ Ċ /** Ċ Ġ* ĠThis Ġmodel Ġexposes Ġthe Ġlist Ġof Ġowned Ġcontract Ġstates . Ċ Ġ*/ Ċ class ĠContract State Model Ġ{ ĊĠĠĠ Ġprivate Ġval Ġvault Updates : ĠObservable < Vault . Update < Contract State >> Ġby Ġobservable ( Node Monitor Model :: vault Updates ) ĊĊĠĠĠ Ġprivate Ġval Ġcontract States Diff : ĠObservable < Diff < Contract State >> Ġ= Ġvault Updates . map Ġ{ ĊĠĠĠĠĠĠĠ ĠDiff ( it . pro duced , Ġit . consumed ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġprivate Ġval Ġcash States Diff : ĠObservable < Diff < Cash . State >> Ġ= Ġcontract States Diff . map Ġ{ ĊĠĠĠĠĠĠĠ ĠDiff ( it . added . filter Cash State And Refs (), Ġit . removed . filter Cash State And Refs ()) ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġcash States : ĠObservable List < State And Ref < Cash . State >> Ġ= Ġcash States Diff . fold ( FX Collections . observable ArrayList ()) Ġ{ Ġlist : ĠMutable List < State And Ref < Cash . State >>, Ġstates Diff Ġ-> ĊĠĠĠĠĠĠĠ Ġlist . remove If Ġ{ Ġit Ġin Ġstates Diff . removed Ġ} ĊĠĠĠĠĠĠĠ Ġlist . addAll ( states Diff . added ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġcash Ġ= Ġcash States . map Ġ{ Ġit . state . data . amount Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġfun ĠCollection < State And Ref < Contract State >> . filter Cash State And Refs (): ĠList < State And Ref < Cash . State >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġthis . map Ġ{ Ġstate And Ref Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( state And Ref . state . data Ġis ĠCash . State ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠKotlin Ġdoesn 't Ġun ify Ġhere Ġfor Ġsome Ġreason ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstate And Ref Ġas ĠState And Ref < Cash . State > ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}. filter NotNull () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ Ċ } Ċ