Skip to content

[Backend] Wire createStreamSchema validation into POST /v1/streams #452

@ogazboiz

Description

@ogazboiz

Join the discussion on Telegram

Why this matters

The POST /v1/streams controller (createStream in backend/src/controllers/stream.controller.ts) destructures req.body directly and passes the values straight into prisma.stream.upsert with no validation. A createStreamSchema already exists in backend/src/validators/stream.validator.ts but is never imported or used anywhere. As a result, the endpoint will:

  • throw an unhandled error and return 500 when depositedAmount/ratePerSecond are missing or non-numeric (BigInt(undefined) / parseInt(NaN)),
  • divide by zero in endTime computation when ratePerSecond is "0",
  • accept malformed Stellar addresses for sender/recipient.

Wiring the existing validator gives clean 400 responses and removes the dead code.

Acceptance criteria

  • Validate the request body with createStreamSchema (or zod safeParse) at the top of createStream and return 400 with error.issues on failure.
  • Validate sender/recipient are valid Stellar public keys (a Stellar address validator already exists in the stream validators per issue Add input validation for Stellar addresses in stream endpoints #379).
  • Guard ratePerSecond === '0' before the endTime division.
  • Add an integration test covering a missing-field body returning 400 (extend backend/tests/integration/streams.test.ts).

Files to touch

  • backend/src/controllers/stream.controller.ts
  • backend/src/validators/stream.validator.ts
  • backend/tests/integration/streams.test.ts

Out of scope

  • Changing the on-chain create flow (this endpoint only registers/mirrors metadata).

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendBackend related tasksgood first issueGood for newcomers

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions