@aeternity/aepp-sdk 9.0.1 → 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 (137) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +1 -1
  5. package/dist/aepp-sdk.browser.js.map +1 -1
  6. package/dist/aepp-sdk.js +1 -1
  7. package/dist/aepp-sdk.js.map +1 -1
  8. package/es/account/base.js +30 -122
  9. package/es/account/base.js.map +1 -1
  10. package/es/account/memory.js +17 -19
  11. package/es/account/memory.js.map +1 -1
  12. package/es/account/multiple.js +73 -164
  13. package/es/account/multiple.js.map +1 -1
  14. package/es/ae/aens.js +164 -599
  15. package/es/ae/aens.js.map +1 -1
  16. package/es/ae/contract.js +82 -759
  17. package/es/ae/contract.js.map +1 -1
  18. package/es/ae/index.js +78 -315
  19. package/es/ae/index.js.map +1 -1
  20. package/es/ae/oracle.js +130 -498
  21. package/es/ae/oracle.js.map +1 -1
  22. package/es/chain/index.js +1 -1
  23. package/es/chain/index.js.map +1 -1
  24. package/es/chain/node.js +288 -1008
  25. package/es/chain/node.js.map +1 -1
  26. package/es/channel/handlers.js +597 -1086
  27. package/es/channel/handlers.js.map +1 -1
  28. package/es/channel/index.js +203 -451
  29. package/es/channel/index.js.map +1 -1
  30. package/es/channel/internal.js +129 -301
  31. package/es/channel/internal.js.map +1 -1
  32. package/es/contract/aci/index.js +319 -480
  33. package/es/contract/aci/index.js.map +1 -1
  34. package/es/contract/aci/transformation.js +35 -711
  35. package/es/contract/aci/transformation.js.map +1 -1
  36. package/es/contract/compiler.js +129 -203
  37. package/es/contract/compiler.js.map +1 -1
  38. package/es/contract/ga/helpers.js +16 -114
  39. package/es/contract/ga/helpers.js.map +1 -1
  40. package/es/contract/ga/index.js +101 -242
  41. package/es/contract/ga/index.js.map +1 -1
  42. package/es/contract/index.js +1 -1
  43. package/es/contract/index.js.map +1 -1
  44. package/es/index.js +1 -2
  45. package/es/index.js.map +1 -1
  46. package/es/node-pool/index.js +54 -73
  47. package/es/node-pool/index.js.map +1 -1
  48. package/es/node.js +56 -157
  49. package/es/node.js.map +1 -1
  50. package/es/other.d.ts +1 -1
  51. package/es/tx/builder/helpers.js +38 -75
  52. package/es/tx/builder/helpers.js.map +1 -1
  53. package/es/tx/builder/index.js +196 -294
  54. package/es/tx/builder/index.js.map +1 -1
  55. package/es/tx/builder/schema.js +577 -459
  56. package/es/tx/builder/schema.js.map +1 -1
  57. package/es/tx/index.js +1 -1
  58. package/es/tx/index.js.map +1 -1
  59. package/es/tx/tx-object.js +105 -132
  60. package/es/tx/tx-object.js.map +1 -1
  61. package/es/tx/tx.js +808 -1628
  62. package/es/tx/tx.js.map +1 -1
  63. package/es/tx/validator.js +132 -268
  64. package/es/tx/validator.js.map +1 -1
  65. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
  66. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  67. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
  68. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  69. package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
  70. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  71. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  72. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  73. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
  74. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  75. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
  76. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  77. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +353 -600
  78. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  79. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  80. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  81. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  82. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  83. package/es/utils/amount-formatter.js +41 -61
  84. package/es/utils/amount-formatter.js.map +1 -1
  85. package/es/utils/async-init.js +28 -64
  86. package/es/utils/async-init.js.map +1 -1
  87. package/es/utils/bignumber.js +3 -11
  88. package/es/utils/bignumber.js.map +1 -1
  89. package/es/utils/bytes.js +5 -9
  90. package/es/utils/bytes.js.map +1 -1
  91. package/es/utils/crypto.js +47 -62
  92. package/es/utils/crypto.js.map +1 -1
  93. package/es/utils/hd-wallet.js +45 -81
  94. package/es/utils/hd-wallet.js.map +1 -1
  95. package/es/utils/json-big.js +16 -49
  96. package/es/utils/json-big.js.map +1 -1
  97. package/es/utils/keystore.js +81 -246
  98. package/es/utils/keystore.js.map +1 -1
  99. package/es/utils/mptree.js +88 -134
  100. package/es/utils/mptree.js.map +1 -1
  101. package/es/utils/other.js +10 -60
  102. package/es/utils/other.js.map +1 -1
  103. package/es/utils/semver-satisfies.js +9 -28
  104. package/es/utils/semver-satisfies.js.map +1 -1
  105. package/es/utils/string.js +4 -13
  106. package/es/utils/string.js.map +1 -1
  107. package/es/utils/swagger.js +85 -224
  108. package/es/utils/swagger.js.map +1 -1
  109. package/package.json +44 -40
  110. package/src/account/multiple.js +18 -19
  111. package/src/ae/aens.js +25 -21
  112. package/src/ae/contract.js +32 -163
  113. package/src/ae/index.js +3 -3
  114. package/src/ae/oracle.js +18 -14
  115. package/src/chain/node.js +2 -4
  116. package/src/channel/handlers.js +0 -1
  117. package/src/channel/index.js +4 -5
  118. package/src/contract/aci/index.js +221 -102
  119. package/src/contract/aci/transformation.js +30 -422
  120. package/src/contract/compiler.js +45 -4
  121. package/src/contract/ga/helpers.js +1 -8
  122. package/src/contract/ga/index.js +13 -11
  123. package/src/index.js +0 -2
  124. package/src/node-pool/index.js +21 -12
  125. package/src/node.js +22 -26
  126. package/src/tx/builder/index.js +2 -1
  127. package/src/tx/builder/schema.js +2 -1
  128. package/src/tx/tx.js +147 -143
  129. package/src/tx/validator.js +9 -7
  130. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
  131. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +3 -3
  132. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  133. package/src/utils/bignumber.ts +2 -1
  134. package/src/utils/other.ts +1 -1
  135. package/src/utils/semver-satisfies.ts +1 -1
  136. package/src/utils/swagger.js +14 -7
  137. package/src/contract/aci/helpers.js +0 -140
