Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #138 from niteshbalusu11:clean-failed-payments-com…
Browse files Browse the repository at this point in the history
…mand

Added clean-failed-payments command
  • Loading branch information
niteshbalusu11 authored Dec 19, 2022
2 parents 627c4d4 + f1883f3 commit 983d87d
Show file tree
Hide file tree
Showing 16 changed files with 613 additions and 132 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ chart-fees-paid
# Show a chart of payments received
chart-payments-received

# Remove old failed payment data for probes and other failed payments
clean-failed-payments

# See details on how closed channels resolved on-chain
closed

Expand Down
43 changes: 43 additions & 0 deletions SERVER.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,49 @@ try {

<br></br>

### CleanFailedPayments

```javascript
/**
@PostRequest
@Url
http://localhost:8055/api/clean-failed-payments
@Body
{
is_dry_run: <Avoid Actually Deleting Payments>
lnd: <Authenticated LND API Object>
logger: <Winston Logger Object>
}
@Returns
{
[total_failed_payments_found]: <Failed Payments Found Number>
[total_failed_payments_deleted]: <Failed Payments Deleted Number>
}
*/
*/

try {
const url = 'http://localhost:8055/api/clean-failed-payments';

const postBody = {
is_dry_run: false,
};

const config = {
headers: { Authorization: `Bearer ${accessToken}` },
};

const response = await axios.post(url, postBody, config);
} catch (error) {
console.error(error);
}
```

<br></br>

### Closed

```javascript
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@
"@mui/icons-material": "^5.10.14",
"@mui/material": "^5.10.14",
"@mui/x-date-pickers": "^5.0.8",
"@nestjs/common": "^9.2.0",
"@nestjs/common": "^9.2.1",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.2.0",
"@nestjs/core": "^9.2.1",
"@nestjs/jwt": "^9.0.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.2.0",
"@nestjs/platform-socket.io": "^9.2.0",
"@nestjs/platform-express": "^9.2.1",
"@nestjs/platform-socket.io": "^9.2.1",
"@nestjs/schedule": "^2.1.0",
"@nestjs/websockets": "^9.2.0",
"@nestjs/websockets": "^9.2.1",
"antd": "^4.23.4",
"async": "^3.2.4",
"axios": "^0.27.2",
"balanceofsatoshis": "^13.10.4",
"balanceofsatoshis": "^13.10.7",
"bcryptjs": "^2.4.3",
"chart.js": "^4.0.1",
"chart.js": "^4.1.1",
"class-sanitizer": "^1.0.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"class-validator": "^0.14.0",
"json-to-pretty-yaml": "^1.2.2",
"jwt-decode": "^3.1.2",
"lightning": "^6.3.2",
"lightning": "^6.8.0",
"nest-winston": "^1.8.0",
"next": "^12.3.1",
"nookies": "^2.5.2",
Expand All @@ -72,24 +72,24 @@
"passport-local": "^1.0.0",
"qrcode.react": "^3.1.0",
"react": "^18.2.0",
"react-chartjs-2": "^5.0.1",
"react-chartjs-2": "^5.1.0",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.2.0",
"react-js-cron": "^2.1.2",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.5.7",
"socket.io-client": "^4.5.3"
"rxjs": "^7.8.0",
"socket.io-client": "^4.5.4"
},
"devDependencies": {
"@mapbox/node-pre-gyp": "^1.0.10",
"@nestjs/cli": "^9.1.5",
"@nestjs/schematics": "^9.0.3",
"@next/eslint-plugin-next": "^13.0.4",
"@playwright/test": "^1.28.0",
"@types/async": "^3.2.15",
"@playwright/test": "^1.29.0",
"@types/async": "^3.2.16",
"@types/cron": "^2.0.0",
"@types/express": "^4.17.14",
"@types/node": "^18.11.9",
"@types/express": "^4.17.15",
"@types/node": "^18.11.17",
"@types/passport-local": "^1.0.34",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
Expand All @@ -111,6 +111,6 @@
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"typescript": "^4.9.3"
"typescript": "^4.9.4"
}
}
10 changes: 10 additions & 0 deletions src/client/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ const commands: Commands = [
start: 'Start',
},
},
{
name: 'Clean Failed Payments',
value: 'CleanFailedPayments',
description: 'Clean out past failed payment data.',
longDescription:
'Clean out past failed payment data. Remove old failed payment data for probes and other failed payments. (This command might take a long time to run).',
flags: {
dryrun: 'Dryrun',
},
},
{
name: 'Closed',
value: 'Closed',
Expand Down
44 changes: 44 additions & 0 deletions src/client/output/CleanFailedPaymentsOutput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';

/*
Renders the output of the CleanFailedPayments command.
*/

const styles = {
div: {
marginTop: '50px',
marginLeft: '10px',
},
text: {
fontSize: '15px',
fontWeight: 'bold',
display: 'inline-block',
},
};

type Data = {
data: {
total_failed_payments_deleted?: number;
total_failed_payments_found?: number;
};
};

const CleanFailedPaymentsOutput = ({ data }: Data) => {
return (
<div style={styles.div}>
{data.total_failed_payments_deleted === undefined && data.total_failed_payments_found === undefined ? (
<h3>{'No Failed Payments Found/Deleted'}</h3>
) : null}

{data.total_failed_payments_deleted !== undefined ? (
<h3 id="paymentsdeleted">{`Total Failed Payments Deleted: ${data.total_failed_payments_deleted}`}</h3>
) : null}

{data.total_failed_payments_found !== undefined ? (
<h3 id="paymentsfound">{`Total Failed Payments Found: ${data.total_failed_payments_found}`}</h3>
) : null}
</div>
);
};

export default CleanFailedPaymentsOutput;
2 changes: 2 additions & 0 deletions src/client/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ChartChainFeesOutput from './ChartChainFeesOutput';
import ChartFeesEarnedOutput from './ChartFeesEarnedOutput';
import ChartFeesPaidOutput from './ChartFeesPaidOutput';
import ChartPaymentsReceivedOutput from './ChartPaymentsReceivedOutput';
import CleanFailedPaymentsOutput from './CleanFailedPaymentsOutput';
import ClosedOutput from './ClosedOutput';
import CreateGroupChannelOutput from './CreateGroupChannelOutput';
import FeesOutput from './FeesOutput';
Expand All @@ -29,6 +30,7 @@ export {
ChartFeesEarnedOutput,
ChartFeesPaidOutput,
ChartPaymentsReceivedOutput,
CleanFailedPaymentsOutput,
ClosedOutput,
CreateGroupChannelOutput,
FeesOutput,
Expand Down
106 changes: 106 additions & 0 deletions src/client/pages/commands/CleanFailedPayments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import * as types from '~shared/types';

import { CssBaseline, FormControlLabel, Stack, TextField } from '@mui/material';
import React, { useState } from 'react';
import {
StandardHomeButtonLink,
StandardSwitch,
StartFlexBox,
SubmitButton,
} from '~client/standard_components/app-components';
import commands, { globalCommands } from '../../commands';

import { CleanFailedPaymentsOutput } from '~client/output';
import Head from 'next/head';
import { axiosPostWithAlert } from '~client/utils/axios';

const CleanFailedPaymentsCommand = commands.find(n => n.value === 'CleanFailedPayments');

/*
Renders the bos clean-failed-payments command
GET call to the NestJs process to get failed payments found or deleted
*/

const CleanFailedPayments = () => {
const [data, setData] = useState(undefined);
const [dryRun, setDryRun] = useState(false);
const [node, setNode] = useState('');

const handleDryRunChange = () => {
setDryRun(previousValue => !previousValue);
};

const handleNodeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setNode(event.target.value);
};

const fetchData = async () => {
const postBody: types.commandCleanFailedPayments = {
node,
is_dry_run: dryRun,
};

const { result } = await axiosPostWithAlert({ path: 'clean-failed-payments', postBody });

if (!!result) {
setData(result);
}
};

return (
<CssBaseline>
<Head>
<title>Clean Failed Payments</title>
</Head>
<StartFlexBox>
<StandardHomeButtonLink />
<Stack spacing={3} style={styles.form}>
<h2>{CleanFailedPaymentsCommand.name}</h2>
<h4 style={styles.h4}>{CleanFailedPaymentsCommand.longDescription}</h4>
<FormControlLabel
style={styles.switch}
control={
<StandardSwitch
checked={dryRun}
onChange={handleDryRunChange}
id={CleanFailedPaymentsCommand.flags.dryrun}
/>
}
label={CleanFailedPaymentsCommand.flags.dryrun}
/>
<TextField
type="text"
placeholder={globalCommands.node.name}
label={globalCommands.node.name}
id={globalCommands.node.value}
onChange={handleNodeChange}
style={styles.textField}
/>
<SubmitButton variant="contained" onClick={fetchData}>
Run Command
</SubmitButton>
{!!data ? <CleanFailedPaymentsOutput data={data} /> : null}
</Stack>
</StartFlexBox>
</CssBaseline>
);
};

export default CleanFailedPayments;

const styles = {
form: {
marginLeft: '50px',
marginTop: '100px',
width: '700px',
},
h4: {
marginTop: '0px',
},
switch: {
width: '100px',
},
textField: {
width: '500px',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { cleanFailedPayments } from 'balanceofsatoshis/wallets';

/** Clean out failed payments from the wallet
{
is_dry_run: <Avoid Actually Deleting Payments>
lnd: <Authenticated LND API Object>
logger: <Winston Logger Object>
}
@returns via Promise
{
[total_failed_payments_found]: <Failed Payments Found Number>
[total_failed_payments_deleted]: <Failed Payments Deleted Number>
}
*/

const cleanFailedPaymentsCommand = async ({ args, lnd, logger }) => {
const result = await cleanFailedPayments({
lnd,
logger,
is_dry_run: args.is_dry_run,
});

return { result };
};

export default cleanFailedPaymentsCommand;
2 changes: 2 additions & 0 deletions src/server/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import chartChainFeesCommand from './chartChainFees/chart_chain_fees_command';
import chartFeesEarnedCommand from './chartFeesEarned/chart_fees_earned_command';
import chartFeesPaidCommand from './chartFeesPaid/chart_fees_paid_command';
import chartPaymentsReceivedCommand from './chartPaymentsReceived/chart_payments_received_command';
import cleanFailedPaymentsCommand from './cleanFailedPayments/clean_failed_payments_command';
import closedCommand from './closed/closed_command';
import createChannelGroupCommand from './createChannelGroup/create_channel_group_command';
import feesCommand from './fees/fees_command';
Expand Down Expand Up @@ -38,6 +39,7 @@ export {
chartFeesEarnedCommand,
chartFeesPaidCommand,
chartPaymentsReceivedCommand,
cleanFailedPaymentsCommand,
closedCommand,
createChannelGroupCommand,
feesCommand,
Expand Down
5 changes: 5 additions & 0 deletions src/server/modules/commands/commands.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export class CommandsController {
return this.commandsService.chartPaymentsReceivedCommand(args);
}

@Post('clean-failed-payments')
async cleanFailedPaymentsCommand(@Body() args: dto.cleanFailedPaymentsDto) {
return this.commandsService.cleanFailedPaymentsCommand(args);
}

@Get('closed')
async closedCommand(@Query() args: dto.closedDto) {
return this.commandsService.closedCommand(args);
Expand Down
Loading

0 comments on commit 983d87d

Please sign in to comment.