package Ġcom . syn e chron . cord app . clear ing house . flows Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġcom . syn e chron . cord app . common . exception . Invalid Party Exception Ċ import Ġcom . syn e chron . cord app . common . flows . Identity Sync Flow Ċ import Ġcom . syn e chron . cord app . common . flows . Receive Transaction Un Verified Flow Ċ import Ġcom . syn e chron . cord app . contract . Asset Transfer Contract Ċ import Ġcom . syn e chron . cord app . flows . Abstract Asset Set tlement Flow Ċ import Ġcom . syn e chron . cord app . state . Asset Transfer Ċ import Ġcom . syn e chron . cord app . state . Request Status Ċ import Ġnet . cord a . core . contracts . Command Ċ import Ġnet . cord a . core . contracts . Unique Identifier Ċ import Ġnet . cord a . core . flows . Collect Signatures Flow Ċ import Ġnet . cord a . core . flows . Final ity Flow Ċ import Ġnet . cord a . core . flows . Send Transaction Flow Ċ import Ġnet . cord a . core . flows . Start able By RPC Ċ 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 . core . utilities . seconds Ċ Ċ /** Ċ Ġ* ĠCreate Ġnew Ġtransaction Ġto Ġprocess Ġthe Ġreceived Ġtransaction Ġto Ġset tle Ġ[ Asset Transfer ] Ġrequest . Ċ Ġ* ĠIt Ġaccepts Ġthe Ġ[ Asset Transfer ] Ġstate 's Ġ[ linear Id ] Ġas Ġinput Ġto Ġstart Ġthis Ġflow Ġand Ġcollect s Ġthe Ġ[ Cash ] Ġand Ġ[ Asset ] Ġinput Ġand Ġoutput Ġstates Ġfrom Ġcounter - party . Ċ Ġ* ĠFor Ġdemo : Ċ Ġ* Ġ 1 . ĠClear ing ĠHouse Ġset Ġrequest Status Ġto Ġ[ Request Status . TRANSFER RED ] Ġif Ġeverything Ġis Ġokay Ċ Ġ* ĠĠĠ Ġ( i . e . Ġby Ġoffline Ġverify ing Ġthe Ġdata Ġof Ġ[ Asset Transfer . asset ] Ġis Ġvalid ). Ċ Ġ* Ċ Ġ* ĠOn Ġsuccessful Ġcompletion Ġof Ġa Ġflow , Ġ[ Asset ] Ġstate Ġownership Ġis Ġtransferred Ġto Ġ` Buyer ` Ġparty Ċ Ġ* Ġand Ġ[ Cash ] Ġtokens Ġequals Ġto Ġ[ Asset . purchase Cost ] Ġis Ġtransferred Ġto Ġ` S eller ` Ġparty . Ċ Ġ*/ Ċ @ Start able By RPC Ċ class ĠAsset Set tlement Init iator Flow ( val Ġlinear Id : ĠUnique Identifier ) Ġ: ĠAbstract Asset Set tlement Flow < Signed Transaction >() Ġ{ ĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġobject ĠINITIAL ISING Ġ: ĠProgress Tracker . Step (" Perform ing Ġinitial Ġsteps .") ĊĠĠĠĠĠĠĠ Ġobject ĠBUILD ING Ġ: ĠProgress Tracker . Step (" Building Ġand Ġverify ing Ġtransaction .") ĊĠĠĠĠĠĠĠ Ġobject ĠCOL LECT _ STAT ES Ġ: ĠProgress Tracker . Step (" Collect ĠAsset Ġand ĠCash Ġstates Ġfrom Ġcounter party .") ĊĠĠĠĠĠĠĠ Ġobject ĠIDENTITY _ SYNC Ġ: ĠProgress Tracker . Step (" Sync Ġident ities Ġwith Ġcounter Ġparties .") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġchild Progress Tracker () Ġ= ĠIdentity Sync Flow . Send . tracker () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġobject ĠSIGN ING Ġ: ĠProgress Tracker . Step (" Signing Ġtransaction .") ĊĠĠĠĠĠĠĠ Ġobject ĠCOL LECT ING Ġ: ĠProgress Tracker . Step (" Collect ing Ġcounter party Ġsignature .") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ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 ( INITIAL ISING , ĠBUILD ING , ĠCOL LECT _ STAT ES , ĠIDENTITY _ SYNC , ĠSIGN ING , ĠCOL LECT ING , ĠFIN AL ISING ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġval Ġprogress Tracker : ĠProgress Tracker Ġ= Ġtracker () ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠINITIAL ISING ĊĠĠĠĠĠĠĠ Ġval Ġin Asset Transfer Ġ= Ġservice Hub . load State ( linear Id , ĠAsset Transfer :: class . java ) ĊĠĠĠĠĠĠĠ Ġval Ġparticipants Ġ= Ġin Asset Transfer . state . data . participants ĊĠĠĠĠĠĠĠ Ġval Ġout Asset Transfer Ġ= Ġin Asset Transfer . state . data . copy ( status Ġ= ĠRequest Status . TRANSFER RED ) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( our Identity . name Ġ!= Ġservice Hub . resolve Identity ( out Asset Transfer . clear ing House !! ). name ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠInvalid Party Exception (" Flow Ġmust Ġbe Ġinitiated Ġby ĠC ust od ian .") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠBUILD ING ĊĠĠĠĠĠĠĠ Ġval Ġt xb Ġ= ĠTransaction Builder ( in Asset Transfer . state . not ary ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Input State ( in Asset Transfer ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Output State ( out Asset Transfer , ĠAsset Transfer Contract . AS SET _ TRANSFER _ CONTRACT _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Command ( Asset Transfer Contract . Commands . Set tle Request (), Ġparticipants . map Ġ{ Ġit . own ing Key Ġ}) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠCOL LECT _ STAT ES ĊĠĠĠĠĠĠĠ Ġ// Create Ġtemporary Ġpartial Ġtransaction . ĊĠĠĠĠĠĠĠ Ġval Ġtemp P tx Ġ= Ġservice Hub . sign Initial Transaction ( tx b ) ĊĠĠĠĠĠĠĠ Ġval Ġsecurity S eller Session Ġ= Ġinitiate Flow ( service Hub . resolve Identity ( out Asset Transfer . security S eller )) ĊĠĠĠĠĠĠĠ Ġ// Send Ġpartial Ġtransaction Ġto ĠSecurity ĠOwner Ġi . e . Ġ` S eller `. ĊĠĠĠĠĠĠĠ Ġsub Flow ( Send Transaction Flow ( security S eller Session , Ġtemp P tx )) ĊĠĠĠĠĠĠĠ Ġ// Receive Ġtransaction Ġwith Ġinput Ġand Ġoutput Ġof ĠAsset Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġasset P tx Ġ= Ġsub Flow ( Receive Transaction Un Verified Flow ( security S eller Session )) ĊĊĠĠĠĠĠĠĠ Ġ// Send Ġpartial Ġtransaction Ġto Ġ` Buyer `. ĊĠĠĠĠĠĠĠ Ġval Ġsecurity Buyer Session Ġ= Ġinitiate Flow ( service Hub . resolve Identity ( out Asset Transfer . security Buyer )) ĊĠĠĠĠĠĠĠ Ġsub Flow ( Send Transaction Flow ( security Buyer Session , Ġtemp P tx )) ĊĠĠĠĠĠĠĠ Ġ// Send Ġflows ĠID Ġfor Ġsoft Ġlock Ġof Ġthe Ġcash Ġstate . ĊĠĠĠĠĠĠĠ Ġsecurity Buyer Session . send ( tx b . lock Id ) ĊĠĠĠĠĠĠĠ Ġ// Receive Ġand Ġregister Ġthe Ġanonymous Ġidentity Ġwere Ġcreated Ġfor ĠCash Ġtransfer . ĊĠĠĠĠĠĠĠ Ġsub Flow ( net . cord a . conf idential . Identity Sync Flow . Receive ( security Buyer Session )) ĊĠĠĠĠĠĠĠ Ġ// Receive Ġtransaction Ġwith Ġinput Ġand Ġoutput Ġstate Ġof ĠCash Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġcash P tx Ġ= Ġsub Flow ( Receive Transaction Un Verified Flow ( security Buyer Session )) ĊĊĠĠĠĠĠĠĠ Ġ// Add ĠAsset Ġstates Ġand Ġcommands Ġto Ġorigin ĠTransaction ĠBuilder Ġ` tx b `. ĊĠĠĠĠĠĠĠ Ġval Ġasset L tx Ġ= Ġasset P tx . to Ledger Transaction ( service Hub , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġasset L tx . inputs . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġt xb . add Input State ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġasset L tx . outputs . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġt xb . add Output State ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġasset L tx . commands . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġt xb . add Command ( Command ( it . value , Ġit . sign ers )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// Add ĠCash Ġstates Ġand Ġcommands Ġto Ġorigin ĠTransaction ĠBuilder Ġ` tx b `. ĊĠĠĠĠĠĠĠ Ġval Ġcash L tx Ġ= Ġcash P tx . to Ledger Transaction ( service Hub , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġcash L tx . inputs . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġt xb . add Input State ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġcash L tx . outputs . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġt xb . add Output State ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġcash L tx . commands . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġt xb . add Command ( Command ( it . value , Ġit . sign ers )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠIDENTITY _ SYNC ĊĠĠĠĠĠĠĠ Ġval Ġcounter Party Sessions Ġ= Ġset Of ( security Buyer Session , Ġsecurity S eller Session ) ĊĠĠĠĠĠĠĠ Ġsub Flow ( Identity Sync Flow . Send ( counter Party Sessions , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġt xb . to Wire Transaction ( service Hub ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠIDENTITY _ SYNC . child Progress Tracker ())) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠSIGN ING ĊĠĠĠĠĠĠĠ Ġt xb . setTime Window ( service Hub . clock . instant (), Ġ 6 0 . seconds ) ĊĠĠĠĠĠĠĠ Ġval Ġp tx Ġ= Ġservice Hub . sign Initial Transaction ( tx b , Ġout Asset Transfer . clear ing House !!. own ing Key ) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠCOL LECT ING ĊĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġsub Flow ( Collect Signatures Flow ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġp tx , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcounter Party Sessions , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( out Asset Transfer . clear ing House !!. own ing Key ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCOL LECT ING . child Progress Tracker ()) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠFIN AL ISING ĊĠĠĠĠĠĠĠ Ġval Ġf tx Ġ= Ġsub Flow ( Final ity Flow ( st x , ĠFIN AL ISING . child Progress Tracker ())) ĊĠĠĠĠĠĠĠ Ġreturn Ġf tx ĊĠĠĠ Ġ} Ċ } Ċ