package/es/chain/node.js CHANGED
@@ -1,29 +1,19 @@
1
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
2
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
3
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
4
- import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
5
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
6
- import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
7
- import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
8
- import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/objectWithoutProperties";
9
- import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
10
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
11
- import _merge from "ramda/src/merge";
12
- import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
13
- var _excluded = ["result", "reason"],
14
- _excluded2 = ["results"];
15
- import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
16
-
17
- 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; }
18
-
19
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context30; _forEachInstanceProperty(_context30 = ownKeys(Object(source), true)).call(_context30, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context31; _forEachInstanceProperty(_context31 = ownKeys(Object(source))).call(_context31, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
20
-
21
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
22
- import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
23
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
24
- import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
25
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
26
- import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2018 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
27
17
  import Chain from './';
28
18
  import { AE_AMOUNT_FORMATS, formatAmount } from '../utils/amount-formatter';
29
19
  import verifyTransaction from '../tx/validator';
@@ -40,199 +30,94 @@ import { DRY_RUN_ACCOUNT, NAME_ID_KEY } from '../tx/builder/schema';
40
30
  * @example import { ChainNode } from '@aeternity/aepp-sdk'
41
31
  */
42
32
 
43
- function sendTransaction(_x) {
44
- return _sendTransaction.apply(this, arguments);
45
- }
46
-
47
- function _sendTransaction() {
48
- _sendTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tx) {
49
- var _this = this;
50
-
51
- var options,
52
- _R$merge,
53
- waitMined,
54
- verify,
33
+ async function sendTransaction(tx) {
34
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
35
+ const {
36
+ waitMined,
37
+ verify
38
+ } = { ...this.Ae.defaults,
39
+ ...options
40
+ };
41
+
42
+ if (verify) {
43
+ const validation = await verifyTransaction(tx, this.selectedNode.instance);
44
+
45
+ if (validation.length) {
46
+ const message = 'Transaction verification errors: ' + validation.map(v => v.message).join(', ');
47
+ throw Object.assign(new Error(message), {
48
+ code: 'TX_VERIFICATION_ERROR',
55
49
  validation,
56
- message,
57
- _yield$this$api$postT,
58
- txHash,
59
- txData,
60
- _args = arguments;
61
-
62
- return _regeneratorRuntime.wrap(function _callee$(_context) {
63
- while (1) {
64
- switch (_context.prev = _context.next) {
65
- case 0:
66
- options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
67
- _R$merge = _merge(this.Ae.defaults, options), waitMined = _R$merge.waitMined, verify = _R$merge.verify;
68
-
69
- if (!verify) {
70
- _context.next = 9;
71
- break;
72
- }
73
-
74
- _context.next = 5;
75
- return verifyTransaction(tx, this.selectedNode.instance);
76
-
77
- case 5:
78
- validation = _context.sent;
79
-
80
- if (!validation.length) {
81
- _context.next = 9;
82
- break;
83
- }
84
-
85
- message = 'Transaction verification errors: ' + _mapInstanceProperty(validation).call(validation, function (v) {
86
- return v.message;
87
- }).join(', ');
88
- throw _Object$assign(new Error(message), {
89
- code: 'TX_VERIFICATION_ERROR',
90
- validation: validation,
91
- transaction: tx
92
- });
93
-
94
- case 9:
95
- _context.prev = 9;
96
- _context.next = 12;
97
- return this.api.postTransaction({
98
- tx: tx
99
- });
100
-
101
- case 12:
102
- _yield$this$api$postT = _context.sent;
103
- txHash = _yield$this$api$postT.txHash;
104
-
105
- if (!waitMined) {
106
- _context.next = 35;
107
- break;
108
- }
109
-
110
- _context.t0 = _objectSpread;
111
- _context.t1 = _objectSpread;
112
- _context.t2 = {};
113
- _context.next = 20;
114
- return this.poll(txHash, options);
115
-
116
- case 20:
117
- _context.t3 = _context.sent;
118
- _context.t4 = (0, _context.t1)(_context.t2, _context.t3);
119
- _context.t5 = {};
120
- _context.t6 = {
121
- rawTx: tx
122
- };
123
- txData = (0, _context.t0)(_context.t4, _context.t5, _context.t6);
124
-
125
- if (!options.confirm) {
126
- _context.next = 34;
127
- break;
128
- }
129
-
130
- _context.t7 = _objectSpread;
131
- _context.t8 = _objectSpread({}, txData);
132
- _context.t9 = {};
133
- _context.next = 31;
134
- return this.waitForTxConfirm(txHash, options);
135
-
136
- case 31:
137
- _context.t10 = _context.sent;
138
- _context.t11 = {
139
- confirmationHeight: _context.t10
140
- };
141
- return _context.abrupt("return", (0, _context.t7)(_context.t8, _context.t9, _context.t11));
142
-
143
- case 34:
144
- return _context.abrupt("return", txData);
145
-
146
- case 35:
147
- return _context.abrupt("return", {
148
- hash: txHash,
149
- rawTx: tx
150
- });
151
-
152
- case 38:
153
- _context.prev = 38;
154
- _context.t12 = _context["catch"](9);
155
- throw _Object$assign(_context.t12, {
156
- rawTx: tx,
157
- verifyTx: function verifyTx() {
158
- return verifyTransaction(tx, _this.selectedNode.instance);
159
- }
160
- });
50
+ transaction: tx
51
+ });
52
+ }
53
+ }
161
54
 
162
- case 41:
163
- case "end":
164
- return _context.stop();
165
- }
55
+ try {
56
+ const {
57
+ txHash
58
+ } = await this.api.postTransaction({
59
+ tx
60
+ });
61
+
62
+ if (waitMined) {
63
+ const txData = { ...(await this.poll(txHash, options)),
64
+ rawTx: tx
65
+ }; // wait for transaction confirmation
66
+
67
+ if (options.confirm) {
68
+ return { ...txData,
69
+ confirmationHeight: await this.waitForTxConfirm(txHash, options)
70
+ };
166
71
  }
167
- }, _callee, this, [[9, 38]]);
168
- }));
169
- return _sendTransaction.apply(this, arguments);
170
- }
171
72
 
172
- function waitForTxConfirm(_x2) {
173
- return _waitForTxConfirm.apply(this, arguments);
73
+ return txData;
74
+ }
75
+
76
+ return {
77
+ hash: txHash,
78
+ rawTx: tx
79
+ };
80
+ } catch (error) {
81
+ throw Object.assign(error, {
82
+ rawTx: tx,
83
+ verifyTx: () => verifyTransaction(tx, this.selectedNode.instance)
84
+ });
85
+ }
174
86
  }
175
87
 
176
- function _waitForTxConfirm() {
177
- _waitForTxConfirm = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(txHash) {
178
- var options,
179
- _yield$this$tx,
180
- blockHeight,
181
- height,
182
- _yield$this$tx2,
183
- newBlockHeight,
184
- _args2 = arguments;
185
-
186
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
187
- while (1) {
188
- switch (_context2.prev = _context2.next) {
189
- case 0:
190
- options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {
191
- confirm: 3
192
- };
193
- options.confirm = options.confirm === true ? 3 : options.confirm;
194
- _context2.next = 4;
195
- return this.tx(txHash);
196
-
197
- case 4:
198
- _yield$this$tx = _context2.sent;
199
- blockHeight = _yield$this$tx.blockHeight;
200
- _context2.next = 8;
201
- return this.awaitHeight(blockHeight + options.confirm, options);
202
-
203
- case 8:
204
- height = _context2.sent;
205
- _context2.next = 11;
206
- return this.tx(txHash);
207
-
208
- case 11:
209
- _yield$this$tx2 = _context2.sent;
210
- newBlockHeight = _yield$this$tx2.blockHeight;
211
- _context2.t0 = newBlockHeight;
212
- _context2.next = _context2.t0 === -1 ? 16 : _context2.t0 === blockHeight ? 17 : 18;
213
- break;
214
-
215
- case 16:
216
- throw new Error("Transaction ".concat(txHash, " is removed from chain"));
217
-
218
- case 17:
219
- return _context2.abrupt("return", height);
220
-
221
- case 18:
222
- return _context2.abrupt("return", waitForTxConfirm(txHash, options));
223
-
224
- case 19:
225
- case "end":
226
- return _context2.stop();
227
- }
228
- }
229
- }, _callee2, this);
230
- }));
231
- return _waitForTxConfirm.apply(this, arguments);
88
+ async function waitForTxConfirm(txHash) {
89
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
90
+ confirm: 3
91
+ };
92
+ options.confirm = options.confirm === true ? 3 : options.confirm;
93
+ const {
94
+ blockHeight
95
+ } = await this.tx(txHash);
96
+ const height = await this.awaitHeight(blockHeight + options.confirm, options);
97
+ const {
98
+ blockHeight: newBlockHeight
99
+ } = await this.tx(txHash);
100
+
101
+ switch (newBlockHeight) {
102
+ case -1:
103
+ throw new Error(`Transaction ${txHash} is removed from chain`);
104
+
105
+ case blockHeight:
106
+ return height;
107
+
108
+ default:
109
+ return waitForTxConfirm(txHash, options);
110
+ }
232
111
  }
