@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/index.js
CHANGED
@@ -125,6 +125,7 @@ __export(src_exports, {
|
|
125
125
|
calculateTXFeeForSummary: () => calculateTXFeeForSummary,
|
126
126
|
coinQuantityfy: () => coinQuantityfy,
|
127
127
|
deferPromise: () => deferPromise,
|
128
|
+
deployScriptOrPredicate: () => deployScriptOrPredicate,
|
128
129
|
dispatchFuelConnectorEvent: () => dispatchFuelConnectorEvent,
|
129
130
|
english: () => english,
|
130
131
|
extractBurnedAssetsFromReceipts: () => extractBurnedAssetsFromReceipts,
|
@@ -218,9 +219,9 @@ module.exports = __toCommonJS(src_exports);
|
|
218
219
|
|
219
220
|
// src/account.ts
|
220
221
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
221
|
-
var
|
222
|
+
var import_address5 = require("@fuel-ts/address");
|
222
223
|
var import_crypto2 = require("@fuel-ts/crypto");
|
223
|
-
var
|
224
|
+
var import_errors20 = require("@fuel-ts/errors");
|
224
225
|
var import_interfaces = require("@fuel-ts/interfaces");
|
225
226
|
var import_math21 = require("@fuel-ts/math");
|
226
227
|
var import_transactions24 = require("@fuel-ts/transactions");
|
@@ -264,7 +265,7 @@ var addAmountToCoinQuantities = (params) => {
|
|
264
265
|
|
265
266
|
// src/providers/provider.ts
|
266
267
|
var import_address3 = require("@fuel-ts/address");
|
267
|
-
var
|
268
|
+
var import_errors18 = require("@fuel-ts/errors");
|
268
269
|
var import_math18 = require("@fuel-ts/math");
|
269
270
|
var import_transactions22 = require("@fuel-ts/transactions");
|
270
271
|
var import_utils28 = require("@fuel-ts/utils");
|
@@ -317,9 +318,6 @@ var ReceiptFragmentDoc = import_graphql_tag.default`
|
|
317
318
|
var SuccessStatusFragmentDoc = import_graphql_tag.default`
|
318
319
|
fragment SuccessStatusFragment on SuccessStatus {
|
319
320
|
type: __typename
|
320
|
-
block {
|
321
|
-
id
|
322
|
-
}
|
323
321
|
time
|
324
322
|
programState {
|
325
323
|
returnType
|
@@ -332,6 +330,14 @@ var SuccessStatusFragmentDoc = import_graphql_tag.default`
|
|
332
330
|
totalFee
|
333
331
|
}
|
334
332
|
${ReceiptFragmentDoc}`;
|
333
|
+
var SuccessStatusWithBlockIdFragmentDoc = import_graphql_tag.default`
|
334
|
+
fragment SuccessStatusWithBlockIdFragment on SuccessStatus {
|
335
|
+
...SuccessStatusFragment
|
336
|
+
block {
|
337
|
+
id
|
338
|
+
}
|
339
|
+
}
|
340
|
+
${SuccessStatusFragmentDoc}`;
|
335
341
|
var MalleableTransactionFieldsFragmentDoc = import_graphql_tag.default`
|
336
342
|
fragment malleableTransactionFieldsFragment on Transaction {
|
337
343
|
receiptsRoot
|
@@ -376,9 +382,6 @@ var MalleableTransactionFieldsFragmentDoc = import_graphql_tag.default`
|
|
376
382
|
var FailureStatusFragmentDoc = import_graphql_tag.default`
|
377
383
|
fragment FailureStatusFragment on FailureStatus {
|
378
384
|
type: __typename
|
379
|
-
block {
|
380
|
-
id
|
381
|
-
}
|
382
385
|
totalGas
|
383
386
|
totalFee
|
384
387
|
time
|
@@ -388,6 +391,14 @@ var FailureStatusFragmentDoc = import_graphql_tag.default`
|
|
388
391
|
}
|
389
392
|
}
|
390
393
|
${ReceiptFragmentDoc}`;
|
394
|
+
var FailureStatusWithBlockIdFragmentDoc = import_graphql_tag.default`
|
395
|
+
fragment FailureStatusWithBlockIdFragment on FailureStatus {
|
396
|
+
...FailureStatusFragment
|
397
|
+
block {
|
398
|
+
id
|
399
|
+
}
|
400
|
+
}
|
401
|
+
${FailureStatusFragmentDoc}`;
|
391
402
|
var SqueezedOutStatusFragmentDoc = import_graphql_tag.default`
|
392
403
|
fragment SqueezedOutStatusFragment on SqueezedOutStatus {
|
393
404
|
type: __typename
|
@@ -400,13 +411,13 @@ var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
|
|
400
411
|
...SubmittedStatusFragment
|
401
412
|
}
|
402
413
|
... on SuccessStatus {
|
403
|
-
...
|
414
|
+
...SuccessStatusWithBlockIdFragment
|
404
415
|
transaction {
|
405
416
|
...malleableTransactionFieldsFragment
|
406
417
|
}
|
407
418
|
}
|
408
419
|
... on FailureStatus {
|
409
|
-
...
|
420
|
+
...FailureStatusWithBlockIdFragment
|
410
421
|
transaction {
|
411
422
|
...malleableTransactionFieldsFragment
|
412
423
|
}
|
@@ -416,9 +427,9 @@ var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
|
|
416
427
|
}
|
417
428
|
}
|
418
429
|
${SubmittedStatusFragmentDoc}
|
419
|
-
${
|
430
|
+
${SuccessStatusWithBlockIdFragmentDoc}
|
420
431
|
${MalleableTransactionFieldsFragmentDoc}
|
421
|
-
${
|
432
|
+
${FailureStatusWithBlockIdFragmentDoc}
|
422
433
|
${SqueezedOutStatusFragmentDoc}`;
|
423
434
|
var TransactionStatusFragmentDoc = import_graphql_tag.default`
|
424
435
|
fragment transactionStatusFragment on TransactionStatus {
|
@@ -448,6 +459,12 @@ var TransactionFragmentDoc = import_graphql_tag.default`
|
|
448
459
|
}
|
449
460
|
}
|
450
461
|
${TransactionStatusFragmentDoc}`;
|
462
|
+
var TransactionRawPayloadFragmentDoc = import_graphql_tag.default`
|
463
|
+
fragment transactionRawPayloadFragment on Transaction {
|
464
|
+
id
|
465
|
+
rawPayload
|
466
|
+
}
|
467
|
+
`;
|
451
468
|
var InputEstimatePredicatesFragmentDoc = import_graphql_tag.default`
|
452
469
|
fragment inputEstimatePredicatesFragment on Input {
|
453
470
|
... on InputCoin {
|
@@ -535,7 +552,6 @@ var CoinFragmentDoc = import_graphql_tag.default`
|
|
535
552
|
fragment coinFragment on Coin {
|
536
553
|
type: __typename
|
537
554
|
utxoId
|
538
|
-
owner
|
539
555
|
amount
|
540
556
|
assetId
|
541
557
|
blockCreated
|
@@ -559,10 +575,15 @@ var MessageFragmentDoc = import_graphql_tag.default`
|
|
559
575
|
sender
|
560
576
|
recipient
|
561
577
|
data
|
562
|
-
nonce
|
563
578
|
daHeight
|
564
579
|
}
|
565
580
|
`;
|
581
|
+
var GetMessageFragmentDoc = import_graphql_tag.default`
|
582
|
+
fragment getMessageFragment on Message {
|
583
|
+
...messageFragment
|
584
|
+
nonce
|
585
|
+
}
|
586
|
+
${MessageFragmentDoc}`;
|
566
587
|
var MessageProofFragmentDoc = import_graphql_tag.default`
|
567
588
|
fragment messageProofFragment on MessageProof {
|
568
589
|
messageProof {
|
@@ -607,7 +628,6 @@ var MessageProofFragmentDoc = import_graphql_tag.default`
|
|
607
628
|
}
|
608
629
|
sender
|
609
630
|
recipient
|
610
|
-
nonce
|
611
631
|
amount
|
612
632
|
data
|
613
633
|
}
|
@@ -756,12 +776,6 @@ var RelayedTransactionStatusFragmentDoc = import_graphql_tag.default`
|
|
756
776
|
}
|
757
777
|
}
|
758
778
|
`;
|
759
|
-
var TransactionRawPayloadFragmentDoc = import_graphql_tag.default`
|
760
|
-
fragment transactionRawPayload on Transaction {
|
761
|
-
id
|
762
|
-
rawPayload
|
763
|
-
}
|
764
|
-
`;
|
765
779
|
var GetVersionDocument = import_graphql_tag.default`
|
766
780
|
query getVersion {
|
767
781
|
nodeInfo {
|
@@ -804,16 +818,34 @@ var GetTransactionDocument = import_graphql_tag.default`
|
|
804
818
|
var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
805
819
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
806
820
|
transaction(id: $transactionId) {
|
807
|
-
|
821
|
+
id
|
822
|
+
rawPayload
|
823
|
+
status {
|
824
|
+
... on SubmittedStatus {
|
825
|
+
...SubmittedStatusFragment
|
826
|
+
}
|
827
|
+
... on SuccessStatus {
|
828
|
+
...SuccessStatusWithBlockIdFragment
|
829
|
+
}
|
830
|
+
... on FailureStatus {
|
831
|
+
...FailureStatusWithBlockIdFragment
|
832
|
+
}
|
833
|
+
... on SqueezedOutStatus {
|
834
|
+
...SqueezedOutStatusFragment
|
835
|
+
}
|
836
|
+
}
|
808
837
|
}
|
809
838
|
}
|
810
|
-
${
|
839
|
+
${SubmittedStatusFragmentDoc}
|
840
|
+
${SuccessStatusWithBlockIdFragmentDoc}
|
841
|
+
${FailureStatusWithBlockIdFragmentDoc}
|
842
|
+
${SqueezedOutStatusFragmentDoc}`;
|
811
843
|
var GetTransactionsDocument = import_graphql_tag.default`
|
812
844
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
813
845
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
814
846
|
edges {
|
815
847
|
node {
|
816
|
-
|
848
|
+
rawPayload
|
817
849
|
}
|
818
850
|
}
|
819
851
|
pageInfo {
|
@@ -821,8 +853,7 @@ var GetTransactionsDocument = import_graphql_tag.default`
|
|
821
853
|
}
|
822
854
|
}
|
823
855
|
}
|
824
|
-
${
|
825
|
-
${PageInfoFragmentDoc}`;
|
856
|
+
${PageInfoFragmentDoc}`;
|
826
857
|
var GetTransactionsByOwnerDocument = import_graphql_tag.default`
|
827
858
|
query getTransactionsByOwner($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
|
828
859
|
transactionsByOwner(
|
@@ -881,7 +912,7 @@ var GetBlockWithTransactionsDocument = import_graphql_tag.default`
|
|
881
912
|
block(id: $blockId, height: $blockHeight) {
|
882
913
|
...blockFragment
|
883
914
|
transactions {
|
884
|
-
...
|
915
|
+
...transactionRawPayloadFragment
|
885
916
|
}
|
886
917
|
}
|
887
918
|
}
|
@@ -906,6 +937,7 @@ var GetCoinDocument = import_graphql_tag.default`
|
|
906
937
|
query getCoin($coinId: UtxoId!) {
|
907
938
|
coin(utxoId: $coinId) {
|
908
939
|
...coinFragment
|
940
|
+
owner
|
909
941
|
}
|
910
942
|
}
|
911
943
|
${CoinFragmentDoc}`;
|
@@ -1014,13 +1046,13 @@ var GetMessagesDocument = import_graphql_tag.default`
|
|
1014
1046
|
}
|
1015
1047
|
edges {
|
1016
1048
|
node {
|
1017
|
-
...
|
1049
|
+
...getMessageFragment
|
1018
1050
|
}
|
1019
1051
|
}
|
1020
1052
|
}
|
1021
1053
|
}
|
1022
1054
|
${PageInfoFragmentDoc}
|
1023
|
-
${
|
1055
|
+
${GetMessageFragmentDoc}`;
|
1024
1056
|
var GetMessageProofDocument = import_graphql_tag.default`
|
1025
1057
|
query getMessageProof($transactionId: TransactionId!, $nonce: Nonce!, $commitBlockId: BlockId, $commitBlockHeight: U32) {
|
1026
1058
|
messageProof(
|
@@ -1555,9 +1587,11 @@ function assembleReceiptByType(receipt) {
|
|
1555
1587
|
const { receiptType } = receipt;
|
1556
1588
|
switch (receiptType) {
|
1557
1589
|
case "CALL" /* Call */: {
|
1590
|
+
const id = hexOrZero(receipt.id || receipt.contractId);
|
1558
1591
|
const callReceipt = {
|
1559
1592
|
type: import_transactions3.ReceiptType.Call,
|
1560
|
-
|
1593
|
+
id,
|
1594
|
+
from: id,
|
1561
1595
|
to: hexOrZero(receipt?.to),
|
1562
1596
|
amount: (0, import_math4.bn)(receipt.amount),
|
1563
1597
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1614,24 +1648,36 @@ function assembleReceiptByType(receipt) {
|
|
1614
1648
|
return revertReceipt;
|
1615
1649
|
}
|
1616
1650
|
case "LOG" /* Log */: {
|
1651
|
+
const ra = (0, import_math4.bn)(receipt.ra);
|
1652
|
+
const rb = (0, import_math4.bn)(receipt.rb);
|
1653
|
+
const rc = (0, import_math4.bn)(receipt.rc);
|
1654
|
+
const rd = (0, import_math4.bn)(receipt.rd);
|
1617
1655
|
const logReceipt = {
|
1618
1656
|
type: import_transactions3.ReceiptType.Log,
|
1619
1657
|
id: hexOrZero(receipt.id || receipt.contractId),
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1658
|
+
ra,
|
1659
|
+
rb,
|
1660
|
+
rc,
|
1661
|
+
rd,
|
1662
|
+
val0: ra,
|
1663
|
+
val1: rb,
|
1664
|
+
val2: rc,
|
1665
|
+
val3: rd,
|
1624
1666
|
pc: (0, import_math4.bn)(receipt.pc),
|
1625
1667
|
is: (0, import_math4.bn)(receipt.is)
|
1626
1668
|
};
|
1627
1669
|
return logReceipt;
|
1628
1670
|
}
|
1629
1671
|
case "LOG_DATA" /* LogData */: {
|
1672
|
+
const ra = (0, import_math4.bn)(receipt.ra);
|
1673
|
+
const rb = (0, import_math4.bn)(receipt.rb);
|
1630
1674
|
const logDataReceipt = {
|
1631
1675
|
type: import_transactions3.ReceiptType.LogData,
|
1632
1676
|
id: hexOrZero(receipt.id || receipt.contractId),
|
1633
|
-
|
1634
|
-
|
1677
|
+
ra,
|
1678
|
+
rb,
|
1679
|
+
val0: ra,
|
1680
|
+
val1: rb,
|
1635
1681
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1636
1682
|
len: (0, import_math4.bn)(receipt.len),
|
1637
1683
|
digest: hexOrZero(receipt.digest),
|
@@ -1642,9 +1688,11 @@ function assembleReceiptByType(receipt) {
|
|
1642
1688
|
return logDataReceipt;
|
1643
1689
|
}
|
1644
1690
|
case "TRANSFER" /* Transfer */: {
|
1691
|
+
const id = hexOrZero(receipt.id || receipt.contractId);
|
1645
1692
|
const transferReceipt = {
|
1646
1693
|
type: import_transactions3.ReceiptType.Transfer,
|
1647
|
-
|
1694
|
+
id,
|
1695
|
+
from: id,
|
1648
1696
|
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1649
1697
|
amount: (0, import_math4.bn)(receipt.amount),
|
1650
1698
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1654,9 +1702,11 @@ function assembleReceiptByType(receipt) {
|
|
1654
1702
|
return transferReceipt;
|
1655
1703
|
}
|
1656
1704
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1705
|
+
const id = hexOrZero(receipt.id || receipt.contractId);
|
1657
1706
|
const transferOutReceipt = {
|
1658
1707
|
type: import_transactions3.ReceiptType.TransferOut,
|
1659
|
-
|
1708
|
+
id,
|
1709
|
+
from: id,
|
1660
1710
|
to: hexOrZero(receipt.toAddress || receipt.to),
|
1661
1711
|
amount: (0, import_math4.bn)(receipt.amount),
|
1662
1712
|
assetId: hexOrZero(receipt.assetId),
|
@@ -2718,7 +2768,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
2718
2768
|
type = import_transactions7.TransactionType.Blob;
|
2719
2769
|
/** Blob ID */
|
2720
2770
|
blobId;
|
2721
|
-
/** Witness index of
|
2771
|
+
/** Witness index of the bytecode to create */
|
2722
2772
|
witnessIndex;
|
2723
2773
|
/**
|
2724
2774
|
* Creates an instance `BlobTransactionRequest`.
|
@@ -4102,14 +4152,14 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
4102
4152
|
switch (gqlTransactionStatus.type) {
|
4103
4153
|
case "SuccessStatus":
|
4104
4154
|
time = gqlTransactionStatus.time;
|
4105
|
-
blockId = gqlTransactionStatus.block
|
4155
|
+
blockId = gqlTransactionStatus.block?.id;
|
4106
4156
|
isStatusSuccess = true;
|
4107
4157
|
totalFee = (0, import_math15.bn)(gqlTransactionStatus.totalFee);
|
4108
4158
|
totalGas = (0, import_math15.bn)(gqlTransactionStatus.totalGas);
|
4109
4159
|
break;
|
4110
4160
|
case "FailureStatus":
|
4111
4161
|
time = gqlTransactionStatus.time;
|
4112
|
-
blockId = gqlTransactionStatus.block
|
4162
|
+
blockId = gqlTransactionStatus.block?.id;
|
4113
4163
|
isStatusFailure = true;
|
4114
4164
|
totalFee = (0, import_math15.bn)(gqlTransactionStatus.totalFee);
|
4115
4165
|
totalGas = (0, import_math15.bn)(gqlTransactionStatus.totalGas);
|
@@ -4420,8 +4470,8 @@ var TransactionResponse = class {
|
|
4420
4470
|
const subscription = this.submitTxSubscription ?? await this.provider.operations.statusChange({
|
4421
4471
|
transactionId: this.id
|
4422
4472
|
});
|
4423
|
-
for await (const
|
4424
|
-
const statusChange = "statusChange" in
|
4473
|
+
for await (const sub2 of subscription) {
|
4474
|
+
const statusChange = "statusChange" in sub2 ? sub2.statusChange : sub2.submitAndAwaitStatus;
|
4425
4475
|
this.status = statusChange;
|
4426
4476
|
if (statusChange.type === "SqueezedOutStatus") {
|
4427
4477
|
this.unsetResourceCache();
|
@@ -4544,11 +4594,53 @@ var handleGqlErrorMessage = (errorMessage, rawError) => {
|
|
4544
4594
|
{},
|
4545
4595
|
rawError
|
4546
4596
|
);
|
4597
|
+
case "max number of coins is reached while trying to fit the target" /* MAX_COINS_REACHED */:
|
4598
|
+
throw new import_errors16.FuelError(
|
4599
|
+
import_errors16.ErrorCode.MAX_COINS_REACHED,
|
4600
|
+
"The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.",
|
4601
|
+
{},
|
4602
|
+
rawError
|
4603
|
+
);
|
4547
4604
|
default:
|
4548
4605
|
throw new import_errors16.FuelError(import_errors16.ErrorCode.INVALID_REQUEST, errorMessage);
|
4549
4606
|
}
|
4550
4607
|
};
|
4551
4608
|
|
4609
|
+
// src/providers/utils/validate-pagination-args.ts
|
4610
|
+
var import_errors17 = require("@fuel-ts/errors");
|
4611
|
+
var validatePaginationArgs = (params) => {
|
4612
|
+
const { paginationLimit, inputArgs = {} } = params;
|
4613
|
+
const { first, last, after, before } = inputArgs;
|
4614
|
+
if (after && before) {
|
4615
|
+
throw new import_errors17.FuelError(
|
4616
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4617
|
+
'Pagination arguments "after" and "before" cannot be used together'
|
4618
|
+
);
|
4619
|
+
}
|
4620
|
+
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
4621
|
+
throw new import_errors17.FuelError(
|
4622
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4623
|
+
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
4624
|
+
);
|
4625
|
+
}
|
4626
|
+
if (first && before) {
|
4627
|
+
throw new import_errors17.FuelError(
|
4628
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4629
|
+
'The use of pagination argument "first" with "before" is not supported'
|
4630
|
+
);
|
4631
|
+
}
|
4632
|
+
if (last && after) {
|
4633
|
+
throw new import_errors17.FuelError(
|
4634
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4635
|
+
'The use of pagination argument "last" with "after" is not supported'
|
4636
|
+
);
|
4637
|
+
}
|
4638
|
+
if (!first && !last) {
|
4639
|
+
inputArgs.first = paginationLimit;
|
4640
|
+
}
|
4641
|
+
return inputArgs;
|
4642
|
+
};
|
4643
|
+
|
4552
4644
|
// src/providers/provider.ts
|
4553
4645
|
var MAX_RETRIES = 10;
|
4554
4646
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
@@ -4693,7 +4785,7 @@ var _Provider = class {
|
|
4693
4785
|
try {
|
4694
4786
|
parsedUrl = new URL(url);
|
4695
4787
|
} catch (error) {
|
4696
|
-
throw new
|
4788
|
+
throw new import_errors18.FuelError(import_errors18.FuelError.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
|
4697
4789
|
}
|
4698
4790
|
const username = parsedUrl.username;
|
4699
4791
|
const password = parsedUrl.password;
|
@@ -4728,8 +4820,8 @@ var _Provider = class {
|
|
4728
4820
|
getChain() {
|
4729
4821
|
const chain = _Provider.chainInfoCache[this.urlWithoutAuth];
|
4730
4822
|
if (!chain) {
|
4731
|
-
throw new
|
4732
|
-
|
4823
|
+
throw new import_errors18.FuelError(
|
4824
|
+
import_errors18.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
4733
4825
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4734
4826
|
);
|
4735
4827
|
}
|
@@ -4743,8 +4835,8 @@ var _Provider = class {
|
|
4743
4835
|
getNode() {
|
4744
4836
|
const node = _Provider.nodeInfoCache[this.urlWithoutAuth];
|
4745
4837
|
if (!node) {
|
4746
|
-
throw new
|
4747
|
-
|
4838
|
+
throw new import_errors18.FuelError(
|
4839
|
+
import_errors18.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
4748
4840
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4749
4841
|
);
|
4750
4842
|
}
|
@@ -4970,14 +5062,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4970
5062
|
}
|
4971
5063
|
} = this.getChain();
|
4972
5064
|
if ((0, import_math18.bn)(tx.inputs.length).gt(maxInputs)) {
|
4973
|
-
throw new
|
4974
|
-
|
5065
|
+
throw new import_errors18.FuelError(
|
5066
|
+
import_errors18.ErrorCode.MAX_INPUTS_EXCEEDED,
|
4975
5067
|
`The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
|
4976
5068
|
);
|
4977
5069
|
}
|
4978
5070
|
if ((0, import_math18.bn)(tx.outputs.length).gt(maxOutputs)) {
|
4979
|
-
throw new
|
4980
|
-
|
5071
|
+
throw new import_errors18.FuelError(
|
5072
|
+
import_errors18.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
4981
5073
|
`The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
|
4982
5074
|
);
|
4983
5075
|
}
|
@@ -5390,7 +5482,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5390
5482
|
const {
|
5391
5483
|
coins: { edges, pageInfo }
|
5392
5484
|
} = await this.operations.getCoins({
|
5393
|
-
...
|
5485
|
+
...validatePaginationArgs({
|
5394
5486
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
5395
5487
|
inputArgs: paginationArgs
|
5396
5488
|
}),
|
@@ -5400,7 +5492,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5400
5492
|
id: node.utxoId,
|
5401
5493
|
assetId: node.assetId,
|
5402
5494
|
amount: (0, import_math18.bn)(node.amount),
|
5403
|
-
owner:
|
5495
|
+
owner: ownerAddress,
|
5404
5496
|
blockCreated: (0, import_math18.bn)(node.blockCreated),
|
5405
5497
|
txCreatedIdx: (0, import_math18.bn)(node.txCreatedIdx)
|
5406
5498
|
}));
|
@@ -5454,7 +5546,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5454
5546
|
id: coin.utxoId,
|
5455
5547
|
amount: (0, import_math18.bn)(coin.amount),
|
5456
5548
|
assetId: coin.assetId,
|
5457
|
-
owner:
|
5549
|
+
owner: ownerAddress,
|
5458
5550
|
blockCreated: (0, import_math18.bn)(coin.blockCreated),
|
5459
5551
|
txCreatedIdx: (0, import_math18.bn)(coin.txCreatedIdx)
|
5460
5552
|
};
|
@@ -5529,7 +5621,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5529
5621
|
const {
|
5530
5622
|
blocks: { edges, pageInfo }
|
5531
5623
|
} = await this.operations.getBlocks({
|
5532
|
-
...
|
5624
|
+
...validatePaginationArgs({
|
5533
5625
|
paginationLimit: BLOCKS_PAGE_SIZE_LIMIT,
|
5534
5626
|
inputArgs: params
|
5535
5627
|
})
|
@@ -5608,7 +5700,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5608
5700
|
0
|
5609
5701
|
)?.[0];
|
5610
5702
|
} catch (error) {
|
5611
|
-
if (error instanceof
|
5703
|
+
if (error instanceof import_errors18.FuelError && error.code === import_errors18.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5612
5704
|
console.warn("Unsupported transaction type encountered");
|
5613
5705
|
return null;
|
5614
5706
|
}
|
@@ -5624,7 +5716,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5624
5716
|
const {
|
5625
5717
|
transactions: { edges, pageInfo }
|
5626
5718
|
} = await this.operations.getTransactions({
|
5627
|
-
...
|
5719
|
+
...validatePaginationArgs({
|
5628
5720
|
inputArgs: paginationArgs,
|
5629
5721
|
paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
|
5630
5722
|
})
|
@@ -5634,7 +5726,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5634
5726
|
try {
|
5635
5727
|
return coder.decode((0, import_utils28.arrayify)(rawPayload), 0)[0];
|
5636
5728
|
} catch (error) {
|
5637
|
-
if (error instanceof
|
5729
|
+
if (error instanceof import_errors18.FuelError && error.code === import_errors18.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5638
5730
|
console.warn("Unsupported transaction type encountered");
|
5639
5731
|
return null;
|
5640
5732
|
}
|
@@ -5719,7 +5811,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5719
5811
|
const {
|
5720
5812
|
messages: { edges, pageInfo }
|
5721
5813
|
} = await this.operations.getMessages({
|
5722
|
-
...
|
5814
|
+
...validatePaginationArgs({
|
5723
5815
|
inputArgs: paginationArgs,
|
5724
5816
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
|
5725
5817
|
}),
|
@@ -5760,8 +5852,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5760
5852
|
nonce
|
5761
5853
|
};
|
5762
5854
|
if (commitBlockId && commitBlockHeight) {
|
5763
|
-
throw new
|
5764
|
-
|
5855
|
+
throw new import_errors18.FuelError(
|
5856
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5765
5857
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5766
5858
|
);
|
5767
5859
|
}
|
@@ -5943,13 +6035,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5943
6035
|
messageId: import_transactions22.InputMessageCoder.getMessageId({
|
5944
6036
|
sender: rawMessage.sender,
|
5945
6037
|
recipient: rawMessage.recipient,
|
5946
|
-
nonce
|
6038
|
+
nonce,
|
5947
6039
|
amount: (0, import_math18.bn)(rawMessage.amount),
|
5948
6040
|
data: rawMessage.data
|
5949
6041
|
}),
|
5950
6042
|
sender: import_address3.Address.fromAddressOrString(rawMessage.sender),
|
5951
6043
|
recipient: import_address3.Address.fromAddressOrString(rawMessage.recipient),
|
5952
|
-
nonce
|
6044
|
+
nonce,
|
5953
6045
|
amount: (0, import_math18.bn)(rawMessage.amount),
|
5954
6046
|
data: import_transactions22.InputMessageCoder.decodeData(rawMessage.data),
|
5955
6047
|
daHeight: (0, import_math18.bn)(rawMessage.daHeight)
|
@@ -5971,41 +6063,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5971
6063
|
}
|
5972
6064
|
return relayedTransactionStatus;
|
5973
6065
|
}
|
5974
|
-
/**
|
5975
|
-
* @hidden
|
5976
|
-
*/
|
5977
|
-
validatePaginationArgs(params) {
|
5978
|
-
const { paginationLimit, inputArgs = {} } = params;
|
5979
|
-
const { first, last, after, before } = inputArgs;
|
5980
|
-
if (after && before) {
|
5981
|
-
throw new import_errors17.FuelError(
|
5982
|
-
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5983
|
-
'Pagination arguments "after" and "before" cannot be used together'
|
5984
|
-
);
|
5985
|
-
}
|
5986
|
-
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5987
|
-
throw new import_errors17.FuelError(
|
5988
|
-
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5989
|
-
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5990
|
-
);
|
5991
|
-
}
|
5992
|
-
if (first && before) {
|
5993
|
-
throw new import_errors17.FuelError(
|
5994
|
-
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5995
|
-
'The use of pagination argument "first" with "before" is not supported'
|
5996
|
-
);
|
5997
|
-
}
|
5998
|
-
if (last && after) {
|
5999
|
-
throw new import_errors17.FuelError(
|
6000
|
-
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
6001
|
-
'The use of pagination argument "last" with "after" is not supported'
|
6002
|
-
);
|
6003
|
-
}
|
6004
|
-
if (!first && !last) {
|
6005
|
-
inputArgs.first = paginationLimit;
|
6006
|
-
}
|
6007
|
-
return inputArgs;
|
6008
|
-
}
|
6009
6066
|
/**
|
6010
6067
|
* @hidden
|
6011
6068
|
*/
|
@@ -6051,7 +6108,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
6051
6108
|
__publicField(Provider, "nodeInfoCache", {});
|
6052
6109
|
|
6053
6110
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
6054
|
-
var
|
6111
|
+
var import_errors19 = require("@fuel-ts/errors");
|
6055
6112
|
var import_math19 = require("@fuel-ts/math");
|
6056
6113
|
var import_transactions23 = require("@fuel-ts/transactions");
|
6057
6114
|
var import_utils31 = require("@fuel-ts/utils");
|
@@ -6061,8 +6118,8 @@ async function getTransactionSummary(params) {
|
|
6061
6118
|
transactionId: id
|
6062
6119
|
});
|
6063
6120
|
if (!gqlTransaction) {
|
6064
|
-
throw new
|
6065
|
-
|
6121
|
+
throw new import_errors19.FuelError(
|
6122
|
+
import_errors19.ErrorCode.TRANSACTION_NOT_FOUND,
|
6066
6123
|
`Transaction not found for given id: ${id}.`
|
6067
6124
|
);
|
6068
6125
|
}
|
@@ -6130,7 +6187,15 @@ async function getTransactionSummaryFromRequest(params) {
|
|
6130
6187
|
}
|
6131
6188
|
async function getTransactionsSummaries(params) {
|
6132
6189
|
const { filters, provider, abiMap } = params;
|
6133
|
-
const {
|
6190
|
+
const { owner, ...inputArgs } = filters;
|
6191
|
+
const validPaginationParams = validatePaginationArgs({
|
6192
|
+
inputArgs,
|
6193
|
+
paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
|
6194
|
+
});
|
6195
|
+
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner({
|
6196
|
+
...validPaginationParams,
|
6197
|
+
owner
|
6198
|
+
});
|
6134
6199
|
const { edges, pageInfo } = transactionsByOwner;
|
6135
6200
|
const {
|
6136
6201
|
consensusParameters: {
|
@@ -6850,37 +6915,46 @@ var mergeQuantities = (...coinQuantities) => {
|
|
6850
6915
|
|
6851
6916
|
// src/utils/formatTransferToContractScriptData.ts
|
6852
6917
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
6918
|
+
var import_address4 = require("@fuel-ts/address");
|
6853
6919
|
var import_math20 = require("@fuel-ts/math");
|
6854
6920
|
var import_utils33 = require("@fuel-ts/utils");
|
6855
6921
|
var asm = __toESM(require("@fuels/vm-asm"));
|
6856
|
-
var formatTransferToContractScriptData = (
|
6857
|
-
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
6922
|
+
var formatTransferToContractScriptData = (transferParams) => {
|
6858
6923
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
6859
|
-
|
6860
|
-
|
6861
|
-
|
6862
|
-
|
6863
|
-
|
6864
|
-
|
6865
|
-
|
6924
|
+
return transferParams.reduce((acc, transferParam) => {
|
6925
|
+
const { assetId, amount, contractId } = transferParam;
|
6926
|
+
const encoded = numberCoder.encode(new import_math20.BN(amount).toNumber());
|
6927
|
+
const scriptData = (0, import_utils33.concat)([
|
6928
|
+
import_address4.Address.fromAddressOrString(contractId).toBytes(),
|
6929
|
+
encoded,
|
6930
|
+
(0, import_utils33.arrayify)(assetId)
|
6931
|
+
]);
|
6932
|
+
return (0, import_utils33.concat)([acc, scriptData]);
|
6933
|
+
}, new Uint8Array());
|
6866
6934
|
};
|
6867
|
-
var assembleTransferToContractScript = async (
|
6868
|
-
const scriptData = formatTransferToContractScriptData(
|
6935
|
+
var assembleTransferToContractScript = async (transferParams) => {
|
6936
|
+
const scriptData = formatTransferToContractScriptData(transferParams);
|
6869
6937
|
await asm.initWasm();
|
6870
|
-
|
6871
|
-
|
6872
|
-
|
6873
|
-
|
6874
|
-
|
6875
|
-
|
6876
|
-
|
6877
|
-
|
6878
|
-
|
6879
|
-
|
6880
|
-
|
6881
|
-
|
6882
|
-
|
6883
|
-
|
6938
|
+
let script = new Uint8Array();
|
6939
|
+
transferParams.forEach((_, i) => {
|
6940
|
+
const offset = (import_abi_coder6.CONTRACT_ID_LEN + import_abi_coder6.WORD_SIZE + import_abi_coder6.ASSET_ID_LEN) * i;
|
6941
|
+
script = (0, import_utils33.concat)([
|
6942
|
+
script,
|
6943
|
+
// Load ScriptData into register 0x10.
|
6944
|
+
asm.gtf(16, 0, asm.GTFArgs.ScriptData).to_bytes(),
|
6945
|
+
// Add the offset to 0x10 so it will point to the current contract ID, store in 0x11.
|
6946
|
+
asm.addi(17, 16, offset).to_bytes(),
|
6947
|
+
// Add CONTRACT_ID_LEN to 0x11 to point to the amount in the ScriptData, store in 0x12.
|
6948
|
+
asm.addi(18, 17, import_abi_coder6.CONTRACT_ID_LEN).to_bytes(),
|
6949
|
+
// Load word to the amount at 0x12 into register 0x13.
|
6950
|
+
asm.lw(19, 18, 0).to_bytes(),
|
6951
|
+
// Add WORD_SIZE to 0x12 to point to the asset ID in the ScriptData, store in 0x14.
|
6952
|
+
asm.addi(20, 18, import_abi_coder6.WORD_SIZE).to_bytes(),
|
6953
|
+
// Perform the transfer using contract ID in 0x11, amount in 0x13, and asset ID in 0x14.
|
6954
|
+
asm.tr(17, 19, 20).to_bytes()
|
6955
|
+
]);
|
6956
|
+
});
|
6957
|
+
script = (0, import_utils33.concat)([script, asm.ret(1).to_bytes()]);
|
6884
6958
|
return { script, scriptData };
|
6885
6959
|
};
|
6886
6960
|
|
@@ -6910,7 +6984,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6910
6984
|
super();
|
6911
6985
|
this._provider = provider;
|
6912
6986
|
this._connector = connector;
|
6913
|
-
this.address =
|
6987
|
+
this.address = import_address5.Address.fromDynamicInput(address);
|
6914
6988
|
}
|
6915
6989
|
/**
|
6916
6990
|
* The provider used to interact with the network.
|
@@ -6921,7 +6995,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6921
6995
|
*/
|
6922
6996
|
get provider() {
|
6923
6997
|
if (!this._provider) {
|
6924
|
-
throw new
|
6998
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
6925
6999
|
}
|
6926
7000
|
return this._provider;
|
6927
7001
|
}
|
@@ -7072,8 +7146,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7072
7146
|
fundingAttempts += 1;
|
7073
7147
|
}
|
7074
7148
|
if (needsToBeFunded) {
|
7075
|
-
throw new
|
7076
|
-
|
7149
|
+
throw new import_errors20.FuelError(
|
7150
|
+
import_errors20.ErrorCode.NOT_ENOUGH_FUNDS,
|
7077
7151
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
7078
7152
|
);
|
7079
7153
|
}
|
@@ -7144,7 +7218,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7144
7218
|
const { destination, amount, assetId } = transferParams;
|
7145
7219
|
this.validateTransferAmount(amount);
|
7146
7220
|
request.addCoinOutput(
|
7147
|
-
|
7221
|
+
import_address5.Address.fromAddressOrString(destination),
|
7148
7222
|
amount,
|
7149
7223
|
assetId ?? this.provider.getBaseAssetId()
|
7150
7224
|
);
|
@@ -7178,35 +7252,35 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7178
7252
|
* @returns A promise that resolves to the transaction response.
|
7179
7253
|
*/
|
7180
7254
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
7181
|
-
|
7182
|
-
|
7183
|
-
|
7184
|
-
"Transfer amount must be a positive number."
|
7185
|
-
);
|
7186
|
-
}
|
7187
|
-
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
7188
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
7189
|
-
const { script, scriptData } = await assembleTransferToContractScript({
|
7190
|
-
hexlifiedContractId: contractAddress.toB256(),
|
7191
|
-
amountToTransfer: (0, import_math21.bn)(amount),
|
7192
|
-
assetId: assetIdToTransfer
|
7193
|
-
});
|
7255
|
+
return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams);
|
7256
|
+
}
|
7257
|
+
async batchTransferToContracts(contractTransferParams, txParams = {}) {
|
7194
7258
|
let request = new ScriptTransactionRequest({
|
7195
|
-
...txParams
|
7196
|
-
script,
|
7197
|
-
scriptData
|
7198
|
-
});
|
7199
|
-
request.addContractInputAndOutput(contractAddress);
|
7200
|
-
const txCost = await this.getTransactionCost(request, {
|
7201
|
-
quantities: [{ amount: (0, import_math21.bn)(amount), assetId: String(assetIdToTransfer) }]
|
7259
|
+
...txParams
|
7202
7260
|
});
|
7203
|
-
|
7204
|
-
|
7205
|
-
|
7206
|
-
|
7207
|
-
|
7261
|
+
const quantities = [];
|
7262
|
+
const transferParams = contractTransferParams.map((transferParam) => {
|
7263
|
+
const amount = (0, import_math21.bn)(transferParam.amount);
|
7264
|
+
const contractAddress = import_address5.Address.fromAddressOrString(transferParam.contractId);
|
7265
|
+
const assetId = transferParam.assetId ? (0, import_utils34.hexlify)(transferParam.assetId) : this.provider.getBaseAssetId();
|
7266
|
+
if (amount.lte(0)) {
|
7267
|
+
throw new import_errors20.FuelError(
|
7268
|
+
import_errors20.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7269
|
+
"Transfer amount must be a positive number."
|
7270
|
+
);
|
7271
|
+
}
|
7272
|
+
request.addContractInputAndOutput(contractAddress);
|
7273
|
+
quantities.push({ amount, assetId });
|
7274
|
+
return {
|
7275
|
+
amount,
|
7276
|
+
contractId: contractAddress.toB256(),
|
7277
|
+
assetId
|
7278
|
+
};
|
7208
7279
|
});
|
7209
|
-
await
|
7280
|
+
const { script, scriptData } = await assembleTransferToContractScript(transferParams);
|
7281
|
+
request.script = script;
|
7282
|
+
request.scriptData = scriptData;
|
7283
|
+
request = await this.estimateAndFundTransaction(request, txParams, { quantities });
|
7210
7284
|
return this.sendTransaction(request);
|
7211
7285
|
}
|
7212
7286
|
/**
|
@@ -7218,7 +7292,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7218
7292
|
* @returns A promise that resolves to the transaction response.
|
7219
7293
|
*/
|
7220
7294
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
7221
|
-
const recipientAddress =
|
7295
|
+
const recipientAddress = import_address5.Address.fromAddressOrString(recipient);
|
7222
7296
|
const recipientDataArray = (0, import_utils34.arrayify)(
|
7223
7297
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
7224
7298
|
);
|
@@ -7306,7 +7380,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7306
7380
|
*/
|
7307
7381
|
async signMessage(message) {
|
7308
7382
|
if (!this._connector) {
|
7309
|
-
throw new
|
7383
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
7310
7384
|
}
|
7311
7385
|
return this._connector.signMessage(this.address.toString(), message);
|
7312
7386
|
}
|
@@ -7318,8 +7392,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7318
7392
|
*/
|
7319
7393
|
async signTransaction(transactionRequestLike) {
|
7320
7394
|
if (!this._connector) {
|
7321
|
-
throw new
|
7322
|
-
|
7395
|
+
throw new import_errors20.FuelError(
|
7396
|
+
import_errors20.ErrorCode.MISSING_CONNECTOR,
|
7323
7397
|
"A connector is required to sign transactions."
|
7324
7398
|
);
|
7325
7399
|
}
|
@@ -7378,16 +7452,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7378
7452
|
/** @hidden * */
|
7379
7453
|
validateTransferAmount(amount) {
|
7380
7454
|
if ((0, import_math21.bn)(amount).lte(0)) {
|
7381
|
-
throw new
|
7382
|
-
|
7455
|
+
throw new import_errors20.FuelError(
|
7456
|
+
import_errors20.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7383
7457
|
"Transfer amount must be a positive number."
|
7384
7458
|
);
|
7385
7459
|
}
|
7386
7460
|
}
|
7387
7461
|
/** @hidden * */
|
7388
|
-
async estimateAndFundTransaction(transactionRequest, txParams) {
|
7462
|
+
async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
|
7389
7463
|
let request = transactionRequest;
|
7390
|
-
const txCost = await this.getTransactionCost(request);
|
7464
|
+
const txCost = await this.getTransactionCost(request, costParams);
|
7391
7465
|
request = this.validateGasLimitAndMaxFee({
|
7392
7466
|
transactionRequest: request,
|
7393
7467
|
gasUsed: txCost.gasUsed,
|
@@ -7408,16 +7482,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7408
7482
|
if (!(0, import_utils34.isDefined)(setGasLimit)) {
|
7409
7483
|
request.gasLimit = gasUsed;
|
7410
7484
|
} else if (gasUsed.gt(setGasLimit)) {
|
7411
|
-
throw new
|
7412
|
-
|
7485
|
+
throw new import_errors20.FuelError(
|
7486
|
+
import_errors20.ErrorCode.GAS_LIMIT_TOO_LOW,
|
7413
7487
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
7414
7488
|
);
|
7415
7489
|
}
|
7416
7490
|
if (!(0, import_utils34.isDefined)(setMaxFee)) {
|
7417
7491
|
request.maxFee = maxFee;
|
7418
7492
|
} else if (maxFee.gt(setMaxFee)) {
|
7419
|
-
throw new
|
7420
|
-
|
7493
|
+
throw new import_errors20.FuelError(
|
7494
|
+
import_errors20.ErrorCode.MAX_FEE_TOO_LOW,
|
7421
7495
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
7422
7496
|
);
|
7423
7497
|
}
|
@@ -7430,7 +7504,7 @@ var import_hasher4 = require("@fuel-ts/hasher");
|
|
7430
7504
|
var import_utils37 = require("@fuel-ts/utils");
|
7431
7505
|
|
7432
7506
|
// src/signer/signer.ts
|
7433
|
-
var
|
7507
|
+
var import_address6 = require("@fuel-ts/address");
|
7434
7508
|
var import_crypto3 = require("@fuel-ts/crypto");
|
7435
7509
|
var import_hasher3 = require("@fuel-ts/hasher");
|
7436
7510
|
var import_math22 = require("@fuel-ts/math");
|
@@ -7457,7 +7531,7 @@ var Signer = class {
|
|
7457
7531
|
this.privateKey = (0, import_utils35.hexlify)(privateKeyBytes);
|
7458
7532
|
this.publicKey = (0, import_utils35.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
7459
7533
|
this.compressedPublicKey = (0, import_utils35.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
7460
|
-
this.address =
|
7534
|
+
this.address = import_address6.Address.fromPublicKey(this.publicKey);
|
7461
7535
|
}
|
7462
7536
|
/**
|
7463
7537
|
* Sign data using the Signer instance
|
@@ -7515,7 +7589,7 @@ var Signer = class {
|
|
7515
7589
|
* @returns Address from signature
|
7516
7590
|
*/
|
7517
7591
|
static recoverAddress(data, signature) {
|
7518
|
-
return
|
7592
|
+
return import_address6.Address.fromPublicKey(Signer.recoverPublicKey(data, signature));
|
7519
7593
|
}
|
7520
7594
|
/**
|
7521
7595
|
* Generate a random privateKey
|
@@ -7539,9 +7613,9 @@ var Signer = class {
|
|
7539
7613
|
};
|
7540
7614
|
|
7541
7615
|
// src/wallet/keystore-wallet.ts
|
7542
|
-
var
|
7616
|
+
var import_address7 = require("@fuel-ts/address");
|
7543
7617
|
var import_crypto4 = require("@fuel-ts/crypto");
|
7544
|
-
var
|
7618
|
+
var import_errors21 = require("@fuel-ts/errors");
|
7545
7619
|
var import_utils36 = require("@fuel-ts/utils");
|
7546
7620
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
7547
7621
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -7556,7 +7630,7 @@ var removeHexPrefix = (hexString) => {
|
|
7556
7630
|
};
|
7557
7631
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
7558
7632
|
const privateKeyBuffer = (0, import_crypto4.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
7559
|
-
const ownerAddress =
|
7633
|
+
const ownerAddress = import_address7.Address.fromAddressOrString(address);
|
7560
7634
|
const salt = (0, import_crypto4.randomBytes)(DEFAULT_KEY_SIZE);
|
7561
7635
|
const key = (0, import_crypto4.scrypt)({
|
7562
7636
|
password: (0, import_crypto4.bufferFromString)(password),
|
@@ -7618,8 +7692,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7618
7692
|
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
7619
7693
|
const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
7620
7694
|
if (mac !== macHash) {
|
7621
|
-
throw new
|
7622
|
-
|
7695
|
+
throw new import_errors21.FuelError(
|
7696
|
+
import_errors21.ErrorCode.INVALID_PASSWORD,
|
7623
7697
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
7624
7698
|
);
|
7625
7699
|
}
|
@@ -7749,14 +7823,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
7749
7823
|
|
7750
7824
|
// src/hdwallet/hdwallet.ts
|
7751
7825
|
var import_crypto6 = require("@fuel-ts/crypto");
|
7752
|
-
var
|
7826
|
+
var import_errors24 = require("@fuel-ts/errors");
|
7753
7827
|
var import_hasher7 = require("@fuel-ts/hasher");
|
7754
7828
|
var import_math23 = require("@fuel-ts/math");
|
7755
7829
|
var import_utils41 = require("@fuel-ts/utils");
|
7756
7830
|
|
7757
7831
|
// src/mnemonic/mnemonic.ts
|
7758
7832
|
var import_crypto5 = require("@fuel-ts/crypto");
|
7759
|
-
var
|
7833
|
+
var import_errors23 = require("@fuel-ts/errors");
|
7760
7834
|
var import_hasher6 = require("@fuel-ts/hasher");
|
7761
7835
|
var import_utils39 = require("@fuel-ts/utils");
|
7762
7836
|
|
@@ -9819,7 +9893,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
9819
9893
|
})(Language || {});
|
9820
9894
|
|
9821
9895
|
// src/mnemonic/utils.ts
|
9822
|
-
var
|
9896
|
+
var import_errors22 = require("@fuel-ts/errors");
|
9823
9897
|
var import_hasher5 = require("@fuel-ts/hasher");
|
9824
9898
|
var import_utils38 = require("@fuel-ts/utils");
|
9825
9899
|
function getLowerMask(bits) {
|
@@ -9868,8 +9942,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9868
9942
|
for (let i = 0; i < words.length; i += 1) {
|
9869
9943
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
9870
9944
|
if (index === -1) {
|
9871
|
-
throw new
|
9872
|
-
|
9945
|
+
throw new import_errors22.FuelError(
|
9946
|
+
import_errors22.ErrorCode.INVALID_MNEMONIC,
|
9873
9947
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
9874
9948
|
);
|
9875
9949
|
}
|
@@ -9885,8 +9959,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9885
9959
|
const checksumMask = getUpperMask(checksumBits);
|
9886
9960
|
const checksum = (0, import_utils38.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
9887
9961
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
9888
|
-
throw new
|
9889
|
-
|
9962
|
+
throw new import_errors22.FuelError(
|
9963
|
+
import_errors22.ErrorCode.INVALID_CHECKSUM,
|
9890
9964
|
"Checksum validation failed for the provided mnemonic."
|
9891
9965
|
);
|
9892
9966
|
}
|
@@ -9900,16 +9974,16 @@ var TestnetPRV = "0x04358394";
|
|
9900
9974
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
9901
9975
|
function assertWordList(wordlist) {
|
9902
9976
|
if (wordlist.length !== 2048) {
|
9903
|
-
throw new
|
9904
|
-
|
9977
|
+
throw new import_errors23.FuelError(
|
9978
|
+
import_errors23.ErrorCode.INVALID_WORD_LIST,
|
9905
9979
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
9906
9980
|
);
|
9907
9981
|
}
|
9908
9982
|
}
|
9909
9983
|
function assertEntropy(entropy) {
|
9910
9984
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
9911
|
-
throw new
|
9912
|
-
|
9985
|
+
throw new import_errors23.FuelError(
|
9986
|
+
import_errors23.ErrorCode.INVALID_ENTROPY,
|
9913
9987
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
9914
9988
|
);
|
9915
9989
|
}
|
@@ -9919,7 +9993,7 @@ function assertMnemonic(words) {
|
|
9919
9993
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
9920
9994
|
", "
|
9921
9995
|
)}] words, but got ${words.length}.`;
|
9922
|
-
throw new
|
9996
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
9923
9997
|
}
|
9924
9998
|
}
|
9925
9999
|
var Mnemonic = class {
|
@@ -10037,8 +10111,8 @@ var Mnemonic = class {
|
|
10037
10111
|
static masterKeysFromSeed(seed) {
|
10038
10112
|
const seedArray = (0, import_utils39.arrayify)(seed);
|
10039
10113
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
10040
|
-
throw new
|
10041
|
-
|
10114
|
+
throw new import_errors23.FuelError(
|
10115
|
+
import_errors23.ErrorCode.INVALID_SEED,
|
10042
10116
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
10043
10117
|
);
|
10044
10118
|
}
|
@@ -10115,7 +10189,7 @@ function isValidExtendedKey(extendedKey) {
|
|
10115
10189
|
function parsePath(path, depth = 0) {
|
10116
10190
|
const components = path.split("/");
|
10117
10191
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
10118
|
-
throw new
|
10192
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
|
10119
10193
|
}
|
10120
10194
|
if (components[0] === "m") {
|
10121
10195
|
components.shift();
|
@@ -10144,8 +10218,8 @@ var HDWallet = class {
|
|
10144
10218
|
this.privateKey = (0, import_utils41.hexlify)(config.privateKey);
|
10145
10219
|
} else {
|
10146
10220
|
if (!config.publicKey) {
|
10147
|
-
throw new
|
10148
|
-
|
10221
|
+
throw new import_errors24.FuelError(
|
10222
|
+
import_errors24.ErrorCode.HD_WALLET_ERROR,
|
10149
10223
|
"Both public and private Key cannot be missing. At least one should be provided."
|
10150
10224
|
);
|
10151
10225
|
}
|
@@ -10174,8 +10248,8 @@ var HDWallet = class {
|
|
10174
10248
|
const data = new Uint8Array(37);
|
10175
10249
|
if (index & HARDENED_INDEX) {
|
10176
10250
|
if (!privateKey) {
|
10177
|
-
throw new
|
10178
|
-
|
10251
|
+
throw new import_errors24.FuelError(
|
10252
|
+
import_errors24.ErrorCode.HD_WALLET_ERROR,
|
10179
10253
|
"Cannot derive a hardened index without a private Key."
|
10180
10254
|
);
|
10181
10255
|
}
|
@@ -10227,8 +10301,8 @@ var HDWallet = class {
|
|
10227
10301
|
*/
|
10228
10302
|
toExtendedKey(isPublic = false, testnet = false) {
|
10229
10303
|
if (this.depth >= 256) {
|
10230
|
-
throw new
|
10231
|
-
|
10304
|
+
throw new import_errors24.FuelError(
|
10305
|
+
import_errors24.ErrorCode.HD_WALLET_ERROR,
|
10232
10306
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
10233
10307
|
);
|
10234
10308
|
}
|
@@ -10259,10 +10333,10 @@ var HDWallet = class {
|
|
10259
10333
|
const bytes = (0, import_utils41.arrayify)(decoded);
|
10260
10334
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
10261
10335
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
10262
|
-
throw new
|
10336
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
10263
10337
|
}
|
10264
10338
|
if (!validChecksum) {
|
10265
|
-
throw new
|
10339
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
10266
10340
|
}
|
10267
10341
|
const depth = bytes[4];
|
10268
10342
|
const parentFingerprint = (0, import_utils41.hexlify)(bytes.slice(5, 9));
|
@@ -10270,14 +10344,14 @@ var HDWallet = class {
|
|
10270
10344
|
const chainCode = (0, import_utils41.hexlify)(bytes.slice(13, 45));
|
10271
10345
|
const key = bytes.slice(45, 78);
|
10272
10346
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
10273
|
-
throw new
|
10274
|
-
|
10347
|
+
throw new import_errors24.FuelError(
|
10348
|
+
import_errors24.ErrorCode.HD_WALLET_ERROR,
|
10275
10349
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
10276
10350
|
);
|
10277
10351
|
}
|
10278
10352
|
if (isPublicExtendedKey(bytes)) {
|
10279
10353
|
if (key[0] !== 3) {
|
10280
|
-
throw new
|
10354
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
10281
10355
|
}
|
10282
10356
|
return new HDWallet({
|
10283
10357
|
publicKey: key,
|
@@ -10288,7 +10362,7 @@ var HDWallet = class {
|
|
10288
10362
|
});
|
10289
10363
|
}
|
10290
10364
|
if (key[0] !== 0) {
|
10291
|
-
throw new
|
10365
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
10292
10366
|
}
|
10293
10367
|
return new HDWallet({
|
10294
10368
|
privateKey: key.slice(1),
|
@@ -10454,9 +10528,9 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
10454
10528
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
10455
10529
|
|
10456
10530
|
// src/wallet-manager/wallet-manager.ts
|
10457
|
-
var
|
10531
|
+
var import_address10 = require("@fuel-ts/address");
|
10458
10532
|
var import_crypto7 = require("@fuel-ts/crypto");
|
10459
|
-
var
|
10533
|
+
var import_errors27 = require("@fuel-ts/errors");
|
10460
10534
|
var import_events = require("events");
|
10461
10535
|
|
10462
10536
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -10478,8 +10552,8 @@ var MemoryStorage = class {
|
|
10478
10552
|
};
|
10479
10553
|
|
10480
10554
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
10481
|
-
var
|
10482
|
-
var
|
10555
|
+
var import_address8 = require("@fuel-ts/address");
|
10556
|
+
var import_errors25 = require("@fuel-ts/errors");
|
10483
10557
|
var _secret;
|
10484
10558
|
var MnemonicVault = class {
|
10485
10559
|
constructor(options) {
|
@@ -10527,7 +10601,7 @@ var MnemonicVault = class {
|
|
10527
10601
|
}
|
10528
10602
|
exportAccount(address) {
|
10529
10603
|
let numberOfAccounts = 0;
|
10530
|
-
const ownerAddress =
|
10604
|
+
const ownerAddress = import_address8.Address.fromAddressOrString(address);
|
10531
10605
|
do {
|
10532
10606
|
const wallet = Wallet.fromMnemonic(__privateGet(this, _secret), this.getDerivePath(numberOfAccounts));
|
10533
10607
|
if (wallet.address.equals(ownerAddress)) {
|
@@ -10535,8 +10609,8 @@ var MnemonicVault = class {
|
|
10535
10609
|
}
|
10536
10610
|
numberOfAccounts += 1;
|
10537
10611
|
} while (numberOfAccounts < this.numberOfAccounts);
|
10538
|
-
throw new
|
10539
|
-
|
10612
|
+
throw new import_errors25.FuelError(
|
10613
|
+
import_errors25.ErrorCode.WALLET_MANAGER_ERROR,
|
10540
10614
|
`Account with address '${address}' not found in derived wallets.`
|
10541
10615
|
);
|
10542
10616
|
}
|
@@ -10549,8 +10623,8 @@ _secret = new WeakMap();
|
|
10549
10623
|
__publicField(MnemonicVault, "type", "mnemonic");
|
10550
10624
|
|
10551
10625
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
10552
|
-
var
|
10553
|
-
var
|
10626
|
+
var import_address9 = require("@fuel-ts/address");
|
10627
|
+
var import_errors26 = require("@fuel-ts/errors");
|
10554
10628
|
var _privateKeys;
|
10555
10629
|
var PrivateKeyVault = class {
|
10556
10630
|
/**
|
@@ -10586,13 +10660,13 @@ var PrivateKeyVault = class {
|
|
10586
10660
|
return this.getPublicAccount(wallet.privateKey);
|
10587
10661
|
}
|
10588
10662
|
exportAccount(address) {
|
10589
|
-
const ownerAddress =
|
10663
|
+
const ownerAddress = import_address9.Address.fromAddressOrString(address);
|
10590
10664
|
const privateKey = __privateGet(this, _privateKeys).find(
|
10591
10665
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
10592
10666
|
);
|
10593
10667
|
if (!privateKey) {
|
10594
|
-
throw new
|
10595
|
-
|
10668
|
+
throw new import_errors26.FuelError(
|
10669
|
+
import_errors26.ErrorCode.WALLET_MANAGER_ERROR,
|
10596
10670
|
`No private key found for address '${address}'.`
|
10597
10671
|
);
|
10598
10672
|
}
|
@@ -10616,7 +10690,7 @@ var ERROR_MESSAGES = {
|
|
10616
10690
|
};
|
10617
10691
|
function assert(condition, message) {
|
10618
10692
|
if (!condition) {
|
10619
|
-
throw new
|
10693
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.WALLET_MANAGER_ERROR, message);
|
10620
10694
|
}
|
10621
10695
|
}
|
10622
10696
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -10684,7 +10758,7 @@ var _WalletManager = class extends import_events.EventEmitter {
|
|
10684
10758
|
* Create a Wallet instance for the specific account
|
10685
10759
|
*/
|
10686
10760
|
getWallet(address) {
|
10687
|
-
const ownerAddress =
|
10761
|
+
const ownerAddress = import_address10.Address.fromAddressOrString(address);
|
10688
10762
|
const vaultState = __privateGet(this, _vaults).find(
|
10689
10763
|
(vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
|
10690
10764
|
);
|
@@ -10695,7 +10769,7 @@ var _WalletManager = class extends import_events.EventEmitter {
|
|
10695
10769
|
* Export specific account privateKey
|
10696
10770
|
*/
|
10697
10771
|
exportPrivateKey(address) {
|
10698
|
-
const ownerAddress =
|
10772
|
+
const ownerAddress = import_address10.Address.fromAddressOrString(address);
|
10699
10773
|
assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
|
10700
10774
|
const vaultState = __privateGet(this, _vaults).find(
|
10701
10775
|
(vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
|
@@ -10842,25 +10916,25 @@ deserializeVaults_fn = function(vaults) {
|
|
10842
10916
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
10843
10917
|
|
10844
10918
|
// src/wallet-manager/types.ts
|
10845
|
-
var
|
10919
|
+
var import_errors28 = require("@fuel-ts/errors");
|
10846
10920
|
var Vault = class {
|
10847
10921
|
constructor(_options) {
|
10848
|
-
throw new
|
10922
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
10849
10923
|
}
|
10850
10924
|
serialize() {
|
10851
|
-
throw new
|
10925
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
10852
10926
|
}
|
10853
10927
|
getAccounts() {
|
10854
|
-
throw new
|
10928
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
10855
10929
|
}
|
10856
10930
|
addAccount() {
|
10857
|
-
throw new
|
10931
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
10858
10932
|
}
|
10859
10933
|
exportAccount(_address) {
|
10860
|
-
throw new
|
10934
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
10861
10935
|
}
|
10862
10936
|
getWallet(_address) {
|
10863
|
-
throw new
|
10937
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
10864
10938
|
}
|
10865
10939
|
};
|
10866
10940
|
__publicField(Vault, "type");
|
@@ -10869,35 +10943,237 @@ var StorageAbstract = class {
|
|
10869
10943
|
|
10870
10944
|
// src/predicate/predicate.ts
|
10871
10945
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
10872
|
-
var
|
10873
|
-
var
|
10946
|
+
var import_address11 = require("@fuel-ts/address");
|
10947
|
+
var import_errors30 = require("@fuel-ts/errors");
|
10948
|
+
var import_utils45 = require("@fuel-ts/utils");
|
10949
|
+
|
10950
|
+
// src/utils/deployScriptOrPredicate.ts
|
10951
|
+
var import_errors29 = require("@fuel-ts/errors");
|
10952
|
+
var import_hasher8 = require("@fuel-ts/hasher");
|
10953
|
+
var import_math24 = require("@fuel-ts/math");
|
10874
10954
|
var import_utils43 = require("@fuel-ts/utils");
|
10875
10955
|
|
10956
|
+
// src/utils/predicate-script-loader-instructions.ts
|
10957
|
+
var import_utils42 = require("@fuel-ts/utils");
|
10958
|
+
var asm2 = __toESM(require("@fuels/vm-asm"));
|
10959
|
+
var BLOB_ID_SIZE = 32;
|
10960
|
+
var REG_ADDRESS_OF_DATA_AFTER_CODE = 16;
|
10961
|
+
var REG_START_OF_LOADED_CODE = 17;
|
10962
|
+
var REG_GENERAL_USE = 18;
|
10963
|
+
var WORD_SIZE2 = 8;
|
10964
|
+
function getDataOffset(binary) {
|
10965
|
+
const OFFSET_INDEX = 8;
|
10966
|
+
const dataView = new DataView(binary.buffer, OFFSET_INDEX, 8);
|
10967
|
+
const dataOffset = dataView.getBigUint64(0, false);
|
10968
|
+
return Number(dataOffset);
|
10969
|
+
}
|
10970
|
+
function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
10971
|
+
const { RegId, Instruction } = asm2;
|
10972
|
+
const REG_PC = RegId.pc().to_u8();
|
10973
|
+
const REG_SP = RegId.sp().to_u8();
|
10974
|
+
const REG_IS = RegId.is().to_u8();
|
10975
|
+
const getInstructions = (numOfInstructions2) => [
|
10976
|
+
// 1. Load the blob content into memory
|
10977
|
+
// Find the start of the hardcoded blob ID, which is located after the loader code ends.
|
10978
|
+
asm2.move_(REG_ADDRESS_OF_DATA_AFTER_CODE, REG_PC),
|
10979
|
+
// hold the address of the blob ID.
|
10980
|
+
asm2.addi(
|
10981
|
+
REG_ADDRESS_OF_DATA_AFTER_CODE,
|
10982
|
+
REG_ADDRESS_OF_DATA_AFTER_CODE,
|
10983
|
+
numOfInstructions2 * Instruction.size()
|
10984
|
+
),
|
10985
|
+
// The code is going to be loaded from the current value of SP onwards, save
|
10986
|
+
// the location into REG_START_OF_LOADED_CODE so we can jump into it at the end.
|
10987
|
+
asm2.move_(REG_START_OF_LOADED_CODE, REG_SP),
|
10988
|
+
// REG_GENERAL_USE to hold the size of the blob.
|
10989
|
+
asm2.bsiz(REG_GENERAL_USE, REG_ADDRESS_OF_DATA_AFTER_CODE),
|
10990
|
+
// Push the blob contents onto the stack.
|
10991
|
+
asm2.ldc(REG_ADDRESS_OF_DATA_AFTER_CODE, 0, REG_GENERAL_USE, 1),
|
10992
|
+
// Move on to the data section length
|
10993
|
+
asm2.addi(REG_ADDRESS_OF_DATA_AFTER_CODE, REG_ADDRESS_OF_DATA_AFTER_CODE, BLOB_ID_SIZE),
|
10994
|
+
// load the size of the data section into REG_GENERAL_USE
|
10995
|
+
asm2.lw(REG_GENERAL_USE, REG_ADDRESS_OF_DATA_AFTER_CODE, 0),
|
10996
|
+
// after we have read the length of the data section, we move the pointer to the actual
|
10997
|
+
// data by skipping WORD_SIZE bytes.
|
10998
|
+
asm2.addi(REG_ADDRESS_OF_DATA_AFTER_CODE, REG_ADDRESS_OF_DATA_AFTER_CODE, WORD_SIZE2),
|
10999
|
+
// load the data section of the executable
|
11000
|
+
asm2.ldc(REG_ADDRESS_OF_DATA_AFTER_CODE, 0, REG_GENERAL_USE, 2),
|
11001
|
+
// Jump into the memory where the contract is loaded.
|
11002
|
+
// What follows is called _jmp_mem by the sway compiler.
|
11003
|
+
// Subtract the address contained in IS because jmp will add it back.
|
11004
|
+
asm2.sub(REG_START_OF_LOADED_CODE, REG_START_OF_LOADED_CODE, REG_IS),
|
11005
|
+
// jmp will multiply by 4, so we need to divide to cancel that out.
|
11006
|
+
asm2.divi(REG_START_OF_LOADED_CODE, REG_START_OF_LOADED_CODE, 4),
|
11007
|
+
// Jump to the start of the contract we loaded.
|
11008
|
+
asm2.jmp(REG_START_OF_LOADED_CODE)
|
11009
|
+
];
|
11010
|
+
const getInstructionsNoDataSection = (numOfInstructions2) => [
|
11011
|
+
// 1. Load the blob content into memory
|
11012
|
+
// Find the start of the hardcoded blob ID, which is located after the loader code ends.
|
11013
|
+
// 1. Load the blob content into memory
|
11014
|
+
// Find the start of the hardcoded blob ID, which is located after the loader code ends.
|
11015
|
+
asm2.move_(REG_ADDRESS_OF_DATA_AFTER_CODE, REG_PC),
|
11016
|
+
// hold the address of the blob ID.
|
11017
|
+
asm2.addi(
|
11018
|
+
REG_ADDRESS_OF_DATA_AFTER_CODE,
|
11019
|
+
REG_ADDRESS_OF_DATA_AFTER_CODE,
|
11020
|
+
numOfInstructions2 * Instruction.size()
|
11021
|
+
),
|
11022
|
+
// The code is going to be loaded from the current value of SP onwards, save
|
11023
|
+
// the location into REG_START_OF_LOADED_CODE so we can jump into it at the end.
|
11024
|
+
asm2.move_(REG_START_OF_LOADED_CODE, REG_SP),
|
11025
|
+
// REG_GENERAL_USE to hold the size of the blob.
|
11026
|
+
asm2.bsiz(REG_GENERAL_USE, REG_ADDRESS_OF_DATA_AFTER_CODE),
|
11027
|
+
// Push the blob contents onto the stack.
|
11028
|
+
asm2.ldc(REG_ADDRESS_OF_DATA_AFTER_CODE, 0, REG_GENERAL_USE, 1),
|
11029
|
+
// Jump into the memory where the contract is loaded.
|
11030
|
+
// What follows is called _jmp_mem by the sway compiler.
|
11031
|
+
// Subtract the address contained in IS because jmp will add it back.
|
11032
|
+
asm2.sub(REG_START_OF_LOADED_CODE, REG_START_OF_LOADED_CODE, REG_IS),
|
11033
|
+
// jmp will multiply by 4, so we need to divide to cancel that out.
|
11034
|
+
asm2.divi(REG_START_OF_LOADED_CODE, REG_START_OF_LOADED_CODE, 4),
|
11035
|
+
// Jump to the start of the contract we loaded.
|
11036
|
+
asm2.jmp(REG_START_OF_LOADED_CODE)
|
11037
|
+
];
|
11038
|
+
const offset = getDataOffset(originalBinary);
|
11039
|
+
if (originalBinary.length < offset) {
|
11040
|
+
throw new Error(
|
11041
|
+
`Data section offset is out of bounds, offset: ${offset}, binary length: ${originalBinary.length}`
|
11042
|
+
);
|
11043
|
+
}
|
11044
|
+
const dataSection = originalBinary.slice(offset);
|
11045
|
+
if (dataSection.length > 0) {
|
11046
|
+
const numOfInstructions2 = getInstructions(0).length;
|
11047
|
+
if (numOfInstructions2 > 65535) {
|
11048
|
+
throw new Error("Too many instructions, exceeding u16::MAX.");
|
11049
|
+
}
|
11050
|
+
const instructionBytes2 = new Uint8Array(
|
11051
|
+
getInstructions(numOfInstructions2).flatMap(
|
11052
|
+
(instruction) => Array.from(instruction.to_bytes())
|
11053
|
+
)
|
11054
|
+
);
|
11055
|
+
const blobBytes2 = new Uint8Array(blobId);
|
11056
|
+
const dataSectionLenBytes = new Uint8Array(8);
|
11057
|
+
const dataView = new DataView(dataSectionLenBytes.buffer);
|
11058
|
+
dataView.setBigUint64(0, BigInt(dataSection.length), false);
|
11059
|
+
const loaderBytecode2 = new Uint8Array([
|
11060
|
+
...instructionBytes2,
|
11061
|
+
...blobBytes2,
|
11062
|
+
...dataSectionLenBytes
|
11063
|
+
]);
|
11064
|
+
return {
|
11065
|
+
loaderBytecode: (0, import_utils42.concat)([loaderBytecode2, dataSection]),
|
11066
|
+
blobOffset: loaderBytecode2.length
|
11067
|
+
};
|
11068
|
+
}
|
11069
|
+
const numOfInstructions = getInstructionsNoDataSection(0).length;
|
11070
|
+
if (numOfInstructions > 65535) {
|
11071
|
+
throw new Error("Too many instructions, exceeding u16::MAX.");
|
11072
|
+
}
|
11073
|
+
const instructionBytes = new Uint8Array(
|
11074
|
+
getInstructionsNoDataSection(numOfInstructions).flatMap(
|
11075
|
+
(instruction) => Array.from(instruction.to_bytes())
|
11076
|
+
)
|
11077
|
+
);
|
11078
|
+
const blobBytes = new Uint8Array(blobId);
|
11079
|
+
const loaderBytecode = new Uint8Array([...instructionBytes, ...blobBytes]);
|
11080
|
+
return { loaderBytecode };
|
11081
|
+
}
|
11082
|
+
|
11083
|
+
// src/utils/deployScriptOrPredicate.ts
|
11084
|
+
async function fundBlobTx(deployer, blobTxRequest) {
|
11085
|
+
let totalCost = (0, import_math24.bn)(0);
|
11086
|
+
const chainInfo = deployer.provider.getChain();
|
11087
|
+
const gasPrice = await deployer.provider.estimateGasPrice(10);
|
11088
|
+
const priceFactor = chainInfo.consensusParameters.feeParameters.gasPriceFactor;
|
11089
|
+
const minGas = blobTxRequest.calculateMinGas(chainInfo);
|
11090
|
+
const minFee = calculateGasFee({
|
11091
|
+
gasPrice,
|
11092
|
+
gas: minGas,
|
11093
|
+
priceFactor,
|
11094
|
+
tip: blobTxRequest.tip
|
11095
|
+
}).add(1);
|
11096
|
+
totalCost = totalCost.add(minFee);
|
11097
|
+
if (totalCost.gt(await deployer.getBalance())) {
|
11098
|
+
throw new import_errors29.FuelError(import_errors29.ErrorCode.FUNDS_TOO_LOW, "Insufficient balance to deploy predicate.");
|
11099
|
+
}
|
11100
|
+
const txCost = await deployer.getTransactionCost(blobTxRequest);
|
11101
|
+
blobTxRequest.maxFee = txCost.maxFee;
|
11102
|
+
return deployer.fund(blobTxRequest, txCost);
|
11103
|
+
}
|
11104
|
+
function adjustConfigurableOffsets(jsonAbi, configurableOffsetDiff) {
|
11105
|
+
const { configurables: readOnlyConfigurables } = jsonAbi;
|
11106
|
+
const configurables = [];
|
11107
|
+
readOnlyConfigurables.forEach((config) => {
|
11108
|
+
configurables.push({ ...config, offset: config.offset - configurableOffsetDiff });
|
11109
|
+
});
|
11110
|
+
return { ...jsonAbi, configurables };
|
11111
|
+
}
|
11112
|
+
async function deployScriptOrPredicate({
|
11113
|
+
deployer,
|
11114
|
+
bytecode,
|
11115
|
+
abi,
|
11116
|
+
loaderInstanceCallback
|
11117
|
+
}) {
|
11118
|
+
const dataSectionOffset = getDataOffset((0, import_utils43.arrayify)(bytecode));
|
11119
|
+
const byteCodeWithoutDataSection = bytecode.slice(0, dataSectionOffset);
|
11120
|
+
const blobId = (0, import_hasher8.hash)(byteCodeWithoutDataSection);
|
11121
|
+
const blobTxRequest = new BlobTransactionRequest({
|
11122
|
+
blobId,
|
11123
|
+
witnessIndex: 0,
|
11124
|
+
witnesses: [byteCodeWithoutDataSection]
|
11125
|
+
});
|
11126
|
+
const { loaderBytecode, blobOffset } = getPredicateScriptLoaderInstructions(
|
11127
|
+
(0, import_utils43.arrayify)(bytecode),
|
11128
|
+
(0, import_utils43.arrayify)(blobId)
|
11129
|
+
);
|
11130
|
+
const configurableOffsetDiff = byteCodeWithoutDataSection.length - (blobOffset || 0);
|
11131
|
+
const newAbi = adjustConfigurableOffsets(abi, configurableOffsetDiff);
|
11132
|
+
const blobExists = (await deployer.provider.getBlobs([blobId])).length > 0;
|
11133
|
+
const loaderInstance = loaderInstanceCallback(loaderBytecode, newAbi);
|
11134
|
+
if (blobExists) {
|
11135
|
+
return {
|
11136
|
+
waitForResult: () => Promise.resolve(loaderInstance),
|
11137
|
+
blobId
|
11138
|
+
};
|
11139
|
+
}
|
11140
|
+
const fundedBlobRequest = await fundBlobTx(deployer, blobTxRequest);
|
11141
|
+
const waitForResult = async () => {
|
11142
|
+
try {
|
11143
|
+
const blobTx = await deployer.sendTransaction(fundedBlobRequest);
|
11144
|
+
const result = await blobTx.waitForResult();
|
11145
|
+
if (result.status !== "success" /* success */) {
|
11146
|
+
throw new Error();
|
11147
|
+
}
|
11148
|
+
} catch (err) {
|
11149
|
+
throw new import_errors29.FuelError(import_errors29.ErrorCode.TRANSACTION_FAILED, "Failed to deploy predicate chunk");
|
11150
|
+
}
|
11151
|
+
return loaderInstance;
|
11152
|
+
};
|
11153
|
+
return {
|
11154
|
+
waitForResult,
|
11155
|
+
blobId
|
11156
|
+
};
|
11157
|
+
}
|
11158
|
+
|
10876
11159
|
// src/predicate/utils/getPredicateRoot.ts
|
10877
|
-
var
|
11160
|
+
var import_hasher9 = require("@fuel-ts/hasher");
|
10878
11161
|
var import_merkle = require("@fuel-ts/merkle");
|
10879
|
-
var
|
11162
|
+
var import_utils44 = require("@fuel-ts/utils");
|
10880
11163
|
var getPredicateRoot = (bytecode) => {
|
10881
11164
|
const chunkSize = 16 * 1024;
|
10882
|
-
const bytes = (0,
|
10883
|
-
const chunks = (0,
|
10884
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
10885
|
-
const predicateRoot = (0,
|
11165
|
+
const bytes = (0, import_utils44.arrayify)(bytecode);
|
11166
|
+
const chunks = (0, import_utils44.chunkAndPadBytes)(bytes, chunkSize);
|
11167
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils44.hexlify)(c)));
|
11168
|
+
const predicateRoot = (0, import_hasher9.hash)((0, import_utils44.concat)(["0x4655454C", codeRoot]));
|
10886
11169
|
return predicateRoot;
|
10887
11170
|
};
|
10888
11171
|
|
10889
11172
|
// src/predicate/predicate.ts
|
10890
|
-
function getDataOffset(binary) {
|
10891
|
-
const buffer = binary.buffer.slice(binary.byteOffset + 8, binary.byteOffset + 16);
|
10892
|
-
const dataView = new DataView(buffer);
|
10893
|
-
const dataOffset = dataView.getBigUint64(0, false);
|
10894
|
-
return Number(dataOffset);
|
10895
|
-
}
|
10896
11173
|
var Predicate = class extends Account {
|
10897
11174
|
bytes;
|
10898
11175
|
predicateData = [];
|
10899
11176
|
interface;
|
10900
|
-
loaderBytecode = "";
|
10901
11177
|
/**
|
10902
11178
|
* Creates an instance of the Predicate class.
|
10903
11179
|
*
|
@@ -10912,24 +11188,17 @@ var Predicate = class extends Account {
|
|
10912
11188
|
abi,
|
10913
11189
|
provider,
|
10914
11190
|
data,
|
10915
|
-
configurableConstants
|
10916
|
-
/**
|
10917
|
-
* TODO: Implement a getBytes method within the Predicate class. This method should return the loaderBytecode if it is set.
|
10918
|
-
* The getBytes method should be used in all places where we use this.bytes.
|
10919
|
-
* Note: Do not set loaderBytecode to a default string here; it should remain undefined when not provided.
|
10920
|
-
*/
|
10921
|
-
loaderBytecode = ""
|
11191
|
+
configurableConstants
|
10922
11192
|
}) {
|
10923
11193
|
const { predicateBytes, predicateInterface } = Predicate.processPredicateData(
|
10924
11194
|
bytecode,
|
10925
11195
|
abi,
|
10926
11196
|
configurableConstants
|
10927
11197
|
);
|
10928
|
-
const address =
|
11198
|
+
const address = import_address11.Address.fromB256(getPredicateRoot(predicateBytes));
|
10929
11199
|
super(address, provider);
|
10930
11200
|
this.bytes = predicateBytes;
|
10931
11201
|
this.interface = predicateInterface;
|
10932
|
-
this.loaderBytecode = loaderBytecode;
|
10933
11202
|
if (data !== void 0 && data.length > 0) {
|
10934
11203
|
this.predicateData = data;
|
10935
11204
|
}
|
@@ -10948,8 +11217,8 @@ var Predicate = class extends Account {
|
|
10948
11217
|
}
|
10949
11218
|
request.inputs.filter(isRequestInputCoinOrMessage).forEach((input) => {
|
10950
11219
|
if (isRequestInputResourceFromOwner(input, this.address)) {
|
10951
|
-
input.predicate = (0,
|
10952
|
-
input.predicateData = (0,
|
11220
|
+
input.predicate = (0, import_utils45.hexlify)(this.bytes);
|
11221
|
+
input.predicateData = (0, import_utils45.hexlify)(this.getPredicateData());
|
10953
11222
|
input.witnessIndex = 0;
|
10954
11223
|
}
|
10955
11224
|
});
|
@@ -10991,16 +11260,13 @@ var Predicate = class extends Account {
|
|
10991
11260
|
* @returns An object containing the new predicate bytes and interface.
|
10992
11261
|
*/
|
10993
11262
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
10994
|
-
let predicateBytes = (0,
|
10995
|
-
|
10996
|
-
if (
|
10997
|
-
|
10998
|
-
|
10999
|
-
|
11000
|
-
|
11001
|
-
'Cannot use ABI without "main" function.'
|
11002
|
-
);
|
11003
|
-
}
|
11263
|
+
let predicateBytes = (0, import_utils45.arrayify)(bytes);
|
11264
|
+
const abiInterface = new import_abi_coder8.Interface(jsonAbi);
|
11265
|
+
if (abiInterface.functions.main === void 0) {
|
11266
|
+
throw new import_errors30.FuelError(
|
11267
|
+
import_errors30.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
11268
|
+
'Cannot use ABI without "main" function.'
|
11269
|
+
);
|
11004
11270
|
}
|
11005
11271
|
if (configurableConstants && Object.keys(configurableConstants).length) {
|
11006
11272
|
predicateBytes = Predicate.setConfigurableConstants(
|
@@ -11029,8 +11295,8 @@ var Predicate = class extends Account {
|
|
11029
11295
|
);
|
11030
11296
|
return resources.map((resource) => ({
|
11031
11297
|
...resource,
|
11032
|
-
predicate: (0,
|
11033
|
-
predicateData: (0,
|
11298
|
+
predicate: (0, import_utils45.hexlify)(this.bytes),
|
11299
|
+
predicateData: (0, import_utils45.hexlify)(this.getPredicateData())
|
11034
11300
|
}));
|
11035
11301
|
}
|
11036
11302
|
/**
|
@@ -11042,8 +11308,8 @@ var Predicate = class extends Account {
|
|
11042
11308
|
generateFakeResources(coins) {
|
11043
11309
|
return super.generateFakeResources(coins).map((coin) => ({
|
11044
11310
|
...coin,
|
11045
|
-
predicate: (0,
|
11046
|
-
predicateData: (0,
|
11311
|
+
predicate: (0, import_utils45.hexlify)(this.bytes),
|
11312
|
+
predicateData: (0, import_utils45.hexlify)(this.getPredicateData())
|
11047
11313
|
}));
|
11048
11314
|
}
|
11049
11315
|
/**
|
@@ -11054,25 +11320,19 @@ var Predicate = class extends Account {
|
|
11054
11320
|
* @param abiInterface - The ABI interface of the predicate.
|
11055
11321
|
* @returns The mutated bytes with the configurable constants set.
|
11056
11322
|
*/
|
11057
|
-
static setConfigurableConstants(bytes, configurableConstants, abiInterface
|
11323
|
+
static setConfigurableConstants(bytes, configurableConstants, abiInterface) {
|
11058
11324
|
const mutatedBytes = bytes;
|
11059
11325
|
try {
|
11060
|
-
if (!abiInterface) {
|
11061
|
-
throw new import_errors28.FuelError(
|
11062
|
-
import_errors28.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
11063
|
-
"Cannot validate configurable constants because the Predicate was instantiated without a JSON ABI"
|
11064
|
-
);
|
11065
|
-
}
|
11066
11326
|
if (Object.keys(abiInterface.configurables).length === 0) {
|
11067
|
-
throw new
|
11068
|
-
|
11327
|
+
throw new import_errors30.FuelError(
|
11328
|
+
import_errors30.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
11069
11329
|
"Predicate has no configurable constants to be set"
|
11070
11330
|
);
|
11071
11331
|
}
|
11072
11332
|
Object.entries(configurableConstants).forEach(([key, value]) => {
|
11073
11333
|
if (!abiInterface?.configurables[key]) {
|
11074
|
-
throw new
|
11075
|
-
|
11334
|
+
throw new import_errors30.FuelError(
|
11335
|
+
import_errors30.ErrorCode.CONFIGURABLE_NOT_FOUND,
|
11076
11336
|
`No configurable constant named '${key}' found in the Predicate`
|
11077
11337
|
);
|
11078
11338
|
}
|
@@ -11080,18 +11340,9 @@ var Predicate = class extends Account {
|
|
11080
11340
|
const encoded = abiInterface.encodeConfigurable(key, value);
|
11081
11341
|
mutatedBytes.set(encoded, offset);
|
11082
11342
|
});
|
11083
|
-
if (loaderBytecode) {
|
11084
|
-
const offset = getDataOffset(bytes);
|
11085
|
-
const dataSection = mutatedBytes.slice(offset);
|
11086
|
-
const dataSectionLen = dataSection.length;
|
11087
|
-
const dataSectionLenBytes = new Uint8Array(8);
|
11088
|
-
const dataSectionLenDataView = new DataView(dataSectionLenBytes.buffer);
|
11089
|
-
dataSectionLenDataView.setBigUint64(0, BigInt(dataSectionLen), false);
|
11090
|
-
mutatedBytes.set((0, import_utils43.concat)([loaderBytecode, dataSectionLenBytes, dataSection]));
|
11091
|
-
}
|
11092
11343
|
} catch (err) {
|
11093
|
-
throw new
|
11094
|
-
|
11344
|
+
throw new import_errors30.FuelError(
|
11345
|
+
import_errors30.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
11095
11346
|
`Error setting configurable constants: ${err.message}.`
|
11096
11347
|
);
|
11097
11348
|
}
|
@@ -11119,13 +11370,35 @@ var Predicate = class extends Account {
|
|
11119
11370
|
}
|
11120
11371
|
return index;
|
11121
11372
|
}
|
11373
|
+
/**
|
11374
|
+
*
|
11375
|
+
* @param account - The account used to pay the deployment costs.
|
11376
|
+
* @returns The _blobId_ and a _waitForResult_ callback that returns the deployed predicate
|
11377
|
+
* once the blob deployment transaction finishes.
|
11378
|
+
*
|
11379
|
+
* The returned loader predicate will have the same configurable constants
|
11380
|
+
* as the original predicate which was used to generate the loader predicate.
|
11381
|
+
*/
|
11382
|
+
async deploy(account) {
|
11383
|
+
return deployScriptOrPredicate({
|
11384
|
+
deployer: account,
|
11385
|
+
abi: this.interface.jsonAbi,
|
11386
|
+
bytecode: this.bytes,
|
11387
|
+
loaderInstanceCallback: (loaderBytecode, newAbi) => new Predicate({
|
11388
|
+
bytecode: loaderBytecode,
|
11389
|
+
abi: newAbi,
|
11390
|
+
provider: this.provider,
|
11391
|
+
data: this.predicateData
|
11392
|
+
})
|
11393
|
+
});
|
11394
|
+
}
|
11122
11395
|
};
|
11123
11396
|
|
11124
11397
|
// src/connectors/fuel.ts
|
11125
|
-
var
|
11398
|
+
var import_errors33 = require("@fuel-ts/errors");
|
11126
11399
|
|
11127
11400
|
// src/connectors/fuel-connector.ts
|
11128
|
-
var
|
11401
|
+
var import_errors31 = require("@fuel-ts/errors");
|
11129
11402
|
var import_events2 = require("events");
|
11130
11403
|
|
11131
11404
|
// src/connectors/types/connector-types.ts
|
@@ -11200,7 +11473,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11200
11473
|
* @returns Always true.
|
11201
11474
|
*/
|
11202
11475
|
async ping() {
|
11203
|
-
throw new
|
11476
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11204
11477
|
}
|
11205
11478
|
/**
|
11206
11479
|
* Should return the current version of the connector
|
@@ -11209,7 +11482,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11209
11482
|
* @returns boolean - connection status.
|
11210
11483
|
*/
|
11211
11484
|
async version() {
|
11212
|
-
throw new
|
11485
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11213
11486
|
}
|
11214
11487
|
/**
|
11215
11488
|
* Should return true if the connector is connected
|
@@ -11218,7 +11491,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11218
11491
|
* @returns The connection status.
|
11219
11492
|
*/
|
11220
11493
|
async isConnected() {
|
11221
|
-
throw new
|
11494
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11222
11495
|
}
|
11223
11496
|
/**
|
11224
11497
|
* Should return all the accounts authorized for the
|
@@ -11227,7 +11500,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11227
11500
|
* @returns The accounts addresses strings
|
11228
11501
|
*/
|
11229
11502
|
async accounts() {
|
11230
|
-
throw new
|
11503
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11231
11504
|
}
|
11232
11505
|
/**
|
11233
11506
|
* Should start the connection process and return
|
@@ -11239,7 +11512,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11239
11512
|
* @returns boolean - connection status.
|
11240
11513
|
*/
|
11241
11514
|
async connect() {
|
11242
|
-
throw new
|
11515
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11243
11516
|
}
|
11244
11517
|
/**
|
11245
11518
|
* Should disconnect the current connection and
|
@@ -11249,7 +11522,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11249
11522
|
* @returns The connection status.
|
11250
11523
|
*/
|
11251
11524
|
async disconnect() {
|
11252
|
-
throw new
|
11525
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11253
11526
|
}
|
11254
11527
|
/**
|
11255
11528
|
* Should start the sign message process and return
|
@@ -11261,7 +11534,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11261
11534
|
* @returns Message signature
|
11262
11535
|
*/
|
11263
11536
|
async signMessage(_address, _message) {
|
11264
|
-
throw new
|
11537
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11265
11538
|
}
|
11266
11539
|
/**
|
11267
11540
|
* Should start the sign transaction process and return
|
@@ -11273,7 +11546,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11273
11546
|
* @returns Transaction signature
|
11274
11547
|
*/
|
11275
11548
|
async signTransaction(_address, _transaction) {
|
11276
|
-
throw new
|
11549
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11277
11550
|
}
|
11278
11551
|
/**
|
11279
11552
|
* Should start the send transaction process and return
|
@@ -11289,7 +11562,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11289
11562
|
* @returns The transaction id
|
11290
11563
|
*/
|
11291
11564
|
async sendTransaction(_address, _transaction) {
|
11292
|
-
throw new
|
11565
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11293
11566
|
}
|
11294
11567
|
/**
|
11295
11568
|
* Should return the current account selected inside the connector, if the account
|
@@ -11300,7 +11573,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11300
11573
|
* @returns The current account selected otherwise null.
|
11301
11574
|
*/
|
11302
11575
|
async currentAccount() {
|
11303
|
-
throw new
|
11576
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11304
11577
|
}
|
11305
11578
|
/**
|
11306
11579
|
* Should add the assets metadata to the connector and return true if the asset
|
@@ -11314,7 +11587,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11314
11587
|
* @returns True if the asset was added successfully
|
11315
11588
|
*/
|
11316
11589
|
async addAssets(_assets) {
|
11317
|
-
throw new
|
11590
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11318
11591
|
}
|
11319
11592
|
/**
|
11320
11593
|
* Should add the asset metadata to the connector and return true if the asset
|
@@ -11328,7 +11601,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11328
11601
|
* @returns True if the asset was added successfully
|
11329
11602
|
*/
|
11330
11603
|
async addAsset(_asset) {
|
11331
|
-
throw new
|
11604
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11332
11605
|
}
|
11333
11606
|
/**
|
11334
11607
|
* Should return all the assets added to the connector. If a connection is already established.
|
@@ -11336,7 +11609,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11336
11609
|
* @returns Array of assets metadata from the connector vinculated to the all accounts from a specific Wallet.
|
11337
11610
|
*/
|
11338
11611
|
async assets() {
|
11339
|
-
throw new
|
11612
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11340
11613
|
}
|
11341
11614
|
/**
|
11342
11615
|
* Should start the add network process and return true if the network was added successfully.
|
@@ -11347,7 +11620,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11347
11620
|
* @returns Return true if the network was added successfully
|
11348
11621
|
*/
|
11349
11622
|
async addNetwork(_networkUrl) {
|
11350
|
-
throw new
|
11623
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11351
11624
|
}
|
11352
11625
|
/**
|
11353
11626
|
* Should start the select network process and return true if the network has change successfully.
|
@@ -11358,7 +11631,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11358
11631
|
* @returns Return true if the network was added successfully
|
11359
11632
|
*/
|
11360
11633
|
async selectNetwork(_network) {
|
11361
|
-
throw new
|
11634
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11362
11635
|
}
|
11363
11636
|
/**
|
11364
11637
|
* Should return all the networks available from the connector. If the connection is already established.
|
@@ -11366,7 +11639,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11366
11639
|
* @returns Return all the networks added to the connector.
|
11367
11640
|
*/
|
11368
11641
|
async networks() {
|
11369
|
-
throw new
|
11642
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11370
11643
|
}
|
11371
11644
|
/**
|
11372
11645
|
* Should return the current network selected inside the connector. Even if the connection is not established.
|
@@ -11374,7 +11647,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11374
11647
|
* @returns Return the current network selected inside the connector.
|
11375
11648
|
*/
|
11376
11649
|
async currentNetwork() {
|
11377
|
-
throw new
|
11650
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11378
11651
|
}
|
11379
11652
|
/**
|
11380
11653
|
* Should add the ABI to the connector and return true if the ABI was added successfully.
|
@@ -11384,7 +11657,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11384
11657
|
* @returns Return true if the ABI was added successfully.
|
11385
11658
|
*/
|
11386
11659
|
async addABI(_contractId, _abi) {
|
11387
|
-
throw new
|
11660
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11388
11661
|
}
|
11389
11662
|
/**
|
11390
11663
|
* Should return the ABI from the connector vinculated to the all accounts from a specific Wallet.
|
@@ -11393,7 +11666,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11393
11666
|
* @returns The ABI if it exists, otherwise return null.
|
11394
11667
|
*/
|
11395
11668
|
async getABI(_id) {
|
11396
|
-
throw new
|
11669
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11397
11670
|
}
|
11398
11671
|
/**
|
11399
11672
|
* Should return true if the abi exists in the connector vinculated to the all accounts from a specific Wallet.
|
@@ -11402,7 +11675,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11402
11675
|
* @returns Returns true if the abi exists or false if not.
|
11403
11676
|
*/
|
11404
11677
|
async hasABI(_id) {
|
11405
|
-
throw new
|
11678
|
+
throw new import_errors31.FuelError(import_errors31.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11406
11679
|
}
|
11407
11680
|
/**
|
11408
11681
|
* Event listener for the connector.
|
@@ -11446,7 +11719,7 @@ function dispatchFuelConnectorEvent(connector) {
|
|
11446
11719
|
}
|
11447
11720
|
|
11448
11721
|
// src/connectors/utils/promises.ts
|
11449
|
-
var
|
11722
|
+
var import_errors32 = require("@fuel-ts/errors");
|
11450
11723
|
function deferPromise() {
|
11451
11724
|
const defer = {};
|
11452
11725
|
defer.promise = new Promise((resolve, reject) => {
|
@@ -11458,7 +11731,7 @@ function deferPromise() {
|
|
11458
11731
|
async function withTimeout(promise, timeout = 1050) {
|
11459
11732
|
const timeoutPromise = new Promise((resolve, reject) => {
|
11460
11733
|
setTimeout(() => {
|
11461
|
-
reject(new
|
11734
|
+
reject(new import_errors32.FuelError(import_errors32.FuelError.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
11462
11735
|
}, timeout);
|
11463
11736
|
});
|
11464
11737
|
return Promise.race([timeoutPromise, promise]);
|
@@ -11493,7 +11766,7 @@ var _Fuel = class extends FuelConnector {
|
|
11493
11766
|
this._targetUnsubscribe = this.setupConnectorListener();
|
11494
11767
|
await connectResponse;
|
11495
11768
|
} catch (error) {
|
11496
|
-
throw new
|
11769
|
+
throw new import_errors33.FuelError(import_errors33.ErrorCode.INVALID_PROVIDER, "Error initializing Fuel Connector");
|
11497
11770
|
}
|
11498
11771
|
}
|
11499
11772
|
async init() {
|
@@ -11559,8 +11832,8 @@ var _Fuel = class extends FuelConnector {
|
|
11559
11832
|
const hasConnector = await this.hasConnector();
|
11560
11833
|
await this.pingConnector();
|
11561
11834
|
if (!this._currentConnector || !hasConnector) {
|
11562
|
-
throw new
|
11563
|
-
|
11835
|
+
throw new import_errors33.FuelError(
|
11836
|
+
import_errors33.ErrorCode.MISSING_CONNECTOR,
|
11564
11837
|
`No connector selected for calling ${method}. Use hasConnector before executing other methods.`
|
11565
11838
|
);
|
11566
11839
|
}
|
@@ -11624,7 +11897,7 @@ var _Fuel = class extends FuelConnector {
|
|
11624
11897
|
cacheTime: PING_CACHE_TIME
|
11625
11898
|
})();
|
11626
11899
|
} catch {
|
11627
|
-
throw new
|
11900
|
+
throw new import_errors33.FuelError(import_errors33.ErrorCode.INVALID_PROVIDER, "Current connector is not available.");
|
11628
11901
|
}
|
11629
11902
|
}
|
11630
11903
|
/**
|
@@ -11773,7 +12046,7 @@ var _Fuel = class extends FuelConnector {
|
|
11773
12046
|
const currentNetwork = await this.currentNetwork();
|
11774
12047
|
provider = await Provider.create(currentNetwork.url);
|
11775
12048
|
} else {
|
11776
|
-
throw new
|
12049
|
+
throw new import_errors33.FuelError(import_errors33.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
|
11777
12050
|
}
|
11778
12051
|
return provider;
|
11779
12052
|
}
|
@@ -11881,6 +12154,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
11881
12154
|
calculateTXFeeForSummary,
|
11882
12155
|
coinQuantityfy,
|
11883
12156
|
deferPromise,
|
12157
|
+
deployScriptOrPredicate,
|
11884
12158
|
dispatchFuelConnectorEvent,
|
11885
12159
|
english,
|
11886
12160
|
extractBurnedAssetsFromReceipts,
|