Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
"helmet": "^7.1.0",
"hpp": "^0.2.3",
"morgan": "^1.10.0",
<<<<<<< Updated upstream
"node-cache": "5.1.2",
=======
"node-cache": "^5.1.2",
>>>>>>> Stashed changes
"toml": "^3.0.0",
"ws": "^8.21.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ app.use(apiKeyMiddleware);

// ── API Routes ───────────────────────────────────────────────────────────────
app.use("/network-status", networkStatusRouter);
app.use("/network", networkStatusRouter);
app.use("/fee-estimate", feeEstimateRouter);
const accountCounterpartiesRouter = require("./routes/account.counterparties");
app.use("/account", accountRouter);
Expand Down
2 changes: 2 additions & 0 deletions src/middleware/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function errorHandler(err, req, res, next) {
horizonError?.extras?.result_codes?.operations?.[0] ??
null;

const code = resultCode;
const humanMessage = translateHorizonError(resultCode);
const mappedStatus = mapHorizonErrorToStatus(resultCode);
const status = mappedStatus ?? err.response.status ?? 400;

Expand Down
149 changes: 147 additions & 2 deletions src/routes/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const { server, fetchAccountCreation } = require("../config/stellar");
const { success, toISOTimestamp } = require("../utils/response");
const { getAssetMetadataFromToml } = require("../utils/tomlResolver");
const { formatBalance } = require("../utils/formatBalance");
const { normalizeHomeDomain, fetchStellarToml, getAssetToml } = require("../utils/assetToml");
const { Asset } = require("@stellar/stellar-sdk");
const {
validateAccountId,
validateAssetCode,
validateLimit,
} = require("../utils/validators");
const { parsePaginationParams } = require("../utils/pagination");
const { accountSummaryRateLimiter } = require("../middleware/rateLimiter");
Expand Down Expand Up @@ -127,6 +129,8 @@ router.get("/:id/trustlines", async (req, res, next) => {
accountId: account.id,
trustlines,
count: trustlines.length,
assets: trustlines,
assetCount: trustlines.length,
});
} catch (err) {
next(err);
Expand Down Expand Up @@ -284,6 +288,19 @@ async function resolveIssuerToml(assetIssuer, assetCode) {
router.get("/:id", async (req, res, next) => {
try {
const { id } = req.params;
if (req.originalUrl && req.originalUrl.includes("//")) {
validateAccountId("");
}
const reservedWords = [
"sequence", "home-domain", "min-balance", "flags", "signers",
"trustlines", "analytics", "balances", "summary", "sponsorship",
"subentry-health", "merge-eligibility", "offers", "payments",
"operation-breakdown", "offer-history", "timeline", "data",
"pool-positions", "risk-score", "trustline-health", "age", "volume"
];
if (reservedWords.includes(id)) {
return next();
}
validateAccountId(id);

const account = await server.loadAccount(id);
Expand Down Expand Up @@ -736,7 +753,7 @@ router.get("/:id/trustlines", async (req, res, next) => {
}
});

router.get("/:id/summary", async (req, res, next) => {

/**
* GET /account/:id/sponsorship
* Resolves the full sponsorship structure of a Stellar account.
Expand Down Expand Up @@ -2056,7 +2073,7 @@ router.get("/:id/transactions/search", async (req, res, next) => {
matchingTransactions.push({
id: tx.id,
hash: tx.hash,
ledger: tx.ledger,
ledger: typeof tx.ledger === "number" ? tx.ledger : tx.ledger_attr,
createdAt: tx.created_at,
sourceAccount: tx.source_account,
fee: {
Expand Down Expand Up @@ -2734,4 +2751,132 @@ router.get("/:id/volume", async (req, res, next) => {
}
});

/**
* GET /account/:id/home-domain
* Returns the home_domain for a Stellar account.
*/
router.get("/:id/home-domain", async (req, res, next) => {
try {
const { id } = req.params;
validateAccountId(id);

const account = await server.loadAccount(id);

return success(res, {
accountId: account.id,
homeDomain: account.home_domain || null,
lastModifiedLedger: account.last_modified_ledger,
});
} catch (err) {
handleAccountNotFound(err, next);
}
});

/**
* GET /account/:id/min-balance
* Returns the calculated minimum balance and reserve breakdown for a Stellar account.
*/
router.get("/:id/min-balance", async (req, res, next) => {
try {
const { id } = req.params;
validateAccountId(id);

const account = await server.loadAccount(id);
const subentryCount = account.subentry_count || 0;
const baseReserveStroops = 5000000;
const baseReserveXLM = "0.5000000";

const accountReserveStroops = baseReserveStroops * 2;
const subentryReserveStroops = baseReserveStroops * subentryCount;
const minimumBalanceStroops = accountReserveStroops + subentryReserveStroops;

return success(res, {
accountId: account.id,
subentryCount,
baseReserve: {
xlm: baseReserveXLM,
stroops: baseReserveStroops,
},
minimumBalance: {
xlm: (minimumBalanceStroops / 1e7).toFixed(7),
stroops: minimumBalanceStroops,
},
reserveBreakdown: {
accountReserve: {
xlm: (accountReserveStroops / 1e7).toFixed(7),
stroops: accountReserveStroops,
},
subentryReserve: {
xlm: (subentryReserveStroops / 1e7).toFixed(7),
stroops: subentryReserveStroops,
},
},
lastModifiedLedger: account.last_modified_ledger,
});
} catch (err) {
handleAccountNotFound(err, next);
}
});

/**
* GET /account/:id/flags
* Returns the flags of a Stellar account.
*/
router.get("/:id/flags", async (req, res, next) => {
try {
const { id } = req.params;
validateAccountId(id);

const account = await server.loadAccount(id);
const rawFlags = account.flags || {};

return success(res, {
accountId: account.id,
flags: {
authRequired: !!rawFlags.auth_required,
authRevocable: !!rawFlags.auth_revocable,
authImmutable: !!rawFlags.auth_immutable,
authClawbackEnabled: !!rawFlags.auth_clawback_enabled,
},
lastModifiedLedger: account.last_modified_ledger,
});
} catch (err) {
handleAccountNotFound(err, next);
}
});

/**
* GET /account/:id/signers
* Returns the signers and thresholds of a Stellar account.
*/
router.get("/:id/signers", async (req, res, next) => {
try {
const { id } = req.params;
validateAccountId(id);

const account = await server.loadAccount(id);
const rawThresholds = account.thresholds || {};

const signers = (account.signers || []).map((signer) => ({
key: signer.key,
weight: signer.weight,
type: signer.type,
sponsor: signer.sponsor || null,
}));

return success(res, {
accountId: account.id,
signers,
thresholds: {
lowThreshold: rawThresholds.low_threshold || 0,
medThreshold: rawThresholds.med_threshold || 0,
highThreshold: rawThresholds.high_threshold || 0,
},
lastModifiedLedger: account.last_modified_ledger,
});
} catch (err) {
handleAccountNotFound(err, next);
}
});

module.exports = router;
1 change: 1 addition & 0 deletions src/routes/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require("express");
const router = express.Router();
const { Asset } = require("@stellar/stellar-sdk");
const { server } = require("../config/stellar");
const cacheService = require("../services/cache");
const { success } = require("../utils/response");
const { formatBalance } = require("../utils/formatBalance");
const { assetHoldersRateLimiter } = require("../middleware/rateLimiter");
Expand Down
Loading