@fuel-ts/account 0.99.0 → 0.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts +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 +4116 -3431
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +970 -562
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +900 -502
- 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 +75 -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/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 +3839 -3179
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +895 -537
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +827 -469
- 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.mjs
CHANGED
@@ -732,9 +732,9 @@ import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
|
732
732
|
import { Address as Address4 } from "@fuel-ts/address";
|
733
733
|
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
734
734
|
import { ErrorCode as ErrorCode18, FuelError as FuelError20 } from "@fuel-ts/errors";
|
735
|
-
import { bn as
|
736
|
-
import { InputType as
|
737
|
-
import { arrayify as
|
735
|
+
import { bn as bn20 } from "@fuel-ts/math";
|
736
|
+
import { InputType as InputType7 } from "@fuel-ts/transactions";
|
737
|
+
import { arrayify as arrayify16, hexlify as hexlify17, isDefined as isDefined3 } from "@fuel-ts/utils";
|
738
738
|
import { clone as clone9 } from "ramda";
|
739
739
|
|
740
740
|
// src/providers/coin-quantity.ts
|
@@ -753,10 +753,9 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
753
753
|
assetId = coinQuantityLike.assetId;
|
754
754
|
max = coinQuantityLike.max ?? void 0;
|
755
755
|
}
|
756
|
-
const bnAmount = bn(amount);
|
757
756
|
return {
|
758
757
|
assetId: hexlify(assetId),
|
759
|
-
amount:
|
758
|
+
amount: bn(amount),
|
760
759
|
max: max ? bn(max) : void 0
|
761
760
|
};
|
762
761
|
};
|
@@ -773,13 +772,12 @@ var addAmountToCoinQuantities = (params) => {
|
|
773
772
|
};
|
774
773
|
|
775
774
|
// src/providers/provider.ts
|
776
|
-
import { Address as Address2 } from "@fuel-ts/address";
|
775
|
+
import { Address as Address2, isB256 } from "@fuel-ts/address";
|
777
776
|
import { ErrorCode as ErrorCode16, FuelError as FuelError18 } from "@fuel-ts/errors";
|
778
|
-
import {
|
779
|
-
import {
|
780
|
-
import { arrayify as arrayify12, hexlify as
|
781
|
-
import { checkFuelCoreVersionCompatibility, versions } from "@fuel-ts/versions";
|
782
|
-
import { equalBytes } from "@noble/curves/abstract/utils";
|
777
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
778
|
+
import { InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
|
779
|
+
import { arrayify as arrayify12, hexlify as hexlify16, DateTime as DateTime2, isDefined as isDefined2 } from "@fuel-ts/utils";
|
780
|
+
import { checkFuelCoreVersionCompatibility, gte, versions } from "@fuel-ts/versions";
|
783
781
|
import { GraphQLClient } from "graphql-request";
|
784
782
|
import gql2 from "graphql-tag";
|
785
783
|
import { clone as clone8 } from "ramda";
|
@@ -1391,6 +1389,16 @@ var EstimatePredicatesDocument = gql`
|
|
1391
1389
|
}
|
1392
1390
|
}
|
1393
1391
|
${TransactionEstimatePredicatesFragmentDoc}`;
|
1392
|
+
var EstimatePredicatesAndGasPriceDocument = gql`
|
1393
|
+
query estimatePredicatesAndGasPrice($encodedTransaction: HexString!, $blockHorizon: U32!) {
|
1394
|
+
estimatePredicates(tx: $encodedTransaction) {
|
1395
|
+
...transactionEstimatePredicatesFragment
|
1396
|
+
}
|
1397
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
1398
|
+
gasPrice
|
1399
|
+
}
|
1400
|
+
}
|
1401
|
+
${TransactionEstimatePredicatesFragmentDoc}`;
|
1394
1402
|
var GetLatestBlockDocument = gql`
|
1395
1403
|
query getLatestBlock {
|
1396
1404
|
chain {
|
@@ -1506,6 +1514,13 @@ var GetBalanceDocument = gql`
|
|
1506
1514
|
}
|
1507
1515
|
}
|
1508
1516
|
`;
|
1517
|
+
var GetBalanceV2Document = gql`
|
1518
|
+
query getBalanceV2($owner: Address!, $assetId: AssetId!) {
|
1519
|
+
balance(owner: $owner, assetId: $assetId) {
|
1520
|
+
amountU128
|
1521
|
+
}
|
1522
|
+
}
|
1523
|
+
`;
|
1509
1524
|
var GetLatestGasPriceDocument = gql`
|
1510
1525
|
query getLatestGasPrice {
|
1511
1526
|
latestGasPrice {
|
@@ -1538,6 +1553,27 @@ var GetBalancesDocument = gql`
|
|
1538
1553
|
}
|
1539
1554
|
}
|
1540
1555
|
`;
|
1556
|
+
var GetBalancesV2Document = gql`
|
1557
|
+
query getBalancesV2($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
1558
|
+
balances(
|
1559
|
+
filter: $filter
|
1560
|
+
after: $after
|
1561
|
+
before: $before
|
1562
|
+
first: $first
|
1563
|
+
last: $last
|
1564
|
+
) {
|
1565
|
+
pageInfo {
|
1566
|
+
...pageInfoFragment
|
1567
|
+
}
|
1568
|
+
edges {
|
1569
|
+
node {
|
1570
|
+
assetId
|
1571
|
+
amountU128
|
1572
|
+
}
|
1573
|
+
}
|
1574
|
+
}
|
1575
|
+
}
|
1576
|
+
${PageInfoFragmentDoc}`;
|
1541
1577
|
var GetMessagesDocument = gql`
|
1542
1578
|
query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
|
1543
1579
|
messages(
|
@@ -1592,6 +1628,15 @@ var GetRelayedTransactionStatusDocument = gql`
|
|
1592
1628
|
}
|
1593
1629
|
}
|
1594
1630
|
${RelayedTransactionStatusFragmentDoc}`;
|
1631
|
+
var GetAssetDetailsDocument = gql`
|
1632
|
+
query getAssetDetails($assetId: AssetId!) {
|
1633
|
+
assetDetails(id: $assetId) {
|
1634
|
+
subId
|
1635
|
+
contractId
|
1636
|
+
totalSupply
|
1637
|
+
}
|
1638
|
+
}
|
1639
|
+
`;
|
1595
1640
|
var DryRunDocument = gql`
|
1596
1641
|
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean, $gasPrice: U64) {
|
1597
1642
|
dryRun(
|
@@ -1692,6 +1737,9 @@ function getSdk(requester) {
|
|
1692
1737
|
estimatePredicates(variables, options) {
|
1693
1738
|
return requester(EstimatePredicatesDocument, variables, options);
|
1694
1739
|
},
|
1740
|
+
estimatePredicatesAndGasPrice(variables, options) {
|
1741
|
+
return requester(EstimatePredicatesAndGasPriceDocument, variables, options);
|
1742
|
+
},
|
1695
1743
|
getLatestBlock(variables, options) {
|
1696
1744
|
return requester(GetLatestBlockDocument, variables, options);
|
1697
1745
|
},
|
@@ -1725,6 +1773,9 @@ function getSdk(requester) {
|
|
1725
1773
|
getBalance(variables, options) {
|
1726
1774
|
return requester(GetBalanceDocument, variables, options);
|
1727
1775
|
},
|
1776
|
+
getBalanceV2(variables, options) {
|
1777
|
+
return requester(GetBalanceV2Document, variables, options);
|
1778
|
+
},
|
1728
1779
|
getLatestGasPrice(variables, options) {
|
1729
1780
|
return requester(GetLatestGasPriceDocument, variables, options);
|
1730
1781
|
},
|
@@ -1734,6 +1785,9 @@ function getSdk(requester) {
|
|
1734
1785
|
getBalances(variables, options) {
|
1735
1786
|
return requester(GetBalancesDocument, variables, options);
|
1736
1787
|
},
|
1788
|
+
getBalancesV2(variables, options) {
|
1789
|
+
return requester(GetBalancesV2Document, variables, options);
|
1790
|
+
},
|
1737
1791
|
getMessages(variables, options) {
|
1738
1792
|
return requester(GetMessagesDocument, variables, options);
|
1739
1793
|
},
|
@@ -1749,6 +1803,9 @@ function getSdk(requester) {
|
|
1749
1803
|
getRelayedTransactionStatus(variables, options) {
|
1750
1804
|
return requester(GetRelayedTransactionStatusDocument, variables, options);
|
1751
1805
|
},
|
1806
|
+
getAssetDetails(variables, options) {
|
1807
|
+
return requester(GetAssetDetailsDocument, variables, options);
|
1808
|
+
},
|
1752
1809
|
dryRun(variables, options) {
|
1753
1810
|
return requester(DryRunDocument, variables, options);
|
1754
1811
|
},
|
@@ -1783,24 +1840,23 @@ import { print } from "graphql";
|
|
1783
1840
|
// src/providers/utils/handle-gql-error-message.ts
|
1784
1841
|
import { ErrorCode, FuelError } from "@fuel-ts/errors";
|
1785
1842
|
var mapGqlErrorMessage = (error) => {
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
default:
|
1802
|
-
return new FuelError(ErrorCode.INVALID_REQUEST, error.message, {}, error);
|
1843
|
+
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)) {
|
1844
|
+
return new FuelError(
|
1845
|
+
ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
1846
|
+
`Insufficient funds or too many small value coins. Consider combining UTXOs.`,
|
1847
|
+
{},
|
1848
|
+
error
|
1849
|
+
);
|
1850
|
+
}
|
1851
|
+
if (new RegExp("resource was not found in table" /* ASSET_NOT_FOUND */).test(error.message)) {
|
1852
|
+
return new FuelError(
|
1853
|
+
ErrorCode.ASSET_NOT_FOUND,
|
1854
|
+
`Asset not found for given asset id.`,
|
1855
|
+
{},
|
1856
|
+
error
|
1857
|
+
);
|
1803
1858
|
}
|
1859
|
+
return new FuelError(ErrorCode.INVALID_REQUEST, error.message, {}, error);
|
1804
1860
|
};
|
1805
1861
|
var mapGqlErrorWithIncompatibleNodeVersion = (error, incompatibleNodeVersionMessage) => {
|
1806
1862
|
if (!incompatibleNodeVersionMessage) {
|
@@ -1900,74 +1956,16 @@ __publicField(FuelGraphqlSubscriber, "incompatibleNodeVersionMessage", false);
|
|
1900
1956
|
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
1901
1957
|
|
1902
1958
|
// src/providers/resource-cache.ts
|
1903
|
-
import {
|
1904
|
-
import { hexlify as
|
1905
|
-
var cache = /* @__PURE__ */ new Map();
|
1906
|
-
var ResourceCache = class {
|
1907
|
-
ttl;
|
1908
|
-
constructor(ttl) {
|
1909
|
-
this.ttl = ttl;
|
1910
|
-
if (typeof ttl !== "number" || this.ttl <= 0) {
|
1911
|
-
throw new FuelError3(
|
1912
|
-
ErrorCode3.INVALID_TTL,
|
1913
|
-
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
1914
|
-
);
|
1915
|
-
}
|
1916
|
-
}
|
1917
|
-
// Add resources to the cache
|
1918
|
-
set(transactionId, resources) {
|
1919
|
-
const currentTime = Date.now();
|
1920
|
-
const existingResources = cache.get(transactionId) || {
|
1921
|
-
utxos: /* @__PURE__ */ new Set(),
|
1922
|
-
messages: /* @__PURE__ */ new Set(),
|
1923
|
-
timestamp: currentTime
|
1924
|
-
};
|
1925
|
-
resources.utxos.forEach((utxo) => existingResources.utxos.add(hexlify2(utxo)));
|
1926
|
-
resources.messages.forEach((message) => existingResources.messages.add(hexlify2(message)));
|
1927
|
-
cache.set(transactionId, existingResources);
|
1928
|
-
}
|
1929
|
-
// Remove resources from the cache for a given transaction ID
|
1930
|
-
unset(transactionId) {
|
1931
|
-
cache.delete(transactionId);
|
1932
|
-
}
|
1933
|
-
// Get all cached resources and remove expired ones
|
1934
|
-
getActiveData() {
|
1935
|
-
const allResources = { utxos: [], messages: [] };
|
1936
|
-
const currentTime = Date.now();
|
1937
|
-
cache.forEach((resource, transactionId) => {
|
1938
|
-
if (currentTime - resource.timestamp < this.ttl) {
|
1939
|
-
allResources.utxos.push(...resource.utxos);
|
1940
|
-
allResources.messages.push(...resource.messages);
|
1941
|
-
} else {
|
1942
|
-
cache.delete(transactionId);
|
1943
|
-
}
|
1944
|
-
});
|
1945
|
-
return allResources;
|
1946
|
-
}
|
1947
|
-
// Check if a UTXO ID or message nonce is already cached and not expired
|
1948
|
-
isCached(key) {
|
1949
|
-
const currentTime = Date.now();
|
1950
|
-
for (const [transactionId, resourceData] of cache.entries()) {
|
1951
|
-
if (currentTime - resourceData.timestamp > this.ttl) {
|
1952
|
-
cache.delete(transactionId);
|
1953
|
-
} else if (resourceData.utxos.has(key) || resourceData.messages.has(key)) {
|
1954
|
-
return true;
|
1955
|
-
}
|
1956
|
-
}
|
1957
|
-
return false;
|
1958
|
-
}
|
1959
|
-
clear() {
|
1960
|
-
cache.clear();
|
1961
|
-
}
|
1962
|
-
};
|
1959
|
+
import { FuelError as FuelError12, ErrorCode as ErrorCode10 } from "@fuel-ts/errors";
|
1960
|
+
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
1963
1961
|
|
1964
1962
|
// src/providers/transaction-request/input.ts
|
1965
1963
|
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1966
1964
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1967
|
-
import { ErrorCode as
|
1965
|
+
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1968
1966
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1969
1967
|
import { InputType } from "@fuel-ts/transactions";
|
1970
|
-
import { arrayify, hexlify as
|
1968
|
+
import { arrayify, hexlify as hexlify2 } from "@fuel-ts/utils";
|
1971
1969
|
var inputify = (value) => {
|
1972
1970
|
const { type } = value;
|
1973
1971
|
switch (value.type) {
|
@@ -1976,11 +1974,11 @@ var inputify = (value) => {
|
|
1976
1974
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1977
1975
|
return {
|
1978
1976
|
type: InputType.Coin,
|
1979
|
-
txID:
|
1977
|
+
txID: hexlify2(arrayify(value.id).slice(0, BYTES_32)),
|
1980
1978
|
outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
|
1981
|
-
owner:
|
1979
|
+
owner: hexlify2(value.owner),
|
1982
1980
|
amount: bn2(value.amount),
|
1983
|
-
assetId:
|
1981
|
+
assetId: hexlify2(value.assetId),
|
1984
1982
|
txPointer: {
|
1985
1983
|
blockHeight: toNumber(arrayify(value.txPointer).slice(0, 8)),
|
1986
1984
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
@@ -1989,8 +1987,8 @@ var inputify = (value) => {
|
|
1989
1987
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1990
1988
|
predicateLength: bn2(predicate.length),
|
1991
1989
|
predicateDataLength: bn2(predicateData.length),
|
1992
|
-
predicate:
|
1993
|
-
predicateData:
|
1990
|
+
predicate: hexlify2(predicate),
|
1991
|
+
predicateData: hexlify2(predicateData)
|
1994
1992
|
};
|
1995
1993
|
}
|
1996
1994
|
case InputType.Contract: {
|
@@ -2004,7 +2002,7 @@ var inputify = (value) => {
|
|
2004
2002
|
blockHeight: toNumber(arrayify(value.txPointer).slice(0, 8)),
|
2005
2003
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
2006
2004
|
},
|
2007
|
-
contractID:
|
2005
|
+
contractID: hexlify2(value.contractId)
|
2008
2006
|
};
|
2009
2007
|
}
|
2010
2008
|
case InputType.Message: {
|
@@ -2013,23 +2011,23 @@ var inputify = (value) => {
|
|
2013
2011
|
const data = arrayify(value.data ?? "0x");
|
2014
2012
|
return {
|
2015
2013
|
type: InputType.Message,
|
2016
|
-
sender:
|
2017
|
-
recipient:
|
2014
|
+
sender: hexlify2(value.sender),
|
2015
|
+
recipient: hexlify2(value.recipient),
|
2018
2016
|
amount: bn2(value.amount),
|
2019
|
-
nonce:
|
2017
|
+
nonce: hexlify2(value.nonce),
|
2020
2018
|
witnessIndex: value.witnessIndex,
|
2021
2019
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
2022
2020
|
predicateLength: bn2(predicate.length),
|
2023
2021
|
predicateDataLength: bn2(predicateData.length),
|
2024
|
-
predicate:
|
2025
|
-
predicateData:
|
2026
|
-
data:
|
2022
|
+
predicate: hexlify2(predicate),
|
2023
|
+
predicateData: hexlify2(predicateData),
|
2024
|
+
data: hexlify2(data),
|
2027
2025
|
dataLength: data.length
|
2028
2026
|
};
|
2029
2027
|
}
|
2030
2028
|
default: {
|
2031
|
-
throw new
|
2032
|
-
|
2029
|
+
throw new FuelError3(
|
2030
|
+
ErrorCode3.INVALID_TRANSACTION_INPUT,
|
2033
2031
|
`Invalid transaction input type: ${type}.`
|
2034
2032
|
);
|
2035
2033
|
}
|
@@ -2038,19 +2036,19 @@ var inputify = (value) => {
|
|
2038
2036
|
|
2039
2037
|
// src/providers/transaction-request/output.ts
|
2040
2038
|
import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
2041
|
-
import { ErrorCode as
|
2039
|
+
import { ErrorCode as ErrorCode4, FuelError as FuelError4 } from "@fuel-ts/errors";
|
2042
2040
|
import { bn as bn3 } from "@fuel-ts/math";
|
2043
2041
|
import { OutputType } from "@fuel-ts/transactions";
|
2044
|
-
import { hexlify as
|
2042
|
+
import { hexlify as hexlify3 } from "@fuel-ts/utils";
|
2045
2043
|
var outputify = (value) => {
|
2046
2044
|
const { type } = value;
|
2047
2045
|
switch (type) {
|
2048
2046
|
case OutputType.Coin: {
|
2049
2047
|
return {
|
2050
2048
|
type: OutputType.Coin,
|
2051
|
-
to:
|
2049
|
+
to: hexlify3(value.to),
|
2052
2050
|
amount: bn3(value.amount),
|
2053
|
-
assetId:
|
2051
|
+
assetId: hexlify3(value.assetId)
|
2054
2052
|
};
|
2055
2053
|
}
|
2056
2054
|
case OutputType.Contract: {
|
@@ -2064,9 +2062,9 @@ var outputify = (value) => {
|
|
2064
2062
|
case OutputType.Change: {
|
2065
2063
|
return {
|
2066
2064
|
type: OutputType.Change,
|
2067
|
-
to:
|
2065
|
+
to: hexlify3(value.to),
|
2068
2066
|
amount: bn3(0),
|
2069
|
-
assetId:
|
2067
|
+
assetId: hexlify3(value.assetId)
|
2070
2068
|
};
|
2071
2069
|
}
|
2072
2070
|
case OutputType.Variable: {
|
@@ -2080,13 +2078,13 @@ var outputify = (value) => {
|
|
2080
2078
|
case OutputType.ContractCreated: {
|
2081
2079
|
return {
|
2082
2080
|
type: OutputType.ContractCreated,
|
2083
|
-
contractId:
|
2084
|
-
stateRoot:
|
2081
|
+
contractId: hexlify3(value.contractId),
|
2082
|
+
stateRoot: hexlify3(value.stateRoot)
|
2085
2083
|
};
|
2086
2084
|
}
|
2087
2085
|
default: {
|
2088
|
-
throw new
|
2089
|
-
|
2086
|
+
throw new FuelError4(
|
2087
|
+
ErrorCode4.INVALID_TRANSACTION_INPUT,
|
2090
2088
|
`Invalid transaction output type: ${type}.`
|
2091
2089
|
);
|
2092
2090
|
}
|
@@ -2098,7 +2096,7 @@ import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
|
2098
2096
|
import { Address, addressify } from "@fuel-ts/address";
|
2099
2097
|
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
2100
2098
|
import { randomBytes } from "@fuel-ts/crypto";
|
2101
|
-
import { FuelError as
|
2099
|
+
import { FuelError as FuelError9 } from "@fuel-ts/errors";
|
2102
2100
|
import { bn as bn8 } from "@fuel-ts/math";
|
2103
2101
|
import {
|
2104
2102
|
PolicyType,
|
@@ -2119,31 +2117,157 @@ var isCoin = (resource) => "id" in resource;
|
|
2119
2117
|
var isMessage = (resource) => "recipient" in resource;
|
2120
2118
|
|
2121
2119
|
// src/providers/utils/receipts.ts
|
2120
|
+
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
2121
|
+
import { FAILED_TRANSFER_TO_ADDRESS_SIGNAL } from "@fuel-ts/transactions/configs";
|
2122
|
+
|
2123
|
+
// src/providers/utils/serialization.ts
|
2122
2124
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
2123
|
-
import { ErrorCode as
|
2125
|
+
import { ErrorCode as ErrorCode5, FuelError as FuelError5 } from "@fuel-ts/errors";
|
2124
2126
|
import { bn as bn4 } from "@fuel-ts/math";
|
2125
2127
|
import { getMintedAssetId, InputMessageCoder, ReceiptType } from "@fuel-ts/transactions";
|
2126
|
-
import {
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2128
|
+
import { hexlify as hexlify4, arrayify as arrayify2 } from "@fuel-ts/utils";
|
2129
|
+
var deserializeChain = (chain) => {
|
2130
|
+
const { name, daHeight, consensusParameters } = chain;
|
2131
|
+
const {
|
2132
|
+
contractParams,
|
2133
|
+
feeParams,
|
2134
|
+
predicateParams,
|
2135
|
+
scriptParams,
|
2136
|
+
txParams,
|
2137
|
+
gasCosts,
|
2138
|
+
baseAssetId,
|
2139
|
+
chainId,
|
2140
|
+
version
|
2141
|
+
} = consensusParameters;
|
2142
|
+
return {
|
2143
|
+
name,
|
2144
|
+
baseChainHeight: bn4(daHeight),
|
2145
|
+
consensusParameters: {
|
2146
|
+
version,
|
2147
|
+
chainId: bn4(chainId),
|
2148
|
+
baseAssetId,
|
2149
|
+
feeParameters: {
|
2150
|
+
version: feeParams.version,
|
2151
|
+
gasPerByte: bn4(feeParams.gasPerByte),
|
2152
|
+
gasPriceFactor: bn4(feeParams.gasPriceFactor)
|
2153
|
+
},
|
2154
|
+
contractParameters: {
|
2155
|
+
version: contractParams.version,
|
2156
|
+
contractMaxSize: bn4(contractParams.contractMaxSize),
|
2157
|
+
maxStorageSlots: bn4(contractParams.maxStorageSlots)
|
2158
|
+
},
|
2159
|
+
txParameters: {
|
2160
|
+
version: txParams.version,
|
2161
|
+
maxInputs: bn4(txParams.maxInputs),
|
2162
|
+
maxOutputs: bn4(txParams.maxOutputs),
|
2163
|
+
maxWitnesses: bn4(txParams.maxWitnesses),
|
2164
|
+
maxGasPerTx: bn4(txParams.maxGasPerTx),
|
2165
|
+
maxSize: bn4(txParams.maxSize),
|
2166
|
+
maxBytecodeSubsections: bn4(txParams.maxBytecodeSubsections)
|
2167
|
+
},
|
2168
|
+
predicateParameters: {
|
2169
|
+
version: predicateParams.version,
|
2170
|
+
maxPredicateLength: bn4(predicateParams.maxPredicateLength),
|
2171
|
+
maxPredicateDataLength: bn4(predicateParams.maxPredicateDataLength),
|
2172
|
+
maxGasPerPredicate: bn4(predicateParams.maxGasPerPredicate),
|
2173
|
+
maxMessageDataLength: bn4(predicateParams.maxMessageDataLength)
|
2174
|
+
},
|
2175
|
+
scriptParameters: {
|
2176
|
+
version: scriptParams.version,
|
2177
|
+
maxScriptLength: bn4(scriptParams.maxScriptLength),
|
2178
|
+
maxScriptDataLength: bn4(scriptParams.maxScriptDataLength)
|
2179
|
+
},
|
2180
|
+
gasCosts
|
2134
2181
|
}
|
2135
|
-
|
2136
|
-
|
2182
|
+
};
|
2183
|
+
};
|
2184
|
+
var serializeChain = (chain) => {
|
2185
|
+
const { name, baseChainHeight, consensusParameters } = chain;
|
2186
|
+
const {
|
2187
|
+
contractParameters,
|
2188
|
+
feeParameters,
|
2189
|
+
predicateParameters,
|
2190
|
+
scriptParameters,
|
2191
|
+
txParameters,
|
2192
|
+
gasCosts,
|
2193
|
+
baseAssetId,
|
2194
|
+
chainId,
|
2195
|
+
version
|
2196
|
+
} = consensusParameters;
|
2197
|
+
return {
|
2198
|
+
name,
|
2199
|
+
daHeight: baseChainHeight.toString(),
|
2200
|
+
consensusParameters: {
|
2201
|
+
version,
|
2202
|
+
chainId: chainId.toString(),
|
2203
|
+
baseAssetId,
|
2204
|
+
feeParams: {
|
2205
|
+
version: feeParameters.version,
|
2206
|
+
gasPerByte: feeParameters.gasPerByte.toString(),
|
2207
|
+
gasPriceFactor: feeParameters.gasPriceFactor.toString()
|
2208
|
+
},
|
2209
|
+
contractParams: {
|
2210
|
+
version: contractParameters.version,
|
2211
|
+
contractMaxSize: contractParameters.contractMaxSize.toString(),
|
2212
|
+
maxStorageSlots: contractParameters.maxStorageSlots.toString()
|
2213
|
+
},
|
2214
|
+
txParams: {
|
2215
|
+
version: txParameters.version,
|
2216
|
+
maxInputs: txParameters.maxInputs.toString(),
|
2217
|
+
maxOutputs: txParameters.maxOutputs.toString(),
|
2218
|
+
maxWitnesses: txParameters.maxWitnesses.toString(),
|
2219
|
+
maxGasPerTx: txParameters.maxGasPerTx.toString(),
|
2220
|
+
maxSize: txParameters.maxSize.toString(),
|
2221
|
+
maxBytecodeSubsections: txParameters.maxBytecodeSubsections.toString()
|
2222
|
+
},
|
2223
|
+
predicateParams: {
|
2224
|
+
version: predicateParameters.version,
|
2225
|
+
maxPredicateLength: predicateParameters.maxPredicateLength.toString(),
|
2226
|
+
maxPredicateDataLength: predicateParameters.maxPredicateDataLength.toString(),
|
2227
|
+
maxGasPerPredicate: predicateParameters.maxGasPerPredicate.toString(),
|
2228
|
+
maxMessageDataLength: predicateParameters.maxMessageDataLength.toString()
|
2229
|
+
},
|
2230
|
+
scriptParams: {
|
2231
|
+
version: scriptParameters.version,
|
2232
|
+
maxScriptLength: scriptParameters.maxScriptLength.toString(),
|
2233
|
+
maxScriptDataLength: scriptParameters.maxScriptDataLength.toString()
|
2234
|
+
},
|
2235
|
+
gasCosts
|
2137
2236
|
}
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
)
|
2237
|
+
};
|
2238
|
+
};
|
2239
|
+
var deserializeNodeInfo = (nodeInfo) => {
|
2240
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
2241
|
+
return {
|
2242
|
+
maxDepth: bn4(maxDepth),
|
2243
|
+
maxTx: bn4(maxTx),
|
2244
|
+
nodeVersion,
|
2245
|
+
utxoValidation,
|
2246
|
+
vmBacktrace
|
2247
|
+
};
|
2248
|
+
};
|
2249
|
+
var serializeNodeInfo = (nodeInfo) => {
|
2250
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
2251
|
+
return {
|
2252
|
+
maxDepth: maxDepth.toString(),
|
2253
|
+
maxTx: maxTx.toString(),
|
2254
|
+
nodeVersion,
|
2255
|
+
utxoValidation,
|
2256
|
+
vmBacktrace
|
2257
|
+
};
|
2258
|
+
};
|
2259
|
+
var deserializeProviderCache = (cache2) => ({
|
2260
|
+
consensusParametersTimestamp: cache2.consensusParametersTimestamp,
|
2261
|
+
chain: deserializeChain(cache2.chain),
|
2262
|
+
nodeInfo: deserializeNodeInfo(cache2.nodeInfo)
|
2263
|
+
});
|
2264
|
+
var serializeProviderCache = async (provider) => ({
|
2265
|
+
consensusParametersTimestamp: provider.consensusParametersTimestamp,
|
2266
|
+
chain: serializeChain(await provider.getChain()),
|
2267
|
+
nodeInfo: serializeNodeInfo(await provider.getNode())
|
2268
|
+
});
|
2145
2269
|
var hexOrZero = (hex) => hex || ZeroBytes323;
|
2146
|
-
|
2270
|
+
var deserializeReceipt = (receipt) => {
|
2147
2271
|
const { receiptType } = receipt;
|
2148
2272
|
switch (receiptType) {
|
2149
2273
|
case "CALL" /* Call */: {
|
@@ -2287,7 +2411,7 @@ function assembleReceiptByType(receipt) {
|
|
2287
2411
|
recipient,
|
2288
2412
|
nonce,
|
2289
2413
|
amount,
|
2290
|
-
data:
|
2414
|
+
data: hexlify4(data)
|
2291
2415
|
});
|
2292
2416
|
const receiptMessageOut = {
|
2293
2417
|
type: ReceiptType.MessageOut,
|
@@ -2333,12 +2457,32 @@ function assembleReceiptByType(receipt) {
|
|
2333
2457
|
return burnReceipt;
|
2334
2458
|
}
|
2335
2459
|
default:
|
2336
|
-
throw new
|
2460
|
+
throw new FuelError5(ErrorCode5.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
2337
2461
|
}
|
2338
|
-
}
|
2462
|
+
};
|
2463
|
+
|
2464
|
+
// src/providers/utils/receipts.ts
|
2465
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType2.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
2466
|
+
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === ReceiptType2.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
2467
|
+
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
2468
|
+
(memo, receipt) => {
|
2469
|
+
if (doesReceiptHaveMissingOutputVariables(receipt)) {
|
2470
|
+
memo.missingOutputVariables.push(receipt);
|
2471
|
+
}
|
2472
|
+
if (doesReceiptHaveMissingContractId(receipt)) {
|
2473
|
+
memo.missingOutputContractIds.push(receipt);
|
2474
|
+
}
|
2475
|
+
return memo;
|
2476
|
+
},
|
2477
|
+
{
|
2478
|
+
missingOutputVariables: [],
|
2479
|
+
missingOutputContractIds: []
|
2480
|
+
}
|
2481
|
+
);
|
2482
|
+
var assembleReceiptByType = (gqlReceipt) => deserializeReceipt(gqlReceipt);
|
2339
2483
|
|
2340
2484
|
// src/providers/utils/block-explorer.ts
|
2341
|
-
import { ErrorCode as
|
2485
|
+
import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/errors";
|
2342
2486
|
var DEFAULT_BLOCK_EXPLORER_URL = "https://app.fuel.network";
|
2343
2487
|
var getPathFromInput = (key, value) => {
|
2344
2488
|
const pathMap = {
|
@@ -2372,15 +2516,15 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
2372
2516
|
}));
|
2373
2517
|
const hasAnyDefinedValues = definedValues.length > 0;
|
2374
2518
|
if (definedValues.length > 1) {
|
2375
|
-
throw new
|
2376
|
-
|
2519
|
+
throw new FuelError6(
|
2520
|
+
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
2377
2521
|
`Only one of the following can be passed in to buildBlockExplorerUrl: ${customInputParams.map((param) => param.key).join(", ")}.`
|
2378
2522
|
);
|
2379
2523
|
}
|
2380
2524
|
if (path && definedValues.length > 0) {
|
2381
2525
|
const inputKeys = customInputParams.map(({ key }) => key).join(", ");
|
2382
|
-
throw new
|
2383
|
-
|
2526
|
+
throw new FuelError6(
|
2527
|
+
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
2384
2528
|
`You cannot pass in a path to 'buildBlockExplorerUrl' along with any of the following: ${inputKeys}.`
|
2385
2529
|
);
|
2386
2530
|
}
|
@@ -2401,11 +2545,11 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
2401
2545
|
|
2402
2546
|
// src/providers/utils/gas.ts
|
2403
2547
|
import { bn as bn5 } from "@fuel-ts/math";
|
2404
|
-
import { ReceiptType as
|
2548
|
+
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
2405
2549
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
2406
2550
|
var getGasUsedFromReceipts = (receipts) => {
|
2407
2551
|
const scriptResult = receipts.filter(
|
2408
|
-
(receipt) => receipt.type ===
|
2552
|
+
(receipt) => receipt.type === ReceiptType3.ScriptResult
|
2409
2553
|
);
|
2410
2554
|
const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), bn5(0));
|
2411
2555
|
return gasUsed;
|
@@ -2538,13 +2682,13 @@ var calculateGasFee = (params) => {
|
|
2538
2682
|
};
|
2539
2683
|
|
2540
2684
|
// src/providers/utils/json.ts
|
2541
|
-
import { hexlify as
|
2685
|
+
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
2542
2686
|
import { clone } from "ramda";
|
2543
2687
|
function normalize(object) {
|
2544
2688
|
Object.keys(object).forEach((key) => {
|
2545
2689
|
switch (object[key]?.constructor.name) {
|
2546
2690
|
case "Uint8Array":
|
2547
|
-
object[key] =
|
2691
|
+
object[key] = hexlify5(object[key]);
|
2548
2692
|
break;
|
2549
2693
|
case "Array":
|
2550
2694
|
object[key] = normalize(object[key]);
|
@@ -2569,9 +2713,9 @@ function normalizeJSON(root) {
|
|
2569
2713
|
}
|
2570
2714
|
|
2571
2715
|
// src/providers/utils/extract-tx-error.ts
|
2572
|
-
import { ErrorCode as
|
2716
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2573
2717
|
import { bn as bn6 } from "@fuel-ts/math";
|
2574
|
-
import { ReceiptType as
|
2718
|
+
import { ReceiptType as ReceiptType4 } from "@fuel-ts/transactions";
|
2575
2719
|
import {
|
2576
2720
|
FAILED_REQUIRE_SIGNAL,
|
2577
2721
|
FAILED_ASSERT_EQ_SIGNAL,
|
@@ -2590,7 +2734,7 @@ You can read more about this error at:
|
|
2590
2734
|
|
2591
2735
|
${PANIC_DOC_URL}#variant.${statusReason}`;
|
2592
2736
|
}
|
2593
|
-
return new
|
2737
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, {
|
2594
2738
|
...metadata,
|
2595
2739
|
reason: statusReason
|
2596
2740
|
});
|
@@ -2598,7 +2742,7 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
|
|
2598
2742
|
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
2599
2743
|
var assembleRevertError = (receipts, logs, metadata) => {
|
2600
2744
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
2601
|
-
const revertReceipt = receipts.find(({ type }) => type ===
|
2745
|
+
const revertReceipt = receipts.find(({ type }) => type === ReceiptType4.Revert);
|
2602
2746
|
let reason = "";
|
2603
2747
|
if (revertReceipt) {
|
2604
2748
|
const reasonHex = bn6(revertReceipt.val).toHex();
|
@@ -2611,15 +2755,15 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2611
2755
|
break;
|
2612
2756
|
}
|
2613
2757
|
case FAILED_ASSERT_EQ_SIGNAL: {
|
2614
|
-
const
|
2758
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
2615
2759
|
reason = "assert_eq";
|
2616
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${
|
2760
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
2617
2761
|
break;
|
2618
2762
|
}
|
2619
2763
|
case FAILED_ASSERT_NE_SIGNAL: {
|
2620
|
-
const
|
2764
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2621
2765
|
reason = "assert_ne";
|
2622
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${
|
2766
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
2623
2767
|
break;
|
2624
2768
|
}
|
2625
2769
|
case FAILED_ASSERT_SIGNAL:
|
@@ -2627,12 +2771,12 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2627
2771
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
2628
2772
|
break;
|
2629
2773
|
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
2630
|
-
reason = "
|
2631
|
-
errorMessage = `The transaction reverted because it's missing an "
|
2774
|
+
reason = "MissingOutputVariable";
|
2775
|
+
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
2632
2776
|
break;
|
2633
2777
|
default:
|
2634
|
-
throw new
|
2635
|
-
|
2778
|
+
throw new FuelError7(
|
2779
|
+
ErrorCode7.UNKNOWN,
|
2636
2780
|
`The transaction reverted with an unknown reason: ${revertReceipt.val}`,
|
2637
2781
|
{
|
2638
2782
|
...metadata,
|
@@ -2641,15 +2785,15 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2641
2785
|
);
|
2642
2786
|
}
|
2643
2787
|
}
|
2644
|
-
return new
|
2788
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, {
|
2645
2789
|
...metadata,
|
2646
2790
|
reason
|
2647
2791
|
});
|
2648
2792
|
};
|
2649
2793
|
var extractTxError = (params) => {
|
2650
2794
|
const { receipts, statusReason, logs } = params;
|
2651
|
-
const isPanic = receipts.some(({ type }) => type ===
|
2652
|
-
const isRevert = receipts.some(({ type }) => type ===
|
2795
|
+
const isPanic = receipts.some(({ type }) => type === ReceiptType4.Panic);
|
2796
|
+
const isRevert = receipts.some(({ type }) => type === ReceiptType4.Revert);
|
2653
2797
|
const metadata = {
|
2654
2798
|
logs,
|
2655
2799
|
receipts,
|
@@ -2686,9 +2830,10 @@ var NoWitnessByOwnerError = class extends Error {
|
|
2686
2830
|
};
|
2687
2831
|
|
2688
2832
|
// src/providers/transaction-request/helpers.ts
|
2689
|
-
import { ErrorCode as
|
2833
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2690
2834
|
import { bn as bn7 } from "@fuel-ts/math";
|
2691
2835
|
import { InputType as InputType2, OutputType as OutputType2 } from "@fuel-ts/transactions";
|
2836
|
+
import { hexlify as hexlify6 } from "@fuel-ts/utils";
|
2692
2837
|
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
2693
2838
|
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
2694
2839
|
var isRequestInputMessageWithoutData = (input) => input.type === InputType2.Message && bn7(input.data).isZero();
|
@@ -2696,6 +2841,7 @@ var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequ
|
|
2696
2841
|
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2697
2842
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2698
2843
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
2844
|
+
var isPredicate = (input) => isRequestInputCoinOrMessage(input) && !!input.predicate && hexlify6(input.predicate) !== "0x";
|
2699
2845
|
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
2700
2846
|
if (isRequestInputCoin(input) && input.assetId === assetId) {
|
2701
2847
|
return acc.add(input.amount);
|
@@ -2757,7 +2903,7 @@ var validateTransactionForAssetBurn = (baseAssetId, transactionRequest, enableAs
|
|
2757
2903
|
"Add the relevant change outputs to the transaction to avoid burning assets.",
|
2758
2904
|
"Or enable asset burn, upon sending the transaction."
|
2759
2905
|
].join("\n");
|
2760
|
-
throw new
|
2906
|
+
throw new FuelError8(ErrorCode8.ASSET_BURN_DETECTED, message);
|
2761
2907
|
};
|
2762
2908
|
|
2763
2909
|
// src/providers/transaction-request/witness.ts
|
@@ -2776,6 +2922,8 @@ var BaseTransactionRequest = class {
|
|
2776
2922
|
tip;
|
2777
2923
|
/** Block until which tx cannot be included */
|
2778
2924
|
maturity;
|
2925
|
+
/** The block number after which the transaction is no longer valid. */
|
2926
|
+
expiration;
|
2779
2927
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
2780
2928
|
maxFee;
|
2781
2929
|
/** The maximum amount of witness data allowed for the transaction */
|
@@ -2786,6 +2934,12 @@ var BaseTransactionRequest = class {
|
|
2786
2934
|
outputs = [];
|
2787
2935
|
/** List of witnesses */
|
2788
2936
|
witnesses = [];
|
2937
|
+
/**
|
2938
|
+
* @hidden
|
2939
|
+
*
|
2940
|
+
* The current status of the transaction
|
2941
|
+
*/
|
2942
|
+
flag = { state: void 0, transactionId: void 0, summary: void 0 };
|
2789
2943
|
/**
|
2790
2944
|
* Constructor for initializing a base transaction request.
|
2791
2945
|
*
|
@@ -2794,6 +2948,7 @@ var BaseTransactionRequest = class {
|
|
2794
2948
|
constructor({
|
2795
2949
|
tip,
|
2796
2950
|
maturity,
|
2951
|
+
expiration,
|
2797
2952
|
maxFee,
|
2798
2953
|
witnessLimit,
|
2799
2954
|
inputs,
|
@@ -2802,6 +2957,7 @@ var BaseTransactionRequest = class {
|
|
2802
2957
|
} = {}) {
|
2803
2958
|
this.tip = tip ? bn8(tip) : void 0;
|
2804
2959
|
this.maturity = maturity && maturity > 0 ? maturity : void 0;
|
2960
|
+
this.expiration = expiration && expiration > 0 ? expiration : void 0;
|
2805
2961
|
this.witnessLimit = isDefined(witnessLimit) ? bn8(witnessLimit) : void 0;
|
2806
2962
|
this.maxFee = bn8(maxFee);
|
2807
2963
|
this.inputs = inputs ?? [];
|
@@ -2811,7 +2967,7 @@ var BaseTransactionRequest = class {
|
|
2811
2967
|
static getPolicyMeta(req) {
|
2812
2968
|
let policyTypes = 0;
|
2813
2969
|
const policies = [];
|
2814
|
-
const { tip, witnessLimit, maturity } = req;
|
2970
|
+
const { tip, witnessLimit, maturity, expiration } = req;
|
2815
2971
|
if (bn8(tip).gt(0)) {
|
2816
2972
|
policyTypes += PolicyType.Tip;
|
2817
2973
|
policies.push({ data: bn8(tip), type: PolicyType.Tip });
|
@@ -2826,6 +2982,10 @@ var BaseTransactionRequest = class {
|
|
2826
2982
|
}
|
2827
2983
|
policyTypes += PolicyType.MaxFee;
|
2828
2984
|
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
|
2985
|
+
if (expiration && expiration > 0) {
|
2986
|
+
policyTypes += PolicyType.Expiration;
|
2987
|
+
policies.push({ data: expiration, type: PolicyType.Expiration });
|
2988
|
+
}
|
2829
2989
|
return {
|
2830
2990
|
policyTypes,
|
2831
2991
|
policies
|
@@ -2898,8 +3058,7 @@ var BaseTransactionRequest = class {
|
|
2898
3058
|
* @returns The index of the created witness.
|
2899
3059
|
*/
|
2900
3060
|
addEmptyWitness() {
|
2901
|
-
this.addWitness(concat([ZeroBytes324, ZeroBytes324]));
|
2902
|
-
return this.witnesses.length - 1;
|
3061
|
+
return this.addWitness(concat([ZeroBytes324, ZeroBytes324]));
|
2903
3062
|
}
|
2904
3063
|
/**
|
2905
3064
|
* Updates the witness for a given owner and signature.
|
@@ -3142,7 +3301,7 @@ var BaseTransactionRequest = class {
|
|
3142
3301
|
* @hidden
|
3143
3302
|
*/
|
3144
3303
|
metadataGas(_gasCosts) {
|
3145
|
-
throw new
|
3304
|
+
throw new FuelError9(FuelError9.CODES.NOT_IMPLEMENTED, "Not implemented");
|
3146
3305
|
}
|
3147
3306
|
/**
|
3148
3307
|
* @hidden
|
@@ -3269,6 +3428,21 @@ var BaseTransactionRequest = class {
|
|
3269
3428
|
byteLength() {
|
3270
3429
|
return this.toTransactionBytes().byteLength;
|
3271
3430
|
}
|
3431
|
+
/**
|
3432
|
+
* @hidden
|
3433
|
+
*
|
3434
|
+
* Used internally to update the state of a transaction request.
|
3435
|
+
*
|
3436
|
+
* @param state - The state to update.
|
3437
|
+
*/
|
3438
|
+
updateState(chainId, state, summary) {
|
3439
|
+
if (!state) {
|
3440
|
+
this.flag = { state: void 0, transactionId: void 0, summary: void 0 };
|
3441
|
+
return;
|
3442
|
+
}
|
3443
|
+
const transactionId = this.getTransactionId(chainId);
|
3444
|
+
this.flag = { state, transactionId, summary };
|
3445
|
+
}
|
3272
3446
|
};
|
3273
3447
|
|
3274
3448
|
// src/providers/transaction-request/blob-transaction-request.ts
|
@@ -3750,7 +3924,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3750
3924
|
};
|
3751
3925
|
|
3752
3926
|
// src/providers/transaction-request/upgrade-transaction-request.ts
|
3753
|
-
import { FuelError as
|
3927
|
+
import { FuelError as FuelError10 } from "@fuel-ts/errors";
|
3754
3928
|
import { hash } from "@fuel-ts/hasher";
|
3755
3929
|
import {
|
3756
3930
|
TransactionType as TransactionType5,
|
@@ -3857,7 +4031,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3857
4031
|
}
|
3858
4032
|
};
|
3859
4033
|
} else {
|
3860
|
-
throw new
|
4034
|
+
throw new FuelError10(FuelError10.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3861
4035
|
}
|
3862
4036
|
return {
|
3863
4037
|
type: TransactionType5.Upgrade,
|
@@ -3899,7 +4073,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3899
4073
|
txBytesSize
|
3900
4074
|
});
|
3901
4075
|
}
|
3902
|
-
throw new
|
4076
|
+
throw new FuelError10(FuelError10.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3903
4077
|
}
|
3904
4078
|
};
|
3905
4079
|
|
@@ -4014,7 +4188,7 @@ var AbstractScriptRequest = class {
|
|
4014
4188
|
};
|
4015
4189
|
|
4016
4190
|
// src/providers/transaction-request/utils.ts
|
4017
|
-
import { ErrorCode as
|
4191
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError11 } from "@fuel-ts/errors";
|
4018
4192
|
import { TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
4019
4193
|
var transactionRequestify = (obj) => {
|
4020
4194
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest || obj instanceof UpgradeTransactionRequest || obj instanceof UploadTransactionRequest) {
|
@@ -4038,8 +4212,8 @@ var transactionRequestify = (obj) => {
|
|
4038
4212
|
return UploadTransactionRequest.from(obj);
|
4039
4213
|
}
|
4040
4214
|
default: {
|
4041
|
-
throw new
|
4042
|
-
|
4215
|
+
throw new FuelError11(
|
4216
|
+
ErrorCode9.UNSUPPORTED_TRANSACTION_TYPE,
|
4043
4217
|
`Unsupported transaction type: ${type}.`
|
4044
4218
|
);
|
4045
4219
|
}
|
@@ -4051,6 +4225,97 @@ var isTransactionTypeBlob = (request2) => request2.type === TransactionType7.Blo
|
|
4051
4225
|
var isTransactionTypeUpgrade = (request2) => request2.type === TransactionType7.Upgrade;
|
4052
4226
|
var isTransactionTypeUpload = (request2) => request2.type === TransactionType7.Upload;
|
4053
4227
|
|
4228
|
+
// src/providers/resource-cache.ts
|
4229
|
+
var cache = /* @__PURE__ */ new Map();
|
4230
|
+
var ResourceCache = class {
|
4231
|
+
ttl;
|
4232
|
+
constructor(ttl) {
|
4233
|
+
this.ttl = ttl;
|
4234
|
+
if (typeof ttl !== "number" || this.ttl <= 0) {
|
4235
|
+
throw new FuelError12(
|
4236
|
+
ErrorCode10.INVALID_TTL,
|
4237
|
+
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
4238
|
+
);
|
4239
|
+
}
|
4240
|
+
}
|
4241
|
+
// Add resources to the cache
|
4242
|
+
set(transactionId, inputs) {
|
4243
|
+
const transactionResourceCache = this.setupResourcesCache(inputs);
|
4244
|
+
cache.set(transactionId, transactionResourceCache);
|
4245
|
+
}
|
4246
|
+
unset(transactionId) {
|
4247
|
+
cache.delete(transactionId);
|
4248
|
+
}
|
4249
|
+
getActiveData(owner) {
|
4250
|
+
const activeData = { utxos: [], messages: [] };
|
4251
|
+
const currentTime = Date.now();
|
4252
|
+
const expired = [];
|
4253
|
+
cache.forEach((resource, transactionId) => {
|
4254
|
+
const isActive = currentTime - resource.timestamp < this.ttl;
|
4255
|
+
if (isActive) {
|
4256
|
+
const resourcesFromOwner = resource.owners.get(owner);
|
4257
|
+
if (resourcesFromOwner) {
|
4258
|
+
activeData.utxos.push(...resourcesFromOwner.utxos);
|
4259
|
+
activeData.messages.push(...resourcesFromOwner.messages);
|
4260
|
+
}
|
4261
|
+
} else {
|
4262
|
+
expired.push(transactionId);
|
4263
|
+
}
|
4264
|
+
});
|
4265
|
+
expired.forEach(this.unset);
|
4266
|
+
activeData.utxos.reverse();
|
4267
|
+
activeData.messages.reverse();
|
4268
|
+
return activeData;
|
4269
|
+
}
|
4270
|
+
isCached(owner, key) {
|
4271
|
+
const currentTime = Date.now();
|
4272
|
+
let cached = false;
|
4273
|
+
const expired = [];
|
4274
|
+
for (const [transactionId, resourceData] of cache.entries()) {
|
4275
|
+
const isActive = currentTime - resourceData.timestamp < this.ttl;
|
4276
|
+
if (isActive) {
|
4277
|
+
const resourcesFromOwner = resourceData.owners.get(owner);
|
4278
|
+
if (resourcesFromOwner?.utxos.has(key) || resourcesFromOwner?.messages.has(key)) {
|
4279
|
+
cached = true;
|
4280
|
+
break;
|
4281
|
+
}
|
4282
|
+
} else {
|
4283
|
+
expired.push(transactionId);
|
4284
|
+
}
|
4285
|
+
}
|
4286
|
+
expired.forEach(this.unset);
|
4287
|
+
return cached;
|
4288
|
+
}
|
4289
|
+
clear() {
|
4290
|
+
cache.clear();
|
4291
|
+
}
|
4292
|
+
setupResourcesCache(inputs) {
|
4293
|
+
const currentTime = Date.now();
|
4294
|
+
const transactionResourcesCache = {
|
4295
|
+
owners: /* @__PURE__ */ new Map(),
|
4296
|
+
timestamp: currentTime
|
4297
|
+
};
|
4298
|
+
inputs.filter(isRequestInputCoinOrMessage).forEach((input) => {
|
4299
|
+
const { owner, key, type } = this.extractResourceData(input);
|
4300
|
+
if (!transactionResourcesCache.owners.has(owner)) {
|
4301
|
+
transactionResourcesCache.owners.set(owner, { utxos: /* @__PURE__ */ new Set(), messages: /* @__PURE__ */ new Set() });
|
4302
|
+
}
|
4303
|
+
if (type === "utxo") {
|
4304
|
+
transactionResourcesCache.owners.get(owner)?.utxos.add(key);
|
4305
|
+
} else {
|
4306
|
+
transactionResourcesCache.owners.get(owner)?.messages.add(key);
|
4307
|
+
}
|
4308
|
+
});
|
4309
|
+
return transactionResourcesCache;
|
4310
|
+
}
|
4311
|
+
extractResourceData(input) {
|
4312
|
+
if (isRequestInputCoin(input)) {
|
4313
|
+
return { owner: hexlify14(input.owner), key: hexlify14(input.id), type: "utxo" };
|
4314
|
+
}
|
4315
|
+
return { owner: hexlify14(input.recipient), key: hexlify14(input.nonce), type: "message" };
|
4316
|
+
}
|
4317
|
+
};
|
4318
|
+
|
4054
4319
|
// src/providers/transaction-response/transaction-response.ts
|
4055
4320
|
import { ErrorCode as ErrorCode14, FuelError as FuelError16 } from "@fuel-ts/errors";
|
4056
4321
|
import { bn as bn16 } from "@fuel-ts/math";
|
@@ -4060,7 +4325,7 @@ import { arrayify as arrayify11, assertUnreachable } from "@fuel-ts/utils";
|
|
4060
4325
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
4061
4326
|
import { bn as bn15 } from "@fuel-ts/math";
|
4062
4327
|
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
4063
|
-
import { DateTime, hexlify as
|
4328
|
+
import { DateTime, hexlify as hexlify15 } from "@fuel-ts/utils";
|
4064
4329
|
|
4065
4330
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
4066
4331
|
import { bn as bn12 } from "@fuel-ts/math";
|
@@ -4132,40 +4397,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
4132
4397
|
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
4133
4398
|
import { ErrorCode as ErrorCode12, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4134
4399
|
import { bn as bn13 } from "@fuel-ts/math";
|
4135
|
-
import { ReceiptType as
|
4136
|
-
|
4137
|
-
// src/providers/transaction-summary/call.ts
|
4138
|
-
import { Interface as Interface2 } from "@fuel-ts/abi-coder";
|
4139
|
-
var getFunctionCall = ({ abi, receipt }) => {
|
4140
|
-
const abiInterface = new Interface2(abi);
|
4141
|
-
const callFunctionSelector = receipt.param1.toHex(8);
|
4142
|
-
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
4143
|
-
const inputs = functionFragment.jsonFn.inputs;
|
4144
|
-
const encodedArgs = receipt.param2.toHex();
|
4145
|
-
let argumentsProvided;
|
4146
|
-
const data = functionFragment.decodeArguments(encodedArgs);
|
4147
|
-
if (data) {
|
4148
|
-
argumentsProvided = inputs.reduce((prev, input, index) => {
|
4149
|
-
const value = data[index];
|
4150
|
-
const name = input.name;
|
4151
|
-
if (name) {
|
4152
|
-
return {
|
4153
|
-
...prev,
|
4154
|
-
// reparse to remove bn
|
4155
|
-
[name]: JSON.parse(JSON.stringify(value))
|
4156
|
-
};
|
4157
|
-
}
|
4158
|
-
return prev;
|
4159
|
-
}, {});
|
4160
|
-
}
|
4161
|
-
const call = {
|
4162
|
-
functionSignature: functionFragment.signature,
|
4163
|
-
functionName: functionFragment.name,
|
4164
|
-
argumentsProvided,
|
4165
|
-
...receipt.amount?.isZero() ? {} : { amount: receipt.amount, assetId: receipt.assetId }
|
4166
|
-
};
|
4167
|
-
return call;
|
4168
|
-
};
|
4400
|
+
import { ReceiptType as ReceiptType5, TransactionType as TransactionType9 } from "@fuel-ts/transactions";
|
4169
4401
|
|
4170
4402
|
// src/providers/transaction-summary/input.ts
|
4171
4403
|
import { ErrorCode as ErrorCode11, FuelError as FuelError13 } from "@fuel-ts/errors";
|
@@ -4363,10 +4595,10 @@ function hasSameAssetId(a) {
|
|
4363
4595
|
return (b) => a.assetId === b.assetId;
|
4364
4596
|
}
|
4365
4597
|
function getReceiptsCall(receipts) {
|
4366
|
-
return getReceiptsByType(receipts,
|
4598
|
+
return getReceiptsByType(receipts, ReceiptType5.Call);
|
4367
4599
|
}
|
4368
4600
|
function getReceiptsMessageOut(receipts) {
|
4369
|
-
return getReceiptsByType(receipts,
|
4601
|
+
return getReceiptsByType(receipts, ReceiptType5.MessageOut);
|
4370
4602
|
}
|
4371
4603
|
function mergeAssets(op1, op2) {
|
4372
4604
|
const assets1 = op1.assetsSent || [];
|
@@ -4404,7 +4636,11 @@ function mergeOperations(existing, toAdd) {
|
|
4404
4636
|
return {
|
4405
4637
|
...existing,
|
4406
4638
|
assetsSent: mergeAssetsSent(existing, toAdd),
|
4407
|
-
calls: mergeCalls(existing, toAdd)
|
4639
|
+
calls: mergeCalls(existing, toAdd),
|
4640
|
+
receipts: [
|
4641
|
+
...existing.receipts || [],
|
4642
|
+
...toAdd.receipts?.filter((r) => !existing.receipts?.some((er) => er === r)) || []
|
4643
|
+
]
|
4408
4644
|
};
|
4409
4645
|
}
|
4410
4646
|
function addOperation(operations, toAdd) {
|
@@ -4415,7 +4651,7 @@ function addOperation(operations, toAdd) {
|
|
4415
4651
|
return operations.map((op, index) => index === existingIndex ? mergeOperations(op, toAdd) : op);
|
4416
4652
|
}
|
4417
4653
|
function getReceiptsTransferOut(receipts) {
|
4418
|
-
return getReceiptsByType(receipts,
|
4654
|
+
return getReceiptsByType(receipts, ReceiptType5.TransferOut);
|
4419
4655
|
}
|
4420
4656
|
function getWithdrawFromFuelOperations({
|
4421
4657
|
inputs,
|
@@ -4444,7 +4680,8 @@ function getWithdrawFromFuelOperations({
|
|
4444
4680
|
amount: receipt.amount,
|
4445
4681
|
assetId: baseAssetId
|
4446
4682
|
}
|
4447
|
-
]
|
4683
|
+
],
|
4684
|
+
receipts: [receipt]
|
4448
4685
|
});
|
4449
4686
|
return newWithdrawFromFuelOps;
|
4450
4687
|
}
|
@@ -4454,19 +4691,12 @@ function getWithdrawFromFuelOperations({
|
|
4454
4691
|
);
|
4455
4692
|
return withdrawFromFuelOperations;
|
4456
4693
|
}
|
4457
|
-
function getContractCalls(contractInput, abiMap,
|
4694
|
+
function getContractCalls(contractInput, abiMap, _receipt, _rawPayload, _maxInputs) {
|
4458
4695
|
const abi = abiMap?.[contractInput.contractID];
|
4459
4696
|
if (!abi) {
|
4460
4697
|
return [];
|
4461
4698
|
}
|
4462
|
-
return [
|
4463
|
-
getFunctionCall({
|
4464
|
-
abi,
|
4465
|
-
receipt,
|
4466
|
-
rawPayload,
|
4467
|
-
maxInputs
|
4468
|
-
})
|
4469
|
-
];
|
4699
|
+
return [];
|
4470
4700
|
}
|
4471
4701
|
function getAssetsSent(receipt) {
|
4472
4702
|
return receipt.amount?.isZero() ? void 0 : [
|
@@ -4496,7 +4726,8 @@ function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload,
|
|
4496
4726
|
address: receipt.to
|
4497
4727
|
},
|
4498
4728
|
assetsSent: getAssetsSent(receipt),
|
4499
|
-
calls
|
4729
|
+
calls,
|
4730
|
+
receipts: [receipt]
|
4500
4731
|
}
|
4501
4732
|
];
|
4502
4733
|
}
|
@@ -4553,7 +4784,8 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
4553
4784
|
assetId: assetId.toString(),
|
4554
4785
|
amount
|
4555
4786
|
}
|
4556
|
-
]
|
4787
|
+
],
|
4788
|
+
receipts: [receipt]
|
4557
4789
|
};
|
4558
4790
|
}
|
4559
4791
|
function getTransferOperations({
|
@@ -4598,11 +4830,11 @@ function getTransferOperations({
|
|
4598
4830
|
});
|
4599
4831
|
const transferReceipts = getReceiptsByType(
|
4600
4832
|
receipts,
|
4601
|
-
|
4833
|
+
ReceiptType5.Transfer
|
4602
4834
|
);
|
4603
4835
|
const transferOutReceipts = getReceiptsByType(
|
4604
4836
|
receipts,
|
4605
|
-
|
4837
|
+
ReceiptType5.TransferOut
|
4606
4838
|
);
|
4607
4839
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
4608
4840
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -4686,12 +4918,12 @@ function getOperations({
|
|
4686
4918
|
}
|
4687
4919
|
|
4688
4920
|
// src/providers/transaction-summary/receipt.ts
|
4689
|
-
import { ReceiptType as
|
4690
|
-
var processGqlReceipt = (gqlReceipt) =>
|
4921
|
+
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
4922
|
+
var processGqlReceipt = (gqlReceipt) => deserializeReceipt(gqlReceipt);
|
4691
4923
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
4692
4924
|
const mintedAssets = [];
|
4693
4925
|
receipts.forEach((receipt) => {
|
4694
|
-
if (receipt.type ===
|
4926
|
+
if (receipt.type === ReceiptType6.Mint) {
|
4695
4927
|
mintedAssets.push({
|
4696
4928
|
subId: receipt.subId,
|
4697
4929
|
contractId: receipt.contractId,
|
@@ -4705,7 +4937,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
4705
4937
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
4706
4938
|
const burnedAssets = [];
|
4707
4939
|
receipts.forEach((receipt) => {
|
4708
|
-
if (receipt.type ===
|
4940
|
+
if (receipt.type === ReceiptType6.Burn) {
|
4709
4941
|
burnedAssets.push({
|
4710
4942
|
subId: receipt.subId,
|
4711
4943
|
contractId: receipt.contractId,
|
@@ -4802,7 +5034,7 @@ function assembleTransactionSummary(params) {
|
|
4802
5034
|
baseAssetId
|
4803
5035
|
} = params;
|
4804
5036
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
4805
|
-
const rawPayload =
|
5037
|
+
const rawPayload = hexlify15(transactionBytes);
|
4806
5038
|
const operations = getOperations({
|
4807
5039
|
transactionType: transaction.type,
|
4808
5040
|
inputs: transaction.inputs || [],
|
@@ -4864,13 +5096,13 @@ function assembleTransactionSummary(params) {
|
|
4864
5096
|
}
|
4865
5097
|
|
4866
5098
|
// src/providers/transaction-response/getDecodedLogs.ts
|
4867
|
-
import { Interface as
|
4868
|
-
import { ReceiptType as
|
5099
|
+
import { Interface as Interface2, BigNumberCoder } from "@fuel-ts/abi-coder";
|
5100
|
+
import { ReceiptType as ReceiptType7 } from "@fuel-ts/transactions";
|
4869
5101
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
4870
5102
|
return receipts.reduce((logs, receipt) => {
|
4871
|
-
if (receipt.type ===
|
4872
|
-
const interfaceToUse = new
|
4873
|
-
const data = receipt.type ===
|
5103
|
+
if (receipt.type === ReceiptType7.LogData || receipt.type === ReceiptType7.Log) {
|
5104
|
+
const interfaceToUse = new Interface2(externalAbis[receipt.id] || mainAbi);
|
5105
|
+
const data = receipt.type === ReceiptType7.Log ? new BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
4874
5106
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
4875
5107
|
logs.push(decodedLog);
|
4876
5108
|
}
|
@@ -4992,7 +5224,7 @@ var TransactionResponse = class {
|
|
4992
5224
|
switch (status?.type) {
|
4993
5225
|
case "SuccessStatus":
|
4994
5226
|
case "FailureStatus":
|
4995
|
-
return status.receipts.map(
|
5227
|
+
return status.receipts.map(deserializeReceipt);
|
4996
5228
|
default:
|
4997
5229
|
return [];
|
4998
5230
|
}
|
@@ -5116,7 +5348,6 @@ var TransactionResponse = class {
|
|
5116
5348
|
const { receipts } = transactionResult;
|
5117
5349
|
const status = this.status ?? this.gqlTransaction?.status;
|
5118
5350
|
if (status?.type === "FailureStatus") {
|
5119
|
-
this.unsetResourceCache();
|
5120
5351
|
const { reason } = status;
|
5121
5352
|
throw extractTxError({
|
5122
5353
|
receipts,
|
@@ -5133,6 +5364,7 @@ var TransactionResponse = class {
|
|
5133
5364
|
*/
|
5134
5365
|
async waitForResult(contractsAbiMap) {
|
5135
5366
|
await this.waitForStatusChange();
|
5367
|
+
this.unsetResourceCache();
|
5136
5368
|
return this.assembleResult(contractsAbiMap);
|
5137
5369
|
}
|
5138
5370
|
/**
|
@@ -5185,6 +5417,22 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
5185
5417
|
};
|
5186
5418
|
}
|
5187
5419
|
|
5420
|
+
// src/providers/utils/helpers.ts
|
5421
|
+
var adjustResourcesToExclude = (params) => {
|
5422
|
+
const { userInput, cached, maxInputs } = params;
|
5423
|
+
const final = { ...userInput };
|
5424
|
+
let total = final.utxos.length + final.messages.length;
|
5425
|
+
if (total >= maxInputs) {
|
5426
|
+
return final;
|
5427
|
+
}
|
5428
|
+
final.utxos = [...final.utxos, ...cached.utxos.slice(0, maxInputs - total)];
|
5429
|
+
total = final.utxos.length + final.messages.length;
|
5430
|
+
if (total < maxInputs) {
|
5431
|
+
final.messages = [...final.messages, ...cached.messages.slice(0, maxInputs - total)];
|
5432
|
+
}
|
5433
|
+
return final;
|
5434
|
+
};
|
5435
|
+
|
5188
5436
|
// src/providers/utils/validate-pagination-args.ts
|
5189
5437
|
import { FuelError as FuelError17, ErrorCode as ErrorCode15 } from "@fuel-ts/errors";
|
5190
5438
|
var validatePaginationArgs = (params) => {
|
@@ -5224,64 +5472,10 @@ var validatePaginationArgs = (params) => {
|
|
5224
5472
|
var MAX_RETRIES = 10;
|
5225
5473
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
5226
5474
|
var TRANSACTIONS_PAGE_SIZE_LIMIT = 60;
|
5475
|
+
var BALANCES_PAGE_SIZE_LIMIT = 100;
|
5227
5476
|
var BLOCKS_PAGE_SIZE_LIMIT = 5;
|
5228
5477
|
var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
|
5229
5478
|
var GAS_USED_MODIFIER = 1.2;
|
5230
|
-
var processGqlChain = (chain) => {
|
5231
|
-
const { name, daHeight, consensusParameters } = chain;
|
5232
|
-
const {
|
5233
|
-
contractParams,
|
5234
|
-
feeParams,
|
5235
|
-
predicateParams,
|
5236
|
-
scriptParams,
|
5237
|
-
txParams,
|
5238
|
-
gasCosts,
|
5239
|
-
baseAssetId,
|
5240
|
-
chainId,
|
5241
|
-
version
|
5242
|
-
} = consensusParameters;
|
5243
|
-
return {
|
5244
|
-
name,
|
5245
|
-
baseChainHeight: bn17(daHeight),
|
5246
|
-
consensusParameters: {
|
5247
|
-
version,
|
5248
|
-
chainId: bn17(chainId),
|
5249
|
-
baseAssetId,
|
5250
|
-
feeParameters: {
|
5251
|
-
version: feeParams.version,
|
5252
|
-
gasPerByte: bn17(feeParams.gasPerByte),
|
5253
|
-
gasPriceFactor: bn17(feeParams.gasPriceFactor)
|
5254
|
-
},
|
5255
|
-
contractParameters: {
|
5256
|
-
version: contractParams.version,
|
5257
|
-
contractMaxSize: bn17(contractParams.contractMaxSize),
|
5258
|
-
maxStorageSlots: bn17(contractParams.maxStorageSlots)
|
5259
|
-
},
|
5260
|
-
txParameters: {
|
5261
|
-
version: txParams.version,
|
5262
|
-
maxInputs: bn17(txParams.maxInputs),
|
5263
|
-
maxOutputs: bn17(txParams.maxOutputs),
|
5264
|
-
maxWitnesses: bn17(txParams.maxWitnesses),
|
5265
|
-
maxGasPerTx: bn17(txParams.maxGasPerTx),
|
5266
|
-
maxSize: bn17(txParams.maxSize),
|
5267
|
-
maxBytecodeSubsections: bn17(txParams.maxBytecodeSubsections)
|
5268
|
-
},
|
5269
|
-
predicateParameters: {
|
5270
|
-
version: predicateParams.version,
|
5271
|
-
maxPredicateLength: bn17(predicateParams.maxPredicateLength),
|
5272
|
-
maxPredicateDataLength: bn17(predicateParams.maxPredicateDataLength),
|
5273
|
-
maxGasPerPredicate: bn17(predicateParams.maxGasPerPredicate),
|
5274
|
-
maxMessageDataLength: bn17(predicateParams.maxMessageDataLength)
|
5275
|
-
},
|
5276
|
-
scriptParameters: {
|
5277
|
-
version: scriptParams.version,
|
5278
|
-
maxScriptLength: bn17(scriptParams.maxScriptLength),
|
5279
|
-
maxScriptDataLength: bn17(scriptParams.maxScriptDataLength)
|
5280
|
-
},
|
5281
|
-
gasCosts
|
5282
|
-
}
|
5283
|
-
};
|
5284
|
-
};
|
5285
5479
|
var _cacheInputs, cacheInputs_fn;
|
5286
5480
|
var _Provider = class {
|
5287
5481
|
/**
|
@@ -5303,13 +5497,19 @@ var _Provider = class {
|
|
5303
5497
|
/** @hidden */
|
5304
5498
|
__publicField(this, "urlWithoutAuth");
|
5305
5499
|
/** @hidden */
|
5500
|
+
__publicField(this, "features", {
|
5501
|
+
balancePagination: false,
|
5502
|
+
amount128: false
|
5503
|
+
});
|
5504
|
+
/** @hidden */
|
5306
5505
|
__publicField(this, "consensusParametersTimestamp");
|
5307
5506
|
__publicField(this, "options", {
|
5308
5507
|
timeout: void 0,
|
5309
5508
|
resourceCacheTTL: void 0,
|
5310
5509
|
fetch: void 0,
|
5311
5510
|
retryOptions: void 0,
|
5312
|
-
headers: void 0
|
5511
|
+
headers: void 0,
|
5512
|
+
cache: void 0
|
5313
5513
|
});
|
5314
5514
|
const { url: rawUrl, urlWithoutAuth, headers: authHeaders } = _Provider.extractBasicAuth(url);
|
5315
5515
|
this.url = rawUrl;
|
@@ -5323,7 +5523,13 @@ var _Provider = class {
|
|
5323
5523
|
headers
|
5324
5524
|
};
|
5325
5525
|
this.operations = this.createOperations();
|
5326
|
-
const { resourceCacheTTL } = this.options;
|
5526
|
+
const { resourceCacheTTL, cache: cache2 } = this.options;
|
5527
|
+
if (cache2) {
|
5528
|
+
const { consensusParametersTimestamp, chain, nodeInfo } = deserializeProviderCache(cache2);
|
5529
|
+
this.consensusParametersTimestamp = consensusParametersTimestamp;
|
5530
|
+
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
5531
|
+
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
5532
|
+
}
|
5327
5533
|
if (isDefined2(resourceCacheTTL)) {
|
5328
5534
|
if (resourceCacheTTL !== -1) {
|
5329
5535
|
this.cache = new ResourceCache(resourceCacheTTL);
|
@@ -5382,7 +5588,8 @@ var _Provider = class {
|
|
5382
5588
|
* Initialize Provider async stuff
|
5383
5589
|
*/
|
5384
5590
|
async init() {
|
5385
|
-
await this.fetchChainAndNodeInfo();
|
5591
|
+
const { nodeInfo } = await this.fetchChainAndNodeInfo();
|
5592
|
+
this.setupFeatures(nodeInfo.nodeVersion);
|
5386
5593
|
return this;
|
5387
5594
|
}
|
5388
5595
|
/**
|
@@ -5453,15 +5660,9 @@ var _Provider = class {
|
|
5453
5660
|
}
|
5454
5661
|
} catch (_err) {
|
5455
5662
|
const data = await this.operations.getChainAndNodeInfo();
|
5456
|
-
nodeInfo =
|
5457
|
-
maxDepth: bn17(data.nodeInfo.maxDepth),
|
5458
|
-
maxTx: bn17(data.nodeInfo.maxTx),
|
5459
|
-
nodeVersion: data.nodeInfo.nodeVersion,
|
5460
|
-
utxoValidation: data.nodeInfo.utxoValidation,
|
5461
|
-
vmBacktrace: data.nodeInfo.vmBacktrace
|
5462
|
-
};
|
5663
|
+
nodeInfo = deserializeNodeInfo(data.nodeInfo);
|
5463
5664
|
_Provider.setIncompatibleNodeVersionMessage(nodeInfo);
|
5464
|
-
chain =
|
5665
|
+
chain = deserializeChain(data.chain);
|
5465
5666
|
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
5466
5667
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
5467
5668
|
this.consensusParametersTimestamp = Date.now();
|
@@ -5539,6 +5740,15 @@ var _Provider = class {
|
|
5539
5740
|
});
|
5540
5741
|
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
5541
5742
|
}
|
5743
|
+
/**
|
5744
|
+
* @hidden
|
5745
|
+
*/
|
5746
|
+
setupFeatures(nodeVersion) {
|
5747
|
+
if (gte(nodeVersion, "0.41.0")) {
|
5748
|
+
this.features.balancePagination = true;
|
5749
|
+
this.features.amount128 = true;
|
5750
|
+
}
|
5751
|
+
}
|
5542
5752
|
/**
|
5543
5753
|
* Returns the version of the connected node.
|
5544
5754
|
*
|
@@ -5570,13 +5780,7 @@ var _Provider = class {
|
|
5570
5780
|
*/
|
5571
5781
|
async fetchNode() {
|
5572
5782
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
5573
|
-
const processedNodeInfo =
|
5574
|
-
maxDepth: bn17(nodeInfo.maxDepth),
|
5575
|
-
maxTx: bn17(nodeInfo.maxTx),
|
5576
|
-
nodeVersion: nodeInfo.nodeVersion,
|
5577
|
-
utxoValidation: nodeInfo.utxoValidation,
|
5578
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
5579
|
-
};
|
5783
|
+
const processedNodeInfo = deserializeNodeInfo(nodeInfo);
|
5580
5784
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = processedNodeInfo;
|
5581
5785
|
return processedNodeInfo;
|
5582
5786
|
}
|
@@ -5587,7 +5791,7 @@ var _Provider = class {
|
|
5587
5791
|
*/
|
5588
5792
|
async fetchChain() {
|
5589
5793
|
const { chain } = await this.operations.getChain();
|
5590
|
-
const processedChain =
|
5794
|
+
const processedChain = deserializeChain(chain);
|
5591
5795
|
_Provider.chainInfoCache[this.urlWithoutAuth] = processedChain;
|
5592
5796
|
return processedChain;
|
5593
5797
|
}
|
@@ -5614,6 +5818,21 @@ var _Provider = class {
|
|
5614
5818
|
} = all;
|
5615
5819
|
return baseAssetId;
|
5616
5820
|
}
|
5821
|
+
/**
|
5822
|
+
* Retrieves the details of an asset given its ID.
|
5823
|
+
*
|
5824
|
+
* @param assetId - The unique identifier of the asset.
|
5825
|
+
* @returns A promise that resolves to an object containing the asset details.
|
5826
|
+
*/
|
5827
|
+
async getAssetDetails(assetId) {
|
5828
|
+
const { assetDetails } = await this.operations.getAssetDetails({ assetId });
|
5829
|
+
const { contractId, subId, totalSupply } = assetDetails;
|
5830
|
+
return {
|
5831
|
+
subId,
|
5832
|
+
contractId,
|
5833
|
+
totalSupply: bn17(totalSupply)
|
5834
|
+
};
|
5835
|
+
}
|
5617
5836
|
/**
|
5618
5837
|
* @hidden
|
5619
5838
|
*/
|
@@ -5657,7 +5876,7 @@ var _Provider = class {
|
|
5657
5876
|
await this.estimateTxDependencies(transactionRequest);
|
5658
5877
|
}
|
5659
5878
|
await this.validateTransaction(transactionRequest);
|
5660
|
-
const encodedTransaction =
|
5879
|
+
const encodedTransaction = hexlify16(transactionRequest.toTransactionBytes());
|
5661
5880
|
let abis;
|
5662
5881
|
if (isTransactionTypeScript(transactionRequest)) {
|
5663
5882
|
abis = transactionRequest.abis;
|
@@ -5682,48 +5901,70 @@ var _Provider = class {
|
|
5682
5901
|
if (estimateTxDependencies) {
|
5683
5902
|
return this.estimateTxDependencies(transactionRequest);
|
5684
5903
|
}
|
5685
|
-
const encodedTransaction =
|
5904
|
+
const encodedTransaction = hexlify16(transactionRequest.toTransactionBytes());
|
5686
5905
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
5687
5906
|
encodedTransactions: encodedTransaction,
|
5688
5907
|
utxoValidation: utxoValidation || false
|
5689
5908
|
});
|
5690
5909
|
const [{ receipts: rawReceipts, status: dryRunStatus }] = dryRunStatuses;
|
5691
|
-
const receipts = rawReceipts.map(
|
5910
|
+
const receipts = rawReceipts.map(deserializeReceipt);
|
5692
5911
|
return { receipts, dryRunStatus };
|
5693
5912
|
}
|
5694
5913
|
/**
|
5695
|
-
*
|
5914
|
+
* Estimates the gas usage for predicates in a transaction request.
|
5696
5915
|
*
|
5697
5916
|
* @template T - The type of the transaction request object.
|
5698
5917
|
*
|
5699
|
-
* @param transactionRequest - The transaction request
|
5700
|
-
* @returns A promise that resolves to the
|
5918
|
+
* @param transactionRequest - The transaction request to estimate predicates for.
|
5919
|
+
* @returns A promise that resolves to the updated transaction request with estimated gas usage for predicates.
|
5701
5920
|
*/
|
5702
5921
|
async estimatePredicates(transactionRequest) {
|
5703
|
-
const shouldEstimatePredicates =
|
5704
|
-
|
5705
|
-
(input) => "predicate" in input && input.predicate && !equalBytes(arrayify12(input.predicate), arrayify12("0x")) && new BN2(input.predicateGasUsed).isZero()
|
5706
|
-
)
|
5922
|
+
const shouldEstimatePredicates = transactionRequest.inputs.some(
|
5923
|
+
(input) => isPredicate(input) && bn17(input.predicateGasUsed).isZero()
|
5707
5924
|
);
|
5708
5925
|
if (!shouldEstimatePredicates) {
|
5709
5926
|
return transactionRequest;
|
5710
5927
|
}
|
5711
|
-
const encodedTransaction =
|
5928
|
+
const encodedTransaction = hexlify16(transactionRequest.toTransactionBytes());
|
5712
5929
|
const response = await this.operations.estimatePredicates({
|
5713
5930
|
encodedTransaction
|
5714
5931
|
});
|
5715
|
-
const {
|
5716
|
-
|
5717
|
-
|
5718
|
-
|
5719
|
-
|
5720
|
-
if ("predicateGasUsed" in input && bn17(input.predicateGasUsed).gt(0)) {
|
5721
|
-
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
5722
|
-
}
|
5723
|
-
});
|
5724
|
-
}
|
5932
|
+
const { estimatePredicates } = response;
|
5933
|
+
transactionRequest = this.parseEstimatePredicatesResponse(
|
5934
|
+
transactionRequest,
|
5935
|
+
estimatePredicates
|
5936
|
+
);
|
5725
5937
|
return transactionRequest;
|
5726
5938
|
}
|
5939
|
+
/**
|
5940
|
+
* Estimates the gas price and predicates for a given transaction request and block horizon.
|
5941
|
+
*
|
5942
|
+
* @param transactionRequest - The transaction request to estimate predicates and gas price for.
|
5943
|
+
* @param blockHorizon - The block horizon to use for gas price estimation.
|
5944
|
+
* @returns A promise that resolves to an object containing the updated transaction
|
5945
|
+
* request and the estimated gas price.
|
5946
|
+
*/
|
5947
|
+
async estimatePredicatesAndGasPrice(transactionRequest, blockHorizon) {
|
5948
|
+
const shouldEstimatePredicates = transactionRequest.inputs.some(
|
5949
|
+
(input) => isPredicate(input) && bn17(input.predicateGasUsed).isZero()
|
5950
|
+
);
|
5951
|
+
if (!shouldEstimatePredicates) {
|
5952
|
+
const gasPrice2 = await this.estimateGasPrice(blockHorizon);
|
5953
|
+
return { transactionRequest, gasPrice: gasPrice2 };
|
5954
|
+
}
|
5955
|
+
const {
|
5956
|
+
estimateGasPrice: { gasPrice },
|
5957
|
+
estimatePredicates
|
5958
|
+
} = await this.operations.estimatePredicatesAndGasPrice({
|
5959
|
+
blockHorizon: String(blockHorizon),
|
5960
|
+
encodedTransaction: hexlify16(transactionRequest.toTransactionBytes())
|
5961
|
+
});
|
5962
|
+
transactionRequest = this.parseEstimatePredicatesResponse(
|
5963
|
+
transactionRequest,
|
5964
|
+
estimatePredicates
|
5965
|
+
);
|
5966
|
+
return { transactionRequest, gasPrice: bn17(gasPrice) };
|
5967
|
+
}
|
5727
5968
|
/**
|
5728
5969
|
* Will dryRun a transaction and check for missing dependencies.
|
5729
5970
|
*
|
@@ -5737,11 +5978,13 @@ var _Provider = class {
|
|
5737
5978
|
async estimateTxDependencies(transactionRequest, { gasPrice: gasPriceParam } = {}) {
|
5738
5979
|
if (isTransactionTypeCreate(transactionRequest)) {
|
5739
5980
|
return {
|
5981
|
+
rawReceipts: [],
|
5740
5982
|
receipts: [],
|
5741
5983
|
outputVariables: 0,
|
5742
5984
|
missingContractIds: []
|
5743
5985
|
};
|
5744
5986
|
}
|
5987
|
+
let rawReceipts = [];
|
5745
5988
|
let receipts = [];
|
5746
5989
|
const missingContractIds = [];
|
5747
5990
|
let outputVariables = 0;
|
@@ -5750,13 +5993,14 @@ var _Provider = class {
|
|
5750
5993
|
const gasPrice = gasPriceParam ?? await this.estimateGasPrice(10);
|
5751
5994
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
5752
5995
|
const {
|
5753
|
-
dryRun: [{ receipts:
|
5996
|
+
dryRun: [{ receipts: serializedReceipts, status }]
|
5754
5997
|
} = await this.operations.dryRun({
|
5755
|
-
encodedTransactions: [
|
5998
|
+
encodedTransactions: [hexlify16(transactionRequest.toTransactionBytes())],
|
5756
5999
|
utxoValidation: false,
|
5757
6000
|
gasPrice: gasPrice.toString()
|
5758
6001
|
});
|
5759
|
-
|
6002
|
+
rawReceipts = serializedReceipts;
|
6003
|
+
receipts = serializedReceipts.map(deserializeReceipt);
|
5760
6004
|
dryRunStatus = status;
|
5761
6005
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
5762
6006
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
@@ -5777,6 +6021,7 @@ var _Provider = class {
|
|
5777
6021
|
}
|
5778
6022
|
}
|
5779
6023
|
return {
|
6024
|
+
rawReceipts,
|
5780
6025
|
receipts,
|
5781
6026
|
outputVariables,
|
5782
6027
|
missingContractIds,
|
@@ -5795,6 +6040,7 @@ var _Provider = class {
|
|
5795
6040
|
*/
|
5796
6041
|
async estimateMultipleTxDependencies(transactionRequests) {
|
5797
6042
|
const results = transactionRequests.map(() => ({
|
6043
|
+
rawReceipts: [],
|
5798
6044
|
receipts: [],
|
5799
6045
|
outputVariables: 0,
|
5800
6046
|
missingContractIds: [],
|
@@ -5804,7 +6050,7 @@ var _Provider = class {
|
|
5804
6050
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
5805
6051
|
allRequests.forEach((req, index) => {
|
5806
6052
|
if (isTransactionTypeScript(req)) {
|
5807
|
-
serializedTransactionsMap.set(index,
|
6053
|
+
serializedTransactionsMap.set(index, hexlify16(req.toTransactionBytes()));
|
5808
6054
|
}
|
5809
6055
|
});
|
5810
6056
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -5822,7 +6068,7 @@ var _Provider = class {
|
|
5822
6068
|
const requestIdx = transactionsToProcess[i];
|
5823
6069
|
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
5824
6070
|
const result = results[requestIdx];
|
5825
|
-
result.receipts = rawReceipts.map(
|
6071
|
+
result.receipts = rawReceipts.map(deserializeReceipt);
|
5826
6072
|
result.dryRunStatus = status;
|
5827
6073
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
5828
6074
|
result.receipts
|
@@ -5840,7 +6086,7 @@ var _Provider = class {
|
|
5840
6086
|
transactionRequest: request2
|
5841
6087
|
});
|
5842
6088
|
request2.maxFee = maxFee;
|
5843
|
-
serializedTransactionsMap.set(requestIdx,
|
6089
|
+
serializedTransactionsMap.set(requestIdx, hexlify16(request2.toTransactionBytes()));
|
5844
6090
|
nextRoundTransactions.push(requestIdx);
|
5845
6091
|
}
|
5846
6092
|
}
|
@@ -5861,13 +6107,13 @@ var _Provider = class {
|
|
5861
6107
|
if (estimateTxDependencies) {
|
5862
6108
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
5863
6109
|
}
|
5864
|
-
const encodedTransactions = transactionRequests.map((tx) =>
|
6110
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify16(tx.toTransactionBytes()));
|
5865
6111
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
5866
6112
|
encodedTransactions,
|
5867
6113
|
utxoValidation: utxoValidation || false
|
5868
6114
|
});
|
5869
6115
|
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
5870
|
-
const receipts = rawReceipts.map(
|
6116
|
+
const receipts = rawReceipts.map(deserializeReceipt);
|
5871
6117
|
return { receipts, dryRunStatus: status };
|
5872
6118
|
});
|
5873
6119
|
return results;
|
@@ -5961,14 +6207,14 @@ var _Provider = class {
|
|
5961
6207
|
if (estimateTxDependencies) {
|
5962
6208
|
return this.estimateTxDependencies(transactionRequest);
|
5963
6209
|
}
|
5964
|
-
const encodedTransactions = [
|
6210
|
+
const encodedTransactions = [hexlify16(transactionRequest.toTransactionBytes())];
|
5965
6211
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
5966
6212
|
encodedTransactions,
|
5967
6213
|
utxoValidation: true
|
5968
6214
|
});
|
5969
6215
|
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
5970
6216
|
const { id, receipts, status } = dryRunStatus;
|
5971
|
-
const processedReceipts = receipts.map(
|
6217
|
+
const processedReceipts = receipts.map(deserializeReceipt);
|
5972
6218
|
return { id, receipts: processedReceipts, status };
|
5973
6219
|
});
|
5974
6220
|
return { receipts: callResult[0].receipts };
|
@@ -5999,14 +6245,20 @@ var _Provider = class {
|
|
5999
6245
|
await signatureCallback(signedRequest);
|
6000
6246
|
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
6001
6247
|
}
|
6002
|
-
|
6248
|
+
let gasPrice;
|
6249
|
+
if (gasPriceParam) {
|
6250
|
+
gasPrice = gasPriceParam;
|
6251
|
+
await this.estimatePredicates(signedRequest);
|
6252
|
+
} else {
|
6253
|
+
({ gasPrice } = await this.estimatePredicatesAndGasPrice(signedRequest, 10));
|
6254
|
+
}
|
6003
6255
|
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
6004
|
-
const gasPrice = gasPriceParam ?? await this.estimateGasPrice(10);
|
6005
6256
|
let { maxFee, maxGas, minFee, minGas, gasLimit } = await this.estimateTxGasAndFee({
|
6006
6257
|
// Fetches and returns a gas price
|
6007
6258
|
transactionRequest: signedRequest,
|
6008
6259
|
gasPrice
|
6009
6260
|
});
|
6261
|
+
let rawReceipts = [];
|
6010
6262
|
let receipts = [];
|
6011
6263
|
let dryRunStatus;
|
6012
6264
|
let missingContractIds = [];
|
@@ -6018,7 +6270,7 @@ var _Provider = class {
|
|
6018
6270
|
if (signatureCallback) {
|
6019
6271
|
await signatureCallback(txRequestClone);
|
6020
6272
|
}
|
6021
|
-
({ receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone, { gasPrice }));
|
6273
|
+
({ rawReceipts, receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone, { gasPrice }));
|
6022
6274
|
if (dryRunStatus && "reason" in dryRunStatus) {
|
6023
6275
|
throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
|
6024
6276
|
}
|
@@ -6031,7 +6283,12 @@ var _Provider = class {
|
|
6031
6283
|
gasPrice
|
6032
6284
|
}));
|
6033
6285
|
}
|
6286
|
+
const transactionSummary = {
|
6287
|
+
gasPrice: gasPrice.toString(),
|
6288
|
+
receipts: rawReceipts
|
6289
|
+
};
|
6034
6290
|
return {
|
6291
|
+
rawReceipts,
|
6035
6292
|
receipts,
|
6036
6293
|
gasUsed,
|
6037
6294
|
gasPrice,
|
@@ -6044,7 +6301,8 @@ var _Provider = class {
|
|
6044
6301
|
addedSignatures,
|
6045
6302
|
estimatedPredicates: txRequestClone.inputs,
|
6046
6303
|
dryRunStatus,
|
6047
|
-
updateMaxFee
|
6304
|
+
updateMaxFee,
|
6305
|
+
transactionSummary
|
6048
6306
|
};
|
6049
6307
|
}
|
6050
6308
|
/**
|
@@ -6065,7 +6323,7 @@ var _Provider = class {
|
|
6065
6323
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
6066
6324
|
inputArgs: paginationArgs
|
6067
6325
|
}),
|
6068
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId &&
|
6326
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && hexlify16(assetId) }
|
6069
6327
|
});
|
6070
6328
|
const coins = edges.map(({ node }) => ({
|
6071
6329
|
id: node.utxoId,
|
@@ -6090,23 +6348,33 @@ var _Provider = class {
|
|
6090
6348
|
*/
|
6091
6349
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
6092
6350
|
const ownerAddress = new Address2(owner);
|
6093
|
-
|
6094
|
-
messages: excludedIds?.messages?.map((nonce) =>
|
6095
|
-
utxos: excludedIds?.utxos?.map((id) =>
|
6351
|
+
let idsToExclude = {
|
6352
|
+
messages: excludedIds?.messages?.map((nonce) => hexlify16(nonce)) || [],
|
6353
|
+
utxos: excludedIds?.utxos?.map((id) => hexlify16(id)) || []
|
6096
6354
|
};
|
6097
6355
|
if (this.cache) {
|
6098
|
-
const cached = this.cache.getActiveData();
|
6099
|
-
|
6100
|
-
|
6356
|
+
const cached = this.cache.getActiveData(ownerAddress.toB256());
|
6357
|
+
if (cached.utxos.length || cached.messages.length) {
|
6358
|
+
const {
|
6359
|
+
consensusParameters: {
|
6360
|
+
txParameters: { maxInputs }
|
6361
|
+
}
|
6362
|
+
} = await this.getChain();
|
6363
|
+
idsToExclude = adjustResourcesToExclude({
|
6364
|
+
userInput: idsToExclude,
|
6365
|
+
cached,
|
6366
|
+
maxInputs: maxInputs.toNumber()
|
6367
|
+
});
|
6368
|
+
}
|
6101
6369
|
}
|
6102
6370
|
const coinsQuery = {
|
6103
6371
|
owner: ownerAddress.toB256(),
|
6104
6372
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
6105
|
-
assetId:
|
6106
|
-
amount: amount.toString(10),
|
6373
|
+
assetId: hexlify16(assetId),
|
6374
|
+
amount: (amount.eqn(0) ? bn17(1) : amount).toString(10),
|
6107
6375
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
6108
6376
|
})),
|
6109
|
-
excludedIds:
|
6377
|
+
excludedIds: idsToExclude
|
6110
6378
|
};
|
6111
6379
|
const result = await this.operations.getCoinsToSpend(coinsQuery);
|
6112
6380
|
const coins = result.coinsToSpend.flat().map((coin) => {
|
@@ -6164,7 +6432,7 @@ var _Provider = class {
|
|
6164
6432
|
} = await this.operations.getLatestBlock();
|
6165
6433
|
block = latestBlock;
|
6166
6434
|
} else {
|
6167
|
-
const isblockId = typeof idOrHeight === "string" && idOrHeight
|
6435
|
+
const isblockId = typeof idOrHeight === "string" && isB256(idOrHeight);
|
6168
6436
|
const variables = isblockId ? { blockId: idOrHeight } : { height: bn17(idOrHeight).toString(10) };
|
6169
6437
|
const response = await this.operations.getBlock(variables);
|
6170
6438
|
block = response.block;
|
@@ -6235,8 +6503,10 @@ var _Provider = class {
|
|
6235
6503
|
variables = { blockHeight: bn17(idOrHeight).toString(10) };
|
6236
6504
|
} else if (idOrHeight === "latest") {
|
6237
6505
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
6238
|
-
} else {
|
6506
|
+
} else if (typeof idOrHeight === "string" && isB256(idOrHeight)) {
|
6239
6507
|
variables = { blockId: idOrHeight };
|
6508
|
+
} else {
|
6509
|
+
variables = { blockHeight: bn17(idOrHeight).toString() };
|
6240
6510
|
}
|
6241
6511
|
const { block } = await this.operations.getBlockWithTransactions(variables);
|
6242
6512
|
if (!block) {
|
@@ -6352,7 +6622,7 @@ var _Provider = class {
|
|
6352
6622
|
async getContractBalance(contractId, assetId) {
|
6353
6623
|
const { contractBalance } = await this.operations.getContractBalance({
|
6354
6624
|
contract: new Address2(contractId).toB256(),
|
6355
|
-
asset:
|
6625
|
+
asset: hexlify16(assetId)
|
6356
6626
|
});
|
6357
6627
|
return bn17(contractBalance.amount, 10);
|
6358
6628
|
}
|
@@ -6364,11 +6634,20 @@ var _Provider = class {
|
|
6364
6634
|
* @returns A promise that resolves to the balance.
|
6365
6635
|
*/
|
6366
6636
|
async getBalance(owner, assetId) {
|
6367
|
-
const
|
6368
|
-
|
6369
|
-
|
6637
|
+
const ownerStr = new Address2(owner).toB256();
|
6638
|
+
const assetIdStr = hexlify16(assetId);
|
6639
|
+
if (!this.features.amount128) {
|
6640
|
+
const { balance: balance2 } = await this.operations.getBalance({
|
6641
|
+
owner: ownerStr,
|
6642
|
+
assetId: assetIdStr
|
6643
|
+
});
|
6644
|
+
return bn17(balance2.amount, 10);
|
6645
|
+
}
|
6646
|
+
const { balance } = await this.operations.getBalanceV2({
|
6647
|
+
owner: ownerStr,
|
6648
|
+
assetId: assetIdStr
|
6370
6649
|
});
|
6371
|
-
return bn17(balance.
|
6650
|
+
return bn17(balance.amountU128, 10);
|
6372
6651
|
}
|
6373
6652
|
/**
|
6374
6653
|
* Returns balances for the given owner.
|
@@ -6377,7 +6656,16 @@ var _Provider = class {
|
|
6377
6656
|
* @param paginationArgs - Pagination arguments (optional).
|
6378
6657
|
* @returns A promise that resolves to the balances.
|
6379
6658
|
*/
|
6380
|
-
async getBalances(owner) {
|
6659
|
+
async getBalances(owner, paginationArgs) {
|
6660
|
+
if (!this.features.balancePagination) {
|
6661
|
+
return this.getBalancesV1(owner, paginationArgs);
|
6662
|
+
}
|
6663
|
+
return this.getBalancesV2(owner, paginationArgs);
|
6664
|
+
}
|
6665
|
+
/**
|
6666
|
+
* @hidden
|
6667
|
+
*/
|
6668
|
+
async getBalancesV1(owner, _paginationArgs) {
|
6381
6669
|
const {
|
6382
6670
|
balances: { edges }
|
6383
6671
|
} = await this.operations.getBalances({
|
@@ -6394,6 +6682,25 @@ var _Provider = class {
|
|
6394
6682
|
}));
|
6395
6683
|
return { balances };
|
6396
6684
|
}
|
6685
|
+
/**
|
6686
|
+
* @hidden
|
6687
|
+
*/
|
6688
|
+
async getBalancesV2(owner, paginationArgs) {
|
6689
|
+
const {
|
6690
|
+
balances: { edges, pageInfo }
|
6691
|
+
} = await this.operations.getBalancesV2({
|
6692
|
+
...validatePaginationArgs({
|
6693
|
+
inputArgs: paginationArgs,
|
6694
|
+
paginationLimit: BALANCES_PAGE_SIZE_LIMIT
|
6695
|
+
}),
|
6696
|
+
filter: { owner: new Address2(owner).toB256() }
|
6697
|
+
});
|
6698
|
+
const balances = edges.map(({ node }) => ({
|
6699
|
+
assetId: node.assetId,
|
6700
|
+
amount: bn17(node.amountU128)
|
6701
|
+
}));
|
6702
|
+
return { balances, pageInfo };
|
6703
|
+
}
|
6397
6704
|
/**
|
6398
6705
|
* Returns message for the given address.
|
6399
6706
|
*
|
@@ -6460,15 +6767,12 @@ var _Provider = class {
|
|
6460
6767
|
if (commitBlockHeight) {
|
6461
6768
|
inputObject = {
|
6462
6769
|
...inputObject,
|
6463
|
-
//
|
6464
|
-
// This should
|
6770
|
+
// Convert BN into a number string required on the query
|
6771
|
+
// This should probably be fixed on the fuel client side
|
6465
6772
|
commitBlockHeight: commitBlockHeight.toNumber().toString()
|
6466
6773
|
};
|
6467
6774
|
}
|
6468
6775
|
const result = await this.operations.getMessageProof(inputObject);
|
6469
|
-
if (!result.messageProof) {
|
6470
|
-
return null;
|
6471
|
-
}
|
6472
6776
|
const {
|
6473
6777
|
messageProof,
|
6474
6778
|
messageBlockHeader,
|
@@ -6577,16 +6881,15 @@ var _Provider = class {
|
|
6577
6881
|
* @returns A promise that resolves to the result of the check.
|
6578
6882
|
*/
|
6579
6883
|
async isUserAccount(id) {
|
6580
|
-
const
|
6581
|
-
|
6582
|
-
contractId: id,
|
6583
|
-
transactionId: id
|
6584
|
-
});
|
6585
|
-
if (contract || blob || transaction) {
|
6586
|
-
return false;
|
6587
|
-
}
|
6588
|
-
return true;
|
6884
|
+
const type = await this.getAddressType(id);
|
6885
|
+
return type === "Account";
|
6589
6886
|
}
|
6887
|
+
/**
|
6888
|
+
* Determines the type of address based on the provided ID.
|
6889
|
+
*
|
6890
|
+
* @param id - The ID to be checked.
|
6891
|
+
* @returns A promise that resolves to a string indicating the type of address.
|
6892
|
+
*/
|
6590
6893
|
async getAddressType(id) {
|
6591
6894
|
const { contract, blob, transaction } = await this.operations.isUserAccount({
|
6592
6895
|
blobId: id,
|
@@ -6602,6 +6905,13 @@ var _Provider = class {
|
|
6602
6905
|
if (transaction) {
|
6603
6906
|
return "Transaction";
|
6604
6907
|
}
|
6908
|
+
try {
|
6909
|
+
const asset = await this.getAssetDetails(id);
|
6910
|
+
if (asset) {
|
6911
|
+
return "Asset";
|
6912
|
+
}
|
6913
|
+
} catch (e) {
|
6914
|
+
}
|
6605
6915
|
return "Account";
|
6606
6916
|
}
|
6607
6917
|
/**
|
@@ -6676,6 +6986,19 @@ var _Provider = class {
|
|
6676
6986
|
statusReason: status.reason
|
6677
6987
|
});
|
6678
6988
|
}
|
6989
|
+
/**
|
6990
|
+
* @hidden
|
6991
|
+
*/
|
6992
|
+
parseEstimatePredicatesResponse(transactionRequest, { inputs }) {
|
6993
|
+
if (inputs) {
|
6994
|
+
inputs.forEach((input, i) => {
|
6995
|
+
if (input && "predicateGasUsed" in input && bn17(input.predicateGasUsed).gt(0)) {
|
6996
|
+
transactionRequest.inputs[i].predicateGasUsed = input.predicateGasUsed;
|
6997
|
+
}
|
6998
|
+
});
|
6999
|
+
}
|
7000
|
+
return transactionRequest;
|
7001
|
+
}
|
6679
7002
|
};
|
6680
7003
|
var Provider = _Provider;
|
6681
7004
|
_cacheInputs = new WeakSet();
|
@@ -6683,18 +7006,7 @@ cacheInputs_fn = function(inputs, transactionId) {
|
|
6683
7006
|
if (!this.cache) {
|
6684
7007
|
return;
|
6685
7008
|
}
|
6686
|
-
|
6687
|
-
(acc, input) => {
|
6688
|
-
if (input.type === InputType7.Coin) {
|
6689
|
-
acc.utxos.push(input.id);
|
6690
|
-
} else if (input.type === InputType7.Message) {
|
6691
|
-
acc.messages.push(input.nonce);
|
6692
|
-
}
|
6693
|
-
return acc;
|
6694
|
-
},
|
6695
|
-
{ utxos: [], messages: [] }
|
6696
|
-
);
|
6697
|
-
this.cache.set(transactionId, inputsToCache);
|
7009
|
+
this.cache.set(transactionId, inputs);
|
6698
7010
|
};
|
6699
7011
|
/** @hidden */
|
6700
7012
|
__publicField(Provider, "chainInfoCache", {});
|
@@ -6727,7 +7039,7 @@ async function getTransactionSummary(params) {
|
|
6727
7039
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
6728
7040
|
txReceipts = gqlTransaction.status.receipts;
|
6729
7041
|
}
|
6730
|
-
const receipts = txReceipts.map(
|
7042
|
+
const receipts = txReceipts.map(deserializeReceipt);
|
6731
7043
|
const {
|
6732
7044
|
consensusParameters: {
|
6733
7045
|
feeParameters: { gasPerByte, gasPriceFactor },
|
@@ -6811,7 +7123,7 @@ async function getTransactionsSummaries(params) {
|
|
6811
7123
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
6812
7124
|
txReceipts = gqlTransaction.status.receipts;
|
6813
7125
|
}
|
6814
|
-
const receipts = txReceipts.map(
|
7126
|
+
const receipts = txReceipts.map(deserializeReceipt);
|
6815
7127
|
const transactionSummary = assembleTransactionSummary({
|
6816
7128
|
id,
|
6817
7129
|
receipts,
|
@@ -6838,6 +7150,39 @@ async function getTransactionsSummaries(params) {
|
|
6838
7150
|
};
|
6839
7151
|
}
|
6840
7152
|
|
7153
|
+
// src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
|
7154
|
+
import { bn as bn19 } from "@fuel-ts/math";
|
7155
|
+
import { TransactionCoder as TransactionCoder7 } from "@fuel-ts/transactions";
|
7156
|
+
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
7157
|
+
var assembleTransactionSummaryFromJson = async (opts) => {
|
7158
|
+
const { provider, transactionSummary } = opts;
|
7159
|
+
const { id, transactionBytes, gasPrice, receipts } = transactionSummary;
|
7160
|
+
const {
|
7161
|
+
consensusParameters: {
|
7162
|
+
baseAssetId,
|
7163
|
+
txParameters: { maxInputs, maxGasPerTx },
|
7164
|
+
feeParameters: { gasPriceFactor, gasPerByte },
|
7165
|
+
gasCosts
|
7166
|
+
}
|
7167
|
+
} = await provider.getChain();
|
7168
|
+
const deserializedTransactionBytes = arrayify14(transactionBytes);
|
7169
|
+
const [transaction] = new TransactionCoder7().decode(deserializedTransactionBytes, 0);
|
7170
|
+
return assembleTransactionSummary({
|
7171
|
+
id,
|
7172
|
+
transaction,
|
7173
|
+
transactionBytes: deserializedTransactionBytes,
|
7174
|
+
receipts: receipts.map(deserializeReceipt),
|
7175
|
+
gasPrice: bn19(gasPrice),
|
7176
|
+
// From chain
|
7177
|
+
baseAssetId,
|
7178
|
+
maxInputs,
|
7179
|
+
gasCosts,
|
7180
|
+
maxGasPerTx,
|
7181
|
+
gasPerByte,
|
7182
|
+
gasPriceFactor
|
7183
|
+
});
|
7184
|
+
};
|
7185
|
+
|
6841
7186
|
// src/providers/utils/merge-quantities.ts
|
6842
7187
|
var mergeQuantities = (...coinQuantities) => {
|
6843
7188
|
const resultMap = {};
|
@@ -6859,14 +7204,14 @@ var AbstractAccount = class {
|
|
6859
7204
|
// src/utils/formatTransferToContractScriptData.ts
|
6860
7205
|
import { ASSET_ID_LEN, BigNumberCoder as BigNumberCoder2, CONTRACT_ID_LEN, WORD_SIZE } from "@fuel-ts/abi-coder";
|
6861
7206
|
import { Address as Address3 } from "@fuel-ts/address";
|
6862
|
-
import { arrayify as
|
7207
|
+
import { arrayify as arrayify15, concat as concat3 } from "@fuel-ts/utils";
|
6863
7208
|
import * as asm from "@fuels/vm-asm";
|
6864
7209
|
var formatTransferToContractScriptData = (transferParams) => {
|
6865
7210
|
const numberCoder = new BigNumberCoder2("u64");
|
6866
7211
|
return transferParams.reduce((acc, transferParam) => {
|
6867
7212
|
const { assetId, amount, contractId } = transferParam;
|
6868
7213
|
const encoded = numberCoder.encode(amount);
|
6869
|
-
const scriptData = concat3([new Address3(contractId).toBytes(), encoded,
|
7214
|
+
const scriptData = concat3([new Address3(contractId).toBytes(), encoded, arrayify15(assetId)]);
|
6870
7215
|
return concat3([acc, scriptData]);
|
6871
7216
|
}, new Uint8Array());
|
6872
7217
|
};
|
@@ -7010,12 +7355,20 @@ var Account = class extends AbstractAccount {
|
|
7010
7355
|
* @returns A promise that resolves to the funded transaction request.
|
7011
7356
|
*/
|
7012
7357
|
async fund(request2, params) {
|
7013
|
-
const {
|
7358
|
+
const {
|
7359
|
+
addedSignatures,
|
7360
|
+
estimatedPredicates,
|
7361
|
+
requiredQuantities,
|
7362
|
+
updateMaxFee,
|
7363
|
+
gasPrice,
|
7364
|
+
transactionSummary
|
7365
|
+
} = params;
|
7366
|
+
const chainId = await this.provider.getChainId();
|
7014
7367
|
const fee = request2.maxFee;
|
7015
7368
|
const baseAssetId = await this.provider.getBaseAssetId();
|
7016
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount ||
|
7369
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn20(0);
|
7017
7370
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
7018
|
-
amount:
|
7371
|
+
amount: bn20(fee),
|
7019
7372
|
assetId: baseAssetId,
|
7020
7373
|
coinQuantities: requiredQuantities
|
7021
7374
|
});
|
@@ -7023,7 +7376,7 @@ var Account = class extends AbstractAccount {
|
|
7023
7376
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
7024
7377
|
quantitiesDict[assetId] = {
|
7025
7378
|
required: amount,
|
7026
|
-
owned:
|
7379
|
+
owned: bn20(0)
|
7027
7380
|
};
|
7028
7381
|
});
|
7029
7382
|
request2.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -7085,10 +7438,11 @@ var Account = class extends AbstractAccount {
|
|
7085
7438
|
}
|
7086
7439
|
if (needsToBeFunded) {
|
7087
7440
|
throw new FuelError20(
|
7088
|
-
ErrorCode18.
|
7441
|
+
ErrorCode18.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
7089
7442
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
7090
7443
|
);
|
7091
7444
|
}
|
7445
|
+
request2.updateState(chainId, "funded", transactionSummary);
|
7092
7446
|
await this.provider.validateTransaction(request2);
|
7093
7447
|
request2.updatePredicateGasUsed(estimatedPredicates);
|
7094
7448
|
const requestToReestimate = clone9(request2);
|
@@ -7199,9 +7553,9 @@ var Account = class extends AbstractAccount {
|
|
7199
7553
|
const quantities = [];
|
7200
7554
|
const defaultAssetId = await this.provider.getBaseAssetId();
|
7201
7555
|
const transferParams = contractTransferParams.map((transferParam) => {
|
7202
|
-
const amount =
|
7556
|
+
const amount = bn20(transferParam.amount);
|
7203
7557
|
const contractAddress = new Address4(transferParam.contractId);
|
7204
|
-
const assetId = transferParam.assetId ?
|
7558
|
+
const assetId = transferParam.assetId ? hexlify17(transferParam.assetId) : defaultAssetId;
|
7205
7559
|
if (amount.lte(0)) {
|
7206
7560
|
throw new FuelError20(
|
7207
7561
|
ErrorCode18.INVALID_TRANSFER_AMOUNT,
|
@@ -7232,21 +7586,21 @@ var Account = class extends AbstractAccount {
|
|
7232
7586
|
*/
|
7233
7587
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
7234
7588
|
const recipientAddress = new Address4(recipient);
|
7235
|
-
const recipientDataArray =
|
7589
|
+
const recipientDataArray = arrayify16(
|
7236
7590
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
7237
7591
|
);
|
7238
|
-
const amountDataArray =
|
7239
|
-
"0x".concat(
|
7592
|
+
const amountDataArray = arrayify16(
|
7593
|
+
"0x".concat(bn20(amount).toHex().substring(2).padStart(16, "0"))
|
7240
7594
|
);
|
7241
7595
|
const script = new Uint8Array([
|
7242
|
-
...
|
7596
|
+
...arrayify16(withdrawScript.bytes),
|
7243
7597
|
...recipientDataArray,
|
7244
7598
|
...amountDataArray
|
7245
7599
|
]);
|
7246
7600
|
const params = { script, ...txParams };
|
7247
7601
|
const baseAssetId = await this.provider.getBaseAssetId();
|
7248
7602
|
let request2 = new ScriptTransactionRequest(params);
|
7249
|
-
const quantities = [{ amount:
|
7603
|
+
const quantities = [{ amount: bn20(amount), assetId: baseAssetId }];
|
7250
7604
|
const txCost = await this.getTransactionCost(request2, { quantities });
|
7251
7605
|
request2 = this.validateGasLimitAndMaxFee({
|
7252
7606
|
transactionRequest: request2,
|
@@ -7272,9 +7626,9 @@ var Account = class extends AbstractAccount {
|
|
7272
7626
|
const baseAssetId = await this.provider.getBaseAssetId();
|
7273
7627
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
7274
7628
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
7275
|
-
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount:
|
7629
|
+
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: bn20("100000000000000000") }];
|
7276
7630
|
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
7277
|
-
if (input.type ===
|
7631
|
+
if (input.type === InputType7.Coin) {
|
7278
7632
|
return input.assetId === assetId;
|
7279
7633
|
}
|
7280
7634
|
if (isRequestInputMessageWithoutData(input)) {
|
@@ -7346,16 +7700,28 @@ var Account = class extends AbstractAccount {
|
|
7346
7700
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
7347
7701
|
* @returns A promise that resolves to the transaction response.
|
7348
7702
|
*/
|
7349
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true,
|
7703
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, ...connectorOptions } = {}) {
|
7704
|
+
let transactionRequest = transactionRequestify(transactionRequestLike);
|
7350
7705
|
if (this._connector) {
|
7351
|
-
|
7352
|
-
|
7353
|
-
|
7354
|
-
|
7355
|
-
|
7706
|
+
const { onBeforeSend, skipCustomFee = false } = connectorOptions;
|
7707
|
+
transactionRequest = await this.prepareTransactionForSend(transactionRequest);
|
7708
|
+
const params = {
|
7709
|
+
onBeforeSend,
|
7710
|
+
skipCustomFee,
|
7711
|
+
provider: {
|
7712
|
+
url: this.provider.url,
|
7713
|
+
cache: await serializeProviderCache(this.provider)
|
7714
|
+
},
|
7715
|
+
transactionState: transactionRequest.flag.state,
|
7716
|
+
transactionSummary: await this.prepareTransactionSummary(transactionRequest)
|
7717
|
+
};
|
7718
|
+
const transaction = await this._connector.sendTransaction(
|
7719
|
+
this.address.toString(),
|
7720
|
+
transactionRequest,
|
7721
|
+
params
|
7356
7722
|
);
|
7723
|
+
return typeof transaction === "string" ? this.provider.getTransactionResponse(transaction) : transaction;
|
7357
7724
|
}
|
7358
|
-
const transactionRequest = transactionRequestify(transactionRequestLike);
|
7359
7725
|
if (estimateTxDependencies) {
|
7360
7726
|
await this.provider.estimateTxDependencies(transactionRequest);
|
7361
7727
|
}
|
@@ -7385,16 +7751,38 @@ var Account = class extends AbstractAccount {
|
|
7385
7751
|
*/
|
7386
7752
|
generateFakeResources(coins) {
|
7387
7753
|
return coins.map((coin) => ({
|
7388
|
-
id:
|
7754
|
+
id: hexlify17(randomBytes2(UTXO_ID_LEN3)),
|
7389
7755
|
owner: this.address,
|
7390
|
-
blockCreated:
|
7391
|
-
txCreatedIdx:
|
7756
|
+
blockCreated: bn20(1),
|
7757
|
+
txCreatedIdx: bn20(1),
|
7392
7758
|
...coin
|
7393
7759
|
}));
|
7394
7760
|
}
|
7761
|
+
/** @hidden */
|
7762
|
+
async prepareTransactionForSend(request2) {
|
7763
|
+
const { transactionId } = request2.flag;
|
7764
|
+
if (!isDefined3(transactionId)) {
|
7765
|
+
return request2;
|
7766
|
+
}
|
7767
|
+
const chainId = await this.provider.getChainId();
|
7768
|
+
const currentTransactionId = request2.getTransactionId(chainId);
|
7769
|
+
if (transactionId !== currentTransactionId) {
|
7770
|
+
request2.updateState(chainId);
|
7771
|
+
}
|
7772
|
+
return request2;
|
7773
|
+
}
|
7774
|
+
/** @hidden */
|
7775
|
+
async prepareTransactionSummary(request2) {
|
7776
|
+
const chainId = await this.provider.getChainId();
|
7777
|
+
return isDefined3(request2.flag.summary) ? {
|
7778
|
+
...request2.flag.summary,
|
7779
|
+
id: request2.getTransactionId(chainId),
|
7780
|
+
transactionBytes: hexlify17(request2.toTransactionBytes())
|
7781
|
+
} : void 0;
|
7782
|
+
}
|
7395
7783
|
/** @hidden * */
|
7396
7784
|
validateTransferAmount(amount) {
|
7397
|
-
if (
|
7785
|
+
if (bn20(amount).lte(0)) {
|
7398
7786
|
throw new FuelError20(
|
7399
7787
|
ErrorCode18.INVALID_TRANSFER_AMOUNT,
|
7400
7788
|
"Transfer amount must be a positive number."
|
@@ -7444,14 +7832,14 @@ var Account = class extends AbstractAccount {
|
|
7444
7832
|
|
7445
7833
|
// src/wallet/base-wallet-unlocked.ts
|
7446
7834
|
import { hashMessage } from "@fuel-ts/hasher";
|
7447
|
-
import { hexlify as
|
7835
|
+
import { hexlify as hexlify20 } from "@fuel-ts/utils";
|
7448
7836
|
|
7449
7837
|
// src/signer/signer.ts
|
7450
7838
|
import { Address as Address5 } from "@fuel-ts/address";
|
7451
7839
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
7452
7840
|
import { hash as hash2 } from "@fuel-ts/hasher";
|
7453
7841
|
import { toBytes } from "@fuel-ts/math";
|
7454
|
-
import { hexlify as
|
7842
|
+
import { hexlify as hexlify18, concat as concat4, arrayify as arrayify17 } from "@fuel-ts/utils";
|
7455
7843
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
7456
7844
|
var Signer = class {
|
7457
7845
|
address;
|
@@ -7471,9 +7859,9 @@ var Signer = class {
|
|
7471
7859
|
}
|
7472
7860
|
}
|
7473
7861
|
const privateKeyBytes = toBytes(privateKey, 32);
|
7474
|
-
this.privateKey =
|
7475
|
-
this.publicKey =
|
7476
|
-
this.compressedPublicKey =
|
7862
|
+
this.privateKey = hexlify18(privateKeyBytes);
|
7863
|
+
this.publicKey = hexlify18(secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
7864
|
+
this.compressedPublicKey = hexlify18(secp256k1.getPublicKey(privateKeyBytes, true));
|
7477
7865
|
this.address = new Address5(this.publicKey);
|
7478
7866
|
}
|
7479
7867
|
/**
|
@@ -7487,11 +7875,11 @@ var Signer = class {
|
|
7487
7875
|
* @returns hashed signature
|
7488
7876
|
*/
|
7489
7877
|
sign(data) {
|
7490
|
-
const signature = secp256k1.sign(
|
7878
|
+
const signature = secp256k1.sign(arrayify17(data), arrayify17(this.privateKey));
|
7491
7879
|
const r = toBytes(`0x${signature.r.toString(16)}`, 32);
|
7492
7880
|
const s = toBytes(`0x${signature.s.toString(16)}`, 32);
|
7493
7881
|
s[0] |= (signature.recovery || 0) << 7;
|
7494
|
-
return
|
7882
|
+
return hexlify18(concat4([r, s]));
|
7495
7883
|
}
|
7496
7884
|
/**
|
7497
7885
|
* Add point on the current elliptic curve
|
@@ -7500,8 +7888,8 @@ var Signer = class {
|
|
7500
7888
|
* @returns compressed point on the curve
|
7501
7889
|
*/
|
7502
7890
|
addPoint(point) {
|
7503
|
-
const p0 = secp256k1.ProjectivePoint.fromHex(
|
7504
|
-
const p1 = secp256k1.ProjectivePoint.fromHex(
|
7891
|
+
const p0 = secp256k1.ProjectivePoint.fromHex(arrayify17(this.compressedPublicKey));
|
7892
|
+
const p1 = secp256k1.ProjectivePoint.fromHex(arrayify17(point));
|
7505
7893
|
const result = p0.add(p1);
|
7506
7894
|
return `0x${result.toHex(true)}`;
|
7507
7895
|
}
|
@@ -7513,16 +7901,16 @@ var Signer = class {
|
|
7513
7901
|
* @returns public key from signature from the
|
7514
7902
|
*/
|
7515
7903
|
static recoverPublicKey(data, signature) {
|
7516
|
-
const signedMessageBytes =
|
7904
|
+
const signedMessageBytes = arrayify17(signature);
|
7517
7905
|
const r = signedMessageBytes.slice(0, 32);
|
7518
7906
|
const s = signedMessageBytes.slice(32, 64);
|
7519
7907
|
const recoveryParam = (s[0] & 128) >> 7;
|
7520
7908
|
s[0] &= 127;
|
7521
|
-
const sig = new secp256k1.Signature(BigInt(
|
7909
|
+
const sig = new secp256k1.Signature(BigInt(hexlify18(r)), BigInt(hexlify18(s))).addRecoveryBit(
|
7522
7910
|
recoveryParam
|
7523
7911
|
);
|
7524
|
-
const publicKey = sig.recoverPublicKey(
|
7525
|
-
return
|
7912
|
+
const publicKey = sig.recoverPublicKey(arrayify17(data)).toRawBytes(false).slice(1);
|
7913
|
+
return hexlify18(publicKey);
|
7526
7914
|
}
|
7527
7915
|
/**
|
7528
7916
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -7541,7 +7929,7 @@ var Signer = class {
|
|
7541
7929
|
* @returns random 32-byte hashed
|
7542
7930
|
*/
|
7543
7931
|
static generatePrivateKey(entropy) {
|
7544
|
-
return entropy ? hash2(concat4([randomBytes3(32),
|
7932
|
+
return entropy ? hash2(concat4([randomBytes3(32), arrayify17(entropy)])) : randomBytes3(32);
|
7545
7933
|
}
|
7546
7934
|
/**
|
7547
7935
|
* Extended publicKey from a compact publicKey
|
@@ -7550,8 +7938,8 @@ var Signer = class {
|
|
7550
7938
|
* @returns extended publicKey
|
7551
7939
|
*/
|
7552
7940
|
static extendPublicKey(publicKey) {
|
7553
|
-
const point = secp256k1.ProjectivePoint.fromHex(
|
7554
|
-
return
|
7941
|
+
const point = secp256k1.ProjectivePoint.fromHex(arrayify17(publicKey));
|
7942
|
+
return hexlify18(point.toRawBytes(false).slice(1));
|
7555
7943
|
}
|
7556
7944
|
};
|
7557
7945
|
|
@@ -7568,7 +7956,7 @@ import {
|
|
7568
7956
|
randomUUID
|
7569
7957
|
} from "@fuel-ts/crypto";
|
7570
7958
|
import { ErrorCode as ErrorCode19, FuelError as FuelError21 } from "@fuel-ts/errors";
|
7571
|
-
import { hexlify as
|
7959
|
+
import { hexlify as hexlify19 } from "@fuel-ts/utils";
|
7572
7960
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
7573
7961
|
var DEFAULT_KDF_PARAMS_R = 8;
|
7574
7962
|
var DEFAULT_KDF_PARAMS_P = 1;
|
@@ -7650,7 +8038,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7650
8038
|
);
|
7651
8039
|
}
|
7652
8040
|
const buffer = await decryptJsonWalletData(ciphertextBuffer, key, ivBuffer);
|
7653
|
-
const privateKey =
|
8041
|
+
const privateKey = hexlify19(buffer);
|
7654
8042
|
return privateKey;
|
7655
8043
|
}
|
7656
8044
|
|
@@ -7695,7 +8083,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
7695
8083
|
*/
|
7696
8084
|
async signMessage(message) {
|
7697
8085
|
const signedMessage = await this.signer().sign(hashMessage(message));
|
7698
|
-
return
|
8086
|
+
return hexlify20(signedMessage);
|
7699
8087
|
}
|
7700
8088
|
/**
|
7701
8089
|
* Signs a transaction with the wallet's private key.
|
@@ -7708,7 +8096,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
7708
8096
|
const chainId = await this.provider.getChainId();
|
7709
8097
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
7710
8098
|
const signature = await this.signer().sign(hashedTransaction);
|
7711
|
-
return
|
8099
|
+
return hexlify20(signature);
|
7712
8100
|
}
|
7713
8101
|
/**
|
7714
8102
|
* Populates a transaction with the witnesses signature.
|
@@ -7782,14 +8170,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
7782
8170
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
7783
8171
|
import { ErrorCode as ErrorCode22, FuelError as FuelError24 } from "@fuel-ts/errors";
|
7784
8172
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
7785
|
-
import { bn as
|
7786
|
-
import { arrayify as
|
8173
|
+
import { bn as bn21, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
8174
|
+
import { arrayify as arrayify20, hexlify as hexlify22, concat as concat6, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
7787
8175
|
|
7788
8176
|
// src/mnemonic/mnemonic.ts
|
7789
8177
|
import { randomBytes as randomBytes5, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
7790
8178
|
import { ErrorCode as ErrorCode21, FuelError as FuelError23 } from "@fuel-ts/errors";
|
7791
8179
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
7792
|
-
import { arrayify as
|
8180
|
+
import { arrayify as arrayify19, hexlify as hexlify21, concat as concat5, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
7793
8181
|
|
7794
8182
|
// src/wordlists/words/english.ts
|
7795
8183
|
var english = [
|
@@ -9852,7 +10240,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
9852
10240
|
// src/mnemonic/utils.ts
|
9853
10241
|
import { ErrorCode as ErrorCode20, FuelError as FuelError22 } from "@fuel-ts/errors";
|
9854
10242
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
9855
|
-
import { arrayify as
|
10243
|
+
import { arrayify as arrayify18 } from "@fuel-ts/utils";
|
9856
10244
|
function getLowerMask(bits) {
|
9857
10245
|
return (1 << bits) - 1;
|
9858
10246
|
}
|
@@ -9887,14 +10275,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
9887
10275
|
}
|
9888
10276
|
}
|
9889
10277
|
const checksumBits = entropy.length / 4;
|
9890
|
-
const checksum =
|
10278
|
+
const checksum = arrayify18(sha2562(entropy))[0] & getUpperMask(checksumBits);
|
9891
10279
|
indices[indices.length - 1] <<= checksumBits;
|
9892
10280
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
9893
10281
|
return indices;
|
9894
10282
|
}
|
9895
10283
|
function mnemonicWordsToEntropy(words, wordlist) {
|
9896
10284
|
const size = Math.ceil(11 * words.length / 8);
|
9897
|
-
const entropy =
|
10285
|
+
const entropy = arrayify18(new Uint8Array(size));
|
9898
10286
|
let offset = 0;
|
9899
10287
|
for (let i = 0; i < words.length; i += 1) {
|
9900
10288
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -9914,7 +10302,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9914
10302
|
const entropyBits = 32 * words.length / 3;
|
9915
10303
|
const checksumBits = words.length / 3;
|
9916
10304
|
const checksumMask = getUpperMask(checksumBits);
|
9917
|
-
const checksum =
|
10305
|
+
const checksum = arrayify18(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
9918
10306
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
9919
10307
|
throw new FuelError22(
|
9920
10308
|
ErrorCode20.INVALID_CHECKSUM,
|
@@ -9989,7 +10377,7 @@ var Mnemonic = class {
|
|
9989
10377
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
9990
10378
|
const words = getWords(phrase);
|
9991
10379
|
assertMnemonic(words);
|
9992
|
-
return
|
10380
|
+
return hexlify21(mnemonicWordsToEntropy(words, wordlist));
|
9993
10381
|
}
|
9994
10382
|
/**
|
9995
10383
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -9997,7 +10385,7 @@ var Mnemonic = class {
|
|
9997
10385
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
9998
10386
|
*/
|
9999
10387
|
static entropyToMnemonic(entropy, wordlist = english) {
|
10000
|
-
const entropyBytes =
|
10388
|
+
const entropyBytes = arrayify19(entropy);
|
10001
10389
|
assertWordList(wordlist);
|
10002
10390
|
assertEntropy(entropyBytes);
|
10003
10391
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -10066,14 +10454,14 @@ var Mnemonic = class {
|
|
10066
10454
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
10067
10455
|
*/
|
10068
10456
|
static masterKeysFromSeed(seed) {
|
10069
|
-
const seedArray =
|
10457
|
+
const seedArray = arrayify19(seed);
|
10070
10458
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
10071
10459
|
throw new FuelError23(
|
10072
10460
|
ErrorCode21.INVALID_SEED,
|
10073
10461
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
10074
10462
|
);
|
10075
10463
|
}
|
10076
|
-
return
|
10464
|
+
return arrayify19(computeHmac("sha512", MasterSecret, seedArray));
|
10077
10465
|
}
|
10078
10466
|
/**
|
10079
10467
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -10084,7 +10472,7 @@ var Mnemonic = class {
|
|
10084
10472
|
*/
|
10085
10473
|
static seedToExtendedKey(seed, testnet = false) {
|
10086
10474
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
10087
|
-
const prefix =
|
10475
|
+
const prefix = arrayify19(testnet ? TestnetPRV : MainnetPRV);
|
10088
10476
|
const depth = "0x00";
|
10089
10477
|
const fingerprint = "0x00000000";
|
10090
10478
|
const index = "0x00000000";
|
@@ -10114,7 +10502,7 @@ var Mnemonic = class {
|
|
10114
10502
|
* @returns A randomly generated mnemonic
|
10115
10503
|
*/
|
10116
10504
|
static generate(size = 32, extraEntropy = "") {
|
10117
|
-
const entropy = extraEntropy ? sha2563(concat5([randomBytes5(size),
|
10505
|
+
const entropy = extraEntropy ? sha2563(concat5([randomBytes5(size), arrayify19(extraEntropy)])) : randomBytes5(size);
|
10118
10506
|
return Mnemonic.entropyToMnemonic(entropy);
|
10119
10507
|
}
|
10120
10508
|
};
|
@@ -10122,10 +10510,10 @@ var mnemonic_default = Mnemonic;
|
|
10122
10510
|
|
10123
10511
|
// src/hdwallet/hdwallet.ts
|
10124
10512
|
var HARDENED_INDEX = 2147483648;
|
10125
|
-
var MainnetPRV2 =
|
10126
|
-
var MainnetPUB =
|
10127
|
-
var TestnetPRV2 =
|
10128
|
-
var TestnetPUB =
|
10513
|
+
var MainnetPRV2 = hexlify22("0x0488ade4");
|
10514
|
+
var MainnetPUB = hexlify22("0x0488b21e");
|
10515
|
+
var TestnetPRV2 = hexlify22("0x04358394");
|
10516
|
+
var TestnetPUB = hexlify22("0x043587cf");
|
10129
10517
|
function base58check(data) {
|
10130
10518
|
return encodeBase582(concat6([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
|
10131
10519
|
}
|
@@ -10136,11 +10524,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
10136
10524
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
10137
10525
|
}
|
10138
10526
|
function isPublicExtendedKey(extendedKey) {
|
10139
|
-
return [MainnetPUB, TestnetPUB].includes(
|
10527
|
+
return [MainnetPUB, TestnetPUB].includes(hexlify22(extendedKey.slice(0, 4)));
|
10140
10528
|
}
|
10141
10529
|
function isValidExtendedKey(extendedKey) {
|
10142
10530
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
10143
|
-
|
10531
|
+
hexlify22(extendedKey.slice(0, 4))
|
10144
10532
|
);
|
10145
10533
|
}
|
10146
10534
|
function parsePath(path, depth = 0) {
|
@@ -10158,8 +10546,8 @@ function parsePath(path, depth = 0) {
|
|
10158
10546
|
var HDWallet = class {
|
10159
10547
|
depth = 0;
|
10160
10548
|
index = 0;
|
10161
|
-
fingerprint =
|
10162
|
-
parentFingerprint =
|
10549
|
+
fingerprint = hexlify22("0x00000000");
|
10550
|
+
parentFingerprint = hexlify22("0x00000000");
|
10163
10551
|
privateKey;
|
10164
10552
|
publicKey;
|
10165
10553
|
chainCode;
|
@@ -10171,8 +10559,8 @@ var HDWallet = class {
|
|
10171
10559
|
constructor(config) {
|
10172
10560
|
if (config.privateKey) {
|
10173
10561
|
const signer = new Signer(config.privateKey);
|
10174
|
-
this.publicKey =
|
10175
|
-
this.privateKey =
|
10562
|
+
this.publicKey = hexlify22(signer.compressedPublicKey);
|
10563
|
+
this.privateKey = hexlify22(config.privateKey);
|
10176
10564
|
} else {
|
10177
10565
|
if (!config.publicKey) {
|
10178
10566
|
throw new FuelError24(
|
@@ -10180,7 +10568,7 @@ var HDWallet = class {
|
|
10180
10568
|
"Both public and private Key cannot be missing. At least one should be provided."
|
10181
10569
|
);
|
10182
10570
|
}
|
10183
|
-
this.publicKey =
|
10571
|
+
this.publicKey = hexlify22(config.publicKey);
|
10184
10572
|
}
|
10185
10573
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
10186
10574
|
this.fingerprint = dataSlice2(ripemd160(sha2564(this.publicKey)), 0, 4);
|
@@ -10199,9 +10587,9 @@ var HDWallet = class {
|
|
10199
10587
|
* @returns A new instance of HDWallet on the derived index
|
10200
10588
|
*/
|
10201
10589
|
deriveIndex(index) {
|
10202
|
-
const privateKey = this.privateKey &&
|
10203
|
-
const publicKey =
|
10204
|
-
const chainCode =
|
10590
|
+
const privateKey = this.privateKey && arrayify20(this.privateKey);
|
10591
|
+
const publicKey = arrayify20(this.publicKey);
|
10592
|
+
const chainCode = arrayify20(this.chainCode);
|
10205
10593
|
const data = new Uint8Array(37);
|
10206
10594
|
if (index & HARDENED_INDEX) {
|
10207
10595
|
if (!privateKey) {
|
@@ -10212,15 +10600,15 @@ var HDWallet = class {
|
|
10212
10600
|
}
|
10213
10601
|
data.set(privateKey, 1);
|
10214
10602
|
} else {
|
10215
|
-
data.set(
|
10603
|
+
data.set(arrayify20(this.publicKey));
|
10216
10604
|
}
|
10217
10605
|
data.set(toBytes2(index, 4), 33);
|
10218
|
-
const bytes =
|
10606
|
+
const bytes = arrayify20(computeHmac2("sha512", chainCode, data));
|
10219
10607
|
const IL = bytes.slice(0, 32);
|
10220
10608
|
const IR = bytes.slice(32);
|
10221
10609
|
if (privateKey) {
|
10222
10610
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
10223
|
-
const ki =
|
10611
|
+
const ki = bn21(IL).add(privateKey).mod(N).toBytes(32);
|
10224
10612
|
return new HDWallet({
|
10225
10613
|
privateKey: ki,
|
10226
10614
|
chainCode: IR,
|
@@ -10229,7 +10617,7 @@ var HDWallet = class {
|
|
10229
10617
|
parentFingerprint: this.fingerprint
|
10230
10618
|
});
|
10231
10619
|
}
|
10232
|
-
const signer = new Signer(
|
10620
|
+
const signer = new Signer(hexlify22(IL));
|
10233
10621
|
const Ki = signer.addPoint(publicKey);
|
10234
10622
|
return new HDWallet({
|
10235
10623
|
publicKey: Ki,
|
@@ -10264,12 +10652,12 @@ var HDWallet = class {
|
|
10264
10652
|
);
|
10265
10653
|
}
|
10266
10654
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
10267
|
-
const depth =
|
10655
|
+
const depth = hexlify22(Uint8Array.from([this.depth]));
|
10268
10656
|
const parentFingerprint = this.parentFingerprint;
|
10269
10657
|
const index = toHex(this.index, 4);
|
10270
10658
|
const chainCode = this.chainCode;
|
10271
10659
|
const key = this.privateKey != null && !isPublic ? concat6(["0x00", this.privateKey]) : this.publicKey;
|
10272
|
-
const extendedKey =
|
10660
|
+
const extendedKey = arrayify20(concat6([prefix, depth, parentFingerprint, index, chainCode, key]));
|
10273
10661
|
return base58check(extendedKey);
|
10274
10662
|
}
|
10275
10663
|
/**
|
@@ -10281,13 +10669,13 @@ var HDWallet = class {
|
|
10281
10669
|
static fromSeed(seed) {
|
10282
10670
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
10283
10671
|
return new HDWallet({
|
10284
|
-
chainCode:
|
10285
|
-
privateKey:
|
10672
|
+
chainCode: arrayify20(masterKey.slice(32)),
|
10673
|
+
privateKey: arrayify20(masterKey.slice(0, 32))
|
10286
10674
|
});
|
10287
10675
|
}
|
10288
10676
|
static fromExtendedKey(extendedKey) {
|
10289
|
-
const decoded =
|
10290
|
-
const bytes =
|
10677
|
+
const decoded = hexlify22(toBytes2(decodeBase58(extendedKey)));
|
10678
|
+
const bytes = arrayify20(decoded);
|
10291
10679
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
10292
10680
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
10293
10681
|
throw new FuelError24(ErrorCode22.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -10296,9 +10684,9 @@ var HDWallet = class {
|
|
10296
10684
|
throw new FuelError24(ErrorCode22.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
10297
10685
|
}
|
10298
10686
|
const depth = bytes[4];
|
10299
|
-
const parentFingerprint =
|
10300
|
-
const index = parseInt(
|
10301
|
-
const chainCode =
|
10687
|
+
const parentFingerprint = hexlify22(bytes.slice(5, 9));
|
10688
|
+
const index = parseInt(hexlify22(bytes.slice(9, 13)).substring(2), 16);
|
10689
|
+
const chainCode = hexlify22(bytes.slice(13, 45));
|
10302
10690
|
const key = bytes.slice(45, 78);
|
10303
10691
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
10304
10692
|
throw new FuelError24(
|
@@ -10899,15 +11287,15 @@ var StorageAbstract = class {
|
|
10899
11287
|
};
|
10900
11288
|
|
10901
11289
|
// src/predicate/predicate.ts
|
10902
|
-
import { Interface as
|
11290
|
+
import { Interface as Interface3 } from "@fuel-ts/abi-coder";
|
10903
11291
|
import { Address as Address10 } from "@fuel-ts/address";
|
10904
11292
|
import { ErrorCode as ErrorCode28, FuelError as FuelError30 } from "@fuel-ts/errors";
|
10905
|
-
import { arrayify as
|
11293
|
+
import { arrayify as arrayify23, hexlify as hexlify24 } from "@fuel-ts/utils";
|
10906
11294
|
|
10907
11295
|
// src/utils/deployScriptOrPredicate.ts
|
10908
11296
|
import { FuelError as FuelError29, ErrorCode as ErrorCode27 } from "@fuel-ts/errors";
|
10909
|
-
import { bn as
|
10910
|
-
import { arrayify as
|
11297
|
+
import { bn as bn22 } from "@fuel-ts/math";
|
11298
|
+
import { arrayify as arrayify21 } from "@fuel-ts/utils";
|
10911
11299
|
|
10912
11300
|
// src/utils/predicate-script-loader-instructions.ts
|
10913
11301
|
import { BigNumberCoder as BigNumberCoder3 } from "@fuel-ts/abi-coder";
|
@@ -11054,7 +11442,7 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
|
11054
11442
|
|
11055
11443
|
// src/utils/deployScriptOrPredicate.ts
|
11056
11444
|
async function fundBlobTx(deployer, blobTxRequest) {
|
11057
|
-
let totalCost =
|
11445
|
+
let totalCost = bn22(0);
|
11058
11446
|
const chainInfo = await deployer.provider.getChain();
|
11059
11447
|
const gasPrice = await deployer.provider.estimateGasPrice(10);
|
11060
11448
|
const priceFactor = chainInfo.consensusParameters.feeParameters.gasPriceFactor;
|
@@ -11087,8 +11475,8 @@ async function deployScriptOrPredicate({
|
|
11087
11475
|
abi,
|
11088
11476
|
loaderInstanceCallback
|
11089
11477
|
}) {
|
11090
|
-
const blobId = getBytecodeId(
|
11091
|
-
const configurableOffset = getBytecodeConfigurableOffset(
|
11478
|
+
const blobId = getBytecodeId(arrayify21(bytecode));
|
11479
|
+
const configurableOffset = getBytecodeConfigurableOffset(arrayify21(bytecode));
|
11092
11480
|
const byteCodeWithoutConfigurableSection = bytecode.slice(0, configurableOffset);
|
11093
11481
|
const blobTxRequest = new BlobTransactionRequest({
|
11094
11482
|
blobId,
|
@@ -11096,8 +11484,8 @@ async function deployScriptOrPredicate({
|
|
11096
11484
|
witnesses: [byteCodeWithoutConfigurableSection]
|
11097
11485
|
});
|
11098
11486
|
const { loaderBytecode, blobOffset } = getPredicateScriptLoaderInstructions(
|
11099
|
-
|
11100
|
-
|
11487
|
+
arrayify21(bytecode),
|
11488
|
+
arrayify21(blobId)
|
11101
11489
|
);
|
11102
11490
|
const newConfigurableOffsetDiff = byteCodeWithoutConfigurableSection.length - (blobOffset || 0);
|
11103
11491
|
const newAbi = adjustConfigurableOffsets(abi, newConfigurableOffsetDiff);
|
@@ -11131,12 +11519,12 @@ async function deployScriptOrPredicate({
|
|
11131
11519
|
// src/predicate/utils/getPredicateRoot.ts
|
11132
11520
|
import { hash as hash3 } from "@fuel-ts/hasher";
|
11133
11521
|
import { calcRoot } from "@fuel-ts/merkle";
|
11134
|
-
import { chunkAndPadBytes, hexlify as
|
11522
|
+
import { chunkAndPadBytes, hexlify as hexlify23, concat as concat8, arrayify as arrayify22 } from "@fuel-ts/utils";
|
11135
11523
|
var getPredicateRoot = (bytecode) => {
|
11136
11524
|
const chunkSize = 16 * 1024;
|
11137
|
-
const bytes =
|
11525
|
+
const bytes = arrayify22(bytecode);
|
11138
11526
|
const chunks = chunkAndPadBytes(bytes, chunkSize);
|
11139
|
-
const codeRoot = calcRoot(chunks.map((c) =>
|
11527
|
+
const codeRoot = calcRoot(chunks.map((c) => hexlify23(c)));
|
11140
11528
|
const predicateRoot = hash3(concat8(["0x4655454C", codeRoot]));
|
11141
11529
|
return predicateRoot;
|
11142
11530
|
};
|
@@ -11171,7 +11559,7 @@ var Predicate = class extends Account {
|
|
11171
11559
|
);
|
11172
11560
|
const address = new Address10(getPredicateRoot(predicateBytes));
|
11173
11561
|
super(address, provider);
|
11174
|
-
this.initialBytecode =
|
11562
|
+
this.initialBytecode = arrayify23(bytecode);
|
11175
11563
|
this.bytes = predicateBytes;
|
11176
11564
|
this.interface = predicateInterface;
|
11177
11565
|
this.configurableConstants = configurableConstants;
|
@@ -11193,8 +11581,8 @@ var Predicate = class extends Account {
|
|
11193
11581
|
}
|
11194
11582
|
request2.inputs.filter(isRequestInputCoinOrMessage).forEach((input) => {
|
11195
11583
|
if (isRequestInputResourceFromOwner(input, this.address)) {
|
11196
|
-
input.predicate =
|
11197
|
-
input.predicateData =
|
11584
|
+
input.predicate = hexlify24(this.bytes);
|
11585
|
+
input.predicateData = hexlify24(this.getPredicateData());
|
11198
11586
|
input.witnessIndex = 0;
|
11199
11587
|
}
|
11200
11588
|
});
|
@@ -11250,8 +11638,8 @@ var Predicate = class extends Account {
|
|
11250
11638
|
* @returns An object containing the new predicate bytes and interface.
|
11251
11639
|
*/
|
11252
11640
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
11253
|
-
let predicateBytes =
|
11254
|
-
const abiInterface = new
|
11641
|
+
let predicateBytes = arrayify23(bytes);
|
11642
|
+
const abiInterface = new Interface3(jsonAbi);
|
11255
11643
|
if (abiInterface.functions.main === void 0) {
|
11256
11644
|
throw new FuelError30(
|
11257
11645
|
ErrorCode28.ABI_MAIN_METHOD_MISSING,
|
@@ -11285,8 +11673,8 @@ var Predicate = class extends Account {
|
|
11285
11673
|
);
|
11286
11674
|
return resources.map((resource) => ({
|
11287
11675
|
...resource,
|
11288
|
-
predicate:
|
11289
|
-
predicateData:
|
11676
|
+
predicate: hexlify24(this.bytes),
|
11677
|
+
predicateData: hexlify24(this.getPredicateData())
|
11290
11678
|
}));
|
11291
11679
|
}
|
11292
11680
|
/**
|
@@ -11298,8 +11686,8 @@ var Predicate = class extends Account {
|
|
11298
11686
|
generateFakeResources(coins) {
|
11299
11687
|
return super.generateFakeResources(coins).map((coin) => ({
|
11300
11688
|
...coin,
|
11301
|
-
predicate:
|
11302
|
-
predicateData:
|
11689
|
+
predicate: hexlify24(this.bytes),
|
11690
|
+
predicateData: hexlify24(this.getPredicateData())
|
11303
11691
|
}));
|
11304
11692
|
}
|
11305
11693
|
/**
|
@@ -11549,7 +11937,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
11549
11937
|
* @param address - The address to sign the transaction
|
11550
11938
|
* @param transaction - The transaction to send
|
11551
11939
|
* @param params - Optional parameters to send the transaction
|
11552
|
-
* @returns The transaction id
|
11940
|
+
* @returns The transaction id or transaction response
|
11553
11941
|
*/
|
11554
11942
|
async sendTransaction(_address, _transaction, _params) {
|
11555
11943
|
throw new FuelError31(FuelError31.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
@@ -12079,6 +12467,7 @@ export {
|
|
12079
12467
|
AbstractScriptRequest,
|
12080
12468
|
Account,
|
12081
12469
|
AddressType,
|
12470
|
+
BALANCES_PAGE_SIZE_LIMIT,
|
12082
12471
|
BLOCKS_PAGE_SIZE_LIMIT,
|
12083
12472
|
BaseTransactionRequest,
|
12084
12473
|
BaseWalletUnlocked,
|
@@ -12130,6 +12519,7 @@ export {
|
|
12130
12519
|
assembleReceiptByType,
|
12131
12520
|
assembleRevertError,
|
12132
12521
|
assembleTransactionSummary,
|
12522
|
+
assembleTransactionSummaryFromJson,
|
12133
12523
|
assets,
|
12134
12524
|
buildBlockExplorerUrl,
|
12135
12525
|
cacheFor,
|
@@ -12146,6 +12536,10 @@ export {
|
|
12146
12536
|
coinQuantityfy,
|
12147
12537
|
deferPromise,
|
12148
12538
|
deployScriptOrPredicate,
|
12539
|
+
deserializeChain,
|
12540
|
+
deserializeNodeInfo,
|
12541
|
+
deserializeProviderCache,
|
12542
|
+
deserializeReceipt,
|
12149
12543
|
dispatchFuelConnectorEvent,
|
12150
12544
|
english,
|
12151
12545
|
extractBurnedAssetsFromReceipts,
|
@@ -12210,6 +12604,7 @@ export {
|
|
12210
12604
|
isInputCoin,
|
12211
12605
|
isMessage,
|
12212
12606
|
isMessageCoin,
|
12607
|
+
isPredicate,
|
12213
12608
|
isRawCoin,
|
12214
12609
|
isRawMessage,
|
12215
12610
|
isRequestInputCoin,
|
@@ -12238,6 +12633,9 @@ export {
|
|
12238
12633
|
resolveGasDependentCosts,
|
12239
12634
|
resolveIconPaths,
|
12240
12635
|
returnZeroScript,
|
12636
|
+
serializeChain,
|
12637
|
+
serializeNodeInfo,
|
12638
|
+
serializeProviderCache,
|
12241
12639
|
transactionRequestify,
|
12242
12640
|
urlJoin,
|
12243
12641
|
validateTransactionForAssetBurn,
|