@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.1

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 (145) hide show
  1. package/README.md +16 -9
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  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.js +33 -119
  10. package/es/account/base.js.map +1 -1
  11. package/es/account/memory.js +17 -19
  12. package/es/account/memory.js.map +1 -1
  13. package/es/account/multiple.js +75 -154
  14. package/es/account/multiple.js.map +1 -1
  15. package/es/ae/aens.js +164 -599
  16. package/es/ae/aens.js.map +1 -1
  17. package/es/ae/contract.js +108 -916
  18. package/es/ae/contract.js.map +1 -1
  19. package/es/ae/index.js +89 -250
  20. package/es/ae/index.js.map +1 -1
  21. package/es/ae/oracle.js +132 -500
  22. package/es/ae/oracle.js.map +1 -1
  23. package/es/chain/index.js +4 -23
  24. package/es/chain/index.js.map +1 -1
  25. package/es/chain/node.js +292 -1018
  26. package/es/chain/node.js.map +1 -1
  27. package/es/channel/handlers.js +597 -1086
  28. package/es/channel/handlers.js.map +1 -1
  29. package/es/channel/index.js +203 -451
  30. package/es/channel/index.js.map +1 -1
  31. package/es/channel/internal.js +129 -301
  32. package/es/channel/internal.js.map +1 -1
  33. package/es/contract/aci/index.js +319 -491
  34. package/es/contract/aci/index.js.map +1 -1
  35. package/es/contract/aci/transformation.js +35 -711
  36. package/es/contract/aci/transformation.js.map +1 -1
  37. package/es/contract/compiler.js +129 -203
  38. package/es/contract/compiler.js.map +1 -1
  39. package/es/contract/ga/helpers.js +17 -122
  40. package/es/contract/ga/helpers.js.map +1 -1
  41. package/es/contract/ga/index.js +102 -247
  42. package/es/contract/ga/index.js.map +1 -1
  43. package/es/contract/index.js +1 -1
  44. package/es/contract/index.js.map +1 -1
  45. package/es/index.js +2 -3
  46. package/es/index.js.map +1 -1
  47. package/es/node-pool/index.js +54 -73
  48. package/es/node-pool/index.js.map +1 -1
  49. package/es/node.js +56 -157
  50. package/es/node.js.map +1 -1
  51. package/es/other.d.ts +1 -1
  52. package/es/tx/builder/helpers.js +49 -89
  53. package/es/tx/builder/helpers.js.map +1 -1
  54. package/es/tx/builder/index.js +205 -303
  55. package/es/tx/builder/index.js.map +1 -1
  56. package/es/tx/builder/schema.js +585 -573
  57. package/es/tx/builder/schema.js.map +1 -1
  58. package/es/tx/index.js +1 -1
  59. package/es/tx/index.js.map +1 -1
  60. package/es/tx/tx-object.js +105 -135
  61. package/es/tx/tx-object.js.map +1 -1
  62. package/es/tx/tx.js +810 -1586
  63. package/es/tx/tx.js.map +1 -1
  64. package/es/tx/validator.js +191 -426
  65. package/es/tx/validator.js.map +1 -1
  66. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
  67. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  68. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
  69. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  70. package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
  71. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  72. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  73. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  74. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
  75. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  76. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
  77. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  78. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +354 -603
  79. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  80. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  81. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  82. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  83. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  84. package/es/utils/amount-formatter.js +41 -61
  85. package/es/utils/amount-formatter.js.map +1 -1
  86. package/es/utils/async-init.js +28 -64
  87. package/es/utils/async-init.js.map +1 -1
  88. package/es/utils/bignumber.js +3 -11
  89. package/es/utils/bignumber.js.map +1 -1
  90. package/es/utils/bytes.js +5 -9
  91. package/es/utils/bytes.js.map +1 -1
  92. package/es/utils/crypto.js +49 -75
  93. package/es/utils/crypto.js.map +1 -1
  94. package/es/utils/hd-wallet.js +45 -81
  95. package/es/utils/hd-wallet.js.map +1 -1
  96. package/es/utils/json-big.js +16 -49
  97. package/es/utils/json-big.js.map +1 -1
  98. package/es/utils/keystore.js +81 -246
  99. package/es/utils/keystore.js.map +1 -1
  100. package/es/utils/mptree.js +88 -134
  101. package/es/utils/mptree.js.map +1 -1
  102. package/es/utils/other.js +10 -60
  103. package/es/utils/other.js.map +1 -1
  104. package/es/utils/semver-satisfies.js +9 -28
  105. package/es/utils/semver-satisfies.js.map +1 -1
  106. package/es/utils/string.js +4 -13
  107. package/es/utils/string.js.map +1 -1
  108. package/es/utils/swagger.js +85 -218
  109. package/es/utils/swagger.js.map +1 -1
  110. package/package.json +52 -43
  111. package/src/account/base.js +8 -9
  112. package/src/account/multiple.js +20 -16
  113. package/src/ae/aens.js +25 -21
  114. package/src/ae/contract.js +65 -246
  115. package/src/ae/index.js +31 -7
  116. package/src/ae/oracle.js +21 -17
  117. package/src/chain/index.js +2 -12
  118. package/src/chain/node.js +26 -29
  119. package/src/channel/handlers.js +0 -1
  120. package/src/channel/index.js +4 -5
  121. package/src/contract/aci/index.js +221 -106
  122. package/src/contract/aci/transformation.js +30 -422
  123. package/src/contract/compiler.js +45 -4
  124. package/src/contract/ga/helpers.js +2 -12
  125. package/src/contract/ga/index.js +22 -26
  126. package/src/index.js +2 -4
  127. package/src/node-pool/index.js +21 -12
  128. package/src/node.js +22 -26
  129. package/src/tx/builder/helpers.js +12 -24
  130. package/src/tx/builder/index.js +18 -15
  131. package/src/tx/builder/schema.js +43 -108
  132. package/src/tx/tx-object.js +0 -2
  133. package/src/tx/tx.js +157 -144
  134. package/src/tx/validator.js +134 -202
  135. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
  136. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
  137. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  138. package/src/utils/amount-formatter.ts +1 -1
  139. package/src/utils/bignumber.ts +2 -1
  140. package/src/utils/crypto.js +4 -17
  141. package/src/utils/other.ts +1 -1
  142. package/src/utils/semver-satisfies.ts +1 -1
  143. package/src/utils/swagger.js +24 -7
  144. package/CHANGELOG.md +0 -1716
  145. package/src/contract/aci/helpers.js +0 -140
