feat(api-server): wire batch-initiate endpoint to contract batch semantics - #947
Open
okonkwofreeman001 wants to merge 1 commit into
Open
Conversation
…ntics The /v1/swap/batch-initiate handler returned "not yet implemented". Reuse the batch semantics validated in the contract's batch tests: cap batch size at MAX_BATCH_SIZE (50), reject non-positive prices, allocate sequential swap IDs (contract NextId), create Pending swaps with a ~7-day expiry served back through the AtomicIP#316 cache so GET /swap/{swap_id} reads them, and cache results under the AtomicIP#523 idempotency key for replay. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <[email protected]>
|
@okonkwofreeman001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #843
Closes #844
Summary
The
POST /v1/swap/batch-initiateendpoint (aliased as/v1/swap/bulk/initiate) was unwired: after validating request shape and checking the idempotency store, it always returned400 batch_initiate_swap not yet implemented.This PR wires the endpoint to the batch semantics already implemented and validated in the
AtomicSwapcontract's batch tests (contracts/atomic_swap/src/batch_swap_features_tests.rs,batch_approval_tests.rs,batch_history_tests.rs) by mirroringbatch_initiate_swapincontracts/atomic_swap/src/lib.rs.What changed
api-server/src/handlers.rsNew validations matching the contract (previously missing):
MAX_BATCH_SIZE(50) → mirrorsContractError::BatchTooLargerequire_positive_price/PriceTooSmallip_ids/priceslength mismatch, empty batch, duplicateip_ids(Implement Swap Batch Deduplication #524), idempotency replay (Add Swap Batch Idempotency #523)Execution pass mirroring the contract:
NEXT_SWAP_IDcounter (stands in for the contract'sNextIduntil handlers are wired to a live Soroban RPC client)SwapRecordper IP withstatus = Pendingandexpiry = now + 604800(7 days, same as the contract)cache::swap_key), soGET /swap/{swap_id}returns themBatchInitiateSwapResponse { swap_ids }and caches the response under the Add Swap Batch Idempotency #523 idempotency key so replays return the same IDs instead of allocating new onesapi-server/src/main.rsAdded handler tests:
swap_ids, and the created swaps read back viaGET /swap/{id}asPendingwith a futureexpirySemantics mirrored from the contract
batch_initiate_swap)BatchEmptypanicBatchSizeMismatchpanicBatchTooLarge(MAX_BATCH_SIZE= 50)SwapExistson duplicateip_idsrequire_positive_priceNextIdsequential IDsNEXT_SWAP_IDatomic counterSwapRecordPending,now + 604800expirySwapRecordPending,now + 604800expiry, cached forGET /swap/{id}Testing
Not run in this environment: it has no Rust toolchain, and
api-serverbuilds as a standalone workspace (it is excluded from the root workspace due to an async-graphql version conflict). Verify locally with:cargo test --manifest-path api-server/Cargo.tomlThe existing 400-path tests (
test_batch_initiate_swap_mismatched_lengths_returns_400,test_batch_initiate_swap_empty_ids_returns_400) are unchanged and still pass.