-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle interface methods in LF conversion (#11054)
changelog_begin changelog_end
- Loading branch information
1 parent
87ecf1f
commit 6d8cf70
Showing
3 changed files
with
110 additions
and
14 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
46 changes: 46 additions & 0 deletions
46
compiler/damlc/tests/daml-test-files/InterfaceMethods.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,46 @@ | ||
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- @SINCE-LF-FEATURE DAML_INTERFACE | ||
|
||
-- TODO https://github.com/digital-asset/daml/issues/11006 | ||
-- Merge into Interface once methods are supported on the scala side. | ||
-- @ERROR Expr.call_interface not yet implemented | ||
module InterfaceMethods where | ||
|
||
interface Token where | ||
getAmount : Decimal | ||
choice Split : (ContractId Token, ContractId Token) | ||
with | ||
splitAmount : Decimal | ||
|
||
choice Transfer : ContractId Token | ||
with | ||
newOwner : Party | ||
|
||
template Asset | ||
with | ||
issuer : Party | ||
owner : Party | ||
amount : Decimal | ||
where | ||
signatory issuer, owner | ||
implements Token where | ||
let getAmount = amount | ||
choice Split : (ContractId Token, ContractId Token) | ||
with | ||
splitAmount : Decimal | ||
controller owner | ||
do | ||
assert (splitAmount < amount) | ||
cid1 <- create this with amount = splitAmount | ||
cid2 <- create this with amount = amount - splitAmount | ||
pure (toTokenContractId cid1, toTokenContractId cid2) | ||
|
||
choice Transfer : ContractId Token | ||
with | ||
newOwner : Party | ||
controller owner, newOwner | ||
do | ||
cid <- create this with owner = newOwner | ||
pure (toTokenContractId cid) |