233
112
 
234
- function getAccount(_x3) {
235
- return _getAccount.apply(this, arguments);
113
+ async function getAccount(address) {
114
+ let {
115
+ height,
116
+ hash
117
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
118
+ if (height) return this.api.getAccountByPubkeyAndHeight(address, height);
119
+ if (hash) return this.api.getAccountByPubkeyAndHash(address, hash);
120
+ return this.api.getAccountByPubkey(address);
236
121
  }
237
122
  /**
238
123
  * @function
@@ -240,700 +125,184 @@ function getAccount(_x3) {
240
125
  */
241
126
 
242
127
 
243
- function _getAccount() {
244
- _getAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(address) {
245
- var _ref,
246
- height,
247
- hash,
248
- _args3 = arguments;
249
-
250
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
251
- while (1) {
252
- switch (_context3.prev = _context3.next) {
253
- case 0:
254
- _ref = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {}, height = _ref.height, hash = _ref.hash;
255
-
256
- if (!height) {
257
- _context3.next = 3;
258
- break;
259
- }
260
-
261
- return _context3.abrupt("return", this.api.getAccountByPubkeyAndHeight(address, height));
262
-
263
- case 3:
264
- if (!hash) {
265
- _context3.next = 5;
266
- break;
267
- }
268
-
269
- return _context3.abrupt("return", this.api.getAccountByPubkeyAndHash(address, hash));
270
-
271
- case 5:
272
- return _context3.abrupt("return", this.api.getAccountByPubkey(address));
273
-
274
- case 6:
275
- case "end":
276
- return _context3.stop();
277
- }
278
- }
279
- }, _callee3, this);
280
- }));
281
- return _getAccount.apply(this, arguments);
282
- }
283
-
284
- function balance(_x4) {
285
- return _balance.apply(this, arguments);
286
- }
287
-
288
- function _balance() {
289
- _balance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(address) {
290
- var _ref2,
291
- height,
292
- hash,
293
- _ref2$format,
294
- format,
295
- _yield$this$getAccoun,
296
- balance,
297
- _args4 = arguments;
298
-
299
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
300
- while (1) {
301
- switch (_context4.prev = _context4.next) {
302
- case 0:
303
- _ref2 = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}, height = _ref2.height, hash = _ref2.hash, _ref2$format = _ref2.format, format = _ref2$format === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref2$format;
304
- _context4.next = 3;
305
- return this.getAccount(address, {
306
- hash: hash,
307
- height: height
308
- });
309
-
310
- case 3:
311
- _yield$this$getAccoun = _context4.sent;
312
- balance = _yield$this$getAccoun.balance;
313
- return _context4.abrupt("return", formatAmount(balance, {
314
- targetDenomination: format
315
- }).toString());
316
-
317
- case 6:
318
- case "end":
319
- return _context4.stop();
320
- }
321
- }
322
- }, _callee4, this);
128
+ async function balance(address) {
129
+ let {
130
+ height,
131
+ hash,
132
+ format = AE_AMOUNT_FORMATS.AETTOS
133
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
134
+ const {
135
+ balance
136
+ } = await this.getAccount(address, {
137
+ hash,
138
+ height
139
+ });
140
+ return formatAmount(balance, {
141
+ targetDenomination: format
142
+ }).toString();
143
+ }
144
+
145
+ async function getBalance(address) {
146
+ let {
147
+ height,
148
+ hash,
149
+ format = AE_AMOUNT_FORMATS.AETTOS
150
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
151
+ const {
152
+ balance
153
+ } = await this.getAccount(address, {
154
+ hash,
155
+ height
156
+ }).catch(_ => ({
157
+ balance: 0
323
158
  }));
324
- return _balance.apply(this, arguments);
159
+ return formatAmount(balance, {
160
+ targetDenomination: format
161
+ }).toString();
325
162
  }
326
163
 
327
- function getBalance(_x5) {
328
- return _getBalance.apply(this, arguments);
329
- }
330
-
331
- function _getBalance() {
332
- _getBalance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(address) {
333
- var _ref3,
334
- height,
335
- hash,
336
- _ref3$format,
337
- format,
338
- _yield$this$getAccoun2,
339
- balance,
340
- _args5 = arguments;
341
-
342
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
343
- while (1) {
344
- switch (_context5.prev = _context5.next) {
345
- case 0:
346
- _ref3 = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {}, height = _ref3.height, hash = _ref3.hash, _ref3$format = _ref3.format, format = _ref3$format === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref3$format;
347
- _context5.next = 3;
348
- return this.getAccount(address, {
349
- hash: hash,
350
- height: height
351
- })["catch"](function (_) {
352
- return {
353
- balance: 0
354
- };
355
- });
356
-
357
- case 3:
358
- _yield$this$getAccoun2 = _context5.sent;
359
- balance = _yield$this$getAccoun2.balance;
360
- return _context5.abrupt("return", formatAmount(balance, {
361
- targetDenomination: format
362
- }).toString());
164
+ async function tx(hash) {
165
+ let info = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
166
+ const tx = await this.api.getTransactionByHash(hash);
363
167
 
364
- case 6:
365
- case "end":
366
- return _context5.stop();
367
- }
368
- }
369
- }, _callee5, this);
370
- }));
371
- return _getBalance.apply(this, arguments);
372
- }
168
+ if (['ContractCreateTx', 'ContractCallTx', 'ChannelForceProgressTx'].includes(tx.tx.type) && info && tx.blockHeight !== -1) {
169
+ try {
170
+ return { ...tx,
171
+ ...(await this.getTxInfo(hash))
172
+ };
173
+ } catch (e) {}
174
+ }
373
175
 
