Error: Attempt to fetch or exercise a contract not visible to the committer
- Muhammad_MoizOP 1
Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful Daml Script. We now recommend using that for all purposes. For more information, and to learn how to use Script please check out @Andreas’ post on our blog.
Here is my code
template Attandance with systemUser : Party associate : Optional Party punchInTime : Optional Time punchOutTime :Optional Time where signatory systemUser nonconsuming choice PunchIn : ContractId Attandance with currentTime : Time controller associate do create this with punchInTime = Some currentTime nonconsuming choice PunchOut : ContractId Attandance with currentTime : Time controller associate do create this with punchOutTime = Some currentTimeHere is my scenario of update punchIn
setup = do systemUser <- getParty "Alice" associate <- getParty "Bob" atid <- submit systemUser do create Attandance with systemUser associate = None punchInTime = None punchOutTime = None submit associate do exercise asid PunchIn with currentTime <- getTime return()Attempt to fetch or exercise a contract not visible to the committer.
** Contract: #2:0 (Attendence:Attandance)**
** Committer: 'Bob**
** Disclosed to: 'Alice**
I know why this error occur because systemUser create Attendance and associate exercise the choice but systemUser has to create attendance and associate PunchIn or PunchOut, I make “associate” observer, but it not solved. - SamirTalwar 1
Looks like you need to take care of two things.
Firstly, you need to actually pass the associate to the
Attendancecontact, by settingassociate = Some associate.Secondly, you need to declare the associate as an observer of a contract, by stating
observer associateunderneath thesignatoryline of the contract. - Muhammad_Moiz 1
associate entity enters only in Attendance when he PunchIn,
- Muhammad_Moiz 1
And I create associate as observer but it dont work.
- SamirTalwar 1
I’m afraid you’re going to have to somehow pass in your associate, or the contract will not be visible to them.
DAML contracts are private; you have to explicitly declare the parties that can see them. If a party needs to be able to exercise a choice on a contract, the signatory first needs to make them an observer.
In this case, you need to pass in your associate before punching in or out. If the associate is unknown when the contract is created, you’ll need a kind of two-phase flow, in which the signatory can exercise a choice to add an associate to the contract.
- Leonid_Rozenberg 1
Could you post an example, in particular how you create the
Attendanceinstance and specify the associate. If it is the same as what you originally posted, thenassociate = Nonedoes not specify a
partyas the associate` on that contract.