Skip to content

feat: add capability to specify 'force' parameter on bulkd endpoint when creating transactions #939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented May 22, 2025

Fixes LX-51

@gfyrag gfyrag requested a review from a team as a code owner May 22, 2025 08:08
Copy link

coderabbitai bot commented May 22, 2025

Walkthrough

The changes introduce a new optional boolean property, force, to several transaction-related API request schemas, models, and documentation. The backend logic is updated to support this property, allowing the "force" flag to be set via either the request payload or query parameter. A new test verifies bulk transaction creation with the force flag.

Changes

File(s) Change Summary
docs/api/README.md, pkg/client/docs/models/components/v2posttransaction.md Added documentation for the new optional force boolean property in transaction-related request bodies and schemas.
pkg/client/docs/models/operations/v2createtransactionrequest.md, pkg/client/models/operations/v2createtransaction.go Marked the Force field as deprecated in documentation and code comments, warning of its future removal.
pkg/client/models/components/v2posttransaction.go Added the optional Force *bool field and a corresponding GetForce() method to the V2PostTransaction struct.
internal/api/bulking/elements.go Added a Force field to TransactionRequest and updated the ToCore method to use this field instead of an argument.
internal/api/bulking/bulker.go Updated the processElement function to call ToCore() without arguments, reflecting the new method signature.
internal/api/v2/controllers_transactions_create.go Merged the force flag from payload and query param, setting payload.Force accordingly before calling ToCore().
test/e2e/api_bulk_test.go Added a new test case to verify bulk transaction creation with the force flag enabled.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Controller
    participant Bulker
    participant Elements
    participant LedgerController

    Client->>API_Controller: POST /transactions (with force in body or query)
    API_Controller->>API_Controller: Merge force from body/query
    API_Controller->>Bulker: Create transaction with payload (force set)
    Bulker->>Elements: TransactionRequest.ToCore()
    Elements->>LedgerController: TxToScriptData(..., allowUnboundedOverdrafts=Force)
    LedgerController-->>Elements: ScriptData
    Elements-->>Bulker: CreateTransaction
    Bulker-->>API_Controller: Result
    API_Controller-->>Client: Response
Loading

Suggested reviewers

  • paul-nicolas

Poem

In the ledger’s warren, a flag now appears—
A forceful new option to calm all your fears.
Whether bulk or a single, just set it to true,
The tests all agree: it works like a brew!
🐇✨
Here’s to new features, with hops and with cheers!

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@gfyrag
Copy link
Contributor Author

gfyrag commented May 22, 2025

Fixes LX-51

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
pkg/client/models/operations/v2createtransaction.go (1)

17-18: Enhance the deprecation notice with migration guidance.

The deprecation notice correctly indicates that the Force field will be removed, but it doesn't specify what users should migrate to. Consider adding specific guidance about using the force field in the request body instead of as a query parameter.

//
- // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible.
+ // Deprecated: This will be removed in a future release, please migrate to using the `force` field in the request body (V2PostTransaction.Force) instead of as a query parameter.
pkg/client/docs/models/components/v2posttransaction.md (1)

15-15: Add description and example for the Force field.

The newly added Force field lacks a description explaining its purpose and usage. Consider adding a clear description of what this field does (e.g., "Disable balance checks when creating transactions") and provide an example value (e.g., true).

- | `Force`                                                                                                                                                | **bool*                                                                                                                                                | :heavy_minus_sign:                                                                                                                                     | N/A                                                                                                                                                    |                                                                                                                                                        |
+ | `Force`                                                                                                                                                | **bool*                                                                                                                                                | :heavy_minus_sign:                                                                                                                                     | Disable balance checks when creating transactions. When set to true, transactions can bring accounts below zero.                                        | true                                                                                                                                                   |
pkg/client/docs/models/operations/v2createtransactionrequest.md (1)

11-11: Deprecation notice is clear but has minor formatting issues.

The Markdown formatting for the deprecated Force field correctly uses strikethrough and provides a clear warning notice, which helps users understand that they should migrate away from it. However, there are spaces inside the emphasis markers which may cause rendering issues in some Markdown parsers.

