-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LF: builtins to create, signatory, and obersver on interface payload.
CHANGELOG_BEGIN CHANGELOG_END
- Loading branch information
1 parent
b9a5a83
commit 9bfb529
Showing
6 changed files
with
119 additions
and
6 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
21 changes: 21 additions & 0 deletions
21
compiler/damlc/daml-stdlib-src/DA/Experimental/Interface.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,21 @@ | ||
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
{-# LANGUAGE CPP #-} | ||
|
||
module DA.Experimental.Interface( | ||
interfaceCreate, | ||
interfaceSignatory, | ||
interfaceObserver, | ||
) where | ||
|
||
import GHC.Types (primitive) | ||
|
||
interfaceCreate: t -> Update (ContractId t) | ||
interfaceCreate = primitive @"$INTERFACE_CREATE" | ||
|
||
interfaceSignatory: t -> [Party] | ||
interfaceSignatory = primitive @"$INTERFACE_SIGNATORIES" | ||
|
||
interfaceObserver: t -> [Party] | ||
interfaceObserver = primitive @"$INTERFACE_OBSERVERS" |
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
74 changes: 74 additions & 0 deletions
74
compiler/damlc/tests/daml-test-files/InterfaceExperimental.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,74 @@ | ||
-- 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/10810 | ||
-- DROP when we have more meaningful test for create, signatories, observers | ||
module InterfaceExperimental where | ||
|
||
import DA.Assert ((===)) | ||
import DA.Experimental.Interface | ||
import GHC.Types (primitive) | ||
|
||
interface Token where | ||
getAmount : Int | ||
|
||
choice Split : (ContractId Token, ContractId Token) | ||
with | ||
splitAmount : Int | ||
|
||
choice Transfer : ContractId Token | ||
with | ||
newOwner : Party | ||
|
||
nonconsuming choice Noop : () | ||
with | ||
nothing : () | ||
|
||
template Asset | ||
with | ||
issuer : Party | ||
owner : Party | ||
amount : Int | ||
where | ||
signatory issuer | ||
observer issuer, owner | ||
implements Token where | ||
let getAmount = amount | ||
|
||
choice Split : (ContractId Token, ContractId Token) | ||
with | ||
splitAmount : Int | ||
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) | ||
|
||
nonconsuming choice Noop : () | ||
with | ||
nothing : () | ||
controller owner | ||
do | ||
pure () | ||
|
||
main = scenario do | ||
alice <- getParty "Alice" | ||
bob <- getParty "Bob" | ||
let asset = Asset alice bob 15 | ||
let token = toToken asset | ||
submit alice do | ||
interfaceCreate token | ||
interfaceSignatory token === [alice] | ||
interfaceObserver token === [bob, alice] | ||
pure () |
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