I'm making some exercises to get to know Daml and one of the exercises involves the transfer of an Asset from a Party to another Party. Everything works correctly, but I’ve noticed that the owner of the previous Asset contract is marked as ‘Witness’ of the new Asset contract (At Assets.Asset:Asset
, the contract with ID #8:2
has Alice
marked with a W
, Witness
).
I was intrigued with that. What does it means a Party being a ‘Witness’ of a contract and what are its implications? I didn’t found an answer for it in the documentation…
Here is some of the code I’ve used. I’ve applied the propose-accept pattern.
template HolderRole
with
operator : Party
holder : Party
where
signatory operator, holder
key (operator, holder) : (Party, Party)
maintainer key._1
controller holder can
nonconsuming ProposeAssetTransfer : ContractId AssetTransferProposal
with
receiver : Party
assetCid : ContractId Asset
do
exercise assetCid ProposeTransfer with receiver
nonconsuming AcceptAssetTransfer : ContractId Asset
with
assetTransferProposalCid : ContractId AssetTransferProposal
do
exercise assetTransferProposalCid AssetTransferProposal_Accept
template Asset
with
issuer : Party
owner : Party
symbol : Text
quantity : Decimal
where
signatory issuer, owner
controller owner can
ProposeTransfer : ContractId AssetTransferProposal
with
receiver : Party
do
create AssetTransferProposal with receiver, asset = this, assetCid = self
template AssetTransferProposal
with
receiver : Party
asset : Asset
assetCid : ContractId Asset
where
signatory asset.owner, asset.issuer
controller receiver can
AssetTransferProposal_Accept : ContractId Asset
do
create asset with owner = receiver
assetTransferTest = script do
...
-- Transfer an Asset to another Party
assetTransferProposalCid <- submit alice do
exerciseByKeyCmd @HolderRole (operator, alice) ProposeAssetTransfer
with receiver = bob, assetCid = assetCid
-- Accept a transfer
submit bob do
exerciseByKeyCmd @HolderRole (operator, bob) AcceptAssetTransfer
with assetTransferProposalCid = assetTransferProposalCid
This means that Alice
saw the creation of the new contract (#8:2
) because she was a party to the old contract (#6:2
) at the time it was consumed by Bob
exercising AcceptAssetTransfer
on HolderRole
. The implications are that Alice
could see that Bob
became the new owner of Asset
but will not see any future events that involve Asset
such as it being archived as a result of sending the asset to another Party.
Additionally even though Alice
saw/witnessed the creation of the new contract she cannot query for it after the one time event where she witnessed it.
Sometimes the docs are a bit hard to search so here's some relevant links:
As this question was also asked simultaneously on our forum further discussion may be located here.