这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@yashbhutwala
Copy link

@yashbhutwala yashbhutwala commented Sep 17, 2025

Summary

@yashbhutwala yashbhutwala requested a review from a team as a code owner September 17, 2025 01:47
@yashbhutwala yashbhutwala changed the title Support cashu defaults Add Bitcoin Cashu support Sep 17, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @yashbhutwala, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates Cashu payment support into the x402 A2A library. It introduces enhanced functionality for defining Cashu payment requirements, including pre-configured mint URLs, and refines the payment processing workflow to explicitly manage Cashu payloads. These changes aim to provide a clear and robust mechanism for handling Cashu-based transactions within the system.

Highlights

  • Cashu Payment Requirements: Added support for creating Cashu payment requirements, including default mint URLs for Bitcoin testnet and mainnet, and validation for numeric price inputs.
  • Explicit Cashu Payload Handling: Modified wallet helper functions to explicitly process Cashu payment payloads, requiring direct submission of Cashu proofs and preventing implicit handling of Cashu tokens in general payment processing.
  • Unit Test Coverage: New unit tests have been added to validate the correct creation of Cashu payment requirements and the proper processing of Cashu payments.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Bitcoin Cashu payments by updating the core merchant and wallet logic. The changes are well-structured, adding a new 'cashu-token' payment scheme and handling its specific requirements, such as mint URLs and proofs. The inclusion of unit tests for the new functionality is a great practice. My review includes a couple of suggestions to improve code clarity and provide more helpful error messages, but overall, this is a solid implementation.

@yashbhutwala yashbhutwala changed the title Add Bitcoin Cashu support feat: Add Bitcoin Cashu support Sep 17, 2025
@yashbhutwala
Copy link
Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Bitcoin Cashu payments. The changes include updating create_payment_requirements in merchant.py to handle the cashu-token scheme and modifying process_payment in wallet.py to process Cashu payloads. New unit tests have been added to cover the basic flow. My review focuses on improving code structure, enhancing error reporting for better debugging, and expanding test coverage to ensure the new functionality is robust. Overall, the implementation is solid, and the suggested changes are aimed at improving maintainability and reliability.

@yashbhutwala
Copy link
Author

/gemini summary

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This pull request significantly enhances the x402 library by integrating support for Bitcoin Cashu payments. It introduces a new payment scheme, cashu-token, and refactors the payment requirement creation and processing logic to accommodate Cashu-specific parameters and payloads. The changes aim to streamline the handling of Cashu-based payments, making the system more versatile for different cryptocurrency payment methods.

Highlights

  • Bitcoin Cashu Support: Introduced a new payment scheme, 'cashu-token', to support Bitcoin Cashu payments within the x402 framework.
  • Payment Requirements Creation: The create_payment_requirements function now accepts Cashu-specific parameters like mint_url, keyset_id, facilitator_url, and unit, and includes default mint URLs for Bitcoin testnet and mainnet.
  • Payment Processing Logic: Updated the process_payment function to handle cashu-token schemes, requiring an explicit CashuPaymentPayload and performing validation against the payment requirements' accepted mints.
  • Wallet Helper Refinement: Modified process_payment_required to explicitly guide users to process_payment when dealing with cashu-token requirements, ensuring proper handling of Cashu payloads.
  • Unit Tests: Added new unit tests to cover the creation of Cashu payment requirements and the processing of Cashu payments, ensuring the new functionality works as expected.
Changelog
  • python/x402_a2a/core/merchant.py
    • Added mint_url, mint_urls, facilitator_url, keyset_id, keyset_ids, unit, and locks parameters to create_payment_requirements function.
    • Implemented logic within create_payment_requirements to handle the cashu-token scheme, including default mints for Bitcoin testnet/mainnet and validation for price types.
    • Constructed the extra field of PaymentRequirements to include Cashu-specific details like mints, facilitator URL, keyset IDs, and NUT-10 locks.
  • python/x402_a2a/core/wallet.py
    • Imported CashuPaymentPayload type.
    • Modified process_payment_required to raise a ValueError if a cashu-token requirement is selected, instructing users to use process_payment directly.
    • Updated process_payment to accept an optional cashu_payload parameter.
    • Added specific logic within process_payment to handle cashu-token schemes, validating the provided cashu_payload against the payment requirements' accepted mints and token counts.
  • python/x402_a2a/tests/test_core.py
    • Imported create_payment_requirements, process_payment, and CashuPaymentPayload.
    • Added test_create_cashu_payment_requirements to verify the correct creation of Cashu payment requirements.
    • Added test_process_cashu_payment to test the processing of a Cashu payment with a sample CashuPaymentPayload.
  • python/x402_a2a/types/init.py
    • Imported CashuPaymentPayload from x402.types.
    • Exported CashuPaymentPayload to make it accessible from the x402_a2a.types module.
Activity
  • The author, yashbhutwala, requested a review and summary from the gemini bot.
  • A medium priority review comment suggested improving the error message for missing mint_url in create_payment_requirements to be more specific about why it's missing.
  • A medium priority review comment suggested simplifying the retrieval of mintUrl from requirements.extra by removing redundant conditional checks.
  • A high priority review comment suggested enhancing the ValueError message in process_payment for unaccepted mints by including the list of missing mints for easier debugging.
  • A medium priority review comment suggested moving the default_mints dictionary to a module-level constant to improve code organization and performance.
  • A medium priority review comment suggested consolidating the price validation logic in create_payment_requirements into a single if/elif/else structure for better readability and maintainability.
  • A medium priority review comment suggested adding more comprehensive unit tests for create_payment_requirements and process_payment, specifically covering failure scenarios and edge cases related to invalid price types, missing mint URLs, and mismatched Cashu payload data.

@yashbhutwala
Copy link
Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Cashu payments by extending create_payment_requirements and process_payment to handle the cashu-token scheme. The changes include logic for creating payment requirements with Cashu-specific details like mint URLs and processing payments with provided Cashu proofs. Unit tests for the new happy path flows are also included.

My review focuses on improving the robustness and maintainability of the new logic. I've suggested improvements to price validation to prevent silent data loss, refactoring opportunities to reduce code duplication, performance enhancements for payload validation, and an expansion of the test suite to cover important failure scenarios. Overall, the changes are well-structured, and addressing these points will further strengthen the implementation.

Copy link
Collaborator

@jorellis jorellis left a comment

Choose a reason for hiding this comment

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

Thanks for this PR. We're glad to see you're using the extra field for the Cashu-specific data—that's the right approach.

We have an architectural concern about adding this logic directly into the core create_payment_requirements function. Adding Cashu-specific arguments and if...then logic there will bloat the core library and make it hard to maintain as we add more payment methods.

We'd like to propose a more scalable "plugin" approach. We're thinking the new file structure would look like this:

python/
  x402_a2a/
    ...
    core/
      (our existing core files)
    partners/
      __init__.py
      cashu/
        __init__.py
        helpers.py   <-- Your new code would go here
        README.md

In this new partners/cashu/helpers.py, you would add your new functions (like create_cashu_payment_requirements and process_cashu_payment). The core functions would remain untouched.

This keeps our core library clean, stable, and scalable. It correctly separates the "partner implementation" from the "core logic" and lets each partner's code live in one isolated place.

Let us know your thoughts and if you would you be open to refactoring this PR to follow this structure? Thanks again for your contribution!

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This pull request significantly extends the x402 library by introducing robust support for Bitcoin Cashu payments. It achieves this through a strategic refactoring that isolates Cashu-specific functionalities into a new 'partners.cashu' module. This design ensures that the core 'merchant' and 'wallet' components remain clean and adaptable to future payment schemes, while providing specialized helpers for Cashu payment requirement creation and processing. The changes include detailed validation for Cashu payments, comprehensive testing, and clear documentation to guide integration.

Highlights

  • Bitcoin Cashu Integration: Added full support for Bitcoin Cashu payments, introducing a new 'cashu-token' scheme within the x402 library.
  • Modular Design for Payment Schemes: Refactored Cashu-specific logic into a new 'x402_a2a.partners.cashu' module, ensuring core 'merchant' and 'wallet' modules remain generic and scheme-agnostic.
  • Enhanced Payment Processing Delegation: Core wallet functions now explicitly reject 'cashu-token' schemes, directing users to dedicated partner helpers for Cashu payment creation and processing.
  • Comprehensive Testing and Documentation: New unit tests cover various Cashu payment scenarios, including error handling and edge cases, and detailed documentation has been added for the new partner helpers.
Changelog
  • python/x402_a2a/core/merchant.py
    • Minor type import adjustment and formatting fix.
  • python/x402_a2a/core/wallet.py
    • Added explicit ValueError checks to 'process_payment_required' and 'process_payment' to prevent 'cashu-token' schemes from being handled by generic logic, directing users to the new partner helpers.
  • python/x402_a2a/partners/init.py
    • New file, establishes the 'partners' package and imports the 'cashu' submodule.
  • python/x402_a2a/partners/cashu/README.md
    • New file, provides usage instructions and examples for the Cashu partner helpers.
  • python/x402_a2a/partners/cashu/init.py
    • New file, exposes 'create_cashu_payment_requirements' and 'process_cashu_payment' from the 'helpers' module.
  • python/x402_a2a/partners/cashu/helpers.py
    • New file, contains the core logic for Cashu integration, including 'create_cashu_payment_requirements' (with mint resolution, price validation, and extra data handling) and 'process_cashu_payment' (with payload validation and mint matching).
  • python/x402_a2a/pyproject.toml
    • Updated build configuration to include the new 'partners' directory in the wheel package.
  • python/x402_a2a/tests/partners/test_cashu.py
    • New file, introduces dedicated tests for Cashu payment requirement creation and processing, covering various valid and invalid scenarios.
  • python/x402_a2a/tests/test_core.py
    • Minor formatting change (removed trailing newline).
  • python/x402_a2a/types/init.py
    • Updated to import and export 'CashuPaymentPayload' for broader accessibility.
Activity
  • The author, yashbhutwala, requested a review and summary from the gemini bot multiple times.
  • gemini-code-assist[bot] provided several review comments (medium and high priority) regarding error messages, code organization, efficiency, and test coverage.
  • yashbhutwala actively addressed each review comment, confirming updates to the codebase, including improving error messages, simplifying code, enhancing validation, and adding comprehensive tests.
  • Following feedback, yashbhutwala performed a significant refactoring, moving Cashu-specific logic out of core modules into a new 'partners' plugin, making the core scheme-agnostic. This refactoring was detailed in a subsequent comment.

@yashbhutwala
Copy link
Author

@jorellis Thanks for the feedback! I've split the Cashu-specific handling out of the shared merchant/wallet flows into a partner plugin so the core surfaces stay scheme-agnostic.

jorellis
jorellis previously approved these changes Sep 25, 2025
@yashbhutwala
Copy link
Author

@jorellis what's next to get this PR merged? 🙏

@jorellis
Copy link
Collaborator

Hi @yashbhutwala, it looks like there are a few merge conflicts with the current main branch. Once these are resolved, the PR may require another approval, but then should be ready to be merged.

Thanks!

@yashbhutwala yashbhutwala force-pushed the cashu-bitcoin-support branch 2 times, most recently from 9c97465 to cb7b0f5 Compare September 30, 2025 14:13
@yashbhutwala
Copy link
Author

Hi @yashbhutwala, it looks like there are a few merge conflicts with the current main branch. Once these are resolved, the PR may require another approval, but then should be ready to be merged.

Thanks!

@jorellis I have rebased and resolved merge conflicts. This should be good to go, please reapprove. 🙏

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.

2 participants