feat: add POST /api/contracts/deploy endpoint (#33)#70
Merged
SudiptaPaul-31 merged 1 commit intoApr 26, 2026
Merged
Conversation
- Add scripts/006-contracts.sql migration: contracts table with UNIQUE(job_id) guard and idempotent contract_id column on milestones - Add lib/soroban/deploy.ts: deploySorobanEscrow stub with detailed TODO for real Stellar SDK WASM upload + transaction flow - Add lib/contracts/store.ts: typed DB helpers (getJobById, getExistingContract, createContract, createMilestones, linkJobToContract) - Add app/api/contracts/deploy/route.ts: protected route that validates input, verifies job ownership, guards duplicate contracts, calls the Soroban service, persists the contract + milestones, and back-patches jobs.escrow_contract_id Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@patopatrish 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.
Summary
scripts/006-contracts.sql): adds acontractstable withUNIQUE(job_id)to enforce one contract per job, and idempotently adds acontract_idFK column to the existingmilestonestable.lib/soroban/deploy.ts): introducesdeploySorobanEscrow()with a deterministic stub and a detailedTODOblock mapping out the real Stellar SDK steps (WASM upload → contract install → transaction polling).lib/contracts/store.ts): typed helpers —getJobById,getExistingContract,getUserById,createContract,createMilestones,linkJobToContract.app/api/contracts/deploy/route.ts):POST /api/contracts/deployprotected by the existingwithAuth()middleware. Validates all inputs, verifies job ownership, guards against duplicate deployments, calls the Soroban service, persists the contract + milestones, and back-patchesjobs.escrow_contract_id.Error codes
Code | HTTP | Meaning -- | -- | -- INVALID_JOB_ID / INVALID_FREELANCER_ID / INVALID_TOTAL_AMOUNT | 400 | Missing or malformed fields INVALID_MILESTONES | 400 | Milestone array fails per-element validation AUTH_REQUIRED | 401 | Missing / expired access token USER_NOT_FOUND | 401 | Wallet has no platform account FORBIDDEN | 403 | Caller is not the job's client JOB_NOT_FOUND / FREELANCER_NOT_FOUND | 404 | Resource doesn't exist CONTRACT_ALREADY_EXISTS / JOB_NOT_DEPLOYABLE | 409 | Business-rule conflicts DEPLOYMENT_FAILED | 500 | Soroban deployment threw DB_ERROR | 500 | Persistence failureTest plan
scripts/006-contracts.sqlagainst your Neon DBPOST /api/contracts/deploywith a valid JWT, existingjobIdowned by the caller, a validfreelancerId, andtotalAmount— expect201withcontractAddressandtxHash409 CONTRACT_ALREADY_EXISTS401 AUTH_REQUIREDjobIdbelonging to a different client — expect403 FORBIDDEN400with the relevant codedeploySorobanEscrowstub for real SDK calls when Soroban integration is readyCloses #33