forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make create-daml-app setup idempotent (digital-asset#12320)
* Make create-daml-app setup idempotent changelog_begin changelog_end * review feedback changelog_begin changelog_end
- Loading branch information
1 parent
98b7ad7
commit b845587
Showing
1 changed file
with
23 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
module Setup where | ||
|
||
import DA.Foldable | ||
import DA.Action (unless) | ||
import DA.Foldable (forA_) | ||
import qualified DA.Text as T | ||
import Daml.Script | ||
|
||
setup : Script () | ||
setup = do | ||
forA_ [("Alice", "alice"), ("Bob", "bob"), ("Charlie", "charlie")] $ \(displayName, userName) -> do | ||
p <- allocatePartyWithHint displayName (PartyIdHint ("p" <> userName)) | ||
createUser (User userName (Some p)) [CanActAs p] | ||
let displayNames = ["Alice", "Bob", "Charlie"] | ||
forA_ displayNames $ \displayName -> do | ||
let userId = toUserId displayName | ||
u <- getUser userId | ||
case u of | ||
Some _ -> | ||
-- user already exists do nothing | ||
pure () | ||
None -> do | ||
let partyIdHint = toPartyIdHint displayName | ||
p <- allocatePartyWithHint displayName (PartyIdHint partyIdHint) | ||
createUser (User userId (Some p)) [CanActAs p] | ||
pure () | ||
|
||
toUserId : Text -> Text | ||
toUserId = T.asciiToLower | ||
|
||
-- TODO Drop hints once we have aliases. | ||
toPartyIdHint : Text -> Text | ||
toPartyIdHint p = "p" <> toUserId p |