forked from Emmy123222/Stellar-MicroPay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduledTransactionRoutes.js
More file actions
69 lines (62 loc) · 1.76 KB
/
Copy pathscheduledTransactionRoutes.js
File metadata and controls
69 lines (62 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"use strict";
const express = require("express");
const router = express.Router();
const scheduledTransactionService = require("../services/scheduledTransactionService");
/**
* POST /api/scheduled-txns
* Schedules a new transaction for future submission.
* Body: { signedXDR: string, submitAt: string (ISO 8601) }
*/
router.post("/", (req, res, next) => {
try {
const { signedXDR, submitAt } = req.body;
if (!signedXDR || !submitAt) {
return res.status(400).json({ error: "Missing signedXDR or submitAt" });
}
const scheduledTx = scheduledTransactionService.scheduleTransaction(
signedXDR,
submitAt
);
res.status(201).json({
message: "Transaction scheduled successfully",
id: scheduledTx.id,
publicKey: scheduledTx.publicKey,
submitAt: scheduledTx.submitAt.toISOString(),
});
} catch (error) {
next(error);
}
});
/**
* GET /api/scheduled-txns/:publicKey
* Lists all pending scheduled transactions for a given public key.
*/
router.get("/:publicKey", (req, res, next) => {
try {
const { publicKey } = req.params;
const transactions = scheduledTransactionService.getScheduledTransactions(
publicKey
);
res.json(transactions);
} catch (error) {
next(error);
}
});
/**
* DELETE /api/scheduled-txns/:id
* Cancels a scheduled transaction.
*/
router.delete("/:id", (req, res, next) => {
try {
const { id } = req.params;
const cancelled = scheduledTransactionService.cancelScheduledTransaction(id);
if (cancelled) {
res.json({ message: `Transaction ${id} cancelled successfully.` });
} else {
res.status(404).json({ error: `Transaction ${id} not found or not pending.` });
}
} catch (error) {
next(error);
}
});
module.exports = router;