@fuel-ts/account 0.94.3 → 0.94.5
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.map +1 -1
- package/dist/index.global.js +391 -436
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +345 -195
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +427 -285
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +250 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +3 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +36 -3
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +2 -0
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +4 -2
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +3 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
- package/dist/providers/utils/handle-gql-error-message.d.ts +6 -0
- package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -0
- package/dist/providers/utils/receipts.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +235 -286
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +300 -162
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +372 -239
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -349,20 +349,14 @@ var launchNode = async ({
|
|
349
349
|
const rows = text.split("\n");
|
350
350
|
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
351
351
|
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
snapshotDir: snapshotDirToUse,
|
361
|
-
pid: child.pid
|
362
|
-
})
|
363
|
-
),
|
364
|
-
500
|
365
|
-
);
|
352
|
+
resolve({
|
353
|
+
cleanup,
|
354
|
+
ip: realIp,
|
355
|
+
port: realPort,
|
356
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
357
|
+
snapshotDir: snapshotDirToUse,
|
358
|
+
pid: child.pid
|
359
|
+
});
|
366
360
|
}
|
367
361
|
if (/error/i.test(text)) {
|
368
362
|
console.log(text);
|
@@ -381,7 +375,7 @@ var launchNode = async ({
|
|
381
375
|
|
382
376
|
// src/test-utils/setup-test-provider-and-wallets.ts
|
383
377
|
var import_utils41 = require("@fuel-ts/utils");
|
384
|
-
var
|
378
|
+
var import_ramda8 = require("ramda");
|
385
379
|
|
386
380
|
// src/providers/coin-quantity.ts
|
387
381
|
var import_math2 = require("@fuel-ts/math");
|
@@ -420,14 +414,15 @@ var addAmountToCoinQuantities = (params) => {
|
|
420
414
|
|
421
415
|
// src/providers/provider.ts
|
422
416
|
var import_address4 = require("@fuel-ts/address");
|
423
|
-
var
|
417
|
+
var import_errors17 = require("@fuel-ts/errors");
|
424
418
|
var import_math19 = require("@fuel-ts/math");
|
425
419
|
var import_transactions20 = require("@fuel-ts/transactions");
|
426
420
|
var import_utils26 = require("@fuel-ts/utils");
|
427
421
|
var import_versions = require("@fuel-ts/versions");
|
428
422
|
var import_utils27 = require("@noble/curves/abstract/utils");
|
429
423
|
var import_graphql_request = require("graphql-request");
|
430
|
-
var
|
424
|
+
var import_graphql_tag2 = __toESM(require("graphql-tag"));
|
425
|
+
var import_ramda6 = require("ramda");
|
431
426
|
|
432
427
|
// src/providers/__generated__/operations.ts
|
433
428
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
@@ -760,6 +755,14 @@ var BlockFragmentDoc = import_graphql_tag.default`
|
|
760
755
|
height
|
761
756
|
header {
|
762
757
|
time
|
758
|
+
daHeight
|
759
|
+
stateTransitionBytecodeVersion
|
760
|
+
transactionsCount
|
761
|
+
transactionsRoot
|
762
|
+
messageOutboxRoot
|
763
|
+
eventInboxRoot
|
764
|
+
prevRoot
|
765
|
+
applicationHash
|
763
766
|
}
|
764
767
|
transactions {
|
765
768
|
id
|
@@ -1367,6 +1370,13 @@ var SubmitAndAwaitDocument = import_graphql_tag.default`
|
|
1367
1370
|
}
|
1368
1371
|
}
|
1369
1372
|
${TransactionStatusSubscriptionFragmentDoc}`;
|
1373
|
+
var SubmitAndAwaitStatusDocument = import_graphql_tag.default`
|
1374
|
+
subscription submitAndAwaitStatus($encodedTransaction: HexString!) {
|
1375
|
+
submitAndAwaitStatus(tx: $encodedTransaction) {
|
1376
|
+
...transactionStatusSubscriptionFragment
|
1377
|
+
}
|
1378
|
+
}
|
1379
|
+
${TransactionStatusSubscriptionFragmentDoc}`;
|
1370
1380
|
var StatusChangeDocument = import_graphql_tag.default`
|
1371
1381
|
subscription statusChange($transactionId: TransactionId!) {
|
1372
1382
|
statusChange(id: $transactionId) {
|
@@ -1463,6 +1473,9 @@ function getSdk(requester) {
|
|
1463
1473
|
submitAndAwait(variables, options) {
|
1464
1474
|
return requester(SubmitAndAwaitDocument, variables, options);
|
1465
1475
|
},
|
1476
|
+
submitAndAwaitStatus(variables, options) {
|
1477
|
+
return requester(SubmitAndAwaitStatusDocument, variables, options);
|
1478
|
+
},
|
1466
1479
|
statusChange(variables, options) {
|
1467
1480
|
return requester(StatusChangeDocument, variables, options);
|
1468
1481
|
}
|
@@ -1489,7 +1502,9 @@ var _FuelGraphqlSubscriber = class {
|
|
1489
1502
|
Accept: "text/event-stream"
|
1490
1503
|
}
|
1491
1504
|
});
|
1492
|
-
|
1505
|
+
const [errorReader, resultReader] = response.body.tee().map((stream) => stream.getReader());
|
1506
|
+
await new _FuelGraphqlSubscriber(errorReader).next();
|
1507
|
+
return new _FuelGraphqlSubscriber(resultReader);
|
1493
1508
|
}
|
1494
1509
|
events = [];
|
1495
1510
|
parsingLeftover = "";
|
@@ -1532,10 +1547,8 @@ var _FuelGraphqlSubscriber = class {
|
|
1532
1547
|
/**
|
1533
1548
|
* Gets called when `break` is called in a `for-await-of` loop.
|
1534
1549
|
*/
|
1535
|
-
|
1536
|
-
|
1537
|
-
this.stream.releaseLock();
|
1538
|
-
return { done: true, value: void 0 };
|
1550
|
+
return() {
|
1551
|
+
return Promise.resolve({ done: true, value: void 0 });
|
1539
1552
|
}
|
1540
1553
|
[Symbol.asyncIterator]() {
|
1541
1554
|
return this;
|
@@ -1748,6 +1761,9 @@ var import_math9 = require("@fuel-ts/math");
|
|
1748
1761
|
var import_transactions7 = require("@fuel-ts/transactions");
|
1749
1762
|
var import_utils11 = require("@fuel-ts/utils");
|
1750
1763
|
|
1764
|
+
// src/providers/message.ts
|
1765
|
+
var isMessageCoin = (message) => !("data" in message);
|
1766
|
+
|
1751
1767
|
// src/providers/resource.ts
|
1752
1768
|
var isCoin = (resource) => "id" in resource;
|
1753
1769
|
|
@@ -1903,12 +1919,12 @@ function assembleReceiptByType(receipt) {
|
|
1903
1919
|
const amount = (0, import_math5.bn)(receipt.amount);
|
1904
1920
|
const data = receipt.data ? (0, import_utils7.arrayify)(receipt.data) : Uint8Array.from([]);
|
1905
1921
|
const digest = hexOrZero(receipt.digest);
|
1906
|
-
const messageId = import_transactions3.
|
1922
|
+
const messageId = import_transactions3.InputMessageCoder.getMessageId({
|
1907
1923
|
sender,
|
1908
1924
|
recipient,
|
1909
1925
|
nonce,
|
1910
1926
|
amount,
|
1911
|
-
data
|
1927
|
+
data: (0, import_utils7.hexlify)(data)
|
1912
1928
|
});
|
1913
1929
|
const receiptMessageOut = {
|
1914
1930
|
type: import_transactions3.ReceiptType.MessageOut,
|
@@ -1925,7 +1941,7 @@ function assembleReceiptByType(receipt) {
|
|
1925
1941
|
case "MINT" /* Mint */: {
|
1926
1942
|
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1927
1943
|
const subId = hexOrZero(receipt.subId);
|
1928
|
-
const assetId = import_transactions3.
|
1944
|
+
const assetId = (0, import_transactions3.getMintedAssetId)(contractId, subId);
|
1929
1945
|
const mintReceipt = {
|
1930
1946
|
type: import_transactions3.ReceiptType.Mint,
|
1931
1947
|
subId,
|
@@ -1940,7 +1956,7 @@ function assembleReceiptByType(receipt) {
|
|
1940
1956
|
case "BURN" /* Burn */: {
|
1941
1957
|
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1942
1958
|
const subId = hexOrZero(receipt.subId);
|
1943
|
-
const assetId = import_transactions3.
|
1959
|
+
const assetId = (0, import_transactions3.getMintedAssetId)(contractId, subId);
|
1944
1960
|
const burnReceipt = {
|
1945
1961
|
type: import_transactions3.ReceiptType.Burn,
|
1946
1962
|
subId,
|
@@ -2122,20 +2138,22 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2122
2138
|
let reason = "";
|
2123
2139
|
if (revertReceipt) {
|
2124
2140
|
const reasonHex = (0, import_math7.bn)(revertReceipt.val).toHex();
|
2141
|
+
const lastLog = logs[logs.length - 1];
|
2142
|
+
const lastButOneLog = logs[logs.length - 2];
|
2125
2143
|
switch (reasonHex) {
|
2126
2144
|
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
2127
2145
|
reason = "require";
|
2128
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(
|
2146
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
2129
2147
|
break;
|
2130
2148
|
}
|
2131
2149
|
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
2132
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(
|
2150
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
2133
2151
|
reason = "assert_eq";
|
2134
2152
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
2135
2153
|
break;
|
2136
2154
|
}
|
2137
2155
|
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
2138
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(
|
2156
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2139
2157
|
reason = "assert_ne";
|
2140
2158
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
2141
2159
|
break;
|
@@ -2196,7 +2214,9 @@ var import_math8 = require("@fuel-ts/math");
|
|
2196
2214
|
var import_transactions6 = require("@fuel-ts/transactions");
|
2197
2215
|
var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
|
2198
2216
|
var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
|
2199
|
-
var
|
2217
|
+
var isRequestInputMessageWithoutData = (input) => input.type === import_transactions6.InputType.Message && (0, import_math8.bn)(input.data).isZero();
|
2218
|
+
var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
2219
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2200
2220
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2201
2221
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
2202
2222
|
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
@@ -2492,7 +2512,7 @@ var BaseTransactionRequest = class {
|
|
2492
2512
|
* @param message - Message resource.
|
2493
2513
|
*/
|
2494
2514
|
addMessageInput(message) {
|
2495
|
-
const { recipient, sender, amount, predicate, nonce,
|
2515
|
+
const { recipient, sender, amount, predicate, nonce, predicateData } = message;
|
2496
2516
|
let witnessIndex;
|
2497
2517
|
if (message.predicate) {
|
2498
2518
|
witnessIndex = 0;
|
@@ -2507,13 +2527,16 @@ var BaseTransactionRequest = class {
|
|
2507
2527
|
type: import_transactions7.InputType.Message,
|
2508
2528
|
sender: sender.toB256(),
|
2509
2529
|
recipient: recipient.toB256(),
|
2530
|
+
data: isMessageCoin(message) ? "0x" : message.data,
|
2510
2531
|
amount,
|
2511
2532
|
witnessIndex,
|
2512
2533
|
predicate,
|
2513
2534
|
predicateData
|
2514
2535
|
};
|
2515
2536
|
this.pushInput(input);
|
2516
|
-
|
2537
|
+
if (isMessageCoin(message)) {
|
2538
|
+
this.addChangeOutput(recipient, message.assetId);
|
2539
|
+
}
|
2517
2540
|
}
|
2518
2541
|
/**
|
2519
2542
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2645,6 +2668,8 @@ var BaseTransactionRequest = class {
|
|
2645
2668
|
*
|
2646
2669
|
* @param quantities - CoinQuantity Array.
|
2647
2670
|
* @param baseAssetId - The base asset to fund the transaction.
|
2671
|
+
* @deprecated - This method is deprecated and will be removed in future versions.
|
2672
|
+
* Please use `Account.generateFakeResources` along with `this.addResources` instead.
|
2648
2673
|
*/
|
2649
2674
|
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2650
2675
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
@@ -2713,7 +2738,7 @@ var BaseTransactionRequest = class {
|
|
2713
2738
|
});
|
2714
2739
|
}
|
2715
2740
|
updatePredicateGasUsed(inputs) {
|
2716
|
-
const inputsToExtractGasUsed = inputs.filter(
|
2741
|
+
const inputsToExtractGasUsed = inputs.filter(isRequestInputCoinOrMessage);
|
2717
2742
|
this.inputs.filter(isRequestInputResource).forEach((i) => {
|
2718
2743
|
const owner = getRequestInputResourceOwner(i);
|
2719
2744
|
const correspondingInput = inputsToExtractGasUsed.find(
|
@@ -2729,6 +2754,9 @@ var BaseTransactionRequest = class {
|
|
2729
2754
|
}
|
2730
2755
|
};
|
2731
2756
|
|
2757
|
+
// src/providers/transaction-request/blob-transaction-request.ts
|
2758
|
+
var import_ramda3 = require("ramda");
|
2759
|
+
|
2732
2760
|
// src/providers/transaction-request/hash-transaction.ts
|
2733
2761
|
var import_configs7 = require("@fuel-ts/address/configs");
|
2734
2762
|
var import_hasher2 = require("@fuel-ts/hasher");
|
@@ -2803,10 +2831,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2803
2831
|
// src/providers/transaction-request/blob-transaction-request.ts
|
2804
2832
|
var BlobTransactionRequest = class extends BaseTransactionRequest {
|
2805
2833
|
static from(obj) {
|
2806
|
-
|
2807
|
-
return obj;
|
2808
|
-
}
|
2809
|
-
return new this(obj);
|
2834
|
+
return new this((0, import_ramda3.clone)(obj));
|
2810
2835
|
}
|
2811
2836
|
/** Type of the transaction */
|
2812
2837
|
type = import_transactions7.TransactionType.Blob;
|
@@ -2869,6 +2894,7 @@ var import_configs8 = require("@fuel-ts/address/configs");
|
|
2869
2894
|
var import_math11 = require("@fuel-ts/math");
|
2870
2895
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2871
2896
|
var import_utils16 = require("@fuel-ts/utils");
|
2897
|
+
var import_ramda4 = require("ramda");
|
2872
2898
|
|
2873
2899
|
// src/providers/transaction-request/storage-slot.ts
|
2874
2900
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2896,10 +2922,7 @@ var storageSlotify = (storageSlot) => {
|
|
2896
2922
|
// src/providers/transaction-request/create-transaction-request.ts
|
2897
2923
|
var CreateTransactionRequest = class extends BaseTransactionRequest {
|
2898
2924
|
static from(obj) {
|
2899
|
-
|
2900
|
-
return obj;
|
2901
|
-
}
|
2902
|
-
return new this(obj);
|
2925
|
+
return new this((0, import_ramda4.clone)(obj));
|
2903
2926
|
}
|
2904
2927
|
/** Type of the transaction */
|
2905
2928
|
type = import_transactions9.TransactionType.Create;
|
@@ -2988,6 +3011,7 @@ var import_configs9 = require("@fuel-ts/address/configs");
|
|
2988
3011
|
var import_math12 = require("@fuel-ts/math");
|
2989
3012
|
var import_transactions10 = require("@fuel-ts/transactions");
|
2990
3013
|
var import_utils18 = require("@fuel-ts/utils");
|
3014
|
+
var import_ramda5 = require("ramda");
|
2991
3015
|
|
2992
3016
|
// src/providers/transaction-request/scripts.ts
|
2993
3017
|
var import_utils17 = require("@fuel-ts/utils");
|
@@ -3018,10 +3042,7 @@ var withdrawScript = {
|
|
3018
3042
|
// src/providers/transaction-request/script-transaction-request.ts
|
3019
3043
|
var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
3020
3044
|
static from(obj) {
|
3021
|
-
|
3022
|
-
return obj;
|
3023
|
-
}
|
3024
|
-
return new this(obj);
|
3045
|
+
return new this((0, import_ramda5.clone)(obj));
|
3025
3046
|
}
|
3026
3047
|
/** Type of the transaction */
|
3027
3048
|
type = import_transactions10.TransactionType.Script;
|
@@ -4057,29 +4078,30 @@ function mapGqlOutputsToTxOutputs(outputs) {
|
|
4057
4078
|
});
|
4058
4079
|
}
|
4059
4080
|
var TransactionResponse = class {
|
4060
|
-
/** Transaction ID */
|
4061
|
-
id;
|
4062
|
-
/** Current provider */
|
4063
|
-
provider;
|
4064
|
-
/** Gas used on the transaction */
|
4065
|
-
gasUsed = (0, import_math18.bn)(0);
|
4066
|
-
/** The graphql Transaction with receipts object. */
|
4067
|
-
gqlTransaction;
|
4068
|
-
request;
|
4069
|
-
status;
|
4070
|
-
abis;
|
4071
4081
|
/**
|
4072
4082
|
* Constructor for `TransactionResponse`.
|
4073
4083
|
*
|
4074
4084
|
* @param tx - The transaction ID or TransactionRequest.
|
4075
4085
|
* @param provider - The provider.
|
4076
4086
|
*/
|
4077
|
-
constructor(tx, provider, abis) {
|
4087
|
+
constructor(tx, provider, abis, submitTxSubscription) {
|
4088
|
+
this.submitTxSubscription = submitTxSubscription;
|
4078
4089
|
this.id = typeof tx === "string" ? tx : tx.getTransactionId(provider.getChainId());
|
4079
4090
|
this.provider = provider;
|
4080
4091
|
this.abis = abis;
|
4081
4092
|
this.request = typeof tx === "string" ? void 0 : tx;
|
4082
4093
|
}
|
4094
|
+
/** Transaction ID */
|
4095
|
+
id;
|
4096
|
+
/** Current provider */
|
4097
|
+
provider;
|
4098
|
+
/** Gas used on the transaction */
|
4099
|
+
gasUsed = (0, import_math18.bn)(0);
|
4100
|
+
/** The graphql Transaction with receipts object. */
|
4101
|
+
gqlTransaction;
|
4102
|
+
request;
|
4103
|
+
status;
|
4104
|
+
abis;
|
4083
4105
|
/**
|
4084
4106
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
4085
4107
|
* an instance of `TransactionResponse` and wait for the transaction to be fetched
|
@@ -4212,10 +4234,11 @@ var TransactionResponse = class {
|
|
4212
4234
|
if (status && status !== "SubmittedStatus") {
|
4213
4235
|
return;
|
4214
4236
|
}
|
4215
|
-
const subscription = await this.provider.operations.statusChange({
|
4237
|
+
const subscription = this.submitTxSubscription ?? await this.provider.operations.statusChange({
|
4216
4238
|
transactionId: this.id
|
4217
4239
|
});
|
4218
|
-
for await (const
|
4240
|
+
for await (const sub of subscription) {
|
4241
|
+
const statusChange = "statusChange" in sub ? sub.statusChange : sub.submitAndAwaitStatus;
|
4219
4242
|
this.status = statusChange;
|
4220
4243
|
if (statusChange.type === "SqueezedOutStatus") {
|
4221
4244
|
this.unsetResourceCache();
|
@@ -4327,6 +4350,22 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4327
4350
|
};
|
4328
4351
|
}
|
4329
4352
|
|
4353
|
+
// src/providers/utils/handle-gql-error-message.ts
|
4354
|
+
var import_errors16 = require("@fuel-ts/errors");
|
4355
|
+
var handleGqlErrorMessage = (errorMessage, rawError) => {
|
4356
|
+
switch (errorMessage) {
|
4357
|
+
case "not enough coins to fit the target" /* NOT_ENOUGH_COINS */:
|
4358
|
+
throw new import_errors16.FuelError(
|
4359
|
+
import_errors16.ErrorCode.NOT_ENOUGH_FUNDS,
|
4360
|
+
`The account(s) sending the transaction don't have enough funds to cover the transaction.`,
|
4361
|
+
{},
|
4362
|
+
rawError
|
4363
|
+
);
|
4364
|
+
default:
|
4365
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.INVALID_REQUEST, errorMessage);
|
4366
|
+
}
|
4367
|
+
};
|
4368
|
+
|
4330
4369
|
// src/providers/provider.ts
|
4331
4370
|
var MAX_RETRIES = 10;
|
4332
4371
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
@@ -4453,6 +4492,17 @@ var _Provider = class {
|
|
4453
4492
|
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
4454
4493
|
}, retryOptions);
|
4455
4494
|
}
|
4495
|
+
static extractBasicAuth(url) {
|
4496
|
+
const parsedUrl = new URL(url);
|
4497
|
+
const username = parsedUrl.username;
|
4498
|
+
const password = parsedUrl.password;
|
4499
|
+
const urlNoBasicAuth = `${parsedUrl.origin}${parsedUrl.pathname}`;
|
4500
|
+
if (!(username && password)) {
|
4501
|
+
return { url, auth: void 0 };
|
4502
|
+
}
|
4503
|
+
const auth = `Basic ${btoa(`${username}:${password}`)}`;
|
4504
|
+
return { url: urlNoBasicAuth, auth };
|
4505
|
+
}
|
4456
4506
|
/**
|
4457
4507
|
* Creates a new instance of the Provider class. This is the recommended way to initialize a Provider.
|
4458
4508
|
*
|
@@ -4462,7 +4512,17 @@ var _Provider = class {
|
|
4462
4512
|
* @returns A promise that resolves to a Provider instance.
|
4463
4513
|
*/
|
4464
4514
|
static async create(url, options = {}) {
|
4465
|
-
const
|
4515
|
+
const { url: urlToUse, auth } = this.extractBasicAuth(url);
|
4516
|
+
const provider = new _Provider(urlToUse, {
|
4517
|
+
...options,
|
4518
|
+
requestMiddleware: async (request) => {
|
4519
|
+
if (auth && request) {
|
4520
|
+
request.headers ??= {};
|
4521
|
+
request.headers.Authorization = auth;
|
4522
|
+
}
|
4523
|
+
return options.requestMiddleware?.(request) ?? request;
|
4524
|
+
}
|
4525
|
+
});
|
4466
4526
|
await provider.fetchChainAndNodeInfo();
|
4467
4527
|
return provider;
|
4468
4528
|
}
|
@@ -4474,8 +4534,8 @@ var _Provider = class {
|
|
4474
4534
|
getChain() {
|
4475
4535
|
const chain = _Provider.chainInfoCache[this.url];
|
4476
4536
|
if (!chain) {
|
4477
|
-
throw new
|
4478
|
-
|
4537
|
+
throw new import_errors17.FuelError(
|
4538
|
+
import_errors17.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
4479
4539
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4480
4540
|
);
|
4481
4541
|
}
|
@@ -4489,8 +4549,8 @@ var _Provider = class {
|
|
4489
4549
|
getNode() {
|
4490
4550
|
const node = _Provider.nodeInfoCache[this.url];
|
4491
4551
|
if (!node) {
|
4492
|
-
throw new
|
4493
|
-
|
4552
|
+
throw new import_errors17.FuelError(
|
4553
|
+
import_errors17.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
4494
4554
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4495
4555
|
);
|
4496
4556
|
}
|
@@ -4568,10 +4628,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4568
4628
|
if ("response" in response) {
|
4569
4629
|
const graphQlResponse = response.response;
|
4570
4630
|
if (Array.isArray(graphQlResponse?.errors)) {
|
4571
|
-
|
4572
|
-
|
4573
|
-
|
4574
|
-
);
|
4631
|
+
for (const error of graphQlResponse.errors) {
|
4632
|
+
handleGqlErrorMessage(error.message, error);
|
4633
|
+
}
|
4575
4634
|
}
|
4576
4635
|
}
|
4577
4636
|
}
|
@@ -4589,7 +4648,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4589
4648
|
}
|
4590
4649
|
return gqlClient.request(query, vars);
|
4591
4650
|
};
|
4592
|
-
|
4651
|
+
const customOperations = (requester) => ({
|
4652
|
+
getBlobs(variables) {
|
4653
|
+
const queryParams = variables.blobIds.map((_, i) => `$blobId${i}: BlobId!`).join(", ");
|
4654
|
+
const blobParams = variables.blobIds.map((_, i) => `blob${i}: blob(id: $blobId${i}) { id }`).join("\n");
|
4655
|
+
const updatedVariables = variables.blobIds.reduce(
|
4656
|
+
(acc, blobId, i) => {
|
4657
|
+
acc[`blobId${i}`] = blobId;
|
4658
|
+
return acc;
|
4659
|
+
},
|
4660
|
+
{}
|
4661
|
+
);
|
4662
|
+
const document = import_graphql_tag2.default`
|
4663
|
+
query getBlobs(${queryParams}) {
|
4664
|
+
${blobParams}
|
4665
|
+
}
|
4666
|
+
`;
|
4667
|
+
return requester(document, updatedVariables);
|
4668
|
+
}
|
4669
|
+
});
|
4670
|
+
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
4593
4671
|
}
|
4594
4672
|
/**
|
4595
4673
|
* Returns the version of the connected node.
|
@@ -4664,14 +4742,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4664
4742
|
validateTransaction(tx, consensusParameters) {
|
4665
4743
|
const { maxOutputs, maxInputs } = consensusParameters.txParameters;
|
4666
4744
|
if ((0, import_math19.bn)(tx.inputs.length).gt(maxInputs)) {
|
4667
|
-
throw new
|
4668
|
-
|
4745
|
+
throw new import_errors17.FuelError(
|
4746
|
+
import_errors17.ErrorCode.MAX_INPUTS_EXCEEDED,
|
4669
4747
|
"The transaction exceeds the maximum allowed number of inputs."
|
4670
4748
|
);
|
4671
4749
|
}
|
4672
4750
|
if ((0, import_math19.bn)(tx.outputs.length).gt(maxOutputs)) {
|
4673
|
-
throw new
|
4674
|
-
|
4751
|
+
throw new import_errors17.FuelError(
|
4752
|
+
import_errors17.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
4675
4753
|
"The transaction exceeds the maximum allowed number of outputs."
|
4676
4754
|
);
|
4677
4755
|
}
|
@@ -4698,11 +4776,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4698
4776
|
if (isTransactionTypeScript(transactionRequest)) {
|
4699
4777
|
abis = transactionRequest.abis;
|
4700
4778
|
}
|
4701
|
-
const {
|
4702
|
-
|
4703
|
-
|
4704
|
-
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionId);
|
4705
|
-
return new TransactionResponse(transactionRequest, this, abis);
|
4779
|
+
const subscription = await this.operations.submitAndAwaitStatus({ encodedTransaction });
|
4780
|
+
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionRequest.getTransactionId(this.getChainId()));
|
4781
|
+
return new TransactionResponse(transactionRequest, this, abis, subscription);
|
4706
4782
|
}
|
4707
4783
|
/**
|
4708
4784
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -4832,7 +4908,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4832
4908
|
missingContractIds: [],
|
4833
4909
|
dryRunStatus: void 0
|
4834
4910
|
}));
|
4835
|
-
const allRequests = (0,
|
4911
|
+
const allRequests = (0, import_ramda6.clone)(transactionRequests);
|
4836
4912
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4837
4913
|
allRequests.forEach((req, index) => {
|
4838
4914
|
if (isTransactionTypeScript(req)) {
|
@@ -4992,13 +5068,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4992
5068
|
* @returns A promise that resolves to the transaction cost object.
|
4993
5069
|
*/
|
4994
5070
|
async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
|
4995
|
-
const txRequestClone = (0,
|
5071
|
+
const txRequestClone = (0, import_ramda6.clone)(transactionRequestify(transactionRequestLike));
|
4996
5072
|
const updateMaxFee = txRequestClone.maxFee.eq(0);
|
4997
5073
|
const isScriptTransaction = isTransactionTypeScript(txRequestClone);
|
4998
5074
|
if (isScriptTransaction) {
|
4999
5075
|
txRequestClone.gasLimit = (0, import_math19.bn)(0);
|
5000
5076
|
}
|
5001
|
-
const signedRequest = (0,
|
5077
|
+
const signedRequest = (0, import_ramda6.clone)(txRequestClone);
|
5002
5078
|
let addedSignatures = 0;
|
5003
5079
|
if (signatureCallback && isTransactionTypeScript(signedRequest)) {
|
5004
5080
|
const lengthBefore = signedRequest.witnesses.length;
|
@@ -5136,6 +5212,21 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5136
5212
|
}).filter((v) => !!v);
|
5137
5213
|
return coins;
|
5138
5214
|
}
|
5215
|
+
/**
|
5216
|
+
* Returns an array of blobIds that exist on chain, for a given array of blobIds.
|
5217
|
+
*
|
5218
|
+
* @param blobIds - blobIds to check.
|
5219
|
+
* @returns - A promise that resolves to an array of blobIds that exist on chain.
|
5220
|
+
*/
|
5221
|
+
async getBlobs(blobIds) {
|
5222
|
+
const res = await this.operations.getBlobs({ blobIds });
|
5223
|
+
const blobs = [];
|
5224
|
+
Object.keys(res).forEach((key) => {
|
5225
|
+
const val = res[key];
|
5226
|
+
blobs.push(val?.id ?? null);
|
5227
|
+
});
|
5228
|
+
return blobs.filter((v) => v);
|
5229
|
+
}
|
5139
5230
|
/**
|
5140
5231
|
* Returns block matching the given ID or height.
|
5141
5232
|
*
|
@@ -5157,11 +5248,22 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5157
5248
|
if (!block) {
|
5158
5249
|
return null;
|
5159
5250
|
}
|
5251
|
+
const { header, height, id, transactions } = block;
|
5160
5252
|
return {
|
5161
|
-
id
|
5162
|
-
height: (0, import_math19.bn)(
|
5163
|
-
time:
|
5164
|
-
|
5253
|
+
id,
|
5254
|
+
height: (0, import_math19.bn)(height),
|
5255
|
+
time: header.time,
|
5256
|
+
header: {
|
5257
|
+
applicationHash: header.applicationHash,
|
5258
|
+
daHeight: (0, import_math19.bn)(header.daHeight),
|
5259
|
+
eventInboxRoot: header.eventInboxRoot,
|
5260
|
+
messageOutboxRoot: header.messageOutboxRoot,
|
5261
|
+
prevRoot: header.prevRoot,
|
5262
|
+
stateTransitionBytecodeVersion: header.stateTransitionBytecodeVersion,
|
5263
|
+
transactionsCount: header.transactionsCount,
|
5264
|
+
transactionsRoot: header.transactionsRoot
|
5265
|
+
},
|
5266
|
+
transactionIds: transactions.map((tx) => tx.id)
|
5165
5267
|
};
|
5166
5268
|
}
|
5167
5269
|
/**
|
@@ -5183,6 +5285,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5183
5285
|
id: block.id,
|
5184
5286
|
height: (0, import_math19.bn)(block.height),
|
5185
5287
|
time: block.header.time,
|
5288
|
+
header: {
|
5289
|
+
applicationHash: block.header.applicationHash,
|
5290
|
+
daHeight: (0, import_math19.bn)(block.header.daHeight),
|
5291
|
+
eventInboxRoot: block.header.eventInboxRoot,
|
5292
|
+
messageOutboxRoot: block.header.messageOutboxRoot,
|
5293
|
+
prevRoot: block.header.prevRoot,
|
5294
|
+
stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion,
|
5295
|
+
transactionsCount: block.header.transactionsCount,
|
5296
|
+
transactionsRoot: block.header.transactionsRoot
|
5297
|
+
},
|
5186
5298
|
transactionIds: block.transactions.map((tx) => tx.id)
|
5187
5299
|
}));
|
5188
5300
|
return { blocks, pageInfo };
|
@@ -5210,6 +5322,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5210
5322
|
id: block.id,
|
5211
5323
|
height: (0, import_math19.bn)(block.height, 10),
|
5212
5324
|
time: block.header.time,
|
5325
|
+
header: {
|
5326
|
+
applicationHash: block.header.applicationHash,
|
5327
|
+
daHeight: (0, import_math19.bn)(block.header.daHeight),
|
5328
|
+
eventInboxRoot: block.header.eventInboxRoot,
|
5329
|
+
messageOutboxRoot: block.header.messageOutboxRoot,
|
5330
|
+
prevRoot: block.header.prevRoot,
|
5331
|
+
stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion,
|
5332
|
+
transactionsCount: block.header.transactionsCount,
|
5333
|
+
transactionsRoot: block.header.transactionsRoot
|
5334
|
+
},
|
5213
5335
|
transactionIds: block.transactions.map((tx) => tx.id),
|
5214
5336
|
transactions: block.transactions.map(
|
5215
5337
|
(tx) => new import_transactions20.TransactionCoder().decode((0, import_utils26.arrayify)(tx.rawPayload), 0)?.[0]
|
@@ -5233,7 +5355,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5233
5355
|
0
|
5234
5356
|
)?.[0];
|
5235
5357
|
} catch (error) {
|
5236
|
-
if (error instanceof
|
5358
|
+
if (error instanceof import_errors17.FuelError && error.code === import_errors17.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5237
5359
|
console.warn("Unsupported transaction type encountered");
|
5238
5360
|
return null;
|
5239
5361
|
}
|
@@ -5254,7 +5376,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5254
5376
|
try {
|
5255
5377
|
return coder.decode((0, import_utils26.arrayify)(rawPayload), 0)[0];
|
5256
5378
|
} catch (error) {
|
5257
|
-
if (error instanceof
|
5379
|
+
if (error instanceof import_errors17.FuelError && error.code === import_errors17.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5258
5380
|
console.warn("Unsupported transaction type encountered");
|
5259
5381
|
return null;
|
5260
5382
|
}
|
@@ -5380,8 +5502,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5380
5502
|
nonce
|
5381
5503
|
};
|
5382
5504
|
if (commitBlockId && commitBlockHeight) {
|
5383
|
-
throw new
|
5384
|
-
|
5505
|
+
throw new import_errors17.FuelError(
|
5506
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5385
5507
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5386
5508
|
);
|
5387
5509
|
}
|
@@ -5521,10 +5643,25 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5521
5643
|
* @returns A promise that resolves to the Message object or null.
|
5522
5644
|
*/
|
5523
5645
|
async getMessageByNonce(nonce) {
|
5524
|
-
const { message } = await this.operations.getMessageByNonce({ nonce });
|
5525
|
-
if (!
|
5646
|
+
const { message: rawMessage } = await this.operations.getMessageByNonce({ nonce });
|
5647
|
+
if (!rawMessage) {
|
5526
5648
|
return null;
|
5527
5649
|
}
|
5650
|
+
const message = {
|
5651
|
+
messageId: import_transactions20.InputMessageCoder.getMessageId({
|
5652
|
+
sender: rawMessage.sender,
|
5653
|
+
recipient: rawMessage.recipient,
|
5654
|
+
nonce: rawMessage.nonce,
|
5655
|
+
amount: (0, import_math19.bn)(rawMessage.amount),
|
5656
|
+
data: rawMessage.data
|
5657
|
+
}),
|
5658
|
+
sender: import_address4.Address.fromAddressOrString(rawMessage.sender),
|
5659
|
+
recipient: import_address4.Address.fromAddressOrString(rawMessage.recipient),
|
5660
|
+
nonce: rawMessage.nonce,
|
5661
|
+
amount: (0, import_math19.bn)(rawMessage.amount),
|
5662
|
+
data: import_transactions20.InputMessageCoder.decodeData(rawMessage.data),
|
5663
|
+
daHeight: (0, import_math19.bn)(rawMessage.daHeight)
|
5664
|
+
};
|
5528
5665
|
return message;
|
5529
5666
|
}
|
5530
5667
|
/**
|
@@ -5549,26 +5686,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5549
5686
|
const { paginationLimit, inputArgs = {} } = params;
|
5550
5687
|
const { first, last, after, before } = inputArgs;
|
5551
5688
|
if (after && before) {
|
5552
|
-
throw new
|
5553
|
-
|
5689
|
+
throw new import_errors17.FuelError(
|
5690
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5554
5691
|
'Pagination arguments "after" and "before" cannot be used together'
|
5555
5692
|
);
|
5556
5693
|
}
|
5557
5694
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5558
|
-
throw new
|
5559
|
-
|
5695
|
+
throw new import_errors17.FuelError(
|
5696
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5560
5697
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5561
5698
|
);
|
5562
5699
|
}
|
5563
5700
|
if (first && before) {
|
5564
|
-
throw new
|
5565
|
-
|
5701
|
+
throw new import_errors17.FuelError(
|
5702
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5566
5703
|
'The use of pagination argument "first" with "before" is not supported'
|
5567
5704
|
);
|
5568
5705
|
}
|
5569
5706
|
if (last && after) {
|
5570
|
-
throw new
|
5571
|
-
|
5707
|
+
throw new import_errors17.FuelError(
|
5708
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5572
5709
|
'The use of pagination argument "last" with "after" is not supported'
|
5573
5710
|
);
|
5574
5711
|
}
|
@@ -5622,7 +5759,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
5622
5759
|
__publicField(Provider, "nodeInfoCache", {});
|
5623
5760
|
|
5624
5761
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
5625
|
-
var
|
5762
|
+
var import_errors18 = require("@fuel-ts/errors");
|
5626
5763
|
var import_math20 = require("@fuel-ts/math");
|
5627
5764
|
var import_transactions21 = require("@fuel-ts/transactions");
|
5628
5765
|
var import_utils29 = require("@fuel-ts/utils");
|
@@ -5723,7 +5860,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
5723
5860
|
|
5724
5861
|
// src/test-utils/wallet-config.ts
|
5725
5862
|
var import_crypto9 = require("@fuel-ts/crypto");
|
5726
|
-
var
|
5863
|
+
var import_errors24 = require("@fuel-ts/errors");
|
5727
5864
|
var import_utils40 = require("@fuel-ts/utils");
|
5728
5865
|
|
5729
5866
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -5734,11 +5871,12 @@ var import_utils35 = require("@fuel-ts/utils");
|
|
5734
5871
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
5735
5872
|
var import_address5 = require("@fuel-ts/address");
|
5736
5873
|
var import_crypto5 = require("@fuel-ts/crypto");
|
5737
|
-
var
|
5874
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5738
5875
|
var import_interfaces = require("@fuel-ts/interfaces");
|
5739
5876
|
var import_math22 = require("@fuel-ts/math");
|
5877
|
+
var import_transactions22 = require("@fuel-ts/transactions");
|
5740
5878
|
var import_utils33 = require("@fuel-ts/utils");
|
5741
|
-
var
|
5879
|
+
var import_ramda7 = require("ramda");
|
5742
5880
|
|
5743
5881
|
// src/providers/utils/merge-quantities.ts
|
5744
5882
|
var mergeQuantities = (...coinQuantities) => {
|
@@ -5827,7 +5965,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5827
5965
|
*/
|
5828
5966
|
get provider() {
|
5829
5967
|
if (!this._provider) {
|
5830
|
-
throw new
|
5968
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
5831
5969
|
}
|
5832
5970
|
return this._provider;
|
5833
5971
|
}
|
@@ -5945,7 +6083,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5945
6083
|
);
|
5946
6084
|
request.addResources(resources);
|
5947
6085
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5948
|
-
const requestToReestimate2 = (0,
|
6086
|
+
const requestToReestimate2 = (0, import_ramda7.clone)(request);
|
5949
6087
|
if (addedSignatures) {
|
5950
6088
|
Array.from({ length: addedSignatures }).forEach(
|
5951
6089
|
() => requestToReestimate2.addEmptyWitness()
|
@@ -5960,7 +6098,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5960
6098
|
gasPrice
|
5961
6099
|
});
|
5962
6100
|
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
5963
|
-
request.inputs,
|
6101
|
+
request.inputs.filter(isRequestInputResource),
|
5964
6102
|
baseAssetId,
|
5965
6103
|
baseAssetId
|
5966
6104
|
);
|
@@ -5978,13 +6116,13 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5978
6116
|
fundingAttempts += 1;
|
5979
6117
|
}
|
5980
6118
|
if (needsToBeFunded) {
|
5981
|
-
throw new
|
5982
|
-
|
6119
|
+
throw new import_errors19.FuelError(
|
6120
|
+
import_errors19.ErrorCode.NOT_ENOUGH_FUNDS,
|
5983
6121
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
5984
6122
|
);
|
5985
6123
|
}
|
5986
6124
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5987
|
-
const requestToReestimate = (0,
|
6125
|
+
const requestToReestimate = (0, import_ramda7.clone)(request);
|
5988
6126
|
if (addedSignatures) {
|
5989
6127
|
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
5990
6128
|
}
|
@@ -6084,8 +6222,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6084
6222
|
*/
|
6085
6223
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
6086
6224
|
if ((0, import_math22.bn)(amount).lte(0)) {
|
6087
|
-
throw new
|
6088
|
-
|
6225
|
+
throw new import_errors19.FuelError(
|
6226
|
+
import_errors19.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
6089
6227
|
"Transfer amount must be a positive number."
|
6090
6228
|
);
|
6091
6229
|
}
|
@@ -6160,16 +6298,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6160
6298
|
* @returns A promise that resolves to the transaction cost object.
|
6161
6299
|
*/
|
6162
6300
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
|
6163
|
-
const txRequestClone = (0,
|
6301
|
+
const txRequestClone = (0, import_ramda7.clone)(transactionRequestify(transactionRequestLike));
|
6164
6302
|
const baseAssetId = this.provider.getBaseAssetId();
|
6165
6303
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
6166
6304
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
6167
6305
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math22.bn)("100000000000000000") }];
|
6168
6306
|
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
6169
|
-
if (
|
6307
|
+
if (input.type === import_transactions22.InputType.Coin) {
|
6170
6308
|
return input.assetId === assetId;
|
6171
6309
|
}
|
6172
|
-
if (
|
6310
|
+
if (isRequestInputMessageWithoutData(input)) {
|
6173
6311
|
return baseAssetId === assetId;
|
6174
6312
|
}
|
6175
6313
|
return false;
|
@@ -6211,7 +6349,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6211
6349
|
*/
|
6212
6350
|
async signMessage(message) {
|
6213
6351
|
if (!this._connector) {
|
6214
|
-
throw new
|
6352
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
6215
6353
|
}
|
6216
6354
|
return this._connector.signMessage(this.address.toString(), message);
|
6217
6355
|
}
|
@@ -6223,8 +6361,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6223
6361
|
*/
|
6224
6362
|
async signTransaction(transactionRequestLike) {
|
6225
6363
|
if (!this._connector) {
|
6226
|
-
throw new
|
6227
|
-
|
6364
|
+
throw new import_errors19.FuelError(
|
6365
|
+
import_errors19.ErrorCode.MISSING_CONNECTOR,
|
6228
6366
|
"A connector is required to sign transactions."
|
6229
6367
|
);
|
6230
6368
|
}
|
@@ -6283,8 +6421,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6283
6421
|
/** @hidden * */
|
6284
6422
|
validateTransferAmount(amount) {
|
6285
6423
|
if ((0, import_math22.bn)(amount).lte(0)) {
|
6286
|
-
throw new
|
6287
|
-
|
6424
|
+
throw new import_errors19.FuelError(
|
6425
|
+
import_errors19.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
6288
6426
|
"Transfer amount must be a positive number."
|
6289
6427
|
);
|
6290
6428
|
}
|
@@ -6313,16 +6451,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6313
6451
|
if (!(0, import_utils33.isDefined)(setGasLimit)) {
|
6314
6452
|
request.gasLimit = gasUsed;
|
6315
6453
|
} else if (gasUsed.gt(setGasLimit)) {
|
6316
|
-
throw new
|
6317
|
-
|
6454
|
+
throw new import_errors19.FuelError(
|
6455
|
+
import_errors19.ErrorCode.GAS_LIMIT_TOO_LOW,
|
6318
6456
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
6319
6457
|
);
|
6320
6458
|
}
|
6321
6459
|
if (!(0, import_utils33.isDefined)(setMaxFee)) {
|
6322
6460
|
request.maxFee = maxFee;
|
6323
6461
|
} else if (maxFee.gt(setMaxFee)) {
|
6324
|
-
throw new
|
6325
|
-
|
6462
|
+
throw new import_errors19.FuelError(
|
6463
|
+
import_errors19.ErrorCode.MAX_FEE_TOO_LOW,
|
6326
6464
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
6327
6465
|
);
|
6328
6466
|
}
|
@@ -6333,7 +6471,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6333
6471
|
// src/wallet/keystore-wallet.ts
|
6334
6472
|
var import_address6 = require("@fuel-ts/address");
|
6335
6473
|
var import_crypto6 = require("@fuel-ts/crypto");
|
6336
|
-
var
|
6474
|
+
var import_errors20 = require("@fuel-ts/errors");
|
6337
6475
|
var import_utils34 = require("@fuel-ts/utils");
|
6338
6476
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
6339
6477
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -6410,8 +6548,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
6410
6548
|
const macHashUint8Array = (0, import_crypto6.keccak256)(data);
|
6411
6549
|
const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
|
6412
6550
|
if (mac !== macHash) {
|
6413
|
-
throw new
|
6414
|
-
|
6551
|
+
throw new import_errors20.FuelError(
|
6552
|
+
import_errors20.ErrorCode.INVALID_PASSWORD,
|
6415
6553
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
6416
6554
|
);
|
6417
6555
|
}
|
@@ -6541,14 +6679,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
6541
6679
|
|
6542
6680
|
// src/hdwallet/hdwallet.ts
|
6543
6681
|
var import_crypto8 = require("@fuel-ts/crypto");
|
6544
|
-
var
|
6682
|
+
var import_errors23 = require("@fuel-ts/errors");
|
6545
6683
|
var import_hasher6 = require("@fuel-ts/hasher");
|
6546
6684
|
var import_math23 = require("@fuel-ts/math");
|
6547
6685
|
var import_utils39 = require("@fuel-ts/utils");
|
6548
6686
|
|
6549
6687
|
// src/mnemonic/mnemonic.ts
|
6550
6688
|
var import_crypto7 = require("@fuel-ts/crypto");
|
6551
|
-
var
|
6689
|
+
var import_errors22 = require("@fuel-ts/errors");
|
6552
6690
|
var import_hasher5 = require("@fuel-ts/hasher");
|
6553
6691
|
var import_utils37 = require("@fuel-ts/utils");
|
6554
6692
|
|
@@ -8605,7 +8743,7 @@ var english = [
|
|
8605
8743
|
];
|
8606
8744
|
|
8607
8745
|
// src/mnemonic/utils.ts
|
8608
|
-
var
|
8746
|
+
var import_errors21 = require("@fuel-ts/errors");
|
8609
8747
|
var import_hasher4 = require("@fuel-ts/hasher");
|
8610
8748
|
var import_utils36 = require("@fuel-ts/utils");
|
8611
8749
|
function getLowerMask(bits) {
|
@@ -8654,8 +8792,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8654
8792
|
for (let i = 0; i < words.length; i += 1) {
|
8655
8793
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
8656
8794
|
if (index === -1) {
|
8657
|
-
throw new
|
8658
|
-
|
8795
|
+
throw new import_errors21.FuelError(
|
8796
|
+
import_errors21.ErrorCode.INVALID_MNEMONIC,
|
8659
8797
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
8660
8798
|
);
|
8661
8799
|
}
|
@@ -8671,8 +8809,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8671
8809
|
const checksumMask = getUpperMask(checksumBits);
|
8672
8810
|
const checksum = (0, import_utils36.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8673
8811
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8674
|
-
throw new
|
8675
|
-
|
8812
|
+
throw new import_errors21.FuelError(
|
8813
|
+
import_errors21.ErrorCode.INVALID_CHECKSUM,
|
8676
8814
|
"Checksum validation failed for the provided mnemonic."
|
8677
8815
|
);
|
8678
8816
|
}
|
@@ -8686,16 +8824,16 @@ var TestnetPRV = "0x04358394";
|
|
8686
8824
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
8687
8825
|
function assertWordList(wordlist) {
|
8688
8826
|
if (wordlist.length !== 2048) {
|
8689
|
-
throw new
|
8690
|
-
|
8827
|
+
throw new import_errors22.FuelError(
|
8828
|
+
import_errors22.ErrorCode.INVALID_WORD_LIST,
|
8691
8829
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
8692
8830
|
);
|
8693
8831
|
}
|
8694
8832
|
}
|
8695
8833
|
function assertEntropy(entropy) {
|
8696
8834
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
8697
|
-
throw new
|
8698
|
-
|
8835
|
+
throw new import_errors22.FuelError(
|
8836
|
+
import_errors22.ErrorCode.INVALID_ENTROPY,
|
8699
8837
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
8700
8838
|
);
|
8701
8839
|
}
|
@@ -8705,7 +8843,7 @@ function assertMnemonic(words) {
|
|
8705
8843
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
8706
8844
|
", "
|
8707
8845
|
)}] words, but got ${words.length}.`;
|
8708
|
-
throw new
|
8846
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
8709
8847
|
}
|
8710
8848
|
}
|
8711
8849
|
var Mnemonic = class {
|
@@ -8823,8 +8961,8 @@ var Mnemonic = class {
|
|
8823
8961
|
static masterKeysFromSeed(seed) {
|
8824
8962
|
const seedArray = (0, import_utils37.arrayify)(seed);
|
8825
8963
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8826
|
-
throw new
|
8827
|
-
|
8964
|
+
throw new import_errors22.FuelError(
|
8965
|
+
import_errors22.ErrorCode.INVALID_SEED,
|
8828
8966
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8829
8967
|
);
|
8830
8968
|
}
|
@@ -8901,7 +9039,7 @@ function isValidExtendedKey(extendedKey) {
|
|
8901
9039
|
function parsePath(path2, depth = 0) {
|
8902
9040
|
const components = path2.split("/");
|
8903
9041
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
8904
|
-
throw new
|
9042
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
8905
9043
|
}
|
8906
9044
|
if (components[0] === "m") {
|
8907
9045
|
components.shift();
|
@@ -8930,8 +9068,8 @@ var HDWallet = class {
|
|
8930
9068
|
this.privateKey = (0, import_utils39.hexlify)(config.privateKey);
|
8931
9069
|
} else {
|
8932
9070
|
if (!config.publicKey) {
|
8933
|
-
throw new
|
8934
|
-
|
9071
|
+
throw new import_errors23.FuelError(
|
9072
|
+
import_errors23.ErrorCode.HD_WALLET_ERROR,
|
8935
9073
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8936
9074
|
);
|
8937
9075
|
}
|
@@ -8960,8 +9098,8 @@ var HDWallet = class {
|
|
8960
9098
|
const data = new Uint8Array(37);
|
8961
9099
|
if (index & HARDENED_INDEX) {
|
8962
9100
|
if (!privateKey) {
|
8963
|
-
throw new
|
8964
|
-
|
9101
|
+
throw new import_errors23.FuelError(
|
9102
|
+
import_errors23.ErrorCode.HD_WALLET_ERROR,
|
8965
9103
|
"Cannot derive a hardened index without a private Key."
|
8966
9104
|
);
|
8967
9105
|
}
|
@@ -9013,8 +9151,8 @@ var HDWallet = class {
|
|
9013
9151
|
*/
|
9014
9152
|
toExtendedKey(isPublic = false, testnet = false) {
|
9015
9153
|
if (this.depth >= 256) {
|
9016
|
-
throw new
|
9017
|
-
|
9154
|
+
throw new import_errors23.FuelError(
|
9155
|
+
import_errors23.ErrorCode.HD_WALLET_ERROR,
|
9018
9156
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
9019
9157
|
);
|
9020
9158
|
}
|
@@ -9045,10 +9183,10 @@ var HDWallet = class {
|
|
9045
9183
|
const bytes = (0, import_utils39.arrayify)(decoded);
|
9046
9184
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
9047
9185
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
9048
|
-
throw new
|
9186
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
9049
9187
|
}
|
9050
9188
|
if (!validChecksum) {
|
9051
|
-
throw new
|
9189
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
9052
9190
|
}
|
9053
9191
|
const depth = bytes[4];
|
9054
9192
|
const parentFingerprint = (0, import_utils39.hexlify)(bytes.slice(5, 9));
|
@@ -9056,14 +9194,14 @@ var HDWallet = class {
|
|
9056
9194
|
const chainCode = (0, import_utils39.hexlify)(bytes.slice(13, 45));
|
9057
9195
|
const key = bytes.slice(45, 78);
|
9058
9196
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
9059
|
-
throw new
|
9060
|
-
|
9197
|
+
throw new import_errors23.FuelError(
|
9198
|
+
import_errors23.ErrorCode.HD_WALLET_ERROR,
|
9061
9199
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
9062
9200
|
);
|
9063
9201
|
}
|
9064
9202
|
if (isPublicExtendedKey(bytes)) {
|
9065
9203
|
if (key[0] !== 3) {
|
9066
|
-
throw new
|
9204
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
9067
9205
|
}
|
9068
9206
|
return new HDWallet({
|
9069
9207
|
publicKey: key,
|
@@ -9074,7 +9212,7 @@ var HDWallet = class {
|
|
9074
9212
|
});
|
9075
9213
|
}
|
9076
9214
|
if (key[0] !== 0) {
|
9077
|
-
throw new
|
9215
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
9078
9216
|
}
|
9079
9217
|
return new HDWallet({
|
9080
9218
|
privateKey: key.slice(1),
|
@@ -9318,26 +9456,26 @@ var WalletsConfig = class {
|
|
9318
9456
|
amountPerCoin
|
9319
9457
|
}) {
|
9320
9458
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
9321
|
-
throw new
|
9322
|
-
|
9459
|
+
throw new import_errors24.FuelError(
|
9460
|
+
import_errors24.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9323
9461
|
"Number of wallets must be greater than zero."
|
9324
9462
|
);
|
9325
9463
|
}
|
9326
9464
|
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
9327
|
-
throw new
|
9328
|
-
|
9465
|
+
throw new import_errors24.FuelError(
|
9466
|
+
import_errors24.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9329
9467
|
"Number of assets per wallet must be greater than zero."
|
9330
9468
|
);
|
9331
9469
|
}
|
9332
9470
|
if (coinsPerAsset <= 0) {
|
9333
|
-
throw new
|
9334
|
-
|
9471
|
+
throw new import_errors24.FuelError(
|
9472
|
+
import_errors24.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9335
9473
|
"Number of coins per asset must be greater than zero."
|
9336
9474
|
);
|
9337
9475
|
}
|
9338
9476
|
if (amountPerCoin < 0) {
|
9339
|
-
throw new
|
9340
|
-
|
9477
|
+
throw new import_errors24.FuelError(
|
9478
|
+
import_errors24.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9341
9479
|
"Amount per coin must be greater than or equal to zero."
|
9342
9480
|
);
|
9343
9481
|
}
|
@@ -9369,7 +9507,7 @@ async function setupTestProviderAndWallets({
|
|
9369
9507
|
const launchNodeOptions = {
|
9370
9508
|
loggingEnabled: false,
|
9371
9509
|
...nodeOptions,
|
9372
|
-
snapshotConfig: (0,
|
9510
|
+
snapshotConfig: (0, import_ramda8.mergeDeepRight)(
|
9373
9511
|
import_utils41.defaultSnapshotConfigs,
|
9374
9512
|
walletsConfig.apply(nodeOptions?.snapshotConfig)
|
9375
9513
|
),
|