Skip to content
Discussions/Outreach/My first badge :)Forum ↗

My first badge :)

Outreach11 posts498 views7 likesLast activity Sep 2022
TH
thomaslangloisOP
Sep 2022

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

BE
Ben_M
Sep 2022

Congratulation @thomaslanglois

Look forward to seeing you progress, good luck!

RI
rikotacards
Sep 2022

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

NE
nemanja
Sep 2022

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

TH
thomaslanglois
Sep 2022

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.

A_
a_putkov
Sep 2022

@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
TH
thomaslanglois
Sep 2022

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

TH
thomaslanglois
Sep 2022
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.

HA
Halloran
Sep 2022

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

A_
a_putkov
Sep 2022

@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.

BE
Ben_M
Sep 2022

Congratulation @Halloran

Look forward to seeing you progress, good luck!

← Back to Discussions