154 lines
5.6 KiB
JavaScript
154 lines
5.6 KiB
JavaScript
"use strict";
|
|
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.getOverview = getOverview;
|
|
exports.listColdWallets = listColdWallets;
|
|
exports.setColdWallet = setColdWallet;
|
|
exports.listSweeps = listSweeps;
|
|
exports.runSweeps = runSweeps;
|
|
exports.requestFunding = requestFunding;
|
|
exports.confirmFunding = confirmFunding;
|
|
exports.listFunding = listFunding;
|
|
exports.cancelFunding = cancelFunding;
|
|
const treasuryService = __importStar(require("../services/treasuryService"));
|
|
const sweepService = __importStar(require("../services/sweepService"));
|
|
async function getOverview(_req, res) {
|
|
try {
|
|
const overview = await treasuryService.getTreasuryOverview();
|
|
res.json(overview);
|
|
}
|
|
catch (e) {
|
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed to load treasury' });
|
|
}
|
|
}
|
|
async function listColdWallets(_req, res) {
|
|
try {
|
|
res.json({ items: await treasuryService.listColdWallets() });
|
|
}
|
|
catch (e) {
|
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed to list cold wallets' });
|
|
}
|
|
}
|
|
async function setColdWallet(req, res) {
|
|
try {
|
|
const { walletTypeId, address, label } = req.body;
|
|
if (typeof walletTypeId !== 'number' || !address) {
|
|
res.status(400).json({ error: 'walletTypeId and address are required' });
|
|
return;
|
|
}
|
|
const row = await treasuryService.setColdWallet({ walletTypeId, address, label });
|
|
res.json(row);
|
|
}
|
|
catch (e) {
|
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Failed to set cold wallet' });
|
|
}
|
|
}
|
|
async function listSweeps(req, res) {
|
|
try {
|
|
const status = req.query.status || undefined;
|
|
const limit = parseInt(req.query.limit || '50', 10);
|
|
const offset = parseInt(req.query.offset || '0', 10);
|
|
const result = await treasuryService.listSweeps({ status, limit, offset });
|
|
res.json(result);
|
|
}
|
|
catch (e) {
|
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed to list sweeps' });
|
|
}
|
|
}
|
|
async function runSweeps(_req, res) {
|
|
try {
|
|
const processed = await sweepService.processPendingSweeps();
|
|
res.json({ processed });
|
|
}
|
|
catch (e) {
|
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Sweep run failed' });
|
|
}
|
|
}
|
|
async function requestFunding(req, res) {
|
|
try {
|
|
const { walletTypeId, amount, notes } = req.body;
|
|
if (typeof walletTypeId !== 'number' || amount == null) {
|
|
res.status(400).json({ error: 'walletTypeId and amount are required' });
|
|
return;
|
|
}
|
|
const result = await treasuryService.requestColdToHotFunding(req.user.userId, {
|
|
walletTypeId,
|
|
amountRaw: BigInt(amount),
|
|
notes,
|
|
});
|
|
res.status(201).json(result);
|
|
}
|
|
catch (e) {
|
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Funding request failed' });
|
|
}
|
|
}
|
|
async function confirmFunding(req, res) {
|
|
try {
|
|
const fundingId = req.params.fundingId;
|
|
const { blockchainTxId } = req.body;
|
|
if (!blockchainTxId) {
|
|
res.status(400).json({ error: 'blockchainTxId is required' });
|
|
return;
|
|
}
|
|
const result = await treasuryService.confirmColdToHotFunding(req.user.userId, fundingId, blockchainTxId);
|
|
res.json(result);
|
|
}
|
|
catch (e) {
|
|
const msg = e instanceof Error ? e.message : 'Confirm failed';
|
|
res.status(msg.includes('not found') ? 404 : 400).json({ error: msg });
|
|
}
|
|
}
|
|
async function listFunding(req, res) {
|
|
try {
|
|
const status = req.query.status || undefined;
|
|
const limit = parseInt(req.query.limit || '50', 10);
|
|
const offset = parseInt(req.query.offset || '0', 10);
|
|
const result = await treasuryService.listFunding({ status, limit, offset });
|
|
res.json(result);
|
|
}
|
|
catch (e) {
|
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed to list funding' });
|
|
}
|
|
}
|
|
async function cancelFunding(req, res) {
|
|
try {
|
|
await treasuryService.cancelFunding(req.params.fundingId);
|
|
res.json({ message: 'Cancelled' });
|
|
}
|
|
catch (e) {
|
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Cancel failed' });
|
|
}
|
|
}
|
|
//# sourceMappingURL=treasuryController.js.map
|