-
Notifications
You must be signed in to change notification settings - Fork 2
Implement claim all calibnet token API #334
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
WalkthroughAdds a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant API as /api/claim_token_all
participant Claim as claim_token(faucet_info, address)
participant Aggregator as Aggregator
note right of API #DDF2E6: API calls per-faucet claim handlers\nand returns JSON Vec<ClaimResponse>
User->>API: GET /api/claim_token_all?address=...
API->>Claim: claim_token(CalibnetUSDFC, address)
activate Claim
Claim-->>API: TxHash or Error
deactivate Claim
API->>Claim: claim_token(CalibnetFIL, address)
activate Claim
Claim-->>API: TxHash or Error
deactivate Claim
API->>Aggregator: build Vec<ClaimResponse>{faucet_info, tx_hash?, error?}
Aggregator-->>User: 200 JSON [ ClaimResponse, ... ] / 400/429 as applicable
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #334 +/- ##
==========================================
- Coverage 39.03% 38.75% -0.29%
==========================================
Files 40 40
Lines 2559 2578 +19
==========================================
Hits 999 999
- Misses 1560 1579 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/faucet/server_api.rs (1)
214-218: Add breaking change entry to CHANGELOG.md forclaim_tokenAPI response format change.The CHANGELOG.md has an empty
Breakingsection, but the API response format forclaim_tokenhas changed from a plain string to a JSON object withClaimResponsestructure. This breaking change must be documented.Update the Breaking section in CHANGELOG.md to include an entry similar to:
[#XXX](link): Breaking change -claim_tokenendpoint now returns JSON object withfaucet_infoandtx_hashinstead of plain string transaction hashNote: The API documentation (docs/api-documentation.md) is already accurate and reflects the current JSON response format. No frontend clients were found in this codebase to update.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
docs/api-documentation.md(4 hunks)src/faucet/server_api.rs(8 hunks)src/lib.rs(1 hunks)src/utils/address.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/faucet/server_api.rs (1)
src/lib.rs (5)
server_fn(74-74)server_fn(75-75)server_fn(76-76)server_fn(77-77)server_fn(78-78)
🔇 Additional comments (7)
src/utils/address.rs (1)
111-111: LGTM! Error message improvement.The updated error message is more informative and consistent with the log message above.
docs/api-documentation.md (2)
13-78: LGTM! Clear documentation updates.The updated documentation accurately reflects the new JSON response format with
faucet_infoandtx_hash.
301-310: Good addition of rate limit details.The rate limits table provides clear guidance on faucet constraints, which is helpful for users to understand the service limits.
src/lib.rs (1)
78-78: LGTM! Proper endpoint registration.The registration of
ClaimTokenAllfollows the established pattern and is necessary for the new endpoint to function.src/faucet/server_api.rs (3)
352-356: LGTM! Proper ClaimResponse construction.The function correctly constructs a
ClaimResponsewith the transaction hash on success.
384-388: LGTM! Consistent with native claim handling.The function correctly constructs a
ClaimResponsemirroring the pattern used inhandle_native_claim.
8-8: LGTM! Required imports added.The imports for
TxHashandSerialize/Deserializeare necessary for the newClaimResponsestruct.Also applies to: 13-13
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.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/faucet/server_api.rs (1)
201-208: Consider the enum-based design suggested in previous review.The existing review comment about enforcing mutual exclusivity between
tx_hashanderrorremains unaddressed. The current design allows both fields to beNoneor bothSome, which represents invalid states.
🧹 Nitpick comments (1)
src/faucet/server_api.rs (1)
250-272: Document partial success behavior.The implementation correctly handles full success and full failure cases. However, the partial success scenario (e.g.,
CalibnetUSDFCsucceeds butCalibnetFILfails) is not explicitly documented indocs/api-documentation.md.In this case, the HTTP status code will be set by whichever
claim_tokencall executes last, so a partial success would return an error status code (400/429/500) even though one claim succeeded. The response body will correctly show one success and one failure.Consider documenting this behavior in the API documentation to clarify expectations for consumers.
Would you like me to suggest specific documentation updates for the partial success scenario?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/api-documentation.md(3 hunks)src/faucet/server_api.rs(8 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/faucet/server_api.rs (1)
src/lib.rs (5)
server_fn(74-74)server_fn(75-75)server_fn(76-76)server_fn(77-77)server_fn(78-78)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: e2e
🔇 Additional comments (6)
src/faucet/server_api.rs (4)
8-8: LGTM: Type-safe transaction hash.Using
TxHashfrom alloy primitives improves type safety over plain strings and aligns with the alloy ecosystem used in the codebase.Also applies to: 13-13
218-218: LGTM: Improved return type.Returning
TxHashinstead ofStringprovides better type safety and makes the contract clearer.
317-317: LGTM: Consistent type usage.The return type change to
TxHashis consistent with the updatedclaim_tokensignature and eliminates unnecessary string conversions.Also applies to: 351-351
363-363: LGTM: Consistent type usage.The return type change to
TxHashaligns with the updated API signature and removes unnecessary conversions.Also applies to: 379-379
docs/api-documentation.md (2)
42-72: LGTM: Improved documentation clarity.Separating the success examples for
CalibnetFILandCalibnetUSDFCmakes the documentation more readable and provides clearer guidance for users.
146-221: LGTM: Comprehensive API documentation.The new endpoint documentation is well-structured, clearly describes the JSON response format, and provides helpful examples.
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.
Actionable comments posted: 1
♻️ Duplicate comments (2)
docs/api-documentation.md (2)
265-267: Remove undocumented parameter from curl example.Same issue as line 234—the curl command includes
faucet_info=CalibnetFIL, which should not be present based on the documented query parameters and endpoint design.Apply this diff:
-curl "https://forest-explorer.chainsafe.dev/api/claim_token_all?faucet_info=CalibnetFIL&address=0xAe9C4b9508c929966ef37209b336E5796D632CDc" +curl "https://forest-explorer.chainsafe.dev/api/claim_token_all?address=0xAe9C4b9508c929966ef37209b336E5796D632CDc"
233-235: Remove undocumented parameter from curl example.The curl command includes
faucet_info=CalibnetFIL, which contradicts the documented query parameters (line 159-163) that only listaddressas required. The endpoint description (line 154-155) states it automatically claims both CalibnetUSDFC and CalibnetFIL, so this parameter should not be present.Apply this diff:
-curl "https://forest-explorer.chainsafe.dev/api/claim_token_all?faucet_info=CalibnetFIL&address=invalidaddress" +curl "https://forest-explorer.chainsafe.dev/api/claim_token_all?address=invalidaddress"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs/api-documentation.md(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: codedov
- GitHub Check: deploy
- GitHub Check: e2e
🔇 Additional comments (1)
docs/api-documentation.md (1)
178-192: Response structure documentation is clear and well-formatted.The Claim Response section clearly explains the per-faucet result format with conditional fields (
tx_hashon success,erroron failure). This aligns well with the JSON examples provided.
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
docs/api-documentation.md (2)
239-254: Usejsoncode block for JSON responses.Line 239 marks the response as a
bashcode block, but the content is JSON. This causes inconsistent syntax highlighting compared to the success example at line 209, which correctly usesjson.Apply this diff to use the correct code block type:
**Response:** -```bash +```json [ { "faucet_info": "CalibnetUSDFC",
271-286: Usejsoncode block for JSON responses.Line 271 marks the response as a
bashcode block, but the content is JSON. This should usejsonto match the success example formatting and provide correct syntax highlighting.Apply this diff to use the correct code block type:
**Response:** -```bash +```json [ { "faucet_info": "CalibnetUSDFC",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs/api-documentation.md(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: e2e
- GitHub Check: deploy
- GitHub Check: codedov
- GitHub Check: lint
🔇 Additional comments (2)
docs/api-documentation.md (2)
159-286: Query parameters and examples are consistent.The endpoint correctly documents only the
addressparameter, and all success/failure examples consistently use only this parameter. The previous query parameter inconsistency has been resolved. ✓
178-220: Response structure documentation is clear and well-formatted.The documentation clearly explains the response structure, and the success example uses the proper
jsoncode block for syntax highlighting. ✓
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
docs/api-documentation.md (2)
167-174: Clarify when different status codes are returned and what they indicate for per-faucet results.The Status Codes table (200, 400, 429, 500) doesn't clarify the response behavior for partial failures. The examples show scenarios where both faucets fail identically (400 and 429 cases), but the documentation should explicitly address:
- What status code is returned if one faucet succeeds and the other fails?
- Is the status code determined by the "worst" error, the first error, or the last?
The current description "Tokens successfully claimed" for status 200 is ambiguous when per-faucet errors are possible in the response body.
Consider updating line 171 to:
-| 200 | Tokens successfully claimed | +| 200 | All token claims processed successfully |And add clarification to the Status Codes section (after line 175) explaining the behavior for partial failures:
**Note:** The HTTP status code reflects the result of claim attempts. If all claims succeed, status 200 is returned. If validation fails for the address, status 400 is returned for both faucets. If rate-limited, status 429 is returned. If individual faucets fail with different error types, the last error encountered determines the final HTTP status code.Alternatively, add an example demonstrating mixed success/failure (one faucet succeeds, one fails) to clarify the behavior.
290-293: Clarify rate-limiting scope for the All API.Line 292 states "Each address is subject to rate limiting" but doesn't clarify whether this is:
- Per address across both faucets combined, or
- Per address per individual faucet
The example at lines 272–285 demonstrates different cooldown times per faucet (46 seconds vs. 12 seconds), which implies independent per-faucet rate limiting. However, the Key Points text is ambiguous.
Consider updating line 292 to:
-- Each address is subject to rate limiting to prevent abuse. +- Each address is subject to independent rate limiting per faucet to prevent abuse.This makes it explicit that the two faucets have separate rate limit counters, as demonstrated in the 429 example.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs/api-documentation.md(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: e2e
- GitHub Check: lint
- GitHub Check: codedov
- GitHub Check: deploy
Summary of changes
Changes introduced in this pull request:
/api/claim_token_allAPI to requests claims for bothCalibnetUSDFCandCalibnetFILin one call.claim_tokenand aggregates the results.Preview URL: https://36c9a6e.forest-explorer-preview.workers.dev
Reference issue to close (if applicable)
Closes #333
Other information and links
Change checklist
adheres to the team's
documentation standards,
(if possible),
should be reflected in this document.
Summary by CodeRabbit
New Features
Documentation
Bug Fixes