Skip to content
CCPEDIAby Unity Nodes
App Development

I am not seeing an archived contract in the TransactionTree

4 posts76 viewsLast activity Nov 2024

  1. cohen.avrahamOP

    G-d willing

    Hello guys,
    I have the following code:

    template A
      with
        owner : Party
        id : Int
        value : Int
        something : Text
      where
        signatory owner
    
        choice DoSomething: ContractId A
          controller owner
          do
            create this with value = 10
    

    The DoSomething choice basically archives the previous version of its own.
    However, when looking at the TransactionTree I cannot see the archived version.
    I am trying to check that using the following script:

    testDoSomething : Script ()
    testDoSomething = script do
      alice <- allocateParty "alice"
      a <- submit alice do
                createCmd A with owner = alice, id = 1, value = 1, something = "Some Text"
     
      TransactionTree{rootEvents = [ExercisedEvent Exercised{contractId, choice,
          childEvents = [CreatedEvent created]
        }]} <-
        submitTree alice do
          exerciseCmd a DoSomething
     
      debug $ fromAnyTemplate @A created.argument
     
      pure ()
    

    I expected to get more from in the transaction tree. For example, when I tried to do:

    TransactionTree{rootEvents = [ExercisedEvent Exercised{contractId, choice,
          childEvents = [CreatedEvent created, ExercisedEvent archived]
        }]} <-
        submitTree alice do
          exerciseCmd a DoSomething
    

    But this code fails since there is no ExercisedEvent in the return value.
    So, how can I get the archived contract that happened during the exercise of DoSomething?

    Thanks,

  2. WallaceKelly

    Disclaimer: I do not answer your question. :frowning:

    You are correct that the Transaction Tree does not include explicit mention of the archiving of the contract.

    That is consistent with what we see in the Daml Studio Transaction View.

    That is also consistent with the fact that Archive is an auto-generated choice on the contract. And, to be honest, you are not exercising that choice, like this example:

    There have been related discussions on these two posts:

    So, how can I get the archived contract that happened during the exercise of DoSomething ?

    :thinking:

  3. bernhard

    The consuming exercise is the root node.

  4. cohen.avraham

    Thanks @bernhard for your comment.
    Can you tell me how I can detect all of the true archived contracts that happened during an exercise of a choice?
    After examining the TransactionTree I can do that by matching a CreateEvent with an ExercisedEvent that has the same contracted.
    Why when the call to the archive function does not add ExerciseEvent with a choice named Archive? If that could happen, it would be very useful.