Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sdk/docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,18 @@ daml_test(
for version in [DEV_LF_VERSION]
]

daml_test(
name = "docs-canton-network-daml-test",
timeout = "long",
srcs = glob(["source/sdk/docs-canton-network/code-snippets/**/*.daml"]),
additional_compiler_flags = [
"-Wupgrade-interfaces",
"-Wupgrade-exceptions",
],
deps = ["//daml-script/daml:daml-script.dar"],
)


daml_test(
name = "quickstart-daml-test",
srcs = glob(
Expand Down Expand Up @@ -474,6 +486,8 @@ daml_test(
for version in [DEV_LF_VERSION]
]



daml_test(
name = "daml-intro-9-daml-test",
srcs = glob(["source/sdk/tutorials/smart-contracts/daml/daml-intro-9/**/*.daml"]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module DocsCN_AppdevDeepDivesCompositionMultiParty where

import DA.Optional

-- appdev_deep-dives_composition-multi-party_L78.mdx
template TradeRequest
with
buyer : Party
seller : Party
asset : Text
price : Decimal
where
signatory buyer
observer seller

choice ConfirmTrade : ContractId TradeSettlement
controller seller
do create TradeSettlement with
buyer
seller
asset
price

template TradeSettlement
with
buyer : Party
seller : Party
asset : Text
price : Decimal
where
signatory buyer, seller

choice Settle : ()
controller seller
do pure ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module DocsCN_AppdevDeepDivesPrivacyModel where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_deep-dives_privacy-model_L92.mdx
-- choice SettleTrade : ()
-- controller buyer
-- do
-- -- Fetching sellerAsset here divulges it to the buyer
-- asset <- fetch sellerAssetId
-- archive sellerAssetId
-- create Asset with owner = buyer, issuer = asset.issuer, value = asset.value
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module DocsCN_AppdevModulesM1MentalModels where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_modules_m1-mental-models_L84.mdx
-- choice DoThing : Result
-- controller owner -- Declaration, not code
-- do
-- -- Only owner can reach here
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module DocsCN_AppdevModulesM2MigrationChecklist where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_modules_m2-migration-checklist_L166.mdx
-- -- Daml: No modifier needed
-- choice AdminAction : ()
-- controller admin -- Only admin can exercise
-- do
-- -- Protocol enforces this
-- pure ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module DocsCN_AppdevModulesM2MultiPartyWorkflows where

import DA.Optional

-- appdev_modules_m2-multi-party-workflows_L174.mdx
data WorkflowState
= Proposed
| Approved
| Settled
deriving (Eq, Show)

template Workflow
with
initiator : Party
approver : Party
settler : Party
state : WorkflowState
payload : Text
where
signatory initiator
observer approver, settler

choice Approve : ContractId Workflow
controller approver
do
assertMsg "Must be in Proposed state" (state == Proposed)
create this with state = Approved

choice Settle : ContractId Workflow
controller settler
do
assertMsg "Must be in Approved state" (state == Approved)
create this with state = Settled

-- appdev_modules_m2-multi-party-workflows_L208.mdx
-- choice ExecuteSwap : ()
-- with
-- assetA : ContractId Asset
-- assetB : ContractId Asset
-- controller buyer, seller
-- do
-- -- Both happen atomically or neither does
-- exercise assetA Transfer with newOwner = buyer
-- exercise assetB Transfer with newOwner = seller

-- appdev_modules_m2-multi-party-workflows_L260.mdx
-- template Vote
-- with
-- proposal : Text
-- voters : [Party]
-- votes : [(Party, Bool)]
-- threshold : Int
-- where
-- signatory (map fst votes)
-- observer voters

-- choice CastVote : ContractId Vote
-- with
-- voter : Party
-- approve : Bool
-- controller voter
-- do
-- assertMsg "Not a voter" (voter `elem` voters)
-- assertMsg "Already voted" (voter `notElem` map fst votes)
-- create this with votes = (voter, approve) :: votes

-- choice TallyAndExecute : ()
-- controller voters
-- do
-- let approvals = length [v | (_, v) <- votes, v]
-- assertMsg "Threshold not met" (approvals >= threshold)
-- -- Execute the proposal...
-- pure ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module DocsCN_AppdevModulesM2SmartContractParadigm where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_modules_m2-smart-contract-paradigm_L152.mdx
-- process : [Decimal] -> Update [Decimal]
-- process items = do
-- forA items \item -> do
-- assertMsg "Over threshold" (item <= threshold)
-- pure (item * 2.0)

-- appdev_modules_m2-smart-contract-paradigm_L86.mdx
-- -- Canton: Holdings are individual contracts
-- -- Alice's total balance = sum of all Token contracts where owner = Alice
--
-- -- Query: Find all my tokens
-- myTokens <- queryContractKey @Token myParty
-- totalBalance <- pure $ sum [amount | Token{amount} <- myTokens]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module DocsCN_AppdevModulesM3DesignPatterns where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_modules_m3-design-patterns_L80.mdx
-- import Intro.Asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module DocsCN_AppdevModulesM3LanguageFundamentals where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_modules_m3-language-fundamentals_L109.mdx
-- increment3 = (1 +)
-- double = (* 2)

-- appdev_modules_m3-language-fundamentals_L280.mdx
-- boolToInt2 b = if b
-- then 1
-- else 0

-- appdev_modules_m3-language-fundamentals_L52.mdx
-- add n m = n + m

-- appdev_modules_m3-language-fundamentals_L84.mdx
-- increment2 = add 1

-- appdev_modules_m3-language-fundamentals_L96.mdx
-- three = 1 `add` 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module DocsCN_AppdevModulesM4BackendDev where

import DA.Optional

-- appdev_modules_m4-backend-dev_L261.mdx
template LicenseComment
with
provider : Party
user : Party
licenseNum : Int
commenter : Party
body : Text
createdAt : Time
where
signatory commenter
observer provider, user
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module DocsCN_AppdevModulesM7Performance where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_modules_m7-performance_L36.mdx
-- -- Avoid: creates N contracts in one transaction
-- choice ProcessBatch : [ContractId Item]
-- controller processor
-- do mapA (\item -> create Item with ...) items

-- appdev_modules_m7-performance_L45.mdx
-- -- Better: one contract representing the batch
-- choice ProcessBatch : ContractId BatchResult
-- controller processor
-- do create BatchResult with items = processedItems
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module DocsCN_AppdevReferenceDamlLanguageReference where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_reference_daml-language-reference_L185.mdx
-- -- Code from: code-snippets/Snippets.daml
-- -- [Include actual code example here]

-- appdev_reference_daml-language-reference_L36.mdx
-- data Address = Address
-- { street : Text
-- , city : Text
-- }
--
-- data Color = Red | Green | Blue
--
-- newtype Token = Token Int
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module DocsCN_AppdevTroubleshootingGuideDevelopmentIssues where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- appdev_troubleshooting-guide_development-issues_L21.mdx
-- asset <- fetch assetCid
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module DocsCN_OverviewLearnLedgerModel where

import DA.Optional

-- Wrapper for documentation code fragments
template DocSnippetWrapper
with
owner : Party
where
signatory owner

-- Code fragments below are for documentation only
-- They are wrapped for compilation checking

-- overview_learn_ledger-model_L269.mdx
-- choice ClaimAfterDeadline : ()
-- controller beneficiary
-- do
-- assertDeadlineExceeded "claim-after-deadline" deadline
-- -- ... claim logic

-- overview_learn_ledger-model_L283.mdx
-- -- Atomic swap: both transfers happen or neither does
-- choice ExecuteSwap : ()
-- controller buyer
-- do
-- exercise assetId Transfer with newOwner = buyer
-- exercise paymentId Transfer with newOwner = seller
Loading