@fuel-ts/account 0.94.9 → 0.96.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.
@@ -374,7 +374,7 @@ import { ErrorCode as ErrorCode14, FuelError as FuelError17 } from "@fuel-ts/err
374
374
  import { BN as BN2, bn as bn17 } from "@fuel-ts/math";
375
375
  import { InputType as InputType7, InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
376
376
  import { arrayify as arrayify13, hexlify as hexlify17, DateTime as DateTime2, isDefined as isDefined2 } from "@fuel-ts/utils";
377
- import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
377
+ import { checkFuelCoreVersionCompatibility, versions } from "@fuel-ts/versions";
378
378
  import { equalBytes } from "@noble/curves/abstract/utils";
379
379
  import { GraphQLClient } from "graphql-request";
380
380
  import gql2 from "graphql-tag";
@@ -617,6 +617,26 @@ var DryRunTransactionExecutionStatusFragmentDoc = gql`
617
617
  }
618
618
  ${DryRunTransactionStatusFragmentDoc}
619
619
  ${ReceiptFragmentDoc}`;
620
+ var BlockFragmentDoc = gql`
621
+ fragment blockFragment on Block {
622
+ id
623
+ height
624
+ header {
625
+ time
626
+ daHeight
627
+ stateTransitionBytecodeVersion
628
+ transactionsCount
629
+ transactionsRoot
630
+ messageOutboxRoot
631
+ eventInboxRoot
632
+ prevRoot
633
+ applicationHash
634
+ }
635
+ transactions {
636
+ id
637
+ }
638
+ }
639
+ `;
620
640
  var CoinFragmentDoc = gql`
621
641
  fragment coinFragment on Coin {
622
642
  type: __typename
@@ -698,33 +718,6 @@ var MessageProofFragmentDoc = gql`
698
718
  data
699
719
  }
700
720
  `;
701
- var BalanceFragmentDoc = gql`
702
- fragment balanceFragment on Balance {
703
- owner
704
- amount
705
- assetId
706
- }
707
- `;
708
- var BlockFragmentDoc = gql`
709
- fragment blockFragment on Block {
710
- id
711
- height
712
- header {
713
- time
714
- daHeight
715
- stateTransitionBytecodeVersion
716
- transactionsCount
717
- transactionsRoot
718
- messageOutboxRoot
719
- eventInboxRoot
720
- prevRoot
721
- applicationHash
722
- }
723
- transactions {
724
- id
725
- }
726
- }
727
- `;
728
721
  var TxParametersFragmentDoc = gql`
