Hi DAML’ers,
I’m currently trying to learn DAML by developing such a card activity management system. I have a template, let’s say Card which consists of cardType, cardStatus, ExpiredDate, and PINOffet. However, I need to restrict the PINOfset field, even signatory is not allowed to see it.
How to do that in DAML? is there any mechanism to restrict the authority in field’s level?
Hi @nr185,
if I understand you correctly you want to limit visibility of specific fields instead of having visibility be defined at the level of contracts.
Currently that is not possible. Either a party sees a contract and all fields in it or it doesn’t see the contract at all.
So if you want to limit visibility of specific fields, you need to split the contract into different ones with different fields and then have different visibility on those contracts.
I am currently, trying to create a daml program about card activity management. In short, this system is about linking card number with the account number, activate the card (update card status from not active to active), and once the activation is success, it will update count of the card stock in card Inventory, will become count -1.
Hence, I create 3 templates : CardInventory, Card, and Account.
Now I get an error as shown in this pic.
This is from the Card Template. I’m confused why this error happened.
Looks like you just have to assign values to the fields customerService, cardInv and branch when you create the card. Just like you did with cardNumber, cardStatus and lastUpdate. It would be helpful if you’d share the definition of the Card template.
Yes,
This is the complete version for the card template.
template CardInventory
with
branch : Text
count : Int
staff : Party
auditor : [Party]
customer : Party
where
signatory staff
observer auditor
template Card
with
cardNumber : Text
cardStatus : Text
lastUpdate : Date
customerService : Party
cardInv : CardInventory
branch : Text
where
signatory customerService, customer
observer cardInv.customerService, cardInv.auditor
preconsuming choice ActivationCard : ContractId Card
with
newCard : Text
controller customerService
do
cardContractId <- lookupByKey @Card(cardNumber, cardStatus)
now <- getTime
assertMsg "This card status must be Not Active (NA)" (cardStatus /= "NA")
assertMsg "Update card stock in branch" (branch /= cardInv.branch)
create Card with
cardNumber = newCard
cardStatus = "AA"
lastUpdate = now
Thank you for your help and sorry for the very basic question. I need to fully understand about this.
If your intent with the ActivationCard choice is to archive the current contract and replace it with the activated version you can do create this with instead of create Card with. When you do this you only need to update the fields you want to and the rest will keep their previous values.
Also the choice is currently preconsuming and you might have to remove that.
Also some other notes:
I noticed your Card template has a customer signatory but that’s not a field on Card perhaps you intended cardInv.customer?
assertMsg "This card status must be Not Active (NA)" (cardStatus /= "NA") from the error message this seems to suggest that you want to do cardStatus == "NA"
By the way I stuck with this problem. I’m sure this must be a simple mistake. But honestly, I am still confusing where is the mistake. “parse error (possibly incorrect indentation or mismatched brackets)”
Dates do not have a literal representation in Daml, so you have to “build” them by calling functions on other data types. Here’s a full, self-contained example:
module Main where
import Daml.Script
import DA.Date
test : Script ()
test = script do
let today = DA.Date.fromGregorian (2021, DA.Date.Aug, 4)
debug $ "Today is " <> show today
return ()