@aeternity/aepp-sdk 9.0.1 → 11.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.
Files changed (284) hide show
  1. package/README.md +15 -14
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/account/base.mjs +179 -0
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/memory.mjs +99 -0
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/multiple.mjs +179 -0
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/aens.mjs +404 -0
  16. package/es/ae/aens.mjs.map +1 -0
  17. package/es/ae/{aepp.js → aepp.mjs} +9 -9
  18. package/es/ae/aepp.mjs.map +1 -0
  19. package/es/ae/contract.mjs +159 -0
  20. package/es/ae/contract.mjs.map +1 -0
  21. package/es/ae/index.mjs +207 -0
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/oracle.mjs +339 -0
  24. package/es/ae/oracle.mjs.map +1 -0
  25. package/es/ae/{universal.js → universal.mjs} +10 -10
  26. package/es/ae/universal.mjs.map +1 -0
  27. package/es/ae/{wallet.js → wallet.mjs} +10 -10
  28. package/es/ae/wallet.mjs.map +1 -0
  29. package/es/aepp-wallet-communication/schema.d.ts +74 -0
  30. package/es/bignumber.d.ts +1 -7
  31. package/es/chain/{index.js → index.mjs} +29 -9
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/node.mjs +442 -0
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/handlers.mjs +1110 -0
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +245 -472
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/internal.mjs +283 -0
  40. package/es/channel/internal.mjs.map +1 -0
  41. package/es/contract/aci.mjs +477 -0
  42. package/es/contract/aci.mjs.map +1 -0
  43. package/es/contract/compiler.mjs +115 -0
  44. package/es/contract/compiler.mjs.map +1 -0
  45. package/es/contract/ga/helpers.mjs +30 -0
  46. package/es/contract/ga/helpers.mjs.map +1 -0
  47. package/es/contract/ga/index.mjs +178 -0
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/errors.d.ts +284 -0
  50. package/es/index.mjs +57 -0
  51. package/es/index.mjs.map +1 -0
  52. package/es/node-pool/index.mjs +188 -0
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/node.mjs +133 -0
  55. package/es/node.mjs.map +1 -0
  56. package/es/other.d.ts +1 -1
  57. package/es/tx/builder/field-types.mjs +74 -0
  58. package/es/tx/builder/field-types.mjs.map +1 -0
  59. package/es/tx/builder/helpers.mjs +363 -0
  60. package/es/tx/builder/helpers.mjs.map +1 -0
  61. package/es/tx/builder/index.mjs +606 -0
  62. package/es/tx/builder/index.mjs.map +1 -0
  63. package/es/tx/builder/schema.mjs +760 -0
  64. package/es/tx/builder/schema.mjs.map +1 -0
  65. package/es/tx/{index.js → index.mjs} +107 -15
  66. package/es/tx/index.mjs.map +1 -0
  67. package/es/tx/tx-object.mjs +283 -0
  68. package/es/tx/tx-object.mjs.map +1 -0
  69. package/es/tx/tx.mjs +938 -0
  70. package/es/tx/tx.mjs.map +1 -0
  71. package/es/tx/validator.mjs +247 -0
  72. package/es/tx/validator.mjs.map +1 -0
  73. package/es/typings/blakejs/index.d.mjs +2 -0
  74. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  75. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
  76. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
  78. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  80. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
  82. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
  84. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
  86. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
  88. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
  90. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  92. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
  94. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  95. package/es/utils/amount-formatter.mjs +139 -0
  96. package/es/utils/amount-formatter.mjs.map +1 -0
  97. package/es/utils/async-init.mjs +64 -0
  98. package/es/utils/async-init.mjs.map +1 -0
  99. package/es/utils/bignumber.mjs +21 -0
  100. package/es/utils/bignumber.mjs.map +1 -0
  101. package/es/utils/{bytes.js → bytes.mjs} +16 -12
  102. package/es/utils/bytes.mjs.map +1 -0
  103. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  104. package/es/utils/crypto-ts.mjs.map +1 -0
  105. package/es/utils/crypto.mjs +239 -0
  106. package/es/utils/crypto.mjs.map +1 -0
  107. package/es/utils/errors.mjs +689 -0
  108. package/es/utils/errors.mjs.map +1 -0
  109. package/es/utils/hd-wallet.mjs +111 -0
  110. package/es/utils/hd-wallet.mjs.map +1 -0
  111. package/es/utils/json-big.mjs +45 -0
  112. package/es/utils/json-big.mjs.map +1 -0
  113. package/es/utils/keystore.mjs +240 -0
  114. package/es/utils/keystore.mjs.map +1 -0
  115. package/es/utils/mptree.mjs +161 -0
  116. package/es/utils/mptree.mjs.map +1 -0
  117. package/es/utils/other.mjs +43 -0
  118. package/es/utils/other.mjs.map +1 -0
  119. package/es/utils/semver-satisfies.mjs +16 -0
  120. package/es/utils/semver-satisfies.mjs.map +1 -0
  121. package/es/utils/{string.js → string.mjs} +5 -14
  122. package/es/utils/string.mjs.map +1 -0
  123. package/es/utils/swagger.mjs +164 -0
  124. package/es/utils/swagger.mjs.map +1 -0
  125. package/package.json +55 -62
  126. package/src/account/base.js +3 -1
  127. package/src/account/memory.js +13 -8
  128. package/src/account/multiple.js +31 -22
  129. package/src/ae/aens.js +75 -77
  130. package/src/ae/aepp.js +2 -2
  131. package/src/ae/contract.js +27 -291
  132. package/src/ae/index.js +9 -7
  133. package/src/ae/oracle.js +51 -28
  134. package/src/ae/universal.js +4 -2
  135. package/src/ae/wallet.js +2 -2
  136. package/src/chain/index.js +29 -6
  137. package/src/chain/node.js +95 -67
  138. package/src/channel/handlers.js +30 -21
  139. package/src/channel/index.js +44 -20
  140. package/src/channel/internal.js +30 -24
  141. package/src/contract/aci.js +376 -0
  142. package/src/contract/compiler.js +41 -91
  143. package/src/contract/ga/helpers.js +10 -13
  144. package/src/contract/ga/index.js +42 -33
  145. package/src/index.js +9 -10
  146. package/src/node-pool/index.js +29 -17
  147. package/src/node.js +33 -36
  148. package/src/tx/builder/field-types.js +61 -0
  149. package/src/tx/builder/helpers.js +126 -84
  150. package/src/tx/builder/index.js +83 -41
  151. package/src/tx/builder/schema.js +50 -40
  152. package/src/tx/index.js +101 -12
  153. package/src/tx/tx-object.js +35 -15
  154. package/src/tx/tx.js +232 -153
  155. package/src/tx/validator.js +34 -12
  156. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  157. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  158. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  159. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  160. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  161. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
  162. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  163. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
  164. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  165. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  166. package/src/utils/amount-formatter.ts +4 -3
  167. package/src/utils/async-init.js +10 -6
  168. package/src/utils/bignumber.ts +3 -10
  169. package/src/utils/bytes.ts +3 -2
  170. package/src/utils/crypto-ts.ts +2 -2
  171. package/src/utils/crypto.js +10 -144
  172. package/src/utils/errors.ts +683 -0
  173. package/src/utils/hd-wallet.js +11 -26
  174. package/src/utils/keystore.js +57 -53
  175. package/src/utils/mptree.ts +12 -6
  176. package/src/utils/other.ts +1 -1
  177. package/src/utils/semver-satisfies.ts +1 -1
  178. package/src/utils/swagger.js +75 -45
  179. package/es/account/base.js +0 -259
  180. package/es/account/base.js.map +0 -1
  181. package/es/account/memory.js +0 -86
  182. package/es/account/memory.js.map +0 -1
  183. package/es/account/multiple.js +0 -267
  184. package/es/account/multiple.js.map +0 -1
  185. package/es/ae/aens.js +0 -829
  186. package/es/ae/aens.js.map +0 -1
  187. package/es/ae/aepp.js.map +0 -1
  188. package/es/ae/contract.js +0 -985
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js +0 -442
  191. package/es/ae/index.js.map +0 -1
  192. package/es/ae/oracle.js +0 -690
  193. package/es/ae/oracle.js.map +0 -1
  194. package/es/ae/universal.js.map +0 -1
  195. package/es/ae/wallet.js.map +0 -1
  196. package/es/chain/index.js.map +0 -1
  197. package/es/chain/node.js +0 -1119
  198. package/es/chain/node.js.map +0 -1
  199. package/es/channel/handlers.js +0 -1601
  200. package/es/channel/handlers.js.map +0 -1
  201. package/es/channel/index.js.map +0 -1
  202. package/es/channel/internal.js +0 -438
  203. package/es/channel/internal.js.map +0 -1
  204. package/es/contract/aci/helpers.js +0 -298
  205. package/es/contract/aci/helpers.js.map +0 -1
  206. package/es/contract/aci/index.js +0 -517
  207. package/es/contract/aci/index.js.map +0 -1
  208. package/es/contract/aci/transformation.js +0 -742
  209. package/es/contract/aci/transformation.js.map +0 -1
  210. package/es/contract/compiler.js +0 -316
  211. package/es/contract/compiler.js.map +0 -1
  212. package/es/contract/ga/helpers.js +0 -120
  213. package/es/contract/ga/helpers.js.map +0 -1
  214. package/es/contract/ga/index.js +0 -307
  215. package/es/contract/ga/index.js.map +0 -1
  216. package/es/contract/index.js +0 -158
  217. package/es/contract/index.js.map +0 -1
  218. package/es/index.js +0 -57
  219. package/es/index.js.map +0 -1
  220. package/es/node-pool/index.js +0 -204
  221. package/es/node-pool/index.js.map +0 -1
  222. package/es/node.js +0 -228
  223. package/es/node.js.map +0 -1
  224. package/es/tx/builder/helpers.js +0 -355
  225. package/es/tx/builder/helpers.js.map +0 -1
  226. package/es/tx/builder/index.js +0 -686
  227. package/es/tx/builder/index.js.map +0 -1
  228. package/es/tx/builder/schema.js +0 -695
  229. package/es/tx/builder/schema.js.map +0 -1
  230. package/es/tx/index.js.map +0 -1
  231. package/es/tx/tx-object.js +0 -297
  232. package/es/tx/tx-object.js.map +0 -1
  233. package/es/tx/tx.js +0 -1757
  234. package/es/tx/tx.js.map +0 -1
  235. package/es/tx/validator.js +0 -344
  236. package/es/tx/validator.js.map +0 -1
  237. package/es/typings/blakejs/index.d.js +0 -2
  238. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  239. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
  240. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  241. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  242. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  243. package/es/utils/aepp-wallet-communication/helpers.js +0 -148
  244. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  245. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
  246. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  247. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
  248. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  249. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
  250. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  251. package/es/utils/aepp-wallet-communication/schema.js +0 -103
  252. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  253. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
  254. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  255. package/es/utils/amount-formatter.js +0 -152
  256. package/es/utils/amount-formatter.js.map +0 -1
  257. package/es/utils/async-init.js +0 -103
  258. package/es/utils/async-init.js.map +0 -1
  259. package/es/utils/bignumber.js +0 -36
  260. package/es/utils/bignumber.js.map +0 -1
  261. package/es/utils/bytes.js.map +0 -1
  262. package/es/utils/crypto-ts.js.map +0 -1
  263. package/es/utils/crypto.js +0 -358
  264. package/es/utils/crypto.js.map +0 -1
  265. package/es/utils/hd-wallet.js +0 -148
  266. package/es/utils/hd-wallet.js.map +0 -1
  267. package/es/utils/json-big.js +0 -78
  268. package/es/utils/json-big.js.map +0 -1
  269. package/es/utils/keystore.js +0 -393
  270. package/es/utils/keystore.js.map +0 -1
  271. package/es/utils/mptree.js +0 -198
  272. package/es/utils/mptree.js.map +0 -1
  273. package/es/utils/other.js +0 -93
  274. package/es/utils/other.js.map +0 -1
  275. package/es/utils/semver-satisfies.js +0 -35
  276. package/es/utils/semver-satisfies.js.map +0 -1
  277. package/es/utils/string.js.map +0 -1
  278. package/es/utils/swagger.js +0 -269
  279. package/es/utils/swagger.js.map +0 -1
  280. package/src/contract/aci/helpers.js +0 -140
  281. package/src/contract/aci/index.js +0 -191
  282. package/src/contract/aci/transformation.js +0 -464
  283. package/src/contract/index.js +0 -159
  284. package/src/utils/aepp-wallet-communication/schema.js +0 -110
