mirror of
https://github.com/alexbosworth/balanceofsatoshis.git
synced 2026-08-13 12:33:37 +02:00
add sorting to forwards command
This commit is contained in:
parent
83f4ccd6c6
commit
5a12d67e50
5 changed files with 50 additions and 4 deletions
|
|
@ -1,5 +1,9 @@
|
|||
# Versions
|
||||
|
||||
## 11.31.0
|
||||
|
||||
- `forwards`: Add `--sort` option to sort forwarding peers
|
||||
|
||||
## 11.30.0
|
||||
|
||||
- `telegram`: Add support for setting the description of a created trade-secret
|
||||
|
|
|
|||
3
bos
3
bos
|
|
@ -627,12 +627,14 @@ prog
|
|||
// Get forwards
|
||||
.command('forwards', 'Show recent forwarding earnings')
|
||||
.help('Peers where routing has taken place from inbound and outbound sides')
|
||||
.help('Sorts: earned_in/earned_out/earned_total/inbound/liquidity/outbound')
|
||||
.option('--complete', 'Show complete set of records in non table view')
|
||||
.option('--days <days>', 'Number of past days to evaluate', INT)
|
||||
.option('--in <from>', 'Forwards that originated from a specific peer')
|
||||
.option('--no-color', 'Mute all colors')
|
||||
.option('--node <node_name>', 'Node to get forwards for')
|
||||
.option('--out <to>', 'Forwards that sent out to a specified peer')
|
||||
.option('--sort <type>', 'Sort forward-active peers by earnings/liquidity')
|
||||
.action((args, options, logger) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
|
|
@ -646,6 +648,7 @@ prog
|
|||
fs: {getFile: readFile},
|
||||
is_monochrome: !!options.noColor,
|
||||
is_table: !options.complete,
|
||||
sort: options.sort || undefined,
|
||||
to: (await lnSync.findKey({lnd, query: options.out})).public_key,
|
||||
},
|
||||
responses.returnObject({logger, reject, resolve, table}));
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ const {now} = Date;
|
|||
const numDays = 1;
|
||||
const {parse} = Date;
|
||||
const sort = (a, b) => a > b ? 1 : ((b > a) ? -1 : 0);
|
||||
const sortsForEarning = ['earned_in', 'earned_out', 'earned_total'];
|
||||
const sortsForCapital = ['inbound', 'liquidity', 'outbound'];
|
||||
const tokensAsBigTokens = tokens => !!tokens ? (tokens / 1e8).toFixed(8) : '';
|
||||
const uniq = arr => Array.from(new Set(arr));
|
||||
const wideSizeCols = 155;
|
||||
|
|
@ -41,7 +43,8 @@ const wideSizeCols = 155;
|
|||
}
|
||||
[is_monochrome]: <Mute Colors Bool>
|
||||
[is_table]: <Return Results As Table Bool>
|
||||
lnd: <Authenticated LND gRPC API Object>
|
||||
lnd: <Authenticated LND API Object>
|
||||
[sort]: <Sort By Field String>
|
||||
}
|
||||
|
||||
@returns via cbk or Promise
|
||||
|
|
@ -71,6 +74,12 @@ module.exports = (args, cbk) => {
|
|||
return cbk([400, 'ExpectedLndToGetForwardingInformation']);
|
||||
}
|
||||
|
||||
const sorts = [].concat(sortsForCapital).concat(sortsForEarning);
|
||||
|
||||
if (!!args.sort && !sorts.includes(args.sort)) {
|
||||
return cbk([400, 'ExpectedKnownSortToSortForwards', {sorts}]);
|
||||
}
|
||||
|
||||
return cbk();
|
||||
},
|
||||
|
||||
|
|
@ -256,6 +265,36 @@ module.exports = (args, cbk) => {
|
|||
|
||||
const sorted = peers
|
||||
.sort((a, b) => {
|
||||
if (args.sort === 'earned_in') {
|
||||
return a.earned_inbound_fees - b.earned_inbound_fees;
|
||||
}
|
||||
|
||||
if (args.sort === 'earned_out') {
|
||||
return a.earned_inbound_fees - b.earned_outbound_fees;
|
||||
}
|
||||
|
||||
if (args.sort === 'earned_total') {
|
||||
const aTotal = a.earned_inbound_fees + a.earned_outbound_fees;
|
||||
const bTotal = b.earned_inbound_fees + b.earned_outbound_fees;
|
||||
|
||||
return aTotal - bTotal;
|
||||
}
|
||||
|
||||
if (args.sort === 'inbound') {
|
||||
return a.liquidity_inbound - b.liquidity_inbound;
|
||||
}
|
||||
|
||||
if (args.sort === 'liquidity') {
|
||||
const aTotal = a.liquidity_inbound + a.liquidity_outbound;
|
||||
const bTotal = b.liquidity_inbound + b.liquidity_outbound;
|
||||
|
||||
return aTotal - bTotal;
|
||||
}
|
||||
|
||||
if (args.sort === 'outbound') {
|
||||
return a.liquidity_outbound - b.liquidity_outbound;
|
||||
}
|
||||
|
||||
const aEvents = [a.last_outbound_at, a.last_inbound_at];
|
||||
const bEvents = [b.last_outbound_at, b.last_inbound_at];
|
||||
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "balanceofsatoshis",
|
||||
"version": "11.30.0",
|
||||
"version": "11.31.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "balanceofsatoshis",
|
||||
"version": "11.30.0",
|
||||
"version": "11.31.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@alexbosworth/caporal": "1.4.0",
|
||||
|
|
|
|||
|
|
@ -80,5 +80,5 @@
|
|||
"postpublish": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t alexbosworth/balanceofsatoshis --push .",
|
||||
"test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/arrays/*.js test/balances/*.js test/chain/*.js test/display/*.js test/encryption/*.js test/lnd/*.js test/network/*.js test/nodes/*.js test/peers/*.js test/responses/*.js test/routing/*.js test/services/*.js test/swaps/*.js test/tags/*.js test/wallets/*.js"
|
||||
},
|
||||
"version": "11.30.0"
|
||||
"version": "11.31.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue