@aeternity/aepp-sdk 8.2.1 → 10.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 +216 -337
- package/README.md +16 -9
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.js +36 -120
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +238 -465
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +328 -495
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +131 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +41 -106
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- package/src/contract/aci/helpers.js +0 -140
package/es/channel/handlers.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
4
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
5
|
-
import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
|
|
6
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
7
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
8
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
9
|
-
|
|
10
1
|
/*
|
|
11
2
|
* ISC License (ISC)
|
|
12
3
|
* Copyright (c) 2018 aeternity developers
|
|
@@ -28,55 +19,33 @@ import { options, changeStatus, changeState, call, send, emit, channelId, discon
|
|
|
28
19
|
import { unpackTx, buildTx } from '../tx/builder';
|
|
29
20
|
|
|
30
21
|
function encodeRlpTx(rlpBinary) {
|
|
31
|
-
return
|
|
22
|
+
return `tx_${encodeBase64Check(rlpBinary)}`;
|
|
32
23
|
}
|
|
33
24
|
|
|
34
|
-
function appendSignature(
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
async function appendSignature(tx, signFn) {
|
|
26
|
+
const {
|
|
27
|
+
signatures,
|
|
28
|
+
encodedTx
|
|
29
|
+
} = unpackTx(tx).tx;
|
|
30
|
+
const result = await signFn(encodeRlpTx(encodedTx.rlpEncoded));
|
|
31
|
+
|
|
32
|
+
if (typeof result === 'string') {
|
|
33
|
+
const {
|
|
34
|
+
tx: signedTx,
|
|
35
|
+
txType
|
|
36
|
+
} = unpackTx(result);
|
|
37
|
+
return encodeRlpTx(buildTx({
|
|
38
|
+
signatures: signatures.concat(signedTx.signatures),
|
|
39
|
+
encodedTx: signedTx.encodedTx.rlpEncoded
|
|
40
|
+
}, txType).rlpEncoded);
|
|
41
|
+
}
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
_appendSignature = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tx, signFn) {
|
|
40
|
-
var _unpackTx$tx, signatures, encodedTx, result, _unpackTx, signedTx, txType;
|
|
41
|
-
|
|
42
|
-
return _regeneratorRuntime.wrap(function _callee$(_context4) {
|
|
43
|
-
while (1) {
|
|
44
|
-
switch (_context4.prev = _context4.next) {
|
|
45
|
-
case 0:
|
|
46
|
-
_unpackTx$tx = unpackTx(tx).tx, signatures = _unpackTx$tx.signatures, encodedTx = _unpackTx$tx.encodedTx;
|
|
47
|
-
_context4.next = 3;
|
|
48
|
-
return signFn(encodeRlpTx(encodedTx.rlpEncoded));
|
|
49
|
-
|
|
50
|
-
case 3:
|
|
51
|
-
result = _context4.sent;
|
|
52
|
-
|
|
53
|
-
if (!(typeof result === 'string')) {
|
|
54
|
-
_context4.next = 7;
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
_unpackTx = unpackTx(result), signedTx = _unpackTx.tx, txType = _unpackTx.txType;
|
|
59
|
-
return _context4.abrupt("return", encodeRlpTx(buildTx({
|
|
60
|
-
signatures: _concatInstanceProperty(signatures).call(signatures, signedTx.signatures),
|
|
61
|
-
encodedTx: signedTx.encodedTx.rlpEncoded
|
|
62
|
-
}, txType).rlpEncoded));
|
|
63
|
-
|
|
64
|
-
case 7:
|
|
65
|
-
return _context4.abrupt("return", result);
|
|
66
|
-
|
|
67
|
-
case 8:
|
|
68
|
-
case "end":
|
|
69
|
-
return _context4.stop();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}, _callee);
|
|
73
|
-
}));
|
|
74
|
-
return _appendSignature.apply(this, arguments);
|
|
43
|
+
return result;
|
|
75
44
|
}
|
|
76
45
|
|
|
77
46
|
function handleUnexpectedMessage(channel, message, state) {
|
|
78
47
|
if (state && state.reject) {
|
|
79
|
-
state.reject(
|
|
48
|
+
state.reject(Object.assign(new Error(`Unexpected message received:\n\n${JSON.stringify(message)}`), {
|
|
80
49
|
wsMessage: message
|
|
81
50
|
}));
|
|
82
51
|
}
|
|
@@ -88,9 +57,7 @@ function handleUnexpectedMessage(channel, message, state) {
|
|
|
88
57
|
|
|
89
58
|
export function awaitingConnection(channel, message, state) {
|
|
90
59
|
if (message.method === 'channels.info') {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (_includesInstanceProperty(_context = ['channel_accept', 'funding_created']).call(_context, message.params.data.event)) {
|
|
60
|
+
if (['channel_accept', 'funding_created'].includes(message.params.data.event)) {
|
|
94
61
|
changeStatus(channel, {
|
|
95
62
|
channel_accept: 'accepted',
|
|
96
63
|
funding_created: 'halfSigned'
|
|
@@ -125,124 +92,53 @@ export function awaitingConnection(channel, message, state) {
|
|
|
125
92
|
};
|
|
126
93
|
}
|
|
127
94
|
}
|
|
128
|
-
export function awaitingReconnection(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!(message.method === 'channels.info')) {
|
|
139
|
-
_context5.next = 10;
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (!(message.params.data.event === 'fsm_up')) {
|
|
144
|
-
_context5.next = 10;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
fsmId.set(channel, message.params.data.fsm_id);
|
|
149
|
-
_context5.t0 = changeState;
|
|
150
|
-
_context5.t1 = channel;
|
|
151
|
-
_context5.next = 7;
|
|
152
|
-
return call(channel, 'channels.get.offchain_state', {});
|
|
153
|
-
|
|
154
|
-
case 7:
|
|
155
|
-
_context5.t2 = _context5.sent.signed_tx;
|
|
156
|
-
(0, _context5.t0)(_context5.t1, _context5.t2);
|
|
157
|
-
return _context5.abrupt("return", {
|
|
158
|
-
handler: channelOpen
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
case 10:
|
|
162
|
-
return _context5.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
163
|
-
|
|
164
|
-
case 11:
|
|
165
|
-
case "end":
|
|
166
|
-
return _context5.stop();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}, _callee2);
|
|
170
|
-
}));
|
|
171
|
-
return _awaitingReconnection.apply(this, arguments);
|
|
172
|
-
}
|
|
95
|
+
export async function awaitingReconnection(channel, message, state) {
|
|
96
|
+
if (message.method === 'channels.info') {
|
|
97
|
+
if (message.params.data.event === 'fsm_up') {
|
|
98
|
+
fsmId.set(channel, message.params.data.fsm_id);
|
|
99
|
+
changeState(channel, (await call(channel, 'channels.get.offchain_state', {})).signed_tx);
|
|
100
|
+
return {
|
|
101
|
+
handler: channelOpen
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
173
105
|
|
|
174
|
-
|
|
175
|
-
return _awaitingChannelCreateTx.apply(this, arguments);
|
|
106
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
176
107
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (!(message.method === "channels.sign.".concat(tag))) {
|
|
192
|
-
_context6.next = 13;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (!message.params.data.tx) {
|
|
197
|
-
_context6.next = 8;
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
_context6.next = 5;
|
|
202
|
-
return options.get(channel).sign(tag, message.params.data.tx);
|
|
203
|
-
|
|
204
|
-
case 5:
|
|
205
|
-
_signedTx = _context6.sent;
|
|
206
|
-
send(channel, {
|
|
207
|
-
jsonrpc: '2.0',
|
|
208
|
-
method: "channels.".concat(tag),
|
|
209
|
-
params: {
|
|
210
|
-
tx: _signedTx
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
return _context6.abrupt("return", {
|
|
214
|
-
handler: awaitingOnChainTx
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
case 8:
|
|
218
|
-
_context6.next = 10;
|
|
219
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
220
|
-
return options.get(channel).sign(tag, tx);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
case 10:
|
|
224
|
-
signedTx = _context6.sent;
|
|
225
|
-
send(channel, {
|
|
226
|
-
jsonrpc: '2.0',
|
|
227
|
-
method: "channels.".concat(tag),
|
|
228
|
-
params: {
|
|
229
|
-
signed_tx: signedTx
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
return _context6.abrupt("return", {
|
|
233
|
-
handler: awaitingOnChainTx
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
case 13:
|
|
237
|
-
case "end":
|
|
238
|
-
return _context6.stop();
|
|
108
|
+
export async function awaitingChannelCreateTx(channel, message, state) {
|
|
109
|
+
const tag = {
|
|
110
|
+
initiator: 'initiator_sign',
|
|
111
|
+
responder: 'responder_sign'
|
|
112
|
+
}[options.get(channel).role];
|
|
113
|
+
|
|
114
|
+
if (message.method === `channels.sign.${tag}`) {
|
|
115
|
+
if (message.params.data.tx) {
|
|
116
|
+
const signedTx = await options.get(channel).sign(tag, message.params.data.tx);
|
|
117
|
+
send(channel, {
|
|
118
|
+
jsonrpc: '2.0',
|
|
119
|
+
method: `channels.${tag}`,
|
|
120
|
+
params: {
|
|
121
|
+
tx: signedTx
|
|
239
122
|
}
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
handler: awaitingOnChainTx
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => options.get(channel).sign(tag, tx));
|
|
130
|
+
send(channel, {
|
|
131
|
+
jsonrpc: '2.0',
|
|
132
|
+
method: `channels.${tag}`,
|
|
133
|
+
params: {
|
|
134
|
+
signed_tx: signedTx
|
|
240
135
|
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
handler: awaitingOnChainTx
|
|
139
|
+
};
|
|
140
|
+
}
|
|
244
141
|
}
|
|
245
|
-
|
|
246
142
|
export function awaitingOnChainTx(channel, message, state) {
|
|
247
143
|
if (message.method === 'channels.on_chain_tx') {
|
|
248
144
|
if (message.params.data.info === 'funding_signed' && options.get(channel).role === 'initiator') {
|
|
@@ -268,7 +164,7 @@ export function awaitingOnChainTx(channel, message, state) {
|
|
|
268
164
|
}
|
|
269
165
|
export function awaitingBlockInclusion(channel, message, state) {
|
|
270
166
|
if (message.method === 'channels.info') {
|
|
271
|
-
|
|
167
|
+
const handler = {
|
|
272
168
|
funding_created: awaitingBlockInclusion,
|
|
273
169
|
own_funding_locked: awaitingBlockInclusion,
|
|
274
170
|
funding_locked: awaitingOpenConfirmation
|
|
@@ -276,7 +172,7 @@ export function awaitingBlockInclusion(channel, message, state) {
|
|
|
276
172
|
|
|
277
173
|
if (handler) {
|
|
278
174
|
return {
|
|
279
|
-
handler
|
|
175
|
+
handler
|
|
280
176
|
};
|
|
281
177
|
}
|
|
282
178
|
}
|
|
@@ -307,284 +203,206 @@ export function awaitingInitialState(channel, message, state) {
|
|
|
307
203
|
};
|
|
308
204
|
}
|
|
309
205
|
}
|
|
310
|
-
export function channelOpen(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
case 18:
|
|
374
|
-
return _context7.abrupt("return", {
|
|
375
|
-
handler: channelOpen
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
case 19:
|
|
379
|
-
return _context7.abrupt("break", 26);
|
|
380
|
-
|
|
381
|
-
case 20:
|
|
382
|
-
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
383
|
-
info: message.params.data.info,
|
|
384
|
-
type: message.params.data.type
|
|
385
|
-
});
|
|
386
|
-
return _context7.abrupt("return", {
|
|
387
|
-
handler: channelOpen
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
case 22:
|
|
391
|
-
return _context7.abrupt("return", {
|
|
392
|
-
handler: channelOpen
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
case 23:
|
|
396
|
-
changeState(channel, message.params.data.state);
|
|
397
|
-
return _context7.abrupt("return", {
|
|
398
|
-
handler: channelOpen
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
case 25:
|
|
402
|
-
return _context7.abrupt("return", awaitingTxSignRequest(channel, message, state));
|
|
403
|
-
|
|
404
|
-
case 26:
|
|
405
|
-
case "end":
|
|
406
|
-
return _context7.stop();
|
|
407
|
-
}
|
|
206
|
+
export async function channelOpen(channel, message, state) {
|
|
207
|
+
switch (message.method) {
|
|
208
|
+
case 'channels.info':
|
|
209
|
+
switch (message.params.data.event) {
|
|
210
|
+
case 'update':
|
|
211
|
+
case 'withdraw_created':
|
|
212
|
+
case 'deposit_created':
|
|
213
|
+
return {
|
|
214
|
+
handler: awaitingTxSignRequest
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
case 'own_withdraw_locked':
|
|
218
|
+
case 'withdraw_locked':
|
|
219
|
+
case 'own_deposit_locked':
|
|
220
|
+
case 'deposit_locked':
|
|
221
|
+
case 'peer_disconnected':
|
|
222
|
+
case 'channel_reestablished':
|
|
223
|
+
case 'open':
|
|
224
|
+
// TODO: Better handling of peer_disconnected event.
|
|
225
|
+
//
|
|
226
|
+
// We should enter intermediate state where offchain transactions
|
|
227
|
+
// are blocked until channel is reestablished.
|
|
228
|
+
emit(channel, message.params.data.event);
|
|
229
|
+
return {
|
|
230
|
+
handler: channelOpen
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
case 'fsm_up':
|
|
234
|
+
fsmId.set(channel, message.params.data.fsm_id);
|
|
235
|
+
return {
|
|
236
|
+
handler: channelOpen
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
case 'timeout':
|
|
240
|
+
case 'close_mutual':
|
|
241
|
+
return {
|
|
242
|
+
handler: channelOpen
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
case 'closing':
|
|
246
|
+
changeStatus(channel, 'closing');
|
|
247
|
+
return {
|
|
248
|
+
handler: channelOpen
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
case 'closed_confirmed':
|
|
252
|
+
changeStatus(channel, 'closed');
|
|
253
|
+
return {
|
|
254
|
+
handler: channelClosed
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
case 'died':
|
|
258
|
+
changeStatus(channel, 'died');
|
|
259
|
+
return {
|
|
260
|
+
handler: channelClosed
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
case 'shutdown':
|
|
264
|
+
return {
|
|
265
|
+
handler: channelOpen
|
|
266
|
+
};
|
|
408
267
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
268
|
+
|
|
269
|
+
break;
|
|
270
|
+
|
|
271
|
+
case 'channels.on_chain_tx':
|
|
272
|
+
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
273
|
+
info: message.params.data.info,
|
|
274
|
+
type: message.params.data.type
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
handler: channelOpen
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
case 'channels.leave':
|
|
281
|
+
// TODO: emit event
|
|
282
|
+
return {
|
|
283
|
+
handler: channelOpen
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
case 'channels.update':
|
|
287
|
+
changeState(channel, message.params.data.state);
|
|
288
|
+
return {
|
|
289
|
+
handler: channelOpen
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
case 'channels.sign.shutdown_sign_ack':
|
|
293
|
+
return awaitingTxSignRequest(channel, message, state);
|
|
294
|
+
}
|
|
412
295
|
}
|
|
413
296
|
|
|
414
|
-
channelOpen.enter =
|
|
297
|
+
channelOpen.enter = channel => {
|
|
415
298
|
changeStatus(channel, 'open');
|
|
416
299
|
};
|
|
417
300
|
|
|
418
|
-
export function awaitingOffChainTx(
|
|
419
|
-
|
|
420
|
-
|
|
301
|
+
export async function awaitingOffChainTx(channel, message, state) {
|
|
302
|
+
if (message.method === 'channels.sign.update') {
|
|
303
|
+
const {
|
|
304
|
+
sign
|
|
305
|
+
} = state;
|
|
421
306
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
_context8.next = 17;
|
|
432
|
-
break;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
sign = state.sign;
|
|
436
|
-
|
|
437
|
-
if (!message.params.data.tx) {
|
|
438
|
-
_context8.next = 8;
|
|
439
|
-
break;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
_context8.next = 5;
|
|
443
|
-
return sign(message.params.data.tx, {
|
|
444
|
-
updates: message.params.data.updates
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
case 5:
|
|
448
|
-
_signedTx2 = _context8.sent;
|
|
449
|
-
send(channel, {
|
|
450
|
-
jsonrpc: '2.0',
|
|
451
|
-
method: 'channels.update',
|
|
452
|
-
params: {
|
|
453
|
-
tx: _signedTx2
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
return _context8.abrupt("return", {
|
|
457
|
-
handler: awaitingOffChainUpdate,
|
|
458
|
-
state: state
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
case 8:
|
|
462
|
-
_context8.next = 10;
|
|
463
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
464
|
-
return sign(tx, {
|
|
465
|
-
updates: message.params.data.updates
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
case 10:
|
|
470
|
-
signedTx = _context8.sent;
|
|
471
|
-
|
|
472
|
-
if (!(typeof signedTx === 'string')) {
|
|
473
|
-
_context8.next = 14;
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
send(channel, {
|
|
478
|
-
jsonrpc: '2.0',
|
|
479
|
-
method: 'channels.update',
|
|
480
|
-
params: {
|
|
481
|
-
signed_tx: signedTx
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
return _context8.abrupt("return", {
|
|
485
|
-
handler: awaitingOffChainUpdate,
|
|
486
|
-
state: state
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
case 14:
|
|
490
|
-
if (!(typeof signedTx === 'number')) {
|
|
491
|
-
_context8.next = 17;
|
|
492
|
-
break;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
send(channel, {
|
|
496
|
-
jsonrpc: '2.0',
|
|
497
|
-
method: 'channels.update',
|
|
498
|
-
params: {
|
|
499
|
-
error: signedTx
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
return _context8.abrupt("return", {
|
|
503
|
-
handler: awaitingOffChainTx,
|
|
504
|
-
state: state
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
case 17:
|
|
508
|
-
if (!(message.method === 'channels.error')) {
|
|
509
|
-
_context8.next = 20;
|
|
510
|
-
break;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
state.reject(new Error(message.data.message));
|
|
514
|
-
return _context8.abrupt("return", {
|
|
515
|
-
handler: channelOpen
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
case 20:
|
|
519
|
-
if (!message.error) {
|
|
520
|
-
_context8.next = 24;
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
_message$error$data = message.error.data, data = _message$error$data === void 0 ? [] : _message$error$data;
|
|
525
|
-
|
|
526
|
-
if (_findInstanceProperty(data).call(data, function (i) {
|
|
527
|
-
return i.code === 1001;
|
|
528
|
-
})) {
|
|
529
|
-
state.reject(new Error('Insufficient balance'));
|
|
530
|
-
} else if (_findInstanceProperty(data).call(data, function (i) {
|
|
531
|
-
return i.code === 1002;
|
|
532
|
-
})) {
|
|
533
|
-
state.reject(new Error('Amount cannot be negative'));
|
|
534
|
-
} else {
|
|
535
|
-
state.reject(new Error(message.error.message));
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
return _context8.abrupt("return", {
|
|
539
|
-
handler: channelOpen
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
case 24:
|
|
543
|
-
if (!(message.method === 'channels.conflict')) {
|
|
544
|
-
_context8.next = 27;
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
state.resolve({
|
|
549
|
-
accepted: false,
|
|
550
|
-
errorCode: message.params.data.error_code,
|
|
551
|
-
errorMessage: message.params.data.error_msg
|
|
552
|
-
});
|
|
553
|
-
return _context8.abrupt("return", {
|
|
554
|
-
handler: channelOpen
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
case 27:
|
|
558
|
-
if (!(message.method === 'channels.info')) {
|
|
559
|
-
_context8.next = 31;
|
|
560
|
-
break;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
if (!(message.params.data.event === 'aborted_update')) {
|
|
564
|
-
_context8.next = 31;
|
|
565
|
-
break;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
state.resolve({
|
|
569
|
-
accepted: false
|
|
570
|
-
});
|
|
571
|
-
return _context8.abrupt("return", {
|
|
572
|
-
handler: channelOpen
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
case 31:
|
|
576
|
-
return _context8.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
577
|
-
|
|
578
|
-
case 32:
|
|
579
|
-
case "end":
|
|
580
|
-
return _context8.stop();
|
|
307
|
+
if (message.params.data.tx) {
|
|
308
|
+
const signedTx = await sign(message.params.data.tx, {
|
|
309
|
+
updates: message.params.data.updates
|
|
310
|
+
});
|
|
311
|
+
send(channel, {
|
|
312
|
+
jsonrpc: '2.0',
|
|
313
|
+
method: 'channels.update',
|
|
314
|
+
params: {
|
|
315
|
+
tx: signedTx
|
|
581
316
|
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
317
|
+
});
|
|
318
|
+
return {
|
|
319
|
+
handler: awaitingOffChainUpdate,
|
|
320
|
+
state
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => sign(tx, {
|
|
325
|
+
updates: message.params.data.updates
|
|
326
|
+
}));
|
|
587
327
|
|
|
328
|
+
if (typeof signedTx === 'string') {
|
|
329
|
+
send(channel, {
|
|
330
|
+
jsonrpc: '2.0',
|
|
331
|
+
method: 'channels.update',
|
|
332
|
+
params: {
|
|
333
|
+
signed_tx: signedTx
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
return {
|
|
337
|
+
handler: awaitingOffChainUpdate,
|
|
338
|
+
state
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (typeof signedTx === 'number') {
|
|
343
|
+
send(channel, {
|
|
344
|
+
jsonrpc: '2.0',
|
|
345
|
+
method: 'channels.update',
|
|
346
|
+
params: {
|
|
347
|
+
error: signedTx
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
return {
|
|
351
|
+
handler: awaitingOffChainTx,
|
|
352
|
+
state
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (message.method === 'channels.error') {
|
|
358
|
+
state.reject(new Error(message.data.message));
|
|
359
|
+
return {
|
|
360
|
+
handler: channelOpen
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (message.error) {
|
|
365
|
+
const {
|
|
366
|
+
data = []
|
|
367
|
+
} = message.error;
|
|
368
|
+
|
|
369
|
+
if (data.find(i => i.code === 1001)) {
|
|
370
|
+
state.reject(new Error('Insufficient balance'));
|
|
371
|
+
} else if (data.find(i => i.code === 1002)) {
|
|
372
|
+
state.reject(new Error('Amount cannot be negative'));
|
|
373
|
+
} else {
|
|
374
|
+
state.reject(new Error(message.error.message));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
handler: channelOpen
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (message.method === 'channels.conflict') {
|
|
383
|
+
state.resolve({
|
|
384
|
+
accepted: false,
|
|
385
|
+
errorCode: message.params.data.error_code,
|
|
386
|
+
errorMessage: message.params.data.error_msg
|
|
387
|
+
});
|
|
388
|
+
return {
|
|
389
|
+
handler: channelOpen
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (message.method === 'channels.info') {
|
|
394
|
+
if (message.params.data.event === 'aborted_update') {
|
|
395
|
+
state.resolve({
|
|
396
|
+
accepted: false
|
|
397
|
+
});
|
|
398
|
+
return {
|
|
399
|
+
handler: channelOpen
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
405
|
+
}
|
|
588
406
|
export function awaitingOffChainUpdate(channel, message, state) {
|
|
589
407
|
if (message.method === 'channels.update') {
|
|
590
408
|
changeState(channel, message.params.data.state);
|
|
@@ -628,137 +446,83 @@ export function awaitingOffChainUpdate(channel, message, state) {
|
|
|
628
446
|
|
|
629
447
|
return handleUnexpectedMessage(channel, message, state);
|
|
630
448
|
}
|
|
631
|
-
export function awaitingTxSignRequest(
|
|
632
|
-
|
|
633
|
-
}
|
|
449
|
+
export async function awaitingTxSignRequest(channel, message, state) {
|
|
450
|
+
const [, tag] = message.method.match(/^channels\.sign\.([^.]+)$/) || [];
|
|
634
451
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
break;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
_context9.next = 5;
|
|
656
|
-
return options.get(channel).sign(tag, message.params.data.tx, {
|
|
657
|
-
updates: message.params.data.updates
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
case 5:
|
|
661
|
-
signedTx = _context9.sent;
|
|
662
|
-
|
|
663
|
-
if (!signedTx) {
|
|
664
|
-
_context9.next = 9;
|
|
665
|
-
break;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
send(channel, {
|
|
669
|
-
jsonrpc: '2.0',
|
|
670
|
-
method: "channels.".concat(tag),
|
|
671
|
-
params: {
|
|
672
|
-
tx: signedTx
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
return _context9.abrupt("return", {
|
|
676
|
-
handler: channelOpen
|
|
677
|
-
});
|
|
678
|
-
|
|
679
|
-
case 9:
|
|
680
|
-
_context9.next = 20;
|
|
681
|
-
break;
|
|
682
|
-
|
|
683
|
-
case 11:
|
|
684
|
-
_context9.next = 13;
|
|
685
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
686
|
-
return options.get(channel).sign(tag, tx, {
|
|
687
|
-
updates: message.params.data.updates
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
case 13:
|
|
692
|
-
_signedTx3 = _context9.sent;
|
|
693
|
-
|
|
694
|
-
if (!(typeof _signedTx3 === 'string')) {
|
|
695
|
-
_context9.next = 17;
|
|
696
|
-
break;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
send(channel, {
|
|
700
|
-
jsonrpc: '2.0',
|
|
701
|
-
method: "channels.".concat(tag),
|
|
702
|
-
params: {
|
|
703
|
-
signed_tx: _signedTx3
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
return _context9.abrupt("return", {
|
|
707
|
-
handler: channelOpen
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
case 17:
|
|
711
|
-
if (!(typeof _signedTx3 === 'number')) {
|
|
712
|
-
_context9.next = 20;
|
|
713
|
-
break;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
send(channel, {
|
|
717
|
-
jsonrpc: '2.0',
|
|
718
|
-
method: "channels.".concat(tag),
|
|
719
|
-
params: {
|
|
720
|
-
error: _signedTx3
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
return _context9.abrupt("return", {
|
|
724
|
-
handler: awaitingUpdateConflict,
|
|
725
|
-
state: state
|
|
726
|
-
});
|
|
727
|
-
|
|
728
|
-
case 20:
|
|
729
|
-
// soft-reject via competing update
|
|
730
|
-
send(channel, {
|
|
731
|
-
jsonrpc: '2.0',
|
|
732
|
-
method: 'channels.update.new',
|
|
733
|
-
params: {
|
|
734
|
-
from: generateKeyPair().publicKey,
|
|
735
|
-
to: generateKeyPair().publicKey,
|
|
736
|
-
amount: 1
|
|
737
|
-
}
|
|
738
|
-
});
|
|
739
|
-
return _context9.abrupt("return", {
|
|
740
|
-
handler: awaitingUpdateConflict,
|
|
741
|
-
state: state
|
|
742
|
-
});
|
|
743
|
-
|
|
744
|
-
case 22:
|
|
745
|
-
return _context9.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
746
|
-
|
|
747
|
-
case 23:
|
|
748
|
-
case "end":
|
|
749
|
-
return _context9.stop();
|
|
750
|
-
}
|
|
452
|
+
if (tag) {
|
|
453
|
+
if (message.params.data.tx) {
|
|
454
|
+
const signedTx = await options.get(channel).sign(tag, message.params.data.tx, {
|
|
455
|
+
updates: message.params.data.updates
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
if (signedTx) {
|
|
459
|
+
send(channel, {
|
|
460
|
+
jsonrpc: '2.0',
|
|
461
|
+
method: `channels.${tag}`,
|
|
462
|
+
params: {
|
|
463
|
+
tx: signedTx
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
return {
|
|
467
|
+
handler: channelOpen
|
|
468
|
+
};
|
|
751
469
|
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
}
|
|
470
|
+
} else {
|
|
471
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => options.get(channel).sign(tag, tx, {
|
|
472
|
+
updates: message.params.data.updates
|
|
473
|
+
}));
|
|
474
|
+
|
|
475
|
+
if (typeof signedTx === 'string') {
|
|
476
|
+
send(channel, {
|
|
477
|
+
jsonrpc: '2.0',
|
|
478
|
+
method: `channels.${tag}`,
|
|
479
|
+
params: {
|
|
480
|
+
signed_tx: signedTx
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
return {
|
|
484
|
+
handler: channelOpen
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (typeof signedTx === 'number') {
|
|
489
|
+
send(channel, {
|
|
490
|
+
jsonrpc: '2.0',
|
|
491
|
+
method: `channels.${tag}`,
|
|
492
|
+
params: {
|
|
493
|
+
error: signedTx
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
return {
|
|
497
|
+
handler: awaitingUpdateConflict,
|
|
498
|
+
state
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
} // soft-reject via competing update
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
send(channel, {
|
|
505
|
+
jsonrpc: '2.0',
|
|
506
|
+
method: 'channels.update.new',
|
|
507
|
+
params: {
|
|
508
|
+
from: generateKeyPair().publicKey,
|
|
509
|
+
to: generateKeyPair().publicKey,
|
|
510
|
+
amount: 1
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
return {
|
|
514
|
+
handler: awaitingUpdateConflict,
|
|
515
|
+
state
|
|
516
|
+
};
|
|
517
|
+
}
|
|
756
518
|
|
|
519
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
520
|
+
}
|
|
757
521
|
export function awaitingUpdateConflict(channel, message, state) {
|
|
758
522
|
if (message.error) {
|
|
759
523
|
return {
|
|
760
524
|
handler: awaitingUpdateConflict,
|
|
761
|
-
state
|
|
525
|
+
state
|
|
762
526
|
};
|
|
763
527
|
}
|
|
764
528
|
|
|
@@ -770,84 +534,45 @@ export function awaitingUpdateConflict(channel, message, state) {
|
|
|
770
534
|
|
|
771
535
|
return handleUnexpectedMessage(channel, message, state);
|
|
772
536
|
}
|
|
773
|
-
export function awaitingShutdownTx(
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
while (1) {
|
|
783
|
-
switch (_context10.prev = _context10.next) {
|
|
784
|
-
case 0:
|
|
785
|
-
if (!(message.method === 'channels.sign.shutdown_sign')) {
|
|
786
|
-
_context10.next = 12;
|
|
787
|
-
break;
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
if (!message.params.data.tx) {
|
|
791
|
-
_context10.next = 7;
|
|
792
|
-
break;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
_context10.next = 4;
|
|
796
|
-
return state.sign(message.params.data.tx);
|
|
797
|
-
|
|
798
|
-
case 4:
|
|
799
|
-
_signedTx4 = _context10.sent;
|
|
800
|
-
send(channel, {
|
|
801
|
-
jsonrpc: '2.0',
|
|
802
|
-
method: 'channels.shutdown_sign',
|
|
803
|
-
params: {
|
|
804
|
-
tx: _signedTx4
|
|
805
|
-
}
|
|
806
|
-
});
|
|
807
|
-
return _context10.abrupt("return", {
|
|
808
|
-
handler: awaitingShutdownOnChainTx,
|
|
809
|
-
state: state
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
case 7:
|
|
813
|
-
_context10.next = 9;
|
|
814
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
815
|
-
return state.sign(tx);
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
case 9:
|
|
819
|
-
signedTx = _context10.sent;
|
|
820
|
-
send(channel, {
|
|
821
|
-
jsonrpc: '2.0',
|
|
822
|
-
method: 'channels.shutdown_sign',
|
|
823
|
-
params: {
|
|
824
|
-
signed_tx: signedTx
|
|
825
|
-
}
|
|
826
|
-
});
|
|
827
|
-
return _context10.abrupt("return", {
|
|
828
|
-
handler: awaitingShutdownOnChainTx,
|
|
829
|
-
state: state
|
|
830
|
-
});
|
|
831
|
-
|
|
832
|
-
case 12:
|
|
833
|
-
return _context10.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
834
|
-
|
|
835
|
-
case 13:
|
|
836
|
-
case "end":
|
|
837
|
-
return _context10.stop();
|
|
537
|
+
export async function awaitingShutdownTx(channel, message, state) {
|
|
538
|
+
if (message.method === 'channels.sign.shutdown_sign') {
|
|
539
|
+
if (message.params.data.tx) {
|
|
540
|
+
const signedTx = await state.sign(message.params.data.tx);
|
|
541
|
+
send(channel, {
|
|
542
|
+
jsonrpc: '2.0',
|
|
543
|
+
method: 'channels.shutdown_sign',
|
|
544
|
+
params: {
|
|
545
|
+
tx: signedTx
|
|
838
546
|
}
|
|
547
|
+
});
|
|
548
|
+
return {
|
|
549
|
+
handler: awaitingShutdownOnChainTx,
|
|
550
|
+
state
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => state.sign(tx));
|
|
555
|
+
send(channel, {
|
|
556
|
+
jsonrpc: '2.0',
|
|
557
|
+
method: 'channels.shutdown_sign',
|
|
558
|
+
params: {
|
|
559
|
+
signed_tx: signedTx
|
|
839
560
|
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
561
|
+
});
|
|
562
|
+
return {
|
|
563
|
+
handler: awaitingShutdownOnChainTx,
|
|
564
|
+
state
|
|
565
|
+
};
|
|
566
|
+
}
|
|
844
567
|
|
|
568
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
569
|
+
}
|
|
845
570
|
export function awaitingShutdownOnChainTx(channel, message, state) {
|
|
846
571
|
if (message.method === 'channels.on_chain_tx') {
|
|
847
572
|
// state.resolve(message.params.data.tx)
|
|
848
573
|
return {
|
|
849
574
|
handler: channelClosed,
|
|
850
|
-
state
|
|
575
|
+
state
|
|
851
576
|
};
|
|
852
577
|
}
|
|
853
578
|
|
|
@@ -874,108 +599,64 @@ export function awaitingLeave(channel, message, state) {
|
|
|
874
599
|
|
|
875
600
|
return handleUnexpectedMessage(channel, message, state);
|
|
876
601
|
}
|
|
877
|
-
export function awaitingWithdrawTx(
|
|
878
|
-
|
|
879
|
-
|
|
602
|
+
export async function awaitingWithdrawTx(channel, message, state) {
|
|
603
|
+
if (message.method === 'channels.sign.withdraw_tx') {
|
|
604
|
+
const {
|
|
605
|
+
sign
|
|
606
|
+
} = state;
|
|
607
|
+
|
|
608
|
+
if (message.params.data.tx) {
|
|
609
|
+
const signedTx = await sign(message.params.data.tx, {
|
|
610
|
+
updates: message.params.data.updates
|
|
611
|
+
});
|
|
612
|
+
send(channel, {
|
|
613
|
+
jsonrpc: '2.0',
|
|
614
|
+
method: 'channels.withdraw_tx',
|
|
615
|
+
params: {
|
|
616
|
+
tx: signedTx
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
return {
|
|
620
|
+
handler: awaitingWithdrawCompletion,
|
|
621
|
+
state
|
|
622
|
+
};
|
|
623
|
+
}
|
|
880
624
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
break;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
sign = state.sign;
|
|
895
|
-
|
|
896
|
-
if (!message.params.data.tx) {
|
|
897
|
-
_context11.next = 8;
|
|
898
|
-
break;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
_context11.next = 5;
|
|
902
|
-
return sign(message.params.data.tx, {
|
|
903
|
-
updates: message.params.data.updates
|
|
904
|
-
});
|
|
905
|
-
|
|
906
|
-
case 5:
|
|
907
|
-
_signedTx5 = _context11.sent;
|
|
908
|
-
send(channel, {
|
|
909
|
-
jsonrpc: '2.0',
|
|
910
|
-
method: 'channels.withdraw_tx',
|
|
911
|
-
params: {
|
|
912
|
-
tx: _signedTx5
|
|
913
|
-
}
|
|
914
|
-
});
|
|
915
|
-
return _context11.abrupt("return", {
|
|
916
|
-
handler: awaitingWithdrawCompletion,
|
|
917
|
-
state: state
|
|
918
|
-
});
|
|
919
|
-
|
|
920
|
-
case 8:
|
|
921
|
-
_context11.next = 10;
|
|
922
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
923
|
-
return sign(tx, {
|
|
924
|
-
updates: message.params.data.updates
|
|
925
|
-
});
|
|
926
|
-
});
|
|
927
|
-
|
|
928
|
-
case 10:
|
|
929
|
-
signedTx = _context11.sent;
|
|
930
|
-
|
|
931
|
-
if (!(typeof signedTx === 'string')) {
|
|
932
|
-
_context11.next = 14;
|
|
933
|
-
break;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
send(channel, {
|
|
937
|
-
jsonrpc: '2.0',
|
|
938
|
-
method: 'channels.withdraw_tx',
|
|
939
|
-
params: {
|
|
940
|
-
signed_tx: signedTx
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
return _context11.abrupt("return", {
|
|
944
|
-
handler: awaitingWithdrawCompletion,
|
|
945
|
-
state: state
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
case 14:
|
|
949
|
-
if (!(typeof signedTx === 'number')) {
|
|
950
|
-
_context11.next = 17;
|
|
951
|
-
break;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
send(channel, {
|
|
955
|
-
jsonrpc: '2.0',
|
|
956
|
-
method: 'channels.withdraw_tx',
|
|
957
|
-
params: {
|
|
958
|
-
error: signedTx
|
|
959
|
-
}
|
|
960
|
-
});
|
|
961
|
-
return _context11.abrupt("return", {
|
|
962
|
-
handler: awaitingWithdrawCompletion,
|
|
963
|
-
state: state
|
|
964
|
-
});
|
|
965
|
-
|
|
966
|
-
case 17:
|
|
967
|
-
return _context11.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
968
|
-
|
|
969
|
-
case 18:
|
|
970
|
-
case "end":
|
|
971
|
-
return _context11.stop();
|
|
625
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => sign(tx, {
|
|
626
|
+
updates: message.params.data.updates
|
|
627
|
+
}));
|
|
628
|
+
|
|
629
|
+
if (typeof signedTx === 'string') {
|
|
630
|
+
send(channel, {
|
|
631
|
+
jsonrpc: '2.0',
|
|
632
|
+
method: 'channels.withdraw_tx',
|
|
633
|
+
params: {
|
|
634
|
+
signed_tx: signedTx
|
|
972
635
|
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
}
|
|
636
|
+
});
|
|
637
|
+
return {
|
|
638
|
+
handler: awaitingWithdrawCompletion,
|
|
639
|
+
state
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
if (typeof signedTx === 'number') {
|
|
644
|
+
send(channel, {
|
|
645
|
+
jsonrpc: '2.0',
|
|
646
|
+
method: 'channels.withdraw_tx',
|
|
647
|
+
params: {
|
|
648
|
+
error: signedTx
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
return {
|
|
652
|
+
handler: awaitingWithdrawCompletion,
|
|
653
|
+
state
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
}
|
|
978
657
|
|
|
658
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
659
|
+
}
|
|
979
660
|
export function awaitingWithdrawCompletion(channel, message, state) {
|
|
980
661
|
if (message.method === 'channels.on_chain_tx') {
|
|
981
662
|
if (state.onOnChainTx) {
|
|
@@ -984,15 +665,13 @@ export function awaitingWithdrawCompletion(channel, message, state) {
|
|
|
984
665
|
|
|
985
666
|
return {
|
|
986
667
|
handler: awaitingWithdrawCompletion,
|
|
987
|
-
state
|
|
668
|
+
state
|
|
988
669
|
};
|
|
989
670
|
}
|
|
990
671
|
|
|
991
672
|
if (message.method === 'channels.info') {
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
if (_includesInstanceProperty(_context2 = ['own_withdraw_locked', 'withdraw_locked']).call(_context2, message.params.data.event)) {
|
|
995
|
-
var callback = {
|
|
673
|
+
if (['own_withdraw_locked', 'withdraw_locked'].includes(message.params.data.event)) {
|
|
674
|
+
const callback = {
|
|
996
675
|
own_withdraw_locked: state.onOwnWithdrawLocked,
|
|
997
676
|
withdraw_locked: state.onWithdrawLocked
|
|
998
677
|
}[message.params.data.event];
|
|
@@ -1003,7 +682,7 @@ export function awaitingWithdrawCompletion(channel, message, state) {
|
|
|
1003
682
|
|
|
1004
683
|
return {
|
|
1005
684
|
handler: awaitingWithdrawCompletion,
|
|
1006
|
-
state
|
|
685
|
+
state
|
|
1007
686
|
};
|
|
1008
687
|
}
|
|
1009
688
|
}
|
|
@@ -1043,108 +722,64 @@ export function awaitingWithdrawCompletion(channel, message, state) {
|
|
|
1043
722
|
|
|
1044
723
|
return handleUnexpectedMessage(channel, message, state);
|
|
1045
724
|
}
|
|
1046
|
-
export function awaitingDepositTx(
|
|
1047
|
-
|
|
1048
|
-
|
|
725
|
+
export async function awaitingDepositTx(channel, message, state) {
|
|
726
|
+
if (message.method === 'channels.sign.deposit_tx') {
|
|
727
|
+
const {
|
|
728
|
+
sign
|
|
729
|
+
} = state;
|
|
730
|
+
|
|
731
|
+
if (message.params.data.tx) {
|
|
732
|
+
const signedTx = await sign(message.params.data.tx, {
|
|
733
|
+
updates: message.params.data.updates
|
|
734
|
+
});
|
|
735
|
+
send(channel, {
|
|
736
|
+
jsonrpc: '2.0',
|
|
737
|
+
method: 'channels.deposit_tx',
|
|
738
|
+
params: {
|
|
739
|
+
tx: signedTx
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
return {
|
|
743
|
+
handler: awaitingDepositCompletion,
|
|
744
|
+
state
|
|
745
|
+
};
|
|
746
|
+
}
|
|
1049
747
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
break;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
sign = state.sign;
|
|
1064
|
-
|
|
1065
|
-
if (!message.params.data.tx) {
|
|
1066
|
-
_context12.next = 8;
|
|
1067
|
-
break;
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
_context12.next = 5;
|
|
1071
|
-
return sign(message.params.data.tx, {
|
|
1072
|
-
updates: message.params.data.updates
|
|
1073
|
-
});
|
|
1074
|
-
|
|
1075
|
-
case 5:
|
|
1076
|
-
_signedTx6 = _context12.sent;
|
|
1077
|
-
send(channel, {
|
|
1078
|
-
jsonrpc: '2.0',
|
|
1079
|
-
method: 'channels.deposit_tx',
|
|
1080
|
-
params: {
|
|
1081
|
-
tx: _signedTx6
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
|
-
return _context12.abrupt("return", {
|
|
1085
|
-
handler: awaitingDepositCompletion,
|
|
1086
|
-
state: state
|
|
1087
|
-
});
|
|
1088
|
-
|
|
1089
|
-
case 8:
|
|
1090
|
-
_context12.next = 10;
|
|
1091
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
1092
|
-
return sign(tx, {
|
|
1093
|
-
updates: message.params.data.updates
|
|
1094
|
-
});
|
|
1095
|
-
});
|
|
1096
|
-
|
|
1097
|
-
case 10:
|
|
1098
|
-
signedTx = _context12.sent;
|
|
1099
|
-
|
|
1100
|
-
if (!(typeof signedTx === 'string')) {
|
|
1101
|
-
_context12.next = 14;
|
|
1102
|
-
break;
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
send(channel, {
|
|
1106
|
-
jsonrpc: '2.0',
|
|
1107
|
-
method: 'channels.deposit_tx',
|
|
1108
|
-
params: {
|
|
1109
|
-
signed_tx: signedTx
|
|
1110
|
-
}
|
|
1111
|
-
});
|
|
1112
|
-
return _context12.abrupt("return", {
|
|
1113
|
-
handler: awaitingDepositCompletion,
|
|
1114
|
-
state: state
|
|
1115
|
-
});
|
|
1116
|
-
|
|
1117
|
-
case 14:
|
|
1118
|
-
if (!(typeof signedTx === 'number')) {
|
|
1119
|
-
_context12.next = 17;
|
|
1120
|
-
break;
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
send(channel, {
|
|
1124
|
-
jsonrpc: '2.0',
|
|
1125
|
-
method: 'channels.deposit_tx',
|
|
1126
|
-
params: {
|
|
1127
|
-
error: signedTx
|
|
1128
|
-
}
|
|
1129
|
-
});
|
|
1130
|
-
return _context12.abrupt("return", {
|
|
1131
|
-
handler: awaitingDepositCompletion,
|
|
1132
|
-
state: state
|
|
1133
|
-
});
|
|
1134
|
-
|
|
1135
|
-
case 17:
|
|
1136
|
-
return _context12.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
1137
|
-
|
|
1138
|
-
case 18:
|
|
1139
|
-
case "end":
|
|
1140
|
-
return _context12.stop();
|
|
748
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => sign(tx, {
|
|
749
|
+
updates: message.params.data.updates
|
|
750
|
+
}));
|
|
751
|
+
|
|
752
|
+
if (typeof signedTx === 'string') {
|
|
753
|
+
send(channel, {
|
|
754
|
+
jsonrpc: '2.0',
|
|
755
|
+
method: 'channels.deposit_tx',
|
|
756
|
+
params: {
|
|
757
|
+
signed_tx: signedTx
|
|
1141
758
|
}
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
}
|
|
759
|
+
});
|
|
760
|
+
return {
|
|
761
|
+
handler: awaitingDepositCompletion,
|
|
762
|
+
state
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (typeof signedTx === 'number') {
|
|
767
|
+
send(channel, {
|
|
768
|
+
jsonrpc: '2.0',
|
|
769
|
+
method: 'channels.deposit_tx',
|
|
770
|
+
params: {
|
|
771
|
+
error: signedTx
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
return {
|
|
775
|
+
handler: awaitingDepositCompletion,
|
|
776
|
+
state
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
}
|
|
1147
780
|
|
|
781
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
782
|
+
}
|
|
1148
783
|
export function awaitingDepositCompletion(channel, message, state) {
|
|
1149
784
|
if (message.method === 'channels.on_chain_tx') {
|
|
1150
785
|
if (state.onOnChainTx) {
|
|
@@ -1153,15 +788,13 @@ export function awaitingDepositCompletion(channel, message, state) {
|
|
|
1153
788
|
|
|
1154
789
|
return {
|
|
1155
790
|
handler: awaitingDepositCompletion,
|
|
1156
|
-
state
|
|
791
|
+
state
|
|
1157
792
|
};
|
|
1158
793
|
}
|
|
1159
794
|
|
|
1160
795
|
if (message.method === 'channels.info') {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
if (_includesInstanceProperty(_context3 = ['own_deposit_locked', 'deposit_locked']).call(_context3, message.params.data.event)) {
|
|
1164
|
-
var callback = {
|
|
796
|
+
if (['own_deposit_locked', 'deposit_locked'].includes(message.params.data.event)) {
|
|
797
|
+
const callback = {
|
|
1165
798
|
own_deposit_locked: state.onOwnDepositLocked,
|
|
1166
799
|
deposit_locked: state.onDepositLocked
|
|
1167
800
|
}[message.params.data.event];
|
|
@@ -1172,7 +805,7 @@ export function awaitingDepositCompletion(channel, message, state) {
|
|
|
1172
805
|
|
|
1173
806
|
return {
|
|
1174
807
|
handler: awaitingDepositCompletion,
|
|
1175
|
-
state
|
|
808
|
+
state
|
|
1176
809
|
};
|
|
1177
810
|
}
|
|
1178
811
|
}
|
|
@@ -1212,106 +845,62 @@ export function awaitingDepositCompletion(channel, message, state) {
|
|
|
1212
845
|
|
|
1213
846
|
return handleUnexpectedMessage(channel, message, state);
|
|
1214
847
|
}
|
|
1215
|
-
export function awaitingNewContractTx(
|
|
1216
|
-
|
|
1217
|
-
|
|
848
|
+
export async function awaitingNewContractTx(channel, message, state) {
|
|
849
|
+
if (message.method === 'channels.sign.update') {
|
|
850
|
+
if (message.params.data.tx) {
|
|
851
|
+
const signedTx = await state.sign(message.params.data.tx);
|
|
852
|
+
send(channel, {
|
|
853
|
+
jsonrpc: '2.0',
|
|
854
|
+
method: 'channels.update',
|
|
855
|
+
params: {
|
|
856
|
+
tx: signedTx
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
return {
|
|
860
|
+
handler: awaitingNewContractCompletion,
|
|
861
|
+
state
|
|
862
|
+
};
|
|
863
|
+
}
|
|
1218
864
|
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
if (!(message.method === 'channels.sign.update')) {
|
|
1228
|
-
_context13.next = 16;
|
|
1229
|
-
break;
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
if (!message.params.data.tx) {
|
|
1233
|
-
_context13.next = 7;
|
|
1234
|
-
break;
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
_context13.next = 4;
|
|
1238
|
-
return state.sign(message.params.data.tx);
|
|
1239
|
-
|
|
1240
|
-
case 4:
|
|
1241
|
-
_signedTx7 = _context13.sent;
|
|
1242
|
-
send(channel, {
|
|
1243
|
-
jsonrpc: '2.0',
|
|
1244
|
-
method: 'channels.update',
|
|
1245
|
-
params: {
|
|
1246
|
-
tx: _signedTx7
|
|
1247
|
-
}
|
|
1248
|
-
});
|
|
1249
|
-
return _context13.abrupt("return", {
|
|
1250
|
-
handler: awaitingNewContractCompletion,
|
|
1251
|
-
state: state
|
|
1252
|
-
});
|
|
1253
|
-
|
|
1254
|
-
case 7:
|
|
1255
|
-
_context13.next = 9;
|
|
1256
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
1257
|
-
return state.sign(tx);
|
|
1258
|
-
});
|
|
1259
|
-
|
|
1260
|
-
case 9:
|
|
1261
|
-
signedTx = _context13.sent;
|
|
1262
|
-
|
|
1263
|
-
if (!(typeof signedTx === 'string')) {
|
|
1264
|
-
_context13.next = 13;
|
|
1265
|
-
break;
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
send(channel, {
|
|
1269
|
-
jsonrpc: '2.0',
|
|
1270
|
-
method: 'channels.update',
|
|
1271
|
-
params: {
|
|
1272
|
-
signed_tx: signedTx
|
|
1273
|
-
}
|
|
1274
|
-
});
|
|
1275
|
-
return _context13.abrupt("return", {
|
|
1276
|
-
handler: awaitingNewContractCompletion,
|
|
1277
|
-
state: state
|
|
1278
|
-
});
|
|
1279
|
-
|
|
1280
|
-
case 13:
|
|
1281
|
-
if (!(typeof signedTx === 'number')) {
|
|
1282
|
-
_context13.next = 16;
|
|
1283
|
-
break;
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
send(channel, {
|
|
1287
|
-
jsonrpc: '2.0',
|
|
1288
|
-
method: 'channels.update',
|
|
1289
|
-
params: {
|
|
1290
|
-
error: signedTx
|
|
1291
|
-
}
|
|
1292
|
-
});
|
|
1293
|
-
return _context13.abrupt("return", {
|
|
1294
|
-
handler: awaitingNewContractCompletion,
|
|
1295
|
-
state: state
|
|
1296
|
-
});
|
|
1297
|
-
|
|
1298
|
-
case 16:
|
|
1299
|
-
return _context13.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
1300
|
-
|
|
1301
|
-
case 17:
|
|
1302
|
-
case "end":
|
|
1303
|
-
return _context13.stop();
|
|
865
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => state.sign(tx));
|
|
866
|
+
|
|
867
|
+
if (typeof signedTx === 'string') {
|
|
868
|
+
send(channel, {
|
|
869
|
+
jsonrpc: '2.0',
|
|
870
|
+
method: 'channels.update',
|
|
871
|
+
params: {
|
|
872
|
+
signed_tx: signedTx
|
|
1304
873
|
}
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
}
|
|
874
|
+
});
|
|
875
|
+
return {
|
|
876
|
+
handler: awaitingNewContractCompletion,
|
|
877
|
+
state
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (typeof signedTx === 'number') {
|
|
882
|
+
send(channel, {
|
|
883
|
+
jsonrpc: '2.0',
|
|
884
|
+
method: 'channels.update',
|
|
885
|
+
params: {
|
|
886
|
+
error: signedTx
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
return {
|
|
890
|
+
handler: awaitingNewContractCompletion,
|
|
891
|
+
state
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
}
|
|
1310
895
|
|
|
896
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
897
|
+
}
|
|
1311
898
|
export function awaitingNewContractCompletion(channel, message, state) {
|
|
1312
899
|
if (message.method === 'channels.update') {
|
|
1313
|
-
|
|
1314
|
-
|
|
900
|
+
const {
|
|
901
|
+
round
|
|
902
|
+
} = unpackTx(message.params.data.state).tx.encodedTx.tx;
|
|
903
|
+
const owner = options.get(channel)[{
|
|
1315
904
|
initiator: 'initiatorId',
|
|
1316
905
|
responder: 'responderId'
|
|
1317
906
|
}[options.get(channel).role]];
|
|
@@ -1350,159 +939,81 @@ export function awaitingNewContractCompletion(channel, message, state) {
|
|
|
1350
939
|
|
|
1351
940
|
return handleUnexpectedMessage(channel, message, state);
|
|
1352
941
|
}
|
|
1353
|
-
export function awaitingCallContractUpdateTx(
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
case 0:
|
|
1365
|
-
if (!(message.method === 'channels.sign.update')) {
|
|
1366
|
-
_context14.next = 16;
|
|
1367
|
-
break;
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
if (!message.params.data.tx) {
|
|
1371
|
-
_context14.next = 7;
|
|
1372
|
-
break;
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
_context14.next = 4;
|
|
1376
|
-
return state.sign(message.params.data.tx, {
|
|
1377
|
-
updates: message.params.data.updates
|
|
1378
|
-
});
|
|
1379
|
-
|
|
1380
|
-
case 4:
|
|
1381
|
-
_signedTx8 = _context14.sent;
|
|
1382
|
-
send(channel, {
|
|
1383
|
-
jsonrpc: '2.0',
|
|
1384
|
-
method: 'channels.update',
|
|
1385
|
-
params: {
|
|
1386
|
-
tx: _signedTx8
|
|
1387
|
-
}
|
|
1388
|
-
});
|
|
1389
|
-
return _context14.abrupt("return", {
|
|
1390
|
-
handler: awaitingCallContractCompletion,
|
|
1391
|
-
state: state
|
|
1392
|
-
});
|
|
1393
|
-
|
|
1394
|
-
case 7:
|
|
1395
|
-
_context14.next = 9;
|
|
1396
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
1397
|
-
return state.sign(tx, {
|
|
1398
|
-
updates: message.params.data.updates
|
|
1399
|
-
});
|
|
1400
|
-
});
|
|
1401
|
-
|
|
1402
|
-
case 9:
|
|
1403
|
-
signedTx = _context14.sent;
|
|
1404
|
-
|
|
1405
|
-
if (!(typeof signedTx === 'string')) {
|
|
1406
|
-
_context14.next = 13;
|
|
1407
|
-
break;
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
send(channel, {
|
|
1411
|
-
jsonrpc: '2.0',
|
|
1412
|
-
method: 'channels.update',
|
|
1413
|
-
params: {
|
|
1414
|
-
signed_tx: signedTx
|
|
1415
|
-
}
|
|
1416
|
-
});
|
|
1417
|
-
return _context14.abrupt("return", {
|
|
1418
|
-
handler: awaitingCallContractCompletion,
|
|
1419
|
-
state: state
|
|
1420
|
-
});
|
|
1421
|
-
|
|
1422
|
-
case 13:
|
|
1423
|
-
if (!(typeof signedTx === 'number')) {
|
|
1424
|
-
_context14.next = 16;
|
|
1425
|
-
break;
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
send(channel, {
|
|
1429
|
-
jsonrpc: '2.0',
|
|
1430
|
-
method: 'channels.update',
|
|
1431
|
-
params: {
|
|
1432
|
-
error: signedTx
|
|
1433
|
-
}
|
|
1434
|
-
});
|
|
1435
|
-
return _context14.abrupt("return", {
|
|
1436
|
-
handler: awaitingCallContractCompletion,
|
|
1437
|
-
state: state
|
|
1438
|
-
});
|
|
1439
|
-
|
|
1440
|
-
case 16:
|
|
1441
|
-
return _context14.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
1442
|
-
|
|
1443
|
-
case 17:
|
|
1444
|
-
case "end":
|
|
1445
|
-
return _context14.stop();
|
|
942
|
+
export async function awaitingCallContractUpdateTx(channel, message, state) {
|
|
943
|
+
if (message.method === 'channels.sign.update') {
|
|
944
|
+
if (message.params.data.tx) {
|
|
945
|
+
const signedTx = await state.sign(message.params.data.tx, {
|
|
946
|
+
updates: message.params.data.updates
|
|
947
|
+
});
|
|
948
|
+
send(channel, {
|
|
949
|
+
jsonrpc: '2.0',
|
|
950
|
+
method: 'channels.update',
|
|
951
|
+
params: {
|
|
952
|
+
tx: signedTx
|
|
1446
953
|
}
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
}
|
|
954
|
+
});
|
|
955
|
+
return {
|
|
956
|
+
handler: awaitingCallContractCompletion,
|
|
957
|
+
state
|
|
958
|
+
};
|
|
959
|
+
}
|
|
1452
960
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
}
|
|
961
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => state.sign(tx, {
|
|
962
|
+
updates: message.params.data.updates
|
|
963
|
+
}));
|
|
1456
964
|
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
case 0:
|
|
1464
|
-
if (!(message.method === 'channels.sign.force_progress_tx')) {
|
|
1465
|
-
_context15.next = 6;
|
|
1466
|
-
break;
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
_context15.next = 3;
|
|
1470
|
-
return appendSignature(message.params.data.signed_tx, function (tx) {
|
|
1471
|
-
return state.sign(tx, {
|
|
1472
|
-
updates: message.params.data.updates
|
|
1473
|
-
});
|
|
1474
|
-
});
|
|
1475
|
-
|
|
1476
|
-
case 3:
|
|
1477
|
-
signedTx = _context15.sent;
|
|
1478
|
-
send(channel, {
|
|
1479
|
-
jsonrpc: '2.0',
|
|
1480
|
-
method: 'channels.force_progress_sign',
|
|
1481
|
-
params: {
|
|
1482
|
-
signed_tx: signedTx
|
|
1483
|
-
}
|
|
1484
|
-
});
|
|
1485
|
-
return _context15.abrupt("return", {
|
|
1486
|
-
handler: awaitingForceProgressCompletion,
|
|
1487
|
-
state: state
|
|
1488
|
-
});
|
|
1489
|
-
|
|
1490
|
-
case 6:
|
|
1491
|
-
return _context15.abrupt("return", handleUnexpectedMessage(channel, message, state));
|
|
1492
|
-
|
|
1493
|
-
case 7:
|
|
1494
|
-
case "end":
|
|
1495
|
-
return _context15.stop();
|
|
965
|
+
if (typeof signedTx === 'string') {
|
|
966
|
+
send(channel, {
|
|
967
|
+
jsonrpc: '2.0',
|
|
968
|
+
method: 'channels.update',
|
|
969
|
+
params: {
|
|
970
|
+
signed_tx: signedTx
|
|
1496
971
|
}
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
972
|
+
});
|
|
973
|
+
return {
|
|
974
|
+
handler: awaitingCallContractCompletion,
|
|
975
|
+
state
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
if (typeof signedTx === 'number') {
|
|
980
|
+
send(channel, {
|
|
981
|
+
jsonrpc: '2.0',
|
|
982
|
+
method: 'channels.update',
|
|
983
|
+
params: {
|
|
984
|
+
error: signedTx
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
return {
|
|
988
|
+
handler: awaitingCallContractCompletion,
|
|
989
|
+
state
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
1501
995
|
}
|
|
996
|
+
export async function awaitingCallContractForceProgressUpdate(channel, message, state) {
|
|
997
|
+
if (message.method === 'channels.sign.force_progress_tx') {
|
|
998
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, tx => state.sign(tx, {
|
|
999
|
+
updates: message.params.data.updates
|
|
1000
|
+
}));
|
|
1001
|
+
send(channel, {
|
|
1002
|
+
jsonrpc: '2.0',
|
|
1003
|
+
method: 'channels.force_progress_sign',
|
|
1004
|
+
params: {
|
|
1005
|
+
signed_tx: signedTx
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
return {
|
|
1009
|
+
handler: awaitingForceProgressCompletion,
|
|
1010
|
+
state
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1502
1013
|
|
|
1014
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
1015
|
+
}
|
|
1503
1016
|
export function awaitingForceProgressCompletion(channel, message, state) {
|
|
1504
|
-
console.log('From force progress await completion ->', message);
|
|
1505
|
-
|
|
1506
1017
|
if (message.method === 'channels.on_chain_tx') {
|
|
1507
1018
|
if (state.onOnChainTx) {
|
|
1508
1019
|
state.onOnChainTx(message.params.data);
|
|
@@ -1575,14 +1086,14 @@ export function channelClosed(channel, message, state) {
|
|
|
1575
1086
|
};
|
|
1576
1087
|
if (message.params.data.event === 'closing') return {
|
|
1577
1088
|
handler: channelClosed,
|
|
1578
|
-
state
|
|
1089
|
+
state
|
|
1579
1090
|
};
|
|
1580
1091
|
|
|
1581
1092
|
if (message.params.data.info === 'channel_closed') {
|
|
1582
1093
|
state.closeTx = message.params.data.tx;
|
|
1583
1094
|
return {
|
|
1584
1095
|
handler: channelClosed,
|
|
1585
|
-
state
|
|
1096
|
+
state
|
|
1586
1097
|
};
|
|
1587
1098
|
}
|
|
1588
1099
|
|
|
@@ -1595,7 +1106,7 @@ export function channelClosed(channel, message, state) {
|
|
|
1595
1106
|
|
|
1596
1107
|
return {
|
|
1597
1108
|
handler: channelClosed,
|
|
1598
|
-
state
|
|
1109
|
+
state
|
|
1599
1110
|
};
|
|
1600
1111
|
}
|
|
1601
1112
|
//# sourceMappingURL=handlers.js.map
|