@fuel-ts/account 0.99.0 → 0.100.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts +9 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +7 -6
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/types/data-type.d.ts +8 -1
- package/dist/connectors/types/data-type.d.ts.map +1 -1
- package/dist/index.global.js +4164 -3454
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1125 -691
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1035 -611
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts +1 -1
- package/dist/providers/__generated__/operations.d.ts +98 -3
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +77 -11
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource-cache.d.ts +6 -4
- package/dist/providers/resource-cache.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +10 -1
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +29 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary-from-serialized.d.ts +7 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary-from-serialized.d.ts.map +1 -0
- package/dist/providers/transaction-summary/call.d.ts +8 -2
- package/dist/providers/transaction-summary/call.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/index.d.ts +1 -0
- package/dist/providers/transaction-summary/index.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/transaction-summary/receipt.d.ts +3 -2
- package/dist/providers/transaction-summary/receipt.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +5 -3
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/providers/utils/handle-gql-error-message.d.ts +0 -4
- package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -1
- package/dist/providers/utils/helpers.d.ts +14 -0
- package/dist/providers/utils/helpers.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/providers/utils/receipts.d.ts +4 -3
- package/dist/providers/utils/receipts.d.ts.map +1 -1
- package/dist/providers/utils/serialization.d.ts +35 -0
- package/dist/providers/utils/serialization.d.ts.map +1 -0
- package/dist/signer/signer.d.ts +1 -1
- package/dist/test-utils.global.js +3879 -3184
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +1002 -607
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +922 -527
- package/dist/test-utils.mjs.map +1 -1
- package/dist/utils/formatTransferToContractScriptData.d.ts +3 -3
- package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
- package/dist/utils/predicate-script-loader-instructions.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +21 -21
package/dist/index.js
CHANGED
@@ -61,6 +61,7 @@ __export(src_exports, {
|
|
61
61
|
AbstractScriptRequest: () => AbstractScriptRequest,
|
62
62
|
Account: () => Account,
|
63
63
|
AddressType: () => AddressType,
|
64
|
+
BALANCES_PAGE_SIZE_LIMIT: () => BALANCES_PAGE_SIZE_LIMIT,
|
64
65
|
BLOCKS_PAGE_SIZE_LIMIT: () => BLOCKS_PAGE_SIZE_LIMIT,
|
65
66
|
BaseTransactionRequest: () => BaseTransactionRequest,
|
66
67
|
BaseWalletUnlocked: () => BaseWalletUnlocked,
|
@@ -96,7 +97,7 @@ __export(src_exports, {
|
|
96
97
|
TRANSACTIONS_PAGE_SIZE_LIMIT: () => TRANSACTIONS_PAGE_SIZE_LIMIT,
|
97
98
|
TransactionResponse: () => TransactionResponse,
|
98
99
|
TransactionStatus: () => TransactionStatus,
|
99
|
-
TransactionType: () =>
|
100
|
+
TransactionType: () => import_transactions8.TransactionType,
|
100
101
|
TransactionTypeName: () => TransactionTypeName,
|
101
102
|
UpgradeTransactionRequest: () => UpgradeTransactionRequest,
|
102
103
|
UploadTransactionRequest: () => UploadTransactionRequest,
|
@@ -112,6 +113,7 @@ __export(src_exports, {
|
|
112
113
|
assembleReceiptByType: () => assembleReceiptByType,
|
113
114
|
assembleRevertError: () => assembleRevertError,
|
114
115
|
assembleTransactionSummary: () => assembleTransactionSummary,
|
116
|
+
assembleTransactionSummaryFromJson: () => assembleTransactionSummaryFromJson,
|
115
117
|
assets: () => assets,
|
116
118
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
117
119
|
cacheFor: () => cacheFor,
|
@@ -128,6 +130,10 @@ __export(src_exports, {
|
|
128
130
|
coinQuantityfy: () => coinQuantityfy,
|
129
131
|
deferPromise: () => deferPromise,
|
130
132
|
deployScriptOrPredicate: () => deployScriptOrPredicate,
|
133
|
+
deserializeChain: () => deserializeChain,
|
134
|
+
deserializeNodeInfo: () => deserializeNodeInfo,
|
135
|
+
deserializeProviderCache: () => deserializeProviderCache,
|
136
|
+
deserializeReceipt: () => deserializeReceipt,
|
131
137
|
dispatchFuelConnectorEvent: () => dispatchFuelConnectorEvent,
|
132
138
|
english: () => english,
|
133
139
|
extractBurnedAssetsFromReceipts: () => extractBurnedAssetsFromReceipts,
|
@@ -192,6 +198,7 @@ __export(src_exports, {
|
|
192
198
|
isInputCoin: () => isInputCoin,
|
193
199
|
isMessage: () => isMessage,
|
194
200
|
isMessageCoin: () => isMessageCoin,
|
201
|
+
isPredicate: () => isPredicate,
|
195
202
|
isRawCoin: () => isRawCoin,
|
196
203
|
isRawMessage: () => isRawMessage,
|
197
204
|
isRequestInputCoin: () => isRequestInputCoin,
|
@@ -220,6 +227,9 @@ __export(src_exports, {
|
|
220
227
|
resolveGasDependentCosts: () => resolveGasDependentCosts,
|
221
228
|
resolveIconPaths: () => resolveIconPaths,
|
222
229
|
returnZeroScript: () => returnZeroScript,
|
230
|
+
serializeChain: () => serializeChain,
|
231
|
+
serializeNodeInfo: () => serializeNodeInfo,
|
232
|
+
serializeProviderCache: () => serializeProviderCache,
|
223
233
|
transactionRequestify: () => transactionRequestify,
|
224
234
|
urlJoin: () => urlJoin,
|
225
235
|
validateTransactionForAssetBurn: () => validateTransactionForAssetBurn,
|
@@ -929,12 +939,12 @@ var getAssetsByOwner = async (opts) => {
|
|
929
939
|
};
|
930
940
|
|
931
941
|
// src/account.ts
|
932
|
-
var
|
942
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
933
943
|
var import_address5 = require("@fuel-ts/address");
|
934
944
|
var import_crypto2 = require("@fuel-ts/crypto");
|
935
|
-
var
|
936
|
-
var
|
937
|
-
var
|
945
|
+
var import_errors22 = require("@fuel-ts/errors");
|
946
|
+
var import_math21 = require("@fuel-ts/math");
|
947
|
+
var import_transactions26 = require("@fuel-ts/transactions");
|
938
948
|
var import_utils34 = require("@fuel-ts/utils");
|
939
949
|
var import_ramda9 = require("ramda");
|
940
950
|
|
@@ -954,10 +964,9 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
954
964
|
assetId = coinQuantityLike.assetId;
|
955
965
|
max = coinQuantityLike.max ?? void 0;
|
956
966
|
}
|
957
|
-
const bnAmount = (0, import_math.bn)(amount);
|
958
967
|
return {
|
959
968
|
assetId: (0, import_utils2.hexlify)(assetId),
|
960
|
-
amount:
|
969
|
+
amount: (0, import_math.bn)(amount),
|
961
970
|
max: max ? (0, import_math.bn)(max) : void 0
|
962
971
|
};
|
963
972
|
};
|
@@ -975,16 +984,34 @@ var addAmountToCoinQuantities = (params) => {
|
|
975
984
|
|
976
985
|
// src/providers/provider.ts
|
977
986
|
var import_address3 = require("@fuel-ts/address");
|
978
|
-
var
|
987
|
+
var import_errors20 = require("@fuel-ts/errors");
|
979
988
|
var import_math18 = require("@fuel-ts/math");
|
980
|
-
var
|
989
|
+
var import_transactions23 = require("@fuel-ts/transactions");
|
981
990
|
var import_utils29 = require("@fuel-ts/utils");
|
982
991
|
var import_versions = require("@fuel-ts/versions");
|
983
|
-
var import_utils30 = require("@noble/curves/abstract/utils");
|
984
992
|
var import_graphql_request = require("graphql-request");
|
985
993
|
var import_graphql_tag2 = __toESM(require("graphql-tag"));
|
986
994
|
var import_ramda8 = require("ramda");
|
987
995
|
|
996
|
+
// src/connectors/utils/promises.ts
|
997
|
+
var import_errors = require("@fuel-ts/errors");
|
998
|
+
function deferPromise() {
|
999
|
+
const defer = {};
|
1000
|
+
defer.promise = new Promise((resolve, reject) => {
|
1001
|
+
defer.reject = reject;
|
1002
|
+
defer.resolve = resolve;
|
1003
|
+
});
|
1004
|
+
return defer;
|
1005
|
+
}
|
1006
|
+
async function withTimeout(promise, timeout = 1050) {
|
1007
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
1008
|
+
setTimeout(() => {
|
1009
|
+
reject(new import_errors.FuelError(import_errors.FuelError.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
1010
|
+
}, timeout);
|
1011
|
+
});
|
1012
|
+
return Promise.race([timeoutPromise, promise]);
|
1013
|
+
}
|
1014
|
+
|
988
1015
|
// src/providers/__generated__/operations.ts
|
989
1016
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
990
1017
|
var SubmittedStatusFragmentDoc = import_graphql_tag.default`
|
@@ -1592,6 +1619,16 @@ var EstimatePredicatesDocument = import_graphql_tag.default`
|
|
1592
1619
|
}
|
1593
1620
|
}
|
1594
1621
|
${TransactionEstimatePredicatesFragmentDoc}`;
|
1622
|
+
var EstimatePredicatesAndGasPriceDocument = import_graphql_tag.default`
|
1623
|
+
query estimatePredicatesAndGasPrice($encodedTransaction: HexString!, $blockHorizon: U32!) {
|
1624
|
+
estimatePredicates(tx: $encodedTransaction) {
|
1625
|
+
...transactionEstimatePredicatesFragment
|
1626
|
+
}
|
1627
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
1628
|
+
gasPrice
|
1629
|
+
}
|
1630
|
+
}
|
1631
|
+
${TransactionEstimatePredicatesFragmentDoc}`;
|
1595
1632
|
var GetLatestBlockDocument = import_graphql_tag.default`
|
1596
1633
|
query getLatestBlock {
|
1597
1634
|
chain {
|
@@ -1707,6 +1744,13 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
1707
1744
|
}
|
1708
1745
|
}
|
1709
1746
|
`;
|
1747
|
+
var GetBalanceV2Document = import_graphql_tag.default`
|
1748
|
+
query getBalanceV2($owner: Address!, $assetId: AssetId!) {
|
1749
|
+
balance(owner: $owner, assetId: $assetId) {
|
1750
|
+
amountU128
|
1751
|
+
}
|
1752
|
+
}
|
1753
|
+
`;
|
1710
1754
|
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
1711
1755
|
query getLatestGasPrice {
|
1712
1756
|
latestGasPrice {
|
@@ -1739,6 +1783,27 @@ var GetBalancesDocument = import_graphql_tag.default`
|
|
1739
1783
|
}
|
1740
1784
|
}
|
1741
1785
|
`;
|
1786
|
+
var GetBalancesV2Document = import_graphql_tag.default`
|
1787
|
+
query getBalancesV2($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
1788
|
+
balances(
|
1789
|
+
filter: $filter
|
1790
|
+
after: $after
|
1791
|
+
before: $before
|
1792
|
+
first: $first
|
1793
|
+
last: $last
|
1794
|
+
) {
|
1795
|
+
pageInfo {
|
1796
|
+
...pageInfoFragment
|
1797
|
+
}
|
1798
|
+
edges {
|
1799
|
+
node {
|
1800
|
+
assetId
|
1801
|
+
amountU128
|
1802
|
+
}
|
1803
|
+
}
|
1804
|
+
}
|
1805
|
+
}
|
1806
|
+
${PageInfoFragmentDoc}`;
|
1742
1807
|
var GetMessagesDocument = import_graphql_tag.default`
|
1743
1808
|
query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
|
1744
1809
|
messages(
|
@@ -1793,6 +1858,15 @@ var GetRelayedTransactionStatusDocument = import_graphql_tag.default`
|
|
1793
1858
|
}
|
1794
1859
|
}
|
1795
1860
|
${RelayedTransactionStatusFragmentDoc}`;
|
1861
|
+
var GetAssetDetailsDocument = import_graphql_tag.default`
|
1862
|
+
query getAssetDetails($assetId: AssetId!) {
|
1863
|
+
assetDetails(id: $assetId) {
|
1864
|
+
subId
|
1865
|
+
contractId
|
1866
|
+
totalSupply
|
1867
|
+
}
|
1868
|
+
}
|
1869
|
+
`;
|
1796
1870
|
var DryRunDocument = import_graphql_tag.default`
|
1797
1871
|
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean, $gasPrice: U64) {
|
1798
1872
|
dryRun(
|
@@ -1893,6 +1967,9 @@ function getSdk(requester) {
|
|
1893
1967
|
estimatePredicates(variables, options) {
|
1894
1968
|
return requester(EstimatePredicatesDocument, variables, options);
|
1895
1969
|
},
|
1970
|
+
estimatePredicatesAndGasPrice(variables, options) {
|
1971
|
+
return requester(EstimatePredicatesAndGasPriceDocument, variables, options);
|
1972
|
+
},
|
1896
1973
|
getLatestBlock(variables, options) {
|
1897
1974
|
return requester(GetLatestBlockDocument, variables, options);
|
1898
1975
|
},
|
@@ -1926,6 +2003,9 @@ function getSdk(requester) {
|
|
1926
2003
|
getBalance(variables, options) {
|
1927
2004
|
return requester(GetBalanceDocument, variables, options);
|
1928
2005
|
},
|
2006
|
+
getBalanceV2(variables, options) {
|
2007
|
+
return requester(GetBalanceV2Document, variables, options);
|
2008
|
+
},
|
1929
2009
|
getLatestGasPrice(variables, options) {
|
1930
2010
|
return requester(GetLatestGasPriceDocument, variables, options);
|
1931
2011
|
},
|
@@ -1935,6 +2015,9 @@ function getSdk(requester) {
|
|
1935
2015
|
getBalances(variables, options) {
|
1936
2016
|
return requester(GetBalancesDocument, variables, options);
|
1937
2017
|
},
|
2018
|
+
getBalancesV2(variables, options) {
|
2019
|
+
return requester(GetBalancesV2Document, variables, options);
|
2020
|
+
},
|
1938
2021
|
getMessages(variables, options) {
|
1939
2022
|
return requester(GetMessagesDocument, variables, options);
|
1940
2023
|
},
|
@@ -1950,6 +2033,9 @@ function getSdk(requester) {
|
|
1950
2033
|
getRelayedTransactionStatus(variables, options) {
|
1951
2034
|
return requester(GetRelayedTransactionStatusDocument, variables, options);
|
1952
2035
|
},
|
2036
|
+
getAssetDetails(variables, options) {
|
2037
|
+
return requester(GetAssetDetailsDocument, variables, options);
|
2038
|
+
},
|
1953
2039
|
dryRun(variables, options) {
|
1954
2040
|
return requester(DryRunDocument, variables, options);
|
1955
2041
|
},
|
@@ -1978,36 +2064,35 @@ function getSdk(requester) {
|
|
1978
2064
|
}
|
1979
2065
|
|
1980
2066
|
// src/providers/fuel-graphql-subscriber.ts
|
1981
|
-
var
|
2067
|
+
var import_errors3 = require("@fuel-ts/errors");
|
1982
2068
|
var import_graphql = require("graphql");
|
1983
2069
|
|
1984
2070
|
// src/providers/utils/handle-gql-error-message.ts
|
1985
|
-
var
|
2071
|
+
var import_errors2 = require("@fuel-ts/errors");
|
1986
2072
|
var mapGqlErrorMessage = (error) => {
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
default:
|
2003
|
-
return new import_errors.FuelError(import_errors.ErrorCode.INVALID_REQUEST, error.message, {}, error);
|
2073
|
+
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)) {
|
2074
|
+
return new import_errors2.FuelError(
|
2075
|
+
import_errors2.ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
2076
|
+
`Insufficient funds or too many small value coins. Consider combining UTXOs.`,
|
2077
|
+
{},
|
2078
|
+
error
|
2079
|
+
);
|
2080
|
+
}
|
2081
|
+
if (new RegExp("resource was not found in table" /* ASSET_NOT_FOUND */).test(error.message)) {
|
2082
|
+
return new import_errors2.FuelError(
|
2083
|
+
import_errors2.ErrorCode.ASSET_NOT_FOUND,
|
2084
|
+
`Asset not found for given asset id.`,
|
2085
|
+
{},
|
2086
|
+
error
|
2087
|
+
);
|
2004
2088
|
}
|
2089
|
+
return new import_errors2.FuelError(import_errors2.ErrorCode.INVALID_REQUEST, error.message, {}, error);
|
2005
2090
|
};
|
2006
2091
|
var mapGqlErrorWithIncompatibleNodeVersion = (error, incompatibleNodeVersionMessage) => {
|
2007
2092
|
if (!incompatibleNodeVersionMessage) {
|
2008
2093
|
return error;
|
2009
2094
|
}
|
2010
|
-
return new
|
2095
|
+
return new import_errors2.FuelError(
|
2011
2096
|
error.code,
|
2012
2097
|
`${error.message}
|
2013
2098
|
|
@@ -2026,7 +2111,7 @@ var assertGqlResponseHasNoErrors = (errors, incompatibleNodeVersionMessage = fal
|
|
2026
2111
|
}
|
2027
2112
|
const errorMessage = mappedErrors.map((err) => err.message).join("\n");
|
2028
2113
|
throw mapGqlErrorWithIncompatibleNodeVersion(
|
2029
|
-
new
|
2114
|
+
new import_errors2.FuelError(import_errors2.ErrorCode.INVALID_REQUEST, errorMessage, {}, mappedErrors),
|
2030
2115
|
incompatibleNodeVersionMessage
|
2031
2116
|
);
|
2032
2117
|
};
|
@@ -2077,8 +2162,8 @@ var _FuelGraphqlSubscriber = class {
|
|
2077
2162
|
try {
|
2078
2163
|
this.events.push(JSON.parse(match.replace(/^data:/, "")));
|
2079
2164
|
} catch (e) {
|
2080
|
-
throw new
|
2081
|
-
|
2165
|
+
throw new import_errors3.FuelError(
|
2166
|
+
import_errors3.ErrorCode.STREAM_PARSING_ERROR,
|
2082
2167
|
`Error while parsing stream data response: ${text}`
|
2083
2168
|
);
|
2084
2169
|
}
|
@@ -2101,66 +2186,8 @@ __publicField(FuelGraphqlSubscriber, "incompatibleNodeVersionMessage", false);
|
|
2101
2186
|
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
2102
2187
|
|
2103
2188
|
// src/providers/resource-cache.ts
|
2104
|
-
var
|
2105
|
-
var
|
2106
|
-
var cache = /* @__PURE__ */ new Map();
|
2107
|
-
var ResourceCache = class {
|
2108
|
-
ttl;
|
2109
|
-
constructor(ttl) {
|
2110
|
-
this.ttl = ttl;
|
2111
|
-
if (typeof ttl !== "number" || this.ttl <= 0) {
|
2112
|
-
throw new import_errors3.FuelError(
|
2113
|
-
import_errors3.ErrorCode.INVALID_TTL,
|
2114
|
-
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
2115
|
-
);
|
2116
|
-
}
|
2117
|
-
}
|
2118
|
-
// Add resources to the cache
|
2119
|
-
set(transactionId, resources) {
|
2120
|
-
const currentTime = Date.now();
|
2121
|
-
const existingResources = cache.get(transactionId) || {
|
2122
|
-
utxos: /* @__PURE__ */ new Set(),
|
2123
|
-
messages: /* @__PURE__ */ new Set(),
|
2124
|
-
timestamp: currentTime
|
2125
|
-
};
|
2126
|
-
resources.utxos.forEach((utxo) => existingResources.utxos.add((0, import_utils3.hexlify)(utxo)));
|
2127
|
-
resources.messages.forEach((message) => existingResources.messages.add((0, import_utils3.hexlify)(message)));
|
2128
|
-
cache.set(transactionId, existingResources);
|
2129
|
-
}
|
2130
|
-
// Remove resources from the cache for a given transaction ID
|
2131
|
-
unset(transactionId) {
|
2132
|
-
cache.delete(transactionId);
|
2133
|
-
}
|
2134
|
-
// Get all cached resources and remove expired ones
|
2135
|
-
getActiveData() {
|
2136
|
-
const allResources = { utxos: [], messages: [] };
|
2137
|
-
const currentTime = Date.now();
|
2138
|
-
cache.forEach((resource, transactionId) => {
|
2139
|
-
if (currentTime - resource.timestamp < this.ttl) {
|
2140
|
-
allResources.utxos.push(...resource.utxos);
|
2141
|
-
allResources.messages.push(...resource.messages);
|
2142
|
-
} else {
|
2143
|
-
cache.delete(transactionId);
|
2144
|
-
}
|
2145
|
-
});
|
2146
|
-
return allResources;
|
2147
|
-
}
|
2148
|
-
// Check if a UTXO ID or message nonce is already cached and not expired
|
2149
|
-
isCached(key) {
|
2150
|
-
const currentTime = Date.now();
|
2151
|
-
for (const [transactionId, resourceData] of cache.entries()) {
|
2152
|
-
if (currentTime - resourceData.timestamp > this.ttl) {
|
2153
|
-
cache.delete(transactionId);
|
2154
|
-
} else if (resourceData.utxos.has(key) || resourceData.messages.has(key)) {
|
2155
|
-
return true;
|
2156
|
-
}
|
2157
|
-
}
|
2158
|
-
return false;
|
2159
|
-
}
|
2160
|
-
clear() {
|
2161
|
-
cache.clear();
|
2162
|
-
}
|
2163
|
-
};
|
2189
|
+
var import_errors14 = require("@fuel-ts/errors");
|
2190
|
+
var import_utils22 = require("@fuel-ts/utils");
|
2164
2191
|
|
2165
2192
|
// src/providers/transaction-request/input.ts
|
2166
2193
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
@@ -2168,30 +2195,30 @@ var import_configs = require("@fuel-ts/address/configs");
|
|
2168
2195
|
var import_errors4 = require("@fuel-ts/errors");
|
2169
2196
|
var import_math2 = require("@fuel-ts/math");
|
2170
2197
|
var import_transactions = require("@fuel-ts/transactions");
|
2171
|
-
var
|
2198
|
+
var import_utils3 = require("@fuel-ts/utils");
|
2172
2199
|
var inputify = (value) => {
|
2173
2200
|
const { type } = value;
|
2174
2201
|
switch (value.type) {
|
2175
2202
|
case import_transactions.InputType.Coin: {
|
2176
|
-
const predicate = (0,
|
2177
|
-
const predicateData = (0,
|
2203
|
+
const predicate = (0, import_utils3.arrayify)(value.predicate ?? "0x");
|
2204
|
+
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
2178
2205
|
return {
|
2179
2206
|
type: import_transactions.InputType.Coin,
|
2180
|
-
txID: (0,
|
2181
|
-
outputIndex: (0, import_math2.toNumber)((0,
|
2182
|
-
owner: (0,
|
2207
|
+
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
|
2208
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
|
2209
|
+
owner: (0, import_utils3.hexlify)(value.owner),
|
2183
2210
|
amount: (0, import_math2.bn)(value.amount),
|
2184
|
-
assetId: (0,
|
2211
|
+
assetId: (0, import_utils3.hexlify)(value.assetId),
|
2185
2212
|
txPointer: {
|
2186
|
-
blockHeight: (0, import_math2.toNumber)((0,
|
2187
|
-
txIndex: (0, import_math2.toNumber)((0,
|
2213
|
+
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
2214
|
+
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
2188
2215
|
},
|
2189
2216
|
witnessIndex: value.witnessIndex,
|
2190
2217
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
2191
2218
|
predicateLength: (0, import_math2.bn)(predicate.length),
|
2192
2219
|
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
2193
|
-
predicate: (0,
|
2194
|
-
predicateData: (0,
|
2220
|
+
predicate: (0, import_utils3.hexlify)(predicate),
|
2221
|
+
predicateData: (0, import_utils3.hexlify)(predicateData)
|
2195
2222
|
};
|
2196
2223
|
}
|
2197
2224
|
case import_transactions.InputType.Contract: {
|
@@ -2202,29 +2229,29 @@ var inputify = (value) => {
|
|
2202
2229
|
balanceRoot: import_configs.ZeroBytes32,
|
2203
2230
|
stateRoot: import_configs.ZeroBytes32,
|
2204
2231
|
txPointer: {
|
2205
|
-
blockHeight: (0, import_math2.toNumber)((0,
|
2206
|
-
txIndex: (0, import_math2.toNumber)((0,
|
2232
|
+
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
2233
|
+
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
2207
2234
|
},
|
2208
|
-
contractID: (0,
|
2235
|
+
contractID: (0, import_utils3.hexlify)(value.contractId)
|
2209
2236
|
};
|
2210
2237
|
}
|
2211
2238
|
case import_transactions.InputType.Message: {
|
2212
|
-
const predicate = (0,
|
2213
|
-
const predicateData = (0,
|
2214
|
-
const data = (0,
|
2239
|
+
const predicate = (0, import_utils3.arrayify)(value.predicate ?? "0x");
|
2240
|
+
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
2241
|
+
const data = (0, import_utils3.arrayify)(value.data ?? "0x");
|
2215
2242
|
return {
|
2216
2243
|
type: import_transactions.InputType.Message,
|
2217
|
-
sender: (0,
|
2218
|
-
recipient: (0,
|
2244
|
+
sender: (0, import_utils3.hexlify)(value.sender),
|
2245
|
+
recipient: (0, import_utils3.hexlify)(value.recipient),
|
2219
2246
|
amount: (0, import_math2.bn)(value.amount),
|
2220
|
-
nonce: (0,
|
2247
|
+
nonce: (0, import_utils3.hexlify)(value.nonce),
|
2221
2248
|
witnessIndex: value.witnessIndex,
|
2222
2249
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
2223
2250
|
predicateLength: (0, import_math2.bn)(predicate.length),
|
2224
2251
|
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
2225
|
-
predicate: (0,
|
2226
|
-
predicateData: (0,
|
2227
|
-
data: (0,
|
2252
|
+
predicate: (0, import_utils3.hexlify)(predicate),
|
2253
|
+
predicateData: (0, import_utils3.hexlify)(predicateData),
|
2254
|
+
data: (0, import_utils3.hexlify)(data),
|
2228
2255
|
dataLength: data.length
|
2229
2256
|
};
|
2230
2257
|
}
|
@@ -2242,16 +2269,16 @@ var import_configs2 = require("@fuel-ts/address/configs");
|
|
2242
2269
|
var import_errors5 = require("@fuel-ts/errors");
|
2243
2270
|
var import_math3 = require("@fuel-ts/math");
|
2244
2271
|
var import_transactions2 = require("@fuel-ts/transactions");
|
2245
|
-
var
|
2272
|
+
var import_utils4 = require("@fuel-ts/utils");
|
2246
2273
|
var outputify = (value) => {
|
2247
2274
|
const { type } = value;
|
2248
2275
|
switch (type) {
|
2249
2276
|
case import_transactions2.OutputType.Coin: {
|
2250
2277
|
return {
|
2251
2278
|
type: import_transactions2.OutputType.Coin,
|
2252
|
-
to: (0,
|
2279
|
+
to: (0, import_utils4.hexlify)(value.to),
|
2253
2280
|
amount: (0, import_math3.bn)(value.amount),
|
2254
|
-
assetId: (0,
|
2281
|
+
assetId: (0, import_utils4.hexlify)(value.assetId)
|
2255
2282
|
};
|
2256
2283
|
}
|
2257
2284
|
case import_transactions2.OutputType.Contract: {
|
@@ -2265,9 +2292,9 @@ var outputify = (value) => {
|
|
2265
2292
|
case import_transactions2.OutputType.Change: {
|
2266
2293
|
return {
|
2267
2294
|
type: import_transactions2.OutputType.Change,
|
2268
|
-
to: (0,
|
2295
|
+
to: (0, import_utils4.hexlify)(value.to),
|
2269
2296
|
amount: (0, import_math3.bn)(0),
|
2270
|
-
assetId: (0,
|
2297
|
+
assetId: (0, import_utils4.hexlify)(value.assetId)
|
2271
2298
|
};
|
2272
2299
|
}
|
2273
2300
|
case import_transactions2.OutputType.Variable: {
|
@@ -2281,8 +2308,8 @@ var outputify = (value) => {
|
|
2281
2308
|
case import_transactions2.OutputType.ContractCreated: {
|
2282
2309
|
return {
|
2283
2310
|
type: import_transactions2.OutputType.ContractCreated,
|
2284
|
-
contractId: (0,
|
2285
|
-
stateRoot: (0,
|
2311
|
+
contractId: (0, import_utils4.hexlify)(value.contractId),
|
2312
|
+
stateRoot: (0, import_utils4.hexlify)(value.stateRoot)
|
2286
2313
|
};
|
2287
2314
|
}
|
2288
2315
|
default: {
|
@@ -2301,7 +2328,7 @@ var import_configs6 = require("@fuel-ts/address/configs");
|
|
2301
2328
|
var import_crypto = require("@fuel-ts/crypto");
|
2302
2329
|
var import_errors10 = require("@fuel-ts/errors");
|
2303
2330
|
var import_math8 = require("@fuel-ts/math");
|
2304
|
-
var
|
2331
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2305
2332
|
var import_utils10 = require("@fuel-ts/utils");
|
2306
2333
|
|
2307
2334
|
// src/providers/message.ts
|
@@ -2314,31 +2341,157 @@ var isCoin = (resource) => "id" in resource;
|
|
2314
2341
|
var isMessage = (resource) => "recipient" in resource;
|
2315
2342
|
|
2316
2343
|
// src/providers/utils/receipts.ts
|
2344
|
+
var import_transactions4 = require("@fuel-ts/transactions");
|
2345
|
+
var import_configs4 = require("@fuel-ts/transactions/configs");
|
2346
|
+
|
2347
|
+
// src/providers/utils/serialization.ts
|
2317
2348
|
var import_configs3 = require("@fuel-ts/address/configs");
|
2318
2349
|
var import_errors6 = require("@fuel-ts/errors");
|
2319
2350
|
var import_math4 = require("@fuel-ts/math");
|
2320
2351
|
var import_transactions3 = require("@fuel-ts/transactions");
|
2321
|
-
var
|
2322
|
-
var
|
2323
|
-
|
2324
|
-
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2328
|
-
|
2352
|
+
var import_utils5 = require("@fuel-ts/utils");
|
2353
|
+
var deserializeChain = (chain) => {
|
2354
|
+
const { name, daHeight, consensusParameters } = chain;
|
2355
|
+
const {
|
2356
|
+
contractParams,
|
2357
|
+
feeParams,
|
2358
|
+
predicateParams,
|
2359
|
+
scriptParams,
|
2360
|
+
txParams,
|
2361
|
+
gasCosts,
|
2362
|
+
baseAssetId,
|
2363
|
+
chainId,
|
2364
|
+
version
|
2365
|
+
} = consensusParameters;
|
2366
|
+
return {
|
2367
|
+
name,
|
2368
|
+
baseChainHeight: (0, import_math4.bn)(daHeight),
|
2369
|
+
consensusParameters: {
|
2370
|
+
version,
|
2371
|
+
chainId: (0, import_math4.bn)(chainId),
|
2372
|
+
baseAssetId,
|
2373
|
+
feeParameters: {
|
2374
|
+
version: feeParams.version,
|
2375
|
+
gasPerByte: (0, import_math4.bn)(feeParams.gasPerByte),
|
2376
|
+
gasPriceFactor: (0, import_math4.bn)(feeParams.gasPriceFactor)
|
2377
|
+
},
|
2378
|
+
contractParameters: {
|
2379
|
+
version: contractParams.version,
|
2380
|
+
contractMaxSize: (0, import_math4.bn)(contractParams.contractMaxSize),
|
2381
|
+
maxStorageSlots: (0, import_math4.bn)(contractParams.maxStorageSlots)
|
2382
|
+
},
|
2383
|
+
txParameters: {
|
2384
|
+
version: txParams.version,
|
2385
|
+
maxInputs: (0, import_math4.bn)(txParams.maxInputs),
|
2386
|
+
maxOutputs: (0, import_math4.bn)(txParams.maxOutputs),
|
2387
|
+
maxWitnesses: (0, import_math4.bn)(txParams.maxWitnesses),
|
2388
|
+
maxGasPerTx: (0, import_math4.bn)(txParams.maxGasPerTx),
|
2389
|
+
maxSize: (0, import_math4.bn)(txParams.maxSize),
|
2390
|
+
maxBytecodeSubsections: (0, import_math4.bn)(txParams.maxBytecodeSubsections)
|
2391
|
+
},
|
2392
|
+
predicateParameters: {
|
2393
|
+
version: predicateParams.version,
|
2394
|
+
maxPredicateLength: (0, import_math4.bn)(predicateParams.maxPredicateLength),
|
2395
|
+
maxPredicateDataLength: (0, import_math4.bn)(predicateParams.maxPredicateDataLength),
|
2396
|
+
maxGasPerPredicate: (0, import_math4.bn)(predicateParams.maxGasPerPredicate),
|
2397
|
+
maxMessageDataLength: (0, import_math4.bn)(predicateParams.maxMessageDataLength)
|
2398
|
+
},
|
2399
|
+
scriptParameters: {
|
2400
|
+
version: scriptParams.version,
|
2401
|
+
maxScriptLength: (0, import_math4.bn)(scriptParams.maxScriptLength),
|
2402
|
+
maxScriptDataLength: (0, import_math4.bn)(scriptParams.maxScriptDataLength)
|
2403
|
+
},
|
2404
|
+
gasCosts
|
2329
2405
|
}
|
2330
|
-
|
2331
|
-
|
2406
|
+
};
|
2407
|
+
};
|
2408
|
+
var serializeChain = (chain) => {
|
2409
|
+
const { name, baseChainHeight, consensusParameters } = chain;
|
2410
|
+
const {
|
2411
|
+
contractParameters,
|
2412
|
+
feeParameters,
|
2413
|
+
predicateParameters,
|
2414
|
+
scriptParameters,
|
2415
|
+
txParameters,
|
2416
|
+
gasCosts,
|
2417
|
+
baseAssetId,
|
2418
|
+
chainId,
|
2419
|
+
version
|
2420
|
+
} = consensusParameters;
|
2421
|
+
return {
|
2422
|
+
name,
|
2423
|
+
daHeight: baseChainHeight.toString(),
|
2424
|
+
consensusParameters: {
|
2425
|
+
version,
|
2426
|
+
chainId: chainId.toString(),
|
2427
|
+
baseAssetId,
|
2428
|
+
feeParams: {
|
2429
|
+
version: feeParameters.version,
|
2430
|
+
gasPerByte: feeParameters.gasPerByte.toString(),
|
2431
|
+
gasPriceFactor: feeParameters.gasPriceFactor.toString()
|
2432
|
+
},
|
2433
|
+
contractParams: {
|
2434
|
+
version: contractParameters.version,
|
2435
|
+
contractMaxSize: contractParameters.contractMaxSize.toString(),
|
2436
|
+
maxStorageSlots: contractParameters.maxStorageSlots.toString()
|
2437
|
+
},
|
2438
|
+
txParams: {
|
2439
|
+
version: txParameters.version,
|
2440
|
+
maxInputs: txParameters.maxInputs.toString(),
|
2441
|
+
maxOutputs: txParameters.maxOutputs.toString(),
|
2442
|
+
maxWitnesses: txParameters.maxWitnesses.toString(),
|
2443
|
+
maxGasPerTx: txParameters.maxGasPerTx.toString(),
|
2444
|
+
maxSize: txParameters.maxSize.toString(),
|
2445
|
+
maxBytecodeSubsections: txParameters.maxBytecodeSubsections.toString()
|
2446
|
+
},
|
2447
|
+
predicateParams: {
|
2448
|
+
version: predicateParameters.version,
|
2449
|
+
maxPredicateLength: predicateParameters.maxPredicateLength.toString(),
|
2450
|
+
maxPredicateDataLength: predicateParameters.maxPredicateDataLength.toString(),
|
2451
|
+
maxGasPerPredicate: predicateParameters.maxGasPerPredicate.toString(),
|
2452
|
+
maxMessageDataLength: predicateParameters.maxMessageDataLength.toString()
|
2453
|
+
},
|
2454
|
+
scriptParams: {
|
2455
|
+
version: scriptParameters.version,
|
2456
|
+
maxScriptLength: scriptParameters.maxScriptLength.toString(),
|
2457
|
+
maxScriptDataLength: scriptParameters.maxScriptDataLength.toString()
|
2458
|
+
},
|
2459
|
+
gasCosts
|
2332
2460
|
}
|
2333
|
-
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
2339
|
-
)
|
2461
|
+
};
|
2462
|
+
};
|
2463
|
+
var deserializeNodeInfo = (nodeInfo) => {
|
2464
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
2465
|
+
return {
|
2466
|
+
maxDepth: (0, import_math4.bn)(maxDepth),
|
2467
|
+
maxTx: (0, import_math4.bn)(maxTx),
|
2468
|
+
nodeVersion,
|
2469
|
+
utxoValidation,
|
2470
|
+
vmBacktrace
|
2471
|
+
};
|
2472
|
+
};
|
2473
|
+
var serializeNodeInfo = (nodeInfo) => {
|
2474
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
2475
|
+
return {
|
2476
|
+
maxDepth: maxDepth.toString(),
|
2477
|
+
maxTx: maxTx.toString(),
|
2478
|
+
nodeVersion,
|
2479
|
+
utxoValidation,
|
2480
|
+
vmBacktrace
|
2481
|
+
};
|
2482
|
+
};
|
2483
|
+
var deserializeProviderCache = (cache2) => ({
|
2484
|
+
consensusParametersTimestamp: cache2.consensusParametersTimestamp,
|
2485
|
+
chain: deserializeChain(cache2.chain),
|
2486
|
+
nodeInfo: deserializeNodeInfo(cache2.nodeInfo)
|
2487
|
+
});
|
2488
|
+
var serializeProviderCache = async (provider) => ({
|
2489
|
+
consensusParametersTimestamp: provider.consensusParametersTimestamp,
|
2490
|
+
chain: serializeChain(await provider.getChain()),
|
2491
|
+
nodeInfo: serializeNodeInfo(await provider.getNode())
|
2492
|
+
});
|
2340
2493
|
var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
|
2341
|
-
|
2494
|
+
var deserializeReceipt = (receipt) => {
|
2342
2495
|
const { receiptType } = receipt;
|
2343
2496
|
switch (receiptType) {
|
2344
2497
|
case "CALL" /* Call */: {
|
@@ -2474,7 +2627,7 @@ function assembleReceiptByType(receipt) {
|
|
2474
2627
|
const recipient = hexOrZero(receipt.recipient);
|
2475
2628
|
const nonce = hexOrZero(receipt.nonce);
|
2476
2629
|
const amount = (0, import_math4.bn)(receipt.amount);
|
2477
|
-
const data = receipt.data ? (0,
|
2630
|
+
const data = receipt.data ? (0, import_utils5.arrayify)(receipt.data) : Uint8Array.from([]);
|
2478
2631
|
const digest = hexOrZero(receipt.digest);
|
2479
2632
|
const len = (0, import_math4.bn)(receipt.len).toNumber();
|
2480
2633
|
const messageId = import_transactions3.InputMessageCoder.getMessageId({
|
@@ -2482,7 +2635,7 @@ function assembleReceiptByType(receipt) {
|
|
2482
2635
|
recipient,
|
2483
2636
|
nonce,
|
2484
2637
|
amount,
|
2485
|
-
data: (0,
|
2638
|
+
data: (0, import_utils5.hexlify)(data)
|
2486
2639
|
});
|
2487
2640
|
const receiptMessageOut = {
|
2488
2641
|
type: import_transactions3.ReceiptType.MessageOut,
|
@@ -2530,7 +2683,27 @@ function assembleReceiptByType(receipt) {
|
|
2530
2683
|
default:
|
2531
2684
|
throw new import_errors6.FuelError(import_errors6.ErrorCode.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
2532
2685
|
}
|
2533
|
-
}
|
2686
|
+
};
|
2687
|
+
|
2688
|
+
// src/providers/utils/receipts.ts
|
2689
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions4.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
2690
|
+
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions4.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
2691
|
+
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
2692
|
+
(memo, receipt) => {
|
2693
|
+
if (doesReceiptHaveMissingOutputVariables(receipt)) {
|
2694
|
+
memo.missingOutputVariables.push(receipt);
|
2695
|
+
}
|
2696
|
+
if (doesReceiptHaveMissingContractId(receipt)) {
|
2697
|
+
memo.missingOutputContractIds.push(receipt);
|
2698
|
+
}
|
2699
|
+
return memo;
|
2700
|
+
},
|
2701
|
+
{
|
2702
|
+
missingOutputVariables: [],
|
2703
|
+
missingOutputContractIds: []
|
2704
|
+
}
|
2705
|
+
);
|
2706
|
+
var assembleReceiptByType = (gqlReceipt) => deserializeReceipt(gqlReceipt);
|
2534
2707
|
|
2535
2708
|
// src/providers/utils/block-explorer.ts
|
2536
2709
|
var import_errors7 = require("@fuel-ts/errors");
|
@@ -2596,11 +2769,11 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
2596
2769
|
|
2597
2770
|
// src/providers/utils/gas.ts
|
2598
2771
|
var import_math5 = require("@fuel-ts/math");
|
2599
|
-
var
|
2600
|
-
var
|
2772
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
2773
|
+
var import_utils6 = require("@fuel-ts/utils");
|
2601
2774
|
var getGasUsedFromReceipts = (receipts) => {
|
2602
2775
|
const scriptResult = receipts.filter(
|
2603
|
-
(receipt) => receipt.type ===
|
2776
|
+
(receipt) => receipt.type === import_transactions5.ReceiptType.ScriptResult
|
2604
2777
|
);
|
2605
2778
|
const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), (0, import_math5.bn)(0));
|
2606
2779
|
return gasUsed;
|
@@ -2634,7 +2807,7 @@ function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
|
2634
2807
|
const totalGas = chargeableInputs.reduce((total, input) => {
|
2635
2808
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
2636
2809
|
return total.add(
|
2637
|
-
vmInitializationCost.add(resolveGasDependentCosts((0,
|
2810
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
2638
2811
|
);
|
2639
2812
|
}
|
2640
2813
|
return total.add(gasCosts.ecr1);
|
@@ -2733,13 +2906,13 @@ var calculateGasFee = (params) => {
|
|
2733
2906
|
};
|
2734
2907
|
|
2735
2908
|
// src/providers/utils/json.ts
|
2736
|
-
var
|
2909
|
+
var import_utils7 = require("@fuel-ts/utils");
|
2737
2910
|
var import_ramda = require("ramda");
|
2738
2911
|
function normalize(object) {
|
2739
2912
|
Object.keys(object).forEach((key) => {
|
2740
2913
|
switch (object[key]?.constructor.name) {
|
2741
2914
|
case "Uint8Array":
|
2742
|
-
object[key] = (0,
|
2915
|
+
object[key] = (0, import_utils7.hexlify)(object[key]);
|
2743
2916
|
break;
|
2744
2917
|
case "Array":
|
2745
2918
|
object[key] = normalize(object[key]);
|
@@ -2766,7 +2939,7 @@ function normalizeJSON(root) {
|
|
2766
2939
|
// src/providers/utils/extract-tx-error.ts
|
2767
2940
|
var import_errors8 = require("@fuel-ts/errors");
|
2768
2941
|
var import_math6 = require("@fuel-ts/math");
|
2769
|
-
var
|
2942
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
2770
2943
|
var import_configs5 = require("@fuel-ts/transactions/configs");
|
2771
2944
|
var assemblePanicError = (statusReason, metadata) => {
|
2772
2945
|
let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
|
@@ -2785,7 +2958,7 @@ ${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
|
|
2785
2958
|
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
2786
2959
|
var assembleRevertError = (receipts, logs, metadata) => {
|
2787
2960
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
2788
|
-
const revertReceipt = receipts.find(({ type }) => type ===
|
2961
|
+
const revertReceipt = receipts.find(({ type }) => type === import_transactions6.ReceiptType.Revert);
|
2789
2962
|
let reason = "";
|
2790
2963
|
if (revertReceipt) {
|
2791
2964
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
@@ -2798,15 +2971,15 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2798
2971
|
break;
|
2799
2972
|
}
|
2800
2973
|
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
2801
|
-
const
|
2974
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
2802
2975
|
reason = "assert_eq";
|
2803
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${
|
2976
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
2804
2977
|
break;
|
2805
2978
|
}
|
2806
2979
|
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
2807
|
-
const
|
2980
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2808
2981
|
reason = "assert_ne";
|
2809
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${
|
2982
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
2810
2983
|
break;
|
2811
2984
|
}
|
2812
2985
|
case import_configs5.FAILED_ASSERT_SIGNAL:
|
@@ -2814,8 +2987,8 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2814
2987
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
2815
2988
|
break;
|
2816
2989
|
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
2817
|
-
reason = "
|
2818
|
-
errorMessage = `The transaction reverted because it's missing an "
|
2990
|
+
reason = "MissingOutputVariable";
|
2991
|
+
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
2819
2992
|
break;
|
2820
2993
|
default:
|
2821
2994
|
throw new import_errors8.FuelError(
|
@@ -2835,8 +3008,8 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2835
3008
|
};
|
2836
3009
|
var extractTxError = (params) => {
|
2837
3010
|
const { receipts, statusReason, logs } = params;
|
2838
|
-
const isPanic = receipts.some(({ type }) => type ===
|
2839
|
-
const isRevert = receipts.some(({ type }) => type ===
|
3011
|
+
const isPanic = receipts.some(({ type }) => type === import_transactions6.ReceiptType.Panic);
|
3012
|
+
const isRevert = receipts.some(({ type }) => type === import_transactions6.ReceiptType.Revert);
|
2840
3013
|
const metadata = {
|
2841
3014
|
logs,
|
2842
3015
|
receipts,
|
@@ -2875,14 +3048,16 @@ var NoWitnessByOwnerError = class extends Error {
|
|
2875
3048
|
// src/providers/transaction-request/helpers.ts
|
2876
3049
|
var import_errors9 = require("@fuel-ts/errors");
|
2877
3050
|
var import_math7 = require("@fuel-ts/math");
|
2878
|
-
var
|
2879
|
-
var
|
2880
|
-
var
|
2881
|
-
var
|
3051
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
3052
|
+
var import_utils8 = require("@fuel-ts/utils");
|
3053
|
+
var isRequestInputCoin = (input) => input.type === import_transactions7.InputType.Coin;
|
3054
|
+
var isRequestInputMessage = (input) => input.type === import_transactions7.InputType.Message;
|
3055
|
+
var isRequestInputMessageWithoutData = (input) => input.type === import_transactions7.InputType.Message && (0, import_math7.bn)(input.data).isZero();
|
2882
3056
|
var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
2883
3057
|
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2884
3058
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2885
3059
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
3060
|
+
var isPredicate = (input) => isRequestInputCoinOrMessage(input) && !!input.predicate && (0, import_utils8.hexlify)(input.predicate) !== "0x";
|
2886
3061
|
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
2887
3062
|
if (isRequestInputCoin(input) && input.assetId === assetId) {
|
2888
3063
|
return acc.add(input.amount);
|
@@ -2927,7 +3102,7 @@ var getBurnableAssetCount = (baseAssetId, transactionRequest) => {
|
|
2927
3102
|
coinInputs.add(baseAssetId);
|
2928
3103
|
}
|
2929
3104
|
const changeOutputs = new Set(
|
2930
|
-
outputs.filter((output) => output.type ===
|
3105
|
+
outputs.filter((output) => output.type === import_transactions7.OutputType.Change).map((output) => output.assetId)
|
2931
3106
|
);
|
2932
3107
|
const difference = new Set([...coinInputs].filter((x) => !changeOutputs.has(x)));
|
2933
3108
|
return difference.size;
|
@@ -2963,6 +3138,8 @@ var BaseTransactionRequest = class {
|
|
2963
3138
|
tip;
|
2964
3139
|
/** Block until which tx cannot be included */
|
2965
3140
|
maturity;
|
3141
|
+
/** The block number after which the transaction is no longer valid. */
|
3142
|
+
expiration;
|
2966
3143
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
2967
3144
|
maxFee;
|
2968
3145
|
/** The maximum amount of witness data allowed for the transaction */
|
@@ -2973,6 +3150,12 @@ var BaseTransactionRequest = class {
|
|
2973
3150
|
outputs = [];
|
2974
3151
|
/** List of witnesses */
|
2975
3152
|
witnesses = [];
|
3153
|
+
/**
|
3154
|
+
* @hidden
|
3155
|
+
*
|
3156
|
+
* The current status of the transaction
|
3157
|
+
*/
|
3158
|
+
flag = { state: void 0, transactionId: void 0, summary: void 0 };
|
2976
3159
|
/**
|
2977
3160
|
* Constructor for initializing a base transaction request.
|
2978
3161
|
*
|
@@ -2981,6 +3164,7 @@ var BaseTransactionRequest = class {
|
|
2981
3164
|
constructor({
|
2982
3165
|
tip,
|
2983
3166
|
maturity,
|
3167
|
+
expiration,
|
2984
3168
|
maxFee,
|
2985
3169
|
witnessLimit,
|
2986
3170
|
inputs,
|
@@ -2989,6 +3173,7 @@ var BaseTransactionRequest = class {
|
|
2989
3173
|
} = {}) {
|
2990
3174
|
this.tip = tip ? (0, import_math8.bn)(tip) : void 0;
|
2991
3175
|
this.maturity = maturity && maturity > 0 ? maturity : void 0;
|
3176
|
+
this.expiration = expiration && expiration > 0 ? expiration : void 0;
|
2992
3177
|
this.witnessLimit = (0, import_utils10.isDefined)(witnessLimit) ? (0, import_math8.bn)(witnessLimit) : void 0;
|
2993
3178
|
this.maxFee = (0, import_math8.bn)(maxFee);
|
2994
3179
|
this.inputs = inputs ?? [];
|
@@ -2998,21 +3183,25 @@ var BaseTransactionRequest = class {
|
|
2998
3183
|
static getPolicyMeta(req) {
|
2999
3184
|
let policyTypes = 0;
|
3000
3185
|
const policies = [];
|
3001
|
-
const { tip, witnessLimit, maturity } = req;
|
3186
|
+
const { tip, witnessLimit, maturity, expiration } = req;
|
3002
3187
|
if ((0, import_math8.bn)(tip).gt(0)) {
|
3003
|
-
policyTypes +=
|
3004
|
-
policies.push({ data: (0, import_math8.bn)(tip), type:
|
3188
|
+
policyTypes += import_transactions8.PolicyType.Tip;
|
3189
|
+
policies.push({ data: (0, import_math8.bn)(tip), type: import_transactions8.PolicyType.Tip });
|
3005
3190
|
}
|
3006
3191
|
if ((0, import_utils10.isDefined)(witnessLimit) && (0, import_math8.bn)(witnessLimit).gte(0)) {
|
3007
|
-
policyTypes +=
|
3008
|
-
policies.push({ data: (0, import_math8.bn)(witnessLimit), type:
|
3192
|
+
policyTypes += import_transactions8.PolicyType.WitnessLimit;
|
3193
|
+
policies.push({ data: (0, import_math8.bn)(witnessLimit), type: import_transactions8.PolicyType.WitnessLimit });
|
3009
3194
|
}
|
3010
3195
|
if (maturity && maturity > 0) {
|
3011
|
-
policyTypes +=
|
3012
|
-
policies.push({ data: maturity, type:
|
3196
|
+
policyTypes += import_transactions8.PolicyType.Maturity;
|
3197
|
+
policies.push({ data: maturity, type: import_transactions8.PolicyType.Maturity });
|
3198
|
+
}
|
3199
|
+
policyTypes += import_transactions8.PolicyType.MaxFee;
|
3200
|
+
policies.push({ data: req.maxFee, type: import_transactions8.PolicyType.MaxFee });
|
3201
|
+
if (expiration && expiration > 0) {
|
3202
|
+
policyTypes += import_transactions8.PolicyType.Expiration;
|
3203
|
+
policies.push({ data: expiration, type: import_transactions8.PolicyType.Expiration });
|
3013
3204
|
}
|
3014
|
-
policyTypes += import_transactions7.PolicyType.MaxFee;
|
3015
|
-
policies.push({ data: req.maxFee, type: import_transactions7.PolicyType.MaxFee });
|
3016
3205
|
return {
|
3017
3206
|
policyTypes,
|
3018
3207
|
policies
|
@@ -3045,7 +3234,7 @@ var BaseTransactionRequest = class {
|
|
3045
3234
|
* @returns The transaction bytes.
|
3046
3235
|
*/
|
3047
3236
|
toTransactionBytes() {
|
3048
|
-
return new
|
3237
|
+
return new import_transactions8.TransactionCoder().encode(this.toTransaction());
|
3049
3238
|
}
|
3050
3239
|
/**
|
3051
3240
|
* @hidden
|
@@ -3085,8 +3274,7 @@ var BaseTransactionRequest = class {
|
|
3085
3274
|
* @returns The index of the created witness.
|
3086
3275
|
*/
|
3087
3276
|
addEmptyWitness() {
|
3088
|
-
this.addWitness((0, import_utils10.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
3089
|
-
return this.witnesses.length - 1;
|
3277
|
+
return this.addWitness((0, import_utils10.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
3090
3278
|
}
|
3091
3279
|
/**
|
3092
3280
|
* Updates the witness for a given owner and signature.
|
@@ -3136,7 +3324,7 @@ var BaseTransactionRequest = class {
|
|
3136
3324
|
*/
|
3137
3325
|
getCoinInputs() {
|
3138
3326
|
return this.inputs.filter(
|
3139
|
-
(input) => input.type ===
|
3327
|
+
(input) => input.type === import_transactions8.InputType.Coin
|
3140
3328
|
);
|
3141
3329
|
}
|
3142
3330
|
/**
|
@@ -3146,7 +3334,7 @@ var BaseTransactionRequest = class {
|
|
3146
3334
|
*/
|
3147
3335
|
getCoinOutputs() {
|
3148
3336
|
return this.outputs.filter(
|
3149
|
-
(output) => output.type ===
|
3337
|
+
(output) => output.type === import_transactions8.OutputType.Coin
|
3150
3338
|
);
|
3151
3339
|
}
|
3152
3340
|
/**
|
@@ -3156,7 +3344,7 @@ var BaseTransactionRequest = class {
|
|
3156
3344
|
*/
|
3157
3345
|
getChangeOutputs() {
|
3158
3346
|
return this.outputs.filter(
|
3159
|
-
(output) => output.type ===
|
3347
|
+
(output) => output.type === import_transactions8.OutputType.Change
|
3160
3348
|
);
|
3161
3349
|
}
|
3162
3350
|
/**
|
@@ -3168,9 +3356,9 @@ var BaseTransactionRequest = class {
|
|
3168
3356
|
const ownerAddress = (0, import_address.addressify)(owner);
|
3169
3357
|
const found = this.inputs.find((input) => {
|
3170
3358
|
switch (input.type) {
|
3171
|
-
case
|
3359
|
+
case import_transactions8.InputType.Coin:
|
3172
3360
|
return (0, import_utils10.hexlify)(input.owner) === ownerAddress.toB256();
|
3173
|
-
case
|
3361
|
+
case import_transactions8.InputType.Message:
|
3174
3362
|
return (0, import_utils10.hexlify)(input.recipient) === ownerAddress.toB256();
|
3175
3363
|
default:
|
3176
3364
|
return false;
|
@@ -3197,7 +3385,7 @@ var BaseTransactionRequest = class {
|
|
3197
3385
|
}
|
3198
3386
|
const input = {
|
3199
3387
|
id,
|
3200
|
-
type:
|
3388
|
+
type: import_transactions8.InputType.Coin,
|
3201
3389
|
owner: owner.toB256(),
|
3202
3390
|
amount,
|
3203
3391
|
assetId,
|
@@ -3228,7 +3416,7 @@ var BaseTransactionRequest = class {
|
|
3228
3416
|
}
|
3229
3417
|
const input = {
|
3230
3418
|
nonce,
|
3231
|
-
type:
|
3419
|
+
type: import_transactions8.InputType.Message,
|
3232
3420
|
sender: sender.toB256(),
|
3233
3421
|
recipient: recipient.toB256(),
|
3234
3422
|
data: isMessageCoin(message) ? "0x" : message.data,
|
@@ -3277,7 +3465,7 @@ var BaseTransactionRequest = class {
|
|
3277
3465
|
*/
|
3278
3466
|
addCoinOutput(to, amount, assetId) {
|
3279
3467
|
this.pushOutput({
|
3280
|
-
type:
|
3468
|
+
type: import_transactions8.OutputType.Coin,
|
3281
3469
|
to: (0, import_address.addressify)(to).toB256(),
|
3282
3470
|
amount,
|
3283
3471
|
assetId
|
@@ -3293,7 +3481,7 @@ var BaseTransactionRequest = class {
|
|
3293
3481
|
addCoinOutputs(to, quantities) {
|
3294
3482
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
3295
3483
|
this.pushOutput({
|
3296
|
-
type:
|
3484
|
+
type: import_transactions8.OutputType.Coin,
|
3297
3485
|
to: (0, import_address.addressify)(to).toB256(),
|
3298
3486
|
amount: quantity.amount,
|
3299
3487
|
assetId: quantity.assetId
|
@@ -3313,7 +3501,7 @@ var BaseTransactionRequest = class {
|
|
3313
3501
|
);
|
3314
3502
|
if (!changeOutput) {
|
3315
3503
|
this.pushOutput({
|
3316
|
-
type:
|
3504
|
+
type: import_transactions8.OutputType.Change,
|
3317
3505
|
to: (0, import_address.addressify)(to).toB256(),
|
3318
3506
|
assetId
|
3319
3507
|
});
|
@@ -3456,6 +3644,21 @@ var BaseTransactionRequest = class {
|
|
3456
3644
|
byteLength() {
|
3457
3645
|
return this.toTransactionBytes().byteLength;
|
3458
3646
|
}
|
3647
|
+
/**
|
3648
|
+
* @hidden
|
3649
|
+
*
|
3650
|
+
* Used internally to update the state of a transaction request.
|
3651
|
+
*
|
3652
|
+
* @param state - The state to update.
|
3653
|
+
*/
|
3654
|
+
updateState(chainId, state, summary) {
|
3655
|
+
if (!state) {
|
3656
|
+
this.flag = { state: void 0, transactionId: void 0, summary: void 0 };
|
3657
|
+
return;
|
3658
|
+
}
|
3659
|
+
const transactionId = this.getTransactionId(chainId);
|
3660
|
+
this.flag = { state, transactionId, summary };
|
3661
|
+
}
|
3459
3662
|
};
|
3460
3663
|
|
3461
3664
|
// src/providers/transaction-request/blob-transaction-request.ts
|
@@ -3465,18 +3668,18 @@ var import_ramda3 = require("ramda");
|
|
3465
3668
|
var import_configs7 = require("@fuel-ts/address/configs");
|
3466
3669
|
var import_hasher = require("@fuel-ts/hasher");
|
3467
3670
|
var import_math9 = require("@fuel-ts/math");
|
3468
|
-
var
|
3671
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
3469
3672
|
var import_utils12 = require("@fuel-ts/utils");
|
3470
3673
|
var import_ramda2 = require("ramda");
|
3471
3674
|
function hashTransaction(transactionRequest, chainId) {
|
3472
3675
|
const transaction = transactionRequest.toTransaction();
|
3473
|
-
if (transaction.type ===
|
3676
|
+
if (transaction.type === import_transactions9.TransactionType.Script) {
|
3474
3677
|
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
3475
3678
|
}
|
3476
3679
|
transaction.inputs = transaction.inputs.map((input) => {
|
3477
3680
|
const inputClone = (0, import_ramda2.clone)(input);
|
3478
3681
|
switch (inputClone.type) {
|
3479
|
-
case
|
3682
|
+
case import_transactions9.InputType.Coin: {
|
3480
3683
|
inputClone.txPointer = {
|
3481
3684
|
blockHeight: 0,
|
3482
3685
|
txIndex: 0
|
@@ -3484,11 +3687,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3484
3687
|
inputClone.predicateGasUsed = (0, import_math9.bn)(0);
|
3485
3688
|
return inputClone;
|
3486
3689
|
}
|
3487
|
-
case
|
3690
|
+
case import_transactions9.InputType.Message: {
|
3488
3691
|
inputClone.predicateGasUsed = (0, import_math9.bn)(0);
|
3489
3692
|
return inputClone;
|
3490
3693
|
}
|
3491
|
-
case
|
3694
|
+
case import_transactions9.InputType.Contract: {
|
3492
3695
|
inputClone.txPointer = {
|
3493
3696
|
blockHeight: 0,
|
3494
3697
|
txIndex: 0
|
@@ -3506,16 +3709,16 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3506
3709
|
transaction.outputs = transaction.outputs.map((output) => {
|
3507
3710
|
const outputClone = (0, import_ramda2.clone)(output);
|
3508
3711
|
switch (outputClone.type) {
|
3509
|
-
case
|
3712
|
+
case import_transactions9.OutputType.Contract: {
|
3510
3713
|
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
3511
3714
|
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
3512
3715
|
return outputClone;
|
3513
3716
|
}
|
3514
|
-
case
|
3717
|
+
case import_transactions9.OutputType.Change: {
|
3515
3718
|
outputClone.amount = (0, import_math9.bn)(0);
|
3516
3719
|
return outputClone;
|
3517
3720
|
}
|
3518
|
-
case
|
3721
|
+
case import_transactions9.OutputType.Variable: {
|
3519
3722
|
outputClone.to = import_configs7.ZeroBytes32;
|
3520
3723
|
outputClone.amount = (0, import_math9.bn)(0);
|
3521
3724
|
outputClone.assetId = import_configs7.ZeroBytes32;
|
@@ -3528,7 +3731,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
3528
3731
|
transaction.witnessesCount = 0;
|
3529
3732
|
transaction.witnesses = [];
|
3530
3733
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
3531
|
-
const concatenatedData = (0, import_utils12.concat)([chainIdBytes, new
|
3734
|
+
const concatenatedData = (0, import_utils12.concat)([chainIdBytes, new import_transactions9.TransactionCoder().encode(transaction)]);
|
3532
3735
|
return (0, import_hasher.sha256)(concatenatedData);
|
3533
3736
|
}
|
3534
3737
|
|
@@ -3538,7 +3741,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
3538
3741
|
return new this((0, import_ramda3.clone)(obj));
|
3539
3742
|
}
|
3540
3743
|
/** Type of the transaction */
|
3541
|
-
type =
|
3744
|
+
type = import_transactions8.TransactionType.Blob;
|
3542
3745
|
/** Blob ID */
|
3543
3746
|
blobId;
|
3544
3747
|
/** Witness index of the bytecode to create */
|
@@ -3562,7 +3765,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
3562
3765
|
const baseTransaction = this.getBaseTransaction();
|
3563
3766
|
const { witnessIndex, blobId } = this;
|
3564
3767
|
return {
|
3565
|
-
type:
|
3768
|
+
type: import_transactions8.TransactionType.Blob,
|
3566
3769
|
...baseTransaction,
|
3567
3770
|
blobId,
|
3568
3771
|
witnessIndex
|
@@ -3596,7 +3799,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
3596
3799
|
// src/providers/transaction-request/create-transaction-request.ts
|
3597
3800
|
var import_configs8 = require("@fuel-ts/address/configs");
|
3598
3801
|
var import_math10 = require("@fuel-ts/math");
|
3599
|
-
var
|
3802
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
3600
3803
|
var import_utils15 = require("@fuel-ts/utils");
|
3601
3804
|
var import_ramda4 = require("ramda");
|
3602
3805
|
|
@@ -3629,7 +3832,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
3629
3832
|
return new this((0, import_ramda4.clone)(obj));
|
3630
3833
|
}
|
3631
3834
|
/** Type of the transaction */
|
3632
|
-
type =
|
3835
|
+
type = import_transactions10.TransactionType.Create;
|
3633
3836
|
/** Witness index of contract bytecode to create */
|
3634
3837
|
bytecodeWitnessIndex;
|
3635
3838
|
/** Salt */
|
@@ -3657,7 +3860,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
3657
3860
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
3658
3861
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
3659
3862
|
return {
|
3660
|
-
type:
|
3863
|
+
type: import_transactions10.TransactionType.Create,
|
3661
3864
|
...baseTransaction,
|
3662
3865
|
bytecodeWitnessIndex,
|
3663
3866
|
storageSlotsCount: (0, import_math10.bn)(storageSlots.length),
|
@@ -3672,7 +3875,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
3672
3875
|
*/
|
3673
3876
|
getContractCreatedOutputs() {
|
3674
3877
|
return this.outputs.filter(
|
3675
|
-
(output) => output.type ===
|
3878
|
+
(output) => output.type === import_transactions10.OutputType.ContractCreated
|
3676
3879
|
);
|
3677
3880
|
}
|
3678
3881
|
/**
|
@@ -3693,7 +3896,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
3693
3896
|
*/
|
3694
3897
|
addContractCreatedOutput(contractId, stateRoot) {
|
3695
3898
|
this.pushOutput({
|
3696
|
-
type:
|
3899
|
+
type: import_transactions10.OutputType.ContractCreated,
|
3697
3900
|
contractId,
|
3698
3901
|
stateRoot
|
3699
3902
|
});
|
@@ -3713,7 +3916,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
3713
3916
|
var import_address2 = require("@fuel-ts/address");
|
3714
3917
|
var import_configs9 = require("@fuel-ts/address/configs");
|
3715
3918
|
var import_math11 = require("@fuel-ts/math");
|
3716
|
-
var
|
3919
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
3717
3920
|
var import_utils17 = require("@fuel-ts/utils");
|
3718
3921
|
var import_ramda5 = require("ramda");
|
3719
3922
|
|
@@ -3749,7 +3952,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3749
3952
|
return new this((0, import_ramda5.clone)(obj));
|
3750
3953
|
}
|
3751
3954
|
/** Type of the transaction */
|
3752
|
-
type =
|
3955
|
+
type = import_transactions11.TransactionType.Script;
|
3753
3956
|
/** Gas limit for transaction */
|
3754
3957
|
gasLimit;
|
3755
3958
|
/** Script to execute */
|
@@ -3792,7 +3995,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3792
3995
|
const script = (0, import_utils17.arrayify)(this.script ?? "0x");
|
3793
3996
|
const scriptData = (0, import_utils17.arrayify)(this.scriptData ?? "0x");
|
3794
3997
|
return {
|
3795
|
-
type:
|
3998
|
+
type: import_transactions11.TransactionType.Script,
|
3796
3999
|
scriptGasLimit: this.gasLimit,
|
3797
4000
|
...super.getBaseTransaction(),
|
3798
4001
|
scriptLength: (0, import_math11.bn)(script.length),
|
@@ -3809,7 +4012,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3809
4012
|
*/
|
3810
4013
|
getContractInputs() {
|
3811
4014
|
return this.inputs.filter(
|
3812
|
-
(input) => input.type ===
|
4015
|
+
(input) => input.type === import_transactions11.InputType.Contract
|
3813
4016
|
);
|
3814
4017
|
}
|
3815
4018
|
/**
|
@@ -3819,7 +4022,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3819
4022
|
*/
|
3820
4023
|
getContractOutputs() {
|
3821
4024
|
return this.outputs.filter(
|
3822
|
-
(output) => output.type ===
|
4025
|
+
(output) => output.type === import_transactions11.OutputType.Contract
|
3823
4026
|
);
|
3824
4027
|
}
|
3825
4028
|
/**
|
@@ -3829,7 +4032,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3829
4032
|
*/
|
3830
4033
|
getVariableOutputs() {
|
3831
4034
|
return this.outputs.filter(
|
3832
|
-
(output) => output.type ===
|
4035
|
+
(output) => output.type === import_transactions11.OutputType.Variable
|
3833
4036
|
);
|
3834
4037
|
}
|
3835
4038
|
/**
|
@@ -3852,7 +4055,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3852
4055
|
let outputsNumber = numberOfVariables;
|
3853
4056
|
while (outputsNumber) {
|
3854
4057
|
this.pushOutput({
|
3855
|
-
type:
|
4058
|
+
type: import_transactions11.OutputType.Variable
|
3856
4059
|
});
|
3857
4060
|
outputsNumber -= 1;
|
3858
4061
|
}
|
@@ -3896,12 +4099,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3896
4099
|
return this;
|
3897
4100
|
}
|
3898
4101
|
const inputIndex = super.pushInput({
|
3899
|
-
type:
|
4102
|
+
type: import_transactions11.InputType.Contract,
|
3900
4103
|
contractId: contractAddress.toB256(),
|
3901
4104
|
txPointer: "0x00000000000000000000000000000000"
|
3902
4105
|
});
|
3903
4106
|
this.pushOutput({
|
3904
|
-
type:
|
4107
|
+
type: import_transactions11.OutputType.Contract,
|
3905
4108
|
inputIndex
|
3906
4109
|
});
|
3907
4110
|
return this;
|
@@ -3939,7 +4142,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3939
4142
|
// src/providers/transaction-request/upgrade-transaction-request.ts
|
3940
4143
|
var import_errors12 = require("@fuel-ts/errors");
|
3941
4144
|
var import_hasher2 = require("@fuel-ts/hasher");
|
3942
|
-
var
|
4145
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
3943
4146
|
var import_utils18 = require("@fuel-ts/utils");
|
3944
4147
|
var import_ramda6 = require("ramda");
|
3945
4148
|
var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
@@ -3950,7 +4153,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3950
4153
|
return new this((0, import_ramda6.clone)(obj));
|
3951
4154
|
}
|
3952
4155
|
/** The type of transaction */
|
3953
|
-
type =
|
4156
|
+
type = import_transactions12.TransactionType.Upgrade;
|
3954
4157
|
/** The upgrade purpose */
|
3955
4158
|
upgradePurpose;
|
3956
4159
|
/** Witness index of consensus */
|
@@ -3968,7 +4171,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3968
4171
|
super(rest);
|
3969
4172
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
3970
4173
|
this.upgradePurpose = upgradePurpose ?? {
|
3971
|
-
type:
|
4174
|
+
type: import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters,
|
3972
4175
|
checksum: "0x"
|
3973
4176
|
};
|
3974
4177
|
}
|
@@ -3982,7 +4185,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3982
4185
|
addConsensusParametersUpgradePurpose(consensus) {
|
3983
4186
|
this.bytecodeWitnessIndex = this.addWitness(consensus);
|
3984
4187
|
this.upgradePurpose = {
|
3985
|
-
type:
|
4188
|
+
type: import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters,
|
3986
4189
|
checksum: (0, import_hasher2.hash)(consensus)
|
3987
4190
|
};
|
3988
4191
|
return this;
|
@@ -3996,7 +4199,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3996
4199
|
*/
|
3997
4200
|
addStateTransitionUpgradePurpose(bytecodeRoot) {
|
3998
4201
|
this.upgradePurpose = {
|
3999
|
-
type:
|
4202
|
+
type: import_transactions12.UpgradePurposeTypeEnum.StateTransition,
|
4000
4203
|
data: (0, import_utils18.hexlify)(bytecodeRoot)
|
4001
4204
|
};
|
4002
4205
|
return this;
|
@@ -4010,10 +4213,10 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
4010
4213
|
* @returns - The current instance of `UpgradeTransactionRequest`.
|
4011
4214
|
*/
|
4012
4215
|
addUpgradePurpose(type, data) {
|
4013
|
-
if (type ===
|
4216
|
+
if (type === import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters) {
|
4014
4217
|
this.addConsensusParametersUpgradePurpose(data);
|
4015
4218
|
}
|
4016
|
-
if (type ===
|
4219
|
+
if (type === import_transactions12.UpgradePurposeTypeEnum.StateTransition) {
|
4017
4220
|
this.addStateTransitionUpgradePurpose(data);
|
4018
4221
|
}
|
4019
4222
|
return this;
|
@@ -4025,17 +4228,17 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
4025
4228
|
*/
|
4026
4229
|
toTransaction() {
|
4027
4230
|
let upgradePurpose;
|
4028
|
-
if (this.upgradePurpose.type ===
|
4231
|
+
if (this.upgradePurpose.type === import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters) {
|
4029
4232
|
upgradePurpose = {
|
4030
|
-
type:
|
4233
|
+
type: import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters,
|
4031
4234
|
data: {
|
4032
4235
|
witnessIndex: this.bytecodeWitnessIndex,
|
4033
4236
|
checksum: this.upgradePurpose.checksum
|
4034
4237
|
}
|
4035
4238
|
};
|
4036
|
-
} else if (this.upgradePurpose.type ===
|
4239
|
+
} else if (this.upgradePurpose.type === import_transactions12.UpgradePurposeTypeEnum.StateTransition) {
|
4037
4240
|
upgradePurpose = {
|
4038
|
-
type:
|
4241
|
+
type: import_transactions12.UpgradePurposeTypeEnum.StateTransition,
|
4039
4242
|
data: {
|
4040
4243
|
bytecodeRoot: (0, import_utils18.hexlify)(this.upgradePurpose.data)
|
4041
4244
|
}
|
@@ -4044,7 +4247,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
4044
4247
|
throw new import_errors12.FuelError(import_errors12.FuelError.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
4045
4248
|
}
|
4046
4249
|
return {
|
4047
|
-
type:
|
4250
|
+
type: import_transactions12.TransactionType.Upgrade,
|
4048
4251
|
...super.getBaseTransaction(),
|
4049
4252
|
upgradePurpose
|
4050
4253
|
};
|
@@ -4068,7 +4271,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
4068
4271
|
*/
|
4069
4272
|
metadataGas(gasCosts) {
|
4070
4273
|
const txBytesSize = this.byteSize();
|
4071
|
-
if (this.upgradePurpose.type ===
|
4274
|
+
if (this.upgradePurpose.type === import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters) {
|
4072
4275
|
const witnessIndex = this.bytecodeWitnessIndex;
|
4073
4276
|
const consensusSize = this.witnesses[witnessIndex].length;
|
4074
4277
|
return calculateMetadataGasForTxUpgrade({
|
@@ -4077,7 +4280,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
4077
4280
|
consensusSize
|
4078
4281
|
});
|
4079
4282
|
}
|
4080
|
-
if (this.upgradePurpose.type ===
|
4283
|
+
if (this.upgradePurpose.type === import_transactions12.UpgradePurposeTypeEnum.StateTransition) {
|
4081
4284
|
return calculateMetadataGasForTxUpgrade({
|
4082
4285
|
gasCosts,
|
4083
4286
|
txBytesSize
|
@@ -4089,7 +4292,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
4089
4292
|
|
4090
4293
|
// src/providers/transaction-request/upload-transaction-request.ts
|
4091
4294
|
var import_configs10 = require("@fuel-ts/address/configs");
|
4092
|
-
var
|
4295
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
4093
4296
|
var import_utils20 = require("@fuel-ts/utils");
|
4094
4297
|
var import_ramda7 = require("ramda");
|
4095
4298
|
var UploadTransactionRequest = class extends BaseTransactionRequest {
|
@@ -4100,7 +4303,7 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
4100
4303
|
return new this((0, import_ramda7.clone)(obj));
|
4101
4304
|
}
|
4102
4305
|
/** Type of the transaction */
|
4103
|
-
type =
|
4306
|
+
type = import_transactions13.TransactionType.Upload;
|
4104
4307
|
/** The witness index of the subsection of the bytecode. */
|
4105
4308
|
witnessIndex;
|
4106
4309
|
/** The subsection data. */
|
@@ -4149,7 +4352,7 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
4149
4352
|
const baseTransaction = this.getBaseTransaction();
|
4150
4353
|
const { subsectionIndex, subsectionsNumber, root, proofSet } = this.subsection;
|
4151
4354
|
return {
|
4152
|
-
type:
|
4355
|
+
type: import_transactions13.TransactionType.Upload,
|
4153
4356
|
...baseTransaction,
|
4154
4357
|
subsectionIndex,
|
4155
4358
|
subsectionsNumber,
|
@@ -4199,26 +4402,26 @@ var AbstractScriptRequest = class {
|
|
4199
4402
|
|
4200
4403
|
// src/providers/transaction-request/utils.ts
|
4201
4404
|
var import_errors13 = require("@fuel-ts/errors");
|
4202
|
-
var
|
4405
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
4203
4406
|
var transactionRequestify = (obj) => {
|
4204
4407
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest || obj instanceof UpgradeTransactionRequest || obj instanceof UploadTransactionRequest) {
|
4205
4408
|
return obj;
|
4206
4409
|
}
|
4207
4410
|
const { type } = obj;
|
4208
4411
|
switch (obj.type) {
|
4209
|
-
case
|
4412
|
+
case import_transactions14.TransactionType.Script: {
|
4210
4413
|
return ScriptTransactionRequest.from(obj);
|
4211
4414
|
}
|
4212
|
-
case
|
4415
|
+
case import_transactions14.TransactionType.Create: {
|
4213
4416
|
return CreateTransactionRequest.from(obj);
|
4214
4417
|
}
|
4215
|
-
case
|
4418
|
+
case import_transactions14.TransactionType.Blob: {
|
4216
4419
|
return BlobTransactionRequest.from(obj);
|
4217
4420
|
}
|
4218
|
-
case
|
4421
|
+
case import_transactions14.TransactionType.Upgrade: {
|
4219
4422
|
return UpgradeTransactionRequest.from(obj);
|
4220
4423
|
}
|
4221
|
-
case
|
4424
|
+
case import_transactions14.TransactionType.Upload: {
|
4222
4425
|
return UploadTransactionRequest.from(obj);
|
4223
4426
|
}
|
4224
4427
|
default: {
|
@@ -4229,27 +4432,118 @@ var transactionRequestify = (obj) => {
|
|
4229
4432
|
}
|
4230
4433
|
}
|
4231
4434
|
};
|
4232
|
-
var isTransactionTypeScript = (request2) => request2.type ===
|
4233
|
-
var isTransactionTypeCreate = (request2) => request2.type ===
|
4234
|
-
var isTransactionTypeBlob = (request2) => request2.type ===
|
4235
|
-
var isTransactionTypeUpgrade = (request2) => request2.type ===
|
4236
|
-
var isTransactionTypeUpload = (request2) => request2.type ===
|
4435
|
+
var isTransactionTypeScript = (request2) => request2.type === import_transactions14.TransactionType.Script;
|
4436
|
+
var isTransactionTypeCreate = (request2) => request2.type === import_transactions14.TransactionType.Create;
|
4437
|
+
var isTransactionTypeBlob = (request2) => request2.type === import_transactions14.TransactionType.Blob;
|
4438
|
+
var isTransactionTypeUpgrade = (request2) => request2.type === import_transactions14.TransactionType.Upgrade;
|
4439
|
+
var isTransactionTypeUpload = (request2) => request2.type === import_transactions14.TransactionType.Upload;
|
4440
|
+
|
4441
|
+
// src/providers/resource-cache.ts
|
4442
|
+
var cache = /* @__PURE__ */ new Map();
|
4443
|
+
var ResourceCache = class {
|
4444
|
+
ttl;
|
4445
|
+
constructor(ttl) {
|
4446
|
+
this.ttl = ttl;
|
4447
|
+
if (typeof ttl !== "number" || this.ttl <= 0) {
|
4448
|
+
throw new import_errors14.FuelError(
|
4449
|
+
import_errors14.ErrorCode.INVALID_TTL,
|
4450
|
+
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
4451
|
+
);
|
4452
|
+
}
|
4453
|
+
}
|
4454
|
+
// Add resources to the cache
|
4455
|
+
set(transactionId, inputs) {
|
4456
|
+
const transactionResourceCache = this.setupResourcesCache(inputs);
|
4457
|
+
cache.set(transactionId, transactionResourceCache);
|
4458
|
+
}
|
4459
|
+
unset(transactionId) {
|
4460
|
+
cache.delete(transactionId);
|
4461
|
+
}
|
4462
|
+
getActiveData(owner) {
|
4463
|
+
const activeData = { utxos: [], messages: [] };
|
4464
|
+
const currentTime = Date.now();
|
4465
|
+
const expired = [];
|
4466
|
+
cache.forEach((resource, transactionId) => {
|
4467
|
+
const isActive = currentTime - resource.timestamp < this.ttl;
|
4468
|
+
if (isActive) {
|
4469
|
+
const resourcesFromOwner = resource.owners.get(owner);
|
4470
|
+
if (resourcesFromOwner) {
|
4471
|
+
activeData.utxos.push(...resourcesFromOwner.utxos);
|
4472
|
+
activeData.messages.push(...resourcesFromOwner.messages);
|
4473
|
+
}
|
4474
|
+
} else {
|
4475
|
+
expired.push(transactionId);
|
4476
|
+
}
|
4477
|
+
});
|
4478
|
+
expired.forEach(this.unset);
|
4479
|
+
activeData.utxos.reverse();
|
4480
|
+
activeData.messages.reverse();
|
4481
|
+
return activeData;
|
4482
|
+
}
|
4483
|
+
isCached(owner, key) {
|
4484
|
+
const currentTime = Date.now();
|
4485
|
+
let cached = false;
|
4486
|
+
const expired = [];
|
4487
|
+
for (const [transactionId, resourceData] of cache.entries()) {
|
4488
|
+
const isActive = currentTime - resourceData.timestamp < this.ttl;
|
4489
|
+
if (isActive) {
|
4490
|
+
const resourcesFromOwner = resourceData.owners.get(owner);
|
4491
|
+
if (resourcesFromOwner?.utxos.has(key) || resourcesFromOwner?.messages.has(key)) {
|
4492
|
+
cached = true;
|
4493
|
+
break;
|
4494
|
+
}
|
4495
|
+
} else {
|
4496
|
+
expired.push(transactionId);
|
4497
|
+
}
|
4498
|
+
}
|
4499
|
+
expired.forEach(this.unset);
|
4500
|
+
return cached;
|
4501
|
+
}
|
4502
|
+
clear() {
|
4503
|
+
cache.clear();
|
4504
|
+
}
|
4505
|
+
setupResourcesCache(inputs) {
|
4506
|
+
const currentTime = Date.now();
|
4507
|
+
const transactionResourcesCache = {
|
4508
|
+
owners: /* @__PURE__ */ new Map(),
|
4509
|
+
timestamp: currentTime
|
4510
|
+
};
|
4511
|
+
inputs.filter(isRequestInputCoinOrMessage).forEach((input) => {
|
4512
|
+
const { owner, key, type } = this.extractResourceData(input);
|
4513
|
+
if (!transactionResourcesCache.owners.has(owner)) {
|
4514
|
+
transactionResourcesCache.owners.set(owner, { utxos: /* @__PURE__ */ new Set(), messages: /* @__PURE__ */ new Set() });
|
4515
|
+
}
|
4516
|
+
if (type === "utxo") {
|
4517
|
+
transactionResourcesCache.owners.get(owner)?.utxos.add(key);
|
4518
|
+
} else {
|
4519
|
+
transactionResourcesCache.owners.get(owner)?.messages.add(key);
|
4520
|
+
}
|
4521
|
+
});
|
4522
|
+
return transactionResourcesCache;
|
4523
|
+
}
|
4524
|
+
extractResourceData(input) {
|
4525
|
+
if (isRequestInputCoin(input)) {
|
4526
|
+
return { owner: (0, import_utils22.hexlify)(input.owner), key: (0, import_utils22.hexlify)(input.id), type: "utxo" };
|
4527
|
+
}
|
4528
|
+
return { owner: (0, import_utils22.hexlify)(input.recipient), key: (0, import_utils22.hexlify)(input.nonce), type: "message" };
|
4529
|
+
}
|
4530
|
+
};
|
4237
4531
|
|
4238
4532
|
// src/providers/transaction-response/transaction-response.ts
|
4239
|
-
var
|
4533
|
+
var import_errors18 = require("@fuel-ts/errors");
|
4240
4534
|
var import_math17 = require("@fuel-ts/math");
|
4241
|
-
var
|
4535
|
+
var import_transactions22 = require("@fuel-ts/transactions");
|
4242
4536
|
var import_utils26 = require("@fuel-ts/utils");
|
4243
4537
|
|
4244
4538
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
4245
4539
|
var import_math16 = require("@fuel-ts/math");
|
4246
|
-
var
|
4540
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4247
4541
|
var import_utils24 = require("@fuel-ts/utils");
|
4248
4542
|
|
4249
4543
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
4250
4544
|
var import_math12 = require("@fuel-ts/math");
|
4251
|
-
var
|
4252
|
-
var
|
4545
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
4546
|
+
var import_utils23 = require("@fuel-ts/utils");
|
4253
4547
|
var calculateTXFeeForSummary = (params) => {
|
4254
4548
|
const {
|
4255
4549
|
gasPrice,
|
@@ -4259,17 +4553,17 @@ var calculateTXFeeForSummary = (params) => {
|
|
4259
4553
|
} = params;
|
4260
4554
|
const gasPerByte = (0, import_math12.bn)(feeParams.gasPerByte);
|
4261
4555
|
const gasPriceFactor = (0, import_math12.bn)(feeParams.gasPriceFactor);
|
4262
|
-
const transactionBytes = (0,
|
4263
|
-
const [transaction] = new
|
4556
|
+
const transactionBytes = (0, import_utils23.arrayify)(rawPayload);
|
4557
|
+
const [transaction] = new import_transactions15.TransactionCoder().decode(transactionBytes, 0);
|
4264
4558
|
const { type, witnesses, inputs, policies } = transaction;
|
4265
4559
|
let metadataGas = (0, import_math12.bn)(0);
|
4266
4560
|
let gasLimit = (0, import_math12.bn)(0);
|
4267
|
-
if (type !==
|
4561
|
+
if (type !== import_transactions15.TransactionType.Create && type !== import_transactions15.TransactionType.Script) {
|
4268
4562
|
return (0, import_math12.bn)(0);
|
4269
4563
|
}
|
4270
|
-
if (type ===
|
4564
|
+
if (type === import_transactions15.TransactionType.Create) {
|
4271
4565
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
4272
|
-
const contractBytesSize = (0, import_math12.bn)((0,
|
4566
|
+
const contractBytesSize = (0, import_math12.bn)((0, import_utils23.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
4273
4567
|
metadataGas = calculateMetadataGasForTxCreate({
|
4274
4568
|
contractBytesSize,
|
4275
4569
|
gasCosts,
|
@@ -4293,7 +4587,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
4293
4587
|
metadataGas,
|
4294
4588
|
txBytesSize: transactionBytes.length
|
4295
4589
|
});
|
4296
|
-
const witnessLimit = policies.find((policy) => policy.type ===
|
4590
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions15.PolicyType.WitnessLimit)?.data;
|
4297
4591
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
4298
4592
|
const maxGas = getMaxGas({
|
4299
4593
|
gasPerByte,
|
@@ -4314,47 +4608,14 @@ var calculateTXFeeForSummary = (params) => {
|
|
4314
4608
|
|
4315
4609
|
// src/providers/transaction-summary/operations.ts
|
4316
4610
|
var import_configs11 = require("@fuel-ts/address/configs");
|
4317
|
-
var
|
4611
|
+
var import_errors16 = require("@fuel-ts/errors");
|
4318
4612
|
var import_math14 = require("@fuel-ts/math");
|
4319
|
-
var
|
4320
|
-
|
4321
|
-
// src/providers/transaction-summary/call.ts
|
4322
|
-
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4323
|
-
var getFunctionCall = ({ abi, receipt }) => {
|
4324
|
-
const abiInterface = new import_abi_coder4.Interface(abi);
|
4325
|
-
const callFunctionSelector = receipt.param1.toHex(8);
|
4326
|
-
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
4327
|
-
const inputs = functionFragment.jsonFn.inputs;
|
4328
|
-
const encodedArgs = receipt.param2.toHex();
|
4329
|
-
let argumentsProvided;
|
4330
|
-
const data = functionFragment.decodeArguments(encodedArgs);
|
4331
|
-
if (data) {
|
4332
|
-
argumentsProvided = inputs.reduce((prev, input, index) => {
|
4333
|
-
const value = data[index];
|
4334
|
-
const name = input.name;
|
4335
|
-
if (name) {
|
4336
|
-
return {
|
4337
|
-
...prev,
|
4338
|
-
// reparse to remove bn
|
4339
|
-
[name]: JSON.parse(JSON.stringify(value))
|
4340
|
-
};
|
4341
|
-
}
|
4342
|
-
return prev;
|
4343
|
-
}, {});
|
4344
|
-
}
|
4345
|
-
const call = {
|
4346
|
-
functionSignature: functionFragment.signature,
|
4347
|
-
functionName: functionFragment.name,
|
4348
|
-
argumentsProvided,
|
4349
|
-
...receipt.amount?.isZero() ? {} : { amount: receipt.amount, assetId: receipt.assetId }
|
4350
|
-
};
|
4351
|
-
return call;
|
4352
|
-
};
|
4613
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
4353
4614
|
|
4354
4615
|
// src/providers/transaction-summary/input.ts
|
4355
|
-
var
|
4616
|
+
var import_errors15 = require("@fuel-ts/errors");
|
4356
4617
|
var import_math13 = require("@fuel-ts/math");
|
4357
|
-
var
|
4618
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
4358
4619
|
function getInputsByTypes(inputs, types) {
|
4359
4620
|
return inputs.filter((i) => types.includes(i.type));
|
4360
4621
|
}
|
@@ -4362,19 +4623,19 @@ function getInputsByType(inputs, type) {
|
|
4362
4623
|
return inputs.filter((i) => i.type === type);
|
4363
4624
|
}
|
4364
4625
|
function getInputsCoin(inputs) {
|
4365
|
-
return getInputsByType(inputs,
|
4626
|
+
return getInputsByType(inputs, import_transactions16.InputType.Coin);
|
4366
4627
|
}
|
4367
4628
|
function getInputsMessage(inputs) {
|
4368
|
-
return getInputsByType(inputs,
|
4629
|
+
return getInputsByType(inputs, import_transactions16.InputType.Message);
|
4369
4630
|
}
|
4370
4631
|
function getInputsCoinAndMessage(inputs) {
|
4371
|
-
return getInputsByTypes(inputs, [
|
4632
|
+
return getInputsByTypes(inputs, [import_transactions16.InputType.Coin, import_transactions16.InputType.Message]);
|
4372
4633
|
}
|
4373
4634
|
function isInputCoin(input) {
|
4374
|
-
return input.type ===
|
4635
|
+
return input.type === import_transactions16.InputType.Coin;
|
4375
4636
|
}
|
4376
4637
|
function getInputsContract(inputs) {
|
4377
|
-
return getInputsByType(inputs,
|
4638
|
+
return getInputsByType(inputs, import_transactions16.InputType.Contract);
|
4378
4639
|
}
|
4379
4640
|
function findCoinInput(inputs, assetId) {
|
4380
4641
|
const coinInputs = getInputsCoin(inputs);
|
@@ -4420,43 +4681,43 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
4420
4681
|
if (!contractInput) {
|
4421
4682
|
return void 0;
|
4422
4683
|
}
|
4423
|
-
if (contractInput.type !==
|
4424
|
-
throw new
|
4425
|
-
|
4684
|
+
if (contractInput.type !== import_transactions16.InputType.Contract) {
|
4685
|
+
throw new import_errors15.FuelError(
|
4686
|
+
import_errors15.ErrorCode.INVALID_TRANSACTION_INPUT,
|
4426
4687
|
`Contract input should be of type 'contract'.`
|
4427
4688
|
);
|
4428
4689
|
}
|
4429
4690
|
return contractInput;
|
4430
4691
|
}
|
4431
4692
|
function getInputAccountAddress(input) {
|
4432
|
-
if (input.type ===
|
4693
|
+
if (input.type === import_transactions16.InputType.Coin) {
|
4433
4694
|
return input.owner.toString();
|
4434
4695
|
}
|
4435
|
-
if (input.type ===
|
4696
|
+
if (input.type === import_transactions16.InputType.Message) {
|
4436
4697
|
return input.recipient.toString();
|
4437
4698
|
}
|
4438
4699
|
return "";
|
4439
4700
|
}
|
4440
4701
|
|
4441
4702
|
// src/providers/transaction-summary/output.ts
|
4442
|
-
var
|
4703
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
4443
4704
|
function getOutputsByType(outputs, type) {
|
4444
4705
|
return outputs.filter((o) => o.type === type);
|
4445
4706
|
}
|
4446
4707
|
function getOutputsContractCreated(outputs) {
|
4447
|
-
return getOutputsByType(outputs,
|
4708
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.ContractCreated);
|
4448
4709
|
}
|
4449
4710
|
function getOutputsCoin(outputs) {
|
4450
|
-
return getOutputsByType(outputs,
|
4711
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.Coin);
|
4451
4712
|
}
|
4452
4713
|
function getOutputsChange(outputs) {
|
4453
|
-
return getOutputsByType(outputs,
|
4714
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.Change);
|
4454
4715
|
}
|
4455
4716
|
function getOutputsContract(outputs) {
|
4456
|
-
return getOutputsByType(outputs,
|
4717
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.Contract);
|
4457
4718
|
}
|
4458
4719
|
function getOutputsVariable(outputs) {
|
4459
|
-
return getOutputsByType(outputs,
|
4720
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.Variable);
|
4460
4721
|
}
|
4461
4722
|
|
4462
4723
|
// src/providers/transaction-summary/types.ts
|
@@ -4502,21 +4763,21 @@ function getReceiptsByType(receipts, type) {
|
|
4502
4763
|
}
|
4503
4764
|
function getTransactionTypeName(transactionType) {
|
4504
4765
|
switch (transactionType) {
|
4505
|
-
case
|
4766
|
+
case import_transactions18.TransactionType.Mint:
|
4506
4767
|
return "Mint" /* Mint */;
|
4507
|
-
case
|
4768
|
+
case import_transactions18.TransactionType.Create:
|
4508
4769
|
return "Create" /* Create */;
|
4509
|
-
case
|
4770
|
+
case import_transactions18.TransactionType.Script:
|
4510
4771
|
return "Script" /* Script */;
|
4511
|
-
case
|
4772
|
+
case import_transactions18.TransactionType.Blob:
|
4512
4773
|
return "Blob" /* Blob */;
|
4513
|
-
case
|
4774
|
+
case import_transactions18.TransactionType.Upgrade:
|
4514
4775
|
return "Upgrade" /* Upgrade */;
|
4515
|
-
case
|
4776
|
+
case import_transactions18.TransactionType.Upload:
|
4516
4777
|
return "Upload" /* Upload */;
|
4517
4778
|
default:
|
4518
|
-
throw new
|
4519
|
-
|
4779
|
+
throw new import_errors16.FuelError(
|
4780
|
+
import_errors16.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
4520
4781
|
`Unsupported transaction type: ${transactionType}.`
|
4521
4782
|
);
|
4522
4783
|
}
|
@@ -4547,10 +4808,10 @@ function hasSameAssetId(a) {
|
|
4547
4808
|
return (b) => a.assetId === b.assetId;
|
4548
4809
|
}
|
4549
4810
|
function getReceiptsCall(receipts) {
|
4550
|
-
return getReceiptsByType(receipts,
|
4811
|
+
return getReceiptsByType(receipts, import_transactions18.ReceiptType.Call);
|
4551
4812
|
}
|
4552
4813
|
function getReceiptsMessageOut(receipts) {
|
4553
|
-
return getReceiptsByType(receipts,
|
4814
|
+
return getReceiptsByType(receipts, import_transactions18.ReceiptType.MessageOut);
|
4554
4815
|
}
|
4555
4816
|
function mergeAssets(op1, op2) {
|
4556
4817
|
const assets1 = op1.assetsSent || [];
|
@@ -4588,7 +4849,11 @@ function mergeOperations(existing, toAdd) {
|
|
4588
4849
|
return {
|
4589
4850
|
...existing,
|
4590
4851
|
assetsSent: mergeAssetsSent(existing, toAdd),
|
4591
|
-
calls: mergeCalls(existing, toAdd)
|
4852
|
+
calls: mergeCalls(existing, toAdd),
|
4853
|
+
receipts: [
|
4854
|
+
...existing.receipts || [],
|
4855
|
+
...toAdd.receipts?.filter((r) => !existing.receipts?.some((er) => er === r)) || []
|
4856
|
+
]
|
4592
4857
|
};
|
4593
4858
|
}
|
4594
4859
|
function addOperation(operations, toAdd) {
|
@@ -4599,7 +4864,7 @@ function addOperation(operations, toAdd) {
|
|
4599
4864
|
return operations.map((op, index) => index === existingIndex ? mergeOperations(op, toAdd) : op);
|
4600
4865
|
}
|
4601
4866
|
function getReceiptsTransferOut(receipts) {
|
4602
|
-
return getReceiptsByType(receipts,
|
4867
|
+
return getReceiptsByType(receipts, import_transactions18.ReceiptType.TransferOut);
|
4603
4868
|
}
|
4604
4869
|
function getWithdrawFromFuelOperations({
|
4605
4870
|
inputs,
|
@@ -4628,7 +4893,8 @@ function getWithdrawFromFuelOperations({
|
|
4628
4893
|
amount: receipt.amount,
|
4629
4894
|
assetId: baseAssetId
|
4630
4895
|
}
|
4631
|
-
]
|
4896
|
+
],
|
4897
|
+
receipts: [receipt]
|
4632
4898
|
});
|
4633
4899
|
return newWithdrawFromFuelOps;
|
4634
4900
|
}
|
@@ -4638,19 +4904,12 @@ function getWithdrawFromFuelOperations({
|
|
4638
4904
|
);
|
4639
4905
|
return withdrawFromFuelOperations;
|
4640
4906
|
}
|
4641
|
-
function getContractCalls(contractInput, abiMap,
|
4907
|
+
function getContractCalls(contractInput, abiMap, _receipt, _rawPayload, _maxInputs) {
|
4642
4908
|
const abi = abiMap?.[contractInput.contractID];
|
4643
|
-
if (!abi) {
|
4644
|
-
return [];
|
4645
|
-
}
|
4646
|
-
return [
|
4647
|
-
getFunctionCall({
|
4648
|
-
abi,
|
4649
|
-
receipt,
|
4650
|
-
rawPayload,
|
4651
|
-
maxInputs
|
4652
|
-
})
|
4653
|
-
];
|
4909
|
+
if (!abi) {
|
4910
|
+
return [];
|
4911
|
+
}
|
4912
|
+
return [];
|
4654
4913
|
}
|
4655
4914
|
function getAssetsSent(receipt) {
|
4656
4915
|
return receipt.amount?.isZero() ? void 0 : [
|
@@ -4680,7 +4939,8 @@ function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload,
|
|
4680
4939
|
address: receipt.to
|
4681
4940
|
},
|
4682
4941
|
assetsSent: getAssetsSent(receipt),
|
4683
|
-
calls
|
4942
|
+
calls,
|
4943
|
+
receipts: [receipt]
|
4684
4944
|
}
|
4685
4945
|
];
|
4686
4946
|
}
|
@@ -4737,7 +4997,8 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
4737
4997
|
assetId: assetId.toString(),
|
4738
4998
|
amount
|
4739
4999
|
}
|
4740
|
-
]
|
5000
|
+
],
|
5001
|
+
receipts: [receipt]
|
4741
5002
|
};
|
4742
5003
|
}
|
4743
5004
|
function getTransferOperations({
|
@@ -4782,11 +5043,11 @@ function getTransferOperations({
|
|
4782
5043
|
});
|
4783
5044
|
const transferReceipts = getReceiptsByType(
|
4784
5045
|
receipts,
|
4785
|
-
|
5046
|
+
import_transactions18.ReceiptType.Transfer
|
4786
5047
|
);
|
4787
5048
|
const transferOutReceipts = getReceiptsByType(
|
4788
5049
|
receipts,
|
4789
|
-
|
5050
|
+
import_transactions18.ReceiptType.TransferOut
|
4790
5051
|
);
|
4791
5052
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
4792
5053
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -4870,12 +5131,12 @@ function getOperations({
|
|
4870
5131
|
}
|
4871
5132
|
|
4872
5133
|
// src/providers/transaction-summary/receipt.ts
|
4873
|
-
var
|
4874
|
-
var processGqlReceipt = (gqlReceipt) =>
|
5134
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
5135
|
+
var processGqlReceipt = (gqlReceipt) => deserializeReceipt(gqlReceipt);
|
4875
5136
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
4876
5137
|
const mintedAssets = [];
|
4877
5138
|
receipts.forEach((receipt) => {
|
4878
|
-
if (receipt.type ===
|
5139
|
+
if (receipt.type === import_transactions19.ReceiptType.Mint) {
|
4879
5140
|
mintedAssets.push({
|
4880
5141
|
subId: receipt.subId,
|
4881
5142
|
contractId: receipt.contractId,
|
@@ -4889,7 +5150,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
4889
5150
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
4890
5151
|
const burnedAssets = [];
|
4891
5152
|
receipts.forEach((receipt) => {
|
4892
|
-
if (receipt.type ===
|
5153
|
+
if (receipt.type === import_transactions19.ReceiptType.Burn) {
|
4893
5154
|
burnedAssets.push({
|
4894
5155
|
subId: receipt.subId,
|
4895
5156
|
contractId: receipt.contractId,
|
@@ -4902,7 +5163,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
4902
5163
|
};
|
4903
5164
|
|
4904
5165
|
// src/providers/transaction-summary/status.ts
|
4905
|
-
var
|
5166
|
+
var import_errors17 = require("@fuel-ts/errors");
|
4906
5167
|
var import_math15 = require("@fuel-ts/math");
|
4907
5168
|
var getTransactionStatusName = (gqlStatus) => {
|
4908
5169
|
switch (gqlStatus) {
|
@@ -4915,8 +5176,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
4915
5176
|
case "SqueezedOutStatus":
|
4916
5177
|
return "squeezedout" /* squeezedout */;
|
4917
5178
|
default:
|
4918
|
-
throw new
|
4919
|
-
|
5179
|
+
throw new import_errors17.FuelError(
|
5180
|
+
import_errors17.ErrorCode.INVALID_TRANSACTION_STATUS,
|
4920
5181
|
`Invalid transaction status: ${gqlStatus}.`
|
4921
5182
|
);
|
4922
5183
|
}
|
@@ -4998,7 +5259,7 @@ function assembleTransactionSummary(params) {
|
|
4998
5259
|
baseAssetId
|
4999
5260
|
});
|
5000
5261
|
const typeName = getTransactionTypeName(transaction.type);
|
5001
|
-
const tip = (0, import_math16.bn)(transaction.policies?.find((policy) => policy.type ===
|
5262
|
+
const tip = (0, import_math16.bn)(transaction.policies?.find((policy) => policy.type === import_transactions20.PolicyType.Tip)?.data);
|
5002
5263
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
5003
5264
|
const fee = totalFee ?? calculateTXFeeForSummary({
|
5004
5265
|
gasPrice,
|
@@ -5048,15 +5309,27 @@ function assembleTransactionSummary(params) {
|
|
5048
5309
|
}
|
5049
5310
|
|
5050
5311
|
// src/providers/transaction-response/getDecodedLogs.ts
|
5051
|
-
var
|
5052
|
-
var
|
5312
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
5313
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
5314
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
5053
5315
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
5316
|
+
let mainContract = "";
|
5317
|
+
if (mainAbi.programType === "contract") {
|
5318
|
+
const firstCallReceipt = receipts.find(
|
5319
|
+
(r) => r.type === import_transactions21.ReceiptType.Call && r.id === import_configs12.ZeroBytes32
|
5320
|
+
);
|
5321
|
+
mainContract = firstCallReceipt.to;
|
5322
|
+
}
|
5054
5323
|
return receipts.reduce((logs, receipt) => {
|
5055
|
-
if (receipt.type ===
|
5056
|
-
const
|
5057
|
-
const
|
5058
|
-
|
5059
|
-
|
5324
|
+
if (receipt.type === import_transactions21.ReceiptType.LogData || receipt.type === import_transactions21.ReceiptType.Log) {
|
5325
|
+
const isLogFromMainAbi = receipt.id === import_configs12.ZeroBytes32 || mainContract === receipt.id;
|
5326
|
+
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
5327
|
+
if (isDecodable) {
|
5328
|
+
const interfaceToUse = isLogFromMainAbi ? new import_abi_coder4.Interface(mainAbi) : new import_abi_coder4.Interface(externalAbis[receipt.id]);
|
5329
|
+
const data = receipt.type === import_transactions21.ReceiptType.Log ? new import_abi_coder4.BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
5330
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
5331
|
+
logs.push(decodedLog);
|
5332
|
+
}
|
5060
5333
|
}
|
5061
5334
|
return logs;
|
5062
5335
|
}, []);
|
@@ -5068,24 +5341,24 @@ function mapGqlOutputsToTxOutputs(outputs) {
|
|
5068
5341
|
const obj = "amount" in o ? { ...o, amount: (0, import_math17.bn)(o.amount) } : o;
|
5069
5342
|
switch (obj.type) {
|
5070
5343
|
case "CoinOutput":
|
5071
|
-
return { ...obj, type:
|
5344
|
+
return { ...obj, type: import_transactions22.OutputType.Coin };
|
5072
5345
|
case "ContractOutput":
|
5073
5346
|
return {
|
5074
5347
|
...obj,
|
5075
|
-
type:
|
5348
|
+
type: import_transactions22.OutputType.Contract,
|
5076
5349
|
inputIndex: parseInt(obj.inputIndex, 10)
|
5077
5350
|
};
|
5078
5351
|
case "ChangeOutput":
|
5079
5352
|
return {
|
5080
5353
|
...obj,
|
5081
|
-
type:
|
5354
|
+
type: import_transactions22.OutputType.Change
|
5082
5355
|
};
|
5083
5356
|
case "VariableOutput":
|
5084
|
-
return { ...obj, type:
|
5357
|
+
return { ...obj, type: import_transactions22.OutputType.Variable };
|
5085
5358
|
case "ContractCreated":
|
5086
5359
|
return {
|
5087
5360
|
...obj,
|
5088
|
-
type:
|
5361
|
+
type: import_transactions22.OutputType.ContractCreated,
|
5089
5362
|
contractId: obj.contract
|
5090
5363
|
};
|
5091
5364
|
default:
|
@@ -5145,7 +5418,7 @@ var TransactionResponse = class {
|
|
5145
5418
|
const correspondingInput = status.transaction.inputs?.[idx];
|
5146
5419
|
return {
|
5147
5420
|
...input,
|
5148
|
-
txPointer:
|
5421
|
+
txPointer: import_transactions22.TxPointerCoder.decodeFromGqlScalar(correspondingInput.txPointer)
|
5149
5422
|
};
|
5150
5423
|
}
|
5151
5424
|
return input;
|
@@ -5176,7 +5449,7 @@ var TransactionResponse = class {
|
|
5176
5449
|
switch (status?.type) {
|
5177
5450
|
case "SuccessStatus":
|
5178
5451
|
case "FailureStatus":
|
5179
|
-
return status.receipts.map(
|
5452
|
+
return status.receipts.map(deserializeReceipt);
|
5180
5453
|
default:
|
5181
5454
|
return [];
|
5182
5455
|
}
|
@@ -5212,7 +5485,7 @@ var TransactionResponse = class {
|
|
5212
5485
|
* @returns The decoded transaction.
|
5213
5486
|
*/
|
5214
5487
|
decodeTransaction(transactionWithReceipts) {
|
5215
|
-
return new
|
5488
|
+
return new import_transactions22.TransactionCoder().decode(
|
5216
5489
|
(0, import_utils26.arrayify)(transactionWithReceipts.rawPayload),
|
5217
5490
|
0
|
5218
5491
|
)?.[0];
|
@@ -5261,8 +5534,8 @@ var TransactionResponse = class {
|
|
5261
5534
|
this.status = statusChange;
|
5262
5535
|
if (statusChange.type === "SqueezedOutStatus") {
|
5263
5536
|
this.unsetResourceCache();
|
5264
|
-
throw new
|
5265
|
-
|
5537
|
+
throw new import_errors18.FuelError(
|
5538
|
+
import_errors18.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
5266
5539
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
5267
5540
|
);
|
5268
5541
|
}
|
@@ -5300,7 +5573,6 @@ var TransactionResponse = class {
|
|
5300
5573
|
const { receipts } = transactionResult;
|
5301
5574
|
const status = this.status ?? this.gqlTransaction?.status;
|
5302
5575
|
if (status?.type === "FailureStatus") {
|
5303
|
-
this.unsetResourceCache();
|
5304
5576
|
const { reason } = status;
|
5305
5577
|
throw extractTxError({
|
5306
5578
|
receipts,
|
@@ -5317,6 +5589,7 @@ var TransactionResponse = class {
|
|
5317
5589
|
*/
|
5318
5590
|
async waitForResult(contractsAbiMap) {
|
5319
5591
|
await this.waitForStatusChange();
|
5592
|
+
this.unsetResourceCache();
|
5320
5593
|
return this.assembleResult(contractsAbiMap);
|
5321
5594
|
}
|
5322
5595
|
/**
|
@@ -5369,32 +5642,48 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
5369
5642
|
};
|
5370
5643
|
}
|
5371
5644
|
|
5645
|
+
// src/providers/utils/helpers.ts
|
5646
|
+
var adjustResourcesToExclude = (params) => {
|
5647
|
+
const { userInput, cached, maxInputs } = params;
|
5648
|
+
const final = { ...userInput };
|
5649
|
+
let total = final.utxos.length + final.messages.length;
|
5650
|
+
if (total >= maxInputs) {
|
5651
|
+
return final;
|
5652
|
+
}
|
5653
|
+
final.utxos = [...final.utxos, ...cached.utxos.slice(0, maxInputs - total)];
|
5654
|
+
total = final.utxos.length + final.messages.length;
|
5655
|
+
if (total < maxInputs) {
|
5656
|
+
final.messages = [...final.messages, ...cached.messages.slice(0, maxInputs - total)];
|
5657
|
+
}
|
5658
|
+
return final;
|
5659
|
+
};
|
5660
|
+
|
5372
5661
|
// src/providers/utils/validate-pagination-args.ts
|
5373
|
-
var
|
5662
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5374
5663
|
var validatePaginationArgs = (params) => {
|
5375
5664
|
const { paginationLimit, inputArgs = {} } = params;
|
5376
5665
|
const { first, last, after, before } = inputArgs;
|
5377
5666
|
if (after && before) {
|
5378
|
-
throw new
|
5379
|
-
|
5667
|
+
throw new import_errors19.FuelError(
|
5668
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5380
5669
|
'Pagination arguments "after" and "before" cannot be used together'
|
5381
5670
|
);
|
5382
5671
|
}
|
5383
5672
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5384
|
-
throw new
|
5385
|
-
|
5673
|
+
throw new import_errors19.FuelError(
|
5674
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5386
5675
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5387
5676
|
);
|
5388
5677
|
}
|
5389
5678
|
if (first && before) {
|
5390
|
-
throw new
|
5391
|
-
|
5679
|
+
throw new import_errors19.FuelError(
|
5680
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5392
5681
|
'The use of pagination argument "first" with "before" is not supported'
|
5393
5682
|
);
|
5394
5683
|
}
|
5395
5684
|
if (last && after) {
|
5396
|
-
throw new
|
5397
|
-
|
5685
|
+
throw new import_errors19.FuelError(
|
5686
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5398
5687
|
'The use of pagination argument "last" with "after" is not supported'
|
5399
5688
|
);
|
5400
5689
|
}
|
@@ -5408,64 +5697,10 @@ var validatePaginationArgs = (params) => {
|
|
5408
5697
|
var MAX_RETRIES = 10;
|
5409
5698
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
5410
5699
|
var TRANSACTIONS_PAGE_SIZE_LIMIT = 60;
|
5700
|
+
var BALANCES_PAGE_SIZE_LIMIT = 100;
|
5411
5701
|
var BLOCKS_PAGE_SIZE_LIMIT = 5;
|
5412
5702
|
var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
|
5413
5703
|
var GAS_USED_MODIFIER = 1.2;
|
5414
|
-
var processGqlChain = (chain) => {
|
5415
|
-
const { name, daHeight, consensusParameters } = chain;
|
5416
|
-
const {
|
5417
|
-
contractParams,
|
5418
|
-
feeParams,
|
5419
|
-
predicateParams,
|
5420
|
-
scriptParams,
|
5421
|
-
txParams,
|
5422
|
-
gasCosts,
|
5423
|
-
baseAssetId,
|
5424
|
-
chainId,
|
5425
|
-
version
|
5426
|
-
} = consensusParameters;
|
5427
|
-
return {
|
5428
|
-
name,
|
5429
|
-
baseChainHeight: (0, import_math18.bn)(daHeight),
|
5430
|
-
consensusParameters: {
|
5431
|
-
version,
|
5432
|
-
chainId: (0, import_math18.bn)(chainId),
|
5433
|
-
baseAssetId,
|
5434
|
-
feeParameters: {
|
5435
|
-
version: feeParams.version,
|
5436
|
-
gasPerByte: (0, import_math18.bn)(feeParams.gasPerByte),
|
5437
|
-
gasPriceFactor: (0, import_math18.bn)(feeParams.gasPriceFactor)
|
5438
|
-
},
|
5439
|
-
contractParameters: {
|
5440
|
-
version: contractParams.version,
|
5441
|
-
contractMaxSize: (0, import_math18.bn)(contractParams.contractMaxSize),
|
5442
|
-
maxStorageSlots: (0, import_math18.bn)(contractParams.maxStorageSlots)
|
5443
|
-
},
|
5444
|
-
txParameters: {
|
5445
|
-
version: txParams.version,
|
5446
|
-
maxInputs: (0, import_math18.bn)(txParams.maxInputs),
|
5447
|
-
maxOutputs: (0, import_math18.bn)(txParams.maxOutputs),
|
5448
|
-
maxWitnesses: (0, import_math18.bn)(txParams.maxWitnesses),
|
5449
|
-
maxGasPerTx: (0, import_math18.bn)(txParams.maxGasPerTx),
|
5450
|
-
maxSize: (0, import_math18.bn)(txParams.maxSize),
|
5451
|
-
maxBytecodeSubsections: (0, import_math18.bn)(txParams.maxBytecodeSubsections)
|
5452
|
-
},
|
5453
|
-
predicateParameters: {
|
5454
|
-
version: predicateParams.version,
|
5455
|
-
maxPredicateLength: (0, import_math18.bn)(predicateParams.maxPredicateLength),
|
5456
|
-
maxPredicateDataLength: (0, import_math18.bn)(predicateParams.maxPredicateDataLength),
|
5457
|
-
maxGasPerPredicate: (0, import_math18.bn)(predicateParams.maxGasPerPredicate),
|
5458
|
-
maxMessageDataLength: (0, import_math18.bn)(predicateParams.maxMessageDataLength)
|
5459
|
-
},
|
5460
|
-
scriptParameters: {
|
5461
|
-
version: scriptParams.version,
|
5462
|
-
maxScriptLength: (0, import_math18.bn)(scriptParams.maxScriptLength),
|
5463
|
-
maxScriptDataLength: (0, import_math18.bn)(scriptParams.maxScriptDataLength)
|
5464
|
-
},
|
5465
|
-
gasCosts
|
5466
|
-
}
|
5467
|
-
};
|
5468
|
-
};
|
5469
5704
|
var _cacheInputs, cacheInputs_fn;
|
5470
5705
|
var _Provider = class {
|
5471
5706
|
/**
|
@@ -5487,13 +5722,19 @@ var _Provider = class {
|
|
5487
5722
|
/** @hidden */
|
5488
5723
|
__publicField(this, "urlWithoutAuth");
|
5489
5724
|
/** @hidden */
|
5725
|
+
__publicField(this, "features", {
|
5726
|
+
balancePagination: false,
|
5727
|
+
amount128: false
|
5728
|
+
});
|
5729
|
+
/** @hidden */
|
5490
5730
|
__publicField(this, "consensusParametersTimestamp");
|
5491
5731
|
__publicField(this, "options", {
|
5492
5732
|
timeout: void 0,
|
5493
5733
|
resourceCacheTTL: void 0,
|
5494
5734
|
fetch: void 0,
|
5495
5735
|
retryOptions: void 0,
|
5496
|
-
headers: void 0
|
5736
|
+
headers: void 0,
|
5737
|
+
cache: void 0
|
5497
5738
|
});
|
5498
5739
|
const { url: rawUrl, urlWithoutAuth, headers: authHeaders } = _Provider.extractBasicAuth(url);
|
5499
5740
|
this.url = rawUrl;
|
@@ -5507,7 +5748,13 @@ var _Provider = class {
|
|
5507
5748
|
headers
|
5508
5749
|
};
|
5509
5750
|
this.operations = this.createOperations();
|
5510
|
-
const { resourceCacheTTL } = this.options;
|
5751
|
+
const { resourceCacheTTL, cache: cache2 } = this.options;
|
5752
|
+
if (cache2) {
|
5753
|
+
const { consensusParametersTimestamp, chain, nodeInfo } = deserializeProviderCache(cache2);
|
5754
|
+
this.consensusParametersTimestamp = consensusParametersTimestamp;
|
5755
|
+
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
5756
|
+
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
5757
|
+
}
|
5511
5758
|
if ((0, import_utils29.isDefined)(resourceCacheTTL)) {
|
5512
5759
|
if (resourceCacheTTL !== -1) {
|
5513
5760
|
this.cache = new ResourceCache(resourceCacheTTL);
|
@@ -5520,6 +5767,7 @@ var _Provider = class {
|
|
5520
5767
|
}
|
5521
5768
|
/** @hidden */
|
5522
5769
|
static clearChainAndNodeCaches() {
|
5770
|
+
_Provider.inflightFetchChainAndNodeInfoRequests = {};
|
5523
5771
|
_Provider.nodeInfoCache = {};
|
5524
5772
|
_Provider.chainInfoCache = {};
|
5525
5773
|
}
|
@@ -5548,7 +5796,7 @@ var _Provider = class {
|
|
5548
5796
|
try {
|
5549
5797
|
parsedUrl = new URL(url);
|
5550
5798
|
} catch (error) {
|
5551
|
-
throw new
|
5799
|
+
throw new import_errors20.FuelError(import_errors20.FuelError.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
|
5552
5800
|
}
|
5553
5801
|
const username = parsedUrl.username;
|
5554
5802
|
const password = parsedUrl.password;
|
@@ -5566,7 +5814,8 @@ var _Provider = class {
|
|
5566
5814
|
* Initialize Provider async stuff
|
5567
5815
|
*/
|
5568
5816
|
async init() {
|
5569
|
-
await this.fetchChainAndNodeInfo();
|
5817
|
+
const { nodeInfo } = await this.fetchChainAndNodeInfo();
|
5818
|
+
this.setupFeatures(nodeInfo.nodeVersion);
|
5570
5819
|
return this;
|
5571
5820
|
}
|
5572
5821
|
/**
|
@@ -5636,19 +5885,24 @@ var _Provider = class {
|
|
5636
5885
|
throw new Error(`Jumps to the catch block and re-fetch`);
|
5637
5886
|
}
|
5638
5887
|
} catch (_err) {
|
5888
|
+
const inflightRequest = _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];
|
5889
|
+
if (inflightRequest) {
|
5890
|
+
const now2 = await inflightRequest;
|
5891
|
+
this.consensusParametersTimestamp = now2;
|
5892
|
+
return this.fetchChainAndNodeInfo();
|
5893
|
+
}
|
5894
|
+
const { promise, resolve } = deferPromise();
|
5895
|
+
_Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth] = promise;
|
5639
5896
|
const data = await this.operations.getChainAndNodeInfo();
|
5640
|
-
nodeInfo =
|
5641
|
-
|
5642
|
-
maxTx: (0, import_math18.bn)(data.nodeInfo.maxTx),
|
5643
|
-
nodeVersion: data.nodeInfo.nodeVersion,
|
5644
|
-
utxoValidation: data.nodeInfo.utxoValidation,
|
5645
|
-
vmBacktrace: data.nodeInfo.vmBacktrace
|
5646
|
-
};
|
5897
|
+
nodeInfo = deserializeNodeInfo(data.nodeInfo);
|
5898
|
+
chain = deserializeChain(data.chain);
|
5647
5899
|
_Provider.setIncompatibleNodeVersionMessage(nodeInfo);
|
5648
|
-
chain = processGqlChain(data.chain);
|
5649
5900
|
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
5650
5901
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
5651
|
-
|
5902
|
+
const now = Date.now();
|
5903
|
+
this.consensusParametersTimestamp = now;
|
5904
|
+
resolve(now);
|
5905
|
+
delete _Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];
|
5652
5906
|
}
|
5653
5907
|
return {
|
5654
5908
|
chain,
|
@@ -5723,6 +5977,15 @@ var _Provider = class {
|
|
5723
5977
|
});
|
5724
5978
|
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
5725
5979
|
}
|
5980
|
+
/**
|
5981
|
+
* @hidden
|
5982
|
+
*/
|
5983
|
+
setupFeatures(nodeVersion) {
|
5984
|
+
if ((0, import_versions.gte)(nodeVersion, "0.41.0")) {
|
5985
|
+
this.features.balancePagination = true;
|
5986
|
+
this.features.amount128 = true;
|
5987
|
+
}
|
5988
|
+
}
|
5726
5989
|
/**
|
5727
5990
|
* Returns the version of the connected node.
|
5728
5991
|
*
|
@@ -5754,13 +6017,7 @@ var _Provider = class {
|
|
5754
6017
|
*/
|
5755
6018
|
async fetchNode() {
|
5756
6019
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
5757
|
-
const processedNodeInfo =
|
5758
|
-
maxDepth: (0, import_math18.bn)(nodeInfo.maxDepth),
|
5759
|
-
maxTx: (0, import_math18.bn)(nodeInfo.maxTx),
|
5760
|
-
nodeVersion: nodeInfo.nodeVersion,
|
5761
|
-
utxoValidation: nodeInfo.utxoValidation,
|
5762
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
5763
|
-
};
|
6020
|
+
const processedNodeInfo = deserializeNodeInfo(nodeInfo);
|
5764
6021
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = processedNodeInfo;
|
5765
6022
|
return processedNodeInfo;
|
5766
6023
|
}
|
@@ -5771,7 +6028,7 @@ var _Provider = class {
|
|
5771
6028
|
*/
|
5772
6029
|
async fetchChain() {
|
5773
6030
|
const { chain } = await this.operations.getChain();
|
5774
|
-
const processedChain =
|
6031
|
+
const processedChain = deserializeChain(chain);
|
5775
6032
|
_Provider.chainInfoCache[this.urlWithoutAuth] = processedChain;
|
5776
6033
|
return processedChain;
|
5777
6034
|
}
|
@@ -5798,6 +6055,21 @@ var _Provider = class {
|
|
5798
6055
|
} = all;
|
5799
6056
|
return baseAssetId;
|
5800
6057
|
}
|
6058
|
+
/**
|
6059
|
+
* Retrieves the details of an asset given its ID.
|
6060
|
+
*
|
6061
|
+
* @param assetId - The unique identifier of the asset.
|
6062
|
+
* @returns A promise that resolves to an object containing the asset details.
|
6063
|
+
*/
|
6064
|
+
async getAssetDetails(assetId) {
|
6065
|
+
const { assetDetails } = await this.operations.getAssetDetails({ assetId });
|
6066
|
+
const { contractId, subId, totalSupply } = assetDetails;
|
6067
|
+
return {
|
6068
|
+
subId,
|
6069
|
+
contractId,
|
6070
|
+
totalSupply: (0, import_math18.bn)(totalSupply)
|
6071
|
+
};
|
6072
|
+
}
|
5801
6073
|
/**
|
5802
6074
|
* @hidden
|
5803
6075
|
*/
|
@@ -5808,14 +6080,14 @@ var _Provider = class {
|
|
5808
6080
|
}
|
5809
6081
|
} = await this.getChain();
|
5810
6082
|
if ((0, import_math18.bn)(tx.inputs.length).gt(maxInputs)) {
|
5811
|
-
throw new
|
5812
|
-
|
6083
|
+
throw new import_errors20.FuelError(
|
6084
|
+
import_errors20.ErrorCode.MAX_INPUTS_EXCEEDED,
|
5813
6085
|
`The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
|
5814
6086
|
);
|
5815
6087
|
}
|
5816
6088
|
if ((0, import_math18.bn)(tx.outputs.length).gt(maxOutputs)) {
|
5817
|
-
throw new
|
5818
|
-
|
6089
|
+
throw new import_errors20.FuelError(
|
6090
|
+
import_errors20.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
5819
6091
|
`The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
|
5820
6092
|
);
|
5821
6093
|
}
|
@@ -5872,22 +6144,20 @@ var _Provider = class {
|
|
5872
6144
|
utxoValidation: utxoValidation || false
|
5873
6145
|
});
|
5874
6146
|
const [{ receipts: rawReceipts, status: dryRunStatus }] = dryRunStatuses;
|
5875
|
-
const receipts = rawReceipts.map(
|
6147
|
+
const receipts = rawReceipts.map(deserializeReceipt);
|
5876
6148
|
return { receipts, dryRunStatus };
|
5877
6149
|
}
|
5878
6150
|
/**
|
5879
|
-
*
|
6151
|
+
* Estimates the gas usage for predicates in a transaction request.
|
5880
6152
|
*
|
5881
6153
|
* @template T - The type of the transaction request object.
|
5882
6154
|
*
|
5883
|
-
* @param transactionRequest - The transaction request
|
5884
|
-
* @returns A promise that resolves to the
|
6155
|
+
* @param transactionRequest - The transaction request to estimate predicates for.
|
6156
|
+
* @returns A promise that resolves to the updated transaction request with estimated gas usage for predicates.
|
5885
6157
|
*/
|
5886
6158
|
async estimatePredicates(transactionRequest) {
|
5887
|
-
const shouldEstimatePredicates =
|
5888
|
-
|
5889
|
-
(input) => "predicate" in input && input.predicate && !(0, import_utils30.equalBytes)((0, import_utils29.arrayify)(input.predicate), (0, import_utils29.arrayify)("0x")) && new import_math18.BN(input.predicateGasUsed).isZero()
|
5890
|
-
)
|
6159
|
+
const shouldEstimatePredicates = transactionRequest.inputs.some(
|
6160
|
+
(input) => isPredicate(input) && (0, import_math18.bn)(input.predicateGasUsed).isZero()
|
5891
6161
|
);
|
5892
6162
|
if (!shouldEstimatePredicates) {
|
5893
6163
|
return transactionRequest;
|
@@ -5896,18 +6166,42 @@ var _Provider = class {
|
|
5896
6166
|
const response = await this.operations.estimatePredicates({
|
5897
6167
|
encodedTransaction
|
5898
6168
|
});
|
5899
|
-
const {
|
5900
|
-
|
5901
|
-
|
5902
|
-
|
5903
|
-
|
5904
|
-
if ("predicateGasUsed" in input && (0, import_math18.bn)(input.predicateGasUsed).gt(0)) {
|
5905
|
-
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
5906
|
-
}
|
5907
|
-
});
|
5908
|
-
}
|
6169
|
+
const { estimatePredicates } = response;
|
6170
|
+
transactionRequest = this.parseEstimatePredicatesResponse(
|
6171
|
+
transactionRequest,
|
6172
|
+
estimatePredicates
|
6173
|
+
);
|
5909
6174
|
return transactionRequest;
|
5910
6175
|
}
|
6176
|
+
/**
|
6177
|
+
* Estimates the gas price and predicates for a given transaction request and block horizon.
|
6178
|
+
*
|
6179
|
+
* @param transactionRequest - The transaction request to estimate predicates and gas price for.
|
6180
|
+
* @param blockHorizon - The block horizon to use for gas price estimation.
|
6181
|
+
* @returns A promise that resolves to an object containing the updated transaction
|
6182
|
+
* request and the estimated gas price.
|
6183
|
+
*/
|
6184
|
+
async estimatePredicatesAndGasPrice(transactionRequest, blockHorizon) {
|
6185
|
+
const shouldEstimatePredicates = transactionRequest.inputs.some(
|
6186
|
+
(input) => isPredicate(input) && (0, import_math18.bn)(input.predicateGasUsed).isZero()
|
6187
|
+
);
|
6188
|
+
if (!shouldEstimatePredicates) {
|
6189
|
+
const gasPrice2 = await this.estimateGasPrice(blockHorizon);
|
6190
|
+
return { transactionRequest, gasPrice: gasPrice2 };
|
6191
|
+
}
|
6192
|
+
const {
|
6193
|
+
estimateGasPrice: { gasPrice },
|
6194
|
+
estimatePredicates
|
6195
|
+
} = await this.operations.estimatePredicatesAndGasPrice({
|
6196
|
+
blockHorizon: String(blockHorizon),
|
6197
|
+
encodedTransaction: (0, import_utils29.hexlify)(transactionRequest.toTransactionBytes())
|
6198
|
+
});
|
6199
|
+
transactionRequest = this.parseEstimatePredicatesResponse(
|
6200
|
+
transactionRequest,
|
6201
|
+
estimatePredicates
|
6202
|
+
);
|
6203
|
+
return { transactionRequest, gasPrice: (0, import_math18.bn)(gasPrice) };
|
6204
|
+
}
|
5911
6205
|
/**
|
5912
6206
|
* Will dryRun a transaction and check for missing dependencies.
|
5913
6207
|
*
|
@@ -5921,11 +6215,13 @@ var _Provider = class {
|
|
5921
6215
|
async estimateTxDependencies(transactionRequest, { gasPrice: gasPriceParam } = {}) {
|
5922
6216
|
if (isTransactionTypeCreate(transactionRequest)) {
|
5923
6217
|
return {
|
6218
|
+
rawReceipts: [],
|
5924
6219
|
receipts: [],
|
5925
6220
|
outputVariables: 0,
|
5926
6221
|
missingContractIds: []
|
5927
6222
|
};
|
5928
6223
|
}
|
6224
|
+
let rawReceipts = [];
|
5929
6225
|
let receipts = [];
|
5930
6226
|
const missingContractIds = [];
|
5931
6227
|
let outputVariables = 0;
|
@@ -5934,13 +6230,14 @@ var _Provider = class {
|
|
5934
6230
|
const gasPrice = gasPriceParam ?? await this.estimateGasPrice(10);
|
5935
6231
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
5936
6232
|
const {
|
5937
|
-
dryRun: [{ receipts:
|
6233
|
+
dryRun: [{ receipts: serializedReceipts, status }]
|
5938
6234
|
} = await this.operations.dryRun({
|
5939
6235
|
encodedTransactions: [(0, import_utils29.hexlify)(transactionRequest.toTransactionBytes())],
|
5940
6236
|
utxoValidation: false,
|
5941
6237
|
gasPrice: gasPrice.toString()
|
5942
6238
|
});
|
5943
|
-
|
6239
|
+
rawReceipts = serializedReceipts;
|
6240
|
+
receipts = serializedReceipts.map(deserializeReceipt);
|
5944
6241
|
dryRunStatus = status;
|
5945
6242
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
5946
6243
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
@@ -5961,6 +6258,7 @@ var _Provider = class {
|
|
5961
6258
|
}
|
5962
6259
|
}
|
5963
6260
|
return {
|
6261
|
+
rawReceipts,
|
5964
6262
|
receipts,
|
5965
6263
|
outputVariables,
|
5966
6264
|
missingContractIds,
|
@@ -5979,6 +6277,7 @@ var _Provider = class {
|
|
5979
6277
|
*/
|
5980
6278
|
async estimateMultipleTxDependencies(transactionRequests) {
|
5981
6279
|
const results = transactionRequests.map(() => ({
|
6280
|
+
rawReceipts: [],
|
5982
6281
|
receipts: [],
|
5983
6282
|
outputVariables: 0,
|
5984
6283
|
missingContractIds: [],
|
@@ -6006,7 +6305,7 @@ var _Provider = class {
|
|
6006
6305
|
const requestIdx = transactionsToProcess[i];
|
6007
6306
|
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
6008
6307
|
const result = results[requestIdx];
|
6009
|
-
result.receipts = rawReceipts.map(
|
6308
|
+
result.receipts = rawReceipts.map(deserializeReceipt);
|
6010
6309
|
result.dryRunStatus = status;
|
6011
6310
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
6012
6311
|
result.receipts
|
@@ -6051,7 +6350,7 @@ var _Provider = class {
|
|
6051
6350
|
utxoValidation: utxoValidation || false
|
6052
6351
|
});
|
6053
6352
|
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
6054
|
-
const receipts = rawReceipts.map(
|
6353
|
+
const receipts = rawReceipts.map(deserializeReceipt);
|
6055
6354
|
return { receipts, dryRunStatus: status };
|
6056
6355
|
});
|
6057
6356
|
return results;
|
@@ -6152,7 +6451,7 @@ var _Provider = class {
|
|
6152
6451
|
});
|
6153
6452
|
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
6154
6453
|
const { id, receipts, status } = dryRunStatus;
|
6155
|
-
const processedReceipts = receipts.map(
|
6454
|
+
const processedReceipts = receipts.map(deserializeReceipt);
|
6156
6455
|
return { id, receipts: processedReceipts, status };
|
6157
6456
|
});
|
6158
6457
|
return { receipts: callResult[0].receipts };
|
@@ -6183,14 +6482,20 @@ var _Provider = class {
|
|
6183
6482
|
await signatureCallback(signedRequest);
|
6184
6483
|
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
6185
6484
|
}
|
6186
|
-
|
6485
|
+
let gasPrice;
|
6486
|
+
if (gasPriceParam) {
|
6487
|
+
gasPrice = gasPriceParam;
|
6488
|
+
await this.estimatePredicates(signedRequest);
|
6489
|
+
} else {
|
6490
|
+
({ gasPrice } = await this.estimatePredicatesAndGasPrice(signedRequest, 10));
|
6491
|
+
}
|
6187
6492
|
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
6188
|
-
const gasPrice = gasPriceParam ?? await this.estimateGasPrice(10);
|
6189
6493
|
let { maxFee, maxGas, minFee, minGas, gasLimit } = await this.estimateTxGasAndFee({
|
6190
6494
|
// Fetches and returns a gas price
|
6191
6495
|
transactionRequest: signedRequest,
|
6192
6496
|
gasPrice
|
6193
6497
|
});
|
6498
|
+
let rawReceipts = [];
|
6194
6499
|
let receipts = [];
|
6195
6500
|
let dryRunStatus;
|
6196
6501
|
let missingContractIds = [];
|
@@ -6202,7 +6507,7 @@ var _Provider = class {
|
|
6202
6507
|
if (signatureCallback) {
|
6203
6508
|
await signatureCallback(txRequestClone);
|
6204
6509
|
}
|
6205
|
-
({ receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone, { gasPrice }));
|
6510
|
+
({ rawReceipts, receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone, { gasPrice }));
|
6206
6511
|
if (dryRunStatus && "reason" in dryRunStatus) {
|
6207
6512
|
throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
|
6208
6513
|
}
|
@@ -6215,7 +6520,12 @@ var _Provider = class {
|
|
6215
6520
|
gasPrice
|
6216
6521
|
}));
|
6217
6522
|
}
|
6523
|
+
const transactionSummary = {
|
6524
|
+
gasPrice: gasPrice.toString(),
|
6525
|
+
receipts: rawReceipts
|
6526
|
+
};
|
6218
6527
|
return {
|
6528
|
+
rawReceipts,
|
6219
6529
|
receipts,
|
6220
6530
|
gasUsed,
|
6221
6531
|
gasPrice,
|
@@ -6228,7 +6538,8 @@ var _Provider = class {
|
|
6228
6538
|
addedSignatures,
|
6229
6539
|
estimatedPredicates: txRequestClone.inputs,
|
6230
6540
|
dryRunStatus,
|
6231
|
-
updateMaxFee
|
6541
|
+
updateMaxFee,
|
6542
|
+
transactionSummary
|
6232
6543
|
};
|
6233
6544
|
}
|
6234
6545
|
/**
|
@@ -6274,23 +6585,33 @@ var _Provider = class {
|
|
6274
6585
|
*/
|
6275
6586
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
6276
6587
|
const ownerAddress = new import_address3.Address(owner);
|
6277
|
-
|
6588
|
+
let idsToExclude = {
|
6278
6589
|
messages: excludedIds?.messages?.map((nonce) => (0, import_utils29.hexlify)(nonce)) || [],
|
6279
6590
|
utxos: excludedIds?.utxos?.map((id) => (0, import_utils29.hexlify)(id)) || []
|
6280
6591
|
};
|
6281
6592
|
if (this.cache) {
|
6282
|
-
const cached = this.cache.getActiveData();
|
6283
|
-
|
6284
|
-
|
6593
|
+
const cached = this.cache.getActiveData(ownerAddress.toB256());
|
6594
|
+
if (cached.utxos.length || cached.messages.length) {
|
6595
|
+
const {
|
6596
|
+
consensusParameters: {
|
6597
|
+
txParameters: { maxInputs }
|
6598
|
+
}
|
6599
|
+
} = await this.getChain();
|
6600
|
+
idsToExclude = adjustResourcesToExclude({
|
6601
|
+
userInput: idsToExclude,
|
6602
|
+
cached,
|
6603
|
+
maxInputs: maxInputs.toNumber()
|
6604
|
+
});
|
6605
|
+
}
|
6285
6606
|
}
|
6286
6607
|
const coinsQuery = {
|
6287
6608
|
owner: ownerAddress.toB256(),
|
6288
6609
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
6289
6610
|
assetId: (0, import_utils29.hexlify)(assetId),
|
6290
|
-
amount: amount.toString(10),
|
6611
|
+
amount: (amount.eqn(0) ? (0, import_math18.bn)(1) : amount).toString(10),
|
6291
6612
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
6292
6613
|
})),
|
6293
|
-
excludedIds:
|
6614
|
+
excludedIds: idsToExclude
|
6294
6615
|
};
|
6295
6616
|
const result = await this.operations.getCoinsToSpend(coinsQuery);
|
6296
6617
|
const coins = result.coinsToSpend.flat().map((coin) => {
|
@@ -6348,7 +6669,7 @@ var _Provider = class {
|
|
6348
6669
|
} = await this.operations.getLatestBlock();
|
6349
6670
|
block = latestBlock;
|
6350
6671
|
} else {
|
6351
|
-
const isblockId = typeof idOrHeight === "string" && idOrHeight
|
6672
|
+
const isblockId = typeof idOrHeight === "string" && (0, import_address3.isB256)(idOrHeight);
|
6352
6673
|
const variables = isblockId ? { blockId: idOrHeight } : { height: (0, import_math18.bn)(idOrHeight).toString(10) };
|
6353
6674
|
const response = await this.operations.getBlock(variables);
|
6354
6675
|
block = response.block;
|
@@ -6419,8 +6740,10 @@ var _Provider = class {
|
|
6419
6740
|
variables = { blockHeight: (0, import_math18.bn)(idOrHeight).toString(10) };
|
6420
6741
|
} else if (idOrHeight === "latest") {
|
6421
6742
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
6422
|
-
} else {
|
6743
|
+
} else if (typeof idOrHeight === "string" && (0, import_address3.isB256)(idOrHeight)) {
|
6423
6744
|
variables = { blockId: idOrHeight };
|
6745
|
+
} else {
|
6746
|
+
variables = { blockHeight: (0, import_math18.bn)(idOrHeight).toString() };
|
6424
6747
|
}
|
6425
6748
|
const { block } = await this.operations.getBlockWithTransactions(variables);
|
6426
6749
|
if (!block) {
|
@@ -6442,7 +6765,7 @@ var _Provider = class {
|
|
6442
6765
|
},
|
6443
6766
|
transactionIds: block.transactions.map((tx) => tx.id),
|
6444
6767
|
transactions: block.transactions.map(
|
6445
|
-
(tx) => new
|
6768
|
+
(tx) => new import_transactions23.TransactionCoder().decode((0, import_utils29.arrayify)(tx.rawPayload), 0)?.[0]
|
6446
6769
|
)
|
6447
6770
|
};
|
6448
6771
|
}
|
@@ -6458,12 +6781,12 @@ var _Provider = class {
|
|
6458
6781
|
return null;
|
6459
6782
|
}
|
6460
6783
|
try {
|
6461
|
-
return new
|
6784
|
+
return new import_transactions23.TransactionCoder().decode(
|
6462
6785
|
(0, import_utils29.arrayify)(transaction.rawPayload),
|
6463
6786
|
0
|
6464
6787
|
)?.[0];
|
6465
6788
|
} catch (error) {
|
6466
|
-
if (error instanceof
|
6789
|
+
if (error instanceof import_errors20.FuelError && error.code === import_errors20.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
6467
6790
|
console.warn("Unsupported transaction type encountered");
|
6468
6791
|
return null;
|
6469
6792
|
}
|
@@ -6484,12 +6807,12 @@ var _Provider = class {
|
|
6484
6807
|
paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
|
6485
6808
|
})
|
6486
6809
|
});
|
6487
|
-
const coder = new
|
6810
|
+
const coder = new import_transactions23.TransactionCoder();
|
6488
6811
|
const transactions = edges.map(({ node: { rawPayload } }) => {
|
6489
6812
|
try {
|
6490
6813
|
return coder.decode((0, import_utils29.arrayify)(rawPayload), 0)[0];
|
6491
6814
|
} catch (error) {
|
6492
|
-
if (error instanceof
|
6815
|
+
if (error instanceof import_errors20.FuelError && error.code === import_errors20.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
6493
6816
|
console.warn("Unsupported transaction type encountered");
|
6494
6817
|
return null;
|
6495
6818
|
}
|
@@ -6548,11 +6871,20 @@ var _Provider = class {
|
|
6548
6871
|
* @returns A promise that resolves to the balance.
|
6549
6872
|
*/
|
6550
6873
|
async getBalance(owner, assetId) {
|
6551
|
-
const
|
6552
|
-
|
6553
|
-
|
6874
|
+
const ownerStr = new import_address3.Address(owner).toB256();
|
6875
|
+
const assetIdStr = (0, import_utils29.hexlify)(assetId);
|
6876
|
+
if (!this.features.amount128) {
|
6877
|
+
const { balance: balance2 } = await this.operations.getBalance({
|
6878
|
+
owner: ownerStr,
|
6879
|
+
assetId: assetIdStr
|
6880
|
+
});
|
6881
|
+
return (0, import_math18.bn)(balance2.amount, 10);
|
6882
|
+
}
|
6883
|
+
const { balance } = await this.operations.getBalanceV2({
|
6884
|
+
owner: ownerStr,
|
6885
|
+
assetId: assetIdStr
|
6554
6886
|
});
|
6555
|
-
return (0, import_math18.bn)(balance.
|
6887
|
+
return (0, import_math18.bn)(balance.amountU128, 10);
|
6556
6888
|
}
|
6557
6889
|
/**
|
6558
6890
|
* Returns balances for the given owner.
|
@@ -6561,7 +6893,16 @@ var _Provider = class {
|
|
6561
6893
|
* @param paginationArgs - Pagination arguments (optional).
|
6562
6894
|
* @returns A promise that resolves to the balances.
|
6563
6895
|
*/
|
6564
|
-
async getBalances(owner) {
|
6896
|
+
async getBalances(owner, paginationArgs) {
|
6897
|
+
if (!this.features.balancePagination) {
|
6898
|
+
return this.getBalancesV1(owner, paginationArgs);
|
6899
|
+
}
|
6900
|
+
return this.getBalancesV2(owner, paginationArgs);
|
6901
|
+
}
|
6902
|
+
/**
|
6903
|
+
* @hidden
|
6904
|
+
*/
|
6905
|
+
async getBalancesV1(owner, _paginationArgs) {
|
6565
6906
|
const {
|
6566
6907
|
balances: { edges }
|
6567
6908
|
} = await this.operations.getBalances({
|
@@ -6578,6 +6919,25 @@ var _Provider = class {
|
|
6578
6919
|
}));
|
6579
6920
|
return { balances };
|
6580
6921
|
}
|
6922
|
+
/**
|
6923
|
+
* @hidden
|
6924
|
+
*/
|
6925
|
+
async getBalancesV2(owner, paginationArgs) {
|
6926
|
+
const {
|
6927
|
+
balances: { edges, pageInfo }
|
6928
|
+
} = await this.operations.getBalancesV2({
|
6929
|
+
...validatePaginationArgs({
|
6930
|
+
inputArgs: paginationArgs,
|
6931
|
+
paginationLimit: BALANCES_PAGE_SIZE_LIMIT
|
6932
|
+
}),
|
6933
|
+
filter: { owner: new import_address3.Address(owner).toB256() }
|
6934
|
+
});
|
6935
|
+
const balances = edges.map(({ node }) => ({
|
6936
|
+
assetId: node.assetId,
|
6937
|
+
amount: (0, import_math18.bn)(node.amountU128)
|
6938
|
+
}));
|
6939
|
+
return { balances, pageInfo };
|
6940
|
+
}
|
6581
6941
|
/**
|
6582
6942
|
* Returns message for the given address.
|
6583
6943
|
*
|
@@ -6596,7 +6956,7 @@ var _Provider = class {
|
|
6596
6956
|
owner: new import_address3.Address(address).toB256()
|
6597
6957
|
});
|
6598
6958
|
const messages = edges.map(({ node }) => ({
|
6599
|
-
messageId:
|
6959
|
+
messageId: import_transactions23.InputMessageCoder.getMessageId({
|
6600
6960
|
sender: node.sender,
|
6601
6961
|
recipient: node.recipient,
|
6602
6962
|
nonce: node.nonce,
|
@@ -6607,7 +6967,7 @@ var _Provider = class {
|
|
6607
6967
|
recipient: new import_address3.Address(node.recipient),
|
6608
6968
|
nonce: node.nonce,
|
6609
6969
|
amount: (0, import_math18.bn)(node.amount),
|
6610
|
-
data:
|
6970
|
+
data: import_transactions23.InputMessageCoder.decodeData(node.data),
|
6611
6971
|
daHeight: (0, import_math18.bn)(node.daHeight)
|
6612
6972
|
}));
|
6613
6973
|
return {
|
@@ -6630,8 +6990,8 @@ var _Provider = class {
|
|
6630
6990
|
nonce
|
6631
6991
|
};
|
6632
6992
|
if (commitBlockId && commitBlockHeight) {
|
6633
|
-
throw new
|
6634
|
-
|
6993
|
+
throw new import_errors20.FuelError(
|
6994
|
+
import_errors20.ErrorCode.INVALID_INPUT_PARAMETERS,
|
6635
6995
|
"commitBlockId and commitBlockHeight cannot be used together"
|
6636
6996
|
);
|
6637
6997
|
}
|
@@ -6644,15 +7004,12 @@ var _Provider = class {
|
|
6644
7004
|
if (commitBlockHeight) {
|
6645
7005
|
inputObject = {
|
6646
7006
|
...inputObject,
|
6647
|
-
//
|
6648
|
-
// This should
|
7007
|
+
// Convert BN into a number string required on the query
|
7008
|
+
// This should probably be fixed on the fuel client side
|
6649
7009
|
commitBlockHeight: commitBlockHeight.toNumber().toString()
|
6650
7010
|
};
|
6651
7011
|
}
|
6652
7012
|
const result = await this.operations.getMessageProof(inputObject);
|
6653
|
-
if (!result.messageProof) {
|
6654
|
-
return null;
|
6655
|
-
}
|
6656
7013
|
const {
|
6657
7014
|
messageProof,
|
6658
7015
|
messageBlockHeader,
|
@@ -6761,16 +7118,15 @@ var _Provider = class {
|
|
6761
7118
|
* @returns A promise that resolves to the result of the check.
|
6762
7119
|
*/
|
6763
7120
|
async isUserAccount(id) {
|
6764
|
-
const
|
6765
|
-
|
6766
|
-
contractId: id,
|
6767
|
-
transactionId: id
|
6768
|
-
});
|
6769
|
-
if (contract || blob || transaction) {
|
6770
|
-
return false;
|
6771
|
-
}
|
6772
|
-
return true;
|
7121
|
+
const type = await this.getAddressType(id);
|
7122
|
+
return type === "Account";
|
6773
7123
|
}
|
7124
|
+
/**
|
7125
|
+
* Determines the type of address based on the provided ID.
|
7126
|
+
*
|
7127
|
+
* @param id - The ID to be checked.
|
7128
|
+
* @returns A promise that resolves to a string indicating the type of address.
|
7129
|
+
*/
|
6774
7130
|
async getAddressType(id) {
|
6775
7131
|
const { contract, blob, transaction } = await this.operations.isUserAccount({
|
6776
7132
|
blobId: id,
|
@@ -6786,6 +7142,13 @@ var _Provider = class {
|
|
6786
7142
|
if (transaction) {
|
6787
7143
|
return "Transaction";
|
6788
7144
|
}
|
7145
|
+
try {
|
7146
|
+
const asset = await this.getAssetDetails(id);
|
7147
|
+
if (asset) {
|
7148
|
+
return "Asset";
|
7149
|
+
}
|
7150
|
+
} catch (e) {
|
7151
|
+
}
|
6789
7152
|
return "Account";
|
6790
7153
|
}
|
6791
7154
|
/**
|
@@ -6810,7 +7173,7 @@ var _Provider = class {
|
|
6810
7173
|
return null;
|
6811
7174
|
}
|
6812
7175
|
const message = {
|
6813
|
-
messageId:
|
7176
|
+
messageId: import_transactions23.InputMessageCoder.getMessageId({
|
6814
7177
|
sender: rawMessage.sender,
|
6815
7178
|
recipient: rawMessage.recipient,
|
6816
7179
|
nonce,
|
@@ -6821,7 +7184,7 @@ var _Provider = class {
|
|
6821
7184
|
recipient: new import_address3.Address(rawMessage.recipient),
|
6822
7185
|
nonce,
|
6823
7186
|
amount: (0, import_math18.bn)(rawMessage.amount),
|
6824
|
-
data:
|
7187
|
+
data: import_transactions23.InputMessageCoder.decodeData(rawMessage.data),
|
6825
7188
|
daHeight: (0, import_math18.bn)(rawMessage.daHeight)
|
6826
7189
|
};
|
6827
7190
|
return message;
|
@@ -6860,6 +7223,19 @@ var _Provider = class {
|
|
6860
7223
|
statusReason: status.reason
|
6861
7224
|
});
|
6862
7225
|
}
|
7226
|
+
/**
|
7227
|
+
* @hidden
|
7228
|
+
*/
|
7229
|
+
parseEstimatePredicatesResponse(transactionRequest, { inputs }) {
|
7230
|
+
if (inputs) {
|
7231
|
+
inputs.forEach((input, i) => {
|
7232
|
+
if (input && "predicateGasUsed" in input && (0, import_math18.bn)(input.predicateGasUsed).gt(0)) {
|
7233
|
+
transactionRequest.inputs[i].predicateGasUsed = input.predicateGasUsed;
|
7234
|
+
}
|
7235
|
+
});
|
7236
|
+
}
|
7237
|
+
return transactionRequest;
|
7238
|
+
}
|
6863
7239
|
};
|
6864
7240
|
var Provider = _Provider;
|
6865
7241
|
_cacheInputs = new WeakSet();
|
@@ -6867,20 +7243,11 @@ cacheInputs_fn = function(inputs, transactionId) {
|
|
6867
7243
|
if (!this.cache) {
|
6868
7244
|
return;
|
6869
7245
|
}
|
6870
|
-
|
6871
|
-
(acc, input) => {
|
6872
|
-
if (input.type === import_transactions22.InputType.Coin) {
|
6873
|
-
acc.utxos.push(input.id);
|
6874
|
-
} else if (input.type === import_transactions22.InputType.Message) {
|
6875
|
-
acc.messages.push(input.nonce);
|
6876
|
-
}
|
6877
|
-
return acc;
|
6878
|
-
},
|
6879
|
-
{ utxos: [], messages: [] }
|
6880
|
-
);
|
6881
|
-
this.cache.set(transactionId, inputsToCache);
|
7246
|
+
this.cache.set(transactionId, inputs);
|
6882
7247
|
};
|
6883
7248
|
/** @hidden */
|
7249
|
+
__publicField(Provider, "inflightFetchChainAndNodeInfoRequests", {});
|
7250
|
+
/** @hidden */
|
6884
7251
|
__publicField(Provider, "chainInfoCache", {});
|
6885
7252
|
/** @hidden */
|
6886
7253
|
__publicField(Provider, "nodeInfoCache", {});
|
@@ -6888,30 +7255,30 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
6888
7255
|
__publicField(Provider, "incompatibleNodeVersionMessage", "");
|
6889
7256
|
|
6890
7257
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
6891
|
-
var
|
7258
|
+
var import_errors21 = require("@fuel-ts/errors");
|
6892
7259
|
var import_math19 = require("@fuel-ts/math");
|
6893
|
-
var
|
6894
|
-
var
|
7260
|
+
var import_transactions24 = require("@fuel-ts/transactions");
|
7261
|
+
var import_utils31 = require("@fuel-ts/utils");
|
6895
7262
|
async function getTransactionSummary(params) {
|
6896
7263
|
const { id, provider, abiMap } = params;
|
6897
7264
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
6898
7265
|
transactionId: id
|
6899
7266
|
});
|
6900
7267
|
if (!gqlTransaction) {
|
6901
|
-
throw new
|
6902
|
-
|
7268
|
+
throw new import_errors21.FuelError(
|
7269
|
+
import_errors21.ErrorCode.TRANSACTION_NOT_FOUND,
|
6903
7270
|
`Transaction not found for given id: ${id}.`
|
6904
7271
|
);
|
6905
7272
|
}
|
6906
|
-
const [decodedTransaction] = new
|
6907
|
-
(0,
|
7273
|
+
const [decodedTransaction] = new import_transactions24.TransactionCoder().decode(
|
7274
|
+
(0, import_utils31.arrayify)(gqlTransaction.rawPayload),
|
6908
7275
|
0
|
6909
7276
|
);
|
6910
7277
|
let txReceipts = [];
|
6911
7278
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
6912
7279
|
txReceipts = gqlTransaction.status.receipts;
|
6913
7280
|
}
|
6914
|
-
const receipts = txReceipts.map(
|
7281
|
+
const receipts = txReceipts.map(deserializeReceipt);
|
6915
7282
|
const {
|
6916
7283
|
consensusParameters: {
|
6917
7284
|
feeParameters: { gasPerByte, gasPriceFactor },
|
@@ -6926,7 +7293,7 @@ async function getTransactionSummary(params) {
|
|
6926
7293
|
id: gqlTransaction.id,
|
6927
7294
|
receipts,
|
6928
7295
|
transaction: decodedTransaction,
|
6929
|
-
transactionBytes: (0,
|
7296
|
+
transactionBytes: (0, import_utils31.arrayify)(gqlTransaction.rawPayload),
|
6930
7297
|
gqlTransactionStatus: gqlTransaction.status,
|
6931
7298
|
gasPerByte: (0, import_math19.bn)(gasPerByte),
|
6932
7299
|
gasPriceFactor: (0, import_math19.bn)(gasPriceFactor),
|
@@ -6990,17 +7357,17 @@ async function getTransactionsSummaries(params) {
|
|
6990
7357
|
const transactions = edges.map((edge) => {
|
6991
7358
|
const { node: gqlTransaction } = edge;
|
6992
7359
|
const { id, rawPayload, status } = gqlTransaction;
|
6993
|
-
const [decodedTransaction] = new
|
7360
|
+
const [decodedTransaction] = new import_transactions24.TransactionCoder().decode((0, import_utils31.arrayify)(rawPayload), 0);
|
6994
7361
|
let txReceipts = [];
|
6995
7362
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
6996
7363
|
txReceipts = gqlTransaction.status.receipts;
|
6997
7364
|
}
|
6998
|
-
const receipts = txReceipts.map(
|
7365
|
+
const receipts = txReceipts.map(deserializeReceipt);
|
6999
7366
|
const transactionSummary = assembleTransactionSummary({
|
7000
7367
|
id,
|
7001
7368
|
receipts,
|
7002
7369
|
transaction: decodedTransaction,
|
7003
|
-
transactionBytes: (0,
|
7370
|
+
transactionBytes: (0, import_utils31.arrayify)(rawPayload),
|
7004
7371
|
gqlTransactionStatus: status,
|
7005
7372
|
abiMap,
|
7006
7373
|
gasPerByte,
|
@@ -7022,6 +7389,39 @@ async function getTransactionsSummaries(params) {
|
|
7022
7389
|
};
|
7023
7390
|
}
|
7024
7391
|
|
7392
|
+
// src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
|
7393
|
+
var import_math20 = require("@fuel-ts/math");
|
7394
|
+
var import_transactions25 = require("@fuel-ts/transactions");
|
7395
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7396
|
+
var assembleTransactionSummaryFromJson = async (opts) => {
|
7397
|
+
const { provider, transactionSummary } = opts;
|
7398
|
+
const { id, transactionBytes, gasPrice, receipts } = transactionSummary;
|
7399
|
+
const {
|
7400
|
+
consensusParameters: {
|
7401
|
+
baseAssetId,
|
7402
|
+
txParameters: { maxInputs, maxGasPerTx },
|
7403
|
+
feeParameters: { gasPriceFactor, gasPerByte },
|
7404
|
+
gasCosts
|
7405
|
+
}
|
7406
|
+
} = await provider.getChain();
|
7407
|
+
const deserializedTransactionBytes = (0, import_utils32.arrayify)(transactionBytes);
|
7408
|
+
const [transaction] = new import_transactions25.TransactionCoder().decode(deserializedTransactionBytes, 0);
|
7409
|
+
return assembleTransactionSummary({
|
7410
|
+
id,
|
7411
|
+
transaction,
|
7412
|
+
transactionBytes: deserializedTransactionBytes,
|
7413
|
+
receipts: receipts.map(deserializeReceipt),
|
7414
|
+
gasPrice: (0, import_math20.bn)(gasPrice),
|
7415
|
+
// From chain
|
7416
|
+
baseAssetId,
|
7417
|
+
maxInputs,
|
7418
|
+
gasCosts,
|
7419
|
+
maxGasPerTx,
|
7420
|
+
gasPerByte,
|
7421
|
+
gasPriceFactor
|
7422
|
+
});
|
7423
|
+
};
|
7424
|
+
|
7025
7425
|
// src/providers/utils/merge-quantities.ts
|
7026
7426
|
var mergeQuantities = (...coinQuantities) => {
|
7027
7427
|
const resultMap = {};
|
@@ -7041,12 +7441,12 @@ var AbstractAccount = class {
|
|
7041
7441
|
};
|
7042
7442
|
|
7043
7443
|
// src/utils/formatTransferToContractScriptData.ts
|
7044
|
-
var
|
7444
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
7045
7445
|
var import_address4 = require("@fuel-ts/address");
|
7046
7446
|
var import_utils33 = require("@fuel-ts/utils");
|
7047
7447
|
var asm = __toESM(require("@fuels/vm-asm"));
|
7048
7448
|
var formatTransferToContractScriptData = (transferParams) => {
|
7049
|
-
const numberCoder = new
|
7449
|
+
const numberCoder = new import_abi_coder5.BigNumberCoder("u64");
|
7050
7450
|
return transferParams.reduce((acc, transferParam) => {
|
7051
7451
|
const { assetId, amount, contractId } = transferParam;
|
7052
7452
|
const encoded = numberCoder.encode(amount);
|
@@ -7059,7 +7459,7 @@ var assembleTransferToContractScript = async (transferParams) => {
|
|
7059
7459
|
await asm.initWasm();
|
7060
7460
|
let script = new Uint8Array();
|
7061
7461
|
transferParams.forEach((_, i) => {
|
7062
|
-
const offset = (
|
7462
|
+
const offset = (import_abi_coder5.CONTRACT_ID_LEN + import_abi_coder5.WORD_SIZE + import_abi_coder5.ASSET_ID_LEN) * i;
|
7063
7463
|
script = (0, import_utils33.concat)([
|
7064
7464
|
script,
|
7065
7465
|
// Load ScriptData into register 0x10.
|
@@ -7067,11 +7467,11 @@ var assembleTransferToContractScript = async (transferParams) => {
|
|
7067
7467
|
// Add the offset to 0x10 so it will point to the current contract ID, store in 0x11.
|
7068
7468
|
asm.addi(17, 16, offset).to_bytes(),
|
7069
7469
|
// Add CONTRACT_ID_LEN to 0x11 to point to the amount in the ScriptData, store in 0x12.
|
7070
|
-
asm.addi(18, 17,
|
7470
|
+
asm.addi(18, 17, import_abi_coder5.CONTRACT_ID_LEN).to_bytes(),
|
7071
7471
|
// Load word to the amount at 0x12 into register 0x13.
|
7072
7472
|
asm.lw(19, 18, 0).to_bytes(),
|
7073
7473
|
// Add WORD_SIZE to 0x12 to point to the asset ID in the ScriptData, store in 0x14.
|
7074
|
-
asm.addi(20, 18,
|
7474
|
+
asm.addi(20, 18, import_abi_coder5.WORD_SIZE).to_bytes(),
|
7075
7475
|
// Perform the transfer using contract ID in 0x11, amount in 0x13, and asset ID in 0x14.
|
7076
7476
|
asm.tr(17, 19, 20).to_bytes()
|
7077
7477
|
]);
|
@@ -7117,7 +7517,7 @@ var Account = class extends AbstractAccount {
|
|
7117
7517
|
*/
|
7118
7518
|
get provider() {
|
7119
7519
|
if (!this._provider) {
|
7120
|
-
throw new
|
7520
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
7121
7521
|
}
|
7122
7522
|
return this._provider;
|
7123
7523
|
}
|
@@ -7194,12 +7594,20 @@ var Account = class extends AbstractAccount {
|
|
7194
7594
|
* @returns A promise that resolves to the funded transaction request.
|
7195
7595
|
*/
|
7196
7596
|
async fund(request2, params) {
|
7197
|
-
const {
|
7597
|
+
const {
|
7598
|
+
addedSignatures,
|
7599
|
+
estimatedPredicates,
|
7600
|
+
requiredQuantities,
|
7601
|
+
updateMaxFee,
|
7602
|
+
gasPrice,
|
7603
|
+
transactionSummary
|
7604
|
+
} = params;
|
7605
|
+
const chainId = await this.provider.getChainId();
|
7198
7606
|
const fee = request2.maxFee;
|
7199
7607
|
const baseAssetId = await this.provider.getBaseAssetId();
|
7200
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0,
|
7608
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math21.bn)(0);
|
7201
7609
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
7202
|
-
amount: (0,
|
7610
|
+
amount: (0, import_math21.bn)(fee),
|
7203
7611
|
assetId: baseAssetId,
|
7204
7612
|
coinQuantities: requiredQuantities
|
7205
7613
|
});
|
@@ -7207,7 +7615,7 @@ var Account = class extends AbstractAccount {
|
|
7207
7615
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
7208
7616
|
quantitiesDict[assetId] = {
|
7209
7617
|
required: amount,
|
7210
|
-
owned: (0,
|
7618
|
+
owned: (0, import_math21.bn)(0)
|
7211
7619
|
};
|
7212
7620
|
});
|
7213
7621
|
request2.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -7268,11 +7676,12 @@ var Account = class extends AbstractAccount {
|
|
7268
7676
|
fundingAttempts += 1;
|
7269
7677
|
}
|
7270
7678
|
if (needsToBeFunded) {
|
7271
|
-
throw new
|
7272
|
-
|
7679
|
+
throw new import_errors22.FuelError(
|
7680
|
+
import_errors22.ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
7273
7681
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
7274
7682
|
);
|
7275
7683
|
}
|
7684
|
+
request2.updateState(chainId, "funded", transactionSummary);
|
7276
7685
|
await this.provider.validateTransaction(request2);
|
7277
7686
|
request2.updatePredicateGasUsed(estimatedPredicates);
|
7278
7687
|
const requestToReestimate = (0, import_ramda9.clone)(request2);
|
@@ -7383,12 +7792,12 @@ var Account = class extends AbstractAccount {
|
|
7383
7792
|
const quantities = [];
|
7384
7793
|
const defaultAssetId = await this.provider.getBaseAssetId();
|
7385
7794
|
const transferParams = contractTransferParams.map((transferParam) => {
|
7386
|
-
const amount = (0,
|
7795
|
+
const amount = (0, import_math21.bn)(transferParam.amount);
|
7387
7796
|
const contractAddress = new import_address5.Address(transferParam.contractId);
|
7388
7797
|
const assetId = transferParam.assetId ? (0, import_utils34.hexlify)(transferParam.assetId) : defaultAssetId;
|
7389
7798
|
if (amount.lte(0)) {
|
7390
|
-
throw new
|
7391
|
-
|
7799
|
+
throw new import_errors22.FuelError(
|
7800
|
+
import_errors22.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7392
7801
|
"Transfer amount must be a positive number."
|
7393
7802
|
);
|
7394
7803
|
}
|
@@ -7420,7 +7829,7 @@ var Account = class extends AbstractAccount {
|
|
7420
7829
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
7421
7830
|
);
|
7422
7831
|
const amountDataArray = (0, import_utils34.arrayify)(
|
7423
|
-
"0x".concat((0,
|
7832
|
+
"0x".concat((0, import_math21.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
7424
7833
|
);
|
7425
7834
|
const script = new Uint8Array([
|
7426
7835
|
...(0, import_utils34.arrayify)(withdrawScript.bytes),
|
@@ -7430,7 +7839,7 @@ var Account = class extends AbstractAccount {
|
|
7430
7839
|
const params = { script, ...txParams };
|
7431
7840
|
const baseAssetId = await this.provider.getBaseAssetId();
|
7432
7841
|
let request2 = new ScriptTransactionRequest(params);
|
7433
|
-
const quantities = [{ amount: (0,
|
7842
|
+
const quantities = [{ amount: (0, import_math21.bn)(amount), assetId: baseAssetId }];
|
7434
7843
|
const txCost = await this.getTransactionCost(request2, { quantities });
|
7435
7844
|
request2 = this.validateGasLimitAndMaxFee({
|
7436
7845
|
transactionRequest: request2,
|
@@ -7456,9 +7865,9 @@ var Account = class extends AbstractAccount {
|
|
7456
7865
|
const baseAssetId = await this.provider.getBaseAssetId();
|
7457
7866
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
7458
7867
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
7459
|
-
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0,
|
7868
|
+
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math21.bn)("100000000000000000") }];
|
7460
7869
|
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
7461
|
-
if (input.type ===
|
7870
|
+
if (input.type === import_transactions26.InputType.Coin) {
|
7462
7871
|
return input.assetId === assetId;
|
7463
7872
|
}
|
7464
7873
|
if (isRequestInputMessageWithoutData(input)) {
|
@@ -7504,7 +7913,7 @@ var Account = class extends AbstractAccount {
|
|
7504
7913
|
*/
|
7505
7914
|
async signMessage(message) {
|
7506
7915
|
if (!this._connector) {
|
7507
|
-
throw new
|
7916
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
7508
7917
|
}
|
7509
7918
|
return this._connector.signMessage(this.address.toString(), message);
|
7510
7919
|
}
|
@@ -7516,8 +7925,8 @@ var Account = class extends AbstractAccount {
|
|
7516
7925
|
*/
|
7517
7926
|
async signTransaction(transactionRequestLike) {
|
7518
7927
|
if (!this._connector) {
|
7519
|
-
throw new
|
7520
|
-
|
7928
|
+
throw new import_errors22.FuelError(
|
7929
|
+
import_errors22.ErrorCode.MISSING_CONNECTOR,
|
7521
7930
|
"A connector is required to sign transactions."
|
7522
7931
|
);
|
7523
7932
|
}
|
@@ -7530,16 +7939,28 @@ var Account = class extends AbstractAccount {
|
|
7530
7939
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
7531
7940
|
* @returns A promise that resolves to the transaction response.
|
7532
7941
|
*/
|
7533
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true,
|
7942
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, ...connectorOptions } = {}) {
|
7943
|
+
let transactionRequest = transactionRequestify(transactionRequestLike);
|
7534
7944
|
if (this._connector) {
|
7535
|
-
|
7536
|
-
|
7537
|
-
|
7538
|
-
|
7539
|
-
|
7945
|
+
const { onBeforeSend, skipCustomFee = false } = connectorOptions;
|
7946
|
+
transactionRequest = await this.prepareTransactionForSend(transactionRequest);
|
7947
|
+
const params = {
|
7948
|
+
onBeforeSend,
|
7949
|
+
skipCustomFee,
|
7950
|
+
provider: {
|
7951
|
+
url: this.provider.url,
|
7952
|
+
cache: await serializeProviderCache(this.provider)
|
7953
|
+
},
|
7954
|
+
transactionState: transactionRequest.flag.state,
|
7955
|
+
transactionSummary: await this.prepareTransactionSummary(transactionRequest)
|
7956
|
+
};
|
7957
|
+
const transaction = await this._connector.sendTransaction(
|
7958
|
+
this.address.toString(),
|
7959
|
+
transactionRequest,
|
7960
|
+
params
|
7540
7961
|
);
|
7962
|
+
return typeof transaction === "string" ? this.provider.getTransactionResponse(transaction) : transaction;
|
7541
7963
|
}
|
7542
|
-
const transactionRequest = transactionRequestify(transactionRequestLike);
|
7543
7964
|
if (estimateTxDependencies) {
|
7544
7965
|
await this.provider.estimateTxDependencies(transactionRequest);
|
7545
7966
|
}
|
@@ -7569,18 +7990,40 @@ var Account = class extends AbstractAccount {
|
|
7569
7990
|
*/
|
7570
7991
|
generateFakeResources(coins) {
|
7571
7992
|
return coins.map((coin) => ({
|
7572
|
-
id: (0, import_utils34.hexlify)((0, import_crypto2.randomBytes)(
|
7993
|
+
id: (0, import_utils34.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder6.UTXO_ID_LEN)),
|
7573
7994
|
owner: this.address,
|
7574
|
-
blockCreated: (0,
|
7575
|
-
txCreatedIdx: (0,
|
7995
|
+
blockCreated: (0, import_math21.bn)(1),
|
7996
|
+
txCreatedIdx: (0, import_math21.bn)(1),
|
7576
7997
|
...coin
|
7577
7998
|
}));
|
7578
7999
|
}
|
8000
|
+
/** @hidden */
|
8001
|
+
async prepareTransactionForSend(request2) {
|
8002
|
+
const { transactionId } = request2.flag;
|
8003
|
+
if (!(0, import_utils34.isDefined)(transactionId)) {
|
8004
|
+
return request2;
|
8005
|
+
}
|
8006
|
+
const chainId = await this.provider.getChainId();
|
8007
|
+
const currentTransactionId = request2.getTransactionId(chainId);
|
8008
|
+
if (transactionId !== currentTransactionId) {
|
8009
|
+
request2.updateState(chainId);
|
8010
|
+
}
|
8011
|
+
return request2;
|
8012
|
+
}
|
8013
|
+
/** @hidden */
|
8014
|
+
async prepareTransactionSummary(request2) {
|
8015
|
+
const chainId = await this.provider.getChainId();
|
8016
|
+
return (0, import_utils34.isDefined)(request2.flag.summary) ? {
|
8017
|
+
...request2.flag.summary,
|
8018
|
+
id: request2.getTransactionId(chainId),
|
8019
|
+
transactionBytes: (0, import_utils34.hexlify)(request2.toTransactionBytes())
|
8020
|
+
} : void 0;
|
8021
|
+
}
|
7579
8022
|
/** @hidden * */
|
7580
8023
|
validateTransferAmount(amount) {
|
7581
|
-
if ((0,
|
7582
|
-
throw new
|
7583
|
-
|
8024
|
+
if ((0, import_math21.bn)(amount).lte(0)) {
|
8025
|
+
throw new import_errors22.FuelError(
|
8026
|
+
import_errors22.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7584
8027
|
"Transfer amount must be a positive number."
|
7585
8028
|
);
|
7586
8029
|
}
|
@@ -7609,16 +8052,16 @@ var Account = class extends AbstractAccount {
|
|
7609
8052
|
if (!(0, import_utils34.isDefined)(setGasLimit)) {
|
7610
8053
|
request2.gasLimit = gasUsed;
|
7611
8054
|
} else if (gasUsed.gt(setGasLimit)) {
|
7612
|
-
throw new
|
7613
|
-
|
8055
|
+
throw new import_errors22.FuelError(
|
8056
|
+
import_errors22.ErrorCode.GAS_LIMIT_TOO_LOW,
|
7614
8057
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
7615
8058
|
);
|
7616
8059
|
}
|
7617
8060
|
if (!(0, import_utils34.isDefined)(setMaxFee)) {
|
7618
8061
|
request2.maxFee = maxFee;
|
7619
8062
|
} else if (maxFee.gt(setMaxFee)) {
|
7620
|
-
throw new
|
7621
|
-
|
8063
|
+
throw new import_errors22.FuelError(
|
8064
|
+
import_errors22.ErrorCode.MAX_FEE_TOO_LOW,
|
7622
8065
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
7623
8066
|
);
|
7624
8067
|
}
|
@@ -7634,7 +8077,7 @@ var import_utils37 = require("@fuel-ts/utils");
|
|
7634
8077
|
var import_address6 = require("@fuel-ts/address");
|
7635
8078
|
var import_crypto3 = require("@fuel-ts/crypto");
|
7636
8079
|
var import_hasher3 = require("@fuel-ts/hasher");
|
7637
|
-
var
|
8080
|
+
var import_math22 = require("@fuel-ts/math");
|
7638
8081
|
var import_utils35 = require("@fuel-ts/utils");
|
7639
8082
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
7640
8083
|
var Signer = class {
|
@@ -7654,7 +8097,7 @@ var Signer = class {
|
|
7654
8097
|
privateKey = `0x${privateKey}`;
|
7655
8098
|
}
|
7656
8099
|
}
|
7657
|
-
const privateKeyBytes = (0,
|
8100
|
+
const privateKeyBytes = (0, import_math22.toBytes)(privateKey, 32);
|
7658
8101
|
this.privateKey = (0, import_utils35.hexlify)(privateKeyBytes);
|
7659
8102
|
this.publicKey = (0, import_utils35.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
7660
8103
|
this.compressedPublicKey = (0, import_utils35.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
@@ -7672,8 +8115,8 @@ var Signer = class {
|
|
7672
8115
|
*/
|
7673
8116
|
sign(data) {
|
7674
8117
|
const signature = import_secp256k1.secp256k1.sign((0, import_utils35.arrayify)(data), (0, import_utils35.arrayify)(this.privateKey));
|
7675
|
-
const r = (0,
|
7676
|
-
const s = (0,
|
8118
|
+
const r = (0, import_math22.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
8119
|
+
const s = (0, import_math22.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
7677
8120
|
s[0] |= (signature.recovery || 0) << 7;
|
7678
8121
|
return (0, import_utils35.hexlify)((0, import_utils35.concat)([r, s]));
|
7679
8122
|
}
|
@@ -7742,7 +8185,7 @@ var Signer = class {
|
|
7742
8185
|
// src/wallet/keystore-wallet.ts
|
7743
8186
|
var import_address7 = require("@fuel-ts/address");
|
7744
8187
|
var import_crypto4 = require("@fuel-ts/crypto");
|
7745
|
-
var
|
8188
|
+
var import_errors23 = require("@fuel-ts/errors");
|
7746
8189
|
var import_utils36 = require("@fuel-ts/utils");
|
7747
8190
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
7748
8191
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -7819,8 +8262,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7819
8262
|
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
7820
8263
|
const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
7821
8264
|
if (mac !== macHash) {
|
7822
|
-
throw new
|
7823
|
-
|
8265
|
+
throw new import_errors23.FuelError(
|
8266
|
+
import_errors23.ErrorCode.INVALID_PASSWORD,
|
7824
8267
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
7825
8268
|
);
|
7826
8269
|
}
|
@@ -7955,14 +8398,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
7955
8398
|
|
7956
8399
|
// src/hdwallet/hdwallet.ts
|
7957
8400
|
var import_crypto6 = require("@fuel-ts/crypto");
|
7958
|
-
var
|
8401
|
+
var import_errors26 = require("@fuel-ts/errors");
|
7959
8402
|
var import_hasher7 = require("@fuel-ts/hasher");
|
7960
|
-
var
|
8403
|
+
var import_math23 = require("@fuel-ts/math");
|
7961
8404
|
var import_utils41 = require("@fuel-ts/utils");
|
7962
8405
|
|
7963
8406
|
// src/mnemonic/mnemonic.ts
|
7964
8407
|
var import_crypto5 = require("@fuel-ts/crypto");
|
7965
|
-
var
|
8408
|
+
var import_errors25 = require("@fuel-ts/errors");
|
7966
8409
|
var import_hasher6 = require("@fuel-ts/hasher");
|
7967
8410
|
var import_utils39 = require("@fuel-ts/utils");
|
7968
8411
|
|
@@ -10025,7 +10468,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
10025
10468
|
})(Language || {});
|
10026
10469
|
|
10027
10470
|
// src/mnemonic/utils.ts
|
10028
|
-
var
|
10471
|
+
var import_errors24 = require("@fuel-ts/errors");
|
10029
10472
|
var import_hasher5 = require("@fuel-ts/hasher");
|
10030
10473
|
var import_utils38 = require("@fuel-ts/utils");
|
10031
10474
|
function getLowerMask(bits) {
|
@@ -10074,8 +10517,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
10074
10517
|
for (let i = 0; i < words.length; i += 1) {
|
10075
10518
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
10076
10519
|
if (index === -1) {
|
10077
|
-
throw new
|
10078
|
-
|
10520
|
+
throw new import_errors24.FuelError(
|
10521
|
+
import_errors24.ErrorCode.INVALID_MNEMONIC,
|
10079
10522
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
10080
10523
|
);
|
10081
10524
|
}
|
@@ -10091,8 +10534,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
10091
10534
|
const checksumMask = getUpperMask(checksumBits);
|
10092
10535
|
const checksum = (0, import_utils38.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
10093
10536
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
10094
|
-
throw new
|
10095
|
-
|
10537
|
+
throw new import_errors24.FuelError(
|
10538
|
+
import_errors24.ErrorCode.INVALID_CHECKSUM,
|
10096
10539
|
"Checksum validation failed for the provided mnemonic."
|
10097
10540
|
);
|
10098
10541
|
}
|
@@ -10106,16 +10549,16 @@ var TestnetPRV = "0x04358394";
|
|
10106
10549
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
10107
10550
|
function assertWordList(wordlist) {
|
10108
10551
|
if (wordlist.length !== 2048) {
|
10109
|
-
throw new
|
10110
|
-
|
10552
|
+
throw new import_errors25.FuelError(
|
10553
|
+
import_errors25.ErrorCode.INVALID_WORD_LIST,
|
10111
10554
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
10112
10555
|
);
|
10113
10556
|
}
|
10114
10557
|
}
|
10115
10558
|
function assertEntropy(entropy) {
|
10116
10559
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
10117
|
-
throw new
|
10118
|
-
|
10560
|
+
throw new import_errors25.FuelError(
|
10561
|
+
import_errors25.ErrorCode.INVALID_ENTROPY,
|
10119
10562
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
10120
10563
|
);
|
10121
10564
|
}
|
@@ -10125,7 +10568,7 @@ function assertMnemonic(words) {
|
|
10125
10568
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
10126
10569
|
", "
|
10127
10570
|
)}] words, but got ${words.length}.`;
|
10128
|
-
throw new
|
10571
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
10129
10572
|
}
|
10130
10573
|
}
|
10131
10574
|
var Mnemonic = class {
|
@@ -10243,8 +10686,8 @@ var Mnemonic = class {
|
|
10243
10686
|
static masterKeysFromSeed(seed) {
|
10244
10687
|
const seedArray = (0, import_utils39.arrayify)(seed);
|
10245
10688
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
10246
|
-
throw new
|
10247
|
-
|
10689
|
+
throw new import_errors25.FuelError(
|
10690
|
+
import_errors25.ErrorCode.INVALID_SEED,
|
10248
10691
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
10249
10692
|
);
|
10250
10693
|
}
|
@@ -10321,7 +10764,7 @@ function isValidExtendedKey(extendedKey) {
|
|
10321
10764
|
function parsePath(path, depth = 0) {
|
10322
10765
|
const components = path.split("/");
|
10323
10766
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
10324
|
-
throw new
|
10767
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
|
10325
10768
|
}
|
10326
10769
|
if (components[0] === "m") {
|
10327
10770
|
components.shift();
|
@@ -10350,8 +10793,8 @@ var HDWallet = class {
|
|
10350
10793
|
this.privateKey = (0, import_utils41.hexlify)(config.privateKey);
|
10351
10794
|
} else {
|
10352
10795
|
if (!config.publicKey) {
|
10353
|
-
throw new
|
10354
|
-
|
10796
|
+
throw new import_errors26.FuelError(
|
10797
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10355
10798
|
"Both public and private Key cannot be missing. At least one should be provided."
|
10356
10799
|
);
|
10357
10800
|
}
|
@@ -10380,8 +10823,8 @@ var HDWallet = class {
|
|
10380
10823
|
const data = new Uint8Array(37);
|
10381
10824
|
if (index & HARDENED_INDEX) {
|
10382
10825
|
if (!privateKey) {
|
10383
|
-
throw new
|
10384
|
-
|
10826
|
+
throw new import_errors26.FuelError(
|
10827
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10385
10828
|
"Cannot derive a hardened index without a private Key."
|
10386
10829
|
);
|
10387
10830
|
}
|
@@ -10389,13 +10832,13 @@ var HDWallet = class {
|
|
10389
10832
|
} else {
|
10390
10833
|
data.set((0, import_utils41.arrayify)(this.publicKey));
|
10391
10834
|
}
|
10392
|
-
data.set((0,
|
10835
|
+
data.set((0, import_math23.toBytes)(index, 4), 33);
|
10393
10836
|
const bytes = (0, import_utils41.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
|
10394
10837
|
const IL = bytes.slice(0, 32);
|
10395
10838
|
const IR = bytes.slice(32);
|
10396
10839
|
if (privateKey) {
|
10397
10840
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
10398
|
-
const ki = (0,
|
10841
|
+
const ki = (0, import_math23.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
10399
10842
|
return new HDWallet({
|
10400
10843
|
privateKey: ki,
|
10401
10844
|
chainCode: IR,
|
@@ -10433,15 +10876,15 @@ var HDWallet = class {
|
|
10433
10876
|
*/
|
10434
10877
|
toExtendedKey(isPublic = false, testnet = false) {
|
10435
10878
|
if (this.depth >= 256) {
|
10436
|
-
throw new
|
10437
|
-
|
10879
|
+
throw new import_errors26.FuelError(
|
10880
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10438
10881
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
10439
10882
|
);
|
10440
10883
|
}
|
10441
10884
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
10442
10885
|
const depth = (0, import_utils41.hexlify)(Uint8Array.from([this.depth]));
|
10443
10886
|
const parentFingerprint = this.parentFingerprint;
|
10444
|
-
const index = (0,
|
10887
|
+
const index = (0, import_math23.toHex)(this.index, 4);
|
10445
10888
|
const chainCode = this.chainCode;
|
10446
10889
|
const key = this.privateKey != null && !isPublic ? (0, import_utils41.concat)(["0x00", this.privateKey]) : this.publicKey;
|
10447
10890
|
const extendedKey = (0, import_utils41.arrayify)((0, import_utils41.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
@@ -10461,14 +10904,14 @@ var HDWallet = class {
|
|
10461
10904
|
});
|
10462
10905
|
}
|
10463
10906
|
static fromExtendedKey(extendedKey) {
|
10464
|
-
const decoded = (0, import_utils41.hexlify)((0,
|
10907
|
+
const decoded = (0, import_utils41.hexlify)((0, import_math23.toBytes)((0, import_utils41.decodeBase58)(extendedKey)));
|
10465
10908
|
const bytes = (0, import_utils41.arrayify)(decoded);
|
10466
10909
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
10467
10910
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
10468
|
-
throw new
|
10911
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
10469
10912
|
}
|
10470
10913
|
if (!validChecksum) {
|
10471
|
-
throw new
|
10914
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
10472
10915
|
}
|
10473
10916
|
const depth = bytes[4];
|
10474
10917
|
const parentFingerprint = (0, import_utils41.hexlify)(bytes.slice(5, 9));
|
@@ -10476,14 +10919,14 @@ var HDWallet = class {
|
|
10476
10919
|
const chainCode = (0, import_utils41.hexlify)(bytes.slice(13, 45));
|
10477
10920
|
const key = bytes.slice(45, 78);
|
10478
10921
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
10479
|
-
throw new
|
10480
|
-
|
10922
|
+
throw new import_errors26.FuelError(
|
10923
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10481
10924
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
10482
10925
|
);
|
10483
10926
|
}
|
10484
10927
|
if (isPublicExtendedKey(bytes)) {
|
10485
10928
|
if (key[0] !== 3) {
|
10486
|
-
throw new
|
10929
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
10487
10930
|
}
|
10488
10931
|
return new HDWallet({
|
10489
10932
|
publicKey: key,
|
@@ -10494,7 +10937,7 @@ var HDWallet = class {
|
|
10494
10937
|
});
|
10495
10938
|
}
|
10496
10939
|
if (key[0] !== 0) {
|
10497
|
-
throw new
|
10940
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
10498
10941
|
}
|
10499
10942
|
return new HDWallet({
|
10500
10943
|
privateKey: key.slice(1),
|
@@ -10662,7 +11105,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
10662
11105
|
// src/wallet-manager/wallet-manager.ts
|
10663
11106
|
var import_address10 = require("@fuel-ts/address");
|
10664
11107
|
var import_crypto7 = require("@fuel-ts/crypto");
|
10665
|
-
var
|
11108
|
+
var import_errors29 = require("@fuel-ts/errors");
|
10666
11109
|
var import_events = require("events");
|
10667
11110
|
|
10668
11111
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -10685,7 +11128,7 @@ var MemoryStorage = class {
|
|
10685
11128
|
|
10686
11129
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
10687
11130
|
var import_address8 = require("@fuel-ts/address");
|
10688
|
-
var
|
11131
|
+
var import_errors27 = require("@fuel-ts/errors");
|
10689
11132
|
var _secret;
|
10690
11133
|
var MnemonicVault = class {
|
10691
11134
|
constructor(options) {
|
@@ -10741,8 +11184,8 @@ var MnemonicVault = class {
|
|
10741
11184
|
}
|
10742
11185
|
numberOfAccounts += 1;
|
10743
11186
|
} while (numberOfAccounts < this.numberOfAccounts);
|
10744
|
-
throw new
|
10745
|
-
|
11187
|
+
throw new import_errors27.FuelError(
|
11188
|
+
import_errors27.ErrorCode.WALLET_MANAGER_ERROR,
|
10746
11189
|
`Account with address '${address}' not found in derived wallets.`
|
10747
11190
|
);
|
10748
11191
|
}
|
@@ -10756,7 +11199,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
10756
11199
|
|
10757
11200
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
10758
11201
|
var import_address9 = require("@fuel-ts/address");
|
10759
|
-
var
|
11202
|
+
var import_errors28 = require("@fuel-ts/errors");
|
10760
11203
|
var _privateKeys;
|
10761
11204
|
var PrivateKeyVault = class {
|
10762
11205
|
/**
|
@@ -10797,8 +11240,8 @@ var PrivateKeyVault = class {
|
|
10797
11240
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
10798
11241
|
);
|
10799
11242
|
if (!privateKey) {
|
10800
|
-
throw new
|
10801
|
-
|
11243
|
+
throw new import_errors28.FuelError(
|
11244
|
+
import_errors28.ErrorCode.WALLET_MANAGER_ERROR,
|
10802
11245
|
`No private key found for address '${address}'.`
|
10803
11246
|
);
|
10804
11247
|
}
|
@@ -10822,7 +11265,7 @@ var ERROR_MESSAGES = {
|
|
10822
11265
|
};
|
10823
11266
|
function assert(condition, message) {
|
10824
11267
|
if (!condition) {
|
10825
|
-
throw new
|
11268
|
+
throw new import_errors29.FuelError(import_errors29.ErrorCode.WALLET_MANAGER_ERROR, message);
|
10826
11269
|
}
|
10827
11270
|
}
|
10828
11271
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -11048,25 +11491,25 @@ deserializeVaults_fn = function(vaults) {
|
|
11048
11491
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
11049
11492
|
|
11050
11493
|
// src/wallet-manager/types.ts
|
11051
|
-
var
|
11494
|
+
var import_errors30 = require("@fuel-ts/errors");
|
11052
11495
|
var Vault = class {
|
11053
11496
|
constructor(_options) {
|
11054
|
-
throw new
|
11497
|
+
throw new import_errors30.FuelError(import_errors30.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
11055
11498
|
}
|
11056
11499
|
serialize() {
|
11057
|
-
throw new
|
11500
|
+
throw new import_errors30.FuelError(import_errors30.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
11058
11501
|
}
|
11059
11502
|
getAccounts() {
|
11060
|
-
throw new
|
11503
|
+
throw new import_errors30.FuelError(import_errors30.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
11061
11504
|
}
|
11062
11505
|
addAccount() {
|
11063
|
-
throw new
|
11506
|
+
throw new import_errors30.FuelError(import_errors30.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
11064
11507
|
}
|
11065
11508
|
exportAccount(_address) {
|
11066
|
-
throw new
|
11509
|
+
throw new import_errors30.FuelError(import_errors30.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
11067
11510
|
}
|
11068
11511
|
getWallet(_address) {
|
11069
|
-
throw new
|
11512
|
+
throw new import_errors30.FuelError(import_errors30.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
11070
11513
|
}
|
11071
11514
|
};
|
11072
11515
|
__publicField(Vault, "type");
|
@@ -11074,18 +11517,18 @@ var StorageAbstract = class {
|
|
11074
11517
|
};
|
11075
11518
|
|
11076
11519
|
// src/predicate/predicate.ts
|
11077
|
-
var
|
11520
|
+
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
11078
11521
|
var import_address11 = require("@fuel-ts/address");
|
11079
|
-
var
|
11522
|
+
var import_errors32 = require("@fuel-ts/errors");
|
11080
11523
|
var import_utils45 = require("@fuel-ts/utils");
|
11081
11524
|
|
11082
11525
|
// src/utils/deployScriptOrPredicate.ts
|
11083
|
-
var
|
11084
|
-
var
|
11526
|
+
var import_errors31 = require("@fuel-ts/errors");
|
11527
|
+
var import_math24 = require("@fuel-ts/math");
|
11085
11528
|
var import_utils43 = require("@fuel-ts/utils");
|
11086
11529
|
|
11087
11530
|
// src/utils/predicate-script-loader-instructions.ts
|
11088
|
-
var
|
11531
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
11089
11532
|
var import_hasher8 = require("@fuel-ts/hasher");
|
11090
11533
|
var import_utils42 = require("@fuel-ts/utils");
|
11091
11534
|
var asm2 = __toESM(require("@fuels/vm-asm"));
|
@@ -11097,11 +11540,11 @@ var WORD_SIZE2 = 8;
|
|
11097
11540
|
var DATA_OFFSET_INDEX = 8;
|
11098
11541
|
var CONFIGURABLE_OFFSET_INDEX = 16;
|
11099
11542
|
function getBytecodeDataOffset(bytecode) {
|
11100
|
-
const [offset] = new
|
11543
|
+
const [offset] = new import_abi_coder7.BigNumberCoder("u64").decode(bytecode, DATA_OFFSET_INDEX);
|
11101
11544
|
return offset.toNumber();
|
11102
11545
|
}
|
11103
11546
|
function getBytecodeConfigurableOffset(bytecode) {
|
11104
|
-
const [offset] = new
|
11547
|
+
const [offset] = new import_abi_coder7.BigNumberCoder("u64").decode(bytecode, CONFIGURABLE_OFFSET_INDEX);
|
11105
11548
|
return offset.toNumber();
|
11106
11549
|
}
|
11107
11550
|
function getBytecodeId(bytecode) {
|
@@ -11229,7 +11672,7 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
|
11229
11672
|
|
11230
11673
|
// src/utils/deployScriptOrPredicate.ts
|
11231
11674
|
async function fundBlobTx(deployer, blobTxRequest) {
|
11232
|
-
let totalCost = (0,
|
11675
|
+
let totalCost = (0, import_math24.bn)(0);
|
11233
11676
|
const chainInfo = await deployer.provider.getChain();
|
11234
11677
|
const gasPrice = await deployer.provider.estimateGasPrice(10);
|
11235
11678
|
const priceFactor = chainInfo.consensusParameters.feeParameters.gasPriceFactor;
|
@@ -11242,7 +11685,7 @@ async function fundBlobTx(deployer, blobTxRequest) {
|
|
11242
11685
|
}).add(1);
|
11243
11686
|
totalCost = totalCost.add(minFee);
|
11244
11687
|
if (totalCost.gt(await deployer.getBalance())) {
|
11245
|
-
throw new
|
11688
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.FUNDS_TOO_LOW, "Insufficient balance to deploy predicate.");
|
11246
11689
|
}
|
11247
11690
|
const txCost = await deployer.getTransactionCost(blobTxRequest);
|
11248
11691
|
blobTxRequest.maxFee = txCost.maxFee;
|
@@ -11293,7 +11736,7 @@ async function deployScriptOrPredicate({
|
|
11293
11736
|
throw new Error();
|
11294
11737
|
}
|
11295
11738
|
} catch (err) {
|
11296
|
-
throw new
|
11739
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.TRANSACTION_FAILED, "Failed to deploy predicate chunk");
|
11297
11740
|
}
|
11298
11741
|
return loaderInstance;
|
11299
11742
|
};
|
@@ -11426,10 +11869,10 @@ var Predicate = class extends Account {
|
|
11426
11869
|
*/
|
11427
11870
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
11428
11871
|
let predicateBytes = (0, import_utils45.arrayify)(bytes);
|
11429
|
-
const abiInterface = new
|
11872
|
+
const abiInterface = new import_abi_coder8.Interface(jsonAbi);
|
11430
11873
|
if (abiInterface.functions.main === void 0) {
|
11431
|
-
throw new
|
11432
|
-
|
11874
|
+
throw new import_errors32.FuelError(
|
11875
|
+
import_errors32.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
11433
11876
|
'Cannot use ABI without "main" function.'
|
11434
11877
|
);
|
11435
11878
|
}
|
@@ -11489,15 +11932,15 @@ var Predicate = class extends Account {
|
|
11489
11932
|
const mutatedBytes = bytes;
|
11490
11933
|
try {
|
11491
11934
|
if (Object.keys(abiInterface.configurables).length === 0) {
|
11492
|
-
throw new
|
11493
|
-
|
11935
|
+
throw new import_errors32.FuelError(
|
11936
|
+
import_errors32.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
11494
11937
|
"Predicate has no configurable constants to be set"
|
11495
11938
|
);
|
11496
11939
|
}
|
11497
11940
|
Object.entries(configurableConstants).forEach(([key, value]) => {
|
11498
11941
|
if (!abiInterface?.configurables[key]) {
|
11499
|
-
throw new
|
11500
|
-
|
11942
|
+
throw new import_errors32.FuelError(
|
11943
|
+
import_errors32.ErrorCode.CONFIGURABLE_NOT_FOUND,
|
11501
11944
|
`No configurable constant named '${key}' found in the Predicate`
|
11502
11945
|
);
|
11503
11946
|
}
|
@@ -11506,8 +11949,8 @@ var Predicate = class extends Account {
|
|
11506
11949
|
mutatedBytes.set(encoded, offset);
|
11507
11950
|
});
|
11508
11951
|
} catch (err) {
|
11509
|
-
throw new
|
11510
|
-
|
11952
|
+
throw new import_errors32.FuelError(
|
11953
|
+
import_errors32.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
11511
11954
|
`Error setting configurable constants: ${err.message}.`
|
11512
11955
|
);
|
11513
11956
|
}
|
@@ -11563,7 +12006,7 @@ var Predicate = class extends Account {
|
|
11563
12006
|
var import_errors34 = require("@fuel-ts/errors");
|
11564
12007
|
|
11565
12008
|
// src/connectors/fuel-connector.ts
|
11566
|
-
var
|
12009
|
+
var import_errors33 = require("@fuel-ts/errors");
|
11567
12010
|
var import_events2 = require("events");
|
11568
12011
|
|
11569
12012
|
// src/connectors/types/connector-types.ts
|
@@ -11638,7 +12081,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11638
12081
|
* @returns Always true.
|
11639
12082
|
*/
|
11640
12083
|
async ping() {
|
11641
|
-
throw new
|
12084
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11642
12085
|
}
|
11643
12086
|
/**
|
11644
12087
|
* Should return the current version of the connector
|
@@ -11647,7 +12090,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11647
12090
|
* @returns boolean - connection status.
|
11648
12091
|
*/
|
11649
12092
|
async version() {
|
11650
|
-
throw new
|
12093
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11651
12094
|
}
|
11652
12095
|
/**
|
11653
12096
|
* Should return true if the connector is connected
|
@@ -11656,7 +12099,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11656
12099
|
* @returns The connection status.
|
11657
12100
|
*/
|
11658
12101
|
async isConnected() {
|
11659
|
-
throw new
|
12102
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11660
12103
|
}
|
11661
12104
|
/**
|
11662
12105
|
* Should return all the accounts authorized for the
|
@@ -11665,7 +12108,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11665
12108
|
* @returns The accounts addresses strings
|
11666
12109
|
*/
|
11667
12110
|
async accounts() {
|
11668
|
-
throw new
|
12111
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11669
12112
|
}
|
11670
12113
|
/**
|
11671
12114
|
* Should start the connection process and return
|
@@ -11677,7 +12120,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11677
12120
|
* @returns boolean - connection status.
|
11678
12121
|
*/
|
11679
12122
|
async connect() {
|
11680
|
-
throw new
|
12123
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11681
12124
|
}
|
11682
12125
|
/**
|
11683
12126
|
* Should disconnect the current connection and
|
@@ -11687,7 +12130,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11687
12130
|
* @returns The connection status.
|
11688
12131
|
*/
|
11689
12132
|
async disconnect() {
|
11690
|
-
throw new
|
12133
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11691
12134
|
}
|
11692
12135
|
/**
|
11693
12136
|
* Should start the sign message process and return
|
@@ -11699,7 +12142,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11699
12142
|
* @returns Message signature
|
11700
12143
|
*/
|
11701
12144
|
async signMessage(_address, _message) {
|
11702
|
-
throw new
|
12145
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11703
12146
|
}
|
11704
12147
|
/**
|
11705
12148
|
* Should start the sign transaction process and return
|
@@ -11711,7 +12154,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11711
12154
|
* @returns Transaction signature
|
11712
12155
|
*/
|
11713
12156
|
async signTransaction(_address, _transaction) {
|
11714
|
-
throw new
|
12157
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11715
12158
|
}
|
11716
12159
|
/**
|
11717
12160
|
* Should start the send transaction process and return
|
@@ -11724,10 +12167,10 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11724
12167
|
* @param address - The address to sign the transaction
|
11725
12168
|
* @param transaction - The transaction to send
|
11726
12169
|
* @param params - Optional parameters to send the transaction
|
11727
|
-
* @returns The transaction id
|
12170
|
+
* @returns The transaction id or transaction response
|
11728
12171
|
*/
|
11729
12172
|
async sendTransaction(_address, _transaction, _params) {
|
11730
|
-
throw new
|
12173
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11731
12174
|
}
|
11732
12175
|
/**
|
11733
12176
|
* Should return the current account selected inside the connector, if the account
|
@@ -11738,7 +12181,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11738
12181
|
* @returns The current account selected otherwise null.
|
11739
12182
|
*/
|
11740
12183
|
async currentAccount() {
|
11741
|
-
throw new
|
12184
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11742
12185
|
}
|
11743
12186
|
/**
|
11744
12187
|
* Should add the assets metadata to the connector and return true if the asset
|
@@ -11752,7 +12195,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11752
12195
|
* @returns True if the asset was added successfully
|
11753
12196
|
*/
|
11754
12197
|
async addAssets(_assets) {
|
11755
|
-
throw new
|
12198
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11756
12199
|
}
|
11757
12200
|
/**
|
11758
12201
|
* Should add the asset metadata to the connector and return true if the asset
|
@@ -11766,7 +12209,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11766
12209
|
* @returns True if the asset was added successfully
|
11767
12210
|
*/
|
11768
12211
|
async addAsset(_asset) {
|
11769
|
-
throw new
|
12212
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11770
12213
|
}
|
11771
12214
|
/**
|
11772
12215
|
* Should return all the assets added to the connector. If a connection is already established.
|
@@ -11774,7 +12217,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11774
12217
|
* @returns Array of assets metadata from the connector vinculated to the all accounts from a specific Wallet.
|
11775
12218
|
*/
|
11776
12219
|
async assets() {
|
11777
|
-
throw new
|
12220
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11778
12221
|
}
|
11779
12222
|
/**
|
11780
12223
|
* Should start the add network process and return true if the network was added successfully.
|
@@ -11785,7 +12228,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11785
12228
|
* @returns Return true if the network was added successfully
|
11786
12229
|
*/
|
11787
12230
|
async addNetwork(_networkUrl) {
|
11788
|
-
throw new
|
12231
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11789
12232
|
}
|
11790
12233
|
/**
|
11791
12234
|
* Should start the select network process and return true if the network has change successfully.
|
@@ -11796,7 +12239,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11796
12239
|
* @returns Return true if the network was added successfully
|
11797
12240
|
*/
|
11798
12241
|
async selectNetwork(_network) {
|
11799
|
-
throw new
|
12242
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11800
12243
|
}
|
11801
12244
|
/**
|
11802
12245
|
* Should return all the networks available from the connector. If the connection is already established.
|
@@ -11804,7 +12247,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11804
12247
|
* @returns Return all the networks added to the connector.
|
11805
12248
|
*/
|
11806
12249
|
async networks() {
|
11807
|
-
throw new
|
12250
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11808
12251
|
}
|
11809
12252
|
/**
|
11810
12253
|
* Should return the current network selected inside the connector. Even if the connection is not established.
|
@@ -11812,7 +12255,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11812
12255
|
* @returns Return the current network selected inside the connector.
|
11813
12256
|
*/
|
11814
12257
|
async currentNetwork() {
|
11815
|
-
throw new
|
12258
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11816
12259
|
}
|
11817
12260
|
/**
|
11818
12261
|
* Should add the ABI to the connector and return true if the ABI was added successfully.
|
@@ -11822,7 +12265,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11822
12265
|
* @returns Return true if the ABI was added successfully.
|
11823
12266
|
*/
|
11824
12267
|
async addABI(_contractId, _abi) {
|
11825
|
-
throw new
|
12268
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11826
12269
|
}
|
11827
12270
|
/**
|
11828
12271
|
* Should return the ABI from the connector vinculated to the all accounts from a specific Wallet.
|
@@ -11831,7 +12274,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11831
12274
|
* @returns The ABI if it exists, otherwise return null.
|
11832
12275
|
*/
|
11833
12276
|
async getABI(_id) {
|
11834
|
-
throw new
|
12277
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11835
12278
|
}
|
11836
12279
|
/**
|
11837
12280
|
* Should return true if the abi exists in the connector vinculated to the all accounts from a specific Wallet.
|
@@ -11840,7 +12283,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
11840
12283
|
* @returns Returns true if the abi exists or false if not.
|
11841
12284
|
*/
|
11842
12285
|
async hasABI(_id) {
|
11843
|
-
throw new
|
12286
|
+
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
11844
12287
|
}
|
11845
12288
|
/**
|
11846
12289
|
* Event listener for the connector.
|
@@ -11883,25 +12326,6 @@ function dispatchFuelConnectorEvent(connector) {
|
|
11883
12326
|
);
|
11884
12327
|
}
|
11885
12328
|
|
11886
|
-
// src/connectors/utils/promises.ts
|
11887
|
-
var import_errors33 = require("@fuel-ts/errors");
|
11888
|
-
function deferPromise() {
|
11889
|
-
const defer = {};
|
11890
|
-
defer.promise = new Promise((resolve, reject) => {
|
11891
|
-
defer.reject = reject;
|
11892
|
-
defer.resolve = resolve;
|
11893
|
-
});
|
11894
|
-
return defer;
|
11895
|
-
}
|
11896
|
-
async function withTimeout(promise, timeout = 1050) {
|
11897
|
-
const timeoutPromise = new Promise((resolve, reject) => {
|
11898
|
-
setTimeout(() => {
|
11899
|
-
reject(new import_errors33.FuelError(import_errors33.FuelError.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
11900
|
-
}, timeout);
|
11901
|
-
});
|
11902
|
-
return Promise.race([timeoutPromise, promise]);
|
11903
|
-
}
|
11904
|
-
|
11905
12329
|
// src/connectors/fuel.ts
|
11906
12330
|
var HAS_CONNECTOR_TIMEOUT = 2e3;
|
11907
12331
|
var PING_CACHE_TIME = 5e3;
|
@@ -12255,6 +12679,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
12255
12679
|
AbstractScriptRequest,
|
12256
12680
|
Account,
|
12257
12681
|
AddressType,
|
12682
|
+
BALANCES_PAGE_SIZE_LIMIT,
|
12258
12683
|
BLOCKS_PAGE_SIZE_LIMIT,
|
12259
12684
|
BaseTransactionRequest,
|
12260
12685
|
BaseWalletUnlocked,
|
@@ -12306,6 +12731,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
12306
12731
|
assembleReceiptByType,
|
12307
12732
|
assembleRevertError,
|
12308
12733
|
assembleTransactionSummary,
|
12734
|
+
assembleTransactionSummaryFromJson,
|
12309
12735
|
assets,
|
12310
12736
|
buildBlockExplorerUrl,
|
12311
12737
|
cacheFor,
|
@@ -12322,6 +12748,10 @@ __publicField(Fuel, "defaultConfig", {});
|
|
12322
12748
|
coinQuantityfy,
|
12323
12749
|
deferPromise,
|
12324
12750
|
deployScriptOrPredicate,
|
12751
|
+
deserializeChain,
|
12752
|
+
deserializeNodeInfo,
|
12753
|
+
deserializeProviderCache,
|
12754
|
+
deserializeReceipt,
|
12325
12755
|
dispatchFuelConnectorEvent,
|
12326
12756
|
english,
|
12327
12757
|
extractBurnedAssetsFromReceipts,
|
@@ -12386,6 +12816,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
12386
12816
|
isInputCoin,
|
12387
12817
|
isMessage,
|
12388
12818
|
isMessageCoin,
|
12819
|
+
isPredicate,
|
12389
12820
|
isRawCoin,
|
12390
12821
|
isRawMessage,
|
12391
12822
|
isRequestInputCoin,
|
@@ -12414,6 +12845,9 @@ __publicField(Fuel, "defaultConfig", {});
|
|
12414
12845
|
resolveGasDependentCosts,
|
12415
12846
|
resolveIconPaths,
|
12416
12847
|
returnZeroScript,
|
12848
|
+
serializeChain,
|
12849
|
+
serializeNodeInfo,
|
12850
|
+
serializeProviderCache,
|
12417
12851
|
transactionRequestify,
|
12418
12852
|
urlJoin,
|
12419
12853
|
validateTransactionForAssetBurn,
|