/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 - 2 0 2 1 ĠON IX Labs Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġio . on ix labs . cord a . core . workflow Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġnet . cord a . core . contracts . State And Ref Ċ import Ġnet . cord a . core . contracts . State Ref Ċ import Ġnet . cord a . core . crypto . Secure Hash Ċ import Ġnet . cord a . core . flows .* Ċ import Ġnet . cord a . core . identity . Party Ċ import Ġnet . cord a . core . node . States To Record Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . Progress Tracker . Step Ċ import Ġnet . cord a . core . utilities . unwrap Ċ Ċ /** Ċ Ġ* ĠSets Ġthe Ġcurrent Ġprogress Ġtracker Ġstep . Ċ Ġ* Ċ Ġ* Ġ@ param Ġstep ĠThe Ġprogress Ġtracker Ġstep . Ċ Ġ* Ġ@ param Ġlog ĠDetermines Ġwhether Ġto Ġlog Ġthe Ġstep . Ċ Ġ* Ġ@ param Ġadditional Log Info ĠAdditional Ġinformation Ġto Ġlog Ġwhen Ġsetting Ġthe Ġcurrent Ġstep . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. current Step ( step : ĠStep , Ġlog : ĠBoolean Ġ= Ġtrue , Ġadditional Log Info : ĠString ? Ġ= Ġnull ) Ġ{ ĊĠĠĠ Ġprogress Tracker ?. current Step Ġ= Ġstep ĊĊĠĠĠ Ġif Ġ( log ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( additional Log Info . isNull Or Blank ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . info ( step . label ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . info ("${ step . label } Ġ($ additional Log Info )") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ /** Ċ Ġ* ĠFinds Ġa Ġrecorded Ġtransaction Ġin Ġthe Ġvault Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ċ Ġ* Ġ@ param Ġtransaction Hash ĠThe Ġtransaction Ġhash Ġof Ġthe Ġtransaction Ġto Ġfind . Ċ Ġ* Ġ@ return ĠReturns Ġa Ġ[ Signed Transaction ] Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ġ@ throws ĠFlow Exception ĠIf Ġa Ġsigned ĠTransaction Ġcannot Ġbe Ġfound Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. find Transaction ( transaction Hash : ĠSecure Hash ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġreturn Ġservice Hub . validated Transactions . getTransaction ( transaction Hash ) ĊĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠFlow Exception (" Did Ġnot Ġfind Ġa Ġtransaction Ġwith Ġthe Ġspecified Ġhash : Ġ$ transaction Hash ") Ċ } Ċ Ċ /** Ċ Ġ* ĠFinds Ġa Ġrecorded Ġtransaction Ġin Ġthe Ġvault Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ċ Ġ* Ġ@ param Ġstate Ref ĠThe Ġstate Ġreference Ġof Ġthe Ġtransaction Ġto Ġfind . Ċ Ġ* Ġ@ return ĠReturns Ġa Ġ[ Signed Transaction ] Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ġ@ throws ĠFlow Exception ĠIf Ġa Ġsigned ĠTransaction Ġcannot Ġbe Ġfound Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. find Transaction ( state Ref : ĠState Ref ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġreturn Ġfind Transaction ( state Ref . tx hash ) Ċ } Ċ Ċ /** Ċ Ġ* ĠFinds Ġa Ġrecorded Ġtransaction Ġin Ġthe Ġvault Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ċ Ġ* Ġ@ param Ġstate And Ref ĠThe Ġstate Ġand Ġreference Ġof Ġthe Ġtransaction Ġto Ġfind . Ċ Ġ* Ġ@ return ĠReturns Ġa Ġ[ Signed Transaction ] Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ġ@ throws ĠFlow Exception ĠIf Ġa Ġsigned ĠTransaction Ġcannot Ġbe Ġfound Ġfor Ġthe Ġspecified Ġtransaction Ġhash . Ċ Ġ* Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. find Transaction ( state And Ref : ĠState And Ref < *> ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġreturn Ġfind Transaction ( state And Ref . ref ) Ċ } Ċ Ċ /** Ċ Ġ* ĠProvides Ġa ĠDSL - like Ġtransaction Ġbuilder . Ċ Ġ* ĠTo Ġuse Ġthis Ġfunction , Ġ[ Build Transaction Step ] Ġwill Ġneed Ġto Ġbe Ġe vid ent Ġin Ġyour Ġprogress Ġtracker . Ċ Ġ* Ċ Ġ* Ġ@ param Ġnot ary ĠThe Ġnot ary Ġwhich Ġwill Ġbe Ġapplied Ġto Ġthe Ġtransaction . Ċ Ġ* Ġ@ param Ġaction ĠThe Ġaction Ġwhich Ġwill Ġbe Ġused Ġto Ġbuild Ġthe Ġtransaction . Ċ Ġ* Ġ@ return ĠReturns Ġa Ġ[ Transaction Builder ] Ġrepresenting Ġthe Ġbuilt Ġtransaction . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. build Transaction ( not ary : ĠParty , Ġaction : ĠTransaction Builder . () Ġ-> ĠUnit ): ĠTransaction Builder Ġ{ ĊĠĠĠ Ġcurrent Step ( Build Transaction Step ) ĊĠĠĠ Ġval Ġtransaction Builder Ġ= ĠTransaction Builder ( not ary ) ĊĠĠĠ Ġaction ( transaction Builder ) ĊĠĠĠ Ġreturn Ġtransaction Builder Ċ } Ċ Ċ /** Ċ Ġ* ĠVerifies Ġa Ġtransaction . Ċ Ġ* ĠTo Ġuse Ġthis Ġfunction , Ġ[ Verify Transaction Step ] Ġwill Ġneed Ġto Ġbe Ġe vid ent Ġin Ġyour Ġprogress Ġtracker . Ċ Ġ* Ċ Ġ* Ġ@ param Ġtransaction ĠThe Ġtransaction Ġto Ġverify . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. verify Transaction ( transaction : ĠTransaction Builder ) Ġ{ ĊĠĠĠ Ġcurrent Step ( Verify Transaction Step ) ĊĠĠĠ Ġtransaction . verify ( service Hub ) Ċ } Ċ Ċ /** Ċ Ġ* ĠSign s Ġa Ġtransaction . Ċ Ġ* ĠTo Ġuse Ġthis Ġfunction , Ġ[ Sign Transaction Step ] Ġwill Ġneed Ġto Ġbe Ġe vid ent Ġin Ġyour Ġprogress Ġtracker . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. sign Transaction ( transaction : ĠTransaction Builder ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġcurrent Step ( Sign Transaction Step ) ĊĠĠĠ Ġval Ġour Signing Keys Ġ= Ġtransaction . get Our Signing Keys ( service Hub . key Management Service ) ĊĠĠĠ Ġreturn Ġservice Hub . sign Initial Transaction ( transaction , Ġour Signing Keys ) Ċ } Ċ Ċ /** Ċ Ġ* ĠCollect s Ġall Ġremaining Ġrequired Ġsignatures Ġfrom Ġthe Ġspecified Ġcounter - part ies . Ċ Ġ* ĠTo Ġuse Ġthis Ġfunction , Ġ[ Collect Transaction Signatures Step ] Ġwill Ġneed Ġto Ġbe Ġe vid ent Ġin Ġyour Ġprogress Ġtracker . Ċ Ġ* Ċ Ġ* ĠDue Ġto Ġthe Ġway Ġthis Ġfunction Ġworks , Ġit Ġis Ġintended Ġto Ġbe Ġpaired Ġwith Ġ[ collect Signatures Handler ] Ġin Ġthe Ġcounter - flow . Ċ Ġ* ĠThis Ġfunction Ġwill Ġfilter Ġout Ġall Ġrequired Ġsigning Ġsessions Ġfrom Ġthe Ġsessions Ġprovided , Ġand Ġwill Ġthen Ġnotify Ġall Ċ Ġ* Ġsessions Ġwhether Ġthey Ġare Ġrequired Ġto Ġsign Ġor Ġnot . ĠFor Ġthose Ġsessions Ġrequired Ġto Ġsign , Ġit Ġwill Ġcollect Ġtheir Ġsignature . Ċ Ġ* Ċ Ġ* Ġ@ param Ġtransaction ĠThe Ġtransaction Ġfor Ġwhich Ġto Ġcollect Ġremaining Ġsignatures Ġfrom Ġthe Ġspecified Ġcounter - part ies . Ċ Ġ* Ġ@ param Ġsessions ĠAll Ġflow Ġsessions Ġthat Ġhave Ġbeen Ġpassed Ġto Ġthis Ġflow . Ċ Ġ* Ġ@ param Ġadditional Signing Action ĠAllows Ġadditional Ġsigning Ġactions Ġto Ġbe Ġspecified . ĠThis Ġwill Ġbe Ġexecuted Ġafter Ġall Ġother Ġactivity Ġin Ġthis Ġflow . Ċ Ġ* Ġ@ return ĠReturns Ġa Ġtransaction Ġwhich Ġshould Ġbe Ġsigned Ġby Ġall Ġrequired Ġsign ers . Ċ Ġ* Ġ@ throws ĠFlow Exception Ġif Ġthe Ġlocal Ġnode Ġhas Ġbeen Ġpassed Ġto Ġthis Ġfunction Ġas Ġa Ġcounter - party Ġor Ġin Ġa Ġflow Ġsession . Ċ Ġ*/ Ċ @ Suspend able Ċ inline Ġfun ĠFlow Logic <* >. collect Signatures ( ĊĠĠĠ Ġtransaction : ĠSigned Transaction , ĊĠĠĠ Ġsessions : ĠIterable < Flow Session >, ĊĠĠĠ Ġadditional Signing Action : Ġ(( Signed Transaction ) Ġ-> ĠSigned Transaction ) Ġ= Ġ{ Ġit Ġ} Ċ ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġcurrent Step ( Collect Transaction Signatures Step ) ĊĠĠĠ Ġval Ġmissing Signing Keys Ġ= Ġtransaction . get Missing Sign ers () ĊĊĠĠĠ Ġval Ġsigning Sessions Ġ= Ġsessions . filter Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( it . counter party Ġin Ġservice Hub . my Info . legal Id entities ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠFlow Exception (" Do Ġnot Ġpass Ġflow Ġsessions Ġfor Ġthe Ġlocal Ġnode .") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit . counter party . own ing Key Ġin Ġmissing Signing Keys ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsessions . forEach Ġ{ Ġit . send ( it Ġin Ġsigning Sessions ) Ġ} ĊĊĠĠĠ Ġval Ġsigned Transaction Ġ= Ġif Ġ( signing Sessions . isEmpty ()) Ġtransaction Ġelse Ġsub Flow ( ĊĠĠĠĠĠĠĠ ĠCollect Signatures Flow ( transaction , Ġsigning Sessions , ĠCollect Transaction Signatures Step . child Progress Tracker ()) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġreturn Ġadditional Signing Action ( signed Transaction ) Ċ } Ċ Ċ /** Ċ Ġ* ĠSign s Ġa Ġtransaction . Ċ Ġ* ĠTo Ġuse Ġthis Ġfunction , Ġ[ Sign Transaction Step ] Ġwill Ġneed Ġto Ġbe Ġe vid ent Ġin Ġyour Ġprogress Ġtracker . Ċ Ġ* ĠDue Ġto Ġthe Ġway Ġthis Ġfunction Ġworks , Ġit Ġis Ġintended Ġto Ġbe Ġpaired Ġwith Ġ[ collect Signatures ] Ġin Ġthe Ġiniti ating Ġflow . Ċ Ġ* Ċ Ġ* Ġ@ param Ġsession ĠThe Ġflow Ġsession Ġof Ġthe Ġiniti ating Ġflow Ġthat Ġis Ġrequesting Ġa Ġtransaction Ġsignature . Ċ Ġ* Ġ@ param Ġaction ĠAllows Ġcustom Ġtransaction Ġchecks Ġto Ġbe Ġperformed Ġbefore Ġthe Ġtransaction Ġis Ġsigned . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. collect Signatures Handler ( ĊĠĠĠ Ġsession : ĠFlow Session , ĊĠĠĠ Ġaction : Ġ( Signed Transaction ) Ġ-> ĠUnit Ġ= Ġ{} Ċ ): ĠSigned Transaction ? Ġ{ ĊĠĠĠ Ġval Ġis Required To Sign Ġ= Ġsession . receive < Boolean >(). unwrap Ġ{ Ġit Ġ} ĊĠĠĠ Ġreturn Ġif Ġ( isRequired To Sign ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcurrent Step ( Sign Transaction Step ) ĊĠĠĠĠĠĠĠ Ġsub Flow ( object Ġ: ĠSign Transaction Flow ( session , ĠSign Transaction Step . child Progress Tracker ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcheck Transaction ( st x : ĠSigned Transaction ) Ġ= Ġaction ( st x ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} Ġelse Ġnull Ċ } Ċ Ċ /** Ċ Ġ* ĠFinal izes Ġa Ġtransaction . Ċ Ġ* ĠTo Ġuse Ġthis Ġfunction , Ġ[ Send States To Record Step ] Ġand Ġ[ Finalize Transaction Step ] Ġwill Ġneed Ġto Ġbe Ġe vid ent Ġin Ġyour Ġprogress Ġtracker . Ċ Ġ* Ċ Ġ* ĠThis Ġfunction Ġallows Ġthe Ġinit iator Ġto Ġspecify Ġhow Ġcounter - part ies Ġshould Ġrecord Ġstates Ġof Ġthe Ġfinal ized Ġtransaction . Ċ Ġ* ĠFor Ġeach Ġsession Ġof Ġthe Ġ[ states To Record By Session ] Ġobject , Ġthe Ġcounter - party Ġwill Ġreceive Ġtheir Ġ[ States To Record ] Ċ Ġ* Ġenumeration , Ġunless Ġthey Ġhave Ġspecified Ġan Ġoverride Ġvia Ġthe Ġ[ finalize Transaction Handler ] Ġfunction . ĠFinally Ġthey Ċ Ġ* Ġwill Ġrecord Ġthe Ġfinal ized Ġtransaction . Ċ Ġ* Ċ Ġ* Ġ@ param Ġtransaction ĠThe Ġtransaction Ġto Ġfinalize Ġand Ġrecord . Ċ Ġ* Ġ@ param Ġstates To Record By Session ĠDetermines Ġhow Ġcounter - part ies Ġshould Ġrecord Ġstates Ġin Ġthe Ġtransaction . Ċ Ġ* Ġ@ param Ġour States To Record ĠDetermines Ġhow Ġour Ġnode Ġshould Ġrecord Ġstates Ġin Ġthe Ġtransaction . Ċ Ġ* Ġ@ return ĠReturns Ġa Ġfully Ġsigned , Ġfinal ized Ġand Ġrecorded Ġtransaction . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. finalize Transaction ( ĊĠĠĠ Ġtransaction : ĠSigned Transaction , ĊĠĠĠ Ġstates To Record By Session : ĠStates To Record By Session , ĊĠĠĠ Ġour States To Record : ĠStates To Record Ġ= ĠStates To Record . ONLY _ RE LE V ANT Ċ ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġreturn Ġstates To Record By Session . finalize Transaction ( transaction , Ġthis , Ġour States To Record ) Ċ } Ċ Ċ /** Ċ Ġ* ĠFinal izes Ġa Ġtransaction . Ċ Ġ* ĠTo Ġuse Ġthis Ġfunction , Ġ[ Send States To Record Step ] Ġand Ġ[ Finalize Transaction Step ] Ġwill Ġneed Ġto Ġbe Ġe vid ent Ġin Ġyour Ġprogress Ġtracker . Ċ Ġ* ĠIf Ġyour Ġflow Ġonly Ġupdates Ġa Ġtransaction Ġlocally , Ġyou Ġcan Ġomit Ġ[ Send States To Record Step ] Ġfrom Ġyour Ġprogress Ġtracker . Ċ Ġ* Ċ Ġ* ĠThis Ġfunction Ġallows Ġthe Ġinit iator Ġto Ġspecify Ġhow Ġcounter - part ies Ġshould Ġrecord Ġstates Ġof Ġthe Ġfinal ized Ġtransaction . Ċ Ġ* ĠEach Ġsession Ġwill Ġrecord Ġthe Ġtransaction Ġstates Ġaccording Ġto Ġthe Ġ[ counter party States To Record ] Ġparameter , Ġunless Ġthey Ċ Ġ* Ġhave Ġspecified Ġan Ġoverride Ġvia Ġthe Ġ[ finalize Transaction Handler ] Ġfunction . ĠFinally Ġthey Ġwill Ġrecord Ġthe Ġfinal ized Ġtransaction . Ċ Ġ* Ċ Ġ* Ġ@ param Ġtransaction ĠThe Ġtransaction Ġto Ġbe Ġfinal ized . Ċ Ġ* Ġ@ param Ġsessions ĠThe Ġsessions Ġfor Ġall Ġcounter - part ies Ġand Ġob servers Ġwhere Ġthis Ġtransaction Ġshould Ġbe Ġrecorded . Ċ Ġ* Ġ@ param Ġcounter party States To Record ĠDetermines Ġhow Ġcounter - part ies Ġshould Ġrecord Ġstates Ġin Ġthe Ġtransaction . Ċ Ġ* Ġ@ param Ġour States To Record ĠDetermines Ġhow Ġour Ġnode Ġshould Ġrecord Ġstates Ġin Ġthe Ġtransaction . Ċ Ġ* Ġ@ return ĠReturns Ġa Ġfully Ġsigned , Ġfinal ized Ġand Ġrecorded Ġtransaction . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. finalize Transaction ( ĊĠĠĠ Ġtransaction : ĠSigned Transaction , ĊĠĠĠ Ġsessions : ĠIterable < Flow Session > Ġ= Ġempty List (), ĊĠĠĠ Ġcounter party States To Record : ĠStates To Record Ġ= ĠStates To Record . ONLY _ RE LE V ANT , ĊĠĠĠ Ġour States To Record : ĠStates To Record Ġ= ĠStates To Record . ONLY _ RE LE V ANT Ċ ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġval Ġstates To Record By Session Ġ= ĠStates To Record By Session ( sessions , Ġcounter party States To Record ) ĊĠĠĠ Ġreturn Ġfinalize Transaction ( transaction , Ġstates To Record By Session , Ġour States To Record ) Ċ } Ċ Ċ /** Ċ Ġ* ĠFinal izes Ġa Ġtransaction . Ċ Ġ* ĠTo Ġuse Ġthis Ġfunction , Ġ[ Receive States To Record Step ] Ġand Ġ[ Record Final ized Transaction Step ] Ġwill Ġneed Ġto Ġbe Ġe vid ent Ġin Ġyour Ġprogress Ġtracker . Ċ Ġ* Ċ Ġ* ĠThis Ġfunction Ġwill Ġfirst Ġreceive Ġthe Ġ[ States To Record ] Ġfrom Ġthe Ġiniti ating Ġnode , Ġhowever Ġthis Ġcan Ġbe Ġoverridden Ġusing Ċ Ġ* Ġthe Ġ[ states To Record ] Ġparameter . ĠFinally Ġthe Ġtransaction Ġwill Ġbe Ġreceived Ġand Ġrecorded . Ċ Ġ* Ċ Ġ* Ġ@ param Ġsession ĠThe Ġflow Ġsession Ġof Ġthe Ġiniti ating Ġflow Ġthat Ġis Ġrequesting Ġthe Ġtransaction Ġto Ġbe Ġfinal ized . Ċ Ġ* Ġ@ param Ġexpected Transaction Id ĠThe Ġexpected Ġtransaction ĠID Ġof Ġthe Ġtransaction Ġto Ġbe Ġrecorded . Ċ Ġ* Ġ@ param Ġstates To Record ĠDetermines Ġwhich Ġstates Ġfrom Ġthe Ġtransaction Ġshould Ġbe Ġrecorded . Ċ Ġ* Ġ@ return ĠReturns Ġa Ġfully Ġsigned , Ġfinal ized Ġand Ġrecorded Ġtransaction . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. finalize Transaction Handler ( ĊĠĠĠ Ġsession : ĠFlow Session , ĊĠĠĠ Ġexpected Transaction Id : ĠSecure Hash ? Ġ= Ġnull , ĊĠĠĠ Ġstates To Record : ĠStates To Record ? Ġ= Ġnull Ċ ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġcurrent Step ( Receive States To Record Step ) ĊĠĠĠ Ġval Ġreceived States To Record Ġ= Ġsession . receive < String >(). unwrap Ġ{ ĠStates To Record . valueOf ( it ) Ġ} ĊĠĠĠ Ġval Ġour States To Record Ġ= Ġstates To Record Ġ?: Ġreceived States To Record ĊĊĠĠĠ Ġcurrent Step ( Record Final ized Transaction Step ) ĊĠĠĠ Ġreturn Ġsub Flow ( Receive Final ity Flow ( session , Ġexpected Transaction Id , Ġour States To Record )) Ċ } Ċ Ċ /** Ċ Ġ* ĠPub lishes Ġa Ġ[ Signed Transaction ] Ġto Ġthe Ġspecified Ġflow Ġsessions . Ċ Ġ* Ċ Ġ* Ġ@ param Ġtransaction ĠThe Ġsigned Ġtransaction Ġto Ġpublish . Ċ Ġ* Ġ@ param Ġsessions ĠThe Ġsessions Ġwhere Ġthe Ġsigned Ġtransaction Ġshould Ġbe Ġpublished . Ċ Ġ* Ġ@ param Ġprogress Tracker Step ĠThe Ġprogress Ġtracker Ġstep Ġto Ġset Ġbefore Ġpublishing Ġthe Ġtransaction . Ċ Ġ* Ġ@ return ĠReturns Ġthe Ġpublished Ġ[ Signed Transaction ]. Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. publish Transaction ( ĊĠĠĠ Ġtransaction : ĠSigned Transaction , ĊĠĠĠ Ġsessions : ĠSet < Flow Session >, ĊĠĠĠ Ġprogress Tracker Step : ĠStep Ġ= ĠSend Transaction Step Ċ ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġcurrent Step ( progress Tracker Step ) ĊĠĠĠ Ġsessions . forEach Ġ{ Ġsub Flow ( Send Transaction Flow ( it , Ġtransaction )) Ġ} ĊĠĠĠ Ġreturn Ġtransaction Ċ } Ċ Ċ /** Ċ Ġ* ĠHandles Ġand Ġrecords Ġa Ġpublished Ġ[ Signed Transaction ]. Ċ Ġ* Ċ Ġ* Ġ@ param Ġsession ĠThe Ġsession Ġwhere Ġthe Ġsigned Ġtransaction Ġwas Ġpublished Ġfrom . Ċ Ġ* Ġ@ param Ġstates To Record ĠDetermines Ġwhich Ġstates Ġto Ġrecord Ġfrom Ġthe Ġsigned Ġtransaction . Ċ Ġ* Ġ@ param Ġcheck S ufficient Signatures ĠDetermines Ġwhether Ġto Ġcheck Ġif Ġthe Ġsigned Ġtransaction Ġhas Ġbeen Ġsufficient ly Ġsigned . Ċ Ġ* Ġ@ param Ġprogress Tracker Step ĠThe Ġprogress Ġtracker Ġstep Ġto Ġset Ġbefore Ġrecording Ġthe Ġpublished Ġthe Ġtransaction . Ċ Ġ* Ġ@ return ĠReturns Ġthe Ġpublished Ġ[ Signed Transaction ]. Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. publish Transaction Handler ( ĊĠĠĠ Ġsession : ĠFlow Session , ĊĠĠĠ Ġstates To Record : ĠStates To Record Ġ= ĠStates To Record . ALL _ VISIBLE , ĊĠĠĠ Ġcheck S ufficient Signatures : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġprogress Tracker Step : ĠStep Ġ= ĠReceive Transaction Step Ċ ): ĠSigned Transaction Ġ{ ĊĠĠĠ Ġcurrent Step ( progress Tracker Step ) ĊĠĠĠ Ġreturn Ġsub Flow ( Receive Transaction Flow ( session , Ġcheck S ufficient Signatures , Ġstates To Record )) Ċ } Ċ