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

@@ -756,6 +756,9 @@ ${TransactionFragmentDoc}`;
756
756
  var GetBlocksDocument = gql`
757
757
  query getBlocks($after: String, $before: String, $first: Int, $last: Int) {
758
758
  blocks(after: $after, before: $before, first: $first, last: $last) {
759
+ pageInfo {
760
+ ...pageInfoFragment
761
+ }
759
762
  edges {
760
763
  node {
761
764
  ...blockFragment
@@ -763,7 +766,8 @@ var GetBlocksDocument = gql`
763
766
  }
764
767
  }
765
768
  }
766
- ${BlockFragmentDoc}`;
769
+ ${PageInfoFragmentDoc}
770
+ ${BlockFragmentDoc}`;
767
771
  var GetCoinDocument = gql`
768
772
  query getCoin($coinId: UtxoId!) {
769
773
  coin(utxoId: $coinId) {
@@ -780,6 +784,9 @@ var GetCoinsDocument = gql`
780
784
  first: $first
781
785
  last: $last
782
786
  ) {
787
+ pageInfo {
788
+ ...pageInfoFragment
789
+ }
783
790
  edges {
784
791
  node {
785
792
  ...coinFragment
@@ -787,7 +794,8 @@ var GetCoinsDocument = gql`
787
794
  }
788
795
  }
789
796
  }
790
- ${CoinFragmentDoc}`;
797
+ ${PageInfoFragmentDoc}
798
+ ${CoinFragmentDoc}`;
791
799
  var GetCoinsToSpendDocument = gql`
792
800
  query getCoinsToSpend($owner: Address!, $queryPerAsset: [SpendQueryElementInput!]!, $excludedIds: ExcludeInput) {
793
801
  coinsToSpend(
@@ -846,6 +854,9 @@ var GetBalancesDocument = gql`
846
854
  first: $first
847
855
  last: $last
848
856
  ) {
857
+ pageInfo {
858
+ ...pageInfoFragment
859
+ }
849
860
  edges {
850
861
  node {
851
862
  ...balanceFragment
@@ -853,7 +864,8 @@ var GetBalancesDocument = gql`
853
864
  }
854
865
  }
855
866
  }
856
- ${BalanceFragmentDoc}`;
867
+ ${PageInfoFragmentDoc}
868
+ ${BalanceFragmentDoc}`;
857
869
  var GetMessagesDocument = gql`
858
870
  query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
859
871
  messages(
@@ -863,6 +875,9 @@ var GetMessagesDocument = gql`
863
875
  first: $first
864
876
  last: $last
865
877
  ) {
878
+ pageInfo {
879
+ ...pageInfoFragment
880
+ }
866
881
  edges {
867
882
  node {
868
883
  ...messageFragment
@@ -870,7 +885,8 @@ var GetMessagesDocument = gql`
870
885
  }
871
886
  }
872
887
  }
873
- ${MessageFragmentDoc}`;
888
+ ${PageInfoFragmentDoc}
889
+ ${MessageFragmentDoc}`;
874
890
  var GetMessageProofDocument = gql`
875
891
  query getMessageProof($transactionId: TransactionId!, $nonce: Nonce!, $commitBlockId: BlockId, $commitBlockHeight: U32) {
876
892
  messageProof(
@@ -3594,12 +3610,18 @@ var TransactionResponse = class {
3594
3610
  await this.fetch();
3595
3611
  }
3596
3612
  /**
3597
- * Waits for transaction to complete and returns the result.
3613
+ * Assembles the result of a transaction by retrieving the transaction summary,
3614
+ * decoding logs (if available), and handling transaction failure.
3598
3615
  *
3599
- * @returns The completed transaction result
3616
+ * This method can be used to obtain the result of a transaction that has just
3617
+ * been submitted or one that has already been processed.
3618
+ *
3619
+ * @template TTransactionType - The type of the transaction.
3620
+ * @param contractsAbiMap - The map of contract ABIs.
3621
+ * @returns - The assembled transaction result.
3622
+ * @throws If the transaction status is a failure.
3600
3623
  */
3601
- async waitForResult(contractsAbiMap) {
3602
- await this.waitForStatusChange();
3624
+ async assembleResult(contractsAbiMap) {
3603
3625
  const transactionSummary = await this.getTransactionSummary(contractsAbiMap);
3604
3626
  const transactionResult = {
3605
3627
  gqlTransaction: this.gqlTransaction,
@@ -3625,6 +3647,15 @@ var TransactionResponse = class {
3625
3647
  }
3626
3648
  return transactionResult;
3627
3649
  }
3650
+ /**
3651
+ * Waits for transaction to complete and returns the result.
3652
+ *
3653
+ * @returns The completed transaction result
3654
+ */
3655
+ async waitForResult(contractsAbiMap) {
3656
+ await this.waitForStatusChange();
3657
+ return this.assembleResult(contractsAbiMap);
3658
+ }
3628
3659
  /**
3629
3660
  * Waits for transaction to complete and returns the result.
3630
3661
  *
@@ -3688,6 +3719,8 @@ var mergeQuantities = (...coinQuantities) => {
3688
3719
 
3689
3720
  // src/providers/provider.ts
3690
3721
  var MAX_RETRIES = 10;
3722
+ var RESOURCES_PAGE_SIZE_LIMIT = 512;
3723
+ var BLOCKS_PAGE_SIZE_LIMIT = 5;
3691
3724
  var processGqlChain = (chain) => {
3692
3725
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3693
3726
  const {
@@ -4331,7 +4364,7 @@ Supported fuel-core version: ${supportedVersion}.`
4331
4364
  /**
4332
4365
  * Returns a transaction cost to enable user
4333
4366
  * to set gasLimit and also reserve balance amounts
4334
- * on the the transaction.
4367
+ * on the transaction.
4335
4368
  *
4336
4369
  * @param transactionRequestLike - The transaction request object.
4337
4370
  * @param transactionCostParams - The transaction cost parameters (optional).
@@ -4442,20 +4475,27 @@ Supported fuel-core version: ${supportedVersion}.`
4442
4475
  */
4443
4476
  async getCoins(owner, assetId, paginationArgs) {
4444
4477
  const ownerAddress = Address2.fromAddressOrString(owner);
4445
- const result = await this.operations.getCoins({
4446
- first: 10,
4447
- ...paginationArgs,
4478
+ const {
4479
+ coins: { edges, pageInfo }
4480
+ } = await this.operations.getCoins({
4481
+ ...this.validatePaginationArgs({
4482
+ paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
4483
+ inputArgs: paginationArgs
4484
+ }),
4448
4485
  filter: { owner: ownerAddress.toB256(), assetId: assetId && hexlify12(assetId) }
4449
4486
  });
4450
- const coins = result.coins.edges.map((edge) => edge.node);
4451
- return coins.map((coin) => ({
4452
- id: coin.utxoId,
4453
- assetId: coin.assetId,
4454
- amount: bn17(coin.amount),
4455
- owner: Address2.fromAddressOrString(coin.owner),
4456
- blockCreated: bn17(coin.blockCreated),
4457
- txCreatedIdx: bn17(coin.txCreatedIdx)
4487
+ const coins = edges.map(({ node }) => ({
4488
+ id: node.utxoId,
4489
+ assetId: node.assetId,
4490
+ amount: bn17(node.amount),
4491
+ owner: Address2.fromAddressOrString(node.owner),
4492
+ blockCreated: bn17(node.blockCreated),
4493
+ txCreatedIdx: bn17(node.txCreatedIdx)
4458
4494
  }));
4495
+ return {
4496
+ coins,
4497
+ pageInfo
4498
+ };
4459
4499
  }
4460
4500
  /**
4461
4501
  * Returns resources for the given owner satisfying the spend query.
@@ -4548,14 +4588,21 @@ Supported fuel-core version: ${supportedVersion}.`
4548
4588
  * @returns A promise that resolves to the blocks.
4549
4589
  */
4550
4590
  async getBlocks(params) {
4551
- const { blocks: fetchedData } = await this.operations.getBlocks(params);
4552
- const blocks = fetchedData.edges.map(({ node: block }) => ({
4591
+ const {
4592
+ blocks: { edges, pageInfo }
4593
+ } = await this.operations.getBlocks({
4594
+ ...this.validatePaginationArgs({
4595
+ paginationLimit: BLOCKS_PAGE_SIZE_LIMIT,
4596
+ inputArgs: params
4597
+ })
4598
+ });
4599
+ const blocks = edges.map(({ node: block }) => ({
4553
4600
  id: block.id,
4554
4601
  height: bn17(block.height),
4555
4602
  time: block.header.time,
4556
4603
  transactionIds: block.transactions.map((tx) => tx.id)
4557
4604
  }));
4558
- return blocks;
4605
+ return { blocks, pageInfo };
4559
4606
  }
4560
4607
  /**
4561
4608
  * Returns block matching the given ID or type, including transaction data.
@@ -4665,17 +4712,22 @@ Supported fuel-core version: ${supportedVersion}.`
4665
4712
  * @param paginationArgs - Pagination arguments (optional).
4666
4713
  * @returns A promise that resolves to the balances.
4667
4714
  */
4668
- async getBalances(owner, paginationArgs) {
4669
- const result = await this.operations.getBalances({
4670
- first: 10,
4671
- ...paginationArgs,
4715
+ async getBalances(owner) {
4716
+ const {
4717
+ balances: { edges }
4718
+ } = await this.operations.getBalances({
4719
+ /**
4720
+ * The query parameters for this method were designed to support pagination,
4721
+ * but the current Fuel-Core implementation does not support pagination yet.
4722
+ */
4723
+ first: 1e4,
4672
4724
  filter: { owner: Address2.fromAddressOrString(owner).toB256() }
4673
4725
  });
4674
- const balances = result.balances.edges.map((edge) => edge.node);
4675
- return balances.map((balance) => ({
4676
- assetId: balance.assetId,
4677
- amount: bn17(balance.amount)
4726
+ const balances = edges.map(({ node }) => ({
4727
+ assetId: node.assetId,
4728
+ amount: bn17(node.amount)
4678
4729
  }));
4730
+ return { balances };
4679
4731
  }
4680
4732
  /**
4681
4733
  * Returns message for the given address.
@@ -4685,27 +4737,34 @@ Supported fuel-core version: ${supportedVersion}.`
4685
4737
  * @returns A promise that resolves to the messages.
4686
4738
  */
4687
4739
  async getMessages(address, paginationArgs) {
4688
- const result = await this.operations.getMessages({
4689
- first: 10,
4690
- ...paginationArgs,
4740
+ const {
4741
+ messages: { edges, pageInfo }
4742
+ } = await this.operations.getMessages({
4743
+ ...this.validatePaginationArgs({
4744
+ inputArgs: paginationArgs,
4745
+ paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
4746
+ }),
4691
4747
  owner: Address2.fromAddressOrString(address).toB256()
4692
4748
  });
4693
- const messages = result.messages.edges.map((edge) => edge.node);
4694
- return messages.map((message) => ({
4749
+ const messages = edges.map(({ node }) => ({
4695
4750
  messageId: InputMessageCoder.getMessageId({
4696
- sender: message.sender,
4697
- recipient: message.recipient,
4698
- nonce: message.nonce,
4699
- amount: bn17(message.amount),
4700
- data: message.data
4751
+ sender: node.sender,
4752
+ recipient: node.recipient,
4753
+ nonce: node.nonce,
4754
+ amount: bn17(node.amount),
4755
+ data: node.data
4701
4756
  }),
4702
- sender: Address2.fromAddressOrString(message.sender),
4703
- recipient: Address2.fromAddressOrString(message.recipient),
4704
- nonce: message.nonce,
4705
- amount: bn17(message.amount),
4706
- data: InputMessageCoder.decodeData(message.data),
4707
- daHeight: bn17(message.daHeight)
4757
+ sender: Address2.fromAddressOrString(node.sender),
4758
+ recipient: Address2.fromAddressOrString(node.recipient),
4759
+ nonce: node.nonce,
4760
+ amount: bn17(node.amount),
4761
+ data: InputMessageCoder.decodeData(node.data),
4762
+ daHeight: bn17(node.daHeight)
4708
4763
  }));
4764
+ return {
4765
+ messages,
4766
+ pageInfo
4767
+ };
4709
4768
  }
4710
4769
  /**
4711
4770
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -4884,6 +4943,41 @@ Supported fuel-core version: ${supportedVersion}.`
4884
4943
  }
4885
4944
  return relayedTransactionStatus;
4886
4945
  }
4946
+ /**
4947
+ * @hidden
4948
+ */
4949
+ validatePaginationArgs(params) {
4950
+ const { paginationLimit, inputArgs = {} } = params;
4951
+ const { first, last, after, before } = inputArgs;
4952
+ if (after && before) {
4953
+ throw new FuelError13(
4954
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
4955
+ 'Pagination arguments "after" and "before" cannot be used together'
4956
+ );
4957
+ }
4958
+ if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
4959
+ throw new FuelError13(
4960
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
4961
+ `Pagination limit for this query cannot exceed ${paginationLimit} items`
4962
+ );
4963
+ }
4964
+ if (first && before) {
4965
+ throw new FuelError13(
4966
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
4967
+ 'The use of pagination argument "first" with "before" is not supported'
4968
+ );
4969
+ }
4970
+ if (last && after) {
4971
+ throw new FuelError13(
4972
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
4973
+ 'The use of pagination argument "last" with "after" is not supported'
4974
+ );
4975
+ }
4976
+ if (!first && !last) {
4977
+ inputArgs.first = paginationLimit;
4978
+ }
4979
+ return inputArgs;
4980
+ }
4887
4981
  /**
4888
4982
  * @hidden
4889
4983
  */
@@ -5109,52 +5203,16 @@ var Account = class extends AbstractAccount {
5109
5203
  * @param assetId - The asset ID of the coins to retrieve (optional).
5110
5204
  * @returns A promise that resolves to an array of Coins.
5111
5205
  */
5112
- async getCoins(assetId) {
5113
- const coins = [];
5114
- const pageSize = 9999;
5115
- let cursor;
5116
- for (; ; ) {
5117
- const pageCoins = await this.provider.getCoins(this.address, assetId, {
5118
- first: pageSize,
5119
- after: cursor
5120
- });
5121
- coins.push(...pageCoins);
5122
- const hasNextPage = pageCoins.length >= pageSize;
5123
- if (!hasNextPage) {
5124
- break;
5125
- }
5126
- throw new FuelError15(
5127
- ErrorCode15.NOT_SUPPORTED,
5128
- `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
5129
- );
5130
- }
5131
- return coins;
5206
+ async getCoins(assetId, paginationArgs) {
5207
+ return this.provider.getCoins(this.address, assetId, paginationArgs);
5132
5208
  }
5133
5209
  /**
5134
5210
  * Retrieves messages owned by the account.
5135
5211
  *
5136
5212
  * @returns A promise that resolves to an array of Messages.
5137
5213
  */
5138
- async getMessages() {
5139
- const messages = [];
5140
- const pageSize = 9999;
5141
- let cursor;
5142
- for (; ; ) {
5143
- const pageMessages = await this.provider.getMessages(this.address, {
5144
- first: pageSize,
5145
- after: cursor
5146
- });
5147
- messages.push(...pageMessages);
5148
- const hasNextPage = pageMessages.length >= pageSize;
5149
- if (!hasNextPage) {
5150
- break;
5151
- }
5152
- throw new FuelError15(
5153
- ErrorCode15.NOT_SUPPORTED,
5154
- `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
5155
- );
5156
- }
5157
- return messages;
5214
+ async getMessages(paginationArgs) {
5215
+ return this.provider.getMessages(this.address, paginationArgs);
5158
5216
  }
5159
5217
  /**
5160
5218
  * Retrieves the balance of the account for the given asset.
@@ -5173,25 +5231,7 @@ var Account = class extends AbstractAccount {
5173
5231
  * @returns A promise that resolves to an array of Coins and their quantities.
5174
5232
  */
5175
5233
  async getBalances() {
5176
- const balances = [];
5177
- const pageSize = 9999;
5178
- let cursor;
5179
- for (; ; ) {
5180
- const pageBalances = await this.provider.getBalances(this.address, {
5181
- first: pageSize,
5182
- after: cursor
5183
- });
5184
- balances.push(...pageBalances);
5185
- const hasNextPage = pageBalances.length >= pageSize;
5186
- if (!hasNextPage) {
5187
- break;
5188
- }
5189
- throw new FuelError15(
5190
- ErrorCode15.NOT_SUPPORTED,
5191
- `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
5192
- );
5193
- }
5194
- return balances;
5234
+ return this.provider.getBalances(this.address);
5195
5235
  }
5196
5236
  /**
5197
5237
  * Funds a transaction request by adding the necessary resources.
@@ -8640,7 +8680,6 @@ import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
8640
8680
  import os from "os";
8641
8681
  import path from "path";
8642
8682
  import { getPortPromise } from "portfinder";
8643
- import treeKill from "tree-kill";
8644
8683
  var getFlagValueFromArgs = (args, flag) => {
8645
8684
  const flagIndex = args.indexOf(flag);
8646
8685
  if (flagIndex === -1) {
@@ -8658,19 +8697,6 @@ var extractRemainingArgs = (args, flagsToRemove) => {
8658
8697
  });
8659
8698
  return newArgs;
8660
8699
  };
8661
- var killNode = (params) => {
8662
- const { child, configPath, state, killFn } = params;
8663
- if (!state.isDead) {
8664
- if (child.pid) {
8665
- state.isDead = true;
8666
- killFn(Number(child.pid));
8667
- }
8668
- child.stderr.removeAllListeners();
8669
- if (existsSync(configPath)) {
8670
- rmSync(configPath, { recursive: true });
8671
- }
8672
- }
8673
- };
8674
8700
  function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8675
8701
  const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8676
8702
  ...coin,
@@ -8777,19 +8803,45 @@ var launchNode = async ({
8777
8803
  "--debug",
8778
8804
  ...remainingArgs
8779
8805
  ].flat(),
8780
- { stdio: "pipe" }
8806
+ { stdio: "pipe", detached: true }
8781
8807
  );
8782
8808
  if (loggingEnabled) {
8783
8809
  child.stderr.on("data", (chunk) => {
8784
8810
  console.log(chunk.toString());
8785
8811
  });
8786
8812
  }
8787
- const cleanupConfig = {
8788
- child,
8789
- configPath: tempDir,
8790
- killFn: treeKill,
8791
- state: {
8792
- isDead: false
8813
+ const removeSideffects = () => {
8814
+ child.stderr.removeAllListeners();
8815
+ if (existsSync(tempDir)) {
8816
+ rmSync(tempDir, { recursive: true });
8817
+ }
8818
+ };
8819
+ child.on("error", removeSideffects);
8820
+ child.on("exit", removeSideffects);
8821
+ const childState = {
8822
+ isDead: false
8823
+ };
8824
+ const cleanup = () => {
8825
+ if (childState.isDead) {
8826
+ return;
8827
+ }
8828
+ childState.isDead = true;
8829
+ removeSideffects();
8830
+ if (child.pid !== void 0) {
8831
+ try {
8832
+ process.kill(-child.pid);
8833
+ } catch (e) {
8834
+ const error = e;
8835
+ if (error.code === "ESRCH") {
8836
+ console.log(
8837
+ `fuel-core node under pid ${child.pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
8838
+ );
8839
+ } else {
8840
+ throw e;
8841
+ }
8842
+ }
8843
+ } else {
8844
+ console.error("No PID available for the child process, unable to kill launched node");
8793
8845
  }
8794
8846
  };
8795
8847
  child.stderr.on("data", (chunk) => {
@@ -8799,11 +8851,12 @@ var launchNode = async ({
8799
8851
  const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8800
8852
  const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8801
8853
  resolve({
8802
- cleanup: () => killNode(cleanupConfig),
8854
+ cleanup,
8803
8855
  ip: realIp,
8804
8856
  port: realPort,
8805
8857
  url: `http://${realIp}:${realPort}/v1/graphql`,
8806
- snapshotDir: snapshotDirToUse
8858
+ snapshotDir: snapshotDirToUse,
8859
+ pid: child.pid
8807
8860
  });
8808
8861
  }
8809
8862
  if (/error/i.test(text)) {
@@ -8811,12 +8864,12 @@ var launchNode = async ({
8811
8864
  reject(new FuelError20(FuelError20.CODES.NODE_LAUNCH_FAILED, text));
8812
8865
  }
8813
8866
  });
8814
- process.on("exit", () => killNode(cleanupConfig));
8815
- process.on("SIGINT", () => killNode(cleanupConfig));
8816
- process.on("SIGUSR1", () => killNode(cleanupConfig));
8817
- process.on("SIGUSR2", () => killNode(cleanupConfig));
8818
- process.on("beforeExit", () => killNode(cleanupConfig));
8819
- process.on("uncaughtException", () => killNode(cleanupConfig));
8867
+ process.on("exit", cleanup);
8868
+ process.on("SIGINT", cleanup);
8869
+ process.on("SIGUSR1", cleanup);
8870
+ process.on("SIGUSR2", cleanup);
8871
+ process.on("beforeExit", cleanup);
8872
+ process.on("uncaughtException", cleanup);
8820
8873
  child.on("error", reject);
8821
8874
  })
8822
8875
  );
@@ -9089,7 +9142,6 @@ export {
9089
9142
  TestMessage,
9090
9143
  WalletsConfig,
9091
9144
  generateTestWallet,
9092
- killNode,
9093
9145
  launchNode,
9094
9146
  launchNodeAndGetWallets,
9095
9147
  seedTestWallet,