package Ġcom . trade ix . contract composition . workflows . flows ĊĊ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġcom . trade ix . contract composition . contracts . Composite Contract Ċ import Ġcom . trade ix . contract composition . contracts . commands . Ful fill Ref Inputs Command Ċ import Ġcom . trade ix . contract composition . contracts . common . State Ref Or Ref Ċ import Ġcom . trade ix . contract composition . contracts . states .* Ċ import Ġcom . trade ix . contract composition . workflows . utilities .* Ċ import Ġnet . cord a . core . contracts .* Ċ import Ġnet . cord a . core . flows .* Ċ import Ġnet . cord a . core . identity . Party Ċ import Ġnet . cord a . core . identity . group Abstract Party By Well Known Party Ċ import Ġnet . cord a . core . internal . sign With Cert Ċ import Ġnet . cord a . core . node . Service Hub Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġjava . io . IOException Ċ import Ġjava . lang . Exception Ċ import Ġjava . lang . IllegalArgumentException Ċ import Ġjava . security . PublicKey Ċ import Ġjava . time . Duration Ċ import Ġjava . time . Instant Ċ Ċ /** Ċ Ġ* ĠThis Ġis Ġanother Ġexample Ġflow Ġwhich Ġallows Ġfulfill ment Ġof Ġany Ġstandard Ġcontract . Ċ Ġ* Ċ Ġ* ĠIt Ġwill Ġneed Ġto Ġbe Ġextended Ġin Ġfuture Ġto Ġallow Ġmore Ġflexibility Ġfor Ġclients Ġto Ġinstruct Ġthis Ġflow Ġon Ġhow Ġthey Ġwant Ċ Ġ* Ġto Ġfulfill Ġspecific Ġsub - contracts Ġwhich Ġfall Ġunder Ġthe Ġmain Ġone . ĠThis Ġwill Ġbecome Ġespecially Ġimportant Ġas Ġwe Ġgo Ċ Ġ* Ġfrom ĠMultip ath Ġcontracts Ġ( where Ġthe Ġclient Ġsimply Ġneeds Ġto Ġspecify Ġthe Ġpath Ġwe Ġshould Ġtake Ġto Ġbuild Ġthe Ġtransaction ) Ċ Ġ* Ġto ĠVariable path Ġcontracts Ġ( where Ġvalid Ġpaths Ġare Ġcalculated Ġon Ġthe Ġfly Ġrather Ġthan Ġpre - built Ġinto Ġthe Ġcontract Ġstate ). Ċ Ġ* Ċ Ġ* ĠFor Ġnow , Ġhowever , Ġclients Ġcan Ġonly Ġinstruct Ġthis Ġflow Ġabout ĠA .) Ġwhich Ġpath Ġto Ġtake Ġwhen Ġit Ġencounter s Ġa ĠMultip ath Ċ Ġ* Ġand ĠB .) Ġwhat Ġnew Ġcontract Ġto Ġcreate Ġwhen Ġit Ġencounter s Ġa ĠF ul filled By New Contract Ċ Ġ* Ċ Ġ* ĠThe Ġclass Ġis Ġopen Ġso Ġthat Ġit Ġcan Ġbe Ġextended Ġto Ġdeal Ġwith Ġmore Ġcomplex Ġtypes Ġof Ġfulfill ment Ġrequirements Ġin Ġfuture Ċ Ġ* Ġ( e . g . Ġa ĠF ul filled By New Contract Ġwhich Ġneeds Ġa ĠF ul filled Contracts State Ġas Ġan Ġoutput Ġand Ġtherefore Ġneeds Ġto Ġquery Ġthe Ċ Ġ* Ġvault Ġto Ġfind Ġthe Ġbest Ġway Ġto Ġcreate Ġthe Ġrequired Ġoutput ) Ċ Ġ*/ Ċ Ċ // Prob ably Ġshouldn 't Ġbe Ġiniti ating Ġbut Ġis Ġfor Ġnow Ġso Ġit 's Ġeasier Ġto Ġtest Ċ @ Initi ating Flow Ċ @ Start able By RPC Ċ open Ġclass ĠF ul fill Standard Contract Flow ( ĊĠĠĠĠĠĠĠ Ġ// ĠState Ġcould Ġbe Ġresolved Ġin Ġthis Ġflow Ġbut Ġfor Ġnow Ġwe 'll Ġsay Ġit 's Ġresolved Ġoutside Ġand Ġpassed Ġin Ġas ĠState And Ref ĊĠĠĠĠĠĠĠ Ġval Ġcontract To Ful fill : ĠState And Ref < Contract State >, ĊĠĠĠĠĠĠĠ Ġval Ġnot ary : ĠParty , ĊĠĠĠĠĠĠĠ Ġ// ĠOnly Ġpopulated Ġif Ġwe Ġwant Ġto Ġsend Ġthis Ġtx Ġto Ġparties Ġin Ġaddition Ġthose Ġon Ġparticipants Ġlist ĊĠĠĠĠĠĠĠ Ġval Ġsessions : ĠList < Flow Session > Ġ= ĠlistOf (), ĊĠĠĠĠĠĠĠ Ġval Ġpaths To Ful fill : ĠMap < State Ref , ĠState Ref Or Ref > Ġ= Ġempty Map (), ĊĠĠĠĠĠĠĠ Ġval Ġtickets ToUse : ĠMap < State Ref , ĠState And Ref < Ful filled Contracts State >> Ġ= Ġempty Map (), ĊĠĠĠĠĠĠĠ Ġval Ġnew Contracts To Create : ĠMap < State Ref , ĠContract State > Ġ= Ġempty Map () Ċ ): ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠ Ġprivate Ġval Ġrequired Signatures Ġ= Ġmutable ListOf < PublicKey >() ĊĠĠĠ Ġprivate Ġval Ġtransaction Builder Ġ= ĠTransaction Builder ( not ary Ġ= Ġnot ary ) ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠFirst , Ġwe Ġsimply Ġadd Ġthe Ġstate Ġwhich Ġclient Ġhas Ġasked Ġus Ġto Ġfulfill Ġto Ġref Ġinputs Ġlist ĊĠĠĠĠĠĠĠ Ġtransaction Builder . add Reference State ( Referenced State And Ref ( contract To Ful fill )) ĊĠĠĠĠĠĠĠ Ġ// ĠThen Ġwe Ġcreate Ġa ĠF ul filled Contracts State Ġas Ġproof Ġthat Ġthe Ġabove Ġwas Ġful filled Ġin Ġcase Ġclient Ġneeds Ġit Ġlater ĊĠĠĠĠĠĠĠ Ġ// ĠMay Ġwant Ġto Ġgive Ġthem Ġthe Ġoption Ġto Ġtell Ġus Ġin Ġthe Ġconstructor Ġif Ġthey Ġwould Ġlike Ġproof Ġof Ġany Ġsub contract ĊĠĠĠĠĠĠĠ Ġ// ĠThere Ġdefinitely Ġmay Ġbe Ġcases Ġwhen Ġthey Ġdo . ĠFor Ġexample , Ġfun der Ġtakes Ġback Ġtheir Ġcoll ateral Ġwith Ġa Ġhigher ĊĠĠĠĠĠĠĠ Ġ// Ġcontract Ġbut Ġwants Ġto Ġretain Ġproof Ġof Ġtrade Ġpayment Ġso Ġthey Ġcan Ġuse Ġthat Ġlater Ġif Ġsupplier Ġdefaults ĊĠĠĠĠĠĠĠ Ġtransaction Builder . add Output State ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstate Ġ= ĠF ul filled Contracts State ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġful filled Contracts Ġ= ĠlistOf ( contract To Ful fill . ref ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠJust Ġneeds Ġto Ġexist , Ġits Ġfulfill ment Ġis Ġir relevant . ĠSo Ġwill Ġjust Ġpoint Ġto Ġitself Ġfor Ġrequired Ġcontracts Ġ( ess entially Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontracts Ġ= ĠlistOf ( State Ref Or Ref ( ref Ġ= Ġ 0 )), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġparticipants Ġ= Ġcontract To Ful fill . state . data . participants )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠOur Ġful filled Ġref Ġinputs Ġlist Ġwill Ġbe Ġthe Ġindex Ġof Ġthe Ġref Ġinput Ġwe Ġjust Ġadded Ġand Ġall Ġthe Ġindices Ġof Ġthe ĊĠĠĠĠĠĠĠ Ġ// Ġother Ġcontracts Ġ( if Ġany ) Ġwe Ġneed Ġto Ġalso Ġfulfill Ġin Ġorder Ġto Ġfulfill Ġthe Ġtop - tier Ġcontract ĊĠĠĠĠĠĠĠ Ġval Ġful filled Ref Inputs Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( transaction Builder . reference States (). size Ġ- Ġ 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfulfill Contract ByType ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠ Ġ// Ġadd Ġcommand ĊĠĠĠĠĠĠĠ Ġif Ġ( required Signatures . isEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequired Signatures . add ( service Hub . my Info . legal Id entities . first (). own ing Key ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġtransaction Builder . add Command ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdata Ġ= ĠComposite Contract . Ful fill Composite Contracts ( fulfilled Ref Inputs ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġkeys Ġ= Ġrequired Signatures ) ĊĊĠĠĠĠĠĠĠ Ġval Ġparticipants Ġ= Ġtransaction Builder . output States (). flatMap Ġ{ Ġit . data . participants Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġwell Known Participants Ġ= Ġgroup Abstract Party By Well Known Party ( service Hub , Ġparticipants ). keys Ġ- Ġservice Hub . my Info . legal Id entities ĊĠĠĠĠĠĠĠ Ġval Ġparticipant Sessions Ġ= Ġwell Known Participants . map Ġ{ Ġinitiate Flow ( it ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// Ġfix Ġto Ġsign Ġfor Ġeach Ġkey Ġnot Ġjust Ġthe Ġfirst ĊĠĠĠĠĠĠĠ Ġ// ĠNote Ġthat Ġthis Ġflow Ġonly Ġsupports Ġun il ateral Ġactions Ġmeaning Ġif Ġthere Ġare Ġsignatures Ġwhich Ġare Ġrequired Ġfrom ĊĠĠĠĠĠĠĠ Ġ// Ġother Ġparties Ġon Ġthe Ġnetwork , Ġthis Ġwill Ġfail . ĊĠĠĠĠĠĠĠ Ġval Ġsigned Tx Ġ= Ġservice Hub . sign Initial Transaction ( transaction Builder , Ġrequired Signatures . first ()) ĊĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Final ity Flow ( signed Tx , Ġparticipant Sessions Ġ+ Ġsessions )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// Not Ġsure Ġif Ġthese Ġneed Ġto Ġbe Ġsuspend able Ġbut Ġsetting Ġthem Ġas Ġsuch Ġbecause Ġwas Ġgetting Ġa Ġweird Ġerror Ġin Ġtests ... ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfulfill Contract ByType ( contract To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwhen Ġ( contract To Ful fill . state . data ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠComposite Contract State Ġ-> ĠlistOf ( ful fill Composite Contract ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠMultip ath Contract State Ġ-> ĠlistOf ( ful fill Multip ath Contract ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠDet ached Contract State Ġ-> ĠlistOf ( ful fill Detached Contract ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠDouble S pend Pre vention State Ġ-> ĠlistOf ( ful fill DSP Contract ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠTime Constr ained State Ġ-> ĠlistOf ( ful fill Time Constr ained Contract ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠKey Control State Ġ-> ĠlistOf ( ful fill Key Control Contract ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠF ul filled By New Contract Ġ-> ĠlistOf ( ful fill By New Contract ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠThe Ġtransaction Ġwill Ġnormally Ġfail Ġif Ġthis Ġblock Ġis Ġever Ġreached Ġand Ġthe Ġclass Ġhasn 't Ġbeen Ġextended . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠThis Ġwould Ġmean Ġthe Ġcontracts Ġor Ġone Ġof Ġits Ġsub - contracts Ġis Ġnon - standard Ġand Ġtherefore Ġwe 're Ġnot ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġgoing Ġto Ġdo Ġanything Ġto Ġattempt Ġto Ġfulfill Ġit . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠHowever , Ġwe Ġallow Ġit Ġto Ġbe Ġextended Ġso Ġthat Ġwe Ġcan Ġcreate Ġflows Ġwhich Ġneed Ġto Ġfulfill Ġnon - standard ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġcontracts Ġin Ġthe Ġoverall Ġchain , Ġbut Ġwhich Ġwant Ġto Ġfulfill Ġthe Ġstandard Ġcontracts Ġit Ġsees Ġin Ġthe Ġchain ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġin Ġthe Ġsame Ġway Ġthat Ġthe Ġflow Ġhere Ġhandles Ġthem ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> ĠlistOf ( ful fill Non Standard Contract ( contract To Ful fill )). flatten () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfulfill Composite Contract ( composite Contract To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġadded Ref Indices Ġ= ĠlistOf < Int >() ĊĠĠĠĠĠĠĠ Ġfor Ġ( sub Contract Ġin Ġ(( composite Contract To Ful fill . state . data Ġas ĠComposite Contract State ). contracts )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsub Contract State And Ref Ġ= Ġservice Hub . to State And Ref < Contract State >( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsub Contract . state Ref ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: ĠState Ref ( tx hash Ġ= Ġcomposite Contract To Ful fill . ref . tx hash , Ġindex Ġ= Ġsub Contract . ref !! )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction Builder . add Reference State ( Referenced State And Ref ( sub Contract State And Ref )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadded Ref Indices Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( added Ref Indices , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( transaction Builder . reference States (). size Ġ- Ġ 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfulfill Contract ByType ( sub Contract State And Ref )). flatten () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġadded Ref Indices ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfulfill Multip ath Contract ( multip ath Contract To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġful filled Path Ġ= Ġpaths To Ful fill [ multip ath Contract To Ful fill . ref ] ĊĠĠĠĠĠĠĠ Ġval Ġful filled Path State And Ref Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġservice Hub . to State And Ref < Contract State >( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġful filled Path ?. state Ref Ġ?: ĠState Ref ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtx hash Ġ= Ġmultip ath Contract To Ful fill . ref . tx hash , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġindex Ġ= Ġful filled Path ?. ref !! )) ĊĊĠĠĠĠĠĠĠ Ġtransaction Builder . add Reference State ( Referenced State And Ref ( fulfilled Path State And Ref )) ĊĊĠĠĠĠĠĠĠ Ġreturn ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( transaction Builder . reference States (). size Ġ- Ġ 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfulfill Contract ByType ( fulfilled Path State And Ref )). flatten () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfulfill Detached Contract ( det ached Contract To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġticket ToAdd Ġ= Ġtickets ToUse [ det ached Contract To Ful fill . ref ] ĊĠĠĠĠĠĠĠ Ġtransaction Builder . add Reference State ( Referenced State And Ref ( ticket ToAdd !! )) ĊĠĠĠĠĠĠĠ Ġreturn Ġif Ġ(( det ached Contract To Ful fill . state . data Ġas ĠDet ached Contract State ). det ached Proof Ful filled ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( listOf ( transaction Builder . reference States (). size Ġ- Ġ 1 ), Ġfulfill Contract ByType ( ticket ToAdd )). flatten () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ// ĠIf Ġwe 're Ġnot Ġrequired Ġto Ġfulfill Ġthe Ġproof Ġof Ġprevious Ġfulfill ment Ġ( ticket ), Ġit 's Ġadded Ġas Ġa Ġnormal Ġref Ġinput ĊĠĠĠĠĠĠĠ Ġelse ĠlistOf () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfulfill DSP Contract ( dsp Contract To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġd sp Contract State Ġ= Ġd sp Contract To Ful fill . state . data Ġas ĠDouble S pend Pre vention State ĊĠĠĠĠĠĠĠ Ġval Ġrequired Input State And Ref Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġservice Hub . to State And Ref < Contract State >( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġd sp Contract State . states To Not ar ize . first (). state Ref ?: ĠState Ref ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtx hash Ġ= Ġd sp Contract To Ful fill . ref . tx hash , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġindex Ġ= Ġd sp Contract State . states To Not ar ize . first (). ref !! )) ĊĊĠĠĠĠĠĠĠ Ġtransaction Builder . add Input State ( required Input State And Ref ) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġfulfill Contract ByType ( required Input State And Ref ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠIs Ġit Ġappropriate Ġto Ġput Ġvalidation Ġin Ġhere ? ĠThat Ġis , Ġif Ġwe Ġknow Ġthe Ġtime Ġis Ġnot Ġgoing Ġto Ġmeet Ġthe Ġrequirement ĊĠĠĠ Ġ// Ġin Ġthe ĠTime Constr ained State Ġshould Ġwe Ġthrow Ġan Ġexception Ġor Ġlet Ġthat Ġhappen Ġwhen Ġit Ġgets Ġto Ġverification ? ĊĠĠĠ Ġ// ĠFor Ġnow , ĠI Ġhave Ġnot Ġincluded Ġit . ĠI Ġjust Ġset Ġthe Ġtime Ġwindow Ġand Ġlet Ġthe Ġcontract Ġcode Ġthrow Ġthe Ġerror Ġif Ġneeded ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfulfill Time Constr ained Contract ( time Constr ained Contract To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠBecause Ġwe Ġdon 't Ġhave Ġaccess Ġto Ġthe Ġwindow Ġproperty Ġon Ġthe Ġbuilder , Ġwe Ġcan 't Ġcheck Ġwhether Ġone Ġalready Ġexists ĊĠĠĠĠĠĠĠ Ġ// ĠSo Ġinstead , Ġwe 'll Ġjust Ġadd Ġone Ġregardless Ġof Ġwhether Ġanother Ġis Ġalready Ġthere ĊĠĠĠĠĠĠĠ Ġ// Ġif Ġ( transaction Builder . window Ġ!= Ġnull ) Ġreturn ĠlistOf () ĊĠĠĠĠĠĠĠ Ġ// ĠI Ġhave Ġno Ġidea Ġwhat Ġwe Ġshould Ġset Ġthe Ġtime Ġtolerance Ġto ... need Ġto Ġinvestigate Ġwhat Ġthe Ġdefault Ġshould Ġbe ĊĠĠĠĠĠĠĠ Ġtransaction Builder . setTime Window ( Time Window . with Tolerance ( Instant . now (), ĠDuration . of Seconds ( 1 2 0 ))) ĊĠĠĠĠĠĠĠ Ġreturn ĠlistOf () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠAdd Ġthe Ġkey Ġon Ġthe ĠKey Control Ġstate Ġto Ġthe Ġoverall Ġlist Ġof Ġrequired Ġsignatures Ġwhich Ġwe Ġwill Ġuse Ġat Ġthe Ġend ĊĠĠĠ Ġ// Ġto Ġbuild Ġour Ġfulfill Ġcommand Ġand Ġsign Ġthe Ġtransaction Ġn Ġnumber Ġof Ġtimes . ĊĠĠĠ Ġ// ĠNo Ġadditional Ġful filled Ġref Ġinputs Ġadded Ġso Ġreturn Ġan Ġempty Ġlist ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfulfill Key Control Contract ( key Control State To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġrequired Signatures . add (( key Control State To Ful fill . state . data Ġas ĠKey Control State ). key . own ing Key ) ĊĠĠĠĠĠĠĠ Ġreturn ĠlistOf () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠAdd Ġthe Ġrequired Ġoutput Ġand Ġthen Ġcall Ġinto Ġthe Ġopen Ġfacilitate Contract Creation Ġfunction Ġto Ġdo Ġanything Ġwhich Ġthe ĊĠĠĠ Ġ// Ġoutput 's Ġcontract Ġis Ġgoing Ġto Ġrequire Ġin Ġorder Ġfor Ġit Ġto Ġallow Ġthe Ġoutput Ġto Ġbe Ġvalid ly Ġcreated . ĊĠĠĠ Ġ// ĠFor Ġexample , Ġif Ġwe Ġwere Ġrequired Ġto Ġoutput Ġa Ġcertain ĠF ul filled Contracts State Ġ( as Ġwill Ġbe Ġextremely Ġcommon ) Ġthen ĊĠĠĠ Ġ// Ġwe Ġwould Ġneed Ġthat Ġfunction Ġto Ġgo Ġahead Ġand Ġensure Ġthat Ġall Ġcontracts Ġin Ġthe Ġlist Ġof Ġful filled Ġcontracts Ġon Ġthe ĊĠĠĠ Ġ// ĠF ul filled Contracts State Ġwere Ġalso Ġbeing Ġful filled . ĊĠĠĠ Ġ// ĠWe Ġmay Ġfind Ġthat Ġwe Ġcan Ġeventually Ġhandle Ġthis Ġbit Ġwithin Ġthis Ġclass Ġand Ġcan Ġclose Ġthe Ġfunction , Ġbut Ġit Ġneeds Ġto ĊĠĠĠ Ġ// Ġbe Ġopen Ġfor Ġnow Ġas Ġthere Ġis Ġlogic Ġwe Ġdon 't Ġneed Ġto Ġimplement Ġtoday Ġwhich Ġwill Ġbe Ġabsolutely Ġcritical Ġlater ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfulfill By New Contract ( by New Contract To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠMakes Ġour Ġlives Ġeasier Ġto Ġdeal Ġwith ĠContract States Ġfor Ġnow , Ġbut Ġoutputs Ġshould Ġreally Ġbe Ġspecified Ġas Ġtx States ĊĠĠĠĠĠĠĠ Ġval Ġrequired Output Ġ= Ġnew Contracts To Create [ by New Contract To Ful fill . ref ] ĊĠĠĠĠĠĠĠ Ġif Ġ( required Output Ġ== Ġnull ) Ġthrow ĠIllegalArgumentException () ĊĠĠĠĠĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction Builder . add Output State ( required Output ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠlistOf ( fac ilit ate Contract Creation ( required Output )). flatten () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġopen Ġfun Ġfulfill Non Standard Contract ( non Standard Contract To Ful fill : ĠState And Ref < Contract State >): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠlistOf () ĊĠĠĠ Ġ} ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġopen Ġfun Ġfacilitate Contract Creation ( new Contract : ĠContract State ?): ĠList < Int > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠlistOf () ĊĠĠĠ Ġ} Ċ } Ċ Ċ // ĠCan Ġput Ġlogic Ġin Ġhere Ġto Ġslot Ġful filled Ġcontracts Ġinto Ġa Ġcustom Ġtable Ġor Ġdo Ġwhatever Ġelse Ġwe Ġneed Ġto Ġdo Ġwhen Ġwe Ġhear Ċ // Ġabout Ġcertain Ġcontracts Ġbeing Ġful filled . ĠFor Ġexample , Ġfun der Ġneeds Ġto Ġgo Ġand Ġmake Ġa Ġpayment Ġif Ġthey Ġhere Ġthat Ġsupplier Ċ // Ġhas Ġful filled Ġthe Ġacceptance Ġcontract , Ġin Ġthe Ġcase Ġof Ġreceiv ables Ġdiscount ing Ċ @ Initi ated By ( Ful fill Standard Contract Flow :: class ) Ċ open Ġclass ĠReceive Ful filled Contract Tx ( private Ġval Ġother Side Session : ĠFlow Session ): ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Receive Final ity Flow ( other Side Session Ġ= Ġother Side Session )) ĊĠĠĠ Ġ} Ċ }