@fuel-ts/account 0.100.1 → 0.100.3
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/index.global.js +3868 -1941
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1004 -802
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +939 -739
- package/dist/index.mjs.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +17 -1
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +14 -14
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-response/getAllDecodedLogs.d.ts +30 -0
- package/dist/providers/transaction-response/getAllDecodedLogs.d.ts.map +1 -0
- package/dist/providers/transaction-response/getDecodedLogs.d.ts +20 -1
- package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
- package/dist/providers/transaction-response/index.d.ts +1 -0
- package/dist/providers/transaction-response/index.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 +4 -3
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
- package/dist/providers/utils/serialization.d.ts.map +1 -1
- package/dist/test-utils.global.js +3268 -1786
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +723 -586
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +672 -535
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +14 -14
package/dist/test-utils.mjs
CHANGED
@@ -1,22 +1,5 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
|
-
var
|
3
|
-
var __publicField = (obj, key, value) => {
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
5
|
-
return value;
|
6
|
-
};
|
7
|
-
var __accessCheck = (obj, member, msg) => {
|
8
|
-
if (!member.has(obj))
|
9
|
-
throw TypeError("Cannot " + msg);
|
10
|
-
};
|
11
|
-
var __privateAdd = (obj, member, value) => {
|
12
|
-
if (member.has(obj))
|
13
|
-
throw TypeError("Cannot add the same private member more than once");
|
14
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
15
|
-
};
|
16
|
-
var __privateMethod = (obj, member, method) => {
|
17
|
-
__accessCheck(obj, member, "access private method");
|
18
|
-
return method;
|
19
|
-
};
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
20
3
|
|
21
4
|
// src/test-utils/launchNode.ts
|
22
5
|
import { BYTES_32 } from "@fuel-ts/abi-coder";
|
@@ -34,7 +17,10 @@ import { hash } from "@fuel-ts/hasher";
|
|
34
17
|
import { toBytes } from "@fuel-ts/math";
|
35
18
|
import { hexlify, concat, arrayify } from "@fuel-ts/utils";
|
36
19
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
37
|
-
var Signer = class {
|
20
|
+
var Signer = class _Signer {
|
21
|
+
static {
|
22
|
+
__name(this, "Signer");
|
23
|
+
}
|
38
24
|
address;
|
39
25
|
publicKey;
|
40
26
|
compressedPublicKey;
|
@@ -113,7 +99,7 @@ var Signer = class {
|
|
113
99
|
* @returns Address from signature
|
114
100
|
*/
|
115
101
|
static recoverAddress(data, signature) {
|
116
|
-
return new Address(
|
102
|
+
return new Address(_Signer.recoverPublicKey(data, signature));
|
117
103
|
}
|
118
104
|
/**
|
119
105
|
* Generate a random privateKey
|
@@ -137,14 +123,14 @@ var Signer = class {
|
|
137
123
|
};
|
138
124
|
|
139
125
|
// src/test-utils/launchNode.ts
|
140
|
-
var getFlagValueFromArgs = (args, flag) => {
|
126
|
+
var getFlagValueFromArgs = /* @__PURE__ */ __name((args, flag) => {
|
141
127
|
const flagIndex = args.indexOf(flag);
|
142
128
|
if (flagIndex === -1) {
|
143
129
|
return void 0;
|
144
130
|
}
|
145
131
|
return args[flagIndex + 1];
|
146
|
-
};
|
147
|
-
var extractRemainingArgs = (args, flagsToRemove) => {
|
132
|
+
}, "getFlagValueFromArgs");
|
133
|
+
var extractRemainingArgs = /* @__PURE__ */ __name((args, flagsToRemove) => {
|
148
134
|
const newArgs = [...args];
|
149
135
|
flagsToRemove.forEach((flag) => {
|
150
136
|
const flagIndex = newArgs.indexOf(flag);
|
@@ -153,7 +139,7 @@ var extractRemainingArgs = (args, flagsToRemove) => {
|
|
153
139
|
}
|
154
140
|
});
|
155
141
|
return newArgs;
|
156
|
-
};
|
142
|
+
}, "extractRemainingArgs");
|
157
143
|
function getFinalStateConfigJSON({
|
158
144
|
stateConfig,
|
159
145
|
chainConfig,
|
@@ -212,7 +198,8 @@ function getFinalStateConfigJSON({
|
|
212
198
|
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
213
199
|
return json.replace(regexMakeNumber, "$1$2");
|
214
200
|
}
|
215
|
-
|
201
|
+
__name(getFinalStateConfigJSON, "getFinalStateConfigJSON");
|
202
|
+
var launchNode = /* @__PURE__ */ __name(async ({
|
216
203
|
ip,
|
217
204
|
port,
|
218
205
|
args = [],
|
@@ -298,18 +285,18 @@ var launchNode = async ({
|
|
298
285
|
console.log(chunk.toString());
|
299
286
|
});
|
300
287
|
}
|
301
|
-
const removeChildListeners = () => {
|
288
|
+
const removeChildListeners = /* @__PURE__ */ __name(() => {
|
302
289
|
child.stderr.removeAllListeners();
|
303
|
-
};
|
304
|
-
const removeTempDir = () => {
|
290
|
+
}, "removeChildListeners");
|
291
|
+
const removeTempDir = /* @__PURE__ */ __name(() => {
|
305
292
|
if (existsSync(tempDir)) {
|
306
293
|
rmSync(tempDir, { recursive: true });
|
307
294
|
}
|
308
|
-
};
|
295
|
+
}, "removeTempDir");
|
309
296
|
const childState = {
|
310
297
|
isDead: false
|
311
298
|
};
|
312
|
-
const cleanup = () => {
|
299
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
313
300
|
if (childState.isDead) {
|
314
301
|
return;
|
315
302
|
}
|
@@ -334,7 +321,7 @@ var launchNode = async ({
|
|
334
321
|
console.error("No PID available for the child process, unable to kill launched node");
|
335
322
|
}
|
336
323
|
removeTempDir();
|
337
|
-
};
|
324
|
+
}, "cleanup");
|
338
325
|
child.stderr.on("data", (chunk) => {
|
339
326
|
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
340
327
|
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
@@ -375,7 +362,7 @@ var launchNode = async ({
|
|
375
362
|
reject(err);
|
376
363
|
});
|
377
364
|
})
|
378
|
-
);
|
365
|
+
), "launchNode");
|
379
366
|
|
380
367
|
// src/test-utils/setup-test-provider-and-wallets.ts
|
381
368
|
import { defaultSnapshotConfigs as defaultSnapshotConfigs3 } from "@fuel-ts/utils";
|
@@ -384,7 +371,7 @@ import { mergeDeepRight } from "ramda";
|
|
384
371
|
// src/providers/coin-quantity.ts
|
385
372
|
import { bn } from "@fuel-ts/math";
|
386
373
|
import { hexlify as hexlify3 } from "@fuel-ts/utils";
|
387
|
-
var coinQuantityfy = (coinQuantityLike) => {
|
374
|
+
var coinQuantityfy = /* @__PURE__ */ __name((coinQuantityLike) => {
|
388
375
|
let assetId;
|
389
376
|
let amount;
|
390
377
|
let max;
|
@@ -402,8 +389,8 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
402
389
|
amount: bn(amount),
|
403
390
|
max: max ? bn(max) : void 0
|
404
391
|
};
|
405
|
-
};
|
406
|
-
var addAmountToCoinQuantities = (params) => {
|
392
|
+
}, "coinQuantityfy");
|
393
|
+
var addAmountToCoinQuantities = /* @__PURE__ */ __name((params) => {
|
407
394
|
const { amount, assetId } = params;
|
408
395
|
const coinQuantities = [...params.coinQuantities];
|
409
396
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -413,30 +400,19 @@ var addAmountToCoinQuantities = (params) => {
|
|
413
400
|
coinQuantities.push({ assetId, amount });
|
414
401
|
}
|
415
402
|
return coinQuantities;
|
416
|
-
};
|
403
|
+
}, "addAmountToCoinQuantities");
|
417
404
|
|
418
405
|
// src/providers/provider.ts
|
419
406
|
import { Address as Address3, isB256 } from "@fuel-ts/address";
|
420
|
-
import { ErrorCode as ErrorCode16, FuelError as
|
407
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError19 } from "@fuel-ts/errors";
|
421
408
|
import { bn as bn17 } from "@fuel-ts/math";
|
422
409
|
import { InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
|
423
410
|
import { arrayify as arrayify13, hexlify as hexlify18, DateTime as DateTime2, isDefined as isDefined2 } from "@fuel-ts/utils";
|
424
|
-
import { checkFuelCoreVersionCompatibility,
|
411
|
+
import { checkFuelCoreVersionCompatibility, versions } from "@fuel-ts/versions";
|
425
412
|
import { GraphQLClient } from "graphql-request";
|
426
413
|
import gql2 from "graphql-tag";
|
427
414
|
import { clone as clone8 } from "ramda";
|
428
415
|
|
429
|
-
// src/connectors/utils/promises.ts
|
430
|
-
import { FuelError as FuelError2 } from "@fuel-ts/errors";
|
431
|
-
function deferPromise() {
|
432
|
-
const defer = {};
|
433
|
-
defer.promise = new Promise((resolve, reject) => {
|
434
|
-
defer.reject = reject;
|
435
|
-
defer.resolve = resolve;
|
436
|
-
});
|
437
|
-
return defer;
|
438
|
-
}
|
439
|
-
|
440
416
|
// src/providers/__generated__/operations.ts
|
441
417
|
import gql from "graphql-tag";
|
442
418
|
var SubmittedStatusFragmentDoc = gql`
|
@@ -928,6 +904,11 @@ var NodeInfoFragmentDoc = gql`
|
|
928
904
|
maxTx
|
929
905
|
maxDepth
|
930
906
|
nodeVersion
|
907
|
+
indexation {
|
908
|
+
balances
|
909
|
+
coinsToSpend
|
910
|
+
assetMetadata
|
911
|
+
}
|
931
912
|
}
|
932
913
|
`;
|
933
914
|
var RelayedTransactionStatusFragmentDoc = gql`
|
@@ -1209,7 +1190,7 @@ var GetBalancesDocument = gql`
|
|
1209
1190
|
}
|
1210
1191
|
`;
|
1211
1192
|
var GetBalancesV2Document = gql`
|
1212
|
-
query getBalancesV2($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
1193
|
+
query getBalancesV2($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int, $supportsPagination: Boolean!) {
|
1213
1194
|
balances(
|
1214
1195
|
filter: $filter
|
1215
1196
|
after: $after
|
@@ -1217,7 +1198,7 @@ var GetBalancesV2Document = gql`
|
|
1217
1198
|
first: $first
|
1218
1199
|
last: $last
|
1219
1200
|
) {
|
1220
|
-
pageInfo {
|
1201
|
+
pageInfo @include(if: $supportsPagination) {
|
1221
1202
|
...pageInfoFragment
|
1222
1203
|
}
|
1223
1204
|
edges {
|
@@ -1487,16 +1468,17 @@ function getSdk(requester) {
|
|
1487
1468
|
}
|
1488
1469
|
};
|
1489
1470
|
}
|
1471
|
+
__name(getSdk, "getSdk");
|
1490
1472
|
|
1491
1473
|
// src/providers/fuel-graphql-subscriber.ts
|
1492
|
-
import { ErrorCode as ErrorCode2, FuelError as
|
1474
|
+
import { ErrorCode as ErrorCode2, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1493
1475
|
import { print } from "graphql";
|
1494
1476
|
|
1495
1477
|
// src/providers/utils/handle-gql-error-message.ts
|
1496
|
-
import { ErrorCode, FuelError as
|
1497
|
-
var mapGqlErrorMessage = (error) => {
|
1478
|
+
import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
|
1479
|
+
var mapGqlErrorMessage = /* @__PURE__ */ __name((error) => {
|
1498
1480
|
if (new RegExp("the target cannot be met due to no coins available or exceeding the \\d+ coin limit." /* NOT_ENOUGH_COINS_MAX_COINS */).test(error.message)) {
|
1499
|
-
return new
|
1481
|
+
return new FuelError2(
|
1500
1482
|
ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
1501
1483
|
`Insufficient funds or too many small value coins. Consider combining UTXOs.`,
|
1502
1484
|
{},
|
@@ -1504,20 +1486,20 @@ var mapGqlErrorMessage = (error) => {
|
|
1504
1486
|
);
|
1505
1487
|
}
|
1506
1488
|
if (new RegExp("resource was not found in table" /* ASSET_NOT_FOUND */).test(error.message)) {
|
1507
|
-
return new
|
1489
|
+
return new FuelError2(
|
1508
1490
|
ErrorCode.ASSET_NOT_FOUND,
|
1509
1491
|
`Asset not found for given asset id.`,
|
1510
1492
|
{},
|
1511
1493
|
error
|
1512
1494
|
);
|
1513
1495
|
}
|
1514
|
-
return new
|
1515
|
-
};
|
1516
|
-
var mapGqlErrorWithIncompatibleNodeVersion = (error, incompatibleNodeVersionMessage) => {
|
1496
|
+
return new FuelError2(ErrorCode.INVALID_REQUEST, error.message, {}, error);
|
1497
|
+
}, "mapGqlErrorMessage");
|
1498
|
+
var mapGqlErrorWithIncompatibleNodeVersion = /* @__PURE__ */ __name((error, incompatibleNodeVersionMessage) => {
|
1517
1499
|
if (!incompatibleNodeVersionMessage) {
|
1518
1500
|
return error;
|
1519
1501
|
}
|
1520
|
-
return new
|
1502
|
+
return new FuelError2(
|
1521
1503
|
error.code,
|
1522
1504
|
`${error.message}
|
1523
1505
|
|
@@ -1525,8 +1507,8 @@ ${incompatibleNodeVersionMessage}`,
|
|
1525
1507
|
error.metadata,
|
1526
1508
|
error.rawError
|
1527
1509
|
);
|
1528
|
-
};
|
1529
|
-
var assertGqlResponseHasNoErrors = (errors, incompatibleNodeVersionMessage = false) => {
|
1510
|
+
}, "mapGqlErrorWithIncompatibleNodeVersion");
|
1511
|
+
var assertGqlResponseHasNoErrors = /* @__PURE__ */ __name((errors, incompatibleNodeVersionMessage = false) => {
|
1530
1512
|
if (!Array.isArray(errors)) {
|
1531
1513
|
return;
|
1532
1514
|
}
|
@@ -1536,16 +1518,21 @@ var assertGqlResponseHasNoErrors = (errors, incompatibleNodeVersionMessage = fal
|
|
1536
1518
|
}
|
1537
1519
|
const errorMessage = mappedErrors.map((err) => err.message).join("\n");
|
1538
1520
|
throw mapGqlErrorWithIncompatibleNodeVersion(
|
1539
|
-
new
|
1521
|
+
new FuelError2(ErrorCode.INVALID_REQUEST, errorMessage, {}, mappedErrors),
|
1540
1522
|
incompatibleNodeVersionMessage
|
1541
1523
|
);
|
1542
|
-
};
|
1524
|
+
}, "assertGqlResponseHasNoErrors");
|
1543
1525
|
|
1544
1526
|
// src/providers/fuel-graphql-subscriber.ts
|
1545
|
-
var
|
1527
|
+
var FuelGraphqlSubscriber = class _FuelGraphqlSubscriber {
|
1546
1528
|
constructor(stream) {
|
1547
1529
|
this.stream = stream;
|
1548
1530
|
}
|
1531
|
+
static {
|
1532
|
+
__name(this, "FuelGraphqlSubscriber");
|
1533
|
+
}
|
1534
|
+
static incompatibleNodeVersionMessage = false;
|
1535
|
+
static textDecoder = new TextDecoder();
|
1549
1536
|
static async create(options) {
|
1550
1537
|
const { url, query, variables, fetchFn } = options;
|
1551
1538
|
const response = await fetchFn(`${url}-sub`, {
|
@@ -1587,7 +1574,7 @@ var _FuelGraphqlSubscriber = class {
|
|
1587
1574
|
try {
|
1588
1575
|
this.events.push(JSON.parse(match.replace(/^data:/, "")));
|
1589
1576
|
} catch (e) {
|
1590
|
-
throw new
|
1577
|
+
throw new FuelError3(
|
1591
1578
|
ErrorCode2.STREAM_PARSING_ERROR,
|
1592
1579
|
`Error while parsing stream data response: ${text}`
|
1593
1580
|
);
|
@@ -1606,22 +1593,19 @@ var _FuelGraphqlSubscriber = class {
|
|
1606
1593
|
return this;
|
1607
1594
|
}
|
1608
1595
|
};
|
1609
|
-
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
1610
|
-
__publicField(FuelGraphqlSubscriber, "incompatibleNodeVersionMessage", false);
|
1611
|
-
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
1612
1596
|
|
1613
1597
|
// src/providers/resource-cache.ts
|
1614
|
-
import { FuelError as
|
1598
|
+
import { FuelError as FuelError13, ErrorCode as ErrorCode10 } from "@fuel-ts/errors";
|
1615
1599
|
import { hexlify as hexlify16 } from "@fuel-ts/utils";
|
1616
1600
|
|
1617
1601
|
// src/providers/transaction-request/input.ts
|
1618
1602
|
import { BYTES_32 as BYTES_322, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1619
1603
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1620
|
-
import { ErrorCode as ErrorCode3, FuelError as
|
1604
|
+
import { ErrorCode as ErrorCode3, FuelError as FuelError4 } from "@fuel-ts/errors";
|
1621
1605
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1622
1606
|
import { InputType } from "@fuel-ts/transactions";
|
1623
1607
|
import { arrayify as arrayify2, hexlify as hexlify4 } from "@fuel-ts/utils";
|
1624
|
-
var inputify = (value) => {
|
1608
|
+
var inputify = /* @__PURE__ */ __name((value) => {
|
1625
1609
|
const { type } = value;
|
1626
1610
|
switch (value.type) {
|
1627
1611
|
case InputType.Coin: {
|
@@ -1681,21 +1665,21 @@ var inputify = (value) => {
|
|
1681
1665
|
};
|
1682
1666
|
}
|
1683
1667
|
default: {
|
1684
|
-
throw new
|
1668
|
+
throw new FuelError4(
|
1685
1669
|
ErrorCode3.INVALID_TRANSACTION_INPUT,
|
1686
1670
|
`Invalid transaction input type: ${type}.`
|
1687
1671
|
);
|
1688
1672
|
}
|
1689
1673
|
}
|
1690
|
-
};
|
1674
|
+
}, "inputify");
|
1691
1675
|
|
1692
1676
|
// src/providers/transaction-request/output.ts
|
1693
1677
|
import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
1694
|
-
import { ErrorCode as ErrorCode4, FuelError as
|
1678
|
+
import { ErrorCode as ErrorCode4, FuelError as FuelError5 } from "@fuel-ts/errors";
|
1695
1679
|
import { bn as bn3 } from "@fuel-ts/math";
|
1696
1680
|
import { OutputType } from "@fuel-ts/transactions";
|
1697
1681
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
1698
|
-
var outputify = (value) => {
|
1682
|
+
var outputify = /* @__PURE__ */ __name((value) => {
|
1699
1683
|
const { type } = value;
|
1700
1684
|
switch (type) {
|
1701
1685
|
case OutputType.Coin: {
|
@@ -1738,20 +1722,20 @@ var outputify = (value) => {
|
|
1738
1722
|
};
|
1739
1723
|
}
|
1740
1724
|
default: {
|
1741
|
-
throw new
|
1725
|
+
throw new FuelError5(
|
1742
1726
|
ErrorCode4.INVALID_TRANSACTION_INPUT,
|
1743
1727
|
`Invalid transaction output type: ${type}.`
|
1744
1728
|
);
|
1745
1729
|
}
|
1746
1730
|
}
|
1747
|
-
};
|
1731
|
+
}, "outputify");
|
1748
1732
|
|
1749
1733
|
// src/providers/transaction-request/transaction-request.ts
|
1750
1734
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1751
1735
|
import { Address as Address2, addressify } from "@fuel-ts/address";
|
1752
1736
|
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1753
1737
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
1754
|
-
import { FuelError as
|
1738
|
+
import { FuelError as FuelError10 } from "@fuel-ts/errors";
|
1755
1739
|
import { bn as bn8 } from "@fuel-ts/math";
|
1756
1740
|
import {
|
1757
1741
|
PolicyType,
|
@@ -1763,10 +1747,10 @@ import {
|
|
1763
1747
|
import { concat as concat2, hexlify as hexlify10, isDefined } from "@fuel-ts/utils";
|
1764
1748
|
|
1765
1749
|
// src/providers/message.ts
|
1766
|
-
var isMessageCoin = (message) => !("data" in message);
|
1750
|
+
var isMessageCoin = /* @__PURE__ */ __name((message) => !("data" in message), "isMessageCoin");
|
1767
1751
|
|
1768
1752
|
// src/providers/resource.ts
|
1769
|
-
var isCoin = (resource) => "id" in resource;
|
1753
|
+
var isCoin = /* @__PURE__ */ __name((resource) => "id" in resource, "isCoin");
|
1770
1754
|
|
1771
1755
|
// src/providers/utils/receipts.ts
|
1772
1756
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
@@ -1774,11 +1758,11 @@ import { FAILED_TRANSFER_TO_ADDRESS_SIGNAL } from "@fuel-ts/transactions/configs
|
|
1774
1758
|
|
1775
1759
|
// src/providers/utils/serialization.ts
|
1776
1760
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
1777
|
-
import { ErrorCode as ErrorCode5, FuelError as
|
1761
|
+
import { ErrorCode as ErrorCode5, FuelError as FuelError6 } from "@fuel-ts/errors";
|
1778
1762
|
import { bn as bn4 } from "@fuel-ts/math";
|
1779
1763
|
import { getMintedAssetId, InputMessageCoder, ReceiptType } from "@fuel-ts/transactions";
|
1780
1764
|
import { hexlify as hexlify6, arrayify as arrayify3 } from "@fuel-ts/utils";
|
1781
|
-
var deserializeChain = (chain) => {
|
1765
|
+
var deserializeChain = /* @__PURE__ */ __name((chain) => {
|
1782
1766
|
const { name, daHeight, consensusParameters } = chain;
|
1783
1767
|
const {
|
1784
1768
|
contractParams,
|
@@ -1832,8 +1816,8 @@ var deserializeChain = (chain) => {
|
|
1832
1816
|
gasCosts
|
1833
1817
|
}
|
1834
1818
|
};
|
1835
|
-
};
|
1836
|
-
var serializeChain = (chain) => {
|
1819
|
+
}, "deserializeChain");
|
1820
|
+
var serializeChain = /* @__PURE__ */ __name((chain) => {
|
1837
1821
|
const { name, baseChainHeight, consensusParameters } = chain;
|
1838
1822
|
const {
|
1839
1823
|
contractParameters,
|
@@ -1887,39 +1871,41 @@ var serializeChain = (chain) => {
|
|
1887
1871
|
gasCosts
|
1888
1872
|
}
|
1889
1873
|
};
|
1890
|
-
};
|
1891
|
-
var deserializeNodeInfo = (nodeInfo) => {
|
1892
|
-
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
1874
|
+
}, "serializeChain");
|
1875
|
+
var deserializeNodeInfo = /* @__PURE__ */ __name((nodeInfo) => {
|
1876
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace, indexation } = nodeInfo;
|
1893
1877
|
return {
|
1894
1878
|
maxDepth: bn4(maxDepth),
|
1895
1879
|
maxTx: bn4(maxTx),
|
1896
1880
|
nodeVersion,
|
1897
1881
|
utxoValidation,
|
1898
|
-
vmBacktrace
|
1882
|
+
vmBacktrace,
|
1883
|
+
indexation
|
1899
1884
|
};
|
1900
|
-
};
|
1901
|
-
var serializeNodeInfo = (nodeInfo) => {
|
1902
|
-
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
1885
|
+
}, "deserializeNodeInfo");
|
1886
|
+
var serializeNodeInfo = /* @__PURE__ */ __name((nodeInfo) => {
|
1887
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace, indexation } = nodeInfo;
|
1903
1888
|
return {
|
1904
1889
|
maxDepth: maxDepth.toString(),
|
1905
1890
|
maxTx: maxTx.toString(),
|
1906
1891
|
nodeVersion,
|
1907
1892
|
utxoValidation,
|
1908
|
-
vmBacktrace
|
1893
|
+
vmBacktrace,
|
1894
|
+
indexation
|
1909
1895
|
};
|
1910
|
-
};
|
1911
|
-
var deserializeProviderCache = (cache2) => ({
|
1896
|
+
}, "serializeNodeInfo");
|
1897
|
+
var deserializeProviderCache = /* @__PURE__ */ __name((cache2) => ({
|
1912
1898
|
consensusParametersTimestamp: cache2.consensusParametersTimestamp,
|
1913
1899
|
chain: deserializeChain(cache2.chain),
|
1914
1900
|
nodeInfo: deserializeNodeInfo(cache2.nodeInfo)
|
1915
|
-
});
|
1916
|
-
var serializeProviderCache = async (provider) => ({
|
1901
|
+
}), "deserializeProviderCache");
|
1902
|
+
var serializeProviderCache = /* @__PURE__ */ __name(async (provider) => ({
|
1917
1903
|
consensusParametersTimestamp: provider.consensusParametersTimestamp,
|
1918
1904
|
chain: serializeChain(await provider.getChain()),
|
1919
1905
|
nodeInfo: serializeNodeInfo(await provider.getNode())
|
1920
|
-
});
|
1921
|
-
var hexOrZero = (hex) => hex || ZeroBytes323;
|
1922
|
-
var deserializeReceipt = (receipt) => {
|
1906
|
+
}), "serializeProviderCache");
|
1907
|
+
var hexOrZero = /* @__PURE__ */ __name((hex) => hex || ZeroBytes323, "hexOrZero");
|
1908
|
+
var deserializeReceipt = /* @__PURE__ */ __name((receipt) => {
|
1923
1909
|
const { receiptType } = receipt;
|
1924
1910
|
switch (receiptType) {
|
1925
1911
|
case "CALL" /* Call */: {
|
@@ -2109,14 +2095,14 @@ var deserializeReceipt = (receipt) => {
|
|
2109
2095
|
return burnReceipt;
|
2110
2096
|
}
|
2111
2097
|
default:
|
2112
|
-
throw new
|
2098
|
+
throw new FuelError6(ErrorCode5.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
2113
2099
|
}
|
2114
|
-
};
|
2100
|
+
}, "deserializeReceipt");
|
2115
2101
|
|
2116
2102
|
// src/providers/utils/receipts.ts
|
2117
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType2.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
2118
|
-
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === ReceiptType2.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
2119
|
-
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
2103
|
+
var doesReceiptHaveMissingOutputVariables = /* @__PURE__ */ __name((receipt) => receipt.type === ReceiptType2.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL, "doesReceiptHaveMissingOutputVariables");
|
2104
|
+
var doesReceiptHaveMissingContractId = /* @__PURE__ */ __name((receipt) => receipt.type === ReceiptType2.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000", "doesReceiptHaveMissingContractId");
|
2105
|
+
var getReceiptsWithMissingData = /* @__PURE__ */ __name((receipts) => receipts.reduce(
|
2120
2106
|
(memo, receipt) => {
|
2121
2107
|
if (doesReceiptHaveMissingOutputVariables(receipt)) {
|
2122
2108
|
memo.missingOutputVariables.push(receipt);
|
@@ -2130,22 +2116,22 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
2130
2116
|
missingOutputVariables: [],
|
2131
2117
|
missingOutputContractIds: []
|
2132
2118
|
}
|
2133
|
-
);
|
2119
|
+
), "getReceiptsWithMissingData");
|
2134
2120
|
|
2135
2121
|
// src/providers/utils/block-explorer.ts
|
2136
|
-
import { ErrorCode as ErrorCode6, FuelError as
|
2122
|
+
import { ErrorCode as ErrorCode6, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2137
2123
|
|
2138
2124
|
// src/providers/utils/gas.ts
|
2139
2125
|
import { bn as bn5 } from "@fuel-ts/math";
|
2140
2126
|
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
2141
2127
|
import { arrayify as arrayify4 } from "@fuel-ts/utils";
|
2142
|
-
var getGasUsedFromReceipts = (receipts) => {
|
2128
|
+
var getGasUsedFromReceipts = /* @__PURE__ */ __name((receipts) => {
|
2143
2129
|
const scriptResult = receipts.filter(
|
2144
2130
|
(receipt) => receipt.type === ReceiptType3.ScriptResult
|
2145
2131
|
);
|
2146
2132
|
const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), bn5(0));
|
2147
2133
|
return gasUsed;
|
2148
|
-
};
|
2134
|
+
}, "getGasUsedFromReceipts");
|
2149
2135
|
function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
2150
2136
|
const base = bn5(gasDependentCost.base);
|
2151
2137
|
let dependentValue = bn5(0);
|
@@ -2156,6 +2142,7 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
2156
2142
|
}
|
2157
2143
|
return base.add(dependentValue);
|
2158
2144
|
}
|
2145
|
+
__name(resolveGasDependentCosts, "resolveGasDependentCosts");
|
2159
2146
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
2160
2147
|
const witnessCache = [];
|
2161
2148
|
const chargeableInputs = inputs.filter((input) => {
|
@@ -2182,6 +2169,7 @@ function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
|
2182
2169
|
}, bn5(0));
|
2183
2170
|
return totalGas;
|
2184
2171
|
}
|
2172
|
+
__name(gasUsedByInputs, "gasUsedByInputs");
|
2185
2173
|
function getMinGas(params) {
|
2186
2174
|
const { gasCosts, gasPerByte, inputs, metadataGas, txBytesSize } = params;
|
2187
2175
|
const vmInitGas = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
@@ -2190,6 +2178,7 @@ function getMinGas(params) {
|
|
2190
2178
|
const minGas = vmInitGas.add(bytesGas).add(inputsGas).add(metadataGas).maxU64();
|
2191
2179
|
return minGas;
|
2192
2180
|
}
|
2181
|
+
__name(getMinGas, "getMinGas");
|
2193
2182
|
function getMaxGas(params) {
|
2194
2183
|
const {
|
2195
2184
|
gasPerByte,
|
@@ -2206,6 +2195,7 @@ function getMaxGas(params) {
|
|
2206
2195
|
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
2207
2196
|
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
2208
2197
|
}
|
2198
|
+
__name(getMaxGas, "getMaxGas");
|
2209
2199
|
function calculateMetadataGasForTxCreate({
|
2210
2200
|
gasCosts,
|
2211
2201
|
stateRootSize,
|
@@ -2220,12 +2210,14 @@ function calculateMetadataGasForTxCreate({
|
|
2220
2210
|
const metadataGas = contractRootGas.add(stateRootGas).add(txIdGas).add(contractIdGas);
|
2221
2211
|
return metadataGas.maxU64();
|
2222
2212
|
}
|
2213
|
+
__name(calculateMetadataGasForTxCreate, "calculateMetadataGasForTxCreate");
|
2223
2214
|
function calculateMetadataGasForTxScript({
|
2224
2215
|
gasCosts,
|
2225
2216
|
txBytesSize
|
2226
2217
|
}) {
|
2227
2218
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
2228
2219
|
}
|
2220
|
+
__name(calculateMetadataGasForTxScript, "calculateMetadataGasForTxScript");
|
2229
2221
|
function calculateMetadataGasForTxBlob({
|
2230
2222
|
gasCosts,
|
2231
2223
|
txBytesSize,
|
@@ -2235,6 +2227,7 @@ function calculateMetadataGasForTxBlob({
|
|
2235
2227
|
const blobLen = resolveGasDependentCosts(witnessBytesSize, gasCosts.s256);
|
2236
2228
|
return txId.add(blobLen);
|
2237
2229
|
}
|
2230
|
+
__name(calculateMetadataGasForTxBlob, "calculateMetadataGasForTxBlob");
|
2238
2231
|
function calculateMetadataGasForTxUpgrade({
|
2239
2232
|
gasCosts,
|
2240
2233
|
txBytesSize,
|
@@ -2247,6 +2240,7 @@ function calculateMetadataGasForTxUpgrade({
|
|
2247
2240
|
}
|
2248
2241
|
return txId;
|
2249
2242
|
}
|
2243
|
+
__name(calculateMetadataGasForTxUpgrade, "calculateMetadataGasForTxUpgrade");
|
2250
2244
|
function calculateMetadataGasForTxUpload({
|
2251
2245
|
gasCosts,
|
2252
2246
|
txBytesSize,
|
@@ -2260,6 +2254,7 @@ function calculateMetadataGasForTxUpload({
|
|
2260
2254
|
txId.add(subsectionsLen);
|
2261
2255
|
return txId;
|
2262
2256
|
}
|
2257
|
+
__name(calculateMetadataGasForTxUpload, "calculateMetadataGasForTxUpload");
|
2263
2258
|
function calculateMinGasForTxUpload({
|
2264
2259
|
gasCosts,
|
2265
2260
|
baseMinGas,
|
@@ -2268,10 +2263,11 @@ function calculateMinGasForTxUpload({
|
|
2268
2263
|
const additionalStoragePerByte = bn5(gasCosts.newStoragePerByte).mul(subsectionSize);
|
2269
2264
|
return bn5(baseMinGas).add(additionalStoragePerByte);
|
2270
2265
|
}
|
2271
|
-
|
2266
|
+
__name(calculateMinGasForTxUpload, "calculateMinGasForTxUpload");
|
2267
|
+
var calculateGasFee = /* @__PURE__ */ __name((params) => {
|
2272
2268
|
const { gas, gasPrice, priceFactor, tip } = params;
|
2273
2269
|
return gas.mul(gasPrice).div(priceFactor).add(bn5(tip));
|
2274
|
-
};
|
2270
|
+
}, "calculateGasFee");
|
2275
2271
|
|
2276
2272
|
// src/providers/utils/json.ts
|
2277
2273
|
import { hexlify as hexlify7 } from "@fuel-ts/utils";
|
@@ -2300,12 +2296,14 @@ function normalize(object) {
|
|
2300
2296
|
});
|
2301
2297
|
return object;
|
2302
2298
|
}
|
2299
|
+
__name(normalize, "normalize");
|
2303
2300
|
function normalizeJSON(root) {
|
2304
2301
|
return normalize(clone(root));
|
2305
2302
|
}
|
2303
|
+
__name(normalizeJSON, "normalizeJSON");
|
2306
2304
|
|
2307
2305
|
// src/providers/utils/extract-tx-error.ts
|
2308
|
-
import { ErrorCode as ErrorCode7, FuelError as
|
2306
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2309
2307
|
import { bn as bn6 } from "@fuel-ts/math";
|
2310
2308
|
import { ReceiptType as ReceiptType4 } from "@fuel-ts/transactions";
|
2311
2309
|
import {
|
@@ -2317,7 +2315,7 @@ import {
|
|
2317
2315
|
PANIC_REASONS,
|
2318
2316
|
PANIC_DOC_URL
|
2319
2317
|
} from "@fuel-ts/transactions/configs";
|
2320
|
-
var assemblePanicError = (statusReason, metadata) => {
|
2318
|
+
var assemblePanicError = /* @__PURE__ */ __name((statusReason, metadata) => {
|
2321
2319
|
let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
|
2322
2320
|
if (PANIC_REASONS.includes(statusReason)) {
|
2323
2321
|
errorMessage = `${errorMessage}
|
@@ -2326,13 +2324,13 @@ You can read more about this error at:
|
|
2326
2324
|
|
2327
2325
|
${PANIC_DOC_URL}#variant.${statusReason}`;
|
2328
2326
|
}
|
2329
|
-
return new
|
2327
|
+
return new FuelError8(ErrorCode7.SCRIPT_REVERTED, errorMessage, {
|
2330
2328
|
...metadata,
|
2331
2329
|
reason: statusReason
|
2332
2330
|
});
|
2333
|
-
};
|
2334
|
-
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
2335
|
-
var assembleRevertError = (receipts, logs, metadata) => {
|
2331
|
+
}, "assemblePanicError");
|
2332
|
+
var stringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, null, 2), "stringify");
|
2333
|
+
var assembleRevertError = /* @__PURE__ */ __name((receipts, logs, metadata) => {
|
2336
2334
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
2337
2335
|
const revertReceipt = receipts.find(({ type }) => type === ReceiptType4.Revert);
|
2338
2336
|
let reason = "";
|
@@ -2367,7 +2365,7 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2367
2365
|
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
2368
2366
|
break;
|
2369
2367
|
default:
|
2370
|
-
throw new
|
2368
|
+
throw new FuelError8(
|
2371
2369
|
ErrorCode7.UNKNOWN,
|
2372
2370
|
`The transaction reverted with an unknown reason: ${revertReceipt.val}`,
|
2373
2371
|
{
|
@@ -2377,17 +2375,18 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2377
2375
|
);
|
2378
2376
|
}
|
2379
2377
|
}
|
2380
|
-
return new
|
2378
|
+
return new FuelError8(ErrorCode7.SCRIPT_REVERTED, errorMessage, {
|
2381
2379
|
...metadata,
|
2382
2380
|
reason
|
2383
2381
|
});
|
2384
|
-
};
|
2385
|
-
var extractTxError = (params) => {
|
2386
|
-
const { receipts, statusReason, logs } = params;
|
2382
|
+
}, "assembleRevertError");
|
2383
|
+
var extractTxError = /* @__PURE__ */ __name((params) => {
|
2384
|
+
const { receipts, statusReason, logs, groupedLogs } = params;
|
2387
2385
|
const isPanic = receipts.some(({ type }) => type === ReceiptType4.Panic);
|
2388
2386
|
const isRevert = receipts.some(({ type }) => type === ReceiptType4.Revert);
|
2389
2387
|
const metadata = {
|
2390
2388
|
logs,
|
2389
|
+
groupedLogs,
|
2391
2390
|
receipts,
|
2392
2391
|
panic: isPanic,
|
2393
2392
|
revert: isRevert,
|
@@ -2397,7 +2396,7 @@ var extractTxError = (params) => {
|
|
2397
2396
|
return assemblePanicError(statusReason, metadata);
|
2398
2397
|
}
|
2399
2398
|
return assembleRevertError(receipts, logs, metadata);
|
2400
|
-
};
|
2399
|
+
}, "extractTxError");
|
2401
2400
|
|
2402
2401
|
// src/providers/transaction-request/errors.ts
|
2403
2402
|
var NoWitnessAtIndexError = class extends Error {
|
@@ -2406,23 +2405,26 @@ var NoWitnessAtIndexError = class extends Error {
|
|
2406
2405
|
this.index = index;
|
2407
2406
|
this.message = `Witness at index "${index}" was not found`;
|
2408
2407
|
}
|
2408
|
+
static {
|
2409
|
+
__name(this, "NoWitnessAtIndexError");
|
2410
|
+
}
|
2409
2411
|
name = "NoWitnessAtIndexError";
|
2410
2412
|
};
|
2411
2413
|
|
2412
2414
|
// src/providers/transaction-request/helpers.ts
|
2413
|
-
import { ErrorCode as ErrorCode8, FuelError as
|
2415
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2414
2416
|
import { bn as bn7 } from "@fuel-ts/math";
|
2415
2417
|
import { InputType as InputType2, OutputType as OutputType2 } from "@fuel-ts/transactions";
|
2416
2418
|
import { hexlify as hexlify8 } from "@fuel-ts/utils";
|
2417
|
-
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
2418
|
-
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
2419
|
-
var isRequestInputMessageWithoutData = (input) => input.type === InputType2.Message && bn7(input.data).isZero();
|
2420
|
-
var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
2421
|
-
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2422
|
-
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2423
|
-
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
2424
|
-
var isPredicate = (input) => isRequestInputCoinOrMessage(input) && !!input.predicate && hexlify8(input.predicate) !== "0x";
|
2425
|
-
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
2419
|
+
var isRequestInputCoin = /* @__PURE__ */ __name((input) => input.type === InputType2.Coin, "isRequestInputCoin");
|
2420
|
+
var isRequestInputMessage = /* @__PURE__ */ __name((input) => input.type === InputType2.Message, "isRequestInputMessage");
|
2421
|
+
var isRequestInputMessageWithoutData = /* @__PURE__ */ __name((input) => input.type === InputType2.Message && bn7(input.data).isZero(), "isRequestInputMessageWithoutData");
|
2422
|
+
var isRequestInputCoinOrMessage = /* @__PURE__ */ __name((input) => isRequestInputCoin(input) || isRequestInputMessage(input), "isRequestInputCoinOrMessage");
|
2423
|
+
var isRequestInputResource = /* @__PURE__ */ __name((input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input), "isRequestInputResource");
|
2424
|
+
var getRequestInputResourceOwner = /* @__PURE__ */ __name((input) => isRequestInputCoin(input) ? input.owner : input.recipient, "getRequestInputResourceOwner");
|
2425
|
+
var isRequestInputResourceFromOwner = /* @__PURE__ */ __name((input, owner) => getRequestInputResourceOwner(input) === owner.toB256(), "isRequestInputResourceFromOwner");
|
2426
|
+
var isPredicate = /* @__PURE__ */ __name((input) => isRequestInputCoinOrMessage(input) && !!input.predicate && hexlify8(input.predicate) !== "0x", "isPredicate");
|
2427
|
+
var getAssetAmountInRequestInputs = /* @__PURE__ */ __name((inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
2426
2428
|
if (isRequestInputCoin(input) && input.assetId === assetId) {
|
2427
2429
|
return acc.add(input.amount);
|
2428
2430
|
}
|
@@ -2430,8 +2432,8 @@ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filte
|
|
2430
2432
|
return acc.add(input.amount);
|
2431
2433
|
}
|
2432
2434
|
return acc;
|
2433
|
-
}, bn7(0));
|
2434
|
-
var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
2435
|
+
}, bn7(0)), "getAssetAmountInRequestInputs");
|
2436
|
+
var cacheRequestInputsResourcesFromOwner = /* @__PURE__ */ __name((inputs, owner) => inputs.reduce(
|
2435
2437
|
(acc, input) => {
|
2436
2438
|
if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
|
2437
2439
|
acc.utxos.push(input.id);
|
@@ -2444,8 +2446,8 @@ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
|
2444
2446
|
utxos: [],
|
2445
2447
|
messages: []
|
2446
2448
|
}
|
2447
|
-
);
|
2448
|
-
var getBurnableAssetCount = (baseAssetId, transactionRequest) => {
|
2449
|
+
), "cacheRequestInputsResourcesFromOwner");
|
2450
|
+
var getBurnableAssetCount = /* @__PURE__ */ __name((baseAssetId, transactionRequest) => {
|
2449
2451
|
const { inputs, outputs } = transactionRequest;
|
2450
2452
|
const coinInputs = new Set(inputs.filter(isRequestInputCoin).map((input) => input.assetId));
|
2451
2453
|
if (inputs.some((i) => isRequestInputMessage(i) && bn7(i.amount).gt(0))) {
|
@@ -2456,8 +2458,8 @@ var getBurnableAssetCount = (baseAssetId, transactionRequest) => {
|
|
2456
2458
|
);
|
2457
2459
|
const difference = new Set([...coinInputs].filter((x) => !changeOutputs.has(x)));
|
2458
2460
|
return difference.size;
|
2459
|
-
};
|
2460
|
-
var validateTransactionForAssetBurn = (baseAssetId, transactionRequest, enableAssetBurn = false) => {
|
2461
|
+
}, "getBurnableAssetCount");
|
2462
|
+
var validateTransactionForAssetBurn = /* @__PURE__ */ __name((baseAssetId, transactionRequest, enableAssetBurn = false) => {
|
2461
2463
|
if (enableAssetBurn === true) {
|
2462
2464
|
return;
|
2463
2465
|
}
|
@@ -2469,21 +2471,24 @@ var validateTransactionForAssetBurn = (baseAssetId, transactionRequest, enableAs
|
|
2469
2471
|
"Add the relevant change outputs to the transaction to avoid burning assets.",
|
2470
2472
|
"Or enable asset burn, upon sending the transaction."
|
2471
2473
|
].join("\n");
|
2472
|
-
throw new
|
2473
|
-
};
|
2474
|
+
throw new FuelError9(ErrorCode8.ASSET_BURN_DETECTED, message);
|
2475
|
+
}, "validateTransactionForAssetBurn");
|
2474
2476
|
|
2475
2477
|
// src/providers/transaction-request/witness.ts
|
2476
2478
|
import { arrayify as arrayify5, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2477
|
-
var witnessify = (value) => {
|
2479
|
+
var witnessify = /* @__PURE__ */ __name((value) => {
|
2478
2480
|
const data = arrayify5(value);
|
2479
2481
|
return {
|
2480
2482
|
data: hexlify9(data),
|
2481
2483
|
dataLength: data.length
|
2482
2484
|
};
|
2483
|
-
};
|
2485
|
+
}, "witnessify");
|
2484
2486
|
|
2485
2487
|
// src/providers/transaction-request/transaction-request.ts
|
2486
|
-
var BaseTransactionRequest = class {
|
2488
|
+
var BaseTransactionRequest = class _BaseTransactionRequest {
|
2489
|
+
static {
|
2490
|
+
__name(this, "BaseTransactionRequest");
|
2491
|
+
}
|
2487
2492
|
/** Gas price for transaction */
|
2488
2493
|
tip;
|
2489
2494
|
/** Block until which tx cannot be included */
|
@@ -2566,7 +2571,7 @@ var BaseTransactionRequest = class {
|
|
2566
2571
|
const inputs = this.inputs?.map(inputify) ?? [];
|
2567
2572
|
const outputs = this.outputs?.map(outputify) ?? [];
|
2568
2573
|
const witnesses = this.witnesses?.map(witnessify) ?? [];
|
2569
|
-
const { policyTypes, policies } =
|
2574
|
+
const { policyTypes, policies } = _BaseTransactionRequest.getPolicyMeta(this);
|
2570
2575
|
return {
|
2571
2576
|
policyTypes,
|
2572
2577
|
inputs,
|
@@ -2867,7 +2872,7 @@ var BaseTransactionRequest = class {
|
|
2867
2872
|
* @hidden
|
2868
2873
|
*/
|
2869
2874
|
metadataGas(_gasCosts) {
|
2870
|
-
throw new
|
2875
|
+
throw new FuelError10(FuelError10.CODES.NOT_IMPLEMENTED, "Not implemented");
|
2871
2876
|
}
|
2872
2877
|
/**
|
2873
2878
|
* @hidden
|
@@ -2914,13 +2919,13 @@ var BaseTransactionRequest = class {
|
|
2914
2919
|
* Please use `Account.generateFakeResources` along with `this.addResources` instead.
|
2915
2920
|
*/
|
2916
2921
|
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2917
|
-
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2922
|
+
const findAssetInput = /* @__PURE__ */ __name((assetId) => this.inputs.find((input) => {
|
2918
2923
|
if ("assetId" in input) {
|
2919
2924
|
return input.assetId === assetId;
|
2920
2925
|
}
|
2921
2926
|
return false;
|
2922
|
-
});
|
2923
|
-
const updateAssetInput = (assetId, quantity) => {
|
2927
|
+
}), "findAssetInput");
|
2928
|
+
const updateAssetInput = /* @__PURE__ */ __name((assetId, quantity) => {
|
2924
2929
|
const assetInput = findAssetInput(assetId);
|
2925
2930
|
let usedQuantity = quantity;
|
2926
2931
|
if (assetId === baseAssetId) {
|
@@ -2941,7 +2946,7 @@ var BaseTransactionRequest = class {
|
|
2941
2946
|
}
|
2942
2947
|
]);
|
2943
2948
|
}
|
2944
|
-
};
|
2949
|
+
}, "updateAssetInput");
|
2945
2950
|
updateAssetInput(baseAssetId, bn8(1e11));
|
2946
2951
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2947
2952
|
return this;
|
@@ -3029,6 +3034,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3029
3034
|
transaction.inputs = transaction.inputs.map((input) => {
|
3030
3035
|
const inputClone = clone2(input);
|
3031
3036
|
switch (inputClone.type) {
|
3037
|
+
// Zero out on signing: txPointer, predicateGasUsed
|
3032
3038
|
case InputType4.Coin: {
|
3033
3039
|
inputClone.txPointer = {
|
3034
3040
|
blockHeight: 0,
|
@@ -3037,10 +3043,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3037
3043
|
inputClone.predicateGasUsed = bn9(0);
|
3038
3044
|
return inputClone;
|
3039
3045
|
}
|
3046
|
+
// Zero out on signing: predicateGasUsed
|
3040
3047
|
case InputType4.Message: {
|
3041
3048
|
inputClone.predicateGasUsed = bn9(0);
|
3042
3049
|
return inputClone;
|
3043
3050
|
}
|
3051
|
+
// Zero out on signing: txID, outputIndex, balanceRoot, stateRoot, and txPointer
|
3044
3052
|
case InputType4.Contract: {
|
3045
3053
|
inputClone.txPointer = {
|
3046
3054
|
blockHeight: 0,
|
@@ -3059,15 +3067,18 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3059
3067
|
transaction.outputs = transaction.outputs.map((output) => {
|
3060
3068
|
const outputClone = clone2(output);
|
3061
3069
|
switch (outputClone.type) {
|
3070
|
+
// Zero out on signing: balanceRoot, stateRoot
|
3062
3071
|
case OutputType4.Contract: {
|
3063
3072
|
outputClone.balanceRoot = ZeroBytes325;
|
3064
3073
|
outputClone.stateRoot = ZeroBytes325;
|
3065
3074
|
return outputClone;
|
3066
3075
|
}
|
3076
|
+
// Zero out on signing: amount
|
3067
3077
|
case OutputType4.Change: {
|
3068
3078
|
outputClone.amount = bn9(0);
|
3069
3079
|
return outputClone;
|
3070
3080
|
}
|
3081
|
+
// Zero out on signing: amount, to and assetId
|
3071
3082
|
case OutputType4.Variable: {
|
3072
3083
|
outputClone.to = ZeroBytes325;
|
3073
3084
|
outputClone.amount = bn9(0);
|
@@ -3084,9 +3095,13 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3084
3095
|
const concatenatedData = concat3([chainIdBytes, new TransactionCoder2().encode(transaction)]);
|
3085
3096
|
return sha256(concatenatedData);
|
3086
3097
|
}
|
3098
|
+
__name(hashTransaction, "hashTransaction");
|
3087
3099
|
|
3088
3100
|
// src/providers/transaction-request/blob-transaction-request.ts
|
3089
3101
|
var BlobTransactionRequest = class extends BaseTransactionRequest {
|
3102
|
+
static {
|
3103
|
+
__name(this, "BlobTransactionRequest");
|
3104
|
+
}
|
3090
3105
|
static from(obj) {
|
3091
3106
|
return new this(clone3(obj));
|
3092
3107
|
}
|
@@ -3155,12 +3170,12 @@ import { clone as clone4 } from "ramda";
|
|
3155
3170
|
|
3156
3171
|
// src/providers/transaction-request/storage-slot.ts
|
3157
3172
|
import { arrayify as arrayify6, hexlify as hexlify11 } from "@fuel-ts/utils";
|
3158
|
-
var getStorageValue = (value) => {
|
3173
|
+
var getStorageValue = /* @__PURE__ */ __name((value) => {
|
3159
3174
|
const v = new Uint8Array(32);
|
3160
3175
|
v.set(arrayify6(value));
|
3161
3176
|
return v;
|
3162
|
-
};
|
3163
|
-
var storageSlotify = (storageSlot) => {
|
3177
|
+
}, "getStorageValue");
|
3178
|
+
var storageSlotify = /* @__PURE__ */ __name((storageSlot) => {
|
3164
3179
|
let key;
|
3165
3180
|
let value;
|
3166
3181
|
if (Array.isArray(storageSlot)) {
|
@@ -3174,10 +3189,13 @@ var storageSlotify = (storageSlot) => {
|
|
3174
3189
|
key: hexlify11(key),
|
3175
3190
|
value: hexlify11(getStorageValue(value))
|
3176
3191
|
};
|
3177
|
-
};
|
3192
|
+
}, "storageSlotify");
|
3178
3193
|
|
3179
3194
|
// src/providers/transaction-request/create-transaction-request.ts
|
3180
3195
|
var CreateTransactionRequest = class extends BaseTransactionRequest {
|
3196
|
+
static {
|
3197
|
+
__name(this, "CreateTransactionRequest");
|
3198
|
+
}
|
3181
3199
|
static from(obj) {
|
3182
3200
|
return new this(clone4(obj));
|
3183
3201
|
}
|
@@ -3279,7 +3297,7 @@ var returnZeroScript = {
|
|
3279
3297
|
*/
|
3280
3298
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
3281
3299
|
bytes: arrayify8("0x24000000"),
|
3282
|
-
encodeScriptData: () => new Uint8Array(0)
|
3300
|
+
encodeScriptData: /* @__PURE__ */ __name(() => new Uint8Array(0), "encodeScriptData")
|
3283
3301
|
};
|
3284
3302
|
var withdrawScript = {
|
3285
3303
|
/*
|
@@ -3293,11 +3311,14 @@ var withdrawScript = {
|
|
3293
3311
|
*/
|
3294
3312
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
3295
3313
|
bytes: arrayify8("0x5040C0105D44C0064C40001124000000"),
|
3296
|
-
encodeScriptData: () => new Uint8Array(0)
|
3314
|
+
encodeScriptData: /* @__PURE__ */ __name(() => new Uint8Array(0), "encodeScriptData")
|
3297
3315
|
};
|
3298
3316
|
|
3299
3317
|
// src/providers/transaction-request/script-transaction-request.ts
|
3300
3318
|
var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
3319
|
+
static {
|
3320
|
+
__name(this, "ScriptTransactionRequest");
|
3321
|
+
}
|
3301
3322
|
static from(obj) {
|
3302
3323
|
return new this(clone5(obj));
|
3303
3324
|
}
|
@@ -3490,7 +3511,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3490
3511
|
};
|
3491
3512
|
|
3492
3513
|
// src/providers/transaction-request/upgrade-transaction-request.ts
|
3493
|
-
import { FuelError as
|
3514
|
+
import { FuelError as FuelError11 } from "@fuel-ts/errors";
|
3494
3515
|
import { hash as hash2 } from "@fuel-ts/hasher";
|
3495
3516
|
import {
|
3496
3517
|
TransactionType as TransactionType5,
|
@@ -3498,9 +3519,12 @@ import {
|
|
3498
3519
|
} from "@fuel-ts/transactions";
|
3499
3520
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
3500
3521
|
import { clone as clone6 } from "ramda";
|
3501
|
-
var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
3522
|
+
var UpgradeTransactionRequest = class _UpgradeTransactionRequest extends BaseTransactionRequest {
|
3523
|
+
static {
|
3524
|
+
__name(this, "UpgradeTransactionRequest");
|
3525
|
+
}
|
3502
3526
|
static from(obj) {
|
3503
|
-
if (obj instanceof
|
3527
|
+
if (obj instanceof _UpgradeTransactionRequest) {
|
3504
3528
|
return obj;
|
3505
3529
|
}
|
3506
3530
|
return new this(clone6(obj));
|
@@ -3597,7 +3621,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3597
3621
|
}
|
3598
3622
|
};
|
3599
3623
|
} else {
|
3600
|
-
throw new
|
3624
|
+
throw new FuelError11(FuelError11.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3601
3625
|
}
|
3602
3626
|
return {
|
3603
3627
|
type: TransactionType5.Upgrade,
|
@@ -3639,7 +3663,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3639
3663
|
txBytesSize
|
3640
3664
|
});
|
3641
3665
|
}
|
3642
|
-
throw new
|
3666
|
+
throw new FuelError11(FuelError11.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3643
3667
|
}
|
3644
3668
|
};
|
3645
3669
|
|
@@ -3648,9 +3672,12 @@ import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
|
3648
3672
|
import { TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
3649
3673
|
import { arrayify as arrayify10, hexlify as hexlify15 } from "@fuel-ts/utils";
|
3650
3674
|
import { clone as clone7 } from "ramda";
|
3651
|
-
var UploadTransactionRequest = class extends BaseTransactionRequest {
|
3675
|
+
var UploadTransactionRequest = class _UploadTransactionRequest extends BaseTransactionRequest {
|
3676
|
+
static {
|
3677
|
+
__name(this, "UploadTransactionRequest");
|
3678
|
+
}
|
3652
3679
|
static from(obj) {
|
3653
|
-
if (obj instanceof
|
3680
|
+
if (obj instanceof _UploadTransactionRequest) {
|
3654
3681
|
return obj;
|
3655
3682
|
}
|
3656
3683
|
return new this(clone7(obj));
|
@@ -3750,9 +3777,9 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
3750
3777
|
};
|
3751
3778
|
|
3752
3779
|
// src/providers/transaction-request/utils.ts
|
3753
|
-
import { ErrorCode as ErrorCode9, FuelError as
|
3780
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError12 } from "@fuel-ts/errors";
|
3754
3781
|
import { TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
3755
|
-
var transactionRequestify = (obj) => {
|
3782
|
+
var transactionRequestify = /* @__PURE__ */ __name((obj) => {
|
3756
3783
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest || obj instanceof UpgradeTransactionRequest || obj instanceof UploadTransactionRequest) {
|
3757
3784
|
return obj;
|
3758
3785
|
}
|
@@ -3774,24 +3801,27 @@ var transactionRequestify = (obj) => {
|
|
3774
3801
|
return UploadTransactionRequest.from(obj);
|
3775
3802
|
}
|
3776
3803
|
default: {
|
3777
|
-
throw new
|
3804
|
+
throw new FuelError12(
|
3778
3805
|
ErrorCode9.UNSUPPORTED_TRANSACTION_TYPE,
|
3779
3806
|
`Unsupported transaction type: ${type}.`
|
3780
3807
|
);
|
3781
3808
|
}
|
3782
3809
|
}
|
3783
|
-
};
|
3784
|
-
var isTransactionTypeScript = (request) => request.type === TransactionType7.Script;
|
3785
|
-
var isTransactionTypeCreate = (request) => request.type === TransactionType7.Create;
|
3810
|
+
}, "transactionRequestify");
|
3811
|
+
var isTransactionTypeScript = /* @__PURE__ */ __name((request) => request.type === TransactionType7.Script, "isTransactionTypeScript");
|
3812
|
+
var isTransactionTypeCreate = /* @__PURE__ */ __name((request) => request.type === TransactionType7.Create, "isTransactionTypeCreate");
|
3786
3813
|
|
3787
3814
|
// src/providers/resource-cache.ts
|
3788
3815
|
var cache = /* @__PURE__ */ new Map();
|
3789
3816
|
var ResourceCache = class {
|
3817
|
+
static {
|
3818
|
+
__name(this, "ResourceCache");
|
3819
|
+
}
|
3790
3820
|
ttl;
|
3791
3821
|
constructor(ttl) {
|
3792
3822
|
this.ttl = ttl;
|
3793
3823
|
if (typeof ttl !== "number" || this.ttl <= 0) {
|
3794
|
-
throw new
|
3824
|
+
throw new FuelError13(
|
3795
3825
|
ErrorCode10.INVALID_TTL,
|
3796
3826
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
3797
3827
|
);
|
@@ -3876,7 +3906,7 @@ var ResourceCache = class {
|
|
3876
3906
|
};
|
3877
3907
|
|
3878
3908
|
// src/providers/transaction-response/transaction-response.ts
|
3879
|
-
import { ErrorCode as ErrorCode14, FuelError as
|
3909
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError17 } from "@fuel-ts/errors";
|
3880
3910
|
import { bn as bn16 } from "@fuel-ts/math";
|
3881
3911
|
import { OutputType as OutputType8, TransactionCoder as TransactionCoder4, TxPointerCoder } from "@fuel-ts/transactions";
|
3882
3912
|
import { arrayify as arrayify12, assertUnreachable } from "@fuel-ts/utils";
|
@@ -3890,7 +3920,7 @@ import { DateTime, hexlify as hexlify17 } from "@fuel-ts/utils";
|
|
3890
3920
|
import { bn as bn12 } from "@fuel-ts/math";
|
3891
3921
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType8 } from "@fuel-ts/transactions";
|
3892
3922
|
import { arrayify as arrayify11 } from "@fuel-ts/utils";
|
3893
|
-
var calculateTXFeeForSummary = (params) => {
|
3923
|
+
var calculateTXFeeForSummary = /* @__PURE__ */ __name((params) => {
|
3894
3924
|
const {
|
3895
3925
|
gasPrice,
|
3896
3926
|
rawPayload,
|
@@ -3950,43 +3980,51 @@ var calculateTXFeeForSummary = (params) => {
|
|
3950
3980
|
tip
|
3951
3981
|
});
|
3952
3982
|
return maxFee;
|
3953
|
-
};
|
3983
|
+
}, "calculateTXFeeForSummary");
|
3954
3984
|
|
3955
3985
|
// src/providers/transaction-summary/operations.ts
|
3956
3986
|
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
3957
|
-
import { ErrorCode as ErrorCode12, FuelError as
|
3987
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError15 } from "@fuel-ts/errors";
|
3958
3988
|
import { bn as bn13 } from "@fuel-ts/math";
|
3959
3989
|
import { ReceiptType as ReceiptType5, TransactionType as TransactionType9 } from "@fuel-ts/transactions";
|
3960
3990
|
|
3961
3991
|
// src/providers/transaction-summary/input.ts
|
3962
|
-
import { ErrorCode as ErrorCode11, FuelError as
|
3992
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError14 } from "@fuel-ts/errors";
|
3963
3993
|
import { BN } from "@fuel-ts/math";
|
3964
3994
|
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
3965
3995
|
function getInputsByTypes(inputs, types) {
|
3966
3996
|
return inputs.filter((i) => types.includes(i.type));
|
3967
3997
|
}
|
3998
|
+
__name(getInputsByTypes, "getInputsByTypes");
|
3968
3999
|
function getInputsByType(inputs, type) {
|
3969
4000
|
return inputs.filter((i) => i.type === type);
|
3970
4001
|
}
|
4002
|
+
__name(getInputsByType, "getInputsByType");
|
3971
4003
|
function getInputsCoin(inputs) {
|
3972
4004
|
return getInputsByType(inputs, InputType6.Coin);
|
3973
4005
|
}
|
4006
|
+
__name(getInputsCoin, "getInputsCoin");
|
3974
4007
|
function getInputsMessage(inputs) {
|
3975
4008
|
return getInputsByType(inputs, InputType6.Message);
|
3976
4009
|
}
|
4010
|
+
__name(getInputsMessage, "getInputsMessage");
|
3977
4011
|
function getInputsCoinAndMessage(inputs) {
|
3978
4012
|
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
3979
4013
|
}
|
4014
|
+
__name(getInputsCoinAndMessage, "getInputsCoinAndMessage");
|
3980
4015
|
function isInputCoin(input) {
|
3981
4016
|
return input.type === InputType6.Coin;
|
3982
4017
|
}
|
4018
|
+
__name(isInputCoin, "isInputCoin");
|
3983
4019
|
function getInputsContract(inputs) {
|
3984
4020
|
return getInputsByType(inputs, InputType6.Contract);
|
3985
4021
|
}
|
4022
|
+
__name(getInputsContract, "getInputsContract");
|
3986
4023
|
function findCoinInput(inputs, assetId) {
|
3987
4024
|
const coinInputs = getInputsCoin(inputs);
|
3988
4025
|
return coinInputs.find((i) => i.assetId === assetId);
|
3989
4026
|
}
|
4027
|
+
__name(findCoinInput, "findCoinInput");
|
3990
4028
|
function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId) {
|
3991
4029
|
const aggregated = /* @__PURE__ */ new Map();
|
3992
4030
|
getInputsCoinAndMessage(inputs).forEach((input) => {
|
@@ -4006,9 +4044,11 @@ function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId) {
|
|
4006
4044
|
});
|
4007
4045
|
return aggregated;
|
4008
4046
|
}
|
4047
|
+
__name(aggregateInputsAmountsByAssetAndOwner, "aggregateInputsAmountsByAssetAndOwner");
|
4009
4048
|
function findMessageInput(inputs) {
|
4010
4049
|
return getInputsMessage(inputs)?.[0];
|
4011
4050
|
}
|
4051
|
+
__name(findMessageInput, "findMessageInput");
|
4012
4052
|
function getInputFromAssetId(inputs, assetId, isBaseAsset = false) {
|
4013
4053
|
const coinInput = findCoinInput(inputs, assetId);
|
4014
4054
|
if (coinInput) {
|
@@ -4019,6 +4059,7 @@ function getInputFromAssetId(inputs, assetId, isBaseAsset = false) {
|
|
4019
4059
|
}
|
4020
4060
|
return void 0;
|
4021
4061
|
}
|
4062
|
+
__name(getInputFromAssetId, "getInputFromAssetId");
|
4022
4063
|
function getInputContractFromIndex(inputs, inputIndex) {
|
4023
4064
|
if (inputIndex == null) {
|
4024
4065
|
return void 0;
|
@@ -4028,13 +4069,14 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
4028
4069
|
return void 0;
|
4029
4070
|
}
|
4030
4071
|
if (contractInput.type !== InputType6.Contract) {
|
4031
|
-
throw new
|
4072
|
+
throw new FuelError14(
|
4032
4073
|
ErrorCode11.INVALID_TRANSACTION_INPUT,
|
4033
4074
|
`Contract input should be of type 'contract'.`
|
4034
4075
|
);
|
4035
4076
|
}
|
4036
4077
|
return contractInput;
|
4037
4078
|
}
|
4079
|
+
__name(getInputContractFromIndex, "getInputContractFromIndex");
|
4038
4080
|
function getInputAccountAddress(input) {
|
4039
4081
|
if (input.type === InputType6.Coin) {
|
4040
4082
|
return input.owner.toString();
|
@@ -4044,29 +4086,36 @@ function getInputAccountAddress(input) {
|
|
4044
4086
|
}
|
4045
4087
|
return "";
|
4046
4088
|
}
|
4089
|
+
__name(getInputAccountAddress, "getInputAccountAddress");
|
4047
4090
|
|
4048
4091
|
// src/providers/transaction-summary/output.ts
|
4049
4092
|
import { OutputType as OutputType7 } from "@fuel-ts/transactions";
|
4050
4093
|
function getOutputsByType(outputs, type) {
|
4051
4094
|
return outputs.filter((o) => o.type === type);
|
4052
4095
|
}
|
4096
|
+
__name(getOutputsByType, "getOutputsByType");
|
4053
4097
|
function getOutputsContractCreated(outputs) {
|
4054
4098
|
return getOutputsByType(outputs, OutputType7.ContractCreated);
|
4055
4099
|
}
|
4100
|
+
__name(getOutputsContractCreated, "getOutputsContractCreated");
|
4056
4101
|
function getOutputsCoin(outputs) {
|
4057
4102
|
return getOutputsByType(outputs, OutputType7.Coin);
|
4058
4103
|
}
|
4104
|
+
__name(getOutputsCoin, "getOutputsCoin");
|
4059
4105
|
function getOutputsChange(outputs) {
|
4060
4106
|
return getOutputsByType(outputs, OutputType7.Change);
|
4061
4107
|
}
|
4108
|
+
__name(getOutputsChange, "getOutputsChange");
|
4062
4109
|
function getOutputsContract(outputs) {
|
4063
4110
|
return getOutputsByType(outputs, OutputType7.Contract);
|
4064
4111
|
}
|
4112
|
+
__name(getOutputsContract, "getOutputsContract");
|
4065
4113
|
|
4066
4114
|
// src/providers/transaction-summary/operations.ts
|
4067
4115
|
function getReceiptsByType(receipts, type) {
|
4068
4116
|
return (receipts ?? []).filter((r) => r.type === type);
|
4069
4117
|
}
|
4118
|
+
__name(getReceiptsByType, "getReceiptsByType");
|
4070
4119
|
function getTransactionTypeName(transactionType) {
|
4071
4120
|
switch (transactionType) {
|
4072
4121
|
case TransactionType9.Mint:
|
@@ -4082,40 +4131,50 @@ function getTransactionTypeName(transactionType) {
|
|
4082
4131
|
case TransactionType9.Upload:
|
4083
4132
|
return "Upload" /* Upload */;
|
4084
4133
|
default:
|
4085
|
-
throw new
|
4134
|
+
throw new FuelError15(
|
4086
4135
|
ErrorCode12.UNSUPPORTED_TRANSACTION_TYPE,
|
4087
4136
|
`Unsupported transaction type: ${transactionType}.`
|
4088
4137
|
);
|
4089
4138
|
}
|
4090
4139
|
}
|
4140
|
+
__name(getTransactionTypeName, "getTransactionTypeName");
|
4091
4141
|
function isType(transactionType, type) {
|
4092
4142
|
const txType = getTransactionTypeName(transactionType);
|
4093
4143
|
return txType === type;
|
4094
4144
|
}
|
4145
|
+
__name(isType, "isType");
|
4095
4146
|
function isTypeMint(transactionType) {
|
4096
4147
|
return isType(transactionType, "Mint" /* Mint */);
|
4097
4148
|
}
|
4149
|
+
__name(isTypeMint, "isTypeMint");
|
4098
4150
|
function isTypeCreate(transactionType) {
|
4099
4151
|
return isType(transactionType, "Create" /* Create */);
|
4100
4152
|
}
|
4153
|
+
__name(isTypeCreate, "isTypeCreate");
|
4101
4154
|
function isTypeScript(transactionType) {
|
4102
4155
|
return isType(transactionType, "Script" /* Script */);
|
4103
4156
|
}
|
4157
|
+
__name(isTypeScript, "isTypeScript");
|
4104
4158
|
function isTypeUpgrade(transactionType) {
|
4105
4159
|
return isType(transactionType, "Upgrade" /* Upgrade */);
|
4106
4160
|
}
|
4161
|
+
__name(isTypeUpgrade, "isTypeUpgrade");
|
4107
4162
|
function isTypeUpload(transactionType) {
|
4108
4163
|
return isType(transactionType, "Upload" /* Upload */);
|
4109
4164
|
}
|
4165
|
+
__name(isTypeUpload, "isTypeUpload");
|
4110
4166
|
function isTypeBlob(transactionType) {
|
4111
4167
|
return isType(transactionType, "Blob" /* Blob */);
|
4112
4168
|
}
|
4169
|
+
__name(isTypeBlob, "isTypeBlob");
|
4113
4170
|
function getReceiptsCall(receipts) {
|
4114
4171
|
return getReceiptsByType(receipts, ReceiptType5.Call);
|
4115
4172
|
}
|
4173
|
+
__name(getReceiptsCall, "getReceiptsCall");
|
4116
4174
|
function getReceiptsMessageOut(receipts) {
|
4117
4175
|
return getReceiptsByType(receipts, ReceiptType5.MessageOut);
|
4118
4176
|
}
|
4177
|
+
__name(getReceiptsMessageOut, "getReceiptsMessageOut");
|
4119
4178
|
function mergeAssets(op1, op2) {
|
4120
4179
|
const assets1 = op1.assetsSent || [];
|
4121
4180
|
const assets2 = op2.assetsSent || [];
|
@@ -4133,21 +4192,25 @@ function mergeAssets(op1, op2) {
|
|
4133
4192
|
});
|
4134
4193
|
return Array.from(assetMap.values());
|
4135
4194
|
}
|
4195
|
+
__name(mergeAssets, "mergeAssets");
|
4136
4196
|
function isSameOperation(a, b) {
|
4137
4197
|
return a.name === b.name && a.from?.address === b.from?.address && a.to?.address === b.to?.address && a.from?.type === b.from?.type && a.to?.type === b.to?.type;
|
4138
4198
|
}
|
4199
|
+
__name(isSameOperation, "isSameOperation");
|
4139
4200
|
function mergeAssetsSent(existing, toAdd) {
|
4140
4201
|
if (!toAdd.assetsSent?.length) {
|
4141
4202
|
return existing.assetsSent;
|
4142
4203
|
}
|
4143
4204
|
return existing.assetsSent?.length ? mergeAssets(existing, toAdd) : toAdd.assetsSent;
|
4144
4205
|
}
|
4206
|
+
__name(mergeAssetsSent, "mergeAssetsSent");
|
4145
4207
|
function mergeCalls(existing, toAdd) {
|
4146
4208
|
if (!toAdd.calls?.length) {
|
4147
4209
|
return existing.calls;
|
4148
4210
|
}
|
4149
4211
|
return [...existing.calls || [], ...toAdd.calls];
|
4150
4212
|
}
|
4213
|
+
__name(mergeCalls, "mergeCalls");
|
4151
4214
|
function mergeOperations(existing, toAdd) {
|
4152
4215
|
return {
|
4153
4216
|
...existing,
|
@@ -4159,6 +4222,7 @@ function mergeOperations(existing, toAdd) {
|
|
4159
4222
|
]
|
4160
4223
|
};
|
4161
4224
|
}
|
4225
|
+
__name(mergeOperations, "mergeOperations");
|
4162
4226
|
function addOperation(operations, toAdd) {
|
4163
4227
|
const existingIndex = operations.findIndex((op) => isSameOperation(op, toAdd));
|
4164
4228
|
if (existingIndex === -1) {
|
@@ -4166,6 +4230,7 @@ function addOperation(operations, toAdd) {
|
|
4166
4230
|
}
|
4167
4231
|
return operations.map((op, index) => index === existingIndex ? mergeOperations(op, toAdd) : op);
|
4168
4232
|
}
|
4233
|
+
__name(addOperation, "addOperation");
|
4169
4234
|
function getWithdrawFromFuelOperations({
|
4170
4235
|
inputs,
|
4171
4236
|
receipts,
|
@@ -4204,6 +4269,7 @@ function getWithdrawFromFuelOperations({
|
|
4204
4269
|
);
|
4205
4270
|
return withdrawFromFuelOperations;
|
4206
4271
|
}
|
4272
|
+
__name(getWithdrawFromFuelOperations, "getWithdrawFromFuelOperations");
|
4207
4273
|
function getContractCalls(contractInput, abiMap, _receipt, _rawPayload, _maxInputs) {
|
4208
4274
|
const abi = abiMap?.[contractInput.contractID];
|
4209
4275
|
if (!abi) {
|
@@ -4211,6 +4277,7 @@ function getContractCalls(contractInput, abiMap, _receipt, _rawPayload, _maxInpu
|
|
4211
4277
|
}
|
4212
4278
|
return [];
|
4213
4279
|
}
|
4280
|
+
__name(getContractCalls, "getContractCalls");
|
4214
4281
|
function getAssetsSent(receipt) {
|
4215
4282
|
return receipt.amount?.isZero() ? void 0 : [
|
4216
4283
|
{
|
@@ -4219,6 +4286,7 @@ function getAssetsSent(receipt) {
|
|
4219
4286
|
}
|
4220
4287
|
];
|
4221
4288
|
}
|
4289
|
+
__name(getAssetsSent, "getAssetsSent");
|
4222
4290
|
function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload, maxInputs, baseAssetId) {
|
4223
4291
|
const assetId = receipt.assetId === ZeroBytes329 ? baseAssetId : receipt.assetId;
|
4224
4292
|
const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
|
@@ -4244,6 +4312,7 @@ function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload,
|
|
4244
4312
|
}
|
4245
4313
|
];
|
4246
4314
|
}
|
4315
|
+
__name(processCallReceipt, "processCallReceipt");
|
4247
4316
|
function getContractCallOperations({
|
4248
4317
|
inputs,
|
4249
4318
|
outputs,
|
@@ -4273,6 +4342,7 @@ function getContractCallOperations({
|
|
4273
4342
|
);
|
4274
4343
|
});
|
4275
4344
|
}
|
4345
|
+
__name(getContractCallOperations, "getContractCallOperations");
|
4276
4346
|
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
4277
4347
|
const { to: toAddress, assetId, amount } = receipt;
|
4278
4348
|
let { id: fromAddress } = receipt;
|
@@ -4301,6 +4371,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
4301
4371
|
receipts: [receipt]
|
4302
4372
|
};
|
4303
4373
|
}
|
4374
|
+
__name(extractTransferOperationFromReceipt, "extractTransferOperationFromReceipt");
|
4304
4375
|
function getTransferOperations({
|
4305
4376
|
inputs,
|
4306
4377
|
outputs,
|
@@ -4355,6 +4426,7 @@ function getTransferOperations({
|
|
4355
4426
|
});
|
4356
4427
|
return operations;
|
4357
4428
|
}
|
4429
|
+
__name(getTransferOperations, "getTransferOperations");
|
4358
4430
|
function getPayProducerOperations(outputs) {
|
4359
4431
|
const coinOutputs = getOutputsCoin(outputs);
|
4360
4432
|
const payProducerOperations = coinOutputs.reduce((prev, output) => {
|
@@ -4379,6 +4451,7 @@ function getPayProducerOperations(outputs) {
|
|
4379
4451
|
}, []);
|
4380
4452
|
return payProducerOperations;
|
4381
4453
|
}
|
4454
|
+
__name(getPayProducerOperations, "getPayProducerOperations");
|
4382
4455
|
function getContractCreatedOperations({ inputs, outputs }) {
|
4383
4456
|
const contractCreatedOutputs = getOutputsContractCreated(outputs);
|
4384
4457
|
const input = getInputsCoinAndMessage(inputs)[0];
|
@@ -4399,6 +4472,7 @@ function getContractCreatedOperations({ inputs, outputs }) {
|
|
4399
4472
|
}, []);
|
4400
4473
|
return contractCreatedOperations;
|
4401
4474
|
}
|
4475
|
+
__name(getContractCreatedOperations, "getContractCreatedOperations");
|
4402
4476
|
function getOperations({
|
4403
4477
|
transactionType,
|
4404
4478
|
inputs,
|
@@ -4429,10 +4503,11 @@ function getOperations({
|
|
4429
4503
|
}
|
4430
4504
|
return [...getPayProducerOperations(outputs)];
|
4431
4505
|
}
|
4506
|
+
__name(getOperations, "getOperations");
|
4432
4507
|
|
4433
4508
|
// src/providers/transaction-summary/receipt.ts
|
4434
4509
|
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
4435
|
-
var extractMintedAssetsFromReceipts = (receipts) => {
|
4510
|
+
var extractMintedAssetsFromReceipts = /* @__PURE__ */ __name((receipts) => {
|
4436
4511
|
const mintedAssets = [];
|
4437
4512
|
receipts.forEach((receipt) => {
|
4438
4513
|
if (receipt.type === ReceiptType6.Mint) {
|
@@ -4445,8 +4520,8 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
4445
4520
|
}
|
4446
4521
|
});
|
4447
4522
|
return mintedAssets;
|
4448
|
-
};
|
4449
|
-
var extractBurnedAssetsFromReceipts = (receipts) => {
|
4523
|
+
}, "extractMintedAssetsFromReceipts");
|
4524
|
+
var extractBurnedAssetsFromReceipts = /* @__PURE__ */ __name((receipts) => {
|
4450
4525
|
const burnedAssets = [];
|
4451
4526
|
receipts.forEach((receipt) => {
|
4452
4527
|
if (receipt.type === ReceiptType6.Burn) {
|
@@ -4459,12 +4534,12 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
4459
4534
|
}
|
4460
4535
|
});
|
4461
4536
|
return burnedAssets;
|
4462
|
-
};
|
4537
|
+
}, "extractBurnedAssetsFromReceipts");
|
4463
4538
|
|
4464
4539
|
// src/providers/transaction-summary/status.ts
|
4465
|
-
import { ErrorCode as ErrorCode13, FuelError as
|
4540
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError16 } from "@fuel-ts/errors";
|
4466
4541
|
import { bn as bn14 } from "@fuel-ts/math";
|
4467
|
-
var getTransactionStatusName = (gqlStatus) => {
|
4542
|
+
var getTransactionStatusName = /* @__PURE__ */ __name((gqlStatus) => {
|
4468
4543
|
switch (gqlStatus) {
|
4469
4544
|
case "FailureStatus":
|
4470
4545
|
return "failure" /* failure */;
|
@@ -4475,13 +4550,13 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
4475
4550
|
case "SqueezedOutStatus":
|
4476
4551
|
return "squeezedout" /* squeezedout */;
|
4477
4552
|
default:
|
4478
|
-
throw new
|
4553
|
+
throw new FuelError16(
|
4479
4554
|
ErrorCode13.INVALID_TRANSACTION_STATUS,
|
4480
4555
|
`Invalid transaction status: ${gqlStatus}.`
|
4481
4556
|
);
|
4482
4557
|
}
|
4483
|
-
};
|
4484
|
-
var processGraphqlStatus = (gqlTransactionStatus) => {
|
4558
|
+
}, "getTransactionStatusName");
|
4559
|
+
var processGraphqlStatus = /* @__PURE__ */ __name((gqlTransactionStatus) => {
|
4485
4560
|
let time;
|
4486
4561
|
let blockId;
|
4487
4562
|
let status;
|
@@ -4525,8 +4600,8 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
4525
4600
|
isStatusPending
|
4526
4601
|
};
|
4527
4602
|
return processedGraphqlStatus;
|
4528
|
-
};
|
4529
|
-
var getTotalFeeFromStatus = (status) => status && "totalFee" in status ? bn14(status.totalFee) : void 0;
|
4603
|
+
}, "processGraphqlStatus");
|
4604
|
+
var getTotalFeeFromStatus = /* @__PURE__ */ __name((status) => status && "totalFee" in status ? bn14(status.totalFee) : void 0, "getTotalFeeFromStatus");
|
4530
4605
|
|
4531
4606
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
4532
4607
|
function assembleTransactionSummary(params) {
|
@@ -4606,12 +4681,14 @@ function assembleTransactionSummary(params) {
|
|
4606
4681
|
};
|
4607
4682
|
return transactionSummary;
|
4608
4683
|
}
|
4684
|
+
__name(assembleTransactionSummary, "assembleTransactionSummary");
|
4609
4685
|
|
4610
|
-
// src/providers/transaction-response/
|
4686
|
+
// src/providers/transaction-response/getAllDecodedLogs.ts
|
4611
4687
|
import { Interface as Interface2, BigNumberCoder } from "@fuel-ts/abi-coder";
|
4612
4688
|
import { ZeroBytes32 as ZeroBytes3210 } from "@fuel-ts/address/configs";
|
4613
4689
|
import { ReceiptType as ReceiptType7 } from "@fuel-ts/transactions";
|
4614
|
-
function
|
4690
|
+
function getAllDecodedLogs(opts) {
|
4691
|
+
const { receipts, mainAbi, externalAbis = {} } = opts;
|
4615
4692
|
let mainContract = "";
|
4616
4693
|
if (mainAbi.programType === "contract") {
|
4617
4694
|
const firstCallReceipt = receipts.find(
|
@@ -4619,20 +4696,25 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
4619
4696
|
);
|
4620
4697
|
mainContract = firstCallReceipt.to;
|
4621
4698
|
}
|
4622
|
-
return receipts.reduce(
|
4623
|
-
|
4624
|
-
|
4625
|
-
|
4626
|
-
|
4627
|
-
|
4628
|
-
|
4629
|
-
|
4630
|
-
|
4699
|
+
return receipts.reduce(
|
4700
|
+
({ logs, groupedLogs }, receipt) => {
|
4701
|
+
if (receipt.type === ReceiptType7.LogData || receipt.type === ReceiptType7.Log) {
|
4702
|
+
const isLogFromMainAbi = receipt.id === ZeroBytes3210 || mainContract === receipt.id;
|
4703
|
+
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
4704
|
+
if (isDecodable) {
|
4705
|
+
const interfaceToUse = isLogFromMainAbi ? new Interface2(mainAbi) : new Interface2(externalAbis[receipt.id]);
|
4706
|
+
const data = receipt.type === ReceiptType7.Log ? new BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
4707
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
4708
|
+
logs.push(decodedLog);
|
4709
|
+
groupedLogs[receipt.id] = [...groupedLogs[receipt.id] || [], decodedLog];
|
4710
|
+
}
|
4631
4711
|
}
|
4632
|
-
|
4633
|
-
|
4634
|
-
|
4712
|
+
return { logs, groupedLogs };
|
4713
|
+
},
|
4714
|
+
{ logs: [], groupedLogs: {} }
|
4715
|
+
);
|
4635
4716
|
}
|
4717
|
+
__name(getAllDecodedLogs, "getAllDecodedLogs");
|
4636
4718
|
|
4637
4719
|
// src/providers/transaction-response/transaction-response.ts
|
4638
4720
|
function mapGqlOutputsToTxOutputs(outputs) {
|
@@ -4665,7 +4747,8 @@ function mapGqlOutputsToTxOutputs(outputs) {
|
|
4665
4747
|
}
|
4666
4748
|
});
|
4667
4749
|
}
|
4668
|
-
|
4750
|
+
__name(mapGqlOutputsToTxOutputs, "mapGqlOutputsToTxOutputs");
|
4751
|
+
var TransactionResponse = class _TransactionResponse {
|
4669
4752
|
/**
|
4670
4753
|
* Constructor for `TransactionResponse`.
|
4671
4754
|
*
|
@@ -4680,6 +4763,9 @@ var TransactionResponse = class {
|
|
4680
4763
|
this.request = typeof tx === "string" ? void 0 : tx;
|
4681
4764
|
this.waitForResult = this.waitForResult.bind(this);
|
4682
4765
|
}
|
4766
|
+
static {
|
4767
|
+
__name(this, "TransactionResponse");
|
4768
|
+
}
|
4683
4769
|
/** Transaction ID */
|
4684
4770
|
id;
|
4685
4771
|
/** Current provider */
|
@@ -4701,7 +4787,7 @@ var TransactionResponse = class {
|
|
4701
4787
|
*/
|
4702
4788
|
static async create(id, provider, abis) {
|
4703
4789
|
const chainId = await provider.getChainId();
|
4704
|
-
const response = new
|
4790
|
+
const response = new _TransactionResponse(id, provider, chainId, abis);
|
4705
4791
|
await response.fetch();
|
4706
4792
|
return response;
|
4707
4793
|
}
|
@@ -4833,7 +4919,7 @@ var TransactionResponse = class {
|
|
4833
4919
|
this.status = statusChange;
|
4834
4920
|
if (statusChange.type === "SqueezedOutStatus") {
|
4835
4921
|
this.unsetResourceCache();
|
4836
|
-
throw new
|
4922
|
+
throw new FuelError17(
|
4837
4923
|
ErrorCode14.TRANSACTION_SQUEEZED_OUT,
|
4838
4924
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
4839
4925
|
);
|
@@ -4860,14 +4946,15 @@ var TransactionResponse = class {
|
|
4860
4946
|
const transactionResult = {
|
4861
4947
|
...transactionSummary
|
4862
4948
|
};
|
4863
|
-
let logs = [];
|
4949
|
+
let { logs, groupedLogs } = { logs: [], groupedLogs: {} };
|
4864
4950
|
if (this.abis) {
|
4865
|
-
logs =
|
4866
|
-
transactionSummary.receipts,
|
4867
|
-
this.abis.main,
|
4868
|
-
this.abis.otherContractsAbis
|
4869
|
-
);
|
4951
|
+
({ logs, groupedLogs } = getAllDecodedLogs({
|
4952
|
+
receipts: transactionSummary.receipts,
|
4953
|
+
mainAbi: this.abis.main,
|
4954
|
+
externalAbis: this.abis.otherContractsAbis
|
4955
|
+
}));
|
4870
4956
|
transactionResult.logs = logs;
|
4957
|
+
transactionResult.groupedLogs = groupedLogs;
|
4871
4958
|
}
|
4872
4959
|
const { receipts } = transactionResult;
|
4873
4960
|
const status = this.status ?? this.gqlTransaction?.status;
|
@@ -4876,7 +4963,8 @@ var TransactionResponse = class {
|
|
4876
4963
|
throw extractTxError({
|
4877
4964
|
receipts,
|
4878
4965
|
statusReason: reason,
|
4879
|
-
logs
|
4966
|
+
logs,
|
4967
|
+
groupedLogs
|
4880
4968
|
});
|
4881
4969
|
}
|
4882
4970
|
return transactionResult;
|
@@ -4904,6 +4992,11 @@ var TransactionResponse = class {
|
|
4904
4992
|
}
|
4905
4993
|
};
|
4906
4994
|
|
4995
|
+
// src/providers/transaction-response/getDecodedLogs.ts
|
4996
|
+
import { Interface as Interface3, BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
|
4997
|
+
import { ZeroBytes32 as ZeroBytes3211 } from "@fuel-ts/address/configs";
|
4998
|
+
import { ReceiptType as ReceiptType8 } from "@fuel-ts/transactions";
|
4999
|
+
|
4907
5000
|
// src/providers/utils/auto-retry-fetch.ts
|
4908
5001
|
import { sleep } from "@fuel-ts/utils";
|
4909
5002
|
function getWaitDelay(options, retryAttemptNum) {
|
@@ -4918,6 +5011,7 @@ function getWaitDelay(options, retryAttemptNum) {
|
|
4918
5011
|
return 2 ** (retryAttemptNum - 1) * duration;
|
4919
5012
|
}
|
4920
5013
|
}
|
5014
|
+
__name(getWaitDelay, "getWaitDelay");
|
4921
5015
|
function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
4922
5016
|
if (options === void 0) {
|
4923
5017
|
return fetchFn;
|
@@ -4940,9 +5034,10 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4940
5034
|
}
|
4941
5035
|
};
|
4942
5036
|
}
|
5037
|
+
__name(autoRetryFetch, "autoRetryFetch");
|
4943
5038
|
|
4944
5039
|
// src/providers/utils/helpers.ts
|
4945
|
-
var adjustResourcesToExclude = (params) => {
|
5040
|
+
var adjustResourcesToExclude = /* @__PURE__ */ __name((params) => {
|
4946
5041
|
const { userInput, cached, maxInputs } = params;
|
4947
5042
|
const final = { ...userInput };
|
4948
5043
|
let total = final.utxos.length + final.messages.length;
|
@@ -4955,33 +5050,33 @@ var adjustResourcesToExclude = (params) => {
|
|
4955
5050
|
final.messages = [...final.messages, ...cached.messages.slice(0, maxInputs - total)];
|
4956
5051
|
}
|
4957
5052
|
return final;
|
4958
|
-
};
|
5053
|
+
}, "adjustResourcesToExclude");
|
4959
5054
|
|
4960
5055
|
// src/providers/utils/validate-pagination-args.ts
|
4961
|
-
import { FuelError as
|
4962
|
-
var validatePaginationArgs = (params) => {
|
5056
|
+
import { FuelError as FuelError18, ErrorCode as ErrorCode15 } from "@fuel-ts/errors";
|
5057
|
+
var validatePaginationArgs = /* @__PURE__ */ __name((params) => {
|
4963
5058
|
const { paginationLimit, inputArgs = {} } = params;
|
4964
5059
|
const { first, last, after, before } = inputArgs;
|
4965
5060
|
if (after && before) {
|
4966
|
-
throw new
|
5061
|
+
throw new FuelError18(
|
4967
5062
|
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
4968
5063
|
'Pagination arguments "after" and "before" cannot be used together'
|
4969
5064
|
);
|
4970
5065
|
}
|
4971
5066
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
4972
|
-
throw new
|
5067
|
+
throw new FuelError18(
|
4973
5068
|
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
4974
5069
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
4975
5070
|
);
|
4976
5071
|
}
|
4977
5072
|
if (first && before) {
|
4978
|
-
throw new
|
5073
|
+
throw new FuelError18(
|
4979
5074
|
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
4980
5075
|
'The use of pagination argument "first" with "before" is not supported'
|
4981
5076
|
);
|
4982
5077
|
}
|
4983
5078
|
if (last && after) {
|
4984
|
-
throw new
|
5079
|
+
throw new FuelError18(
|
4985
5080
|
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
4986
5081
|
'The use of pagination argument "last" with "after" is not supported'
|
4987
5082
|
);
|
@@ -4990,18 +5085,71 @@ var validatePaginationArgs = (params) => {
|
|
4990
5085
|
inputArgs.first = paginationLimit;
|
4991
5086
|
}
|
4992
5087
|
return inputArgs;
|
4993
|
-
};
|
5088
|
+
}, "validatePaginationArgs");
|
4994
5089
|
|
4995
5090
|
// src/providers/provider.ts
|
4996
5091
|
var MAX_RETRIES = 10;
|
4997
5092
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
4998
5093
|
var TRANSACTIONS_PAGE_SIZE_LIMIT = 60;
|
4999
5094
|
var BALANCES_PAGE_SIZE_LIMIT = 100;
|
5095
|
+
var NON_PAGINATED_BALANCES_SIZE = 1e4;
|
5000
5096
|
var BLOCKS_PAGE_SIZE_LIMIT = 5;
|
5001
5097
|
var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
|
5002
5098
|
var GAS_USED_MODIFIER = 1.2;
|
5003
|
-
var
|
5004
|
-
|
5099
|
+
var Provider = class _Provider {
|
5100
|
+
static {
|
5101
|
+
__name(this, "Provider");
|
5102
|
+
}
|
5103
|
+
operations;
|
5104
|
+
cache;
|
5105
|
+
/** @hidden */
|
5106
|
+
static clearChainAndNodeCaches() {
|
5107
|
+
_Provider.inflightFetchChainAndNodeInfoRequests = {};
|
5108
|
+
_Provider.nodeInfoCache = {};
|
5109
|
+
_Provider.chainInfoCache = {};
|
5110
|
+
}
|
5111
|
+
/** @hidden */
|
5112
|
+
url;
|
5113
|
+
/** @hidden */
|
5114
|
+
urlWithoutAuth;
|
5115
|
+
/** @hidden */
|
5116
|
+
static inflightFetchChainAndNodeInfoRequests = {};
|
5117
|
+
/** @hidden */
|
5118
|
+
static chainInfoCache = {};
|
5119
|
+
/** @hidden */
|
5120
|
+
static nodeInfoCache = {};
|
5121
|
+
/** @hidden */
|
5122
|
+
static incompatibleNodeVersionMessage = "";
|
5123
|
+
/** @hidden */
|
5124
|
+
consensusParametersTimestamp;
|
5125
|
+
options = {
|
5126
|
+
timeout: void 0,
|
5127
|
+
resourceCacheTTL: void 0,
|
5128
|
+
fetch: void 0,
|
5129
|
+
retryOptions: void 0,
|
5130
|
+
headers: void 0,
|
5131
|
+
cache: void 0
|
5132
|
+
};
|
5133
|
+
/**
|
5134
|
+
* @hidden
|
5135
|
+
*/
|
5136
|
+
static getFetchFn(options) {
|
5137
|
+
const { retryOptions, timeout, headers } = options;
|
5138
|
+
return autoRetryFetch(async (...args) => {
|
5139
|
+
const url = args[0];
|
5140
|
+
const request = args[1];
|
5141
|
+
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
5142
|
+
let fullRequest = {
|
5143
|
+
...request,
|
5144
|
+
signal,
|
5145
|
+
headers: { ...request?.headers, ...headers }
|
5146
|
+
};
|
5147
|
+
if (options.requestMiddleware) {
|
5148
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
5149
|
+
}
|
5150
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
5151
|
+
}, retryOptions);
|
5152
|
+
}
|
5005
5153
|
/**
|
5006
5154
|
* Constructor to initialize a Provider.
|
5007
5155
|
*
|
@@ -5010,31 +5158,6 @@ var _Provider = class {
|
|
5010
5158
|
* @hidden
|
5011
5159
|
*/
|
5012
5160
|
constructor(url, options = {}) {
|
5013
|
-
/**
|
5014
|
-
* @hidden
|
5015
|
-
*/
|
5016
|
-
__privateAdd(this, _cacheInputs);
|
5017
|
-
__publicField(this, "operations");
|
5018
|
-
__publicField(this, "cache");
|
5019
|
-
/** @hidden */
|
5020
|
-
__publicField(this, "url");
|
5021
|
-
/** @hidden */
|
5022
|
-
__publicField(this, "urlWithoutAuth");
|
5023
|
-
/** @hidden */
|
5024
|
-
__publicField(this, "features", {
|
5025
|
-
balancePagination: false,
|
5026
|
-
amount128: false
|
5027
|
-
});
|
5028
|
-
/** @hidden */
|
5029
|
-
__publicField(this, "consensusParametersTimestamp");
|
5030
|
-
__publicField(this, "options", {
|
5031
|
-
timeout: void 0,
|
5032
|
-
resourceCacheTTL: void 0,
|
5033
|
-
fetch: void 0,
|
5034
|
-
retryOptions: void 0,
|
5035
|
-
headers: void 0,
|
5036
|
-
cache: void 0
|
5037
|
-
});
|
5038
5161
|
const { url: rawUrl, urlWithoutAuth, headers: authHeaders } = _Provider.extractBasicAuth(url);
|
5039
5162
|
this.url = rawUrl;
|
5040
5163
|
this.urlWithoutAuth = urlWithoutAuth;
|
@@ -5064,38 +5187,12 @@ var _Provider = class {
|
|
5064
5187
|
this.cache = new ResourceCache(DEFAULT_RESOURCE_CACHE_TTL);
|
5065
5188
|
}
|
5066
5189
|
}
|
5067
|
-
/** @hidden */
|
5068
|
-
static clearChainAndNodeCaches() {
|
5069
|
-
_Provider.inflightFetchChainAndNodeInfoRequests = {};
|
5070
|
-
_Provider.nodeInfoCache = {};
|
5071
|
-
_Provider.chainInfoCache = {};
|
5072
|
-
}
|
5073
|
-
/**
|
5074
|
-
* @hidden
|
5075
|
-
*/
|
5076
|
-
static getFetchFn(options) {
|
5077
|
-
const { retryOptions, timeout, headers } = options;
|
5078
|
-
return autoRetryFetch(async (...args) => {
|
5079
|
-
const url = args[0];
|
5080
|
-
const request = args[1];
|
5081
|
-
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
5082
|
-
let fullRequest = {
|
5083
|
-
...request,
|
5084
|
-
signal,
|
5085
|
-
headers: { ...request?.headers, ...headers }
|
5086
|
-
};
|
5087
|
-
if (options.requestMiddleware) {
|
5088
|
-
fullRequest = await options.requestMiddleware(fullRequest);
|
5089
|
-
}
|
5090
|
-
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
5091
|
-
}, retryOptions);
|
5092
|
-
}
|
5093
5190
|
static extractBasicAuth(url) {
|
5094
5191
|
let parsedUrl;
|
5095
5192
|
try {
|
5096
5193
|
parsedUrl = new URL(url);
|
5097
5194
|
} catch (error) {
|
5098
|
-
throw new
|
5195
|
+
throw new FuelError19(FuelError19.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
|
5099
5196
|
}
|
5100
5197
|
const username = parsedUrl.username;
|
5101
5198
|
const password = parsedUrl.password;
|
@@ -5113,8 +5210,7 @@ var _Provider = class {
|
|
5113
5210
|
* Initialize Provider async stuff
|
5114
5211
|
*/
|
5115
5212
|
async init() {
|
5116
|
-
|
5117
|
-
this.setupFeatures(nodeInfo.nodeVersion);
|
5213
|
+
await this.fetchChainAndNodeInfo();
|
5118
5214
|
return this;
|
5119
5215
|
}
|
5120
5216
|
/**
|
@@ -5174,39 +5270,52 @@ var _Provider = class {
|
|
5174
5270
|
* @returns A promise that resolves to the Chain and NodeInfo.
|
5175
5271
|
*/
|
5176
5272
|
async fetchChainAndNodeInfo(ignoreCache = false) {
|
5177
|
-
|
5178
|
-
|
5179
|
-
|
5180
|
-
|
5181
|
-
chain
|
5182
|
-
|
5183
|
-
|
5184
|
-
|
5185
|
-
|
5186
|
-
|
5187
|
-
|
5188
|
-
|
5189
|
-
|
5190
|
-
|
5191
|
-
|
5192
|
-
}
|
5193
|
-
const { promise, resolve } = deferPromise();
|
5194
|
-
_Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth] = promise;
|
5195
|
-
const data = await this.operations.getChainAndNodeInfo();
|
5196
|
-
nodeInfo = deserializeNodeInfo(data.nodeInfo);
|
5197
|
-
chain = deserializeChain(data.chain);
|
5198
|
-
_Provider.setIncompatibleNodeVersionMessage(nodeInfo);
|
5199
|
-
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
5200
|
-
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
5201
|
-
const now = Date.now();
|
5202
|
-
this.consensusParametersTimestamp = now;
|
5203
|
-
resolve(now);
|
5204
|
-
delete _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];
|
5273
|
+
const nodeInfo = _Provider.nodeInfoCache[this.urlWithoutAuth];
|
5274
|
+
const chain = _Provider.chainInfoCache[this.urlWithoutAuth];
|
5275
|
+
const hasCache = nodeInfo && chain;
|
5276
|
+
if (hasCache && !ignoreCache) {
|
5277
|
+
return { nodeInfo, chain };
|
5278
|
+
}
|
5279
|
+
const inflightRequest = _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];
|
5280
|
+
if (inflightRequest) {
|
5281
|
+
return inflightRequest.then((data) => {
|
5282
|
+
this.consensusParametersTimestamp = data.consensusParametersTimestamp;
|
5283
|
+
return {
|
5284
|
+
nodeInfo: _Provider.nodeInfoCache[this.urlWithoutAuth],
|
5285
|
+
chain: _Provider.chainInfoCache[this.urlWithoutAuth]
|
5286
|
+
};
|
5287
|
+
});
|
5205
5288
|
}
|
5206
|
-
|
5207
|
-
chain,
|
5208
|
-
nodeInfo
|
5209
|
-
|
5289
|
+
const getChainAndNodeInfoFromNetwork = this.operations.getChainAndNodeInfo().then((data) => ({
|
5290
|
+
chain: deserializeChain(data.chain),
|
5291
|
+
nodeInfo: deserializeNodeInfo(data.nodeInfo),
|
5292
|
+
consensusParametersTimestamp: Date.now()
|
5293
|
+
})).then((data) => {
|
5294
|
+
_Provider.setIncompatibleNodeVersionMessage(data.nodeInfo);
|
5295
|
+
_Provider.chainInfoCache[this.urlWithoutAuth] = data.chain;
|
5296
|
+
_Provider.nodeInfoCache[this.urlWithoutAuth] = data.nodeInfo;
|
5297
|
+
this.consensusParametersTimestamp = data.consensusParametersTimestamp;
|
5298
|
+
return data;
|
5299
|
+
}).catch((err) => {
|
5300
|
+
const error = new FuelError19(
|
5301
|
+
FuelError19.CODES.CONNECTION_REFUSED,
|
5302
|
+
"Unable to fetch chain and node info from the network",
|
5303
|
+
{ url: this.urlWithoutAuth },
|
5304
|
+
err
|
5305
|
+
);
|
5306
|
+
error.cause = { code: "ECONNREFUSED" };
|
5307
|
+
throw error;
|
5308
|
+
}).finally(() => {
|
5309
|
+
delete _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];
|
5310
|
+
});
|
5311
|
+
_Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth] = getChainAndNodeInfoFromNetwork;
|
5312
|
+
return _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth].then((data) => {
|
5313
|
+
this.consensusParametersTimestamp = data.consensusParametersTimestamp;
|
5314
|
+
return {
|
5315
|
+
nodeInfo: _Provider.nodeInfoCache[this.urlWithoutAuth],
|
5316
|
+
chain: _Provider.chainInfoCache[this.urlWithoutAuth]
|
5317
|
+
};
|
5318
|
+
});
|
5210
5319
|
}
|
5211
5320
|
/**
|
5212
5321
|
* @hidden
|
@@ -5231,8 +5340,8 @@ var _Provider = class {
|
|
5231
5340
|
createOperations() {
|
5232
5341
|
const fetchFn = _Provider.getFetchFn(this.options);
|
5233
5342
|
const gqlClient = new GraphQLClient(this.urlWithoutAuth, {
|
5234
|
-
fetch: (input, requestInit) => fetchFn(input.toString(), requestInit || {}, this.options),
|
5235
|
-
responseMiddleware: (response) => {
|
5343
|
+
fetch: /* @__PURE__ */ __name((input, requestInit) => fetchFn(input.toString(), requestInit || {}, this.options), "fetch"),
|
5344
|
+
responseMiddleware: /* @__PURE__ */ __name((response) => {
|
5236
5345
|
if ("response" in response) {
|
5237
5346
|
const graphQlResponse = response.response;
|
5238
5347
|
assertGqlResponseHasNoErrors(
|
@@ -5240,22 +5349,22 @@ var _Provider = class {
|
|
5240
5349
|
_Provider.incompatibleNodeVersionMessage
|
5241
5350
|
);
|
5242
5351
|
}
|
5243
|
-
}
|
5352
|
+
}, "responseMiddleware")
|
5244
5353
|
});
|
5245
|
-
const executeQuery = (query, vars) => {
|
5354
|
+
const executeQuery = /* @__PURE__ */ __name((query, vars) => {
|
5246
5355
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
5247
5356
|
const isSubscription = opDefinition?.operation === "subscription";
|
5248
5357
|
if (isSubscription) {
|
5249
5358
|
return FuelGraphqlSubscriber.create({
|
5250
5359
|
url: this.urlWithoutAuth,
|
5251
5360
|
query,
|
5252
|
-
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
5361
|
+
fetchFn: /* @__PURE__ */ __name((url, requestInit) => fetchFn(url, requestInit, this.options), "fetchFn"),
|
5253
5362
|
variables: vars
|
5254
5363
|
});
|
5255
5364
|
}
|
5256
5365
|
return gqlClient.request(query, vars);
|
5257
|
-
};
|
5258
|
-
const customOperations = (requester) => ({
|
5366
|
+
}, "executeQuery");
|
5367
|
+
const customOperations = /* @__PURE__ */ __name((requester) => ({
|
5259
5368
|
getBlobs(variables) {
|
5260
5369
|
const queryParams = variables.blobIds.map((_, i) => `$blobId${i}: BlobId!`).join(", ");
|
5261
5370
|
const blobParams = variables.blobIds.map((_, i) => `blob${i}: blob(id: $blobId${i}) { id }`).join("\n");
|
@@ -5273,18 +5382,9 @@ var _Provider = class {
|
|
5273
5382
|
`;
|
5274
5383
|
return requester(document, updatedVariables);
|
5275
5384
|
}
|
5276
|
-
});
|
5385
|
+
}), "customOperations");
|
5277
5386
|
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
5278
5387
|
}
|
5279
|
-
/**
|
5280
|
-
* @hidden
|
5281
|
-
*/
|
5282
|
-
setupFeatures(nodeVersion) {
|
5283
|
-
if (gte(nodeVersion, "0.41.0")) {
|
5284
|
-
this.features.balancePagination = true;
|
5285
|
-
this.features.amount128 = true;
|
5286
|
-
}
|
5287
|
-
}
|
5288
5388
|
/**
|
5289
5389
|
* Returns the version of the connected node.
|
5290
5390
|
*
|
@@ -5361,6 +5461,13 @@ var _Provider = class {
|
|
5361
5461
|
* @returns A promise that resolves to an object containing the asset details.
|
5362
5462
|
*/
|
5363
5463
|
async getAssetDetails(assetId) {
|
5464
|
+
const { assetMetadata } = await this.getNodeFeatures();
|
5465
|
+
if (!assetMetadata) {
|
5466
|
+
throw new FuelError19(
|
5467
|
+
ErrorCode16.UNSUPPORTED_FEATURE,
|
5468
|
+
"The current node does not supports fetching asset details"
|
5469
|
+
);
|
5470
|
+
}
|
5364
5471
|
const { assetDetails } = await this.operations.getAssetDetails({ assetId });
|
5365
5472
|
const { contractId, subId, totalSupply } = assetDetails;
|
5366
5473
|
return {
|
@@ -5369,6 +5476,15 @@ var _Provider = class {
|
|
5369
5476
|
totalSupply: bn17(totalSupply)
|
5370
5477
|
};
|
5371
5478
|
}
|
5479
|
+
/**
|
5480
|
+
* @hidden
|
5481
|
+
*/
|
5482
|
+
#cacheInputs(inputs, transactionId) {
|
5483
|
+
if (!this.cache) {
|
5484
|
+
return;
|
5485
|
+
}
|
5486
|
+
this.cache.set(transactionId, inputs);
|
5487
|
+
}
|
5372
5488
|
/**
|
5373
5489
|
* @hidden
|
5374
5490
|
*/
|
@@ -5379,13 +5495,13 @@ var _Provider = class {
|
|
5379
5495
|
}
|
5380
5496
|
} = await this.getChain();
|
5381
5497
|
if (bn17(tx.inputs.length).gt(maxInputs)) {
|
5382
|
-
throw new
|
5498
|
+
throw new FuelError19(
|
5383
5499
|
ErrorCode16.MAX_INPUTS_EXCEEDED,
|
5384
5500
|
`The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
|
5385
5501
|
);
|
5386
5502
|
}
|
5387
5503
|
if (bn17(tx.outputs.length).gt(maxOutputs)) {
|
5388
|
-
throw new
|
5504
|
+
throw new FuelError19(
|
5389
5505
|
ErrorCode16.MAX_OUTPUTS_EXCEEDED,
|
5390
5506
|
`The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
|
5391
5507
|
);
|
@@ -5418,7 +5534,10 @@ var _Provider = class {
|
|
5418
5534
|
abis = transactionRequest.abis;
|
5419
5535
|
}
|
5420
5536
|
const subscription = await this.operations.submitAndAwaitStatus({ encodedTransaction });
|
5421
|
-
|
5537
|
+
this.#cacheInputs(
|
5538
|
+
transactionRequest.inputs,
|
5539
|
+
transactionRequest.getTransactionId(await this.getChainId())
|
5540
|
+
);
|
5422
5541
|
const chainId = await this.getChainId();
|
5423
5542
|
return new TransactionResponse(transactionRequest, this, chainId, abis, subscription);
|
5424
5543
|
}
|
@@ -6085,7 +6204,7 @@ var _Provider = class {
|
|
6085
6204
|
0
|
6086
6205
|
)?.[0];
|
6087
6206
|
} catch (error) {
|
6088
|
-
if (error instanceof
|
6207
|
+
if (error instanceof FuelError19 && error.code === ErrorCode16.UNSUPPORTED_TRANSACTION_TYPE) {
|
6089
6208
|
console.warn("Unsupported transaction type encountered");
|
6090
6209
|
return null;
|
6091
6210
|
}
|
@@ -6111,7 +6230,7 @@ var _Provider = class {
|
|
6111
6230
|
try {
|
6112
6231
|
return coder.decode(arrayify13(rawPayload), 0)[0];
|
6113
6232
|
} catch (error) {
|
6114
|
-
if (error instanceof
|
6233
|
+
if (error instanceof FuelError19 && error.code === ErrorCode16.UNSUPPORTED_TRANSACTION_TYPE) {
|
6115
6234
|
console.warn("Unsupported transaction type encountered");
|
6116
6235
|
return null;
|
6117
6236
|
}
|
@@ -6170,18 +6289,9 @@ var _Provider = class {
|
|
6170
6289
|
* @returns A promise that resolves to the balance.
|
6171
6290
|
*/
|
6172
6291
|
async getBalance(owner, assetId) {
|
6173
|
-
const ownerStr = new Address3(owner).toB256();
|
6174
|
-
const assetIdStr = hexlify18(assetId);
|
6175
|
-
if (!this.features.amount128) {
|
6176
|
-
const { balance: balance2 } = await this.operations.getBalance({
|
6177
|
-
owner: ownerStr,
|
6178
|
-
assetId: assetIdStr
|
6179
|
-
});
|
6180
|
-
return bn17(balance2.amount, 10);
|
6181
|
-
}
|
6182
6292
|
const { balance } = await this.operations.getBalanceV2({
|
6183
|
-
owner:
|
6184
|
-
assetId:
|
6293
|
+
owner: new Address3(owner).toB256(),
|
6294
|
+
assetId: hexlify18(assetId)
|
6185
6295
|
});
|
6186
6296
|
return bn17(balance.amountU128, 10);
|
6187
6297
|
}
|
@@ -6193,49 +6303,29 @@ var _Provider = class {
|
|
6193
6303
|
* @returns A promise that resolves to the balances.
|
6194
6304
|
*/
|
6195
6305
|
async getBalances(owner, paginationArgs) {
|
6196
|
-
|
6197
|
-
|
6306
|
+
let args = { first: NON_PAGINATED_BALANCES_SIZE };
|
6307
|
+
const { balancesPagination: supportsPagination } = await this.getNodeFeatures();
|
6308
|
+
if (supportsPagination) {
|
6309
|
+
args = validatePaginationArgs({
|
6310
|
+
inputArgs: paginationArgs,
|
6311
|
+
paginationLimit: BALANCES_PAGE_SIZE_LIMIT
|
6312
|
+
});
|
6198
6313
|
}
|
6199
|
-
return this.getBalancesV2(owner, paginationArgs);
|
6200
|
-
}
|
6201
|
-
/**
|
6202
|
-
* @hidden
|
6203
|
-
*/
|
6204
|
-
async getBalancesV1(owner, _paginationArgs) {
|
6205
|
-
const {
|
6206
|
-
balances: { edges }
|
6207
|
-
} = await this.operations.getBalances({
|
6208
|
-
/**
|
6209
|
-
* The query parameters for this method were designed to support pagination,
|
6210
|
-
* but the current Fuel-Core implementation does not support pagination yet.
|
6211
|
-
*/
|
6212
|
-
first: 1e4,
|
6213
|
-
filter: { owner: new Address3(owner).toB256() }
|
6214
|
-
});
|
6215
|
-
const balances = edges.map(({ node }) => ({
|
6216
|
-
assetId: node.assetId,
|
6217
|
-
amount: bn17(node.amount)
|
6218
|
-
}));
|
6219
|
-
return { balances };
|
6220
|
-
}
|
6221
|
-
/**
|
6222
|
-
* @hidden
|
6223
|
-
*/
|
6224
|
-
async getBalancesV2(owner, paginationArgs) {
|
6225
6314
|
const {
|
6226
6315
|
balances: { edges, pageInfo }
|
6227
6316
|
} = await this.operations.getBalancesV2({
|
6228
|
-
...
|
6229
|
-
|
6230
|
-
|
6231
|
-
}),
|
6232
|
-
filter: { owner: new Address3(owner).toB256() }
|
6317
|
+
...args,
|
6318
|
+
filter: { owner: new Address3(owner).toB256() },
|
6319
|
+
supportsPagination
|
6233
6320
|
});
|
6234
6321
|
const balances = edges.map(({ node }) => ({
|
6235
6322
|
assetId: node.assetId,
|
6236
6323
|
amount: bn17(node.amountU128)
|
6237
6324
|
}));
|
6238
|
-
return {
|
6325
|
+
return {
|
6326
|
+
balances,
|
6327
|
+
...supportsPagination ? { pageInfo } : {}
|
6328
|
+
};
|
6239
6329
|
}
|
6240
6330
|
/**
|
6241
6331
|
* Returns message for the given address.
|
@@ -6289,7 +6379,7 @@ var _Provider = class {
|
|
6289
6379
|
nonce
|
6290
6380
|
};
|
6291
6381
|
if (commitBlockId && commitBlockHeight) {
|
6292
|
-
throw new
|
6382
|
+
throw new FuelError19(
|
6293
6383
|
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
6294
6384
|
"commitBlockId and commitBlockHeight cannot be used together"
|
6295
6385
|
);
|
@@ -6509,19 +6599,32 @@ var _Provider = class {
|
|
6509
6599
|
extractDryRunError(transactionRequest, receipts, dryRunStatus) {
|
6510
6600
|
const status = dryRunStatus;
|
6511
6601
|
let logs = [];
|
6602
|
+
let groupedLogs = {};
|
6512
6603
|
if (transactionRequest.abis) {
|
6513
|
-
logs =
|
6604
|
+
({ logs, groupedLogs } = getAllDecodedLogs({
|
6514
6605
|
receipts,
|
6515
|
-
transactionRequest.abis.main,
|
6516
|
-
transactionRequest.abis.otherContractsAbis
|
6517
|
-
);
|
6606
|
+
mainAbi: transactionRequest.abis.main,
|
6607
|
+
externalAbis: transactionRequest.abis.otherContractsAbis
|
6608
|
+
}));
|
6518
6609
|
}
|
6519
6610
|
return extractTxError({
|
6520
6611
|
logs,
|
6612
|
+
groupedLogs,
|
6521
6613
|
receipts,
|
6522
6614
|
statusReason: status.reason
|
6523
6615
|
});
|
6524
6616
|
}
|
6617
|
+
/**
|
6618
|
+
* @hidden
|
6619
|
+
*/
|
6620
|
+
async getNodeFeatures() {
|
6621
|
+
const { indexation } = await this.getNode();
|
6622
|
+
return {
|
6623
|
+
assetMetadata: Boolean(indexation?.assetMetadata),
|
6624
|
+
balancesPagination: Boolean(indexation?.balances),
|
6625
|
+
coinsToSpend: Boolean(indexation?.coinsToSpend)
|
6626
|
+
};
|
6627
|
+
}
|
6525
6628
|
/**
|
6526
6629
|
* @hidden
|
6527
6630
|
*/
|
@@ -6536,25 +6639,9 @@ var _Provider = class {
|
|
6536
6639
|
return transactionRequest;
|
6537
6640
|
}
|
6538
6641
|
};
|
6539
|
-
var Provider = _Provider;
|
6540
|
-
_cacheInputs = new WeakSet();
|
6541
|
-
cacheInputs_fn = function(inputs, transactionId) {
|
6542
|
-
if (!this.cache) {
|
6543
|
-
return;
|
6544
|
-
}
|
6545
|
-
this.cache.set(transactionId, inputs);
|
6546
|
-
};
|
6547
|
-
/** @hidden */
|
6548
|
-
__publicField(Provider, "inflightFetchChainAndNodeInfoRequests", {});
|
6549
|
-
/** @hidden */
|
6550
|
-
__publicField(Provider, "chainInfoCache", {});
|
6551
|
-
/** @hidden */
|
6552
|
-
__publicField(Provider, "nodeInfoCache", {});
|
6553
|
-
/** @hidden */
|
6554
|
-
__publicField(Provider, "incompatibleNodeVersionMessage", "");
|
6555
6642
|
|
6556
6643
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
6557
|
-
import { ErrorCode as ErrorCode17, FuelError as
|
6644
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError20 } from "@fuel-ts/errors";
|
6558
6645
|
import { bn as bn18 } from "@fuel-ts/math";
|
6559
6646
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
6560
6647
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
@@ -6567,10 +6654,19 @@ import { arrayify as arrayify15 } from "@fuel-ts/utils";
|
|
6567
6654
|
// src/test-utils/test-asset-id.ts
|
6568
6655
|
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
6569
6656
|
import { hexlify as hexlify19 } from "@fuel-ts/utils";
|
6570
|
-
var
|
6657
|
+
var TestAssetId = class _TestAssetId {
|
6571
6658
|
constructor(value) {
|
6572
6659
|
this.value = value;
|
6573
6660
|
}
|
6661
|
+
static {
|
6662
|
+
__name(this, "TestAssetId");
|
6663
|
+
}
|
6664
|
+
static A = new _TestAssetId(
|
6665
|
+
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
6666
|
+
);
|
6667
|
+
static B = new _TestAssetId(
|
6668
|
+
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
6669
|
+
);
|
6574
6670
|
static random(count = 1) {
|
6575
6671
|
const assetIds = [];
|
6576
6672
|
for (let i = 0; i < count; i++) {
|
@@ -6579,17 +6675,10 @@ var _TestAssetId = class {
|
|
6579
6675
|
return assetIds;
|
6580
6676
|
}
|
6581
6677
|
};
|
6582
|
-
var TestAssetId = _TestAssetId;
|
6583
|
-
__publicField(TestAssetId, "A", new _TestAssetId(
|
6584
|
-
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
6585
|
-
));
|
6586
|
-
__publicField(TestAssetId, "B", new _TestAssetId(
|
6587
|
-
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
6588
|
-
));
|
6589
6678
|
|
6590
6679
|
// src/test-utils/wallet-config.ts
|
6591
6680
|
import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
|
6592
|
-
import { FuelError as
|
6681
|
+
import { FuelError as FuelError26 } from "@fuel-ts/errors";
|
6593
6682
|
import { bn as bn22 } from "@fuel-ts/math";
|
6594
6683
|
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify25 } from "@fuel-ts/utils";
|
6595
6684
|
|
@@ -6601,14 +6690,14 @@ import { hexlify as hexlify22 } from "@fuel-ts/utils";
|
|
6601
6690
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
6602
6691
|
import { Address as Address5 } from "@fuel-ts/address";
|
6603
6692
|
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
6604
|
-
import { ErrorCode as ErrorCode18, FuelError as
|
6693
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError21 } from "@fuel-ts/errors";
|
6605
6694
|
import { bn as bn20 } from "@fuel-ts/math";
|
6606
6695
|
import { InputType as InputType7 } from "@fuel-ts/transactions";
|
6607
6696
|
import { arrayify as arrayify17, hexlify as hexlify20, isDefined as isDefined3 } from "@fuel-ts/utils";
|
6608
6697
|
import { clone as clone9 } from "ramda";
|
6609
6698
|
|
6610
6699
|
// src/providers/utils/merge-quantities.ts
|
6611
|
-
var mergeQuantities = (...coinQuantities) => {
|
6700
|
+
var mergeQuantities = /* @__PURE__ */ __name((...coinQuantities) => {
|
6612
6701
|
const resultMap = {};
|
6613
6702
|
function addToMap({ amount, assetId }) {
|
6614
6703
|
if (resultMap[assetId]) {
|
@@ -6617,29 +6706,33 @@ var mergeQuantities = (...coinQuantities) => {
|
|
6617
6706
|
resultMap[assetId] = amount;
|
6618
6707
|
}
|
6619
6708
|
}
|
6709
|
+
__name(addToMap, "addToMap");
|
6620
6710
|
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
6621
6711
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
6622
|
-
};
|
6712
|
+
}, "mergeQuantities");
|
6623
6713
|
|
6624
6714
|
// src/types.ts
|
6625
6715
|
var AbstractAccount = class {
|
6716
|
+
static {
|
6717
|
+
__name(this, "AbstractAccount");
|
6718
|
+
}
|
6626
6719
|
};
|
6627
6720
|
|
6628
6721
|
// src/utils/formatTransferToContractScriptData.ts
|
6629
|
-
import { ASSET_ID_LEN, BigNumberCoder as
|
6722
|
+
import { ASSET_ID_LEN, BigNumberCoder as BigNumberCoder3, CONTRACT_ID_LEN, WORD_SIZE } from "@fuel-ts/abi-coder";
|
6630
6723
|
import { Address as Address4 } from "@fuel-ts/address";
|
6631
6724
|
import { arrayify as arrayify16, concat as concat4 } from "@fuel-ts/utils";
|
6632
6725
|
import * as asm from "@fuels/vm-asm";
|
6633
|
-
var formatTransferToContractScriptData = (transferParams) => {
|
6634
|
-
const numberCoder = new
|
6726
|
+
var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
|
6727
|
+
const numberCoder = new BigNumberCoder3("u64");
|
6635
6728
|
return transferParams.reduce((acc, transferParam) => {
|
6636
6729
|
const { assetId, amount, contractId } = transferParam;
|
6637
6730
|
const encoded = numberCoder.encode(amount);
|
6638
6731
|
const scriptData = concat4([new Address4(contractId).toBytes(), encoded, arrayify16(assetId)]);
|
6639
6732
|
return concat4([acc, scriptData]);
|
6640
6733
|
}, new Uint8Array());
|
6641
|
-
};
|
6642
|
-
var assembleTransferToContractScript = async (transferParams) => {
|
6734
|
+
}, "formatTransferToContractScriptData");
|
6735
|
+
var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferParams) => {
|
6643
6736
|
const scriptData = formatTransferToContractScriptData(transferParams);
|
6644
6737
|
await asm.initWasm();
|
6645
6738
|
let script = new Uint8Array();
|
@@ -6663,11 +6756,14 @@ var assembleTransferToContractScript = async (transferParams) => {
|
|
6663
6756
|
});
|
6664
6757
|
script = concat4([script, asm.ret(1).to_bytes()]);
|
6665
6758
|
return { script, scriptData };
|
6666
|
-
};
|
6759
|
+
}, "assembleTransferToContractScript");
|
6667
6760
|
|
6668
6761
|
// src/account.ts
|
6669
6762
|
var MAX_FUNDING_ATTEMPTS = 5;
|
6670
6763
|
var Account = class extends AbstractAccount {
|
6764
|
+
static {
|
6765
|
+
__name(this, "Account");
|
6766
|
+
}
|
6671
6767
|
/**
|
6672
6768
|
* The address associated with the account.
|
6673
6769
|
*/
|
@@ -6702,7 +6798,7 @@ var Account = class extends AbstractAccount {
|
|
6702
6798
|
*/
|
6703
6799
|
get provider() {
|
6704
6800
|
if (!this._provider) {
|
6705
|
-
throw new
|
6801
|
+
throw new FuelError21(ErrorCode18.MISSING_PROVIDER, "Provider not set");
|
6706
6802
|
}
|
6707
6803
|
return this._provider;
|
6708
6804
|
}
|
@@ -6861,7 +6957,7 @@ var Account = class extends AbstractAccount {
|
|
6861
6957
|
fundingAttempts += 1;
|
6862
6958
|
}
|
6863
6959
|
if (needsToBeFunded) {
|
6864
|
-
throw new
|
6960
|
+
throw new FuelError21(
|
6865
6961
|
ErrorCode18.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
6866
6962
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
6867
6963
|
);
|
@@ -6981,7 +7077,7 @@ var Account = class extends AbstractAccount {
|
|
6981
7077
|
const contractAddress = new Address5(transferParam.contractId);
|
6982
7078
|
const assetId = transferParam.assetId ? hexlify20(transferParam.assetId) : defaultAssetId;
|
6983
7079
|
if (amount.lte(0)) {
|
6984
|
-
throw new
|
7080
|
+
throw new FuelError21(
|
6985
7081
|
ErrorCode18.INVALID_TRANSFER_AMOUNT,
|
6986
7082
|
"Transfer amount must be a positive number."
|
6987
7083
|
);
|
@@ -7051,7 +7147,7 @@ var Account = class extends AbstractAccount {
|
|
7051
7147
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
7052
7148
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
7053
7149
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: bn20("100000000000000000") }];
|
7054
|
-
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
7150
|
+
const findAssetInput = /* @__PURE__ */ __name((assetId) => txRequestClone.inputs.find((input) => {
|
7055
7151
|
if (input.type === InputType7.Coin) {
|
7056
7152
|
return input.assetId === assetId;
|
7057
7153
|
}
|
@@ -7059,8 +7155,8 @@ var Account = class extends AbstractAccount {
|
|
7059
7155
|
return baseAssetId === assetId;
|
7060
7156
|
}
|
7061
7157
|
return false;
|
7062
|
-
});
|
7063
|
-
const updateAssetInput = (assetId, quantity) => {
|
7158
|
+
}), "findAssetInput");
|
7159
|
+
const updateAssetInput = /* @__PURE__ */ __name((assetId, quantity) => {
|
7064
7160
|
const assetInput = findAssetInput(assetId);
|
7065
7161
|
const usedQuantity = quantity;
|
7066
7162
|
if (assetInput && "amount" in assetInput) {
|
@@ -7075,7 +7171,7 @@ var Account = class extends AbstractAccount {
|
|
7075
7171
|
])
|
7076
7172
|
);
|
7077
7173
|
}
|
7078
|
-
};
|
7174
|
+
}, "updateAssetInput");
|
7079
7175
|
mergeQuantities(requiredQuantities, transactionFeeForDryRun).forEach(
|
7080
7176
|
({ amount, assetId }) => updateAssetInput(assetId, amount)
|
7081
7177
|
);
|
@@ -7098,7 +7194,7 @@ var Account = class extends AbstractAccount {
|
|
7098
7194
|
*/
|
7099
7195
|
async signMessage(message) {
|
7100
7196
|
if (!this._connector) {
|
7101
|
-
throw new
|
7197
|
+
throw new FuelError21(ErrorCode18.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
7102
7198
|
}
|
7103
7199
|
return this._connector.signMessage(this.address.toString(), message);
|
7104
7200
|
}
|
@@ -7110,7 +7206,7 @@ var Account = class extends AbstractAccount {
|
|
7110
7206
|
*/
|
7111
7207
|
async signTransaction(transactionRequestLike) {
|
7112
7208
|
if (!this._connector) {
|
7113
|
-
throw new
|
7209
|
+
throw new FuelError21(
|
7114
7210
|
ErrorCode18.MISSING_CONNECTOR,
|
7115
7211
|
"A connector is required to sign transactions."
|
7116
7212
|
);
|
@@ -7207,7 +7303,7 @@ var Account = class extends AbstractAccount {
|
|
7207
7303
|
/** @hidden * */
|
7208
7304
|
validateTransferAmount(amount) {
|
7209
7305
|
if (bn20(amount).lte(0)) {
|
7210
|
-
throw new
|
7306
|
+
throw new FuelError21(
|
7211
7307
|
ErrorCode18.INVALID_TRANSFER_AMOUNT,
|
7212
7308
|
"Transfer amount must be a positive number."
|
7213
7309
|
);
|
@@ -7237,7 +7333,7 @@ var Account = class extends AbstractAccount {
|
|
7237
7333
|
if (!isDefined3(setGasLimit)) {
|
7238
7334
|
request.gasLimit = gasUsed;
|
7239
7335
|
} else if (gasUsed.gt(setGasLimit)) {
|
7240
|
-
throw new
|
7336
|
+
throw new FuelError21(
|
7241
7337
|
ErrorCode18.GAS_LIMIT_TOO_LOW,
|
7242
7338
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
7243
7339
|
);
|
@@ -7245,7 +7341,7 @@ var Account = class extends AbstractAccount {
|
|
7245
7341
|
if (!isDefined3(setMaxFee)) {
|
7246
7342
|
request.maxFee = maxFee;
|
7247
7343
|
} else if (maxFee.gt(setMaxFee)) {
|
7248
|
-
throw new
|
7344
|
+
throw new FuelError21(
|
7249
7345
|
ErrorCode18.MAX_FEE_TOO_LOW,
|
7250
7346
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
7251
7347
|
);
|
@@ -7266,19 +7362,19 @@ import {
|
|
7266
7362
|
encryptJsonWalletData,
|
7267
7363
|
randomUUID as randomUUID2
|
7268
7364
|
} from "@fuel-ts/crypto";
|
7269
|
-
import { ErrorCode as ErrorCode19, FuelError as
|
7365
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError22 } from "@fuel-ts/errors";
|
7270
7366
|
import { hexlify as hexlify21 } from "@fuel-ts/utils";
|
7271
7367
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
7272
7368
|
var DEFAULT_KDF_PARAMS_R = 8;
|
7273
7369
|
var DEFAULT_KDF_PARAMS_P = 1;
|
7274
7370
|
var DEFAULT_KEY_SIZE = 32;
|
7275
7371
|
var DEFAULT_IV_SIZE = 16;
|
7276
|
-
var removeHexPrefix = (hexString) => {
|
7372
|
+
var removeHexPrefix = /* @__PURE__ */ __name((hexString) => {
|
7277
7373
|
if (/^0x/.test(hexString)) {
|
7278
7374
|
return hexString.slice(2);
|
7279
7375
|
}
|
7280
7376
|
return hexString;
|
7281
|
-
};
|
7377
|
+
}, "removeHexPrefix");
|
7282
7378
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
7283
7379
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
7284
7380
|
const ownerAddress = new Address6(address);
|
@@ -7317,6 +7413,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
7317
7413
|
};
|
7318
7414
|
return JSON.stringify(keystore);
|
7319
7415
|
}
|
7416
|
+
__name(encryptKeystoreWallet, "encryptKeystoreWallet");
|
7320
7417
|
async function decryptKeystoreWallet(jsonWallet, password) {
|
7321
7418
|
const keystoreWallet = JSON.parse(jsonWallet);
|
7322
7419
|
const {
|
@@ -7343,7 +7440,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7343
7440
|
const macHashUint8Array = keccak256(data);
|
7344
7441
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
7345
7442
|
if (mac !== macHash) {
|
7346
|
-
throw new
|
7443
|
+
throw new FuelError22(
|
7347
7444
|
ErrorCode19.INVALID_PASSWORD,
|
7348
7445
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
7349
7446
|
);
|
@@ -7352,9 +7449,17 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7352
7449
|
const privateKey = hexlify21(buffer);
|
7353
7450
|
return privateKey;
|
7354
7451
|
}
|
7452
|
+
__name(decryptKeystoreWallet, "decryptKeystoreWallet");
|
7355
7453
|
|
7356
7454
|
// src/wallet/base-wallet-unlocked.ts
|
7357
7455
|
var BaseWalletUnlocked = class extends Account {
|
7456
|
+
static {
|
7457
|
+
__name(this, "BaseWalletUnlocked");
|
7458
|
+
}
|
7459
|
+
/**
|
7460
|
+
* Default HDWallet path.
|
7461
|
+
*/
|
7462
|
+
static defaultPath = "m/44'/1179993420'/0'/0/0";
|
7358
7463
|
/**
|
7359
7464
|
* A function that returns the wallet's signer.
|
7360
7465
|
*/
|
@@ -7472,21 +7577,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
7472
7577
|
return encryptKeystoreWallet(this.privateKey, this.address, password);
|
7473
7578
|
}
|
7474
7579
|
};
|
7475
|
-
/**
|
7476
|
-
* Default HDWallet path.
|
7477
|
-
*/
|
7478
|
-
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
7479
7580
|
|
7480
7581
|
// src/hdwallet/hdwallet.ts
|
7481
7582
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
7482
|
-
import { ErrorCode as ErrorCode22, FuelError as
|
7583
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError25 } from "@fuel-ts/errors";
|
7483
7584
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
7484
7585
|
import { bn as bn21, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
7485
7586
|
import { arrayify as arrayify20, hexlify as hexlify24, concat as concat6, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
7486
7587
|
|
7487
7588
|
// src/mnemonic/mnemonic.ts
|
7488
7589
|
import { randomBytes as randomBytes7, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
7489
|
-
import { ErrorCode as ErrorCode21, FuelError as
|
7590
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError24 } from "@fuel-ts/errors";
|
7490
7591
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
7491
7592
|
import { arrayify as arrayify19, hexlify as hexlify23, concat as concat5, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
7492
7593
|
|
@@ -9543,27 +9644,31 @@ var english = [
|
|
9543
9644
|
];
|
9544
9645
|
|
9545
9646
|
// src/mnemonic/utils.ts
|
9546
|
-
import { ErrorCode as ErrorCode20, FuelError as
|
9647
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError23 } from "@fuel-ts/errors";
|
9547
9648
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
9548
9649
|
import { arrayify as arrayify18 } from "@fuel-ts/utils";
|
9549
9650
|
function getLowerMask(bits) {
|
9550
9651
|
return (1 << bits) - 1;
|
9551
9652
|
}
|
9653
|
+
__name(getLowerMask, "getLowerMask");
|
9552
9654
|
function getUpperMask(bits) {
|
9553
9655
|
return (1 << bits) - 1 << 8 - bits;
|
9554
9656
|
}
|
9657
|
+
__name(getUpperMask, "getUpperMask");
|
9555
9658
|
function getWords(mnemonic) {
|
9556
9659
|
if (!Array.isArray(mnemonic)) {
|
9557
9660
|
return mnemonic.split(/\s+/);
|
9558
9661
|
}
|
9559
9662
|
return mnemonic;
|
9560
9663
|
}
|
9664
|
+
__name(getWords, "getWords");
|
9561
9665
|
function getPhrase(mnemonic) {
|
9562
9666
|
if (Array.isArray(mnemonic)) {
|
9563
9667
|
return mnemonic.join(" ");
|
9564
9668
|
}
|
9565
9669
|
return mnemonic;
|
9566
9670
|
}
|
9671
|
+
__name(getPhrase, "getPhrase");
|
9567
9672
|
function entropyToMnemonicIndices(entropy) {
|
9568
9673
|
const indices = [0];
|
9569
9674
|
let remainingBits = 11;
|
@@ -9585,6 +9690,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
9585
9690
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
9586
9691
|
return indices;
|
9587
9692
|
}
|
9693
|
+
__name(entropyToMnemonicIndices, "entropyToMnemonicIndices");
|
9588
9694
|
function mnemonicWordsToEntropy(words, wordlist) {
|
9589
9695
|
const size = Math.ceil(11 * words.length / 8);
|
9590
9696
|
const entropy = arrayify18(new Uint8Array(size));
|
@@ -9592,7 +9698,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9592
9698
|
for (let i = 0; i < words.length; i += 1) {
|
9593
9699
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
9594
9700
|
if (index === -1) {
|
9595
|
-
throw new
|
9701
|
+
throw new FuelError23(
|
9596
9702
|
ErrorCode20.INVALID_MNEMONIC,
|
9597
9703
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
9598
9704
|
);
|
@@ -9609,13 +9715,14 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9609
9715
|
const checksumMask = getUpperMask(checksumBits);
|
9610
9716
|
const checksum = arrayify18(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
9611
9717
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
9612
|
-
throw new
|
9718
|
+
throw new FuelError23(
|
9613
9719
|
ErrorCode20.INVALID_CHECKSUM,
|
9614
9720
|
"Checksum validation failed for the provided mnemonic."
|
9615
9721
|
);
|
9616
9722
|
}
|
9617
9723
|
return entropy.slice(0, entropyBits / 8);
|
9618
9724
|
}
|
9725
|
+
__name(mnemonicWordsToEntropy, "mnemonicWordsToEntropy");
|
9619
9726
|
|
9620
9727
|
// src/mnemonic/mnemonic.ts
|
9621
9728
|
var MasterSecret = toUtf8Bytes("Bitcoin seed");
|
@@ -9624,29 +9731,35 @@ var TestnetPRV = "0x04358394";
|
|
9624
9731
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
9625
9732
|
function assertWordList(wordlist) {
|
9626
9733
|
if (wordlist.length !== 2048) {
|
9627
|
-
throw new
|
9734
|
+
throw new FuelError24(
|
9628
9735
|
ErrorCode21.INVALID_WORD_LIST,
|
9629
9736
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
9630
9737
|
);
|
9631
9738
|
}
|
9632
9739
|
}
|
9740
|
+
__name(assertWordList, "assertWordList");
|
9633
9741
|
function assertEntropy(entropy) {
|
9634
9742
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
9635
|
-
throw new
|
9743
|
+
throw new FuelError24(
|
9636
9744
|
ErrorCode21.INVALID_ENTROPY,
|
9637
9745
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
9638
9746
|
);
|
9639
9747
|
}
|
9640
9748
|
}
|
9749
|
+
__name(assertEntropy, "assertEntropy");
|
9641
9750
|
function assertMnemonic(words) {
|
9642
9751
|
if (!MNEMONIC_SIZES.includes(words.length)) {
|
9643
9752
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
9644
9753
|
", "
|
9645
9754
|
)}] words, but got ${words.length}.`;
|
9646
|
-
throw new
|
9755
|
+
throw new FuelError24(ErrorCode21.INVALID_MNEMONIC, errorMsg);
|
9647
9756
|
}
|
9648
9757
|
}
|
9649
|
-
|
9758
|
+
__name(assertMnemonic, "assertMnemonic");
|
9759
|
+
var Mnemonic = class _Mnemonic {
|
9760
|
+
static {
|
9761
|
+
__name(this, "Mnemonic");
|
9762
|
+
}
|
9650
9763
|
wordlist;
|
9651
9764
|
/**
|
9652
9765
|
*
|
@@ -9663,7 +9776,7 @@ var Mnemonic = class {
|
|
9663
9776
|
* @returns Entropy hash
|
9664
9777
|
*/
|
9665
9778
|
mnemonicToEntropy(phrase) {
|
9666
|
-
return
|
9779
|
+
return _Mnemonic.mnemonicToEntropy(phrase, this.wordlist);
|
9667
9780
|
}
|
9668
9781
|
/**
|
9669
9782
|
*
|
@@ -9671,7 +9784,7 @@ var Mnemonic = class {
|
|
9671
9784
|
* @returns Mnemonic phrase
|
9672
9785
|
*/
|
9673
9786
|
entropyToMnemonic(entropy) {
|
9674
|
-
return
|
9787
|
+
return _Mnemonic.entropyToMnemonic(entropy, this.wordlist);
|
9675
9788
|
}
|
9676
9789
|
/**
|
9677
9790
|
*
|
@@ -9712,8 +9825,8 @@ var Mnemonic = class {
|
|
9712
9825
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
9713
9826
|
*/
|
9714
9827
|
static mnemonicToMasterKeys(phrase, passphrase = "") {
|
9715
|
-
const seed =
|
9716
|
-
return
|
9828
|
+
const seed = _Mnemonic.mnemonicToSeed(phrase, passphrase);
|
9829
|
+
return _Mnemonic.masterKeysFromSeed(seed);
|
9717
9830
|
}
|
9718
9831
|
/**
|
9719
9832
|
* Validates if given mnemonic is valid
|
@@ -9729,7 +9842,7 @@ var Mnemonic = class {
|
|
9729
9842
|
return false;
|
9730
9843
|
}
|
9731
9844
|
while (i < words.length) {
|
9732
|
-
if (
|
9845
|
+
if (_Mnemonic.binarySearch(words[i]) === false) {
|
9733
9846
|
return false;
|
9734
9847
|
}
|
9735
9848
|
i += 1;
|
@@ -9761,7 +9874,7 @@ var Mnemonic = class {
|
|
9761
9874
|
static masterKeysFromSeed(seed) {
|
9762
9875
|
const seedArray = arrayify19(seed);
|
9763
9876
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
9764
|
-
throw new
|
9877
|
+
throw new FuelError24(
|
9765
9878
|
ErrorCode21.INVALID_SEED,
|
9766
9879
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
9767
9880
|
);
|
@@ -9776,7 +9889,7 @@ var Mnemonic = class {
|
|
9776
9889
|
* @returns BIP-32 extended private key
|
9777
9890
|
*/
|
9778
9891
|
static seedToExtendedKey(seed, testnet = false) {
|
9779
|
-
const masterKey =
|
9892
|
+
const masterKey = _Mnemonic.masterKeysFromSeed(seed);
|
9780
9893
|
const prefix = arrayify19(testnet ? TestnetPRV : MainnetPRV);
|
9781
9894
|
const depth = "0x00";
|
9782
9895
|
const fingerprint = "0x00000000";
|
@@ -9808,7 +9921,7 @@ var Mnemonic = class {
|
|
9808
9921
|
*/
|
9809
9922
|
static generate(size = 32, extraEntropy = "") {
|
9810
9923
|
const entropy = extraEntropy ? sha2563(concat5([randomBytes7(size), arrayify19(extraEntropy)])) : randomBytes7(size);
|
9811
|
-
return
|
9924
|
+
return _Mnemonic.entropyToMnemonic(entropy);
|
9812
9925
|
}
|
9813
9926
|
};
|
9814
9927
|
var mnemonic_default = Mnemonic;
|
@@ -9822,24 +9935,28 @@ var TestnetPUB = hexlify24("0x043587cf");
|
|
9822
9935
|
function base58check(data) {
|
9823
9936
|
return encodeBase582(concat6([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
|
9824
9937
|
}
|
9938
|
+
__name(base58check, "base58check");
|
9825
9939
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
9826
9940
|
if (isPublic) {
|
9827
9941
|
return testnet ? TestnetPUB : MainnetPUB;
|
9828
9942
|
}
|
9829
9943
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
9830
9944
|
}
|
9945
|
+
__name(getExtendedKeyPrefix, "getExtendedKeyPrefix");
|
9831
9946
|
function isPublicExtendedKey(extendedKey) {
|
9832
9947
|
return [MainnetPUB, TestnetPUB].includes(hexlify24(extendedKey.slice(0, 4)));
|
9833
9948
|
}
|
9949
|
+
__name(isPublicExtendedKey, "isPublicExtendedKey");
|
9834
9950
|
function isValidExtendedKey(extendedKey) {
|
9835
9951
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
9836
9952
|
hexlify24(extendedKey.slice(0, 4))
|
9837
9953
|
);
|
9838
9954
|
}
|
9955
|
+
__name(isValidExtendedKey, "isValidExtendedKey");
|
9839
9956
|
function parsePath(path2, depth = 0) {
|
9840
9957
|
const components = path2.split("/");
|
9841
9958
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
9842
|
-
throw new
|
9959
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
9843
9960
|
}
|
9844
9961
|
if (components[0] === "m") {
|
9845
9962
|
components.shift();
|
@@ -9848,7 +9965,11 @@ function parsePath(path2, depth = 0) {
|
|
9848
9965
|
(p) => ~p.indexOf(`'`) ? parseInt(p, 10) + HARDENED_INDEX : parseInt(p, 10)
|
9849
9966
|
);
|
9850
9967
|
}
|
9851
|
-
|
9968
|
+
__name(parsePath, "parsePath");
|
9969
|
+
var HDWallet = class _HDWallet {
|
9970
|
+
static {
|
9971
|
+
__name(this, "HDWallet");
|
9972
|
+
}
|
9852
9973
|
depth = 0;
|
9853
9974
|
index = 0;
|
9854
9975
|
fingerprint = hexlify24("0x00000000");
|
@@ -9868,7 +9989,7 @@ var HDWallet = class {
|
|
9868
9989
|
this.privateKey = hexlify24(config.privateKey);
|
9869
9990
|
} else {
|
9870
9991
|
if (!config.publicKey) {
|
9871
|
-
throw new
|
9992
|
+
throw new FuelError25(
|
9872
9993
|
ErrorCode22.HD_WALLET_ERROR,
|
9873
9994
|
"Both public and private Key cannot be missing. At least one should be provided."
|
9874
9995
|
);
|
@@ -9898,7 +10019,7 @@ var HDWallet = class {
|
|
9898
10019
|
const data = new Uint8Array(37);
|
9899
10020
|
if (index & HARDENED_INDEX) {
|
9900
10021
|
if (!privateKey) {
|
9901
|
-
throw new
|
10022
|
+
throw new FuelError25(
|
9902
10023
|
ErrorCode22.HD_WALLET_ERROR,
|
9903
10024
|
"Cannot derive a hardened index without a private Key."
|
9904
10025
|
);
|
@@ -9914,7 +10035,7 @@ var HDWallet = class {
|
|
9914
10035
|
if (privateKey) {
|
9915
10036
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
9916
10037
|
const ki = bn21(IL).add(privateKey).mod(N).toBytes(32);
|
9917
|
-
return new
|
10038
|
+
return new _HDWallet({
|
9918
10039
|
privateKey: ki,
|
9919
10040
|
chainCode: IR,
|
9920
10041
|
index,
|
@@ -9924,7 +10045,7 @@ var HDWallet = class {
|
|
9924
10045
|
}
|
9925
10046
|
const signer = new Signer(hexlify24(IL));
|
9926
10047
|
const Ki = signer.addPoint(publicKey);
|
9927
|
-
return new
|
10048
|
+
return new _HDWallet({
|
9928
10049
|
publicKey: Ki,
|
9929
10050
|
chainCode: IR,
|
9930
10051
|
index,
|
@@ -9951,7 +10072,7 @@ var HDWallet = class {
|
|
9951
10072
|
*/
|
9952
10073
|
toExtendedKey(isPublic = false, testnet = false) {
|
9953
10074
|
if (this.depth >= 256) {
|
9954
|
-
throw new
|
10075
|
+
throw new FuelError25(
|
9955
10076
|
ErrorCode22.HD_WALLET_ERROR,
|
9956
10077
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
9957
10078
|
);
|
@@ -9973,7 +10094,7 @@ var HDWallet = class {
|
|
9973
10094
|
*/
|
9974
10095
|
static fromSeed(seed) {
|
9975
10096
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
9976
|
-
return new
|
10097
|
+
return new _HDWallet({
|
9977
10098
|
chainCode: arrayify20(masterKey.slice(32)),
|
9978
10099
|
privateKey: arrayify20(masterKey.slice(0, 32))
|
9979
10100
|
});
|
@@ -9983,10 +10104,10 @@ var HDWallet = class {
|
|
9983
10104
|
const bytes = arrayify20(decoded);
|
9984
10105
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
9985
10106
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
9986
|
-
throw new
|
10107
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
9987
10108
|
}
|
9988
10109
|
if (!validChecksum) {
|
9989
|
-
throw new
|
10110
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
9990
10111
|
}
|
9991
10112
|
const depth = bytes[4];
|
9992
10113
|
const parentFingerprint = hexlify24(bytes.slice(5, 9));
|
@@ -9994,16 +10115,16 @@ var HDWallet = class {
|
|
9994
10115
|
const chainCode = hexlify24(bytes.slice(13, 45));
|
9995
10116
|
const key = bytes.slice(45, 78);
|
9996
10117
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
9997
|
-
throw new
|
10118
|
+
throw new FuelError25(
|
9998
10119
|
ErrorCode22.HD_WALLET_ERROR,
|
9999
10120
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
10000
10121
|
);
|
10001
10122
|
}
|
10002
10123
|
if (isPublicExtendedKey(bytes)) {
|
10003
10124
|
if (key[0] !== 3) {
|
10004
|
-
throw new
|
10125
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, "Invalid public extended key.");
|
10005
10126
|
}
|
10006
|
-
return new
|
10127
|
+
return new _HDWallet({
|
10007
10128
|
publicKey: key,
|
10008
10129
|
chainCode,
|
10009
10130
|
index,
|
@@ -10012,9 +10133,9 @@ var HDWallet = class {
|
|
10012
10133
|
});
|
10013
10134
|
}
|
10014
10135
|
if (key[0] !== 0) {
|
10015
|
-
throw new
|
10136
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, "Invalid private extended key.");
|
10016
10137
|
}
|
10017
|
-
return new
|
10138
|
+
return new _HDWallet({
|
10018
10139
|
privateKey: key.slice(1),
|
10019
10140
|
chainCode,
|
10020
10141
|
index,
|
@@ -10027,6 +10148,9 @@ var hdwallet_default = HDWallet;
|
|
10027
10148
|
|
10028
10149
|
// src/wallet/wallets.ts
|
10029
10150
|
var WalletLocked = class extends Account {
|
10151
|
+
static {
|
10152
|
+
__name(this, "WalletLocked");
|
10153
|
+
}
|
10030
10154
|
/**
|
10031
10155
|
* Unlocks the wallet using the provided private key and returns an instance of WalletUnlocked.
|
10032
10156
|
*
|
@@ -10037,7 +10161,10 @@ var WalletLocked = class extends Account {
|
|
10037
10161
|
return new WalletUnlocked(privateKey, this._provider);
|
10038
10162
|
}
|
10039
10163
|
};
|
10040
|
-
var WalletUnlocked = class extends BaseWalletUnlocked {
|
10164
|
+
var WalletUnlocked = class _WalletUnlocked extends BaseWalletUnlocked {
|
10165
|
+
static {
|
10166
|
+
__name(this, "WalletUnlocked");
|
10167
|
+
}
|
10041
10168
|
/**
|
10042
10169
|
* Locks the wallet and returns an instance of WalletLocked.
|
10043
10170
|
*
|
@@ -10055,7 +10182,7 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10055
10182
|
*/
|
10056
10183
|
static generate(generateOptions) {
|
10057
10184
|
const privateKey = Signer.generatePrivateKey(generateOptions?.entropy);
|
10058
|
-
return new
|
10185
|
+
return new _WalletUnlocked(privateKey, generateOptions?.provider);
|
10059
10186
|
}
|
10060
10187
|
/**
|
10061
10188
|
* Create a Wallet Unlocked from a seed.
|
@@ -10067,8 +10194,8 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10067
10194
|
*/
|
10068
10195
|
static fromSeed(seed, path2, provider) {
|
10069
10196
|
const hdWallet = hdwallet_default.fromSeed(seed);
|
10070
|
-
const childWallet = hdWallet.derivePath(path2 ||
|
10071
|
-
return new
|
10197
|
+
const childWallet = hdWallet.derivePath(path2 || _WalletUnlocked.defaultPath);
|
10198
|
+
return new _WalletUnlocked(childWallet.privateKey, provider);
|
10072
10199
|
}
|
10073
10200
|
/**
|
10074
10201
|
* Create a Wallet Unlocked from a mnemonic phrase.
|
@@ -10082,8 +10209,8 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10082
10209
|
static fromMnemonic(mnemonic, path2, passphrase, provider) {
|
10083
10210
|
const seed = mnemonic_default.mnemonicToSeed(mnemonic, passphrase);
|
10084
10211
|
const hdWallet = hdwallet_default.fromSeed(seed);
|
10085
|
-
const childWallet = hdWallet.derivePath(path2 ||
|
10086
|
-
return new
|
10212
|
+
const childWallet = hdWallet.derivePath(path2 || _WalletUnlocked.defaultPath);
|
10213
|
+
return new _WalletUnlocked(childWallet.privateKey, provider);
|
10087
10214
|
}
|
10088
10215
|
/**
|
10089
10216
|
* Create a Wallet Unlocked from an extended key.
|
@@ -10094,7 +10221,7 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10094
10221
|
*/
|
10095
10222
|
static fromExtendedKey(extendedKey, provider) {
|
10096
10223
|
const hdWallet = hdwallet_default.fromExtendedKey(extendedKey);
|
10097
|
-
return new
|
10224
|
+
return new _WalletUnlocked(hdWallet.privateKey, provider);
|
10098
10225
|
}
|
10099
10226
|
/**
|
10100
10227
|
* Create a Wallet Unlocked from an encrypted JSON.
|
@@ -10106,12 +10233,15 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10106
10233
|
*/
|
10107
10234
|
static async fromEncryptedJson(jsonWallet, password, provider) {
|
10108
10235
|
const privateKey = await decryptKeystoreWallet(jsonWallet, password);
|
10109
|
-
return new
|
10236
|
+
return new _WalletUnlocked(privateKey, provider);
|
10110
10237
|
}
|
10111
10238
|
};
|
10112
10239
|
|
10113
10240
|
// src/wallet/wallet.ts
|
10114
10241
|
var Wallet = class {
|
10242
|
+
static {
|
10243
|
+
__name(this, "Wallet");
|
10244
|
+
}
|
10115
10245
|
/**
|
10116
10246
|
* Creates a locked wallet instance from an address and a provider.
|
10117
10247
|
*
|
@@ -10132,71 +10262,74 @@ var Wallet = class {
|
|
10132
10262
|
static fromPrivateKey(privateKey, provider) {
|
10133
10263
|
return new WalletUnlocked(privateKey, provider);
|
10134
10264
|
}
|
10265
|
+
/**
|
10266
|
+
* Generate a new Wallet Unlocked with a random key pair.
|
10267
|
+
*
|
10268
|
+
* @param generateOptions - Options to customize the generation process (optional).
|
10269
|
+
* @returns An unlocked wallet instance.
|
10270
|
+
*/
|
10271
|
+
static generate = WalletUnlocked.generate;
|
10272
|
+
/**
|
10273
|
+
* Create a Wallet Unlocked from a seed.
|
10274
|
+
*
|
10275
|
+
* @param seed - The seed phrase.
|
10276
|
+
* @param provider - A Provider instance (optional).
|
10277
|
+
* @param path - The derivation path (optional).
|
10278
|
+
* @returns An unlocked wallet instance.
|
10279
|
+
*/
|
10280
|
+
static fromSeed = WalletUnlocked.fromSeed;
|
10281
|
+
/**
|
10282
|
+
* Create a Wallet Unlocked from a mnemonic phrase.
|
10283
|
+
*
|
10284
|
+
* @param mnemonic - The mnemonic phrase.
|
10285
|
+
* @param provider - A Provider instance (optional).
|
10286
|
+
* @param path - The derivation path (optional).
|
10287
|
+
* @param passphrase - The passphrase for the mnemonic (optional).
|
10288
|
+
* @returns An unlocked wallet instance.
|
10289
|
+
*/
|
10290
|
+
static fromMnemonic = WalletUnlocked.fromMnemonic;
|
10291
|
+
/**
|
10292
|
+
* Create a Wallet Unlocked from an extended key.
|
10293
|
+
*
|
10294
|
+
* @param extendedKey - The extended key.
|
10295
|
+
* @param provider - A Provider instance (optional).
|
10296
|
+
* @returns An unlocked wallet instance.
|
10297
|
+
*/
|
10298
|
+
static fromExtendedKey = WalletUnlocked.fromExtendedKey;
|
10299
|
+
/**
|
10300
|
+
* Create a Wallet Unlocked from an encrypted JSON.
|
10301
|
+
*
|
10302
|
+
* @param jsonWallet - The encrypted JSON keystore.
|
10303
|
+
* @param password - The password to decrypt the JSON.
|
10304
|
+
* @param provider - A Provider instance (optional).
|
10305
|
+
* @returns An unlocked wallet instance.
|
10306
|
+
*/
|
10307
|
+
static fromEncryptedJson = WalletUnlocked.fromEncryptedJson;
|
10135
10308
|
};
|
10136
|
-
/**
|
10137
|
-
* Generate a new Wallet Unlocked with a random key pair.
|
10138
|
-
*
|
10139
|
-
* @param generateOptions - Options to customize the generation process (optional).
|
10140
|
-
* @returns An unlocked wallet instance.
|
10141
|
-
*/
|
10142
|
-
__publicField(Wallet, "generate", WalletUnlocked.generate);
|
10143
|
-
/**
|
10144
|
-
* Create a Wallet Unlocked from a seed.
|
10145
|
-
*
|
10146
|
-
* @param seed - The seed phrase.
|
10147
|
-
* @param provider - A Provider instance (optional).
|
10148
|
-
* @param path - The derivation path (optional).
|
10149
|
-
* @returns An unlocked wallet instance.
|
10150
|
-
*/
|
10151
|
-
__publicField(Wallet, "fromSeed", WalletUnlocked.fromSeed);
|
10152
|
-
/**
|
10153
|
-
* Create a Wallet Unlocked from a mnemonic phrase.
|
10154
|
-
*
|
10155
|
-
* @param mnemonic - The mnemonic phrase.
|
10156
|
-
* @param provider - A Provider instance (optional).
|
10157
|
-
* @param path - The derivation path (optional).
|
10158
|
-
* @param passphrase - The passphrase for the mnemonic (optional).
|
10159
|
-
* @returns An unlocked wallet instance.
|
10160
|
-
*/
|
10161
|
-
__publicField(Wallet, "fromMnemonic", WalletUnlocked.fromMnemonic);
|
10162
|
-
/**
|
10163
|
-
* Create a Wallet Unlocked from an extended key.
|
10164
|
-
*
|
10165
|
-
* @param extendedKey - The extended key.
|
10166
|
-
* @param provider - A Provider instance (optional).
|
10167
|
-
* @returns An unlocked wallet instance.
|
10168
|
-
*/
|
10169
|
-
__publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
10170
|
-
/**
|
10171
|
-
* Create a Wallet Unlocked from an encrypted JSON.
|
10172
|
-
*
|
10173
|
-
* @param jsonWallet - The encrypted JSON keystore.
|
10174
|
-
* @param password - The password to decrypt the JSON.
|
10175
|
-
* @param provider - A Provider instance (optional).
|
10176
|
-
* @returns An unlocked wallet instance.
|
10177
|
-
*/
|
10178
|
-
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
10179
10309
|
|
10180
10310
|
// src/test-utils/wallet-config.ts
|
10181
|
-
var WalletsConfig = class {
|
10311
|
+
var WalletsConfig = class _WalletsConfig {
|
10312
|
+
static {
|
10313
|
+
__name(this, "WalletsConfig");
|
10314
|
+
}
|
10182
10315
|
initialState;
|
10183
10316
|
options;
|
10184
10317
|
wallets;
|
10185
|
-
generateWallets = () => {
|
10318
|
+
generateWallets = /* @__PURE__ */ __name(() => {
|
10186
10319
|
const generatedWallets = [];
|
10187
10320
|
for (let index = 1; index <= this.options.count; index++) {
|
10188
10321
|
generatedWallets.push(new WalletUnlocked(randomBytes8(32)));
|
10189
10322
|
}
|
10190
10323
|
return generatedWallets;
|
10191
|
-
};
|
10324
|
+
}, "generateWallets");
|
10192
10325
|
constructor(baseAssetId, config) {
|
10193
|
-
|
10326
|
+
_WalletsConfig.validate(config);
|
10194
10327
|
this.options = config;
|
10195
10328
|
const { assets, coinsPerAsset, amountPerCoin, messages } = this.options;
|
10196
10329
|
this.wallets = this.generateWallets();
|
10197
10330
|
this.initialState = {
|
10198
|
-
messages:
|
10199
|
-
coins:
|
10331
|
+
messages: _WalletsConfig.createMessages(this.wallets, messages),
|
10332
|
+
coins: _WalletsConfig.createCoins(
|
10200
10333
|
this.wallets,
|
10201
10334
|
baseAssetId,
|
10202
10335
|
assets,
|
@@ -10256,26 +10389,26 @@ var WalletsConfig = class {
|
|
10256
10389
|
amountPerCoin
|
10257
10390
|
}) {
|
10258
10391
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
10259
|
-
throw new
|
10260
|
-
|
10392
|
+
throw new FuelError26(
|
10393
|
+
FuelError26.CODES.INVALID_INPUT_PARAMETERS,
|
10261
10394
|
"Number of wallets must be greater than zero."
|
10262
10395
|
);
|
10263
10396
|
}
|
10264
10397
|
if (Array.isArray(assets) && assets.length === 0 || typeof assets === "number" && assets <= 0) {
|
10265
|
-
throw new
|
10266
|
-
|
10398
|
+
throw new FuelError26(
|
10399
|
+
FuelError26.CODES.INVALID_INPUT_PARAMETERS,
|
10267
10400
|
"Number of assets per wallet must be greater than zero."
|
10268
10401
|
);
|
10269
10402
|
}
|
10270
10403
|
if (coinsPerAsset <= 0) {
|
10271
|
-
throw new
|
10272
|
-
|
10404
|
+
throw new FuelError26(
|
10405
|
+
FuelError26.CODES.INVALID_INPUT_PARAMETERS,
|
10273
10406
|
"Number of coins per asset must be greater than zero."
|
10274
10407
|
);
|
10275
10408
|
}
|
10276
10409
|
if (bn22(amountPerCoin).lt(0)) {
|
10277
|
-
throw new
|
10278
|
-
|
10410
|
+
throw new FuelError26(
|
10411
|
+
FuelError26.CODES.INVALID_INPUT_PARAMETERS,
|
10279
10412
|
"Amount per coin must be greater than or equal to zero."
|
10280
10413
|
);
|
10281
10414
|
}
|
@@ -10318,9 +10451,9 @@ async function setupTestProviderAndWallets({
|
|
10318
10451
|
if (launchNodeServerPort) {
|
10319
10452
|
const serverUrl = `http://localhost:${launchNodeServerPort}`;
|
10320
10453
|
url = await (await fetch(serverUrl, { method: "POST", body: JSON.stringify(launchNodeOptions) })).text();
|
10321
|
-
cleanup = () => {
|
10454
|
+
cleanup = /* @__PURE__ */ __name(() => {
|
10322
10455
|
fetch(`${serverUrl}/cleanup/${url}`);
|
10323
|
-
};
|
10456
|
+
}, "cleanup");
|
10324
10457
|
} else {
|
10325
10458
|
const settings = await launchNode(launchNodeOptions);
|
10326
10459
|
url = settings.url;
|
@@ -10345,6 +10478,7 @@ async function setupTestProviderAndWallets({
|
|
10345
10478
|
[Symbol.dispose]: cleanup
|
10346
10479
|
};
|
10347
10480
|
}
|
10481
|
+
__name(setupTestProviderAndWallets, "setupTestProviderAndWallets");
|
10348
10482
|
|
10349
10483
|
// src/test-utils/test-message.ts
|
10350
10484
|
import { Address as Address7 } from "@fuel-ts/address";
|
@@ -10352,6 +10486,9 @@ import { randomBytes as randomBytes9 } from "@fuel-ts/crypto";
|
|
10352
10486
|
import { bn as bn23 } from "@fuel-ts/math";
|
10353
10487
|
import { hexlify as hexlify26 } from "@fuel-ts/utils";
|
10354
10488
|
var TestMessage = class {
|
10489
|
+
static {
|
10490
|
+
__name(this, "TestMessage");
|
10491
|
+
}
|
10355
10492
|
sender;
|
10356
10493
|
recipient;
|
10357
10494
|
nonce;
|