@fuel-ts/account 0.96.1 → 0.97.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.
- package/dist/account.d.ts +6 -0
- package/dist/account.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +563 -298
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +594 -320
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +600 -327
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +16 -11
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +94 -126
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +5 -8
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/blob-transaction-request.d.ts +2 -2
- package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts +3 -2
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +38 -8
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/providers/utils/handle-gql-error-message.d.ts +2 -1
- package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -1
- package/dist/providers/utils/receipts.d.ts.map +1 -1
- package/dist/providers/utils/validate-pagination-args.d.ts +9 -0
- package/dist/providers/utils/validate-pagination-args.d.ts.map +1 -0
- package/dist/test-utils.global.js +302 -237
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +276 -211
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +287 -222
- package/dist/test-utils.mjs.map +1 -1
- package/dist/utils/deployScriptOrPredicate.d.ts +14 -0
- package/dist/utils/deployScriptOrPredicate.d.ts.map +1 -0
- package/dist/utils/formatTransferToContractScriptData.d.ts +7 -7
- package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
- package/dist/utils/predicate-script-loader-instructions.d.ts +9 -0
- package/dist/utils/predicate-script-loader-instructions.d.ts.map +1 -0
- package/package.json +17 -17
package/dist/test-utils.js
CHANGED
@@ -408,7 +408,7 @@ var addAmountToCoinQuantities = (params) => {
|
|
408
408
|
|
409
409
|
// src/providers/provider.ts
|
410
410
|
var import_address4 = require("@fuel-ts/address");
|
411
|
-
var
|
411
|
+
var import_errors19 = require("@fuel-ts/errors");
|
412
412
|
var import_math19 = require("@fuel-ts/math");
|
413
413
|
var import_transactions22 = require("@fuel-ts/transactions");
|
414
414
|
var import_utils30 = require("@fuel-ts/utils");
|
@@ -461,9 +461,6 @@ var ReceiptFragmentDoc = import_graphql_tag.default`
|
|
461
461
|
var SuccessStatusFragmentDoc = import_graphql_tag.default`
|
462
462
|
fragment SuccessStatusFragment on SuccessStatus {
|
463
463
|
type: __typename
|
464
|
-
block {
|
465
|
-
id
|
466
|
-
}
|
467
464
|
time
|
468
465
|
programState {
|
469
466
|
returnType
|
@@ -476,6 +473,14 @@ var SuccessStatusFragmentDoc = import_graphql_tag.default`
|
|
476
473
|
totalFee
|
477
474
|
}
|
478
475
|
${ReceiptFragmentDoc}`;
|
476
|
+
var SuccessStatusWithBlockIdFragmentDoc = import_graphql_tag.default`
|
477
|
+
fragment SuccessStatusWithBlockIdFragment on SuccessStatus {
|
478
|
+
...SuccessStatusFragment
|
479
|
+
block {
|
480
|
+
id
|
481
|
+
}
|
482
|
+
}
|
483
|
+
${SuccessStatusFragmentDoc}`;
|
479
484
|
var MalleableTransactionFieldsFragmentDoc = import_graphql_tag.default`
|
480
485
|
fragment malleableTransactionFieldsFragment on Transaction {
|
481
486
|
receiptsRoot
|
@@ -520,9 +525,6 @@ var MalleableTransactionFieldsFragmentDoc = import_graphql_tag.default`
|
|
520
525
|
var FailureStatusFragmentDoc = import_graphql_tag.default`
|
521
526
|
fragment FailureStatusFragment on FailureStatus {
|
522
527
|
type: __typename
|
523
|
-
block {
|
524
|
-
id
|
525
|
-
}
|
526
528
|
totalGas
|
527
529
|
totalFee
|
528
530
|
time
|
@@ -532,6 +534,14 @@ var FailureStatusFragmentDoc = import_graphql_tag.default`
|
|
532
534
|
}
|
533
535
|
}
|
534
536
|
${ReceiptFragmentDoc}`;
|
537
|
+
var FailureStatusWithBlockIdFragmentDoc = import_graphql_tag.default`
|
538
|
+
fragment FailureStatusWithBlockIdFragment on FailureStatus {
|
539
|
+
...FailureStatusFragment
|
540
|
+
block {
|
541
|
+
id
|
542
|
+
}
|
543
|
+
}
|
544
|
+
${FailureStatusFragmentDoc}`;
|
535
545
|
var SqueezedOutStatusFragmentDoc = import_graphql_tag.default`
|
536
546
|
fragment SqueezedOutStatusFragment on SqueezedOutStatus {
|
537
547
|
type: __typename
|
@@ -544,13 +554,13 @@ var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
|
|
544
554
|
...SubmittedStatusFragment
|
545
555
|
}
|
546
556
|
... on SuccessStatus {
|
547
|
-
...
|
557
|
+
...SuccessStatusWithBlockIdFragment
|
548
558
|
transaction {
|
549
559
|
...malleableTransactionFieldsFragment
|
550
560
|
}
|
551
561
|
}
|
552
562
|
... on FailureStatus {
|
553
|
-
...
|
563
|
+
...FailureStatusWithBlockIdFragment
|
554
564
|
transaction {
|
555
565
|
...malleableTransactionFieldsFragment
|
556
566
|
}
|
@@ -560,9 +570,9 @@ var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
|
|
560
570
|
}
|
561
571
|
}
|
562
572
|
${SubmittedStatusFragmentDoc}
|
563
|
-
${
|
573
|
+
${SuccessStatusWithBlockIdFragmentDoc}
|
564
574
|
${MalleableTransactionFieldsFragmentDoc}
|
565
|
-
${
|
575
|
+
${FailureStatusWithBlockIdFragmentDoc}
|
566
576
|
${SqueezedOutStatusFragmentDoc}`;
|
567
577
|
var TransactionStatusFragmentDoc = import_graphql_tag.default`
|
568
578
|
fragment transactionStatusFragment on TransactionStatus {
|
@@ -592,6 +602,12 @@ var TransactionFragmentDoc = import_graphql_tag.default`
|
|
592
602
|
}
|
593
603
|
}
|
594
604
|
${TransactionStatusFragmentDoc}`;
|
605
|
+
var TransactionRawPayloadFragmentDoc = import_graphql_tag.default`
|
606
|
+
fragment transactionRawPayloadFragment on Transaction {
|
607
|
+
id
|
608
|
+
rawPayload
|
609
|
+
}
|
610
|
+
`;
|
595
611
|
var InputEstimatePredicatesFragmentDoc = import_graphql_tag.default`
|
596
612
|
fragment inputEstimatePredicatesFragment on Input {
|
597
613
|
... on InputCoin {
|
@@ -679,7 +695,6 @@ var CoinFragmentDoc = import_graphql_tag.default`
|
|
679
695
|
fragment coinFragment on Coin {
|
680
696
|
type: __typename
|
681
697
|
utxoId
|
682
|
-
owner
|
683
698
|
amount
|
684
699
|
assetId
|
685
700
|
blockCreated
|
@@ -703,10 +718,15 @@ var MessageFragmentDoc = import_graphql_tag.default`
|
|
703
718
|
sender
|
704
719
|
recipient
|
705
720
|
data
|
706
|
-
nonce
|
707
721
|
daHeight
|
708
722
|
}
|
709
723
|
`;
|
724
|
+
var GetMessageFragmentDoc = import_graphql_tag.default`
|
725
|
+
fragment getMessageFragment on Message {
|
726
|
+
...messageFragment
|
727
|
+
nonce
|
728
|
+
}
|
729
|
+
${MessageFragmentDoc}`;
|
710
730
|
var MessageProofFragmentDoc = import_graphql_tag.default`
|
711
731
|
fragment messageProofFragment on MessageProof {
|
712
732
|
messageProof {
|
@@ -751,7 +771,6 @@ var MessageProofFragmentDoc = import_graphql_tag.default`
|
|
751
771
|
}
|
752
772
|
sender
|
753
773
|
recipient
|
754
|
-
nonce
|
755
774
|
amount
|
756
775
|
data
|
757
776
|
}
|
@@ -900,12 +919,6 @@ var RelayedTransactionStatusFragmentDoc = import_graphql_tag.default`
|
|
900
919
|
}
|
901
920
|
}
|
902
921
|
`;
|
903
|
-
var TransactionRawPayloadFragmentDoc = import_graphql_tag.default`
|
904
|
-
fragment transactionRawPayload on Transaction {
|
905
|
-
id
|
906
|
-
rawPayload
|
907
|
-
}
|
908
|
-
`;
|
909
922
|
var GetVersionDocument = import_graphql_tag.default`
|
910
923
|
query getVersion {
|
911
924
|
nodeInfo {
|
@@ -948,16 +961,34 @@ var GetTransactionDocument = import_graphql_tag.default`
|
|
948
961
|
var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
949
962
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
950
963
|
transaction(id: $transactionId) {
|
951
|
-
|
964
|
+
id
|
965
|
+
rawPayload
|
966
|
+
status {
|
967
|
+
... on SubmittedStatus {
|
968
|
+
...SubmittedStatusFragment
|
969
|
+
}
|
970
|
+
... on SuccessStatus {
|
971
|
+
...SuccessStatusWithBlockIdFragment
|
972
|
+
}
|
973
|
+
... on FailureStatus {
|
974
|
+
...FailureStatusWithBlockIdFragment
|
975
|
+
}
|
976
|
+
... on SqueezedOutStatus {
|
977
|
+
...SqueezedOutStatusFragment
|
978
|
+
}
|
979
|
+
}
|
952
980
|
}
|
953
981
|
}
|
954
|
-
${
|
982
|
+
${SubmittedStatusFragmentDoc}
|
983
|
+
${SuccessStatusWithBlockIdFragmentDoc}
|
984
|
+
${FailureStatusWithBlockIdFragmentDoc}
|
985
|
+
${SqueezedOutStatusFragmentDoc}`;
|
955
986
|
var GetTransactionsDocument = import_graphql_tag.default`
|
956
987
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
957
988
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
958
989
|
edges {
|
959
990
|
node {
|
960
|
-
|
991
|
+
rawPayload
|
961
992
|
}
|
962
993
|
}
|
963
994
|
pageInfo {
|
@@ -965,8 +996,7 @@ var GetTransactionsDocument = import_graphql_tag.default`
|
|
965
996
|
}
|
966
997
|
}
|
967
998
|
}
|
968
|
-
${
|
969
|
-
${PageInfoFragmentDoc}`;
|
999
|
+
${PageInfoFragmentDoc}`;
|
970
1000
|
var GetTransactionsByOwnerDocument = import_graphql_tag.default`
|
971
1001
|
query getTransactionsByOwner($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
|
972
1002
|
transactionsByOwner(
|
@@ -1025,7 +1055,7 @@ var GetBlockWithTransactionsDocument = import_graphql_tag.default`
|
|
1025
1055
|
block(id: $blockId, height: $blockHeight) {
|
1026
1056
|
...blockFragment
|
1027
1057
|
transactions {
|
1028
|
-
...
|
1058
|
+
...transactionRawPayloadFragment
|
1029
1059
|
}
|
1030
1060
|
}
|
1031
1061
|
}
|
@@ -1050,6 +1080,7 @@ var GetCoinDocument = import_graphql_tag.default`
|
|
1050
1080
|
query getCoin($coinId: UtxoId!) {
|
1051
1081
|
coin(utxoId: $coinId) {
|
1052
1082
|
...coinFragment
|
1083
|
+
owner
|
1053
1084
|
}
|
1054
1085
|
}
|
1055
1086
|
${CoinFragmentDoc}`;
|
@@ -1158,13 +1189,13 @@ var GetMessagesDocument = import_graphql_tag.default`
|
|
1158
1189
|
}
|
1159
1190
|
edges {
|
1160
1191
|
node {
|
1161
|
-
...
|
1192
|
+
...getMessageFragment
|
1162
1193
|
}
|
1163
1194
|
}
|
1164
1195
|
}
|
1165
1196
|
}
|
1166
1197
|
${PageInfoFragmentDoc}
|
1167
|
-
${
|
1198
|
+
${GetMessageFragmentDoc}`;
|
1168
1199
|
var GetMessageProofDocument = import_graphql_tag.default`
|
1169
1200
|
query getMessageProof($transactionId: TransactionId!, $nonce: Nonce!, $commitBlockId: BlockId, $commitBlockHeight: U32) {
|
1170
1201
|
messageProof(
|
@@ -1696,9 +1727,11 @@ function assembleReceiptByType(receipt) {
|
|
1696
1727
|
const { receiptType } = receipt;
|
1697
1728
|
switch (receiptType) {
|
1698
1729
|
case "CALL" /* Call */: {
|
1730
|
+
const id = hexOrZero(receipt.id || receipt.contractId);
|
1699
1731
|
const callReceipt = {
|
1700
1732
|
type: import_transactions3.ReceiptType.Call,
|
1701
|
-
|
1733
|
+
id,
|
1734
|
+
from: id,
|
1702
1735
|
to: hexOrZero(receipt?.to),
|
1703
1736
|
amount: (0, import_math5.bn)(receipt.amount),
|
1704
1737
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1755,24 +1788,36 @@ function assembleReceiptByType(receipt) {
|
|
1755
1788
|
return revertReceipt;
|
1756
1789
|
}
|
1757
1790
|
case "LOG" /* Log */: {
|
1791
|
+
const ra = (0, import_math5.bn)(receipt.ra);
|
1792
|
+
const rb = (0, import_math5.bn)(receipt.rb);
|
1793
|
+
const rc = (0, import_math5.bn)(receipt.rc);
|
1794
|
+
const rd = (0, import_math5.bn)(receipt.rd);
|
1758
1795
|
const logReceipt = {
|
1759
1796
|
type: import_transactions3.ReceiptType.Log,
|
1760
1797
|
id: hexOrZero(receipt.id || receipt.contractId),
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1798
|
+
ra,
|
1799
|
+
rb,
|
1800
|
+
rc,
|
1801
|
+
rd,
|
1802
|
+
val0: ra,
|
1803
|
+
val1: rb,
|
1804
|
+
val2: rc,
|
1805
|
+
val3: rd,
|
1765
1806
|
pc: (0, import_math5.bn)(receipt.pc),
|
1766
1807
|
is: (0, import_math5.bn)(receipt.is)
|
1767
1808
|
};
|
1768
1809
|
return logReceipt;
|
1769
1810
|
}
|
1770
1811
|
case "LOG_DATA" /* LogData */: {
|
1812
|
+
const ra = (0, import_math5.bn)(receipt.ra);
|
1813
|
+
const rb = (0, import_math5.bn)(receipt.rb);
|
1771
1814
|
const logDataReceipt = {
|
1772
1815
|
type: import_transactions3.ReceiptType.LogData,
|
1773
1816
|
id: hexOrZero(receipt.id || receipt.contractId),
|
1774
|
-
|
1775
|
-
|
1817
|
+
ra,
|
1818
|
+
rb,
|
1819
|
+
val0: ra,
|
1820
|
+
val1: rb,
|
1776
1821
|
ptr: (0, import_math5.bn)(receipt.ptr),
|
1777
1822
|
len: (0, import_math5.bn)(receipt.len),
|
1778
1823
|
digest: hexOrZero(receipt.digest),
|
@@ -1783,9 +1828,11 @@ function assembleReceiptByType(receipt) {
|
|
1783
1828
|
return logDataReceipt;
|
1784
1829
|
}
|
1785
1830
|
case "TRANSFER" /* Transfer */: {
|
1831
|
+
const id = hexOrZero(receipt.id || receipt.contractId);
|
1786
1832
|
const transferReceipt = {
|
1787
1833
|
type: import_transactions3.ReceiptType.Transfer,
|
1788
|
-
|
1834
|
+
id,
|
1835
|
+
from: id,
|
1789
1836
|
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1790
1837
|
amount: (0, import_math5.bn)(receipt.amount),
|
1791
1838
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1795,9 +1842,11 @@ function assembleReceiptByType(receipt) {
|
|
1795
1842
|
return transferReceipt;
|
1796
1843
|
}
|
1797
1844
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1845
|
+
const id = hexOrZero(receipt.id || receipt.contractId);
|
1798
1846
|
const transferOutReceipt = {
|
1799
1847
|
type: import_transactions3.ReceiptType.TransferOut,
|
1800
|
-
|
1848
|
+
id,
|
1849
|
+
from: id,
|
1801
1850
|
to: hexOrZero(receipt.toAddress || receipt.to),
|
1802
1851
|
amount: (0, import_math5.bn)(receipt.amount),
|
1803
1852
|
assetId: hexOrZero(receipt.assetId),
|
@@ -2774,7 +2823,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
2774
2823
|
type = import_transactions7.TransactionType.Blob;
|
2775
2824
|
/** Blob ID */
|
2776
2825
|
blobId;
|
2777
|
-
/** Witness index of
|
2826
|
+
/** Witness index of the bytecode to create */
|
2778
2827
|
witnessIndex;
|
2779
2828
|
/**
|
2780
2829
|
* Creates an instance `BlobTransactionRequest`.
|
@@ -4105,14 +4154,14 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
4105
4154
|
switch (gqlTransactionStatus.type) {
|
4106
4155
|
case "SuccessStatus":
|
4107
4156
|
time = gqlTransactionStatus.time;
|
4108
|
-
blockId = gqlTransactionStatus.block
|
4157
|
+
blockId = gqlTransactionStatus.block?.id;
|
4109
4158
|
isStatusSuccess = true;
|
4110
4159
|
totalFee = (0, import_math16.bn)(gqlTransactionStatus.totalFee);
|
4111
4160
|
totalGas = (0, import_math16.bn)(gqlTransactionStatus.totalGas);
|
4112
4161
|
break;
|
4113
4162
|
case "FailureStatus":
|
4114
4163
|
time = gqlTransactionStatus.time;
|
4115
|
-
blockId = gqlTransactionStatus.block
|
4164
|
+
blockId = gqlTransactionStatus.block?.id;
|
4116
4165
|
isStatusFailure = true;
|
4117
4166
|
totalFee = (0, import_math16.bn)(gqlTransactionStatus.totalFee);
|
4118
4167
|
totalGas = (0, import_math16.bn)(gqlTransactionStatus.totalGas);
|
@@ -4547,11 +4596,53 @@ var handleGqlErrorMessage = (errorMessage, rawError) => {
|
|
4547
4596
|
{},
|
4548
4597
|
rawError
|
4549
4598
|
);
|
4599
|
+
case "max number of coins is reached while trying to fit the target" /* MAX_COINS_REACHED */:
|
4600
|
+
throw new import_errors17.FuelError(
|
4601
|
+
import_errors17.ErrorCode.MAX_COINS_REACHED,
|
4602
|
+
"The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.",
|
4603
|
+
{},
|
4604
|
+
rawError
|
4605
|
+
);
|
4550
4606
|
default:
|
4551
4607
|
throw new import_errors17.FuelError(import_errors17.ErrorCode.INVALID_REQUEST, errorMessage);
|
4552
4608
|
}
|
4553
4609
|
};
|
4554
4610
|
|
4611
|
+
// src/providers/utils/validate-pagination-args.ts
|
4612
|
+
var import_errors18 = require("@fuel-ts/errors");
|
4613
|
+
var validatePaginationArgs = (params) => {
|
4614
|
+
const { paginationLimit, inputArgs = {} } = params;
|
4615
|
+
const { first, last, after, before } = inputArgs;
|
4616
|
+
if (after && before) {
|
4617
|
+
throw new import_errors18.FuelError(
|
4618
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4619
|
+
'Pagination arguments "after" and "before" cannot be used together'
|
4620
|
+
);
|
4621
|
+
}
|
4622
|
+
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
4623
|
+
throw new import_errors18.FuelError(
|
4624
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4625
|
+
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
4626
|
+
);
|
4627
|
+
}
|
4628
|
+
if (first && before) {
|
4629
|
+
throw new import_errors18.FuelError(
|
4630
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4631
|
+
'The use of pagination argument "first" with "before" is not supported'
|
4632
|
+
);
|
4633
|
+
}
|
4634
|
+
if (last && after) {
|
4635
|
+
throw new import_errors18.FuelError(
|
4636
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4637
|
+
'The use of pagination argument "last" with "after" is not supported'
|
4638
|
+
);
|
4639
|
+
}
|
4640
|
+
if (!first && !last) {
|
4641
|
+
inputArgs.first = paginationLimit;
|
4642
|
+
}
|
4643
|
+
return inputArgs;
|
4644
|
+
};
|
4645
|
+
|
4555
4646
|
// src/providers/provider.ts
|
4556
4647
|
var MAX_RETRIES = 10;
|
4557
4648
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
@@ -4696,7 +4787,7 @@ var _Provider = class {
|
|
4696
4787
|
try {
|
4697
4788
|
parsedUrl = new URL(url);
|
4698
4789
|
} catch (error) {
|
4699
|
-
throw new
|
4790
|
+
throw new import_errors19.FuelError(import_errors19.FuelError.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
|
4700
4791
|
}
|
4701
4792
|
const username = parsedUrl.username;
|
4702
4793
|
const password = parsedUrl.password;
|
@@ -4731,8 +4822,8 @@ var _Provider = class {
|
|
4731
4822
|
getChain() {
|
4732
4823
|
const chain = _Provider.chainInfoCache[this.urlWithoutAuth];
|
4733
4824
|
if (!chain) {
|
4734
|
-
throw new
|
4735
|
-
|
4825
|
+
throw new import_errors19.FuelError(
|
4826
|
+
import_errors19.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
4736
4827
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4737
4828
|
);
|
4738
4829
|
}
|
@@ -4746,8 +4837,8 @@ var _Provider = class {
|
|
4746
4837
|
getNode() {
|
4747
4838
|
const node = _Provider.nodeInfoCache[this.urlWithoutAuth];
|
4748
4839
|
if (!node) {
|
4749
|
-
throw new
|
4750
|
-
|
4840
|
+
throw new import_errors19.FuelError(
|
4841
|
+
import_errors19.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
4751
4842
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4752
4843
|
);
|
4753
4844
|
}
|
@@ -4973,14 +5064,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4973
5064
|
}
|
4974
5065
|
} = this.getChain();
|
4975
5066
|
if ((0, import_math19.bn)(tx.inputs.length).gt(maxInputs)) {
|
4976
|
-
throw new
|
4977
|
-
|
5067
|
+
throw new import_errors19.FuelError(
|
5068
|
+
import_errors19.ErrorCode.MAX_INPUTS_EXCEEDED,
|
4978
5069
|
`The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
|
4979
5070
|
);
|
4980
5071
|
}
|
4981
5072
|
if ((0, import_math19.bn)(tx.outputs.length).gt(maxOutputs)) {
|
4982
|
-
throw new
|
4983
|
-
|
5073
|
+
throw new import_errors19.FuelError(
|
5074
|
+
import_errors19.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
4984
5075
|
`The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
|
4985
5076
|
);
|
4986
5077
|
}
|
@@ -5393,7 +5484,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5393
5484
|
const {
|
5394
5485
|
coins: { edges, pageInfo }
|
5395
5486
|
} = await this.operations.getCoins({
|
5396
|
-
...
|
5487
|
+
...validatePaginationArgs({
|
5397
5488
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
5398
5489
|
inputArgs: paginationArgs
|
5399
5490
|
}),
|
@@ -5403,7 +5494,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5403
5494
|
id: node.utxoId,
|
5404
5495
|
assetId: node.assetId,
|
5405
5496
|
amount: (0, import_math19.bn)(node.amount),
|
5406
|
-
owner:
|
5497
|
+
owner: ownerAddress,
|
5407
5498
|
blockCreated: (0, import_math19.bn)(node.blockCreated),
|
5408
5499
|
txCreatedIdx: (0, import_math19.bn)(node.txCreatedIdx)
|
5409
5500
|
}));
|
@@ -5457,7 +5548,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5457
5548
|
id: coin.utxoId,
|
5458
5549
|
amount: (0, import_math19.bn)(coin.amount),
|
5459
5550
|
assetId: coin.assetId,
|
5460
|
-
owner:
|
5551
|
+
owner: ownerAddress,
|
5461
5552
|
blockCreated: (0, import_math19.bn)(coin.blockCreated),
|
5462
5553
|
txCreatedIdx: (0, import_math19.bn)(coin.txCreatedIdx)
|
5463
5554
|
};
|
@@ -5532,7 +5623,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5532
5623
|
const {
|
5533
5624
|
blocks: { edges, pageInfo }
|
5534
5625
|
} = await this.operations.getBlocks({
|
5535
|
-
...
|
5626
|
+
...validatePaginationArgs({
|
5536
5627
|
paginationLimit: BLOCKS_PAGE_SIZE_LIMIT,
|
5537
5628
|
inputArgs: params
|
5538
5629
|
})
|
@@ -5611,7 +5702,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5611
5702
|
0
|
5612
5703
|
)?.[0];
|
5613
5704
|
} catch (error) {
|
5614
|
-
if (error instanceof
|
5705
|
+
if (error instanceof import_errors19.FuelError && error.code === import_errors19.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5615
5706
|
console.warn("Unsupported transaction type encountered");
|
5616
5707
|
return null;
|
5617
5708
|
}
|
@@ -5627,7 +5718,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5627
5718
|
const {
|
5628
5719
|
transactions: { edges, pageInfo }
|
5629
5720
|
} = await this.operations.getTransactions({
|
5630
|
-
...
|
5721
|
+
...validatePaginationArgs({
|
5631
5722
|
inputArgs: paginationArgs,
|
5632
5723
|
paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
|
5633
5724
|
})
|
@@ -5637,7 +5728,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5637
5728
|
try {
|
5638
5729
|
return coder.decode((0, import_utils30.arrayify)(rawPayload), 0)[0];
|
5639
5730
|
} catch (error) {
|
5640
|
-
if (error instanceof
|
5731
|
+
if (error instanceof import_errors19.FuelError && error.code === import_errors19.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5641
5732
|
console.warn("Unsupported transaction type encountered");
|
5642
5733
|
return null;
|
5643
5734
|
}
|
@@ -5722,7 +5813,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5722
5813
|
const {
|
5723
5814
|
messages: { edges, pageInfo }
|
5724
5815
|
} = await this.operations.getMessages({
|
5725
|
-
...
|
5816
|
+
...validatePaginationArgs({
|
5726
5817
|
inputArgs: paginationArgs,
|
5727
5818
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
|
5728
5819
|
}),
|
@@ -5763,8 +5854,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5763
5854
|
nonce
|
5764
5855
|
};
|
5765
5856
|
if (commitBlockId && commitBlockHeight) {
|
5766
|
-
throw new
|
5767
|
-
|
5857
|
+
throw new import_errors19.FuelError(
|
5858
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5768
5859
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5769
5860
|
);
|
5770
5861
|
}
|
@@ -5946,13 +6037,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5946
6037
|
messageId: import_transactions22.InputMessageCoder.getMessageId({
|
5947
6038
|
sender: rawMessage.sender,
|
5948
6039
|
recipient: rawMessage.recipient,
|
5949
|
-
nonce
|
6040
|
+
nonce,
|
5950
6041
|
amount: (0, import_math19.bn)(rawMessage.amount),
|
5951
6042
|
data: rawMessage.data
|
5952
6043
|
}),
|
5953
6044
|
sender: import_address4.Address.fromAddressOrString(rawMessage.sender),
|
5954
6045
|
recipient: import_address4.Address.fromAddressOrString(rawMessage.recipient),
|
5955
|
-
nonce
|
6046
|
+
nonce,
|
5956
6047
|
amount: (0, import_math19.bn)(rawMessage.amount),
|
5957
6048
|
data: import_transactions22.InputMessageCoder.decodeData(rawMessage.data),
|
5958
6049
|
daHeight: (0, import_math19.bn)(rawMessage.daHeight)
|
@@ -5974,41 +6065,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5974
6065
|
}
|
5975
6066
|
return relayedTransactionStatus;
|
5976
6067
|
}
|
5977
|
-
/**
|
5978
|
-
* @hidden
|
5979
|
-
*/
|
5980
|
-
validatePaginationArgs(params) {
|
5981
|
-
const { paginationLimit, inputArgs = {} } = params;
|
5982
|
-
const { first, last, after, before } = inputArgs;
|
5983
|
-
if (after && before) {
|
5984
|
-
throw new import_errors18.FuelError(
|
5985
|
-
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5986
|
-
'Pagination arguments "after" and "before" cannot be used together'
|
5987
|
-
);
|
5988
|
-
}
|
5989
|
-
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5990
|
-
throw new import_errors18.FuelError(
|
5991
|
-
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5992
|
-
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5993
|
-
);
|
5994
|
-
}
|
5995
|
-
if (first && before) {
|
5996
|
-
throw new import_errors18.FuelError(
|
5997
|
-
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5998
|
-
'The use of pagination argument "first" with "before" is not supported'
|
5999
|
-
);
|
6000
|
-
}
|
6001
|
-
if (last && after) {
|
6002
|
-
throw new import_errors18.FuelError(
|
6003
|
-
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
6004
|
-
'The use of pagination argument "last" with "after" is not supported'
|
6005
|
-
);
|
6006
|
-
}
|
6007
|
-
if (!first && !last) {
|
6008
|
-
inputArgs.first = paginationLimit;
|
6009
|
-
}
|
6010
|
-
return inputArgs;
|
6011
|
-
}
|
6012
6068
|
/**
|
6013
6069
|
* @hidden
|
6014
6070
|
*/
|
@@ -6054,7 +6110,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
6054
6110
|
__publicField(Provider, "nodeInfoCache", {});
|
6055
6111
|
|
6056
6112
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
6057
|
-
var
|
6113
|
+
var import_errors20 = require("@fuel-ts/errors");
|
6058
6114
|
var import_math20 = require("@fuel-ts/math");
|
6059
6115
|
var import_transactions23 = require("@fuel-ts/transactions");
|
6060
6116
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -6688,7 +6744,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
6688
6744
|
|
6689
6745
|
// src/test-utils/wallet-config.ts
|
6690
6746
|
var import_crypto9 = require("@fuel-ts/crypto");
|
6691
|
-
var
|
6747
|
+
var import_errors26 = require("@fuel-ts/errors");
|
6692
6748
|
var import_utils44 = require("@fuel-ts/utils");
|
6693
6749
|
|
6694
6750
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -6697,9 +6753,9 @@ var import_utils39 = require("@fuel-ts/utils");
|
|
6697
6753
|
|
6698
6754
|
// src/account.ts
|
6699
6755
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
6700
|
-
var
|
6756
|
+
var import_address6 = require("@fuel-ts/address");
|
6701
6757
|
var import_crypto5 = require("@fuel-ts/crypto");
|
6702
|
-
var
|
6758
|
+
var import_errors21 = require("@fuel-ts/errors");
|
6703
6759
|
var import_interfaces = require("@fuel-ts/interfaces");
|
6704
6760
|
var import_math22 = require("@fuel-ts/math");
|
6705
6761
|
var import_transactions24 = require("@fuel-ts/transactions");
|
@@ -6722,37 +6778,46 @@ var mergeQuantities = (...coinQuantities) => {
|
|
6722
6778
|
|
6723
6779
|
// src/utils/formatTransferToContractScriptData.ts
|
6724
6780
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
6781
|
+
var import_address5 = require("@fuel-ts/address");
|
6725
6782
|
var import_math21 = require("@fuel-ts/math");
|
6726
6783
|
var import_utils36 = require("@fuel-ts/utils");
|
6727
6784
|
var asm = __toESM(require("@fuels/vm-asm"));
|
6728
|
-
var formatTransferToContractScriptData = (
|
6729
|
-
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
6785
|
+
var formatTransferToContractScriptData = (transferParams) => {
|
6730
6786
|
const numberCoder = new import_abi_coder7.BigNumberCoder("u64");
|
6731
|
-
|
6732
|
-
|
6733
|
-
|
6734
|
-
|
6735
|
-
|
6736
|
-
|
6737
|
-
|
6787
|
+
return transferParams.reduce((acc, transferParam) => {
|
6788
|
+
const { assetId, amount, contractId } = transferParam;
|
6789
|
+
const encoded = numberCoder.encode(new import_math21.BN(amount).toNumber());
|
6790
|
+
const scriptData = (0, import_utils36.concat)([
|
6791
|
+
import_address5.Address.fromAddressOrString(contractId).toBytes(),
|
6792
|
+
encoded,
|
6793
|
+
(0, import_utils36.arrayify)(assetId)
|
6794
|
+
]);
|
6795
|
+
return (0, import_utils36.concat)([acc, scriptData]);
|
6796
|
+
}, new Uint8Array());
|
6738
6797
|
};
|
6739
|
-
var assembleTransferToContractScript = async (
|
6740
|
-
const scriptData = formatTransferToContractScriptData(
|
6798
|
+
var assembleTransferToContractScript = async (transferParams) => {
|
6799
|
+
const scriptData = formatTransferToContractScriptData(transferParams);
|
6741
6800
|
await asm.initWasm();
|
6742
|
-
|
6743
|
-
|
6744
|
-
|
6745
|
-
|
6746
|
-
|
6747
|
-
|
6748
|
-
|
6749
|
-
|
6750
|
-
|
6751
|
-
|
6752
|
-
|
6753
|
-
|
6754
|
-
|
6755
|
-
|
6801
|
+
let script = new Uint8Array();
|
6802
|
+
transferParams.forEach((_, i) => {
|
6803
|
+
const offset = (import_abi_coder7.CONTRACT_ID_LEN + import_abi_coder7.WORD_SIZE + import_abi_coder7.ASSET_ID_LEN) * i;
|
6804
|
+
script = (0, import_utils36.concat)([
|
6805
|
+
script,
|
6806
|
+
// Load ScriptData into register 0x10.
|
6807
|
+
asm.gtf(16, 0, asm.GTFArgs.ScriptData).to_bytes(),
|
6808
|
+
// Add the offset to 0x10 so it will point to the current contract ID, store in 0x11.
|
6809
|
+
asm.addi(17, 16, offset).to_bytes(),
|
6810
|
+
// Add CONTRACT_ID_LEN to 0x11 to point to the amount in the ScriptData, store in 0x12.
|
6811
|
+
asm.addi(18, 17, import_abi_coder7.CONTRACT_ID_LEN).to_bytes(),
|
6812
|
+
// Load word to the amount at 0x12 into register 0x13.
|
6813
|
+
asm.lw(19, 18, 0).to_bytes(),
|
6814
|
+
// Add WORD_SIZE to 0x12 to point to the asset ID in the ScriptData, store in 0x14.
|
6815
|
+
asm.addi(20, 18, import_abi_coder7.WORD_SIZE).to_bytes(),
|
6816
|
+
// Perform the transfer using contract ID in 0x11, amount in 0x13, and asset ID in 0x14.
|
6817
|
+
asm.tr(17, 19, 20).to_bytes()
|
6818
|
+
]);
|
6819
|
+
});
|
6820
|
+
script = (0, import_utils36.concat)([script, asm.ret(1).to_bytes()]);
|
6756
6821
|
return { script, scriptData };
|
6757
6822
|
};
|
6758
6823
|
|
@@ -6782,7 +6847,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6782
6847
|
super();
|
6783
6848
|
this._provider = provider;
|
6784
6849
|
this._connector = connector;
|
6785
|
-
this.address =
|
6850
|
+
this.address = import_address6.Address.fromDynamicInput(address);
|
6786
6851
|
}
|
6787
6852
|
/**
|
6788
6853
|
* The provider used to interact with the network.
|
@@ -6793,7 +6858,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6793
6858
|
*/
|
6794
6859
|
get provider() {
|
6795
6860
|
if (!this._provider) {
|
6796
|
-
throw new
|
6861
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
6797
6862
|
}
|
6798
6863
|
return this._provider;
|
6799
6864
|
}
|
@@ -6944,8 +7009,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6944
7009
|
fundingAttempts += 1;
|
6945
7010
|
}
|
6946
7011
|
if (needsToBeFunded) {
|
6947
|
-
throw new
|
6948
|
-
|
7012
|
+
throw new import_errors21.FuelError(
|
7013
|
+
import_errors21.ErrorCode.NOT_ENOUGH_FUNDS,
|
6949
7014
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
6950
7015
|
);
|
6951
7016
|
}
|
@@ -7016,7 +7081,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7016
7081
|
const { destination, amount, assetId } = transferParams;
|
7017
7082
|
this.validateTransferAmount(amount);
|
7018
7083
|
request.addCoinOutput(
|
7019
|
-
|
7084
|
+
import_address6.Address.fromAddressOrString(destination),
|
7020
7085
|
amount,
|
7021
7086
|
assetId ?? this.provider.getBaseAssetId()
|
7022
7087
|
);
|
@@ -7050,35 +7115,35 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7050
7115
|
* @returns A promise that resolves to the transaction response.
|
7051
7116
|
*/
|
7052
7117
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
7053
|
-
|
7054
|
-
|
7055
|
-
|
7056
|
-
"Transfer amount must be a positive number."
|
7057
|
-
);
|
7058
|
-
}
|
7059
|
-
const contractAddress = import_address5.Address.fromAddressOrString(contractId);
|
7060
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
7061
|
-
const { script, scriptData } = await assembleTransferToContractScript({
|
7062
|
-
hexlifiedContractId: contractAddress.toB256(),
|
7063
|
-
amountToTransfer: (0, import_math22.bn)(amount),
|
7064
|
-
assetId: assetIdToTransfer
|
7065
|
-
});
|
7118
|
+
return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams);
|
7119
|
+
}
|
7120
|
+
async batchTransferToContracts(contractTransferParams, txParams = {}) {
|
7066
7121
|
let request = new ScriptTransactionRequest({
|
7067
|
-
...txParams
|
7068
|
-
script,
|
7069
|
-
scriptData
|
7122
|
+
...txParams
|
7070
7123
|
});
|
7071
|
-
|
7072
|
-
const
|
7073
|
-
|
7074
|
-
|
7075
|
-
|
7076
|
-
|
7077
|
-
|
7078
|
-
|
7079
|
-
|
7124
|
+
const quantities = [];
|
7125
|
+
const transferParams = contractTransferParams.map((transferParam) => {
|
7126
|
+
const amount = (0, import_math22.bn)(transferParam.amount);
|
7127
|
+
const contractAddress = import_address6.Address.fromAddressOrString(transferParam.contractId);
|
7128
|
+
const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) : this.provider.getBaseAssetId();
|
7129
|
+
if (amount.lte(0)) {
|
7130
|
+
throw new import_errors21.FuelError(
|
7131
|
+
import_errors21.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7132
|
+
"Transfer amount must be a positive number."
|
7133
|
+
);
|
7134
|
+
}
|
7135
|
+
request.addContractInputAndOutput(contractAddress);
|
7136
|
+
quantities.push({ amount, assetId });
|
7137
|
+
return {
|
7138
|
+
amount,
|
7139
|
+
contractId: contractAddress.toB256(),
|
7140
|
+
assetId
|
7141
|
+
};
|
7080
7142
|
});
|
7081
|
-
await
|
7143
|
+
const { script, scriptData } = await assembleTransferToContractScript(transferParams);
|
7144
|
+
request.script = script;
|
7145
|
+
request.scriptData = scriptData;
|
7146
|
+
request = await this.estimateAndFundTransaction(request, txParams, { quantities });
|
7082
7147
|
return this.sendTransaction(request);
|
7083
7148
|
}
|
7084
7149
|
/**
|
@@ -7090,7 +7155,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7090
7155
|
* @returns A promise that resolves to the transaction response.
|
7091
7156
|
*/
|
7092
7157
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
7093
|
-
const recipientAddress =
|
7158
|
+
const recipientAddress = import_address6.Address.fromAddressOrString(recipient);
|
7094
7159
|
const recipientDataArray = (0, import_utils37.arrayify)(
|
7095
7160
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
7096
7161
|
);
|
@@ -7178,7 +7243,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7178
7243
|
*/
|
7179
7244
|
async signMessage(message) {
|
7180
7245
|
if (!this._connector) {
|
7181
|
-
throw new
|
7246
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
7182
7247
|
}
|
7183
7248
|
return this._connector.signMessage(this.address.toString(), message);
|
7184
7249
|
}
|
@@ -7190,8 +7255,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7190
7255
|
*/
|
7191
7256
|
async signTransaction(transactionRequestLike) {
|
7192
7257
|
if (!this._connector) {
|
7193
|
-
throw new
|
7194
|
-
|
7258
|
+
throw new import_errors21.FuelError(
|
7259
|
+
import_errors21.ErrorCode.MISSING_CONNECTOR,
|
7195
7260
|
"A connector is required to sign transactions."
|
7196
7261
|
);
|
7197
7262
|
}
|
@@ -7250,16 +7315,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7250
7315
|
/** @hidden * */
|
7251
7316
|
validateTransferAmount(amount) {
|
7252
7317
|
if ((0, import_math22.bn)(amount).lte(0)) {
|
7253
|
-
throw new
|
7254
|
-
|
7318
|
+
throw new import_errors21.FuelError(
|
7319
|
+
import_errors21.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7255
7320
|
"Transfer amount must be a positive number."
|
7256
7321
|
);
|
7257
7322
|
}
|
7258
7323
|
}
|
7259
7324
|
/** @hidden * */
|
7260
|
-
async estimateAndFundTransaction(transactionRequest, txParams) {
|
7325
|
+
async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
|
7261
7326
|
let request = transactionRequest;
|
7262
|
-
const txCost = await this.getTransactionCost(request);
|
7327
|
+
const txCost = await this.getTransactionCost(request, costParams);
|
7263
7328
|
request = this.validateGasLimitAndMaxFee({
|
7264
7329
|
transactionRequest: request,
|
7265
7330
|
gasUsed: txCost.gasUsed,
|
@@ -7280,16 +7345,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7280
7345
|
if (!(0, import_utils37.isDefined)(setGasLimit)) {
|
7281
7346
|
request.gasLimit = gasUsed;
|
7282
7347
|
} else if (gasUsed.gt(setGasLimit)) {
|
7283
|
-
throw new
|
7284
|
-
|
7348
|
+
throw new import_errors21.FuelError(
|
7349
|
+
import_errors21.ErrorCode.GAS_LIMIT_TOO_LOW,
|
7285
7350
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
7286
7351
|
);
|
7287
7352
|
}
|
7288
7353
|
if (!(0, import_utils37.isDefined)(setMaxFee)) {
|
7289
7354
|
request.maxFee = maxFee;
|
7290
7355
|
} else if (maxFee.gt(setMaxFee)) {
|
7291
|
-
throw new
|
7292
|
-
|
7356
|
+
throw new import_errors21.FuelError(
|
7357
|
+
import_errors21.ErrorCode.MAX_FEE_TOO_LOW,
|
7293
7358
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
7294
7359
|
);
|
7295
7360
|
}
|
@@ -7298,9 +7363,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7298
7363
|
};
|
7299
7364
|
|
7300
7365
|
// src/wallet/keystore-wallet.ts
|
7301
|
-
var
|
7366
|
+
var import_address7 = require("@fuel-ts/address");
|
7302
7367
|
var import_crypto6 = require("@fuel-ts/crypto");
|
7303
|
-
var
|
7368
|
+
var import_errors22 = require("@fuel-ts/errors");
|
7304
7369
|
var import_utils38 = require("@fuel-ts/utils");
|
7305
7370
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
7306
7371
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -7315,7 +7380,7 @@ var removeHexPrefix = (hexString) => {
|
|
7315
7380
|
};
|
7316
7381
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
7317
7382
|
const privateKeyBuffer = (0, import_crypto6.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
7318
|
-
const ownerAddress =
|
7383
|
+
const ownerAddress = import_address7.Address.fromAddressOrString(address);
|
7319
7384
|
const salt = (0, import_crypto6.randomBytes)(DEFAULT_KEY_SIZE);
|
7320
7385
|
const key = (0, import_crypto6.scrypt)({
|
7321
7386
|
password: (0, import_crypto6.bufferFromString)(password),
|
@@ -7377,8 +7442,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7377
7442
|
const macHashUint8Array = (0, import_crypto6.keccak256)(data);
|
7378
7443
|
const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
|
7379
7444
|
if (mac !== macHash) {
|
7380
|
-
throw new
|
7381
|
-
|
7445
|
+
throw new import_errors22.FuelError(
|
7446
|
+
import_errors22.ErrorCode.INVALID_PASSWORD,
|
7382
7447
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
7383
7448
|
);
|
7384
7449
|
}
|
@@ -7508,14 +7573,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
7508
7573
|
|
7509
7574
|
// src/hdwallet/hdwallet.ts
|
7510
7575
|
var import_crypto8 = require("@fuel-ts/crypto");
|
7511
|
-
var
|
7576
|
+
var import_errors25 = require("@fuel-ts/errors");
|
7512
7577
|
var import_hasher7 = require("@fuel-ts/hasher");
|
7513
7578
|
var import_math23 = require("@fuel-ts/math");
|
7514
7579
|
var import_utils43 = require("@fuel-ts/utils");
|
7515
7580
|
|
7516
7581
|
// src/mnemonic/mnemonic.ts
|
7517
7582
|
var import_crypto7 = require("@fuel-ts/crypto");
|
7518
|
-
var
|
7583
|
+
var import_errors24 = require("@fuel-ts/errors");
|
7519
7584
|
var import_hasher6 = require("@fuel-ts/hasher");
|
7520
7585
|
var import_utils41 = require("@fuel-ts/utils");
|
7521
7586
|
|
@@ -9572,7 +9637,7 @@ var english = [
|
|
9572
9637
|
];
|
9573
9638
|
|
9574
9639
|
// src/mnemonic/utils.ts
|
9575
|
-
var
|
9640
|
+
var import_errors23 = require("@fuel-ts/errors");
|
9576
9641
|
var import_hasher5 = require("@fuel-ts/hasher");
|
9577
9642
|
var import_utils40 = require("@fuel-ts/utils");
|
9578
9643
|
function getLowerMask(bits) {
|
@@ -9621,8 +9686,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9621
9686
|
for (let i = 0; i < words.length; i += 1) {
|
9622
9687
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
9623
9688
|
if (index === -1) {
|
9624
|
-
throw new
|
9625
|
-
|
9689
|
+
throw new import_errors23.FuelError(
|
9690
|
+
import_errors23.ErrorCode.INVALID_MNEMONIC,
|
9626
9691
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
9627
9692
|
);
|
9628
9693
|
}
|
@@ -9638,8 +9703,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9638
9703
|
const checksumMask = getUpperMask(checksumBits);
|
9639
9704
|
const checksum = (0, import_utils40.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
9640
9705
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
9641
|
-
throw new
|
9642
|
-
|
9706
|
+
throw new import_errors23.FuelError(
|
9707
|
+
import_errors23.ErrorCode.INVALID_CHECKSUM,
|
9643
9708
|
"Checksum validation failed for the provided mnemonic."
|
9644
9709
|
);
|
9645
9710
|
}
|
@@ -9653,16 +9718,16 @@ var TestnetPRV = "0x04358394";
|
|
9653
9718
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
9654
9719
|
function assertWordList(wordlist) {
|
9655
9720
|
if (wordlist.length !== 2048) {
|
9656
|
-
throw new
|
9657
|
-
|
9721
|
+
throw new import_errors24.FuelError(
|
9722
|
+
import_errors24.ErrorCode.INVALID_WORD_LIST,
|
9658
9723
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
9659
9724
|
);
|
9660
9725
|
}
|
9661
9726
|
}
|
9662
9727
|
function assertEntropy(entropy) {
|
9663
9728
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
9664
|
-
throw new
|
9665
|
-
|
9729
|
+
throw new import_errors24.FuelError(
|
9730
|
+
import_errors24.ErrorCode.INVALID_ENTROPY,
|
9666
9731
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
9667
9732
|
);
|
9668
9733
|
}
|
@@ -9672,7 +9737,7 @@ function assertMnemonic(words) {
|
|
9672
9737
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
9673
9738
|
", "
|
9674
9739
|
)}] words, but got ${words.length}.`;
|
9675
|
-
throw new
|
9740
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
9676
9741
|
}
|
9677
9742
|
}
|
9678
9743
|
var Mnemonic = class {
|
@@ -9790,8 +9855,8 @@ var Mnemonic = class {
|
|
9790
9855
|
static masterKeysFromSeed(seed) {
|
9791
9856
|
const seedArray = (0, import_utils41.arrayify)(seed);
|
9792
9857
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
9793
|
-
throw new
|
9794
|
-
|
9858
|
+
throw new import_errors24.FuelError(
|
9859
|
+
import_errors24.ErrorCode.INVALID_SEED,
|
9795
9860
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
9796
9861
|
);
|
9797
9862
|
}
|
@@ -9868,7 +9933,7 @@ function isValidExtendedKey(extendedKey) {
|
|
9868
9933
|
function parsePath(path2, depth = 0) {
|
9869
9934
|
const components = path2.split("/");
|
9870
9935
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
9871
|
-
throw new
|
9936
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
9872
9937
|
}
|
9873
9938
|
if (components[0] === "m") {
|
9874
9939
|
components.shift();
|
@@ -9897,8 +9962,8 @@ var HDWallet = class {
|
|
9897
9962
|
this.privateKey = (0, import_utils43.hexlify)(config.privateKey);
|
9898
9963
|
} else {
|
9899
9964
|
if (!config.publicKey) {
|
9900
|
-
throw new
|
9901
|
-
|
9965
|
+
throw new import_errors25.FuelError(
|
9966
|
+
import_errors25.ErrorCode.HD_WALLET_ERROR,
|
9902
9967
|
"Both public and private Key cannot be missing. At least one should be provided."
|
9903
9968
|
);
|
9904
9969
|
}
|
@@ -9927,8 +9992,8 @@ var HDWallet = class {
|
|
9927
9992
|
const data = new Uint8Array(37);
|
9928
9993
|
if (index & HARDENED_INDEX) {
|
9929
9994
|
if (!privateKey) {
|
9930
|
-
throw new
|
9931
|
-
|
9995
|
+
throw new import_errors25.FuelError(
|
9996
|
+
import_errors25.ErrorCode.HD_WALLET_ERROR,
|
9932
9997
|
"Cannot derive a hardened index without a private Key."
|
9933
9998
|
);
|
9934
9999
|
}
|
@@ -9980,8 +10045,8 @@ var HDWallet = class {
|
|
9980
10045
|
*/
|
9981
10046
|
toExtendedKey(isPublic = false, testnet = false) {
|
9982
10047
|
if (this.depth >= 256) {
|
9983
|
-
throw new
|
9984
|
-
|
10048
|
+
throw new import_errors25.FuelError(
|
10049
|
+
import_errors25.ErrorCode.HD_WALLET_ERROR,
|
9985
10050
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
9986
10051
|
);
|
9987
10052
|
}
|
@@ -10012,10 +10077,10 @@ var HDWallet = class {
|
|
10012
10077
|
const bytes = (0, import_utils43.arrayify)(decoded);
|
10013
10078
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
10014
10079
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
10015
|
-
throw new
|
10080
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
10016
10081
|
}
|
10017
10082
|
if (!validChecksum) {
|
10018
|
-
throw new
|
10083
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
10019
10084
|
}
|
10020
10085
|
const depth = bytes[4];
|
10021
10086
|
const parentFingerprint = (0, import_utils43.hexlify)(bytes.slice(5, 9));
|
@@ -10023,14 +10088,14 @@ var HDWallet = class {
|
|
10023
10088
|
const chainCode = (0, import_utils43.hexlify)(bytes.slice(13, 45));
|
10024
10089
|
const key = bytes.slice(45, 78);
|
10025
10090
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
10026
|
-
throw new
|
10027
|
-
|
10091
|
+
throw new import_errors25.FuelError(
|
10092
|
+
import_errors25.ErrorCode.HD_WALLET_ERROR,
|
10028
10093
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
10029
10094
|
);
|
10030
10095
|
}
|
10031
10096
|
if (isPublicExtendedKey(bytes)) {
|
10032
10097
|
if (key[0] !== 3) {
|
10033
|
-
throw new
|
10098
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
10034
10099
|
}
|
10035
10100
|
return new HDWallet({
|
10036
10101
|
publicKey: key,
|
@@ -10041,7 +10106,7 @@ var HDWallet = class {
|
|
10041
10106
|
});
|
10042
10107
|
}
|
10043
10108
|
if (key[0] !== 0) {
|
10044
|
-
throw new
|
10109
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
10045
10110
|
}
|
10046
10111
|
return new HDWallet({
|
10047
10112
|
privateKey: key.slice(1),
|
@@ -10285,26 +10350,26 @@ var WalletsConfig = class {
|
|
10285
10350
|
amountPerCoin
|
10286
10351
|
}) {
|
10287
10352
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
10288
|
-
throw new
|
10289
|
-
|
10353
|
+
throw new import_errors26.FuelError(
|
10354
|
+
import_errors26.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10290
10355
|
"Number of wallets must be greater than zero."
|
10291
10356
|
);
|
10292
10357
|
}
|
10293
10358
|
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
10294
|
-
throw new
|
10295
|
-
|
10359
|
+
throw new import_errors26.FuelError(
|
10360
|
+
import_errors26.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10296
10361
|
"Number of assets per wallet must be greater than zero."
|
10297
10362
|
);
|
10298
10363
|
}
|
10299
10364
|
if (coinsPerAsset <= 0) {
|
10300
|
-
throw new
|
10301
|
-
|
10365
|
+
throw new import_errors26.FuelError(
|
10366
|
+
import_errors26.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10302
10367
|
"Number of coins per asset must be greater than zero."
|
10303
10368
|
);
|
10304
10369
|
}
|
10305
10370
|
if (amountPerCoin < 0) {
|
10306
|
-
throw new
|
10307
|
-
|
10371
|
+
throw new import_errors26.FuelError(
|
10372
|
+
import_errors26.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10308
10373
|
"Amount per coin must be greater than or equal to zero."
|
10309
10374
|
);
|
10310
10375
|
}
|
@@ -10375,7 +10440,7 @@ async function setupTestProviderAndWallets({
|
|
10375
10440
|
}
|
10376
10441
|
|
10377
10442
|
// src/test-utils/test-message.ts
|
10378
|
-
var
|
10443
|
+
var import_address8 = require("@fuel-ts/address");
|
10379
10444
|
var import_crypto10 = require("@fuel-ts/crypto");
|
10380
10445
|
var import_math24 = require("@fuel-ts/math");
|
10381
10446
|
var import_utils46 = require("@fuel-ts/utils");
|
@@ -10393,8 +10458,8 @@ var TestMessage = class {
|
|
10393
10458
|
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
10394
10459
|
*/
|
10395
10460
|
constructor({
|
10396
|
-
sender =
|
10397
|
-
recipient =
|
10461
|
+
sender = import_address8.Address.fromRandom(),
|
10462
|
+
recipient = import_address8.Address.fromRandom(),
|
10398
10463
|
nonce = (0, import_utils46.hexlify)((0, import_crypto10.randomBytes)(32)),
|
10399
10464
|
amount = 1e6,
|
10400
10465
|
data = "",
|