@@ -1,1601 +0,0 @@
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
- /*
11
- * ISC License (ISC)
12
- * Copyright (c) 2018 aeternity developers
13
- *
14
- * Permission to use, copy, modify, and/or distribute this software for any
15
- * purpose with or without fee is hereby granted, provided that the above
16
- * copyright notice and this permission notice appear in all copies.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
- * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
- * PERFORMANCE OF THIS SOFTWARE.
25
- */
26
- import { generateKeyPair, encodeContractAddress, encodeBase64Check } from '../utils/crypto';
27
- import { options, changeStatus, changeState, call, send, emit, channelId, disconnect, fsmId } from './internal';
28
- import { unpackTx, buildTx } from '../tx/builder';
29
-
30
- function encodeRlpTx(rlpBinary) {
31
- return "tx_".concat(encodeBase64Check(rlpBinary));
32
- }
33
-
34
- function appendSignature(_x, _x2) {
35
- return _appendSignature.apply(this, arguments);
36
- }
37
-
38
- function _appendSignature() {
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);
75
- }
76
-
77
- function handleUnexpectedMessage(channel, message, state) {
78
- if (state && state.reject) {
79
- state.reject(_Object$assign(new Error("Unexpected message received:\n\n".concat(_JSON$stringify(message))), {
80
- wsMessage: message
81
- }));
82
- }
83
-
84
- return {
85
- handler: channelOpen
86
- };
87
- }
88
-
89
- export function awaitingConnection(channel, message, state) {
90
- if (message.method === 'channels.info') {
91
- var _context;
92
-
93
- if (_includesInstanceProperty(_context = ['channel_accept', 'funding_created']).call(_context, message.params.data.event)) {
94
- changeStatus(channel, {
95
- channel_accept: 'accepted',
96
- funding_created: 'halfSigned'
97
- }[message.params.data.event]);
98
- return {
99
- handler: awaitingChannelCreateTx
100
- };
101
- }
102
-
103
- if (message.params.data.event === 'channel_reestablished') {
104
- return {
105
- handler: awaitingOpenConfirmation
106
- };
107
- }
108
-
109
- if (message.params.data.event === 'fsm_up') {
110
- fsmId.set(channel, message.params.data.fsm_id);
111
- return {
112
- handler: awaitingConnection
113
- };
114
- }
115
-
116
- return {
117
- handler: awaitingConnection
118
- };
119
- }
120
-
121
- if (message.method === 'channels.error') {
122
- emit(channel, 'error', new Error(message.payload.message));
123
- return {
124
- handler: channelClosed
125
- };
126
- }
127
- }
128
- export function awaitingReconnection(_x3, _x4, _x5) {
129
- return _awaitingReconnection.apply(this, arguments);
130
- }
131
-
132
- function _awaitingReconnection() {
133
- _awaitingReconnection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(channel, message, state) {
134
- return _regeneratorRuntime.wrap(function _callee2$(_context5) {
135
- while (1) {
136
- switch (_context5.prev = _context5.next) {
137
- case 0:
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
- }
173
-
174
- export function awaitingChannelCreateTx(_x6, _x7, _x8) {
175
- return _awaitingChannelCreateTx.apply(this, arguments);
176
- }
177
-
178
- function _awaitingChannelCreateTx() {
179
- _awaitingChannelCreateTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(channel, message, state) {
180
- var tag, _signedTx, signedTx;
181
-
182
- return _regeneratorRuntime.wrap(function _callee3$(_context6) {
183
- while (1) {
184
- switch (_context6.prev = _context6.next) {
185
- case 0:
186
- tag = {
187
- initiator: 'initiator_sign',
188
- responder: 'responder_sign'
189
- }[options.get(channel).role];
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();
239
- }
240
- }
241
- }, _callee3);
242
- }));
243
- return _awaitingChannelCreateTx.apply(this, arguments);
244
- }
245
-
246
- export function awaitingOnChainTx(channel, message, state) {
247
- if (message.method === 'channels.on_chain_tx') {
248
- if (message.params.data.info === 'funding_signed' && options.get(channel).role === 'initiator') {
249
- return {
250
- handler: awaitingBlockInclusion
251
- };
252
- }
253
-
254
- if (message.params.data.info === 'funding_created' && options.get(channel).role === 'responder') {
255
- return {
256
- handler: awaitingBlockInclusion
257
- };
258
- }
259
- }
260
-
261
- if (message.method === 'channels.info' && message.params.data.event === 'funding_signed' && options.get(channel).role === 'initiator') {
262
- channelId.set(channel, message.params.channel_id);
263
- changeStatus(channel, 'signed');
264
- return {
265
- handler: awaitingOnChainTx
266
- };
267
- }
268
- }
269
- export function awaitingBlockInclusion(channel, message, state) {
270
- if (message.method === 'channels.info') {
271
- var handler = {
272
- funding_created: awaitingBlockInclusion,
273
- own_funding_locked: awaitingBlockInclusion,
274
- funding_locked: awaitingOpenConfirmation
275
- }[message.params.data.event];
276
-
277
- if (handler) {
278
- return {
279
- handler: handler
280
- };
281
- }
282
- }
283
-
284
- if (message.method === 'channels.on_chain_tx') {
285
- emit(channel, 'onChainTx', message.params.data.tx, {
286
- info: message.params.data.info,
287
- type: message.params.data.type
288
- });
289
- return {
290
- handler: awaitingBlockInclusion
291
- };
292
- }
293
- }
294
- export function awaitingOpenConfirmation(channel, message, state) {
295
- if (message.method === 'channels.info' && message.params.data.event === 'open') {
296
- channelId.set(channel, message.params.channel_id);
297
- return {
298
- handler: awaitingInitialState
299
- };
300
- }
301
- }
302
- export function awaitingInitialState(channel, message, state) {
303
- if (message.method === 'channels.update') {
304
- changeState(channel, message.params.data.state);
305
- return {
306
- handler: channelOpen
307
- };
308
- }
309
- }
310
- export function channelOpen(_x9, _x10, _x11) {
311
- return _channelOpen.apply(this, arguments);
312
- }
313
-
314
- function _channelOpen() {
315
- _channelOpen = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(channel, message, state) {
316
- return _regeneratorRuntime.wrap(function _callee4$(_context7) {
317
- while (1) {
318
- switch (_context7.prev = _context7.next) {
319
- case 0:
320
- _context7.t0 = message.method;
321
- _context7.next = _context7.t0 === 'channels.info' ? 3 : _context7.t0 === 'channels.on_chain_tx' ? 20 : _context7.t0 === 'channels.leave' ? 22 : _context7.t0 === 'channels.update' ? 23 : _context7.t0 === 'channels.sign.shutdown_sign_ack' ? 25 : 26;
322
- break;
323
-
324
- case 3:
325
- _context7.t1 = message.params.data.event;
326
- _context7.next = _context7.t1 === 'update' ? 6 : _context7.t1 === 'withdraw_created' ? 6 : _context7.t1 === 'deposit_created' ? 6 : _context7.t1 === 'own_withdraw_locked' ? 7 : _context7.t1 === 'withdraw_locked' ? 7 : _context7.t1 === 'own_deposit_locked' ? 7 : _context7.t1 === 'deposit_locked' ? 7 : _context7.t1 === 'peer_disconnected' ? 7 : _context7.t1 === 'channel_reestablished' ? 7 : _context7.t1 === 'open' ? 7 : _context7.t1 === 'fsm_up' ? 9 : _context7.t1 === 'timeout' ? 11 : _context7.t1 === 'close_mutual' ? 11 : _context7.t1 === 'closing' ? 12 : _context7.t1 === 'closed_confirmed' ? 14 : _context7.t1 === 'died' ? 16 : _context7.t1 === 'shutdown' ? 18 : 19;
327
- break;
328
-
329
- case 6:
330
- return _context7.abrupt("return", {
331
- handler: awaitingTxSignRequest
332
- });
333
-
334
- case 7:
335
- // TODO: Better handling of peer_disconnected event.
336
- //
337
- // We should enter intermediate state where offchain transactions
338
- // are blocked until channel is reestablished.
339
- emit(channel, message.params.data.event);
340
- return _context7.abrupt("return", {
341
- handler: channelOpen
342
- });
343
-
344
- case 9:
345
- fsmId.set(channel, message.params.data.fsm_id);
346
- return _context7.abrupt("return", {
347
- handler: channelOpen
348
- });
349
-
350
- case 11:
351
- return _context7.abrupt("return", {
352
- handler: channelOpen
353
- });
354
-
355
- case 12:
356
- changeStatus(channel, 'closing');
357
- return _context7.abrupt("return", {
358
- handler: channelOpen
359
- });
360
-
361
- case 14:
362
- changeStatus(channel, 'closed');
363
- return _context7.abrupt("return", {
364
- handler: channelClosed
365
- });
366
-
367
- case 16:
368
- changeStatus(channel, 'died');
369
- return _context7.abrupt("return", {
370
- handler: channelClosed
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
- }
408
- }
409
- }, _callee4);
410
- }));
411
- return _channelOpen.apply(this, arguments);
412
- }
413
-
414
- channelOpen.enter = function (channel) {
415
- changeStatus(channel, 'open');
416
- };
417
-
418
- export function awaitingOffChainTx(_x12, _x13, _x14) {
419
- return _awaitingOffChainTx.apply(this, arguments);
420
- }
421
-
422
- function _awaitingOffChainTx() {
423
- _awaitingOffChainTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(channel, message, state) {
424
- var sign, _signedTx2, signedTx, _message$error$data, data;
425
-
426
- return _regeneratorRuntime.wrap(function _callee5$(_context8) {
427
- while (1) {
428
- switch (_context8.prev = _context8.next) {
429
- case 0:
430
- if (!(message.method === 'channels.sign.update')) {
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();
581
- }
582
- }
583
- }, _callee5);
584
- }));
585
- return _awaitingOffChainTx.apply(this, arguments);
586
- }
587
-
588
- export function awaitingOffChainUpdate(channel, message, state) {
589
- if (message.method === 'channels.update') {
590
- changeState(channel, message.params.data.state);
591
- state.resolve({
592
- accepted: true,
593
- signedTx: message.params.data.state
594
- });
595
- return {
596
- handler: channelOpen
597
- };
598
- }
599
-
600
- if (message.method === 'channels.conflict') {
601
- state.resolve({
602
- accepted: false,
603
- errorCode: message.params.data.error_code,
604
- errorMessage: message.params.data.error_msg
605
- });
606
- return {
607
- handler: channelOpen
608
- };
609
- }
610
-
611
- if (message.method === 'channels.info') {
612
- if (message.params.data.event === 'aborted_update') {
613
- state.resolve({
614
- accepted: false
615
- });
616
- return {
617
- handler: channelOpen
618
- };
619
- }
620
- }
621
-
622
- if (message.error) {
623
- state.reject(new Error(message.error.message));
624
- return {
625
- handler: channelOpen
626
- };
627
- }
628
-
629
- return handleUnexpectedMessage(channel, message, state);
630
- }
631
- export function awaitingTxSignRequest(_x15, _x16, _x17) {
632
- return _awaitingTxSignRequest.apply(this, arguments);
633
- }
634
-
635
- function _awaitingTxSignRequest() {
636
- _awaitingTxSignRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(channel, message, state) {
637
- var _ref, _ref2, tag, signedTx, _signedTx3;
638
-
639
- return _regeneratorRuntime.wrap(function _callee6$(_context9) {
640
- while (1) {
641
- switch (_context9.prev = _context9.next) {
642
- case 0:
643
- _ref = message.method.match(/^channels\.sign\.([^.]+)$/) || [], _ref2 = _slicedToArray(_ref, 2), tag = _ref2[1];
644
-
645
- if (!tag) {
646
- _context9.next = 22;
647
- break;
648
- }
649
-
650
- if (!message.params.data.tx) {
651
- _context9.next = 11;
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
- }
751
- }
752
- }, _callee6);
753
- }));
754
- return _awaitingTxSignRequest.apply(this, arguments);
755
- }
756
-
757
- export function awaitingUpdateConflict(channel, message, state) {
758
- if (message.error) {
759
- return {
760
- handler: awaitingUpdateConflict,
761
- state: state
762
- };
763
- }
764
-
765
- if (message.method === 'channels.conflict') {
766
- return {
767
- handler: channelOpen
768
- };
769
- }
770
-
771
- return handleUnexpectedMessage(channel, message, state);
772
- }
773
- export function awaitingShutdownTx(_x18, _x19, _x20) {
774
- return _awaitingShutdownTx.apply(this, arguments);
775
- }
776
-
777
- function _awaitingShutdownTx() {
778
- _awaitingShutdownTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(channel, message, state) {
779
- var _signedTx4, signedTx;
780
-
781
- return _regeneratorRuntime.wrap(function _callee7$(_context10) {
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();
838
- }
839
- }
840
- }, _callee7);
841
- }));
842
- return _awaitingShutdownTx.apply(this, arguments);
843
- }
844
-
845
- export function awaitingShutdownOnChainTx(channel, message, state) {
846
- if (message.method === 'channels.on_chain_tx') {
847
- // state.resolve(message.params.data.tx)
848
- return {
849
- handler: channelClosed,
850
- state: state
851
- };
852
- }
853
-
854
- return handleUnexpectedMessage(channel, message, state);
855
- }
856
- export function awaitingLeave(channel, message, state) {
857
- if (message.method === 'channels.leave') {
858
- state.resolve({
859
- channelId: message.params.channel_id,
860
- signedTx: message.params.data.state
861
- });
862
- disconnect(channel);
863
- return {
864
- handler: channelClosed
865
- };
866
- }
867
-
868
- if (message.method === 'channels.error') {
869
- state.reject(new Error(message.data.message));
870
- return {
871
- handler: channelOpen
872
- };
873
- }
874
-
875
- return handleUnexpectedMessage(channel, message, state);
876
- }
877
- export function awaitingWithdrawTx(_x21, _x22, _x23) {
878
- return _awaitingWithdrawTx.apply(this, arguments);
879
- }
880
-
881
- function _awaitingWithdrawTx() {
882
- _awaitingWithdrawTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(channel, message, state) {
883
- var sign, _signedTx5, signedTx;
884
-
885
- return _regeneratorRuntime.wrap(function _callee8$(_context11) {
886
- while (1) {
887
- switch (_context11.prev = _context11.next) {
888
- case 0:
889
- if (!(message.method === 'channels.sign.withdraw_tx')) {
890
- _context11.next = 17;
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();
972
- }
973
- }
974
- }, _callee8);
975
- }));
976
- return _awaitingWithdrawTx.apply(this, arguments);
977
- }
978
-
979
- export function awaitingWithdrawCompletion(channel, message, state) {
980
- if (message.method === 'channels.on_chain_tx') {
981
- if (state.onOnChainTx) {
982
- state.onOnChainTx(message.params.data.tx);
983
- }
984
-
985
- return {
986
- handler: awaitingWithdrawCompletion,
987
- state: state
988
- };
989
- }
990
-
991
- if (message.method === 'channels.info') {
992
- var _context2;
993
-
994
- if (_includesInstanceProperty(_context2 = ['own_withdraw_locked', 'withdraw_locked']).call(_context2, message.params.data.event)) {
995
- var callback = {
996
- own_withdraw_locked: state.onOwnWithdrawLocked,
997
- withdraw_locked: state.onWithdrawLocked
998
- }[message.params.data.event];
999
-
1000
- if (callback) {
1001
- callback();
1002
- }
1003
-
1004
- return {
1005
- handler: awaitingWithdrawCompletion,
1006
- state: state
1007
- };
1008
- }
1009
- }
1010
-
1011
- if (message.method === 'channels.update') {
1012
- changeState(channel, message.params.data.state);
1013
- state.resolve({
1014
- accepted: true,
1015
- signedTx: message.params.data.state
1016
- });
1017
- return {
1018
- handler: channelOpen
1019
- };
1020
- }
1021
-
1022
- if (message.method === 'channels.conflict') {
1023
- state.resolve({
1024
- accepted: false,
1025
- errorCode: message.params.data.error_code,
1026
- errorMessage: message.params.data.error_msg
1027
- });
1028
- return {
1029
- handler: channelOpen
1030
- };
1031
- }
1032
-
1033
- if (message.method === 'channels.info') {
1034
- if (message.params.data.event === 'aborted_update') {
1035
- state.resolve({
1036
- accepted: false
1037
- });
1038
- return {
1039
- handler: channelOpen
1040
- };
1041
- }
1042
- }
1043
-
1044
- return handleUnexpectedMessage(channel, message, state);
1045
- }
1046
- export function awaitingDepositTx(_x24, _x25, _x26) {
1047
- return _awaitingDepositTx.apply(this, arguments);
1048
- }
1049
-
1050
- function _awaitingDepositTx() {
1051
- _awaitingDepositTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(channel, message, state) {
1052
- var sign, _signedTx6, signedTx;
1053
-
1054
- return _regeneratorRuntime.wrap(function _callee9$(_context12) {
1055
- while (1) {
1056
- switch (_context12.prev = _context12.next) {
1057
- case 0:
1058
- if (!(message.method === 'channels.sign.deposit_tx')) {
1059
- _context12.next = 17;
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();
1141
- }
1142
- }
1143
- }, _callee9);
1144
- }));
1145
- return _awaitingDepositTx.apply(this, arguments);
1146
- }
1147
-
1148
- export function awaitingDepositCompletion(channel, message, state) {
1149
- if (message.method === 'channels.on_chain_tx') {
1150
- if (state.onOnChainTx) {
1151
- state.onOnChainTx(message.params.data.tx);
1152
- }
1153
-
1154
- return {
1155
- handler: awaitingDepositCompletion,
1156
- state: state
1157
- };
1158
- }
1159
-
1160
- if (message.method === 'channels.info') {
1161
- var _context3;
1162
-
1163
- if (_includesInstanceProperty(_context3 = ['own_deposit_locked', 'deposit_locked']).call(_context3, message.params.data.event)) {
1164
- var callback = {
1165
- own_deposit_locked: state.onOwnDepositLocked,
1166
- deposit_locked: state.onDepositLocked
1167
- }[message.params.data.event];
1168
-
1169
- if (callback) {
1170
- callback();
1171
- }
1172
-
1173
- return {
1174
- handler: awaitingDepositCompletion,
1175
- state: state
1176
- };
1177
- }
1178
- }
1179
-
1180
- if (message.method === 'channels.update') {
1181
- changeState(channel, message.params.data.state);
1182
- state.resolve({
1183
- accepted: true,
1184
- signedTx: message.params.data.state
1185
- });
1186
- return {
1187
- handler: channelOpen
1188
- };
1189
- }
1190
-
1191
- if (message.method === 'channels.conflict') {
1192
- state.resolve({
1193
- accepted: false,
1194
- errorCode: message.params.data.error_code,
1195
- errorMessage: message.params.data.error_msg
1196
- });
1197
- return {
1198
- handler: channelOpen
1199
- };
1200
- }
1201
-
1202
- if (message.method === 'channels.info') {
1203
- if (message.params.data.event === 'aborted_update') {
1204
- state.resolve({
1205
- accepted: false
1206
- });
1207
- return {
1208
- handler: channelOpen
1209
- };
1210
- }
1211
- }
1212
-
1213
- return handleUnexpectedMessage(channel, message, state);
1214
- }
1215
- export function awaitingNewContractTx(_x27, _x28, _x29) {
1216
- return _awaitingNewContractTx.apply(this, arguments);
1217
- }
1218
-
1219
- function _awaitingNewContractTx() {
1220
- _awaitingNewContractTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(channel, message, state) {
1221
- var _signedTx7, signedTx;
1222
-
1223
- return _regeneratorRuntime.wrap(function _callee10$(_context13) {
1224
- while (1) {
1225
- switch (_context13.prev = _context13.next) {
1226
- case 0:
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();
1304
- }
1305
- }
1306
- }, _callee10);
1307
- }));
1308
- return _awaitingNewContractTx.apply(this, arguments);
1309
- }
1310
-
1311
- export function awaitingNewContractCompletion(channel, message, state) {
1312
- if (message.method === 'channels.update') {
1313
- var round = unpackTx(message.params.data.state).tx.encodedTx.tx.round;
1314
- var owner = options.get(channel)[{
1315
- initiator: 'initiatorId',
1316
- responder: 'responderId'
1317
- }[options.get(channel).role]];
1318
- changeState(channel, message.params.data.state);
1319
- state.resolve({
1320
- accepted: true,
1321
- address: encodeContractAddress(owner, round),
1322
- signedTx: message.params.data.state
1323
- });
1324
- return {
1325
- handler: channelOpen
1326
- };
1327
- }
1328
-
1329
- if (message.method === 'channels.conflict') {
1330
- state.resolve({
1331
- accepted: false,
1332
- errorCode: message.params.data.error_code,
1333
- errorMessage: message.params.data.error_msg
1334
- });
1335
- return {
1336
- handler: channelOpen
1337
- };
1338
- }
1339
-
1340
- if (message.method === 'channels.info') {
1341
- if (message.params.data.event === 'aborted_update') {
1342
- state.resolve({
1343
- accepted: false
1344
- });
1345
- return {
1346
- handler: channelOpen
1347
- };
1348
- }
1349
- }
1350
-
1351
- return handleUnexpectedMessage(channel, message, state);
1352
- }
1353
- export function awaitingCallContractUpdateTx(_x30, _x31, _x32) {
1354
- return _awaitingCallContractUpdateTx.apply(this, arguments);
1355
- }
1356
-
1357
- function _awaitingCallContractUpdateTx() {
1358
- _awaitingCallContractUpdateTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(channel, message, state) {
1359
- var _signedTx8, signedTx;
1360
-
1361
- return _regeneratorRuntime.wrap(function _callee11$(_context14) {
1362
- while (1) {
1363
- switch (_context14.prev = _context14.next) {
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();
1446
- }
1447
- }
1448
- }, _callee11);
1449
- }));
1450
- return _awaitingCallContractUpdateTx.apply(this, arguments);
1451
- }
1452
-
1453
- export function awaitingCallContractForceProgressUpdate(_x33, _x34, _x35) {
1454
- return _awaitingCallContractForceProgressUpdate.apply(this, arguments);
1455
- }
1456
-
1457
- function _awaitingCallContractForceProgressUpdate() {
1458
- _awaitingCallContractForceProgressUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(channel, message, state) {
1459
- var signedTx;
1460
- return _regeneratorRuntime.wrap(function _callee12$(_context15) {
1461
- while (1) {
1462
- switch (_context15.prev = _context15.next) {
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();
1496
- }
1497
- }
1498
- }, _callee12);
1499
- }));
1500
- return _awaitingCallContractForceProgressUpdate.apply(this, arguments);
1501
- }
1502
-
1503
- export function awaitingForceProgressCompletion(channel, message, state) {
1504
- console.log('From force progress await completion ->', message);
1505
-
1506
- if (message.method === 'channels.on_chain_tx') {
1507
- if (state.onOnChainTx) {
1508
- state.onOnChainTx(message.params.data);
1509
- }
1510
-
1511
- emit(channel, 'onChainTx', message.params.data.tx, {
1512
- info: message.params.data.info,
1513
- type: message.params.data.type
1514
- });
1515
- state.resolve({
1516
- accepted: true,
1517
- tx: message.params.data.tx
1518
- });
1519
- }
1520
-
1521
- return handleUnexpectedMessage(channel, message, state);
1522
- }
1523
- export function awaitingCallContractCompletion(channel, message, state) {
1524
- if (message.method === 'channels.update') {
1525
- changeState(channel, message.params.data.state);
1526
- state.resolve({
1527
- accepted: true,
1528
- signedTx: message.params.data.state
1529
- });
1530
- return {
1531
- handler: channelOpen
1532
- };
1533
- }
1534
-
1535
- if (message.method === 'channels.conflict') {
1536
- state.resolve({
1537
- accepted: false,
1538
- errorCode: message.params.data.error_code,
1539
- errorMessage: message.params.data.error_msg
1540
- });
1541
- return {
1542
- handler: channelOpen
1543
- };
1544
- }
1545
-
1546
- if (message.method === 'channels.info') {
1547
- if (message.params.data.event === 'aborted_update') {
1548
- state.resolve({
1549
- accepted: false
1550
- });
1551
- return {
1552
- handler: channelOpen
1553
- };
1554
- }
1555
- }
1556
-
1557
- return handleUnexpectedMessage(channel, message, state);
1558
- }
1559
- export function awaitingCallsPruned(channels, message, state) {
1560
- if (message.method === 'channels.calls_pruned.reply') {
1561
- state.resolve();
1562
- return {
1563
- handler: channelOpen
1564
- };
1565
- }
1566
-
1567
- state.reject(new Error('Unexpected message received'));
1568
- return {
1569
- handler: channelClosed
1570
- };
1571
- }
1572
- export function channelClosed(channel, message, state) {
1573
- if (!state) return {
1574
- handler: channelClosed
1575
- };
1576
- if (message.params.data.event === 'closing') return {
1577
- handler: channelClosed,
1578
- state: state
1579
- };
1580
-
1581
- if (message.params.data.info === 'channel_closed') {
1582
- state.closeTx = message.params.data.tx;
1583
- return {
1584
- handler: channelClosed,
1585
- state: state
1586
- };
1587
- }
1588
-
1589
- if (message.params.data.event === 'closed_confirmed') {
1590
- state.resolve(state.closeTx);
1591
- return {
1592
- handler: channelClosed
1593
- };
1594
- }
1595
-
1596
- return {
1597
- handler: channelClosed,
1598
- state: state
1599
- };
1600
- }
1601
- //# sourceMappingURL=handlers.js.map