@fuel-ts/account 0.0.0-rc-2366-20240620152942 → 0.0.0-rc-2408-20240624133930

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.

@@ -811,6 +811,9 @@ var GetCoinsDocument = import_graphql_tag.default`
811
811
  first: $first
812
812
  last: $last
813
813
  ) {
814
+ pageInfo {
815
+ ...pageInfoFragment
816
+ }
814
817
  edges {
815
818
  node {
816
819
  ...coinFragment
@@ -818,7 +821,8 @@ var GetCoinsDocument = import_graphql_tag.default`
818
821
  }
819
822
  }
820
823
  }
821
- ${CoinFragmentDoc}`;
824
+ ${PageInfoFragmentDoc}
825
+ ${CoinFragmentDoc}`;
822
826
  var GetCoinsToSpendDocument = import_graphql_tag.default`
823
827
  query getCoinsToSpend($owner: Address!, $queryPerAsset: [SpendQueryElementInput!]!, $excludedIds: ExcludeInput) {
824
828
  coinsToSpend(
@@ -877,6 +881,9 @@ var GetBalancesDocument = import_graphql_tag.default`
877
881
  first: $first
878
882
  last: $last
879
883
  ) {
884
+ pageInfo {
885
+ ...pageInfoFragment
886
+ }
880
887
  edges {
881
888
  node {
882
889
  ...balanceFragment
@@ -884,7 +891,8 @@ var GetBalancesDocument = import_graphql_tag.default`
884
891
  }
885
892
  }
886
893
  }
887
- ${BalanceFragmentDoc}`;
894
+ ${PageInfoFragmentDoc}
895
+ ${BalanceFragmentDoc}`;
888
896
  var GetMessagesDocument = import_graphql_tag.default`
889
897
  query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
890
898
  messages(
@@ -894,6 +902,9 @@ var GetMessagesDocument = import_graphql_tag.default`
894
902
  first: $first
895
903
  last: $last
896
904
  ) {
905
+ pageInfo {
906
+ ...pageInfoFragment
907
+ }
897
908
  edges {
898
909
  node {
899
910
  ...messageFragment
@@ -901,7 +912,8 @@ var GetMessagesDocument = import_graphql_tag.default`
901
912
  }
902
913
  }
903
914
  }
904
- ${MessageFragmentDoc}`;
915
+ ${PageInfoFragmentDoc}
916
+ ${MessageFragmentDoc}`;
905
917
  var GetMessageProofDocument = import_graphql_tag.default`
906
918
  query getMessageProof($transactionId: TransactionId!, $nonce: Nonce!, $commitBlockId: BlockId, $commitBlockHeight: U32) {
907
919
  messageProof(
@@ -4439,21 +4451,27 @@ Supported fuel-core version: ${supportedVersion}.`
4439
4451
  * @returns A promise that resolves to the coins.
4440
4452
  */
4441
4453
  async getCoins(owner, assetId, paginationArgs) {
4454
+ this.validatePaginationArgs(paginationArgs);
4442
4455
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4443
- const result = await this.operations.getCoins({
4444
- first: 10,
4456
+ const {
4457
+ coins: { edges, pageInfo }
4458
+ } = await this.operations.getCoins({
4459
+ first: 100,
4445
4460
  ...paginationArgs,
4446
4461
  filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4447
4462
  });
4448
- const coins = result.coins.edges.map((edge) => edge.node);
4449
- return coins.map((coin) => ({
4450
- id: coin.utxoId,
4451
- assetId: coin.assetId,
4452
- amount: (0, import_math17.bn)(coin.amount),
4453
- owner: import_address3.Address.fromAddressOrString(coin.owner),
4454
- blockCreated: (0, import_math17.bn)(coin.blockCreated),
4455
- txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
4463
+ const coins = edges.map(({ node }) => ({
4464
+ id: node.utxoId,
4465
+ assetId: node.assetId,
4466
+ amount: (0, import_math17.bn)(node.amount),
4467
+ owner: import_address3.Address.fromAddressOrString(node.owner),
4468
+ blockCreated: (0, import_math17.bn)(node.blockCreated),
4469
+ txCreatedIdx: (0, import_math17.bn)(node.txCreatedIdx)
4456
4470
  }));
4471
+ return {
4472
+ coins,
4473
+ pageInfo
4474
+ };
4457
4475
  }
4458
4476
  /**
4459
4477
  * Returns resources for the given owner satisfying the spend query.
@@ -4663,17 +4681,22 @@ Supported fuel-core version: ${supportedVersion}.`
4663
4681
  * @param paginationArgs - Pagination arguments (optional).
4664
4682
  * @returns A promise that resolves to the balances.
4665
4683
  */
4666
- async getBalances(owner, paginationArgs) {
4667
- const result = await this.operations.getBalances({
4668
- first: 10,
4669
- ...paginationArgs,
4684
+ async getBalances(owner) {
4685
+ const {
4686
+ balances: { edges }
4687
+ } = await this.operations.getBalances({
4688
+ /**
4689
+ * The query parameters for this method were designed to support pagination,
4690
+ * but the current Fuel-Core implementation does not support pagination yet.
4691
+ */
4692
+ first: 1e4,
4670
4693
  filter: { owner: import_address3.Address.fromAddressOrString(owner).toB256() }
4671
4694
  });
4672
- const balances = result.balances.edges.map((edge) => edge.node);
4673
- return balances.map((balance) => ({
4674
- assetId: balance.assetId,
4675
- amount: (0, import_math17.bn)(balance.amount)
4695
+ const balances = edges.map(({ node }) => ({
4696
+ assetId: node.assetId,
4697
+ amount: (0, import_math17.bn)(node.amount)
4676
4698
  }));
4699
+ return { balances };
4677
4700
  }
4678
4701
  /**
4679
4702
  * Returns message for the given address.
@@ -4683,27 +4706,33 @@ Supported fuel-core version: ${supportedVersion}.`
4683
4706
  * @returns A promise that resolves to the messages.
4684
4707
  */
4685
4708
  async getMessages(address, paginationArgs) {
4686
- const result = await this.operations.getMessages({
4687
- first: 10,
4709
+ this.validatePaginationArgs(paginationArgs);
4710
+ const {
4711
+ messages: { edges, pageInfo }
4712
+ } = await this.operations.getMessages({
4713
+ first: 100,
4688
4714
  ...paginationArgs,
4689
4715
  owner: import_address3.Address.fromAddressOrString(address).toB256()
4690
4716
  });
4691
- const messages = result.messages.edges.map((edge) => edge.node);
4692
- return messages.map((message) => ({
4717
+ const messages = edges.map(({ node }) => ({
4693
4718
  messageId: import_transactions20.InputMessageCoder.getMessageId({
4694
- sender: message.sender,
4695
- recipient: message.recipient,
4696
- nonce: message.nonce,
4697
- amount: (0, import_math17.bn)(message.amount),
4698
- data: message.data
4719
+ sender: node.sender,
4720
+ recipient: node.recipient,
4721
+ nonce: node.nonce,
4722
+ amount: (0, import_math17.bn)(node.amount),
4723
+ data: node.data
4699
4724
  }),
4700
- sender: import_address3.Address.fromAddressOrString(message.sender),
4701
- recipient: import_address3.Address.fromAddressOrString(message.recipient),
4702
- nonce: message.nonce,
4703
- amount: (0, import_math17.bn)(message.amount),
4704
- data: import_transactions20.InputMessageCoder.decodeData(message.data),
4705
- daHeight: (0, import_math17.bn)(message.daHeight)
4725
+ sender: import_address3.Address.fromAddressOrString(node.sender),
4726
+ recipient: import_address3.Address.fromAddressOrString(node.recipient),
4727
+ nonce: node.nonce,
4728
+ amount: (0, import_math17.bn)(node.amount),
4729
+ data: import_transactions20.InputMessageCoder.decodeData(node.data),
4730
+ daHeight: (0, import_math17.bn)(node.daHeight)
4706
4731
  }));
4732
+ return {
4733
+ messages,
4734
+ pageInfo
4735
+ };
4707
4736
  }
4708
4737
  /**
4709
4738
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -4882,6 +4911,18 @@ Supported fuel-core version: ${supportedVersion}.`
4882
4911
  }
4883
4912
  return relayedTransactionStatus;
4884
4913
  }
4914
+ /**
4915
+ * @hidden
4916
+ */
4917
+ validatePaginationArgs({ first, last } = {}) {
4918
+ const MAX_PAGINATION_LIMIT = 1e3;
4919
+ if ((first || 0) > MAX_PAGINATION_LIMIT || (last || 0) > MAX_PAGINATION_LIMIT) {
4920
+ throw new import_errors14.FuelError(
4921
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
4922
+ "Pagination limit cannot exceed 1000 items"
4923
+ );
4924
+ }
4925
+ }
4885
4926
  /**
4886
4927
  * @hidden
4887
4928
  */
@@ -5107,52 +5148,16 @@ var Account = class extends import_interfaces.AbstractAccount {
5107
5148
  * @param assetId - The asset ID of the coins to retrieve (optional).
5108
5149
  * @returns A promise that resolves to an array of Coins.
5109
5150
  */
5110
- async getCoins(assetId) {
5111
- const coins = [];
5112
- const pageSize = 9999;
5113
- let cursor;
5114
- for (; ; ) {
5115
- const pageCoins = await this.provider.getCoins(this.address, assetId, {
5116
- first: pageSize,
5117
- after: cursor
5118
- });
5119
- coins.push(...pageCoins);
5120
- const hasNextPage = pageCoins.length >= pageSize;
5121
- if (!hasNextPage) {
5122
- break;
5123
- }
5124
- throw new import_errors16.FuelError(
5125
- import_errors16.ErrorCode.NOT_SUPPORTED,
5126
- `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
5127
- );
5128
- }
5129
- return coins;
5151
+ async getCoins(assetId, paginationArgs) {
5152
+ return this.provider.getCoins(this.address, assetId, paginationArgs);
5130
5153
  }
5131
5154
  /**
5132
5155
  * Retrieves messages owned by the account.
5133
5156
  *
5134
5157
  * @returns A promise that resolves to an array of Messages.
5135
5158
  */
5136
- async getMessages() {
5137
- const messages = [];
5138
- const pageSize = 9999;
5139
- let cursor;
5140
- for (; ; ) {
5141
- const pageMessages = await this.provider.getMessages(this.address, {
5142
- first: pageSize,
5143
- after: cursor
5144
- });
5145
- messages.push(...pageMessages);
5146
- const hasNextPage = pageMessages.length >= pageSize;
5147
- if (!hasNextPage) {
5148
- break;
5149
- }
5150
- throw new import_errors16.FuelError(
5151
- import_errors16.ErrorCode.NOT_SUPPORTED,
5152
- `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
5153
- );
5154
- }
5155
- return messages;
5159
+ async getMessages(paginationArgs) {
5160
+ return this.provider.getMessages(this.address, paginationArgs);
5156
5161
  }
5157
5162
  /**
5158
5163
  * Retrieves the balance of the account for the given asset.
@@ -5171,25 +5176,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5171
5176
  * @returns A promise that resolves to an array of Coins and their quantities.
5172
5177
  */
5173
5178
  async getBalances() {
5174
- const balances = [];
5175
- const pageSize = 9999;
5176
- let cursor;
5177
- for (; ; ) {
5178
- const pageBalances = await this.provider.getBalances(this.address, {
5179
- first: pageSize,
5180
- after: cursor
5181
- });
5182
- balances.push(...pageBalances);
5183
- const hasNextPage = pageBalances.length >= pageSize;
5184
- if (!hasNextPage) {
5185
- break;
5186
- }
5187
- throw new import_errors16.FuelError(
5188
- import_errors16.ErrorCode.NOT_SUPPORTED,
5189
- `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
5190
- );
5191
- }
5192
- return balances;
5179
+ return this.provider.getBalances(this.address);
5193
5180
  }
5194
5181
  /**
5195
5182
  * Funds a transaction request by adding the necessary resources.