package Ġnet . cord a . finance . flows Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġnet . cord a . core . contracts . Amount Ċ import Ġnet . cord a . core . contracts . Ins ufficient Balance Exception Ċ import Ġnet . cord a . core . flows .* Ċ import Ġnet . cord a . core . node . services . query By Ċ import Ġnet . cord a . core . node . services . vault . DEFAULT _ PAGE _ NUM Ċ import Ġnet . cord a . core . node . services . vault . Page Specification Ċ import Ġnet . cord a . core . node . services . vault . Query Criteria . Vault Query Criteria Ċ import Ġnet . cord a . core . serialization . C ord a Serializable Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . Opaque Bytes Ċ import Ġnet . cord a . core . utilities . Progress Tracker Ċ import Ġnet . cord a . finance . contracts . asset . Cash Ċ import Ġnet . cord a . finance . contracts . asset . Abstract Cash Selection Ċ import Ġnet . cord a . finance . flows . Abstract Cash Flow . Companion . FINAL ISING _ TX Ċ import Ġnet . cord a . finance . flows . Abstract Cash Flow . Companion . GENER ATING _ TX Ċ import Ġnet . cord a . finance . flows . Abstract Cash Flow . Companion . SIGN ING _ TX Ċ import Ġnet . cord a . finance . iss ued By Ċ import Ġjava . util .* Ċ Ċ /** Ċ Ġ* ĠInit i ates Ġa Ġflow Ġthat Ġproduces Ġan Ġcash Ġexit Ġtransaction . Ċ Ġ* Ċ Ġ* Ġ@ param Ġamount Ġthe Ġamount Ġof Ġa Ġcurrency Ġto Ġremove Ġfrom Ġthe Ġledger . Ċ Ġ* Ġ@ param Ġissuer Ref Ġthe Ġreference Ġon Ġthe Ġissued Ġcurrency . ĠAdded Ġto Ġthe Ġnode 's Ġlegal Ġidentity Ġto Ġdetermine Ġthe Ċ Ġ* Ġissuer . Ċ Ġ*/ Ċ @ Initi ating Flow Ċ @ Start able By RPC Ċ class ĠCash Exit Flow ( private Ġval Ġamount : ĠAmount < Currency >, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġissuer Ref : ĠO pa que Bytes , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprogress Tracker : ĠProgress Tracker ) Ġ: ĠAbstract Cash Flow < Abstract Cash Flow . Result >( progress Tracker ) Ġ{ ĊĠĠĠ Ġconstructor ( amount : ĠAmount < Currency >, Ġissuer Ref : ĠO pa que Bytes ) Ġ: Ġthis ( amount , Ġissuer Ref , Ġtracker ()) ĊĠĠĠ Ġconstructor ( request : ĠExit Request ) Ġ: Ġthis ( request . amount , Ġrequest . issuer Ref , Ġtracker ()) ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġtracker () Ġ= ĠProgress Tracker ( GENER ATING _ TX , ĠSIGN ING _ TX , ĠFIN AL ISING _ TX ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* Ġ@ return Ġthe Ġsigned Ġtransaction , Ġand Ġa Ġmapping Ġof Ġparties Ġto Ġnew Ġanonymous Ġident ities Ġgenerated ĊĠĠĠĠ Ġ* Ġ( for Ġthis Ġflow Ġthis Ġmap Ġis Ġalways Ġempty ). ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġ@ Throws ( Cash Exception :: class ) ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠAbstract Cash Flow . Result Ġ{ ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠGENER ATING _ TX ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠTransaction Builder ( not ary Ġ= Ġnull ) ĊĠĠĠĠĠĠĠ Ġval Ġissuer Ġ= Ġour Identity . ref ( issuer Ref ) ĊĠĠĠĠĠĠĠ Ġval Ġexit States Ġ= ĠAbstract Cash Selection ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. getInstance Ġ{ Ġservice Hub . jdbc Session (). metaData Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. un consumed Cash States For S pending ( service Hub , Ġamount , Ġset Of ( issuer . party ), Ġbuilder . not ary , Ġbuilder . lock Id , Ġset Of ( issuer . reference )) ĊĠĠĠĠĠĠĠ Ġval Ġsign ers Ġ= Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġchange Owner Ġ= Ġexit States . as Sequence (). map Ġ{ Ġit . state . data . owner Ġ}. toSet (). first OrNull () Ġ?: Ġthrow ĠIns ufficient Balance Exception ( amount ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCash (). generate Exit ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġbuilder , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġamount . iss ued By ( issuer ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġexit States , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġchange Owner ) ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( e : ĠIns ufficient Balance Exception ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠCash Exception (" Exit ing Ġmore Ġcash Ġthan Ġexists ", Ġe ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// ĠWork Ġout Ġwho Ġthe Ġowners Ġof Ġthe Ġburn t Ġstates Ġwere Ġ( specify Ġpage Ġsize Ġso Ġwe Ġdon 't Ġsilently Ġdrop Ġany Ġif Ġ> ĠDEFAULT _ PAGE _ SIZE ) ĊĠĠĠĠĠĠĠ Ġval Ġinput States Ġ= Ġservice Hub . vault Service . query By < Cash . State >( Vault Query Criteria ( state Refs Ġ= Ġbuilder . input States ()), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPage Specification ( pageNumber Ġ= ĠDEFAULT _ PAGE _ NUM , ĠpageSize Ġ= Ġbuilder . input States (). size )). states ĊĊĠĠĠĠĠĠĠ Ġval Ġparticipant Sessions Ġ= Ġinput States ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. as Sequence () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. map NotNull Ġ{ Ġservice Hub . identity Service . well Known Party From Anonymous ( it . state . data . owner ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Not ( service Hub . my Info :: is Legal Identity ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. distinct () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. map (:: init iate Flow ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. toList () ĊĠĠĠĠĠĠĠ Ġ// ĠSign Ġtransaction ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠSIGN ING _ TX ĊĠĠĠĠĠĠĠ Ġval Ġtx Ġ= Ġservice Hub . sign Initial Transaction ( builder , Ġsign ers ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCommit Ġthe Ġtransaction ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠFIN AL ISING _ TX ĊĠĠĠĠĠĠĠ Ġval Ġnot ar ised Ġ= Ġfinal ise Tx ( tx , Ġparticipant Sessions , Ġ" Unable Ġto Ġnot ar ise Ġexit ") ĊĠĠĠĠĠĠĠ Ġreturn ĠResult ( not ar ised , Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ C ord a Serializable ĊĠĠĠ Ġclass ĠExit Request ( amount : ĠAmount < Currency >, Ġval Ġissuer Ref : ĠO pa que Bytes ) Ġ: ĠAbstract Request ( amount ) Ċ } Ċ Ċ @ Initi ated By ( Cash Exit Flow :: class ) Ċ class ĠCash Exit Responder Flow ( private Ġval Ġother Side : ĠFlow Session ) Ġ: ĠFlow Logic < Unit >() Ġ{ ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall () Ġ{ ĊĠĠĠĠĠĠĠ Ġsub Flow ( Receive Final ity Flow ( other Side )) ĊĠĠĠ Ġ} Ċ } Ċ