729
722
  fragment TxParametersFragment on TxParameters {
730
723
  version
@@ -782,167 +775,6 @@ var DependentCostFragmentDoc = gql`
782
775
  `;
783
776
  var GasCostsFragmentDoc = gql`
784
777
  fragment GasCostsFragment on GasCosts {
785
- version
786
- add
787
- addi
788
- aloc
789
- and
790
- andi
791
- bal
792
- bhei
793
- bhsh
794
- burn
795
- cb
796
- cfei
797
- cfsi
798
- div
799
- divi
800
- ecr1
801
- eck1
802
- ed19
803
- eq
804
- exp
805
- expi
806
- flag
807
- gm
808
- gt
809
- gtf
810
- ji
811
- jmp
812
- jne
813
- jnei
814
- jnzi
815
- jmpf
816
- jmpb
817
- jnzf
818
- jnzb
819
- jnef
820
- jneb
821
- lb
822
- log
823
- lt
824
- lw
825
- mint
826
- mlog
827
- modOp
828
- modi
829
- moveOp
830
- movi
831
- mroo
832
- mul
833
- muli
834
- mldv
835
- noop
836
- not
837
- or
838
- ori
839
- poph
840
- popl
841
- pshh
842
- pshl
843
- ret
844
- rvrt
845
- sb
846
- sll
847
- slli
848
- srl
849
- srli
850
- srw
851
- sub
852
- subi
853
- sw
854
- sww
855
- time
856
- tr
857
- tro
858
- wdcm
859
- wqcm
860
- wdop
861
- wqop
862
- wdml
863
- wqml
864
- wddv
865
- wqdv
866
- wdmd
867
- wqmd
868
- wdam
869
- wqam
870
- wdmm
871
- wqmm
872
- xor
873
- xori
874
- alocDependentCost {
875
- ...DependentCostFragment
876
- }
877
- bldd {
878
- ...DependentCostFragment
879
- }
880
- bsiz {
881
- ...DependentCostFragment
882
- }
883
- cfe {
884
- ...DependentCostFragment
885
- }
886
- cfeiDependentCost {
887
- ...DependentCostFragment
888
- }
889
- call {
890
- ...DependentCostFragment
891
- }
892
- ccp {
893
- ...DependentCostFragment
894
- }
895
- croo {
896
- ...DependentCostFragment
897
- }
898
- csiz {
899
- ...DependentCostFragment
900
- }
901
- ed19DependentCost {
902
- ...DependentCostFragment
903
- }
904
- k256 {
905
- ...DependentCostFragment
906
- }
907
- ldc {
908
- ...DependentCostFragment
909
- }
910
- logd {
911
- ...DependentCostFragment
912
- }
913
- mcl {
914
- ...DependentCostFragment
915
- }
916
- mcli {
917
- ...DependentCostFragment
918
- }
919
- mcp {
920
- ...DependentCostFragment
921
- }
922
- mcpi {
923
- ...DependentCostFragment
924
- }
925
- meq {
926
- ...DependentCostFragment
927
- }
928
- retd {
929
- ...DependentCostFragment
930
- }
931
- s256 {
932
- ...DependentCostFragment
933
- }
934
- scwq {
935
- ...DependentCostFragment
936
- }
937
- smo {
938
- ...DependentCostFragment
939
- }
940
- srwq {
941
- ...DependentCostFragment
942
- }
943
- swwq {
944
- ...DependentCostFragment
945
- }
946
778
  contractRoot {
947
779
  ...DependentCostFragment
948
780
  }
@@ -952,6 +784,10 @@ var GasCostsFragmentDoc = gql`
952
784
  vmInitialization {
953
785
  ...DependentCostFragment
954
786
  }
787
+ s256 {
788
+ ...DependentCostFragment
789
+ }
790
+ ecr1
955
791
  newStoragePerByte
956
792
  }
957
793
  ${DependentCostFragmentDoc}`;
@@ -988,16 +824,12 @@ ${GasCostsFragmentDoc}`;
988
824
  var ChainInfoFragmentDoc = gql`
989
825
  fragment chainInfoFragment on ChainInfo {
990
826
  name
991
- latestBlock {
992
- ...blockFragment
993
- }
994
827
  daHeight
995
828
  consensusParameters {
996
829
  ...consensusParametersFragment
997
830
  }
998
831
  }
999
- ${BlockFragmentDoc}
1000
- ${ConsensusParametersFragmentDoc}`;
832
+ ${ConsensusParametersFragmentDoc}`;
1001
833
  var ContractBalanceFragmentDoc = gql`
1002
834
  fragment contractBalanceFragment on ContractBalance {
1003
835
  contract
@@ -1030,6 +862,12 @@ var RelayedTransactionStatusFragmentDoc = gql`
1030
862
  }
1031
863
  }
1032
864
  `;
865
+ var TransactionRawPayloadFragmentDoc = gql`
866
+ fragment transactionRawPayload on Transaction {
867
+ id
868
+ rawPayload
869
+ }
870
+ `;
1033
871
  var GetVersionDocument = gql`
1034
872
  query getVersion {
1035
873
  nodeInfo {
@@ -1051,6 +889,17 @@ var GetChainDocument = gql`
1051
889
  }
1052
890
  }
1053
891
  ${ChainInfoFragmentDoc}`;
892
+ var GetChainAndNodeInfoDocument = gql`
893
+ query getChainAndNodeInfo {
894
+ chain {
895
+ ...chainInfoFragment
896
+ }
897
+ nodeInfo {
898
+ ...nodeInfoFragment
899
+ }
900
+ }
901
+ ${ChainInfoFragmentDoc}
902
+ ${NodeInfoFragmentDoc}`;
1054
903
  var GetTransactionDocument = gql`
