Refer to PartyId in Canton setup of multiple hosts

Hi Team,

I am testing Canton community 0.23.0, and use examples/03 to build a 2-pn-1-domain setup in three AWS EC2 instances. The setup and connection of PN to domain works well.

I’m using the same flow of PaintScenario.sc and do it through Canton REPL.

In participant1,
var alice = participant1.parties.enable("Alice")

In participant2,
var bob = participant2.parties.enable("Bob")
var bank = participant2.parties.enable("Bank")

The question come out that, in participant2, I try to create command (bank issues Iou to alice), where I need to refer to the PartyId of alice. Since alice never appears in participant2, I can’t use alice.toPrim. How can I refer to alice as PartyId from participant2?

In fact Alice is visible in participant2 through participant2.parties.list() but I have no clue how to extract this as a PartyId for alice.

Thanks in advance.

kc

1 Like

Hi @kctam

The alice.toPrim turns a Canton party id into a scala ledger client bindings party Scala bindings — Daml SDK 1.13.0 documentation. So that’s just a helper in order to make use of Scala code generation within a Canton console.

In order to get Alice’ party on P2, you have several options. First, you can use list

@ participant2.parties.list(filterParty="Alice").map(_.party).head.toPrim
res7: com.daml.ledger.client.binding.package.Primitive.Party = "Alice::1220936b34d2160f2e220ec78fc78cc9bd077f7fd3aca9d419f99d0183c5d21805b1"

Or to assume that you’ve learned the party id out of band and you put it into a P.Party (ledger client bindings).

@ P.Party("Alice::1220936b34d2160f2e220ec78fc78cc9bd077f7fd3aca9d419f99d0183c5d21805b1")
res8: scalaz.package.@@[String, com.daml.ledger.api.refinements.ApiTypes.PartyTag] = "Alice::1220936b34d2160f2e220ec78fc78cc9bd077f7fd3aca9d419f99d0183c5d21805b1"

Or you can also create a PartyId directly to use toPrim:

@ PartyId.tryFromProtoPrimitive("Alice::1220936b34d2160f2e220ec78fc78cc9bd077f7fd3aca9d419f99d0183c5d21805b1")
res9: PartyId = Alice::1220936b34d2...

Does that help?

Cheers,
Ratko

2 Likes

Thanks Ratko. It works well.

Possibly a final question following my test: now I need to obtain the active contracts (Iou.Iou Contract and Paint.OfferToPaintHouseByPainter) which were created in P2 (by Bank and Bob, respectively). It is easy when it’s done in one host but similarly, I need to obtain this in P1 in this multi-host setup. I think we have some way to get it back through ledger_api in P1 such that alice can accept the offer.

Sorry that I’m new in this area so just try to learn more. Thanks again for your help.

Thanks in advance… kc

1 Like

Indeed, any distributed setup adds complexity. You might want to look at the

participant.ledger_api.acs.* 

functions, in particular at

participant.ledger_api.acs.await

which you can use as

participant.ledger_api.acs.await(alice, Iou.Iou)

This will then wait for the contract. There is also a predicate argument that lets you filter on the contract arguments.

All these steps are fine for setups / demos. In a true system, you would rather use Daml Triggers - Off-Ledger Automation in Daml — Daml SDK 1.13.0 documentation or write your on reactive automation logic using the ledger api and writing your own bindings / Java bindings — Daml SDK 1.13.0 documentation.

Or you would use humans and write a UI so that they react to events.

2 Likes

Thanks @Ratko_Veprek . Reallly appreciate your prompt response. Everything works fine. I can deploy a multi-host setup for examples/01.

At this moment I am more just repeating the example in a multi-host setup. When I’m building something for demonstration, I definitely use the methods you suggested.

Thanks again and have a great day!

cheers, kc

1 Like

Only as a last resort of course, humans are far too messy

1 Like