@aeternity/aepp-sdk 13.0.0-beta.0 → 13.0.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 (57) hide show
  1. package/README.md +1 -1
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  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 +68 -27
  7. package/dist/aepp-sdk.js.map +1 -1
  8. package/es/AeSdkAepp.d.ts +5 -4
  9. package/es/AeSdkAepp.mjs +13 -17
  10. package/es/AeSdkAepp.mjs.map +1 -1
  11. package/es/account/Generalized.mjs +1 -1
  12. package/es/account/Generalized.mjs.map +1 -1
  13. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  14. package/es/chain.mjs +1 -1
  15. package/es/chain.mjs.map +1 -1
  16. package/es/contract/Contract.d.ts +1 -2
  17. package/es/contract/Contract.mjs +23 -4
  18. package/es/contract/Contract.mjs.map +1 -1
  19. package/es/contract/compiler/Base.d.ts +3 -0
  20. package/es/contract/compiler/Base.mjs.map +1 -1
  21. package/es/index-browser.d.ts +1 -1
  22. package/es/index-browser.mjs +1 -1
  23. package/es/index-browser.mjs.map +1 -1
  24. package/es/tx/execution-cost.d.ts +17 -0
  25. package/es/tx/execution-cost.mjs +17 -0
  26. package/es/tx/execution-cost.mjs.map +1 -1
  27. package/es/utils/amount-formatter.d.ts +1 -2
  28. package/es/utils/amount-formatter.mjs +2 -2
  29. package/es/utils/amount-formatter.mjs.map +1 -1
  30. package/es/utils/errors.mjs +1 -1
  31. package/es/utils/errors.mjs.map +1 -1
  32. package/package.json +3 -3
  33. package/src/AeSdkAepp.ts +16 -14
  34. package/src/account/Generalized.ts +1 -1
  35. package/src/aepp-wallet-communication/rpc/types.ts +1 -0
  36. package/src/chain.ts +1 -1
  37. package/src/contract/Contract.ts +29 -8
  38. package/src/contract/compiler/Base.ts +3 -0
  39. package/src/index-browser.ts +3 -1
  40. package/src/tx/execution-cost.ts +17 -0
  41. package/src/utils/amount-formatter.ts +1 -1
  42. package/src/utils/errors.ts +1 -1
  43. package/types-legacy/ts4.2/AeSdkAepp.d.ts +5 -4
  44. package/types-legacy/ts4.2/contract/Contract.d.ts +1 -2
  45. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +3 -0
  46. package/types-legacy/ts4.2/index-browser.d.ts +1 -1
  47. package/types-legacy/ts4.2/tx/execution-cost.d.ts +17 -0
  48. package/types-legacy/ts4.2/utils/amount-formatter.d.ts +1 -2
  49. package/types-legacy/ts4.5/AeSdkAepp.d.ts +5 -4
  50. package/types-legacy/ts4.5/contract/Contract.d.ts +1 -2
  51. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +3 -0
  52. package/types-legacy/ts4.5/index-browser.d.ts +1 -1
  53. package/types-legacy/ts4.5/tx/execution-cost.d.ts +17 -0
  54. package/types-legacy/ts4.5/utils/amount-formatter.d.ts +1 -2
  55. package/es/typings/@aeternity__aepp-calldata/index.d.mjs +0 -2
  56. package/es/typings/@aeternity__aepp-calldata/index.d.mjs.map +0 -1
  57. package/src/typings/@aeternity__aepp-calldata/index.d.ts +0 -20
