package Ġcom . r 3 . cord a . lib . tokens . workflows . utilities Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġcom . r 3 . cord a . lib . tokens . contracts . states . Abstract Token Ċ import Ġcom . r 3 . cord a . lib . tokens . workflows . internal . flows . distribution . has Distribution Record Ċ import Ġcom . r 3 . cord a . lib . tokens . workflows . internal . schemas . Distribution Record Ċ import Ġnet . cord a . core . contracts . Command With Part ies Ċ import Ġnet . cord a . core . contracts . Contract State Ċ import Ġnet . cord a . core . contracts . State And Ref Ċ import Ġnet . cord a . core . contracts . Unique Identifier Ċ import Ġnet . cord a . core . flows . Flow Logic Ċ import Ġnet . cord a . core . flows . Flow Session Ċ import Ġnet . cord a . core . identity . Abstract Party Ċ import Ġnet . cord a . core . identity . Party Ċ import Ġnet . cord a . core . node . Service Hub Ċ import Ġnet . cord a . core . node . services . Identity Service Ċ import Ġnet . cord a . core . transactions . Ledger Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġjava . security . PublicKey Ċ Ċ /** Ċ Ġ* ĠUtility Ġfunction Ġto Ġpersist Ġa Ġnew Ġentity Ġpert aining Ġto Ġa Ġdistribution Ġrecord . Ċ Ġ* ĠTODO : ĠAdd Ġsome Ġerror Ġhandling . Ċ Ġ*/ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. add Party To Distribution List ( party : ĠParty , Ġlinear Id : ĠUnique Identifier ) Ġ{ ĊĠĠĠ Ġ// ĠCreate Ġan Ġpersist Ġa Ġnew Ġentity . ĊĠĠĠ Ġval Ġhas Record Ġ= Ġhas Distribution Record ( service Hub , Ġlinear Id , Ġparty ) ĊĠĠĠ Ġif Ġ(! has Record ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdistribution Record Ġ= ĠDistribution Record ( linear Id . id , Ġparty ) ĊĠĠĠĠĠĠĠ Ġservice Hub . with EntityManager Ġ{ Ġpersist ( distribution Record ) Ġ} ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info (" Already Ġstored Ġa Ġdistribution Ġrecord Ġfor Ġ$ party Ġand Ġ$ linear Id .") ĊĠĠĠ Ġ} Ċ Ċ } Ċ Ċ val ĠLed ger Transaction . participants : ĠList < Abstract Party > ĊĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinput Participants Ġ= Ġinput States . flatMap ( Contract State :: participants ) ĊĠĠĠĠĠĠĠ Ġval Ġoutput Participants Ġ= Ġoutput States . flatMap ( Contract State :: participants ) ĊĠĠĠĠĠĠĠ Ġreturn Ġinput Participants Ġ+ Ġoutput Participants ĊĠĠĠ Ġ} Ċ Ċ @ Suspend able Ċ fun ĠLed ger Transaction . our Signing Keys ( services : ĠService Hub ): ĠList < PublicKey > Ġ{ ĊĠĠĠ Ġval Ġsigning Keys Ġ= Ġcommands . flatMap ( Command With Part ies <* >:: sign ers ) ĊĠĠĠ Ġreturn Ġservices . key Management Service . filter My Keys ( signing Keys ). toList () Ċ } Ċ Ċ @ Suspend able Ċ fun ĠAbstract Party . to Party ( services : ĠService Hub ) Ġ= Ġservices . identity Service . require Known Conf idential Identity ( this ) Ċ Ċ @ Suspend able Ċ fun ĠList < Abstract Party >. to Well Known Part ies ( services : ĠService Hub ): ĠList < Party > Ġ{ ĊĠĠĠ Ġreturn Ġmap ( services . identity Service :: require Known Conf idential Identity ) Ċ } Ċ Ċ // ĠNeeds Ġto Ġdeal Ġwith Ġconf idential Ġident ities . Ċ @ Suspend able Ċ fun Ġrequire Sessions For Participants ( participants : ĠCollection < Party >, Ġsessions : ĠList < Flow Session >) Ġ{ ĊĠĠĠ Ġval Ġsession Part ies Ġ= Ġsessions . map ( Flow Session :: counter party ) ĊĠĠĠ Ġrequire ( session Part ies . contains All ( participants )) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmissing Ġ= Ġparticipants Ġ- Ġsession Part ies ĊĠĠĠĠĠĠĠ Ġ" There Ġshould Ġbe Ġa Ġflow Ġsession Ġfor Ġall Ġstate Ġparticipants . ĠS essions Ġare Ġmissing Ġfor Ġ$ missing ." ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. sessions For Participants ( states : ĠList < Contract State >): ĠList < Flow Session > Ġ{ ĊĠĠĠ Ġval Ġstate Part ies Ġ= Ġstates . flatMap ( Contract State :: participants ) ĊĠĠĠ Ġreturn Ġsessions For Part ies ( state Part ies ) Ċ } Ċ Ċ @ Suspend able Ċ fun ĠFlow Logic <* >. sessions For Part ies ( part ies : ĠList < Abstract Party >): ĠList < Flow Session > Ġ{ ĊĠĠĠ Ġval Ġwell Known Part ies Ġ= Ġparties . to Well Known Part ies ( service Hub ) ĊĠĠĠ Ġreturn Ġwell Known Part ies . map (:: init iate Flow ) Ċ } Ċ Ċ // ĠExtension Ġfunction Ġthat Ġhas Ġn icer Ġerror Ġmessage Ġthan Ġthe Ġdefault Ġone Ġfrom Ġ[ Identity Service :: require Well Known Party From Anonymous ]. Ċ @ Suspend able Ċ fun ĠIdentity Service . require Known Conf idential Identity ( party : ĠAbstract Party ): ĠParty Ġ{ ĊĠĠĠ Ġreturn Ġwell Known Party From Anonymous ( party ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠIllegalArgumentException (" Called Ġflow Ġwith Ġanonymous Ġparty Ġthat Ġnode Ġdoesn 't Ġknow Ġabout . Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Make Ġsure Ġthat ĠRequest Conf idential Identity Ġflow Ġis Ġcalled Ġbefore .") Ċ } Ċ Ċ // ĠUtilities Ġfor Ġensuring Ġthat Ġthe Ġcorrect ĠJ AR Ġwhich Ġimplements ĠTokenType Ġis Ġadded Ġto Ġthe Ġtransaction . Ċ Ċ fun Ġadd TokenType Jar ( tokens : ĠList < Abstract Token >, Ġtransaction Builder : ĠTransaction Builder ) Ġ{ ĊĠĠĠ Ġtokens . forEach Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠIf Ġthere 's Ġno ĠJ AR Ġhash Ġthen Ġwe Ġdon 't Ġneed Ġto Ġdo Ġanything . ĊĠĠĠĠĠĠĠ Ġval Ġhash Ġ= Ġit . token Type Jar Hash Ġ?: Ġreturn ĊĠĠĠĠĠĠĠ Ġif Ġ(! transaction Builder . attachments (). contains ( hash )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction Builder . add Attachment ( hash ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ fun Ġadd TokenType Jar ( tokens : ĠIterable < State And Ref < Abstract Token >>, Ġtransaction Builder : ĠTransaction Builder ) Ġ{ ĊĠĠĠ Ġadd TokenType Jar ( tokens . map Ġ{ Ġit . state . data Ġ}, Ġtransaction Builder ) Ċ } Ċ Ċ fun Ġadd TokenType Jar ( change Output : ĠAbstract Token , Ġtransaction Builder : ĠTransaction Builder ) Ġ{ ĊĠĠĠ Ġadd TokenType Jar ( listOf ( change Output ), Ġtransaction Builder ) Ċ } Ċ Ċ fun Ġadd TokenType Jar ( input : ĠState And Ref < Abstract Token >, Ġtransaction Builder : ĠTransaction Builder ) Ġ{ ĊĠĠĠ Ġadd TokenType Jar ( input . state . data , Ġtransaction Builder ) Ċ } ĊĊ