lightning 6.4.1 → 6.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -0
- package/grpc/grpc_services.json +3 -0
- package/grpc/protos/chainkit.proto +59 -0
- package/grpc/protos/lightning.proto +20 -1
- package/index.js +2 -0
- package/lnd_methods/index.js +2 -0
- package/lnd_methods/invoices/get_invoices.d.ts +2 -1
- package/lnd_methods/invoices/get_invoices.js +17 -6
- package/lnd_methods/macaroon/methods.json +4 -0
- package/lnd_methods/macaroon/subscribe_to_rpc_requests.d.ts +4 -0
- package/lnd_methods/offchain/get_failed_payments.d.ts +4 -1
- package/lnd_methods/offchain/get_failed_payments.js +18 -82
- package/lnd_methods/offchain/get_payment.d.ts +2 -2
- package/lnd_methods/offchain/get_payments.d.ts +4 -1
- package/lnd_methods/offchain/get_payments.js +17 -81
- package/lnd_methods/offchain/get_pending_payments.d.ts +4 -1
- package/lnd_methods/offchain/get_pending_payments.js +18 -82
- package/lnd_methods/offchain/list_payments.js +218 -0
- package/lnd_methods/onchain/get_block.js +78 -0
- package/lnd_methods/onchain/index.js +2 -0
- package/package.json +4 -4
- package/test/lnd_grpc/test_authenticated_lnd_grpc.js +1 -0
- package/test/lnd_methods/invoices/test_get_invoices.js +18 -1
- package/test/lnd_methods/offchain/test_get_failed_payments.js +5 -5
- package/test/lnd_methods/offchain/test_get_payments.js +9 -0
- package/test/lnd_methods/offchain/test_get_pending_payments.js +5 -5
- package/test/lnd_methods/offchain/test_list_payments.js +45 -0
- package/test/lnd_methods/onchain/test_get_block.js +92 -0
- package/typescript/shared.d.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
+
## 6.6.0
|
|
4
|
+
|
|
5
|
+
- `getBlock`: Add method to get a raw block from the chain
|
|
6
|
+
|
|
7
|
+
## 6.5.0
|
|
8
|
+
|
|
9
|
+
- `getFailedPayments`, `getInvoices`, `getPayments`, `getPendingPayments`: add
|
|
10
|
+
support for date based filtering with `created_after` and `created_before`
|
|
11
|
+
arguments
|
|
12
|
+
|
|
3
13
|
## 6.4.1
|
|
4
14
|
|
|
5
15
|
- `subscribeToRpcRequests`: `open_channel_request` add support for
|
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ variables set:
|
|
|
139
139
|
specific channel.
|
|
140
140
|
- [getBackups](https://github.com/alexbosworth/ln-service#getbackups): Get recovery details for
|
|
141
141
|
all channels.
|
|
142
|
+
- [getBlock](https://github.com/alexbosworth/ln-service#getblock): Get a block
|
|
142
143
|
- [getChainBalance](https://github.com/alexbosworth/ln-service#getchainbalance): Get the amount
|
|
143
144
|
of on-chain funds.
|
|
144
145
|
- [getChainFeeEstimate](https://github.com/alexbosworth/ln-service#getchainfeeestimate):
|
package/grpc/grpc_services.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"maxReceiveMessageLength": 924288000,
|
|
5
5
|
"packageTypes": {
|
|
6
6
|
"Autopilot": "autopilotrpc",
|
|
7
|
+
"ChainKit": "chainrpc",
|
|
7
8
|
"ChainNotifier": "chainrpc",
|
|
8
9
|
"Invoices": "invoicesrpc",
|
|
9
10
|
"Lightning": "lnrpc",
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
},
|
|
20
21
|
"protoFiles": {
|
|
21
22
|
"Autopilot": "autopilot.proto",
|
|
23
|
+
"ChainKit": "chainkit.proto",
|
|
22
24
|
"ChainNotifier": "chainnotifier.proto",
|
|
23
25
|
"Invoices": "invoices.proto",
|
|
24
26
|
"Lightning": "lightning.proto",
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
"protosDir": "../grpc/protos",
|
|
36
38
|
"serviceTypes": {
|
|
37
39
|
"autopilot": "Autopilot",
|
|
40
|
+
"blocks": "ChainKit",
|
|
38
41
|
"chain": "ChainNotifier",
|
|
39
42
|
"default": "Lightning",
|
|
40
43
|
"invoices": "Invoices",
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package chainrpc;
|
|
4
|
+
|
|
5
|
+
option go_package = "github.com/lightningnetwork/lnd/lnrpc/chainrpc";
|
|
6
|
+
|
|
7
|
+
// ChainKit is a service that can be used to get information from the
|
|
8
|
+
// chain backend.
|
|
9
|
+
service ChainKit {
|
|
10
|
+
/* lncli: `chain getblock`
|
|
11
|
+
GetBlock returns a block given the corresponding block hash.
|
|
12
|
+
*/
|
|
13
|
+
rpc GetBlock (GetBlockRequest) returns (GetBlockResponse);
|
|
14
|
+
|
|
15
|
+
/* lncli: `chain getbestblock`
|
|
16
|
+
GetBestBlock returns the block hash and current height from the valid
|
|
17
|
+
most-work chain.
|
|
18
|
+
*/
|
|
19
|
+
rpc GetBestBlock (GetBestBlockRequest) returns (GetBestBlockResponse);
|
|
20
|
+
|
|
21
|
+
/* lncli: `chain getblockhash`
|
|
22
|
+
GetBlockHash returns the hash of the block in the best blockchain
|
|
23
|
+
at the given height.
|
|
24
|
+
*/
|
|
25
|
+
rpc GetBlockHash (GetBlockHashRequest) returns (GetBlockHashResponse);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
message GetBlockRequest {
|
|
29
|
+
// The hash of the requested block.
|
|
30
|
+
bytes block_hash = 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// TODO(ffranr): The neutrino GetBlock response includes many
|
|
34
|
+
// additional helpful fields. Consider adding them here also.
|
|
35
|
+
message GetBlockResponse {
|
|
36
|
+
// The raw bytes of the requested block.
|
|
37
|
+
bytes raw_block = 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
message GetBestBlockRequest {
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
message GetBestBlockResponse {
|
|
44
|
+
// The hash of the best block.
|
|
45
|
+
bytes block_hash = 1;
|
|
46
|
+
|
|
47
|
+
// The height of the best block.
|
|
48
|
+
int32 block_height = 2;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
message GetBlockHashRequest {
|
|
52
|
+
// Block height of the target best chain block.
|
|
53
|
+
int64 block_height = 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
message GetBlockHashResponse {
|
|
57
|
+
// The hash of the best block at the specified height.
|
|
58
|
+
bytes block_hash = 1;
|
|
59
|
+
}
|
|
@@ -3351,7 +3351,7 @@ message Invoice {
|
|
|
3351
3351
|
int64 value_msat = 23;
|
|
3352
3352
|
|
|
3353
3353
|
/*
|
|
3354
|
-
Whether this invoice has been fulfilled
|
|
3354
|
+
Whether this invoice has been fulfilled.
|
|
3355
3355
|
|
|
3356
3356
|
The field is deprecated. Use the state field instead (compare to SETTLED).
|
|
3357
3357
|
*/
|
|
@@ -3359,12 +3359,14 @@ message Invoice {
|
|
|
3359
3359
|
|
|
3360
3360
|
/*
|
|
3361
3361
|
When this invoice was created.
|
|
3362
|
+
Measured in seconds since the unix epoch.
|
|
3362
3363
|
Note: Output only, don't specify for creating an invoice.
|
|
3363
3364
|
*/
|
|
3364
3365
|
int64 creation_date = 7;
|
|
3365
3366
|
|
|
3366
3367
|
/*
|
|
3367
3368
|
When this invoice was settled.
|
|
3369
|
+
Measured in seconds since the unix epoch.
|
|
3368
3370
|
Note: Output only, don't specify for creating an invoice.
|
|
3369
3371
|
*/
|
|
3370
3372
|
int64 settle_date = 8;
|
|
@@ -3631,7 +3633,16 @@ message ListInvoiceRequest {
|
|
|
3631
3633
|
specified index offset. This can be used to paginate backwards.
|
|
3632
3634
|
*/
|
|
3633
3635
|
bool reversed = 6;
|
|
3636
|
+
|
|
3637
|
+
// If set, returns all invoices with a creation date greater than or equal
|
|
3638
|
+
// to it. Measured in seconds since the unix epoch.
|
|
3639
|
+
uint64 creation_date_start = 7;
|
|
3640
|
+
|
|
3641
|
+
// If set, returns all invoices with a creation date less than or equal to
|
|
3642
|
+
// it. Measured in seconds since the unix epoch.
|
|
3643
|
+
uint64 creation_date_end = 8;
|
|
3634
3644
|
}
|
|
3645
|
+
|
|
3635
3646
|
message ListInvoiceResponse {
|
|
3636
3647
|
/*
|
|
3637
3648
|
A list of invoices from the time slice of the time series specified in the
|
|
@@ -3830,6 +3841,14 @@ message ListPaymentsRequest {
|
|
|
3830
3841
|
of payments, as all of them have to be iterated through to be counted.
|
|
3831
3842
|
*/
|
|
3832
3843
|
bool count_total_payments = 5;
|
|
3844
|
+
|
|
3845
|
+
// If set, returns all invoices with a creation date greater than or equal
|
|
3846
|
+
// to it. Measured in seconds since the unix epoch.
|
|
3847
|
+
uint64 creation_date_start = 6;
|
|
3848
|
+
|
|
3849
|
+
// If set, returns all invoices with a creation date less than or equal to
|
|
3850
|
+
// it. Measured in seconds since the unix epoch.
|
|
3851
|
+
uint64 creation_date_end = 7;
|
|
3833
3852
|
}
|
|
3834
3853
|
|
|
3835
3854
|
message ListPaymentsResponse {
|
package/index.js
CHANGED
|
@@ -32,6 +32,7 @@ const {getAccessIds} = require('./lnd_methods');
|
|
|
32
32
|
const {getAutopilot} = require('./lnd_methods');
|
|
33
33
|
const {getBackup} = require('./lnd_methods');
|
|
34
34
|
const {getBackups} = require('./lnd_methods');
|
|
35
|
+
const {getBlock} = require('./lnd_methods');
|
|
35
36
|
const {getChainBalance} = require('./lnd_methods');
|
|
36
37
|
const {getChainFeeEstimate} = require('./lnd_methods');
|
|
37
38
|
const {getChainFeeRate} = require('./lnd_methods');
|
|
@@ -182,6 +183,7 @@ module.exports = {
|
|
|
182
183
|
getAutopilot,
|
|
183
184
|
getBackup,
|
|
184
185
|
getBackups,
|
|
186
|
+
getBlock,
|
|
185
187
|
getChainBalance,
|
|
186
188
|
getChainFeeEstimate,
|
|
187
189
|
getChainFeeRate,
|
package/lnd_methods/index.js
CHANGED
|
@@ -30,6 +30,7 @@ const {getAccessIds} = require('./macaroon');
|
|
|
30
30
|
const {getAutopilot} = require('./info');
|
|
31
31
|
const {getBackup} = require('./offchain');
|
|
32
32
|
const {getBackups} = require('./offchain');
|
|
33
|
+
const {getBlock} = require('./onchain');
|
|
33
34
|
const {getChainBalance} = require('./onchain');
|
|
34
35
|
const {getChainFeeEstimate} = require('./onchain');
|
|
35
36
|
const {getChainFeeRate} = require('./onchain');
|
|
@@ -176,6 +177,7 @@ module.exports = {
|
|
|
176
177
|
getAutopilot,
|
|
177
178
|
getBackup,
|
|
178
179
|
getBackups,
|
|
180
|
+
getBlock,
|
|
179
181
|
getChainBalance,
|
|
180
182
|
getChainFeeEstimate,
|
|
181
183
|
getChainFeeRate,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticatedLightningArgs,
|
|
3
3
|
AuthenticatedLightningMethod,
|
|
4
|
+
DateRangeFilterArgs,
|
|
4
5
|
PaginationArgs,
|
|
5
6
|
} from '../../typescript';
|
|
6
7
|
|
|
@@ -8,7 +9,7 @@ export type GetInvoicesArgs = AuthenticatedLightningArgs<
|
|
|
8
9
|
PaginationArgs & {
|
|
9
10
|
/** Omit Canceled and Settled Invoices Bool */
|
|
10
11
|
is_unconfirmed?: boolean;
|
|
11
|
-
}
|
|
12
|
+
} & DateRangeFilterArgs
|
|
12
13
|
>;
|
|
13
14
|
|
|
14
15
|
export type GetInvoicesResult = {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const {createHash} = require('crypto');
|
|
2
|
-
|
|
3
1
|
const asyncAuto = require('async/auto');
|
|
4
2
|
const asyncRetry = require('async/retry');
|
|
5
3
|
const {returnResult} = require('asyncjs-util');
|
|
@@ -9,6 +7,8 @@ const {isLnd} = require('./../../lnd_requests');
|
|
|
9
7
|
const {rpcInvoiceAsInvoice} = require('./../../lnd_responses');
|
|
10
8
|
const {sortBy} = require('./../../arrays');
|
|
11
9
|
|
|
10
|
+
const asStart = n => !!n ? Math.floor(new Date(n).getTime() / 1e3) : undefined;
|
|
11
|
+
const asEnd = n => !!n ? Math.ceil(new Date(n).getTime() / 1e3) : undefined;
|
|
12
12
|
const createdAtSort = array => sortBy({array, attribute: 'created_at'});
|
|
13
13
|
const defaultLimit = 100;
|
|
14
14
|
const {isArray} = Array;
|
|
@@ -27,7 +27,12 @@ const type = 'default';
|
|
|
27
27
|
|
|
28
28
|
Invoice `payment` is not supported on LND 0.11.1 and below
|
|
29
29
|
|
|
30
|
+
`created_after` is not supported on LND 0.15.5 and below
|
|
31
|
+
`created_before` is not supported on LND 0.15.5 and below
|
|
32
|
+
|
|
30
33
|
{
|
|
34
|
+
[created_after]: <Creation Date After or Equal to ISO 8601 Date String>
|
|
35
|
+
[created_before]: <Creation Date Before or Equal to ISO 8601 Date String>
|
|
31
36
|
[is_unconfirmed]: <Omit Canceled and Settled Invoices Bool>
|
|
32
37
|
[limit]: <Page Result Limit Number>
|
|
33
38
|
lnd: <Authenticated LND API Object>
|
|
@@ -106,16 +111,20 @@ module.exports = (args, cbk) => {
|
|
|
106
111
|
|
|
107
112
|
// Get the list of invoices
|
|
108
113
|
listInvoices: ['validate', ({}, cbk) => {
|
|
114
|
+
let after = asStart(args.created_after);
|
|
115
|
+
let before = asEnd(args.created_before);
|
|
116
|
+
let limit = args.limit || defaultLimit;
|
|
109
117
|
let offset;
|
|
110
|
-
let resultsLimit = args.limit || defaultLimit;
|
|
111
118
|
|
|
112
119
|
// When there is a token, parse it out into an offset and a limit
|
|
113
120
|
if (!!args.token) {
|
|
114
121
|
try {
|
|
115
122
|
const pagingToken = parse(args.token);
|
|
116
123
|
|
|
124
|
+
after = pagingToken.after;
|
|
125
|
+
before = pagingToken.before;
|
|
117
126
|
offset = pagingToken.offset;
|
|
118
|
-
|
|
127
|
+
limit = pagingToken.limit;
|
|
119
128
|
} catch (err) {
|
|
120
129
|
return cbk([400, 'ExpectedValidPagingTokenForInvoicesReq', {err}]);
|
|
121
130
|
}
|
|
@@ -123,8 +132,10 @@ module.exports = (args, cbk) => {
|
|
|
123
132
|
|
|
124
133
|
return asyncRetry({}, cbk => {
|
|
125
134
|
return args.lnd[type][method]({
|
|
135
|
+
creation_date_start: after,
|
|
136
|
+
creation_date_end: before,
|
|
126
137
|
index_offset: offset || Number(),
|
|
127
|
-
num_max_invoices:
|
|
138
|
+
num_max_invoices: limit,
|
|
128
139
|
pending_only: args.is_unconfirmed === true || undefined,
|
|
129
140
|
reversed: true,
|
|
130
141
|
},
|
|
@@ -151,7 +162,7 @@ module.exports = (args, cbk) => {
|
|
|
151
162
|
|
|
152
163
|
const offset = Number(res.first_index_offset);
|
|
153
164
|
|
|
154
|
-
const token = stringify({
|
|
165
|
+
const token = stringify({after, before, limit, offset});
|
|
155
166
|
|
|
156
167
|
return cbk(null, {
|
|
157
168
|
invoices: res.invoices,
|
|
@@ -77,6 +77,10 @@ export type SubscribeToRpcRequestsOpenChannelRequestEvent =
|
|
|
77
77
|
partner_public_key: string;
|
|
78
78
|
/** Peer Output CSV Delay Number */
|
|
79
79
|
partner_csv_delay?: number;
|
|
80
|
+
/** Routing Base Fee Millitokens Charged String */
|
|
81
|
+
base_fee_mtokens?: string;
|
|
82
|
+
/** Routing Fee Rate In Millitokens Per Million Number */
|
|
83
|
+
fee_rate?: number;
|
|
80
84
|
}>;
|
|
81
85
|
|
|
82
86
|
/** A pay to route request was intercepted: by default it will be rejected */
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticatedLightningArgs,
|
|
3
3
|
AuthenticatedLightningMethod,
|
|
4
|
+
DateRangeFilterArgs,
|
|
4
5
|
PaginationArgs,
|
|
5
6
|
} from '../../typescript';
|
|
6
7
|
|
|
7
|
-
export type GetFailedPaymentsArgs = AuthenticatedLightningArgs<
|
|
8
|
+
export type GetFailedPaymentsArgs = AuthenticatedLightningArgs<
|
|
9
|
+
PaginationArgs & DateRangeFilterArgs
|
|
10
|
+
>;
|
|
8
11
|
|
|
9
12
|
export type GetFailedPaymentsResult = {
|
|
10
13
|
payments: {
|
|
@@ -2,23 +2,21 @@ const asyncAuto = require('async/auto');
|
|
|
2
2
|
const {returnResult} = require('asyncjs-util');
|
|
3
3
|
|
|
4
4
|
const {isLnd} = require('./../../lnd_requests');
|
|
5
|
-
const
|
|
6
|
-
const {sortBy} = require('./../../arrays');
|
|
5
|
+
const listPayments = require('./list_payments');
|
|
7
6
|
|
|
8
|
-
const defaultLimit = 250;
|
|
9
|
-
const {isArray} = Array;
|
|
10
|
-
const isFailed = payment => !!payment && payment.status === 'FAILED';
|
|
11
|
-
const lastPageFirstIndexOffset = 1;
|
|
12
7
|
const method = 'listPayments';
|
|
13
|
-
const {parse} = JSON;
|
|
14
|
-
const {stringify} = JSON;
|
|
15
8
|
const type = 'default';
|
|
16
9
|
|
|
17
10
|
/** Get failed payments made through channels.
|
|
18
11
|
|
|
19
12
|
Requires `offchain:read` permission
|
|
20
13
|
|
|
14
|
+
`created_after` is not supported on LND 0.15.5 and below
|
|
15
|
+
`created_before` is not supported on LND 0.15.5 and below
|
|
16
|
+
|
|
21
17
|
{
|
|
18
|
+
[created_after]: <Creation Date After or Equal to ISO 8601 Date String>
|
|
19
|
+
[created_before]: <Creation Date Before or Equal to ISO 8601 Date String>
|
|
22
20
|
[limit]: <Page Result Limit Number>
|
|
23
21
|
lnd: <Authenticated LND API Object>
|
|
24
22
|
[token]: <Opaque Paging Token String>
|
|
@@ -96,16 +94,16 @@ const type = 'default';
|
|
|
96
94
|
[next]: <Next Opaque Paging Token String>
|
|
97
95
|
}
|
|
98
96
|
*/
|
|
99
|
-
module.exports = (
|
|
97
|
+
module.exports = (args, cbk) => {
|
|
100
98
|
return new Promise((resolve, reject) => {
|
|
101
99
|
return asyncAuto({
|
|
102
100
|
// Check arguments
|
|
103
101
|
validate: cbk => {
|
|
104
|
-
if (!!limit && !!token) {
|
|
102
|
+
if (!!args.limit && !!args.token) {
|
|
105
103
|
return cbk([400, 'ExpectedNoLimitWhenPagingPayFailuresWithToken']);
|
|
106
104
|
}
|
|
107
105
|
|
|
108
|
-
if (!isLnd({
|
|
106
|
+
if (!isLnd({method, type, lnd: args.lnd})) {
|
|
109
107
|
return cbk([400, 'ExpectedLndForGetFailedPaymentsRequest']);
|
|
110
108
|
}
|
|
111
109
|
|
|
@@ -114,79 +112,17 @@ module.exports = ({limit, lnd, token}, cbk) => {
|
|
|
114
112
|
|
|
115
113
|
// Get all payments
|
|
116
114
|
listPayments: ['validate', ({}, cbk) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
offset = pagingToken.offset;
|
|
125
|
-
resultsLimit = pagingToken.limit;
|
|
126
|
-
} catch (err) {
|
|
127
|
-
return cbk([400, 'ExpectedValidPagingTokenForGetFailed', {err}]);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return lnd[type][method]({
|
|
132
|
-
include_incomplete: true,
|
|
133
|
-
index_offset: offset || Number(),
|
|
134
|
-
max_payments: resultsLimit,
|
|
135
|
-
reversed: true,
|
|
115
|
+
return listPayments({
|
|
116
|
+
created_after: args.created_after,
|
|
117
|
+
created_before: args.created_before,
|
|
118
|
+
is_failed: true,
|
|
119
|
+
limit: args.limit,
|
|
120
|
+
lnd: args.lnd,
|
|
121
|
+
token: args.token,
|
|
136
122
|
},
|
|
137
|
-
|
|
138
|
-
if (!!err) {
|
|
139
|
-
return cbk([503, 'UnexpectedGetFailedPaymentsError', {err}]);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!res || !isArray(res.payments)) {
|
|
143
|
-
return cbk([503, 'ExpectedFailedPaymentsInListPaymentsResponse']);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (typeof res.last_index_offset !== 'string') {
|
|
147
|
-
return cbk([503, 'ExpectedLastIndexOffsetWhenRequestingFailed']);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const lastOffset = Number(res.last_index_offset);
|
|
151
|
-
const offset = Number(res.first_index_offset);
|
|
152
|
-
|
|
153
|
-
const token = stringify({offset, limit: resultsLimit});
|
|
154
|
-
|
|
155
|
-
return cbk(null, {
|
|
156
|
-
payments: res.payments.filter(isFailed),
|
|
157
|
-
token: offset <= lastPageFirstIndexOffset ? undefined : token,
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
}],
|
|
161
|
-
|
|
162
|
-
// Check and map payments
|
|
163
|
-
foundPayments: ['listPayments', ({listPayments}, cbk) => {
|
|
164
|
-
try {
|
|
165
|
-
const payments = listPayments.payments.map(rpcPaymentAsPayment);
|
|
166
|
-
|
|
167
|
-
return cbk(null, payments);
|
|
168
|
-
} catch (err) {
|
|
169
|
-
return cbk([503, err.message]);
|
|
170
|
-
}
|
|
171
|
-
}],
|
|
172
|
-
|
|
173
|
-
// Final found failed payments
|
|
174
|
-
payments: [
|
|
175
|
-
'foundPayments',
|
|
176
|
-
'listPayments',
|
|
177
|
-
({foundPayments, listPayments}, cbk) =>
|
|
178
|
-
{
|
|
179
|
-
const payments = sortBy({
|
|
180
|
-
array: foundPayments,
|
|
181
|
-
attribute: 'created_at',
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
return cbk(null, {
|
|
185
|
-
next: listPayments.token || undefined,
|
|
186
|
-
payments: payments.sorted.reverse(),
|
|
187
|
-
});
|
|
123
|
+
cbk);
|
|
188
124
|
}],
|
|
189
125
|
},
|
|
190
|
-
returnResult({reject, resolve, of: '
|
|
126
|
+
returnResult({reject, resolve, of: 'listPayments'}, cbk));
|
|
191
127
|
});
|
|
192
128
|
};
|
|
@@ -91,7 +91,7 @@ export type GetPaymentResult = {
|
|
|
91
91
|
tokens: number;
|
|
92
92
|
/** Total Millitokens Paid On All Paths */
|
|
93
93
|
total_mtokens: string;
|
|
94
|
-
}[]
|
|
94
|
+
}[];
|
|
95
95
|
/** BOLT 11 Payment Request */
|
|
96
96
|
request?: string;
|
|
97
97
|
/** Payment Forwarding Fee Rounded Up Tokens */
|
|
@@ -147,7 +147,7 @@ export type GetPaymentResult = {
|
|
|
147
147
|
tokens: number;
|
|
148
148
|
/** Total Millitokens Pending */
|
|
149
149
|
total_mtokens: string;
|
|
150
|
-
}[]
|
|
150
|
+
}[];
|
|
151
151
|
/** BOLT 11 Payment Request */
|
|
152
152
|
request?: string;
|
|
153
153
|
/** Payment Tokens Rounded Up */
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticatedLightningArgs,
|
|
3
3
|
AuthenticatedLightningMethod,
|
|
4
|
+
DateRangeFilterArgs,
|
|
4
5
|
PaginationArgs,
|
|
5
6
|
} from '../../typescript';
|
|
6
7
|
|
|
7
|
-
export type GetPaymentsArgs = AuthenticatedLightningArgs<
|
|
8
|
+
export type GetPaymentsArgs = AuthenticatedLightningArgs<
|
|
9
|
+
PaginationArgs & DateRangeFilterArgs
|
|
10
|
+
>;
|
|
8
11
|
|
|
9
12
|
export type GetPaymentsResult = {
|
|
10
13
|
payments: {
|
|
@@ -2,22 +2,21 @@ const asyncAuto = require('async/auto');
|
|
|
2
2
|
const {returnResult} = require('asyncjs-util');
|
|
3
3
|
|
|
4
4
|
const {isLnd} = require('./../../lnd_requests');
|
|
5
|
-
const
|
|
6
|
-
const {sortBy} = require('./../../arrays');
|
|
5
|
+
const listPayments = require('./list_payments');
|
|
7
6
|
|
|
8
|
-
const defaultLimit = 250;
|
|
9
|
-
const {isArray} = Array;
|
|
10
|
-
const lastPageFirstIndexOffset = 1;
|
|
11
7
|
const method = 'listPayments';
|
|
12
|
-
const {parse} = JSON;
|
|
13
|
-
const {stringify} = JSON;
|
|
14
8
|
const type = 'default';
|
|
15
9
|
|
|
16
10
|
/** Get payments made through channels.
|
|
17
11
|
|
|
18
12
|
Requires `offchain:read` permission
|
|
19
13
|
|
|
14
|
+
`created_after` is not supported on LND 0.15.5 and below
|
|
15
|
+
`created_before` is not supported on LND 0.15.5 and below
|
|
16
|
+
|
|
20
17
|
{
|
|
18
|
+
[created_after]: <Creation Date After or Equal to ISO 8601 Date String>
|
|
19
|
+
[created_before]: <Creation Date Before or Equal to ISO 8601 Date String>
|
|
21
20
|
[limit]: <Page Result Limit Number>
|
|
22
21
|
lnd: <Authenticated LND API Object>
|
|
23
22
|
[token]: <Opaque Paging Token String>
|
|
@@ -101,16 +100,16 @@ const type = 'default';
|
|
|
101
100
|
[next]: <Next Opaque Paging Token String>
|
|
102
101
|
}
|
|
103
102
|
*/
|
|
104
|
-
module.exports = (
|
|
103
|
+
module.exports = (args, cbk) => {
|
|
105
104
|
return new Promise((resolve, reject) => {
|
|
106
105
|
return asyncAuto({
|
|
107
106
|
// Check arguments
|
|
108
107
|
validate: cbk => {
|
|
109
|
-
if (!!limit && !!token) {
|
|
108
|
+
if (!!args.limit && !!args.token) {
|
|
110
109
|
return cbk([400, 'UnexpectedLimitWhenPagingPaymentsWithToken']);
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
if (!isLnd({
|
|
112
|
+
if (!isLnd({method, type, lnd: args.lnd})) {
|
|
114
113
|
return cbk([400, 'ExpectedLndForGetPaymentsRequest']);
|
|
115
114
|
}
|
|
116
115
|
|
|
@@ -119,79 +118,16 @@ module.exports = ({limit, lnd, token}, cbk) => {
|
|
|
119
118
|
|
|
120
119
|
// Get all payments
|
|
121
120
|
listPayments: ['validate', ({}, cbk) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
offset = pagingToken.offset;
|
|
130
|
-
resultsLimit = pagingToken.limit;
|
|
131
|
-
} catch (err) {
|
|
132
|
-
return cbk([400, 'ExpectedValidPagingTokenForPaymentReq', {err}]);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return lnd[type][method]({
|
|
137
|
-
include_incomplete: false,
|
|
138
|
-
index_offset: offset || Number(),
|
|
139
|
-
max_payments: resultsLimit,
|
|
140
|
-
reversed: true,
|
|
121
|
+
return listPayments({
|
|
122
|
+
created_after: args.created_after,
|
|
123
|
+
created_before: args.created_before,
|
|
124
|
+
limit: args.limit,
|
|
125
|
+
lnd: args.lnd,
|
|
126
|
+
token: args.token,
|
|
141
127
|
},
|
|
142
|
-
|
|
143
|
-
if (!!err) {
|
|
144
|
-
return cbk([503, 'UnexpectedGetPaymentsError', {err}]);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (!res || !isArray(res.payments)) {
|
|
148
|
-
return cbk([503, 'ExpectedPaymentsInListPaymentsResponse']);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (typeof res.last_index_offset !== 'string') {
|
|
152
|
-
return cbk([503, 'ExpectedLastIndexOffsetWhenRequestingPayments']);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const lastOffset = Number(res.last_index_offset);
|
|
156
|
-
const offset = Number(res.first_index_offset);
|
|
157
|
-
|
|
158
|
-
const token = stringify({offset, limit: resultsLimit});
|
|
159
|
-
|
|
160
|
-
return cbk(null, {
|
|
161
|
-
payments: res.payments,
|
|
162
|
-
token: offset <= lastPageFirstIndexOffset ? undefined : token,
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
}],
|
|
166
|
-
|
|
167
|
-
// Check and map payments
|
|
168
|
-
foundPayments: ['listPayments', ({listPayments}, cbk) => {
|
|
169
|
-
try {
|
|
170
|
-
const payments = listPayments.payments.map(rpcPaymentAsPayment);
|
|
171
|
-
|
|
172
|
-
return cbk(null, payments);
|
|
173
|
-
} catch (err) {
|
|
174
|
-
return cbk([503, err.message]);
|
|
175
|
-
}
|
|
176
|
-
}],
|
|
177
|
-
|
|
178
|
-
// Final found payments
|
|
179
|
-
payments: [
|
|
180
|
-
'foundPayments',
|
|
181
|
-
'listPayments',
|
|
182
|
-
({foundPayments, listPayments}, cbk) =>
|
|
183
|
-
{
|
|
184
|
-
const payments = sortBy({
|
|
185
|
-
array: foundPayments,
|
|
186
|
-
attribute: 'created_at',
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
return cbk(null, {
|
|
190
|
-
next: listPayments.token || undefined,
|
|
191
|
-
payments: payments.sorted.reverse(),
|
|
192
|
-
});
|
|
128
|
+
cbk);
|
|
193
129
|
}],
|
|
194
130
|
},
|
|
195
|
-
returnResult({reject, resolve, of: '
|
|
131
|
+
returnResult({reject, resolve, of: 'listPayments'}, cbk));
|
|
196
132
|
});
|
|
197
133
|
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticatedLightningArgs,
|
|
3
3
|
AuthenticatedLightningMethod,
|
|
4
|
+
DateRangeFilterArgs,
|
|
4
5
|
PaginationArgs,
|
|
5
6
|
} from '../../typescript';
|
|
6
7
|
|
|
7
|
-
export type GetPendingPaymentsArgs = AuthenticatedLightningArgs<
|
|
8
|
+
export type GetPendingPaymentsArgs = AuthenticatedLightningArgs<
|
|
9
|
+
PaginationArgs & DateRangeFilterArgs
|
|
10
|
+
>;
|
|
8
11
|
|
|
9
12
|
export type GetPendingPaymentsResult = {
|
|
10
13
|
payments: {
|