feat: Create new data access to allow for in-memory transactions.
Resolves #1380, Resolves #1331
Description:
- Create a new
NoConfirmHttpDataAccessin order to bypass the persistence of a request while it's being created. - Add the
skipCreateConfirmationboolean tohttp-request-networkto useNoConfirmHttpDataAccessinstead of the defaultHttpDataAccess. - Add
persistTransactionmethod toRequestNetwork. - Add
preparePaymentRequestmethod in order to create a structured request object that can be used for paying the request.
@alexandre-abrioux your comment convinced me we should inject this feature at the DataAccess layer, instead of the TransactionManager layer.
My Goal
- RN SDK provides a function to Create and return a request in-memory, without persisting, including signature and encryption, on the front end.
- RN SDK provides a function to Persist an in-memory request by sending it to a Request Node, from the backend.
I want a good developer experience for (1) and (2). In my opinion, this means it's accessible via the RequestNetwork Client object.
Proposed Solution
Implement (1) by injecting a not-yet-implemented NoConfirmHttpDataAccess and calling requestNetwork.createRequest()
Implement (2) by injecting an HttpDataAccess and calling not-yet-implemented requestNetwork.persistRequest()
The NoConfirmHttpDataAccess will be very similar to the existing HttpDataAccess except that it will "Fire and Forget" similar to the DatabaseDataWrite pseudocode posted by @alexandre-abrioux
The HttpRequestNetwork will need a new boolean argument skipCreateConfirmation. When true It will instantiate a NoConfirmHttpDataAccess.
The proposed persistRequest() function would be added to the RequestNetwork base class and will call this.dataAccess.persistTransaction() - skipping the RequestLogic and TransactionManager layers.
FYI @aimensahnoun
Walkthrough
The recent updates to request-client.js introduce mechanisms enabling payment requests to be created and processed in-memory before being persisted. These changes include the addition of new methods and properties in key classes (RequestNetwork, Request, HttpRequestNetwork) that support the creation, handling, and conditional persistence of in-memory payment requests. The updates aim to optimize user experience by shortening the critical path for payment operations and offering more flexibility in request handling.
Changes
| Files/Modules | Change Summary |
|---|---|
.../src/api/request-network.ts |
Added prepareRequestDataForPayment and persistRequest methods to RequestNetwork class. Introduced ClientTypes and ExtensionTypes imports. Updated dataAccess property signature. |
.../src/api/request.ts |
Introduced inMemoryInfo property in Request class to handle in-memory requests, including transaction data, topics, and payment request data. |
.../src/http-request-network.ts |
Added skipPersistence parameter in HttpRequestNetwork constructor and conditionally instantiated NoPersistHttpDataAccess based on this parameter. Updated the options interface to include skipPersistence. |
.../src/request-logic-types.ts |
Introduced IInMemoryInfo interface for in-memory request handling, specifying transaction data, topics, and request data. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant HttpRequestNetwork
participant RequestNetwork
participant InMemoryTransactionManager
participant NoPersistHttpDataAccess
User->>HttpRequestNetwork: createRequest(skipPersistence: true)
HttpRequestNetwork->>RequestNetwork: handleRequestCreation()
RequestNetwork->>InMemoryTransactionManager: createInMemoryRequest()
InMemoryTransactionManager->>NoPersistHttpDataAccess: prepareDataForInMemoryRequest()
NoPersistHttpDataAccess-->>InMemoryTransactionManager: return prepared data
InMemoryTransactionManager-->>RequestNetwork: return in-memory request
RequestNetwork-->>HttpRequestNetwork: return in-memory request
HttpRequestNetwork-->>User: return in-memory request
User->>HttpRequestNetwork: sendPayment(inMemoryRequest)
HttpRequestNetwork->>RequestNetwork: handlePayment(inMemoryRequest)
RequestNetwork->>InMemoryTransactionManager: processPayment(inMemoryRequest)
InMemoryTransactionManager-->>RequestNetwork: payment processed
RequestNetwork-->>HttpRequestNetwork: payment processed
HttpRequestNetwork-->>User: payment processed
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Enable the creation and payment of in-memory requests before persistence (#1380, #1331) | ✅ | |
Introduce an InMemoryTransactionManager for handling transactions without immediate persistence (#1380) |
✅ | |
Update HttpRequestNetwork to support skipPersistence option (#1380, #1331) |
✅ |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai generate interesting stats about this repository and render them as a table. -
@coderabbitai show all the console.log statements in this repository. -
@coderabbitai read src/utils.ts and generate unit testing code. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (invoked as PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.