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

Potentially problematic release.


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

package/dist/index.mjs CHANGED
@@ -761,6 +761,9 @@ ${TransactionFragmentDoc}`;
761
761
  var GetBlocksDocument = gql`
762
762
  query getBlocks($after: String, $before: String, $first: Int, $last: Int) {
763
763
  blocks(after: $after, before: $before, first: $first, last: $last) {
764
+ pageInfo {
765
+ ...pageInfoFragment
766
+ }
764
767
  edges {
765
768
  node {
766
769
  ...blockFragment
@@ -768,7 +771,8 @@ var GetBlocksDocument = gql`
768
771
  }
769
772
  }
770
773
  }
771
- ${BlockFragmentDoc}`;
774
+ ${PageInfoFragmentDoc}
775
+ ${BlockFragmentDoc}`;
772
776
  var GetCoinDocument = gql`
773
777
  query getCoin($coinId: UtxoId!) {
774
778
  coin(utxoId: $coinId) {
@@ -785,6 +789,9 @@ var GetCoinsDocument = gql`
785
789
  first: $first
786
790
  last: $last
787
791
  ) {
792
+ pageInfo {
793
+ ...pageInfoFragment
794
+ }
788
795
  edges {
789
796
  node {
790
797
  ...coinFragment
@@ -792,7 +799,8 @@ var GetCoinsDocument = gql`
792
799
  }
793
800
  }
794
801
  }
795
- ${CoinFragmentDoc}`;
802
+ ${PageInfoFragmentDoc}
803
+ ${CoinFragmentDoc}`;
796
804
  var GetCoinsToSpendDocument = gql`
797
805
  query getCoinsToSpend($owner: Address!, $queryPerAsset: [SpendQueryElementInput!]!, $excludedIds: ExcludeInput) {
798
806
  coinsToSpend(
@@ -851,6 +859,9 @@ var GetBalancesDocument = gql`
851
859
  first: $first
852
860
  last: $last
853
861
  ) {
862
+ pageInfo {
863
+ ...pageInfoFragment
864
+ }
854
865
  edges {
855
866
  node {
856
867
  ...balanceFragment
@@ -858,7 +869,8 @@ var GetBalancesDocument = gql`
858
869
  }
859
870
  }
860
871
  }
861
- ${BalanceFragmentDoc}`;
872
+ ${PageInfoFragmentDoc}
873
+ ${BalanceFragmentDoc}`;
862
874
  var GetMessagesDocument = gql`
863
875
  query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
864
876
  messages(
@@ -868,6 +880,9 @@ var GetMessagesDocument = gql`
868
880
  first: $first
869
881
  last: $last
870
882
  ) {
883
+ pageInfo {
884
+ ...pageInfoFragment
885
+ }
871
886
  edges {
872
887
  node {
873
888
  ...messageFragment
@@ -875,7 +890,8 @@ var GetMessagesDocument = gql`
875
890
  }
876
891
  }
877
892
  }
878
- ${MessageFragmentDoc}`;
893
+ ${PageInfoFragmentDoc}
894
+ ${MessageFragmentDoc}`;
879
895
  var GetMessageProofDocument = gql`
880
896
  query getMessageProof($transactionId: TransactionId!, $nonce: Nonce!, $commitBlockId: BlockId, $commitBlockHeight: U32) {
881
897
  messageProof(
@@ -3736,12 +3752,18 @@ var TransactionResponse = class {
3736
3752
  await this.fetch();
3737
3753
  }
3738
3754
  /**
3739
- * Waits for transaction to complete and returns the result.
3755
+ * Assembles the result of a transaction by retrieving the transaction summary,
3756
+ * decoding logs (if available), and handling transaction failure.
3740
3757
  *
3741
- * @returns The completed transaction result
3758
+ * This method can be used to obtain the result of a transaction that has just
3759
+ * been submitted or one that has already been processed.
3760
+ *
3761
+ * @template TTransactionType - The type of the transaction.
3762
+ * @param contractsAbiMap - The map of contract ABIs.
3763
+ * @returns - The assembled transaction result.
3764
+ * @throws If the transaction status is a failure.
3742
3765
  */
3743
- async waitForResult(contractsAbiMap) {
3744
- await this.waitForStatusChange();
3766
+ async assembleResult(contractsAbiMap) {
3745
3767
  const transactionSummary = await this.getTransactionSummary(contractsAbiMap);
3746
3768
  const transactionResult = {
3747
3769
  gqlTransaction: this.gqlTransaction,
@@ -3767,6 +3789,15 @@ var TransactionResponse = class {
3767
3789
  }
3768
3790
  return transactionResult;
3769
3791
  }
3792
+ /**
3793
+ * Waits for transaction to complete and returns the result.
3794
+ *
3795
+ * @returns The completed transaction result
3796
+ */
3797
+ async waitForResult(contractsAbiMap) {
3798
+ await this.waitForStatusChange();
3799
+ return this.assembleResult(contractsAbiMap);
3800
+ }
3770
3801
  /**
3771
3802
  * Waits for transaction to complete and returns the result.
3772
3803
  *
@@ -3830,6 +3861,8 @@ var mergeQuantities = (...coinQuantities) => {
3830
3861
 
3831
3862
  // src/providers/provider.ts
3832
3863
  var MAX_RETRIES = 10;
3864
+ var RESOURCES_PAGE_SIZE_LIMIT = 512;
3865
+ var BLOCKS_PAGE_SIZE_LIMIT = 5;
3833
3866
  var processGqlChain = (chain) => {
3834
3867
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3835
3868
  const {
@@ -4473,7 +4506,7 @@ Supported fuel-core version: ${supportedVersion}.`
4473
4506
  /**
4474
4507
  * Returns a transaction cost to enable user
4475
4508
  * to set gasLimit and also reserve balance amounts
4476
- * on the the transaction.
4509
+ * on the transaction.
4477
4510
  *
4478
4511
  * @param transactionRequestLike - The transaction request object.
4479
4512
  * @param transactionCostParams - The transaction cost parameters (optional).
@@ -4584,20 +4617,27 @@ Supported fuel-core version: ${supportedVersion}.`
4584
4617
  */
4585
4618
  async getCoins(owner, assetId, paginationArgs) {
4586
4619
  const ownerAddress = Address2.fromAddressOrString(owner);
4587
- const result = await this.operations.getCoins({
4588
- first: 10,
4589
- ...paginationArgs,
4620
+ const {
4621
+ coins: { edges, pageInfo }
4622
+ } = await this.operations.getCoins({
4623
+ ...this.validatePaginationArgs({
4624
+ paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
4625
+ inputArgs: paginationArgs
4626
+ }),
4590
4627
  filter: { owner: ownerAddress.toB256(), assetId: assetId && hexlify12(assetId) }
4591
4628
  });
4592
- const coins = result.coins.edges.map((edge) => edge.node);
4593
- return coins.map((coin) => ({
4594
- id: coin.utxoId,
4595
- assetId: coin.assetId,
4596
- amount: bn17(coin.amount),
4597
- owner: Address2.fromAddressOrString(coin.owner),
4598
- blockCreated: bn17(coin.blockCreated),
4599
- txCreatedIdx: bn17(coin.txCreatedIdx)
4629
+ const coins = edges.map(({ node }) => ({
4630
+ id: node.utxoId,
4631
+ assetId: node.assetId,
4632
+ amount: bn17(node.amount),
4633
+ owner: Address2.fromAddressOrString(node.owner),
4634
+ blockCreated: bn17(node.blockCreated),
4635
+ txCreatedIdx: bn17(node.txCreatedIdx)
4600
4636
  }));
4637
+ return {
4638
+ coins,
4639
+ pageInfo
4640
+ };
4601
4641
  }
4602
4642
  /**
4603
4643
  * Returns resources for the given owner satisfying the spend query.
@@ -4690,14 +4730,21 @@ Supported fuel-core version: ${supportedVersion}.`
4690
4730
  * @returns A promise that resolves to the blocks.
4691
4731
  */
4692
4732
  async getBlocks(params) {
4693
- const { blocks: fetchedData } = await this.operations.getBlocks(params);
4694
- const blocks = fetchedData.edges.map(({ node: block }) => ({
4733
+ const {
4734
+ blocks: { edges, pageInfo }
4735
+ } = await this.operations.getBlocks({
4736
+ ...this.validatePaginationArgs({
4737
+ paginationLimit: BLOCKS_PAGE_SIZE_LIMIT,
4738
+ inputArgs: params
4739
+ })
4740
+ });
4741
+ const blocks = edges.map(({ node: block }) => ({
4695
4742
  id: block.id,
4696
4743
  height: bn17(block.height),
4697
4744
  time: block.header.time,
4698
4745
  transactionIds: block.transactions.map((tx) => tx.id)
4699
4746
  }));
4700
- return blocks;
4747
+ return { blocks, pageInfo };
4701
4748
  }
4702
4749
  /**
4703
4750
  * Returns block matching the given ID or type, including transaction data.
@@ -4807,17 +4854,22 @@ Supported fuel-core version: ${supportedVersion}.`
4807
4854
  * @param paginationArgs - Pagination arguments (optional).
4808
4855
  * @returns A promise that resolves to the balances.
4809
4856
  */
4810
- async getBalances(owner, paginationArgs) {
4811
- const result = await this.operations.getBalances({
4812
- first: 10,
4813
- ...paginationArgs,
4857
+ async getBalances(owner) {
4858
+ const {
4859
+ balances: { edges }
4860
+ } = await this.operations.getBalances({
4861
+ /**
4862
+ * The query parameters for this method were designed to support pagination,
4863
+ * but the current Fuel-Core implementation does not support pagination yet.
4864
+ */
4865
+ first: 1e4,
4814
4866
  filter: { owner: Address2.fromAddressOrString(owner).toB256() }
4815
4867
  });
4816
- const balances = result.balances.edges.map((edge) => edge.node);
4817
- return balances.map((balance) => ({
4818
- assetId: balance.assetId,
4819
- amount: bn17(balance.amount)
4868
+ const balances = edges.map(({ node }) => ({
4869
+ assetId: node.assetId,
4870
+ amount: bn17(node.amount)
4820
4871
  }));
4872
+ return { balances };
4821
4873
  }
4822
4874
  /**
4823
4875
  * Returns message for the given address.
@@ -4827,27 +4879,34 @@ Supported fuel-core version: ${supportedVersion}.`
4827
4879
  * @returns A promise that resolves to the messages.
4828
4880
  */
4829
4881
  async getMessages(address, paginationArgs) {
4830
- const result = await this.operations.getMessages({
4831
- first: 10,
4832
- ...paginationArgs,
4882
+ const {
4883
+ messages: { edges, pageInfo }
4884
+ } = await this.operations.getMessages({
4885
+ ...this.validatePaginationArgs({
4886
+ inputArgs: paginationArgs,
4887
+ paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
4888
+ }),
4833
4889
  owner: Address2.fromAddressOrString(address).toB256()
4834
4890
  });
4835
- const messages = result.messages.edges.map((edge) => edge.node);
4836
- return messages.map((message) => ({
4891
+ const messages = edges.map(({ node }) => ({
4837
4892
  messageId: InputMessageCoder.getMessageId({
4838
- sender: message.sender,
4839
- recipient: message.recipient,
4840
- nonce: message.nonce,
4841
- amount: bn17(message.amount),
4842
- data: message.data
4893
+ sender: node.sender,
4894
+ recipient: node.recipient,
4895
+ nonce: node.nonce,
4896
+ amount: bn17(node.amount),
4897
+ data: node.data
4843
4898
  }),
4844
- sender: Address2.fromAddressOrString(message.sender),
4845
- recipient: Address2.fromAddressOrString(message.recipient),
4846
- nonce: message.nonce,
4847
- amount: bn17(message.amount),
4848
- data: InputMessageCoder.decodeData(message.data),
4849
- daHeight: bn17(message.daHeight)
4899
+ sender: Address2.fromAddressOrString(node.sender),
4900
+ recipient: Address2.fromAddressOrString(node.recipient),
4901
+ nonce: node.nonce,
4902
+ amount: bn17(node.amount),
4903
+ data: InputMessageCoder.decodeData(node.data),
4904
+ daHeight: bn17(node.daHeight)
4850
4905
  }));
4906
+ return {
4907
+ messages,
4908
+ pageInfo
4909
+ };
4851
4910
  }
4852
4911
  /**
4853
4912
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -5026,6 +5085,41 @@ Supported fuel-core version: ${supportedVersion}.`
5026
5085
  }
5027
5086
  return relayedTransactionStatus;
5028
5087
  }
5088
+ /**
5089
+ * @hidden
5090
+ */
5091
+ validatePaginationArgs(params) {
5092
+ const { paginationLimit, inputArgs = {} } = params;
5093
+ const { first, last, after, before } = inputArgs;
5094
+ if (after && before) {
5095
+ throw new FuelError13(
5096
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
5097
+ 'Pagination arguments "after" and "before" cannot be used together'
5098
+ );
5099
+ }
5100
+ if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
5101
+ throw new FuelError13(
5102
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
5103
+ `Pagination limit for this query cannot exceed ${paginationLimit} items`
5104
+ );
5105
+ }
5106
+ if (first && before) {
5107
+ throw new FuelError13(
5108
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
5109
+ 'The use of pagination argument "first" with "before" is not supported'
5110
+ );
5111
+ }
5112
+ if (last && after) {
5113
+ throw new FuelError13(
5114
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
5115
+ 'The use of pagination argument "last" with "after" is not supported'
5116
+ );
5117
+ }
5118
+ if (!first && !last) {
5119
+ inputArgs.first = paginationLimit;
5120
+ }
5121
+ return inputArgs;
5122
+ }
5029
5123
  /**
5030
5124
  * @hidden
5031
5125
  */
@@ -5426,52 +5520,16 @@ var Account = class extends AbstractAccount {
5426
5520
  * @param assetId - The asset ID of the coins to retrieve (optional).
5427
5521
  * @returns A promise that resolves to an array of Coins.
5428
5522
  */
5429
- async getCoins(assetId) {
5430
- const coins = [];
5431
- const pageSize = 9999;
5432
- let cursor;
5433
- for (; ; ) {
5434
- const pageCoins = await this.provider.getCoins(this.address, assetId, {
5435
- first: pageSize,
5436
- after: cursor
5437
- });
5438
- coins.push(...pageCoins);
5439
- const hasNextPage = pageCoins.length >= pageSize;
5440
- if (!hasNextPage) {
5441
- break;
5442
- }
5443
- throw new FuelError15(
5444
- ErrorCode15.NOT_SUPPORTED,
5445
- `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
5446
- );
5447
- }
5448
- return coins;
5523
+ async getCoins(assetId, paginationArgs) {
5524
+ return this.provider.getCoins(this.address, assetId, paginationArgs);
5449
5525
  }
5450
5526
  /**
5451
5527
  * Retrieves messages owned by the account.
5452
5528
  *
5453
5529
  * @returns A promise that resolves to an array of Messages.
5454
5530
  */
5455
- async getMessages() {
5456
- const messages = [];
5457
- const pageSize = 9999;
5458
- let cursor;
5459
- for (; ; ) {
5460
- const pageMessages = await this.provider.getMessages(this.address, {
5461
- first: pageSize,
5462
- after: cursor
5463
- });
5464
- messages.push(...pageMessages);
5465
- const hasNextPage = pageMessages.length >= pageSize;
5466
- if (!hasNextPage) {
5467
- break;
5468
- }
5469
- throw new FuelError15(
5470
- ErrorCode15.NOT_SUPPORTED,
5471
- `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
5472
- );
5473
- }
5474
- return messages;
5531
+ async getMessages(paginationArgs) {
5532
+ return this.provider.getMessages(this.address, paginationArgs);
5475
5533
  }
5476
5534
  /**
5477
5535
  * Retrieves the balance of the account for the given asset.
@@ -5490,25 +5548,7 @@ var Account = class extends AbstractAccount {
5490
5548
  * @returns A promise that resolves to an array of Coins and their quantities.
5491
5549
  */
5492
5550
  async getBalances() {
5493
- const balances = [];
5494
- const pageSize = 9999;
5495
- let cursor;
5496
- for (; ; ) {
5497
- const pageBalances = await this.provider.getBalances(this.address, {
5498
- first: pageSize,
5499
- after: cursor
5500
- });
5501
- balances.push(...pageBalances);
5502
- const hasNextPage = pageBalances.length >= pageSize;
5503
- if (!hasNextPage) {
5504
- break;
5505
- }
5506
- throw new FuelError15(
5507
- ErrorCode15.NOT_SUPPORTED,
5508
- `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
5509
- );
5510
- }
5511
- return balances;
5551
+ return this.provider.getBalances(this.address);
5512
5552
  }
5513
5553
  /**
5514
5554
  * Funds a transaction request by adding the necessary resources.
@@ -9745,7 +9785,7 @@ var FuelConnector = class extends EventEmitter2 {
9745
9785
  throw new Error("Method not implemented.");
9746
9786
  }
9747
9787
  /**
9748
- * Should add the the assets metadata to the connector and return true if the asset
9788
+ * Should add the assets metadata to the connector and return true if the asset
9749
9789
  * was added successfully.
9750
9790
  *
9751
9791
  * If the asset already exists it should throw an error.
@@ -9759,7 +9799,7 @@ var FuelConnector = class extends EventEmitter2 {
9759
9799
  throw new Error("Method not implemented.");
9760
9800
  }
9761
9801
  /**
9762
- * Should add the the asset metadata to the connector and return true if the asset
9802
+ * Should add the asset metadata to the connector and return true if the asset
9763
9803
  * was added successfully.
9764
9804
  *
9765
9805
  * If the asset already exists it should throw an error.
@@ -10240,6 +10280,7 @@ __publicField(Fuel, "defaultConfig", {});
10240
10280
  export {
10241
10281
  Account,
10242
10282
  AddressType,
10283
+ BLOCKS_PAGE_SIZE_LIMIT,
10243
10284
  BaseTransactionRequest,
10244
10285
  BaseWalletUnlocked,
10245
10286
  CHAIN_IDS,
@@ -10264,6 +10305,7 @@ export {
10264
10305
  Predicate,
10265
10306
  PrivateKeyVault,
10266
10307
  Provider,
10308
+ RESOURCES_PAGE_SIZE_LIMIT,
10267
10309
  ScriptTransactionRequest,
10268
10310
  Signer,
10269
10311
  StorageAbstract,