package Ġcom . template Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġcom . template . contracts . Loan Contract Ċ import Ġcom . template . states . Loan State Ċ import Ġnet . cord a . core . contracts . Command Ċ import Ġnet . cord a . core . contracts . Unique Identifier Ċ import Ġnet . cord a . core . contracts . require That Ċ import Ġnet . cord a . core . flows .* Ċ import Ġnet . cord a . core . node . services . query By Ċ import Ġnet . cord a . core . node . services . vault . Query Criteria Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . Progress Tracker Ċ Ċ @ Initi ating Flow Ċ @ Start able By RPC Ċ class ĠPay Amount Flow ( val ĠID : ĠUnique Identifier , Ġval Ġamount : ĠInt ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġobject ĠINITIAL ISE Ġ: ĠProgress Tracker . Step (" Initial ise Ġflow .") ĊĠĠĠĠĠĠĠ Ġobject ĠQUERY _ VA ULT Ġ: ĠProgress Tracker . Step (" Query Ġvault Ġfor Ġinput Ġstates .") ĊĠĠĠĠĠĠĠ Ġobject ĠBUILD _ TX Ġ: ĠProgress Tracker . Step (" Build Ġtransaction .") ĊĠĠĠĠĠĠĠ Ġobject ĠVERIFY _ TX Ġ: ĠProgress Tracker . Step (" Verify Ġtransaction .") ĊĠĠĠĠĠĠĠ Ġobject ĠSIGN _ TX Ġ: ĠProgress Tracker . Step (" Sign Ġtransaction .") ĊĠĠĠĠĠĠĠ Ġobject ĠOTHER _ PAR TY _ SIGN Ġ: ĠProgress Tracker . Step (" Request Ġother Ġparty Ġfor Ġsignature .") ĊĠĠĠĠĠĠĠ Ġobject ĠFIN ALI SE Ġ: ĠProgress Tracker . Step (" Final ise Ġtransaction .") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġchild Progress Tracker () Ġ= ĠFinal ity Flow . tracker () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfun Ġtracker () Ġ= ĠProgress Tracker ( INITIAL ISE , ĠQUERY _ VA ULT , ĠBUILD _ TX , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠVERIFY _ TX , ĠSIGN _ TX , ĠOTHER _ PAR TY _ SIGN , ĠFIN ALI SE ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġval Ġprogress Tracker Ġ= Ġtracker () ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġnot ary Ġ= Ġservice Hub . network Map Cache . not ary Id entities [ 0 ] ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠINITIAL ISE ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠQUERY _ VA ULT ĊĠĠĠĠĠĠĠ Ġval Ġvault Query Criteria Ġ= ĠQuery Criteria . Linear State Query Criteria ( listOf ( our Identity ), ĠlistOf ( ID )) ĊĠĠĠĠĠĠĠ Ġval Ġinput State Ġ= Ġservice Hub . vault Service . query By < Loan State >( vault Query Criteria ). states . first () ĊĠĠĠĠĠĠĠ Ġval Ġl ender Ġ= Ġinput State . state . data . l ender ĊĠĠĠĠĠĠĠ Ġval Ġchk Ġ= Ġinput State . state . data . amount ToBe Paid Ġ- Ġamount ĊĠĠĠĠĠĠĠ Ġval Ġtx Builder : ĠTransaction Builder ĊĠĠĠĠĠĠĠ Ġval Ġoutput State : ĠLo an State ĊĠĠĠĠĠĠĠ Ġval Ġloan State Command Ġ: ĠCommand < Loan Contract . Commands > ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠBUILD _ TX ĊĊĠĠĠĠĠĠĠ Ġif Ġ( chk Ġ> Ġ 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoutput State Ġ= ĠLo an State ( chk , Ġinput State . state . data . interest Rate , Ġinput State . state . data . rep ayment Schedule , Ġour Identity , Ġl ender , ĠID ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġloan State Command Ġ= ĠCommand ( Loan Contract . Commands . Update (), ĠlistOf ( our Identity . own ing Key , Ġl ender . own ing Key )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtx Builder Ġ= ĠTransaction Builder ( not ary ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Input State ( input State ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Output State ( output State , ĠLo an Contract . LO AN _ CONTRACT _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Command ( loan State Command ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġloan State Command Ġ= ĠCommand ( Loan Contract . Commands . Close (), ĠlistOf ( our Identity . own ing Key , Ġl ender . own ing Key )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtx Builder Ġ= ĠTransaction Builder ( not ary ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Input State ( input State ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Command ( loan State Command ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠVERIFY _ TX ĊĠĠĠĠĠĠĠ Ġtx Builder . verify ( service Hub ) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠSIGN _ TX ĊĠĠĠĠĠĠĠ Ġval Ġpartially Signed Transaction Ġ= Ġservice Hub . sign Initial Transaction ( tx Builder ) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠOTHER _ PAR TY _ SIGN ĊĠĠĠĠĠĠĠ Ġval Ġother Party Session Ġ= Ġinitiate Flow ( l ender ) ĊĠĠĠĠĠĠĠ Ġval Ġcompletely Signed Transaction Ġ= Ġsub Flow ( Collect Signatures Flow ( part ially Signed Transaction , ĠlistOf ( other Party Session ))) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠFIN ALI SE ĊĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Final ity Flow ( comp let ely Signed Transaction )) ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Initi ated By ( Pay Amount Flow :: class ) Ċ class ĠCheck Amount Paid Flow ( val Ġcounter party Session : ĠFlow Session ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsign Transaction Flow Ġ= Ġobject Ġ: ĠSign Transaction Flow ( counter party Session , ĠSign Transaction Flow . tracker ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcheck Transaction ( st x : ĠSigned Transaction ) Ġ= Ġrequire That Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ/* val Ġoutput Ġ= Ġst x . tx . outputs . single (). data ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" This Ġmust Ġbe Ġa Ġloan Ġrecord Ġtransaction ." Ġusing Ġ( output Ġis ĠLo an State ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġoutput State Ġ= Ġoutput Ġas ĠLo an State ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġinput Ġ= Ġst x . tx . inputs [ 0 ] ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġinput State Ġ= Ġservice Hub . load State ( input ). data Ġas ĠLo an State ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" The Ġamount Ġshould Ġbe Ġpositive ." Ġusing Ġ( output State . amount ToBe Paid Ġ< Ġinput State . amount ToBe Paid ) */ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( sign Transaction Flow ) ĊĠĠĠ Ġ} Ċ } Ċ