-| ~~`Force`~~                                                                                                                                                                            | **bool*                                                                                                                                                                                | :heavy_minus_sign:                                                                                                                                                                     | : warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.<br/><br/>Disable balance checks when passing postings          | true                                                                                                                                                                                   |
+| ~~`Force`~~                                                                                                                                                                            | **bool*                                                                                                                                                                                | :heavy_minus_sign:                                                                                                                                                                     | :warning: **DEPRECATED**: This will be removed in a future release, please migrate away from it as soon as possible.<br/><br/>Disable balance checks when passing postings          | true                                                                                                                                                                                   |
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

11-11: Spaces inside emphasis markers
null

(MD037, no-space-in-emphasis)


11-11: Spaces inside emphasis markers
null

(MD037, no-space-in-emphasis)

docs/api/README.md (3)

517-518: Clarify force support in Bulk request parameters
The JSON example correctly shows the new force flag at the element level, but the Bulk create endpoint’s parameters table (lines 524–532) does not mention force. If a top-level force query parameter is supported, it should be documented here; otherwise add a note clarifying that force is only scoped per-element in the request body.


1333-1334: Demonstrate force as a query parameter in code sample
The payload example includes force in the body, but the endpoint also accepts force via query string. Consider updating the first line of the HTTP request to POST http://localhost:8080/v2/{ledger}/transactions?force=true HTTP/1.1 to illustrate this alternative usage.


2726-2727: Add description for the force property in the PostTransaction schema
The new table row for force lacks a descriptive entry. Populate the Description column (e.g. “Disable balance checks when passing postings”) to match the query parameter’s explanation and improve discoverability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b88db5 and b2da5b8.

⛔ Files ignored due to path filters (3)
  • openapi.yaml is excluded by !**/*.yaml
  • openapi/v2.yaml is excluded by !**/*.yaml
  • pkg/client/.speakeasy/gen.lock is excluded by !**/*.lock, !**/*.lock
📒 Files selected for processing (9)
  • docs/api/README.md (7 hunks)
  • internal/api/bulking/bulker.go (1 hunks)
  • internal/api/bulking/elements.go (2 hunks)
  • internal/api/v2/controllers_transactions_create.go (1 hunks)
  • pkg/client/docs/models/components/v2posttransaction.md (1 hunks)
  • pkg/client/docs/models/operations/v2createtransactionrequest.md (1 hunks)
  • pkg/client/models/components/v2posttransaction.go (2 hunks)
  • pkg/client/models/operations/v2createtransaction.go (1 hunks)
  • test/e2e/api_bulk_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
internal/api/bulking/bulker.go (1)
internal/api/bulking/elements.go (1)
  • TransactionRequest (97-106)
internal/api/bulking/elements.go (2)
internal/controller/ledger/controller.go (1)
  • CreateTransaction (93-97)
internal/controller/ledger/numscript.go (1)
  • TxToScriptData (17-124)
🪛 markdownlint-cli2 (0.17.2)
pkg/client/docs/models/operations/v2createtransactionrequest.md

11-11: Spaces inside emphasis markers
null

(MD037, no-space-in-emphasis)


11-11: Spaces inside emphasis markers
null

(MD037, no-space-in-emphasis)

🔇 Additional comments (9)
internal/api/bulking/bulker.go (1)

130-130:

✅ Verification successful

Verify that the behavior remains consistent with the previous implementation.

The change from ToCore(false) to ToCore() reflects the updated method signature that now uses the Force field from the TransactionRequest struct instead of a parameter. This is a good refactoring that encapsulates the force flag within the request struct.


🏁 Script executed:

#!/bin/bash
# Description: Verify the default value of the Force field in TransactionRequest struct

# Let's check the implementation of ToCore() method to understand how the Force field is used
rg -A 10 "func \(.*TransactionRequest\) ToCore" internal/api/bulking/elements.go

# Also check if there are any tests that verify the behavior of this method
rg "Test.*TransactionRequest.*ToCore" -g "*.go"

Length of output: 456


I want to confirm exactly how the Force field is defined and used in ToCore() before wrapping up.


🏁 Script executed:

#!/bin/bash
# Show the TransactionRequest struct definition (including json tags)
rg -A 5 "type TransactionRequest" internal/api/bulking/elements.go

# Show where and how req.Force is referenced inside ToCore()
rg -A 5 "req\.Force" internal/api/bulking/elements.go

