How to use qualified template names in REPL queries?

I’m running the paint agreement use case on Canton, and trying to query the PaintHouse contract instances using DAML REPL, attached to a Canton participant node.

The problem is that the package contains two PaintHouse templates, one in the Paint module and another in the SafePaint module.

So I’m trying to use the qualified Paint.PaintHouse template name in the REPL query, but keep running into a strange error message:

balazsigyorgy@Orss-MacBook-Air ~ % daml repl --ledger-host=localhost --ledger-port=5021 /Users/balazsigyorgy/canton-0.18.2/dars/CantonExamples.dar  --import CantonExamples
daml> Some details <- find (\d -> d.displayName == Some "Alice") <$> listKnownParties
daml> let alice = details.party
daml> alice
'Alice::01e74ceb0405f555dc0b05e682bf1f57a75e499084d445176eea2354dad7291dbc'
daml> ph <- query @Paint.PaintHouse alice
daml> ph
File:     Line4.daml
Hidden:   no
Range:    13:60-13:70
Source:   typecheck
Severity: DsError
Message: 
  Line4.daml:13:61: error:
  Ambiguous occurrence ‘PaintHouse’
  It could refer to
  either ‘Paint.PaintHouse’,
  imported from ‘Paint’ at Line4.daml:10:1-12
  or ‘SafePaint.PaintHouse’,
  imported from ‘SafePaint’ at Line4.daml:11:1-16
File:     Line4.daml
Hidden:   no
Range:    13:72-13:82
Source:   typecheck
Severity: DsError
Message: 
  Line4.daml:13:73: error:
  Ambiguous occurrence ‘PaintHouse’
  It could refer to
  either ‘Paint.PaintHouse’,
  imported from ‘Paint’ at Line4.daml:10:1-12
  or ‘SafePaint.PaintHouse’,
  imported from ‘SafePaint’ at Line4.daml:11:1-16
daml> 

I have already run the PaintScenario.sc Scala script (see Getting Started — Canton 0.22.0 documentation), and the query using the Scala REPL returns the following result:

@ participant1.ledger_api.acs.of_all().filter(_.templateId == "Paint.PaintHouse").map(_.arguments) 
res17: Seq[Map[String, Any]] = ListBuffer(
  Map("painter" -> "Bob::01d78c99e87c61d360930cf413c7d03dcbdd8882ad63d18dee2db1a20952c19b49", "houseOwner" -> "Alice::01e74ceb0405f555dc0b05e682bf1f57a75e499084d445176eea2354dad7291dbc")
)
1 Like

Hi @gyorgybalazsi, unfortunately I cannot reproduce this:

moritz@adjunction ~/D/c/d/CantonExamples> DAML_SDK_VERSION=1.5.0 daml repl .daml/dist/CantonExamples-0.18.2.dar --import CantonExamples --ledger-host localhost --ledger-port 6865
daml> p <- allocateParty "p"
daml> query @PaintHouse p
File:     Line1.daml
Hidden:   no
Range:    15:23-15:33
Source:   typecheck
Severity: DsError
Message: 
  Line1.daml:15:24: error:
  Ambiguous occurrence ‘PaintHouse’
  It could refer to
  either ‘Paint.PaintHouse’,
  imported from ‘Paint’ at Line1.daml:10:1-12
  or ‘SafePaint.PaintHouse’,
  imported from ‘SafePaint’ at Line1.daml:11:1-16
daml> query @Paint.PaintHouse p
[]

Which SDK version are you using? I tried this with 1.5.0, the 1.5.0 snapshot used in the latest canton release as well as the latest 1.6.0 snapshot 1.6.0-snapshot.20200930.5312.0.b9a1905d.

2 Likes

I didn’t modify the default SDK version of Canton

1 Like

Could you try running this and query-ing for a party which actually has a “Paint.Painthouse” contract? I think the problem occurs when you want to print out the non-empty result.

I have already run the PaintScenario.sc Scala script (see Getting Started — Daml SDK 2.6.5 documentation).

1 Like

I’ve tried that as well but it seems to work just fine:

moritz@adjunction ~/D/c/d/CantonExamples>  daml repl .daml/dist/CantonExamples-0.18.2.dar --import CantonExamples --ledger-host localhost --ledger-port 6865
DAML SDK 1.5.0 has been released!
See https://github.com/digital-asset/daml/releases/tag/v1.5.0 for details.

daml> p <- allocateParty "p"
daml> query @Paint.PaintHouse p
[]
daml> submit p $ createCmd (Paint.PaintHouse p p)
c<contract-id>
daml> query @Paint.PaintHouse p
[(<contract-id>,PaintHouse {painter = 'party-833d2323', houseOwner = 'party-833d2323'})]
1 Like

If I create the contract your way, I get the same result as you. But if I run the Scala script according to the instructions in the docs, I get the error.

Anyways, now I know what is the correct way of using query in REPL.

1 Like

Oh I see what the issue is:

daml> query @Paint.PaintHouse p

works fine and prints out the contratcs.

daml> cs <- query @Paint.PaintHouse p
daml> cs

fails.

That’s definitely a bug, we’ll look into it and get back to you when it’s fixed.

2 Likes

Yess, one more bug in my collection…

1 Like

Hi @gyorgybalazsi, we’ve just merged the fix for this in https://github.com/digital-asset/daml/pull/7544 so it will land in next weeks snapshot (it’s probably not going to make it into 1.6 since it’s a bit too late for that).

2 Likes

Thank you!

1 Like

Hi @gyorgybalazsi,we’ve just released 1.7.0-snapshot.20201006.5358.0.0c1cadcf which should fix this issue.

2 Likes

Thansks, will try!

1 Like

Perfect, thank you:

daml> alice <- allocatePartyWithHint "Alice" (PartyIdHint "alice")
daml> painter <- allocatePartyWithHint "Painter" (PartyIdHint "painter")
daml> bank <- allocatePartyWithHint "Bank" (PartyIdHint "bank") 
daml> iouCid <- submit bank $ createCmd $ Iou bank alice (Amount 100.0 "USD") [painter]
daml> offerCid <- submit alice $ createCmd $ OfferToPaintHouseByOwner alice painter bank iouCid
daml> submit painter $ exerciseCmd offerCid AcceptByPainter
<contract-id>
daml> [(cid,c)] <- query @Paint.PaintHouse alice
daml> c
PaintHouse {painter = 'painter', houseOwner = 'alice'}
daml> 
2 Likes