Chat CorDapp Design

ChatState

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:

Data model for facts recorded to the ledger
Data model for facts recorded to the ledger

Where:

  • id is a unique identifier for the chat, it is the equivalent of a linearId 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. (LinearStates and LinearId are not implemented yet in Corda 5 as of Beta-1).

  • chatName is a human readable name for the chat, it does not guarantee uniqueness.

  • messageFrom is the MemberX500Name for the virtual node which created this ChatState.

  • message is the message in the Chat.

  • participants is the list of PublicKeys belonging to the vnodes 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 (combination of the ChatState and ChatContract) can be represented by a simple Smart Contract View diagram:

Smart Contract View diagram
Smart Contract View diagram

Chat State Evolution

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

CDL state evolution view
CDL state evolution view
  • The Create transaction has no input and starts a new chat with a unique id. The id operates similarly to the Corda 4 LinearStateId, 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 in the Chat Application:

FlowFlow typeInputsAction
CreateNewChatFlowClientStartableFlow
  • chatName
  • otherMember
  • message
  • Forms a draft transaction using the transaction builder, which creates a new ChatState with the details provided.
  • Signs the draft transaction with the VNodes first Ledger Key.
  • Calls FinalizeChatSubFlow which finalizes the transaction.
  • UpdateChatFlowClientStartableFlow
  • id
  • message
  • Locates the last message in the backchain for the given id.
  • Creates a draft transaction which consumes the last message in the chain and creates a new ChatState with the latest message.
  • Signs the draft transaction with the vnodes first Ledger Key.
  • Calls FinalizeChatSubFlow which finalises the transaction.
  • ListChatsFlowClientStartableFlow
  • none
  • Calls FinalizeChatSubFlow which finalises the transaction.
  • GetChatsFlowClientStartableFlow
  • id
  • numberofRecords
  • Reads the backchain to a depth of numberOfRecords for a given id.
  • Returns the list of messages together with who sent them.
  • FinalizeChatFlowSubFlow
  • signedTransaction (to finalize)
  • otherMember
  • The common subflow used by both by both CreateNewChatFlow and UpdateChatFlow.
  • This removes the need to duplicate the responder code.
  • Sets up a session with the FinalizeChatResponderFlow and calls the finality() function finality()/ receiveFinality( functions, collects required signatures, notarises the transaction, and stores the finalized transaction to the respective vaults.
  • FinalizeChatResponderFlowResponderFlow
  • FlowSession
  • Runs the receiveFinality() function which performs the responder side of the finality() function.ReceiveFinality() takes a Lambda verifier which runs validations on the transactions.
  • The validator checks for banned words and checks that the message comes from the same party as the 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.