lightning 9.2.1 → 9.3.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 +6 -0
- package/lnd_methods/offchain/subscribe_to_past_payment.d.ts +2 -0
- package/lnd_methods/offchain/subscribe_to_past_payment.js +1 -0
- package/lnd_methods/offchain/subscribe_to_pay.d.ts +2 -0
- package/lnd_methods/offchain/subscribe_to_pay.js +1 -0
- package/lnd_methods/offchain/subscribe_to_pay_via_details.js +1 -0
- package/lnd_methods/offchain/subscribe_to_pay_via_request.js +1 -0
- package/lnd_methods/offchain/subscribe_to_payments.js +1 -0
- package/lnd_responses/failure_from_payment.d.ts +11 -0
- package/lnd_responses/failure_from_payment.js +12 -0
- package/package.json +2 -2
- package/test/lnd_responses/test_failure_from_payment.js +24 -4
- package/test/typescript/failure_from_payment.test-d.ts +13 -5
package/CHANGELOG.md
CHANGED
|
@@ -56,6 +56,8 @@ export type SubscribeToPastPaymentConfirmedEvent = {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
export type SubscribeToPastPaymentFailedEvent = {
|
|
59
|
+
/** Payment Hash Hex */
|
|
60
|
+
id: string;
|
|
59
61
|
/** Failed Due To Lack of Balance */
|
|
60
62
|
is_insufficient_balance: boolean;
|
|
61
63
|
/** Failed Due to Payment Rejected At Destination */
|
|
@@ -77,6 +77,7 @@ const unknownServiceErr = 'unknown service verrpc.Versioner';
|
|
|
77
77
|
|
|
78
78
|
@event 'failed'
|
|
79
79
|
{
|
|
80
|
+
id: <Payment Hash Hex String>
|
|
80
81
|
is_insufficient_balance: <Failed Due To Lack of Balance Bool>
|
|
81
82
|
is_invalid_payment: <Failed Due to Payment Rejected At Destination Bool>
|
|
82
83
|
is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
|
|
@@ -138,6 +138,8 @@ export type SubscribeToPayConfirmedEvent = {
|
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
export type SubscribeToPayFailedEvent = {
|
|
141
|
+
/** Payment Hash Hex */
|
|
142
|
+
id: string;
|
|
141
143
|
/** Failed Due To Lack of Balance Bool> */
|
|
142
144
|
is_insufficient_balance: boolean;
|
|
143
145
|
/** Failed Due to Invalid Payment Bool> */
|
|
@@ -125,6 +125,7 @@ const unknownServiceErr = 'unknown service verrpc.Versioner';
|
|
|
125
125
|
|
|
126
126
|
@event 'failed'
|
|
127
127
|
{
|
|
128
|
+
id: <Payment Hash Hex String>
|
|
128
129
|
is_insufficient_balance: <Failed Due To Lack of Balance Bool>
|
|
129
130
|
is_invalid_payment: <Failed Due to Invalid Payment Bool>
|
|
130
131
|
is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
|
|
@@ -97,6 +97,7 @@ const type = 'router';
|
|
|
97
97
|
|
|
98
98
|
@event 'failed'
|
|
99
99
|
{
|
|
100
|
+
id: <Payment Hash Hex String>
|
|
100
101
|
is_insufficient_balance: <Failed Due To Lack of Balance Bool>
|
|
101
102
|
is_invalid_payment: <Failed Due to Invalid Payment Bool>
|
|
102
103
|
is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
|
|
@@ -77,6 +77,7 @@ const type = 'router';
|
|
|
77
77
|
|
|
78
78
|
@event 'failed'
|
|
79
79
|
{
|
|
80
|
+
id: <Payment Hash Hex String>
|
|
80
81
|
is_insufficient_balance: <Failed Due To Lack of Balance Bool>
|
|
81
82
|
is_invalid_payment: <Failed Due to Invalid Payment Bool>
|
|
82
83
|
is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
|
|
@@ -63,6 +63,7 @@ const type = 'router';
|
|
|
63
63
|
|
|
64
64
|
@event 'failed'
|
|
65
65
|
{
|
|
66
|
+
id: <Payment Hash Hex String>
|
|
66
67
|
is_insufficient_balance: <Failed Due To Lack of Balance Bool>
|
|
67
68
|
is_invalid_payment: <Failed Due to Payment Rejected At Destination Bool>
|
|
68
69
|
is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {FailureReason} from '../typescript';
|
|
2
2
|
|
|
3
3
|
export type FailureFromPaymentArgs = {
|
|
4
|
+
payment_hash: string;
|
|
4
5
|
failure_reason: FailureReason;
|
|
5
6
|
};
|
|
6
7
|
|
|
7
8
|
export type FailureFromPaymentResult = {
|
|
9
|
+
/** Payment Hash Hex String */
|
|
10
|
+
id: string;
|
|
8
11
|
/** Payment Failed Due to Insufficient Balance Bool */
|
|
9
12
|
is_insufficient_balance: boolean;
|
|
10
13
|
/** Payment Failed Due to Invalid Details Rejection Bool */
|
|
@@ -16,32 +19,40 @@ export type FailureFromPaymentResult = {
|
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
export function failureFromPayment(payment: {
|
|
22
|
+
payment_hash: string,
|
|
19
23
|
failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE';
|
|
20
24
|
}): {
|
|
25
|
+
id: string,
|
|
21
26
|
is_insufficient_balance: true;
|
|
22
27
|
is_invalid_payment: false;
|
|
23
28
|
is_pathfinding_timeout: false;
|
|
24
29
|
is_route_not_found: false;
|
|
25
30
|
};
|
|
26
31
|
export function failureFromPayment(payment: {
|
|
32
|
+
payment_hash: string,
|
|
27
33
|
failure_reason: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS';
|
|
28
34
|
}): {
|
|
35
|
+
id: string,
|
|
29
36
|
is_insufficient_balance: false;
|
|
30
37
|
is_invalid_payment: true;
|
|
31
38
|
is_pathfinding_timeout: false;
|
|
32
39
|
is_route_not_found: false;
|
|
33
40
|
};
|
|
34
41
|
export function failureFromPayment(payment: {
|
|
42
|
+
payment_hash: string,
|
|
35
43
|
failure_reason: 'FAILURE_REASON_TIMEOUT';
|
|
36
44
|
}): {
|
|
45
|
+
id: string,
|
|
37
46
|
is_insufficient_balance: false;
|
|
38
47
|
is_invalid_payment: false;
|
|
39
48
|
is_pathfinding_timeout: true;
|
|
40
49
|
is_route_not_found: false;
|
|
41
50
|
};
|
|
42
51
|
export function failureFromPayment(payment: {
|
|
52
|
+
payment_hash: string,
|
|
43
53
|
failure_reason: 'FAILURE_REASON_NO_ROUTE';
|
|
44
54
|
}): {
|
|
55
|
+
id: string,
|
|
45
56
|
is_insufficient_balance: false;
|
|
46
57
|
is_invalid_payment: false;
|
|
47
58
|
is_pathfinding_timeout: false;
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
const {failureReason} = require('./constants');
|
|
2
2
|
|
|
3
|
+
const is256Hex = n => !!n && /^[0-9A-F]{64}$/i.test(n);
|
|
4
|
+
|
|
3
5
|
/** Derive failure status from payment
|
|
4
6
|
|
|
5
7
|
{
|
|
6
8
|
failure_reason: <Payment Failure Reason String>
|
|
9
|
+
payment_hash: <Payment SHA256 Hash Hex String>
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
@throws
|
|
13
|
+
<Error>
|
|
14
|
+
|
|
9
15
|
@returns
|
|
10
16
|
{
|
|
17
|
+
id: <Payment Hash Hex String>
|
|
11
18
|
is_insufficient_balance: <Payment Failed Due to Insufficient Balance Bool>
|
|
12
19
|
is_invalid_payment: <Payment Failed Due to Invalid Details Rejection Bool>
|
|
13
20
|
is_pathfinding_timeout: <Failure Due To Pathfinding Timeout Failure Bool>
|
|
@@ -17,7 +24,12 @@ const {failureReason} = require('./constants');
|
|
|
17
24
|
module.exports = payment => {
|
|
18
25
|
const state = payment.failure_reason;
|
|
19
26
|
|
|
27
|
+
if (!is256Hex(payment.payment_hash)) {
|
|
28
|
+
throw new Error('ExpectedPaymentHashForPaymentAsFailedPayment');
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
return {
|
|
32
|
+
id: payment.payment_hash,
|
|
21
33
|
is_insufficient_balance: state === failureReason.insufficient_balance,
|
|
22
34
|
is_invalid_payment: state === failureReason.invalid_payment,
|
|
23
35
|
is_pathfinding_timeout: state === failureReason.pathfinding_timeout_failed,
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@grpc/grpc-js": "1.8.14",
|
|
11
11
|
"@grpc/proto-loader": "0.7.6",
|
|
12
12
|
"@types/express": "4.17.17",
|
|
13
|
-
"@types/node": "18.16.
|
|
13
|
+
"@types/node": "18.16.3",
|
|
14
14
|
"@types/request": "2.48.8",
|
|
15
15
|
"@types/ws": "8.5.4",
|
|
16
16
|
"async": "3.2.4",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"directory": "test/typescript"
|
|
60
60
|
},
|
|
61
61
|
"types": "index.d.ts",
|
|
62
|
-
"version": "9.
|
|
62
|
+
"version": "9.3.0"
|
|
63
63
|
}
|
|
@@ -2,8 +2,11 @@ const {test} = require('@alexbosworth/tap');
|
|
|
2
2
|
|
|
3
3
|
const {failureFromPayment} = require('./../../lnd_responses');
|
|
4
4
|
|
|
5
|
+
const id = Buffer.alloc(32).toString('hex')
|
|
6
|
+
|
|
5
7
|
const makeExpected = overrides => {
|
|
6
8
|
const expected = {
|
|
9
|
+
id,
|
|
7
10
|
is_insufficient_balance: false,
|
|
8
11
|
is_invalid_payment: false,
|
|
9
12
|
is_pathfinding_timeout: false,
|
|
@@ -17,25 +20,42 @@ const makeExpected = overrides => {
|
|
|
17
20
|
|
|
18
21
|
const tests = [
|
|
19
22
|
{
|
|
20
|
-
args: {
|
|
23
|
+
args: {
|
|
24
|
+
failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE',
|
|
25
|
+
payment_hash: id,
|
|
26
|
+
},
|
|
21
27
|
description: 'Insufficient balance mapped',
|
|
22
28
|
expected: makeExpected({is_insufficient_balance: true}),
|
|
23
29
|
},
|
|
24
30
|
{
|
|
25
|
-
args: {
|
|
31
|
+
args: {
|
|
32
|
+
failure_reason: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS',
|
|
33
|
+
payment_hash: id,
|
|
34
|
+
},
|
|
26
35
|
description: 'Invalid payment is mapped',
|
|
27
36
|
expected: makeExpected({is_invalid_payment: true}),
|
|
28
37
|
},
|
|
29
38
|
{
|
|
30
|
-
args: {
|
|
39
|
+
args: {
|
|
40
|
+
failure_reason: 'FAILURE_REASON_NO_ROUTE',
|
|
41
|
+
payment_hash: id,
|
|
42
|
+
},
|
|
31
43
|
description: 'No route is mapped',
|
|
32
44
|
expected: makeExpected({is_route_not_found: true}),
|
|
33
45
|
},
|
|
34
46
|
{
|
|
35
|
-
args: {
|
|
47
|
+
args: {
|
|
48
|
+
failure_reason: 'FAILURE_REASON_TIMEOUT',
|
|
49
|
+
payment_hash: id,
|
|
50
|
+
},
|
|
36
51
|
description: 'Timeout is mapped',
|
|
37
52
|
expected: makeExpected({is_pathfinding_timeout: true}),
|
|
38
53
|
},
|
|
54
|
+
{
|
|
55
|
+
args: {payment_hash: undefined},
|
|
56
|
+
description: 'A payment hash is expected',
|
|
57
|
+
error: 'ExpectedPaymentHashForPaymentAsFailedPayment',
|
|
58
|
+
},
|
|
39
59
|
];
|
|
40
60
|
|
|
41
61
|
tests.forEach(({args, description, error, expected}) => {
|
|
@@ -1,41 +1,49 @@
|
|
|
1
1
|
import {expectError, expectType} from 'tsd';
|
|
2
2
|
import {failureFromPayment} from '../../lnd_responses/failure_from_payment';
|
|
3
3
|
|
|
4
|
+
const payment_hash = Buffer.alloc(32).toString('hex')
|
|
5
|
+
|
|
4
6
|
expectError(failureFromPayment());
|
|
5
7
|
expectError(failureFromPayment({}));
|
|
6
|
-
expectError(failureFromPayment({failure_reason: 'invalid failure reason'}));
|
|
8
|
+
expectError(failureFromPayment({payment_hash, failure_reason: 'invalid failure reason'}));
|
|
7
9
|
|
|
8
10
|
expectType<{
|
|
11
|
+
id: string;
|
|
9
12
|
is_insufficient_balance: boolean;
|
|
10
13
|
is_invalid_payment: boolean;
|
|
11
14
|
is_pathfinding_timeout: boolean;
|
|
12
15
|
is_route_not_found: boolean;
|
|
13
|
-
}>(failureFromPayment({failure_reason: 'FAILURE_REASON_NONE'}));
|
|
16
|
+
}>(failureFromPayment({payment_hash, failure_reason: 'FAILURE_REASON_NONE'}));
|
|
14
17
|
expectType<{
|
|
18
|
+
id: string;
|
|
15
19
|
is_insufficient_balance: true;
|
|
16
20
|
is_invalid_payment: false;
|
|
17
21
|
is_pathfinding_timeout: false;
|
|
18
22
|
is_route_not_found: false;
|
|
19
|
-
}>(failureFromPayment({failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE'}));
|
|
23
|
+
}>(failureFromPayment({payment_hash, failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE'}));
|
|
20
24
|
expectType<{
|
|
25
|
+
id: string;
|
|
21
26
|
is_insufficient_balance: false;
|
|
22
27
|
is_invalid_payment: true;
|
|
23
28
|
is_pathfinding_timeout: false;
|
|
24
29
|
is_route_not_found: false;
|
|
25
30
|
}>(
|
|
26
31
|
failureFromPayment({
|
|
32
|
+
payment_hash,
|
|
27
33
|
failure_reason: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS',
|
|
28
34
|
})
|
|
29
35
|
);
|
|
30
36
|
expectType<{
|
|
37
|
+
id: string;
|
|
31
38
|
is_insufficient_balance: false;
|
|
32
39
|
is_invalid_payment: false;
|
|
33
40
|
is_pathfinding_timeout: true;
|
|
34
41
|
is_route_not_found: false;
|
|
35
|
-
}>(failureFromPayment({failure_reason: 'FAILURE_REASON_TIMEOUT'}));
|
|
42
|
+
}>(failureFromPayment({payment_hash, failure_reason: 'FAILURE_REASON_TIMEOUT'}));
|
|
36
43
|
expectType<{
|
|
44
|
+
id: string;
|
|
37
45
|
is_insufficient_balance: false;
|
|
38
46
|
is_invalid_payment: false;
|
|
39
47
|
is_pathfinding_timeout: false;
|
|
40
48
|
is_route_not_found: true;
|
|
41
|
-
}>(failureFromPayment({failure_reason: 'FAILURE_REASON_NO_ROUTE'}));
|
|
49
|
+
}>(failureFromPayment({payment_hash, failure_reason: 'FAILURE_REASON_NO_ROUTE'}));
|