package Ġcom . template . flows Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġcom . template . FORWARD _ CONTRACT _ ID Ċ import Ġcom . template . Forward Contract Ċ import Ġcom . template . Forward State Ċ import Ġcom . template . base . OR AC LE _ NAME Ċ import Ġcom . template . base . Spot Price Ċ import Ġcom . template . flows . Oracle Query Ċ import Ġcom . template . oracle . Oracle Ċ import Ġfirst Identity ByName Ċ import Ġfirst Not ary Ċ import Ġio . netty . handler . codec . rt sp . Rt sp Methods . SETUP Ċ import Ġnet . cord a . core . contracts . Command Ċ import Ġnet . cord a . core . contracts . State Ref Ċ 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 . identity . C ord a X 5 0 0 Name Ċ import Ġnet . cord a . core . identity . Party Ċ import Ġnet . cord a . core . node . Service Hub Ċ import Ġnet . cord a . core . serialization . C ord a Serializable Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . Progress Tracker Ċ import Ġnet . cord a . finance . contracts . asset . Cash Ċ import Ġnet . cord a . finance . flows . Two Party Trade Flow Ċ import Ġjava . math . BigDecimal Ċ import Ġjava . time . Instant Ċ import Ġjava . util . function . Predicate Ċ Ċ @ Initi ating Flow Ċ @ S chedul able Flow Ċ @ Start able By RPC Ċ @ C ord a Serializable Ċ class ĠSet tle Cash Flow ( private Ġval Ġinit iator : ĠParty , Ġprivate Ġval Ġaccept or : ĠParty , Ġprivate Ġval Ġinstrument : ĠString , Ġprivate Ġval Ġinstrument Quantity : ĠBigDecimal , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġdelivery Price : ĠBigDecimal , Ġprivate Ġval Ġset tlement Timestamp : ĠInstant , Ġprivate Ġval Ġset tlement Type : ĠString , Ġprivate Ġval Ġposition : ĠString , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġthis State Ref : ĠState Ref , Ġprivate Ġval Ġforward State : ĠForward State ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġobject ĠSET _ UP Ġ: ĠProgress Tracker . Step (" Initial ising Ġflow .") ĊĠĠĠĠĠĠĠ Ġobject ĠQUERY ING _ THE _ OR AC LE Ġ: ĠProgress Tracker . Step (" Query ing Ġoracle Ġfor Ġthe Ġcurrent Ġspot Ġprice Ġand Ġvol atility .") ĊĠĠĠĠĠĠĠ Ġobject ĠBUILD ING _ THE _ TX Ġ: ĠProgress Tracker . Step (" Building Ġtransaction .") ĊĠĠĠĠĠĠĠ Ġobject ĠCHECK _ C ASH Ġ: ĠProgress Tracker . Step (" Check Ġcash Ġamount ") ĊĠĠĠĠĠĠĠ Ġobject ĠVERIFY ING _ THE _ TX Ġ: ĠProgress Tracker . Step (" Verify ing Ġtransaction .") ĊĠĠĠĠĠĠĠ Ġobject ĠWE _ SIGN Ġ: ĠProgress Tracker . Step (" Signing Ġtransaction .") ĊĠĠĠĠĠĠĠ Ġobject ĠOR AC LE _ SIG NS Ġ: ĠProgress Tracker . Step (" Request ing Ġoracle Ġsignature .") ĊĠĠĠĠĠĠĠ Ġobject ĠOTHER S _ SIGN Ġ: ĠProgress Tracker . Step (" Collect ing Ġcounter party Ġsignatures .") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġchild Progress Tracker () Ġ= ĠCollect Signatures Flow . tracker () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġobject ĠFIN AL ISING Ġ: ĠProgress Tracker . Step (" Final ising Ġtransaction ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġchild Progress Tracker () Ġ= ĠFinal ity Flow . tracker () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfun Ġtracker () Ġ= ĠProgress Tracker ( SET _ UP , ĠQUERY ING _ THE _ OR AC LE , ĠBUILD ING _ THE _ TX , ĠCHECK _ C ASH , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠVERIFY ING _ THE _ TX , ĠWE _ SIGN , ĠOR AC LE _ SIG NS , ĠOTHER S _ SIGN , ĠFIN AL ISING ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġval Ġprogress Tracker Ġ= Ġtracker () ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠSET _ UP ĊĠĠĠĠĠĠĠ Ġval Ġnot ary Ġ= Ġservice Hub . first Not ary () ĊĠĠĠĠĠĠĠ Ġval Ġoracle Ġ= Ġservice Hub . network Map Cache . getNode By Legal Name ( OR AC LE _ NAME )?. legal Id entities ?. first () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠIllegalArgumentException (" Requested Ġoracle Ġ$ OR AC LE _ NAME Ġnot Ġfound Ġon Ġnetwork .") ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠQUERY ING _ THE _ OR AC LE ĊĠĠĠĠĠĠĠ Ġval Ġspot Price Ġ= Ġsub Flow ( Oracle Query ( oracle , Ġinstrument )) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠBUILD ING _ THE _ TX ĊĠĠĠĠĠĠĠ Ġval Ġrequired Sign ers Ġ= ĠlistOf ( forward State . init iator , Ġforward State . accept or ). map Ġ{ Ġit . own ing Key Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġset tle Command Ġ= ĠCommand ( Forward Contract . Commands . Set tle Cash (), Ġrequired Sign ers ) ĊĠĠĠĠĠĠĠ Ġval Ġoracle Command Ġ= ĠCommand ( Forward Contract . Oracle Command ( spot Price ), Ġoracle . own ing Key ) ĊĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠTransaction Builder ( not ary ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Output State ( forward State , ĠFOR WARD _ CONTRACT _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Command ( set tle Command ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Command ( oracle Command ) Ċ Ċ // ĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠCHECK _ C ASH Ċ // ĠĠĠĠĠĠĠ Ġval Ġforward Price Ġ= ĠForward State . calculate Cash ( forward State , Ġspot Price ) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠVERIFY ING _ THE _ TX ĊĠĠĠĠĠĠĠ Ġbuilder . verify ( service Hub ) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠWE _ SIGN ĊĠĠĠĠĠĠĠ Ġval Ġp tx Ġ= Ġservice Hub . sign Initial Transaction ( builder ) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠOR AC LE _ SIG NS ĊĠĠĠĠĠĠĠ Ġval Ġf tx Ġ= Ġp tx . build Filtered Transaction ( Predicate Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit Ġis ĠCommand < *> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ&& Ġit . value Ġis ĠForward Contract . Oracle Command ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ&& Ġoracle . own ing Key Ġin Ġit . sign ers ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ Ġval Ġoracle Signature Ġ= Ġsub Flow ( Oracle Request Signature ( oracle , Ġf tx )) ĊĠĠĠĠĠĠĠ Ġval Ġp tx With Oracle Sig Ġ= Ġp tx . with Additional Signature ( oracle Signature ) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠOTHER S _ SIGN ĊĠĠĠĠĠĠĠ Ġval Ġissuer Session Ġ= Ġinitiate Flow ( forward State . init iator ) ĊĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġsub Flow ( Collect Signatures Flow ( pt x With Oracle Sig , ĠlistOf ( issuer Session ), ĠOTHER S _ SIGN . child Progress Tracker ())) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠFIN AL ISING ĊĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Final ity Flow ( st x , ĠFIN AL ISING . child Progress Tracker ())) ĊĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Initi ating Flow Ċ @ Initi ated By ( Set tle Cash Flow :: class ) Ċ class ĠSet tle Cash Flow Responder ( val Ġcounter party Session : ĠFlow Session ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġflow Ġ= Ġobject Ġ: ĠSign Transaction Flow ( counter party Session ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcheck Transaction ( st x : ĠSigned Transaction ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠWe Ġcheck Ġthe Ġoracle Ġis Ġa Ġrequired Ġsigner . ĠIf Ġso , Ġwe Ġcan Ġtrust Ġthe Ġspot Ġprice Ġand Ġvol atility Ġdata . ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġoracle Ġ= Ġservice Hub . first Identity ByName ( OR AC LE _ NAME ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġst x . required Signing Keys . contains ( oracle . own ing Key ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġsub Flow ( flow ) ĊĠĠĠĠĠĠĠ Ġreturn ĠwaitFor Ledger Commit ( st x . id ) ĊĠĠĠ Ġ} Ċ }