374
- function tx(_x6) {
375
- return _tx.apply(this, arguments);
176
+ return tx;
376
177
  }
377
178
 
378
- function _tx() {
379
- _tx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(hash) {
380
- var _context6;
381
-
382
- var info,
383
- tx,
384
- _args6 = arguments;
385
- return _regeneratorRuntime.wrap(function _callee6$(_context7) {
386
- while (1) {
387
- switch (_context7.prev = _context7.next) {
388
- case 0:
389
- info = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : true;
390
- _context7.next = 3;
391
- return this.api.getTransactionByHash(hash);
392
-
393
- case 3:
394
- tx = _context7.sent;
395
-
396
- if (!(_includesInstanceProperty(_context6 = ['ContractCreateTx', 'ContractCallTx', 'ChannelForceProgressTx']).call(_context6, tx.tx.type) && info && tx.blockHeight !== -1)) {
397
- _context7.next = 16;
398
- break;
399
- }
179
+ async function height() {
180
+ try {
181
+ if (!this._heightPromise) {
182
+ this._heightPromise = this.api.getCurrentKeyBlockHeight();
183
+ }
400
184
 
401
- _context7.prev = 5;
402
- _context7.t0 = _objectSpread;
403
- _context7.t1 = _objectSpread({}, tx);
404
- _context7.next = 10;
405
- return this.getTxInfo(hash);
406
-
407
- case 10:
408
- _context7.t2 = _context7.sent;
409
- return _context7.abrupt("return", (0, _context7.t0)(_context7.t1, _context7.t2));
410
-
411
- case 14:
412
- _context7.prev = 14;
413
- _context7.t3 = _context7["catch"](5);
414
-
415
- case 16:
416
- return _context7.abrupt("return", tx);
417
-
418
- case 17:
419
- case "end":
420
- return _context7.stop();
421
- }
422
- }
423
- }, _callee6, this, [[5, 14]]);
424
- }));
425
- return _tx.apply(this, arguments);
426
- }
427
-
428
- function height() {
429
- return _height.apply(this, arguments);
185
+ return (await this._heightPromise).height;
186
+ } finally {
187
+ delete this._heightPromise;
188
+ }
430
189
  }
431
190
 
432
- function _height() {
433
- _height = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
434
- return _regeneratorRuntime.wrap(function _callee7$(_context8) {
435
- while (1) {
436
- switch (_context8.prev = _context8.next) {
437
- case 0:
438
- _context8.prev = 0;
439
-
440
- if (!this._heightPromise) {
441
- this._heightPromise = this.api.getCurrentKeyBlockHeight();
442
- }
443
-
444
- _context8.next = 4;
445
- return this._heightPromise;
191
+ async function awaitHeight(height) {
192
+ let {
193
+ interval = 5000,
194
+ attempts = 20
195
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
196
+ let currentHeight;
446
197
 
447
- case 4:
448
- return _context8.abrupt("return", _context8.sent.height);
449
-
450
- case 5:
451
- _context8.prev = 5;
452
- delete this._heightPromise;
453
- return _context8.finish(5);
454
-
455
- case 8:
456
- case "end":
457
- return _context8.stop();
458
- }
459
- }
460
- }, _callee7, this, [[0,, 5, 8]]);
461
- }));
462
- return _height.apply(this, arguments);
463
- }
198
+ for (let i = 0; i < attempts; i++) {
199
+ if (i) await pause(interval);
200
+ currentHeight = await this.height();
201
+ if (currentHeight >= height) return currentHeight;
202
+ }
464
203
 
465
- function awaitHeight(_x7) {
466
- return _awaitHeight.apply(this, arguments);
204
+ throw new Error(`Giving up after ${(attempts - 1) * interval}ms, current height: ${currentHeight}, desired height: ${height}`);
467
205
  }
468
206
  /**
469
207
  * @deprecated
470
208
  */
471
209
 
472
210
 
