@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.

@@ -52,7 +52,6 @@ __export(test_utils_exports, {
52
52
  TestMessage: () => TestMessage,
53
53
  WalletsConfig: () => WalletsConfig,
54
54
  generateTestWallet: () => generateTestWallet,
55
- killNode: () => killNode,
56
55
  launchNode: () => launchNode,
57
56
  launchNodeAndGetWallets: () => launchNodeAndGetWallets,
58
57
  seedTestWallet: () => seedTestWallet,
@@ -793,6 +792,9 @@ ${TransactionFragmentDoc}`;
793
792
  var GetBlocksDocument = import_graphql_tag.default`
794
793
  query getBlocks($after: String, $before: String, $first: Int, $last: Int) {
795
794
  blocks(after: $after, before: $before, first: $first, last: $last) {
795
+ pageInfo {
796
+ ...pageInfoFragment
797
+ }
796
798
  edges {
797
799
  node {
798
800
  ...blockFragment
@@ -800,7 +802,8 @@ var GetBlocksDocument = import_graphql_tag.default`
800
802
  }
801
803
  }
802
804
  }
803
- ${BlockFragmentDoc}`;
805
+ ${PageInfoFragmentDoc}
806
+ ${BlockFragmentDoc}`;
804
807
  var GetCoinDocument = import_graphql_tag.default`
805
808
  query getCoin($coinId: UtxoId!) {
806
809
  coin(utxoId: $coinId) {
@@ -817,6 +820,9 @@ var GetCoinsDocument = import_graphql_tag.default`
817
820
  first: $first
818
821
  last: $last
819
822
  ) {
823
+ pageInfo {
824
+ ...pageInfoFragment
825
+ }
820
826
  edges {
821
827
  node {
822
828
  ...coinFragment
@@ -824,7 +830,8 @@ var GetCoinsDocument = import_graphql_tag.default`
824
830
  }
825
831
  }
826
832
  }
827
- ${CoinFragmentDoc}`;
833
+ ${PageInfoFragmentDoc}
834
+ ${CoinFragmentDoc}`;
828
835
  var GetCoinsToSpendDocument = import_graphql_tag.default`
829
836
  query getCoinsToSpend($owner: Address!, $queryPerAsset: [SpendQueryElementInput!]!, $excludedIds: ExcludeInput) {
830
837
  coinsToSpend(
@@ -883,6 +890,9 @@ var GetBalancesDocument = import_graphql_tag.default`
883
890
  first: $first
884
891
  last: $last
885
892
  ) {
893
+ pageInfo {
894
+ ...pageInfoFragment
895
+ }
886
896
  edges {
887
897
  node {
888
898
  ...balanceFragment
@@ -890,7 +900,8 @@ var GetBalancesDocument = import_graphql_tag.default`
890
900
  }
891
901
  }
892
902
  }
893
- ${BalanceFragmentDoc}`;
903
+ ${PageInfoFragmentDoc}
904
+ ${BalanceFragmentDoc}`;
894
905
  var GetMessagesDocument = import_graphql_tag.default`
895
906
  query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
896
907
  messages(
@@ -900,6 +911,9 @@ var GetMessagesDocument = import_graphql_tag.default`
900
911
  first: $first
901
912
  last: $last
902
913
  ) {
914
+ pageInfo {
915
+ ...pageInfoFragment
916
+ }
903
917
  edges {
904
918
  node {
905
919
  ...messageFragment
@@ -907,7 +921,8 @@ var GetMessagesDocument = import_graphql_tag.default`
907
921
  }
908
922
  }
909
923
  }
910
- ${MessageFragmentDoc}`;
924
+ ${PageInfoFragmentDoc}
925
+ ${MessageFragmentDoc}`;
911
926
  var GetMessageProofDocument = import_graphql_tag.default`
912
927
  query getMessageProof($transactionId: TransactionId!, $nonce: Nonce!, $commitBlockId: BlockId, $commitBlockHeight: U32) {
913
928
  messageProof(
@@ -3612,12 +3627,18 @@ var TransactionResponse = class {
3612
3627
  await this.fetch();
3613
3628
  }
3614
3629
  /**
3615
- * Waits for transaction to complete and returns the result.
3630
+ * Assembles the result of a transaction by retrieving the transaction summary,
3631
+ * decoding logs (if available), and handling transaction failure.
3616
3632
  *
3617
- * @returns The completed transaction result
3633
+ * This method can be used to obtain the result of a transaction that has just
3634
+ * been submitted or one that has already been processed.
3635
+ *
3636
+ * @template TTransactionType - The type of the transaction.
3637
+ * @param contractsAbiMap - The map of contract ABIs.
3638
+ * @returns - The assembled transaction result.
3639
+ * @throws If the transaction status is a failure.
3618
3640
  */
3619
- async waitForResult(contractsAbiMap) {
3620
- await this.waitForStatusChange();
3641
+ async assembleResult(contractsAbiMap) {
3621
3642
  const transactionSummary = await this.getTransactionSummary(contractsAbiMap);
3622
3643
  const transactionResult = {
3623
3644
  gqlTransaction: this.gqlTransaction,
@@ -3643,6 +3664,15 @@ var TransactionResponse = class {
3643
3664
  }
3644
3665
  return transactionResult;
3645
3666
  }
3667
+ /**
3668
+ * Waits for transaction to complete and returns the result.
3669
+ *
3670
+ * @returns The completed transaction result
3671
+ */
3672
+ async waitForResult(contractsAbiMap) {
3673
+ await this.waitForStatusChange();
3674
+ return this.assembleResult(contractsAbiMap);
3675
+ }
3646
3676
  /**
3647
3677
  * Waits for transaction to complete and returns the result.
3648
3678
  *
@@ -3706,6 +3736,8 @@ var mergeQuantities = (...coinQuantities) => {
3706
3736
 
3707
3737
  // src/providers/provider.ts
3708
3738
  var MAX_RETRIES = 10;
3739
+ var RESOURCES_PAGE_SIZE_LIMIT = 512;
3740
+ var BLOCKS_PAGE_SIZE_LIMIT = 5;
3709
3741
  var processGqlChain = (chain) => {
3710
3742
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3711
3743
  const {
@@ -4349,7 +4381,7 @@ Supported fuel-core version: ${supportedVersion}.`
4349
4381
  /**
4350
4382
  * Returns a transaction cost to enable user
4351
4383
  * to set gasLimit and also reserve balance amounts
4352
- * on the the transaction.
4384
+ * on the transaction.
4353
4385
  *
4354
4386
  * @param transactionRequestLike - The transaction request object.
4355
4387
  * @param transactionCostParams - The transaction cost parameters (optional).
@@ -4460,20 +4492,27 @@ Supported fuel-core version: ${supportedVersion}.`
4460
4492
  */
4461
4493
  async getCoins(owner, assetId, paginationArgs) {
4462
4494
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4463
- const result = await this.operations.getCoins({
4464
- first: 10,
4465
- ...paginationArgs,
4495
+ const {
4496
+ coins: { edges, pageInfo }
4497
+ } = await this.operations.getCoins({
4498
+ ...this.validatePaginationArgs({
4499
+ paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
4500
+ inputArgs: paginationArgs
4501
+ }),
4466
4502
  filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4467
4503
  });
4468
- const coins = result.coins.edges.map((edge) => edge.node);
4469
- return coins.map((coin) => ({
4470
- id: coin.utxoId,
4471
- assetId: coin.assetId,
4472
- amount: (0, import_math17.bn)(coin.amount),
4473
- owner: import_address3.Address.fromAddressOrString(coin.owner),
4474
- blockCreated: (0, import_math17.bn)(coin.blockCreated),
4475
- txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
4504
+ const coins = edges.map(({ node }) => ({
4505
+ id: node.utxoId,
4506
+ assetId: node.assetId,
4507
+ amount: (0, import_math17.bn)(node.amount),
4508
+ owner: import_address3.Address.fromAddressOrString(node.owner),
4509
+ blockCreated: (0, import_math17.bn)(node.blockCreated),
4510
+ txCreatedIdx: (0, import_math17.bn)(node.txCreatedIdx)
4476
4511
  }));
4512
+ return {
4513
+ coins,
4514
+ pageInfo
4515
+ };
4477
4516
  }
4478
4517
  /**
4479
4518
  * Returns resources for the given owner satisfying the spend query.
@@ -4566,14 +4605,21 @@ Supported fuel-core version: ${supportedVersion}.`
4566
4605
  * @returns A promise that resolves to the blocks.
4567
4606
  */
4568
4607
  async getBlocks(params) {
4569
- const { blocks: fetchedData } = await this.operations.getBlocks(params);
4570
- const blocks = fetchedData.edges.map(({ node: block }) => ({
4608
+ const {
4609
+ blocks: { edges, pageInfo }
4610
+ } = await this.operations.getBlocks({
4611
+ ...this.validatePaginationArgs({
4612
+ paginationLimit: BLOCKS_PAGE_SIZE_LIMIT,
4613
+ inputArgs: params
4614
+ })
4615
+ });
4616
+ const blocks = edges.map(({ node: block }) => ({
4571
4617
  id: block.id,
4572
4618
  height: (0, import_math17.bn)(block.height),
4573
4619
  time: block.header.time,
4574
4620
  transactionIds: block.transactions.map((tx) => tx.id)
4575
4621
  }));
4576
- return blocks;
4622
+ return { blocks, pageInfo };
4577
4623
  }
4578
4624
  /**
4579
4625
  * Returns block matching the given ID or type, including transaction data.
@@ -4683,17 +4729,22 @@ Supported fuel-core version: ${supportedVersion}.`
4683
4729
  * @param paginationArgs - Pagination arguments (optional).
4684
4730
  * @returns A promise that resolves to the balances.
4685
4731
  */
4686
- async getBalances(owner, paginationArgs) {
4687
- const result = await this.operations.getBalances({
4688
- first: 10,
4689
- ...paginationArgs,
4732
+ async getBalances(owner) {
4733
+ const {
4734
+ balances: { edges }
4735
+ } = await this.operations.getBalances({
4736
+ /**
4737
+ * The query parameters for this method were designed to support pagination,
4738
+ * but the current Fuel-Core implementation does not support pagination yet.
4739
+ */
4740
+ first: 1e4,
4690
4741
  filter: { owner: import_address3.Address.fromAddressOrString(owner).toB256() }
4691
4742
  });
4692
- const balances = result.balances.edges.map((edge) => edge.node);
4693
- return balances.map((balance) => ({
4694
- assetId: balance.assetId,
4695
- amount: (0, import_math17.bn)(balance.amount)
4743
+ const balances = edges.map(({ node }) => ({
4744
+ assetId: node.assetId,
4745
+ amount: (0, import_math17.bn)(node.amount)
4696
4746
  }));
4747
+ return { balances };
4697
4748
  }
4698
4749
  /**
4699
4750
  * Returns message for the given address.
@@ -4703,27 +4754,34 @@ Supported fuel-core version: ${supportedVersion}.`
4703
4754
  * @returns A promise that resolves to the messages.
4704
4755
  */
4705
4756
  async getMessages(address, paginationArgs) {
4706
- const result = await this.operations.getMessages({
4707
- first: 10,
4708
- ...paginationArgs,
4757
+ const {
4758
+ messages: { edges, pageInfo }
4759
+ } = await this.operations.getMessages({
4760
+ ...this.validatePaginationArgs({
4761
+ inputArgs: paginationArgs,
4762
+ paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
4763
+ }),
4709
4764
  owner: import_address3.Address.fromAddressOrString(address).toB256()
4710
4765
  });
4711
- const messages = result.messages.edges.map((edge) => edge.node);
4712
- return messages.map((message) => ({
4766
+ const messages = edges.map(({ node }) => ({
4713
4767
  messageId: import_transactions20.InputMessageCoder.getMessageId({
4714
- sender: message.sender,
4715
- recipient: message.recipient,
4716
- nonce: message.nonce,
4717
- amount: (0, import_math17.bn)(message.amount),
4718
- data: message.data
4768
+ sender: node.sender,
4769
+ recipient: node.recipient,
4770
+ nonce: node.nonce,
4771
+ amount: (0, import_math17.bn)(node.amount),
4772
+ data: node.data
4719
4773
  }),
4720
- sender: import_address3.Address.fromAddressOrString(message.sender),
4721
- recipient: import_address3.Address.fromAddressOrString(message.recipient),
4722
- nonce: message.nonce,
4723
- amount: (0, import_math17.bn)(message.amount),
4724
- data: import_transactions20.InputMessageCoder.decodeData(message.data),
4725
- daHeight: (0, import_math17.bn)(message.daHeight)
4774
+ sender: import_address3.Address.fromAddressOrString(node.sender),
4775
+ recipient: import_address3.Address.fromAddressOrString(node.recipient),
4776
+ nonce: node.nonce,
4777
+ amount: (0, import_math17.bn)(node.amount),
4778
+ data: import_transactions20.InputMessageCoder.decodeData(node.data),
4779
+ daHeight: (0, import_math17.bn)(node.daHeight)
4726
4780
  }));
4781
+ return {
4782
+ messages,
4783
+ pageInfo
4784
+ };
4727
4785
  }
4728
4786
  /**
4729
4787
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -4902,6 +4960,41 @@ Supported fuel-core version: ${supportedVersion}.`
4902
4960
  }
4903
4961
  return relayedTransactionStatus;
4904
4962
  }
4963
+ /**
4964
+ * @hidden
4965
+ */
4966
+ validatePaginationArgs(params) {
4967
+ const { paginationLimit, inputArgs = {} } = params;
4968
+ const { first, last, after, before } = inputArgs;
4969
+ if (after && before) {
4970
+ throw new import_errors14.FuelError(
4971
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
4972
+ 'Pagination arguments "after" and "before" cannot be used together'
4973
+ );
4974
+ }
4975
+ if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
4976
+ throw new import_errors14.FuelError(
4977
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
4978
+ `Pagination limit for this query cannot exceed ${paginationLimit} items`
4979
+ );
4980
+ }
4981
+ if (first && before) {
4982
+ throw new import_errors14.FuelError(
4983
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
4984
+ 'The use of pagination argument "first" with "before" is not supported'
4985
+ );
4986
+ }
4987
+ if (last && after) {
4988
+ throw new import_errors14.FuelError(
4989
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
4990
+ 'The use of pagination argument "last" with "after" is not supported'
4991
+ );
4992
+ }
4993
+ if (!first && !last) {
4994
+ inputArgs.first = paginationLimit;
4995
+ }
4996
+ return inputArgs;
4997
+ }
4905
4998
  /**
4906
4999
  * @hidden
4907
5000
  */
@@ -5127,52 +5220,16 @@ var Account = class extends import_interfaces.AbstractAccount {
5127
5220
  * @param assetId - The asset ID of the coins to retrieve (optional).
5128
5221
  * @returns A promise that resolves to an array of Coins.
5129
5222
  */
5130
- async getCoins(assetId) {
5131
- const coins = [];
5132
- const pageSize = 9999;
5133
- let cursor;
5134
- for (; ; ) {
5135
- const pageCoins = await this.provider.getCoins(this.address, assetId, {
5136
- first: pageSize,
5137
- after: cursor
5138
- });
5139
- coins.push(...pageCoins);
5140
- const hasNextPage = pageCoins.length >= pageSize;
5141
- if (!hasNextPage) {
5142
- break;
5143
- }
5144
- throw new import_errors16.FuelError(
5145
- import_errors16.ErrorCode.NOT_SUPPORTED,
5146
- `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
5147
- );
5148
- }
5149
- return coins;
5223
+ async getCoins(assetId, paginationArgs) {
5224
+ return this.provider.getCoins(this.address, assetId, paginationArgs);
5150
5225
  }
5151
5226
  /**
5152
5227
  * Retrieves messages owned by the account.
5153
5228
  *
5154
5229
  * @returns A promise that resolves to an array of Messages.
5155
5230
  */
5156
- async getMessages() {
5157
- const messages = [];
5158
- const pageSize = 9999;
5159
- let cursor;
5160
- for (; ; ) {
5161
- const pageMessages = await this.provider.getMessages(this.address, {
5162
- first: pageSize,
5163
- after: cursor
5164
- });
5165
- messages.push(...pageMessages);
5166
- const hasNextPage = pageMessages.length >= pageSize;
5167
- if (!hasNextPage) {
5168
- break;
5169
- }
5170
- throw new import_errors16.FuelError(
5171
- import_errors16.ErrorCode.NOT_SUPPORTED,
5172
- `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
5173
- );
5174
- }
5175
- return messages;
5231
+ async getMessages(paginationArgs) {
5232
+ return this.provider.getMessages(this.address, paginationArgs);
5176
5233
  }
5177
5234
  /**
5178
5235
  * Retrieves the balance of the account for the given asset.
@@ -5191,25 +5248,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5191
5248
  * @returns A promise that resolves to an array of Coins and their quantities.
5192
5249
  */
5193
5250
  async getBalances() {
5194
- const balances = [];
5195
- const pageSize = 9999;
5196
- let cursor;
5197
- for (; ; ) {
5198
- const pageBalances = await this.provider.getBalances(this.address, {
5199
- first: pageSize,
5200
- after: cursor
5201
- });
5202
- balances.push(...pageBalances);
5203
- const hasNextPage = pageBalances.length >= pageSize;
5204
- if (!hasNextPage) {
5205
- break;
5206
- }
5207
- throw new import_errors16.FuelError(
5208
- import_errors16.ErrorCode.NOT_SUPPORTED,
5209
- `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
5210
- );
5211
- }
5212
- return balances;
5251
+ return this.provider.getBalances(this.address);
5213
5252
  }
5214
5253
  /**
5215
5254
  * Funds a transaction request by adding the necessary resources.
@@ -8650,7 +8689,6 @@ var import_fs = require("fs");
8650
8689
  var import_os = __toESM(require("os"));
8651
8690
  var import_path = __toESM(require("path"));
8652
8691
  var import_portfinder = require("portfinder");
8653
- var import_tree_kill = __toESM(require("tree-kill"));
8654
8692
  var getFlagValueFromArgs = (args, flag) => {
8655
8693
  const flagIndex = args.indexOf(flag);
8656
8694
  if (flagIndex === -1) {
@@ -8668,19 +8706,6 @@ var extractRemainingArgs = (args, flagsToRemove) => {
8668
8706
  });
8669
8707
  return newArgs;
8670
8708
  };
8671
- var killNode = (params) => {
8672
- const { child, configPath, state, killFn } = params;
8673
- if (!state.isDead) {
8674
- if (child.pid) {
8675
- state.isDead = true;
8676
- killFn(Number(child.pid));
8677
- }
8678
- child.stderr.removeAllListeners();
8679
- if ((0, import_fs.existsSync)(configPath)) {
8680
- (0, import_fs.rmSync)(configPath, { recursive: true });
8681
- }
8682
- }
8683
- };
8684
8709
  function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8685
8710
  const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8686
8711
  ...coin,
@@ -8787,19 +8812,45 @@ var launchNode = async ({
8787
8812
  "--debug",
8788
8813
  ...remainingArgs
8789
8814
  ].flat(),
8790
- { stdio: "pipe" }
8815
+ { stdio: "pipe", detached: true }
8791
8816
  );
8792
8817
  if (loggingEnabled) {
8793
8818
  child.stderr.on("data", (chunk) => {
8794
8819
  console.log(chunk.toString());
8795
8820
  });
8796
8821
  }
8797
- const cleanupConfig = {
8798
- child,
8799
- configPath: tempDir,
8800
- killFn: import_tree_kill.default,
8801
- state: {
8802
- isDead: false
8822
+ const removeSideffects = () => {
8823
+ child.stderr.removeAllListeners();
8824
+ if ((0, import_fs.existsSync)(tempDir)) {
8825
+ (0, import_fs.rmSync)(tempDir, { recursive: true });
8826
+ }
8827
+ };
8828
+ child.on("error", removeSideffects);
8829
+ child.on("exit", removeSideffects);
8830
+ const childState = {
8831
+ isDead: false
8832
+ };
8833
+ const cleanup = () => {
8834
+ if (childState.isDead) {
8835
+ return;
8836
+ }
8837
+ childState.isDead = true;
8838
+ removeSideffects();
8839
+ if (child.pid !== void 0) {
8840
+ try {
8841
+ process.kill(-child.pid);
8842
+ } catch (e) {
8843
+ const error = e;
8844
+ if (error.code === "ESRCH") {
8845
+ console.log(
8846
+ `fuel-core node under pid ${child.pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
8847
+ );
8848
+ } else {
8849
+ throw e;
8850
+ }
8851
+ }
8852
+ } else {
8853
+ console.error("No PID available for the child process, unable to kill launched node");
8803
8854
  }
8804
8855
  };
8805
8856
  child.stderr.on("data", (chunk) => {
@@ -8809,11 +8860,12 @@ var launchNode = async ({
8809
8860
  const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8810
8861
  const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8811
8862
  resolve({
8812
- cleanup: () => killNode(cleanupConfig),
8863
+ cleanup,
8813
8864
  ip: realIp,
8814
8865
  port: realPort,
8815
8866
  url: `http://${realIp}:${realPort}/v1/graphql`,
8816
- snapshotDir: snapshotDirToUse
8867
+ snapshotDir: snapshotDirToUse,
8868
+ pid: child.pid
8817
8869
  });
8818
8870
  }
8819
8871
  if (/error/i.test(text)) {
@@ -8821,12 +8873,12 @@ var launchNode = async ({
8821
8873
  reject(new import_errors21.FuelError(import_errors21.FuelError.CODES.NODE_LAUNCH_FAILED, text));
8822
8874
  }
8823
8875
  });
8824
- process.on("exit", () => killNode(cleanupConfig));
8825
- process.on("SIGINT", () => killNode(cleanupConfig));
8826
- process.on("SIGUSR1", () => killNode(cleanupConfig));
8827
- process.on("SIGUSR2", () => killNode(cleanupConfig));
8828
- process.on("beforeExit", () => killNode(cleanupConfig));
8829
- process.on("uncaughtException", () => killNode(cleanupConfig));
8876
+ process.on("exit", cleanup);
8877
+ process.on("SIGINT", cleanup);
8878
+ process.on("SIGUSR1", cleanup);
8879
+ process.on("SIGUSR2", cleanup);
8880
+ process.on("beforeExit", cleanup);
8881
+ process.on("uncaughtException", cleanup);
8830
8882
  child.on("error", reject);
8831
8883
  })
8832
8884
  );
@@ -9100,7 +9152,6 @@ var TestMessage = class {
9100
9152
  TestMessage,
9101
9153
  WalletsConfig,
9102
9154
  generateTestWallet,
9103
- killNode,
9104
9155
  launchNode,
9105
9156
  launchNodeAndGetWallets,
9106
9157
  seedTestWallet,