Skip to content

Commit

Permalink
status.ts + small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlei committed Jul 18, 2023
1 parent 4db4225 commit 8e22535
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/routes/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getTicket } from "../ticket-queue";
import rTracer from "cls-rtracer";

export default async function (req: Request, res: Response) {
const reqId = (Math.random() + 1).toString(36).substr(2, 5);
const client = await connect();

let account;
Expand Down Expand Up @@ -73,7 +72,9 @@ export default async function (req: Request, res: Response) {
// TODO: check for tefNO_TICKET and try again with another ticket
if (status === "tesSUCCESS" || status === "terQUEUED") {
console.log(
`${reqId} | Funded ${account.address} with ${amount} XRP (${status})`
`${rTracer.id()} | Funded ${
account.address
} with ${amount} XRP (${status})`
);

if (config.BIGQUERY_PROJECT_ID) {
Expand Down Expand Up @@ -118,12 +119,12 @@ export default async function (req: Request, res: Response) {
res.send(response);
}
} catch (err) {
console.log(`${reqId}| ${err}`);
console.log(`${rTracer.id()}| ${err}`);
res.status(500).send({
error: "Unable to fund account. Server load is too high. Try again later",
account,
});
await resetClient("accounts");
await resetClient(rTracer.id().toString());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/routes/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect, resetClient } from "../client";
import { fundingWallet } from "../wallet";
import { checkForWarning, format } from "../utils";
import { AccountInfoResponse, FeeResponse, ServerInfoResponse } from "xrpl";

import * as packageJson from "../../package.json";
export default async function (req: Request, res: Response) {
let client = await connect();
try {
Expand Down Expand Up @@ -39,7 +39,7 @@ export default async function (req: Request, res: Response) {
const processUptime = process.uptime();
const osUptime = os.uptime();
res.send({
faucetVersion: "0.0.2",
faucetVersion: packageJson.version,
processUptime,
processUptimeHhMmSs: format(processUptime),
osUptime,
Expand Down
48 changes: 46 additions & 2 deletions src/routes/status.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
import { Request, Response } from 'express';
import { Request, Response } from "express";
import { connect, resetClient } from "../client";
import { checkForWarning, format } from "../utils";
import { FeeResponse, ServerInfoResponse } from "xrpl";

export default async function(req: Request, res: Response) {}
export default async function (req: Request, res: Response) {
let client = await connect();
try {
const serverInfo: ServerInfoResponse = await client.request({
command: "server_info",
});
checkForWarning(serverInfo.result);

const feeInfo: FeeResponse = await client.request({
command: "fee",
});
checkForWarning(feeInfo.result);

const processUptime = process.uptime();

const text = `*XRP Test Net Faucet:* https://xrpl.org/xrp-testnet-faucet.html
*Uptime:* ${format(processUptime)}
*rippled* buildVersion: ${serverInfo.result.info.build_version}
> completeLedgers: ${serverInfo.result.info.complete_ledgers}
> loadFactor: ${serverInfo.result.info.load_factor}
> peers: ${serverInfo.result.info.peers}
> serverState: ${serverInfo.result.info.server_state}
> validatedLedger.ledgerVersion: ${
serverInfo.result.info.validated_ledger.seq
}
> hostID: ${serverInfo.result.info.hostid}
> open_ledger_fee: ${feeInfo.result.drops.open_ledger_fee} drops
> expected_ledger_size: ${feeInfo.result.expected_ledger_size}
Full info: https://faucet.altnet.rippletest.net/info`;

res.send({
response_type: "in_channel",
text: text,
});
} catch (error) {
console.log("/status error:", error);
res.status(500).send({
error: "Server load is too high. Request status later",
});
await resetClient("status");
}
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
Expand Down

0 comments on commit 8e22535

Please sign in to comment.