@@ -1,29 +1,3 @@
1
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
2
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
4
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
5
- import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
6
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
7
- import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
8
- import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
9
- import _reduce from "ramda/src/reduce";
10
- import _typeof from "@babel/runtime-corejs3/helpers/typeof";
11
- import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
12
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
13
- import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
14
- import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
15
-
16
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
-
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context10; _forEachInstanceProperty(_context10 = ownKeys(Object(source), true)).call(_context10, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context11; _forEachInstanceProperty(_context11 = ownKeys(Object(source))).call(_context11, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
-
20
- import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
21
- import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
22
- import _parseInt from "@babel/runtime-corejs3/core-js-stable/parse-int";
23
- import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
24
- import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
25
- import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
26
-
27
1
  /*
28
2
  * ISC License (ISC)
29
3
  * Copyright (c) 2018 aeternity developers
@@ -55,14 +29,11 @@ import * as handlers from './handlers';
55
29
  import { eventEmitters, status as channelStatus, state as channelState, initialize, enqueueAction, send, channelId, call, disconnect as channelDisconnect, fsmId as channelFsmId } from './internal';
56
30
 
57
31
  function snakeToPascalObjKeys(obj) {
58
- var _context;
59
-
60
- return _reduceInstanceProperty(_context = _Object$entries(obj)).call(_context, function (result, _ref) {
61
- var _ref2 = _slicedToArray(_ref, 2),
62
- key = _ref2[0],
63
- val = _ref2[1];
64
-
65
- return _objectSpread(_objectSpread({}, result), {}, _defineProperty({}, snakeToPascal(key), val));
32
+ return Object.entries(obj).reduce((result, _ref) => {
33
+ let [key, val] = _ref;
34
+ return { ...result,
35
+ [snakeToPascal(key)]: val
36
+ };
66
37
  }, {});
67
38
  }
68
39
  /**
@@ -121,8 +92,8 @@ function status() {
121
92
  */
122
93
 
123
94
 
124
- function state() {
125
- return _state.apply(this, arguments);
95
+ async function state() {
96
+ return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
126
97
  }
127
98
  /**
128
99
  * Get current round
@@ -134,40 +105,17 @@ function state() {
134
105
  */
135
106
 
136
107
 
137
- function _state() {
138
- _state = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
139
- return _regeneratorRuntime.wrap(function _callee2$(_context3) {
140
- while (1) {
141
- switch (_context3.prev = _context3.next) {
142
- case 0:
143
- _context3.t0 = snakeToPascalObjKeys;
144
- _context3.next = 3;
145
- return call(this, 'channels.get.offchain_state', {});
146
-
147
- case 3:
148
- _context3.t1 = _context3.sent;
149
- return _context3.abrupt("return", (0, _context3.t0)(_context3.t1));
150
-
151
- case 5:
152
- case "end":
153
- return _context3.stop();
154
- }
155
- }
156
- }, _callee2, this);
157
- }));
158
- return _state.apply(this, arguments);
159
- }
160
-
161
108
  function round() {
162
- var state = channelState.get(this);
109
+ const state = channelState.get(this);
163
110
 
164
111
  if (!state) {
165
112
  return null;
166
113
  }
167
114
 
168
- var _unpackTx$tx$encodedT = unpackTx(channelState.get(this)).tx.encodedTx,
169
- txType = _unpackTx$tx$encodedT.txType,
170
- tx = _unpackTx$tx$encodedT.tx;
115
+ const {
116
+ txType,
117
+ tx
118
+ } = unpackTx(channelState.get(this)).tx.encodedTx;
171
119
 
172
120
  switch (txType) {
173
121
  case TX_TYPE.channelCreate:
@@ -176,7 +124,7 @@ function round() {
176
124
  case TX_TYPE.channelOffChain:
177
125
  case TX_TYPE.channelWithdraw:
178
126
  case TX_TYPE.channelDeposit:
179
- return _parseInt(tx.round, 10);
127
+ return parseInt(tx.round, 10);
180
128
 
181
129
  default:
182
130
  return null;
@@ -231,28 +179,24 @@ function fsmId() {
231
179
 
232
180
 
233
181
  function update(from, to, amount, sign, metadata) {
234
- var _this = this;
235
-
236
- return new _Promise(function (resolve, reject) {
237
- enqueueAction(_this, function (channel, state) {
238
- return state.handler === handlers.channelOpen;
239
- }, function (channel, state) {
182
+ return new Promise((resolve, reject) => {
183
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
240
184
  send(channel, {
241
185
  jsonrpc: '2.0',
242
186
  method: 'channels.update.new',
243
187
  params: {
244
- from: from,
245
- to: to,
246
- amount: amount,
188
+ from,
189
+ to,
190
+ amount,
247
191
  meta: metadata
248
192
  }
249
193
  });
250
194
  return {
251
195
  handler: handlers.awaitingOffChainTx,
252
196
  state: {
253
- resolve: resolve,
254
- reject: reject,
255
- sign: sign
197
+ resolve,
198
+ reject,
199
+ sign
256
200
  }
257
201
  };
258
202
  });
@@ -278,8 +222,15 @@ function update(from, to, amount, sign, metadata) {
278
222
  */
279
223
 
280
224
 
281
- function poi(_x) {
282
- return _poi.apply(this, arguments);
225
+ async function poi(_ref2) {
226
+ let {
227
+ accounts,
228
+ contracts
229
+ } = _ref2;
230
+ return (await call(this, 'channels.get.poi', {
231
+ accounts,
232
+ contracts
233
+ })).poi;
283
234
  }
284
235
  /**
285
236
  * Get balances
@@ -302,35 +253,10 @@ function poi(_x) {
302
253
  */
303
254
 
304
255
 
305
- function _poi() {
306
- _poi = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref3) {
307
- var accounts, contracts;
308
- return _regeneratorRuntime.wrap(function _callee3$(_context4) {
309
- while (1) {
310
- switch (_context4.prev = _context4.next) {
311
- case 0:
312
- accounts = _ref3.accounts, contracts = _ref3.contracts;
313
- _context4.next = 3;
314
- return call(this, 'channels.get.poi', {
315
- accounts: accounts,
316
- contracts: contracts
317
- });
318
-
319
- case 3:
320
- return _context4.abrupt("return", _context4.sent.poi);
321
-
322
- case 4:
323
- case "end":
324
- return _context4.stop();
325
- }
326
- }
327
- }, _callee3, this);
328
- }));
329
- return _poi.apply(this, arguments);
330
- }
331
-
332
- function balances(_x2) {
333
- return _balances.apply(this, arguments);
256
+ async function balances(accounts) {
257
+ return Object.fromEntries((await call(this, 'channels.get.balances', {
258
+ accounts
259
+ })).map(item => [item.account, item.balance]));
334
260
  }
335
261
  /**
336
262
  * Leave channel
@@ -352,45 +278,9 @@ function balances(_x2) {
352
278
  */
353
279
 
354
280
 
355
- function _balances() {
356
- _balances = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(accounts) {
357
- return _regeneratorRuntime.wrap(function _callee4$(_context5) {
358
- while (1) {
359
- switch (_context5.prev = _context5.next) {
360
- case 0:
361
- _context5.t0 = _reduce;
362
-
363
- _context5.t1 = function (acc, item) {
364
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, item.account, item.balance));
365
- };
366
-
367
- _context5.t2 = {};
368
- _context5.next = 5;
369
- return call(this, 'channels.get.balances', {
370
- accounts: accounts
371
- });
372
-
373
- case 5:
374
- _context5.t3 = _context5.sent;
375
- return _context5.abrupt("return", (0, _context5.t0)(_context5.t1, _context5.t2, _context5.t3));
376
-
377
- case 7:
378
- case "end":
379
- return _context5.stop();
380
- }
381
- }
382
- }, _callee4, this);
383
- }));
384
- return _balances.apply(this, arguments);
385
- }
386
-
387
281
  function leave() {
388
- var _this2 = this;
389
-
390
- return new _Promise(function (resolve, reject) {
391
- enqueueAction(_this2, function (channel, state) {
392
- return state.handler === handlers.channelOpen;
393
- }, function (channel, state) {
282
+ return new Promise((resolve, reject) => {
283
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
394
284
  send(channel, {
395
285
  jsonrpc: '2.0',
396
286
  method: 'channels.leave',
@@ -399,8 +289,8 @@ function leave() {
399
289
  return {
400
290
  handler: handlers.awaitingLeave,
401
291
  state: {
402
- resolve: resolve,
403
- reject: reject
292
+ resolve,
293
+ reject
404
294
  }
405
295
  };
406
296
  });
@@ -421,12 +311,8 @@ function leave() {
421
311
 
422
312
 
423
313
  function shutdown(sign) {
424
- var _this3 = this;
425
-
426
- return new _Promise(function (resolve, reject) {
427
- enqueueAction(_this3, function (channel, state) {
428
- return state.handler === handlers.channelOpen;
429
- }, function (channel, state) {
314
+ return new Promise((resolve, reject) => {
315
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
430
316
  send(channel, {
431
317
  jsonrpc: '2.0',
432
318
  method: 'channels.shutdown',
@@ -435,9 +321,9 @@ function shutdown(sign) {
435
321
  return {
436
322
  handler: handlers.awaitingShutdownTx,
437
323
  state: {
438
- sign: sign,
439
- resolve: resolve,
440
- reject: reject
324
+ sign,
325
+ resolve,
326
+ reject
441
327
  }
442
328
  };
443
329
  });
@@ -492,33 +378,29 @@ function shutdown(sign) {
492
378
 
493
379
 
494
380
  function withdraw(amount, sign) {
495
- var _this4 = this;
496
-
497
- var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
498
- onOnChainTx = _ref4.onOnChainTx,
499
- onOwnWithdrawLocked = _ref4.onOwnWithdrawLocked,
500
- onWithdrawLocked = _ref4.onWithdrawLocked;
501
-
502
- return new _Promise(function (resolve, reject) {
503
- enqueueAction(_this4, function (channel, state) {
504
- return state.handler === handlers.channelOpen;
505
- }, function (channel, state) {
381
+ let {
382
+ onOnChainTx,
383
+ onOwnWithdrawLocked,
384
+ onWithdrawLocked
385
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
386
+ return new Promise((resolve, reject) => {
387
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
506
388
  send(channel, {
507
389
  jsonrpc: '2.0',
508
390
  method: 'channels.withdraw',
509
391
  params: {
510
- amount: amount
392
+ amount
511
393
  }
512
394
  });
513
395
  return {
514
396
  handler: handlers.awaitingWithdrawTx,
515
397
  state: {
516
- sign: sign,
517
- resolve: resolve,
518
- reject: reject,
519
- onOnChainTx: onOnChainTx,
520
- onOwnWithdrawLocked: onOwnWithdrawLocked,
521
- onWithdrawLocked: onWithdrawLocked
398
+ sign,
399
+ resolve,
400
+ reject,
401
+ onOnChainTx,
402
+ onOwnWithdrawLocked,
403
+ onWithdrawLocked
522
404
  }
523
405
  };
524
406
  });
@@ -574,33 +456,29 @@ function withdraw(amount, sign) {
574
456
 
575
457
 
576
458
  function deposit(amount, sign) {
577
- var _this5 = this;
578
-
579
- var _ref5 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
580
- onOnChainTx = _ref5.onOnChainTx,
581
- onOwnDepositLocked = _ref5.onOwnDepositLocked,
582
- onDepositLocked = _ref5.onDepositLocked;
583
-
584
- return new _Promise(function (resolve, reject) {
585
- enqueueAction(_this5, function (channel, state) {
586
- return state.handler === handlers.channelOpen;
587
- }, function (channel, state) {
459
+ let {
460
+ onOnChainTx,
461
+ onOwnDepositLocked,
462
+ onDepositLocked
463
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
464
+ return new Promise((resolve, reject) => {
465
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
588
466
  send(channel, {
589
467
  jsonrpc: '2.0',
590
468
  method: 'channels.deposit',
591
469
  params: {
592
- amount: amount
470
+ amount
593
471
  }
594
472
  });
595
473
  return {
596
474
  handler: handlers.awaitingDepositTx,
597
475
  state: {
598
- sign: sign,
599
- resolve: resolve,
600
- reject: reject,
601
- onOnChainTx: onOnChainTx,
602
- onOwnDepositLocked: onOwnDepositLocked,
603
- onDepositLocked: onDepositLocked
476
+ sign,
477
+ resolve,
478
+ reject,
479
+ onOnChainTx,
480
+ onOwnDepositLocked,
481
+ onDepositLocked
604
482
  }
605
483
  };
606
484
  });
@@ -640,25 +518,23 @@ function deposit(amount, sign) {
640
518
  */
641
519
 
642
520
 
643
- function createContract(_ref6, sign) {
644
- var _this6 = this;
645
-
646
- var code = _ref6.code,
647
- callData = _ref6.callData,
648
- deposit = _ref6.deposit,
649
- vmVersion = _ref6.vmVersion,
650
- abiVersion = _ref6.abiVersion;
651
- return new _Promise(function (resolve, reject) {
652
- enqueueAction(_this6, function (channel, state) {
653
- return state.handler === handlers.channelOpen;
654
- }, function (channel, state) {
521
+ function createContract(_ref3, sign) {
522
+ let {
523
+ code,
524
+ callData,
525
+ deposit,
526
+ vmVersion,
527
+ abiVersion
528
+ } = _ref3;
529
+ return new Promise((resolve, reject) => {
530
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
655
531
  send(channel, {
656
532
  jsonrpc: '2.0',
657
533
  method: 'channels.update.new_contract',
658
534
  params: {
659
- code: code,
535
+ code,
660
536
  call_data: callData,
661
- deposit: deposit,
537
+ deposit,
662
538
  vm_version: vmVersion,
663
539
  abi_version: abiVersion
664
540
  }
@@ -666,9 +542,9 @@ function createContract(_ref6, sign) {
666
542
  return {
667
543
  handler: handlers.awaitingNewContractTx,
668
544
  state: {
669
- sign: sign,
670
- resolve: resolve,
671
- reject: reject
545
+ sign,
546
+ resolve,
547
+ reject
672
548
  }
673
549
  };
674
550
  });
@@ -712,22 +588,20 @@ function createContract(_ref6, sign) {
712
588
  */
713
589
 
714
590
 
715
- function callContract(_ref7, sign) {
716
- var _this7 = this;
717
-
718
- var amount = _ref7.amount,
719
- callData = _ref7.callData,
720
- contract = _ref7.contract,
721
- abiVersion = _ref7.abiVersion;
722
- return new _Promise(function (resolve, reject) {
723
- enqueueAction(_this7, function (channel, state) {
724
- return state.handler === handlers.channelOpen;
725
- }, function (channel, state) {
591
+ function callContract(_ref4, sign) {
592
+ let {
593
+ amount,
594
+ callData,
595
+ contract,
596
+ abiVersion
597
+ } = _ref4;
598
+ return new Promise((resolve, reject) => {
599
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
726
600
  send(channel, {
727
601
  jsonrpc: '2.0',
728
602
  method: 'channels.update.call_contract',
729
603
  params: {
730
- amount: amount,
604
+ amount,
731
605
  call_data: callData,
732
606
  contract_id: contract,
733
607
  abi_version: abiVersion
@@ -736,9 +610,9 @@ function callContract(_ref7, sign) {
736
610
  return {
737
611
  handler: handlers.awaitingCallContractUpdateTx,
738
612
  state: {
739
- resolve: resolve,
740
- reject: reject,
741
- sign: sign
613
+ resolve,
614
+ reject,
615
+ sign
742
616
  }
743
617
  };
744
618
  });
@@ -773,45 +647,40 @@ function callContract(_ref7, sign) {
773
647
  */
774
648
 
775
649
 
776
- function forceProgress(_ref8, sign) {
777
- var _this8 = this;
778
-
779
- var amount = _ref8.amount,
780
- callData = _ref8.callData,
781
- contract = _ref8.contract,
782
- abiVersion = _ref8.abiVersion,
783
- _ref8$gas = _ref8.gas,
784
- gas = _ref8$gas === void 0 ? 1000000 : _ref8$gas,
785
- _ref8$gasPrice = _ref8.gasPrice,
786
- gasPrice = _ref8$gasPrice === void 0 ? 1000000000 : _ref8$gasPrice,
787
- nonce = _ref8.nonce;
788
-
789
- var _ref9 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
790
- onOnChainTx = _ref9.onOnChainTx;
791
-
792
- return new _Promise(function (resolve, reject) {
793
- enqueueAction(_this8, function (channel, state) {
794
- return state.handler === handlers.channelOpen;
795
- }, function (channel, state) {
650
+ function forceProgress(_ref5, sign) {
651
+ let {
652
+ amount,
653
+ callData,
654
+ contract,
655
+ abiVersion,
656
+ gas = 1000000,
657
+ gasPrice = 1000000000,
658
+ nonce
659
+ } = _ref5;
660
+ let {
661
+ onOnChainTx
662
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
663
+ return new Promise((resolve, reject) => {
664
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
796
665
  send(channel, {
797
666
  jsonrpc: '2.0',
798
667
  method: 'channels.force_progress',
799
668
  params: {
800
- amount: amount,
669
+ amount,
801
670
  call_data: callData,
802
671
  contract_id: contract,
803
672
  abi_version: abiVersion,
804
673
  gas_price: gasPrice,
805
- gas: gas
674
+ gas
806
675
  }
807
676
  });
808
677
  return {
809
678
  handler: handlers.awaitingCallContractForceProgressUpdate,
810
679
  state: {
811
- resolve: resolve,
812
- reject: reject,
813
- sign: sign,
814
- onOnChainTx: onOnChainTx
680
+ resolve,
681
+ reject,
682
+ sign,
683
+ onOnChainTx
815
684
  }
816
685
  };
817
686
  });
@@ -846,8 +715,19 @@ function forceProgress(_ref8, sign) {
846
715
  */
847
716
 
848
717
 
849
- function callContractStatic(_x3) {
850
- return _callContractStatic.apply(this, arguments);
718
+ async function callContractStatic(_ref6) {
719
+ let {
720
+ amount,
721
+ callData,
722
+ contract,
723
+ abiVersion
724
+ } = _ref6;
725
+ return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
726
+ amount,
727
+ call_data: callData,
728
+ contract_id: contract,
729
+ abi_version: abiVersion
730
+ }));
851
731
  }
852
732
  /**
853
733
  * Get contract call result
@@ -870,39 +750,17 @@ function callContractStatic(_x3) {
870
750
  */
871
751
 
872
752
 
873
- function _callContractStatic() {
874
- _callContractStatic = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref10) {
875
- var amount, callData, contract, abiVersion;
876
- return _regeneratorRuntime.wrap(function _callee5$(_context6) {
877
- while (1) {
878
- switch (_context6.prev = _context6.next) {
879
- case 0:
880
- amount = _ref10.amount, callData = _ref10.callData, contract = _ref10.contract, abiVersion = _ref10.abiVersion;
881
- _context6.t0 = snakeToPascalObjKeys;
882
- _context6.next = 4;
883
- return call(this, 'channels.dry_run.call_contract', {
884
- amount: amount,
885
- call_data: callData,
886
- contract_id: contract,
887
- abi_version: abiVersion
888
- });
889
-
890
- case 4:
891
- _context6.t1 = _context6.sent;
892
- return _context6.abrupt("return", (0, _context6.t0)(_context6.t1));
893
-
894
- case 6:
895
- case "end":
896
- return _context6.stop();
897
- }
898
- }
899
- }, _callee5, this);
753
+ async function getContractCall(_ref7) {
754
+ let {
755
+ caller,
756
+ contract,
757
+ round
758
+ } = _ref7;
759
+ return snakeToPascalObjKeys(await call(this, 'channels.get.contract_call', {
760
+ caller_id: caller,
761
+ contract_id: contract,
762
+ round
900
763
  }));
901
- return _callContractStatic.apply(this, arguments);
902
- }
903
-
904
- function getContractCall(_x4) {
905
- return _getContractCall.apply(this, arguments);
906
764
  }
907
765
  /**
908
766
  * Get contract latest state
@@ -917,38 +775,13 @@ function getContractCall(_x4) {
917
775
  */
918
776
 
919
777
 
920
- function _getContractCall() {
921
- _getContractCall = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref11) {
922
- var caller, contract, round;
923
- return _regeneratorRuntime.wrap(function _callee6$(_context7) {
924
- while (1) {
925
- switch (_context7.prev = _context7.next) {
926
- case 0:
927
- caller = _ref11.caller, contract = _ref11.contract, round = _ref11.round;
928
- _context7.t0 = snakeToPascalObjKeys;
929
- _context7.next = 4;
930
- return call(this, 'channels.get.contract_call', {
931
- caller_id: caller,
932
- contract_id: contract,
933
- round: round
934
- });
935
-
936
- case 4:
937
- _context7.t1 = _context7.sent;
938
- return _context7.abrupt("return", (0, _context7.t0)(_context7.t1));
939
-
940
- case 6:
941
- case "end":
942
- return _context7.stop();
943
- }
944
- }
945
- }, _callee6, this);
946
- }));
947
- return _getContractCall.apply(this, arguments);
948
- }
949
-
950
- function getContractState(_x5) {
951
- return _getContractState.apply(this, arguments);
778
+ async function getContractState(contract) {
779
+ const result = await call(this, 'channels.get.contract', {
780
+ pubkey: contract
781
+ });
782
+ return snakeToPascalObjKeys({ ...result,
783
+ contract: snakeToPascalObjKeys(result.contract)
784
+ });
952
785
  }
953
786
  /**
954
787
  * Clean up all locally stored contract calls
@@ -962,41 +795,9 @@ function getContractState(_x5) {
962
795
  */
963
796
 
964
797
 
965
- function _getContractState() {
966
- _getContractState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(contract) {
967
- var result;
968
- return _regeneratorRuntime.wrap(function _callee7$(_context8) {
969
- while (1) {
970
- switch (_context8.prev = _context8.next) {
971
- case 0:
972
- _context8.next = 2;
973
- return call(this, 'channels.get.contract', {
974
- pubkey: contract
975
- });
976
-
977
- case 2:
978
- result = _context8.sent;
979
- return _context8.abrupt("return", snakeToPascalObjKeys(_objectSpread(_objectSpread({}, result), {}, {
980
- contract: snakeToPascalObjKeys(result.contract)
981
- })));
982
-
983
- case 4:
984
- case "end":
985
- return _context8.stop();
986
- }
987
- }
988
- }, _callee7, this);
989
- }));
990
- return _getContractState.apply(this, arguments);
991
- }
992
-
993
798
  function cleanContractCalls() {
994
- var _this9 = this;
995
-
996
- return new _Promise(function (resolve, reject) {
997
- enqueueAction(_this9, function (channel, state) {
998
- return state.handler === handlers.channelOpen;
999
- }, function (channel, state) {
799
+ return new Promise((resolve, reject) => {
800
+ enqueueAction(this, (channel, state) => state.handler === handlers.channelOpen, (channel, state) => {
1000
801
  send(channel, {
1001
802
  jsonrpc: '2.0',
1002
803
  method: 'channels.clean_contract_calls',
@@ -1005,8 +806,8 @@ function cleanContractCalls() {
1005
806
  return {
1006
807
  handler: handlers.awaitingCallsPruned,
1007
808
  state: {
1008
- resolve: resolve,
1009
- reject: reject
809
+ resolve,
810
+ reject
1010
811
  }
1011
812
  };
1012
813
  });
@@ -1031,35 +832,28 @@ function cleanContractCalls() {
1031
832
 
1032
833
 
1033
834
  function sendMessage(message, recipient) {
1034
- var _this10 = this;
835
+ let info = message;
1035
836
 
1036
- var info = message;
1037
-
1038
- if (_typeof(message) === 'object') {
1039
- info = _JSON$stringify(message);
837
+ if (typeof message === 'object') {
838
+ info = JSON.stringify(message);
1040
839
  }
1041
840
 
1042
- var doSend = function doSend(channel) {
1043
- return send(channel, {
1044
- jsonrpc: '2.0',
1045
- method: 'channels.message',
1046
- params: {
1047
- info: info,
1048
- to: recipient
1049
- }
1050
- });
1051
- };
841
+ const doSend = channel => send(channel, {
842
+ jsonrpc: '2.0',
843
+ method: 'channels.message',
844
+ params: {
845
+ info,
846
+ to: recipient
847
+ }
848
+ });
1052
849
 
1053
850
  if (this.status() === 'connecting') {
1054
- var onStatusChanged = function onStatusChanged(status) {
851
+ const onStatusChanged = status => {
1055
852
  if (status !== 'connecting') {
1056
853
  // For some reason we can't immediately send a message when connection is
1057
854
  // established. Thus we wait 500ms which seems to work.
1058
- _setTimeout(function () {
1059
- return doSend(_this10);
1060
- }, 500);
1061
-
1062
- _this10.off('statusChanged', onStatusChanged);
855
+ setTimeout(() => doSend(this), 500);
856
+ this.off('statusChanged', onStatusChanged);
1063
857
  }
1064
858
  };
1065
859
 
@@ -1069,8 +863,13 @@ function sendMessage(message, recipient) {
1069
863
  }
1070
864
  }
1071
865
 
1072
- function reconnect(_x6, _x7) {
1073
- return _reconnect.apply(this, arguments);
866
+ async function reconnect(options, txParams) {
867
+ const {
868
+ sign
869
+ } = options;
870
+ return Channel({ ...options,
871
+ reconnectTx: await sign('reconnect', buildTx(txParams, TX_TYPE.channelReconnect).tx)
872
+ });
1074
873
  }
1075
874
  /**
1076
875
  * Channel
@@ -1122,85 +921,38 @@ function reconnect(_x6, _x7) {
1122
921
  */
1123
922
 
1124
923
 
1125
- function _reconnect() {
1126
- _reconnect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(options, txParams) {
1127
- var sign;
1128
- return _regeneratorRuntime.wrap(function _callee8$(_context9) {
1129
- while (1) {
1130
- switch (_context9.prev = _context9.next) {
1131
- case 0:
1132
- sign = options.sign;
1133
- _context9.t0 = Channel;
1134
- _context9.t1 = _objectSpread;
1135
- _context9.t2 = _objectSpread({}, options);
1136
- _context9.t3 = {};
1137
- _context9.next = 7;
1138
- return sign('reconnect', buildTx(txParams, TX_TYPE.channelReconnect).tx);
1139
-
1140
- case 7:
1141
- _context9.t4 = _context9.sent;
1142
- _context9.t5 = {
1143
- reconnectTx: _context9.t4
1144
- };
1145
- _context9.t6 = (0, _context9.t1)(_context9.t2, _context9.t3, _context9.t5);
1146
- return _context9.abrupt("return", (0, _context9.t0)(_context9.t6));
1147
-
1148
- case 11:
1149
- case "end":
1150
- return _context9.stop();
1151
- }
1152
- }
1153
- }, _callee8);
1154
- }));
1155
- return _reconnect.apply(this, arguments);
1156
- }
1157
-
1158
- var Channel = AsyncInit.compose({
1159
- init: function init(options) {
1160
- var _this11 = this;
1161
-
1162
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1163
- return _regeneratorRuntime.wrap(function _callee$(_context2) {
1164
- while (1) {
1165
- switch (_context2.prev = _context2.next) {
1166
- case 0:
1167
- initialize(_this11, options);
1168
-
1169
- case 1:
1170
- case "end":
1171
- return _context2.stop();
1172
- }
1173
- }
1174
- }, _callee);
1175
- }))();
924
+ const Channel = AsyncInit.compose({
925
+ async init(options) {
926
+ initialize(this, options);
1176
927
  },
928
+
1177
929
  methods: {
1178
- on: on,
1179
- off: off,
1180
- status: status,
1181
- state: state,
1182
- round: round,
1183
- id: id,
1184
- fsmId: fsmId,
1185
- update: update,
1186
- poi: poi,
1187
- balances: balances,
1188
- leave: leave,
1189
- shutdown: shutdown,
1190
- sendMessage: sendMessage,
1191
- withdraw: withdraw,
1192
- deposit: deposit,
1193
- createContract: createContract,
1194
- callContract: callContract,
1195
- callContractStatic: callContractStatic,
1196
- getContractCall: getContractCall,
1197
- getContractState: getContractState,
1198
- disconnect: disconnect,
1199
- cleanContractCalls: cleanContractCalls,
1200
- forceProgress: forceProgress
930
+ on,
931
+ off,
932
+ status,
933
+ state,
934
+ round,
935
+ id,
936
+ fsmId,
937
+ update,
938
+ poi,
939
+ balances,
940
+ leave,
941
+ shutdown,
942
+ sendMessage,
943
+ withdraw,
944
+ deposit,
945
+ createContract,
946
+ callContract,
947
+ callContractStatic,
948
+ getContractCall,
949
+ getContractState,
950
+ disconnect,
951
+ cleanContractCalls,
952
+ forceProgress
1201
953
  },
1202
954
  statics: {
1203
- reconnect: reconnect
955
+ reconnect
1204
956
  }
1205
957
  });
1206
958
  export default Channel;