This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from niteshbalusu11:niteshbalusu11/issue115
Add support for bos fees command
- Loading branch information
Showing
16 changed files
with
502 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { StandardTableOutput } from '~client/standard_components/app-components'; | ||
|
||
// Renders the output of the bos fees command | ||
|
||
type Props = { | ||
data: { | ||
rows: string[][]; | ||
}; | ||
}; | ||
|
||
const FeesOutput = ({ data }: Props) => { | ||
return ( | ||
<div style={{ marginTop: '30px' }}> | ||
{!!data ? <StandardTableOutput data={data} tableId="feesOutput" /> : <h2>No Output to display</h2>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default FeesOutput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import * as types from '~shared/types'; | ||
|
||
import { Button, CssBaseline, IconButton, Stack, TextField } from '@mui/material'; | ||
import React, { useState } from 'react'; | ||
import { StandardHomeButtonLink, StartFlexBox, SubmitButton } from '~client/standard_components/app-components'; | ||
import commands, { globalCommands } from '../../commands'; | ||
|
||
import DeleteIcon from '@mui/icons-material/Delete'; | ||
import { FeesOutput } from '~client/output'; | ||
import Head from 'next/head'; | ||
import { axiosPostWithAlert } from '~client/utils/axios'; | ||
|
||
const FeesCommand = commands.find(n => n.value === 'Fees'); | ||
|
||
/* | ||
Renders the bos fees command | ||
POST call to the NestJs process to get fees information | ||
*/ | ||
|
||
const styles = { | ||
form: { | ||
marginLeft: '50px', | ||
marginTop: '100px', | ||
width: '800px', | ||
}, | ||
textField: { | ||
width: '500px', | ||
marginTop: '10px', | ||
}, | ||
h4: { | ||
marginTop: '0px', | ||
}, | ||
button: { | ||
color: 'white', | ||
fontWeight: 'bold', | ||
borderRadius: '10px', | ||
border: '1px solid black', | ||
marginTop: '20px', | ||
width: '50px', | ||
}, | ||
iconButton: { | ||
width: '50px', | ||
marginTop: '0px', | ||
}, | ||
}; | ||
|
||
const Fees = () => { | ||
const [cltvDelta, setCltvDelta] = useState(undefined); | ||
const [data, setData] = useState(undefined); | ||
const [feeRate, setFeeRate] = useState(undefined); | ||
const [formValues, setFormValues] = useState([{ node: '' }]); | ||
const [node, setNode] = useState(undefined); | ||
|
||
const handeNodeChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setNode(event.target.value); | ||
}; | ||
|
||
const handleFeeRateChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setFeeRate(event.target.value); | ||
}; | ||
|
||
const handleCltvDeltaChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setCltvDelta(event.target.value); | ||
}; | ||
|
||
// ============================================================================ | ||
const removeFormFields = (i: number) => { | ||
const newFormValues = [...formValues]; | ||
newFormValues.splice(i, 1); | ||
setFormValues(newFormValues); | ||
}; | ||
|
||
const addFormFields = () => { | ||
setFormValues([...formValues, { node: '' }]); | ||
}; | ||
|
||
const handleChange = (i: number, e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { | ||
const newFormValues = [...formValues]; | ||
newFormValues[i][e.target.name] = e.target.value; | ||
setFormValues(newFormValues); | ||
}; | ||
|
||
// ============================================================================ | ||
|
||
const fetchData = async () => { | ||
const query: types.commandFees = { | ||
node, | ||
cltv_delta: Number(cltvDelta), | ||
fee_rate: feeRate, | ||
to: formValues.map(n => n.node), | ||
}; | ||
|
||
const result = await axiosPostWithAlert({ path: 'fees', postBody: query }); | ||
|
||
if (!!result) { | ||
setData(result); | ||
} | ||
}; | ||
|
||
return ( | ||
<CssBaseline> | ||
<Head> | ||
<title>Fees</title> | ||
</Head> | ||
<StartFlexBox> | ||
<StandardHomeButtonLink /> | ||
|
||
<Stack style={styles.form}> | ||
<h2>{FeesCommand.name}</h2> | ||
<h4 style={styles.h4}>{FeesCommand.longDescription}</h4> | ||
|
||
<TextField | ||
type="text" | ||
placeholder="Fee Rate (Optional)" | ||
label={FeesCommand.flags.set_fee_rate} | ||
id={FeesCommand.flags.set_fee_rate} | ||
onChange={handleFeeRateChange} | ||
style={styles.textField} | ||
/> | ||
|
||
<TextField | ||
type="text" | ||
placeholder="Cltv Delta (Optional)" | ||
label={FeesCommand.flags.set_cltv_delta} | ||
id={FeesCommand.flags.set_cltv_delta} | ||
onChange={handleCltvDeltaChange} | ||
style={styles.textField} | ||
/> | ||
|
||
<> | ||
<Button href="#text-buttons" onClick={() => addFormFields()} style={styles.button}> | ||
Add + | ||
</Button> | ||
{formValues.map((element, index) => ( | ||
<div key={index}> | ||
<TextField | ||
type="text" | ||
label="To" | ||
name="node" | ||
placeholder="Peer key/alias/tag to set fees" | ||
value={element.node || ''} | ||
onChange={e => handleChange(index, e)} | ||
style={styles.textField} | ||
id={`key-${index}`} | ||
/> | ||
{!!index ? ( | ||
<IconButton aria-label="delete" onClick={() => removeFormFields(index)} style={styles.iconButton}> | ||
<DeleteIcon /> | ||
</IconButton> | ||
) : null} | ||
</div> | ||
))} | ||
</> | ||
|
||
<TextField | ||
type="text" | ||
placeholder={globalCommands.node.name} | ||
label={globalCommands.node.name} | ||
id={globalCommands.node.value} | ||
onChange={handeNodeChange} | ||
style={styles.textField} | ||
/> | ||
|
||
<SubmitButton onClick={fetchData}>Run Command</SubmitButton> | ||
{!!data ? <FeesOutput data={data.result}></FeesOutput> : null} | ||
</Stack> | ||
</StartFlexBox> | ||
</CssBaseline> | ||
); | ||
}; | ||
|
||
export default Fees; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as types from '~shared/types'; | ||
|
||
import { AuthenticatedLnd } from 'lightning'; | ||
import { Logger } from 'winston'; | ||
import { adjustFees } from 'balanceofsatoshis/routing'; | ||
import { readFile } from 'fs'; | ||
|
||
/** View and adjust routing fees | ||
{ | ||
[cltv_delta]: <Set CLTV Delta Number> | ||
[fee_rate]: <Fee Rate String> | ||
lnd: <Authenticated LND API Object> | ||
logger: <Winstone Logger Object> | ||
to: [<Adjust Routing Fee To Peer Alias or Public Key or Tag String>] | ||
} | ||
@returns via cbk or Promise | ||
{ | ||
rows: [[<Table Cell String>]] | ||
} | ||
*/ | ||
type Args = { | ||
args: types.commandFees; | ||
lnd: AuthenticatedLnd; | ||
logger: Logger; | ||
}; | ||
const feesCommand = async ({ args, lnd, logger }: Args) => { | ||
const toArray = !!args.to ? args.to.filter((n: string) => !!n) : []; | ||
|
||
const result = await adjustFees({ | ||
lnd, | ||
logger, | ||
cltv_delta: args.cltv_delta || undefined, | ||
fee_rate: args.fee_rate, | ||
fs: { getFile: readFile }, | ||
to: toArray, | ||
}); | ||
|
||
return { result }; | ||
}; | ||
|
||
export default feesCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Body, Controller, Post } from '@nestjs/common'; | ||
import { feesDto } from '~shared/commands.dto'; | ||
import { FeesService } from './fees.service'; | ||
|
||
// Fees controller: Defines routes for fees command | ||
|
||
@Controller() | ||
export class FeesController { | ||
constructor(private feeService: FeesService) {} | ||
|
||
@Post('api/fees') | ||
async fees(@Body() args: feesDto) { | ||
return this.feeService.feesCommand(args); | ||
} | ||
} |
Oops, something went wrong.