Length of output: 708


I’d like to see the full TransactionRequest struct to confirm where Force is declared and its default.


🏁 Script executed:

#!/bin/bash
# Show the full TransactionRequest struct definition
rg -A20 "type TransactionRequest" internal/api/bulking/elements.go

Length of output: 911


Confirm default force behavior remains unchanged

The refactor from ToCore(false) to ToCore() now reads req.Force (defaulting to Go’s zero‐value false when omitted), so behavior with no force flag set is identical to before.

• internal/api/bulking/elements.go:

  • TransactionRequest declares Force bool \json:"force"``
  • ToCore() calls ledgercontroller.TxToScriptData(txData, req.Force), preserving the previous hard-coded false.

No further action required.

pkg/client/models/components/v2posttransaction.go (1)

67-67: LGTM! The field and getter implementation are well-structured.

The new Force field and its getter method follow the established patterns in the codebase:

  • Uses pointer type for optional boolean
  • Includes omitempty in the JSON tag
  • Implements a proper nil check in the getter

Also applies to: 129-135

test/e2e/api_bulk_test.go (1)

63-85: LGTM! Good test coverage for the new force parameter feature.

The new test case correctly validates that bulk transaction creation works when the force parameter is set to true. It follows the existing test patterns and properly uses the pointer helper function for the boolean value.

internal/api/v2/controllers_transactions_create.go (1)

37-44: Good implementation for backward compatibility.

The implementation correctly handles both the query parameter and request payload versions of the force parameter, which provides backward compatibility while supporting the new bulk endpoint capability. The code comments clearly explain the rationale.

Just a minor note: You might want to consider adding a deprecation notice in logs or response headers for the query parameter usage to encourage migration to the request payload approach, similar to the documentation changes.

internal/api/bulking/elements.go (2)

105-105: LGTM! Adding Force field to TransactionRequest struct.

The new Force boolean field is properly added to the struct, allowing it to be parsed from JSON request bodies.


108-124: Simplification of method signature enhances API consistency.

Removing the explicit parameter and using the struct field simplifies the API and makes it more consistent with how other parameters are handled. The implementation correctly passes the Force field value to TxToScriptData.

This change might require updates to any code that calls ToCore() with an explicit parameter, but I can see from the other file changes that this has been addressed in the controllers.

docs/api/README.md (3)

3450-3451: Bulk JSON schema example correctly shows force
The snippet properly positions the new force flag after accountMetadata, and the JSON example is valid and well-formatted.


3525-3526: BulkElement example updated with force
The JSON example cleanly adds the force flag within each element’s data block with correct indentation and no trailing commas.


3597-3598: BulkElementCreateTransaction example integrated force
The snippet accurately includes force in the transaction element’s data, consistent with other examples.

@gfyrag gfyrag enabled auto-merge May 22, 2025 08:12
@gfyrag gfyrag added this pull request to the merge queue May 22, 2025
Copy link

codecov bot commented May 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.21%. Comparing base (3b88db5) to head (b2da5b8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #939      +/-   ##
==========================================
- Coverage   82.25%   82.21%   -0.04%     
==========================================
  Files         141      141              
  Lines        7786     7788       +2     
==========================================
- Hits         6404     6403       -1     
- Misses       1057     1059       +2     
- Partials      325      326       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Merged via the queue into main with commit b824a5f May 22, 2025
8 of 10 checks passed
@gfyrag gfyrag deleted the feat/bulk-create-transaction-force branch May 22, 2025 08:16
Copy link

@fguery fguery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments, but generally looks good. I'm approving and leave it to you if you wnat to fix those comments or not.

@@ -2077,6 +2077,7 @@ paths:
- name: force
in: query
description: Disable balance checks when passing postings
deprecated: true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add in the description what replaces it :)

@@ -818,6 +818,7 @@ paths:
- name: force
in: query
description: Disable balance checks when passing postings
deprecated: true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

@@ -514,7 +514,8 @@ Accept: application/json
"property2": {
"admin": "true"
}
}
},
"force": true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure it's worth the change, but I'd put it to false here to show it's the default (and as forcing something is dangerous, you don't want people to copy/paste this without knowing what that param does)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants