-
Notifications
You must be signed in to change notification settings - Fork 79
feat: Update network field to use caip2 schema BREAKING CHANGE #29
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @jsutaria, 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 introduces a significant change by migrating the 'network' field from arbitrary string literals to the CAIP-2 standard across the codebase and documentation. This standardization aims to enhance interoperability and provide a consistent way to identify various blockchain networks, addressing challenges encountered with string literals in wallet infrastructure development. This is a breaking change that impacts how network identifiers are specified in payment requirements and related configurations. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 is a great step towards standardizing network identification by adopting the CAIP-2 schema. The changes are consistent across most of the codebase. However, I've identified a few critical areas, primarily in error handling paths and documentation examples, where network identifiers are hardcoded to Base mainnet. This could cause incorrect behavior and misleading receipts when your system operates on other networks. My review provides specific suggestions to dynamically determine the network from the available context, ensuring the system is robust and network-agnostic.
python/x402_a2a/executors/client.py
Outdated
| # Payment processing failed | ||
| from ..types import SettleResponse, x402ErrorCode | ||
| failure_response = SettleResponse(success=False, network="base", error_reason=f"Payment failed: {e}") | ||
| failure_response = SettleResponse(success=False, network="eip155:8453", error_reason=f"Payment failed: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of a payment processing failure, the network in the SettleResponse is hardcoded to "eip155:8453" (Base mainnet). This can lead to incorrect failure receipts if the payment was for a different network. The network should be derived from the payment_required response. Using the network from the first available option is a safer default.
| failure_response = SettleResponse(success=False, network="eip155:8453", error_reason=f"Payment failed: {e}") | |
| network = payment_required.accepts[0].network if payment_required and payment_required.accepts else "eip155:8453" | |
| failure_response = SettleResponse(success=False, network=network, error_reason=f"Payment failed: {e}") |
python/x402_a2a/executors/server.py
Outdated
| async def _fail_payment(self, task, error_code: str, error_reason: str, event_queue: EventQueue): | ||
| """Handle payment failure.""" | ||
| failure_response = SettleResponse(success=False, network="base", error_reason=error_reason) | ||
| failure_response = SettleResponse(success=False, network="eip155:8453", error_reason=error_reason) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The network is hardcoded to Base mainnet ("eip155:8453") when creating a failure response. This is problematic as the payment could have been for any network. This method should determine the correct network, for instance by looking up the original PaymentRequirements from the _payment_requirements_store using the task.id. Using a hardcoded mainnet value can lead to misleading failure receipts.
| failure_response = SettleResponse(success=False, network="eip155:8453", error_reason=error_reason) | |
| accepts_array = self._payment_requirements_store.get(task.id) | |
| network = accepts_array[0].network if accepts_array else "eip155:8453" | |
| failure_response = SettleResponse(success=False, network=network, error_reason=error_reason) |
| task = utils.record_payment_failure( | ||
| task, "verification_failed", | ||
| SettleResponse(success=False, network="base", error_reason=verify_response.invalid_reason) | ||
| SettleResponse(success=False, network="eip155:8453", error_reason=verify_response.invalid_reason) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The network is hardcoded to "eip155:8453" (Base mainnet) in this failure case. This is incorrect if the payment was intended for a different network. You should use the network from the payment_requirements object, which is available in this function's scope.
| SettleResponse(success=False, network="eip155:8453", error_reason=verify_response.invalid_reason) | |
| SettleResponse(success=False, network=payment_requirements.network, error_reason=verify_response.invalid_reason) |
| success=settle_response.success, | ||
| transaction=settle_response.transaction, | ||
| network=settle_response.network or "base", | ||
| network=settle_response.network or "eip155:8453", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback network is hardcoded to "eip155:8453" (Base mainnet). If settle_response.network is None, it's safer to fall back to the network specified in the original payment_requirements rather than assuming Base mainnet.
| network=settle_response.network or "eip155:8453", | |
| network=settle_response.network or payment_requirements.network, |
|
I think this is a good call to migrate these to CAIP2. Can we move 'eip155:8453' into an a2a x402 python variable to be used in the tools? |
- Updated docstrings to explicitly mention CAIP-2 format - Added examples for EVM, Bitcoin, Solana, and Cosmos networks - Clarified that Lightning Network uses Bitcoin's CAIP-2 identifier - Changed "Ethereum address" to "Address" (format depends on network) - Added note about namespace:reference format in config This improves developer experience by showing how to use the network field with non-EVM chains that have CAIP-2 identifiers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Committed-By-Agent: claude
Reverted whitespace-only formatting changes (bullet points, trailing spaces, table alignment) that were automatically applied by IDE formatter. Kept substantive changes: network field values updated from "base" to "eip155:8453" (CAIP-2 format) in spec.md examples. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Committed-By-Agent: claude
Description
While building wallet infrastructure, we've found that using string literals for chain names can get - I'd recommend using the caip2 standard which is standard across all chain types, regardless of the network!
BREAKING CHANGE