-
Notifications
You must be signed in to change notification settings - Fork 980
[Feat] Java implementation #178
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
Conversation
|
Someone is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
✅ Heimdall Review Status
|
0d434c1 to
55bc81b
Compare
|
@stefanoamorelli amazingly quick turn around, will review. We need you to sign your commits before we merge https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits |
c79fa24 to
eb86718
Compare
Authored, signed the commits, and rebased ✅ |
0ac9bef to
010bcec
Compare
|
@stefanoamorelli apologies for the delay, CB has been on recharge week. I'm not very versed in Java so gonna have someone from our team who is take a look, should merge this week. Your commits still aren't showing up as signed, do need that or I physically can't merge :) |
010bcec to
26e6dc1
Compare
|
@erikreppel-cb no worries, thanks for letting me know! I've force-pushed the signed commits, does it show on your end too now? And sure, looking forward to your feedback! |
|
@stefanoamorelli yes now they're signed, thank you! |
java/checkstyle-suppressions.xml
Outdated
| <suppress checks="VisibilityModifier" files=".*[/\\]client[/\\].*\.java"/> | ||
|
|
||
| <!-- Suppress indentation checks on all files --> | ||
| <suppress checks="Indentation" files=".*\.java"/> |
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.
Why do we suppress this?
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.
No need actually, removed.
| <module name="IllegalInstantiation"/> | ||
| <module name="SimplifyBooleanExpression"/> | ||
| <module name="SimplifyBooleanReturn"/> | ||
|
|
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.
Consider adding a Javadoc checker to ensure documentation, e.g.:
| <module name="JavadocPackage"/> <module name="MissingJavadocType"> <property name="scope" value="public"/> <property name="excludeScope" value="package"/> </module> | |
| <module name="MissingJavadocMethod"> <property name="scope" value="public"/> | |
| <property name="excludeScope" value="package"/> | |
| <property name="allowMissingPropertyJavadoc" value="true"/> </module> | |
| <module name="MissingJavadocVariable"> <property name="scope" value="public"/> | |
| </module> | |
| <module name="JavadocStyle"> <property name="checkFirstSentence" value="true"/> | |
| <property name="endOfSentenceFormat" value="([.?!][ \t\n\r\f<])|([.?!]$)"/> | |
| <property name="checkEmptyJavadoc" value="true"/> | |
| <property name="checkHtml" value="true"/> | |
| </module> |
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.
Good idea!
| Json.MAPPER.writeValueAsString(body))) | ||
| .build(); | ||
|
|
||
| String json = http.send(request, HttpResponse.BodyHandlers.ofString()).body(); |
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.
Calling .body() directly means we don't do any error handling - feels like we should catch some common cases? CC @erikreppel-cb
| * Implement with web3j, Solana-J, etc., depending on your payment scheme. | ||
| */ | ||
| public interface CryptoSigner { | ||
| /** Returns a hex-encoded signature covering the given payload map. */ |
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.
Could we expand on this Javadoc? It's a bit too abstract to reasonably implement, since interpretations will vary depending on protocol (Ethereum, Solana, etc.)
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.
I've added a more descriptive Javadoc, please let me know if we want more details or a different structure.
|
|
||
| /** Contract for calling an x402 facilitator (HTTP, gRPC, mock, etc.). */ | ||
| public interface FacilitatorClient { | ||
| VerificationResponse verify(String paymentHeader, |
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.
We should add Javadoc to all public methods
|
|
||
| /** Identifies a payment scheme+network pair that a facilitator supports. */ | ||
| public class Kind { | ||
| public String scheme; // e.g. "exact" |
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.
All of these should be public final since they are read only
| private final Map<String, BigInteger> priceTable; // path → amount | ||
| private final FacilitatorClient facilitator; | ||
|
|
||
| public PaymentFilter(String payTo, |
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.
Javadoc these params. priceTable especially needs a detailed description since it dictates the behavior
| Server->>Facilitator: Settle payment (async) | ||
| ``` | ||
|
|
||
| ## Error Handling |
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.
We don't do any error handling for non-402 cases?
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.
Updated ✔️
| /* -------- best-effort async settlement (errors ignored) -------- */ | ||
| try { | ||
| facilitator.settle(header, buildRequirements(path)); | ||
| } catch (Exception ignored) { } |
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.
We don't do any error handling for non-402 cases?
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.
Impoved error handling - most importantly, removed the best-effort settlement to align with the typescript and go counterparties and indeed handle settlement failures.
2af4568 to
a9b495f
Compare
|
@stefanoamorelli looks great, your recent commits aren't showing up as signed, if you can sign those I'll merge |
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
fd0ca9a to
80b31aa
Compare
|
@erikreppel-cb good stuff, thanks! 🎉 Commits should be signed now, sorry about that ✔️ (I think when re-basing from Github UI they lose their signature) |
|
@erikreppel-cb just checking in, should I rebase or is there anything needed from my side before merging? |
|
@stefanoamorelli merged! |

Tip
Better reviewed commit-by-commit. This PR follows conventional, atomic commits.
In this PR we introduce the Java implementation + tests (>85% test coverage), following the existing
typescript, andgoimplementations.A follow-up PR will include a more extensive Java Spring example.
Closes: #164