Skip to content

Commit

Permalink
Remove uses of 'controller ... can' syntax
Browse files Browse the repository at this point in the history
part of #11317
  • Loading branch information
akrmn committed Nov 30, 2021
1 parent 6fc914f commit 28eef8d
Show file tree
Hide file tree
Showing 49 changed files with 916 additions and 835 deletions.
14 changes: 7 additions & 7 deletions compatibility/sandbox-migration/daml/Divulgence.daml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ template AssetDivulgence
assetOwner: Party
where
signatory divulgee
observer assetOwner

controller assetOwner can
nonconsuming Divulge: ()
with
divulgedAsset: ContractId Asset
do
fetch divulgedAsset
return ()
nonconsuming choice Divulge: () with
divulgedAsset: ContractId Asset
controller assetOwner
do
fetch divulgedAsset
return ()
2 changes: 2 additions & 0 deletions compiler/daml-extension/syntaxes/TestGrammar.daml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ template FeatureSuggestion
assert $ elem sponsor founders -- assert -> source.daml
create FeatureAssignment with employee, description, sponsor -- create -> source.daml

-- deprecated syntax
controller employee can
nonconsuming DoNothing : ()
do
return ()

-- deprecated syntax
controller employee can
Revoke : ()
do pure ()
3 changes: 3 additions & 0 deletions compiler/damlc/tests/daml-test-files/ChoiceSyntaxes.daml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

-- Check that all syntaxes for defining choices can be parsed.

{-# OPTIONS_GHC -Wno-controller-can #-}

module ChoiceSyntaxes where

template T with
Expand All @@ -21,6 +23,7 @@ template T with
do
pure ()

-- deprecated syntax
controller p can
C3 : () with
x : ()
Expand Down
26 changes: 14 additions & 12 deletions compiler/damlc/tests/daml-test-files/ConsumedContractKey.daml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- @ERROR range=23:1-23:32; no contract with that key was found
-- @ERROR range=33:1-33:29; consumed in same transaction
-- @ERROR range=25:1-25:32; no contract with that key was found
-- @ERROR range=35:1-35:29; consumed in same transaction
module ConsumedContractKey where

template Foo
Expand All @@ -9,16 +9,18 @@ template Foo
signatory signer
key signer : Party
maintainer key
controller signer can
FetchKey : Foo
do
snd <$> fetchByKey @Foo signer
LookupKey : ()
do
None <- lookupByKey @Foo signer
pure ()
Fetch : Foo
do fetch self
choice FetchKey : Foo
controller signer
do
snd <$> fetchByKey @Foo signer
choice LookupKey : ()
controller signer
do
None <- lookupByKey @Foo signer
pure ()
choice Fetch : Foo
controller signer
do fetch self

testFetchKeyFromConsumingChoice = do
alice <- getParty "Alice"
Expand Down
6 changes: 5 additions & 1 deletion compiler/damlc/tests/daml-test-files/SemanticsEvalOrder.daml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
-- rule's name in the error message itself. If there are multiple tests for
-- the same rule, we use `R_1`, `R_2`, `R_3`, and so on. This is why there is
-- `evExpRecUpdErr1`, `evExpRecUpdErr2_1`, and `evExpRecUpdErr2_2`, for example.)

