Hi Everyone!
I still have problems in retrieving contracts. I am very sorry, I read the resources and documentation but I cannot quite understand how to make my workflow work. Here is what I want to do:
1- I create an asset
2- I update the asset (new docs, new descriptions …)
3- Then I want to retrieve the last updated contract (if there are any updates, otherwise the original contract)
4- Finally I want to sell the last updated contract
In this case, my understanding is that it’s best to use keys as the contractId might be archived if there is an update. Last week I had lots of help from Wallace (Wallace thank you again!) and he’s right, I should not include the entire Asset instance I should just reference the asset with either ContractId or FetchBy Key. I attach the link to the previous post.
Therefore, I restarted my work and modified the code as below:
module Asset where
type AssetId = ContractId Asset
template Asset
with
ownerSolicitor : Party
owner : Party
auctionHouse :Party --also makes sure that all parties are legit
address :Text
idCode: Text --To check how to create an asset ID. To be generated offline
a_description : Text
a_documents : [Text]
a_docLink : Text --to be reviwed to create a link to the documents
v_description : Text
v_documents : [Text]
v_docLink : Text --to be reviwed to create a link to the documents
date: Time
where
signatory ownerSolicitor
observer owner,auctionHouse
key (ownerSolicitor, idCode) : (Party, Text)
maintainer key._1
choice UpdateAsset
: ContractId Asset
with
new_owner : Party
new_address :Text
new_idCode: Text
new_a_description : Text
new_a_documents : [Text]
new_a_docLink : Text
new_v_description : Text
new_v_documents : [Text]
new_v_docLink : Text
new_date:Time
controller ownerSolicitor
do
create this with
owner = new_owner
address = new_address
idCode = new_idCode
a_description = new_a_description
a_documents = a_documents ++ new_a_documents
a_docLink = new_a_docLink
v_description = new_v_description
v_documents = v_documents ++ new_v_documents
v_docLink = new_v_docLink
date = new_date
choice FetchAssetByKey : (ContractId Asset, Asset)
with
assetKey : (Party, Text)
controller ownerSolicitor
do
fetchByKey @Asset assetKey
module Main where
import Asset
import Daml.Script
setup : Script ()
setup = script do
cms <- allocatePartyWithHint "CMS" (PartyIdHint "CMS")
claudia <- allocatePartyWithHint "Claudia" (PartyIdHint "Claudia")
christie<- allocatePartyWithHint "Christie" (PartyIdHint "Christie")
claudia_Budha <- allocatePartyWithHint "Claudia_Budha" (PartyIdHint "Claudia_Budha")
mishconDeReya <- allocatePartyWithHint "MishconDeReya" (PartyIdHint "MishconDeReya")
silvia <- allocatePartyWithHint "Silvia" (PartyIdHint "Silvia")
time <- getTime
assetId <- submit cms do
createCmd Asset with
ownerSolicitor = cms
owner = claudia
auctionHouse = christie
address = "Mulholland Drive"
idCode = "XX2325XXX"
a_description = "Villa by the sea"
a_documents = ["VillaDoc1", "VillaDoc2", "VillaDoc3" ]
a_docLink = "http://villaDocumetsLocation"
v_description = "Portrait of Adele Bloch-Bauer - Klimt"
v_documents = ["KlimtDoc1", "KlimtDoc2", "KlimtDoc3" ]
v_docLink = "http://valuableDocumentsLocation"
date = time
updateAsset <- submit cms do
exerciseCmd assetId UpdateAsset with
new_owner = claudia_Budha
new_address = "Mulholland Drive 135"
new_idCode = "AAA123BBB"
new_a_description = "Villa by the sea with view"
new_a_documents = ["VillaDoc4", "VillaDoc5", "Villa6" ]
new_a_docLink = "http://villaDocumetsLocation_Updated"
new_v_description = "Klimt and Le Moulin de la Galette -Renoir"
new_v_documents = ["Renoir1", "Renoir2", "Renoir3" ]
new_v_docLink = "http://valuableDocumentsLocation_updated"
new_date = time
Some asset <- queryContractId cms updateAsset
submit cms do
exerciseCmd updateAsset FetchAssetByKey
return ()
I would really appreciate some help to understand how to make my workflow work. I also do not understand from the documentation why I need and Helper template to call ‘fetchByKey’ and how to use it.
Again, I am sorry for being a pain, I am lost. If someone could give me some help with a bit of patience, I would be very very grateful.