package Ġcom . r 3 . demo . cross not ary swap . flows Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġcom . r 3 . cord a . lib . tokens . workflows . utilities . to Party Ċ import Ġcom . r 3 . demo . cross not ary swap . flows . dto . Exchange Request DTO Ċ import Ġcom . r 3 . demo . cross not ary swap . flows . dto . F ung ible Asset Request Ċ import Ġcom . r 3 . demo . cross not ary swap . flows . dto . Non F ung ible Asset Request Ċ import Ġcom . r 3 . demo . cross not ary swap . flows . utils .* Ċ import Ġcom . r 3 . demo . cross not ary swap . states . Lock State Ċ import Ġcom . r 3 . demo . cross not ary swap . states . Validated Draft Transfer Of Ownership Ċ import Ġcom . r 3 . demo . generic . flow Fail Ċ import Ġcom . r 3 . demo . generic . get Preferred Not ary For Token Ċ import Ġcom . r 3 . demo . template . flows . Collect Signatures For Comp os ites Ċ import Ġcom . r 3 . demo . template . flows . Collect Signatures For Comp os ites Handler Ċ import Ġnet . cord a . core . contracts . Time Window Ċ import Ġnet . cord a . core . crypto . Composite Key Ċ import Ġnet . cord a . core . crypto . Signature Metadata Ċ import Ġnet . cord a . core . flows .* Ċ import Ġnet . cord a . core . identity . Anonymous 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 . transactions . Wire Transaction ĊĊ Ċ /** Ċ Ġ* ĠInv oked Ġby Ġthe Ġ** seller ** Ġparty Ġto Ġtransfer Ġthe Ġsell er Ġassets Ġand Ġenc umber Ġthem Ġwith Ġa Ġ[ Lock State ] Ċ Ġ* Ġ@ param Ġexchange Request DTO Ġcontaining Ġthe Ġasset Ġexchange Ġinformation Ċ Ġ* Ġ@ param Ġvalidated Draft Transfer Of Ownership Ġobject Ġencaps ulating Ġinformation Ġabout Ġthe Ġdraft Ġunsigned Ġ[ Wire Transaction ], Ċ Ġ* Ġthe Ġnot ary Ġ[ Signature Metadata ] Ċ Ġ*/ Ċ class ĠOffer Enc umber ed Tokens Flow ( ĊĠĠĠ Ġprivate Ġval Ġexchange Request DTO : ĠExchange Request DTO , ĊĠĠĠ Ġprivate Ġval Ġvalidated Draft Transfer Of Ownership : ĠValid ated Draft Transfer Of Ownership , ĊĠĠĠ Ġprivate Ġval Ġbuy er Session : ĠFlow Session Ċ ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġbuy er Party Ġ= Ġexchange Request DTO . buyer . to Party ( service Hub ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcreate Ġthe Ġcomposite Ġkey Ġto Ġtransfer Ġthe Ġsell er Ġasset Ġto . ĠThis Ġis Ġto Ġenable Ġequal Ġcontrol Ġof Ġboth Ġthe ĊĠĠĠĠĠĠĠ Ġ// Ġbuy er Ġand Ġsell er Ġof Ġthe Ġasset . ĊĠĠĠĠĠĠĠ Ġval Ġcomposite Key To Transfer S eller Asset Ġ= Ġservice Hub . register Composite Key ( our Identity , Ġbuy er Session . counter party ) ĊĠĠĠĠĠĠĠ Ġval Ġcomposite Key Holder Party Ġ= ĠAn onymous Party ( composite Key To Transfer S eller Asset ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcreate Ġthe Ġlock Ġstate Ġthat Ġwill Ġenc umber Ġall Ġtokens / states Ġthat Ġthe Ġsell er Ġwill Ġtransfer ĊĠĠĠĠĠĠĠ Ġval Ġlock State Ġ= ĠLock State ( validated Draft Transfer Of Ownership , Ġour Identity , Ġbuy er Party ) ĊĊĠĠĠĠĠĠĠ Ġval Ġtoken Type For S eller Ġ= Ġget TokenType From Asset Request ( exchange Request DTO . seller Asset Request ) ĊĠĠĠĠĠĠĠ Ġ// prepare Ġthe Ġtransaction ĊĠĠĠĠĠĠĠ Ġval Ġtransaction Builder Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTransaction Builder ( not ary Ġ= Ġget Preferred Not ary For Token ( token Type For S eller )) ĊĊĠĠĠĠĠĠĠ Ġ// Ġconstruct Ġthe Ġtransaction Ġthat Ġenc umbers Ġall Ġstates Ġon Ġthe Ġlock Ġstate Ġbased Ġon Ġthe Ġexchange Ġrequest ĊĠĠĠĠĠĠĠ Ġval Ġenc umber ed Transaction Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Enc umber ed Tokens ( transaction Builder , Ġexchange Request DTO , Ġlock State , Ġcomposite Key Holder Party ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġverify Ġand Ġsign ĊĠĠĠĠĠĠĠ Ġenc umber ed Transaction . verify ( service Hub ) ĊĠĠĠĠĠĠĠ Ġval Ġself Signed Tx Ġ= Ġservice Hub . sign Initial Transaction ( enc umber ed Transaction ) ĊĠĠĠĠĠĠĠ Ġval Ġsigned Tx Ġ= Ġsub Flow ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCollect Signatures For Comp os ites ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġself Signed Tx , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( buyer Session ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ)) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Final ity Flow ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction Ġ= Ġsigned Tx , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsessions Ġ= ĠlistOf ( buyer Session ) ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠAdd Ġthe Ġenc umber ed Ġtokens Ġto Ġthe Ġtransaction Ġbuilder Ġbased Ġin Ġ[ Exchange Request DTO ] ĊĠĠĠĠ Ġ* Ġ@ param Ġtransaction Builder Ġto Ġadd Ġthe Ġtokens Ġto ĊĠĠĠĠ Ġ* Ġ@ param Ġexchange Request DTO Ġhaving Ġinformation Ġabout Ġthe Ġswap ĊĠĠĠĠ Ġ* Ġ@ param Ġlock State Ġto Ġbe Ġused ĊĠĠĠĠ Ġ* Ġ@ param Ġcomposite Key Holder Party Ġhaving Ġa Ġ[ Composite Key ] Ġof Ġboth Ġthe Ġsell er Ġand Ġthe Ġbuy er Ġwith Ġequal Ġweights ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġadd Enc umber ed Tokens ( ĊĠĠĠĠĠĠĠ Ġtransaction Builder : ĠTransaction Builder , ĊĠĠĠĠĠĠĠ Ġexchange Request DTO : ĠExchange Request DTO , ĊĠĠĠĠĠĠĠ Ġlock State : ĠLock State , ĊĠĠĠĠĠĠĠ Ġcomposite Key Holder Party : ĠAn onymous Party ĊĠĠĠ Ġ): ĠTransaction Builder Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwith ( transaction Builder ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhen Ġ( exchange Request DTO . seller Asset Request ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠNon F ung ible Asset Request Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Move Token ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġservice Hub Ġ= Ġservice Hub , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtoken Identifier Ġ= Ġexchange Request DTO . seller Asset Request . token Identifier , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġholder Ġ= Ġcomposite Key Holder Party , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadditional Keys Ġ= Ġempty List (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlock State Ġ= Ġlock State ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠF ung ible Asset Request Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Move Tokens ( service Hub Ġ= Ġservice Hub , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġamount Ġ= Ġexchange Request DTO . seller Asset Request . token Amount , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġholder Ġ= Ġcomposite Key Holder Party , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġchange Holder Ġ= Ġour Identity , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadditional Keys Ġ= Ġempty List (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlock State Ġ= Ġlock State ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġflow Fail (" Unable Ġto Ġdetermine Ġtoken Ġtype Ġfor Ġsell er . Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Offer ing Ġenc umber ed Ġtokens Ġfor Ġcustom Ġtoken Ġtype Ġis Ġnot Ġsupported ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġadd Ġadditional Ġ 3 0 s Ġbuffer Ġto Ġthe Ġtime Ġwindow Ġto Ġconsume Ġthe Ġlock Ġstate Ġin Ġaddition ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġto Ġthe Ġoriginally Ġset Ġtime Ġwindow Ġin Ġthe Ġunsigned Ġtx ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Time Window ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTime Window . until Only ( validated Draft Transfer Of Ownership . tx . time Window ?. until Time !! ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. plus Seconds ( 3 0 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ /** Ċ Ġ* ĠBu yer 's Ġresponse Ġto Ġthe Ġoffered Ġenc umber ed Ġtokens Ċ Ġ*/ Ċ class ĠOffer Enc umber ed Tokens Flow Handler ( private Ġval Ġcounter Party Session : ĠFlow Session ) Ġ: ĊĠĠĠ ĠFlow Logic < Signed Transaction >() Ġ{ ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġservice Hub . register Composite Key ( our Identity , Ġcounter Party Session . counter party ) ĊĊĠĠĠĠĠĠĠ Ġsub Flow ( Collect Signatures For Comp os ites Handler ( counter Party Session )) ĊĊĠĠĠĠĠĠĠ Ġval Ġsigned Enc umber ed Tx Ġ= Ġsub Flow ( Receive Final ity Flow ( other Side Session Ġ= Ġcounter Party Session , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstates To Record Ġ= ĠStates To Record . ALL _ VISIBLE )) ĊĊĠĠĠĠĠĠĠ Ġval Ġto Ledger Transaction Ġ= Ġsigned Enc umber ed Tx . to Ledger Transaction ( service Hub ) ĊĠĠĠĠĠĠĠ Ġval Ġlock State Ġ= Ġto Ledger Transaction . outputs OfType ( Lock State :: class . java ). single () ĊĊĠĠĠĠĠĠĠ Ġ// Ġexecute Ġthe Ġrest Ġof Ġthe Ġunlock ing Ġprocess Ġfor Ġthe Ġrecipient Ġof Ġthe Ġlock Ġstate , Ġi . e . Ġbuy er ĊĠĠĠĠĠĠĠ Ġ// ĠTODO Ġcheck Ġidentity Ġlater ĊĠĠĠĠĠĠĠ Ġ// if Ġ( our Identity Ġ== Ġlock State . receiver ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexchange Request DTO Ġ= Ġget Exchange Request By Tx Id ( lock State . tx Id With Not ary Metadata . tx Id . toString ()) ĊĊĠĠĠĠĠĠĠ Ġ// Ġverify Ġif Ġthe Ġtransaction Ġis Ġok Ġas Ġper Ġthe Ġshared Ġexchange Ġrequest ĊĠĠĠĠĠĠĠ Ġverify Shared Transaction Again st Exchange Request ( exchange Request DTO . seller Asset Request , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsigned Enc umber ed Tx . tx , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlock State . composite Key ) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġsigned Enc umber ed Tx ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Initi ating Flow Ċ class ĠOffer Enc umber ed Tokens ( ĊĠĠĠ Ġprivate Ġval ĠrequestId : ĠString , ĊĠĠĠ Ġprivate Ġval Ġvalidated Draft Transfer Of Ownership : ĠValid ated Draft Transfer Of Ownership Ċ ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexchange Request DTO Ġ= Ġget Request ById ( requestId ) ĊĠĠĠĠĠĠĠ Ġval Ġbuy er Session Ġ= Ġinitiate Flow ( exchange Request DTO . buyer ) ĊĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Offer Enc umber ed Tokens Flow ( exchange Request DTO , Ġvalidated Draft Transfer Of Ownership , Ġbuy er Session )) ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Initi ated By ( Offer Enc umber ed Tokens :: class ) Ċ class ĠOffer Enc umber ed Tokens Handler ( private Ġval Ġcounter Party Session : ĠFlow Session ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ= Ġsub Flow ( Offer Enc umber ed Tokens Flow Handler ( counter Party Session )) Ċ } Ċ