473
- function _awaitHeight() {
474
- _awaitHeight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(height) {
475
- var _context9, _context10;
476
-
477
- var _ref4,
478
- _ref4$interval,
479
- interval,
480
- _ref4$attempts,
481
- attempts,
482
- currentHeight,
483
- i,
484
- _args8 = arguments;
485
-
486
- return _regeneratorRuntime.wrap(function _callee8$(_context11) {
487
- while (1) {
488
- switch (_context11.prev = _context11.next) {
489
- case 0:
490
- _ref4 = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {}, _ref4$interval = _ref4.interval, interval = _ref4$interval === void 0 ? 5000 : _ref4$interval, _ref4$attempts = _ref4.attempts, attempts = _ref4$attempts === void 0 ? 20 : _ref4$attempts;
491
- i = 0;
492
-
493
- case 2:
494
- if (!(i < attempts)) {
495
- _context11.next = 14;
496
- break;
497
- }
498
-
499
- if (!i) {
500
- _context11.next = 6;
501
- break;
502
- }
503
-
504
- _context11.next = 6;
505
- return pause(interval);
506
-
507
- case 6:
508
- _context11.next = 8;
509
- return this.height();
510
-
511
- case 8:
512
- currentHeight = _context11.sent;
513
-
514
- if (!(currentHeight >= height)) {
515
- _context11.next = 11;
516
- break;
517
- }
518
-
519
- return _context11.abrupt("return", currentHeight);
520
-
521
- case 11:
522
- i++;
523
- _context11.next = 2;
524
- break;
525
-
526
- case 14:
527
- throw new Error(_concatInstanceProperty(_context9 = _concatInstanceProperty(_context10 = "Giving up after ".concat((attempts - 1) * interval, "ms, current height: ")).call(_context10, currentHeight, ", desired height: ")).call(_context9, height));
528
-
529
- case 15:
530
- case "end":
531
- return _context11.stop();
532
- }
533
- }
534
- }, _callee8, this);
535
- }));
536
- return _awaitHeight.apply(this, arguments);
537
- }
538
-
539
- function topBlock() {
540
- return _topBlock.apply(this, arguments);
541
- }
542
-
543
- function _topBlock() {
544
- _topBlock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
545
- return _regeneratorRuntime.wrap(function _callee9$(_context12) {
546
- while (1) {
547
- switch (_context12.prev = _context12.next) {
548
- case 0:
549
- return _context12.abrupt("return", this.api.getTopHeader());
550
-
551
- case 1:
552
- case "end":
553
- return _context12.stop();
554
- }
555
- }
556
- }, _callee9, this);
557
- }));
558
- return _topBlock.apply(this, arguments);
559
- }
560
-
561
- function poll(_x8) {
562
- return _poll.apply(this, arguments);
563
- }
564
-
565
- function _poll() {
566
- _poll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(th) {
567
- var _context13;
568
-
569
- var _ref5,
570
- _ref5$blocks,
571
- blocks,
572
- _ref5$interval,
573
- interval,
574
- _ref5$allowUnsynced,
575
- allowUnsynced,
576
- max,
577
- _tx2,
578
- _args10 = arguments;
579
-
580
- return _regeneratorRuntime.wrap(function _callee10$(_context14) {
581
- while (1) {
582
- switch (_context14.prev = _context14.next) {
583
- case 0:
584
- _ref5 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref5$blocks = _ref5.blocks, blocks = _ref5$blocks === void 0 ? 10 : _ref5$blocks, _ref5$interval = _ref5.interval, interval = _ref5$interval === void 0 ? 5000 : _ref5$interval, _ref5$allowUnsynced = _ref5.allowUnsynced, allowUnsynced = _ref5$allowUnsynced === void 0 ? false : _ref5$allowUnsynced;
585
- _context14.next = 3;
586
- return this.height();
587
-
588
- case 3:
589
- _context14.t0 = _context14.sent;
590
- _context14.t1 = blocks;
591
- max = _context14.t0 + _context14.t1;
592
-
593
- case 6:
594
- _context14.next = 8;
595
- return this.tx(th)["catch"](function (_) {
596
- return null;
597
- });
598
-
599
- case 8:
600
- _tx2 = _context14.sent;
601
-
602
- if (!(_tx2 && (_tx2.blockHeight !== -1 || allowUnsynced && _tx2.height))) {
603
- _context14.next = 11;
604
- break;
605
- }
606
-
607
- return _context14.abrupt("return", _tx2);
608
-
609
- case 11:
610
- _context14.next = 13;
611
- return pause(interval);
612
-
613
- case 13:
614
- _context14.next = 15;
615
- return this.height();
616
-
617
- case 15:
618
- _context14.t2 = _context14.sent;
619
- _context14.t3 = max;
620
-
621
- if (_context14.t2 < _context14.t3) {
622
- _context14.next = 6;
623
- break;
624
- }
625
-
626
- case 18:
627
- throw new Error(_concatInstanceProperty(_context13 = "Giving up after ".concat(blocks, " blocks mined, transaction hash: ")).call(_context13, th));
628
-
629
- case 19:
630
- case "end":
631
- return _context14.stop();
632
- }
633
- }
634
- }, _callee10, this);
635
- }));
636
- return _poll.apply(this, arguments);
637
- }
638
-
639
- function getTxInfo(_x9) {
640
- return _getTxInfo.apply(this, arguments);
211
+ async function topBlock() {
212
+ return this.api.getTopHeader();
641
213
  }
642
214
 
643
- function _getTxInfo() {
644
- _getTxInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(hash) {
645
- var result;
646
- return _regeneratorRuntime.wrap(function _callee11$(_context15) {
647
- while (1) {
648
- switch (_context15.prev = _context15.next) {
649
- case 0:
650
- _context15.next = 2;
651
- return this.api.getTransactionInfoByHash(hash);
215
+ async function poll(th) {
216
+ let {
217
+ blocks = 10,
218
+ interval = 500,
219
+ allowUnsynced = false
220
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
221
+ const max = (await this.height()) + blocks;
652
222
 
653
- case 2:
654
- result = _context15.sent;
655
- return _context15.abrupt("return", result.callInfo || result);
656
-
657
- case 4:
658
- case "end":
659
- return _context15.stop();
660
- }
661
- }
662
- }, _callee11, this);
663
- }));
664
- return _getTxInfo.apply(this, arguments);
665
- }
223
+ do {
224
+ const tx = await this.tx(th).catch(_ => null);
666
225
 
667
- function mempool() {
668
- return _mempool.apply(this, arguments);
669
- }
226
+ if (tx && (tx.blockHeight !== -1 || allowUnsynced && tx.height)) {
227
+ return tx;
228
+ }
670
229
 
671
- function _mempool() {
672
- _mempool = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
673
- return _regeneratorRuntime.wrap(function _callee12$(_context16) {
674
- while (1) {
675
- switch (_context16.prev = _context16.next) {
676
- case 0:
677
- return _context16.abrupt("return", this.api.getPendingTransactions());
230
+ await pause(interval);
231
+ } while ((await this.height()) < max);
678
232
 
679
- case 1:
680
- case "end":
681
- return _context16.stop();
682
- }
683
- }
684
- }, _callee12, this);
685
- }));
686
- return _mempool.apply(this, arguments);
233
+ throw new Error(`Giving up after ${blocks} blocks mined, transaction hash: ${th}`);
687
234
  }