package/dist/aepp-sdk.js CHANGED
@@ -5109,6 +5109,7 @@ __webpack_require__.d(__webpack_exports__, {
5109
5109
  "DryRunError": () => (/* reexport */ DryRunError),
5110
5110
  "DuplicateContractError": () => (/* reexport */ DuplicateContractError),
5111
5111
  "DuplicateNodeError": () => (/* reexport */ DuplicateNodeError),
5112
+ "Encoded": () => (/* reexport */ encoder_types_namespaceObject),
5112
5113
  "Encoding": () => (/* reexport */ Encoding),
5113
5114
  "IllegalArgumentError": () => (/* reexport */ IllegalArgumentError),
5114
5115
  "IllegalBidFeeError": () => (/* reexport */ IllegalBidFeeError),
@@ -5269,6 +5270,7 @@ __webpack_require__.d(__webpack_exports__, {
5269
5270
  "pollForQueries": () => (/* reexport */ pollForQueries),
5270
5271
  "pollForQueryResponse": () => (/* reexport */ pollForQueryResponse),
5271
5272
  "postQueryToOracle": () => (/* reexport */ postQueryToOracle),
5273
+ "prefixedAmount": () => (/* reexport */ prefixedAmount),
5272
5274
  "produceNameId": () => (/* reexport */ produceNameId),
5273
5275
  "readInt": () => (/* reexport */ readInt),
5274
5276
  "recover": () => (/* reexport */ recover),
@@ -5292,6 +5294,13 @@ __webpack_require__.d(__webpack_exports__, {
5292
5294
  "walletDetector": () => (/* reexport */ wallet_detector)
5293
5295
  });
5294
5296
 
5297
+ // NAMESPACE OBJECT: ./src/utils/encoder-types.ts
5298
+ var encoder_types_namespaceObject = {};
5299
+ __webpack_require__.r(encoder_types_namespaceObject);
5300
+ __webpack_require__.d(encoder_types_namespaceObject, {
5301
+ "Encoding": () => (Encoding)
5302
+ });
5303
+
5295
5304
  // NAMESPACE OBJECT: ./src/apis/node/models/mappers.ts
5296
5305
  var mappers_namespaceObject = {};
5297
5306
  __webpack_require__.r(mappers_namespaceObject);
@@ -5987,7 +5996,7 @@ class MissingContractAddressError extends ContractError {
5987
5996
  */
5988
5997
  class MissingContractDefError extends ContractError {
5989
5998
  constructor() {
5990
- super('Either ACI or source code is required');
5999
+ super('Either ACI or sourceCode or sourceCodePath is required');
5991
6000
  this.name = 'MissingContractDefError';
5992
6001
  }
5993
6002
  }
@@ -6338,9 +6347,9 @@ const getLowerBoundPrefix = exponent => {
6338
6347
  var _prefixes$find;
6339
6348
  return (_prefixes$find = prefixes.find(p => p.magnitude <= exponent)) !== null && _prefixes$find !== void 0 ? _prefixes$find : prefixes[prefixes.length - 1];
6340
6349
  };
6341
- /* harmony default export */ const amount_formatter = (rawValue => {
6350
+ const prefixedAmount = rawValue => {
6342
6351
  var _value$e;
6343
- const value = new BigNumber(rawValue);
6352
+ const value = new (external_bignumber_js_default())(rawValue);
6344
6353
  const exp = (_value$e = value.e) !== null && _value$e !== void 0 ? _value$e : 0;
6345
6354
  const {
6346
6355
  name,
@@ -6348,7 +6357,7 @@ const getLowerBoundPrefix = exponent => {
6348
6357
  } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp);
6349
6358
  const v = value.shiftedBy(-magnitude).precision(9 + Math.min(exp - magnitude, 0)).toFixed();
6350
6359
  return `${v}${name !== '' ? ' ' : ''}${name}`;
6351
- });
6360
+ };
6352
6361
  // EXTERNAL MODULE: external "tweetnacl"
6353
6362
  var external_tweetnacl_ = __webpack_require__(79);
6354
6363
  var external_tweetnacl_default = /*#__PURE__*/__webpack_require__.n(external_tweetnacl_);
@@ -14510,6 +14519,23 @@ class AccountMemory extends AccountBase {
14510
14519
  * Calculates the cost of transaction execution
14511
14520
  * Provides an upper cost of contract-call-related transactions because of `gasLimit`.
14512
14521
  * Also assumes that oracle query fee is 0 unless it is provided in options.
14522
+ *
14523
+ * The idea is that if you need to show transaction details with some accuracy you can define
14524
+ * expense fields that you want to show separately. And to show `getExecutionCost` result as a fee,
14525
+ * subtracting all fields shown separately.
14526
+ *
14527
+ * @example
14528
+ * ```vue
14529
+ * <template>
14530
+ * Amount: {{ txUnpacked.amount }}
14531
+ * Name fee: {{ txUnpacked.nameFee }}
14532
+ * Other fees: {{ getExecutionCost(txEncoded) - txUnpacked.amount - txUnpacked.nameFee }}
14533
+ * </template>
14534
+ * ```
14535
+ *
14536
+ * Doing this way you won't worry to show wrong fee for a transaction you may not support. Because
14537
+ * the SDK calculates the overall price of any transaction on its side.
14538
+ *
14513
14539
  * @param transaction - Transaction to calculate the cost of
14514
14540
  * @param innerTx - Should be provided if transaction wrapped with Tag.PayingForTx
14515
14541
  * @param gasUsed - Amount of gas actually used to make calculation more accurate
@@ -14860,7 +14886,7 @@ async function getHeight({
14860
14886
  * @returns The transaction as it was mined
14861
14887
  */
14862
14888
  async function poll(th, {
14863
- blocks = 10,
14889
+ blocks = 5,
14864
14890
  interval,
14865
14891
  onNode,
14866
14892
  ...options
@@ -15991,9 +16017,22 @@ class Contract {
15991
16017
  */
15992
16018
  async $compile() {
15993
16019
  if (this.$options.bytecode != null) return this.$options.bytecode;
15994
- if (this.$options.sourceCode == null) throw new IllegalArgumentError('Can\'t compile without source code');
15995
16020
  if (this.$options.onCompiler == null) throw new IllegalArgumentError('Can\'t compile without compiler');
15996
- this.$options.bytecode = (await this.$options.onCompiler.compileBySourceCode(this.$options.sourceCode, this.$options.fileSystem)).bytecode;
16021
+ if (this.$options.sourceCode != null) {
16022
+ const {
16023
+ bytecode
16024
+ } = await this.$options.onCompiler.compileBySourceCode(this.$options.sourceCode, this.$options.fileSystem);
16025
+ this.$options.bytecode = bytecode;
16026
+ }
16027
+ if (this.$options.sourceCodePath != null) {
16028
+ const {
16029
+ bytecode
16030
+ } = await this.$options.onCompiler.compile(this.$options.sourceCodePath);
16031
+ this.$options.bytecode = bytecode;
16032
+ }
16033
+ if (this.$options.bytecode == null) {
16034
+ throw new IllegalArgumentError('Can\'t compile without sourceCode and sourceCodePath');
16035
+ }
15997
16036
  return this.$options.bytecode;
15998
16037
  }
15999
16038
  async $getCallResultByTxHash(hash, fnName, options) {
@@ -16256,7 +16295,7 @@ class Contract {
16256
16295
  onNode
16257
16296
  });
16258
16297
  }
16259
- if (address == null && sourceCode == null && bytecode == null) {
16298
+ if (address == null && sourceCode == null && sourceCodePath == null && bytecode == null) {
16260
16299
  throw new MissingContractAddressError('Can\'t create instance by ACI without address');
16261
16300
  }
16262
16301
  if (address != null) {
@@ -16274,13 +16313,19 @@ class Contract {
16274
16313
  if (bytecode != null) isValid = bytecode === onChanBytecode;else if (sourceCode != null) {
16275
16314
  if (onCompiler == null) throw new IllegalArgumentError('Can\'t validate bytecode without compiler');
16276
16315
  isValid = await onCompiler.validateBySourceCode(onChanBytecode, sourceCode, fileSystem);
16316
+ } else if (sourceCodePath != null) {
16317
+ if (onCompiler == null) throw new IllegalArgumentError('Can\'t validate bytecode without compiler');
16318
+ isValid = await onCompiler.validate(onChanBytecode, sourceCodePath);
16319
+ }
16320
+ if (!isValid) {
16321
+ throw new BytecodeMismatchError((sourceCode !== null && sourceCode !== void 0 ? sourceCode : sourceCodePath) != null ? 'source code' : 'bytecode');
16277
16322
  }
16278
- if (!isValid) throw new BytecodeMismatchError(sourceCode != null ? 'source code' : 'bytecode');
16279
16323
  }
16280
16324
  return new ContractWithMethods({
16281
16325
  onCompiler,
16282
16326
  onNode,
16283
16327
  sourceCode,
16328
+ sourceCodePath,
16284
16329
  bytecode,
16285
16330
  aci,
16286
16331
  address,
@@ -17741,11 +17786,19 @@ class AeSdkAepp extends AeSdkBase {
17741
17786
  */
17742
17787
  async connectToWallet(connection, {
17743
17788
  connectNode = false,
17744
- name = 'wallet-node',
17745
- select = false
17789
+ name = 'wallet-node'
17746
17790
  } = {}) {
17747
17791
  if (this.rpcClient != null) throw new AlreadyConnectedError('You are already connected to wallet');
17748
17792
  let disconnectParams;
17793
+ const updateNetwork = params => {
17794
+ if (connectNode) {
17795
+ var _params$node;
17796
+ if (((_params$node = params.node) === null || _params$node === void 0 ? void 0 : _params$node.url) == null) throw new RpcConnectionError('Missing URLs of the Node');
17797
+ this.pool.delete(name);
17798
+ this.addNode(name, new Node_Node(params.node.url), true);
17799
+ }
17800
+ this.onNetworkChange(params);
17801
+ };
17749
17802
  const client = new RpcClient(connection, () => {
17750
17803
  delete this.rpcClient;
17751
17804
  delete this._accounts;
@@ -17755,31 +17808,19 @@ class AeSdkAepp extends AeSdkBase {
17755
17808
  this._accounts = params;
17756
17809
  this.onAddressChange(params);
17757
17810
  },
17758
- [METHODS.updateNetwork]: params => {
17759
- const {
17760
- node
17761
- } = params;
17762
- if (node != null) this.addNode(node.name, new Node_Node(node.url), true);
17763
- this.onNetworkChange(params);
17764
- },
17811
+ [METHODS.updateNetwork]: updateNetwork,
17765
17812
  [METHODS.closeConnection]: params => {
17766
17813
  disconnectParams = params;
17767
17814
  client.connection.disconnect();
17768
17815
  },
17769
17816
  [METHODS.readyToConnect]: () => {}
17770
17817
  });
17771
- const {
17772
- node,
17773
- ...walletInfo
17774
- } = await client.request(METHODS.connect, {
17818
+ const walletInfo = await client.request(METHODS.connect, {
17775
17819
  name: this.name,
17776
17820
  version: RPC_VERSION,
17777
17821
  connectNode
17778
17822
  });
17779
- if (connectNode) {
17780
- if (node == null) throw new RpcConnectionError('Missing URLs of the Node');
17781
- this.addNode(name, new Node_Node(node.url), select);
17782
- }
17823
+ updateNetwork(walletInfo);
17783
17824
  this.rpcClient = client;
17784
17825
  return walletInfo;
17785
17826
  }
@@ -18196,7 +18237,7 @@ class AccountGeneralized extends AccountBase {
18196
18237
  throw new InternalError('Account in generalised, but authFun not provided');
18197
18238
  }
18198
18239
  if (sourceCode == null || args == null) {
18199
- throw new InvalidAuthDataError('Auth data must contain source code and arguments.');
18240
+ throw new InvalidAuthDataError('Auth data must contain sourceCode and args or callData.');
18200
18241
  }
18201
18242
  const contract = await contract_Contract.initialize({
18202
18243
  onCompiler,