"use strict"; /** * Withdrawal controllers — user submission / cancellation and the admin withdrawal queue. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.withdraw = withdraw; exports.cancelOwnWithdrawal = cancelOwnWithdrawal; exports.adminListWithdrawals = adminListWithdrawals; exports.adminGetWithdrawal = adminGetWithdrawal; exports.adminProcessWithdrawal = adminProcessWithdrawal; exports.adminRequeueWithdrawal = adminRequeueWithdrawal; exports.adminRejectWithdrawal = adminRejectWithdrawal; const withdrawalService = __importStar(require("../services/withdrawalService")); const withdrawalAdminService = __importStar(require("../services/withdrawals/withdrawalAdminService")); /** * Records a withdrawal request (status `pending`, amount + fee reserved). * Body: `walletType`, `toAddress`, `amount`, optional `totpCode`, optional `idempotencyKey` * (also accepted as the `Idempotency-Key` header). */ async function withdraw(req, res) { const userId = req.user.userId; const { walletType, toAddress, amount } = req.body; if (!walletType || !toAddress || amount == null) { res.status(400).json({ error: 'walletType, toAddress and amount required' }); return; } const headerKey = req.header('Idempotency-Key')?.trim(); const amountRaw = BigInt(amount); const result = await withdrawalService.requestWithdrawal(userId, walletType, toAddress, amountRaw, req.body.totpCode, { idempotencyKey: req.body.idempotencyKey ?? headerKey ?? null }); res.json(result); } /** User cancels their own withdrawal while it is still pending (refund to available balance). */ async function cancelOwnWithdrawal(req, res) { const row = await withdrawalService.cancelWithdrawal(String(req.params.id), { userId: req.user.userId, }); res.json({ transactionId: row.id, status: row.status }); } async function adminListWithdrawals(req, res) { const q = req.query; const result = await withdrawalAdminService.listWithdrawals({ status: q.status, network: q.network, from: q.from, to: q.to, minAmount: q.minAmount, maxAmount: q.maxAmount, search: q.search, limit: q.limit ? Number(q.limit) : undefined, offset: q.offset ? Number(q.offset) : undefined, }); res.json(result); } async function adminGetWithdrawal(req, res) { const detail = await withdrawalAdminService.getWithdrawalDetail(String(req.params.id)); if (!detail) { res.status(404).json({ error: 'Withdrawal not found', code: 'WITHDRAWAL_NOT_FOUND' }); return; } res.json(detail); } /** Starts (or retries) the payout. Returns the resulting status (processing / pending / failed). */ async function adminProcessWithdrawal(req, res) { const result = await withdrawalService.processWithdrawal(String(req.params.id), { actorType: 'admin', actorUserId: req.user.userId, }); res.json(result); } async function adminRequeueWithdrawal(req, res) { const row = await withdrawalService.requeueWithdrawal(String(req.params.id), req.user.userId); res.json({ transactionId: row.id, status: row.status }); } async function adminRejectWithdrawal(req, res) { const row = await withdrawalService.rejectWithdrawal(String(req.params.id), { actorId: req.user.userId, reason: String(req.body.reason ?? ''), }); res.json({ transactionId: row.id, status: row.status }); } //# sourceMappingURL=withdrawalController.js.map