Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints
How To Implement Time Constraints
Contract time constraints may be implemented using either:
ledger time primitives (i.e. isLedgerTimeLT, isLedgerTimeLE, isLedgerTimeGT and isLedgerTimeGE) or assertions (i.e. assertWithinDeadline and assertDeadlineExceeded)
the use of ledger time primitives and assertions do not constrain the time bound between transaction preparation and submission - e.g. they are suitable for workflows using external parties to sign transactions
or, by calling getTime
calls to getTime constrain transaction preparation and submission workflows to be (by default) within 1 minute.
the 1 minute value is the default value for the ledger time record time tolerance parameter (a dynamic synchronizer parameter).
The next subsections demonstrate how the following Coin and TransferProposal contracts can be modified to use different types of ledger time constraints to control when parties are allowed to perform ledger writes.Coin contract
template Coin with owner: Party issuer: Party amount: Decimal where signatory issuer signatory owner ensure amount > 0.0
choice Transfer : ContractId TransferProposal with newOwner: Party controller owner do create TransferProposal with coin=this; newOwner
TransferProposal contract
template TransferProposal with coin: Coin newOwner: Party where signatory coin.owner signatory coin.issuer observer newOwner
choice AcceptTransfer : ContractId Coin controller newOwner do create coin with owner = newOwner
choice WithdrawTransfer : ContractId Coin controller coin.owner do create coin
Simple coin transfer with consent withdrawal
How to check that a deadline is valid
This design pattern demonstrates how to limit choices so that they must occur by a given deadline.
Motivation
When parties need to perform ledger writes by a given deadline.
Implementation
Transfer proposals can be accepted at any point in time. To restrict this behaviour so that acceptance must occur by a fixed time, a guard for AcceptTransfer choice execution can be added.TransferProposal contract
In the TransferProposal contract, the body of the AcceptTransfer choice is modified to assert that the contract deadline is valid.
choice AcceptTransfer : ContractId Coin controller newOwner do assertWithinDeadline "time-limited-transfer" timeLimit create coin with owner = newOwner
As transfer proposals are created when a Transfer choice is executed, the time by which an AcceptTransfer can be executed needs to be passed in as a choice parameter.Coin contract
In the Coin contract, the Transfer choice has an additional deadline argument, so that TransferProposal contracts can be given a fixed lifetime.
choice Transfer : ContractId TransferProposal with newOwner: Party timeLimit: Time controller owner do create TransferProposal with coin=this; newOwner; timeLimit
Time-limited coin ownership transfer
How to check that a deadline has passed
This design pattern demonstrates how to ensure choices only occur after a given deadline.
Motivation
When parties need to perform ledger writes after a fixed time delay.
Implementation
Transfer proposals can be accepted at any point in time. To restrict this behaviour so that acceptance can only occur after a fixed delay, a guard for AcceptTransfer choice execution can be added.TransferProposal contract
In the TransferProposal contract, the body of the AcceptTransfer choice is modified to assert that the contract deadline has been exceeded or passed.
choice AcceptTransfer : ContractId Coin controller newOwner do assertDeadlineExceeded "delayed-transfer" delay create coin with owner = newOwner
As transfer proposals are created when a Transfer choice is executed, the delay time after which an AcceptTransfer can be executed needs to be passed in as a choice parameter.Coin contract
In the Coin contract, the Transfer choice has an additional deadline argument, so that TransferProposal contracts can be given a delay.
choice Transfer : ContractId TransferProposal with newOwner: Party delay: Time controller owner do create TransferProposal with coin=this; newOwner; delay
Delayed coin ownership transfer
Grant time-limited writes to parties
This design pattern demonstrates how to grant time-limited writes to parties.
Motivation
When parties need to be able to perform ledger writes, but writes need to only be granted for a specific time window.
Implementation
Transfer proposals can be accepted at any point in time. To restrict this behaviour so that acceptance can only occur within a given time window, a guard for AcceptTransfer choice execution can be added.TransferProposal contract
In the TransferProposal contract, the body of the AcceptTransfer choice is modified to assert that the contract deadline has been exceeded or passed.
choice AcceptTransfer : ContractId Coin controller newOwner do withinWindow <- isLedgerTimeGE startTime && isLedgerTimeLT endTime _ <- unless withinWindow $ failWithStatus $ FailureStatus "transfer-outside-time-window" InvalidGivenCurrentSystemStateOther ("Ledger time is outside permitted transfer time window [" <> show startTime <> ", " <> show endTime <> ")") (TextMap.fromList [("startTime", show startTime), ("endTime", show endTime)]) create coin with owner = newOwner
As transfer proposals are created when a Transfer choice is executed, the interval start and end times, during which an AcceptTransfer can be executed need to be passed in as choice parameters.Coin contract
In the Coin contract, the Transfer choice has an additional deadline argument, so that TransferProposal contracts can be given a delay.
choice Transfer : ContractId TransferProposal with newOwner: Party startTime: Time duration: RelTime controller owner do create TransferProposal with coin=this; newOwner; startTime; addRelTime startTime duration
Coin ownership transfer within a time window
Where to use getTime
For workflows that prepare and submit transactions, care needs to be taken when using calls to getTime. This is because calls to getTime cause transactions to be bound to the ledger time, and in turn constrain how sequencers may re-order transactions. Global Synchronizers are configured such that the transaction prepare and submit time window is one minute, so any workflow using getTime must prepare and submit transactions within that one-minute time window.For workflows where this constraint can not be met (e.g. workflows that sign transactions using external parties), it is recommended that workflows are designed to use the ledger time primitives and assertions.
Motivation
When parties need to perform ledger writes by a given deadline, but are able to prepare and submit a transaction within 1 minute.
Implementation
Transfer proposals can be accepted at any point in time. To require acceptance by a fixed time, you can add a guard for AcceptTransfer choice execution. Here you determine the current ledger time by calling getTime.TransferProposal contract
In the TransferProposal contract, the body of the AcceptTransfer choice is modified to assert that the contract deadline is valid relative to the ledger time returned by calling getTime.
choice AcceptTransfer : ContractId Coin controller newOwner do t <- getTime _ <- unless (t < timeLimit) $ failWithStatus $ FailureStatus "deadline-exceeded" InvalidGivenCurrentSystemStateOther ("Ledger time is after deadline " <> show timeLimit) (TextMap.fromList [("timeLimit", show timeLimit)]) create coin with owner = newOwner
As transfer proposals are created when a Transfer choice is executed, the time by which an AcceptTransfer can be executed needs to be passed in as a choice parameter.Coin contract
In the Coin contract, the Transfer choice has an additional deadline argument, so that TransferProposal contracts can be given a fixed lifetime.
choice Transfer : ContractId TransferProposal with newOwner: Party timeLimit: Time controller owner do create TransferProposal with coin=this; newOwner; timeLimit
Add constraints to a contract
You will often want to constrain the data stored or the allowed data transformations in your contract models. In this section, you will learn about the two main mechanisms provided in Daml:
The ensure keyword.
The assert, abort and, error keywords.
To make sense of the latter, you’ll also learn more about the Update and Script types, and do blocks, which will be good preparation for compose, where you will use do blocks to compose choices into complex transactions.Lastly, you will learn about time on the ledger and in Daml Script.
Remember that you can load all the code for this section into a folder called intro-constraints by running dpm new intro-constraints --template daml-intro-constraints
Template preconditions
The first kind of restriction you may want to put on the contract model are called template pre-conditions. These are simply restrictions on the data that can be stored on a contract from that template.Suppose, for example, that the SimpleIou contract from simple_iou should only be able to store positive amounts. You can enforce this using the ensure keyword:
template SimpleIou with issuer : Party owner : Party cash : Cash where signatory issuer observer owner ensure cash.amount > 0.0
The ensure keyword takes a single expression of type Bool. If you want to add more restrictions, use logical operators &&, ||, and not to build up expressions. The below shows the additional restriction that currencies are three capital letters:
The T here stands for the DA.Text which has been imported from the Daml standard library using import DA.Text as T:
test_restrictions = do alice <- allocateParty "Alice" bob <- allocateParty "Bob" dora <- allocateParty "Dora" -- Dora can't issue negative Ious. submitMustFail dora do createCmd SimpleIou with issuer = dora owner = alice cash = Cash with amount = -100.0 currency = "USD" -- Or even zero Ious. submitMustFail dora do createCmd SimpleIou with issuer = dora owner = alice cash = Cash with amount = 0.0 currency = "USD" -- Nor positive Ious with invalid currencies. submitMustFail dora do createCmd SimpleIou with issuer = dora owner = alice cash = Cash with amount = 100.0 currency = "Swiss Francs" -- But positive Ious still work, of course. iou <- submit dora do createCmd SimpleIou with issuer = dora owner = alice cash = Cash with amount = 100.0 currency = "USD"
Assertions
A second common kind of restriction is one on data transformations.For example, the simple Iou in simple_iou allowed the no-op where the owner transfers to themselves. You can prevent that using an assert statement, which you have already encountered in the context of scripts.assert does not return an informative error so often it’s better to use the function assertMsg, which takes a custom error message:
choice Transfer : ContractId SimpleIou with newOwner : Party controller owner do assertMsg "newOwner cannot be equal to owner." (owner /= newOwner) create this with owner = newOwner
-- Alice can't transfer to herself... submitMustFail alice do exerciseCmd iou Transfer with newOwner = alice -- ... but can transfer to Bob. iou2 <- submit alice do exerciseCmd iou Transfer with newOwner = bob
Similarly, you can write a Redeem choice, which allows the owner to redeem an Iouduring business hours on weekdays. The Redeem choice implementation below confirms that getTime returns a value that is during business hours on weekdays. If all those checks pass, the choice does not do anything other than archive the SimpleIou. (This assumes that actual cash changes hands off-ledger:)
choice Redeem : () controller owner do now <- getTime let today = toDateUTC now dow = dayOfWeek today timeofday = now `subTime` time today 0 0 0 hrs = convertRelTimeToMicroseconds timeofday / 3600000000 if (hrs < 8 || hrs > 18) then abort $ "Cannot redeem outside business hours. Current time: " <> show timeofday else case dow of Saturday -> abort "Cannot redeem on a Saturday." Sunday -> abort "Cannot redeem on a Sunday." _ -> return ()
In the above example, the time is taken apart into day of week and hour of day using standard library functions from DA.Date and DA.Time. The hour of the day is checked to be in the range from 8 to 18. The day of week is checked to not be Saturday or Sunday.The following example shows how the Redeem choice is exercised in a script:
-- June 1st 2019 is a Saturday. setTime (time (date 2019 Jun 1) 0 0 0) -- Bob cannot redeem on a Saturday. submitMustFail bob do exerciseCmd iou2 Redeem -- Not even at mid-day. passTime (hours 12) -- Bob cannot redeem on a Saturday. submitMustFail bob do exerciseCmd iou2 Redeem -- Bob also cannot redeem at 6am on a Monday. passTime (hours 42) submitMustFail bob do exerciseCmd iou2 Redeem -- Bob can redeem at 8am on Monday. passTime (hours 2) submit bob do exerciseCmd iou2 Redeem
For the purposes of testing the Redeem choice, the above code sets and advances the ledger time with the setTime and passTime functions respectively. Exercising the choice should fail or should not fail depending on the day of week and the time of day. While that is straightforward, the issue of time on a Daml ledger is worthy of more discussion.
Time on Daml ledgers
Each transaction on a Daml ledger has two timestamps: the ledger time (LT) and the record time (RT).Ledger time (LT) is the time associated with a transaction in the ledger model, as determined by the participant. It is the time of a transaction from a business and application perspective. When you call `getTime, it is the LT that is returned. The LT is used when reasoning about related transactions and commits. The LT can be compared with other LTs to guarantee model consistency. For example, LTs are used to enforce that no transaction depends on a contract that does not exist. This is the requirement known as “causal monotonicity.”Record time (RT) is the time assigned by the persistence layer. It represents the time that the transaction is “physically” recorded. For example, “The backing database ledger has assigned the timestamp of such-and-such time to this transaction.” The only purpose of the RT is to ensure that transactions are being recorded in a timely manner.Each Daml ledger has a policy on the allowed difference between LT and RT called the skew. A consistent zero-skew is not feasible because this is a distributed system. If it is too far off, the transaction will be rejected. This is the requirement known as “bounded skew.” The RT is not relevant beyond this determination of skew.Returning to the theme of business hours, consider the following example: Suppose that the ledger had a skew of 10 seconds. At 17:59:55, just before the end of business hours, Alice submits a transaction to redeem an Iou. One second later, the transaction is assigned an LT of 17:59:56. However, there still may be a few seconds before the transaction is persisted to the underlying storage. For example, the transaction might be written in the underlying backing store at 18:00:06, after business hours. Because LT is within business hours and LT - RT .
Time in test scripts
For tests, you can set time using the following functions:
setTime, which sets the ledger time to the given time.
passTime, which takes a RelTime (a relative time) and moves the ledger by that much.
On a distributed Daml ledger, there are no guarantees that LT or RT are strictly increasing. The only guarantee is that ledger time is increasing with causality. That is, if a transaction TX2 depends on a transaction TX1, then the ledger enforces that the LT of TX2 is greater than or equal to that of TX1.The following script illustrates that idea by moving the logical time back by three days and then trying to exercise a choice on a contract that hasn’t been created yet. That fails, as you would hope.
iou3 <- submit dora do createCmd SimpleIou with issuer = dora owner = alice cash = Cash with amount = 100.0 currency = "USD" passTime (days (-3)) submitMustFail alice do exerciseCmd iou3 Redeem
Actions and do blocks
You have come across do blocks and <- notations in two contexts by now: Script and Update. Both of these are examples of an Action, also called a Monad in functional programming. You can construct Actions conveniently using do notation.Understanding Actions and do blocks is therefore crucial to being able to construct correct contract models and test them, so this section will explain them in some detail.
Pure expressions compared to actions
Expressions in Daml are pure in the sense that they have no side-effects: they neither read nor modify any external state. If you know the value of all variables in scope and write an expression, you can work out the value of that expression on pen and paper.However, the expressions you’ve seen that used the <- notation are not like that. For example, take getTime, which is an Action. Here’s the example we used earlier:“daml
now syntax for functions later.Coin and play are deliberately left obscure in the above. All you have is an action getCoin to get your hands on a Coin in a Script context and an action flipCoin which represents the simplest possible game: a single coin flip resulting in a Face.You can’t play any CoinGame game on pen and paper as you don’t have a coin, but you can write down a script or recipe for a game:
coin_test = do -- The coin is pseudo-random on LT so change the parameter to change the game. setTime (time (date 2019 Jun 1) 0 0 0) passTime (seconds 2) coin <- getCoin let game = do f1r <- flipCoin f2r <- flipCoin f3r <- flipCoin if all (== Heads) [f1r, f2r, f3r] then return "Win" else return "Loss" (newCoin, result) = game.play coin assert (result == "Win")
The game expression is a CoinGame in which a coin is flipped three times. If all three tosses return Heads, the result is "Win", or else "Loss".In a Script context you can get a Coin using the getCoin action, which uses the LT to calculate a seed, and play the game.Somehow the Coin is threaded through the various actions. If you want to look through the looking glass and understand in-depth what’s going on, you can look at the source file to see how the CoinGame action is implemented, though be warned that the implementation uses a lot of Daml features we haven’t introduced yet in this introduction.More generally, if you want to learn more about Actions (aka Monads), we recommend a general course on functional programming, and Haskell in particular. See haskell-connection for some suggestions.
Errors
Above, you’ve learnt about assertMsg and abort, which represent (potentially) failing actions. Actions only have an effect when they are performed, so the following script succeeds or fails depending on the value of abortScript:
nonPerformedAbort = do let abortScript = False let failingAction : Script () = abort "Foo" let successfulAction : Script () = return () if abortScript then failingAction else successfulAction
However, what about errors in contexts other than actions? Suppose we wanted to implement a function pow that takes an integer to the power of another positive integer. How do we handle that the second parameter has to be positive?One option is to make the function explicitly partial by returning an Optional:
optPow : Int -> Int -> Optional IntoptPow base exponent | exponent == 0 = Some 1 | exponent > 0 = let Some result = optPow base (exponent - 1) in Some (base * result) | otherwise = None
This is a useful pattern if we need to be able to handle the error case, but it also forces us to always handle it as we need to extract the result from an Optional. We can see the impact on convenience in the definition of the above function. In cases, like division by zero or the above function, it can therefore be preferable to fail catastrophically instead:
errPow : Int -> Int -> InterrPow base exponent | exponent == 0 = 1 | exponent > 0 = base * errPow base (exponent - 1) | otherwise = error "Negative exponent not supported"
The big downside to this is that even unused errors cause failures. The following script will fail, because failingComputation is evaluated:
nonPerformedError = script do let causeError = False let failingComputation = errPow 1 (-1) let successfulComputation = errPow 1 1 return if causeError then failingComputation else successfulComputation
error should therefore only be used in cases where the error case is unlikely to be encountered, and where explicit partiality would unduly impact usability of the function.
Next up
You can now specify a precise data and data-transformation model for Daml ledgers. In parties, you will learn how to properly involve multiple parties in contracts, how authority works in Daml, and how to build contract models with strong guarantees in contexts with mutually distrusting entities.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Canton Network Docs","colors":{"primary":"#734BE2","light":"#A985FF","dark":"#7B59E8"},"logo":{"light":"https://mintcdn.com/cantonfoundation/OOy41G-b8QJx6Gkr/images/canton-logo-dark.svg?fit=max\u0026auto=format\u0026n=OOy41G-b8QJx6Gkr\u0026q=85\u0026s=d5d59c10fc4ca9be021afb188db72e2f","dark":"https://mintcdn.com/cantonfoundation/OOy41G-b8QJx6Gkr/images/canton-logo-white.svg?fit=max\u0026auto=format\u0026n=OOy41G-b8QJx6Gkr\u0026q=85\u0026s=820871bab1b1be90578959e03e4a3001","href":"/"},"favicon":"https://mintcdn.com/cantonfoundation/OOy41G-b8QJx6Gkr/images/canton-logo-dark.svg?fit=max\u0026auto=format\u0026n=OOy41G-b8QJx6Gkr\u0026q=85\u0026s=d5d59c10fc4ca9be021afb188db72e2f","appearance":{"default":"system"},"footer":{"socials":{"x":"https://x.com/CantonNetwork","github":"https://github.com/canton-network","linkedin":"https://www.linkedin.com/company/canton-network","discord":"https://discord.gg/canton","telegram":"https://t.me/CantonNetwork1"},"links":[{"header":"Legal","items":[{"label":"Documentation License (CC-BY-4.0)","href":"https://creativecommons.org/licenses/by/4.0"},{"label":"Code License (Apache-2.0)","href":"https://www.apache.org/licenses/LICENSE-2.0"}]}]},"fonts":{"heading":{"family":"Inter","weight":700},"body":{"family":"Inter","weight":400}},"styling":{"eyebrows":"breadcrumbs","codeblocks":{"theme":{"light":"github-light","dark":"github-dark"}},"latex":true},"integrations":{"ga4":{"measurementId":"G-F2G1L137JX"},"cookies":{}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","mcp","cursor","vscode"],"display":"header"},"markdown":{"instructions":"If you are building a Canton Network application, start from https://docs.canton.network/appdev/quickstart.md. To run only a local network for your own Daml code, without building the QuickStart demo, see https://docs.canton.network/sdks-tools/development-tools/localnet.md."},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"cantonfoundation","hasAudioNarration":false,"actualSubdomain":"cantonfoundation","customDomains":["docs.canton.network"],"gitSource":{"type":"github","owner":"canton-network","repo":"cf-docs","deployBranch":"main","contentDirectory":"docs-main","isPrivate":false,"mountPath":"","label":""},"feedback":{"contextualFeedback":{"allowEmail":true},"edits":true,"issues":true,"thumbs":true,"agentFeedback":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"REMOVE_BRANDING":{"status":"ENABLED"},"CONTEXTUAL_FEEDBACK":{"status":"ENABLED"},"CODE_SNIPPET_FEEDBACK":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6b0ea6118007c388aa2daf7a","clientVersion":"0.0.4377","searchFilterCounts":[{"language":"default","tag":"API Reference","count":1006},{"language":"default","tag":"Packages","count":503},{"language":"default","tag":"Ledger API","count":449},{"language":"default","tag":"Services","count":283},{"language":"default","tag":"Splice APIs","count":272},{"language":"default","tag":"gRPC API","count":234},{"language":"default","tag":"Java Bindings","count":196},{"language":"default","tag":"Admin API","count":157},{"language":"default","tag":"com.daml.ledger.javaapi.data","count":151},{"language":"default","tag":"Release Notes","count":130}],"searchSettings":{"isFiltersEnabled":false,"showContentSnippets":true}},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true,"deflection":{"enabled":true,"type":"link","url":"https://forum.canton.network/"}},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[],"privacy":{"consentBanner":{"enabled":false}},"googleFontsInlined":false},"customCss":[{"filePath":"styles.css","content":":root{--canton-highlight: #734BE2;--canton-highlight-rgb: 115, 75, 226;--canton-selected-bg: rgba(115, 75, 226, 0.10);--canton-hover-bg: rgba(115, 75, 226, 0.05);--canton-inline-highlight-bg: rgba(115, 75, 226, 0.14);--canton-inline-highlight-border: rgba(115, 75, 226, 0.26);--canton-product-selector-line: rgba(115, 75, 226, 0.70);--canton-product-selector-line-active: #734BE2;--canton-product-selector-divider: rgba(75, 85, 99, 0.16);--x2mdx-ref-canvas: #F6F8FB;--x2mdx-ref-sidebar: #FBFCFD;--x2mdx-ref-surface: #FFFFFF;--x2mdx-ref-text-strong: #11131A;--x2mdx-ref-text: #252937;--x2mdx-ref-text-muted: #6B7280;--x2mdx-ref-border: rgba(17, 19, 26, 0.08);--x2mdx-ref-accent-soft: #F3EEFF;--x2mdx-ref-neutral-soft: #F4F5F7;--x2mdx-ref-info: #1D4ED8;--x2mdx-ref-info-soft: #EDF5FF;--x2mdx-ref-success: #15803D;--x2mdx-ref-success-soft: #ECFBF0;--x2mdx-ref-danger: #B91C1C;--x2mdx-ref-danger-soft: #FFF1F1;--x2mdx-ref-warning: #B16305;--x2mdx-ref-warning-soft: #FFF8E4;--canton-font-family: 'Inter', system-ui, -apple-system, sans-serif}[data-theme=\"dark\"],:root.dark{--canton-highlight: #A985FF;--canton-highlight-rgb: 169, 133, 255;--canton-selected-bg: rgba(169, 133, 255, 0.25);--canton-hover-bg: rgba(169, 133, 255, 0.05);--canton-inline-highlight-bg: rgba(169, 133, 255, 0.22);--canton-inline-highlight-border: rgba(169, 133, 255, 0.34);--canton-product-selector-line: rgba(169, 133, 255, 0.70);--canton-product-selector-line-active: #A985FF;--canton-product-selector-divider: rgba(255, 255, 255, 0.10);--x2mdx-ref-canvas: #111115;--x2mdx-ref-sidebar: #111115;--x2mdx-ref-surface: rgba(17, 24, 39, 0.78);--x2mdx-ref-text-strong: #F3F4F6;--x2mdx-ref-text: #E5E7EB;--x2mdx-ref-text-muted: #D1D5DB;--x2mdx-ref-border: rgba(255, 255, 255, 0.08);--x2mdx-ref-accent-soft: rgba(169, 133, 255, 0.16);--x2mdx-ref-neutral-soft: rgba(156, 163, 175, 0.12);--x2mdx-ref-info: #93C5FD;--x2mdx-ref-info-soft: rgba(29, 78, 216, 0.22);--x2mdx-ref-success: #86EFAC;--x2mdx-ref-success-soft: rgba(21, 128, 61, 0.22);--x2mdx-ref-danger: #FCA5A5;--x2mdx-ref-danger-soft: rgba(185, 28, 28, 0.22);--x2mdx-ref-warning: #FCD34D;--x2mdx-ref-warning-soft: rgba(177, 99, 5, 0.22)}::selection{background-color:var(--canton-selected-bg);color:inherit}::-moz-selection{background-color:var(--canton-selected-bg);color:inherit}mark{background-color:var(--canton-inline-highlight-bg);color:inherit;border-radius:0.25rem;box-shadow:inset 0 0 0 1px var(--canton-inline-highlight-border);padding:0.08em 0.18em}[class*=\"sidebar\"] a:hover,nav a:hover{background-color:var(--canton-hover-bg)}#navigation-items .sidebar-group-header{margin-bottom:0.25rem;line-height:1.25}#navigation-items .sidebar-group li a,#navigation-items .sidebar-group li button{padding-top:0.25rem;padding-bottom:0.25rem;line-height:1.5}:root a[class*=\"bg-primary\"],:root a.text-primary{background-color:rgba(115, 75, 226, 0.08)!important;color:#734BE2!important}[data-theme=\"dark\"] a[class*=\"bg-primary\"],[data-theme=\"dark\"] a.text-primary{background-color:rgba(169, 133, 255, 0.10)!important;color:#A985FF!important}.nav-dropdown-products-selector-trigger{box-shadow:inset 0 0 0 1.5px var(--canton-product-selector-line)!important}.nav-dropdown-products-selector-trigger:hover,.nav-dropdown-products-selector-trigger[aria-expanded=\"true\"]{background-color:var(--canton-hover-bg)!important;box-shadow:inset 0 0 0 2px var(--canton-product-selector-line-active)!important}.nav-dropdown-products-selector-content>a[href=\"/api-reference\"]{border-top:1px solid var(--canton-product-selector-divider);box-sizing:border-box;margin-top:0.35rem;padding-top:0.35rem;width:100%}[class*=\"toc\"] a[class*=\"active\"],[class*=\"toc\"] a[aria-current],[class*=\"TableOfContents\"] a[class*=\"active\"],[class*=\"tableofcontents\"] a[class*=\"active\"],aside[class*=\"right\"] a[class*=\"active\"],[class*=\"on-this-page\"] a[class*=\"active\"]{background-color:transparent!important;color:var(--canton-highlight)!important;font-weight:500}[class*=\"toc\"] a:not([class*=\"active\"]),[class*=\"TableOfContents\"] a:not([class*=\"active\"]),[class*=\"tableofcontents\"] a:not([class*=\"active\"]),aside[class*=\"right\"] a:not([class*=\"active\"]),[class*=\"on-this-page\"] a:not([class*=\"active\"]){background-color:transparent!important}[class*=\"toc\"] a:hover,[class*=\"TableOfContents\"] a:hover,[class*=\"tableofcontents\"] a:hover,aside[class*=\"right\"] a:hover,[class*=\"on-this-page\"] a:hover{background-color:transparent!important;color:var(--canton-highlight)!important}#footer.advanced-footer>div{gap:1.25rem!important;padding-top:2rem!important;padding-bottom:2rem!important}@media (max-width: 767px){#footer.advanced-footer>div{gap:1rem!important;padding-top:1.5rem!important;padding-bottom:1.5rem!important}}a:not([class]){color:var(--canton-highlight)}.prose strong,.prose b,strong,b{font-weight:600!important}:root.dark .prose strong,:root.dark .prose b,[data-theme=\"dark\"] .prose strong,[data-theme=\"dark\"] .prose b,:root.dark strong,:root.dark b,[data-theme=\"dark\"] strong,[data-theme=\"dark\"] b{font-weight:400!important}a:not([class]):hover{color:var(--canton-highlight);opacity:0.8}:not(pre)>code{background-color:rgba(115, 75, 226, 0.10);border-radius:4px;padding:0.125em 0.25em}:root.dark :not(pre)>code,[data-theme=\"dark\"] :not(pre)>code{background-color:rgba(169, 133, 255, 0.20)}pre code::selection,pre code::-moz-selection{background-color:var(--canton-selected-bg)}[class*=\"card\"]:hover{border-color:var(--canton-highlight)}button[class*=\"bg-primary\"],a[class*=\"bg-primary\"]:not([class~=\"card\"]){background-color:var(--canton-highlight)}button[class*=\"bg-primary\"]:hover,a[class*=\"bg-primary\"]:not([class~=\"card\"]):hover{opacity:0.9}table tbody tr:hover{background-color:var(--canton-hover-bg)}[data-component=\"network-variables\"] [role=\"tablist\"]{gap:0.35rem!important;padding:0.35rem!important}[data-component=\"network-variables\"] [role=\"tab\"]{border:1px solid transparent!important;border-radius:0.5rem!important}[data-component=\"network-variables\"] [role=\"tab\"][aria-selected=\"false\"]{border-color:var(--canton-product-selector-divider)!important}[data-component=\"network-variables\"] [role=\"tab\"][aria-selected=\"true\"]{border-color:var(--canton-highlight)!important;box-shadow:inset 0 0 0 1px var(--canton-highlight)!important;color:var(--canton-highlight)!important}table:has(pre){display:block;overflow-x:visible}table:has(pre)>colgroup{display:none}table:has(pre)>tbody,table:has(pre)>thead{display:block}table:has(pre)>tbody>tr,table:has(pre)>thead>tr{display:block}table:has(pre) td,table:has(pre) th{display:block;width:100%!important;max-width:100%}table:has(pre) td>pre,table:has(pre) th>pre{max-width:100%;overflow-x:auto}[data-component-part=\"search-item\"][data-highlighted]{background-color:var(--canton-inline-highlight-bg);color:inherit}[data-component-part=\"search-item-content\"]{white-space:normal;overflow:visible;text-overflow:unset}[data-component-part=\"search-item-breadcrumbs\"]{font-size:10px;line-height:1.25}[data-component-part=\"search-item-breadcrumbs\"] svg{stroke-width:4}[data-component-part=\"search-item-breadcrumbs\"] svg path{stroke-width:4}:focus-visible{outline:2px solid var(--canton-highlight);outline-offset:2px}::-webkit-scrollbar-thumb:hover{background-color:var(--canton-highlight)}[data-theme=\"dark\"]{--canton-text-primary: #F5F5F5;--canton-text-secondary: #B0B0B0}button[aria-haspopup=\"menu\"]:not(.nav-dropdown-trigger):not(#page-context-menu *){background-color:transparent!important;border:1px solid rgba(209, 213, 219, 0.7)!important;border-radius:0.85rem!important;padding:0.375rem 0.875rem!important}button[aria-haspopup=\"menu\"]:not(.nav-dropdown-trigger):not(#page-context-menu *):hover{background-color:rgba(75, 85, 99, 0.05)!important}[data-theme=\"dark\"] button[aria-haspopup=\"menu\"]:not(.nav-dropdown-trigger):not(#page-context-menu *){border-color:rgba(255, 255, 255, 0.07)!important}button[aria-haspopup=\"menu\"]:not(.nav-dropdown-trigger):not(#page-context-menu *) svg{color:rgb(156, 163, 175)!important;stroke:rgb(156, 163, 175)!important}button[aria-haspopup=\"menu\"]:not(.nav-dropdown-trigger):not(#page-context-menu *):hover svg{color:rgb(75, 85, 99)!important;stroke:rgb(75, 85, 99)!important}[data-theme=\"dark\"] button[aria-haspopup=\"menu\"]:not(.nav-dropdown-trigger):not(#page-context-menu *) svg{color:rgb(75, 85, 99)!important;stroke:rgb(75, 85, 99)!important}[data-theme=\"dark\"] button[aria-haspopup=\"menu\"]:not(.nav-dropdown-trigger):not(#page-context-menu *):hover svg{color:rgb(156, 163, 175)!important;stroke:rgb(156, 163, 175)!important}.mermaid{--mermaid-primary-color: var(--canton-highlight)}div.group.relative.overflow-hidden:has(svg)>div.absolute.bottom-2.right-2{opacity:0.1;transition:opacity 200ms ease-in-out}div.group.relative.overflow-hidden:has(svg):hover>div.absolute.bottom-2.right-2,div.group.relative.overflow-hidden:has(svg):focus-within>div.absolute.bottom-2.right-2{opacity:1}div.todo{display:none}body:has(.x2mdx-ref-page):not(:has(.x2mdx-ref-page--manual-api)) #background-color{background-color:var(--x2mdx-ref-canvas)!important}body:has(.x2mdx-ref-page):not(:has(.x2mdx-ref-page--manual-api)) #navbar{border-bottom:1px solid var(--x2mdx-ref-border);background-color:var(--x2mdx-ref-surface)}body:has(.x2mdx-ref-page):not(:has(.x2mdx-ref-page--manual-api)) #sidebar{background-color:var(--x2mdx-ref-sidebar)}body:has(.x2mdx-ref-page):not(:has(.x2mdx-ref-page--manual-api)) #content-container{color:var(--x2mdx-ref-text-muted)}body:has(.x2mdx-ref-page):not(:has(.x2mdx-ref-page--manual-api)) #content-container :is(h1,h2,h3,h4,h5,h6){color:var(--x2mdx-ref-text-strong)}.x2mdx-ref-back{margin:0 0 0.75rem;font-size:0.9rem}.x2mdx-ref-back a{color:var(--canton-highlight);text-decoration:none}.x2mdx-ref-hero{display:grid;min-width:0;max-width:100%;gap:0.75rem;margin:0 0 1.4rem}.x2mdx-ref-hero>*{min-width:0;max-width:100%;overflow-wrap:anywhere}#content-container:has(.x2mdx-ref-page):not(:has(.x2mdx-ref-page--manual-api)) #page-title{display:none!important}#content-container:has(.x2mdx-ref-page) #header>.mt-2.text-lg.prose{display:none!important}.x2mdx-ref-breadcrumbs{display:flex;flex-wrap:wrap;align-items:center;gap:0.5rem;margin:0 0 0.75rem;color:var(--x2mdx-ref-text-muted);font-size:0.9rem;line-height:1.35}.x2mdx-ref-breadcrumbs a{color:var(--canton-highlight);text-decoration:none}.x2mdx-ref-breadcrumbs a:hover{text-decoration:underline}.x2mdx-ref-breadcrumb-separator{color:rgb(156, 163, 175)}.x2mdx-ref-eyebrow{min-width:0;max-width:100%;margin:0;overflow-wrap:anywhere;font-size:0.78rem;font-weight:600;letter-spacing:0.08em;text-transform:uppercase;color:var(--x2mdx-ref-text-muted)}:root.dark .x2mdx-ref-eyebrow,[data-theme=\"dark\"] .x2mdx-ref-eyebrow{color:rgb(156, 163, 175)}.x2mdx-ref-title{min-width:0;max-width:100%;margin:0;overflow-wrap:anywhere;color:var(--x2mdx-ref-text-strong);font-size:clamp(2rem, 3vw, 2.7rem);line-height:1.05}#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-title{max-width:100%;overflow:hidden;font-size:clamp(1.7rem, 2.2vw, 2.25rem);line-height:1.08;text-overflow:ellipsis;white-space:nowrap;word-break:normal;overflow-wrap:normal}#content-container:has(.x2mdx-ref-page--manual-api) .x2mdx-ref-title{overflow:visible;text-overflow:clip;white-space:normal}#content-container:has(.x2mdx-ref-page--manual-api) #page-title{font-size:2.25rem!important;font-weight:600!important;line-height:2.5rem!important}#content-container:has(.x2mdx-ref-page--manual-api) .mdx-content h2{margin-top:1.8rem!important;margin-bottom:0!important;font-size:1.125rem!important;font-weight:600!important;line-height:1.6875rem!important}@media (max-width: 1023px){#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-title{white-space:normal;overflow:visible;text-overflow:clip}}@media (max-width: 639px){#content-container:has(.x2mdx-ref-page--manual-api) #page-title{font-size:1.875rem!important;line-height:2.25rem!important}body:has(.x2mdx-ref-page) .breadcrumb-list{min-width:0;max-width:100%;flex-wrap:wrap}body:has(.x2mdx-ref-page) .breadcrumb-item,body:has(.x2mdx-ref-page) .breadcrumb-item a{min-width:0;max-width:100%;overflow-wrap:anywhere}body:has(.x2mdx-ref-page) .mdx-content>div.table{display:block!important;box-sizing:border-box;width:100%!important;max-width:100%!important;overflow-x:auto}#content-container:has(.x2mdx-ref-page) #pagination{align-items:stretch;flex-direction:column;gap:0.75rem;min-width:0;max-width:100%}#content-container:has(.x2mdx-ref-page) #pagination>a{width:100%;min-width:0;max-width:100%;margin-left:0!important}#content-container:has(.x2mdx-ref-page) #pagination>a span{min-width:0;overflow-wrap:anywhere}}.x2mdx-ref-summary{margin:0;max-width:58rem;color:var(--x2mdx-ref-text-muted);font-size:1.02rem}#content-container:has(.x2mdx-ref-page--manual-api) #content-area #header>div:has(>p){display:block!important}body:has(.x2mdx-ref-page--manual-api):has(#header p) .x2mdx-ref-page--manual-api+.x2mdx-ref-hero .x2mdx-ref-summary{display:none}.x2mdx-ref-api-header-badges{margin-top:0.75rem}body:has(#x2mdx-ref-api-header-badges) .x2mdx-ref-page--manual-api+.x2mdx-ref-hero .x2mdx-ref-badges{display:none}:root.dark .x2mdx-ref-summary,[data-theme=\"dark\"] .x2mdx-ref-summary{color:rgb(209, 213, 219)}.x2mdx-ref-page--operation{display:none}#content-container:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)){max-width:92rem!important}body:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) #table-of-contents-content,body:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) #content-side-layout,body:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) #table-of-contents-layout,body:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) #table-of-contents,body:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) aside:has(#table-of-contents-content),body:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) [aria-label=\"Table of contents\"]{display:none!important}#content-container:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) #content-area{width:100%!important}.x2mdx-ref-operation-shell{display:grid;grid-template-columns:minmax(0, 1fr) minmax(22rem, 26rem);gap:clamp(2rem, 4vw, 4rem);align-items:start;width:100%}.x2mdx-ref-operation-main{min-width:0}.x2mdx-ref-operation-shell:not(:has(.x2mdx-ref-right-rail)){grid-template-columns:minmax(0, 1fr)}.x2mdx-ref-right-rail{display:grid;position:sticky;top:6rem;z-index:1;width:100%;margin:0;gap:1rem}.x2mdx-ref-rail-panel{min-width:0}@media (max-width: 1180px){.x2mdx-ref-operation-shell{grid-template-columns:minmax(0, 1fr)}.x2mdx-ref-right-rail{position:static;width:100%;margin:0 0 2rem}}.x2mdx-ref-rail-code :is(.code-group,[class*=\"code-group\"]){margin:0}.x2mdx-ref-rail-code{display:grid;gap:0.65rem;min-width:0}.x2mdx-ref-rail-head{display:flex;align-items:center;justify-content:space-between;gap:0.75rem;min-width:0}.x2mdx-ref-rail-heading{min-width:0;max-width:13rem;overflow:hidden;color:rgb(31, 41, 55);font-family:ui-monospace, SFMono-Regular, SFMono-RegularFallback, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;font-size:0.82rem;font-weight:500;line-height:1.25;text-overflow:ellipsis;white-space:nowrap}:root.dark .x2mdx-ref-rail-heading,[data-theme=\"dark\"] .x2mdx-ref-rail-heading{color:rgb(229, 231, 235)}.x2mdx-ref-operation-bar{display:flex;align-items:center;gap:0.75rem;width:100%;min-height:3.75rem;margin:0 0 3.25rem;padding:0.55rem 0.75rem;overflow:hidden;border:1px solid var(--x2mdx-ref-border);border-radius:1rem;background:var(--x2mdx-ref-surface);box-shadow:0 1px 2px rgba(13, 12, 17, 0.04)}:root.dark .x2mdx-ref-operation-bar,[data-theme=\"dark\"] .x2mdx-ref-operation-bar{border-color:rgba(255, 255, 255, 0.08);background:rgba(17, 17, 21, 0.6)}.x2mdx-ref-operation-method{flex:0 0 auto;padding:0.32rem 0.55rem;border-radius:0.55rem;background:rgba(22, 163, 74, 0.12);color:rgb(22, 163, 74);font-size:0.86rem;font-weight:700;line-height:1}.x2mdx-ref-operation-method--post,.x2mdx-ref-operation-method--json-rpc{background:rgba(37, 99, 235, 0.12);color:rgb(37, 99, 235)}.x2mdx-ref-operation-method--publish,.x2mdx-ref-operation-method--subscribe{background:rgba(124, 58, 237, 0.12);color:rgb(124, 58, 237)}.x2mdx-ref-operation-bar code{flex:1 1 auto;min-width:0;overflow:hidden;background:transparent;color:inherit;font-size:0.98rem;line-height:1.45;text-overflow:ellipsis;white-space:nowrap}#content-container:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) h2{margin-top:2.5rem!important;margin-bottom:1rem!important;font-size:1.35rem!important;font-weight:700!important;line-height:1.25!important}#content-container:has(.x2mdx-ref-page--operation):not(:has(.x2mdx-ref-page--manual-api)) h3{font-size:1rem!important;line-height:1.35!important}#content-container :is(a[id^=\"interface-\"],a[id^=\"type-alias-\"],a[id^=\"variable-\"],a[id^=\"function-\"])+h4:not(:first-of-type),#content-container :is(a[id^=\"class-\"],a[id^=\"constr-\"],a[id^=\"function-\"],a[id^=\"type-\"])+h3:not(:first-of-type){margin-top:2rem!important;padding-top:1.35rem!important;border-top:1px solid rgba(var(--canton-highlight-rgb), 0.54)}.x2mdx-ref-rail-code--response{position:relative}.x2mdx-ref-response-label{flex:0 1 auto;max-width:11rem;overflow:hidden;color:rgb(115, 114, 118);font-family:ui-monospace, SFMono-Regular, SFMono-RegularFallback, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;font-size:0.75rem;line-height:1.25;text-overflow:ellipsis;white-space:nowrap}:root.dark .x2mdx-ref-response-label,[data-theme=\"dark\"] .x2mdx-ref-response-label{color:rgb(162, 160, 165)}.x2mdx-ref-badges{display:flex;flex-wrap:wrap;gap:0.5rem}.x2mdx-ref-badge{display:inline-flex;align-items:center;min-height:1.55rem;padding:0.14rem 0.52rem;border:1px solid rgba(var(--canton-highlight-rgb), 0.16);border-radius:999px;background:var(--x2mdx-ref-accent-soft);color:var(--canton-highlight);font-size:0.76rem;font-weight:600;line-height:1.1;text-decoration:none}a.x2mdx-ref-badge:hover{filter:brightness(0.96);text-decoration:underline;text-underline-offset:0.16rem}a.x2mdx-ref-badge:focus-visible{outline:2px solid var(--canton-highlight);outline-offset:2px}.x2mdx-ref-badge--neutral{background:var(--x2mdx-ref-neutral-soft);border-color:rgba(107, 114, 128, 0.18);color:var(--x2mdx-ref-text-muted)}:root.dark .x2mdx-ref-badge--neutral,[data-theme=\"dark\"] .x2mdx-ref-badge--neutral{background:rgba(156, 163, 175, 0.12);border-color:rgba(156, 163, 175, 0.16);color:rgb(229, 231, 235)}.x2mdx-ref-badge--added{background:var(--x2mdx-ref-success-soft);border-color:rgba(21, 128, 61, 0.18);color:var(--x2mdx-ref-success)}.x2mdx-ref-badge--changed{background:var(--x2mdx-ref-info-soft);border-color:rgba(29, 78, 216, 0.18);color:var(--x2mdx-ref-info)}.x2mdx-ref-badge--removed{background:var(--x2mdx-ref-danger-soft);border-color:rgba(185, 28, 28, 0.18);color:var(--x2mdx-ref-danger)}.x2mdx-ref-meta-grid{display:grid;grid-template-columns:repeat(auto-fit, minmax(12rem, 1fr));gap:0.75rem;margin:0}.x2mdx-ref-meta-item{min-width:0;padding:0.85rem 0.95rem;border:1px solid var(--x2mdx-ref-border);border-radius:0.7rem;background:var(--x2mdx-ref-surface)}:root.dark .x2mdx-ref-meta-item,[data-theme=\"dark\"] .x2mdx-ref-meta-item{border-color:rgba(255, 255, 255, 0.08);background:rgba(17, 24, 39, 0.7)}.x2mdx-ref-meta-label{display:block;margin:0 0 0.3rem;font-size:0.77rem;font-weight:600;text-transform:uppercase;color:var(--x2mdx-ref-text-muted)}.x2mdx-ref-meta-value{display:block;margin:0;overflow-wrap:anywhere;font-size:0.96rem;font-weight:500;color:var(--x2mdx-ref-text)}.x2mdx-ref-card-grid{display:grid;grid-template-columns:repeat(auto-fit, minmax(16rem, 1fr));gap:1rem}.x2mdx-ref-card{display:grid;align-content:start;gap:0.8rem;min-height:100%;min-width:0;padding:1rem;border:1px solid var(--x2mdx-ref-border);border-radius:0.7rem;background:var(--x2mdx-ref-surface);color:inherit;text-decoration:none;transition:border-color 160ms ease, transform 160ms ease, background-color 160ms ease}.x2mdx-ref-card>*{min-width:0}:root.dark .x2mdx-ref-card,[data-theme=\"dark\"] .x2mdx-ref-card{border-color:rgba(255, 255, 255, 0.08);background:rgba(17, 24, 39, 0.78)}.x2mdx-ref-card:hover{border-color:rgba(var(--canton-highlight-rgb), 0.42);transform:translateY(-1px)}.x2mdx-ref-card-head{display:contents}.x2mdx-ref-card-title{order:0;margin:0;font-size:1rem;font-weight:700;line-height:1.3;color:var(--x2mdx-ref-text-strong);text-decoration:none;overflow-wrap:anywhere}.x2mdx-ref-card-title:hover{color:rgb(var(--canton-highlight-rgb))}.x2mdx-ref-card .x2mdx-ref-badges{order:2}.x2mdx-ref-card-summary{order:1;margin:0;color:var(--x2mdx-ref-text-muted);overflow-wrap:anywhere}.x2mdx-ref-card .x2mdx-ref-meta-grid{order:3}.x2mdx-ref-history{display:grid;gap:0.75rem;margin:0 0 2rem}.x2mdx-ref-history,.x2mdx-ref-history-event,.x2mdx-ref-history-event-head,.x2mdx-ref-history-event-detail{min-width:0;max-width:100%}.x2mdx-ref-history-event{display:grid;gap:0.5rem;padding:0.9rem 1rem;border:0;border-left:3px solid var(--x2mdx-ref-text-muted);border-radius:0.7rem;background:var(--x2mdx-ref-neutral-soft);scroll-margin-top:6rem}:root.dark .x2mdx-ref-history-event,[data-theme=\"dark\"] .x2mdx-ref-history-event{color:var(--x2mdx-ref-text)}.x2mdx-ref-history-event--introduced{border-left-color:var(--x2mdx-ref-success);background:var(--x2mdx-ref-success-soft)}.x2mdx-ref-history-event--changed,.x2mdx-ref-history-event--replacement{border-left-color:var(--x2mdx-ref-info);background:var(--x2mdx-ref-info-soft)}.x2mdx-ref-history-event--removed,.x2mdx-ref-history-event--deprecated,.x2mdx-ref-history-event--remove-as-of{border-left-color:var(--x2mdx-ref-danger);background:var(--x2mdx-ref-danger-soft)}.x2mdx-ref-history-event-head{display:flex;align-items:baseline;justify-content:space-between;gap:1rem}.x2mdx-ref-history-event-label{color:var(--x2mdx-ref-text-strong);font-size:0.92rem;font-weight:700;line-height:1.3}.x2mdx-ref-history-event-version{flex:0 0 auto;background:transparent;color:var(--x2mdx-ref-text-muted);font-size:0.82rem}:root.dark .x2mdx-ref-history-event-version,[data-theme=\"dark\"] .x2mdx-ref-history-event-version{color:rgb(209, 213, 219)}.x2mdx-ref-history-event-detail{margin:0;overflow-wrap:anywhere;color:var(--x2mdx-ref-text-muted);font-size:0.92rem;line-height:1.5}:root.dark .x2mdx-ref-history-event-detail,[data-theme=\"dark\"] .x2mdx-ref-history-event-detail{color:rgb(209, 213, 219)}@media (max-width: 640px){.x2mdx-ref-history-event-head{align-items:flex-start;flex-direction:column;gap:0.35rem}}:root.dark .x2mdx-ref-card-summary,[data-theme=\"dark\"] .x2mdx-ref-card-summary{color:rgb(209, 213, 219)}.x2mdx-ref-panel,.x2mdx-ref-schema{margin:0 0 1rem;padding:1rem;border:1px solid rgba(15, 23, 42, 0.08);border-radius:0.7rem;background:rgba(255, 255, 255, 0.82)}#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-panel,#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-schema{margin:0 0 1.9rem;padding:0;border:0;border-radius:0;background:transparent}#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-panel-head,#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-schema-head{margin-bottom:0.65rem}#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-grid{display:flex;flex-wrap:wrap;gap:0.45rem 1.1rem;padding:0.8rem 0;border-top:1px solid rgba(15, 23, 42, 0.08);border-bottom:1px solid rgba(15, 23, 42, 0.08)}#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-item{display:flex;align-items:baseline;gap:0.35rem;min-width:0;padding:0;border:0;border-radius:0;background:transparent}#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-label{margin:0;font-size:0.72rem;letter-spacing:0;text-transform:none}#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-label::after{content:\":\"}#content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-value{max-width:32rem;font-size:0.86rem;font-weight:500}:root.dark #content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-grid,[data-theme=\"dark\"] #content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-grid,:root.dark #content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-item,[data-theme=\"dark\"] #content-container:has(.x2mdx-ref-page--operation) .x2mdx-ref-meta-item{border-color:rgba(255, 255, 255, 0.08);background:transparent}:root.dark .x2mdx-ref-panel,:root.dark .x2mdx-ref-schema,[data-theme=\"dark\"] .x2mdx-ref-panel,[data-theme=\"dark\"] .x2mdx-ref-schema{border-color:rgba(255, 255, 255, 0.08);background:rgba(17, 24, 39, 0.78)}.x2mdx-ref-panel-head,.x2mdx-ref-schema-head{display:grid;gap:0.3rem;margin-bottom:0.9rem}.x2mdx-ref-panel-head h3,.x2mdx-ref-schema-head h3{margin:0;font-size:1rem;line-height:1.3;overflow-wrap:anywhere}.x2mdx-ref-schema-variants{display:grid;gap:0.8rem;margin-top:0.9rem}.x2mdx-ref-schema-variant-label{font-size:0.77rem;font-weight:700;text-transform:uppercase;color:rgb(107, 114, 128)}.x2mdx-ref-schema-variant{display:grid;gap:0.65rem;min-width:0;padding:0.85rem;border:1px solid rgba(15, 23, 42, 0.08);border-radius:0.65rem;background:rgba(248, 250, 252, 0.72)}:root.dark .x2mdx-ref-schema-variant,[data-theme=\"dark\"] .x2mdx-ref-schema-variant{border-color:rgba(255, 255, 255, 0.08);background:rgba(17, 24, 39, 0.58)}.x2mdx-ref-schema-variant-head{display:grid;gap:0.25rem}.x2mdx-ref-schema-variant-head h4{margin:0;font-size:0.94rem;line-height:1.3;overflow-wrap:anywhere}body:has(.x2mdx-ref-hero) #table-of-contents-content a,body:has(.x2mdx-ref-hero) [aria-label=\"Table of contents\"] a{overflow-wrap:anywhere;word-break:normal}.x2mdx-ref-panel-summary,.x2mdx-ref-schema-summary,.x2mdx-ref-schema-description{margin:0;color:rgb(75, 85, 99)}:root.dark .x2mdx-ref-panel-summary,:root.dark .x2mdx-ref-schema-summary,:root.dark .x2mdx-ref-schema-description,[data-theme=\"dark\"] .x2mdx-ref-panel-summary,[data-theme=\"dark\"] .x2mdx-ref-schema-summary,[data-theme=\"dark\"] .x2mdx-ref-schema-description{color:rgb(209, 213, 219)}.x2mdx-ref-fields{display:grid;margin-top:0.75rem;border-top:1px solid rgba(15, 23, 42, 0.08);border-bottom:1px solid rgba(15, 23, 42, 0.08);border-radius:0;overflow:hidden}:root.dark .x2mdx-ref-fields,[data-theme=\"dark\"] .x2mdx-ref-fields{border-color:rgba(255, 255, 255, 0.08)}.x2mdx-ref-field-row{display:grid;gap:0.35rem;padding:0.75rem 0;background:transparent}.x2mdx-ref-field-row+.x2mdx-ref-field-row{border-top:1px solid rgba(15, 23, 42, 0.08)}:root.dark .x2mdx-ref-field-row+.x2mdx-ref-field-row,[data-theme=\"dark\"] .x2mdx-ref-field-row+.x2mdx-ref-field-row{border-top-color:rgba(255, 255, 255, 0.08)}.x2mdx-ref-field-main{display:flex;flex-wrap:wrap;align-items:center;gap:0.45rem;min-width:0}.x2mdx-ref-field-name{background:transparent;color:var(--canton-highlight);font-size:0.94rem;font-weight:600}.x2mdx-ref-type-badge,.x2mdx-ref-required-badge{display:inline-flex;align-items:center;min-height:1.45rem;padding:0.1rem 0.45rem;border-radius:0.42rem;font-family:ui-monospace, SFMono-Regular, SFMono-RegularFallback, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;font-size:0.76rem;line-height:1}.x2mdx-ref-type-badge{background:rgba(107, 114, 128, 0.12);color:rgb(55, 65, 81)}.x2mdx-ref-required-badge{background:rgba(220, 38, 38, 0.1);color:rgb(153, 27, 27)}.x2mdx-ref-field-description{color:rgb(75, 85, 99);font-size:0.9rem;line-height:1.45;white-space:pre-wrap}@media (max-width: 900px){.x2mdx-ref-field-row{padding:0.7rem 0}}.x2mdx-ref-example-heading{margin:1rem 0 0.45rem;font-size:0.88rem;font-weight:600;text-transform:uppercase;color:rgb(107, 114, 128)}.x2mdx-ref-change-list{display:grid;gap:0.7rem}.x2mdx-ref-change-item{display:grid;gap:0.35rem;padding:0.9rem 1rem;border-left:3px solid var(--canton-highlight);border-radius:0.6rem;background:rgba(var(--canton-highlight-rgb), 0.06)}.x2mdx-ref-change-version{font-size:0.82rem;font-weight:700;text-transform:uppercase;color:var(--canton-highlight)}.x2mdx-ref-enum-list{margin:0.8rem 0 0;padding-left:1rem}"}]}
{"page":{"pagePath":"appdev/modules/m3-working-with-time","slug":"/appdev/modules/m3-working-with-time","pageMetadata":{"title":"Working with Time","description":"Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints","href":"/appdev/modules/m3-working-with-time"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={blockquote:`blockquote`,code:`code`,em:`em`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Mermaid,Tip}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Mermaid)_missingMdxReference(`Mermaid`,true);if(!Tip)_missingMdxReference(`Tip`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`1`,id:`how-to-implement-time-constraints`,children:`How To Implement Time Constraints`}),`\n`,_jsx(_components.p,{children:`Contract time constraints may be implemented using either:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[`ledger time primitives (i.e. `,_jsx(_components.code,{children:`isLedgerTimeLT`}),`, `,_jsx(_components.code,{children:`isLedgerTimeLE`}),`, `,_jsx(_components.code,{children:`isLedgerTimeGT`}),` and `,_jsx(_components.code,{children:`isLedgerTimeGE`}),`) or assertions (i.e. `,_jsx(_components.code,{children:`assertWithinDeadline`}),` and `,_jsx(_components.code,{children:`assertDeadlineExceeded`}),`)`]}),`\n`,_jsxs(_components.blockquote,{children:[`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`the use of ledger time primitives and assertions do not constrain the time bound between transaction preparation and submission - e.g. they are suitable for workflows using external parties to sign transactions`}),`\n`]}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[`or, by calling `,_jsx(_components.code,{children:`getTime`})]}),`\n`,_jsxs(_components.blockquote,{children:[`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`calls to `,_jsx(_components.code,{children:`getTime`}),` constrain transaction preparation and submission workflows to be (by default) within 1 minute.`]}),`\n`,_jsx(_components.li,{children:`the 1 minute value is the default value for the ledger time record time tolerance parameter (a dynamic synchronizer parameter).`}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`The next subsections demonstrate how the following Coin and TransferProposal contracts can be modified to use different types of ledger time constraints to control when parties are allowed to perform ledger writes.`}),`\n`,_jsx(_components.p,{children:`Coin contract`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`10`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`template `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`Coin`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` owner`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Party`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` issuer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Party`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` amount`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Decimal`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` where`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` signatory issuer`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` signatory owner`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` ensure amount `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`>`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` 0.0`})]}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`Transfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` TransferProposal`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Party`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller owner`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`TransferProposal`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`this; newOwner`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`TransferProposal contract`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`template `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`TransferProposal`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Coin`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Party`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` where`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` signatory coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`.`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`owner`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` signatory coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`.`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`issuer`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` observer newOwner`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`AcceptTransfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Coin`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller newOwner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create coin with owner `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`})]}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`WithdrawTransfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Coin`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`.`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`owner`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create coin`})}),`\n`]})})}),`\n`,_jsx(Mermaid,{chart:`flowchart LR\n subgraph Coin[\"Coin (active)\"]\n C1[\"owner: Alice\u003cbr/>issuer: Bank\u003cbr/>newOwner: Bob\"]\n end\n Coin -->|\"Transfer\"| TP\n subgraph TP[\"TransferProposal (active)\"]\n T1[\"newOwner: Bob\u003cbr/>coin: Coin\"]\n end\n TP -->|\"AcceptTransfer\"| Coin2\n subgraph Coin2[\"Coin (new owner)\"]\n C2[\"owner: Bob\u003cbr/>issuer: Bank\"]\n end`}),`\n`,_jsx(_components.p,{children:_jsx(_components.em,{children:`Simple coin transfer with consent withdrawal`})}),`\n`,_jsx(Heading,{level:`2`,id:`how-to-check-that-a-deadline-is-valid`,children:`How to check that a deadline is valid`}),`\n`,_jsx(_components.p,{children:`This design pattern demonstrates how to limit choices so that they must occur by a given deadline.`}),`\n`,_jsx(Heading,{level:`3`,id:`motivation`,children:`Motivation`}),`\n`,_jsx(_components.p,{children:`When parties need to perform ledger writes by a given deadline.`}),`\n`,_jsx(Heading,{level:`3`,id:`implementation`,children:`Implementation`}),`\n`,_jsx(_components.p,{children:`Transfer proposals can be accepted at any point in time. To restrict this behaviour so that acceptance must occur by a fixed time, a guard for AcceptTransfer choice execution can be added.`}),`\n`,_jsx(_components.p,{children:`TransferProposal contract\nIn the TransferProposal contract, the body of the AcceptTransfer choice is modified to assert that the contract deadline is valid.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`AcceptTransfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Coin`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller newOwner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` assertWithinDeadline `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"time-limited-transfer\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` timeLimit`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create coin with owner `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`As transfer proposals are created when a Transfer choice is executed, the time by which an AcceptTransfer can be executed needs to be passed in as a choice parameter.`}),`\n`,_jsx(_components.p,{children:`Coin contract\nIn the Coin contract, the Transfer choice has an additional deadline argument, so that TransferProposal contracts can be given a fixed lifetime.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`Transfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` TransferProposal`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Party`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` timeLimit`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Time`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller owner`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`TransferProposal`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`this; newOwner; timeLimit`})]}),`\n`]})})}),`\n`,_jsx(Mermaid,{chart:`flowchart LR\n subgraph Coin[\"Coin (active)\"]\n C1[\"owner: Alice\u003cbr/>issuer: Bank\"]\n end\n Coin -->|\"Transfer(deadline)\"| TP\n subgraph TP[\"TransferProposal\"]\n T1[\"newOwner: Bob\u003cbr/>deadline: timestamp\"]\n end\n TP -->|\"AcceptTransfer\u003cbr/>assert now ≤ deadline\"| Coin2\n subgraph Coin2[\"Coin (new owner)\"]\n C2[\"owner: Bob\u003cbr/>issuer: Bank\"]\n end`}),`\n`,_jsx(_components.p,{children:_jsx(_components.em,{children:`Time-limited coin ownership transfer`})}),`\n`,_jsx(Heading,{level:`2`,id:`how-to-check-that-a-deadline-has-passed`,children:`How to check that a deadline has passed`}),`\n`,_jsx(_components.p,{children:`This design pattern demonstrates how to ensure choices only occur after a given deadline.`}),`\n`,_jsx(Heading,{level:`3`,id:`motivation-2`,children:`Motivation`}),`\n`,_jsx(_components.p,{children:`When parties need to perform ledger writes after a fixed time delay.`}),`\n`,_jsx(Heading,{level:`3`,id:`implementation-2`,children:`Implementation`}),`\n`,_jsx(_components.p,{children:`Transfer proposals can be accepted at any point in time. To restrict this behaviour so that acceptance can only occur after a fixed delay, a guard for AcceptTransfer choice execution can be added.`}),`\n`,_jsx(_components.p,{children:`TransferProposal contract\nIn the TransferProposal contract, the body of the AcceptTransfer choice is modified to assert that the contract deadline has been exceeded or passed.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`AcceptTransfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Coin`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller newOwner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` assertDeadlineExceeded `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"delayed-transfer\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` delay`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create coin with owner `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`As transfer proposals are created when a Transfer choice is executed, the delay time after which an AcceptTransfer can be executed needs to be passed in as a choice parameter.`}),`\n`,_jsx(_components.p,{children:`Coin contract\nIn the Coin contract, the Transfer choice has an additional deadline argument, so that TransferProposal contracts can be given a delay.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`Transfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` TransferProposal`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Party`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` delay`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Time`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller owner`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`TransferProposal`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`this; newOwner; delay`})]}),`\n`]})})}),`\n`,_jsx(Mermaid,{chart:`flowchart LR\n subgraph Coin[\"Coin (active)\"]\n C1[\"owner: Alice\u003cbr/>issuer: Bank\"]\n end\n Coin -->|\"Transfer(delay)\"| TP\n subgraph TP[\"TransferProposal\"]\n T1[\"newOwner: Bob\u003cbr/>delay: duration\"]\n end\n TP -->|\"AcceptTransfer\u003cbr/>assert now > delay\"| Coin2\n subgraph Coin2[\"Coin (new owner)\"]\n C2[\"owner: Bob\u003cbr/>issuer: Bank\"]\n end`}),`\n`,_jsx(_components.p,{children:_jsx(_components.em,{children:`Delayed coin ownership transfer`})}),`\n`,_jsx(Heading,{level:`2`,id:`grant-time-limited-writes-to-parties`,children:`Grant time-limited writes to parties`}),`\n`,_jsx(_components.p,{children:`This design pattern demonstrates how to grant time-limited writes to parties.`}),`\n`,_jsx(Heading,{level:`3`,id:`motivation-3`,children:`Motivation`}),`\n`,_jsx(_components.p,{children:`When parties need to be able to perform ledger writes, but writes need to only be granted for a specific time window.`}),`\n`,_jsx(Heading,{level:`3`,id:`implementation-3`,children:`Implementation`}),`\n`,_jsx(_components.p,{children:`Transfer proposals can be accepted at any point in time. To restrict this behaviour so that acceptance can only occur within a given time window, a guard for AcceptTransfer choice execution can be added.`}),`\n`,_jsx(_components.p,{children:`TransferProposal contract\nIn the TransferProposal contract, the body of the AcceptTransfer choice is modified to assert that the contract deadline has been exceeded or passed.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`AcceptTransfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Coin`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller newOwner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` withinWindow `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`\u003c-`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` isLedgerTimeGE startTime `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`\u0026\u0026`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` isLedgerTimeLT endTime`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` _ `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`\u003c-`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` unless withinWindow `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`$`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` failWithStatus `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`$`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` FailureStatus`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"transfer-outside-time-window\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` InvalidGivenCurrentSystemStateOther`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` (`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"Ledger time is outside permitted transfer time window [\"`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` \u003c>`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` show startTime `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`\u003c>`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \", \"`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` \u003c>`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` show endTime `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`\u003c>`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \")\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` (`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`TextMap.`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`fromList [(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"startTime\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`, show startTime), (`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"endTime\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`, show endTime)])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create coin with owner `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`As transfer proposals are created when a Transfer choice is executed, the interval start and end times, during which an AcceptTransfer can be executed need to be passed in as choice parameters.`}),`\n`,_jsx(_components.p,{children:`Coin contract\nIn the Coin contract, the Transfer choice has an additional deadline argument, so that TransferProposal contracts can be given a delay.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`Transfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` TransferProposal`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Party`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` startTime`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Time`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` duration`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` RelTime`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller owner`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`TransferProposal`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`this; newOwner; startTime; addRelTime startTime duration`})]}),`\n`]})})}),`\n`,_jsx(Mermaid,{chart:`flowchart LR\n subgraph Coin[\"Coin (active)\"]\n C1[\"owner: Alice\u003cbr/>issuer: Bank\"]\n end\n Coin -->|\"Transfer(start, end)\"| TP\n subgraph TP[\"TransferProposal\"]\n T1[\"newOwner: Bob\u003cbr/>startTime: timestamp\u003cbr/>endTime: timestamp\"]\n end\n TP -->|\"AcceptTransfer\u003cbr/>assert start ≤ now ≤ end\"| Coin2\n subgraph Coin2[\"Coin (new owner)\"]\n C2[\"owner: Bob\u003cbr/>issuer: Bank\"]\n end`}),`\n`,_jsx(_components.p,{children:_jsx(_components.em,{children:`Coin ownership transfer within a time window`})}),`\n`,_jsx(Heading,{level:`2`,id:`where-to-use-gettime`,children:`Where to use getTime`}),`\n`,_jsx(_components.p,{children:`For workflows that prepare and submit transactions, care needs to be taken when using calls to getTime. This is because calls to getTime cause transactions to be bound to the ledger time, and in turn constrain how sequencers may re-order transactions. Global Synchronizers are configured such that the transaction prepare and submit time window is one minute, so any workflow using getTime must prepare and submit transactions within that one-minute time window.`}),`\n`,_jsx(_components.p,{children:`For workflows where this constraint can not be met (e.g. workflows that sign transactions using external parties), it is recommended that workflows are designed to use the ledger time primitives and assertions.`}),`\n`,_jsx(Heading,{level:`3`,id:`motivation-4`,children:`Motivation`}),`\n`,_jsx(_components.p,{children:`When parties need to perform ledger writes by a given deadline, but are able to prepare and submit a transaction within 1 minute.`}),`\n`,_jsx(Heading,{level:`3`,id:`implementation-4`,children:`Implementation`}),`\n`,_jsx(_components.p,{children:`Transfer proposals can be accepted at any point in time. To require acceptance by a fixed time, you can add a guard for AcceptTransfer choice execution. Here you determine the current ledger time by calling getTime.`}),`\n`,_jsx(_components.p,{children:`TransferProposal contract\nIn the TransferProposal contract, the body of the AcceptTransfer choice is modified to assert that the contract deadline is valid relative to the ledger time returned by calling getTime.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`AcceptTransfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Coin`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller newOwner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` t `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`\u003c-`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` getTime`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` _ `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`\u003c-`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` unless (t `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`\u003c`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` timeLimit) `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`$`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` failWithStatus `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`$`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` FailureStatus`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"deadline-exceeded\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` InvalidGivenCurrentSystemStateOther`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` (`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"Ledger time is after deadline \"`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` \u003c>`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` show timeLimit)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` (`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`TextMap.`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`fromList [(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"timeLimit\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`, show timeLimit)])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create coin with owner `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`As transfer proposals are created when a Transfer choice is executed, the time by which an AcceptTransfer can be executed needs to be passed in as a choice parameter.`}),`\n`,_jsx(_components.p,{children:`Coin contract\nIn the Coin contract, the Transfer choice has an additional deadline argument, so that TransferProposal contracts can be given a fixed lifetime.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`haskell`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`haskell`,children:_jsxs(_components.code,{language:`haskell`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`choice `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`Transfer`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` :`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` ContractId`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` TransferProposal`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` newOwner`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Party`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` timeLimit`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` Time`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` controller owner`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` do`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` create `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`TransferProposal`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` with coin`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`this; newOwner; timeLimit`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`1`,id:`add-constraints-to-a-contract`,children:`Add constraints to a contract`}),`\n`,_jsx(_components.p,{children:`You will often want to constrain the data stored or the allowed data transformations in your contract models. In this section, you will learn about the two main mechanisms provided in Daml:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`The `,_jsx(_components.code,{children:`ensure`}),` keyword.`]}),`\n`,_jsxs(_components.li,{children:[`The `,_jsx(_components.code,{children:`assert`}),`, `,_jsx(_components.code,{children:`abort`}),` and, `,_jsx(_components.code,{children:`error`}),` keywords.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`To make sense of the latter, you’ll also learn more about the `,_jsx(_components.code,{children:`Update`}),` and `,_jsx(_components.code,{children:`Script`}),` types, and `,_jsx(_components.code,{children:`do`}),` blocks, which will be good preparation for `,_jsx(_components.code,{children:`compose`}),`, where you will use `,_jsx(_components.code,{children:`do`}),` blocks to compose choices into complex transactions.`]}),`\n`,_jsx(_components.p,{children:`Lastly, you will learn about time on the ledger and in Daml Script.`}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`Remember that you can load all the code for this section into a folder called `,_jsx(_components.code,{children:`intro-constraints`}),` by running `,_jsx(_components.code,{children:`dpm new intro-constraints --template daml-intro-constraints`})]})}),`\n`,_jsx(Heading,{level:`2`,id:`template-preconditions`,children:`Template preconditions`}),`\n`,_jsxs(_components.p,{children:[`The first kind of restriction you may want to put on the contract model are called `,_jsx(_components.em,{children:`template pre-conditions`}),`. These are simply restrictions on the data that can be stored on a contract from that template.`]}),`\n`,_jsxs(_components.p,{children:[`Suppose, for example, that the `,_jsx(_components.code,{children:`SimpleIou`}),` contract from `,_jsx(_components.code,{children:`simple_iou`}),` should only be able to store positive amounts. You can enforce this using the `,_jsx(_components.code,{children:`ensure`}),` keyword:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`template SimpleIou`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` issuer : Party`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` owner : Party`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` cash : Cash`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` where`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` signatory issuer`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` observer owner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` ensure cash.amount > 0.0`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`ensure`}),` keyword takes a single expression of type `,_jsx(_components.code,{children:`Bool`}),`. If you want to add more restrictions, use logical operators `,_jsx(_components.code,{children:`\u0026\u0026`}),`, `,_jsx(_components.code,{children:`||`}),`, and `,_jsx(_components.code,{children:`not`}),` to build up expressions. The below shows the additional restriction that currencies are three capital letters:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`3`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`\u0026\u0026 T.length cash.currency == 3`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \u0026\u0026 T.isUpper cash.currency`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`T`}),` here stands for the `,_jsx(_components.code,{children:`DA.Text`}),` which has been imported from the Daml standard library using `,_jsx(_components.code,{children:`import DA.Text as T`}),`:`]})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`41`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`41`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`test_restrictions = do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` alice \u003c- allocateParty \"Alice\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` bob \u003c- allocateParty \"Bob\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` dora \u003c- allocateParty \"Dora\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- Dora can't issue negative Ious.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submitMustFail dora do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` createCmd SimpleIou with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` issuer = dora`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` owner = alice`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` cash = Cash with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` amount = -100.0`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` currency = \"USD\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- Or even zero Ious.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submitMustFail dora do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` createCmd SimpleIou with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` issuer = dora`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` owner = alice`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` cash = Cash with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` amount = 0.0`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` currency = \"USD\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- Nor positive Ious with invalid currencies.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submitMustFail dora do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` createCmd SimpleIou with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` issuer = dora`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` owner = alice`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` cash = Cash with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` amount = 100.0`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` currency = \"Swiss Francs\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- But positive Ious still work, of course.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` iou \u003c- submit dora do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` createCmd SimpleIou with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` issuer = dora`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` owner = alice`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` cash = Cash with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` amount = 100.0`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` currency = \"USD\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`2`,id:`assertions`,children:`Assertions`}),`\n`,_jsx(_components.p,{children:`A second common kind of restriction is one on data transformations.`}),`\n`,_jsxs(_components.p,{children:[`For example, the simple Iou in `,_jsx(_components.code,{children:`simple_iou`}),` allowed the no-op where the `,_jsx(_components.code,{children:`owner`}),` transfers to themselves. You can prevent that using an `,_jsx(_components.code,{children:`assert`}),` statement, which you have already encountered in the context of scripts.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`assert`}),` does not return an informative error so often it’s better to use the function `,_jsx(_components.code,{children:`assertMsg`}),`, which takes a custom error message:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`choice Transfer`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` : ContractId SimpleIou`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` newOwner : Party`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` controller owner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` assertMsg \"newOwner cannot be equal to owner.\" (owner /= newOwner)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` create this with owner = newOwner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`10`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`-- Alice can't transfer to herself...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submitMustFail alice do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` exerciseCmd iou Transfer with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` newOwner = alice`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- ... but can transfer to Bob.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` iou2 \u003c- submit alice do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` exerciseCmd iou Transfer with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` newOwner = bob`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`Similarly, you can write a `,_jsx(_components.code,{children:`Redeem`}),` choice, which allows the `,_jsx(_components.code,{children:`owner`}),` to redeem an `,_jsx(_components.code,{children:`Iou`}),` `,_jsx(_components.em,{children:`during business hours on weekdays`}),`. The `,_jsx(_components.code,{children:`Redeem`}),` choice implementation below confirms that `,_jsx(_components.code,{children:`getTime`}),` returns a value that is during business hours on weekdays. If all those checks pass, the choice does not do anything other than archive the `,_jsx(_components.code,{children:`SimpleIou`}),`. (This assumes that actual cash changes hands off-ledger:)`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`17`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`17`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`choice Redeem`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` : ()`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` controller owner`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` now \u003c- getTime`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` today = toDateUTC now`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` dow = dayOfWeek today`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:\" timeofday = now `subTime` time today 0 0 0\"})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` hrs = convertRelTimeToMicroseconds timeofday / 3600000000`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` if (hrs \u003c 8 || hrs > 18) then`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` abort $ \"Cannot redeem outside business hours. Current time: \" \u003c> show timeofday`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` else case dow of`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Saturday -> abort \"Cannot redeem on a Saturday.\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Sunday -> abort \"Cannot redeem on a Sunday.\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` _ -> return ()`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`In the above example, the time is taken apart into day of week and hour of day using standard library functions from `,_jsx(_components.code,{children:`DA.Date`}),` and `,_jsx(_components.code,{children:`DA.Time`}),`. The hour of the day is checked to be in the range from 8 to 18. The day of week is checked to not be Saturday or Sunday.`]}),`\n`,_jsxs(_components.p,{children:[`The following example shows how the `,_jsx(_components.code,{children:`Redeem`}),` choice is exercised in a script:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`22`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`22`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`-- June 1st 2019 is a Saturday.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` setTime (time (date 2019 Jun 1) 0 0 0)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- Bob cannot redeem on a Saturday.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submitMustFail bob do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` exerciseCmd iou2 Redeem`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- Not even at mid-day.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` passTime (hours 12)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- Bob cannot redeem on a Saturday.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submitMustFail bob do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` exerciseCmd iou2 Redeem`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- Bob also cannot redeem at 6am on a Monday.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` passTime (hours 42)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submitMustFail bob do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` exerciseCmd iou2 Redeem`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- Bob can redeem at 8am on Monday.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` passTime (hours 2)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submit bob do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` exerciseCmd iou2 Redeem`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`For the purposes of testing the `,_jsx(_components.code,{children:`Redeem`}),` choice, the above code sets and advances the ledger time with the `,_jsx(_components.code,{children:`setTime`}),` and `,_jsx(_components.code,{children:`passTime`}),` functions respectively. Exercising the choice should fail or should not fail depending on the day of week and the time of day. While that is straightforward, the issue of time on a Daml ledger is worthy of more discussion.`]}),`\n`,_jsx(Heading,{level:`2`,id:`time-on-daml-ledgers`,children:`Time on Daml ledgers`}),`\n`,_jsxs(_components.p,{children:[`Each transaction on a Daml ledger has two timestamps: the `,_jsx(_components.em,{children:`ledger time (LT)`}),` and the `,_jsx(_components.em,{children:`record time (RT)`}),`.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Ledger time (LT)`}),\" is the time associated with a transaction in the ledger model, as determined by the participant. It is the time of a transaction from a business and application perspective. When you call `getTime, it is the LT that is returned. The LT is used when reasoning about related transactions and commits. The LT can be compared with other LTs to guarantee model consistency. For example, LTs are used to enforce that no transaction depends on a contract that does not exist. This is the requirement known as “causal monotonicity.”\"]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Record time (RT)`}),` is the time assigned by the persistence layer. It represents the time that the transaction is “physically” recorded. For example, “The backing database ledger has assigned the timestamp of such-and-such time to this transaction.” The only purpose of the RT is to ensure that transactions are being recorded in a timely manner.`]}),`\n`,_jsxs(_components.p,{children:[`Each Daml ledger has a policy on the allowed difference between LT and RT called the `,_jsx(_components.em,{children:`skew`}),`. A consistent zero-skew is not feasible because this is a distributed system. If it is too far off, the transaction will be rejected. This is the requirement known as “bounded skew.” The RT is not relevant beyond this determination of skew.`]}),`\n`,_jsxs(_components.p,{children:[`Returning to the theme of `,_jsx(_components.em,{children:`business hours`}),`, consider the following example: Suppose that the ledger had a skew of 10 seconds. At 17:59:55, just before the end of business hours, Alice submits a transaction to redeem an Iou. One second later, the transaction is assigned an LT of 17:59:56. However, there still may be a few seconds before the transaction is persisted to the underlying storage. For example, the transaction might be written in the underlying backing store at 18:00:06, `,_jsx(_components.em,{children:`after business hours`}),`. Because LT is within business hours and LT - RT .`]}),`\n`,_jsx(Heading,{level:`3`,id:`time-in-test-scripts`,children:`Time in test scripts`}),`\n`,_jsx(_components.p,{children:`For tests, you can set time using the following functions:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`setTime`}),`, which sets the ledger time to the given time.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`passTime`}),`, which takes a `,_jsx(_components.code,{children:`RelTime`}),` (a relative time) and moves the ledger by that much.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`On a distributed Daml ledger, there are no guarantees that LT or RT are strictly increasing. The only guarantee is that ledger time is increasing `,_jsx(_components.em,{children:`with causality`}),`. That is, if a transaction `,_jsx(_components.code,{children:`TX2`}),` depends on a transaction `,_jsx(_components.code,{children:`TX1`}),`, then the ledger enforces that the LT of `,_jsx(_components.code,{children:`TX2`}),` is greater than or equal to that of `,_jsx(_components.code,{children:`TX1`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`The following script illustrates that idea by moving the logical time back by three days and then trying to exercise a choice on a contract `,_jsx(_components.em,{children:`that hasn’t been created yet`}),`. That fails, as you would hope.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`12`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`iou3 \u003c- submit dora do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` createCmd SimpleIou with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` issuer = dora`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` owner = alice`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` cash = Cash with`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` amount = 100.0`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` currency = \"USD\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` passTime (days (-3))`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` submitMustFail alice do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` exerciseCmd iou3 Redeem`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(Heading,{level:`2`,id:`actions-and-do-blocks`,children:[`Actions and `,_jsx(_components.code,{children:`do`}),` blocks`]}),`\n`,_jsxs(_components.p,{children:[`You have come across `,_jsx(_components.code,{children:`do`}),` blocks and `,_jsx(_components.code,{children:`\u003c-`}),` notations in two contexts by now: `,_jsx(_components.code,{children:`Script`}),` and `,_jsx(_components.code,{children:`Update`}),`. Both of these are examples of an `,_jsx(_components.code,{children:`Action`}),`, also called a `,_jsx(_components.em,{children:`Monad`}),` in functional programming. You can construct `,_jsx(_components.code,{children:`Actions`}),` conveniently using `,_jsx(_components.code,{children:`do`}),` notation.`]}),`\n`,_jsxs(_components.p,{children:[`Understanding `,_jsx(_components.code,{children:`Actions`}),` and `,_jsx(_components.code,{children:`do`}),` blocks is therefore crucial to being able to construct correct contract models and test them, so this section will explain them in some detail.`]}),`\n`,_jsx(Heading,{level:`3`,id:`pure-expressions-compared-to-actions`,children:`Pure expressions compared to actions`}),`\n`,_jsx(_components.p,{children:`Expressions in Daml are pure in the sense that they have no side-effects: they neither read nor modify any external state. If you know the value of all variables in scope and write an expression, you can work out the value of that expression on pen and paper.`}),`\n`,_jsxs(_components.p,{children:[`However, the expressions you’ve seen that used the `,_jsx(_components.code,{children:`\u003c-`}),` notation are not like that. For example, take `,_jsx(_components.code,{children:`getTime`}),`, which is an `,_jsx(_components.code,{children:`Action`}),`. Here’s the example we used earlier:`]}),`\n`,_jsx(_components.p,{children:`“daml\nnow syntax for functions later.`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`Coin`}),` and `,_jsx(_components.code,{children:`play`}),` are deliberately left obscure in the above. All you have is an action `,_jsx(_components.code,{children:`getCoin`}),` to get your hands on a `,_jsx(_components.code,{children:`Coin`}),` in a `,_jsx(_components.code,{children:`Script`}),` context and an action `,_jsx(_components.code,{children:`flipCoin`}),` which represents the simplest possible game: a single coin flip resulting in a `,_jsx(_components.code,{children:`Face`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`You can’t play any `,_jsx(_components.code,{children:`CoinGame`}),` game on pen and paper as you don’t have a coin, but you can write down a script or recipe for a game:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`18`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`18`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`coin_test = do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` -- The coin is pseudo-random on LT so change the parameter to change the game.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` setTime (time (date 2019 Jun 1) 0 0 0)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` passTime (seconds 2)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` coin \u003c- getCoin`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` game = do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` f1r \u003c- flipCoin`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` f2r \u003c- flipCoin`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` f3r \u003c- flipCoin`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` if all (== Heads) [f1r, f2r, f3r]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` then return \"Win\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` else return \"Loss\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` (newCoin, result) = game.play coin`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` assert (result == \"Win\")`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`game`}),` expression is a `,_jsx(_components.code,{children:`CoinGame`}),` in which a coin is flipped three times. If all three tosses return `,_jsx(_components.code,{children:`Heads`}),`, the result is `,_jsx(_components.code,{children:`\"Win\"`}),`, or else `,_jsx(_components.code,{children:`\"Loss\"`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`In a `,_jsx(_components.code,{children:`Script`}),` context you can get a `,_jsx(_components.code,{children:`Coin`}),` using the `,_jsx(_components.code,{children:`getCoin`}),` action, which uses the LT to calculate a seed, and play the game.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.em,{children:`Somehow`}),` the `,_jsx(_components.code,{children:`Coin`}),` is threaded through the various actions. If you want to look through the looking glass and understand in-depth what’s going on, you can look at the source file to see how the `,_jsx(_components.code,{children:`CoinGame`}),` action is implemented, though be warned that the implementation uses a lot of Daml features we haven’t introduced yet in this introduction.`]}),`\n`,_jsxs(_components.p,{children:[`More generally, if you want to learn more about Actions (aka Monads), we recommend a general course on functional programming, and Haskell in particular. See `,_jsx(_components.code,{children:`haskell-connection`}),` for some suggestions.`]}),`\n`,_jsx(Heading,{level:`2`,id:`errors`,children:`Errors`}),`\n`,_jsxs(_components.p,{children:[`Above, you’ve learnt about `,_jsx(_components.code,{children:`assertMsg`}),` and `,_jsx(_components.code,{children:`abort`}),`, which represent (potentially) failing actions. Actions only have an effect when they are performed, so the following script succeeds or fails depending on the value of `,_jsx(_components.code,{children:`abortScript`}),`:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`6`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`nonPerformedAbort = do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let abortScript = False`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let failingAction : Script () = abort \"Foo\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let successfulAction : Script () = return ()`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` if abortScript then failingAction else successfulAction`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`However, what about errors in contexts other than actions? Suppose we wanted to implement a function `,_jsx(_components.code,{children:`pow`}),` that takes an integer to the power of another positive integer. How do we handle that the second parameter has to be positive?`]}),`\n`,_jsxs(_components.p,{children:[`One option is to make the function explicitly partial by returning an `,_jsx(_components.code,{children:`Optional`}),`:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`8`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`optPow : Int -> Int -> Optional Int`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`optPow base exponent`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` | exponent == 0 = Some 1`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` | exponent > 0 =`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let Some result = optPow base (exponent - 1)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` in Some (base * result)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` | otherwise = None`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`This is a useful pattern if we need to be able to handle the error case, but it also forces us to always handle it as we need to extract the result from an `,_jsx(_components.code,{children:`Optional`}),`. We can see the impact on convenience in the definition of the above function. In cases, like division by zero or the above function, it can therefore be preferable to fail catastrophically instead:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`6`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`errPow : Int -> Int -> Int`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`errPow base exponent`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` | exponent == 0 = 1`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` | exponent > 0 = base * errPow base (exponent - 1)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` | otherwise = error \"Negative exponent not supported\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`The big downside to this is that even unused errors cause failures. The following script will fail, because `,_jsx(_components.code,{children:`failingComputation`}),` is evaluated:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`6`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`nonPerformedError = script do`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let causeError = False`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let failingComputation = errPow 1 (-1)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` let successfulComputation = errPow 1 1`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` return if causeError then failingComputation else successfulComputation`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`error`}),` should therefore only be used in cases where the error case is unlikely to be encountered, and where explicit partiality would unduly impact usability of the function.`]}),`\n`,_jsx(Heading,{level:`2`,id:`next-up`,children:`Next up`}),`\n`,_jsxs(_components.p,{children:[`You can now specify a precise data and data-transformation model for Daml ledgers. In `,_jsx(_components.code,{children:`parties`}),`, you will learn how to properly involve multiple parties in contracts, how authority works in Daml, and how to build contract models with strong guarantees in contexts with mutually distrusting entities.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":{"light":"github-light","dark":"github-dark"}},"config":{},"pageMetadata":{"title":"Working with Time","description":"Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints","href":"/appdev/modules/m3-working-with-time"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"How To Implement Time Constraints","slug":"how-to-implement-time-constraints","depth":1,"children":[]},{"title":"How to check that a deadline is valid","slug":"how-to-check-that-a-deadline-is-valid","depth":2,"children":[{"title":"Motivation","slug":"motivation","depth":3,"children":[]},{"title":"Implementation","slug":"implementation","depth":3,"children":[]}]},{"title":"How to check that a deadline has passed","slug":"how-to-check-that-a-deadline-has-passed","depth":2,"children":[{"title":"Motivation","slug":"motivation-2","depth":3,"children":[]},{"title":"Implementation","slug":"implementation-2","depth":3,"children":[]}]},{"title":"Grant time-limited writes to parties","slug":"grant-time-limited-writes-to-parties","depth":2,"children":[{"title":"Motivation","slug":"motivation-3","depth":3,"children":[]},{"title":"Implementation","slug":"implementation-3","depth":3,"children":[]}]},{"title":"Where to use getTime","slug":"where-to-use-gettime","depth":2,"children":[{"title":"Motivation","slug":"motivation-4","depth":3,"children":[]},{"title":"Implementation","slug":"implementation-4","depth":3,"children":[]}]},{"title":"Add constraints to a contract","slug":"add-constraints-to-a-contract","depth":1,"children":[]},{"title":"Template preconditions","slug":"template-preconditions","depth":2,"children":[]},{"title":"Assertions","slug":"assertions","depth":2,"children":[]},{"title":"Time on Daml ledgers","slug":"time-on-daml-ledgers","depth":2,"children":[{"title":"Time in test scripts","slug":"time-in-test-scripts","depth":3,"children":[]}]},{"title":"Actions and do blocks","slug":"actions-and-do-blocks","depth":2,"children":[{"title":"Pure expressions compared to actions","slug":"pure-expressions-compared-to-actions","depth":3,"children":[]}]},{"title":"Errors","slug":"errors","depth":2,"children":[]},{"title":"Next up","slug":"next-up","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/cantonfoundation/9c03e72e153d6207/mintlify-sidebar-footer-patch.js","/_mintlify/custom/cantonfoundation/17537d003d412865/osano.js","/_mintlify/custom/cantonfoundation/ab79e5cc3fdba73d/giscus.js","/_mintlify/custom/cantonfoundation/675ffe7726579720/nav-transition.js","/_mintlify/custom/cantonfoundation/9b7a7a7db37d0115/ga-analytics-adjust.js"],"subdomain":"cantonfoundation","siteName":"Canton Network Docs","title":"Working with Time - Canton Network Docs","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-08-04T11:57:56.184Z","originalFileLocation":"appdev/modules/m3-working-with-time.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints\">\u003cmeta data-mint-head name=\"application-name\" content=\"Canton Network Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/svg+xml\" sizes=\"180x180\" href=\"https://mintcdn.com/cantonfoundation/OOy41G-b8QJx6Gkr/images/canton-logo-dark.svg?fit=max\u0026amp;auto=format\u0026amp;n=OOy41G-b8QJx6Gkr\u0026amp;q=85\u0026amp;s=d5d59c10fc4ca9be021afb188db72e2f\">\u003clink data-mint-head rel=\"icon\" type=\"image/svg+xml\" sizes=\"32x32\" href=\"https://mintcdn.com/cantonfoundation/OOy41G-b8QJx6Gkr/images/canton-logo-dark.svg?fit=max\u0026amp;auto=format\u0026amp;n=OOy41G-b8QJx6Gkr\u0026amp;q=85\u0026amp;s=d5d59c10fc4ca9be021afb188db72e2f\">\u003clink data-mint-head rel=\"icon\" type=\"image/svg+xml\" sizes=\"16x16\" href=\"https://mintcdn.com/cantonfoundation/OOy41G-b8QJx6Gkr/images/canton-logo-dark.svg?fit=max\u0026amp;auto=format\u0026amp;n=OOy41G-b8QJx6Gkr\u0026amp;q=85\u0026amp;s=d5d59c10fc4ca9be021afb188db72e2f\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/svg+xml\" href=\"https://mintcdn.com/cantonfoundation/OOy41G-b8QJx6Gkr/images/canton-logo-dark.svg?fit=max\u0026amp;auto=format\u0026amp;n=OOy41G-b8QJx6Gkr\u0026amp;q=85\u0026amp;s=d5d59c10fc4ca9be021afb188db72e2f\">\u003cmeta data-mint-head property=\"og:title\" content=\"Working with Time - Canton Network Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Canton Network Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.canton.network/appdev/modules/m3-working-with-time\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://cantonfoundation.mintlify.site/_mintlify/api/og/v2?division=Module+3%3A+Daml+Smart+Contracts\u0026amp;title=Working+with+Time\u0026amp;description=Implement+time-based+logic+in+Daml+contracts+including+expiration%2C+deadlines%2C+and+time+constraints\u0026amp;theme=ffe2080e38fe73bda4a88670\u0026amp;signature=833a20622a68fe94a884d609499d76bf60ef76947fafabf1db27617184351a27\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Working with Time - Canton Network Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://cantonfoundation.mintlify.site/_mintlify/api/og/v2?division=Module+3%3A+Daml+Smart+Contracts\u0026amp;title=Working+with+Time\u0026amp;description=Implement+time-based+logic+in+Daml+contracts+including+expiration%2C+deadlines%2C+and+time+constraints\u0026amp;theme=ffe2080e38fe73bda4a88670\u0026amp;signature=833a20622a68fe94a884d609499d76bf60ef76947fafabf1db27617184351a27\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"https://mintlify.s3.us-west-1.amazonaws.com/cantonfoundation/_generated/favicon/browserconfig.xml?v=3\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Canton Network Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#734BE2\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.canton.network/appdev/modules/m3-working-with-time\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/appdev/modules/m3-working-with-time.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.canton.network/#organization\",\"name\":\"Canton Network Docs\",\"url\":\"https://docs.canton.network\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/cantonfoundation/OOy41G-b8QJx6Gkr/images/canton-logo-dark.svg?fit=max\u0026auto=format\u0026n=OOy41G-b8QJx6Gkr\u0026q=85\u0026s=d5d59c10fc4ca9be021afb188db72e2f\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.canton.network#website\",\"name\":\"Canton Network Docs\",\"url\":\"https://docs.canton.network\",\"publisher\":{\"@id\":\"https://docs.canton.network/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.canton.network/appdev/modules/m3-working-with-time#webpage\",\"url\":\"https://docs.canton.network/appdev/modules/m3-working-with-time\",\"name\":\"Working with Time\",\"description\":\"Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints\",\"dateModified\":\"2026-08-04T11:57:56.184Z\",\"isPartOf\":{\"@id\":\"https://docs.canton.network#website\"},\"breadcrumb\":{\"@id\":\"https://docs.canton.network/appdev/modules/m3-working-with-time#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.canton.network/appdev/modules/m3-working-with-time#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Module 3: Daml Smart Contracts\",\"item\":\"https://docs.canton.network/appdev/modules/m3-dev-environment\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Working with Time\",\"item\":\"https://docs.canton.network/appdev/modules/m3-working-with-time\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.canton.network/appdev/modules/m3-working-with-time#article\",\"headline\":\"Working with Time\",\"name\":\"Working with Time\",\"description\":\"Implement time-based logic in Daml contracts including expiration, deadlines, and time constraints\",\"url\":\"https://docs.canton.network/appdev/modules/m3-working-with-time\",\"mainEntityOfPage\":{\"@id\":\"https://docs.canton.network/appdev/modules/m3-working-with-time#webpage\"},\"dateModified\":\"2026-08-04T11:57:56.184Z\",\"publisher\":{\"@id\":\"https://docs.canton.network/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.canton.network#website\"}}]}\u003c/script>","agentPointerHref":"/appdev/modules/m3-working-with-time.md","siteName":"Canton Network Docs","nav":{"global":null,"products":[{"product":"Overview","icon":"book-open","pages":[{"title":"Overview","href":"/overview/understand/what-is-canton"}]},{"product":"App Development","icon":"code","groups":[{"group":"Get Started","pages":[{"title":"Choose Your Path","href":"/appdev/get-started/choose-your-path"},{"title":"What's New","href":"/appdev/get-started/whats-new"},{"title":"Upgrading from Previous Versions","href":"/appdev/get-started/upgrading-from-previous-versions"}]},{"group":"QuickStart","pages":[{"title":"Canton Network QuickStart","href":"/appdev/quickstart/index"},{"title":"Prerequisites and Installation","href":"/appdev/quickstart/prerequisites"},{"title":"Running the Demo","href":"/appdev/quickstart/running-the-demo"},{"title":"Project Structure","href":"/appdev/quickstart/project-structure"},{"title":"Using the JSON Ledger API","href":"/appdev/quickstart/json-api"},{"title":"Keycloak in the QuickStart","href":"/appdev/quickstart/keycloak"},{"title":"Onboard External Parties in Quickstart","href":"/appdev/quickstart/external-parties"},{"title":"Deploy Quickstart to DevNet","href":"/appdev/quickstart/deploy-to-devnet"},{"title":"Debugging with lnav","href":"/appdev/quickstart/lnav"},{"title":"Observability and Tracing","href":"/appdev/quickstart/observability-and-tracing"},{"title":"QuickStart FAQ","href":"/appdev/quickstart/faq"}]},{"group":"Module 1: Understanding Canton","pages":[{"title":"Module 1: Understanding Canton","href":"/appdev/modules/m1-understanding-canton"},{"title":"Mental Models for Canton","href":"/appdev/modules/m1-mental-models"},{"title":"The Canton Development Stack","href":"/appdev/modules/m1-development-stack"}]},{"group":"Module 2: Canton for Ethereum Developers","pages":[{"title":"Canton for Blockchain Developers","href":"/appdev/modules/m2-canton-for-ethereum-devs"},{"title":"Concept Translation Tables","href":"/appdev/modules/m2-concept-translation"},{"title":"Privacy Model Differences","href":"/appdev/modules/m2-privacy-differences"},{"title":"Smart Contract Paradigm Shift","href":"/appdev/modules/m2-smart-contract-paradigm"},{"title":"Network Architecture Comparison","href":"/appdev/modules/m2-network-architecture"},{"title":"Multi-Party Workflows","href":"/appdev/modules/m2-multi-party-workflows"},{"title":"Migration Checklist","href":"/appdev/modules/m2-migration-checklist"}]},{"group":"Module 3: Daml Smart Contracts","pages":[{"title":"Development Environment Setup","href":"/appdev/modules/m3-dev-environment"},{"title":"Language Fundamentals","href":"/appdev/modules/m3-language-fundamentals"},{"title":"The Daml Standard Library","href":"/appdev/modules/m3-standard-library"},{"title":"Contract Templates","href":"/appdev/modules/m3-contract-templates"},{"title":"Choices","href":"/appdev/modules/m3-choices"},{"title":"Authorization Model","href":"/appdev/modules/m3-authorization"},{"title":"Composition and Design Patterns","description":"Compose multi-step transactions, understand Daml's execution model and privacy, and apply common multi-party workflow patterns","href":"/appdev/modules/m3-design-patterns"},{"title":"Working with Time","href":"/appdev/modules/m3-working-with-time"},{"title":"Contract Keys","description":"Use contract keys for stable references to contracts and key-based lookups","href":"/appdev/modules/m3-contract-keys"},{"title":"Interfaces","href":"/appdev/modules/m3-interfaces"},{"title":"Testing Daml Contracts","href":"/appdev/modules/m3-testing"},{"title":"Building and Packaging","href":"/appdev/modules/m3-building-packaging"}]},{"group":"Module 4: Full-Stack Application Development","pages":[{"title":"Building Applications","href":"/appdev/modules/m4-building-apps-intro"},{"title":"Application Architecture","href":"/appdev/modules/m4-app-architecture"},{"title":"SDKs and APIs","href":"/appdev/modules/m4-sdks-apis"},{"title":"Backend Development","href":"/appdev/modules/m4-backend-dev"},{"title":"Frontend Development","href":"/appdev/modules/m4-frontend-dev"},{"title":"Canton and the JSON Ledger API","href":"/appdev/modules/m4-json-api-tutorial"},{"title":"Multi-Synchronizer Operations with the JSON Ledger API and TypeScript","href":"/appdev/modules/m4-multi-synchronizer-tutorial"},{"title":"Canton Coin and Traffic","href":"/appdev/modules/m4-canton-coin"},{"title":"Featured App Activity Markers","href":"/appdev/modules/m4-featured-app-activity-marker"},{"title":"Observability","href":"/appdev/modules/m4-observability"},{"title":"Connect and Query PQS","href":"/appdev/modules/m4-pqs-tutorial"},{"title":"Query Contracts and Transactions with PQS","href":"/appdev/modules/m4-query-with-pqs"}]},{"group":"Module 5: Testing \u0026 Deployment","pages":[{"title":"Testing Strategies","href":"/appdev/modules/m5-testing-strategies"},{"title":"LocalNet Development","href":"/appdev/modules/m5-localnet-development"},{"title":"SV Operated Networks and Use-cases","href":"/appdev/modules/m5-networks-and-use-cases"},{"title":"Deployment Progression","href":"/appdev/modules/m5-deployment-progression"},{"title":"Environment Configuration","href":"/appdev/modules/m5-environment-configuration"},{"title":"CI/CD Integration","href":"/appdev/modules/m5-ci-cd-integration"},{"title":"How to upload and query Daml packages","href":"/appdev/modules/m5-manage-daml-packages"}]},{"group":"Module 6: Smart Contract Upgrades","pages":[{"title":"Smart Contract Upgrades Overview","href":"/appdev/modules/m6-overview"},{"title":"Upgrade Compatibility","href":"/appdev/modules/m6-upgrade-compatibility"},{"title":"Writing Your First Upgrade","href":"/appdev/modules/m6-writing-first-upgrade"},{"title":"Package Selection","href":"/appdev/modules/m6-package-selection"},{"title":"Testing Upgrades","href":"/appdev/modules/m6-testing-upgrades"},{"title":"Upgrade Deployment","href":"/appdev/modules/m6-deployment"},{"title":"Upgrade Limitations","href":"/appdev/modules/m6-limitations"},{"title":"Package Naming","href":"/appdev/modules/m6-package-naming"}]},{"group":"Module 7: Production Best Practices","pages":[{"title":"Security Best Practices","href":"/appdev/modules/m7-security"},{"title":"Package Management","href":"/appdev/modules/m7-package-management"},{"title":"Smart Contract Upgrades in Production","href":"/appdev/modules/m7-smart-contract-upgrades"},{"title":"Performance Best Practices","href":"/appdev/modules/m7-performance"},{"title":"Error Handling","href":"/appdev/modules/m7-error-handling"},{"title":"Compliance Considerations","href":"/appdev/modules/m7-compliance"},{"title":"Canton Coin Preapprovals","href":"/appdev/modules/m7-canton-coin-preapprovals"}]},{"group":"Deep Dives","pages":[{"title":"Privacy Model for App Developers","href":"/appdev/deep-dives/privacy-model"},{"title":"Multi-Party Applications and Workflows","href":"/appdev/deep-dives/composition-multi-party"},{"title":"Decentralization","href":"/appdev/deep-dives/decentralization"},{"title":"Multi-Hosting and Resilience","href":"/appdev/deep-dives/multi-hosting"},{"title":"Multi-Synchronizer Application Best Practices","href":"/appdev/deep-dives/multi-synchronizer-best-practices"},{"group":"External Signing","pages":[{"title":"External Signing","href":"/appdev/deep-dives/external-signing"},{"title":"External Signing: Party Onboarding","href":"/appdev/deep-dives/external-signing-onboarding"},{"title":"External Signing: Submitting Transactions, Part 1","href":"/appdev/deep-dives/external-signing-transactions-part-1"},{"title":"External Signing: Submitting Transactions, Part 2","href":"/appdev/deep-dives/external-signing-transactions-part-2"},{"title":"External Signing: Topology Transactions","href":"/appdev/deep-dives/external-signing-topology"},{"title":"External Signing: Hashing Algorithm","href":"/appdev/deep-dives/external-signing-hashing-algorithm"}]},{"group":"External Calls","pages":[{"title":"External Calls","href":"/appdev/deep-dives/external-calls"},{"title":"Using External Calls","href":"/appdev/deep-dives/external-calls-usage"}]},{"title":"Performance Optimization","href":"/appdev/deep-dives/performance-optimization"},{"title":"Active Contracts Head Snapshot (ACHS)","href":"/appdev/deep-dives/achs"},{"title":"Parties and users on a Canton ledger: How to allocate and query parties","href":"/appdev/deep-dives/manage-daml-parties"},{"title":"Contracts and Transactions in Java","href":"/appdev/deep-dives/contracts-and-transactions-in-java"},{"title":"Smart Contract Upgrade (SCU)","href":"/appdev/deep-dives/smart-contract-upgrade"},{"title":"Canton Network Application Architecture Design","href":"/appdev/deep-dives/app-architecture-design"},{"title":"Command Deduplication","href":"/appdev/deep-dives/command-deduplication"},{"title":"Explicit Contract Disclosure","href":"/appdev/deep-dives/explicit-contract-disclosure"},{"title":"Values in the Ledger API","href":"/appdev/deep-dives/values-in-the-ledger-api"},{"title":"Open Tracing in Ledger API Client Applications","href":"/appdev/deep-dives/open-tracing"},{"title":"Authorization","href":"/appdev/deep-dives/authorization"},{"title":"Token Standard","href":"/appdev/deep-dives/token-standard"}]},{"group":"Tooling","pages":[{"title":"Development Tools Overview","href":"/appdev/tooling/development-tools-overview"},{"title":"IDE Setup","href":"/appdev/tooling/ide-setup"},{"title":"Debugging Tools","href":"/appdev/tooling/debugging-tools"}]},{"group":"App Rewards","pages":[{"title":"App Rewards","href":"/appdev/app-rewards"}]},{"group":"Troubleshooting","pages":[{"title":"Common Issues FAQ","href":"/appdev/faq"},{"title":"Troubleshooting Cheat Sheet","href":"/appdev/troubleshooting"},{"title":"Installation Issues","href":"/appdev/troubleshooting-guide/installation-issues"},{"title":"Development Issues","href":"/appdev/troubleshooting-guide/development-issues"},{"title":"Operational Issues","href":"/appdev/troubleshooting-guide/operational-issues"},{"title":"Common Questions","href":"/appdev/troubleshooting-guide/common-questions"},{"title":"Daml Error Codes","href":"/appdev/troubleshooting-guide/error-code-reference"},{"title":"Ledger API Errors","href":"/appdev/troubleshooting-guide/ledger-api-errors"}]},{"group":"Reference","pages":[{"title":"Daml Language Reference","href":"/appdev/reference/daml-language-reference"},{"title":"Daml-LF Reference","href":"/appdev/reference/daml-lf-reference"},{"title":"Admin API Reference","href":"/appdev/reference/admin-api-reference"},{"title":"Configuration Reference","href":"/appdev/reference/configuration-reference"},{"title":"Error Codes","href":"/appdev/reference/error-codes"},{"title":"Smart Contract Upgrading Reference","href":"/appdev/deep-dives/smart-contract-upgrading-reference"}]}]},{"product":"Global Synchronizer","icon":"server","pages":[{"title":"Global Synchronizer","href":"/global-synchronizer/understand/overview"}]},{"product":"Integrations","icon":"plug","pages":[{"title":"Integrations","href":"/integrations/overview"}]},{"product":"SDKs and Tools","icon":"wrench","pages":[{"title":"SDKs and Tools","href":"/sdks-tools/overview"}]},{"product":"API Reference","icon":"book-open","pages":[{"title":"API Reference","href":"/api-reference"}]},{"product":"Release Notes","icon":"note","pages":[{"title":"Release Notes","href":"/release-notes"}]},{"product":"Version Dashboard","icon":"table","pages":[{"title":"Version Dashboard","href":"/shared/version-compatibility-dashboard"}]},{"product":"Page templates","icon":"file-pen","hidden":true,"pages":[{"title":"Page templates","href":"/src/appdev/deep-dives/token-standard"}]}]},"basePath":"","title":"Working with Time - Canton Network Docs","deploymentId":"dpl_Ab6nteg7kvyK8iL73naC2n7fmsWK","buildId":"dpl_Ab6nteg7kvyK8iL73naC2n7fmsWK","dynamics":[],"chunks":[]}