Chat CorDapp Design

The foundation for the Chat app is the ChatState which is the data model for facts recorded to the ledger. It can be represented in the CDL CorDapp Design Language as follows:

Where:
id
is a unique identifier for the chat, it is the equivalent of alinearId
in Corda 4, in other words it is the common identifier for all the states in the backchain for a particular chat between two participants.chatName
is a human readable name for the chat, it does not guarantee uniqueness.messageFrom
is theMemberX500Name
for the virtual node The combination of the context of a user and the ephemeral compute instances created to progress a transaction on that identity's behalf. which created this ChatState.message
is the message in the Chat.participants
is the list ofPublicKeys
belonging to the virtual nodes of the participants of the chat.
The history of a chat will be recorded in the backchain of the chat.
Chat Smart Contract

The Smart Contract Digitizes agreements by turning the contract terms into code that executes automatically when the terms are met. (combination of the ChatState and ChatContract) can be represented by a simple Smart Contract View diagram:

In CDL the arrows represent transactions with the indicated command type. The state at the beginning of the arrow represents the input state, the state at the end of the arrow represents the output state for the transaction.
There is no ChatState status in this simple design.
The multiplicities (numbers on the arrows) indicate that for the create command there should be no input state and one output ChatState.
The multiplicities for the update command indicates there should be one input ChatState and one output ChatState.
SC: indicates the signing constraint, that is who needs to sign the transaction. In this case both participants for both the create and update commands.
The universal constraint applies to all transactions, in this case that there should always be only two participants in the ChatState.
Chat State Evolution

The evolution of the ledger when stepping through the walkthrough steps can be shown using the CDL State evolution view:

- The Create transaction has no input and starts a new chat with a unique
id
. Theid
operates similarly to the Corda 4LinearStateId
, which has not been implemented yet in Corda 5. - Each update transaction creates the new ChatState as an output and consumes the previous ChatState as an input.
- To recreate the historic conversation the back chain is traversed from newest (unconsumed) state to oldest.
Chat Flows

There are six flows Communication between participants in an application network is peer-to-peer using flows. in the Chat Application:
Flow | Flow type | Inputs | Action |
---|---|---|---|
CreateNewChatFlow | ClientStartableFlow | chatName otherMember message | FinalizeChatSubFlow which finalizes the transaction. |
UpdateChatFlow | ClientStartableFlow | id message | id .FinalizeChatSubFlow which finalises the transaction. |
ListChatsFlow | ClientStartableFlow | None | |
GetChatsFlow | ClientStartableFlow | id numberOfRecords | numberOfRecords for a given id . |
FinalizeChatSubFlow | SubFlow | signedTransaction (to finalize) otherMember | CreateNewChatFlow and UpdateChatFlow .FinalizeChatResponderFlow and calls the finalize() function that collects required signatures, notarizes the transaction, and stores the finalized transaction to the respective vaults. |
FinalizeChatResponderFlow | ResponderFlow | FlowSession | FinalizeChatResponderFlow is initiated by the FinalizeChatSubFlow . It runs the receiveFinality() function which performs the responder side of the finality() function. ReceiveFinality() takes a Lambda verifier which runs validations on the transactions.messageFrom field. |
Was this page helpful?
Thanks for your feedback!
Chat with us
Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.
Propose documentation improvements directly
Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.
We're sorry this page wasn't helpful. Let us know how we can make it better!
Chat with us
Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.
Create an issue
Create a new GitHub issue in this repository - submit technical feedback, draw attention to a potential documentation bug, or share ideas for improvement and general feedback.
Propose documentation improvements directly
Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.