forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java bindings/interface support (digital-asset#13366)
* WIP * First working version of java codegen daml interface support * Update language-support/java/codegen/BUILD.bazel Co-authored-by: Remy <remy.haemmerle@daml.com> * Fix compile errors * Simplify code massivly, enjoy less duplication changelog_begin - The Java codegen now has basic support for daml interface definitions. Converting a contract id of a template implementing an interface to a contract id of the interface is possible and both executing interface choices is possible on the contract id of the interface and implementing template. changelog_end * Rename the test file to reflect it is a test file & enhance the inner test name & extend it further * Fix test * Refactor parts of TemplateClass.scala into multiple files * Format that files! * Minimize duplication further * Remove unused comment * Simplify code Co-authored-by: Stephen Compall <stephen.compall@daml.com> * Update language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/CodeGenRunner.scala Co-authored-by: Stephen Compall <stephen.compall@daml.com> * Further refactoring and renaming of the TemplateClassSpec to ContractIdClassBuilderSpec * Fix formatting * Add interface docs * Remove unnecessary code generation of the Contract class for interface types * Use less bool flags and more good function names :) * Fix build Co-authored-by: Remy <remy.haemmerle@daml.com> Co-authored-by: Stephen Compall <stephen.compall@daml.com>
- Loading branch information
1 parent
e724bef
commit cc06073
Showing
23 changed files
with
902 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
docs/source/app-dev/bindings-java/code-snippets/Interfaces.daml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- start snippet: interface example | ||
module Interfaces where | ||
|
||
interface TIf where | ||
getOwner: Party | ||
dup: Update (ContractId TIf) | ||
choice Ham: ContractId TIf with | ||
controller getOwner this | ||
do dup this | ||
choice Useless: ContractId TIf with | ||
interfacely: ContractId TIf | ||
controller getOwner this | ||
do | ||
dup this | ||
|
||
template Child | ||
with | ||
party: Party | ||
where | ||
signatory party | ||
choice Bar: () with | ||
controller party | ||
do | ||
return () | ||
|
||
implements TIf where | ||
getOwner = party | ||
dup = toInterfaceContractId <$> create this | ||
-- end snippet: interface example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
language-support/java/codegen/src/ledger-tests/daml/Interfaces.daml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
module Interfaces where | ||
|
||
interface TIf where | ||
getOwner: Party | ||
dup: Update (ContractId TIf) | ||
choice Ham: ContractId TIf with | ||
controller getOwner this | ||
do dup this | ||
choice Useless: ContractId TIf with | ||
interfacely: ContractId TIf | ||
controller getOwner this | ||
do | ||
dup this | ||
|
||
template Child | ||
with | ||
party: Party | ||
where | ||
signatory party | ||
choice Bar: () with | ||
controller party | ||
do | ||
return () | ||
|
||
implements TIf where | ||
getOwner = party | ||
dup = toInterfaceContractId <$> create this |
39 changes: 39 additions & 0 deletions
39
language-support/java/codegen/src/ledger-tests/scala/com/digitalasset/InterfacesTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml | ||
|
||
import com.daml.ledger.api.testing.utils.SuiteResourceManagementAroundAll | ||
import com.daml.ledger.resources.TestResourceContext | ||
import org.scalatest.flatspec.AsyncFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class Interfaces | ||
extends AsyncFlatSpec | ||
with SandboxTestLedger | ||
with Matchers | ||
with TestResourceContext | ||
with SuiteResourceManagementAroundAll { | ||
|
||
import TestUtil._ | ||
|
||
behavior of "Generated Java code" | ||
|
||
it should "contain all choices of an interface in templates implementing it" in withClient { | ||
client => | ||
for { | ||
alice <- allocateParty | ||
} yield { | ||
sendCmd(client, alice, interfaces.Child.create(alice)) | ||
readActiveContracts(interfaces.Child.Contract.fromCreatedEvent)(client, alice).foreach { | ||
child => | ||
sendCmd(client, alice, child.id.exerciseHam(new interfaces.Ham())) | ||
} | ||
readActiveContracts(interfaces.Child.Contract.fromCreatedEvent)(client, alice).foreach { | ||
child => | ||
sendCmd(client, alice, child.id.toTIf.exerciseHam(new interfaces.Ham())) | ||
} | ||
succeed | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.