Update of Contract information
I am experimenting with DAML and wanted to write a module that saves and updates the details of a “Citizen” called CitizenInfo. I also added a Key = CitizenKey
I have the following DAML code
module Registration where data CitizenInfo = CitizenInfo with citizendetail1 : Text citizendetail2 : Text citizendetail3 : Text deriving (Eq, Show) data CitizenKey = CitizenKey with citizen : Party id : Text deriving (Eq, Show) template CitizenRegistration with registrationCid : CitizenKey registrationData : CitizenInfo where signatory registrationCid.citizen key registrationCid : CitizenKey maintainer key.citizen controller registrationCid.citizen can nonconsuming Register : ContractId CitizenRegistration with newRegistrationCid : CitizenKey newRegistrationData : CitizenInfo do create CitizenRegistration with registrationCid = newRegistrationCid registrationData = newRegistrationData nonconsuming UpdateRegistration : ContractId CitizenRegistration with newCitizenDetails : CitizenInfo do (oldRegistrationCid, oldRegistrationData) <- fetchByKey @CitizenRegistration (key this) archive oldRegistrationCid create CitizenRegistration with registrationCid = oldRegistrationCid registrationData = newCitizenDetails
It currently gives me the following error message at the 2nd last line
Couldn't match expected type ‘CitizenKey’ with actual type ‘ContractId CitizenRegistration’ • In the ‘registrationCid’ field of a record In the first argument of ‘create’, namely ‘CitizenRegistration {registrationCid = oldRegistrationCid, registrationData = newCitizenDetails}’ In a stmt of a 'do' block: create CitizenRegistration {registrationCid = oldRegistrationCid, registrationData = newCitizenDetails}type
Also I want to write a scenario for the UpdateRegistration, so any insights are welcome
You are mixing up contract ids and the data associated with the contract with the given id. registrationCid does not in fact store a contract id. It stores a contract key. So you also need to pass in the contract key not the contract id. Given the data of a template (here oldRegistrationData) you can always use the key function to get the contract key, So to fix your example you can use
create CitizenRegistration with
registrationCid = key oldRegistrationData
registrationData = newCitizenDetails
Thanks for the explanation.
3 posts were split to a new topic: Last statement in a do block must be an expression?
4 posts were split to a new topic: Couldn’t match type ‘Update’ with ‘(->) c0’
3 posts were split to a new topic: Conflicting definitions for ‘alias’