688
235
 
689
- function getCurrentGeneration() {
690
- return _getCurrentGeneration.apply(this, arguments);
236
+ async function getTxInfo(hash) {
237
+ const result = await this.api.getTransactionInfoByHash(hash);
238
+ return result.callInfo || result;
691
239
  }
692
240
 
693
- function _getCurrentGeneration() {
694
- _getCurrentGeneration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
695
- return _regeneratorRuntime.wrap(function _callee13$(_context17) {
696
- while (1) {
697
- switch (_context17.prev = _context17.next) {
698
- case 0:
699
- return _context17.abrupt("return", this.api.getCurrentGeneration());
700
-
701
- case 1:
702
- case "end":
703
- return _context17.stop();
704
- }
705
- }
706
- }, _callee13, this);
707
- }));
708
- return _getCurrentGeneration.apply(this, arguments);
709
- }
710
-
711
- function getGeneration(_x10) {
712
- return _getGeneration.apply(this, arguments);
713
- }
714
-
715
- function _getGeneration() {
716
- _getGeneration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(hashOrHeight) {
717
- return _regeneratorRuntime.wrap(function _callee14$(_context18) {
718
- while (1) {
719
- switch (_context18.prev = _context18.next) {
720
- case 0:
721
- if (!(typeof hashOrHeight === 'string')) {
722
- _context18.next = 2;
723
- break;
724
- }
725
-
726
- return _context18.abrupt("return", this.api.getGenerationByHash(hashOrHeight));
727
-
728
- case 2:
729
- if (!(typeof hashOrHeight === 'number')) {
730
- _context18.next = 4;
731
- break;
732
- }
733
-
734
- return _context18.abrupt("return", this.api.getGenerationByHeight(hashOrHeight));
735
-
736
- case 4:
737
- throw new Error('Invalid param, param must be hash or height');
738
-
739
- case 5:
740
- case "end":
741
- return _context18.stop();
742
- }
743
- }
744
- }, _callee14, this);
745
- }));
746
- return _getGeneration.apply(this, arguments);
747
- }
748
-
749
- function getMicroBlockTransactions(_x11) {
750
- return _getMicroBlockTransactions.apply(this, arguments);
751
- }
752
-
753
- function _getMicroBlockTransactions() {
754
- _getMicroBlockTransactions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(hash) {
755
- return _regeneratorRuntime.wrap(function _callee15$(_context19) {
756
- while (1) {
757
- switch (_context19.prev = _context19.next) {
758
- case 0:
759
- _context19.next = 2;
760
- return this.api.getMicroBlockTransactionsByHash(hash);
761
-
762
- case 2:
763
- return _context19.abrupt("return", _context19.sent.transactions);
764
-
765
- case 3:
766
- case "end":
767
- return _context19.stop();
768
- }
769
- }
770
- }, _callee15, this);
771
- }));
772
- return _getMicroBlockTransactions.apply(this, arguments);
773
- }
774
-
775
- function getKeyBlock(_x12) {
776
- return _getKeyBlock.apply(this, arguments);
777
- }
778
-
779
- function _getKeyBlock() {
780
- _getKeyBlock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(hashOrHeight) {
781
- return _regeneratorRuntime.wrap(function _callee16$(_context20) {
782
- while (1) {
783
- switch (_context20.prev = _context20.next) {
784
- case 0:
785
- if (!(typeof hashOrHeight === 'string')) {
786
- _context20.next = 2;
787
- break;
788
- }
789
-
790
- return _context20.abrupt("return", this.api.getKeyBlockByHash(hashOrHeight));
791
-
792
- case 2:
793
- if (!(typeof hashOrHeight === 'number')) {
794
- _context20.next = 4;
795
- break;
796
- }
797
-
798
- return _context20.abrupt("return", this.api.getKeyBlockByHeight(hashOrHeight));
799
-
800
- case 4:
801
- throw new Error('Invalid param, param must be hash or height');
802
-
803
- case 5:
804
- case "end":
805
- return _context20.stop();
806
- }
807
- }
808
- }, _callee16, this);
809
- }));
810
- return _getKeyBlock.apply(this, arguments);
241
+ async function mempool() {
242
+ return this.api.getPendingTransactions();
811
243
  }
812
244
 
813
- function getMicroBlockHeader(_x13) {
814
- return _getMicroBlockHeader.apply(this, arguments);
245
+ async function getCurrentGeneration() {
246
+ return this.api.getCurrentGeneration();
815
247
  }
816
248
 
817
- function _getMicroBlockHeader() {
818
- _getMicroBlockHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(hash) {
819
- return _regeneratorRuntime.wrap(function _callee17$(_context21) {
820
- while (1) {
821
- switch (_context21.prev = _context21.next) {
822
- case 0:
823
- return _context21.abrupt("return", this.api.getMicroBlockHeaderByHash(hash));
824
-
825
- case 1:
826
- case "end":
827
- return _context21.stop();
828
- }
829
- }
830
- }, _callee17, this);
831
- }));
832
- return _getMicroBlockHeader.apply(this, arguments);
249
+ async function getGeneration(hashOrHeight) {
250
+ if (typeof hashOrHeight === 'string') return this.api.getGenerationByHash(hashOrHeight);
251
+ if (typeof hashOrHeight === 'number') return this.api.getGenerationByHeight(hashOrHeight);
252
+ throw new Error('Invalid param, param must be hash or height');
833
253
  }
834
254
 
