@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/index.mjs
CHANGED
@@ -1,31 +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 __privateGet = (obj, member, getter) => {
|
12
|
-
__accessCheck(obj, member, "read from private field");
|
13
|
-
return getter ? getter.call(obj) : member.get(obj);
|
14
|
-
};
|
15
|
-
var __privateAdd = (obj, member, value) => {
|
16
|
-
if (member.has(obj))
|
17
|
-
throw TypeError("Cannot add the same private member more than once");
|
18
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
19
|
-
};
|
20
|
-
var __privateSet = (obj, member, value, setter) => {
|
21
|
-
__accessCheck(obj, member, "write to private field");
|
22
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
23
|
-
return value;
|
24
|
-
};
|
25
|
-
var __privateMethod = (obj, member, method) => {
|
26
|
-
__accessCheck(obj, member, "access private method");
|
27
|
-
return method;
|
28
|
-
};
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
29
3
|
|
30
4
|
// src/providers/chains.ts
|
31
5
|
var CHAIN_IDS = {
|
@@ -42,7 +16,7 @@ var CHAIN_IDS = {
|
|
42
16
|
};
|
43
17
|
|
44
18
|
// src/assets/utils/network.ts
|
45
|
-
var getDefaultChainId = (networkType) => {
|
19
|
+
var getDefaultChainId = /* @__PURE__ */ __name((networkType) => {
|
46
20
|
if (networkType === "ethereum") {
|
47
21
|
return CHAIN_IDS.eth.sepolia;
|
48
22
|
}
|
@@ -50,8 +24,8 @@ var getDefaultChainId = (networkType) => {
|
|
50
24
|
return CHAIN_IDS.fuel.testnet;
|
51
25
|
}
|
52
26
|
return void 0;
|
53
|
-
};
|
54
|
-
var getAssetNetwork = ({
|
27
|
+
}, "getDefaultChainId");
|
28
|
+
var getAssetNetwork = /* @__PURE__ */ __name(({
|
55
29
|
asset,
|
56
30
|
chainId,
|
57
31
|
networkType
|
@@ -60,8 +34,8 @@ var getAssetNetwork = ({
|
|
60
34
|
(item) => item.chainId === chainId && item.type === networkType
|
61
35
|
);
|
62
36
|
return network;
|
63
|
-
};
|
64
|
-
var getAssetWithNetwork = ({
|
37
|
+
}, "getAssetNetwork");
|
38
|
+
var getAssetWithNetwork = /* @__PURE__ */ __name(({
|
65
39
|
asset,
|
66
40
|
chainId,
|
67
41
|
networkType
|
@@ -83,22 +57,22 @@ var getAssetWithNetwork = ({
|
|
83
57
|
...assetRest,
|
84
58
|
...assetNetwork
|
85
59
|
};
|
86
|
-
};
|
87
|
-
var getAssetEth = (asset, chainId) => getAssetWithNetwork({
|
60
|
+
}, "getAssetWithNetwork");
|
61
|
+
var getAssetEth = /* @__PURE__ */ __name((asset, chainId) => getAssetWithNetwork({
|
88
62
|
asset,
|
89
63
|
networkType: "ethereum",
|
90
64
|
chainId
|
91
|
-
});
|
92
|
-
var getAssetFuel = (asset, chainId) => getAssetWithNetwork({
|
65
|
+
}), "getAssetEth");
|
66
|
+
var getAssetFuel = /* @__PURE__ */ __name((asset, chainId) => getAssetWithNetwork({
|
93
67
|
asset,
|
94
68
|
networkType: "fuel",
|
95
69
|
chainId
|
96
|
-
});
|
70
|
+
}), "getAssetFuel");
|
97
71
|
|
98
72
|
// src/assets/utils/url.ts
|
99
73
|
var DELIMITER_PATH = "/";
|
100
74
|
var trimRegex = /^\/|\/$/g;
|
101
|
-
var trimPath = (path = "") => path.replace(trimRegex, "");
|
75
|
+
var trimPath = /* @__PURE__ */ __name((path = "") => path.replace(trimRegex, ""), "trimPath");
|
102
76
|
function urlJoin(baseUrl, ...paths) {
|
103
77
|
const hasBaseUrl = baseUrl !== null && baseUrl !== void 0;
|
104
78
|
const rootPath = baseUrl?.[0] === "/" && baseUrl.length > 1;
|
@@ -108,6 +82,7 @@ function urlJoin(baseUrl, ...paths) {
|
|
108
82
|
}
|
109
83
|
return allPaths.join(DELIMITER_PATH);
|
110
84
|
}
|
85
|
+
__name(urlJoin, "urlJoin");
|
111
86
|
|
112
87
|
// src/assets/utils/resolveIconPaths.ts
|
113
88
|
function resolveIconPaths(assets2, basePath = "./") {
|
@@ -116,6 +91,7 @@ function resolveIconPaths(assets2, basePath = "./") {
|
|
116
91
|
icon: urlJoin(basePath, asset.icon)
|
117
92
|
}));
|
118
93
|
}
|
94
|
+
__name(resolveIconPaths, "resolveIconPaths");
|
119
95
|
|
120
96
|
// src/assets/utils/fuelAssetsBaseUrl.ts
|
121
97
|
var fuelAssetsBaseUrl = "https://assets.fuel.network/providers/";
|
@@ -690,7 +666,7 @@ var networks = {
|
|
690
666
|
mainnet: "https://mainnet-explorer.fuel.network",
|
691
667
|
testnet: "https://explorer-indexer-testnet.fuel.network"
|
692
668
|
};
|
693
|
-
var request = async (url, slug) => {
|
669
|
+
var request = /* @__PURE__ */ __name(async (url, slug) => {
|
694
670
|
const response = await fetch(`${url}${slug}`, {
|
695
671
|
headers: {
|
696
672
|
"Content-Type": "application/json",
|
@@ -702,20 +678,20 @@ var request = async (url, slug) => {
|
|
702
678
|
} catch (error) {
|
703
679
|
return null;
|
704
680
|
}
|
705
|
-
};
|
706
|
-
var buildQueryString = (parameters) => {
|
681
|
+
}, "request");
|
682
|
+
var buildQueryString = /* @__PURE__ */ __name((parameters) => {
|
707
683
|
const query = new URLSearchParams();
|
708
684
|
Object.entries(parameters).forEach(([key, value]) => {
|
709
685
|
query.set(key, value.toString());
|
710
686
|
});
|
711
687
|
return query.size > 0 ? `?${query.toString()}` : "";
|
712
|
-
};
|
713
|
-
var getAssetById = (opts) => {
|
688
|
+
}, "buildQueryString");
|
689
|
+
var getAssetById = /* @__PURE__ */ __name((opts) => {
|
714
690
|
const { network = "mainnet", assetId } = opts;
|
715
691
|
const url = networks[network];
|
716
692
|
return request(url, `/assets/${assetId}`);
|
717
|
-
};
|
718
|
-
var getAssetsByOwner = async (opts) => {
|
693
|
+
}, "getAssetById");
|
694
|
+
var getAssetsByOwner = /* @__PURE__ */ __name(async (opts) => {
|
719
695
|
const { network = "mainnet", owner, pagination = { last: 10 } } = opts;
|
720
696
|
const url = networks[network];
|
721
697
|
const { last } = pagination;
|
@@ -725,13 +701,13 @@ var getAssetsByOwner = async (opts) => {
|
|
725
701
|
return { data: [], pageInfo: { count: 0 } };
|
726
702
|
}
|
727
703
|
return response;
|
728
|
-
};
|
704
|
+
}, "getAssetsByOwner");
|
729
705
|
|
730
706
|
// src/account.ts
|
731
707
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
732
708
|
import { Address as Address4 } from "@fuel-ts/address";
|
733
709
|
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
734
|
-
import { ErrorCode as ErrorCode18, FuelError as
|
710
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError20 } from "@fuel-ts/errors";
|
735
711
|
import { bn as bn20 } from "@fuel-ts/math";
|
736
712
|
import { InputType as InputType7 } from "@fuel-ts/transactions";
|
737
713
|
import { arrayify as arrayify16, hexlify as hexlify17, isDefined as isDefined3 } from "@fuel-ts/utils";
|
@@ -740,7 +716,7 @@ import { clone as clone9 } from "ramda";
|
|
740
716
|
// src/providers/coin-quantity.ts
|
741
717
|
import { bn } from "@fuel-ts/math";
|
742
718
|
import { hexlify } from "@fuel-ts/utils";
|
743
|
-
var coinQuantityfy = (coinQuantityLike) => {
|
719
|
+
var coinQuantityfy = /* @__PURE__ */ __name((coinQuantityLike) => {
|
744
720
|
let assetId;
|
745
721
|
let amount;
|
746
722
|
let max;
|
@@ -758,8 +734,8 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
758
734
|
amount: bn(amount),
|
759
735
|
max: max ? bn(max) : void 0
|
760
736
|
};
|
761
|
-
};
|
762
|
-
var addAmountToCoinQuantities = (params) => {
|
737
|
+
}, "coinQuantityfy");
|
738
|
+
var addAmountToCoinQuantities = /* @__PURE__ */ __name((params) => {
|
763
739
|
const { amount, assetId } = params;
|
764
740
|
const coinQuantities = [...params.coinQuantities];
|
765
741
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -769,38 +745,19 @@ var addAmountToCoinQuantities = (params) => {
|
|
769
745
|
coinQuantities.push({ assetId, amount });
|
770
746
|
}
|
771
747
|
return coinQuantities;
|
772
|
-
};
|
748
|
+
}, "addAmountToCoinQuantities");
|
773
749
|
|
774
750
|
// src/providers/provider.ts
|
775
751
|
import { Address as Address2, isB256 } from "@fuel-ts/address";
|
776
|
-
import { ErrorCode as ErrorCode16, FuelError as
|
752
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError18 } from "@fuel-ts/errors";
|
777
753
|
import { bn as bn17 } from "@fuel-ts/math";
|
778
754
|
import { InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
|
779
755
|
import { arrayify as arrayify12, hexlify as hexlify16, DateTime as DateTime2, isDefined as isDefined2 } from "@fuel-ts/utils";
|
780
|
-
import { checkFuelCoreVersionCompatibility,
|
756
|
+
import { checkFuelCoreVersionCompatibility, versions } from "@fuel-ts/versions";
|
781
757
|
import { GraphQLClient } from "graphql-request";
|
782
758
|
import gql2 from "graphql-tag";
|
783
759
|
import { clone as clone8 } from "ramda";
|
784
760
|
|
785
|
-
// src/connectors/utils/promises.ts
|
786
|
-
import { FuelError } from "@fuel-ts/errors";
|
787
|
-
function deferPromise() {
|
788
|
-
const defer = {};
|
789
|
-
defer.promise = new Promise((resolve, reject) => {
|
790
|
-
defer.reject = reject;
|
791
|
-
defer.resolve = resolve;
|
792
|
-
});
|
793
|
-
return defer;
|
794
|
-
}
|
795
|
-
async function withTimeout(promise, timeout = 1050) {
|
796
|
-
const timeoutPromise = new Promise((resolve, reject) => {
|
797
|
-
setTimeout(() => {
|
798
|
-
reject(new FuelError(FuelError.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
799
|
-
}, timeout);
|
800
|
-
});
|
801
|
-
return Promise.race([timeoutPromise, promise]);
|
802
|
-
}
|
803
|
-
|
804
761
|
// src/providers/__generated__/operations.ts
|
805
762
|
import gql from "graphql-tag";
|
806
763
|
var SubmittedStatusFragmentDoc = gql`
|
@@ -1292,6 +1249,11 @@ var NodeInfoFragmentDoc = gql`
|
|
1292
1249
|
maxTx
|
1293
1250
|
maxDepth
|
1294
1251
|
nodeVersion
|
1252
|
+
indexation {
|
1253
|
+
balances
|
1254
|
+
coinsToSpend
|
1255
|
+
assetMetadata
|
1256
|
+
}
|
1295
1257
|
}
|
1296
1258
|
`;
|
1297
1259
|
var RelayedTransactionStatusFragmentDoc = gql`
|
@@ -1573,7 +1535,7 @@ var GetBalancesDocument = gql`
|
|
1573
1535
|
}
|
1574
1536
|
`;
|
1575
1537
|
var GetBalancesV2Document = gql`
|
1576
|
-
query getBalancesV2($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
1538
|
+
query getBalancesV2($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int, $supportsPagination: Boolean!) {
|
1577
1539
|
balances(
|
1578
1540
|
filter: $filter
|
1579
1541
|
after: $after
|
@@ -1581,7 +1543,7 @@ var GetBalancesV2Document = gql`
|
|
1581
1543
|
first: $first
|
1582
1544
|
last: $last
|
1583
1545
|
) {
|
1584
|
-
pageInfo {
|
1546
|
+
pageInfo @include(if: $supportsPagination) {
|
1585
1547
|
...pageInfoFragment
|
1586
1548
|
}
|
1587
1549
|
edges {
|
@@ -1851,16 +1813,17 @@ function getSdk(requester) {
|
|
1851
1813
|
}
|
1852
1814
|
};
|
1853
1815
|
}
|
1816
|
+
__name(getSdk, "getSdk");
|
1854
1817
|
|
1855
1818
|
// src/providers/fuel-graphql-subscriber.ts
|
1856
|
-
import { ErrorCode as ErrorCode2, FuelError as
|
1819
|
+
import { ErrorCode as ErrorCode2, FuelError as FuelError2 } from "@fuel-ts/errors";
|
1857
1820
|
import { print } from "graphql";
|
1858
1821
|
|
1859
1822
|
// src/providers/utils/handle-gql-error-message.ts
|
1860
|
-
import { ErrorCode, FuelError
|
1861
|
-
var mapGqlErrorMessage = (error) => {
|
1823
|
+
import { ErrorCode, FuelError } from "@fuel-ts/errors";
|
1824
|
+
var mapGqlErrorMessage = /* @__PURE__ */ __name((error) => {
|
1862
1825
|
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)) {
|
1863
|
-
return new
|
1826
|
+
return new FuelError(
|
1864
1827
|
ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
1865
1828
|
`Insufficient funds or too many small value coins. Consider combining UTXOs.`,
|
1866
1829
|
{},
|
@@ -1868,20 +1831,20 @@ var mapGqlErrorMessage = (error) => {
|
|
1868
1831
|
);
|
1869
1832
|
}
|
1870
1833
|
if (new RegExp("resource was not found in table" /* ASSET_NOT_FOUND */).test(error.message)) {
|
1871
|
-
return new
|
1834
|
+
return new FuelError(
|
1872
1835
|
ErrorCode.ASSET_NOT_FOUND,
|
1873
1836
|
`Asset not found for given asset id.`,
|
1874
1837
|
{},
|
1875
1838
|
error
|
1876
1839
|
);
|
1877
1840
|
}
|
1878
|
-
return new
|
1879
|
-
};
|
1880
|
-
var mapGqlErrorWithIncompatibleNodeVersion = (error, incompatibleNodeVersionMessage) => {
|
1841
|
+
return new FuelError(ErrorCode.INVALID_REQUEST, error.message, {}, error);
|
1842
|
+
}, "mapGqlErrorMessage");
|
1843
|
+
var mapGqlErrorWithIncompatibleNodeVersion = /* @__PURE__ */ __name((error, incompatibleNodeVersionMessage) => {
|
1881
1844
|
if (!incompatibleNodeVersionMessage) {
|
1882
1845
|
return error;
|
1883
1846
|
}
|
1884
|
-
return new
|
1847
|
+
return new FuelError(
|
1885
1848
|
error.code,
|
1886
1849
|
`${error.message}
|
1887
1850
|
|
@@ -1889,8 +1852,8 @@ ${incompatibleNodeVersionMessage}`,
|
|
1889
1852
|
error.metadata,
|
1890
1853
|
error.rawError
|
1891
1854
|
);
|
1892
|
-
};
|
1893
|
-
var assertGqlResponseHasNoErrors = (errors, incompatibleNodeVersionMessage = false) => {
|
1855
|
+
}, "mapGqlErrorWithIncompatibleNodeVersion");
|
1856
|
+
var assertGqlResponseHasNoErrors = /* @__PURE__ */ __name((errors, incompatibleNodeVersionMessage = false) => {
|
1894
1857
|
if (!Array.isArray(errors)) {
|
1895
1858
|
return;
|
1896
1859
|
}
|
@@ -1900,16 +1863,21 @@ var assertGqlResponseHasNoErrors = (errors, incompatibleNodeVersionMessage = fal
|
|
1900
1863
|
}
|
1901
1864
|
const errorMessage = mappedErrors.map((err) => err.message).join("\n");
|
1902
1865
|
throw mapGqlErrorWithIncompatibleNodeVersion(
|
1903
|
-
new
|
1866
|
+
new FuelError(ErrorCode.INVALID_REQUEST, errorMessage, {}, mappedErrors),
|
1904
1867
|
incompatibleNodeVersionMessage
|
1905
1868
|
);
|
1906
|
-
};
|
1869
|
+
}, "assertGqlResponseHasNoErrors");
|
1907
1870
|
|
1908
1871
|
// src/providers/fuel-graphql-subscriber.ts
|
1909
|
-
var
|
1872
|
+
var FuelGraphqlSubscriber = class _FuelGraphqlSubscriber {
|
1910
1873
|
constructor(stream) {
|
1911
1874
|
this.stream = stream;
|
1912
1875
|
}
|
1876
|
+
static {
|
1877
|
+
__name(this, "FuelGraphqlSubscriber");
|
1878
|
+
}
|
1879
|
+
static incompatibleNodeVersionMessage = false;
|
1880
|
+
static textDecoder = new TextDecoder();
|
1913
1881
|
static async create(options) {
|
1914
1882
|
const { url, query, variables, fetchFn } = options;
|
1915
1883
|
const response = await fetchFn(`${url}-sub`, {
|
@@ -1951,7 +1919,7 @@ var _FuelGraphqlSubscriber = class {
|
|
1951
1919
|
try {
|
1952
1920
|
this.events.push(JSON.parse(match.replace(/^data:/, "")));
|
1953
1921
|
} catch (e) {
|
1954
|
-
throw new
|
1922
|
+
throw new FuelError2(
|
1955
1923
|
ErrorCode2.STREAM_PARSING_ERROR,
|
1956
1924
|
`Error while parsing stream data response: ${text}`
|
1957
1925
|
);
|
@@ -1970,22 +1938,19 @@ var _FuelGraphqlSubscriber = class {
|
|
1970
1938
|
return this;
|
1971
1939
|
}
|
1972
1940
|
};
|
1973
|
-
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
1974
|
-
__publicField(FuelGraphqlSubscriber, "incompatibleNodeVersionMessage", false);
|
1975
|
-
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
1976
1941
|
|
1977
1942
|
// src/providers/resource-cache.ts
|
1978
|
-
import { FuelError as
|
1943
|
+
import { FuelError as FuelError12, ErrorCode as ErrorCode10 } from "@fuel-ts/errors";
|
1979
1944
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
1980
1945
|
|
1981
1946
|
// src/providers/transaction-request/input.ts
|
1982
1947
|
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1983
1948
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1984
|
-
import { ErrorCode as ErrorCode3, FuelError as
|
1949
|
+
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1985
1950
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1986
1951
|
import { InputType } from "@fuel-ts/transactions";
|
1987
1952
|
import { arrayify, hexlify as hexlify2 } from "@fuel-ts/utils";
|
1988
|
-
var inputify = (value) => {
|
1953
|
+
var inputify = /* @__PURE__ */ __name((value) => {
|
1989
1954
|
const { type } = value;
|
1990
1955
|
switch (value.type) {
|
1991
1956
|
case InputType.Coin: {
|
@@ -2045,21 +2010,21 @@ var inputify = (value) => {
|
|
2045
2010
|
};
|
2046
2011
|
}
|
2047
2012
|
default: {
|
2048
|
-
throw new
|
2013
|
+
throw new FuelError3(
|
2049
2014
|
ErrorCode3.INVALID_TRANSACTION_INPUT,
|
2050
2015
|
`Invalid transaction input type: ${type}.`
|
2051
2016
|
);
|
2052
2017
|
}
|
2053
2018
|
}
|
2054
|
-
};
|
2019
|
+
}, "inputify");
|
2055
2020
|
|
2056
2021
|
// src/providers/transaction-request/output.ts
|
2057
2022
|
import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
2058
|
-
import { ErrorCode as ErrorCode4, FuelError as
|
2023
|
+
import { ErrorCode as ErrorCode4, FuelError as FuelError4 } from "@fuel-ts/errors";
|
2059
2024
|
import { bn as bn3 } from "@fuel-ts/math";
|
2060
2025
|
import { OutputType } from "@fuel-ts/transactions";
|
2061
2026
|
import { hexlify as hexlify3 } from "@fuel-ts/utils";
|
2062
|
-
var outputify = (value) => {
|
2027
|
+
var outputify = /* @__PURE__ */ __name((value) => {
|
2063
2028
|
const { type } = value;
|
2064
2029
|
switch (type) {
|
2065
2030
|
case OutputType.Coin: {
|
@@ -2102,20 +2067,20 @@ var outputify = (value) => {
|
|
2102
2067
|
};
|
2103
2068
|
}
|
2104
2069
|
default: {
|
2105
|
-
throw new
|
2070
|
+
throw new FuelError4(
|
2106
2071
|
ErrorCode4.INVALID_TRANSACTION_INPUT,
|
2107
2072
|
`Invalid transaction output type: ${type}.`
|
2108
2073
|
);
|
2109
2074
|
}
|
2110
2075
|
}
|
2111
|
-
};
|
2076
|
+
}, "outputify");
|
2112
2077
|
|
2113
2078
|
// src/providers/transaction-request/transaction-request.ts
|
2114
2079
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
2115
2080
|
import { Address, addressify } from "@fuel-ts/address";
|
2116
2081
|
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
2117
2082
|
import { randomBytes } from "@fuel-ts/crypto";
|
2118
|
-
import { FuelError as
|
2083
|
+
import { FuelError as FuelError9 } from "@fuel-ts/errors";
|
2119
2084
|
import { bn as bn8 } from "@fuel-ts/math";
|
2120
2085
|
import {
|
2121
2086
|
PolicyType,
|
@@ -2127,13 +2092,13 @@ import {
|
|
2127
2092
|
import { concat, hexlify as hexlify8, isDefined } from "@fuel-ts/utils";
|
2128
2093
|
|
2129
2094
|
// src/providers/message.ts
|
2130
|
-
var isMessageCoin = (message) => !("data" in message);
|
2095
|
+
var isMessageCoin = /* @__PURE__ */ __name((message) => !("data" in message), "isMessageCoin");
|
2131
2096
|
|
2132
2097
|
// src/providers/resource.ts
|
2133
|
-
var isRawCoin = (resource) => "utxoId" in resource;
|
2134
|
-
var isRawMessage = (resource) => "recipient" in resource;
|
2135
|
-
var isCoin = (resource) => "id" in resource;
|
2136
|
-
var isMessage = (resource) => "recipient" in resource;
|
2098
|
+
var isRawCoin = /* @__PURE__ */ __name((resource) => "utxoId" in resource, "isRawCoin");
|
2099
|
+
var isRawMessage = /* @__PURE__ */ __name((resource) => "recipient" in resource, "isRawMessage");
|
2100
|
+
var isCoin = /* @__PURE__ */ __name((resource) => "id" in resource, "isCoin");
|
2101
|
+
var isMessage = /* @__PURE__ */ __name((resource) => "recipient" in resource, "isMessage");
|
2137
2102
|
|
2138
2103
|
// src/providers/utils/receipts.ts
|
2139
2104
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
@@ -2141,11 +2106,11 @@ import { FAILED_TRANSFER_TO_ADDRESS_SIGNAL } from "@fuel-ts/transactions/configs
|
|
2141
2106
|
|
2142
2107
|
// src/providers/utils/serialization.ts
|
2143
2108
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
2144
|
-
import { ErrorCode as ErrorCode5, FuelError as
|
2109
|
+
import { ErrorCode as ErrorCode5, FuelError as FuelError5 } from "@fuel-ts/errors";
|
2145
2110
|
import { bn as bn4 } from "@fuel-ts/math";
|
2146
2111
|
import { getMintedAssetId, InputMessageCoder, ReceiptType } from "@fuel-ts/transactions";
|
2147
2112
|
import { hexlify as hexlify4, arrayify as arrayify2 } from "@fuel-ts/utils";
|
2148
|
-
var deserializeChain = (chain) => {
|
2113
|
+
var deserializeChain = /* @__PURE__ */ __name((chain) => {
|
2149
2114
|
const { name, daHeight, consensusParameters } = chain;
|
2150
2115
|
const {
|
2151
2116
|
contractParams,
|
@@ -2199,8 +2164,8 @@ var deserializeChain = (chain) => {
|
|
2199
2164
|
gasCosts
|
2200
2165
|
}
|
2201
2166
|
};
|
2202
|
-
};
|
2203
|
-
var serializeChain = (chain) => {
|
2167
|
+
}, "deserializeChain");
|
2168
|
+
var serializeChain = /* @__PURE__ */ __name((chain) => {
|
2204
2169
|
const { name, baseChainHeight, consensusParameters } = chain;
|
2205
2170
|
const {
|
2206
2171
|
contractParameters,
|
@@ -2254,39 +2219,41 @@ var serializeChain = (chain) => {
|
|
2254
2219
|
gasCosts
|
2255
2220
|
}
|
2256
2221
|
};
|
2257
|
-
};
|
2258
|
-
var deserializeNodeInfo = (nodeInfo) => {
|
2259
|
-
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
2222
|
+
}, "serializeChain");
|
2223
|
+
var deserializeNodeInfo = /* @__PURE__ */ __name((nodeInfo) => {
|
2224
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace, indexation } = nodeInfo;
|
2260
2225
|
return {
|
2261
2226
|
maxDepth: bn4(maxDepth),
|
2262
2227
|
maxTx: bn4(maxTx),
|
2263
2228
|
nodeVersion,
|
2264
2229
|
utxoValidation,
|
2265
|
-
vmBacktrace
|
2230
|
+
vmBacktrace,
|
2231
|
+
indexation
|
2266
2232
|
};
|
2267
|
-
};
|
2268
|
-
var serializeNodeInfo = (nodeInfo) => {
|
2269
|
-
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
2233
|
+
}, "deserializeNodeInfo");
|
2234
|
+
var serializeNodeInfo = /* @__PURE__ */ __name((nodeInfo) => {
|
2235
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace, indexation } = nodeInfo;
|
2270
2236
|
return {
|
2271
2237
|
maxDepth: maxDepth.toString(),
|
2272
2238
|
maxTx: maxTx.toString(),
|
2273
2239
|
nodeVersion,
|
2274
2240
|
utxoValidation,
|
2275
|
-
vmBacktrace
|
2241
|
+
vmBacktrace,
|
2242
|
+
indexation
|
2276
2243
|
};
|
2277
|
-
};
|
2278
|
-
var deserializeProviderCache = (cache2) => ({
|
2244
|
+
}, "serializeNodeInfo");
|
2245
|
+
var deserializeProviderCache = /* @__PURE__ */ __name((cache2) => ({
|
2279
2246
|
consensusParametersTimestamp: cache2.consensusParametersTimestamp,
|
2280
2247
|
chain: deserializeChain(cache2.chain),
|
2281
2248
|
nodeInfo: deserializeNodeInfo(cache2.nodeInfo)
|
2282
|
-
});
|
2283
|
-
var serializeProviderCache = async (provider) => ({
|
2249
|
+
}), "deserializeProviderCache");
|
2250
|
+
var serializeProviderCache = /* @__PURE__ */ __name(async (provider) => ({
|
2284
2251
|
consensusParametersTimestamp: provider.consensusParametersTimestamp,
|
2285
2252
|
chain: serializeChain(await provider.getChain()),
|
2286
2253
|
nodeInfo: serializeNodeInfo(await provider.getNode())
|
2287
|
-
});
|
2288
|
-
var hexOrZero = (hex) => hex || ZeroBytes323;
|
2289
|
-
var deserializeReceipt = (receipt) => {
|
2254
|
+
}), "serializeProviderCache");
|
2255
|
+
var hexOrZero = /* @__PURE__ */ __name((hex) => hex || ZeroBytes323, "hexOrZero");
|
2256
|
+
var deserializeReceipt = /* @__PURE__ */ __name((receipt) => {
|
2290
2257
|
const { receiptType } = receipt;
|
2291
2258
|
switch (receiptType) {
|
2292
2259
|
case "CALL" /* Call */: {
|
@@ -2476,14 +2443,14 @@ var deserializeReceipt = (receipt) => {
|
|
2476
2443
|
return burnReceipt;
|
2477
2444
|
}
|
2478
2445
|
default:
|
2479
|
-
throw new
|
2446
|
+
throw new FuelError5(ErrorCode5.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
2480
2447
|
}
|
2481
|
-
};
|
2448
|
+
}, "deserializeReceipt");
|
2482
2449
|
|
2483
2450
|
// src/providers/utils/receipts.ts
|
2484
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType2.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
2485
|
-
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === ReceiptType2.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
2486
|
-
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
2451
|
+
var doesReceiptHaveMissingOutputVariables = /* @__PURE__ */ __name((receipt) => receipt.type === ReceiptType2.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL, "doesReceiptHaveMissingOutputVariables");
|
2452
|
+
var doesReceiptHaveMissingContractId = /* @__PURE__ */ __name((receipt) => receipt.type === ReceiptType2.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000", "doesReceiptHaveMissingContractId");
|
2453
|
+
var getReceiptsWithMissingData = /* @__PURE__ */ __name((receipts) => receipts.reduce(
|
2487
2454
|
(memo, receipt) => {
|
2488
2455
|
if (doesReceiptHaveMissingOutputVariables(receipt)) {
|
2489
2456
|
memo.missingOutputVariables.push(receipt);
|
@@ -2497,13 +2464,13 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
2497
2464
|
missingOutputVariables: [],
|
2498
2465
|
missingOutputContractIds: []
|
2499
2466
|
}
|
2500
|
-
);
|
2501
|
-
var assembleReceiptByType = (gqlReceipt) => deserializeReceipt(gqlReceipt);
|
2467
|
+
), "getReceiptsWithMissingData");
|
2468
|
+
var assembleReceiptByType = /* @__PURE__ */ __name((gqlReceipt) => deserializeReceipt(gqlReceipt), "assembleReceiptByType");
|
2502
2469
|
|
2503
2470
|
// src/providers/utils/block-explorer.ts
|
2504
|
-
import { ErrorCode as ErrorCode6, FuelError as
|
2471
|
+
import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/errors";
|
2505
2472
|
var DEFAULT_BLOCK_EXPLORER_URL = "https://app.fuel.network";
|
2506
|
-
var getPathFromInput = (key, value) => {
|
2473
|
+
var getPathFromInput = /* @__PURE__ */ __name((key, value) => {
|
2507
2474
|
const pathMap = {
|
2508
2475
|
address: `address`,
|
2509
2476
|
txId: `transaction`,
|
@@ -2511,8 +2478,8 @@ var getPathFromInput = (key, value) => {
|
|
2511
2478
|
};
|
2512
2479
|
const path = pathMap[key] || key;
|
2513
2480
|
return `${path}/${value}`;
|
2514
|
-
};
|
2515
|
-
var buildBlockExplorerUrl = (options = {}) => {
|
2481
|
+
}, "getPathFromInput");
|
2482
|
+
var buildBlockExplorerUrl = /* @__PURE__ */ __name((options = {}) => {
|
2516
2483
|
const { blockExplorerUrl, path, providerUrl, address, txId, blockNumber } = options;
|
2517
2484
|
const explorerUrl = blockExplorerUrl || DEFAULT_BLOCK_EXPLORER_URL;
|
2518
2485
|
const customInputParams = [
|
@@ -2535,14 +2502,14 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
2535
2502
|
}));
|
2536
2503
|
const hasAnyDefinedValues = definedValues.length > 0;
|
2537
2504
|
if (definedValues.length > 1) {
|
2538
|
-
throw new
|
2505
|
+
throw new FuelError6(
|
2539
2506
|
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
2540
2507
|
`Only one of the following can be passed in to buildBlockExplorerUrl: ${customInputParams.map((param) => param.key).join(", ")}.`
|
2541
2508
|
);
|
2542
2509
|
}
|
2543
2510
|
if (path && definedValues.length > 0) {
|
2544
2511
|
const inputKeys = customInputParams.map(({ key }) => key).join(", ");
|
2545
|
-
throw new
|
2512
|
+
throw new FuelError6(
|
2546
2513
|
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
2547
2514
|
`You cannot pass in a path to 'buildBlockExplorerUrl' along with any of the following: ${inputKeys}.`
|
2548
2515
|
);
|
@@ -2560,19 +2527,19 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
2560
2527
|
const providerUrlProtocol = cleanProviderUrl?.match(/^https?:\/\//) ? "" : "https://";
|
2561
2528
|
const url = `${protocol}${cleanBlockExplorerUrl}/${cleanPath}${encodedProviderUrl ? `?providerUrl=${providerUrlProtocol}${encodedProviderUrl}` : ""}`;
|
2562
2529
|
return url;
|
2563
|
-
};
|
2530
|
+
}, "buildBlockExplorerUrl");
|
2564
2531
|
|
2565
2532
|
// src/providers/utils/gas.ts
|
2566
2533
|
import { bn as bn5 } from "@fuel-ts/math";
|
2567
2534
|
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
2568
2535
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
2569
|
-
var getGasUsedFromReceipts = (receipts) => {
|
2536
|
+
var getGasUsedFromReceipts = /* @__PURE__ */ __name((receipts) => {
|
2570
2537
|
const scriptResult = receipts.filter(
|
2571
2538
|
(receipt) => receipt.type === ReceiptType3.ScriptResult
|
2572
2539
|
);
|
2573
2540
|
const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), bn5(0));
|
2574
2541
|
return gasUsed;
|
2575
|
-
};
|
2542
|
+
}, "getGasUsedFromReceipts");
|
2576
2543
|
function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
2577
2544
|
const base = bn5(gasDependentCost.base);
|
2578
2545
|
let dependentValue = bn5(0);
|
@@ -2583,6 +2550,7 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
2583
2550
|
}
|
2584
2551
|
return base.add(dependentValue);
|
2585
2552
|
}
|
2553
|
+
__name(resolveGasDependentCosts, "resolveGasDependentCosts");
|
2586
2554
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
2587
2555
|
const witnessCache = [];
|
2588
2556
|
const chargeableInputs = inputs.filter((input) => {
|
@@ -2609,6 +2577,7 @@ function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
|
2609
2577
|
}, bn5(0));
|
2610
2578
|
return totalGas;
|
2611
2579
|
}
|
2580
|
+
__name(gasUsedByInputs, "gasUsedByInputs");
|
2612
2581
|
function getMinGas(params) {
|
2613
2582
|
const { gasCosts, gasPerByte, inputs, metadataGas, txBytesSize } = params;
|
2614
2583
|
const vmInitGas = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
@@ -2617,6 +2586,7 @@ function getMinGas(params) {
|
|
2617
2586
|
const minGas = vmInitGas.add(bytesGas).add(inputsGas).add(metadataGas).maxU64();
|
2618
2587
|
return minGas;
|
2619
2588
|
}
|
2589
|
+
__name(getMinGas, "getMinGas");
|
2620
2590
|
function getMaxGas(params) {
|
2621
2591
|
const {
|
2622
2592
|
gasPerByte,
|
@@ -2633,6 +2603,7 @@ function getMaxGas(params) {
|
|
2633
2603
|
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
2634
2604
|
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
2635
2605
|
}
|
2606
|
+
__name(getMaxGas, "getMaxGas");
|
2636
2607
|
function calculateMetadataGasForTxCreate({
|
2637
2608
|
gasCosts,
|
2638
2609
|
stateRootSize,
|
@@ -2647,12 +2618,14 @@ function calculateMetadataGasForTxCreate({
|
|
2647
2618
|
const metadataGas = contractRootGas.add(stateRootGas).add(txIdGas).add(contractIdGas);
|
2648
2619
|
return metadataGas.maxU64();
|
2649
2620
|
}
|
2621
|
+
__name(calculateMetadataGasForTxCreate, "calculateMetadataGasForTxCreate");
|
2650
2622
|
function calculateMetadataGasForTxScript({
|
2651
2623
|
gasCosts,
|
2652
2624
|
txBytesSize
|
2653
2625
|
}) {
|
2654
2626
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
2655
2627
|
}
|
2628
|
+
__name(calculateMetadataGasForTxScript, "calculateMetadataGasForTxScript");
|
2656
2629
|
function calculateMetadataGasForTxBlob({
|
2657
2630
|
gasCosts,
|
2658
2631
|
txBytesSize,
|
@@ -2662,6 +2635,7 @@ function calculateMetadataGasForTxBlob({
|
|
2662
2635
|
const blobLen = resolveGasDependentCosts(witnessBytesSize, gasCosts.s256);
|
2663
2636
|
return txId.add(blobLen);
|
2664
2637
|
}
|
2638
|
+
__name(calculateMetadataGasForTxBlob, "calculateMetadataGasForTxBlob");
|
2665
2639
|
function calculateMetadataGasForTxUpgrade({
|
2666
2640
|
gasCosts,
|
2667
2641
|
txBytesSize,
|
@@ -2674,6 +2648,7 @@ function calculateMetadataGasForTxUpgrade({
|
|
2674
2648
|
}
|
2675
2649
|
return txId;
|
2676
2650
|
}
|
2651
|
+
__name(calculateMetadataGasForTxUpgrade, "calculateMetadataGasForTxUpgrade");
|
2677
2652
|
function calculateMetadataGasForTxUpload({
|
2678
2653
|
gasCosts,
|
2679
2654
|
txBytesSize,
|
@@ -2687,6 +2662,7 @@ function calculateMetadataGasForTxUpload({
|
|
2687
2662
|
txId.add(subsectionsLen);
|
2688
2663
|
return txId;
|
2689
2664
|
}
|
2665
|
+
__name(calculateMetadataGasForTxUpload, "calculateMetadataGasForTxUpload");
|
2690
2666
|
function calculateMinGasForTxUpload({
|
2691
2667
|
gasCosts,
|
2692
2668
|
baseMinGas,
|
@@ -2695,10 +2671,11 @@ function calculateMinGasForTxUpload({
|
|
2695
2671
|
const additionalStoragePerByte = bn5(gasCosts.newStoragePerByte).mul(subsectionSize);
|
2696
2672
|
return bn5(baseMinGas).add(additionalStoragePerByte);
|
2697
2673
|
}
|
2698
|
-
|
2674
|
+
__name(calculateMinGasForTxUpload, "calculateMinGasForTxUpload");
|
2675
|
+
var calculateGasFee = /* @__PURE__ */ __name((params) => {
|
2699
2676
|
const { gas, gasPrice, priceFactor, tip } = params;
|
2700
2677
|
return gas.mul(gasPrice).div(priceFactor).add(bn5(tip));
|
2701
|
-
};
|
2678
|
+
}, "calculateGasFee");
|
2702
2679
|
|
2703
2680
|
// src/providers/utils/json.ts
|
2704
2681
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -2727,12 +2704,14 @@ function normalize(object) {
|
|
2727
2704
|
});
|
2728
2705
|
return object;
|
2729
2706
|
}
|
2707
|
+
__name(normalize, "normalize");
|
2730
2708
|
function normalizeJSON(root) {
|
2731
2709
|
return normalize(clone(root));
|
2732
2710
|
}
|
2711
|
+
__name(normalizeJSON, "normalizeJSON");
|
2733
2712
|
|
2734
2713
|
// src/providers/utils/extract-tx-error.ts
|
2735
|
-
import { ErrorCode as ErrorCode7, FuelError as
|
2714
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2736
2715
|
import { bn as bn6 } from "@fuel-ts/math";
|
2737
2716
|
import { ReceiptType as ReceiptType4 } from "@fuel-ts/transactions";
|
2738
2717
|
import {
|
@@ -2744,7 +2723,7 @@ import {
|
|
2744
2723
|
PANIC_REASONS,
|
2745
2724
|
PANIC_DOC_URL
|
2746
2725
|
} from "@fuel-ts/transactions/configs";
|
2747
|
-
var assemblePanicError = (statusReason, metadata) => {
|
2726
|
+
var assemblePanicError = /* @__PURE__ */ __name((statusReason, metadata) => {
|
2748
2727
|
let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
|
2749
2728
|
if (PANIC_REASONS.includes(statusReason)) {
|
2750
2729
|
errorMessage = `${errorMessage}
|
@@ -2753,13 +2732,13 @@ You can read more about this error at:
|
|
2753
2732
|
|
2754
2733
|
${PANIC_DOC_URL}#variant.${statusReason}`;
|
2755
2734
|
}
|
2756
|
-
return new
|
2735
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, {
|
2757
2736
|
...metadata,
|
2758
2737
|
reason: statusReason
|
2759
2738
|
});
|
2760
|
-
};
|
2761
|
-
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
2762
|
-
var assembleRevertError = (receipts, logs, metadata) => {
|
2739
|
+
}, "assemblePanicError");
|
2740
|
+
var stringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, null, 2), "stringify");
|
2741
|
+
var assembleRevertError = /* @__PURE__ */ __name((receipts, logs, metadata) => {
|
2763
2742
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
2764
2743
|
const revertReceipt = receipts.find(({ type }) => type === ReceiptType4.Revert);
|
2765
2744
|
let reason = "";
|
@@ -2794,7 +2773,7 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2794
2773
|
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
2795
2774
|
break;
|
2796
2775
|
default:
|
2797
|
-
throw new
|
2776
|
+
throw new FuelError7(
|
2798
2777
|
ErrorCode7.UNKNOWN,
|
2799
2778
|
`The transaction reverted with an unknown reason: ${revertReceipt.val}`,
|
2800
2779
|
{
|
@@ -2804,17 +2783,18 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2804
2783
|
);
|
2805
2784
|
}
|
2806
2785
|
}
|
2807
|
-
return new
|
2786
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, {
|
2808
2787
|
...metadata,
|
2809
2788
|
reason
|
2810
2789
|
});
|
2811
|
-
};
|
2812
|
-
var extractTxError = (params) => {
|
2813
|
-
const { receipts, statusReason, logs } = params;
|
2790
|
+
}, "assembleRevertError");
|
2791
|
+
var extractTxError = /* @__PURE__ */ __name((params) => {
|
2792
|
+
const { receipts, statusReason, logs, groupedLogs } = params;
|
2814
2793
|
const isPanic = receipts.some(({ type }) => type === ReceiptType4.Panic);
|
2815
2794
|
const isRevert = receipts.some(({ type }) => type === ReceiptType4.Revert);
|
2816
2795
|
const metadata = {
|
2817
2796
|
logs,
|
2797
|
+
groupedLogs,
|
2818
2798
|
receipts,
|
2819
2799
|
panic: isPanic,
|
2820
2800
|
revert: isRevert,
|
@@ -2824,10 +2804,13 @@ var extractTxError = (params) => {
|
|
2824
2804
|
return assemblePanicError(statusReason, metadata);
|
2825
2805
|
}
|
2826
2806
|
return assembleRevertError(receipts, logs, metadata);
|
2827
|
-
};
|
2807
|
+
}, "extractTxError");
|
2828
2808
|
|
2829
2809
|
// src/providers/transaction-request/errors.ts
|
2830
2810
|
var ChangeOutputCollisionError = class extends Error {
|
2811
|
+
static {
|
2812
|
+
__name(this, "ChangeOutputCollisionError");
|
2813
|
+
}
|
2831
2814
|
name = "ChangeOutputCollisionError";
|
2832
2815
|
message = 'A ChangeOutput with the same "assetId" already exists for a different "to" address';
|
2833
2816
|
};
|
@@ -2837,6 +2820,9 @@ var NoWitnessAtIndexError = class extends Error {
|
|
2837
2820
|
this.index = index;
|
2838
2821
|
this.message = `Witness at index "${index}" was not found`;
|
2839
2822
|
}
|
2823
|
+
static {
|
2824
|
+
__name(this, "NoWitnessAtIndexError");
|
2825
|
+
}
|
2840
2826
|
name = "NoWitnessAtIndexError";
|
2841
2827
|
};
|
2842
2828
|
var NoWitnessByOwnerError = class extends Error {
|
@@ -2845,23 +2831,26 @@ var NoWitnessByOwnerError = class extends Error {
|
|
2845
2831
|
this.owner = owner;
|
2846
2832
|
this.message = `A witness for the given owner "${owner}" was not found`;
|
2847
2833
|
}
|
2834
|
+
static {
|
2835
|
+
__name(this, "NoWitnessByOwnerError");
|
2836
|
+
}
|
2848
2837
|
name = "NoWitnessByOwnerError";
|
2849
2838
|
};
|
2850
2839
|
|
2851
2840
|
// src/providers/transaction-request/helpers.ts
|
2852
|
-
import { ErrorCode as ErrorCode8, FuelError as
|
2841
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2853
2842
|
import { bn as bn7 } from "@fuel-ts/math";
|
2854
2843
|
import { InputType as InputType2, OutputType as OutputType2 } from "@fuel-ts/transactions";
|
2855
2844
|
import { hexlify as hexlify6 } from "@fuel-ts/utils";
|
2856
|
-
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
2857
|
-
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
2858
|
-
var isRequestInputMessageWithoutData = (input) => input.type === InputType2.Message && bn7(input.data).isZero();
|
2859
|
-
var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
2860
|
-
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2861
|
-
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2862
|
-
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
2863
|
-
var isPredicate = (input) => isRequestInputCoinOrMessage(input) && !!input.predicate && hexlify6(input.predicate) !== "0x";
|
2864
|
-
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
2845
|
+
var isRequestInputCoin = /* @__PURE__ */ __name((input) => input.type === InputType2.Coin, "isRequestInputCoin");
|
2846
|
+
var isRequestInputMessage = /* @__PURE__ */ __name((input) => input.type === InputType2.Message, "isRequestInputMessage");
|
2847
|
+
var isRequestInputMessageWithoutData = /* @__PURE__ */ __name((input) => input.type === InputType2.Message && bn7(input.data).isZero(), "isRequestInputMessageWithoutData");
|
2848
|
+
var isRequestInputCoinOrMessage = /* @__PURE__ */ __name((input) => isRequestInputCoin(input) || isRequestInputMessage(input), "isRequestInputCoinOrMessage");
|
2849
|
+
var isRequestInputResource = /* @__PURE__ */ __name((input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input), "isRequestInputResource");
|
2850
|
+
var getRequestInputResourceOwner = /* @__PURE__ */ __name((input) => isRequestInputCoin(input) ? input.owner : input.recipient, "getRequestInputResourceOwner");
|
2851
|
+
var isRequestInputResourceFromOwner = /* @__PURE__ */ __name((input, owner) => getRequestInputResourceOwner(input) === owner.toB256(), "isRequestInputResourceFromOwner");
|
2852
|
+
var isPredicate = /* @__PURE__ */ __name((input) => isRequestInputCoinOrMessage(input) && !!input.predicate && hexlify6(input.predicate) !== "0x", "isPredicate");
|
2853
|
+
var getAssetAmountInRequestInputs = /* @__PURE__ */ __name((inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
2865
2854
|
if (isRequestInputCoin(input) && input.assetId === assetId) {
|
2866
2855
|
return acc.add(input.amount);
|
2867
2856
|
}
|
@@ -2869,8 +2858,8 @@ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filte
|
|
2869
2858
|
return acc.add(input.amount);
|
2870
2859
|
}
|
2871
2860
|
return acc;
|
2872
|
-
}, bn7(0));
|
2873
|
-
var cacheRequestInputsResources = (inputs) => inputs.filter(isRequestInputResource).reduce(
|
2861
|
+
}, bn7(0)), "getAssetAmountInRequestInputs");
|
2862
|
+
var cacheRequestInputsResources = /* @__PURE__ */ __name((inputs) => inputs.filter(isRequestInputResource).reduce(
|
2874
2863
|
(cache2, input) => {
|
2875
2864
|
if (isRequestInputCoin(input)) {
|
2876
2865
|
cache2.utxos.push(input.id);
|
@@ -2883,8 +2872,8 @@ var cacheRequestInputsResources = (inputs) => inputs.filter(isRequestInputResour
|
|
2883
2872
|
utxos: [],
|
2884
2873
|
messages: []
|
2885
2874
|
}
|
2886
|
-
);
|
2887
|
-
var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
2875
|
+
), "cacheRequestInputsResources");
|
2876
|
+
var cacheRequestInputsResourcesFromOwner = /* @__PURE__ */ __name((inputs, owner) => inputs.reduce(
|
2888
2877
|
(acc, input) => {
|
2889
2878
|
if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
|
2890
2879
|
acc.utxos.push(input.id);
|
@@ -2897,8 +2886,8 @@ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
|
2897
2886
|
utxos: [],
|
2898
2887
|
messages: []
|
2899
2888
|
}
|
2900
|
-
);
|
2901
|
-
var getBurnableAssetCount = (baseAssetId, transactionRequest) => {
|
2889
|
+
), "cacheRequestInputsResourcesFromOwner");
|
2890
|
+
var getBurnableAssetCount = /* @__PURE__ */ __name((baseAssetId, transactionRequest) => {
|
2902
2891
|
const { inputs, outputs } = transactionRequest;
|
2903
2892
|
const coinInputs = new Set(inputs.filter(isRequestInputCoin).map((input) => input.assetId));
|
2904
2893
|
if (inputs.some((i) => isRequestInputMessage(i) && bn7(i.amount).gt(0))) {
|
@@ -2909,8 +2898,8 @@ var getBurnableAssetCount = (baseAssetId, transactionRequest) => {
|
|
2909
2898
|
);
|
2910
2899
|
const difference = new Set([...coinInputs].filter((x) => !changeOutputs.has(x)));
|
2911
2900
|
return difference.size;
|
2912
|
-
};
|
2913
|
-
var validateTransactionForAssetBurn = (baseAssetId, transactionRequest, enableAssetBurn = false) => {
|
2901
|
+
}, "getBurnableAssetCount");
|
2902
|
+
var validateTransactionForAssetBurn = /* @__PURE__ */ __name((baseAssetId, transactionRequest, enableAssetBurn = false) => {
|
2914
2903
|
if (enableAssetBurn === true) {
|
2915
2904
|
return;
|
2916
2905
|
}
|
@@ -2922,21 +2911,24 @@ var validateTransactionForAssetBurn = (baseAssetId, transactionRequest, enableAs
|
|
2922
2911
|
"Add the relevant change outputs to the transaction to avoid burning assets.",
|
2923
2912
|
"Or enable asset burn, upon sending the transaction."
|
2924
2913
|
].join("\n");
|
2925
|
-
throw new
|
2926
|
-
};
|
2914
|
+
throw new FuelError8(ErrorCode8.ASSET_BURN_DETECTED, message);
|
2915
|
+
}, "validateTransactionForAssetBurn");
|
2927
2916
|
|
2928
2917
|
// src/providers/transaction-request/witness.ts
|
2929
2918
|
import { arrayify as arrayify4, hexlify as hexlify7 } from "@fuel-ts/utils";
|
2930
|
-
var witnessify = (value) => {
|
2919
|
+
var witnessify = /* @__PURE__ */ __name((value) => {
|
2931
2920
|
const data = arrayify4(value);
|
2932
2921
|
return {
|
2933
2922
|
data: hexlify7(data),
|
2934
2923
|
dataLength: data.length
|
2935
2924
|
};
|
2936
|
-
};
|
2925
|
+
}, "witnessify");
|
2937
2926
|
|
2938
2927
|
// src/providers/transaction-request/transaction-request.ts
|
2939
|
-
var BaseTransactionRequest = class {
|
2928
|
+
var BaseTransactionRequest = class _BaseTransactionRequest {
|
2929
|
+
static {
|
2930
|
+
__name(this, "BaseTransactionRequest");
|
2931
|
+
}
|
2940
2932
|
/** Gas price for transaction */
|
2941
2933
|
tip;
|
2942
2934
|
/** Block until which tx cannot be included */
|
@@ -3019,7 +3011,7 @@ var BaseTransactionRequest = class {
|
|
3019
3011
|
const inputs = this.inputs?.map(inputify) ?? [];
|
3020
3012
|
const outputs = this.outputs?.map(outputify) ?? [];
|
3021
3013
|
const witnesses = this.witnesses?.map(witnessify) ?? [];
|
3022
|
-
const { policyTypes, policies } =
|
3014
|
+
const { policyTypes, policies } = _BaseTransactionRequest.getPolicyMeta(this);
|
3023
3015
|
return {
|
3024
3016
|
policyTypes,
|
3025
3017
|
inputs,
|
@@ -3320,7 +3312,7 @@ var BaseTransactionRequest = class {
|
|
3320
3312
|
* @hidden
|
3321
3313
|
*/
|
3322
3314
|
metadataGas(_gasCosts) {
|
3323
|
-
throw new
|
3315
|
+
throw new FuelError9(FuelError9.CODES.NOT_IMPLEMENTED, "Not implemented");
|
3324
3316
|
}
|
3325
3317
|
/**
|
3326
3318
|
* @hidden
|
@@ -3367,13 +3359,13 @@ var BaseTransactionRequest = class {
|
|
3367
3359
|
* Please use `Account.generateFakeResources` along with `this.addResources` instead.
|
3368
3360
|
*/
|
3369
3361
|
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
3370
|
-
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
3362
|
+
const findAssetInput = /* @__PURE__ */ __name((assetId) => this.inputs.find((input) => {
|
3371
3363
|
if ("assetId" in input) {
|
3372
3364
|
return input.assetId === assetId;
|
3373
3365
|
}
|
3374
3366
|
return false;
|
3375
|
-
});
|
3376
|
-
const updateAssetInput = (assetId, quantity) => {
|
3367
|
+
}), "findAssetInput");
|
3368
|
+
const updateAssetInput = /* @__PURE__ */ __name((assetId, quantity) => {
|
3377
3369
|
const assetInput = findAssetInput(assetId);
|
3378
3370
|
let usedQuantity = quantity;
|
3379
3371
|
if (assetId === baseAssetId) {
|
@@ -3394,7 +3386,7 @@ var BaseTransactionRequest = class {
|
|
3394
3386
|
}
|
3395
3387
|
]);
|
3396
3388
|
}
|
3397
|
-
};
|
3389
|
+
}, "updateAssetInput");
|
3398
3390
|
updateAssetInput(baseAssetId, bn8(1e11));
|
3399
3391
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
3400
3392
|
return this;
|
@@ -3482,6 +3474,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3482
3474
|
transaction.inputs = transaction.inputs.map((input) => {
|
3483
3475
|
const inputClone = clone2(input);
|
3484
3476
|
switch (inputClone.type) {
|
3477
|
+
// Zero out on signing: txPointer, predicateGasUsed
|
3485
3478
|
case InputType4.Coin: {
|
3486
3479
|
inputClone.txPointer = {
|
3487
3480
|
blockHeight: 0,
|
@@ -3490,10 +3483,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3490
3483
|
inputClone.predicateGasUsed = bn9(0);
|
3491
3484
|
return inputClone;
|
3492
3485
|
}
|
3486
|
+
// Zero out on signing: predicateGasUsed
|
3493
3487
|
case InputType4.Message: {
|
3494
3488
|
inputClone.predicateGasUsed = bn9(0);
|
3495
3489
|
return inputClone;
|
3496
3490
|
}
|
3491
|
+
// Zero out on signing: txID, outputIndex, balanceRoot, stateRoot, and txPointer
|
3497
3492
|
case InputType4.Contract: {
|
3498
3493
|
inputClone.txPointer = {
|
3499
3494
|
blockHeight: 0,
|
@@ -3512,15 +3507,18 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3512
3507
|
transaction.outputs = transaction.outputs.map((output) => {
|
3513
3508
|
const outputClone = clone2(output);
|
3514
3509
|
switch (outputClone.type) {
|
3510
|
+
// Zero out on signing: balanceRoot, stateRoot
|
3515
3511
|
case OutputType4.Contract: {
|
3516
3512
|
outputClone.balanceRoot = ZeroBytes325;
|
3517
3513
|
outputClone.stateRoot = ZeroBytes325;
|
3518
3514
|
return outputClone;
|
3519
3515
|
}
|
3516
|
+
// Zero out on signing: amount
|
3520
3517
|
case OutputType4.Change: {
|
3521
3518
|
outputClone.amount = bn9(0);
|
3522
3519
|
return outputClone;
|
3523
3520
|
}
|
3521
|
+
// Zero out on signing: amount, to and assetId
|
3524
3522
|
case OutputType4.Variable: {
|
3525
3523
|
outputClone.to = ZeroBytes325;
|
3526
3524
|
outputClone.amount = bn9(0);
|
@@ -3537,9 +3535,13 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3537
3535
|
const concatenatedData = concat2([chainIdBytes, new TransactionCoder2().encode(transaction)]);
|
3538
3536
|
return sha256(concatenatedData);
|
3539
3537
|
}
|
3538
|
+
__name(hashTransaction, "hashTransaction");
|
3540
3539
|
|
3541
3540
|
// src/providers/transaction-request/blob-transaction-request.ts
|
3542
3541
|
var BlobTransactionRequest = class extends BaseTransactionRequest {
|
3542
|
+
static {
|
3543
|
+
__name(this, "BlobTransactionRequest");
|
3544
|
+
}
|
3543
3545
|
static from(obj) {
|
3544
3546
|
return new this(clone3(obj));
|
3545
3547
|
}
|
@@ -3608,12 +3610,12 @@ import { clone as clone4 } from "ramda";
|
|
3608
3610
|
|
3609
3611
|
// src/providers/transaction-request/storage-slot.ts
|
3610
3612
|
import { arrayify as arrayify5, hexlify as hexlify9 } from "@fuel-ts/utils";
|
3611
|
-
var getStorageValue = (value) => {
|
3613
|
+
var getStorageValue = /* @__PURE__ */ __name((value) => {
|
3612
3614
|
const v = new Uint8Array(32);
|
3613
3615
|
v.set(arrayify5(value));
|
3614
3616
|
return v;
|
3615
|
-
};
|
3616
|
-
var storageSlotify = (storageSlot) => {
|
3617
|
+
}, "getStorageValue");
|
3618
|
+
var storageSlotify = /* @__PURE__ */ __name((storageSlot) => {
|
3617
3619
|
let key;
|
3618
3620
|
let value;
|
3619
3621
|
if (Array.isArray(storageSlot)) {
|
@@ -3627,10 +3629,13 @@ var storageSlotify = (storageSlot) => {
|
|
3627
3629
|
key: hexlify9(key),
|
3628
3630
|
value: hexlify9(getStorageValue(value))
|
3629
3631
|
};
|
3630
|
-
};
|
3632
|
+
}, "storageSlotify");
|
3631
3633
|
|
3632
3634
|
// src/providers/transaction-request/create-transaction-request.ts
|
3633
3635
|
var CreateTransactionRequest = class extends BaseTransactionRequest {
|
3636
|
+
static {
|
3637
|
+
__name(this, "CreateTransactionRequest");
|
3638
|
+
}
|
3634
3639
|
static from(obj) {
|
3635
3640
|
return new this(clone4(obj));
|
3636
3641
|
}
|
@@ -3732,7 +3737,7 @@ var returnZeroScript = {
|
|
3732
3737
|
*/
|
3733
3738
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
3734
3739
|
bytes: arrayify7("0x24000000"),
|
3735
|
-
encodeScriptData: () => new Uint8Array(0)
|
3740
|
+
encodeScriptData: /* @__PURE__ */ __name(() => new Uint8Array(0), "encodeScriptData")
|
3736
3741
|
};
|
3737
3742
|
var withdrawScript = {
|
3738
3743
|
/*
|
@@ -3746,11 +3751,14 @@ var withdrawScript = {
|
|
3746
3751
|
*/
|
3747
3752
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
3748
3753
|
bytes: arrayify7("0x5040C0105D44C0064C40001124000000"),
|
3749
|
-
encodeScriptData: () => new Uint8Array(0)
|
3754
|
+
encodeScriptData: /* @__PURE__ */ __name(() => new Uint8Array(0), "encodeScriptData")
|
3750
3755
|
};
|
3751
3756
|
|
3752
3757
|
// src/providers/transaction-request/script-transaction-request.ts
|
3753
3758
|
var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
3759
|
+
static {
|
3760
|
+
__name(this, "ScriptTransactionRequest");
|
3761
|
+
}
|
3754
3762
|
static from(obj) {
|
3755
3763
|
return new this(clone5(obj));
|
3756
3764
|
}
|
@@ -3943,7 +3951,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3943
3951
|
};
|
3944
3952
|
|
3945
3953
|
// src/providers/transaction-request/upgrade-transaction-request.ts
|
3946
|
-
import { FuelError as
|
3954
|
+
import { FuelError as FuelError10 } from "@fuel-ts/errors";
|
3947
3955
|
import { hash } from "@fuel-ts/hasher";
|
3948
3956
|
import {
|
3949
3957
|
TransactionType as TransactionType5,
|
@@ -3951,9 +3959,12 @@ import {
|
|
3951
3959
|
} from "@fuel-ts/transactions";
|
3952
3960
|
import { hexlify as hexlify12 } from "@fuel-ts/utils";
|
3953
3961
|
import { clone as clone6 } from "ramda";
|
3954
|
-
var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
3962
|
+
var UpgradeTransactionRequest = class _UpgradeTransactionRequest extends BaseTransactionRequest {
|
3963
|
+
static {
|
3964
|
+
__name(this, "UpgradeTransactionRequest");
|
3965
|
+
}
|
3955
3966
|
static from(obj) {
|
3956
|
-
if (obj instanceof
|
3967
|
+
if (obj instanceof _UpgradeTransactionRequest) {
|
3957
3968
|
return obj;
|
3958
3969
|
}
|
3959
3970
|
return new this(clone6(obj));
|
@@ -4050,7 +4061,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
4050
4061
|
}
|
4051
4062
|
};
|
4052
4063
|
} else {
|
4053
|
-
throw new
|
4064
|
+
throw new FuelError10(FuelError10.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
4054
4065
|
}
|
4055
4066
|
return {
|
4056
4067
|
type: TransactionType5.Upgrade,
|
@@ -4092,7 +4103,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
4092
4103
|
txBytesSize
|
4093
4104
|
});
|
4094
4105
|
}
|
4095
|
-
throw new
|
4106
|
+
throw new FuelError10(FuelError10.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
4096
4107
|
}
|
4097
4108
|
};
|
4098
4109
|
|
@@ -4101,9 +4112,12 @@ import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
|
4101
4112
|
import { TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
4102
4113
|
import { arrayify as arrayify9, hexlify as hexlify13 } from "@fuel-ts/utils";
|
4103
4114
|
import { clone as clone7 } from "ramda";
|
4104
|
-
var UploadTransactionRequest = class extends BaseTransactionRequest {
|
4115
|
+
var UploadTransactionRequest = class _UploadTransactionRequest extends BaseTransactionRequest {
|
4116
|
+
static {
|
4117
|
+
__name(this, "UploadTransactionRequest");
|
4118
|
+
}
|
4105
4119
|
static from(obj) {
|
4106
|
-
if (obj instanceof
|
4120
|
+
if (obj instanceof _UploadTransactionRequest) {
|
4107
4121
|
return obj;
|
4108
4122
|
}
|
4109
4123
|
return new this(clone7(obj));
|
@@ -4204,12 +4218,15 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
4204
4218
|
|
4205
4219
|
// src/providers/transaction-request/types.ts
|
4206
4220
|
var AbstractScriptRequest = class {
|
4221
|
+
static {
|
4222
|
+
__name(this, "AbstractScriptRequest");
|
4223
|
+
}
|
4207
4224
|
};
|
4208
4225
|
|
4209
4226
|
// src/providers/transaction-request/utils.ts
|
4210
|
-
import { ErrorCode as ErrorCode9, FuelError as
|
4227
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError11 } from "@fuel-ts/errors";
|
4211
4228
|
import { TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
4212
|
-
var transactionRequestify = (obj) => {
|
4229
|
+
var transactionRequestify = /* @__PURE__ */ __name((obj) => {
|
4213
4230
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest || obj instanceof UpgradeTransactionRequest || obj instanceof UploadTransactionRequest) {
|
4214
4231
|
return obj;
|
4215
4232
|
}
|
@@ -4231,27 +4248,30 @@ var transactionRequestify = (obj) => {
|
|
4231
4248
|
return UploadTransactionRequest.from(obj);
|
4232
4249
|
}
|
4233
4250
|
default: {
|
4234
|
-
throw new
|
4251
|
+
throw new FuelError11(
|
4235
4252
|
ErrorCode9.UNSUPPORTED_TRANSACTION_TYPE,
|
4236
4253
|
`Unsupported transaction type: ${type}.`
|
4237
4254
|
);
|
4238
4255
|
}
|
4239
4256
|
}
|
4240
|
-
};
|
4241
|
-
var isTransactionTypeScript = (request2) => request2.type === TransactionType7.Script;
|
4242
|
-
var isTransactionTypeCreate = (request2) => request2.type === TransactionType7.Create;
|
4243
|
-
var isTransactionTypeBlob = (request2) => request2.type === TransactionType7.Blob;
|
4244
|
-
var isTransactionTypeUpgrade = (request2) => request2.type === TransactionType7.Upgrade;
|
4245
|
-
var isTransactionTypeUpload = (request2) => request2.type === TransactionType7.Upload;
|
4257
|
+
}, "transactionRequestify");
|
4258
|
+
var isTransactionTypeScript = /* @__PURE__ */ __name((request2) => request2.type === TransactionType7.Script, "isTransactionTypeScript");
|
4259
|
+
var isTransactionTypeCreate = /* @__PURE__ */ __name((request2) => request2.type === TransactionType7.Create, "isTransactionTypeCreate");
|
4260
|
+
var isTransactionTypeBlob = /* @__PURE__ */ __name((request2) => request2.type === TransactionType7.Blob, "isTransactionTypeBlob");
|
4261
|
+
var isTransactionTypeUpgrade = /* @__PURE__ */ __name((request2) => request2.type === TransactionType7.Upgrade, "isTransactionTypeUpgrade");
|
4262
|
+
var isTransactionTypeUpload = /* @__PURE__ */ __name((request2) => request2.type === TransactionType7.Upload, "isTransactionTypeUpload");
|
4246
4263
|
|
4247
4264
|
// src/providers/resource-cache.ts
|
4248
4265
|
var cache = /* @__PURE__ */ new Map();
|
4249
4266
|
var ResourceCache = class {
|
4267
|
+
static {
|
4268
|
+
__name(this, "ResourceCache");
|
4269
|
+
}
|
4250
4270
|
ttl;
|
4251
4271
|
constructor(ttl) {
|
4252
4272
|
this.ttl = ttl;
|
4253
4273
|
if (typeof ttl !== "number" || this.ttl <= 0) {
|
4254
|
-
throw new
|
4274
|
+
throw new FuelError12(
|
4255
4275
|
ErrorCode10.INVALID_TTL,
|
4256
4276
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
4257
4277
|
);
|
@@ -4336,7 +4356,7 @@ var ResourceCache = class {
|
|
4336
4356
|
};
|
4337
4357
|
|
4338
4358
|
// src/providers/transaction-response/transaction-response.ts
|
4339
|
-
import { ErrorCode as ErrorCode14, FuelError as
|
4359
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError16 } from "@fuel-ts/errors";
|
4340
4360
|
import { bn as bn16 } from "@fuel-ts/math";
|
4341
4361
|
import { OutputType as OutputType8, TransactionCoder as TransactionCoder4, TxPointerCoder } from "@fuel-ts/transactions";
|
4342
4362
|
import { arrayify as arrayify11, assertUnreachable } from "@fuel-ts/utils";
|
@@ -4350,7 +4370,7 @@ import { DateTime, hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
4350
4370
|
import { bn as bn12 } from "@fuel-ts/math";
|
4351
4371
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType8 } from "@fuel-ts/transactions";
|
4352
4372
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
4353
|
-
var calculateTXFeeForSummary = (params) => {
|
4373
|
+
var calculateTXFeeForSummary = /* @__PURE__ */ __name((params) => {
|
4354
4374
|
const {
|
4355
4375
|
gasPrice,
|
4356
4376
|
rawPayload,
|
@@ -4410,43 +4430,51 @@ var calculateTXFeeForSummary = (params) => {
|
|
4410
4430
|
tip
|
4411
4431
|
});
|
4412
4432
|
return maxFee;
|
4413
|
-
};
|
4433
|
+
}, "calculateTXFeeForSummary");
|
4414
4434
|
|
4415
4435
|
// src/providers/transaction-summary/operations.ts
|
4416
4436
|
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
4417
|
-
import { ErrorCode as ErrorCode12, FuelError as
|
4437
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4418
4438
|
import { bn as bn13 } from "@fuel-ts/math";
|
4419
4439
|
import { ReceiptType as ReceiptType5, TransactionType as TransactionType9 } from "@fuel-ts/transactions";
|
4420
4440
|
|
4421
4441
|
// src/providers/transaction-summary/input.ts
|
4422
|
-
import { ErrorCode as ErrorCode11, FuelError as
|
4442
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4423
4443
|
import { BN } from "@fuel-ts/math";
|
4424
4444
|
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
4425
4445
|
function getInputsByTypes(inputs, types) {
|
4426
4446
|
return inputs.filter((i) => types.includes(i.type));
|
4427
4447
|
}
|
4448
|
+
__name(getInputsByTypes, "getInputsByTypes");
|
4428
4449
|
function getInputsByType(inputs, type) {
|
4429
4450
|
return inputs.filter((i) => i.type === type);
|
4430
4451
|
}
|
4452
|
+
__name(getInputsByType, "getInputsByType");
|
4431
4453
|
function getInputsCoin(inputs) {
|
4432
4454
|
return getInputsByType(inputs, InputType6.Coin);
|
4433
4455
|
}
|
4456
|
+
__name(getInputsCoin, "getInputsCoin");
|
4434
4457
|
function getInputsMessage(inputs) {
|
4435
4458
|
return getInputsByType(inputs, InputType6.Message);
|
4436
4459
|
}
|
4460
|
+
__name(getInputsMessage, "getInputsMessage");
|
4437
4461
|
function getInputsCoinAndMessage(inputs) {
|
4438
4462
|
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
4439
4463
|
}
|
4464
|
+
__name(getInputsCoinAndMessage, "getInputsCoinAndMessage");
|
4440
4465
|
function isInputCoin(input) {
|
4441
4466
|
return input.type === InputType6.Coin;
|
4442
4467
|
}
|
4468
|
+
__name(isInputCoin, "isInputCoin");
|
4443
4469
|
function getInputsContract(inputs) {
|
4444
4470
|
return getInputsByType(inputs, InputType6.Contract);
|
4445
4471
|
}
|
4472
|
+
__name(getInputsContract, "getInputsContract");
|
4446
4473
|
function findCoinInput(inputs, assetId) {
|
4447
4474
|
const coinInputs = getInputsCoin(inputs);
|
4448
4475
|
return coinInputs.find((i) => i.assetId === assetId);
|
4449
4476
|
}
|
4477
|
+
__name(findCoinInput, "findCoinInput");
|
4450
4478
|
function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId) {
|
4451
4479
|
const aggregated = /* @__PURE__ */ new Map();
|
4452
4480
|
getInputsCoinAndMessage(inputs).forEach((input) => {
|
@@ -4466,9 +4494,11 @@ function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId) {
|
|
4466
4494
|
});
|
4467
4495
|
return aggregated;
|
4468
4496
|
}
|
4497
|
+
__name(aggregateInputsAmountsByAssetAndOwner, "aggregateInputsAmountsByAssetAndOwner");
|
4469
4498
|
function findMessageInput(inputs) {
|
4470
4499
|
return getInputsMessage(inputs)?.[0];
|
4471
4500
|
}
|
4501
|
+
__name(findMessageInput, "findMessageInput");
|
4472
4502
|
function getInputFromAssetId(inputs, assetId, isBaseAsset = false) {
|
4473
4503
|
const coinInput = findCoinInput(inputs, assetId);
|
4474
4504
|
if (coinInput) {
|
@@ -4479,6 +4509,7 @@ function getInputFromAssetId(inputs, assetId, isBaseAsset = false) {
|
|
4479
4509
|
}
|
4480
4510
|
return void 0;
|
4481
4511
|
}
|
4512
|
+
__name(getInputFromAssetId, "getInputFromAssetId");
|
4482
4513
|
function getInputContractFromIndex(inputs, inputIndex) {
|
4483
4514
|
if (inputIndex == null) {
|
4484
4515
|
return void 0;
|
@@ -4488,13 +4519,14 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
4488
4519
|
return void 0;
|
4489
4520
|
}
|
4490
4521
|
if (contractInput.type !== InputType6.Contract) {
|
4491
|
-
throw new
|
4522
|
+
throw new FuelError13(
|
4492
4523
|
ErrorCode11.INVALID_TRANSACTION_INPUT,
|
4493
4524
|
`Contract input should be of type 'contract'.`
|
4494
4525
|
);
|
4495
4526
|
}
|
4496
4527
|
return contractInput;
|
4497
4528
|
}
|
4529
|
+
__name(getInputContractFromIndex, "getInputContractFromIndex");
|
4498
4530
|
function getInputAccountAddress(input) {
|
4499
4531
|
if (input.type === InputType6.Coin) {
|
4500
4532
|
return input.owner.toString();
|
@@ -4504,27 +4536,34 @@ function getInputAccountAddress(input) {
|
|
4504
4536
|
}
|
4505
4537
|
return "";
|
4506
4538
|
}
|
4539
|
+
__name(getInputAccountAddress, "getInputAccountAddress");
|
4507
4540
|
|
4508
4541
|
// src/providers/transaction-summary/output.ts
|
4509
4542
|
import { OutputType as OutputType7 } from "@fuel-ts/transactions";
|
4510
4543
|
function getOutputsByType(outputs, type) {
|
4511
4544
|
return outputs.filter((o) => o.type === type);
|
4512
4545
|
}
|
4546
|
+
__name(getOutputsByType, "getOutputsByType");
|
4513
4547
|
function getOutputsContractCreated(outputs) {
|
4514
4548
|
return getOutputsByType(outputs, OutputType7.ContractCreated);
|
4515
4549
|
}
|
4550
|
+
__name(getOutputsContractCreated, "getOutputsContractCreated");
|
4516
4551
|
function getOutputsCoin(outputs) {
|
4517
4552
|
return getOutputsByType(outputs, OutputType7.Coin);
|
4518
4553
|
}
|
4554
|
+
__name(getOutputsCoin, "getOutputsCoin");
|
4519
4555
|
function getOutputsChange(outputs) {
|
4520
4556
|
return getOutputsByType(outputs, OutputType7.Change);
|
4521
4557
|
}
|
4558
|
+
__name(getOutputsChange, "getOutputsChange");
|
4522
4559
|
function getOutputsContract(outputs) {
|
4523
4560
|
return getOutputsByType(outputs, OutputType7.Contract);
|
4524
4561
|
}
|
4562
|
+
__name(getOutputsContract, "getOutputsContract");
|
4525
4563
|
function getOutputsVariable(outputs) {
|
4526
4564
|
return getOutputsByType(outputs, OutputType7.Variable);
|
4527
4565
|
}
|
4566
|
+
__name(getOutputsVariable, "getOutputsVariable");
|
4528
4567
|
|
4529
4568
|
// src/providers/transaction-summary/types.ts
|
4530
4569
|
var TransactionTypeName = /* @__PURE__ */ ((TransactionTypeName2) => {
|
@@ -4567,6 +4606,7 @@ var ChainName = /* @__PURE__ */ ((ChainName2) => {
|
|
4567
4606
|
function getReceiptsByType(receipts, type) {
|
4568
4607
|
return (receipts ?? []).filter((r) => r.type === type);
|
4569
4608
|
}
|
4609
|
+
__name(getReceiptsByType, "getReceiptsByType");
|
4570
4610
|
function getTransactionTypeName(transactionType) {
|
4571
4611
|
switch (transactionType) {
|
4572
4612
|
case TransactionType9.Mint:
|
@@ -4582,43 +4622,54 @@ function getTransactionTypeName(transactionType) {
|
|
4582
4622
|
case TransactionType9.Upload:
|
4583
4623
|
return "Upload" /* Upload */;
|
4584
4624
|
default:
|
4585
|
-
throw new
|
4625
|
+
throw new FuelError14(
|
4586
4626
|
ErrorCode12.UNSUPPORTED_TRANSACTION_TYPE,
|
4587
4627
|
`Unsupported transaction type: ${transactionType}.`
|
4588
4628
|
);
|
4589
4629
|
}
|
4590
4630
|
}
|
4631
|
+
__name(getTransactionTypeName, "getTransactionTypeName");
|
4591
4632
|
function isType(transactionType, type) {
|
4592
4633
|
const txType = getTransactionTypeName(transactionType);
|
4593
4634
|
return txType === type;
|
4594
4635
|
}
|
4636
|
+
__name(isType, "isType");
|
4595
4637
|
function isTypeMint(transactionType) {
|
4596
4638
|
return isType(transactionType, "Mint" /* Mint */);
|
4597
4639
|
}
|
4640
|
+
__name(isTypeMint, "isTypeMint");
|
4598
4641
|
function isTypeCreate(transactionType) {
|
4599
4642
|
return isType(transactionType, "Create" /* Create */);
|
4600
4643
|
}
|
4644
|
+
__name(isTypeCreate, "isTypeCreate");
|
4601
4645
|
function isTypeScript(transactionType) {
|
4602
4646
|
return isType(transactionType, "Script" /* Script */);
|
4603
4647
|
}
|
4648
|
+
__name(isTypeScript, "isTypeScript");
|
4604
4649
|
function isTypeUpgrade(transactionType) {
|
4605
4650
|
return isType(transactionType, "Upgrade" /* Upgrade */);
|
4606
4651
|
}
|
4652
|
+
__name(isTypeUpgrade, "isTypeUpgrade");
|
4607
4653
|
function isTypeUpload(transactionType) {
|
4608
4654
|
return isType(transactionType, "Upload" /* Upload */);
|
4609
4655
|
}
|
4656
|
+
__name(isTypeUpload, "isTypeUpload");
|
4610
4657
|
function isTypeBlob(transactionType) {
|
4611
4658
|
return isType(transactionType, "Blob" /* Blob */);
|
4612
4659
|
}
|
4660
|
+
__name(isTypeBlob, "isTypeBlob");
|
4613
4661
|
function hasSameAssetId(a) {
|
4614
4662
|
return (b) => a.assetId === b.assetId;
|
4615
4663
|
}
|
4664
|
+
__name(hasSameAssetId, "hasSameAssetId");
|
4616
4665
|
function getReceiptsCall(receipts) {
|
4617
4666
|
return getReceiptsByType(receipts, ReceiptType5.Call);
|
4618
4667
|
}
|
4668
|
+
__name(getReceiptsCall, "getReceiptsCall");
|
4619
4669
|
function getReceiptsMessageOut(receipts) {
|
4620
4670
|
return getReceiptsByType(receipts, ReceiptType5.MessageOut);
|
4621
4671
|
}
|
4672
|
+
__name(getReceiptsMessageOut, "getReceiptsMessageOut");
|
4622
4673
|
function mergeAssets(op1, op2) {
|
4623
4674
|
const assets1 = op1.assetsSent || [];
|
4624
4675
|
const assets2 = op2.assetsSent || [];
|
@@ -4636,21 +4687,25 @@ function mergeAssets(op1, op2) {
|
|
4636
4687
|
});
|
4637
4688
|
return Array.from(assetMap.values());
|
4638
4689
|
}
|
4690
|
+
__name(mergeAssets, "mergeAssets");
|
4639
4691
|
function isSameOperation(a, b) {
|
4640
4692
|
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;
|
4641
4693
|
}
|
4694
|
+
__name(isSameOperation, "isSameOperation");
|
4642
4695
|
function mergeAssetsSent(existing, toAdd) {
|
4643
4696
|
if (!toAdd.assetsSent?.length) {
|
4644
4697
|
return existing.assetsSent;
|
4645
4698
|
}
|
4646
4699
|
return existing.assetsSent?.length ? mergeAssets(existing, toAdd) : toAdd.assetsSent;
|
4647
4700
|
}
|
4701
|
+
__name(mergeAssetsSent, "mergeAssetsSent");
|
4648
4702
|
function mergeCalls(existing, toAdd) {
|
4649
4703
|
if (!toAdd.calls?.length) {
|
4650
4704
|
return existing.calls;
|
4651
4705
|
}
|
4652
4706
|
return [...existing.calls || [], ...toAdd.calls];
|
4653
4707
|
}
|
4708
|
+
__name(mergeCalls, "mergeCalls");
|
4654
4709
|
function mergeOperations(existing, toAdd) {
|
4655
4710
|
return {
|
4656
4711
|
...existing,
|
@@ -4662,6 +4717,7 @@ function mergeOperations(existing, toAdd) {
|
|
4662
4717
|
]
|
4663
4718
|
};
|
4664
4719
|
}
|
4720
|
+
__name(mergeOperations, "mergeOperations");
|
4665
4721
|
function addOperation(operations, toAdd) {
|
4666
4722
|
const existingIndex = operations.findIndex((op) => isSameOperation(op, toAdd));
|
4667
4723
|
if (existingIndex === -1) {
|
@@ -4669,9 +4725,11 @@ function addOperation(operations, toAdd) {
|
|
4669
4725
|
}
|
4670
4726
|
return operations.map((op, index) => index === existingIndex ? mergeOperations(op, toAdd) : op);
|
4671
4727
|
}
|
4728
|
+
__name(addOperation, "addOperation");
|
4672
4729
|
function getReceiptsTransferOut(receipts) {
|
4673
4730
|
return getReceiptsByType(receipts, ReceiptType5.TransferOut);
|
4674
4731
|
}
|
4732
|
+
__name(getReceiptsTransferOut, "getReceiptsTransferOut");
|
4675
4733
|
function getWithdrawFromFuelOperations({
|
4676
4734
|
inputs,
|
4677
4735
|
receipts,
|
@@ -4710,6 +4768,7 @@ function getWithdrawFromFuelOperations({
|
|
4710
4768
|
);
|
4711
4769
|
return withdrawFromFuelOperations;
|
4712
4770
|
}
|
4771
|
+
__name(getWithdrawFromFuelOperations, "getWithdrawFromFuelOperations");
|
4713
4772
|
function getContractCalls(contractInput, abiMap, _receipt, _rawPayload, _maxInputs) {
|
4714
4773
|
const abi = abiMap?.[contractInput.contractID];
|
4715
4774
|
if (!abi) {
|
@@ -4717,6 +4776,7 @@ function getContractCalls(contractInput, abiMap, _receipt, _rawPayload, _maxInpu
|
|
4717
4776
|
}
|
4718
4777
|
return [];
|
4719
4778
|
}
|
4779
|
+
__name(getContractCalls, "getContractCalls");
|
4720
4780
|
function getAssetsSent(receipt) {
|
4721
4781
|
return receipt.amount?.isZero() ? void 0 : [
|
4722
4782
|
{
|
@@ -4725,6 +4785,7 @@ function getAssetsSent(receipt) {
|
|
4725
4785
|
}
|
4726
4786
|
];
|
4727
4787
|
}
|
4788
|
+
__name(getAssetsSent, "getAssetsSent");
|
4728
4789
|
function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload, maxInputs, baseAssetId) {
|
4729
4790
|
const assetId = receipt.assetId === ZeroBytes329 ? baseAssetId : receipt.assetId;
|
4730
4791
|
const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
|
@@ -4750,6 +4811,7 @@ function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload,
|
|
4750
4811
|
}
|
4751
4812
|
];
|
4752
4813
|
}
|
4814
|
+
__name(processCallReceipt, "processCallReceipt");
|
4753
4815
|
function getContractCallOperations({
|
4754
4816
|
inputs,
|
4755
4817
|
outputs,
|
@@ -4779,6 +4841,7 @@ function getContractCallOperations({
|
|
4779
4841
|
);
|
4780
4842
|
});
|
4781
4843
|
}
|
4844
|
+
__name(getContractCallOperations, "getContractCallOperations");
|
4782
4845
|
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
4783
4846
|
const { to: toAddress, assetId, amount } = receipt;
|
4784
4847
|
let { id: fromAddress } = receipt;
|
@@ -4807,6 +4870,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
4807
4870
|
receipts: [receipt]
|
4808
4871
|
};
|
4809
4872
|
}
|
4873
|
+
__name(extractTransferOperationFromReceipt, "extractTransferOperationFromReceipt");
|
4810
4874
|
function getTransferOperations({
|
4811
4875
|
inputs,
|
4812
4876
|
outputs,
|
@@ -4861,6 +4925,7 @@ function getTransferOperations({
|
|
4861
4925
|
});
|
4862
4926
|
return operations;
|
4863
4927
|
}
|
4928
|
+
__name(getTransferOperations, "getTransferOperations");
|
4864
4929
|
function getPayProducerOperations(outputs) {
|
4865
4930
|
const coinOutputs = getOutputsCoin(outputs);
|
4866
4931
|
const payProducerOperations = coinOutputs.reduce((prev, output) => {
|
@@ -4885,6 +4950,7 @@ function getPayProducerOperations(outputs) {
|
|
4885
4950
|
}, []);
|
4886
4951
|
return payProducerOperations;
|
4887
4952
|
}
|
4953
|
+
__name(getPayProducerOperations, "getPayProducerOperations");
|
4888
4954
|
function getContractCreatedOperations({ inputs, outputs }) {
|
4889
4955
|
const contractCreatedOutputs = getOutputsContractCreated(outputs);
|
4890
4956
|
const input = getInputsCoinAndMessage(inputs)[0];
|
@@ -4905,6 +4971,7 @@ function getContractCreatedOperations({ inputs, outputs }) {
|
|
4905
4971
|
}, []);
|
4906
4972
|
return contractCreatedOperations;
|
4907
4973
|
}
|
4974
|
+
__name(getContractCreatedOperations, "getContractCreatedOperations");
|
4908
4975
|
function getOperations({
|
4909
4976
|
transactionType,
|
4910
4977
|
inputs,
|
@@ -4935,11 +5002,12 @@ function getOperations({
|
|
4935
5002
|
}
|
4936
5003
|
return [...getPayProducerOperations(outputs)];
|
4937
5004
|
}
|
5005
|
+
__name(getOperations, "getOperations");
|
4938
5006
|
|
4939
5007
|
// src/providers/transaction-summary/receipt.ts
|
4940
5008
|
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
4941
|
-
var processGqlReceipt = (gqlReceipt) => deserializeReceipt(gqlReceipt);
|
4942
|
-
var extractMintedAssetsFromReceipts = (receipts) => {
|
5009
|
+
var processGqlReceipt = /* @__PURE__ */ __name((gqlReceipt) => deserializeReceipt(gqlReceipt), "processGqlReceipt");
|
5010
|
+
var extractMintedAssetsFromReceipts = /* @__PURE__ */ __name((receipts) => {
|
4943
5011
|
const mintedAssets = [];
|
4944
5012
|
receipts.forEach((receipt) => {
|
4945
5013
|
if (receipt.type === ReceiptType6.Mint) {
|
@@ -4952,8 +5020,8 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
4952
5020
|
}
|
4953
5021
|
});
|
4954
5022
|
return mintedAssets;
|
4955
|
-
};
|
4956
|
-
var extractBurnedAssetsFromReceipts = (receipts) => {
|
5023
|
+
}, "extractMintedAssetsFromReceipts");
|
5024
|
+
var extractBurnedAssetsFromReceipts = /* @__PURE__ */ __name((receipts) => {
|
4957
5025
|
const burnedAssets = [];
|
4958
5026
|
receipts.forEach((receipt) => {
|
4959
5027
|
if (receipt.type === ReceiptType6.Burn) {
|
@@ -4966,12 +5034,12 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
4966
5034
|
}
|
4967
5035
|
});
|
4968
5036
|
return burnedAssets;
|
4969
|
-
};
|
5037
|
+
}, "extractBurnedAssetsFromReceipts");
|
4970
5038
|
|
4971
5039
|
// src/providers/transaction-summary/status.ts
|
4972
|
-
import { ErrorCode as ErrorCode13, FuelError as
|
5040
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError15 } from "@fuel-ts/errors";
|
4973
5041
|
import { bn as bn14 } from "@fuel-ts/math";
|
4974
|
-
var getTransactionStatusName = (gqlStatus) => {
|
5042
|
+
var getTransactionStatusName = /* @__PURE__ */ __name((gqlStatus) => {
|
4975
5043
|
switch (gqlStatus) {
|
4976
5044
|
case "FailureStatus":
|
4977
5045
|
return "failure" /* failure */;
|
@@ -4982,13 +5050,13 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
4982
5050
|
case "SqueezedOutStatus":
|
4983
5051
|
return "squeezedout" /* squeezedout */;
|
4984
5052
|
default:
|
4985
|
-
throw new
|
5053
|
+
throw new FuelError15(
|
4986
5054
|
ErrorCode13.INVALID_TRANSACTION_STATUS,
|
4987
5055
|
`Invalid transaction status: ${gqlStatus}.`
|
4988
5056
|
);
|
4989
5057
|
}
|
4990
|
-
};
|
4991
|
-
var processGraphqlStatus = (gqlTransactionStatus) => {
|
5058
|
+
}, "getTransactionStatusName");
|
5059
|
+
var processGraphqlStatus = /* @__PURE__ */ __name((gqlTransactionStatus) => {
|
4992
5060
|
let time;
|
4993
5061
|
let blockId;
|
4994
5062
|
let status;
|
@@ -5032,8 +5100,8 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
5032
5100
|
isStatusPending
|
5033
5101
|
};
|
5034
5102
|
return processedGraphqlStatus;
|
5035
|
-
};
|
5036
|
-
var getTotalFeeFromStatus = (status) => status && "totalFee" in status ? bn14(status.totalFee) : void 0;
|
5103
|
+
}, "processGraphqlStatus");
|
5104
|
+
var getTotalFeeFromStatus = /* @__PURE__ */ __name((status) => status && "totalFee" in status ? bn14(status.totalFee) : void 0, "getTotalFeeFromStatus");
|
5037
5105
|
|
5038
5106
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
5039
5107
|
function assembleTransactionSummary(params) {
|
@@ -5113,12 +5181,14 @@ function assembleTransactionSummary(params) {
|
|
5113
5181
|
};
|
5114
5182
|
return transactionSummary;
|
5115
5183
|
}
|
5184
|
+
__name(assembleTransactionSummary, "assembleTransactionSummary");
|
5116
5185
|
|
5117
|
-
// src/providers/transaction-response/
|
5186
|
+
// src/providers/transaction-response/getAllDecodedLogs.ts
|
5118
5187
|
import { Interface as Interface2, BigNumberCoder } from "@fuel-ts/abi-coder";
|
5119
5188
|
import { ZeroBytes32 as ZeroBytes3210 } from "@fuel-ts/address/configs";
|
5120
5189
|
import { ReceiptType as ReceiptType7 } from "@fuel-ts/transactions";
|
5121
|
-
function
|
5190
|
+
function getAllDecodedLogs(opts) {
|
5191
|
+
const { receipts, mainAbi, externalAbis = {} } = opts;
|
5122
5192
|
let mainContract = "";
|
5123
5193
|
if (mainAbi.programType === "contract") {
|
5124
5194
|
const firstCallReceipt = receipts.find(
|
@@ -5126,20 +5196,25 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
5126
5196
|
);
|
5127
5197
|
mainContract = firstCallReceipt.to;
|
5128
5198
|
}
|
5129
|
-
return receipts.reduce(
|
5130
|
-
|
5131
|
-
|
5132
|
-
|
5133
|
-
|
5134
|
-
|
5135
|
-
|
5136
|
-
|
5137
|
-
|
5199
|
+
return receipts.reduce(
|
5200
|
+
({ logs, groupedLogs }, receipt) => {
|
5201
|
+
if (receipt.type === ReceiptType7.LogData || receipt.type === ReceiptType7.Log) {
|
5202
|
+
const isLogFromMainAbi = receipt.id === ZeroBytes3210 || mainContract === receipt.id;
|
5203
|
+
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
5204
|
+
if (isDecodable) {
|
5205
|
+
const interfaceToUse = isLogFromMainAbi ? new Interface2(mainAbi) : new Interface2(externalAbis[receipt.id]);
|
5206
|
+
const data = receipt.type === ReceiptType7.Log ? new BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
5207
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
5208
|
+
logs.push(decodedLog);
|
5209
|
+
groupedLogs[receipt.id] = [...groupedLogs[receipt.id] || [], decodedLog];
|
5210
|
+
}
|
5138
5211
|
}
|
5139
|
-
|
5140
|
-
|
5141
|
-
|
5212
|
+
return { logs, groupedLogs };
|
5213
|
+
},
|
5214
|
+
{ logs: [], groupedLogs: {} }
|
5215
|
+
);
|
5142
5216
|
}
|
5217
|
+
__name(getAllDecodedLogs, "getAllDecodedLogs");
|
5143
5218
|
|
5144
5219
|
// src/providers/transaction-response/transaction-response.ts
|
5145
5220
|
function mapGqlOutputsToTxOutputs(outputs) {
|
@@ -5172,7 +5247,8 @@ function mapGqlOutputsToTxOutputs(outputs) {
|
|
5172
5247
|
}
|
5173
5248
|
});
|
5174
5249
|
}
|
5175
|
-
|
5250
|
+
__name(mapGqlOutputsToTxOutputs, "mapGqlOutputsToTxOutputs");
|
5251
|
+
var TransactionResponse = class _TransactionResponse {
|
5176
5252
|
/**
|
5177
5253
|
* Constructor for `TransactionResponse`.
|
5178
5254
|
*
|
@@ -5187,6 +5263,9 @@ var TransactionResponse = class {
|
|
5187
5263
|
this.request = typeof tx === "string" ? void 0 : tx;
|
5188
5264
|
this.waitForResult = this.waitForResult.bind(this);
|
5189
5265
|
}
|
5266
|
+
static {
|
5267
|
+
__name(this, "TransactionResponse");
|
5268
|
+
}
|
5190
5269
|
/** Transaction ID */
|
5191
5270
|
id;
|
5192
5271
|
/** Current provider */
|
@@ -5208,7 +5287,7 @@ var TransactionResponse = class {
|
|
5208
5287
|
*/
|
5209
5288
|
static async create(id, provider, abis) {
|
5210
5289
|
const chainId = await provider.getChainId();
|
5211
|
-
const response = new
|
5290
|
+
const response = new _TransactionResponse(id, provider, chainId, abis);
|
5212
5291
|
await response.fetch();
|
5213
5292
|
return response;
|
5214
5293
|
}
|
@@ -5340,7 +5419,7 @@ var TransactionResponse = class {
|
|
5340
5419
|
this.status = statusChange;
|
5341
5420
|
if (statusChange.type === "SqueezedOutStatus") {
|
5342
5421
|
this.unsetResourceCache();
|
5343
|
-
throw new
|
5422
|
+
throw new FuelError16(
|
5344
5423
|
ErrorCode14.TRANSACTION_SQUEEZED_OUT,
|
5345
5424
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
5346
5425
|
);
|
@@ -5367,14 +5446,15 @@ var TransactionResponse = class {
|
|
5367
5446
|
const transactionResult = {
|
5368
5447
|
...transactionSummary
|
5369
5448
|
};
|
5370
|
-
let logs = [];
|
5449
|
+
let { logs, groupedLogs } = { logs: [], groupedLogs: {} };
|
5371
5450
|
if (this.abis) {
|
5372
|
-
logs =
|
5373
|
-
transactionSummary.receipts,
|
5374
|
-
this.abis.main,
|
5375
|
-
this.abis.otherContractsAbis
|
5376
|
-
);
|
5451
|
+
({ logs, groupedLogs } = getAllDecodedLogs({
|
5452
|
+
receipts: transactionSummary.receipts,
|
5453
|
+
mainAbi: this.abis.main,
|
5454
|
+
externalAbis: this.abis.otherContractsAbis
|
5455
|
+
}));
|
5377
5456
|
transactionResult.logs = logs;
|
5457
|
+
transactionResult.groupedLogs = groupedLogs;
|
5378
5458
|
}
|
5379
5459
|
const { receipts } = transactionResult;
|
5380
5460
|
const status = this.status ?? this.gqlTransaction?.status;
|
@@ -5383,7 +5463,8 @@ var TransactionResponse = class {
|
|
5383
5463
|
throw extractTxError({
|
5384
5464
|
receipts,
|
5385
5465
|
statusReason: reason,
|
5386
|
-
logs
|
5466
|
+
logs,
|
5467
|
+
groupedLogs
|
5387
5468
|
});
|
5388
5469
|
}
|
5389
5470
|
return transactionResult;
|
@@ -5411,6 +5492,34 @@ var TransactionResponse = class {
|
|
5411
5492
|
}
|
5412
5493
|
};
|
5413
5494
|
|
5495
|
+
// src/providers/transaction-response/getDecodedLogs.ts
|
5496
|
+
import { Interface as Interface3, BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
|
5497
|
+
import { ZeroBytes32 as ZeroBytes3211 } from "@fuel-ts/address/configs";
|
5498
|
+
import { ReceiptType as ReceiptType8 } from "@fuel-ts/transactions";
|
5499
|
+
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
5500
|
+
let mainContract = "";
|
5501
|
+
if (mainAbi.programType === "contract") {
|
5502
|
+
const firstCallReceipt = receipts.find(
|
5503
|
+
(r) => r.type === ReceiptType8.Call && r.id === ZeroBytes3211
|
5504
|
+
);
|
5505
|
+
mainContract = firstCallReceipt.to;
|
5506
|
+
}
|
5507
|
+
return receipts.reduce((logs, receipt) => {
|
5508
|
+
if (receipt.type === ReceiptType8.LogData || receipt.type === ReceiptType8.Log) {
|
5509
|
+
const isLogFromMainAbi = receipt.id === ZeroBytes3211 || mainContract === receipt.id;
|
5510
|
+
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
5511
|
+
if (isDecodable) {
|
5512
|
+
const interfaceToUse = isLogFromMainAbi ? new Interface3(mainAbi) : new Interface3(externalAbis[receipt.id]);
|
5513
|
+
const data = receipt.type === ReceiptType8.Log ? new BigNumberCoder2("u64").encode(receipt.ra) : receipt.data;
|
5514
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
5515
|
+
logs.push(decodedLog);
|
5516
|
+
}
|
5517
|
+
}
|
5518
|
+
return logs;
|
5519
|
+
}, []);
|
5520
|
+
}
|
5521
|
+
__name(getDecodedLogs, "getDecodedLogs");
|
5522
|
+
|
5414
5523
|
// src/providers/utils/auto-retry-fetch.ts
|
5415
5524
|
import { sleep } from "@fuel-ts/utils";
|
5416
5525
|
function getWaitDelay(options, retryAttemptNum) {
|
@@ -5425,6 +5534,7 @@ function getWaitDelay(options, retryAttemptNum) {
|
|
5425
5534
|
return 2 ** (retryAttemptNum - 1) * duration;
|
5426
5535
|
}
|
5427
5536
|
}
|
5537
|
+
__name(getWaitDelay, "getWaitDelay");
|
5428
5538
|
function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
5429
5539
|
if (options === void 0) {
|
5430
5540
|
return fetchFn;
|
@@ -5447,9 +5557,10 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
5447
5557
|
}
|
5448
5558
|
};
|
5449
5559
|
}
|
5560
|
+
__name(autoRetryFetch, "autoRetryFetch");
|
5450
5561
|
|
5451
5562
|
// src/providers/utils/helpers.ts
|
5452
|
-
var adjustResourcesToExclude = (params) => {
|
5563
|
+
var adjustResourcesToExclude = /* @__PURE__ */ __name((params) => {
|
5453
5564
|
const { userInput, cached, maxInputs } = params;
|
5454
5565
|
const final = { ...userInput };
|
5455
5566
|
let total = final.utxos.length + final.messages.length;
|
@@ -5462,33 +5573,33 @@ var adjustResourcesToExclude = (params) => {
|
|
5462
5573
|
final.messages = [...final.messages, ...cached.messages.slice(0, maxInputs - total)];
|
5463
5574
|
}
|
5464
5575
|
return final;
|
5465
|
-
};
|
5576
|
+
}, "adjustResourcesToExclude");
|
5466
5577
|
|
5467
5578
|
// src/providers/utils/validate-pagination-args.ts
|
5468
|
-
import { FuelError as
|
5469
|
-
var validatePaginationArgs = (params) => {
|
5579
|
+
import { FuelError as FuelError17, ErrorCode as ErrorCode15 } from "@fuel-ts/errors";
|
5580
|
+
var validatePaginationArgs = /* @__PURE__ */ __name((params) => {
|
5470
5581
|
const { paginationLimit, inputArgs = {} } = params;
|
5471
5582
|
const { first, last, after, before } = inputArgs;
|
5472
5583
|
if (after && before) {
|
5473
|
-
throw new
|
5584
|
+
throw new FuelError17(
|
5474
5585
|
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
5475
5586
|
'Pagination arguments "after" and "before" cannot be used together'
|
5476
5587
|
);
|
5477
5588
|
}
|
5478
5589
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5479
|
-
throw new
|
5590
|
+
throw new FuelError17(
|
5480
5591
|
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
5481
5592
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5482
5593
|
);
|
5483
5594
|
}
|
5484
5595
|
if (first && before) {
|
5485
|
-
throw new
|
5596
|
+
throw new FuelError17(
|
5486
5597
|
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
5487
5598
|
'The use of pagination argument "first" with "before" is not supported'
|
5488
5599
|
);
|
5489
5600
|
}
|
5490
5601
|
if (last && after) {
|
5491
|
-
throw new
|
5602
|
+
throw new FuelError17(
|
5492
5603
|
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
5493
5604
|
'The use of pagination argument "last" with "after" is not supported'
|
5494
5605
|
);
|
@@ -5497,18 +5608,71 @@ var validatePaginationArgs = (params) => {
|
|
5497
5608
|
inputArgs.first = paginationLimit;
|
5498
5609
|
}
|
5499
5610
|
return inputArgs;
|
5500
|
-
};
|
5611
|
+
}, "validatePaginationArgs");
|
5501
5612
|
|
5502
5613
|
// src/providers/provider.ts
|
5503
5614
|
var MAX_RETRIES = 10;
|
5504
5615
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
5505
5616
|
var TRANSACTIONS_PAGE_SIZE_LIMIT = 60;
|
5506
5617
|
var BALANCES_PAGE_SIZE_LIMIT = 100;
|
5618
|
+
var NON_PAGINATED_BALANCES_SIZE = 1e4;
|
5507
5619
|
var BLOCKS_PAGE_SIZE_LIMIT = 5;
|
5508
5620
|
var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
|
5509
5621
|
var GAS_USED_MODIFIER = 1.2;
|
5510
|
-
var
|
5511
|
-
|
5622
|
+
var Provider = class _Provider {
|
5623
|
+
static {
|
5624
|
+
__name(this, "Provider");
|
5625
|
+
}
|
5626
|
+
operations;
|
5627
|
+
cache;
|
5628
|
+
/** @hidden */
|
5629
|
+
static clearChainAndNodeCaches() {
|
5630
|
+
_Provider.inflightFetchChainAndNodeInfoRequests = {};
|
5631
|
+
_Provider.nodeInfoCache = {};
|
5632
|
+
_Provider.chainInfoCache = {};
|
5633
|
+
}
|
5634
|
+
/** @hidden */
|
5635
|
+
url;
|
5636
|
+
/** @hidden */
|
5637
|
+
urlWithoutAuth;
|
5638
|
+
/** @hidden */
|
5639
|
+
static inflightFetchChainAndNodeInfoRequests = {};
|
5640
|
+
/** @hidden */
|
5641
|
+
static chainInfoCache = {};
|
5642
|
+
/** @hidden */
|
5643
|
+
static nodeInfoCache = {};
|
5644
|
+
/** @hidden */
|
5645
|
+
static incompatibleNodeVersionMessage = "";
|
5646
|
+
/** @hidden */
|
5647
|
+
consensusParametersTimestamp;
|
5648
|
+
options = {
|
5649
|
+
timeout: void 0,
|
5650
|
+
resourceCacheTTL: void 0,
|
5651
|
+
fetch: void 0,
|
5652
|
+
retryOptions: void 0,
|
5653
|
+
headers: void 0,
|
5654
|
+
cache: void 0
|
5655
|
+
};
|
5656
|
+
/**
|
5657
|
+
* @hidden
|
5658
|
+
*/
|
5659
|
+
static getFetchFn(options) {
|
5660
|
+
const { retryOptions, timeout, headers } = options;
|
5661
|
+
return autoRetryFetch(async (...args) => {
|
5662
|
+
const url = args[0];
|
5663
|
+
const request2 = args[1];
|
5664
|
+
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
5665
|
+
let fullRequest = {
|
5666
|
+
...request2,
|
5667
|
+
signal,
|
5668
|
+
headers: { ...request2?.headers, ...headers }
|
5669
|
+
};
|
5670
|
+
if (options.requestMiddleware) {
|
5671
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
5672
|
+
}
|
5673
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
5674
|
+
}, retryOptions);
|
5675
|
+
}
|
5512
5676
|
/**
|
5513
5677
|
* Constructor to initialize a Provider.
|
5514
5678
|
*
|
@@ -5517,31 +5681,6 @@ var _Provider = class {
|
|
5517
5681
|
* @hidden
|
5518
5682
|
*/
|
5519
5683
|
constructor(url, options = {}) {
|
5520
|
-
/**
|
5521
|
-
* @hidden
|
5522
|
-
*/
|
5523
|
-
__privateAdd(this, _cacheInputs);
|
5524
|
-
__publicField(this, "operations");
|
5525
|
-
__publicField(this, "cache");
|
5526
|
-
/** @hidden */
|
5527
|
-
__publicField(this, "url");
|
5528
|
-
/** @hidden */
|
5529
|
-
__publicField(this, "urlWithoutAuth");
|
5530
|
-
/** @hidden */
|
5531
|
-
__publicField(this, "features", {
|
5532
|
-
balancePagination: false,
|
5533
|
-
amount128: false
|
5534
|
-
});
|
5535
|
-
/** @hidden */
|
5536
|
-
__publicField(this, "consensusParametersTimestamp");
|
5537
|
-
__publicField(this, "options", {
|
5538
|
-
timeout: void 0,
|
5539
|
-
resourceCacheTTL: void 0,
|
5540
|
-
fetch: void 0,
|
5541
|
-
retryOptions: void 0,
|
5542
|
-
headers: void 0,
|
5543
|
-
cache: void 0
|
5544
|
-
});
|
5545
5684
|
const { url: rawUrl, urlWithoutAuth, headers: authHeaders } = _Provider.extractBasicAuth(url);
|
5546
5685
|
this.url = rawUrl;
|
5547
5686
|
this.urlWithoutAuth = urlWithoutAuth;
|
@@ -5571,38 +5710,12 @@ var _Provider = class {
|
|
5571
5710
|
this.cache = new ResourceCache(DEFAULT_RESOURCE_CACHE_TTL);
|
5572
5711
|
}
|
5573
5712
|
}
|
5574
|
-
/** @hidden */
|
5575
|
-
static clearChainAndNodeCaches() {
|
5576
|
-
_Provider.inflightFetchChainAndNodeInfoRequests = {};
|
5577
|
-
_Provider.nodeInfoCache = {};
|
5578
|
-
_Provider.chainInfoCache = {};
|
5579
|
-
}
|
5580
|
-
/**
|
5581
|
-
* @hidden
|
5582
|
-
*/
|
5583
|
-
static getFetchFn(options) {
|
5584
|
-
const { retryOptions, timeout, headers } = options;
|
5585
|
-
return autoRetryFetch(async (...args) => {
|
5586
|
-
const url = args[0];
|
5587
|
-
const request2 = args[1];
|
5588
|
-
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
5589
|
-
let fullRequest = {
|
5590
|
-
...request2,
|
5591
|
-
signal,
|
5592
|
-
headers: { ...request2?.headers, ...headers }
|
5593
|
-
};
|
5594
|
-
if (options.requestMiddleware) {
|
5595
|
-
fullRequest = await options.requestMiddleware(fullRequest);
|
5596
|
-
}
|
5597
|
-
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
5598
|
-
}, retryOptions);
|
5599
|
-
}
|
5600
5713
|
static extractBasicAuth(url) {
|
5601
5714
|
let parsedUrl;
|
5602
5715
|
try {
|
5603
5716
|
parsedUrl = new URL(url);
|
5604
5717
|
} catch (error) {
|
5605
|
-
throw new
|
5718
|
+
throw new FuelError18(FuelError18.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
|
5606
5719
|
}
|
5607
5720
|
const username = parsedUrl.username;
|
5608
5721
|
const password = parsedUrl.password;
|
@@ -5620,8 +5733,7 @@ var _Provider = class {
|
|
5620
5733
|
* Initialize Provider async stuff
|
5621
5734
|
*/
|
5622
5735
|
async init() {
|
5623
|
-
|
5624
|
-
this.setupFeatures(nodeInfo.nodeVersion);
|
5736
|
+
await this.fetchChainAndNodeInfo();
|
5625
5737
|
return this;
|
5626
5738
|
}
|
5627
5739
|
/**
|
@@ -5681,39 +5793,52 @@ var _Provider = class {
|
|
5681
5793
|
* @returns A promise that resolves to the Chain and NodeInfo.
|
5682
5794
|
*/
|
5683
5795
|
async fetchChainAndNodeInfo(ignoreCache = false) {
|
5684
|
-
|
5685
|
-
|
5686
|
-
|
5687
|
-
|
5688
|
-
chain
|
5689
|
-
|
5690
|
-
|
5691
|
-
|
5692
|
-
|
5693
|
-
|
5694
|
-
|
5695
|
-
|
5696
|
-
|
5697
|
-
|
5698
|
-
|
5699
|
-
}
|
5700
|
-
const { promise, resolve } = deferPromise();
|
5701
|
-
_Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth] = promise;
|
5702
|
-
const data = await this.operations.getChainAndNodeInfo();
|
5703
|
-
nodeInfo = deserializeNodeInfo(data.nodeInfo);
|
5704
|
-
chain = deserializeChain(data.chain);
|
5705
|
-
_Provider.setIncompatibleNodeVersionMessage(nodeInfo);
|
5706
|
-
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
5707
|
-
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
5708
|
-
const now = Date.now();
|
5709
|
-
this.consensusParametersTimestamp = now;
|
5710
|
-
resolve(now);
|
5711
|
-
delete _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];
|
5796
|
+
const nodeInfo = _Provider.nodeInfoCache[this.urlWithoutAuth];
|
5797
|
+
const chain = _Provider.chainInfoCache[this.urlWithoutAuth];
|
5798
|
+
const hasCache = nodeInfo && chain;
|
5799
|
+
if (hasCache && !ignoreCache) {
|
5800
|
+
return { nodeInfo, chain };
|
5801
|
+
}
|
5802
|
+
const inflightRequest = _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];
|
5803
|
+
if (inflightRequest) {
|
5804
|
+
return inflightRequest.then((data) => {
|
5805
|
+
this.consensusParametersTimestamp = data.consensusParametersTimestamp;
|
5806
|
+
return {
|
5807
|
+
nodeInfo: _Provider.nodeInfoCache[this.urlWithoutAuth],
|
5808
|
+
chain: _Provider.chainInfoCache[this.urlWithoutAuth]
|
5809
|
+
};
|
5810
|
+
});
|
5712
5811
|
}
|
5713
|
-
|
5714
|
-
chain,
|
5715
|
-
nodeInfo
|
5716
|
-
|
5812
|
+
const getChainAndNodeInfoFromNetwork = this.operations.getChainAndNodeInfo().then((data) => ({
|
5813
|
+
chain: deserializeChain(data.chain),
|
5814
|
+
nodeInfo: deserializeNodeInfo(data.nodeInfo),
|
5815
|
+
consensusParametersTimestamp: Date.now()
|
5816
|
+
})).then((data) => {
|
5817
|
+
_Provider.setIncompatibleNodeVersionMessage(data.nodeInfo);
|
5818
|
+
_Provider.chainInfoCache[this.urlWithoutAuth] = data.chain;
|
5819
|
+
_Provider.nodeInfoCache[this.urlWithoutAuth] = data.nodeInfo;
|
5820
|
+
this.consensusParametersTimestamp = data.consensusParametersTimestamp;
|
5821
|
+
return data;
|
5822
|
+
}).catch((err) => {
|
5823
|
+
const error = new FuelError18(
|
5824
|
+
FuelError18.CODES.CONNECTION_REFUSED,
|
5825
|
+
"Unable to fetch chain and node info from the network",
|
5826
|
+
{ url: this.urlWithoutAuth },
|
5827
|
+
err
|
5828
|
+
);
|
5829
|
+
error.cause = { code: "ECONNREFUSED" };
|
5830
|
+
throw error;
|
5831
|
+
}).finally(() => {
|
5832
|
+
delete _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];
|
5833
|
+
});
|
5834
|
+
_Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth] = getChainAndNodeInfoFromNetwork;
|
5835
|
+
return _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth].then((data) => {
|
5836
|
+
this.consensusParametersTimestamp = data.consensusParametersTimestamp;
|
5837
|
+
return {
|
5838
|
+
nodeInfo: _Provider.nodeInfoCache[this.urlWithoutAuth],
|
5839
|
+
chain: _Provider.chainInfoCache[this.urlWithoutAuth]
|
5840
|
+
};
|
5841
|
+
});
|
5717
5842
|
}
|
5718
5843
|
/**
|
5719
5844
|
* @hidden
|
@@ -5738,8 +5863,8 @@ var _Provider = class {
|
|
5738
5863
|
createOperations() {
|
5739
5864
|
const fetchFn = _Provider.getFetchFn(this.options);
|
5740
5865
|
const gqlClient = new GraphQLClient(this.urlWithoutAuth, {
|
5741
|
-
fetch: (input, requestInit) => fetchFn(input.toString(), requestInit || {}, this.options),
|
5742
|
-
responseMiddleware: (response) => {
|
5866
|
+
fetch: /* @__PURE__ */ __name((input, requestInit) => fetchFn(input.toString(), requestInit || {}, this.options), "fetch"),
|
5867
|
+
responseMiddleware: /* @__PURE__ */ __name((response) => {
|
5743
5868
|
if ("response" in response) {
|
5744
5869
|
const graphQlResponse = response.response;
|
5745
5870
|
assertGqlResponseHasNoErrors(
|
@@ -5747,22 +5872,22 @@ var _Provider = class {
|
|
5747
5872
|
_Provider.incompatibleNodeVersionMessage
|
5748
5873
|
);
|
5749
5874
|
}
|
5750
|
-
}
|
5875
|
+
}, "responseMiddleware")
|
5751
5876
|
});
|
5752
|
-
const executeQuery = (query, vars) => {
|
5877
|
+
const executeQuery = /* @__PURE__ */ __name((query, vars) => {
|
5753
5878
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
5754
5879
|
const isSubscription = opDefinition?.operation === "subscription";
|
5755
5880
|
if (isSubscription) {
|
5756
5881
|
return FuelGraphqlSubscriber.create({
|
5757
5882
|
url: this.urlWithoutAuth,
|
5758
5883
|
query,
|
5759
|
-
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
5884
|
+
fetchFn: /* @__PURE__ */ __name((url, requestInit) => fetchFn(url, requestInit, this.options), "fetchFn"),
|
5760
5885
|
variables: vars
|
5761
5886
|
});
|
5762
5887
|
}
|
5763
5888
|
return gqlClient.request(query, vars);
|
5764
|
-
};
|
5765
|
-
const customOperations = (requester) => ({
|
5889
|
+
}, "executeQuery");
|
5890
|
+
const customOperations = /* @__PURE__ */ __name((requester) => ({
|
5766
5891
|
getBlobs(variables) {
|
5767
5892
|
const queryParams = variables.blobIds.map((_, i) => `$blobId${i}: BlobId!`).join(", ");
|
5768
5893
|
const blobParams = variables.blobIds.map((_, i) => `blob${i}: blob(id: $blobId${i}) { id }`).join("\n");
|
@@ -5780,18 +5905,9 @@ var _Provider = class {
|
|
5780
5905
|
`;
|
5781
5906
|
return requester(document2, updatedVariables);
|
5782
5907
|
}
|
5783
|
-
});
|
5908
|
+
}), "customOperations");
|
5784
5909
|
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
5785
5910
|
}
|
5786
|
-
/**
|
5787
|
-
* @hidden
|
5788
|
-
*/
|
5789
|
-
setupFeatures(nodeVersion) {
|
5790
|
-
if (gte(nodeVersion, "0.41.0")) {
|
5791
|
-
this.features.balancePagination = true;
|
5792
|
-
this.features.amount128 = true;
|
5793
|
-
}
|
5794
|
-
}
|
5795
5911
|
/**
|
5796
5912
|
* Returns the version of the connected node.
|
5797
5913
|
*
|
@@ -5868,6 +5984,13 @@ var _Provider = class {
|
|
5868
5984
|
* @returns A promise that resolves to an object containing the asset details.
|
5869
5985
|
*/
|
5870
5986
|
async getAssetDetails(assetId) {
|
5987
|
+
const { assetMetadata } = await this.getNodeFeatures();
|
5988
|
+
if (!assetMetadata) {
|
5989
|
+
throw new FuelError18(
|
5990
|
+
ErrorCode16.UNSUPPORTED_FEATURE,
|
5991
|
+
"The current node does not supports fetching asset details"
|
5992
|
+
);
|
5993
|
+
}
|
5871
5994
|
const { assetDetails } = await this.operations.getAssetDetails({ assetId });
|
5872
5995
|
const { contractId, subId, totalSupply } = assetDetails;
|
5873
5996
|
return {
|
@@ -5876,6 +5999,15 @@ var _Provider = class {
|
|
5876
5999
|
totalSupply: bn17(totalSupply)
|
5877
6000
|
};
|
5878
6001
|
}
|
6002
|
+
/**
|
6003
|
+
* @hidden
|
6004
|
+
*/
|
6005
|
+
#cacheInputs(inputs, transactionId) {
|
6006
|
+
if (!this.cache) {
|
6007
|
+
return;
|
6008
|
+
}
|
6009
|
+
this.cache.set(transactionId, inputs);
|
6010
|
+
}
|
5879
6011
|
/**
|
5880
6012
|
* @hidden
|
5881
6013
|
*/
|
@@ -5886,13 +6018,13 @@ var _Provider = class {
|
|
5886
6018
|
}
|
5887
6019
|
} = await this.getChain();
|
5888
6020
|
if (bn17(tx.inputs.length).gt(maxInputs)) {
|
5889
|
-
throw new
|
6021
|
+
throw new FuelError18(
|
5890
6022
|
ErrorCode16.MAX_INPUTS_EXCEEDED,
|
5891
6023
|
`The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
|
5892
6024
|
);
|
5893
6025
|
}
|
5894
6026
|
if (bn17(tx.outputs.length).gt(maxOutputs)) {
|
5895
|
-
throw new
|
6027
|
+
throw new FuelError18(
|
5896
6028
|
ErrorCode16.MAX_OUTPUTS_EXCEEDED,
|
5897
6029
|
`The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
|
5898
6030
|
);
|
@@ -5925,7 +6057,10 @@ var _Provider = class {
|
|
5925
6057
|
abis = transactionRequest.abis;
|
5926
6058
|
}
|
5927
6059
|
const subscription = await this.operations.submitAndAwaitStatus({ encodedTransaction });
|
5928
|
-
|
6060
|
+
this.#cacheInputs(
|
6061
|
+
transactionRequest.inputs,
|
6062
|
+
transactionRequest.getTransactionId(await this.getChainId())
|
6063
|
+
);
|
5929
6064
|
const chainId = await this.getChainId();
|
5930
6065
|
return new TransactionResponse(transactionRequest, this, chainId, abis, subscription);
|
5931
6066
|
}
|
@@ -6592,7 +6727,7 @@ var _Provider = class {
|
|
6592
6727
|
0
|
6593
6728
|
)?.[0];
|
6594
6729
|
} catch (error) {
|
6595
|
-
if (error instanceof
|
6730
|
+
if (error instanceof FuelError18 && error.code === ErrorCode16.UNSUPPORTED_TRANSACTION_TYPE) {
|
6596
6731
|
console.warn("Unsupported transaction type encountered");
|
6597
6732
|
return null;
|
6598
6733
|
}
|
@@ -6618,7 +6753,7 @@ var _Provider = class {
|
|
6618
6753
|
try {
|
6619
6754
|
return coder.decode(arrayify12(rawPayload), 0)[0];
|
6620
6755
|
} catch (error) {
|
6621
|
-
if (error instanceof
|
6756
|
+
if (error instanceof FuelError18 && error.code === ErrorCode16.UNSUPPORTED_TRANSACTION_TYPE) {
|
6622
6757
|
console.warn("Unsupported transaction type encountered");
|
6623
6758
|
return null;
|
6624
6759
|
}
|
@@ -6677,18 +6812,9 @@ var _Provider = class {
|
|
6677
6812
|
* @returns A promise that resolves to the balance.
|
6678
6813
|
*/
|
6679
6814
|
async getBalance(owner, assetId) {
|
6680
|
-
const ownerStr = new Address2(owner).toB256();
|
6681
|
-
const assetIdStr = hexlify16(assetId);
|
6682
|
-
if (!this.features.amount128) {
|
6683
|
-
const { balance: balance2 } = await this.operations.getBalance({
|
6684
|
-
owner: ownerStr,
|
6685
|
-
assetId: assetIdStr
|
6686
|
-
});
|
6687
|
-
return bn17(balance2.amount, 10);
|
6688
|
-
}
|
6689
6815
|
const { balance } = await this.operations.getBalanceV2({
|
6690
|
-
owner:
|
6691
|
-
assetId:
|
6816
|
+
owner: new Address2(owner).toB256(),
|
6817
|
+
assetId: hexlify16(assetId)
|
6692
6818
|
});
|
6693
6819
|
return bn17(balance.amountU128, 10);
|
6694
6820
|
}
|
@@ -6700,49 +6826,29 @@ var _Provider = class {
|
|
6700
6826
|
* @returns A promise that resolves to the balances.
|
6701
6827
|
*/
|
6702
6828
|
async getBalances(owner, paginationArgs) {
|
6703
|
-
|
6704
|
-
|
6829
|
+
let args = { first: NON_PAGINATED_BALANCES_SIZE };
|
6830
|
+
const { balancesPagination: supportsPagination } = await this.getNodeFeatures();
|
6831
|
+
if (supportsPagination) {
|
6832
|
+
args = validatePaginationArgs({
|
6833
|
+
inputArgs: paginationArgs,
|
6834
|
+
paginationLimit: BALANCES_PAGE_SIZE_LIMIT
|
6835
|
+
});
|
6705
6836
|
}
|
6706
|
-
return this.getBalancesV2(owner, paginationArgs);
|
6707
|
-
}
|
6708
|
-
/**
|
6709
|
-
* @hidden
|
6710
|
-
*/
|
6711
|
-
async getBalancesV1(owner, _paginationArgs) {
|
6712
|
-
const {
|
6713
|
-
balances: { edges }
|
6714
|
-
} = await this.operations.getBalances({
|
6715
|
-
/**
|
6716
|
-
* The query parameters for this method were designed to support pagination,
|
6717
|
-
* but the current Fuel-Core implementation does not support pagination yet.
|
6718
|
-
*/
|
6719
|
-
first: 1e4,
|
6720
|
-
filter: { owner: new Address2(owner).toB256() }
|
6721
|
-
});
|
6722
|
-
const balances = edges.map(({ node }) => ({
|
6723
|
-
assetId: node.assetId,
|
6724
|
-
amount: bn17(node.amount)
|
6725
|
-
}));
|
6726
|
-
return { balances };
|
6727
|
-
}
|
6728
|
-
/**
|
6729
|
-
* @hidden
|
6730
|
-
*/
|
6731
|
-
async getBalancesV2(owner, paginationArgs) {
|
6732
6837
|
const {
|
6733
6838
|
balances: { edges, pageInfo }
|
6734
6839
|
} = await this.operations.getBalancesV2({
|
6735
|
-
...
|
6736
|
-
|
6737
|
-
|
6738
|
-
}),
|
6739
|
-
filter: { owner: new Address2(owner).toB256() }
|
6840
|
+
...args,
|
6841
|
+
filter: { owner: new Address2(owner).toB256() },
|
6842
|
+
supportsPagination
|
6740
6843
|
});
|
6741
6844
|
const balances = edges.map(({ node }) => ({
|
6742
6845
|
assetId: node.assetId,
|
6743
6846
|
amount: bn17(node.amountU128)
|
6744
6847
|
}));
|
6745
|
-
return {
|
6848
|
+
return {
|
6849
|
+
balances,
|
6850
|
+
...supportsPagination ? { pageInfo } : {}
|
6851
|
+
};
|
6746
6852
|
}
|
6747
6853
|
/**
|
6748
6854
|
* Returns message for the given address.
|
@@ -6796,7 +6902,7 @@ var _Provider = class {
|
|
6796
6902
|
nonce
|
6797
6903
|
};
|
6798
6904
|
if (commitBlockId && commitBlockHeight) {
|
6799
|
-
throw new
|
6905
|
+
throw new FuelError18(
|
6800
6906
|
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
6801
6907
|
"commitBlockId and commitBlockHeight cannot be used together"
|
6802
6908
|
);
|
@@ -7016,19 +7122,32 @@ var _Provider = class {
|
|
7016
7122
|
extractDryRunError(transactionRequest, receipts, dryRunStatus) {
|
7017
7123
|
const status = dryRunStatus;
|
7018
7124
|
let logs = [];
|
7125
|
+
let groupedLogs = {};
|
7019
7126
|
if (transactionRequest.abis) {
|
7020
|
-
logs =
|
7127
|
+
({ logs, groupedLogs } = getAllDecodedLogs({
|
7021
7128
|
receipts,
|
7022
|
-
transactionRequest.abis.main,
|
7023
|
-
transactionRequest.abis.otherContractsAbis
|
7024
|
-
);
|
7129
|
+
mainAbi: transactionRequest.abis.main,
|
7130
|
+
externalAbis: transactionRequest.abis.otherContractsAbis
|
7131
|
+
}));
|
7025
7132
|
}
|
7026
7133
|
return extractTxError({
|
7027
7134
|
logs,
|
7135
|
+
groupedLogs,
|
7028
7136
|
receipts,
|
7029
7137
|
statusReason: status.reason
|
7030
7138
|
});
|
7031
7139
|
}
|
7140
|
+
/**
|
7141
|
+
* @hidden
|
7142
|
+
*/
|
7143
|
+
async getNodeFeatures() {
|
7144
|
+
const { indexation } = await this.getNode();
|
7145
|
+
return {
|
7146
|
+
assetMetadata: Boolean(indexation?.assetMetadata),
|
7147
|
+
balancesPagination: Boolean(indexation?.balances),
|
7148
|
+
coinsToSpend: Boolean(indexation?.coinsToSpend)
|
7149
|
+
};
|
7150
|
+
}
|
7032
7151
|
/**
|
7033
7152
|
* @hidden
|
7034
7153
|
*/
|
@@ -7043,25 +7162,9 @@ var _Provider = class {
|
|
7043
7162
|
return transactionRequest;
|
7044
7163
|
}
|
7045
7164
|
};
|
7046
|
-
var Provider = _Provider;
|
7047
|
-
_cacheInputs = new WeakSet();
|
7048
|
-
cacheInputs_fn = function(inputs, transactionId) {
|
7049
|
-
if (!this.cache) {
|
7050
|
-
return;
|
7051
|
-
}
|
7052
|
-
this.cache.set(transactionId, inputs);
|
7053
|
-
};
|
7054
|
-
/** @hidden */
|
7055
|
-
__publicField(Provider, "inflightFetchChainAndNodeInfoRequests", {});
|
7056
|
-
/** @hidden */
|
7057
|
-
__publicField(Provider, "chainInfoCache", {});
|
7058
|
-
/** @hidden */
|
7059
|
-
__publicField(Provider, "nodeInfoCache", {});
|
7060
|
-
/** @hidden */
|
7061
|
-
__publicField(Provider, "incompatibleNodeVersionMessage", "");
|
7062
7165
|
|
7063
7166
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
7064
|
-
import { ErrorCode as ErrorCode17, FuelError as
|
7167
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError19 } from "@fuel-ts/errors";
|
7065
7168
|
import { bn as bn18 } from "@fuel-ts/math";
|
7066
7169
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
7067
7170
|
import { arrayify as arrayify13 } from "@fuel-ts/utils";
|
@@ -7071,7 +7174,7 @@ async function getTransactionSummary(params) {
|
|
7071
7174
|
transactionId: id
|
7072
7175
|
});
|
7073
7176
|
if (!gqlTransaction) {
|
7074
|
-
throw new
|
7177
|
+
throw new FuelError19(
|
7075
7178
|
ErrorCode17.TRANSACTION_NOT_FOUND,
|
7076
7179
|
`Transaction not found for given id: ${id}.`
|
7077
7180
|
);
|
@@ -7114,6 +7217,7 @@ async function getTransactionSummary(params) {
|
|
7114
7217
|
...transactionInfo
|
7115
7218
|
};
|
7116
7219
|
}
|
7220
|
+
__name(getTransactionSummary, "getTransactionSummary");
|
7117
7221
|
async function getTransactionSummaryFromRequest(params) {
|
7118
7222
|
const { provider, transactionRequest, abiMap } = params;
|
7119
7223
|
const { receipts } = await provider.dryRun(transactionRequest);
|
@@ -7139,6 +7243,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
7139
7243
|
});
|
7140
7244
|
return transactionSummary;
|
7141
7245
|
}
|
7246
|
+
__name(getTransactionSummaryFromRequest, "getTransactionSummaryFromRequest");
|
7142
7247
|
async function getTransactionsSummaries(params) {
|
7143
7248
|
const { filters, provider, abiMap } = params;
|
7144
7249
|
const { owner, ...inputArgs } = filters;
|
@@ -7194,12 +7299,13 @@ async function getTransactionsSummaries(params) {
|
|
7194
7299
|
pageInfo
|
7195
7300
|
};
|
7196
7301
|
}
|
7302
|
+
__name(getTransactionsSummaries, "getTransactionsSummaries");
|
7197
7303
|
|
7198
7304
|
// src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
|
7199
7305
|
import { bn as bn19 } from "@fuel-ts/math";
|
7200
7306
|
import { TransactionCoder as TransactionCoder7 } from "@fuel-ts/transactions";
|
7201
7307
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
7202
|
-
var assembleTransactionSummaryFromJson = async (opts) => {
|
7308
|
+
var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) => {
|
7203
7309
|
const { provider, transactionSummary } = opts;
|
7204
7310
|
const { id, transactionBytes, gasPrice, receipts } = transactionSummary;
|
7205
7311
|
const {
|
@@ -7226,10 +7332,10 @@ var assembleTransactionSummaryFromJson = async (opts) => {
|
|
7226
7332
|
gasPerByte,
|
7227
7333
|
gasPriceFactor
|
7228
7334
|
});
|
7229
|
-
};
|
7335
|
+
}, "assembleTransactionSummaryFromJson");
|
7230
7336
|
|
7231
7337
|
// src/providers/utils/merge-quantities.ts
|
7232
|
-
var mergeQuantities = (...coinQuantities) => {
|
7338
|
+
var mergeQuantities = /* @__PURE__ */ __name((...coinQuantities) => {
|
7233
7339
|
const resultMap = {};
|
7234
7340
|
function addToMap({ amount, assetId }) {
|
7235
7341
|
if (resultMap[assetId]) {
|
@@ -7238,29 +7344,33 @@ var mergeQuantities = (...coinQuantities) => {
|
|
7238
7344
|
resultMap[assetId] = amount;
|
7239
7345
|
}
|
7240
7346
|
}
|
7347
|
+
__name(addToMap, "addToMap");
|
7241
7348
|
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
7242
7349
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
7243
|
-
};
|
7350
|
+
}, "mergeQuantities");
|
7244
7351
|
|
7245
7352
|
// src/types.ts
|
7246
7353
|
var AbstractAccount = class {
|
7354
|
+
static {
|
7355
|
+
__name(this, "AbstractAccount");
|
7356
|
+
}
|
7247
7357
|
};
|
7248
7358
|
|
7249
7359
|
// src/utils/formatTransferToContractScriptData.ts
|
7250
|
-
import { ASSET_ID_LEN, BigNumberCoder as
|
7360
|
+
import { ASSET_ID_LEN, BigNumberCoder as BigNumberCoder3, CONTRACT_ID_LEN, WORD_SIZE } from "@fuel-ts/abi-coder";
|
7251
7361
|
import { Address as Address3 } from "@fuel-ts/address";
|
7252
7362
|
import { arrayify as arrayify15, concat as concat3 } from "@fuel-ts/utils";
|
7253
7363
|
import * as asm from "@fuels/vm-asm";
|
7254
|
-
var formatTransferToContractScriptData = (transferParams) => {
|
7255
|
-
const numberCoder = new
|
7364
|
+
var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
|
7365
|
+
const numberCoder = new BigNumberCoder3("u64");
|
7256
7366
|
return transferParams.reduce((acc, transferParam) => {
|
7257
7367
|
const { assetId, amount, contractId } = transferParam;
|
7258
7368
|
const encoded = numberCoder.encode(amount);
|
7259
7369
|
const scriptData = concat3([new Address3(contractId).toBytes(), encoded, arrayify15(assetId)]);
|
7260
7370
|
return concat3([acc, scriptData]);
|
7261
7371
|
}, new Uint8Array());
|
7262
|
-
};
|
7263
|
-
var assembleTransferToContractScript = async (transferParams) => {
|
7372
|
+
}, "formatTransferToContractScriptData");
|
7373
|
+
var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferParams) => {
|
7264
7374
|
const scriptData = formatTransferToContractScriptData(transferParams);
|
7265
7375
|
await asm.initWasm();
|
7266
7376
|
let script = new Uint8Array();
|
@@ -7284,11 +7394,14 @@ var assembleTransferToContractScript = async (transferParams) => {
|
|
7284
7394
|
});
|
7285
7395
|
script = concat3([script, asm.ret(1).to_bytes()]);
|
7286
7396
|
return { script, scriptData };
|
7287
|
-
};
|
7397
|
+
}, "assembleTransferToContractScript");
|
7288
7398
|
|
7289
7399
|
// src/account.ts
|
7290
7400
|
var MAX_FUNDING_ATTEMPTS = 5;
|
7291
7401
|
var Account = class extends AbstractAccount {
|
7402
|
+
static {
|
7403
|
+
__name(this, "Account");
|
7404
|
+
}
|
7292
7405
|
/**
|
7293
7406
|
* The address associated with the account.
|
7294
7407
|
*/
|
@@ -7323,7 +7436,7 @@ var Account = class extends AbstractAccount {
|
|
7323
7436
|
*/
|
7324
7437
|
get provider() {
|
7325
7438
|
if (!this._provider) {
|
7326
|
-
throw new
|
7439
|
+
throw new FuelError20(ErrorCode18.MISSING_PROVIDER, "Provider not set");
|
7327
7440
|
}
|
7328
7441
|
return this._provider;
|
7329
7442
|
}
|
@@ -7482,7 +7595,7 @@ var Account = class extends AbstractAccount {
|
|
7482
7595
|
fundingAttempts += 1;
|
7483
7596
|
}
|
7484
7597
|
if (needsToBeFunded) {
|
7485
|
-
throw new
|
7598
|
+
throw new FuelError20(
|
7486
7599
|
ErrorCode18.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
7487
7600
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
7488
7601
|
);
|
@@ -7602,7 +7715,7 @@ var Account = class extends AbstractAccount {
|
|
7602
7715
|
const contractAddress = new Address4(transferParam.contractId);
|
7603
7716
|
const assetId = transferParam.assetId ? hexlify17(transferParam.assetId) : defaultAssetId;
|
7604
7717
|
if (amount.lte(0)) {
|
7605
|
-
throw new
|
7718
|
+
throw new FuelError20(
|
7606
7719
|
ErrorCode18.INVALID_TRANSFER_AMOUNT,
|
7607
7720
|
"Transfer amount must be a positive number."
|
7608
7721
|
);
|
@@ -7672,7 +7785,7 @@ var Account = class extends AbstractAccount {
|
|
7672
7785
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
7673
7786
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
7674
7787
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: bn20("100000000000000000") }];
|
7675
|
-
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
7788
|
+
const findAssetInput = /* @__PURE__ */ __name((assetId) => txRequestClone.inputs.find((input) => {
|
7676
7789
|
if (input.type === InputType7.Coin) {
|
7677
7790
|
return input.assetId === assetId;
|
7678
7791
|
}
|
@@ -7680,8 +7793,8 @@ var Account = class extends AbstractAccount {
|
|
7680
7793
|
return baseAssetId === assetId;
|
7681
7794
|
}
|
7682
7795
|
return false;
|
7683
|
-
});
|
7684
|
-
const updateAssetInput = (assetId, quantity) => {
|
7796
|
+
}), "findAssetInput");
|
7797
|
+
const updateAssetInput = /* @__PURE__ */ __name((assetId, quantity) => {
|
7685
7798
|
const assetInput = findAssetInput(assetId);
|
7686
7799
|
const usedQuantity = quantity;
|
7687
7800
|
if (assetInput && "amount" in assetInput) {
|
@@ -7696,7 +7809,7 @@ var Account = class extends AbstractAccount {
|
|
7696
7809
|
])
|
7697
7810
|
);
|
7698
7811
|
}
|
7699
|
-
};
|
7812
|
+
}, "updateAssetInput");
|
7700
7813
|
mergeQuantities(requiredQuantities, transactionFeeForDryRun).forEach(
|
7701
7814
|
({ amount, assetId }) => updateAssetInput(assetId, amount)
|
7702
7815
|
);
|
@@ -7719,7 +7832,7 @@ var Account = class extends AbstractAccount {
|
|
7719
7832
|
*/
|
7720
7833
|
async signMessage(message) {
|
7721
7834
|
if (!this._connector) {
|
7722
|
-
throw new
|
7835
|
+
throw new FuelError20(ErrorCode18.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
7723
7836
|
}
|
7724
7837
|
return this._connector.signMessage(this.address.toString(), message);
|
7725
7838
|
}
|
@@ -7731,7 +7844,7 @@ var Account = class extends AbstractAccount {
|
|
7731
7844
|
*/
|
7732
7845
|
async signTransaction(transactionRequestLike) {
|
7733
7846
|
if (!this._connector) {
|
7734
|
-
throw new
|
7847
|
+
throw new FuelError20(
|
7735
7848
|
ErrorCode18.MISSING_CONNECTOR,
|
7736
7849
|
"A connector is required to sign transactions."
|
7737
7850
|
);
|
@@ -7828,7 +7941,7 @@ var Account = class extends AbstractAccount {
|
|
7828
7941
|
/** @hidden * */
|
7829
7942
|
validateTransferAmount(amount) {
|
7830
7943
|
if (bn20(amount).lte(0)) {
|
7831
|
-
throw new
|
7944
|
+
throw new FuelError20(
|
7832
7945
|
ErrorCode18.INVALID_TRANSFER_AMOUNT,
|
7833
7946
|
"Transfer amount must be a positive number."
|
7834
7947
|
);
|
@@ -7858,7 +7971,7 @@ var Account = class extends AbstractAccount {
|
|
7858
7971
|
if (!isDefined3(setGasLimit)) {
|
7859
7972
|
request2.gasLimit = gasUsed;
|
7860
7973
|
} else if (gasUsed.gt(setGasLimit)) {
|
7861
|
-
throw new
|
7974
|
+
throw new FuelError20(
|
7862
7975
|
ErrorCode18.GAS_LIMIT_TOO_LOW,
|
7863
7976
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
7864
7977
|
);
|
@@ -7866,7 +7979,7 @@ var Account = class extends AbstractAccount {
|
|
7866
7979
|
if (!isDefined3(setMaxFee)) {
|
7867
7980
|
request2.maxFee = maxFee;
|
7868
7981
|
} else if (maxFee.gt(setMaxFee)) {
|
7869
|
-
throw new
|
7982
|
+
throw new FuelError20(
|
7870
7983
|
ErrorCode18.MAX_FEE_TOO_LOW,
|
7871
7984
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
7872
7985
|
);
|
@@ -7886,7 +7999,10 @@ import { hash as hash2 } from "@fuel-ts/hasher";
|
|
7886
7999
|
import { toBytes } from "@fuel-ts/math";
|
7887
8000
|
import { hexlify as hexlify18, concat as concat4, arrayify as arrayify17 } from "@fuel-ts/utils";
|
7888
8001
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
7889
|
-
var Signer = class {
|
8002
|
+
var Signer = class _Signer {
|
8003
|
+
static {
|
8004
|
+
__name(this, "Signer");
|
8005
|
+
}
|
7890
8006
|
address;
|
7891
8007
|
publicKey;
|
7892
8008
|
compressedPublicKey;
|
@@ -7965,7 +8081,7 @@ var Signer = class {
|
|
7965
8081
|
* @returns Address from signature
|
7966
8082
|
*/
|
7967
8083
|
static recoverAddress(data, signature) {
|
7968
|
-
return new Address5(
|
8084
|
+
return new Address5(_Signer.recoverPublicKey(data, signature));
|
7969
8085
|
}
|
7970
8086
|
/**
|
7971
8087
|
* Generate a random privateKey
|
@@ -8000,19 +8116,19 @@ import {
|
|
8000
8116
|
encryptJsonWalletData,
|
8001
8117
|
randomUUID
|
8002
8118
|
} from "@fuel-ts/crypto";
|
8003
|
-
import { ErrorCode as ErrorCode19, FuelError as
|
8119
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8004
8120
|
import { hexlify as hexlify19 } from "@fuel-ts/utils";
|
8005
8121
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
8006
8122
|
var DEFAULT_KDF_PARAMS_R = 8;
|
8007
8123
|
var DEFAULT_KDF_PARAMS_P = 1;
|
8008
8124
|
var DEFAULT_KEY_SIZE = 32;
|
8009
8125
|
var DEFAULT_IV_SIZE = 16;
|
8010
|
-
var removeHexPrefix = (hexString) => {
|
8126
|
+
var removeHexPrefix = /* @__PURE__ */ __name((hexString) => {
|
8011
8127
|
if (/^0x/.test(hexString)) {
|
8012
8128
|
return hexString.slice(2);
|
8013
8129
|
}
|
8014
8130
|
return hexString;
|
8015
|
-
};
|
8131
|
+
}, "removeHexPrefix");
|
8016
8132
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
8017
8133
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
8018
8134
|
const ownerAddress = new Address6(address);
|
@@ -8051,6 +8167,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
8051
8167
|
};
|
8052
8168
|
return JSON.stringify(keystore);
|
8053
8169
|
}
|
8170
|
+
__name(encryptKeystoreWallet, "encryptKeystoreWallet");
|
8054
8171
|
async function decryptKeystoreWallet(jsonWallet, password) {
|
8055
8172
|
const keystoreWallet = JSON.parse(jsonWallet);
|
8056
8173
|
const {
|
@@ -8077,7 +8194,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
8077
8194
|
const macHashUint8Array = keccak256(data);
|
8078
8195
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
8079
8196
|
if (mac !== macHash) {
|
8080
|
-
throw new
|
8197
|
+
throw new FuelError21(
|
8081
8198
|
ErrorCode19.INVALID_PASSWORD,
|
8082
8199
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
8083
8200
|
);
|
@@ -8086,9 +8203,17 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
8086
8203
|
const privateKey = hexlify19(buffer);
|
8087
8204
|
return privateKey;
|
8088
8205
|
}
|
8206
|
+
__name(decryptKeystoreWallet, "decryptKeystoreWallet");
|
8089
8207
|
|
8090
8208
|
// src/wallet/base-wallet-unlocked.ts
|
8091
8209
|
var BaseWalletUnlocked = class extends Account {
|
8210
|
+
static {
|
8211
|
+
__name(this, "BaseWalletUnlocked");
|
8212
|
+
}
|
8213
|
+
/**
|
8214
|
+
* Default HDWallet path.
|
8215
|
+
*/
|
8216
|
+
static defaultPath = "m/44'/1179993420'/0'/0/0";
|
8092
8217
|
/**
|
8093
8218
|
* A function that returns the wallet's signer.
|
8094
8219
|
*/
|
@@ -8206,21 +8331,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
8206
8331
|
return encryptKeystoreWallet(this.privateKey, this.address, password);
|
8207
8332
|
}
|
8208
8333
|
};
|
8209
|
-
/**
|
8210
|
-
* Default HDWallet path.
|
8211
|
-
*/
|
8212
|
-
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
8213
8334
|
|
8214
8335
|
// src/hdwallet/hdwallet.ts
|
8215
8336
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
8216
|
-
import { ErrorCode as ErrorCode22, FuelError as
|
8337
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8217
8338
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
8218
8339
|
import { bn as bn21, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
8219
8340
|
import { arrayify as arrayify20, hexlify as hexlify22, concat as concat6, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
8220
8341
|
|
8221
8342
|
// src/mnemonic/mnemonic.ts
|
8222
8343
|
import { randomBytes as randomBytes5, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
8223
|
-
import { ErrorCode as ErrorCode21, FuelError as
|
8344
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8224
8345
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
8225
8346
|
import { arrayify as arrayify19, hexlify as hexlify21, concat as concat5, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
8226
8347
|
|
@@ -10283,27 +10404,31 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
10283
10404
|
})(Language || {});
|
10284
10405
|
|
10285
10406
|
// src/mnemonic/utils.ts
|
10286
|
-
import { ErrorCode as ErrorCode20, FuelError as
|
10407
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError22 } from "@fuel-ts/errors";
|
10287
10408
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
10288
10409
|
import { arrayify as arrayify18 } from "@fuel-ts/utils";
|
10289
10410
|
function getLowerMask(bits) {
|
10290
10411
|
return (1 << bits) - 1;
|
10291
10412
|
}
|
10413
|
+
__name(getLowerMask, "getLowerMask");
|
10292
10414
|
function getUpperMask(bits) {
|
10293
10415
|
return (1 << bits) - 1 << 8 - bits;
|
10294
10416
|
}
|
10417
|
+
__name(getUpperMask, "getUpperMask");
|
10295
10418
|
function getWords(mnemonic) {
|
10296
10419
|
if (!Array.isArray(mnemonic)) {
|
10297
10420
|
return mnemonic.split(/\s+/);
|
10298
10421
|
}
|
10299
10422
|
return mnemonic;
|
10300
10423
|
}
|
10424
|
+
__name(getWords, "getWords");
|
10301
10425
|
function getPhrase(mnemonic) {
|
10302
10426
|
if (Array.isArray(mnemonic)) {
|
10303
10427
|
return mnemonic.join(" ");
|
10304
10428
|
}
|
10305
10429
|
return mnemonic;
|
10306
10430
|
}
|
10431
|
+
__name(getPhrase, "getPhrase");
|
10307
10432
|
function entropyToMnemonicIndices(entropy) {
|
10308
10433
|
const indices = [0];
|
10309
10434
|
let remainingBits = 11;
|
@@ -10325,6 +10450,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
10325
10450
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
10326
10451
|
return indices;
|
10327
10452
|
}
|
10453
|
+
__name(entropyToMnemonicIndices, "entropyToMnemonicIndices");
|
10328
10454
|
function mnemonicWordsToEntropy(words, wordlist) {
|
10329
10455
|
const size = Math.ceil(11 * words.length / 8);
|
10330
10456
|
const entropy = arrayify18(new Uint8Array(size));
|
@@ -10332,7 +10458,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
10332
10458
|
for (let i = 0; i < words.length; i += 1) {
|
10333
10459
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
10334
10460
|
if (index === -1) {
|
10335
|
-
throw new
|
10461
|
+
throw new FuelError22(
|
10336
10462
|
ErrorCode20.INVALID_MNEMONIC,
|
10337
10463
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
10338
10464
|
);
|
@@ -10349,13 +10475,14 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
10349
10475
|
const checksumMask = getUpperMask(checksumBits);
|
10350
10476
|
const checksum = arrayify18(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
10351
10477
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
10352
|
-
throw new
|
10478
|
+
throw new FuelError22(
|
10353
10479
|
ErrorCode20.INVALID_CHECKSUM,
|
10354
10480
|
"Checksum validation failed for the provided mnemonic."
|
10355
10481
|
);
|
10356
10482
|
}
|
10357
10483
|
return entropy.slice(0, entropyBits / 8);
|
10358
10484
|
}
|
10485
|
+
__name(mnemonicWordsToEntropy, "mnemonicWordsToEntropy");
|
10359
10486
|
|
10360
10487
|
// src/mnemonic/mnemonic.ts
|
10361
10488
|
var MasterSecret = toUtf8Bytes("Bitcoin seed");
|
@@ -10364,29 +10491,35 @@ var TestnetPRV = "0x04358394";
|
|
10364
10491
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
10365
10492
|
function assertWordList(wordlist) {
|
10366
10493
|
if (wordlist.length !== 2048) {
|
10367
|
-
throw new
|
10494
|
+
throw new FuelError23(
|
10368
10495
|
ErrorCode21.INVALID_WORD_LIST,
|
10369
10496
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
10370
10497
|
);
|
10371
10498
|
}
|
10372
10499
|
}
|
10500
|
+
__name(assertWordList, "assertWordList");
|
10373
10501
|
function assertEntropy(entropy) {
|
10374
10502
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
10375
|
-
throw new
|
10503
|
+
throw new FuelError23(
|
10376
10504
|
ErrorCode21.INVALID_ENTROPY,
|
10377
10505
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
10378
10506
|
);
|
10379
10507
|
}
|
10380
10508
|
}
|
10509
|
+
__name(assertEntropy, "assertEntropy");
|
10381
10510
|
function assertMnemonic(words) {
|
10382
10511
|
if (!MNEMONIC_SIZES.includes(words.length)) {
|
10383
10512
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
10384
10513
|
", "
|
10385
10514
|
)}] words, but got ${words.length}.`;
|
10386
|
-
throw new
|
10515
|
+
throw new FuelError23(ErrorCode21.INVALID_MNEMONIC, errorMsg);
|
10387
10516
|
}
|
10388
10517
|
}
|
10389
|
-
|
10518
|
+
__name(assertMnemonic, "assertMnemonic");
|
10519
|
+
var Mnemonic = class _Mnemonic {
|
10520
|
+
static {
|
10521
|
+
__name(this, "Mnemonic");
|
10522
|
+
}
|
10390
10523
|
wordlist;
|
10391
10524
|
/**
|
10392
10525
|
*
|
@@ -10403,7 +10536,7 @@ var Mnemonic = class {
|
|
10403
10536
|
* @returns Entropy hash
|
10404
10537
|
*/
|
10405
10538
|
mnemonicToEntropy(phrase) {
|
10406
|
-
return
|
10539
|
+
return _Mnemonic.mnemonicToEntropy(phrase, this.wordlist);
|
10407
10540
|
}
|
10408
10541
|
/**
|
10409
10542
|
*
|
@@ -10411,7 +10544,7 @@ var Mnemonic = class {
|
|
10411
10544
|
* @returns Mnemonic phrase
|
10412
10545
|
*/
|
10413
10546
|
entropyToMnemonic(entropy) {
|
10414
|
-
return
|
10547
|
+
return _Mnemonic.entropyToMnemonic(entropy, this.wordlist);
|
10415
10548
|
}
|
10416
10549
|
/**
|
10417
10550
|
*
|
@@ -10452,8 +10585,8 @@ var Mnemonic = class {
|
|
10452
10585
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
10453
10586
|
*/
|
10454
10587
|
static mnemonicToMasterKeys(phrase, passphrase = "") {
|
10455
|
-
const seed =
|
10456
|
-
return
|
10588
|
+
const seed = _Mnemonic.mnemonicToSeed(phrase, passphrase);
|
10589
|
+
return _Mnemonic.masterKeysFromSeed(seed);
|
10457
10590
|
}
|
10458
10591
|
/**
|
10459
10592
|
* Validates if given mnemonic is valid
|
@@ -10469,7 +10602,7 @@ var Mnemonic = class {
|
|
10469
10602
|
return false;
|
10470
10603
|
}
|
10471
10604
|
while (i < words.length) {
|
10472
|
-
if (
|
10605
|
+
if (_Mnemonic.binarySearch(words[i]) === false) {
|
10473
10606
|
return false;
|
10474
10607
|
}
|
10475
10608
|
i += 1;
|
@@ -10501,7 +10634,7 @@ var Mnemonic = class {
|
|
10501
10634
|
static masterKeysFromSeed(seed) {
|
10502
10635
|
const seedArray = arrayify19(seed);
|
10503
10636
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
10504
|
-
throw new
|
10637
|
+
throw new FuelError23(
|
10505
10638
|
ErrorCode21.INVALID_SEED,
|
10506
10639
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
10507
10640
|
);
|
@@ -10516,7 +10649,7 @@ var Mnemonic = class {
|
|
10516
10649
|
* @returns BIP-32 extended private key
|
10517
10650
|
*/
|
10518
10651
|
static seedToExtendedKey(seed, testnet = false) {
|
10519
|
-
const masterKey =
|
10652
|
+
const masterKey = _Mnemonic.masterKeysFromSeed(seed);
|
10520
10653
|
const prefix = arrayify19(testnet ? TestnetPRV : MainnetPRV);
|
10521
10654
|
const depth = "0x00";
|
10522
10655
|
const fingerprint = "0x00000000";
|
@@ -10548,7 +10681,7 @@ var Mnemonic = class {
|
|
10548
10681
|
*/
|
10549
10682
|
static generate(size = 32, extraEntropy = "") {
|
10550
10683
|
const entropy = extraEntropy ? sha2563(concat5([randomBytes5(size), arrayify19(extraEntropy)])) : randomBytes5(size);
|
10551
|
-
return
|
10684
|
+
return _Mnemonic.entropyToMnemonic(entropy);
|
10552
10685
|
}
|
10553
10686
|
};
|
10554
10687
|
var mnemonic_default = Mnemonic;
|
@@ -10562,24 +10695,28 @@ var TestnetPUB = hexlify22("0x043587cf");
|
|
10562
10695
|
function base58check(data) {
|
10563
10696
|
return encodeBase582(concat6([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
|
10564
10697
|
}
|
10698
|
+
__name(base58check, "base58check");
|
10565
10699
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
10566
10700
|
if (isPublic) {
|
10567
10701
|
return testnet ? TestnetPUB : MainnetPUB;
|
10568
10702
|
}
|
10569
10703
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
10570
10704
|
}
|
10705
|
+
__name(getExtendedKeyPrefix, "getExtendedKeyPrefix");
|
10571
10706
|
function isPublicExtendedKey(extendedKey) {
|
10572
10707
|
return [MainnetPUB, TestnetPUB].includes(hexlify22(extendedKey.slice(0, 4)));
|
10573
10708
|
}
|
10709
|
+
__name(isPublicExtendedKey, "isPublicExtendedKey");
|
10574
10710
|
function isValidExtendedKey(extendedKey) {
|
10575
10711
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
10576
10712
|
hexlify22(extendedKey.slice(0, 4))
|
10577
10713
|
);
|
10578
10714
|
}
|
10715
|
+
__name(isValidExtendedKey, "isValidExtendedKey");
|
10579
10716
|
function parsePath(path, depth = 0) {
|
10580
10717
|
const components = path.split("/");
|
10581
10718
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
10582
|
-
throw new
|
10719
|
+
throw new FuelError24(ErrorCode22.HD_WALLET_ERROR, `invalid path - ${path}`);
|
10583
10720
|
}
|
10584
10721
|
if (components[0] === "m") {
|
10585
10722
|
components.shift();
|
@@ -10588,7 +10725,11 @@ function parsePath(path, depth = 0) {
|
|
10588
10725
|
(p) => ~p.indexOf(`'`) ? parseInt(p, 10) + HARDENED_INDEX : parseInt(p, 10)
|
10589
10726
|
);
|
10590
10727
|
}
|
10591
|
-
|
10728
|
+
__name(parsePath, "parsePath");
|
10729
|
+
var HDWallet = class _HDWallet {
|
10730
|
+
static {
|
10731
|
+
__name(this, "HDWallet");
|
10732
|
+
}
|
10592
10733
|
depth = 0;
|
10593
10734
|
index = 0;
|
10594
10735
|
fingerprint = hexlify22("0x00000000");
|
@@ -10608,7 +10749,7 @@ var HDWallet = class {
|
|
10608
10749
|
this.privateKey = hexlify22(config.privateKey);
|
10609
10750
|
} else {
|
10610
10751
|
if (!config.publicKey) {
|
10611
|
-
throw new
|
10752
|
+
throw new FuelError24(
|
10612
10753
|
ErrorCode22.HD_WALLET_ERROR,
|
10613
10754
|
"Both public and private Key cannot be missing. At least one should be provided."
|
10614
10755
|
);
|
@@ -10638,7 +10779,7 @@ var HDWallet = class {
|
|
10638
10779
|
const data = new Uint8Array(37);
|
10639
10780
|
if (index & HARDENED_INDEX) {
|
10640
10781
|
if (!privateKey) {
|
10641
|
-
throw new
|
10782
|
+
throw new FuelError24(
|
10642
10783
|
ErrorCode22.HD_WALLET_ERROR,
|
10643
10784
|
"Cannot derive a hardened index without a private Key."
|
10644
10785
|
);
|
@@ -10654,7 +10795,7 @@ var HDWallet = class {
|
|
10654
10795
|
if (privateKey) {
|
10655
10796
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
10656
10797
|
const ki = bn21(IL).add(privateKey).mod(N).toBytes(32);
|
10657
|
-
return new
|
10798
|
+
return new _HDWallet({
|
10658
10799
|
privateKey: ki,
|
10659
10800
|
chainCode: IR,
|
10660
10801
|
index,
|
@@ -10664,7 +10805,7 @@ var HDWallet = class {
|
|
10664
10805
|
}
|
10665
10806
|
const signer = new Signer(hexlify22(IL));
|
10666
10807
|
const Ki = signer.addPoint(publicKey);
|
10667
|
-
return new
|
10808
|
+
return new _HDWallet({
|
10668
10809
|
publicKey: Ki,
|
10669
10810
|
chainCode: IR,
|
10670
10811
|
index,
|
@@ -10691,7 +10832,7 @@ var HDWallet = class {
|
|
10691
10832
|
*/
|
10692
10833
|
toExtendedKey(isPublic = false, testnet = false) {
|
10693
10834
|
if (this.depth >= 256) {
|
10694
|
-
throw new
|
10835
|
+
throw new FuelError24(
|
10695
10836
|
ErrorCode22.HD_WALLET_ERROR,
|
10696
10837
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
10697
10838
|
);
|
@@ -10713,7 +10854,7 @@ var HDWallet = class {
|
|
10713
10854
|
*/
|
10714
10855
|
static fromSeed(seed) {
|
10715
10856
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
10716
|
-
return new
|
10857
|
+
return new _HDWallet({
|
10717
10858
|
chainCode: arrayify20(masterKey.slice(32)),
|
10718
10859
|
privateKey: arrayify20(masterKey.slice(0, 32))
|
10719
10860
|
});
|
@@ -10723,10 +10864,10 @@ var HDWallet = class {
|
|
10723
10864
|
const bytes = arrayify20(decoded);
|
10724
10865
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
10725
10866
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
10726
|
-
throw new
|
10867
|
+
throw new FuelError24(ErrorCode22.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
10727
10868
|
}
|
10728
10869
|
if (!validChecksum) {
|
10729
|
-
throw new
|
10870
|
+
throw new FuelError24(ErrorCode22.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
10730
10871
|
}
|
10731
10872
|
const depth = bytes[4];
|
10732
10873
|
const parentFingerprint = hexlify22(bytes.slice(5, 9));
|
@@ -10734,16 +10875,16 @@ var HDWallet = class {
|
|
10734
10875
|
const chainCode = hexlify22(bytes.slice(13, 45));
|
10735
10876
|
const key = bytes.slice(45, 78);
|
10736
10877
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
10737
|
-
throw new
|
10878
|
+
throw new FuelError24(
|
10738
10879
|
ErrorCode22.HD_WALLET_ERROR,
|
10739
10880
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
10740
10881
|
);
|
10741
10882
|
}
|
10742
10883
|
if (isPublicExtendedKey(bytes)) {
|
10743
10884
|
if (key[0] !== 3) {
|
10744
|
-
throw new
|
10885
|
+
throw new FuelError24(ErrorCode22.HD_WALLET_ERROR, "Invalid public extended key.");
|
10745
10886
|
}
|
10746
|
-
return new
|
10887
|
+
return new _HDWallet({
|
10747
10888
|
publicKey: key,
|
10748
10889
|
chainCode,
|
10749
10890
|
index,
|
@@ -10752,9 +10893,9 @@ var HDWallet = class {
|
|
10752
10893
|
});
|
10753
10894
|
}
|
10754
10895
|
if (key[0] !== 0) {
|
10755
|
-
throw new
|
10896
|
+
throw new FuelError24(ErrorCode22.HD_WALLET_ERROR, "Invalid private extended key.");
|
10756
10897
|
}
|
10757
|
-
return new
|
10898
|
+
return new _HDWallet({
|
10758
10899
|
privateKey: key.slice(1),
|
10759
10900
|
chainCode,
|
10760
10901
|
index,
|
@@ -10767,6 +10908,9 @@ var hdwallet_default = HDWallet;
|
|
10767
10908
|
|
10768
10909
|
// src/wallet/wallets.ts
|
10769
10910
|
var WalletLocked = class extends Account {
|
10911
|
+
static {
|
10912
|
+
__name(this, "WalletLocked");
|
10913
|
+
}
|
10770
10914
|
/**
|
10771
10915
|
* Unlocks the wallet using the provided private key and returns an instance of WalletUnlocked.
|
10772
10916
|
*
|
@@ -10777,7 +10921,10 @@ var WalletLocked = class extends Account {
|
|
10777
10921
|
return new WalletUnlocked(privateKey, this._provider);
|
10778
10922
|
}
|
10779
10923
|
};
|
10780
|
-
var WalletUnlocked = class extends BaseWalletUnlocked {
|
10924
|
+
var WalletUnlocked = class _WalletUnlocked extends BaseWalletUnlocked {
|
10925
|
+
static {
|
10926
|
+
__name(this, "WalletUnlocked");
|
10927
|
+
}
|
10781
10928
|
/**
|
10782
10929
|
* Locks the wallet and returns an instance of WalletLocked.
|
10783
10930
|
*
|
@@ -10795,7 +10942,7 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10795
10942
|
*/
|
10796
10943
|
static generate(generateOptions) {
|
10797
10944
|
const privateKey = Signer.generatePrivateKey(generateOptions?.entropy);
|
10798
|
-
return new
|
10945
|
+
return new _WalletUnlocked(privateKey, generateOptions?.provider);
|
10799
10946
|
}
|
10800
10947
|
/**
|
10801
10948
|
* Create a Wallet Unlocked from a seed.
|
@@ -10807,8 +10954,8 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10807
10954
|
*/
|
10808
10955
|
static fromSeed(seed, path, provider) {
|
10809
10956
|
const hdWallet = hdwallet_default.fromSeed(seed);
|
10810
|
-
const childWallet = hdWallet.derivePath(path ||
|
10811
|
-
return new
|
10957
|
+
const childWallet = hdWallet.derivePath(path || _WalletUnlocked.defaultPath);
|
10958
|
+
return new _WalletUnlocked(childWallet.privateKey, provider);
|
10812
10959
|
}
|
10813
10960
|
/**
|
10814
10961
|
* Create a Wallet Unlocked from a mnemonic phrase.
|
@@ -10822,8 +10969,8 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10822
10969
|
static fromMnemonic(mnemonic, path, passphrase, provider) {
|
10823
10970
|
const seed = mnemonic_default.mnemonicToSeed(mnemonic, passphrase);
|
10824
10971
|
const hdWallet = hdwallet_default.fromSeed(seed);
|
10825
|
-
const childWallet = hdWallet.derivePath(path ||
|
10826
|
-
return new
|
10972
|
+
const childWallet = hdWallet.derivePath(path || _WalletUnlocked.defaultPath);
|
10973
|
+
return new _WalletUnlocked(childWallet.privateKey, provider);
|
10827
10974
|
}
|
10828
10975
|
/**
|
10829
10976
|
* Create a Wallet Unlocked from an extended key.
|
@@ -10834,7 +10981,7 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10834
10981
|
*/
|
10835
10982
|
static fromExtendedKey(extendedKey, provider) {
|
10836
10983
|
const hdWallet = hdwallet_default.fromExtendedKey(extendedKey);
|
10837
|
-
return new
|
10984
|
+
return new _WalletUnlocked(hdWallet.privateKey, provider);
|
10838
10985
|
}
|
10839
10986
|
/**
|
10840
10987
|
* Create a Wallet Unlocked from an encrypted JSON.
|
@@ -10846,12 +10993,15 @@ var WalletUnlocked = class extends BaseWalletUnlocked {
|
|
10846
10993
|
*/
|
10847
10994
|
static async fromEncryptedJson(jsonWallet, password, provider) {
|
10848
10995
|
const privateKey = await decryptKeystoreWallet(jsonWallet, password);
|
10849
|
-
return new
|
10996
|
+
return new _WalletUnlocked(privateKey, provider);
|
10850
10997
|
}
|
10851
10998
|
};
|
10852
10999
|
|
10853
11000
|
// src/wallet/wallet.ts
|
10854
11001
|
var Wallet = class {
|
11002
|
+
static {
|
11003
|
+
__name(this, "Wallet");
|
11004
|
+
}
|
10855
11005
|
/**
|
10856
11006
|
* Creates a locked wallet instance from an address and a provider.
|
10857
11007
|
*
|
@@ -10872,59 +11022,62 @@ var Wallet = class {
|
|
10872
11022
|
static fromPrivateKey(privateKey, provider) {
|
10873
11023
|
return new WalletUnlocked(privateKey, provider);
|
10874
11024
|
}
|
11025
|
+
/**
|
11026
|
+
* Generate a new Wallet Unlocked with a random key pair.
|
11027
|
+
*
|
11028
|
+
* @param generateOptions - Options to customize the generation process (optional).
|
11029
|
+
* @returns An unlocked wallet instance.
|
11030
|
+
*/
|
11031
|
+
static generate = WalletUnlocked.generate;
|
11032
|
+
/**
|
11033
|
+
* Create a Wallet Unlocked from a seed.
|
11034
|
+
*
|
11035
|
+
* @param seed - The seed phrase.
|
11036
|
+
* @param provider - A Provider instance (optional).
|
11037
|
+
* @param path - The derivation path (optional).
|
11038
|
+
* @returns An unlocked wallet instance.
|
11039
|
+
*/
|
11040
|
+
static fromSeed = WalletUnlocked.fromSeed;
|
11041
|
+
/**
|
11042
|
+
* Create a Wallet Unlocked from a mnemonic phrase.
|
11043
|
+
*
|
11044
|
+
* @param mnemonic - The mnemonic phrase.
|
11045
|
+
* @param provider - A Provider instance (optional).
|
11046
|
+
* @param path - The derivation path (optional).
|
11047
|
+
* @param passphrase - The passphrase for the mnemonic (optional).
|
11048
|
+
* @returns An unlocked wallet instance.
|
11049
|
+
*/
|
11050
|
+
static fromMnemonic = WalletUnlocked.fromMnemonic;
|
11051
|
+
/**
|
11052
|
+
* Create a Wallet Unlocked from an extended key.
|
11053
|
+
*
|
11054
|
+
* @param extendedKey - The extended key.
|
11055
|
+
* @param provider - A Provider instance (optional).
|
11056
|
+
* @returns An unlocked wallet instance.
|
11057
|
+
*/
|
11058
|
+
static fromExtendedKey = WalletUnlocked.fromExtendedKey;
|
11059
|
+
/**
|
11060
|
+
* Create a Wallet Unlocked from an encrypted JSON.
|
11061
|
+
*
|
11062
|
+
* @param jsonWallet - The encrypted JSON keystore.
|
11063
|
+
* @param password - The password to decrypt the JSON.
|
11064
|
+
* @param provider - A Provider instance (optional).
|
11065
|
+
* @returns An unlocked wallet instance.
|
11066
|
+
*/
|
11067
|
+
static fromEncryptedJson = WalletUnlocked.fromEncryptedJson;
|
10875
11068
|
};
|
10876
|
-
/**
|
10877
|
-
* Generate a new Wallet Unlocked with a random key pair.
|
10878
|
-
*
|
10879
|
-
* @param generateOptions - Options to customize the generation process (optional).
|
10880
|
-
* @returns An unlocked wallet instance.
|
10881
|
-
*/
|
10882
|
-
__publicField(Wallet, "generate", WalletUnlocked.generate);
|
10883
|
-
/**
|
10884
|
-
* Create a Wallet Unlocked from a seed.
|
10885
|
-
*
|
10886
|
-
* @param seed - The seed phrase.
|
10887
|
-
* @param provider - A Provider instance (optional).
|
10888
|
-
* @param path - The derivation path (optional).
|
10889
|
-
* @returns An unlocked wallet instance.
|
10890
|
-
*/
|
10891
|
-
__publicField(Wallet, "fromSeed", WalletUnlocked.fromSeed);
|
10892
|
-
/**
|
10893
|
-
* Create a Wallet Unlocked from a mnemonic phrase.
|
10894
|
-
*
|
10895
|
-
* @param mnemonic - The mnemonic phrase.
|
10896
|
-
* @param provider - A Provider instance (optional).
|
10897
|
-
* @param path - The derivation path (optional).
|
10898
|
-
* @param passphrase - The passphrase for the mnemonic (optional).
|
10899
|
-
* @returns An unlocked wallet instance.
|
10900
|
-
*/
|
10901
|
-
__publicField(Wallet, "fromMnemonic", WalletUnlocked.fromMnemonic);
|
10902
|
-
/**
|
10903
|
-
* Create a Wallet Unlocked from an extended key.
|
10904
|
-
*
|
10905
|
-
* @param extendedKey - The extended key.
|
10906
|
-
* @param provider - A Provider instance (optional).
|
10907
|
-
* @returns An unlocked wallet instance.
|
10908
|
-
*/
|
10909
|
-
__publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
10910
|
-
/**
|
10911
|
-
* Create a Wallet Unlocked from an encrypted JSON.
|
10912
|
-
*
|
10913
|
-
* @param jsonWallet - The encrypted JSON keystore.
|
10914
|
-
* @param password - The password to decrypt the JSON.
|
10915
|
-
* @param provider - A Provider instance (optional).
|
10916
|
-
* @returns An unlocked wallet instance.
|
10917
|
-
*/
|
10918
|
-
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
10919
11069
|
|
10920
11070
|
// src/wallet-manager/wallet-manager.ts
|
10921
11071
|
import { Address as Address9 } from "@fuel-ts/address";
|
10922
11072
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
10923
|
-
import { ErrorCode as ErrorCode25, FuelError as
|
11073
|
+
import { ErrorCode as ErrorCode25, FuelError as FuelError27 } from "@fuel-ts/errors";
|
10924
11074
|
import { EventEmitter } from "events";
|
10925
11075
|
|
10926
11076
|
// src/wallet-manager/storages/memory-storage.ts
|
10927
11077
|
var MemoryStorage = class {
|
11078
|
+
static {
|
11079
|
+
__name(this, "MemoryStorage");
|
11080
|
+
}
|
10928
11081
|
storage = /* @__PURE__ */ new Map();
|
10929
11082
|
async getItem(key) {
|
10930
11083
|
const item = await this.storage.get(key);
|
@@ -10943,15 +11096,18 @@ var MemoryStorage = class {
|
|
10943
11096
|
|
10944
11097
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
10945
11098
|
import { Address as Address7 } from "@fuel-ts/address";
|
10946
|
-
import { ErrorCode as ErrorCode23, FuelError as
|
10947
|
-
var _secret;
|
11099
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError25 } from "@fuel-ts/errors";
|
10948
11100
|
var MnemonicVault = class {
|
11101
|
+
static {
|
11102
|
+
__name(this, "MnemonicVault");
|
11103
|
+
}
|
11104
|
+
static type = "mnemonic";
|
11105
|
+
#secret;
|
11106
|
+
pathKey = "{}";
|
11107
|
+
rootPath = `m/44'/1179993420'/${this.pathKey}'/0/0`;
|
11108
|
+
numberOfAccounts = 0;
|
10949
11109
|
constructor(options) {
|
10950
|
-
|
10951
|
-
__publicField(this, "pathKey", "{}");
|
10952
|
-
__publicField(this, "rootPath", `m/44'/1179993420'/${this.pathKey}'/0/0`);
|
10953
|
-
__publicField(this, "numberOfAccounts", 0);
|
10954
|
-
__privateSet(this, _secret, options.secret || mnemonic_default.generate());
|
11110
|
+
this.#secret = options.secret || mnemonic_default.generate();
|
10955
11111
|
this.rootPath = options.rootPath || this.rootPath;
|
10956
11112
|
this.numberOfAccounts = options.numberOfAccounts || 1;
|
10957
11113
|
}
|
@@ -10963,7 +11119,7 @@ var MnemonicVault = class {
|
|
10963
11119
|
}
|
10964
11120
|
serialize() {
|
10965
11121
|
return {
|
10966
|
-
secret:
|
11122
|
+
secret: this.#secret,
|
10967
11123
|
rootPath: this.rootPath,
|
10968
11124
|
numberOfAccounts: this.numberOfAccounts
|
10969
11125
|
};
|
@@ -10972,7 +11128,7 @@ var MnemonicVault = class {
|
|
10972
11128
|
const accounts = [];
|
10973
11129
|
let numberOfAccounts = 0;
|
10974
11130
|
do {
|
10975
|
-
const wallet = Wallet.fromMnemonic(
|
11131
|
+
const wallet = Wallet.fromMnemonic(this.#secret, this.getDerivePath(numberOfAccounts));
|
10976
11132
|
accounts.push({
|
10977
11133
|
publicKey: wallet.publicKey,
|
10978
11134
|
address: wallet.address
|
@@ -10983,7 +11139,7 @@ var MnemonicVault = class {
|
|
10983
11139
|
}
|
10984
11140
|
addAccount() {
|
10985
11141
|
this.numberOfAccounts += 1;
|
10986
|
-
const wallet = Wallet.fromMnemonic(
|
11142
|
+
const wallet = Wallet.fromMnemonic(this.#secret, this.getDerivePath(this.numberOfAccounts - 1));
|
10987
11143
|
return {
|
10988
11144
|
publicKey: wallet.publicKey,
|
10989
11145
|
address: wallet.address
|
@@ -10993,13 +11149,13 @@ var MnemonicVault = class {
|
|
10993
11149
|
let numberOfAccounts = 0;
|
10994
11150
|
const ownerAddress = new Address7(address);
|
10995
11151
|
do {
|
10996
|
-
const wallet = Wallet.fromMnemonic(
|
11152
|
+
const wallet = Wallet.fromMnemonic(this.#secret, this.getDerivePath(numberOfAccounts));
|
10997
11153
|
if (wallet.address.equals(ownerAddress)) {
|
10998
11154
|
return wallet.privateKey;
|
10999
11155
|
}
|
11000
11156
|
numberOfAccounts += 1;
|
11001
11157
|
} while (numberOfAccounts < this.numberOfAccounts);
|
11002
|
-
throw new
|
11158
|
+
throw new FuelError25(
|
11003
11159
|
ErrorCode23.WALLET_MANAGER_ERROR,
|
11004
11160
|
`Account with address '${address}' not found in derived wallets.`
|
11005
11161
|
);
|
@@ -11009,29 +11165,30 @@ var MnemonicVault = class {
|
|
11009
11165
|
return Wallet.fromPrivateKey(privateKey);
|
11010
11166
|
}
|
11011
11167
|
};
|
11012
|
-
_secret = new WeakMap();
|
11013
|
-
__publicField(MnemonicVault, "type", "mnemonic");
|
11014
11168
|
|
11015
11169
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
11016
11170
|
import { Address as Address8 } from "@fuel-ts/address";
|
11017
|
-
import { ErrorCode as ErrorCode24, FuelError as
|
11018
|
-
var _privateKeys;
|
11171
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError26 } from "@fuel-ts/errors";
|
11019
11172
|
var PrivateKeyVault = class {
|
11173
|
+
static {
|
11174
|
+
__name(this, "PrivateKeyVault");
|
11175
|
+
}
|
11176
|
+
static type = "privateKey";
|
11177
|
+
#privateKeys = [];
|
11020
11178
|
/**
|
11021
11179
|
* If privateKey vault is initialized with a secretKey, it creates
|
11022
11180
|
* one account with the fallowing secret
|
11023
11181
|
*/
|
11024
11182
|
constructor(options = {}) {
|
11025
|
-
__privateAdd(this, _privateKeys, []);
|
11026
11183
|
if (options.secret) {
|
11027
|
-
|
11184
|
+
this.#privateKeys = [options.secret];
|
11028
11185
|
} else {
|
11029
|
-
|
11186
|
+
this.#privateKeys = options.accounts || [Wallet.generate().privateKey];
|
11030
11187
|
}
|
11031
11188
|
}
|
11032
11189
|
serialize() {
|
11033
11190
|
return {
|
11034
|
-
accounts:
|
11191
|
+
accounts: this.#privateKeys
|
11035
11192
|
};
|
11036
11193
|
}
|
11037
11194
|
getPublicAccount(privateKey) {
|
@@ -11042,20 +11199,20 @@ var PrivateKeyVault = class {
|
|
11042
11199
|
};
|
11043
11200
|
}
|
11044
11201
|
getAccounts() {
|
11045
|
-
return
|
11202
|
+
return this.#privateKeys.map((pk) => this.getPublicAccount(pk));
|
11046
11203
|
}
|
11047
11204
|
addAccount() {
|
11048
11205
|
const wallet = Wallet.generate();
|
11049
|
-
|
11206
|
+
this.#privateKeys.push(wallet.privateKey);
|
11050
11207
|
return this.getPublicAccount(wallet.privateKey);
|
11051
11208
|
}
|
11052
11209
|
exportAccount(address) {
|
11053
11210
|
const ownerAddress = new Address8(address);
|
11054
|
-
const privateKey =
|
11211
|
+
const privateKey = this.#privateKeys.find(
|
11055
11212
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
11056
11213
|
);
|
11057
11214
|
if (!privateKey) {
|
11058
|
-
throw new
|
11215
|
+
throw new FuelError26(
|
11059
11216
|
ErrorCode24.WALLET_MANAGER_ERROR,
|
11060
11217
|
`No private key found for address '${address}'.`
|
11061
11218
|
);
|
@@ -11067,8 +11224,6 @@ var PrivateKeyVault = class {
|
|
11067
11224
|
return Wallet.fromPrivateKey(privateKey);
|
11068
11225
|
}
|
11069
11226
|
};
|
11070
|
-
_privateKeys = new WeakMap();
|
11071
|
-
__publicField(PrivateKeyVault, "type", "privateKey");
|
11072
11227
|
|
11073
11228
|
// src/wallet-manager/wallet-manager.ts
|
11074
11229
|
var ERROR_MESSAGES = {
|
@@ -11080,49 +11235,50 @@ var ERROR_MESSAGES = {
|
|
11080
11235
|
};
|
11081
11236
|
function assert(condition, message) {
|
11082
11237
|
if (!condition) {
|
11083
|
-
throw new
|
11238
|
+
throw new FuelError27(ErrorCode25.WALLET_MANAGER_ERROR, message);
|
11084
11239
|
}
|
11085
11240
|
}
|
11086
|
-
|
11087
|
-
var
|
11241
|
+
__name(assert, "assert");
|
11242
|
+
var WalletManager = class _WalletManager extends EventEmitter {
|
11243
|
+
static {
|
11244
|
+
__name(this, "WalletManager");
|
11245
|
+
}
|
11246
|
+
/**
|
11247
|
+
* Vaults
|
11248
|
+
*
|
11249
|
+
* Vaults are responsible to store secret keys and return an `Wallet` instance,
|
11250
|
+
* to interact with the network.
|
11251
|
+
*
|
11252
|
+
* Each vault has access to its own state
|
11253
|
+
*
|
11254
|
+
*/
|
11255
|
+
static Vaults = [MnemonicVault, PrivateKeyVault];
|
11256
|
+
/**
|
11257
|
+
* Storage
|
11258
|
+
*
|
11259
|
+
* Persistent encrypted data. `The default storage works only on memory`.
|
11260
|
+
*/
|
11261
|
+
storage = new MemoryStorage();
|
11262
|
+
/* Key name passed to the storage */
|
11263
|
+
STORAGE_KEY = "WalletManager";
|
11264
|
+
// `This variables are only accessible from inside the class`
|
11265
|
+
#vaults = [];
|
11266
|
+
#passphrase = "";
|
11267
|
+
#isLocked = true;
|
11088
11268
|
constructor(options) {
|
11089
11269
|
super();
|
11090
|
-
/**
|
11091
|
-
* Serialize all vaults to store
|
11092
|
-
*
|
11093
|
-
* `This is only accessible from inside the class`
|
11094
|
-
*/
|
11095
|
-
__privateAdd(this, _serializeVaults);
|
11096
|
-
/**
|
11097
|
-
* Deserialize all vaults to state
|
11098
|
-
*
|
11099
|
-
* `This is only accessible from inside the class`
|
11100
|
-
*/
|
11101
|
-
__privateAdd(this, _deserializeVaults);
|
11102
|
-
/**
|
11103
|
-
* Storage
|
11104
|
-
*
|
11105
|
-
* Persistent encrypted data. `The default storage works only on memory`.
|
11106
|
-
*/
|
11107
|
-
__publicField(this, "storage", new MemoryStorage());
|
11108
|
-
/* Key name passed to the storage */
|
11109
|
-
__publicField(this, "STORAGE_KEY", "WalletManager");
|
11110
|
-
// `This variables are only accessible from inside the class`
|
11111
|
-
__privateAdd(this, _vaults, []);
|
11112
|
-
__privateAdd(this, _passphrase, "");
|
11113
|
-
__privateAdd(this, _isLocked, true);
|
11114
11270
|
this.storage = options?.storage || this.storage;
|
11115
11271
|
}
|
11116
11272
|
get isLocked() {
|
11117
|
-
return
|
11273
|
+
return this.#isLocked;
|
11118
11274
|
}
|
11119
11275
|
/**
|
11120
11276
|
* Return the vault serialized object containing all the privateKeys,
|
11121
11277
|
* the format of the return depends on the Vault type.
|
11122
11278
|
*/
|
11123
11279
|
exportVault(vaultId) {
|
11124
|
-
assert(!
|
11125
|
-
const vaultState =
|
11280
|
+
assert(!this.#isLocked, ERROR_MESSAGES.wallet_not_unlocked);
|
11281
|
+
const vaultState = this.#vaults.find((_, idx) => idx === vaultId);
|
11126
11282
|
assert(vaultState, ERROR_MESSAGES.vault_not_found);
|
11127
11283
|
return vaultState.vault.serialize();
|
11128
11284
|
}
|
@@ -11130,7 +11286,7 @@ var _WalletManager = class extends EventEmitter {
|
|
11130
11286
|
* List all vaults on the Wallet Manager, this function not return secret's
|
11131
11287
|
*/
|
11132
11288
|
getVaults() {
|
11133
|
-
return
|
11289
|
+
return this.#vaults.map((v, idx) => ({
|
11134
11290
|
title: v.title,
|
11135
11291
|
type: v.type,
|
11136
11292
|
vaultId: idx
|
@@ -11140,7 +11296,7 @@ var _WalletManager = class extends EventEmitter {
|
|
11140
11296
|
* List all accounts on the Wallet Manager not vault information is revealed
|
11141
11297
|
*/
|
11142
11298
|
getAccounts() {
|
11143
|
-
return
|
11299
|
+
return this.#vaults.flatMap(
|
11144
11300
|
(vaultState, vaultId) => vaultState.vault.getAccounts().map((account) => ({ ...account, vaultId }))
|
11145
11301
|
);
|
11146
11302
|
}
|
@@ -11149,7 +11305,7 @@ var _WalletManager = class extends EventEmitter {
|
|
11149
11305
|
*/
|
11150
11306
|
getWallet(address) {
|
11151
11307
|
const ownerAddress = new Address9(address);
|
11152
|
-
const vaultState =
|
11308
|
+
const vaultState = this.#vaults.find(
|
11153
11309
|
(vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
|
11154
11310
|
);
|
11155
11311
|
assert(vaultState, ERROR_MESSAGES.address_not_found);
|
@@ -11160,8 +11316,8 @@ var _WalletManager = class extends EventEmitter {
|
|
11160
11316
|
*/
|
11161
11317
|
exportPrivateKey(address) {
|
11162
11318
|
const ownerAddress = new Address9(address);
|
11163
|
-
assert(!
|
11164
|
-
const vaultState =
|
11319
|
+
assert(!this.#isLocked, ERROR_MESSAGES.wallet_not_unlocked);
|
11320
|
+
const vaultState = this.#vaults.find(
|
11165
11321
|
(vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
|
11166
11322
|
);
|
11167
11323
|
assert(vaultState, ERROR_MESSAGES.address_not_found);
|
@@ -11173,7 +11329,7 @@ var _WalletManager = class extends EventEmitter {
|
|
11173
11329
|
*/
|
11174
11330
|
async addAccount(options) {
|
11175
11331
|
await this.loadState();
|
11176
|
-
const vaultState =
|
11332
|
+
const vaultState = this.#vaults[options?.vaultId || 0];
|
11177
11333
|
await assert(vaultState, ERROR_MESSAGES.vault_not_found);
|
11178
11334
|
const account = vaultState.vault.addAccount();
|
11179
11335
|
await this.saveState();
|
@@ -11184,7 +11340,7 @@ var _WalletManager = class extends EventEmitter {
|
|
11184
11340
|
* created by the vault.
|
11185
11341
|
*/
|
11186
11342
|
async removeVault(index) {
|
11187
|
-
|
11343
|
+
this.#vaults.splice(index, 1);
|
11188
11344
|
await this.saveState();
|
11189
11345
|
}
|
11190
11346
|
/**
|
@@ -11195,11 +11351,11 @@ var _WalletManager = class extends EventEmitter {
|
|
11195
11351
|
await this.loadState();
|
11196
11352
|
const Vault2 = this.getVaultClass(vaultConfig.type);
|
11197
11353
|
const vault = new Vault2(vaultConfig);
|
11198
|
-
|
11354
|
+
this.#vaults = this.#vaults.concat({
|
11199
11355
|
title: vaultConfig.title,
|
11200
11356
|
type: vaultConfig.type,
|
11201
11357
|
vault
|
11202
|
-
})
|
11358
|
+
});
|
11203
11359
|
await this.saveState();
|
11204
11360
|
}
|
11205
11361
|
/**
|
@@ -11207,9 +11363,9 @@ var _WalletManager = class extends EventEmitter {
|
|
11207
11363
|
* secrets.
|
11208
11364
|
*/
|
11209
11365
|
lock() {
|
11210
|
-
|
11211
|
-
|
11212
|
-
|
11366
|
+
this.#isLocked = true;
|
11367
|
+
this.#vaults = [];
|
11368
|
+
this.#passphrase = "";
|
11213
11369
|
this.emit("lock");
|
11214
11370
|
}
|
11215
11371
|
/**
|
@@ -11217,8 +11373,8 @@ var _WalletManager = class extends EventEmitter {
|
|
11217
11373
|
* Vaults with secrets are not unlocked or instantiated on this moment.
|
11218
11374
|
*/
|
11219
11375
|
async unlock(passphrase) {
|
11220
|
-
|
11221
|
-
|
11376
|
+
this.#passphrase = passphrase;
|
11377
|
+
this.#isLocked = false;
|
11222
11378
|
try {
|
11223
11379
|
await this.loadState();
|
11224
11380
|
this.emit("unlock");
|
@@ -11231,9 +11387,9 @@ var _WalletManager = class extends EventEmitter {
|
|
11231
11387
|
* Update WalletManager encryption passphrase
|
11232
11388
|
*/
|
11233
11389
|
async updatePassphrase(oldpass, newpass) {
|
11234
|
-
const isLocked =
|
11390
|
+
const isLocked = this.#isLocked;
|
11235
11391
|
await this.unlock(oldpass);
|
11236
|
-
|
11392
|
+
this.#passphrase = newpass;
|
11237
11393
|
await this.saveState();
|
11238
11394
|
await this.loadState();
|
11239
11395
|
if (isLocked) {
|
@@ -11244,24 +11400,51 @@ var _WalletManager = class extends EventEmitter {
|
|
11244
11400
|
* Retrieve and decrypt WalletManager state from storage
|
11245
11401
|
*/
|
11246
11402
|
async loadState() {
|
11247
|
-
await assert(!
|
11403
|
+
await assert(!this.#isLocked, ERROR_MESSAGES.wallet_not_unlocked);
|
11248
11404
|
const data = await this.storage.getItem(this.STORAGE_KEY);
|
11249
11405
|
if (data) {
|
11250
|
-
const state = await decrypt(
|
11251
|
-
|
11406
|
+
const state = await decrypt(this.#passphrase, JSON.parse(data));
|
11407
|
+
this.#vaults = this.#deserializeVaults(state.vaults);
|
11252
11408
|
}
|
11253
11409
|
}
|
11254
11410
|
/**
|
11255
11411
|
* Store encrypted WalletManager state on storage
|
11256
11412
|
*/
|
11257
11413
|
async saveState() {
|
11258
|
-
await assert(!
|
11259
|
-
const encryptedData = await encrypt(
|
11260
|
-
vaults:
|
11414
|
+
await assert(!this.#isLocked, ERROR_MESSAGES.wallet_not_unlocked);
|
11415
|
+
const encryptedData = await encrypt(this.#passphrase, {
|
11416
|
+
vaults: this.#serializeVaults(this.#vaults)
|
11261
11417
|
});
|
11262
11418
|
await this.storage.setItem(this.STORAGE_KEY, JSON.stringify(encryptedData));
|
11263
11419
|
this.emit("update");
|
11264
11420
|
}
|
11421
|
+
/**
|
11422
|
+
* Serialize all vaults to store
|
11423
|
+
*
|
11424
|
+
* `This is only accessible from inside the class`
|
11425
|
+
*/
|
11426
|
+
#serializeVaults(vaults) {
|
11427
|
+
return vaults.map(({ title, type, vault }) => ({
|
11428
|
+
title,
|
11429
|
+
type,
|
11430
|
+
data: vault.serialize()
|
11431
|
+
}));
|
11432
|
+
}
|
11433
|
+
/**
|
11434
|
+
* Deserialize all vaults to state
|
11435
|
+
*
|
11436
|
+
* `This is only accessible from inside the class`
|
11437
|
+
*/
|
11438
|
+
#deserializeVaults(vaults) {
|
11439
|
+
return vaults.map(({ title, type, data: vaultConfig }) => {
|
11440
|
+
const VaultClass = this.getVaultClass(type);
|
11441
|
+
return {
|
11442
|
+
title,
|
11443
|
+
type,
|
11444
|
+
vault: new VaultClass(vaultConfig)
|
11445
|
+
};
|
11446
|
+
});
|
11447
|
+
}
|
11265
11448
|
/**
|
11266
11449
|
* Return a instantiable Class reference from `WalletManager.Vaults` supported list.
|
11267
11450
|
*/
|
@@ -11271,79 +11454,52 @@ var _WalletManager = class extends EventEmitter {
|
|
11271
11454
|
return VaultClass;
|
11272
11455
|
}
|
11273
11456
|
};
|
11274
|
-
var WalletManager = _WalletManager;
|
11275
|
-
_vaults = new WeakMap();
|
11276
|
-
_passphrase = new WeakMap();
|
11277
|
-
_isLocked = new WeakMap();
|
11278
|
-
_serializeVaults = new WeakSet();
|
11279
|
-
serializeVaults_fn = function(vaults) {
|
11280
|
-
return vaults.map(({ title, type, vault }) => ({
|
11281
|
-
title,
|
11282
|
-
type,
|
11283
|
-
data: vault.serialize()
|
11284
|
-
}));
|
11285
|
-
};
|
11286
|
-
_deserializeVaults = new WeakSet();
|
11287
|
-
deserializeVaults_fn = function(vaults) {
|
11288
|
-
return vaults.map(({ title, type, data: vaultConfig }) => {
|
11289
|
-
const VaultClass = this.getVaultClass(type);
|
11290
|
-
return {
|
11291
|
-
title,
|
11292
|
-
type,
|
11293
|
-
vault: new VaultClass(vaultConfig)
|
11294
|
-
};
|
11295
|
-
});
|
11296
|
-
};
|
11297
|
-
/**
|
11298
|
-
* Vaults
|
11299
|
-
*
|
11300
|
-
* Vaults are responsible to store secret keys and return an `Wallet` instance,
|
11301
|
-
* to interact with the network.
|
11302
|
-
*
|
11303
|
-
* Each vault has access to its own state
|
11304
|
-
*
|
11305
|
-
*/
|
11306
|
-
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
11307
11457
|
|
11308
11458
|
// src/wallet-manager/types.ts
|
11309
|
-
import { ErrorCode as ErrorCode26, FuelError as
|
11459
|
+
import { ErrorCode as ErrorCode26, FuelError as FuelError28 } from "@fuel-ts/errors";
|
11310
11460
|
var Vault = class {
|
11461
|
+
static {
|
11462
|
+
__name(this, "Vault");
|
11463
|
+
}
|
11464
|
+
static type;
|
11311
11465
|
constructor(_options) {
|
11312
|
-
throw new
|
11466
|
+
throw new FuelError28(ErrorCode26.NOT_IMPLEMENTED, "Not implemented.");
|
11313
11467
|
}
|
11314
11468
|
serialize() {
|
11315
|
-
throw new
|
11469
|
+
throw new FuelError28(ErrorCode26.NOT_IMPLEMENTED, "Not implemented.");
|
11316
11470
|
}
|
11317
11471
|
getAccounts() {
|
11318
|
-
throw new
|
11472
|
+
throw new FuelError28(ErrorCode26.NOT_IMPLEMENTED, "Not implemented.");
|
11319
11473
|
}
|
11320
11474
|
addAccount() {
|
11321
|
-
throw new
|
11475
|
+
throw new FuelError28(ErrorCode26.NOT_IMPLEMENTED, "Not implemented.");
|
11322
11476
|
}
|
11323
11477
|
exportAccount(_address) {
|
11324
|
-
throw new
|
11478
|
+
throw new FuelError28(ErrorCode26.NOT_IMPLEMENTED, "Not implemented.");
|
11325
11479
|
}
|
11326
11480
|
getWallet(_address) {
|
11327
|
-
throw new
|
11481
|
+
throw new FuelError28(ErrorCode26.NOT_IMPLEMENTED, "Not implemented.");
|
11328
11482
|
}
|
11329
11483
|
};
|
11330
|
-
__publicField(Vault, "type");
|
11331
11484
|
var StorageAbstract = class {
|
11485
|
+
static {
|
11486
|
+
__name(this, "StorageAbstract");
|
11487
|
+
}
|
11332
11488
|
};
|
11333
11489
|
|
11334
11490
|
// src/predicate/predicate.ts
|
11335
|
-
import { Interface as
|
11491
|
+
import { Interface as Interface4 } from "@fuel-ts/abi-coder";
|
11336
11492
|
import { Address as Address10 } from "@fuel-ts/address";
|
11337
|
-
import { ErrorCode as ErrorCode28, FuelError as
|
11493
|
+
import { ErrorCode as ErrorCode28, FuelError as FuelError30 } from "@fuel-ts/errors";
|
11338
11494
|
import { arrayify as arrayify23, hexlify as hexlify24 } from "@fuel-ts/utils";
|
11339
11495
|
|
11340
11496
|
// src/utils/deployScriptOrPredicate.ts
|
11341
|
-
import { FuelError as
|
11497
|
+
import { FuelError as FuelError29, ErrorCode as ErrorCode27 } from "@fuel-ts/errors";
|
11342
11498
|
import { bn as bn22 } from "@fuel-ts/math";
|
11343
11499
|
import { arrayify as arrayify21 } from "@fuel-ts/utils";
|
11344
11500
|
|
11345
11501
|
// src/utils/predicate-script-loader-instructions.ts
|
11346
|
-
import { BigNumberCoder as
|
11502
|
+
import { BigNumberCoder as BigNumberCoder4 } from "@fuel-ts/abi-coder";
|
11347
11503
|
import { sha256 as sha2565 } from "@fuel-ts/hasher";
|
11348
11504
|
import { concat as concat7 } from "@fuel-ts/utils";
|
11349
11505
|
import * as asm2 from "@fuels/vm-asm";
|
@@ -11355,29 +11511,33 @@ var WORD_SIZE2 = 8;
|
|
11355
11511
|
var DATA_OFFSET_INDEX = 8;
|
11356
11512
|
var CONFIGURABLE_OFFSET_INDEX = 16;
|
11357
11513
|
function getBytecodeDataOffset(bytecode) {
|
11358
|
-
const [offset] = new
|
11514
|
+
const [offset] = new BigNumberCoder4("u64").decode(bytecode, DATA_OFFSET_INDEX);
|
11359
11515
|
return offset.toNumber();
|
11360
11516
|
}
|
11517
|
+
__name(getBytecodeDataOffset, "getBytecodeDataOffset");
|
11361
11518
|
function getBytecodeConfigurableOffset(bytecode) {
|
11362
|
-
const [offset] = new
|
11519
|
+
const [offset] = new BigNumberCoder4("u64").decode(bytecode, CONFIGURABLE_OFFSET_INDEX);
|
11363
11520
|
return offset.toNumber();
|
11364
11521
|
}
|
11522
|
+
__name(getBytecodeConfigurableOffset, "getBytecodeConfigurableOffset");
|
11365
11523
|
function getBytecodeId(bytecode) {
|
11366
11524
|
const configurableOffset = getBytecodeConfigurableOffset(bytecode);
|
11367
11525
|
const byteCodeWithoutConfigurableSection = bytecode.slice(0, configurableOffset);
|
11368
11526
|
return sha2565(byteCodeWithoutConfigurableSection);
|
11369
11527
|
}
|
11528
|
+
__name(getBytecodeId, "getBytecodeId");
|
11370
11529
|
function getLegacyBlobId(bytecode) {
|
11371
11530
|
const dataOffset = getBytecodeDataOffset(bytecode);
|
11372
11531
|
const byteCodeWithoutDataSection = bytecode.slice(0, dataOffset);
|
11373
11532
|
return sha2565(byteCodeWithoutDataSection);
|
11374
11533
|
}
|
11534
|
+
__name(getLegacyBlobId, "getLegacyBlobId");
|
11375
11535
|
function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
11376
11536
|
const { RegId, Instruction } = asm2;
|
11377
11537
|
const REG_PC = RegId.pc().to_u8();
|
11378
11538
|
const REG_SP = RegId.sp().to_u8();
|
11379
11539
|
const REG_IS = RegId.is().to_u8();
|
11380
|
-
const getInstructions = (numOfInstructions2) => [
|
11540
|
+
const getInstructions = /* @__PURE__ */ __name((numOfInstructions2) => [
|
11381
11541
|
// 1. Load the blob content into memory
|
11382
11542
|
// Find the start of the hardcoded blob ID, which is located after the loader code ends.
|
11383
11543
|
asm2.move_(REG_ADDRESS_OF_DATA_AFTER_CODE, REG_PC),
|
@@ -11411,8 +11571,8 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
|
11411
11571
|
asm2.divi(REG_START_OF_LOADED_CODE, REG_START_OF_LOADED_CODE, 4),
|
11412
11572
|
// Jump to the start of the contract we loaded.
|
11413
11573
|
asm2.jmp(REG_START_OF_LOADED_CODE)
|
11414
|
-
];
|
11415
|
-
const getInstructionsNoDataSection = (numOfInstructions2) => [
|
11574
|
+
], "getInstructions");
|
11575
|
+
const getInstructionsNoDataSection = /* @__PURE__ */ __name((numOfInstructions2) => [
|
11416
11576
|
// 1. Load the blob content into memory
|
11417
11577
|
// Find the start of the hardcoded blob ID, which is located after the loader code ends.
|
11418
11578
|
// 1. Load the blob content into memory
|
@@ -11439,7 +11599,7 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
|
11439
11599
|
asm2.divi(REG_START_OF_LOADED_CODE, REG_START_OF_LOADED_CODE, 4),
|
11440
11600
|
// Jump to the start of the contract we loaded.
|
11441
11601
|
asm2.jmp(REG_START_OF_LOADED_CODE)
|
11442
|
-
];
|
11602
|
+
], "getInstructionsNoDataSection");
|
11443
11603
|
const offset = getBytecodeConfigurableOffset(originalBinary);
|
11444
11604
|
if (originalBinary.length < offset) {
|
11445
11605
|
throw new Error(
|
@@ -11484,6 +11644,7 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
|
11484
11644
|
const loaderBytecode = new Uint8Array([...instructionBytes, ...blobBytes]);
|
11485
11645
|
return { loaderBytecode };
|
11486
11646
|
}
|
11647
|
+
__name(getPredicateScriptLoaderInstructions, "getPredicateScriptLoaderInstructions");
|
11487
11648
|
|
11488
11649
|
// src/utils/deployScriptOrPredicate.ts
|
11489
11650
|
async function fundBlobTx(deployer, blobTxRequest) {
|
@@ -11500,12 +11661,13 @@ async function fundBlobTx(deployer, blobTxRequest) {
|
|
11500
11661
|
}).add(1);
|
11501
11662
|
totalCost = totalCost.add(minFee);
|
11502
11663
|
if (totalCost.gt(await deployer.getBalance())) {
|
11503
|
-
throw new
|
11664
|
+
throw new FuelError29(ErrorCode27.FUNDS_TOO_LOW, "Insufficient balance to deploy predicate.");
|
11504
11665
|
}
|
11505
11666
|
const txCost = await deployer.getTransactionCost(blobTxRequest);
|
11506
11667
|
blobTxRequest.maxFee = txCost.maxFee;
|
11507
11668
|
return deployer.fund(blobTxRequest, txCost);
|
11508
11669
|
}
|
11670
|
+
__name(fundBlobTx, "fundBlobTx");
|
11509
11671
|
function adjustConfigurableOffsets(jsonAbi, configurableOffsetDiff) {
|
11510
11672
|
const { configurables: readOnlyConfigurables } = jsonAbi;
|
11511
11673
|
const configurables = [];
|
@@ -11514,6 +11676,7 @@ function adjustConfigurableOffsets(jsonAbi, configurableOffsetDiff) {
|
|
11514
11676
|
});
|
11515
11677
|
return { ...jsonAbi, configurables };
|
11516
11678
|
}
|
11679
|
+
__name(adjustConfigurableOffsets, "adjustConfigurableOffsets");
|
11517
11680
|
async function deployScriptOrPredicate({
|
11518
11681
|
deployer,
|
11519
11682
|
bytecode,
|
@@ -11538,12 +11701,12 @@ async function deployScriptOrPredicate({
|
|
11538
11701
|
const loaderInstance = loaderInstanceCallback(loaderBytecode, newAbi);
|
11539
11702
|
if (blobExists) {
|
11540
11703
|
return {
|
11541
|
-
waitForResult: () => Promise.resolve(loaderInstance),
|
11704
|
+
waitForResult: /* @__PURE__ */ __name(() => Promise.resolve(loaderInstance), "waitForResult"),
|
11542
11705
|
blobId
|
11543
11706
|
};
|
11544
11707
|
}
|
11545
11708
|
const fundedBlobRequest = await fundBlobTx(deployer, blobTxRequest);
|
11546
|
-
const waitForResult = async () => {
|
11709
|
+
const waitForResult = /* @__PURE__ */ __name(async () => {
|
11547
11710
|
try {
|
11548
11711
|
const blobTx = await deployer.sendTransaction(fundedBlobRequest);
|
11549
11712
|
const result = await blobTx.waitForResult();
|
@@ -11551,31 +11714,35 @@ async function deployScriptOrPredicate({
|
|
11551
11714
|
throw new Error();
|
11552
11715
|
}
|
11553
11716
|
} catch (err) {
|
11554
|
-
throw new
|
11717
|
+
throw new FuelError29(ErrorCode27.TRANSACTION_FAILED, "Failed to deploy predicate chunk");
|
11555
11718
|
}
|
11556
11719
|
return loaderInstance;
|
11557
|
-
};
|
11720
|
+
}, "waitForResult");
|
11558
11721
|
return {
|
11559
11722
|
waitForResult,
|
11560
11723
|
blobId
|
11561
11724
|
};
|
11562
11725
|
}
|
11726
|
+
__name(deployScriptOrPredicate, "deployScriptOrPredicate");
|
11563
11727
|
|
11564
11728
|
// src/predicate/utils/getPredicateRoot.ts
|
11565
11729
|
import { hash as hash3 } from "@fuel-ts/hasher";
|
11566
11730
|
import { calcRoot } from "@fuel-ts/merkle";
|
11567
11731
|
import { chunkAndPadBytes, hexlify as hexlify23, concat as concat8, arrayify as arrayify22 } from "@fuel-ts/utils";
|
11568
|
-
var getPredicateRoot = (bytecode) => {
|
11732
|
+
var getPredicateRoot = /* @__PURE__ */ __name((bytecode) => {
|
11569
11733
|
const chunkSize = 16 * 1024;
|
11570
11734
|
const bytes = arrayify22(bytecode);
|
11571
11735
|
const chunks = chunkAndPadBytes(bytes, chunkSize);
|
11572
11736
|
const codeRoot = calcRoot(chunks.map((c) => hexlify23(c)));
|
11573
11737
|
const predicateRoot = hash3(concat8(["0x4655454C", codeRoot]));
|
11574
11738
|
return predicateRoot;
|
11575
|
-
};
|
11739
|
+
}, "getPredicateRoot");
|
11576
11740
|
|
11577
11741
|
// src/predicate/predicate.ts
|
11578
|
-
var Predicate = class extends Account {
|
11742
|
+
var Predicate = class _Predicate extends Account {
|
11743
|
+
static {
|
11744
|
+
__name(this, "Predicate");
|
11745
|
+
}
|
11579
11746
|
bytes;
|
11580
11747
|
predicateData = [];
|
11581
11748
|
interface;
|
@@ -11597,7 +11764,7 @@ var Predicate = class extends Account {
|
|
11597
11764
|
data,
|
11598
11765
|
configurableConstants
|
11599
11766
|
}) {
|
11600
|
-
const { predicateBytes, predicateInterface } =
|
11767
|
+
const { predicateBytes, predicateInterface } = _Predicate.processPredicateData(
|
11601
11768
|
bytecode,
|
11602
11769
|
abi,
|
11603
11770
|
configurableConstants
|
@@ -11666,7 +11833,7 @@ var Predicate = class extends Account {
|
|
11666
11833
|
* @returns A new Predicate instance with the same bytecode, ABI and provider but with the ability to set the data and configurable constants.
|
11667
11834
|
*/
|
11668
11835
|
toNewInstance(overrides = {}) {
|
11669
|
-
return new
|
11836
|
+
return new _Predicate({
|
11670
11837
|
bytecode: this.initialBytecode,
|
11671
11838
|
abi: this.interface.jsonAbi,
|
11672
11839
|
provider: this.provider,
|
@@ -11684,15 +11851,15 @@ var Predicate = class extends Account {
|
|
11684
11851
|
*/
|
11685
11852
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
11686
11853
|
let predicateBytes = arrayify23(bytes);
|
11687
|
-
const abiInterface = new
|
11854
|
+
const abiInterface = new Interface4(jsonAbi);
|
11688
11855
|
if (abiInterface.functions.main === void 0) {
|
11689
|
-
throw new
|
11856
|
+
throw new FuelError30(
|
11690
11857
|
ErrorCode28.ABI_MAIN_METHOD_MISSING,
|
11691
11858
|
'Cannot use ABI without "main" function.'
|
11692
11859
|
);
|
11693
11860
|
}
|
11694
11861
|
if (configurableConstants && Object.keys(configurableConstants).length) {
|
11695
|
-
predicateBytes =
|
11862
|
+
predicateBytes = _Predicate.setConfigurableConstants(
|
11696
11863
|
predicateBytes,
|
11697
11864
|
configurableConstants,
|
11698
11865
|
abiInterface
|
@@ -11747,14 +11914,14 @@ var Predicate = class extends Account {
|
|
11747
11914
|
const mutatedBytes = bytes;
|
11748
11915
|
try {
|
11749
11916
|
if (Object.keys(abiInterface.configurables).length === 0) {
|
11750
|
-
throw new
|
11917
|
+
throw new FuelError30(
|
11751
11918
|
ErrorCode28.INVALID_CONFIGURABLE_CONSTANTS,
|
11752
11919
|
"Predicate has no configurable constants to be set"
|
11753
11920
|
);
|
11754
11921
|
}
|
11755
11922
|
Object.entries(configurableConstants).forEach(([key, value]) => {
|
11756
11923
|
if (!abiInterface?.configurables[key]) {
|
11757
|
-
throw new
|
11924
|
+
throw new FuelError30(
|
11758
11925
|
ErrorCode28.CONFIGURABLE_NOT_FOUND,
|
11759
11926
|
`No configurable constant named '${key}' found in the Predicate`
|
11760
11927
|
);
|
@@ -11764,7 +11931,7 @@ var Predicate = class extends Account {
|
|
11764
11931
|
mutatedBytes.set(encoded, offset);
|
11765
11932
|
});
|
11766
11933
|
} catch (err) {
|
11767
|
-
throw new
|
11934
|
+
throw new FuelError30(
|
11768
11935
|
ErrorCode28.INVALID_CONFIGURABLE_CONSTANTS,
|
11769
11936
|
`Error setting configurable constants: ${err.message}.`
|
11770
11937
|
);
|
@@ -11807,12 +11974,12 @@ var Predicate = class extends Account {
|
|
11807
11974
|
deployer: account,
|
11808
11975
|
abi: this.interface.jsonAbi,
|
11809
11976
|
bytecode: this.bytes,
|
11810
|
-
loaderInstanceCallback: (loaderBytecode, newAbi) => new
|
11977
|
+
loaderInstanceCallback: /* @__PURE__ */ __name((loaderBytecode, newAbi) => new _Predicate({
|
11811
11978
|
bytecode: loaderBytecode,
|
11812
11979
|
abi: newAbi,
|
11813
11980
|
provider: this.provider,
|
11814
11981
|
data: this.predicateData
|
11815
|
-
})
|
11982
|
+
}), "loaderInstanceCallback")
|
11816
11983
|
});
|
11817
11984
|
}
|
11818
11985
|
};
|
@@ -11821,7 +11988,7 @@ var Predicate = class extends Account {
|
|
11821
11988
|
import { ErrorCode as ErrorCode29, FuelError as FuelError33 } from "@fuel-ts/errors";
|
11822
11989
|
|
11823
11990
|
// src/connectors/fuel-connector.ts
|
11824
|
-
import { FuelError as
|
11991
|
+
import { FuelError as FuelError31 } from "@fuel-ts/errors";
|
11825
11992
|
import { EventEmitter as EventEmitter2 } from "events";
|
11826
11993
|
|
11827
11994
|
// src/connectors/types/connector-types.ts
|
@@ -11863,6 +12030,9 @@ var FuelConnectorEventType = "FuelConnector";
|
|
11863
12030
|
|
11864
12031
|
// src/connectors/types/local-storage.ts
|
11865
12032
|
var LocalStorage = class {
|
12033
|
+
static {
|
12034
|
+
__name(this, "LocalStorage");
|
12035
|
+
}
|
11866
12036
|
storage;
|
11867
12037
|
constructor(localStorage) {
|
11868
12038
|
this.storage = localStorage;
|
@@ -11883,6 +12053,9 @@ var LocalStorage = class {
|
|
11883
12053
|
|
11884
12054
|
// src/connectors/fuel-connector.ts
|
11885
12055
|
var FuelConnector = class extends EventEmitter2 {
|
12056
|
+
static {
|
12057
|
+
__name(this, "FuelConnector");
|
12058
|
+
}
|
11886
12059
|
name = "";
|
11887
12060
|
metadata = {};
|
11888
12061
|
connected = false;
|
@@ -11896,7 +12069,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11896
12069
|
* @returns Always true.
|
11897
12070
|
*/
|
11898
12071
|
async ping() {
|
11899
|
-
throw new
|
12072
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11900
12073
|
}
|
11901
12074
|
/**
|
11902
12075
|
* Should return the current version of the connector
|
@@ -11905,7 +12078,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11905
12078
|
* @returns boolean - connection status.
|
11906
12079
|
*/
|
11907
12080
|
async version() {
|
11908
|
-
throw new
|
12081
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11909
12082
|
}
|
11910
12083
|
/**
|
11911
12084
|
* Should return true if the connector is connected
|
@@ -11914,7 +12087,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11914
12087
|
* @returns The connection status.
|
11915
12088
|
*/
|
11916
12089
|
async isConnected() {
|
11917
|
-
throw new
|
12090
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11918
12091
|
}
|
11919
12092
|
/**
|
11920
12093
|
* Should return all the accounts authorized for the
|
@@ -11923,7 +12096,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11923
12096
|
* @returns The accounts addresses strings
|
11924
12097
|
*/
|
11925
12098
|
async accounts() {
|
11926
|
-
throw new
|
12099
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11927
12100
|
}
|
11928
12101
|
/**
|
11929
12102
|
* Should start the connection process and return
|
@@ -11935,7 +12108,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11935
12108
|
* @returns boolean - connection status.
|
11936
12109
|
*/
|
11937
12110
|
async connect() {
|
11938
|
-
throw new
|
12111
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11939
12112
|
}
|
11940
12113
|
/**
|
11941
12114
|
* Should disconnect the current connection and
|
@@ -11945,7 +12118,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11945
12118
|
* @returns The connection status.
|
11946
12119
|
*/
|
11947
12120
|
async disconnect() {
|
11948
|
-
throw new
|
12121
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11949
12122
|
}
|
11950
12123
|
/**
|
11951
12124
|
* Should start the sign message process and return
|
@@ -11957,7 +12130,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11957
12130
|
* @returns Message signature
|
11958
12131
|
*/
|
11959
12132
|
async signMessage(_address, _message) {
|
11960
|
-
throw new
|
12133
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11961
12134
|
}
|
11962
12135
|
/**
|
11963
12136
|
* Should start the sign transaction process and return
|
@@ -11969,7 +12142,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11969
12142
|
* @returns Transaction signature
|
11970
12143
|
*/
|
11971
12144
|
async signTransaction(_address, _transaction) {
|
11972
|
-
throw new
|
12145
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11973
12146
|
}
|
11974
12147
|
/**
|
11975
12148
|
* Should start the send transaction process and return
|
@@ -11985,7 +12158,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11985
12158
|
* @returns The transaction id or transaction response
|
11986
12159
|
*/
|
11987
12160
|
async sendTransaction(_address, _transaction, _params) {
|
11988
|
-
throw new
|
12161
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11989
12162
|
}
|
11990
12163
|
/**
|
11991
12164
|
* Should return the current account selected inside the connector, if the account
|
@@ -11996,7 +12169,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11996
12169
|
* @returns The current account selected otherwise null.
|
11997
12170
|
*/
|
11998
12171
|
async currentAccount() {
|
11999
|
-
throw new
|
12172
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12000
12173
|
}
|
12001
12174
|
/**
|
12002
12175
|
* Should add the assets metadata to the connector and return true if the asset
|
@@ -12010,7 +12183,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12010
12183
|
* @returns True if the asset was added successfully
|
12011
12184
|
*/
|
12012
12185
|
async addAssets(_assets) {
|
12013
|
-
throw new
|
12186
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12014
12187
|
}
|
12015
12188
|
/**
|
12016
12189
|
* Should add the asset metadata to the connector and return true if the asset
|
@@ -12024,7 +12197,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12024
12197
|
* @returns True if the asset was added successfully
|
12025
12198
|
*/
|
12026
12199
|
async addAsset(_asset) {
|
12027
|
-
throw new
|
12200
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12028
12201
|
}
|
12029
12202
|
/**
|
12030
12203
|
* Should return all the assets added to the connector. If a connection is already established.
|
@@ -12032,7 +12205,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12032
12205
|
* @returns Array of assets metadata from the connector vinculated to the all accounts from a specific Wallet.
|
12033
12206
|
*/
|
12034
12207
|
async assets() {
|
12035
|
-
throw new
|
12208
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12036
12209
|
}
|
12037
12210
|
/**
|
12038
12211
|
* Should start the add network process and return true if the network was added successfully.
|
@@ -12043,7 +12216,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12043
12216
|
* @returns Return true if the network was added successfully
|
12044
12217
|
*/
|
12045
12218
|
async addNetwork(_networkUrl) {
|
12046
|
-
throw new
|
12219
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12047
12220
|
}
|
12048
12221
|
/**
|
12049
12222
|
* Should start the select network process and return true if the network has change successfully.
|
@@ -12054,7 +12227,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12054
12227
|
* @returns Return true if the network was added successfully
|
12055
12228
|
*/
|
12056
12229
|
async selectNetwork(_network) {
|
12057
|
-
throw new
|
12230
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12058
12231
|
}
|
12059
12232
|
/**
|
12060
12233
|
* Should return all the networks available from the connector. If the connection is already established.
|
@@ -12062,7 +12235,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12062
12235
|
* @returns Return all the networks added to the connector.
|
12063
12236
|
*/
|
12064
12237
|
async networks() {
|
12065
|
-
throw new
|
12238
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12066
12239
|
}
|
12067
12240
|
/**
|
12068
12241
|
* Should return the current network selected inside the connector. Even if the connection is not established.
|
@@ -12070,7 +12243,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12070
12243
|
* @returns Return the current network selected inside the connector.
|
12071
12244
|
*/
|
12072
12245
|
async currentNetwork() {
|
12073
|
-
throw new
|
12246
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12074
12247
|
}
|
12075
12248
|
/**
|
12076
12249
|
* Should add the ABI to the connector and return true if the ABI was added successfully.
|
@@ -12080,7 +12253,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12080
12253
|
* @returns Return true if the ABI was added successfully.
|
12081
12254
|
*/
|
12082
12255
|
async addABI(_contractId, _abi) {
|
12083
|
-
throw new
|
12256
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12084
12257
|
}
|
12085
12258
|
/**
|
12086
12259
|
* Should return the ABI from the connector vinculated to the all accounts from a specific Wallet.
|
@@ -12089,7 +12262,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12089
12262
|
* @returns The ABI if it exists, otherwise return null.
|
12090
12263
|
*/
|
12091
12264
|
async getABI(_id) {
|
12092
|
-
throw new
|
12265
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12093
12266
|
}
|
12094
12267
|
/**
|
12095
12268
|
* Should return true if the abi exists in the connector vinculated to the all accounts from a specific Wallet.
|
@@ -12098,7 +12271,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
12098
12271
|
* @returns Returns true if the abi exists or false if not.
|
12099
12272
|
*/
|
12100
12273
|
async hasABI(_id) {
|
12101
|
-
throw new
|
12274
|
+
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
12102
12275
|
}
|
12103
12276
|
/**
|
12104
12277
|
* Event listener for the connector.
|
@@ -12131,6 +12304,7 @@ function cacheFor(fn, { cache: cache2, cacheTime, key }) {
|
|
12131
12304
|
return result;
|
12132
12305
|
};
|
12133
12306
|
}
|
12307
|
+
__name(cacheFor, "cacheFor");
|
12134
12308
|
|
12135
12309
|
// src/connectors/utils/dispatch-fuel-connector-event.ts
|
12136
12310
|
function dispatchFuelConnectorEvent(connector) {
|
@@ -12140,18 +12314,45 @@ function dispatchFuelConnectorEvent(connector) {
|
|
12140
12314
|
})
|
12141
12315
|
);
|
12142
12316
|
}
|
12317
|
+
__name(dispatchFuelConnectorEvent, "dispatchFuelConnectorEvent");
|
12318
|
+
|
12319
|
+
// src/connectors/utils/promises.ts
|
12320
|
+
import { FuelError as FuelError32 } from "@fuel-ts/errors";
|
12321
|
+
function deferPromise() {
|
12322
|
+
const defer = {};
|
12323
|
+
defer.promise = new Promise((resolve, reject) => {
|
12324
|
+
defer.reject = reject;
|
12325
|
+
defer.resolve = resolve;
|
12326
|
+
});
|
12327
|
+
return defer;
|
12328
|
+
}
|
12329
|
+
__name(deferPromise, "deferPromise");
|
12330
|
+
async function withTimeout(promise, timeout = 1050) {
|
12331
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
12332
|
+
setTimeout(() => {
|
12333
|
+
reject(new FuelError32(FuelError32.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
12334
|
+
}, timeout);
|
12335
|
+
});
|
12336
|
+
return Promise.race([timeoutPromise, promise]);
|
12337
|
+
}
|
12338
|
+
__name(withTimeout, "withTimeout");
|
12143
12339
|
|
12144
12340
|
// src/connectors/fuel.ts
|
12145
12341
|
var HAS_CONNECTOR_TIMEOUT = 2e3;
|
12146
12342
|
var PING_CACHE_TIME = 5e3;
|
12147
12343
|
var { warn } = console;
|
12148
|
-
var
|
12344
|
+
var Fuel = class _Fuel extends FuelConnector {
|
12345
|
+
static {
|
12346
|
+
__name(this, "Fuel");
|
12347
|
+
}
|
12348
|
+
static STORAGE_KEY = "fuel-current-connector";
|
12349
|
+
static defaultConfig = {};
|
12149
12350
|
_storage = null;
|
12150
12351
|
_connectors = [];
|
12151
12352
|
_targetObject = null;
|
12152
12353
|
_unsubscribes = [];
|
12153
|
-
_targetUnsubscribe = () => {
|
12154
|
-
};
|
12354
|
+
_targetUnsubscribe = /* @__PURE__ */ __name(() => {
|
12355
|
+
}, "_targetUnsubscribe");
|
12155
12356
|
_pingCache = {};
|
12156
12357
|
_currentConnector;
|
12157
12358
|
_initializationPromise = null;
|
@@ -12224,7 +12425,7 @@ var _Fuel = class extends FuelConnector {
|
|
12224
12425
|
const currentConnector = this._currentConnector;
|
12225
12426
|
this._unsubscribes.map((unSub) => unSub());
|
12226
12427
|
this._unsubscribes = events.map((event) => {
|
12227
|
-
const handler = (...args) => this.emit(event, ...args);
|
12428
|
+
const handler = /* @__PURE__ */ __name((...args) => this.emit(event, ...args), "handler");
|
12228
12429
|
currentConnector.on(event, handler);
|
12229
12430
|
return () => currentConnector.off(event, handler);
|
12230
12431
|
});
|
@@ -12308,7 +12509,7 @@ var _Fuel = class extends FuelConnector {
|
|
12308
12509
|
* Setup a listener for the FuelConnector event and add the connector
|
12309
12510
|
* to the list of new connectors.
|
12310
12511
|
*/
|
12311
|
-
setupConnectorListener = () => {
|
12512
|
+
setupConnectorListener = /* @__PURE__ */ __name(() => {
|
12312
12513
|
const { _targetObject: targetObject } = this;
|
12313
12514
|
const eventName = FuelConnectorEventType;
|
12314
12515
|
if (targetObject?.on) {
|
@@ -12318,9 +12519,9 @@ var _Fuel = class extends FuelConnector {
|
|
12318
12519
|
};
|
12319
12520
|
}
|
12320
12521
|
if (targetObject?.addEventListener) {
|
12321
|
-
const handler = (e) => {
|
12522
|
+
const handler = /* @__PURE__ */ __name((e) => {
|
12322
12523
|
this.addConnector(e.detail);
|
12323
|
-
};
|
12524
|
+
}, "handler");
|
12324
12525
|
targetObject.addEventListener(eventName, handler);
|
12325
12526
|
return () => {
|
12326
12527
|
targetObject.removeEventListener?.(eventName, handler);
|
@@ -12328,11 +12529,11 @@ var _Fuel = class extends FuelConnector {
|
|
12328
12529
|
}
|
12329
12530
|
return () => {
|
12330
12531
|
};
|
12331
|
-
};
|
12532
|
+
}, "setupConnectorListener");
|
12332
12533
|
/**
|
12333
12534
|
* Add a new connector to the list of connectors.
|
12334
12535
|
*/
|
12335
|
-
addConnector = async (connector) => {
|
12536
|
+
addConnector = /* @__PURE__ */ __name(async (connector) => {
|
12336
12537
|
if (!this.getConnector(connector)) {
|
12337
12538
|
this._connectors.push(connector);
|
12338
12539
|
}
|
@@ -12343,8 +12544,8 @@ var _Fuel = class extends FuelConnector {
|
|
12343
12544
|
emitEvents: false
|
12344
12545
|
});
|
12345
12546
|
}
|
12346
|
-
};
|
12347
|
-
triggerConnectorEvents = async () => {
|
12547
|
+
}, "addConnector");
|
12548
|
+
triggerConnectorEvents = /* @__PURE__ */ __name(async () => {
|
12348
12549
|
const [isConnected, networks2, currentNetwork] = await Promise.all([
|
12349
12550
|
this.isConnected(),
|
12350
12551
|
this.networks(),
|
@@ -12361,14 +12562,14 @@ var _Fuel = class extends FuelConnector {
|
|
12361
12562
|
this.emit(this.events.accounts, accounts);
|
12362
12563
|
this.emit(this.events.currentAccount, currentAccount);
|
12363
12564
|
}
|
12364
|
-
};
|
12565
|
+
}, "triggerConnectorEvents");
|
12365
12566
|
/**
|
12366
12567
|
* Get a connector from the list of connectors.
|
12367
12568
|
*/
|
12368
|
-
getConnector = (connector) => this._connectors.find((c) => {
|
12569
|
+
getConnector = /* @__PURE__ */ __name((connector) => this._connectors.find((c) => {
|
12369
12570
|
const connectorName = typeof connector === "string" ? connector : connector.name;
|
12370
12571
|
return c.name === connectorName || c === connector;
|
12371
|
-
}) || null;
|
12572
|
+
}) || null, "getConnector");
|
12372
12573
|
/**
|
12373
12574
|
* Return the list of connectors with the status of installed and connected.
|
12374
12575
|
*/
|
@@ -12485,9 +12686,6 @@ var _Fuel = class extends FuelConnector {
|
|
12485
12686
|
await this.clean();
|
12486
12687
|
}
|
12487
12688
|
};
|
12488
|
-
var Fuel = _Fuel;
|
12489
|
-
__publicField(Fuel, "STORAGE_KEY", "fuel-current-connector");
|
12490
|
-
__publicField(Fuel, "defaultConfig", {});
|
12491
12689
|
export {
|
12492
12690
|
AbstractAccount,
|
12493
12691
|
AbstractScriptRequest,
|
@@ -12516,6 +12714,7 @@ export {
|
|
12516
12714
|
MemoryStorage,
|
12517
12715
|
mnemonic_default as Mnemonic,
|
12518
12716
|
MnemonicVault,
|
12717
|
+
NON_PAGINATED_BALANCES_SIZE,
|
12519
12718
|
NoWitnessAtIndexError,
|
12520
12719
|
NoWitnessByOwnerError,
|
12521
12720
|
OperationName,
|
@@ -12573,6 +12772,7 @@ export {
|
|
12573
12772
|
extractTxError,
|
12574
12773
|
fuelAssetsBaseUrl,
|
12575
12774
|
gasUsedByInputs,
|
12775
|
+
getAllDecodedLogs,
|
12576
12776
|
getAssetAmountInRequestInputs,
|
12577
12777
|
getAssetById,
|
12578
12778
|
getAssetEth,
|