package Ġnet . cord a . c 5 template . flows Ċ Ċ import Ġorg . openc ord a . open net . contracts . Template Contract Ċ import Ġorg . openc ord a . open net . states . Template State Ċ import Ġnet . cord a . system flows . Collect Signatures Flow Ċ import Ġnet . cord a . system flows . Final ity Flow Ċ import Ġnet . cord a . system flows . Receive Final ity Flow Ċ import Ġnet . cord a . system flows . Sign Transaction Flow Ċ import Ġnet . cord a . v 5 . application . flows .* Ċ import Ġnet . cord a . v 5 . application . flows . flow services . Flow Engine Ċ import Ġnet . cord a . v 5 . application . flows . flow services . Flow Identity Ċ import Ġnet . cord a . v 5 . application . flows . flow services . Flow Messaging Ċ import Ġnet . cord a . v 5 . application . identity . C ord a X 5 0 0 Name Ċ import Ġnet . cord a . v 5 . application . injection . C ord a Inject Ċ import Ġnet . cord a . v 5 . application . services . Identity Service Ċ import Ġnet . cord a . v 5 . application . services . json . Json Marshall ing Service Ċ import Ġnet . cord a . v 5 . application . services . json . parse Json Ċ import Ġnet . cord a . v 5 . base . annotations . Suspend able Ċ import Ġnet . cord a . v 5 . ledger . contracts . Command Ċ import Ġnet . cord a . v 5 . ledger . contracts . require That Ċ import Ġnet . cord a . v 5 . ledger . services . Not ary Lookup Service Ċ import Ġnet . cord a . v 5 . ledger . transactions . Signed Transaction Ċ import Ġnet . cord a . v 5 . ledger . transactions . Signed Transaction Digest Ċ import Ġnet . cord a . v 5 . ledger . transactions . Transaction BuilderFactory ĊĊ Ċ @ Initi ating Flow Ċ @ Start able By RPC Ċ class ĠTemplate Flow Ġ@ Json Constructor Ġconstructor ( private Ġval Ġparams : ĠRpc Start Flow Request Parameters ) Ġ: ĠFlow < Signed Transaction Digest > Ġ{ ĊĊĠĠĠ Ġ@ C ord a Inject ĊĠĠĠ Ġlateinit Ġvar Ġflow Engine : ĠFlow Engine ĊĠĠĠ Ġ@ C ord a Inject ĊĠĠĠ Ġlateinit Ġvar Ġflow Identity : ĠFlow Identity ĊĠĠĠ Ġ@ C ord a Inject ĊĠĠĠ Ġlateinit Ġvar Ġflow Messaging : ĠFlow Messaging ĊĠĠĠ Ġ@ C ord a Inject ĊĠĠĠ Ġlateinit Ġvar Ġtransaction BuilderFactory : ĠTransaction BuilderFactory ĊĠĠĠ Ġ@ C ord a Inject ĊĠĠĠ Ġlateinit Ġvar Ġidentity Service : ĠIdentity Service ĊĠĠĠ Ġ@ C ord a Inject ĊĠĠĠ Ġlateinit Ġvar Ġnot ary Lookup : ĠNot ary Lookup Service ĊĠĠĠ Ġ@ C ord a Inject ĊĠĠĠ Ġlateinit Ġvar Ġjson Marshall ing Service : ĠJson Marshall ing Service ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Digest Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Ġparse Ġparameters ĊĠĠĠĠĠĠĠ Ġval Ġmap Of Params : ĠMap < String , ĠString > Ġ= Ġjson Marshall ing Service . parse Json ( params . parameters In Json ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġwith ( map Of Params [" msg "] Ġ?: Ġthrow ĠBad Rpc Start Flow RequestException (" Template ĠState ĠParameter Ġ\" msg \" Ġmissing .")) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthis ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġtarget Ġ= Ġwith ( map Of Params [" receiver "] Ġ?: Ġthrow ĠBad Rpc Start Flow RequestException (" Template ĠState ĠParameter Ġ\" receiver \" Ġmissing .")) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠC ord a X 5 0 0 Name . parse ( this ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġrecipient Party Ġ= Ġidentity Service . party FromName ( target ) Ġ?: Ġthrow ĠNoSuch ElementException (" No Ġparty Ġfound Ġfor ĠX 5 0 0 Ġname Ġ$ target ") ĊĊĠĠĠĠĠĠĠ Ġval Ġnot ary Ġ= Ġnot ary Lookup . get Not ary ( C ord a X 5 0 0 Name . parse (" O = not ary , ĠL = L ondon , ĠC = GB ")) !! ĊĊĠĠĠĠĠĠĠ Ġ// ĠStage Ġ 1 . ĊĠĠĠĠĠĠĠ Ġ// ĠGenerate Ġan Ġunsigned Ġtransaction . ĊĠĠĠĠĠĠĠ Ġval Ġsender Ġ= Ġflow Identity . our Identity ĊĠĠĠĠĠĠĠ Ġval Ġtemplate State Ġ= ĠTemplate State ( message , Ġsender , Ġrecipient Party ) ĊĠĠĠĠĠĠĠ Ġval Ġtx Command Ġ= ĠCommand ( Template Contract . Commands . Create (), ĠlistOf ( sender . own ing Key , recipient Party . own ing Key )) ĊĠĠĠĠĠĠĠ Ġval Ġtx Builder Ġ= Ġtransaction BuilderFactory . create () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Not ary ( not ary ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Output State ( template State , ĠTemplate Contract . ID ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Command ( tx Command ) ĊĊĊĠĠĠĠĠĠĠ Ġ// ĠStage Ġ 2 . ĊĠĠĠĠĠĠĠ Ġ// ĠVerify Ġthat Ġthe Ġtransaction Ġis Ġvalid . ĊĠĠĠĠĠĠĠ Ġtx Builder . verify () ĊĊĠĠĠĠĠĠĠ Ġ// ĠStage Ġ 3 . ĊĠĠĠĠĠĠĠ Ġ// ĠSign Ġthe Ġtransaction . ĊĠĠĠĠĠĠĠ Ġval Ġpart Signed Tx Ġ= Ġtx Builder . sign () ĊĊĠĠĠĠĠĠĠ Ġ// ĠStage Ġ 4 . ĊĠĠĠĠĠĠĠ Ġ// ĠSend Ġthe Ġstate Ġto Ġthe Ġcounter party , Ġand Ġreceive Ġit Ġback Ġwith Ġtheir Ġsignature . ĊĠĠĠĠĠĠĠ Ġval Ġother Party Session Ġ= Ġflow Messaging . init iate Flow ( recipient Party ) ĊĠĠĠĠĠĠĠ Ġval Ġfully Signed Tx Ġ= Ġflow Engine . sub Flow ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCollect Signatures Flow ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpart Signed Tx , Ġset Of ( other Party Session ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠStage Ġ 5 . ĊĠĠĠĠĠĠĠ Ġ// ĠNot ar ise Ġand Ġrecord Ġthe Ġtransaction Ġin Ġboth Ġparties ' Ġvault s . ĊĠĠĠĠĠĠĠ Ġval Ġnot ar ised Tx Ġ= Ġflow Engine . sub Flow ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠFinal ity Flow ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfully Signed Tx , Ġset Of ( other Party Session ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġreturn ĠSigned Transaction Digest ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnot ar ised Tx . id , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnot ar ised Tx . tx . output States . map Ġ{ Ġoutput Ġ-> Ġjson Marshall ing Service . format Json ( output ) Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnot ar ised Tx . sigs ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ Ċ } Ċ Ċ @ Initi ated By ( Template Flow :: class ) Ċ class ĠTemplate Flow Accept or ( val Ġother Party Session : ĠFlow Session ) Ġ: ĠFlow < Signed Transaction > Ġ{ ĊĠĠĠ Ġ@ C ord a Inject ĊĠĠĠ Ġlateinit Ġvar Ġflow Engine : ĠFlow Engine ĊĊĠĠĠ Ġ// Ġinstead , Ġfor Ġnow , Ġdoing Ġthis Ġso Ġit Ġcan Ġbe Ġunit Ġtested Ġseparately : ĊĠĠĠ Ġfun ĠisValid ( st x : ĠSigned Transaction ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrequire That Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġoutput Ġ= Ġst x . tx . outputs . single (). data ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" This Ġmust Ġbe Ġan ĠTemplate State Ġtransaction ." Ġusing Ġ( output Ġis ĠTemplate State ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsign Transaction Flow Ġ= Ġobject Ġ: ĠSign Transaction Flow ( other Party Session ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcheck Transaction ( st x : ĠSigned Transaction ) Ġ= ĠisValid ( st x ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġtx Id Ġ= Ġflow Engine . sub Flow ( sign Transaction Flow ). id ĊĠĠĠĠĠĠĠ Ġreturn Ġflow Engine . sub Flow ( Receive Final ity Flow ( other Party Session , Ġexpected Tx Id Ġ= Ġtx Id )) ĊĠĠĠ Ġ} Ċ }