persist canonical trade flow and provider schema - #374
Conversation
|
@canicefavour 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! 🚀 |
|
Thank you for the work here — the design instincts are right, and I want to be What lands well. Deriving The blocker: this is implemented in the wrong treeThe changes live in Issue #372 names the files under "Source ownership at
None of those were modified except And the one file you did change breaks trade creation
flow VARCHAR(32) NOT NULL,
provider_id UUID NOT NULL REFERENCES users(id),There are 15 Why CI is green anyway
Other items to carry into the rewrite
What I'd like nextRebase onto current One caution on sequencing: CASH-1 blocks CASH-4, CASH-5A, CASH-8, CASH-9 and |
Implemented CASH-1 to establish a canonical product flow and server-derived provider identity for micopay trades. The changes strengthen transactional integrity, remove ambiguity between deposit and cash-out operations, and ensure provider identifiers cannot be controlled or spoofed by clients.
Database & Schema Updates
Added explicit flow and provider_id fields to the trades table.
Supported the two canonical product flows:
deposit
cash_out
Added database-level integrity constraints to enforce valid relationships between flow, provider identity, and legacy merchant/buyer escrow roles.
Updated micopay/sql/init.sql to reflect the canonical trade schema.
Added symmetric up/down database migrations for the new fields and constraints.
Added migration safety checks to detect ambiguous existing trade records and abort with a descriptive error instead of silently assigning incorrect values.
Backend Trade Creation
Updated the trade creation route and service to require an explicit product flow.
Added validation for deposit and cash_out flow values.
Rejected missing or invalid flow values during trade creation.
Prevented clients from controlling the persisted provider_id.
Ignored/rejected client-supplied provider identifiers as appropriate.
Derived provider_id exclusively on the server using authenticated participant information and the selected flow.
Persisted the canonical flow and provider identity atomically with the trade.
Trade API Responses
Updated trade detail and listing queries to expose the canonical fields.
Added flow to trade responses.
Added provider_id to trade responses.
Updated trade projections and service mappings accordingly.
Updated shared TypeScript trade request and response types to match the backend contract.
Integrity & Security
The implementation establishes the backend as the source of truth for provider identity. Client-provided provider IDs can no longer be used to manipulate trade ownership or routing.
Database constraints provide an additional enforcement layer, ensuring invalid combinations of flow, provider, and escrow roles cannot be persisted even if application-level validation is bypassed.
Testing & Verification
Added dedicated backend verification covering:
Valid deposit and cash_out flows.
Missing and invalid flow rejection.
Server-side provider derivation.
Client-supplied provider ID protection.
Trade persistence and response serialization.
Database constraint enforcement.
Migration behavior and ambiguous legacy data handling.
Up/down migration consistency.
Scope Compliance
The implementation was intentionally limited to CASH-1. No changes were made to inbox, scan/completion, cancellation, provider policy, initiator policy, KYC accounting, reputation, provider enrollment, multi-asset escrow, or frontend UI components.
Result
micopay now has a canonical representation of trade product flow and provider identity, with validation enforced across the API, service, shared types, and database layers. This creates a stronger foundation for subsequent cash-out/deposit functionality while preventing client-controlled provider assignment and inconsistent trade states.
Closes #372