@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
@@ -1,30 +1,3 @@
1
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
2
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
3
- import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
4
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
5
- import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
6
- import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
7
- import _typeof from "@babel/runtime-corejs3/helpers/typeof";
8
- import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
9
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
10
- import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
11
-
12
- 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; }
13
-
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context11; _forEachInstanceProperty(_context11 = ownKeys(Object(source), true)).call(_context11, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context12; _forEachInstanceProperty(_context12 = ownKeys(Object(source))).call(_context12, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
15
-
16
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
17
- import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
18
- import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
19
- import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
20
- import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
21
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
22
- import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
23
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
24
- import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
25
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
26
- import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
27
- import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
28
1
  import BigNumber from 'bignumber.js';
29
2
  import { decode as rlpDecode, encode as rlpEncode } from 'rlp';
30
3
  import { AE_AMOUNT_FORMATS, formatAmount } from '../../utils/amount-formatter';
@@ -40,7 +13,7 @@ import MPTree from '../../utils/mptree';
40
13
  * @example import { TxBuilder } from '@aeternity/aepp-sdk'
41
14
  */
42
15
 
43
- var ORACLE_TTL_TYPES = {
16
+ const ORACLE_TTL_TYPES = {
44
17
  delta: 'delta',
45
18
  block: 'block'
46
19
  }; // SERIALIZE AND DESERIALIZE PART
@@ -51,10 +24,7 @@ function deserializeField(value, type, prefix) {
51
24
  switch (type) {
52
25
  case FIELD_TYPES.ctVersion:
53
26
  {
54
- var _value = _slicedToArray(value, 3),
55
- vm = _value[0],
56
- abi = _value[2];
57
-
27
+ const [vm,, abi] = value;
58
28
  return {
59
29
  vmVersion: readInt(Buffer.from([vm])),
60
30
  abiVersion: readInt(Buffer.from([abi]))
@@ -64,14 +34,14 @@ function deserializeField(value, type, prefix) {
64
34
  case FIELD_TYPES.amount:
65
35
  return readInt(value);
66
36
 
67
- case FIELD_TYPES["int"]:
37
+ case FIELD_TYPES.int:
68
38
  return readInt(value);
69
39
 
70
40
  case FIELD_TYPES.id:
71
41
  return readId(value);
72
42
 
73
43
  case FIELD_TYPES.ids:
74
- return _mapInstanceProperty(value).call(value, readId);
44
+ return value.map(readId);
75
45
 
76
46
  case FIELD_TYPES.bool:
77
47
  return value[0] === 1;
@@ -95,9 +65,7 @@ function deserializeField(value, type, prefix) {
95
65
  return unpackTx(value, true);
96
66
 
97
67
  case FIELD_TYPES.rlpBinaries:
98
- return _mapInstanceProperty(value).call(value, function (v) {
99
- return unpackTx(v, true);
100
- });
68
+ return value.map(v => unpackTx(v, true));
101
69
 
102
70
  case FIELD_TYPES.rawBinary:
103
71
  return value;
@@ -106,18 +74,14 @@ function deserializeField(value, type, prefix) {
106
74
  return value.toString('hex');
107
75
 
108
76
  case FIELD_TYPES.offChainUpdates:
109
- return _mapInstanceProperty(value).call(value, function (v) {
110
- return unpackTx(v, true);
111
- });
77
+ return value.map(v => unpackTx(v, true));
112
78
 
113
79
  case FIELD_TYPES.callStack:
114
80
  // TODO: fix this
115
81
  return [readInt(value)];
116
82
 
117
83
  case FIELD_TYPES.mptrees:
118
- return _mapInstanceProperty(value).call(value, function (t) {
119
- return new MPTree(t);
120
- });
84
+ return value.map(t => new MPTree(t));
121
85
 
122
86
  case FIELD_TYPES.callReturnType:
123
87
  switch (readInt(value)) {
@@ -135,18 +99,15 @@ function deserializeField(value, type, prefix) {
135
99
  }
136
100
 
137
101
  case FIELD_TYPES.sophiaCodeTypeInfo:
138
- return _reduceInstanceProperty(value).call(value, function (acc, _ref) {
139
- var _ref2 = _slicedToArray(_ref, 4),
140
- funHash = _ref2[0],
141
- fnName = _ref2[1],
142
- argType = _ref2[2],
143
- outType = _ref2[3];
144
-
145
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, fnName.toString(), {
146
- funHash: funHash,
147
- argType: argType,
148
- outType: outType
149
- }));
102
+ return value.reduce((acc, _ref) => {
103
+ let [funHash, fnName, argType, outType] = _ref;
104
+ return { ...acc,
105
+ [fnName.toString()]: {
106
+ funHash,
107
+ argType,
108
+ outType
109
+ }
110
+ };
150
111
  }, {});
151
112
 
152
113
  default:
@@ -155,18 +116,16 @@ function deserializeField(value, type, prefix) {
155
116
  }
156
117
 
157
118
  function serializeField(value, type, prefix) {
158
- var _value$rlpEncoded, _context;
159
-
160
119
  switch (type) {
161
120
  case FIELD_TYPES.amount:
162
- case FIELD_TYPES["int"]:
121
+ case FIELD_TYPES.int:
163
122
  return writeInt(value);
164
123
 
165
124
  case FIELD_TYPES.id:
166
125
  return writeId(value);
167
126
 
168
127
  case FIELD_TYPES.ids:
169
- return _mapInstanceProperty(value).call(value, writeId);
128
+ return value.map(writeId);
170
129
 
171
130
  case FIELD_TYPES.bool:
172
131
  return Buffer.from([value ? 1 : 0]);
@@ -181,7 +140,7 @@ function serializeField(value, type, prefix) {
181
140
  return Buffer.from(value, 'hex');
182
141
 
183
142
  case FIELD_TYPES.signatures:
184
- return _mapInstanceProperty(value).call(value, Buffer.from);
143
+ return value.map(Buffer.from);
185
144
 
186
145
  case FIELD_TYPES.payload:
187
146
  return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value, 'ba') : toBytes(value);
@@ -193,15 +152,13 @@ function serializeField(value, type, prefix) {
193
152
  return buildPointers(value);
194
153
 
195
154
  case FIELD_TYPES.rlpBinary:
196
- return (_value$rlpEncoded = value.rlpEncoded) !== null && _value$rlpEncoded !== void 0 ? _value$rlpEncoded : value;
155
+ return value.rlpEncoded ?? value;
197
156
 
198
157
  case FIELD_TYPES.mptrees:
199
- return _mapInstanceProperty(value).call(value, function (t) {
200
- return t.serialize();
201
- });
158
+ return value.map(t => t.serialize());
202
159
 
203
160
  case FIELD_TYPES.ctVersion:
204
- return Buffer.from(_concatInstanceProperty(_context = []).call(_context, _toConsumableArray(toBytes(value.vmVersion)), [0], _toConsumableArray(toBytes(value.abiVersion))));
161
+ return Buffer.from([...toBytes(value.vmVersion), 0, ...toBytes(value.abiVersion)]);
205
162
 
206
163
  case FIELD_TYPES.callReturnType:
207
164
  switch (value) {
@@ -224,55 +181,51 @@ function serializeField(value, type, prefix) {
224
181
  }
225
182
 
226
183
  function validateField(value, key, type, prefix) {
227
- var assert = function assert(valid, params) {
228
- return valid ? {} : _defineProperty({}, key, VALIDATION_MESSAGE[type](params));
184
+ const assert = (valid, params) => valid ? {} : {
185
+ [key]: VALIDATION_MESSAGE[type](params)
229
186
  }; // All fields are required
230
187
 
231
188
 
232
- if (value === undefined || value === null) return _defineProperty({}, key, 'Field is required'); // Validate type of value
189
+ if (value === undefined || value === null) return {
190
+ [key]: 'Field is required'
191
+ }; // Validate type of value
233
192
 
234
193
  switch (type) {
235
194
  case FIELD_TYPES.amount:
236
- case FIELD_TYPES["int"]:
195
+ case FIELD_TYPES.int:
237
196
  {
238
- var isMinusValue = (!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).lt(0);
197
+ const isMinusValue = (!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).lt(0);
239
198
  return assert((!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).gte(0), {
240
- value: value,
241
- isMinusValue: isMinusValue
199
+ value,
200
+ isMinusValue
242
201
  });
243
202
  }
244
203
 
245
204
  case FIELD_TYPES.id:
246
205
  {
247
- var prefixes = _Array$isArray(prefix) ? prefix : [prefix];
248
-
249
- var p = _findInstanceProperty(prefixes).call(prefixes, function (p) {
250
- return p === value.split('_')[0];
251
- });
252
-
206
+ const prefixes = Array.isArray(prefix) ? prefix : [prefix];
207
+ const p = prefixes.find(p => p === value.split('_')[0]);
253
208
  return assert(p && PREFIX_ID_TAG[value.split('_')[0]], {
254
- value: value,
255
- prefix: prefix
209
+ value,
210
+ prefix
256
211
  });
257
212
  }
258
213
 
259
214
  case FIELD_TYPES.binary:
260
215
  return assert(value.split('_')[0] === prefix, {
261
- prefix: prefix,
262
- value: value
216
+ prefix,
217
+ value
263
218
  });
264
219
 
265
220
  case FIELD_TYPES.string:
266
221
  return assert(true);
267
222
 
268
223
  case FIELD_TYPES.ctVersion:
269
- return assert(_typeof(value) === 'object' && Object.prototype.hasOwnProperty.call(value, 'abiVersion') && Object.prototype.hasOwnProperty.call(value, 'vmVersion'));
224
+ return assert(typeof value === 'object' && Object.prototype.hasOwnProperty.call(value, 'abiVersion') && Object.prototype.hasOwnProperty.call(value, 'vmVersion'));
270
225
 
271
226
  case FIELD_TYPES.pointers:
272
- return assert(_Array$isArray(value) && !_findInstanceProperty(value).call(value, function (e) {
273
- return e !== Object(e);
274
- }), {
275
- value: value
227
+ return assert(Array.isArray(value) && !value.find(e => e !== Object(e)), {
228
+ value
276
229
  });
277
230
 
278
231
  default:
@@ -281,45 +234,31 @@ function validateField(value, key, type, prefix) {
281
234
  }
282
235
 
283
236
  function transformParams(params, schema) {
284
- var _context2, _context3;
285
-
286
- var _ref5 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
287
- denomination = _ref5.denomination;
288
-
289
- params = _reduceInstanceProperty(_context2 = _filterInstanceProperty(schema).call(schema, function (_ref6) {
290
- var _ref7 = _slicedToArray(_ref6, 2),
291
- _ = _ref7[0],
292
- t = _ref7[1];
293
-
237
+ let {
238
+ denomination
239
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
240
+ params = schema.filter(_ref2 => {
241
+ let [_, t] = _ref2;
294
242
  return t === FIELD_TYPES.amount;
295
- })).call(_context2, function (acc, _ref8) {
296
- var _ref9 = _slicedToArray(_ref8, 1),
297
- key = _ref9[0];
298
-
299
- return _objectSpread(_objectSpread({}, params), {}, _defineProperty({}, key, formatAmount(params[key], {
300
- denomination: denomination
301
- })));
243
+ }).reduce((acc, _ref3) => {
244
+ let [key] = _ref3;
245
+ return { ...params,
246
+ [key]: formatAmount(params[key], {
247
+ denomination
248
+ })
249
+ };
302
250
  }, params);
303
-
304
- var schemaKeys = _mapInstanceProperty(schema).call(schema, function (_ref10) {
305
- var _ref11 = _slicedToArray(_ref10, 1),
306
- k = _ref11[0];
307
-
251
+ const schemaKeys = schema.map(_ref4 => {
252
+ let [k] = _ref4;
308
253
  return k;
309
254
  });
255
+ return Object.entries(params).reduce((acc, _ref5) => {
256
+ let [key, value] = _ref5;
257
+ if (schemaKeys.includes(key)) acc[key] = value;
310
258
 
311
- return _reduceInstanceProperty(_context3 = _Object$entries(params)).call(_context3, function (acc, _ref12) {
312
- var _context4;
313
-
314
- var _ref13 = _slicedToArray(_ref12, 2),
315
- key = _ref13[0],
316
- value = _ref13[1];
317
-
318
- if (_includesInstanceProperty(schemaKeys).call(schemaKeys, key)) acc[key] = value;
319
-
320
- if (_includesInstanceProperty(_context4 = ['oracleTtl', 'queryTtl', 'responseTtl']).call(_context4, key)) {
321
- acc["".concat(key, "Type")] = value.type === ORACLE_TTL_TYPES.delta ? 0 : 1;
322
- acc["".concat(key, "Value")] = value.value;
259
+ if (['oracleTtl', 'queryTtl', 'responseTtl'].includes(key)) {
260
+ acc[`${key}Type`] = value.type === ORACLE_TTL_TYPES.delta ? 0 : 1;
261
+ acc[`${key}Value`] = value.value;
323
262
  }
324
263
 
325
264
  return acc;
@@ -328,12 +267,15 @@ function transformParams(params, schema) {
328
267
 
329
268
 
330
269
  function getOracleRelativeTtl(params, txType) {
331
- var _TX_TYPE$oracleRegist;
332
-
333
- var ttlKey = (_TX_TYPE$oracleRegist = {}, _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleRegister, 'oracleTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleExtend, 'oracleTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleQuery, 'queryTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleResponse, 'responseTtl'), _TX_TYPE$oracleRegist)[txType];
334
-
335
- if (params[ttlKey] || params["".concat(ttlKey, "Value")]) {
336
- return params["".concat(ttlKey, "Value")] || params[ttlKey].value;
270
+ const ttlKey = {
271
+ [TX_TYPE.oracleRegister]: 'oracleTtl',
272
+ [TX_TYPE.oracleExtend]: 'oracleTtl',
273
+ [TX_TYPE.oracleQuery]: 'queryTtl',
274
+ [TX_TYPE.oracleResponse]: 'responseTtl'
275
+ }[txType];
276
+
277
+ if (params[ttlKey] || params[`${ttlKey}Value`]) {
278
+ return params[`${ttlKey}Value`] || params[ttlKey].value;
337
279
  }
338
280
 
339
281
  return 1;
@@ -352,32 +294,33 @@ function getOracleRelativeTtl(params, txType) {
352
294
  */
353
295
 
354
296
 
355
- export function calculateMinFee(txType, _ref14) {
356
- var _ref14$gas = _ref14.gas,
357
- gas = _ref14$gas === void 0 ? 0 : _ref14$gas,
358
- params = _ref14.params,
359
- vsn = _ref14.vsn;
360
- var multiplier = BigNumber(1e9); // 10^9 GAS_PRICE
297
+ export function calculateMinFee(txType, _ref6) {
298
+ let {
299
+ gas = 0,
300
+ params,
301
+ vsn
302
+ } = _ref6;
303
+ const multiplier = BigNumber(1e9); // 10^9 GAS_PRICE
361
304
 
362
305
  if (!params) return BigNumber(DEFAULT_FEE).times(multiplier).toString(10);
363
- var actualFee = buildFee(txType, {
364
- params: _objectSpread(_objectSpread({}, params), {}, {
306
+ let actualFee = buildFee(txType, {
307
+ params: { ...params,
365
308
  fee: 0
366
- }),
367
- multiplier: multiplier,
368
- gas: gas,
369
- vsn: vsn
309
+ },
310
+ multiplier,
311
+ gas,
312
+ vsn
370
313
  });
371
- var expected = BigNumber(0);
314
+ let expected = BigNumber(0);
372
315
 
373
316
  while (!actualFee.eq(expected)) {
374
317
  actualFee = buildFee(txType, {
375
- params: _objectSpread(_objectSpread({}, params), {}, {
318
+ params: { ...params,
376
319
  fee: actualFee
377
- }),
378
- multiplier: multiplier,
379
- gas: gas,
380
- vsn: vsn
320
+ },
321
+ multiplier,
322
+ gas,
323
+ vsn
381
324
  });
382
325
  expected = actualFee;
383
326
  }
@@ -394,24 +337,23 @@ export function calculateMinFee(txType, _ref14) {
394
337
  * @return {BigNumber}
395
338
  */
396
339
 
397
- function buildFee(txType, _ref15) {
398
- var _context5;
399
-
400
- var params = _ref15.params,
401
- _ref15$gas = _ref15.gas,
402
- gas = _ref15$gas === void 0 ? 0 : _ref15$gas,
403
- multiplier = _ref15.multiplier,
404
- vsn = _ref15.vsn;
405
-
406
- var _buildTx = buildTx(_objectSpread({}, params), txType, {
407
- vsn: vsn
408
- }),
409
- txWithOutFee = _buildTx.rlpEncoded;
410
-
411
- var txSize = txWithOutFee.length;
340
+ function buildFee(txType, _ref7) {
341
+ let {
342
+ params,
343
+ gas = 0,
344
+ multiplier,
345
+ vsn
346
+ } = _ref7;
347
+ const {
348
+ rlpEncoded: txWithOutFee
349
+ } = buildTx({ ...params
350
+ }, txType, {
351
+ vsn
352
+ });
353
+ const txSize = txWithOutFee.length;
412
354
  return TX_FEE_BASE_GAS(txType).plus(TX_FEE_OTHER_GAS(txType, txSize, {
413
355
  relativeTtl: getOracleRelativeTtl(params, txType),
414
- innerTxSize: _includesInstanceProperty(_context5 = [TX_TYPE.gaMeta, TX_TYPE.payingFor]).call(_context5, txType) ? params.tx.tx.encodedTx.rlpEncoded.length : 0
356
+ innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType) ? params.tx.tx.encodedTx.rlpEncoded.length : 0
415
357
  })).times(multiplier);
416
358
  }
417
359
  /**
@@ -430,22 +372,19 @@ function buildFee(txType, _ref15) {
430
372
 
431
373
 
432
374
  export function calculateFee() {
433
- var fee = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
434
- var txType = arguments.length > 1 ? arguments[1] : undefined;
435
-
436
- var _ref16 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
437
- _ref16$gas = _ref16.gas,
438
- gas = _ref16$gas === void 0 ? 0 : _ref16$gas,
439
- params = _ref16.params,
440
- _ref16$showWarning = _ref16.showWarning,
441
- showWarning = _ref16$showWarning === void 0 ? true : _ref16$showWarning,
442
- vsn = _ref16.vsn;
443
-
444
- if (!params && showWarning) console.warn("Can't build transaction fee, we will use DEFAULT_FEE(".concat(DEFAULT_FEE, ")"));
375
+ let fee = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
376
+ let txType = arguments.length > 1 ? arguments[1] : undefined;
377
+ let {
378
+ gas = 0,
379
+ params,
380
+ showWarning = true,
381
+ vsn
382
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
383
+ if (!params && showWarning) console.warn(`Can't build transaction fee, we will use DEFAULT_FEE(${DEFAULT_FEE})`);
445
384
  return fee || calculateMinFee(txType, {
446
- params: params,
447
- gas: gas,
448
- vsn: vsn
385
+ params,
386
+ gas,
387
+ vsn
449
388
  });
450
389
  }
451
390
  /**
@@ -458,23 +397,16 @@ export function calculateFee() {
458
397
  * @return {Object} Object with validation errors
459
398
  */
460
399
 
461
- export function validateParams(params, schema, _ref17) {
462
- var _context6;
463
-
464
- var _ref17$excludeKeys = _ref17.excludeKeys,
465
- excludeKeys = _ref17$excludeKeys === void 0 ? [] : _ref17$excludeKeys;
466
- return _reduceInstanceProperty(_context6 = _filterInstanceProperty(schema).call(schema, function (_ref18) {
467
- var _ref19 = _slicedToArray(_ref18, 1),
468
- key = _ref19[0];
469
-
470
- return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key) && key !== 'payload';
471
- })).call(_context6, function (acc, _ref20) {
472
- var _ref21 = _slicedToArray(_ref20, 3),
473
- key = _ref21[0],
474
- type = _ref21[1],
475
- prefix = _ref21[2];
476
-
477
- return _Object$assign(acc, validateField(params[key], key, type, prefix));
400
+ export function validateParams(params, schema, _ref8) {
401
+ let {
402
+ excludeKeys = []
403
+ } = _ref8;
404
+ return schema.filter(_ref9 => {
405
+ let [key] = _ref9;
406
+ return !excludeKeys.includes(key) && key !== 'payload';
407
+ }).reduce((acc, _ref10) => {
408
+ let [key, type, prefix] = _ref10;
409
+ return Object.assign(acc, validateField(params[key], key, type, prefix));
478
410
  }, {});
479
411
  }
480
412
  /**
@@ -491,38 +423,29 @@ export function validateParams(params, schema, _ref17) {
491
423
  */
492
424
 
493
425
  export function buildRawTx(params, schema) {
494
- var _ref22 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
495
- _ref22$excludeKeys = _ref22.excludeKeys,
496
- excludeKeys = _ref22$excludeKeys === void 0 ? [] : _ref22$excludeKeys,
497
- _ref22$denomination = _ref22.denomination,
498
- denomination = _ref22$denomination === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref22$denomination;
499
-
500
- var filteredSchema = _filterInstanceProperty(schema).call(schema, function (_ref23) {
501
- var _ref24 = _slicedToArray(_ref23, 1),
502
- key = _ref24[0];
503
-
504
- return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key);
426
+ let {
427
+ excludeKeys = [],
428
+ denomination = AE_AMOUNT_FORMATS.AETTOS
429
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
430
+ const filteredSchema = schema.filter(_ref11 => {
431
+ let [key] = _ref11;
432
+ return !excludeKeys.includes(key);
505
433
  }); // Transform `amount` type fields to `aettos`
506
434
 
507
-
508
435
  params = transformParams(params, filteredSchema, {
509
- denomination: denomination
436
+ denomination
510
437
  }); // Validation
511
438
 
512
- var valid = validateParams(params, schema, {
513
- excludeKeys: excludeKeys
439
+ const valid = validateParams(params, schema, {
440
+ excludeKeys
514
441
  });
515
442
 
516
- if (_Object$keys(valid).length) {
517
- throw new Error('Transaction build error. ' + _JSON$stringify(valid));
443
+ if (Object.keys(valid).length) {
444
+ throw new Error('Transaction build error. ' + JSON.stringify(valid));
518
445
  }
519
446
 
520
- return _mapInstanceProperty(filteredSchema).call(filteredSchema, function (_ref25) {
521
- var _ref26 = _slicedToArray(_ref25, 3),
522
- key = _ref26[0],
523
- fieldType = _ref26[1],
524
- prefix = _ref26[2];
525
-
447
+ return filteredSchema.map(_ref12 => {
448
+ let [key, fieldType, prefix] = _ref12;
526
449
  return serializeField(params[key], fieldType, prefix);
527
450
  });
528
451
  }
@@ -536,13 +459,11 @@ export function buildRawTx(params, schema) {
536
459
  */
537
460
 
538
461
  export function unpackRawTx(binary, schema) {
539
- return _reduceInstanceProperty(schema).call(schema, function (acc, _ref27, index) {
540
- var _ref28 = _slicedToArray(_ref27, 3),
541
- key = _ref28[0],
542
- fieldType = _ref28[1],
543
- prefix = _ref28[2];
544
-
545
- return _Object$assign(acc, _defineProperty({}, key, deserializeField(binary[index], fieldType, prefix)));
462
+ return schema.reduce((acc, _ref13, index) => {
463
+ let [key, fieldType, prefix] = _ref13;
464
+ return Object.assign(acc, {
465
+ [key]: deserializeField(binary[index], fieldType, prefix)
466
+ });
546
467
  }, {});
547
468
  }
548
469
  /**
@@ -553,24 +474,22 @@ export function unpackRawTx(binary, schema) {
553
474
  * @return {Object} Schema
554
475
  */
555
476
 
556
- var getSchema = function getSchema(_ref29) {
557
- var vsn = _ref29.vsn,
558
- objId = _ref29.objId,
559
- type = _ref29.type;
560
- var isDeserialize = !!objId;
561
- var firstKey = isDeserialize ? objId : type;
562
- var schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA;
477
+ const getSchema = _ref14 => {
478
+ let {
479
+ vsn,
480
+ objId,
481
+ type
482
+ } = _ref14;
483
+ const isDeserialize = !!objId;
484
+ const firstKey = isDeserialize ? objId : type;
485
+ const schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA;
563
486
 
564
487
  if (!schema[firstKey]) {
565
- var _context7;
566
-
567
- throw new Error(_concatInstanceProperty(_context7 = "Transaction ".concat(isDeserialize ? 'deserialization' : 'serialization', " not implemented for ")).call(_context7, isDeserialize ? 'tag ' + objId : type));
488
+ throw new Error(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type}`);
568
489
  }
569
490
 
570
491
  if (!schema[firstKey][vsn]) {
571
- var _context8, _context9;
572
-
573
- throw new Error(_concatInstanceProperty(_context8 = _concatInstanceProperty(_context9 = "Transaction ".concat(isDeserialize ? 'deserialization' : 'serialization', " not implemented for ")).call(_context9, isDeserialize ? 'tag ' + objId : type, " version ")).call(_context8, vsn));
492
+ throw new Error(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type} version ${vsn}`);
574
493
  }
575
494
 
576
495
  return schema[firstKey][vsn];
@@ -590,42 +509,29 @@ var getSchema = function getSchema(_ref29) {
590
509
 
591
510
 
592
511
  export function buildTx(params, type) {
593
- var _context10;
594
-
595
- var _ref30 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
596
- _ref30$excludeKeys = _ref30.excludeKeys,
597
- excludeKeys = _ref30$excludeKeys === void 0 ? [] : _ref30$excludeKeys,
598
- _ref30$prefix = _ref30.prefix,
599
- prefix = _ref30$prefix === void 0 ? 'tx' : _ref30$prefix,
600
- _ref30$vsn = _ref30.vsn,
601
- vsn = _ref30$vsn === void 0 ? VSN : _ref30$vsn,
602
- _ref30$denomination = _ref30.denomination,
603
- denomination = _ref30$denomination === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref30$denomination;
604
-
605
- var _getSchema = getSchema({
606
- type: type,
607
- vsn: vsn
608
- }),
609
- _getSchema2 = _slicedToArray(_getSchema, 2),
610
- schema = _getSchema2[0],
611
- tag = _getSchema2[1];
612
-
613
- var binary = _filterInstanceProperty(_context10 = buildRawTx(_objectSpread(_objectSpread({}, params), {}, {
512
+ let {
513
+ excludeKeys = [],
514
+ prefix = 'tx',
515
+ vsn = VSN,
516
+ denomination = AE_AMOUNT_FORMATS.AETTOS
517
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
518
+ const [schema, tag] = getSchema({
519
+ type,
520
+ vsn
521
+ });
522
+ const binary = buildRawTx({ ...params,
614
523
  VSN: vsn,
615
- tag: tag
616
- }), schema, {
617
- excludeKeys: excludeKeys,
524
+ tag
525
+ }, schema, {
526
+ excludeKeys,
618
527
  denomination: params.denomination || denomination
619
- })).call(_context10, function (e) {
620
- return e !== undefined;
621
- });
622
-
623
- var rlpEncoded = rlpEncode(binary);
624
- var tx = encode(rlpEncoded, prefix);
528
+ }).filter(e => e !== undefined);
529
+ const rlpEncoded = rlpEncode(binary);
530
+ const tx = encode(rlpEncoded, prefix);
625
531
  return {
626
- tx: tx,
627
- rlpEncoded: rlpEncoded,
628
- binary: binary,
532
+ tx,
533
+ rlpEncoded,
534
+ binary,
629
535
  txObject: unpackRawTx(binary, schema)
630
536
  };
631
537
  }
@@ -640,25 +546,21 @@ export function buildTx(params, type) {
640
546
  */
641
547
 
642
548
  export function unpackTx(encodedTx) {
643
- var fromRlpBinary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
644
- var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'tx';
645
- var rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix);
646
- var binary = rlpDecode(rlpEncoded);
647
- var objId = readInt(binary[0]);
648
- var vsn = readInt(binary[1]);
649
-
650
- var _getSchema3 = getSchema({
651
- objId: objId,
652
- vsn: vsn
653
- }),
654
- _getSchema4 = _slicedToArray(_getSchema3, 1),
655
- schema = _getSchema4[0];
656
-
549
+ let fromRlpBinary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
550
+ let prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'tx';
551
+ const rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix);
552
+ const binary = rlpDecode(rlpEncoded);
553
+ const objId = readInt(binary[0]);
554
+ const vsn = readInt(binary[1]);
555
+ const [schema] = getSchema({
556
+ objId,
557
+ vsn
558
+ });
657
559
  return {
658
560
  txType: OBJECT_ID_TX_TYPE[objId],
659
561
  tx: unpackRawTx(binary, schema),
660
- rlpEncoded: rlpEncoded,
661
- binary: binary
562
+ rlpEncoded,
563
+ binary
662
564
  };
663
565
  }
664
566
  /**
@@ -670,17 +572,17 @@ export function unpackTx(encodedTx) {
670
572
  */
671
573
 
672
574
  export function buildTxHash(rawTx) {
673
- var data = typeof rawTx === 'string' && _startsWithInstanceProperty(rawTx).call(rawTx, 'tx_') ? decode(rawTx, 'tx') : rawTx;
575
+ const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx, 'tx') : rawTx;
674
576
  return encode(hash(data), 'th');
675
577
  }
676
578
  export default {
677
- calculateMinFee: calculateMinFee,
678
- calculateFee: calculateFee,
679
- unpackTx: unpackTx,
680
- unpackRawTx: unpackRawTx,
681
- buildTx: buildTx,
682
- buildRawTx: buildRawTx,
683
- validateParams: validateParams,
684
- buildTxHash: buildTxHash
579
+ calculateMinFee,
580
+ calculateFee,
581
+ unpackTx,
582
+ unpackRawTx,
583
+ buildTx,
584
+ buildRawTx,
585
+ validateParams,
586
+ buildTxHash
685
587
  };
686
588
  //# sourceMappingURL=index.js.map