Skip to content

feat(streams): implement stream top-up endpoint (#595)#3

Open
fytgian wants to merge 1 commit into
mainfrom
feature/595-stream-topup
Open

feat(streams): implement stream top-up endpoint (#595)#3
fytgian wants to merge 1 commit into
mainfrom
feature/595-stream-topup

Conversation

@fytgian

@fytgian fytgian commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary

Closes Vera3289#595

Adds the ability for employers to top up existing streams with additional funds without cancellation.

Changes

Modified files

  • api/routes/streams.js — Added POST /:stream_id/top-up route

How it works

  1. Validates stream_id (integer ≥ 1), employer (Stellar G-address), and amount (positive integer string)
  2. Calls get_stream on the Soroban contract to verify the stream exists
  3. Rejects with 400 if the stream is not in Active status (cannot top-up Paused/Cancelled/Exhausted streams)
  4. Submits top_up(employer, stream_id, amount) transaction to the Soroban contract
  5. Invalidates the stream cache so subsequent GET /:stream_id reflects the updated deposit
  6. Returns { success, stream_id, amount_added, transaction_hash }

Acceptance Criteria

Criterion Status
Top-up endpoint implementation POST /v1/api/streams/:stream_id/top-up
Validation of existing stream get_stream call + status check before submission
Fund transfer and escrow update top_up Soroban contract call
Event logging ✅ Soroban contract emits on-chain events; cache invalidated
Fee handling ✅ Handled by Soroban contract; BASE_FEE set in stellarService
Transaction confirmation ✅ Returns transaction_hash from confirmed tx
Input validation ✅ express-validator on all fields

- POST /v1/api/streams/:stream_id/top-up accepts employer + amount
- Validates stream exists via get_stream contract call
- Rejects top-up if stream status is not Active
- Calls top_up(employer, stream_id, amount) on Soroban contract
- Invalidates stream cache after successful top-up
- Full input validation (stream_id, employer address, amount > 0)
- Swagger JSDoc documented
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.

Implement Stream Top-Up Functionality

1 participant