Skip to content
CCPEDIAby Unity Nodes
Outreach

My first badge :)

11 posts558 views7 likesLast activity Sep 2022

  1. thomaslangloisOP 4

    Hi all, Thomas here, playing around with daml an its introduction tutorial.
    It’s working great so far…

  2. Ben_M 1

    Congratulation @thomaslanglois

    Look forward to seeing you progress, good luck!

  3. rikotacards

    Great job Thomas! Keep us posted with your learning journey!

  4. nemanja

    Congrats @thomaslanglois :clap: Keep on learning Daml and let us know how it goes :slight_smile:

  5. thomaslanglois

    Cheers all, thanks for the encouragements.
    Second screenshot…so far so good although I find it strange that for A to send a message to B it only takes B to follow A whereas it takes B to be followed back by A before he can sends A a message.
    I know it seems to be working as per the requirements described in the use case but I would make this requirement reciprocal i.e. A and B can only exchange messages until both follow each other.

    Now how would one do this? I guess the Message contract is fine as is but maybe the SendMessage choice should be more strict and validate the reciprocity by adding an assertMsg statement.

  6. a_putkov 2

    @thomaslanglois
    Indeed. You can restrict the ability to send a message only when both the sender and the recipient follow each other by adding an assertion to the SendMessage choice. The slight complication is that you don’t have all the data required to check if the sender follows the recipient ready available. You have the sender party, which is an argument of the SendMessage choice. But you don’t have the User contract associated with this party, which contains the list of parties the sender follows. To obtain the User contract, you need to fetch it from the ledger. Here’s the modified code for the SendMessage choice

        nonconsuming choice SendMessage: ContractId Message with
            sender: Party
            content: Text
          controller sender
          do
            assertMsg "The recipient must follow the sender" (elem sender following)
            (senderUserCid, senderUser) <- fetchByKey @User sender
            assertMsg "The sender must follow the recipient" (elem this.username senderUser.following)
            create Message with sender, receiver = username, content
    
  7. thomaslanglois

    Thank you, much appreciated, I shall try this shortly :slight_smile:

  8. thomaslanglois
    a_putkov:
           (senderUserCid, senderUser) <- fetchByKey @User sender
            assertMsg "The sender must follow the recipient" (elem this.username senderUser.following)
    

    Works like a charm. Thanks Alex.

  9. Halloran

    Looks like I’ve got it working! Looking forward to adding some features now…

  10. a_putkov

    @Halloran
    Congratulations! And welcome to the community of Damlers.
    Housekeeping note. When making a new post or asking a new question on the forum - always start a new thread. If you need to refer to an existing thread in your post - include a link to the thread you need to reference.
    Have fun learning Daml.

  11. Ben_M

    Congratulation @Halloran

    Look forward to seeing you progress, good luck!