835
- function txDryRun(_x14, _x15, _x16) {
836
- return _txDryRun.apply(this, arguments);
255
+ async function getMicroBlockTransactions(hash) {
256
+ return (await this.api.getMicroBlockTransactionsByHash(hash)).transactions;
837
257
  }
838
258
 
839
- function _txDryRun() {
840
- _txDryRun = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(tx, accountAddress, options) {
841
- var _yield$this$api$prote, _yield$this$api$prote2, _yield$this$api$prote3, result, reason, resultPayload, other;
842
-
843
- return _regeneratorRuntime.wrap(function _callee18$(_context22) {
844
- while (1) {
845
- switch (_context22.prev = _context22.next) {
846
- case 0:
847
- _context22.next = 2;
848
- return this.api.protectedDryRunTxs(_objectSpread(_objectSpread({}, options), {}, {
849
- txs: [{
850
- tx: tx
851
- }],
852
- accounts: [{
853
- pubKey: accountAddress,
854
- amount: DRY_RUN_ACCOUNT.amount
855
- }]
856
- }));
857
-
858
- case 2:
859
- _yield$this$api$prote = _context22.sent;
860
- _yield$this$api$prote2 = _slicedToArray(_yield$this$api$prote.results, 1);
861
- _yield$this$api$prote3 = _yield$this$api$prote2[0];
862
- result = _yield$this$api$prote3.result;
863
- reason = _yield$this$api$prote3.reason;
864
- resultPayload = _objectWithoutProperties(_yield$this$api$prote3, _excluded);
865
- other = _objectWithoutProperties(_yield$this$api$prote, _excluded2);
866
-
867
- if (!(result === 'ok')) {
868
- _context22.next = 11;
869
- break;
870
- }
871
-
872
- return _context22.abrupt("return", _objectSpread(_objectSpread({}, resultPayload), other));
873
-
874
- case 11:
875
- throw _Object$assign(new Error('Dry run error, ' + reason), {
876
- tx: tx,
877
- accountAddress: accountAddress,
878
- options: options
879
- });
880
-
881
- case 12:
882
- case "end":
883
- return _context22.stop();
884
- }
885
- }
886
- }, _callee18, this);
887
- }));
888
- return _txDryRun.apply(this, arguments);
259
+ async function getKeyBlock(hashOrHeight) {
260
+ if (typeof hashOrHeight === 'string') return this.api.getKeyBlockByHash(hashOrHeight);
261
+ if (typeof hashOrHeight === 'number') return this.api.getKeyBlockByHeight(hashOrHeight);
262
+ throw new Error('Invalid param, param must be hash or height');
889
263
  }
890
264
 
891
- function getContractByteCode(_x17) {
892
- return _getContractByteCode.apply(this, arguments);
265
+ async function getMicroBlockHeader(hash) {
266
+ return this.api.getMicroBlockHeaderByHash(hash);
893
267
  }
894
268
 
895
- function _getContractByteCode() {
896
- _getContractByteCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(contractId) {
897
- return _regeneratorRuntime.wrap(function _callee19$(_context23) {
898
- while (1) {
899
- switch (_context23.prev = _context23.next) {
900
- case 0:
901
- return _context23.abrupt("return", this.api.getContractCode(contractId));
902
-
903
- case 1:
904
- case "end":
905
- return _context23.stop();
906
- }
907
- }
908
- }, _callee19, this);
909
- }));
910
- return _getContractByteCode.apply(this, arguments);
269
+ async function txDryRun(tx, accountAddress, options) {
270
+ const {
271
+ results: [{
272
+ result,
273
+ reason,
274
+ ...resultPayload
275
+ }],
276
+ ...other
277
+ } = await this.api.protectedDryRunTxs({ ...options,
278
+ txs: [{
279
+ tx
280
+ }],
281
+ accounts: [{
282
+ pubKey: accountAddress,
283
+ amount: DRY_RUN_ACCOUNT.amount
284
+ }]
285
+ });
286
+ if (result === 'ok') return { ...resultPayload,
287
+ ...other
288
+ };
289
+ throw Object.assign(new Error('Dry run error, ' + reason), {
290
+ tx,
291
+ accountAddress,
292
+ options
293
+ });
911
294
  }
912
295
 
913
- function getContract(_x18) {
914
- return _getContract.apply(this, arguments);
296
+ async function getContractByteCode(contractId) {
297
+ return this.api.getContractCode(contractId);
915
298
  }
916
299
 
917
- function _getContract() {
918
- _getContract = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(contractId) {
919
- return _regeneratorRuntime.wrap(function _callee20$(_context24) {
920
- while (1) {
921
- switch (_context24.prev = _context24.next) {
922
- case 0:
923
- return _context24.abrupt("return", this.api.getContract(contractId));
924
-
925
- case 1:
926
- case "end":
927
- return _context24.stop();
928
- }
929
- }
930
- }, _callee20, this);
931
- }));
932
- return _getContract.apply(this, arguments);
300
+ async function getContract(contractId) {
301
+ return this.api.getContract(contractId);
933
302
  }
934
303
 