1055
904
  query getTransaction($transactionId: TransactionId!) {
1056
905
  transaction(id: $transactionId) {
@@ -1108,6 +957,24 @@ var EstimatePredicatesDocument = gql`
1108
957
  }
1109
958
  }
1110
959
  ${TransactionEstimatePredicatesFragmentDoc}`;
960
+ var GetLatestBlockDocument = gql`
961
+ query getLatestBlock {
962
+ chain {
963
+ latestBlock {
964
+ ...blockFragment
965
+ }
966
+ }
967
+ }
968
+ ${BlockFragmentDoc}`;
969
+ var GetLatestBlockHeightDocument = gql`
970
+ query getLatestBlockHeight {
971
+ chain {
972
+ latestBlock {
973
+ height
974
+ }
975
+ }
976
+ }
977
+ `;
1111
978
  var GetBlockDocument = gql`
1112
979
  query getBlock($blockId: BlockId, $height: U32) {
1113
980
  block(id: $blockId, height: $height) {
@@ -1120,12 +987,12 @@ var GetBlockWithTransactionsDocument = gql`
1120
987
  block(id: $blockId, height: $blockHeight) {
1121
988
  ...blockFragment
1122
989
  transactions {
1123
- ...transactionFragment
990
+ ...transactionRawPayload
1124
991
  }
1125
992
  }
1126
993
  }
1127
994
  ${BlockFragmentDoc}
1128
- ${TransactionFragmentDoc}`;
995
+ ${TransactionRawPayloadFragmentDoc}`;
1129
996
  var GetBlocksDocument = gql`
1130
997
  query getBlocks($after: String, $before: String, $first: Int, $last: Int) {
1131
998
  blocks(after: $after, before: $before, first: $first, last: $last) {
@@ -1200,10 +1067,10 @@ var GetContractBalanceDocument = gql`
1200
1067
  var GetBalanceDocument = gql`
1201
1068
  query getBalance($owner: Address!, $assetId: AssetId!) {
1202
1069
  balance(owner: $owner, assetId: $assetId) {
1203
- ...balanceFragment
1070
+ amount
1204
1071
  }
1205
1072
  }
1206
- ${BalanceFragmentDoc}`;
1073
+ `;
1207
1074
  var GetLatestGasPriceDocument = gql`
1208
1075
  query getLatestGasPrice {
1209
1076
  latestGasPrice {
@@ -1232,13 +1099,13 @@ var GetBalancesDocument = gql`
1232
1099
  }
1233
1100
  edges {
1234
1101
  node {
1235
- ...balanceFragment
1102
+ assetId
1103
+ amount
1236
1104
  }
1237
1105
  }
1238
1106
  }
1239
1107
  }
1240
- ${PageInfoFragmentDoc}
1241
- ${BalanceFragmentDoc}`;
1108
+ ${PageInfoFragmentDoc}`;
1242
1109
  var GetMessagesDocument = gql`
1243
1110
  query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
1244
1111
  messages(
@@ -1319,6 +1186,19 @@ var GetMessageByNonceDocument = gql`
1319
1186
  }
1320
1187
  }
1321
1188
  ${MessageFragmentDoc}`;
1189
+ var IsUserAccountDocument = gql`
1190
+ query isUserAccount($blobId: BlobId!, $contractId: ContractId!, $transactionId: TransactionId!) {
1191
+ blob(id: $blobId) {
1192
+ id
1193
+ }
1194
+ contract(id: $contractId) {
1195
+ id
1196
+ }
1197
+ transaction(id: $transactionId) {
1198
+ id
1199
+ }
1200
+ }
1201
+ `;
1322
1202
  var SubmitAndAwaitDocument = gql`
1323
1203
  subscription submitAndAwait($encodedTransaction: HexString!) {
1324
1204
  submitAndAwait(tx: $encodedTransaction) {
@@ -1351,6 +1231,9 @@ function getSdk(requester) {
1351
1231
  getChain(variables, options) {
1352
1232
  return requester(GetChainDocument, variables, options);
1353
1233
  },
1234
+ getChainAndNodeInfo(variables, options) {
1235
+ return requester(GetChainAndNodeInfoDocument, variables, options);
1236
+ },
1354
1237
  getTransaction(variables, options) {
1355
1238
  return requester(GetTransactionDocument, variables, options);
1356
1239
  },
@@ -1366,6 +1249,12 @@ function getSdk(requester) {
1366
1249
  estimatePredicates(variables, options) {
1367
1250
  return requester(EstimatePredicatesDocument, variables, options);
1368
1251
  },
1252
+ getLatestBlock(variables, options) {
1253
+ return requester(GetLatestBlockDocument, variables, options);
1254
+ },
1255
+ getLatestBlockHeight(variables, options) {
1256
+ return requester(GetLatestBlockHeightDocument, variables, options);
1257
+ },
1369
1258
  getBlock(variables, options) {
1370
1259
  return requester(GetBlockDocument, variables, options);
1371
1260
  },
@@ -1426,6 +1315,9 @@ function getSdk(requester) {
1426
1315
  getMessageByNonce(variables, options) {
1427
1316
  return requester(GetMessageByNonceDocument, variables, options);
1428
1317
  },
1318
+ isUserAccount(variables, options) {
1319
+ return requester(IsUserAccountDocument, variables, options);
1320
+ },
1429
1321
  submitAndAwait(variables, options) {
1430
1322
  return requester(SubmitAndAwaitDocument, variables, options);
1431
1323
  },
@@ -4628,10 +4520,11 @@ var handleGqlErrorMessage = (errorMessage, rawError) => {
4628
4520
  // src/providers/provider.ts
4629
4521
  var MAX_RETRIES = 10;
4630
4522
  var RESOURCES_PAGE_SIZE_LIMIT = 512;
4523
+ var TRANSACTIONS_PAGE_SIZE_LIMIT = 60;
4631
4524
  var BLOCKS_PAGE_SIZE_LIMIT = 5;
4632
4525
  var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
4633
4526
  var processGqlChain = (chain) => {
4634
- const { name, daHeight, consensusParameters, latestBlock } = chain;
4527
+ const { name, daHeight, consensusParameters } = chain;
4635
4528
  const {
4636
4529
  contractParams,
4637
4530
  feeParams,
@@ -4682,14 +4575,6 @@ var processGqlChain = (chain) => {
4682
4575
  maxScriptDataLength: bn17(scriptParams.maxScriptDataLength)
4683
4576
  },
4684
4577
  gasCosts
4685
- },
4686
- latestBlock: {
4687
- id: latestBlock.id,
4688
- height: bn17(latestBlock.height),
4689
- time: latestBlock.header.time,
4690
- transactions: latestBlock.transactions.map((i) => ({
4691
- id: i.id
4692
- }))
4693
4578
  }
4694
4579
  };
4695
4580
  };
@@ -4720,14 +4605,17 @@ var _Provider = class {
4720
4605
  retryOptions: void 0,
4721
4606
  headers: void 0
4722
4607
  });
4723
- const { url: rawUrl, urlWithoutAuth, headers } = _Provider.extractBasicAuth(url);
4608
+ const { url: rawUrl, urlWithoutAuth, headers: authHeaders } = _Provider.extractBasicAuth(url);
4724
4609
  this.url = rawUrl;
4725
4610
  this.urlWithoutAuth = urlWithoutAuth;
4726
- this.options = { ...this.options, ...options };
4727
4611
  this.url = url;
4728
- if (headers) {
4729
- this.options = { ...this.options, headers: { ...this.options.headers, ...headers } };
4730
- }
4612
+ const { FUELS } = versions;
4613
+ const headers = { ...authHeaders, ...options.headers, Source: `ts-sdk-${FUELS}` };
4614
+ this.options = {
4615
+ ...this.options,
4616
+ ...options,
4617
+ headers
4618
+ };
4731
4619
  this.operations = this.createOperations();
4732
4620
  const { resourceCacheTTL } = this.options;
4733
4621
  if (isDefined2(resourceCacheTTL)) {
@@ -4866,9 +4754,25 @@ var _Provider = class {
4866
4754
  * @returns A promise that resolves to the Chain and NodeInfo.
4867
4755
  */
4868
4756
  async fetchChainAndNodeInfo() {
4869
- const nodeInfo = await this.fetchNode();
4870
- _Provider.ensureClientVersionIsSupported(nodeInfo);
4871
- const chain = await this.fetchChain();
4757
+ let nodeInfo;
4758
+ let chain;
4759
+ try {
4760
+ nodeInfo = this.getNode();
4761
+ chain = this.getChain();
4762
+ } catch (error) {
4763
+ const data = await this.operations.getChainAndNodeInfo();
4764
+ nodeInfo = {
4765
+ maxDepth: bn17(data.nodeInfo.maxDepth),
4766
+ maxTx: bn17(data.nodeInfo.maxTx),
4767
+ nodeVersion: data.nodeInfo.nodeVersion,
4768
+ utxoValidation: data.nodeInfo.utxoValidation,
4769
+ vmBacktrace: data.nodeInfo.vmBacktrace
4770
+ };
4771
+ _Provider.ensureClientVersionIsSupported(nodeInfo);
4772
+ chain = processGqlChain(data.chain);
4773
+ _Provider.chainInfoCache[this.urlWithoutAuth] = chain;
4774
+ _Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
4775
+ }
4872
4776
  return {
4873
4777
  chain,
4874
4778
  nodeInfo
@@ -4960,8 +4864,12 @@ Supported fuel-core version: ${supportedVersion}.`
4960
4864
  * @returns A promise that resolves to the latest block number.
4961
4865
  */
4962
4866
  async getBlockNumber() {
4963
- const { chain } = await this.operations.getChain();
4964
- return bn17(chain.latestBlock.height, 10);
4867
+ const {
4868
+ chain: {
4869
+ latestBlock: { height }
4870
+ }
4871
+ } = await this.operations.getLatestBlockHeight();
4872
+ return bn17(height);
4965
4873
  }
4966
4874
  /**
4967
4875
  * Returns the node information for the current provider network.
@@ -5508,17 +5416,18 @@ Supported fuel-core version: ${supportedVersion}.`
5508
5416
  * @returns A promise that resolves to the block or null.
5509
5417
  */
5510
5418
  async getBlock(idOrHeight) {
5511
- let variables;
5512
- if (typeof idOrHeight === "number") {
5513
- variables = { height: bn17(idOrHeight).toString(10) };
5514
- } else if (idOrHeight === "latest") {
5515
- variables = { height: (await this.getBlockNumber()).toString(10) };
5516
- } else if (idOrHeight.length === 66) {
5517
- variables = { blockId: idOrHeight };
5419
+ let block;
5420
+ if (idOrHeight === "latest") {
5421
+ const {
5422
+ chain: { latestBlock }
5423
+ } = await this.operations.getLatestBlock();
5424
+ block = latestBlock;
5518
5425
  } else {
5519
- variables = { blockId: bn17(idOrHeight).toString(10) };
5426
+ const isblockId = typeof idOrHeight === "string" && idOrHeight.length === 66;
5427
+ const variables = isblockId ? { blockId: idOrHeight } : { height: bn17(idOrHeight).toString(10) };
5428
+ const response = await this.operations.getBlock(variables);
5429
+ block = response.block;
5520
5430
  }
5521
- const { block } = await this.operations.getBlock(variables);
5522
5431
  if (!block) {
5523
5432
  return null;
5524
5433
  }
@@ -5644,7 +5553,12 @@ Supported fuel-core version: ${supportedVersion}.`
5644
5553
  async getTransactions(paginationArgs) {
5645
5554
  const {
5646
5555
  transactions: { edges, pageInfo }
5647
- } = await this.operations.getTransactions(paginationArgs);
5556
+ } = await this.operations.getTransactions({
5557
+ ...this.validatePaginationArgs({
5558
+ inputArgs: paginationArgs,
5559
+ paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
5560
+ })
5561
+ });
5648
5562
  const coder = new TransactionCoder5();
5649
5563
  const transactions = edges.map(({ node: { rawPayload } }) => {
5650
5564
  try {
@@ -5900,6 +5814,40 @@ Supported fuel-core version: ${supportedVersion}.`
5900
5814
  });
5901
5815
  return bn17(latestBlockHeight);
5902
5816
  }
5817
+ /**
5818
+ * Check if the given ID is an account.
5819
+ *
5820
+ * @param id - The ID to check.
5821
+ * @returns A promise that resolves to the result of the check.
5822
+ */
5823
+ async isUserAccount(id) {
5824
+ const { contract, blob, transaction } = await this.operations.isUserAccount({
5825
+ blobId: id,
5826
+ contractId: id,
5827
+ transactionId: id
5828
+ });
5829
+ if (contract || blob || transaction) {
5830
+ return false;
5831
+ }
5832
+ return true;
5833
+ }
5834
+ async getAddressType(id) {
5835
+ const { contract, blob, transaction } = await this.operations.isUserAccount({
5836
+ blobId: id,
5837
+ contractId: id,
5838
+ transactionId: id
5839
+ });
5840
+ if (contract) {
5841
+ return "Contract";
5842
+ }
5843
+ if (blob) {
5844
+ return "Blob";
5845
+ }
5846
+ if (transaction) {
5847
+ return "Transaction";
5848
+ }
5849
+ return "Account";
5850
+ }
5903
5851
  /**
5904
5852
  * Get the transaction response for the given transaction ID.
5905
5853
  *