Does fetching an explicitly disclosed contract fail if the contract has been archived?
- WallaceKellyOP
The docs for explicit disclosure describes a Buyer exercising a choice on an explicitly disclosed contract. In that case, if the explicitly disclosed contract has already been archived by AnotherBuyer who exercised that choice first, then the transaction will fail for Buyer. That makes sense.
I am wondering about workflows involving an explicitly disclosed contract for which readers (like Buyer) do not consume the disclosed contract. The reader simply needs to confirm that the contract has not been archived. I could add a
nonconsumingchoice to the explicitly disclosed contract, but I wonder if that is necessary.Question: Can readers of explicitly disclosed contracts perform a
fetchon the contract id of that explicitly disclosed contract (within the implementation of a choice of another contract)? What happens if the explicitly disclosed contract is already archived? - Johan_Sjodin 1
Hi @WallaceKelly,
Question: Can readers of explicitly disclosed contracts perform a
fetchon the contract id of that explicitly disclosed contract (within the implementation of a choice of another contract)? What happens if the explicitly disclosed contract is already archived?Yes, the fetch would succeed when the action is authorized by a stakeholder of the explicitly disclosed contract and the contract is active. Otherwise, the fetch will fail.
As you suggest:
If you lack authorization from a stakeholder, you would need a (dynamically-controlled)Getchoice on the explicitly disclosed contract, which you can exercise to retrieve the contract data.Hope that helps,
Johan - WallaceKelly 3
Thank you, @Johan_Sjodin! Let’s see if I have it clear now.
If I have minimally illustrative templates like this…
template ExplicitlyDisclosedContract with them : Party datum : Text where signatory them template MyTemplate with me : Party where signatory me nonconsuming choice DoSomething : () with cid : ContractId ExplicitlyDisclosedContract controller me do edc <- fetch cid pure ()… then the
fetch cidwill always fail, even if I include a valid DisclosedContract message which I have retrieved from off-ledger and submitted with my Ledger API call (assuming it is onlymesubmitting the command to exercise theDoSomethingchoice.)
In contrast, the following minimally illustrative templates, which now include a non-consuming
Getchoice on the explicitly disclosed contract…template ExplicitlyDisclosedContract with them : Party datum : Text where signatory them nonconsuming choice Get : ExplicitlyDisclosedContract with p : Party controller p do pure this template MyTemplate with me : Party where signatory me nonconsuming choice DoSomething : () with cid : ContractId ExplicitlyDisclosedContract controller me do -- edc <- fetch cid edc <- exercise cid Get with p = me pure ()… and replacing the
fetch cidwithexercise cid Get with p = mewill succeed if the contract has not been archived.Does that illustrate it?
PS. It looks like this Splice code is a real-world example.
Splice's OpenMiningRound template
-- | A mining round for which new rewards can be registered. -- Note that multiple mining rounds can be open at the same time to give some -- time for propagating a new open round, while still registering rewards -- against the previous open round. template OpenMiningRound with dso : Party round : Round amuletPrice : Decimal opensAt : Time -- ^ Time after which transfers can use this mining round targetClosesAt : Time -- ^ Time when this round is expected to be closed as part of standard DSO. The round SHOULD NOT be archived before this time. issuingFor : RelTime -- ^ Timepoint on the issuance curve that was used to determing the issuance configuration for this round. transferConfigUsd : TransferConfig USD -- ^ Configuration determining the fees and limits in USD for Amulet transfers issuanceConfig : IssuanceConfig -- ^ Configuration for issuance of this round. tickDuration : RelTime -- ^ Duration of a tick, which is the duration of half a round. where signatory dso ensure isDefinedRound round nonconsuming choice OpenMiningRound_Fetch : OpenMiningRound with p : Party controller p do pure this - Johan_Sjodin 2
Yes, it does.
The first example would only work if you added a stakeholder (i.e., signatory or observer) of the
ExplicitlyDisclosedContractas a signatory toMyTemplate. Then you have the authorization from a stakeholder to do the fetch.In Daml Finance and various apps, we follow the pattern of adding a
Getchoice for templates and interfaces that are supposed to be explicitly disclosed. Then you don’t need to rely on the authorization of a stakeholder to use its data.