lightning 6.8.1 → 7.0.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 +8 -0
- package/index.js +2 -0
- package/lnd_methods/index.js +2 -0
- package/lnd_methods/onchain/get_chain_addresses.js +83 -0
- package/lnd_methods/onchain/index.js +2 -0
- package/lnd_responses/index.js +2 -0
- package/lnd_responses/rpc_addresses_as_addresses.js +62 -0
- package/package.json +3 -3
- package/test/lnd_methods/onchain/test_get_chain_addresses.js +75 -0
- package/test/lnd_responses/test_rpc_addresses_as_addresses.js +82 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
+
## 7.0.0
|
|
4
|
+
|
|
5
|
+
- `getAddresses`: Add method to get the list of chain addresses
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- Incorrect TypeScript settings for probe and fee rates was corrected
|
|
10
|
+
|
|
3
11
|
## 6.8.1
|
|
4
12
|
|
|
5
13
|
- `subscribeToRpcRequests`: add `max_tokens_per_vbyte` to RPC close requests
|
package/index.js
CHANGED
|
@@ -33,6 +33,7 @@ const {getAutopilot} = require('./lnd_methods');
|
|
|
33
33
|
const {getBackup} = require('./lnd_methods');
|
|
34
34
|
const {getBackups} = require('./lnd_methods');
|
|
35
35
|
const {getBlock} = require('./lnd_methods');
|
|
36
|
+
const {getChainAddresses} = require('./lnd_methods');
|
|
36
37
|
const {getChainBalance} = require('./lnd_methods');
|
|
37
38
|
const {getChainFeeEstimate} = require('./lnd_methods');
|
|
38
39
|
const {getChainFeeRate} = require('./lnd_methods');
|
|
@@ -184,6 +185,7 @@ module.exports = {
|
|
|
184
185
|
getBackup,
|
|
185
186
|
getBackups,
|
|
186
187
|
getBlock,
|
|
188
|
+
getChainAddresses,
|
|
187
189
|
getChainBalance,
|
|
188
190
|
getChainFeeEstimate,
|
|
189
191
|
getChainFeeRate,
|
package/lnd_methods/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const {getAutopilot} = require('./info');
|
|
|
31
31
|
const {getBackup} = require('./offchain');
|
|
32
32
|
const {getBackups} = require('./offchain');
|
|
33
33
|
const {getBlock} = require('./onchain');
|
|
34
|
+
const {getChainAddresses} = require('./onchain');
|
|
34
35
|
const {getChainBalance} = require('./onchain');
|
|
35
36
|
const {getChainFeeEstimate} = require('./onchain');
|
|
36
37
|
const {getChainFeeRate} = require('./onchain');
|
|
@@ -178,6 +179,7 @@ module.exports = {
|
|
|
178
179
|
getBackup,
|
|
179
180
|
getBackups,
|
|
180
181
|
getBlock,
|
|
182
|
+
getChainAddresses,
|
|
181
183
|
getChainBalance,
|
|
182
184
|
getChainFeeEstimate,
|
|
183
185
|
getChainFeeRate,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const asyncAuto = require('async/auto');
|
|
2
|
+
const {returnResult} = require('asyncjs-util');
|
|
3
|
+
|
|
4
|
+
const {isLnd} = require('./../../lnd_requests');
|
|
5
|
+
const {rpcAddressesAsAddresses} = require('./../../lnd_responses');
|
|
6
|
+
|
|
7
|
+
const err404 = 'unknown method ListAddresses for service walletrpc.WalletKit';
|
|
8
|
+
const {isArray} = Array;
|
|
9
|
+
const method = 'listAddresses';
|
|
10
|
+
const type = 'wallet';
|
|
11
|
+
const unsupportedErrorMessage = 'unknown service walletrpc.WalletKit';
|
|
12
|
+
|
|
13
|
+
/** Get the wallet chain addresses
|
|
14
|
+
|
|
15
|
+
Requires `onchain:read` permission
|
|
16
|
+
|
|
17
|
+
This method is not supported on LND 0.15.5 and below
|
|
18
|
+
|
|
19
|
+
{
|
|
20
|
+
lnd: <Authenticated LND API Object>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@returns via cbk or Promise
|
|
24
|
+
{
|
|
25
|
+
addresses: [{
|
|
26
|
+
address: <Chain Address String>
|
|
27
|
+
is_change: <Is Internal Change Address Bool>
|
|
28
|
+
tokens: <Balance of Funds Controlled by Output Script Tokens Number>
|
|
29
|
+
}]
|
|
30
|
+
}
|
|
31
|
+
*/
|
|
32
|
+
module.exports = ({lnd}, cbk) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
return asyncAuto({
|
|
35
|
+
// Check arguments
|
|
36
|
+
validate: cbk => {
|
|
37
|
+
if (!isLnd({lnd, method, type})) {
|
|
38
|
+
return cbk([400, 'ExpectedAuthenticatedLndToGetChainAddresses']);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return cbk();
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
// Get the list of accounts with addresses
|
|
45
|
+
getAddresses: ['validate', ({}, cbk) => {
|
|
46
|
+
return lnd[type][method]({}, (err, res) => {
|
|
47
|
+
// LND 0.15.5 and below do not support listing account addresses
|
|
48
|
+
if (!!err && err.details === err404) {
|
|
49
|
+
return cbk([501, 'BackingLndDoesNotSupportGettingChainAddresses']);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!!err) {
|
|
53
|
+
return cbk([503, 'UnexpectedErrorListingAccountAddresses', {err}]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!res) {
|
|
57
|
+
return cbk([503, 'ExpectedResponseForGetAccountAddressesRequest']);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!isArray(res.account_with_addresses)) {
|
|
61
|
+
return cbk([503, 'ExpectedSetOfAccountAddressesInAddrsResponse']);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return cbk(null, res.account_with_addresses);
|
|
65
|
+
});
|
|
66
|
+
}],
|
|
67
|
+
|
|
68
|
+
// Map the accounts to a list of addresses
|
|
69
|
+
addresses: ['getAddresses', ({getAddresses}, cbk) => {
|
|
70
|
+
try {
|
|
71
|
+
const {addresses} = rpcAddressesAsAddresses({
|
|
72
|
+
accounts: getAddresses,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return cbk(null, {addresses});
|
|
76
|
+
} catch (err) {
|
|
77
|
+
return cbk([503, err.message]);
|
|
78
|
+
}
|
|
79
|
+
}],
|
|
80
|
+
},
|
|
81
|
+
returnResult({reject, resolve, of: 'addresses'}, cbk));
|
|
82
|
+
});
|
|
83
|
+
};
|
|
@@ -4,6 +4,7 @@ const closeChannel = require('./close_channel');
|
|
|
4
4
|
const fundPendingChannels = require('./fund_pending_channels');
|
|
5
5
|
const fundPsbt = require('./fund_psbt');
|
|
6
6
|
const getBlock = require('./get_block');
|
|
7
|
+
const getChainAddresses = require('./get_chain_addresses');
|
|
7
8
|
const getChainBalance = require('./get_chain_balance');
|
|
8
9
|
const getChainFeeEstimate = require('./get_chain_fee_estimate');
|
|
9
10
|
const getChainFeeRate = require('./get_chain_fee_rate');
|
|
@@ -39,6 +40,7 @@ module.exports = {
|
|
|
39
40
|
fundPendingChannels,
|
|
40
41
|
fundPsbt,
|
|
41
42
|
getBlock,
|
|
43
|
+
getChainAddresses,
|
|
42
44
|
getChainBalance,
|
|
43
45
|
getChainFeeEstimate,
|
|
44
46
|
getChainFeeRate,
|
package/lnd_responses/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const pendingFromPayment = require('./pending_from_payment');
|
|
|
15
15
|
const policyFromChannelUpdate = require('./policy_from_channel_update');
|
|
16
16
|
const routesFromQueryRoutes = require('./routes_from_query_routes');
|
|
17
17
|
const routingFailureFromHtlc = require('./routing_failure_from_htlc');
|
|
18
|
+
const rpcAddressesAsAddresses = require('./rpc_addresses_as_addresses');
|
|
18
19
|
const rpcAttemptHtlcAsAttempt = require('./rpc_attempt_htlc_as_attempt');
|
|
19
20
|
const rpcChannelAsChannel = require('./rpc_channel_as_channel');
|
|
20
21
|
const rpcChannelAsOldRpcChannel = require('./rpc_channel_as_old_rpc_channel');
|
|
@@ -60,6 +61,7 @@ module.exports = {
|
|
|
60
61
|
policyFromChannelUpdate,
|
|
61
62
|
routesFromQueryRoutes,
|
|
62
63
|
routingFailureFromHtlc,
|
|
64
|
+
rpcAddressesAsAddresses,
|
|
63
65
|
rpcAttemptHtlcAsAttempt,
|
|
64
66
|
rpcChannelAsChannel,
|
|
65
67
|
rpcChannelAsOldRpcChannel,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const flatten = arr => [].concat(...arr);
|
|
2
|
+
const {isArray} = Array;
|
|
3
|
+
const isBoolean = n => n === false || n === true;
|
|
4
|
+
|
|
5
|
+
/** Derive a list of addresses from a list of accounts with addresses
|
|
6
|
+
|
|
7
|
+
{
|
|
8
|
+
accounts: [{
|
|
9
|
+
addresses: [{
|
|
10
|
+
address: <Chain Address String>
|
|
11
|
+
balance: <Balance Tokens Number String>
|
|
12
|
+
is_internal: <Is Change Address Bool>
|
|
13
|
+
}]
|
|
14
|
+
}]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@throws
|
|
18
|
+
<Error>
|
|
19
|
+
|
|
20
|
+
@returns
|
|
21
|
+
{
|
|
22
|
+
addresses: [{
|
|
23
|
+
address: <Chain Address String>
|
|
24
|
+
is_change: <Is Internal Change Address Bool>
|
|
25
|
+
tokens: <Balance of Funds Controlled by Output Script Tokens Number>
|
|
26
|
+
}]
|
|
27
|
+
}
|
|
28
|
+
*/
|
|
29
|
+
module.exports = ({accounts}) => {
|
|
30
|
+
if (!isArray(accounts)) {
|
|
31
|
+
throw new Error('ExpectedArrayOfAccountsWithAddresses');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Map the accounts addresses to a list of addresses
|
|
35
|
+
const addresses = flatten(accounts.map(account => {
|
|
36
|
+
if (!isArray(account.addresses)) {
|
|
37
|
+
throw new Error('ExpectedArrayOfAddressesInAccountWithAddresses');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return account.addresses.map(accountAddress => {
|
|
41
|
+
if (!accountAddress.address) {
|
|
42
|
+
throw new Error('ExpectedChainAddressInAccountAddress');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!accountAddress.balance) {
|
|
46
|
+
throw new Error('ExpectedBalanceTotalForAccountAddress');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!isBoolean(accountAddress.is_internal)) {
|
|
50
|
+
throw new Error('ExpectedInternalAddressMarkerInAccountAddress');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
address: accountAddress.address,
|
|
55
|
+
is_change: accountAddress.is_internal,
|
|
56
|
+
tokens: Number(accountAddress.balance),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
return {addresses};
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"url": "https://github.com/alexbosworth/lightning/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@grpc/grpc-js": "1.8.
|
|
10
|
+
"@grpc/grpc-js": "1.8.1",
|
|
11
11
|
"@grpc/proto-loader": "0.7.4",
|
|
12
12
|
"@types/express": "4.17.15",
|
|
13
13
|
"@types/node": "18.11.18",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"invoices": "2.2.2",
|
|
27
27
|
"psbt": "2.7.1",
|
|
28
28
|
"tiny-secp256k1": "2.2.1",
|
|
29
|
-
"type-fest": "3.5.
|
|
29
|
+
"type-fest": "3.5.1"
|
|
30
30
|
},
|
|
31
31
|
"description": "Lightning Network client library",
|
|
32
32
|
"devDependencies": {
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"directory": "test/typescript"
|
|
60
60
|
},
|
|
61
61
|
"types": "index.d.ts",
|
|
62
|
-
"version": "
|
|
62
|
+
"version": "7.0.0"
|
|
63
63
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const {getChainAddresses} = require('./../../../lnd_methods');
|
|
4
|
+
|
|
5
|
+
const makeLnd = ({err, res}) => {
|
|
6
|
+
return {
|
|
7
|
+
wallet: {
|
|
8
|
+
listAddresses: ({}, cbk) => {
|
|
9
|
+
if (res !== undefined) {
|
|
10
|
+
return cbk(null, res);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return cbk(err, {account_with_addresses: []});
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const tests = [
|
|
20
|
+
{
|
|
21
|
+
args: {},
|
|
22
|
+
description: 'LND Object is required to get chain addresses',
|
|
23
|
+
error: [400, 'ExpectedAuthenticatedLndToGetChainAddresses'],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
args: {lnd: makeLnd({err: 'err'})},
|
|
27
|
+
description: 'LND errors are passed back',
|
|
28
|
+
error: [503, 'UnexpectedErrorListingAccountAddresses', {err: 'err'}],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
args: {
|
|
32
|
+
lnd: makeLnd({
|
|
33
|
+
err: {
|
|
34
|
+
details: 'unknown method ListAddresses for service walletrpc.WalletKit',
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
description: 'Unknown method is handled',
|
|
39
|
+
error: [501, 'BackingLndDoesNotSupportGettingChainAddresses'],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
args: {lnd: makeLnd({res: null})},
|
|
43
|
+
description: 'A response is expected',
|
|
44
|
+
error: [503, 'ExpectedResponseForGetAccountAddressesRequest'],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
args: {lnd: makeLnd({res: {}})},
|
|
48
|
+
description: 'A response with accounts is expected',
|
|
49
|
+
error: [503, 'ExpectedSetOfAccountAddressesInAddrsResponse'],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
args: {lnd: makeLnd({res: {account_with_addresses: [{}]}})},
|
|
53
|
+
description: 'A valid response with accounts is expected',
|
|
54
|
+
error: [503, 'ExpectedArrayOfAddressesInAccountWithAddresses'],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
args: {lnd: makeLnd({})},
|
|
58
|
+
description: 'Get a list of chain addresses',
|
|
59
|
+
expected: {addresses: []},
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
64
|
+
return test(description, async ({end, rejects, strictSame}) => {
|
|
65
|
+
if (!!error) {
|
|
66
|
+
await rejects(() => getChainAddresses(args), error, 'Got error');
|
|
67
|
+
} else {
|
|
68
|
+
const res = await getChainAddresses(args);
|
|
69
|
+
|
|
70
|
+
strictSame(res, expected, 'Got expected result');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return end();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const {rpcAddressesAsAddresses} = require('./../../lnd_responses');
|
|
4
|
+
|
|
5
|
+
const makeAddress = overrides => {
|
|
6
|
+
const args = {address: 'address', balance: '0', is_internal: false};
|
|
7
|
+
|
|
8
|
+
Object.keys(overrides).forEach(k => args[k] = overrides[k]);
|
|
9
|
+
|
|
10
|
+
return args;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const makeArgs = overrides => {
|
|
14
|
+
const args = {accounts: [{addresses: [makeAddress({})]}]};
|
|
15
|
+
|
|
16
|
+
Object.keys(overrides).forEach(k => args[k] = overrides[k]);
|
|
17
|
+
|
|
18
|
+
return args;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const makeExpected = overrides => {
|
|
22
|
+
const expected = {
|
|
23
|
+
addresses: [{address: 'address', is_change: false, tokens: 0}],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
Object.keys(overrides).forEach(k => expected[k] = overrides[k]);
|
|
27
|
+
|
|
28
|
+
return expected;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const tests = [
|
|
32
|
+
{
|
|
33
|
+
args: makeArgs({accounts: undefined}),
|
|
34
|
+
description: 'Accounts with addresses are expected',
|
|
35
|
+
error: 'ExpectedArrayOfAccountsWithAddresses',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
args: makeArgs({accounts: [{addresses: undefined}]}),
|
|
39
|
+
description: 'Accounts with addresses are expected',
|
|
40
|
+
error: 'ExpectedArrayOfAddressesInAccountWithAddresses',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
args: makeArgs({
|
|
44
|
+
accounts: [{addresses: [makeAddress({address: undefined})]}],
|
|
45
|
+
}),
|
|
46
|
+
description: 'Accounts with address are expected',
|
|
47
|
+
error: 'ExpectedChainAddressInAccountAddress',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
args: makeArgs({
|
|
51
|
+
accounts: [{addresses: [makeAddress({balance: undefined})]}],
|
|
52
|
+
}),
|
|
53
|
+
description: 'Accounts with balances are expected',
|
|
54
|
+
error: 'ExpectedBalanceTotalForAccountAddress',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
args: makeArgs({
|
|
58
|
+
accounts: [{addresses: [makeAddress({is_internal: undefined})]}],
|
|
59
|
+
}),
|
|
60
|
+
description: 'Accounts with internal markers are expected',
|
|
61
|
+
error: 'ExpectedInternalAddressMarkerInAccountAddress',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
args: makeArgs({}),
|
|
65
|
+
description: 'RPC addresses are mapped to addresses',
|
|
66
|
+
expected: makeExpected({}),
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
71
|
+
return test(description, ({end, strictSame, throws}) => {
|
|
72
|
+
if (!!error) {
|
|
73
|
+
throws(() => rpcAddressesAsAddresses(args), new Error(error), 'Got err');
|
|
74
|
+
} else {
|
|
75
|
+
const res = rpcAddressesAsAddresses(args);
|
|
76
|
+
|
|
77
|
+
strictSame(res, expected, 'Got expected result');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return end();
|
|
81
|
+
});
|
|
82
|
+
});
|