# Data flow

This page presents the flow of data that occurs when some actions are performed in the protocol.

### Creating and updating requests

The next schemas show the data flow that happens when a user performs an `accept` action on a request.

#### Request Logic

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-720dd61797f935f6fdf2ed56c3cefe05c2026c79%2F3-RequestLogicFlow.jpg?alt=media" alt=""><figcaption><p><em>Request Logic flow</em></p></figcaption></figure>

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-167ff832889914a18265aa42321a9391693394ac%2F3-AdvancedLogicFlow.jpg?alt=media" alt=""><figcaption><p><em>Request Logic flow with extension data</em></p></figcaption></figure>

#### Transaction

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-639062a7f06c0efe175f5006cd00a2b20ea504c2%2F3-TransactionFlow.jpg?alt=media" alt=""><figcaption><p><em>Transaction flow without encryption</em></p></figcaption></figure>

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-5569bfc30ca33da064a578fb3e634d6d1d8bffd7%2F3-TransactionFlowEncrypted.jpg?alt=media" alt=""><figcaption><p><em>Transaction flow with encryption with two stakeholders</em></p></figcaption></figure>

#### Data-access

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-30b714a4e5276bef9ddc7f3a68af1fc30ce7b0fe%2F3-DataAccessFlow.jpg?alt=media" alt=""><figcaption><p><em>Data-access flow. In this example, several transactions are batched into the block. This feature is not yet implemented.</em></p></figcaption></figure>

#### Storage

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-7b4eaf852f4c516a8cee61be38d3375334502082%2F3-StorageFlow.jpg?alt=media" alt=""><figcaption><p><em>A new block is added to the storage</em></p></figcaption></figure>

### Reading requests

The next schemas show the data flow when the user wants to read the content of a request.

In this case, the user calls this function of Request Logic: `getRequestFromId(0xaaa)` that reads the request with the request id: 0xaaa

#### Storage

There is a permanent data flow between Data Access and Storage layers.

For performance purposes, Data Access will periodically synchronize with the current state of Storage. When a new, not synchronized block is detected, the block content will be dispatched into the Data Access cache.

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-a879e0759eb6f25d8e2b6e4ef07e803f3e9b5691%2F4-DataAccessAndStorageFlow.jpg?alt=media" alt=""><figcaption><p><em>Flow for Data Access synchronization</em></p></figcaption></figure>

#### Data-access

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-e2d737513ed71ee8f3f39c97195b1dc9601866a4%2F4-DataAccessFlow.jpg?alt=media" alt=""><figcaption><p><em>Flow from Data-Access. When a user wants to read a request, Data-Access will read its cache without any communication with the storage layer</em></p></figcaption></figure>

#### Transaction

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-ef6542b3dedf77c58cdcb9936d69ff96d83f93ae%2F4-TransactionFlow.jpg?alt=media" alt=""><figcaption><p><em>Flow from Transaction layer. If the request is encrypted, the transactions are decrypted in this layer</em></p></figcaption></figure>

#### Request Logic

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-9dde052ce977bd20f945fcf03bf8b787f84e363a%2F4-RequestLogicFlow.jpg?alt=media" alt=""><figcaption><p><em>Request Logic flow. Request Logic will compute the state of the request based on the list of actions. In this case, the increaseExpectedAmount action has been signed by the payer</em></p></figcaption></figure>

Some actions from the Transaction layer can be invalid; this is the role of Request Logic to filter them to give the consistent state of the request to the user.

For example, only the payer of the request can increase the expected amount of it. If the action `increaseExpectedAmount` is signed by the payee therefore, the action is ignored.

<figure><img src="https://1914277788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei6UAiSK3iAAi0mFH667%2Fuploads%2Fgit-blob-c93bff4423ffc2c71e4245f3ad64cfbcc878c9da%2F4-RequestLogicFlowInvalid.jpg?alt=media" alt=""><figcaption><p><em>In this example, the increaseExpectedAmount is signed by the payee; therefore, invalid. The expectedAmount of the request keeps its initial value: 5</em></p></figcaption></figure>