{-# OPTIONS_GHC -Wno-controller-can #-}

module SemanticsEvalOrder where

-- @ERROR EvTyAbsErasableErr OK
Expand Down Expand Up @@ -294,7 +297,7 @@ evUpdCreateErr1 = scenario do
create (T_EvUpdCreateErr1 p)
error "EvUpdCreateErr1 failed (4)"

-- @ERROR range=307:1-307:16; Template precondition violated
-- @ERROR range=310:1-310:16; Template precondition violated
template T_EvUpdCreateFail
with
p : Party
Expand Down Expand Up @@ -421,6 +424,7 @@ template T_ControllerCanAddsObserver
p : Party
where
signatory p
-- deprecated syntax
controller (error @Party "controllerCanAddsObserver OK") can
C_ControllerCanAddsObserver: ()
do pure ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ template Bar

key BarKey owner name : BarKey
maintainer key.p

controller owner can
Bar_SomeChoice: Bool
with

choice Bar_SomeChoice: Bool
with
aName: Text
do return True
controller owner
do return True
-- end snippet: template example
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,72 @@ template Iou

observer observers

controller owner can

-- Split the IOU by dividing the amount.
Iou_Split : (IouCid, IouCid)
with
splitAmount: Decimal
do
let restAmount = amount - splitAmount
splitCid <- create this with amount = splitAmount
restCid <- create this with amount = restAmount
return (splitCid, restCid)

-- Merge two IOUs by aggregating their amounts.
Iou_Merge : IouCid
with
otherCid: IouCid
do
otherIou <- fetch otherCid
-- Check the two IOU's are compatible
assert (
currency == otherIou.currency &&
owner == otherIou.owner &&
issuer == otherIou.issuer
)
-- Retire the old Iou
archive otherCid
-- Return the merged Iou
create this with amount = amount + otherIou.amount

Iou_Transfer : ContractId IouTransfer
with
newOwner : Party
do create IouTransfer with iou = this; newOwner

Iou_AddObserver : IouCid
choice Iou_Split : (IouCid, IouCid)
with
newObserver : Party
do create this with observers = newObserver :: observers
splitAmount: Decimal
controller owner
do
let restAmount = amount - splitAmount
splitCid <- create this with amount = splitAmount
restCid <- create this with amount = restAmount
return (splitCid, restCid)

Iou_RemoveObserver : IouCid
with
oldObserver : Party
do create this with observers = filter (/= oldObserver) observers
-- Merge two IOUs by aggregating their amounts.
choice Iou_Merge : IouCid
with
otherCid: IouCid
controller owner
do
otherIou <- fetch otherCid
-- Check the two IOU's are compatible
assert (
currency == otherIou.currency &&
owner == otherIou.owner &&
issuer == otherIou.issuer
)
-- Retire the old Iou
archive otherCid
-- Return the merged Iou
create this with amount = amount + otherIou.amount

choice Iou_Transfer : ContractId IouTransfer
with
newOwner : Party
controller owner
do create IouTransfer with iou = this; newOwner

choice Iou_AddObserver : IouCid
with
newObserver : Party
controller owner
do create this with observers = newObserver :: observers

choice Iou_RemoveObserver : IouCid
with
oldObserver : Party
controller owner
do create this with observers = filter (/= oldObserver) observers

template IouTransfer
with
iou : Iou
newOwner : Party
where
signatory iou.issuer, iou.owner

controller iou.owner can
IouTransfer_Cancel : IouCid
do create iou

controller newOwner can
IouTransfer_Reject : IouCid
do create iou

IouTransfer_Accept : IouCid
do
create iou with
owner = newOwner
observers = []
observer newOwner

choice IouTransfer_Cancel : IouCid
controller iou.owner
do create iou

choice IouTransfer_Reject : IouCid
controller newOwner
do create iou

choice IouTransfer_Accept : IouCid
controller newOwner
do
create iou with
owner = newOwner
observers = []
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,31 @@ template IouTrade
quoteAmount : Decimal
where
signatory buyer
observer seller

controller seller can
IouTrade_Accept : (IouCid, IouCid)
with
quoteIouCid : IouCid
do
baseIou <- fetch baseIouCid
baseIssuer === baseIou.issuer
baseCurrency === baseIou.currency
baseAmount === baseIou.amount
buyer === baseIou.owner
quoteIou <- fetch quoteIouCid
quoteIssuer === quoteIou.issuer
quoteCurrency === quoteIou.currency
quoteAmount === quoteIou.amount
seller === quoteIou.owner
quoteIouTransferCid <- exercise quoteIouCid Iou_Transfer with
newOwner = buyer
transferredQuoteIouCid <- exercise quoteIouTransferCid IouTransfer_Accept
baseIouTransferCid <- exercise baseIouCid Iou_Transfer with
newOwner = seller
transferredBaseIouCid <- exercise baseIouTransferCid IouTransfer_Accept
return (transferredQuoteIouCid, transferredBaseIouCid)
choice IouTrade_Accept : (IouCid, IouCid)
with
quoteIouCid : IouCid
controller seller
do
baseIou <- fetch baseIouCid
baseIssuer === baseIou.issuer
baseCurrency === baseIou.currency
baseAmount === baseIou.amount
buyer === baseIou.owner
quoteIou <- fetch quoteIouCid
quoteIssuer === quoteIou.issuer
quoteCurrency === quoteIou.currency
quoteAmount === quoteIou.amount
seller === quoteIou.owner
quoteIouTransferCid <- exercise quoteIouCid Iou_Transfer with
newOwner = buyer
transferredQuoteIouCid <- exercise quoteIouTransferCid IouTransfer_Accept
baseIouTransferCid <- exercise baseIouCid Iou_Transfer with
newOwner = seller
transferredBaseIouCid <- exercise baseIouTransferCid IouTransfer_Accept
return (transferredQuoteIouCid, transferredBaseIouCid)

TradeProposal_Reject : ()
do return ()
choice TradeProposal_Reject : ()
controller seller
do return ()
18 changes: 10 additions & 8 deletions docs/source/app-dev/code-snippets/LfTranslation.daml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ template Iou
where
-- end code snippet: template data types
signatory issuer
observer owner
-- start code snippet: choice data types
controller owner can
nonconsuming DoNothing: ()
do
return ()
nonconsuming choice DoNothing: ()
controller owner
do
return ()

Transfer: ContractId Iou
with newOwner: Party
do
updateOwner newOwner
choice Transfer: ContractId Iou
with newOwner: Party
controller owner
do
updateOwner newOwner
-- end code snippet: choice data types
10 changes: 5 additions & 5 deletions docs/source/app-dev/code-snippets/Templates.daml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ template MySimpleTemplate
key MySimpleTemplateKey owner: MySimpleTemplateKey
maintainer key.party

controller owner can
MyChoice
: ()
with parameter: Int
do return ()
choice MyChoice
: ()
with parameter: Int
controller owner
do return ()

emptyTemplateTest = scenario do
alice <- getParty "Alice"
Expand Down
19 changes: 10 additions & 9 deletions docs/source/concepts/ledger-model/daml/SimpleIou.daml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ template Iou with
owner : Party
where
signatory obligor
observer owner

controller owner can
Transfer
: ContractId Iou
with newOwner : Party
do create Iou with obligor; owner = newOwner
choice Transfer
: ContractId Iou
with newOwner : Party
controller owner
do create Iou with obligor; owner = newOwner

controller owner can
Settle
: ContractId MustPay
do create MustPay with obligor; owner
choice Settle
: ContractId MustPay
controller owner
do create MustPay with obligor; owner
-- SNIPPET-END

iou = scenario do
Expand Down
Loading

0 comments on commit 28eef8d

Please sign in to comment.