@aeternity/aepp-sdk 8.2.1 → 10.0.0

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