935
- function getName(_x19) {
936
- return _getName.apply(this, arguments);
304
+ async function getName(name) {
305
+ return this.api.getNameEntryByName(name);
937
306
  }
938
307
  /**
939
308
  * Resolve AENS name and return name hash
@@ -946,26 +315,45 @@ function getName(_x19) {
946
315
  */
947
316
 
948
317
 
949
- function _getName() {
950
- _getName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(name) {
951
- return _regeneratorRuntime.wrap(function _callee21$(_context25) {
952
- while (1) {
953
- switch (_context25.prev = _context25.next) {
954
- case 0:
955
- return _context25.abrupt("return", this.api.getNameEntryByName(name));
318
+ async function resolveName(nameOrId, prefix) {
319
+ let {
320
+ verify,
321
+ resolveByNode
322
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
956
323
 
957
- case 1:
958
- case "end":
959
- return _context25.stop();
960
- }
961
- }
962
- }, _callee21, this);
963
- }));
964
- return _getName.apply(this, arguments);
965
- }
324
+ if (!nameOrId || typeof nameOrId !== 'string') {
325
+ throw new Error(`Name or address should be a string: ${nameOrId}`);
326
+ }
327
+
328
+ const prefixes = Object.keys(NAME_ID_KEY);
966
329
 
967
- function resolveName(_x20, _x21) {
968
- return _resolveName.apply(this, arguments);
330
+ if (!prefixes.includes(prefix)) {
331
+ throw new Error(`Invalid prefix ${prefix}, should be one of [${prefixes}]`);
332
+ }
333
+
334
+ try {
335
+ decode(nameOrId, prefix);
336
+ return nameOrId;
337
+ } catch (error) {}
338
+
339
+ if (isNameValid(nameOrId)) {
340
+ if (verify || resolveByNode) {
341
+ const name = await this.getName(nameOrId).catch(_ => null);
342
+ if (!name) throw new Error(`Name not found: ${nameOrId}`);
343
+ const pointer = name.pointers.find(_ref => {
344
+ let {
345
+ id
346
+ } = _ref;
347
+ return id.split('_')[0] === prefix;
348
+ });
349
+ if (!pointer) throw new Error(`Name ${nameOrId} don't have pointers for ${prefix}`);
350
+ if (resolveByNode) return pointer.id;
351
+ }
352
+
353
+ return produceNameId(nameOrId);
354
+ }
355
+
356
+ throw new Error(`Invalid name or address: ${nameOrId}`);
969
357
  }
970
358
  /**
971
359
  * ChainNode Stamp
@@ -981,138 +369,30 @@ function resolveName(_x20, _x21) {
981
369
  */
982
370
 
983
371
 
984
- function _resolveName() {
985
- _resolveName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(nameOrId, prefix) {
986
- var _ref6,
987
- verify,
988
- resolveByNode,
989
- prefixes,
990
- _context26,
991
- _context27,
992
- _context28,
993
- name,
994
- pointer,
995
- _args22 = arguments;
996
-
997
- return _regeneratorRuntime.wrap(function _callee22$(_context29) {
998
- while (1) {
999
- switch (_context29.prev = _context29.next) {
1000
- case 0:
1001
- _ref6 = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {}, verify = _ref6.verify, resolveByNode = _ref6.resolveByNode;
1002
-
1003
- if (!(!nameOrId || typeof nameOrId !== 'string')) {
1004
- _context29.next = 3;
1005
- break;
1006
- }
1007
-
1008
- throw new Error("Name or address should be a string: ".concat(nameOrId));
1009
-
1010
- case 3:
1011
- prefixes = _Object$keys(NAME_ID_KEY);
1012
-
1013
- if (_includesInstanceProperty(prefixes).call(prefixes, prefix)) {
1014
- _context29.next = 6;
1015
- break;
1016
- }
1017
-
1018
- throw new Error(_concatInstanceProperty(_context26 = "Invalid prefix ".concat(prefix, ", should be one of [")).call(_context26, prefixes, "]"));
1019
-
1020
- case 6:
1021
- _context29.prev = 6;
1022
- decode(nameOrId, prefix);
1023
- return _context29.abrupt("return", nameOrId);
1024
-
1025
- case 11:
1026
- _context29.prev = 11;
1027
- _context29.t0 = _context29["catch"](6);
1028
-
1029
- case 13:
1030
- if (!isNameValid(nameOrId)) {
1031
- _context29.next = 26;
1032
- break;
1033
- }
1034
-
1035
- if (!(verify || resolveByNode)) {
1036
- _context29.next = 25;
1037
- break;
1038
- }
1039
-
1040
- _context29.next = 17;
1041
- return this.getName(nameOrId)["catch"](function (_) {
1042
- return null;
1043
- });
1044
-
1045
- case 17:
1046
- name = _context29.sent;
1047
-
1048
- if (name) {
1049
- _context29.next = 20;
1050
- break;
1051
- }
1052
-
1053
- throw new Error("Name not found: ".concat(nameOrId));
1054
-
1055
- case 20:
1056
- pointer = _findInstanceProperty(_context27 = name.pointers).call(_context27, function (_ref7) {
1057
- var id = _ref7.id;
1058
- return id.split('_')[0] === prefix;
1059
- });
1060
-
1061
- if (pointer) {
1062
- _context29.next = 23;
1063
- break;
1064
- }
1065
-
1066
- throw new Error(_concatInstanceProperty(_context28 = "Name ".concat(nameOrId, " don't have pointers for ")).call(_context28, prefix));
1067
-
1068
- case 23:
1069
- if (!resolveByNode) {
1070
- _context29.next = 25;
1071
- break;
1072
- }
1073
-
1074
- return _context29.abrupt("return", pointer.id);
1075
-
1076
- case 25:
1077
- return _context29.abrupt("return", produceNameId(nameOrId));
1078
-
1079
- case 26:
1080
- throw new Error("Invalid name or address: ".concat(nameOrId));
1081
-
1082
- case 27:
1083
- case "end":
1084
- return _context29.stop();
1085
- }
1086
- }
1087
- }, _callee22, this, [[6, 11]]);
1088
- }));
1089
- return _resolveName.apply(this, arguments);
1090
- }
1091
-
1092
- var ChainNode = Chain.compose(NodePool, {
372
+ const ChainNode = Chain.compose(NodePool, {
1093
373
  methods: {
1094
- sendTransaction: sendTransaction,
1095
- balance: balance,
1096
- getBalance: getBalance,
1097
- getAccount: getAccount,
1098
- topBlock: topBlock,
1099
- tx: tx,
1100
- height: height,
1101
- awaitHeight: awaitHeight,
1102
- poll: poll,
1103
- getTxInfo: getTxInfo,
1104
- mempool: mempool,
1105
- getCurrentGeneration: getCurrentGeneration,
1106
- getGeneration: getGeneration,
1107
- getMicroBlockHeader: getMicroBlockHeader,
1108
- getMicroBlockTransactions: getMicroBlockTransactions,
1109
- getKeyBlock: getKeyBlock,
1110
- txDryRun: txDryRun,
1111
- getContractByteCode: getContractByteCode,
1112
- getContract: getContract,
1113
- getName: getName,
1114
- waitForTxConfirm: waitForTxConfirm,
1115
- resolveName: resolveName
374
+ sendTransaction,
375
+ balance,
376
+ getBalance,
377
+ getAccount,
378
+ topBlock,
379
+ tx,
380
+ height,
381
+ awaitHeight,
382
+ poll,
383
+ getTxInfo,
384
+ mempool,
385
+ getCurrentGeneration,
386
+ getGeneration,
387
+ getMicroBlockHeader,
388
+ getMicroBlockTransactions,
389
+ getKeyBlock,
390
+ txDryRun,
391
+ getContractByteCode,
392
+ getContract,
393
+ getName,
394
+ waitForTxConfirm,
395
+ resolveName
1116
396
  }
1117
397
  });
1118
398
  export default ChainNode;