@fuel-ts/account 0.91.0 → 0.92.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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ var src_exports = {};
59
59
  __export(src_exports, {
60
60
  Account: () => Account,
61
61
  AddressType: () => AddressType,
62
+ BLOCKS_PAGE_SIZE_LIMIT: () => BLOCKS_PAGE_SIZE_LIMIT,
62
63
  BaseTransactionRequest: () => BaseTransactionRequest,
63
64
  BaseWalletUnlocked: () => BaseWalletUnlocked,
64
65
  CHAIN_IDS: () => CHAIN_IDS,
@@ -83,6 +84,7 @@ __export(src_exports, {
83
84
  Predicate: () => Predicate,
84
85
  PrivateKeyVault: () => PrivateKeyVault,
85
86
  Provider: () => Provider,
87
+ RESOURCES_PAGE_SIZE_LIMIT: () => RESOURCES_PAGE_SIZE_LIMIT,
86
88
  ScriptTransactionRequest: () => ScriptTransactionRequest,
87
89
  Signer: () => Signer,
88
90
  StorageAbstract: () => StorageAbstract,
@@ -922,6 +924,9 @@ ${TransactionFragmentDoc}`;
922
924
  var GetBlocksDocument = import_graphql_tag.default`
923
925
  query getBlocks($after: String, $before: String, $first: Int, $last: Int) {
924
926
  blocks(after: $after, before: $before, first: $first, last: $last) {
927
+ pageInfo {
928
+ ...pageInfoFragment
929
+ }
925
930
  edges {
926
931
  node {
927
932
  ...blockFragment
@@ -929,7 +934,8 @@ var GetBlocksDocument = import_graphql_tag.default`
929
934
  }
930
935
  }
931
936
  }
932
- ${BlockFragmentDoc}`;
937
+ ${PageInfoFragmentDoc}
938
+ ${BlockFragmentDoc}`;
933
939
  var GetCoinDocument = import_graphql_tag.default`
934
940
  query getCoin($coinId: UtxoId!) {
935
941
  coin(utxoId: $coinId) {
@@ -946,6 +952,9 @@ var GetCoinsDocument = import_graphql_tag.default`
946
952
  first: $first
947
953
  last: $last
948
954
  ) {
955
+ pageInfo {
956
+ ...pageInfoFragment
957
+ }
949
958
  edges {
950
959
  node {
951
960
  ...coinFragment
@@ -953,7 +962,8 @@ var GetCoinsDocument = import_graphql_tag.default`
953
962
  }
954
963
  }
955
964
  }
956
- ${CoinFragmentDoc}`;
965
+ ${PageInfoFragmentDoc}
966
+ ${CoinFragmentDoc}`;
957
967
  var GetCoinsToSpendDocument = import_graphql_tag.default`
958
968
  query getCoinsToSpend($owner: Address!, $queryPerAsset: [SpendQueryElementInput!]!, $excludedIds: ExcludeInput) {
959
969
  coinsToSpend(
@@ -1012,6 +1022,9 @@ var GetBalancesDocument = import_graphql_tag.default`
1012
1022
  first: $first
1013
1023
  last: $last
1014
1024
  ) {
1025
+ pageInfo {
1026
+ ...pageInfoFragment
1027
+ }
1015
1028
  edges {
1016
1029
  node {
1017
1030
  ...balanceFragment
@@ -1019,7 +1032,8 @@ var GetBalancesDocument = import_graphql_tag.default`
1019
1032
  }
1020
1033
  }
1021
1034
  }
1022
- ${BalanceFragmentDoc}`;
1035
+ ${PageInfoFragmentDoc}
1036
+ ${BalanceFragmentDoc}`;
1023
1037
  var GetMessagesDocument = import_graphql_tag.default`
1024
1038
  query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
1025
1039
  messages(
@@ -1029,6 +1043,9 @@ var GetMessagesDocument = import_graphql_tag.default`
1029
1043
  first: $first
1030
1044
  last: $last
1031
1045
  ) {
1046
+ pageInfo {
1047
+ ...pageInfoFragment
1048
+ }
1032
1049
  edges {
1033
1050
  node {
1034
1051
  ...messageFragment
@@ -1036,7 +1053,8 @@ var GetMessagesDocument = import_graphql_tag.default`
1036
1053
  }
1037
1054
  }
1038
1055
  }
1039
- ${MessageFragmentDoc}`;
1056
+ ${PageInfoFragmentDoc}
1057
+ ${MessageFragmentDoc}`;
1040
1058
  var GetMessageProofDocument = import_graphql_tag.default`
1041
1059
  query getMessageProof($transactionId: TransactionId!, $nonce: Nonce!, $commitBlockId: BlockId, $commitBlockHeight: U32) {
1042
1060
  messageProof(
@@ -3878,12 +3896,18 @@ var TransactionResponse = class {
3878
3896
  await this.fetch();
3879
3897
  }
3880
3898
  /**
3881
- * Waits for transaction to complete and returns the result.
3899
+ * Assembles the result of a transaction by retrieving the transaction summary,
3900
+ * decoding logs (if available), and handling transaction failure.
3882
3901
  *
3883
- * @returns The completed transaction result
3902
+ * This method can be used to obtain the result of a transaction that has just
3903
+ * been submitted or one that has already been processed.
3904
+ *
3905
+ * @template TTransactionType - The type of the transaction.
3906
+ * @param contractsAbiMap - The map of contract ABIs.
3907
+ * @returns - The assembled transaction result.
3908
+ * @throws If the transaction status is a failure.
3884
3909
  */
3885
- async waitForResult(contractsAbiMap) {
3886
- await this.waitForStatusChange();
3910
+ async assembleResult(contractsAbiMap) {
3887
3911
  const transactionSummary = await this.getTransactionSummary(contractsAbiMap);
3888
3912
  const transactionResult = {
3889
3913
  gqlTransaction: this.gqlTransaction,
@@ -3909,6 +3933,15 @@ var TransactionResponse = class {
3909
3933
  }
3910
3934
  return transactionResult;
3911
3935
  }
3936
+ /**
3937
+ * Waits for transaction to complete and returns the result.
3938
+ *
3939
+ * @returns The completed transaction result
3940
+ */
3941
+ async waitForResult(contractsAbiMap) {
3942
+ await this.waitForStatusChange();
3943
+ return this.assembleResult(contractsAbiMap);
3944
+ }
3912
3945
  /**
3913
3946
  * Waits for transaction to complete and returns the result.
3914
3947
  *
@@ -3972,6 +4005,8 @@ var mergeQuantities = (...coinQuantities) => {
3972
4005
 
3973
4006
  // src/providers/provider.ts
3974
4007
  var MAX_RETRIES = 10;
4008
+ var RESOURCES_PAGE_SIZE_LIMIT = 512;
4009
+ var BLOCKS_PAGE_SIZE_LIMIT = 5;
3975
4010
  var processGqlChain = (chain) => {
3976
4011
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3977
4012
  const {
@@ -4615,7 +4650,7 @@ Supported fuel-core version: ${supportedVersion}.`
4615
4650
  /**
4616
4651
  * Returns a transaction cost to enable user
4617
4652
  * to set gasLimit and also reserve balance amounts
4618
- * on the the transaction.
4653
+ * on the transaction.
4619
4654
  *
4620
4655
  * @param transactionRequestLike - The transaction request object.
4621
4656
  * @param transactionCostParams - The transaction cost parameters (optional).
@@ -4726,20 +4761,27 @@ Supported fuel-core version: ${supportedVersion}.`
4726
4761
  */
4727
4762
  async getCoins(owner, assetId, paginationArgs) {
4728
4763
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4729
- const result = await this.operations.getCoins({
4730
- first: 10,
4731
- ...paginationArgs,
4764
+ const {
4765
+ coins: { edges, pageInfo }
4766
+ } = await this.operations.getCoins({
4767
+ ...this.validatePaginationArgs({
4768
+ paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
4769
+ inputArgs: paginationArgs
4770
+ }),
4732
4771
  filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4733
4772
  });
4734
- const coins = result.coins.edges.map((edge) => edge.node);
4735
- return coins.map((coin) => ({
4736
- id: coin.utxoId,
4737
- assetId: coin.assetId,
4738
- amount: (0, import_math17.bn)(coin.amount),
4739
- owner: import_address3.Address.fromAddressOrString(coin.owner),
4740
- blockCreated: (0, import_math17.bn)(coin.blockCreated),
4741
- txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
4773
+ const coins = edges.map(({ node }) => ({
4774
+ id: node.utxoId,
4775
+ assetId: node.assetId,
4776
+ amount: (0, import_math17.bn)(node.amount),
4777
+ owner: import_address3.Address.fromAddressOrString(node.owner),
4778
+ blockCreated: (0, import_math17.bn)(node.blockCreated),
4779
+ txCreatedIdx: (0, import_math17.bn)(node.txCreatedIdx)
4742
4780
  }));
4781
+ return {
4782
+ coins,
4783
+ pageInfo
4784
+ };
4743
4785
  }
4744
4786
  /**
4745
4787
  * Returns resources for the given owner satisfying the spend query.
@@ -4832,14 +4874,21 @@ Supported fuel-core version: ${supportedVersion}.`
4832
4874
  * @returns A promise that resolves to the blocks.
4833
4875
  */
4834
4876
  async getBlocks(params) {
4835
- const { blocks: fetchedData } = await this.operations.getBlocks(params);
4836
- const blocks = fetchedData.edges.map(({ node: block }) => ({
4877
+ const {
4878
+ blocks: { edges, pageInfo }
4879
+ } = await this.operations.getBlocks({
4880
+ ...this.validatePaginationArgs({
4881
+ paginationLimit: BLOCKS_PAGE_SIZE_LIMIT,
4882
+ inputArgs: params
4883
+ })
4884
+ });
4885
+ const blocks = edges.map(({ node: block }) => ({
4837
4886
  id: block.id,
4838
4887
  height: (0, import_math17.bn)(block.height),
4839
4888
  time: block.header.time,
4840
4889
  transactionIds: block.transactions.map((tx) => tx.id)
4841
4890
  }));
4842
- return blocks;
4891
+ return { blocks, pageInfo };
4843
4892
  }
4844
4893
  /**
4845
4894
  * Returns block matching the given ID or type, including transaction data.
@@ -4949,17 +4998,22 @@ Supported fuel-core version: ${supportedVersion}.`
4949
4998
  * @param paginationArgs - Pagination arguments (optional).
4950
4999
  * @returns A promise that resolves to the balances.
4951
5000
  */
4952
- async getBalances(owner, paginationArgs) {
4953
- const result = await this.operations.getBalances({
4954
- first: 10,
4955
- ...paginationArgs,
5001
+ async getBalances(owner) {
5002
+ const {
5003
+ balances: { edges }
5004
+ } = await this.operations.getBalances({
5005
+ /**
5006
+ * The query parameters for this method were designed to support pagination,
5007
+ * but the current Fuel-Core implementation does not support pagination yet.
5008
+ */
5009
+ first: 1e4,
4956
5010
  filter: { owner: import_address3.Address.fromAddressOrString(owner).toB256() }
4957
5011
  });
4958
- const balances = result.balances.edges.map((edge) => edge.node);
4959
- return balances.map((balance) => ({
4960
- assetId: balance.assetId,
4961
- amount: (0, import_math17.bn)(balance.amount)
5012
+ const balances = edges.map(({ node }) => ({
5013
+ assetId: node.assetId,
5014
+ amount: (0, import_math17.bn)(node.amount)
4962
5015
  }));
5016
+ return { balances };
4963
5017
  }
4964
5018
  /**
4965
5019
  * Returns message for the given address.
@@ -4969,27 +5023,34 @@ Supported fuel-core version: ${supportedVersion}.`
4969
5023
  * @returns A promise that resolves to the messages.
4970
5024
  */
4971
5025
  async getMessages(address, paginationArgs) {
4972
- const result = await this.operations.getMessages({
4973
- first: 10,
4974
- ...paginationArgs,
5026
+ const {
5027
+ messages: { edges, pageInfo }
5028
+ } = await this.operations.getMessages({
5029
+ ...this.validatePaginationArgs({
5030
+ inputArgs: paginationArgs,
5031
+ paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
5032
+ }),
4975
5033
  owner: import_address3.Address.fromAddressOrString(address).toB256()
4976
5034
  });
4977
- const messages = result.messages.edges.map((edge) => edge.node);
4978
- return messages.map((message) => ({
5035
+ const messages = edges.map(({ node }) => ({
4979
5036
  messageId: import_transactions20.InputMessageCoder.getMessageId({
4980
- sender: message.sender,
4981
- recipient: message.recipient,
4982
- nonce: message.nonce,
4983
- amount: (0, import_math17.bn)(message.amount),
4984
- data: message.data
5037
+ sender: node.sender,
5038
+ recipient: node.recipient,
5039
+ nonce: node.nonce,
5040
+ amount: (0, import_math17.bn)(node.amount),
5041
+ data: node.data
4985
5042
  }),
4986
- sender: import_address3.Address.fromAddressOrString(message.sender),
4987
- recipient: import_address3.Address.fromAddressOrString(message.recipient),
4988
- nonce: message.nonce,
4989
- amount: (0, import_math17.bn)(message.amount),
4990
- data: import_transactions20.InputMessageCoder.decodeData(message.data),
4991
- daHeight: (0, import_math17.bn)(message.daHeight)
5043
+ sender: import_address3.Address.fromAddressOrString(node.sender),
5044
+ recipient: import_address3.Address.fromAddressOrString(node.recipient),
5045
+ nonce: node.nonce,
5046
+ amount: (0, import_math17.bn)(node.amount),
5047
+ data: import_transactions20.InputMessageCoder.decodeData(node.data),
5048
+ daHeight: (0, import_math17.bn)(node.daHeight)
4992
5049
  }));
5050
+ return {
5051
+ messages,
5052
+ pageInfo
5053
+ };
4993
5054
  }
4994
5055
  /**
4995
5056
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -5168,6 +5229,41 @@ Supported fuel-core version: ${supportedVersion}.`
5168
5229
  }
5169
5230
  return relayedTransactionStatus;
5170
5231
  }
5232
+ /**
5233
+ * @hidden
5234
+ */
5235
+ validatePaginationArgs(params) {
5236
+ const { paginationLimit, inputArgs = {} } = params;
5237
+ const { first, last, after, before } = inputArgs;
5238
+ if (after && before) {
5239
+ throw new import_errors14.FuelError(
5240
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5241
+ 'Pagination arguments "after" and "before" cannot be used together'
5242
+ );
5243
+ }
5244
+ if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
5245
+ throw new import_errors14.FuelError(
5246
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5247
+ `Pagination limit for this query cannot exceed ${paginationLimit} items`
5248
+ );
5249
+ }
5250
+ if (first && before) {
5251
+ throw new import_errors14.FuelError(
5252
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5253
+ 'The use of pagination argument "first" with "before" is not supported'
5254
+ );
5255
+ }
5256
+ if (last && after) {
5257
+ throw new import_errors14.FuelError(
5258
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5259
+ 'The use of pagination argument "last" with "after" is not supported'
5260
+ );
5261
+ }
5262
+ if (!first && !last) {
5263
+ inputArgs.first = paginationLimit;
5264
+ }
5265
+ return inputArgs;
5266
+ }
5171
5267
  /**
5172
5268
  * @hidden
5173
5269
  */
@@ -5568,52 +5664,16 @@ var Account = class extends import_interfaces.AbstractAccount {
5568
5664
  * @param assetId - The asset ID of the coins to retrieve (optional).
5569
5665
  * @returns A promise that resolves to an array of Coins.
5570
5666
  */
5571
- async getCoins(assetId) {
5572
- const coins = [];
5573
- const pageSize = 9999;
5574
- let cursor;
5575
- for (; ; ) {
5576
- const pageCoins = await this.provider.getCoins(this.address, assetId, {
5577
- first: pageSize,
5578
- after: cursor
5579
- });
5580
- coins.push(...pageCoins);
5581
- const hasNextPage = pageCoins.length >= pageSize;
5582
- if (!hasNextPage) {
5583
- break;
5584
- }
5585
- throw new import_errors16.FuelError(
5586
- import_errors16.ErrorCode.NOT_SUPPORTED,
5587
- `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
5588
- );
5589
- }
5590
- return coins;
5667
+ async getCoins(assetId, paginationArgs) {
5668
+ return this.provider.getCoins(this.address, assetId, paginationArgs);
5591
5669
  }
5592
5670
  /**
5593
5671
  * Retrieves messages owned by the account.
5594
5672
  *
5595
5673
  * @returns A promise that resolves to an array of Messages.
5596
5674
  */
5597
- async getMessages() {
5598
- const messages = [];
5599
- const pageSize = 9999;
5600
- let cursor;
5601
- for (; ; ) {
5602
- const pageMessages = await this.provider.getMessages(this.address, {
5603
- first: pageSize,
5604
- after: cursor
5605
- });
5606
- messages.push(...pageMessages);
5607
- const hasNextPage = pageMessages.length >= pageSize;
5608
- if (!hasNextPage) {
5609
- break;
5610
- }
5611
- throw new import_errors16.FuelError(
5612
- import_errors16.ErrorCode.NOT_SUPPORTED,
5613
- `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
5614
- );
5615
- }
5616
- return messages;
5675
+ async getMessages(paginationArgs) {
5676
+ return this.provider.getMessages(this.address, paginationArgs);
5617
5677
  }
5618
5678
  /**
5619
5679
  * Retrieves the balance of the account for the given asset.
@@ -5632,25 +5692,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5632
5692
  * @returns A promise that resolves to an array of Coins and their quantities.
5633
5693
  */
5634
5694
  async getBalances() {
5635
- const balances = [];
5636
- const pageSize = 9999;
5637
- let cursor;
5638
- for (; ; ) {
5639
- const pageBalances = await this.provider.getBalances(this.address, {
5640
- first: pageSize,
5641
- after: cursor
5642
- });
5643
- balances.push(...pageBalances);
5644
- const hasNextPage = pageBalances.length >= pageSize;
5645
- if (!hasNextPage) {
5646
- break;
5647
- }
5648
- throw new import_errors16.FuelError(
5649
- import_errors16.ErrorCode.NOT_SUPPORTED,
5650
- `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
5651
- );
5652
- }
5653
- return balances;
5695
+ return this.provider.getBalances(this.address);
5654
5696
  }
5655
5697
  /**
5656
5698
  * Funds a transaction request by adding the necessary resources.
@@ -9879,7 +9921,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
9879
9921
  throw new Error("Method not implemented.");
9880
9922
  }
9881
9923
  /**
9882
- * Should add the the assets metadata to the connector and return true if the asset
9924
+ * Should add the assets metadata to the connector and return true if the asset
9883
9925
  * was added successfully.
9884
9926
  *
9885
9927
  * If the asset already exists it should throw an error.
@@ -9893,7 +9935,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
9893
9935
  throw new Error("Method not implemented.");
9894
9936
  }
9895
9937
  /**
9896
- * Should add the the asset metadata to the connector and return true if the asset
9938
+ * Should add the asset metadata to the connector and return true if the asset
9897
9939
  * was added successfully.
9898
9940
  *
9899
9941
  * If the asset already exists it should throw an error.
@@ -10375,6 +10417,7 @@ __publicField(Fuel, "defaultConfig", {});
10375
10417
  0 && (module.exports = {
10376
10418
  Account,
10377
10419
  AddressType,
10420
+ BLOCKS_PAGE_SIZE_LIMIT,
10378
10421
  BaseTransactionRequest,
10379
10422
  BaseWalletUnlocked,
10380
10423
  CHAIN_IDS,
@@ -10399,6 +10442,7 @@ __publicField(Fuel, "defaultConfig", {});
10399
10442
  Predicate,
10400
10443
  PrivateKeyVault,
10401
10444
  Provider,
10445
+ RESOURCES_PAGE_SIZE_LIMIT,
10402
10446
  ScriptTransactionRequest,
10403
10447
  Signer,
10404
10448
  StorageAbstract,