Skip to content

Commit

Permalink
Remove uses of 'controller ... can' syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
akrmn committed Oct 25, 2021
1 parent 8cb152f commit 87b9546
Show file tree
Hide file tree
Showing 49 changed files with 907 additions and 832 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 ()
1 change: 1 addition & 0 deletions compiler/damlc/tests/daml-test-files/ChoiceSyntaxes.daml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ template T with
do
pure ()

-- deprecated syntax
controller p can
C3 : () with
x : ()
Expand Down
22 changes: 12 additions & 10 deletions compiler/damlc/tests/daml-test-files/ConsumedContractKey.daml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,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
15 changes: 8 additions & 7 deletions docs/source/daml/code-snippets/Keys.daml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ template Divulger
sig : Party
where
signatory divulgee
observer sig

controller sig can
nonconsuming DivulgeKeyed
: Keyed
with
keyedCid : ContractId Keyed
do
fetch keyedCid
nonconsuming choice DivulgeKeyed
: Keyed
with
keyedCid : ContractId Keyed
controller sig
do
fetch keyedCid

template Delegation
with
Expand Down
3 changes: 2 additions & 1 deletion docs/source/daml/code-snippets/Reference.daml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ template NameOfTemplate
do
return () -- replace this line with the choice body

-- option 2 for specifying choices: controller first
-- option 2 for specifying choices (deprecated syntax): controller first
controller exampleParty can
NameOfChoice2
: () -- replace () with the actual return type
Expand Down Expand Up @@ -108,6 +108,7 @@ template NameOfTemplate
return ()

-- start controller-first controller snippet
-- deprecated syntax
controller exampleParty can
-- end controller-first controller snippet
-- start controller-first choice name snippet
Expand Down
Loading

0 comments on commit 87b9546

Please sign in to comment.