paid-services 3.15.1 → 3.15.2
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
CHANGED
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"ecpair": "2.0.1",
|
|
17
17
|
"goldengate": "11.2.1",
|
|
18
18
|
"invoices": "2.0.6",
|
|
19
|
-
"ln-service": "53.
|
|
19
|
+
"ln-service": "53.14.1",
|
|
20
20
|
"ln-sync": "3.12.0",
|
|
21
21
|
"psbt": "2.0.1",
|
|
22
22
|
"p2tr": "1.3.1",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"description": "Lightning Paid Services library",
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@alexbosworth/tap": "15.0.11",
|
|
28
|
-
"ln-docker-daemons": "2.2.
|
|
28
|
+
"ln-docker-daemons": "2.2.9",
|
|
29
29
|
"mock-lnd": "1.4.1",
|
|
30
30
|
"secp256k1": "4.0.3"
|
|
31
31
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"integration-tests": "tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 180 test/integration/*.js",
|
|
48
48
|
"test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/actions/*.js test/balanced/*.js test/capacity/*.js test/client/*.js test/config/*.js test/p2p/*.js test/records/*.js test/respond/*.js test/server/*.js test/server/*.js test/services/*.js test/trades/*.js"
|
|
49
49
|
},
|
|
50
|
-
"version": "3.15.
|
|
50
|
+
"version": "3.15.2"
|
|
51
51
|
}
|
|
@@ -23,7 +23,7 @@ const rateDenominator = 1e6;
|
|
|
23
23
|
ask: <Ask Function>
|
|
24
24
|
lnd: <Authenticated LND API Object>
|
|
25
25
|
logger: <Winston Logger Object>
|
|
26
|
-
request: <Request Function>
|
|
26
|
+
[request]: <Request Function>
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
@returns via cbk or Promise
|
|
@@ -45,10 +45,6 @@ module.exports = ({ask, lnd, logger, request}, cbk) => {
|
|
|
45
45
|
return cbk([400, 'ExpectedLoggerToRespondToSwapOutRequest']);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
if (!request) {
|
|
49
|
-
return cbk([400, 'ExpectedRequestFunctionToRespondToSwapOutReq']);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
48
|
return cbk();
|
|
53
49
|
},
|
|
54
50
|
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const asyncRetry = require('async/retry');
|
|
2
|
+
const {createChainAddress} = require('ln-service');
|
|
3
|
+
const {createInvoice} = require('ln-service');
|
|
4
|
+
const {getChannelBalance} = require('ln-service');
|
|
5
|
+
const {getChannels} = require('ln-service');
|
|
6
|
+
const {getMasterPublicKeys} = require('ln-service');
|
|
7
|
+
const {openChannel} = require('ln-service');
|
|
8
|
+
const {pay} = require('ln-service');
|
|
9
|
+
const {sendToChainAddress} = require('ln-service');
|
|
10
|
+
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
11
|
+
const {test} = require('@alexbosworth/tap');
|
|
12
|
+
|
|
13
|
+
const requestSwapOut = require('./../../swaps/request_swap_out');
|
|
14
|
+
const respondToSwapOut = require('./../../swaps/respond_to_swap_out_request');
|
|
15
|
+
|
|
16
|
+
const capacity = 1e6;
|
|
17
|
+
const count = 6;
|
|
18
|
+
const interval = 100;
|
|
19
|
+
const maturity = 100;
|
|
20
|
+
const size = 2;
|
|
21
|
+
const taprootDerivationPath = `m/86'/0'/0'`;
|
|
22
|
+
const times = 3000;
|
|
23
|
+
const tokens = 1e5;
|
|
24
|
+
|
|
25
|
+
// Start an offchain swap
|
|
26
|
+
test(`Start offchain swap`, async ({end, equal, strictSame}) => {
|
|
27
|
+
const {kill, nodes} = await spawnLightningCluster({size});
|
|
28
|
+
|
|
29
|
+
const [{generate, id, lnd}, target] = nodes;
|
|
30
|
+
|
|
31
|
+
const {keys} = await getMasterPublicKeys({lnd});
|
|
32
|
+
|
|
33
|
+
// Exit early when taproot is not supported
|
|
34
|
+
if (!keys.find(n => n.derivation_path === taprootDerivationPath)) {
|
|
35
|
+
await kill({});
|
|
36
|
+
|
|
37
|
+
return end();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
await generate({count: maturity});
|
|
42
|
+
|
|
43
|
+
// Setup a channel between the nodes
|
|
44
|
+
{
|
|
45
|
+
// Make a channel
|
|
46
|
+
await asyncRetry({interval, times}, async () => {
|
|
47
|
+
await openChannel({
|
|
48
|
+
lnd,
|
|
49
|
+
local_tokens: capacity,
|
|
50
|
+
partner_public_key: target.id,
|
|
51
|
+
partner_socket: target.socket,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await asyncRetry({interval, times}, async () => {
|
|
56
|
+
const {channels} = await getChannels({lnd, is_actve: true});
|
|
57
|
+
|
|
58
|
+
if (!!channels.length) {
|
|
59
|
+
return channels;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await generate({});
|
|
63
|
+
|
|
64
|
+
await sendToChainAddress({
|
|
65
|
+
lnd,
|
|
66
|
+
address: (await createChainAddress({lnd: target.lnd})).address,
|
|
67
|
+
tokens: capacity,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const balance = await getChannelBalance({lnd});
|
|
71
|
+
|
|
72
|
+
if (!balance.channel_balance) {
|
|
73
|
+
throw new Error('WaitingForChannelBalance');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
throw new Error('WaitingForChannelOpen');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
await target.generate({count: maturity});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Collect request messages
|
|
83
|
+
const messages = [];
|
|
84
|
+
|
|
85
|
+
// Make a swap out request
|
|
86
|
+
await requestSwapOut({
|
|
87
|
+
lnd,
|
|
88
|
+
ask: async (args, cbk) => {
|
|
89
|
+
if (args.name === 'tokens') {
|
|
90
|
+
return cbk({tokens: '10000'});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (args.name === 'rate') {
|
|
94
|
+
return cbk({rate: '10'});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const swapRequest = messages.find(n => !!n.swap_request);
|
|
98
|
+
|
|
99
|
+
if (args.name === 'response') {
|
|
100
|
+
return await respondToSwapOut({
|
|
101
|
+
ask: (args, cbk) => {
|
|
102
|
+
if (args.name === 'rate') {
|
|
103
|
+
return cbk({rate: '100'});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (args.name === 'req') {
|
|
107
|
+
return cbk({req: swapRequest.swap_request});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
throw new Error('UnrecognizedQueryForResponse');
|
|
111
|
+
},
|
|
112
|
+
lnd: target.lnd,
|
|
113
|
+
logger: {
|
|
114
|
+
info: async message => {
|
|
115
|
+
if (!!message.response) {
|
|
116
|
+
return cbk({response: message.response});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Transaction is funded, generate funding into a block
|
|
120
|
+
if (!!message.funding_transaction_id) {
|
|
121
|
+
return await target.generate({count});
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (args.name === 'ok') {
|
|
129
|
+
return cbk({ok: true});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
throw new Error('UnrecognizedQueryForRequest');
|
|
133
|
+
},
|
|
134
|
+
logger: {
|
|
135
|
+
info: async message => {
|
|
136
|
+
if (message.broadcasting_tx_to_resolve_swap) {
|
|
137
|
+
await generate({count});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return messages.push(message);
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
} catch (err) {
|
|
145
|
+
strictSame(err, null, 'Expected no failure');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
await kill({});
|
|
149
|
+
|
|
150
|
+
return end();
|
|
151
|
+
});
|