@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/test-utils.js
CHANGED
@@ -435,10 +435,9 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
435
435
|
assetId = coinQuantityLike.assetId;
|
436
436
|
max = coinQuantityLike.max ?? void 0;
|
437
437
|
}
|
438
|
-
const bnAmount = (0, import_math2.bn)(amount);
|
439
438
|
return {
|
440
439
|
assetId: (0, import_utils3.hexlify)(assetId),
|
441
|
-
amount:
|
440
|
+
amount: (0, import_math2.bn)(amount),
|
442
441
|
max: max ? (0, import_math2.bn)(max) : void 0
|
443
442
|
};
|
444
443
|
};
|
@@ -458,10 +457,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
458
457
|
var import_address4 = require("@fuel-ts/address");
|
459
458
|
var import_errors20 = require("@fuel-ts/errors");
|
460
459
|
var import_math19 = require("@fuel-ts/math");
|
461
|
-
var
|
460
|
+
var import_transactions23 = require("@fuel-ts/transactions");
|
462
461
|
var import_utils30 = require("@fuel-ts/utils");
|
463
462
|
var import_versions = require("@fuel-ts/versions");
|
464
|
-
var import_utils31 = require("@noble/curves/abstract/utils");
|
465
463
|
var import_graphql_request = require("graphql-request");
|
466
464
|
var import_graphql_tag2 = __toESM(require("graphql-tag"));
|
467
465
|
var import_ramda8 = require("ramda");
|
@@ -1073,6 +1071,16 @@ var EstimatePredicatesDocument = import_graphql_tag.default`
|
|
1073
1071
|
}
|
1074
1072
|
}
|
1075
1073
|
${TransactionEstimatePredicatesFragmentDoc}`;
|
1074
|
+
var EstimatePredicatesAndGasPriceDocument = import_graphql_tag.default`
|
1075
|
+
query estimatePredicatesAndGasPrice($encodedTransaction: HexString!, $blockHorizon: U32!) {
|
1076
|
+
estimatePredicates(tx: $encodedTransaction) {
|
1077
|
+
...transactionEstimatePredicatesFragment
|
1078
|
+
}
|
1079
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
1080
|
+
gasPrice
|
1081
|
+
}
|
1082
|
+
}
|
1083
|
+
${TransactionEstimatePredicatesFragmentDoc}`;
|
1076
1084
|
var GetLatestBlockDocument = import_graphql_tag.default`
|
1077
1085
|
query getLatestBlock {
|
1078
1086
|
chain {
|
@@ -1188,6 +1196,13 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
1188
1196
|
}
|
1189
1197
|
}
|
1190
1198
|
`;
|
1199
|
+
var GetBalanceV2Document = import_graphql_tag.default`
|
1200
|
+
query getBalanceV2($owner: Address!, $assetId: AssetId!) {
|
1201
|
+
balance(owner: $owner, assetId: $assetId) {
|
1202
|
+
amountU128
|
1203
|
+
}
|
1204
|
+
}
|
1205
|
+
`;
|
1191
1206
|
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
1192
1207
|
query getLatestGasPrice {
|
1193
1208
|
latestGasPrice {
|
@@ -1220,6 +1235,27 @@ var GetBalancesDocument = import_graphql_tag.default`
|
|
1220
1235
|
}
|
1221
1236
|
}
|
1222
1237
|
`;
|
1238
|
+
var GetBalancesV2Document = import_graphql_tag.default`
|
1239
|
+
query getBalancesV2($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
1240
|
+
balances(
|
1241
|
+
filter: $filter
|
1242
|
+
after: $after
|
1243
|
+
before: $before
|
1244
|
+
first: $first
|
1245
|
+
last: $last
|
1246
|
+
) {
|
1247
|
+
pageInfo {
|
1248
|
+
...pageInfoFragment
|
1249
|
+
}
|
1250
|
+
edges {
|
1251
|
+
node {
|
1252
|
+
assetId
|
1253
|
+
amountU128
|
1254
|
+
}
|
1255
|
+
}
|
1256
|
+
}
|
1257
|
+
}
|
1258
|
+
${PageInfoFragmentDoc}`;
|
1223
1259
|
var GetMessagesDocument = import_graphql_tag.default`
|
1224
1260
|
query getMessages($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
|
1225
1261
|
messages(
|
@@ -1274,6 +1310,15 @@ var GetRelayedTransactionStatusDocument = import_graphql_tag.default`
|
|
1274
1310
|
}
|
1275
1311
|
}
|
1276
1312
|
${RelayedTransactionStatusFragmentDoc}`;
|
1313
|
+
var GetAssetDetailsDocument = import_graphql_tag.default`
|
1314
|
+
query getAssetDetails($assetId: AssetId!) {
|
1315
|
+
assetDetails(id: $assetId) {
|
1316
|
+
subId
|
1317
|
+
contractId
|
1318
|
+
totalSupply
|
1319
|
+
}
|
1320
|
+
}
|
1321
|
+
`;
|
1277
1322
|
var DryRunDocument = import_graphql_tag.default`
|
1278
1323
|
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean, $gasPrice: U64) {
|
1279
1324
|
dryRun(
|
@@ -1374,6 +1419,9 @@ function getSdk(requester) {
|
|
1374
1419
|
estimatePredicates(variables, options) {
|
1375
1420
|
return requester(EstimatePredicatesDocument, variables, options);
|
1376
1421
|
},
|
1422
|
+
estimatePredicatesAndGasPrice(variables, options) {
|
1423
|
+
return requester(EstimatePredicatesAndGasPriceDocument, variables, options);
|
1424
|
+
},
|
1377
1425
|
getLatestBlock(variables, options) {
|
1378
1426
|
return requester(GetLatestBlockDocument, variables, options);
|
1379
1427
|
},
|
@@ -1407,6 +1455,9 @@ function getSdk(requester) {
|
|
1407
1455
|
getBalance(variables, options) {
|
1408
1456
|
return requester(GetBalanceDocument, variables, options);
|
1409
1457
|
},
|
1458
|
+
getBalanceV2(variables, options) {
|
1459
|
+
return requester(GetBalanceV2Document, variables, options);
|
1460
|
+
},
|
1410
1461
|
getLatestGasPrice(variables, options) {
|
1411
1462
|
return requester(GetLatestGasPriceDocument, variables, options);
|
1412
1463
|
},
|
@@ -1416,6 +1467,9 @@ function getSdk(requester) {
|
|
1416
1467
|
getBalances(variables, options) {
|
1417
1468
|
return requester(GetBalancesDocument, variables, options);
|
1418
1469
|
},
|
1470
|
+
getBalancesV2(variables, options) {
|
1471
|
+
return requester(GetBalancesV2Document, variables, options);
|
1472
|
+
},
|
1419
1473
|
getMessages(variables, options) {
|
1420
1474
|
return requester(GetMessagesDocument, variables, options);
|
1421
1475
|
},
|
@@ -1431,6 +1485,9 @@ function getSdk(requester) {
|
|
1431
1485
|
getRelayedTransactionStatus(variables, options) {
|
1432
1486
|
return requester(GetRelayedTransactionStatusDocument, variables, options);
|
1433
1487
|
},
|
1488
|
+
getAssetDetails(variables, options) {
|
1489
|
+
return requester(GetAssetDetailsDocument, variables, options);
|
1490
|
+
},
|
1434
1491
|
dryRun(variables, options) {
|
1435
1492
|
return requester(DryRunDocument, variables, options);
|
1436
1493
|
},
|
@@ -1465,24 +1522,23 @@ var import_graphql = require("graphql");
|
|
1465
1522
|
// src/providers/utils/handle-gql-error-message.ts
|
1466
1523
|
var import_errors2 = require("@fuel-ts/errors");
|
1467
1524
|
var mapGqlErrorMessage = (error) => {
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
);
|
1476
|
-
case "max number of coins is reached while trying to fit the target" /* MAX_COINS_REACHED */:
|
1477
|
-
return new import_errors2.FuelError(
|
1478
|
-
import_errors2.ErrorCode.MAX_COINS_REACHED,
|
1479
|
-
"The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.",
|
1480
|
-
{},
|
1481
|
-
error
|
1482
|
-
);
|
1483
|
-
default:
|
1484
|
-
return new import_errors2.FuelError(import_errors2.ErrorCode.INVALID_REQUEST, error.message, {}, error);
|
1525
|
+
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)) {
|
1526
|
+
return new import_errors2.FuelError(
|
1527
|
+
import_errors2.ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
1528
|
+
`Insufficient funds or too many small value coins. Consider combining UTXOs.`,
|
1529
|
+
{},
|
1530
|
+
error
|
1531
|
+
);
|
1485
1532
|
}
|
1533
|
+
if (new RegExp("resource was not found in table" /* ASSET_NOT_FOUND */).test(error.message)) {
|
1534
|
+
return new import_errors2.FuelError(
|
1535
|
+
import_errors2.ErrorCode.ASSET_NOT_FOUND,
|
1536
|
+
`Asset not found for given asset id.`,
|
1537
|
+
{},
|
1538
|
+
error
|
1539
|
+
);
|
1540
|
+
}
|
1541
|
+
return new import_errors2.FuelError(import_errors2.ErrorCode.INVALID_REQUEST, error.message, {}, error);
|
1486
1542
|
};
|
1487
1543
|
var mapGqlErrorWithIncompatibleNodeVersion = (error, incompatibleNodeVersionMessage) => {
|
1488
1544
|
if (!incompatibleNodeVersionMessage) {
|
@@ -1582,97 +1638,39 @@ __publicField(FuelGraphqlSubscriber, "incompatibleNodeVersionMessage", false);
|
|
1582
1638
|
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
1583
1639
|
|
1584
1640
|
// src/providers/resource-cache.ts
|
1585
|
-
var
|
1586
|
-
var
|
1587
|
-
var cache = /* @__PURE__ */ new Map();
|
1588
|
-
var ResourceCache = class {
|
1589
|
-
ttl;
|
1590
|
-
constructor(ttl) {
|
1591
|
-
this.ttl = ttl;
|
1592
|
-
if (typeof ttl !== "number" || this.ttl <= 0) {
|
1593
|
-
throw new import_errors4.FuelError(
|
1594
|
-
import_errors4.ErrorCode.INVALID_TTL,
|
1595
|
-
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
1596
|
-
);
|
1597
|
-
}
|
1598
|
-
}
|
1599
|
-
// Add resources to the cache
|
1600
|
-
set(transactionId, resources) {
|
1601
|
-
const currentTime = Date.now();
|
1602
|
-
const existingResources = cache.get(transactionId) || {
|
1603
|
-
utxos: /* @__PURE__ */ new Set(),
|
1604
|
-
messages: /* @__PURE__ */ new Set(),
|
1605
|
-
timestamp: currentTime
|
1606
|
-
};
|
1607
|
-
resources.utxos.forEach((utxo) => existingResources.utxos.add((0, import_utils4.hexlify)(utxo)));
|
1608
|
-
resources.messages.forEach((message) => existingResources.messages.add((0, import_utils4.hexlify)(message)));
|
1609
|
-
cache.set(transactionId, existingResources);
|
1610
|
-
}
|
1611
|
-
// Remove resources from the cache for a given transaction ID
|
1612
|
-
unset(transactionId) {
|
1613
|
-
cache.delete(transactionId);
|
1614
|
-
}
|
1615
|
-
// Get all cached resources and remove expired ones
|
1616
|
-
getActiveData() {
|
1617
|
-
const allResources = { utxos: [], messages: [] };
|
1618
|
-
const currentTime = Date.now();
|
1619
|
-
cache.forEach((resource, transactionId) => {
|
1620
|
-
if (currentTime - resource.timestamp < this.ttl) {
|
1621
|
-
allResources.utxos.push(...resource.utxos);
|
1622
|
-
allResources.messages.push(...resource.messages);
|
1623
|
-
} else {
|
1624
|
-
cache.delete(transactionId);
|
1625
|
-
}
|
1626
|
-
});
|
1627
|
-
return allResources;
|
1628
|
-
}
|
1629
|
-
// Check if a UTXO ID or message nonce is already cached and not expired
|
1630
|
-
isCached(key) {
|
1631
|
-
const currentTime = Date.now();
|
1632
|
-
for (const [transactionId, resourceData] of cache.entries()) {
|
1633
|
-
if (currentTime - resourceData.timestamp > this.ttl) {
|
1634
|
-
cache.delete(transactionId);
|
1635
|
-
} else if (resourceData.utxos.has(key) || resourceData.messages.has(key)) {
|
1636
|
-
return true;
|
1637
|
-
}
|
1638
|
-
}
|
1639
|
-
return false;
|
1640
|
-
}
|
1641
|
-
clear() {
|
1642
|
-
cache.clear();
|
1643
|
-
}
|
1644
|
-
};
|
1641
|
+
var import_errors14 = require("@fuel-ts/errors");
|
1642
|
+
var import_utils23 = require("@fuel-ts/utils");
|
1645
1643
|
|
1646
1644
|
// src/providers/transaction-request/input.ts
|
1647
1645
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1648
1646
|
var import_configs = require("@fuel-ts/address/configs");
|
1649
|
-
var
|
1647
|
+
var import_errors4 = require("@fuel-ts/errors");
|
1650
1648
|
var import_math3 = require("@fuel-ts/math");
|
1651
1649
|
var import_transactions = require("@fuel-ts/transactions");
|
1652
|
-
var
|
1650
|
+
var import_utils4 = require("@fuel-ts/utils");
|
1653
1651
|
var inputify = (value) => {
|
1654
1652
|
const { type } = value;
|
1655
1653
|
switch (value.type) {
|
1656
1654
|
case import_transactions.InputType.Coin: {
|
1657
|
-
const predicate = (0,
|
1658
|
-
const predicateData = (0,
|
1655
|
+
const predicate = (0, import_utils4.arrayify)(value.predicate ?? "0x");
|
1656
|
+
const predicateData = (0, import_utils4.arrayify)(value.predicateData ?? "0x");
|
1659
1657
|
return {
|
1660
1658
|
type: import_transactions.InputType.Coin,
|
1661
|
-
txID: (0,
|
1662
|
-
outputIndex: (0, import_math3.toNumber)((0,
|
1663
|
-
owner: (0,
|
1659
|
+
txID: (0, import_utils4.hexlify)((0, import_utils4.arrayify)(value.id).slice(0, import_abi_coder2.BYTES_32)),
|
1660
|
+
outputIndex: (0, import_math3.toNumber)((0, import_utils4.arrayify)(value.id).slice(import_abi_coder2.BYTES_32, import_abi_coder2.UTXO_ID_LEN)),
|
1661
|
+
owner: (0, import_utils4.hexlify)(value.owner),
|
1664
1662
|
amount: (0, import_math3.bn)(value.amount),
|
1665
|
-
assetId: (0,
|
1663
|
+
assetId: (0, import_utils4.hexlify)(value.assetId),
|
1666
1664
|
txPointer: {
|
1667
|
-
blockHeight: (0, import_math3.toNumber)((0,
|
1668
|
-
txIndex: (0, import_math3.toNumber)((0,
|
1665
|
+
blockHeight: (0, import_math3.toNumber)((0, import_utils4.arrayify)(value.txPointer).slice(0, 8)),
|
1666
|
+
txIndex: (0, import_math3.toNumber)((0, import_utils4.arrayify)(value.txPointer).slice(8, 16))
|
1669
1667
|
},
|
1670
1668
|
witnessIndex: value.witnessIndex,
|
1671
1669
|
predicateGasUsed: (0, import_math3.bn)(value.predicateGasUsed),
|
1672
1670
|
predicateLength: (0, import_math3.bn)(predicate.length),
|
1673
1671
|
predicateDataLength: (0, import_math3.bn)(predicateData.length),
|
1674
|
-
predicate: (0,
|
1675
|
-
predicateData: (0,
|
1672
|
+
predicate: (0, import_utils4.hexlify)(predicate),
|
1673
|
+
predicateData: (0, import_utils4.hexlify)(predicateData)
|
1676
1674
|
};
|
1677
1675
|
}
|
1678
1676
|
case import_transactions.InputType.Contract: {
|
@@ -1683,35 +1681,35 @@ var inputify = (value) => {
|
|
1683
1681
|
balanceRoot: import_configs.ZeroBytes32,
|
1684
1682
|
stateRoot: import_configs.ZeroBytes32,
|
1685
1683
|
txPointer: {
|
1686
|
-
blockHeight: (0, import_math3.toNumber)((0,
|
1687
|
-
txIndex: (0, import_math3.toNumber)((0,
|
1684
|
+
blockHeight: (0, import_math3.toNumber)((0, import_utils4.arrayify)(value.txPointer).slice(0, 8)),
|
1685
|
+
txIndex: (0, import_math3.toNumber)((0, import_utils4.arrayify)(value.txPointer).slice(8, 16))
|
1688
1686
|
},
|
1689
|
-
contractID: (0,
|
1687
|
+
contractID: (0, import_utils4.hexlify)(value.contractId)
|
1690
1688
|
};
|
1691
1689
|
}
|
1692
1690
|
case import_transactions.InputType.Message: {
|
1693
|
-
const predicate = (0,
|
1694
|
-
const predicateData = (0,
|
1695
|
-
const data = (0,
|
1691
|
+
const predicate = (0, import_utils4.arrayify)(value.predicate ?? "0x");
|
1692
|
+
const predicateData = (0, import_utils4.arrayify)(value.predicateData ?? "0x");
|
1693
|
+
const data = (0, import_utils4.arrayify)(value.data ?? "0x");
|
1696
1694
|
return {
|
1697
1695
|
type: import_transactions.InputType.Message,
|
1698
|
-
sender: (0,
|
1699
|
-
recipient: (0,
|
1696
|
+
sender: (0, import_utils4.hexlify)(value.sender),
|
1697
|
+
recipient: (0, import_utils4.hexlify)(value.recipient),
|
1700
1698
|
amount: (0, import_math3.bn)(value.amount),
|
1701
|
-
nonce: (0,
|
1699
|
+
nonce: (0, import_utils4.hexlify)(value.nonce),
|
1702
1700
|
witnessIndex: value.witnessIndex,
|
1703
1701
|
predicateGasUsed: (0, import_math3.bn)(value.predicateGasUsed),
|
1704
1702
|
predicateLength: (0, import_math3.bn)(predicate.length),
|
1705
1703
|
predicateDataLength: (0, import_math3.bn)(predicateData.length),
|
1706
|
-
predicate: (0,
|
1707
|
-
predicateData: (0,
|
1708
|
-
data: (0,
|
1704
|
+
predicate: (0, import_utils4.hexlify)(predicate),
|
1705
|
+
predicateData: (0, import_utils4.hexlify)(predicateData),
|
1706
|
+
data: (0, import_utils4.hexlify)(data),
|
1709
1707
|
dataLength: data.length
|
1710
1708
|
};
|
1711
1709
|
}
|
1712
1710
|
default: {
|
1713
|
-
throw new
|
1714
|
-
|
1711
|
+
throw new import_errors4.FuelError(
|
1712
|
+
import_errors4.ErrorCode.INVALID_TRANSACTION_INPUT,
|
1715
1713
|
`Invalid transaction input type: ${type}.`
|
1716
1714
|
);
|
1717
1715
|
}
|
@@ -1720,19 +1718,19 @@ var inputify = (value) => {
|
|
1720
1718
|
|
1721
1719
|
// src/providers/transaction-request/output.ts
|
1722
1720
|
var import_configs2 = require("@fuel-ts/address/configs");
|
1723
|
-
var
|
1721
|
+
var import_errors5 = require("@fuel-ts/errors");
|
1724
1722
|
var import_math4 = require("@fuel-ts/math");
|
1725
1723
|
var import_transactions2 = require("@fuel-ts/transactions");
|
1726
|
-
var
|
1724
|
+
var import_utils5 = require("@fuel-ts/utils");
|
1727
1725
|
var outputify = (value) => {
|
1728
1726
|
const { type } = value;
|
1729
1727
|
switch (type) {
|
1730
1728
|
case import_transactions2.OutputType.Coin: {
|
1731
1729
|
return {
|
1732
1730
|
type: import_transactions2.OutputType.Coin,
|
1733
|
-
to: (0,
|
1731
|
+
to: (0, import_utils5.hexlify)(value.to),
|
1734
1732
|
amount: (0, import_math4.bn)(value.amount),
|
1735
|
-
assetId: (0,
|
1733
|
+
assetId: (0, import_utils5.hexlify)(value.assetId)
|
1736
1734
|
};
|
1737
1735
|
}
|
1738
1736
|
case import_transactions2.OutputType.Contract: {
|
@@ -1746,9 +1744,9 @@ var outputify = (value) => {
|
|
1746
1744
|
case import_transactions2.OutputType.Change: {
|
1747
1745
|
return {
|
1748
1746
|
type: import_transactions2.OutputType.Change,
|
1749
|
-
to: (0,
|
1747
|
+
to: (0, import_utils5.hexlify)(value.to),
|
1750
1748
|
amount: (0, import_math4.bn)(0),
|
1751
|
-
assetId: (0,
|
1749
|
+
assetId: (0, import_utils5.hexlify)(value.assetId)
|
1752
1750
|
};
|
1753
1751
|
}
|
1754
1752
|
case import_transactions2.OutputType.Variable: {
|
@@ -1762,13 +1760,13 @@ var outputify = (value) => {
|
|
1762
1760
|
case import_transactions2.OutputType.ContractCreated: {
|
1763
1761
|
return {
|
1764
1762
|
type: import_transactions2.OutputType.ContractCreated,
|
1765
|
-
contractId: (0,
|
1766
|
-
stateRoot: (0,
|
1763
|
+
contractId: (0, import_utils5.hexlify)(value.contractId),
|
1764
|
+
stateRoot: (0, import_utils5.hexlify)(value.stateRoot)
|
1767
1765
|
};
|
1768
1766
|
}
|
1769
1767
|
default: {
|
1770
|
-
throw new
|
1771
|
-
|
1768
|
+
throw new import_errors5.FuelError(
|
1769
|
+
import_errors5.ErrorCode.INVALID_TRANSACTION_INPUT,
|
1772
1770
|
`Invalid transaction output type: ${type}.`
|
1773
1771
|
);
|
1774
1772
|
}
|
@@ -1780,9 +1778,9 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
1780
1778
|
var import_address2 = require("@fuel-ts/address");
|
1781
1779
|
var import_configs6 = require("@fuel-ts/address/configs");
|
1782
1780
|
var import_crypto3 = require("@fuel-ts/crypto");
|
1783
|
-
var
|
1781
|
+
var import_errors10 = require("@fuel-ts/errors");
|
1784
1782
|
var import_math9 = require("@fuel-ts/math");
|
1785
|
-
var
|
1783
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
1786
1784
|
var import_utils11 = require("@fuel-ts/utils");
|
1787
1785
|
|
1788
1786
|
// src/providers/message.ts
|
@@ -1792,31 +1790,157 @@ var isMessageCoin = (message) => !("data" in message);
|
|
1792
1790
|
var isCoin = (resource) => "id" in resource;
|
1793
1791
|
|
1794
1792
|
// src/providers/utils/receipts.ts
|
1793
|
+
var import_transactions4 = require("@fuel-ts/transactions");
|
1794
|
+
var import_configs4 = require("@fuel-ts/transactions/configs");
|
1795
|
+
|
1796
|
+
// src/providers/utils/serialization.ts
|
1795
1797
|
var import_configs3 = require("@fuel-ts/address/configs");
|
1796
|
-
var
|
1798
|
+
var import_errors6 = require("@fuel-ts/errors");
|
1797
1799
|
var import_math5 = require("@fuel-ts/math");
|
1798
1800
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1799
|
-
var
|
1800
|
-
var
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1801
|
+
var import_utils6 = require("@fuel-ts/utils");
|
1802
|
+
var deserializeChain = (chain) => {
|
1803
|
+
const { name, daHeight, consensusParameters } = chain;
|
1804
|
+
const {
|
1805
|
+
contractParams,
|
1806
|
+
feeParams,
|
1807
|
+
predicateParams,
|
1808
|
+
scriptParams,
|
1809
|
+
txParams,
|
1810
|
+
gasCosts,
|
1811
|
+
baseAssetId,
|
1812
|
+
chainId,
|
1813
|
+
version
|
1814
|
+
} = consensusParameters;
|
1815
|
+
return {
|
1816
|
+
name,
|
1817
|
+
baseChainHeight: (0, import_math5.bn)(daHeight),
|
1818
|
+
consensusParameters: {
|
1819
|
+
version,
|
1820
|
+
chainId: (0, import_math5.bn)(chainId),
|
1821
|
+
baseAssetId,
|
1822
|
+
feeParameters: {
|
1823
|
+
version: feeParams.version,
|
1824
|
+
gasPerByte: (0, import_math5.bn)(feeParams.gasPerByte),
|
1825
|
+
gasPriceFactor: (0, import_math5.bn)(feeParams.gasPriceFactor)
|
1826
|
+
},
|
1827
|
+
contractParameters: {
|
1828
|
+
version: contractParams.version,
|
1829
|
+
contractMaxSize: (0, import_math5.bn)(contractParams.contractMaxSize),
|
1830
|
+
maxStorageSlots: (0, import_math5.bn)(contractParams.maxStorageSlots)
|
1831
|
+
},
|
1832
|
+
txParameters: {
|
1833
|
+
version: txParams.version,
|
1834
|
+
maxInputs: (0, import_math5.bn)(txParams.maxInputs),
|
1835
|
+
maxOutputs: (0, import_math5.bn)(txParams.maxOutputs),
|
1836
|
+
maxWitnesses: (0, import_math5.bn)(txParams.maxWitnesses),
|
1837
|
+
maxGasPerTx: (0, import_math5.bn)(txParams.maxGasPerTx),
|
1838
|
+
maxSize: (0, import_math5.bn)(txParams.maxSize),
|
1839
|
+
maxBytecodeSubsections: (0, import_math5.bn)(txParams.maxBytecodeSubsections)
|
1840
|
+
},
|
1841
|
+
predicateParameters: {
|
1842
|
+
version: predicateParams.version,
|
1843
|
+
maxPredicateLength: (0, import_math5.bn)(predicateParams.maxPredicateLength),
|
1844
|
+
maxPredicateDataLength: (0, import_math5.bn)(predicateParams.maxPredicateDataLength),
|
1845
|
+
maxGasPerPredicate: (0, import_math5.bn)(predicateParams.maxGasPerPredicate),
|
1846
|
+
maxMessageDataLength: (0, import_math5.bn)(predicateParams.maxMessageDataLength)
|
1847
|
+
},
|
1848
|
+
scriptParameters: {
|
1849
|
+
version: scriptParams.version,
|
1850
|
+
maxScriptLength: (0, import_math5.bn)(scriptParams.maxScriptLength),
|
1851
|
+
maxScriptDataLength: (0, import_math5.bn)(scriptParams.maxScriptDataLength)
|
1852
|
+
},
|
1853
|
+
gasCosts
|
1807
1854
|
}
|
1808
|
-
|
1809
|
-
|
1855
|
+
};
|
1856
|
+
};
|
1857
|
+
var serializeChain = (chain) => {
|
1858
|
+
const { name, baseChainHeight, consensusParameters } = chain;
|
1859
|
+
const {
|
1860
|
+
contractParameters,
|
1861
|
+
feeParameters,
|
1862
|
+
predicateParameters,
|
1863
|
+
scriptParameters,
|
1864
|
+
txParameters,
|
1865
|
+
gasCosts,
|
1866
|
+
baseAssetId,
|
1867
|
+
chainId,
|
1868
|
+
version
|
1869
|
+
} = consensusParameters;
|
1870
|
+
return {
|
1871
|
+
name,
|
1872
|
+
daHeight: baseChainHeight.toString(),
|
1873
|
+
consensusParameters: {
|
1874
|
+
version,
|
1875
|
+
chainId: chainId.toString(),
|
1876
|
+
baseAssetId,
|
1877
|
+
feeParams: {
|
1878
|
+
version: feeParameters.version,
|
1879
|
+
gasPerByte: feeParameters.gasPerByte.toString(),
|
1880
|
+
gasPriceFactor: feeParameters.gasPriceFactor.toString()
|
1881
|
+
},
|
1882
|
+
contractParams: {
|
1883
|
+
version: contractParameters.version,
|
1884
|
+
contractMaxSize: contractParameters.contractMaxSize.toString(),
|
1885
|
+
maxStorageSlots: contractParameters.maxStorageSlots.toString()
|
1886
|
+
},
|
1887
|
+
txParams: {
|
1888
|
+
version: txParameters.version,
|
1889
|
+
maxInputs: txParameters.maxInputs.toString(),
|
1890
|
+
maxOutputs: txParameters.maxOutputs.toString(),
|
1891
|
+
maxWitnesses: txParameters.maxWitnesses.toString(),
|
1892
|
+
maxGasPerTx: txParameters.maxGasPerTx.toString(),
|
1893
|
+
maxSize: txParameters.maxSize.toString(),
|
1894
|
+
maxBytecodeSubsections: txParameters.maxBytecodeSubsections.toString()
|
1895
|
+
},
|
1896
|
+
predicateParams: {
|
1897
|
+
version: predicateParameters.version,
|
1898
|
+
maxPredicateLength: predicateParameters.maxPredicateLength.toString(),
|
1899
|
+
maxPredicateDataLength: predicateParameters.maxPredicateDataLength.toString(),
|
1900
|
+
maxGasPerPredicate: predicateParameters.maxGasPerPredicate.toString(),
|
1901
|
+
maxMessageDataLength: predicateParameters.maxMessageDataLength.toString()
|
1902
|
+
},
|
1903
|
+
scriptParams: {
|
1904
|
+
version: scriptParameters.version,
|
1905
|
+
maxScriptLength: scriptParameters.maxScriptLength.toString(),
|
1906
|
+
maxScriptDataLength: scriptParameters.maxScriptDataLength.toString()
|
1907
|
+
},
|
1908
|
+
gasCosts
|
1810
1909
|
}
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
)
|
1910
|
+
};
|
1911
|
+
};
|
1912
|
+
var deserializeNodeInfo = (nodeInfo) => {
|
1913
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
1914
|
+
return {
|
1915
|
+
maxDepth: (0, import_math5.bn)(maxDepth),
|
1916
|
+
maxTx: (0, import_math5.bn)(maxTx),
|
1917
|
+
nodeVersion,
|
1918
|
+
utxoValidation,
|
1919
|
+
vmBacktrace
|
1920
|
+
};
|
1921
|
+
};
|
1922
|
+
var serializeNodeInfo = (nodeInfo) => {
|
1923
|
+
const { maxDepth, maxTx, nodeVersion, utxoValidation, vmBacktrace } = nodeInfo;
|
1924
|
+
return {
|
1925
|
+
maxDepth: maxDepth.toString(),
|
1926
|
+
maxTx: maxTx.toString(),
|
1927
|
+
nodeVersion,
|
1928
|
+
utxoValidation,
|
1929
|
+
vmBacktrace
|
1930
|
+
};
|
1931
|
+
};
|
1932
|
+
var deserializeProviderCache = (cache2) => ({
|
1933
|
+
consensusParametersTimestamp: cache2.consensusParametersTimestamp,
|
1934
|
+
chain: deserializeChain(cache2.chain),
|
1935
|
+
nodeInfo: deserializeNodeInfo(cache2.nodeInfo)
|
1936
|
+
});
|
1937
|
+
var serializeProviderCache = async (provider) => ({
|
1938
|
+
consensusParametersTimestamp: provider.consensusParametersTimestamp,
|
1939
|
+
chain: serializeChain(await provider.getChain()),
|
1940
|
+
nodeInfo: serializeNodeInfo(await provider.getNode())
|
1941
|
+
});
|
1818
1942
|
var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
|
1819
|
-
|
1943
|
+
var deserializeReceipt = (receipt) => {
|
1820
1944
|
const { receiptType } = receipt;
|
1821
1945
|
switch (receiptType) {
|
1822
1946
|
case "CALL" /* Call */: {
|
@@ -1952,7 +2076,7 @@ function assembleReceiptByType(receipt) {
|
|
1952
2076
|
const recipient = hexOrZero(receipt.recipient);
|
1953
2077
|
const nonce = hexOrZero(receipt.nonce);
|
1954
2078
|
const amount = (0, import_math5.bn)(receipt.amount);
|
1955
|
-
const data = receipt.data ? (0,
|
2079
|
+
const data = receipt.data ? (0, import_utils6.arrayify)(receipt.data) : Uint8Array.from([]);
|
1956
2080
|
const digest = hexOrZero(receipt.digest);
|
1957
2081
|
const len = (0, import_math5.bn)(receipt.len).toNumber();
|
1958
2082
|
const messageId = import_transactions3.InputMessageCoder.getMessageId({
|
@@ -1960,7 +2084,7 @@ function assembleReceiptByType(receipt) {
|
|
1960
2084
|
recipient,
|
1961
2085
|
nonce,
|
1962
2086
|
amount,
|
1963
|
-
data: (0,
|
2087
|
+
data: (0, import_utils6.hexlify)(data)
|
1964
2088
|
});
|
1965
2089
|
const receiptMessageOut = {
|
1966
2090
|
type: import_transactions3.ReceiptType.MessageOut,
|
@@ -2006,20 +2130,39 @@ function assembleReceiptByType(receipt) {
|
|
2006
2130
|
return burnReceipt;
|
2007
2131
|
}
|
2008
2132
|
default:
|
2009
|
-
throw new
|
2133
|
+
throw new import_errors6.FuelError(import_errors6.ErrorCode.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
2010
2134
|
}
|
2011
|
-
}
|
2135
|
+
};
|
2136
|
+
|
2137
|
+
// src/providers/utils/receipts.ts
|
2138
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions4.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
2139
|
+
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions4.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
2140
|
+
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
2141
|
+
(memo, receipt) => {
|
2142
|
+
if (doesReceiptHaveMissingOutputVariables(receipt)) {
|
2143
|
+
memo.missingOutputVariables.push(receipt);
|
2144
|
+
}
|
2145
|
+
if (doesReceiptHaveMissingContractId(receipt)) {
|
2146
|
+
memo.missingOutputContractIds.push(receipt);
|
2147
|
+
}
|
2148
|
+
return memo;
|
2149
|
+
},
|
2150
|
+
{
|
2151
|
+
missingOutputVariables: [],
|
2152
|
+
missingOutputContractIds: []
|
2153
|
+
}
|
2154
|
+
);
|
2012
2155
|
|
2013
2156
|
// src/providers/utils/block-explorer.ts
|
2014
|
-
var
|
2157
|
+
var import_errors7 = require("@fuel-ts/errors");
|
2015
2158
|
|
2016
2159
|
// src/providers/utils/gas.ts
|
2017
2160
|
var import_math6 = require("@fuel-ts/math");
|
2018
|
-
var
|
2019
|
-
var
|
2161
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
2162
|
+
var import_utils7 = require("@fuel-ts/utils");
|
2020
2163
|
var getGasUsedFromReceipts = (receipts) => {
|
2021
2164
|
const scriptResult = receipts.filter(
|
2022
|
-
(receipt) => receipt.type ===
|
2165
|
+
(receipt) => receipt.type === import_transactions5.ReceiptType.ScriptResult
|
2023
2166
|
);
|
2024
2167
|
const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), (0, import_math6.bn)(0));
|
2025
2168
|
return gasUsed;
|
@@ -2053,7 +2196,7 @@ function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
|
2053
2196
|
const totalGas = chargeableInputs.reduce((total, input) => {
|
2054
2197
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
2055
2198
|
return total.add(
|
2056
|
-
vmInitializationCost.add(resolveGasDependentCosts((0,
|
2199
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils7.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math6.bn)(input.predicateGasUsed))
|
2057
2200
|
);
|
2058
2201
|
}
|
2059
2202
|
return total.add(gasCosts.ecr1);
|
@@ -2152,13 +2295,13 @@ var calculateGasFee = (params) => {
|
|
2152
2295
|
};
|
2153
2296
|
|
2154
2297
|
// src/providers/utils/json.ts
|
2155
|
-
var
|
2298
|
+
var import_utils8 = require("@fuel-ts/utils");
|
2156
2299
|
var import_ramda = require("ramda");
|
2157
2300
|
function normalize(object) {
|
2158
2301
|
Object.keys(object).forEach((key) => {
|
2159
2302
|
switch (object[key]?.constructor.name) {
|
2160
2303
|
case "Uint8Array":
|
2161
|
-
object[key] = (0,
|
2304
|
+
object[key] = (0, import_utils8.hexlify)(object[key]);
|
2162
2305
|
break;
|
2163
2306
|
case "Array":
|
2164
2307
|
object[key] = normalize(object[key]);
|
@@ -2183,9 +2326,9 @@ function normalizeJSON(root) {
|
|
2183
2326
|
}
|
2184
2327
|
|
2185
2328
|
// src/providers/utils/extract-tx-error.ts
|
2186
|
-
var
|
2329
|
+
var import_errors8 = require("@fuel-ts/errors");
|
2187
2330
|
var import_math7 = require("@fuel-ts/math");
|
2188
|
-
var
|
2331
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
2189
2332
|
var import_configs5 = require("@fuel-ts/transactions/configs");
|
2190
2333
|
var assemblePanicError = (statusReason, metadata) => {
|
2191
2334
|
let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
|
@@ -2196,7 +2339,7 @@ You can read more about this error at:
|
|
2196
2339
|
|
2197
2340
|
${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
|
2198
2341
|
}
|
2199
|
-
return new
|
2342
|
+
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
2200
2343
|
...metadata,
|
2201
2344
|
reason: statusReason
|
2202
2345
|
});
|
@@ -2204,7 +2347,7 @@ ${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
|
|
2204
2347
|
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
2205
2348
|
var assembleRevertError = (receipts, logs, metadata) => {
|
2206
2349
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
2207
|
-
const revertReceipt = receipts.find(({ type }) => type ===
|
2350
|
+
const revertReceipt = receipts.find(({ type }) => type === import_transactions6.ReceiptType.Revert);
|
2208
2351
|
let reason = "";
|
2209
2352
|
if (revertReceipt) {
|
2210
2353
|
const reasonHex = (0, import_math7.bn)(revertReceipt.val).toHex();
|
@@ -2217,15 +2360,15 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2217
2360
|
break;
|
2218
2361
|
}
|
2219
2362
|
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
2220
|
-
const
|
2363
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
2221
2364
|
reason = "assert_eq";
|
2222
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${
|
2365
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
2223
2366
|
break;
|
2224
2367
|
}
|
2225
2368
|
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
2226
|
-
const
|
2369
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2227
2370
|
reason = "assert_ne";
|
2228
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${
|
2371
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
2229
2372
|
break;
|
2230
2373
|
}
|
2231
2374
|
case import_configs5.FAILED_ASSERT_SIGNAL:
|
@@ -2233,12 +2376,12 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2233
2376
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
2234
2377
|
break;
|
2235
2378
|
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
2236
|
-
reason = "
|
2237
|
-
errorMessage = `The transaction reverted because it's missing an "
|
2379
|
+
reason = "MissingOutputVariable";
|
2380
|
+
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
2238
2381
|
break;
|
2239
2382
|
default:
|
2240
|
-
throw new
|
2241
|
-
|
2383
|
+
throw new import_errors8.FuelError(
|
2384
|
+
import_errors8.ErrorCode.UNKNOWN,
|
2242
2385
|
`The transaction reverted with an unknown reason: ${revertReceipt.val}`,
|
2243
2386
|
{
|
2244
2387
|
...metadata,
|
@@ -2247,15 +2390,15 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2247
2390
|
);
|
2248
2391
|
}
|
2249
2392
|
}
|
2250
|
-
return new
|
2393
|
+
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
2251
2394
|
...metadata,
|
2252
2395
|
reason
|
2253
2396
|
});
|
2254
2397
|
};
|
2255
2398
|
var extractTxError = (params) => {
|
2256
2399
|
const { receipts, statusReason, logs } = params;
|
2257
|
-
const isPanic = receipts.some(({ type }) => type ===
|
2258
|
-
const isRevert = receipts.some(({ type }) => type ===
|
2400
|
+
const isPanic = receipts.some(({ type }) => type === import_transactions6.ReceiptType.Panic);
|
2401
|
+
const isRevert = receipts.some(({ type }) => type === import_transactions6.ReceiptType.Revert);
|
2259
2402
|
const metadata = {
|
2260
2403
|
logs,
|
2261
2404
|
receipts,
|
@@ -2280,16 +2423,18 @@ var NoWitnessAtIndexError = class extends Error {
|
|
2280
2423
|
};
|
2281
2424
|
|
2282
2425
|
// src/providers/transaction-request/helpers.ts
|
2283
|
-
var
|
2426
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2284
2427
|
var import_math8 = require("@fuel-ts/math");
|
2285
|
-
var
|
2286
|
-
var
|
2287
|
-
var
|
2288
|
-
var
|
2428
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2429
|
+
var import_utils9 = require("@fuel-ts/utils");
|
2430
|
+
var isRequestInputCoin = (input) => input.type === import_transactions7.InputType.Coin;
|
2431
|
+
var isRequestInputMessage = (input) => input.type === import_transactions7.InputType.Message;
|
2432
|
+
var isRequestInputMessageWithoutData = (input) => input.type === import_transactions7.InputType.Message && (0, import_math8.bn)(input.data).isZero();
|
2289
2433
|
var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
2290
2434
|
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2291
2435
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2292
2436
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
2437
|
+
var isPredicate = (input) => isRequestInputCoinOrMessage(input) && !!input.predicate && (0, import_utils9.hexlify)(input.predicate) !== "0x";
|
2293
2438
|
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
2294
2439
|
if (isRequestInputCoin(input) && input.assetId === assetId) {
|
2295
2440
|
return acc.add(input.amount);
|
@@ -2320,7 +2465,7 @@ var getBurnableAssetCount = (baseAssetId, transactionRequest) => {
|
|
2320
2465
|
coinInputs.add(baseAssetId);
|
2321
2466
|
}
|
2322
2467
|
const changeOutputs = new Set(
|
2323
|
-
outputs.filter((output) => output.type ===
|
2468
|
+
outputs.filter((output) => output.type === import_transactions7.OutputType.Change).map((output) => output.assetId)
|
2324
2469
|
);
|
2325
2470
|
const difference = new Set([...coinInputs].filter((x) => !changeOutputs.has(x)));
|
2326
2471
|
return difference.size;
|
@@ -2337,7 +2482,7 @@ var validateTransactionForAssetBurn = (baseAssetId, transactionRequest, enableAs
|
|
2337
2482
|
"Add the relevant change outputs to the transaction to avoid burning assets.",
|
2338
2483
|
"Or enable asset burn, upon sending the transaction."
|
2339
2484
|
].join("\n");
|
2340
|
-
throw new
|
2485
|
+
throw new import_errors9.FuelError(import_errors9.ErrorCode.ASSET_BURN_DETECTED, message);
|
2341
2486
|
};
|
2342
2487
|
|
2343
2488
|
// src/providers/transaction-request/witness.ts
|
@@ -2356,6 +2501,8 @@ var BaseTransactionRequest = class {
|
|
2356
2501
|
tip;
|
2357
2502
|
/** Block until which tx cannot be included */
|
2358
2503
|
maturity;
|
2504
|
+
/** The block number after which the transaction is no longer valid. */
|
2505
|
+
expiration;
|
2359
2506
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
2360
2507
|
maxFee;
|
2361
2508
|
/** The maximum amount of witness data allowed for the transaction */
|
@@ -2366,6 +2513,12 @@ var BaseTransactionRequest = class {
|
|
2366
2513
|
outputs = [];
|
2367
2514
|
/** List of witnesses */
|
2368
2515
|
witnesses = [];
|
2516
|
+
/**
|
2517
|
+
* @hidden
|
2518
|
+
*
|
2519
|
+
* The current status of the transaction
|
2520
|
+
*/
|
2521
|
+
flag = { state: void 0, transactionId: void 0, summary: void 0 };
|
2369
2522
|
/**
|
2370
2523
|
* Constructor for initializing a base transaction request.
|
2371
2524
|
*
|
@@ -2374,6 +2527,7 @@ var BaseTransactionRequest = class {
|
|
2374
2527
|
constructor({
|
2375
2528
|
tip,
|
2376
2529
|
maturity,
|
2530
|
+
expiration,
|
2377
2531
|
maxFee,
|
2378
2532
|
witnessLimit,
|
2379
2533
|
inputs,
|
@@ -2382,6 +2536,7 @@ var BaseTransactionRequest = class {
|
|
2382
2536
|
} = {}) {
|
2383
2537
|
this.tip = tip ? (0, import_math9.bn)(tip) : void 0;
|
2384
2538
|
this.maturity = maturity && maturity > 0 ? maturity : void 0;
|
2539
|
+
this.expiration = expiration && expiration > 0 ? expiration : void 0;
|
2385
2540
|
this.witnessLimit = (0, import_utils11.isDefined)(witnessLimit) ? (0, import_math9.bn)(witnessLimit) : void 0;
|
2386
2541
|
this.maxFee = (0, import_math9.bn)(maxFee);
|
2387
2542
|
this.inputs = inputs ?? [];
|
@@ -2391,21 +2546,25 @@ var BaseTransactionRequest = class {
|
|
2391
2546
|
static getPolicyMeta(req) {
|
2392
2547
|
let policyTypes = 0;
|
2393
2548
|
const policies = [];
|
2394
|
-
const { tip, witnessLimit, maturity } = req;
|
2549
|
+
const { tip, witnessLimit, maturity, expiration } = req;
|
2395
2550
|
if ((0, import_math9.bn)(tip).gt(0)) {
|
2396
|
-
policyTypes +=
|
2397
|
-
policies.push({ data: (0, import_math9.bn)(tip), type:
|
2551
|
+
policyTypes += import_transactions8.PolicyType.Tip;
|
2552
|
+
policies.push({ data: (0, import_math9.bn)(tip), type: import_transactions8.PolicyType.Tip });
|
2398
2553
|
}
|
2399
2554
|
if ((0, import_utils11.isDefined)(witnessLimit) && (0, import_math9.bn)(witnessLimit).gte(0)) {
|
2400
|
-
policyTypes +=
|
2401
|
-
policies.push({ data: (0, import_math9.bn)(witnessLimit), type:
|
2555
|
+
policyTypes += import_transactions8.PolicyType.WitnessLimit;
|
2556
|
+
policies.push({ data: (0, import_math9.bn)(witnessLimit), type: import_transactions8.PolicyType.WitnessLimit });
|
2402
2557
|
}
|
2403
2558
|
if (maturity && maturity > 0) {
|
2404
|
-
policyTypes +=
|
2405
|
-
policies.push({ data: maturity, type:
|
2559
|
+
policyTypes += import_transactions8.PolicyType.Maturity;
|
2560
|
+
policies.push({ data: maturity, type: import_transactions8.PolicyType.Maturity });
|
2561
|
+
}
|
2562
|
+
policyTypes += import_transactions8.PolicyType.MaxFee;
|
2563
|
+
policies.push({ data: req.maxFee, type: import_transactions8.PolicyType.MaxFee });
|
2564
|
+
if (expiration && expiration > 0) {
|
2565
|
+
policyTypes += import_transactions8.PolicyType.Expiration;
|
2566
|
+
policies.push({ data: expiration, type: import_transactions8.PolicyType.Expiration });
|
2406
2567
|
}
|
2407
|
-
policyTypes += import_transactions7.PolicyType.MaxFee;
|
2408
|
-
policies.push({ data: req.maxFee, type: import_transactions7.PolicyType.MaxFee });
|
2409
2568
|
return {
|
2410
2569
|
policyTypes,
|
2411
2570
|
policies
|
@@ -2438,7 +2597,7 @@ var BaseTransactionRequest = class {
|
|
2438
2597
|
* @returns The transaction bytes.
|
2439
2598
|
*/
|
2440
2599
|
toTransactionBytes() {
|
2441
|
-
return new
|
2600
|
+
return new import_transactions8.TransactionCoder().encode(this.toTransaction());
|
2442
2601
|
}
|
2443
2602
|
/**
|
2444
2603
|
* @hidden
|
@@ -2478,8 +2637,7 @@ var BaseTransactionRequest = class {
|
|
2478
2637
|
* @returns The index of the created witness.
|
2479
2638
|
*/
|
2480
2639
|
addEmptyWitness() {
|
2481
|
-
this.addWitness((0, import_utils11.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
2482
|
-
return this.witnesses.length - 1;
|
2640
|
+
return this.addWitness((0, import_utils11.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
2483
2641
|
}
|
2484
2642
|
/**
|
2485
2643
|
* Updates the witness for a given owner and signature.
|
@@ -2529,7 +2687,7 @@ var BaseTransactionRequest = class {
|
|
2529
2687
|
*/
|
2530
2688
|
getCoinInputs() {
|
2531
2689
|
return this.inputs.filter(
|
2532
|
-
(input) => input.type ===
|
2690
|
+
(input) => input.type === import_transactions8.InputType.Coin
|
2533
2691
|
);
|
2534
2692
|
}
|
2535
2693
|
/**
|
@@ -2539,7 +2697,7 @@ var BaseTransactionRequest = class {
|
|
2539
2697
|
*/
|
2540
2698
|
getCoinOutputs() {
|
2541
2699
|
return this.outputs.filter(
|
2542
|
-
(output) => output.type ===
|
2700
|
+
(output) => output.type === import_transactions8.OutputType.Coin
|
2543
2701
|
);
|
2544
2702
|
}
|
2545
2703
|
/**
|
@@ -2549,7 +2707,7 @@ var BaseTransactionRequest = class {
|
|
2549
2707
|
*/
|
2550
2708
|
getChangeOutputs() {
|
2551
2709
|
return this.outputs.filter(
|
2552
|
-
(output) => output.type ===
|
2710
|
+
(output) => output.type === import_transactions8.OutputType.Change
|
2553
2711
|
);
|
2554
2712
|
}
|
2555
2713
|
/**
|
@@ -2561,9 +2719,9 @@ var BaseTransactionRequest = class {
|
|
2561
2719
|
const ownerAddress = (0, import_address2.addressify)(owner);
|
2562
2720
|
const found = this.inputs.find((input) => {
|
2563
2721
|
switch (input.type) {
|
2564
|
-
case
|
2722
|
+
case import_transactions8.InputType.Coin:
|
2565
2723
|
return (0, import_utils11.hexlify)(input.owner) === ownerAddress.toB256();
|
2566
|
-
case
|
2724
|
+
case import_transactions8.InputType.Message:
|
2567
2725
|
return (0, import_utils11.hexlify)(input.recipient) === ownerAddress.toB256();
|
2568
2726
|
default:
|
2569
2727
|
return false;
|
@@ -2590,7 +2748,7 @@ var BaseTransactionRequest = class {
|
|
2590
2748
|
}
|
2591
2749
|
const input = {
|
2592
2750
|
id,
|
2593
|
-
type:
|
2751
|
+
type: import_transactions8.InputType.Coin,
|
2594
2752
|
owner: owner.toB256(),
|
2595
2753
|
amount,
|
2596
2754
|
assetId,
|
@@ -2621,7 +2779,7 @@ var BaseTransactionRequest = class {
|
|
2621
2779
|
}
|
2622
2780
|
const input = {
|
2623
2781
|
nonce,
|
2624
|
-
type:
|
2782
|
+
type: import_transactions8.InputType.Message,
|
2625
2783
|
sender: sender.toB256(),
|
2626
2784
|
recipient: recipient.toB256(),
|
2627
2785
|
data: isMessageCoin(message) ? "0x" : message.data,
|
@@ -2670,7 +2828,7 @@ var BaseTransactionRequest = class {
|
|
2670
2828
|
*/
|
2671
2829
|
addCoinOutput(to, amount, assetId) {
|
2672
2830
|
this.pushOutput({
|
2673
|
-
type:
|
2831
|
+
type: import_transactions8.OutputType.Coin,
|
2674
2832
|
to: (0, import_address2.addressify)(to).toB256(),
|
2675
2833
|
amount,
|
2676
2834
|
assetId
|
@@ -2686,7 +2844,7 @@ var BaseTransactionRequest = class {
|
|
2686
2844
|
addCoinOutputs(to, quantities) {
|
2687
2845
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
2688
2846
|
this.pushOutput({
|
2689
|
-
type:
|
2847
|
+
type: import_transactions8.OutputType.Coin,
|
2690
2848
|
to: (0, import_address2.addressify)(to).toB256(),
|
2691
2849
|
amount: quantity.amount,
|
2692
2850
|
assetId: quantity.assetId
|
@@ -2706,7 +2864,7 @@ var BaseTransactionRequest = class {
|
|
2706
2864
|
);
|
2707
2865
|
if (!changeOutput) {
|
2708
2866
|
this.pushOutput({
|
2709
|
-
type:
|
2867
|
+
type: import_transactions8.OutputType.Change,
|
2710
2868
|
to: (0, import_address2.addressify)(to).toB256(),
|
2711
2869
|
assetId
|
2712
2870
|
});
|
@@ -2722,7 +2880,7 @@ var BaseTransactionRequest = class {
|
|
2722
2880
|
* @hidden
|
2723
2881
|
*/
|
2724
2882
|
metadataGas(_gasCosts) {
|
2725
|
-
throw new
|
2883
|
+
throw new import_errors10.FuelError(import_errors10.FuelError.CODES.NOT_IMPLEMENTED, "Not implemented");
|
2726
2884
|
}
|
2727
2885
|
/**
|
2728
2886
|
* @hidden
|
@@ -2849,6 +3007,21 @@ var BaseTransactionRequest = class {
|
|
2849
3007
|
byteLength() {
|
2850
3008
|
return this.toTransactionBytes().byteLength;
|
2851
3009
|
}
|
3010
|
+
/**
|
3011
|
+
* @hidden
|
3012
|
+
*
|
3013
|
+
* Used internally to update the state of a transaction request.
|
3014
|
+
*
|
3015
|
+
* @param state - The state to update.
|
3016
|
+
*/
|
3017
|
+
updateState(chainId, state, summary) {
|
3018
|
+
if (!state) {
|
3019
|
+
this.flag = { state: void 0, transactionId: void 0, summary: void 0 };
|
3020
|
+
return;
|
3021
|
+
}
|
3022
|
+
const transactionId = this.getTransactionId(chainId);
|
3023
|
+
this.flag = { state, transactionId, summary };
|
3024
|
+
}
|
2852
3025
|
};
|
2853
3026
|
|
2854
3027
|
// src/providers/transaction-request/blob-transaction-request.ts
|
@@ -2858,18 +3031,18 @@ var import_ramda3 = require("ramda");
|
|
2858
3031
|
var import_configs7 = require("@fuel-ts/address/configs");
|
2859
3032
|
var import_hasher2 = require("@fuel-ts/hasher");
|
2860
3033
|
var import_math10 = require("@fuel-ts/math");
|
2861
|
-
var
|
3034
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2862
3035
|
var import_utils13 = require("@fuel-ts/utils");
|
2863
3036
|
var import_ramda2 = require("ramda");
|
2864
3037
|
function hashTransaction(transactionRequest, chainId) {
|
2865
3038
|
const transaction = transactionRequest.toTransaction();
|
2866
|
-
if (transaction.type ===
|
3039
|
+
if (transaction.type === import_transactions9.TransactionType.Script) {
|
2867
3040
|
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2868
3041
|
}
|
2869
3042
|
transaction.inputs = transaction.inputs.map((input) => {
|
2870
3043
|
const inputClone = (0, import_ramda2.clone)(input);
|
2871
3044
|
switch (inputClone.type) {
|
2872
|
-
case
|
3045
|
+
case import_transactions9.InputType.Coin: {
|
2873
3046
|
inputClone.txPointer = {
|
2874
3047
|
blockHeight: 0,
|
2875
3048
|
txIndex: 0
|
@@ -2877,11 +3050,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2877
3050
|
inputClone.predicateGasUsed = (0, import_math10.bn)(0);
|
2878
3051
|
return inputClone;
|
2879
3052
|
}
|
2880
|
-
case
|
3053
|
+
case import_transactions9.InputType.Message: {
|
2881
3054
|
inputClone.predicateGasUsed = (0, import_math10.bn)(0);
|
2882
3055
|
return inputClone;
|
2883
3056
|
}
|
2884
|
-
case
|
3057
|
+
case import_transactions9.InputType.Contract: {
|
2885
3058
|
inputClone.txPointer = {
|
2886
3059
|
blockHeight: 0,
|
2887
3060
|
txIndex: 0
|
@@ -2899,16 +3072,16 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2899
3072
|
transaction.outputs = transaction.outputs.map((output) => {
|
2900
3073
|
const outputClone = (0, import_ramda2.clone)(output);
|
2901
3074
|
switch (outputClone.type) {
|
2902
|
-
case
|
3075
|
+
case import_transactions9.OutputType.Contract: {
|
2903
3076
|
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2904
3077
|
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2905
3078
|
return outputClone;
|
2906
3079
|
}
|
2907
|
-
case
|
3080
|
+
case import_transactions9.OutputType.Change: {
|
2908
3081
|
outputClone.amount = (0, import_math10.bn)(0);
|
2909
3082
|
return outputClone;
|
2910
3083
|
}
|
2911
|
-
case
|
3084
|
+
case import_transactions9.OutputType.Variable: {
|
2912
3085
|
outputClone.to = import_configs7.ZeroBytes32;
|
2913
3086
|
outputClone.amount = (0, import_math10.bn)(0);
|
2914
3087
|
outputClone.assetId = import_configs7.ZeroBytes32;
|
@@ -2921,7 +3094,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2921
3094
|
transaction.witnessesCount = 0;
|
2922
3095
|
transaction.witnesses = [];
|
2923
3096
|
const chainIdBytes = (0, import_hasher2.uint64ToBytesBE)(chainId);
|
2924
|
-
const concatenatedData = (0, import_utils13.concat)([chainIdBytes, new
|
3097
|
+
const concatenatedData = (0, import_utils13.concat)([chainIdBytes, new import_transactions9.TransactionCoder().encode(transaction)]);
|
2925
3098
|
return (0, import_hasher2.sha256)(concatenatedData);
|
2926
3099
|
}
|
2927
3100
|
|
@@ -2931,7 +3104,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
2931
3104
|
return new this((0, import_ramda3.clone)(obj));
|
2932
3105
|
}
|
2933
3106
|
/** Type of the transaction */
|
2934
|
-
type =
|
3107
|
+
type = import_transactions8.TransactionType.Blob;
|
2935
3108
|
/** Blob ID */
|
2936
3109
|
blobId;
|
2937
3110
|
/** Witness index of the bytecode to create */
|
@@ -2955,7 +3128,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
2955
3128
|
const baseTransaction = this.getBaseTransaction();
|
2956
3129
|
const { witnessIndex, blobId } = this;
|
2957
3130
|
return {
|
2958
|
-
type:
|
3131
|
+
type: import_transactions8.TransactionType.Blob,
|
2959
3132
|
...baseTransaction,
|
2960
3133
|
blobId,
|
2961
3134
|
witnessIndex
|
@@ -2989,7 +3162,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
2989
3162
|
// src/providers/transaction-request/create-transaction-request.ts
|
2990
3163
|
var import_configs8 = require("@fuel-ts/address/configs");
|
2991
3164
|
var import_math11 = require("@fuel-ts/math");
|
2992
|
-
var
|
3165
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2993
3166
|
var import_utils16 = require("@fuel-ts/utils");
|
2994
3167
|
var import_ramda4 = require("ramda");
|
2995
3168
|
|
@@ -3022,7 +3195,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
3022
3195
|
return new this((0, import_ramda4.clone)(obj));
|
3023
3196
|
}
|
3024
3197
|
/** Type of the transaction */
|
3025
|
-
type =
|
3198
|
+
type = import_transactions10.TransactionType.Create;
|
3026
3199
|
/** Witness index of contract bytecode to create */
|
3027
3200
|
bytecodeWitnessIndex;
|
3028
3201
|
/** Salt */
|
@@ -3050,7 +3223,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
3050
3223
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
3051
3224
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
3052
3225
|
return {
|
3053
|
-
type:
|
3226
|
+
type: import_transactions10.TransactionType.Create,
|
3054
3227
|
...baseTransaction,
|
3055
3228
|
bytecodeWitnessIndex,
|
3056
3229
|
storageSlotsCount: (0, import_math11.bn)(storageSlots.length),
|
@@ -3065,7 +3238,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
3065
3238
|
*/
|
3066
3239
|
getContractCreatedOutputs() {
|
3067
3240
|
return this.outputs.filter(
|
3068
|
-
(output) => output.type ===
|
3241
|
+
(output) => output.type === import_transactions10.OutputType.ContractCreated
|
3069
3242
|
);
|
3070
3243
|
}
|
3071
3244
|
/**
|
@@ -3086,7 +3259,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
3086
3259
|
*/
|
3087
3260
|
addContractCreatedOutput(contractId, stateRoot) {
|
3088
3261
|
this.pushOutput({
|
3089
|
-
type:
|
3262
|
+
type: import_transactions10.OutputType.ContractCreated,
|
3090
3263
|
contractId,
|
3091
3264
|
stateRoot
|
3092
3265
|
});
|
@@ -3106,7 +3279,7 @@ var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
|
3106
3279
|
var import_address3 = require("@fuel-ts/address");
|
3107
3280
|
var import_configs9 = require("@fuel-ts/address/configs");
|
3108
3281
|
var import_math12 = require("@fuel-ts/math");
|
3109
|
-
var
|
3282
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
3110
3283
|
var import_utils18 = require("@fuel-ts/utils");
|
3111
3284
|
var import_ramda5 = require("ramda");
|
3112
3285
|
|
@@ -3142,7 +3315,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3142
3315
|
return new this((0, import_ramda5.clone)(obj));
|
3143
3316
|
}
|
3144
3317
|
/** Type of the transaction */
|
3145
|
-
type =
|
3318
|
+
type = import_transactions11.TransactionType.Script;
|
3146
3319
|
/** Gas limit for transaction */
|
3147
3320
|
gasLimit;
|
3148
3321
|
/** Script to execute */
|
@@ -3185,7 +3358,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3185
3358
|
const script = (0, import_utils18.arrayify)(this.script ?? "0x");
|
3186
3359
|
const scriptData = (0, import_utils18.arrayify)(this.scriptData ?? "0x");
|
3187
3360
|
return {
|
3188
|
-
type:
|
3361
|
+
type: import_transactions11.TransactionType.Script,
|
3189
3362
|
scriptGasLimit: this.gasLimit,
|
3190
3363
|
...super.getBaseTransaction(),
|
3191
3364
|
scriptLength: (0, import_math12.bn)(script.length),
|
@@ -3202,7 +3375,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3202
3375
|
*/
|
3203
3376
|
getContractInputs() {
|
3204
3377
|
return this.inputs.filter(
|
3205
|
-
(input) => input.type ===
|
3378
|
+
(input) => input.type === import_transactions11.InputType.Contract
|
3206
3379
|
);
|
3207
3380
|
}
|
3208
3381
|
/**
|
@@ -3212,7 +3385,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3212
3385
|
*/
|
3213
3386
|
getContractOutputs() {
|
3214
3387
|
return this.outputs.filter(
|
3215
|
-
(output) => output.type ===
|
3388
|
+
(output) => output.type === import_transactions11.OutputType.Contract
|
3216
3389
|
);
|
3217
3390
|
}
|
3218
3391
|
/**
|
@@ -3222,7 +3395,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3222
3395
|
*/
|
3223
3396
|
getVariableOutputs() {
|
3224
3397
|
return this.outputs.filter(
|
3225
|
-
(output) => output.type ===
|
3398
|
+
(output) => output.type === import_transactions11.OutputType.Variable
|
3226
3399
|
);
|
3227
3400
|
}
|
3228
3401
|
/**
|
@@ -3245,7 +3418,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3245
3418
|
let outputsNumber = numberOfVariables;
|
3246
3419
|
while (outputsNumber) {
|
3247
3420
|
this.pushOutput({
|
3248
|
-
type:
|
3421
|
+
type: import_transactions11.OutputType.Variable
|
3249
3422
|
});
|
3250
3423
|
outputsNumber -= 1;
|
3251
3424
|
}
|
@@ -3289,12 +3462,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3289
3462
|
return this;
|
3290
3463
|
}
|
3291
3464
|
const inputIndex = super.pushInput({
|
3292
|
-
type:
|
3465
|
+
type: import_transactions11.InputType.Contract,
|
3293
3466
|
contractId: contractAddress.toB256(),
|
3294
3467
|
txPointer: "0x00000000000000000000000000000000"
|
3295
3468
|
});
|
3296
3469
|
this.pushOutput({
|
3297
|
-
type:
|
3470
|
+
type: import_transactions11.OutputType.Contract,
|
3298
3471
|
inputIndex
|
3299
3472
|
});
|
3300
3473
|
return this;
|
@@ -3330,9 +3503,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3330
3503
|
};
|
3331
3504
|
|
3332
3505
|
// src/providers/transaction-request/upgrade-transaction-request.ts
|
3333
|
-
var
|
3506
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3334
3507
|
var import_hasher3 = require("@fuel-ts/hasher");
|
3335
|
-
var
|
3508
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
3336
3509
|
var import_utils19 = require("@fuel-ts/utils");
|
3337
3510
|
var import_ramda6 = require("ramda");
|
3338
3511
|
var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
@@ -3343,7 +3516,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3343
3516
|
return new this((0, import_ramda6.clone)(obj));
|
3344
3517
|
}
|
3345
3518
|
/** The type of transaction */
|
3346
|
-
type =
|
3519
|
+
type = import_transactions12.TransactionType.Upgrade;
|
3347
3520
|
/** The upgrade purpose */
|
3348
3521
|
upgradePurpose;
|
3349
3522
|
/** Witness index of consensus */
|
@@ -3361,7 +3534,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3361
3534
|
super(rest);
|
3362
3535
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
3363
3536
|
this.upgradePurpose = upgradePurpose ?? {
|
3364
|
-
type:
|
3537
|
+
type: import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters,
|
3365
3538
|
checksum: "0x"
|
3366
3539
|
};
|
3367
3540
|
}
|
@@ -3375,7 +3548,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3375
3548
|
addConsensusParametersUpgradePurpose(consensus) {
|
3376
3549
|
this.bytecodeWitnessIndex = this.addWitness(consensus);
|
3377
3550
|
this.upgradePurpose = {
|
3378
|
-
type:
|
3551
|
+
type: import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters,
|
3379
3552
|
checksum: (0, import_hasher3.hash)(consensus)
|
3380
3553
|
};
|
3381
3554
|
return this;
|
@@ -3389,7 +3562,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3389
3562
|
*/
|
3390
3563
|
addStateTransitionUpgradePurpose(bytecodeRoot) {
|
3391
3564
|
this.upgradePurpose = {
|
3392
|
-
type:
|
3565
|
+
type: import_transactions12.UpgradePurposeTypeEnum.StateTransition,
|
3393
3566
|
data: (0, import_utils19.hexlify)(bytecodeRoot)
|
3394
3567
|
};
|
3395
3568
|
return this;
|
@@ -3403,10 +3576,10 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3403
3576
|
* @returns - The current instance of `UpgradeTransactionRequest`.
|
3404
3577
|
*/
|
3405
3578
|
addUpgradePurpose(type, data) {
|
3406
|
-
if (type ===
|
3579
|
+
if (type === import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters) {
|
3407
3580
|
this.addConsensusParametersUpgradePurpose(data);
|
3408
3581
|
}
|
3409
|
-
if (type ===
|
3582
|
+
if (type === import_transactions12.UpgradePurposeTypeEnum.StateTransition) {
|
3410
3583
|
this.addStateTransitionUpgradePurpose(data);
|
3411
3584
|
}
|
3412
3585
|
return this;
|
@@ -3418,26 +3591,26 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3418
3591
|
*/
|
3419
3592
|
toTransaction() {
|
3420
3593
|
let upgradePurpose;
|
3421
|
-
if (this.upgradePurpose.type ===
|
3594
|
+
if (this.upgradePurpose.type === import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters) {
|
3422
3595
|
upgradePurpose = {
|
3423
|
-
type:
|
3596
|
+
type: import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters,
|
3424
3597
|
data: {
|
3425
3598
|
witnessIndex: this.bytecodeWitnessIndex,
|
3426
3599
|
checksum: this.upgradePurpose.checksum
|
3427
3600
|
}
|
3428
3601
|
};
|
3429
|
-
} else if (this.upgradePurpose.type ===
|
3602
|
+
} else if (this.upgradePurpose.type === import_transactions12.UpgradePurposeTypeEnum.StateTransition) {
|
3430
3603
|
upgradePurpose = {
|
3431
|
-
type:
|
3604
|
+
type: import_transactions12.UpgradePurposeTypeEnum.StateTransition,
|
3432
3605
|
data: {
|
3433
3606
|
bytecodeRoot: (0, import_utils19.hexlify)(this.upgradePurpose.data)
|
3434
3607
|
}
|
3435
3608
|
};
|
3436
3609
|
} else {
|
3437
|
-
throw new
|
3610
|
+
throw new import_errors12.FuelError(import_errors12.FuelError.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3438
3611
|
}
|
3439
3612
|
return {
|
3440
|
-
type:
|
3613
|
+
type: import_transactions12.TransactionType.Upgrade,
|
3441
3614
|
...super.getBaseTransaction(),
|
3442
3615
|
upgradePurpose
|
3443
3616
|
};
|
@@ -3461,7 +3634,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3461
3634
|
*/
|
3462
3635
|
metadataGas(gasCosts) {
|
3463
3636
|
const txBytesSize = this.byteSize();
|
3464
|
-
if (this.upgradePurpose.type ===
|
3637
|
+
if (this.upgradePurpose.type === import_transactions12.UpgradePurposeTypeEnum.ConsensusParameters) {
|
3465
3638
|
const witnessIndex = this.bytecodeWitnessIndex;
|
3466
3639
|
const consensusSize = this.witnesses[witnessIndex].length;
|
3467
3640
|
return calculateMetadataGasForTxUpgrade({
|
@@ -3470,19 +3643,19 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3470
3643
|
consensusSize
|
3471
3644
|
});
|
3472
3645
|
}
|
3473
|
-
if (this.upgradePurpose.type ===
|
3646
|
+
if (this.upgradePurpose.type === import_transactions12.UpgradePurposeTypeEnum.StateTransition) {
|
3474
3647
|
return calculateMetadataGasForTxUpgrade({
|
3475
3648
|
gasCosts,
|
3476
3649
|
txBytesSize
|
3477
3650
|
});
|
3478
3651
|
}
|
3479
|
-
throw new
|
3652
|
+
throw new import_errors12.FuelError(import_errors12.FuelError.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3480
3653
|
}
|
3481
3654
|
};
|
3482
3655
|
|
3483
3656
|
// src/providers/transaction-request/upload-transaction-request.ts
|
3484
3657
|
var import_configs10 = require("@fuel-ts/address/configs");
|
3485
|
-
var
|
3658
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
3486
3659
|
var import_utils21 = require("@fuel-ts/utils");
|
3487
3660
|
var import_ramda7 = require("ramda");
|
3488
3661
|
var UploadTransactionRequest = class extends BaseTransactionRequest {
|
@@ -3493,7 +3666,7 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
3493
3666
|
return new this((0, import_ramda7.clone)(obj));
|
3494
3667
|
}
|
3495
3668
|
/** Type of the transaction */
|
3496
|
-
type =
|
3669
|
+
type = import_transactions13.TransactionType.Upload;
|
3497
3670
|
/** The witness index of the subsection of the bytecode. */
|
3498
3671
|
witnessIndex;
|
3499
3672
|
/** The subsection data. */
|
@@ -3542,7 +3715,7 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
3542
3715
|
const baseTransaction = this.getBaseTransaction();
|
3543
3716
|
const { subsectionIndex, subsectionsNumber, root, proofSet } = this.subsection;
|
3544
3717
|
return {
|
3545
|
-
type:
|
3718
|
+
type: import_transactions13.TransactionType.Upload,
|
3546
3719
|
...baseTransaction,
|
3547
3720
|
subsectionIndex,
|
3548
3721
|
subsectionsNumber,
|
@@ -3587,55 +3760,146 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
3587
3760
|
};
|
3588
3761
|
|
3589
3762
|
// src/providers/transaction-request/utils.ts
|
3590
|
-
var
|
3591
|
-
var
|
3763
|
+
var import_errors13 = require("@fuel-ts/errors");
|
3764
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
3592
3765
|
var transactionRequestify = (obj) => {
|
3593
3766
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest || obj instanceof UpgradeTransactionRequest || obj instanceof UploadTransactionRequest) {
|
3594
3767
|
return obj;
|
3595
3768
|
}
|
3596
3769
|
const { type } = obj;
|
3597
3770
|
switch (obj.type) {
|
3598
|
-
case
|
3771
|
+
case import_transactions14.TransactionType.Script: {
|
3599
3772
|
return ScriptTransactionRequest.from(obj);
|
3600
3773
|
}
|
3601
|
-
case
|
3774
|
+
case import_transactions14.TransactionType.Create: {
|
3602
3775
|
return CreateTransactionRequest.from(obj);
|
3603
3776
|
}
|
3604
|
-
case
|
3777
|
+
case import_transactions14.TransactionType.Blob: {
|
3605
3778
|
return BlobTransactionRequest.from(obj);
|
3606
3779
|
}
|
3607
|
-
case
|
3780
|
+
case import_transactions14.TransactionType.Upgrade: {
|
3608
3781
|
return UpgradeTransactionRequest.from(obj);
|
3609
3782
|
}
|
3610
|
-
case
|
3783
|
+
case import_transactions14.TransactionType.Upload: {
|
3611
3784
|
return UploadTransactionRequest.from(obj);
|
3612
3785
|
}
|
3613
3786
|
default: {
|
3614
|
-
throw new
|
3615
|
-
|
3787
|
+
throw new import_errors13.FuelError(
|
3788
|
+
import_errors13.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
3616
3789
|
`Unsupported transaction type: ${type}.`
|
3617
3790
|
);
|
3618
3791
|
}
|
3619
3792
|
}
|
3620
3793
|
};
|
3621
|
-
var isTransactionTypeScript = (request) => request.type ===
|
3622
|
-
var isTransactionTypeCreate = (request) => request.type ===
|
3794
|
+
var isTransactionTypeScript = (request) => request.type === import_transactions14.TransactionType.Script;
|
3795
|
+
var isTransactionTypeCreate = (request) => request.type === import_transactions14.TransactionType.Create;
|
3796
|
+
|
3797
|
+
// src/providers/resource-cache.ts
|
3798
|
+
var cache = /* @__PURE__ */ new Map();
|
3799
|
+
var ResourceCache = class {
|
3800
|
+
ttl;
|
3801
|
+
constructor(ttl) {
|
3802
|
+
this.ttl = ttl;
|
3803
|
+
if (typeof ttl !== "number" || this.ttl <= 0) {
|
3804
|
+
throw new import_errors14.FuelError(
|
3805
|
+
import_errors14.ErrorCode.INVALID_TTL,
|
3806
|
+
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
3807
|
+
);
|
3808
|
+
}
|
3809
|
+
}
|
3810
|
+
// Add resources to the cache
|
3811
|
+
set(transactionId, inputs) {
|
3812
|
+
const transactionResourceCache = this.setupResourcesCache(inputs);
|
3813
|
+
cache.set(transactionId, transactionResourceCache);
|
3814
|
+
}
|
3815
|
+
unset(transactionId) {
|
3816
|
+
cache.delete(transactionId);
|
3817
|
+
}
|
3818
|
+
getActiveData(owner) {
|
3819
|
+
const activeData = { utxos: [], messages: [] };
|
3820
|
+
const currentTime = Date.now();
|
3821
|
+
const expired = [];
|
3822
|
+
cache.forEach((resource, transactionId) => {
|
3823
|
+
const isActive = currentTime - resource.timestamp < this.ttl;
|
3824
|
+
if (isActive) {
|
3825
|
+
const resourcesFromOwner = resource.owners.get(owner);
|
3826
|
+
if (resourcesFromOwner) {
|
3827
|
+
activeData.utxos.push(...resourcesFromOwner.utxos);
|
3828
|
+
activeData.messages.push(...resourcesFromOwner.messages);
|
3829
|
+
}
|
3830
|
+
} else {
|
3831
|
+
expired.push(transactionId);
|
3832
|
+
}
|
3833
|
+
});
|
3834
|
+
expired.forEach(this.unset);
|
3835
|
+
activeData.utxos.reverse();
|
3836
|
+
activeData.messages.reverse();
|
3837
|
+
return activeData;
|
3838
|
+
}
|
3839
|
+
isCached(owner, key) {
|
3840
|
+
const currentTime = Date.now();
|
3841
|
+
let cached = false;
|
3842
|
+
const expired = [];
|
3843
|
+
for (const [transactionId, resourceData] of cache.entries()) {
|
3844
|
+
const isActive = currentTime - resourceData.timestamp < this.ttl;
|
3845
|
+
if (isActive) {
|
3846
|
+
const resourcesFromOwner = resourceData.owners.get(owner);
|
3847
|
+
if (resourcesFromOwner?.utxos.has(key) || resourcesFromOwner?.messages.has(key)) {
|
3848
|
+
cached = true;
|
3849
|
+
break;
|
3850
|
+
}
|
3851
|
+
} else {
|
3852
|
+
expired.push(transactionId);
|
3853
|
+
}
|
3854
|
+
}
|
3855
|
+
expired.forEach(this.unset);
|
3856
|
+
return cached;
|
3857
|
+
}
|
3858
|
+
clear() {
|
3859
|
+
cache.clear();
|
3860
|
+
}
|
3861
|
+
setupResourcesCache(inputs) {
|
3862
|
+
const currentTime = Date.now();
|
3863
|
+
const transactionResourcesCache = {
|
3864
|
+
owners: /* @__PURE__ */ new Map(),
|
3865
|
+
timestamp: currentTime
|
3866
|
+
};
|
3867
|
+
inputs.filter(isRequestInputCoinOrMessage).forEach((input) => {
|
3868
|
+
const { owner, key, type } = this.extractResourceData(input);
|
3869
|
+
if (!transactionResourcesCache.owners.has(owner)) {
|
3870
|
+
transactionResourcesCache.owners.set(owner, { utxos: /* @__PURE__ */ new Set(), messages: /* @__PURE__ */ new Set() });
|
3871
|
+
}
|
3872
|
+
if (type === "utxo") {
|
3873
|
+
transactionResourcesCache.owners.get(owner)?.utxos.add(key);
|
3874
|
+
} else {
|
3875
|
+
transactionResourcesCache.owners.get(owner)?.messages.add(key);
|
3876
|
+
}
|
3877
|
+
});
|
3878
|
+
return transactionResourcesCache;
|
3879
|
+
}
|
3880
|
+
extractResourceData(input) {
|
3881
|
+
if (isRequestInputCoin(input)) {
|
3882
|
+
return { owner: (0, import_utils23.hexlify)(input.owner), key: (0, import_utils23.hexlify)(input.id), type: "utxo" };
|
3883
|
+
}
|
3884
|
+
return { owner: (0, import_utils23.hexlify)(input.recipient), key: (0, import_utils23.hexlify)(input.nonce), type: "message" };
|
3885
|
+
}
|
3886
|
+
};
|
3623
3887
|
|
3624
3888
|
// src/providers/transaction-response/transaction-response.ts
|
3625
3889
|
var import_errors18 = require("@fuel-ts/errors");
|
3626
3890
|
var import_math18 = require("@fuel-ts/math");
|
3627
|
-
var
|
3891
|
+
var import_transactions22 = require("@fuel-ts/transactions");
|
3628
3892
|
var import_utils27 = require("@fuel-ts/utils");
|
3629
3893
|
|
3630
3894
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
3631
3895
|
var import_math17 = require("@fuel-ts/math");
|
3632
|
-
var
|
3896
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
3633
3897
|
var import_utils25 = require("@fuel-ts/utils");
|
3634
3898
|
|
3635
3899
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
3636
3900
|
var import_math13 = require("@fuel-ts/math");
|
3637
|
-
var
|
3638
|
-
var
|
3901
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3902
|
+
var import_utils24 = require("@fuel-ts/utils");
|
3639
3903
|
var calculateTXFeeForSummary = (params) => {
|
3640
3904
|
const {
|
3641
3905
|
gasPrice,
|
@@ -3645,17 +3909,17 @@ var calculateTXFeeForSummary = (params) => {
|
|
3645
3909
|
} = params;
|
3646
3910
|
const gasPerByte = (0, import_math13.bn)(feeParams.gasPerByte);
|
3647
3911
|
const gasPriceFactor = (0, import_math13.bn)(feeParams.gasPriceFactor);
|
3648
|
-
const transactionBytes = (0,
|
3649
|
-
const [transaction] = new
|
3912
|
+
const transactionBytes = (0, import_utils24.arrayify)(rawPayload);
|
3913
|
+
const [transaction] = new import_transactions15.TransactionCoder().decode(transactionBytes, 0);
|
3650
3914
|
const { type, witnesses, inputs, policies } = transaction;
|
3651
3915
|
let metadataGas = (0, import_math13.bn)(0);
|
3652
3916
|
let gasLimit = (0, import_math13.bn)(0);
|
3653
|
-
if (type !==
|
3917
|
+
if (type !== import_transactions15.TransactionType.Create && type !== import_transactions15.TransactionType.Script) {
|
3654
3918
|
return (0, import_math13.bn)(0);
|
3655
3919
|
}
|
3656
|
-
if (type ===
|
3920
|
+
if (type === import_transactions15.TransactionType.Create) {
|
3657
3921
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
3658
|
-
const contractBytesSize = (0, import_math13.bn)((0,
|
3922
|
+
const contractBytesSize = (0, import_math13.bn)((0, import_utils24.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
3659
3923
|
metadataGas = calculateMetadataGasForTxCreate({
|
3660
3924
|
contractBytesSize,
|
3661
3925
|
gasCosts,
|
@@ -3679,7 +3943,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3679
3943
|
metadataGas,
|
3680
3944
|
txBytesSize: transactionBytes.length
|
3681
3945
|
});
|
3682
|
-
const witnessLimit = policies.find((policy) => policy.type ===
|
3946
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions15.PolicyType.WitnessLimit)?.data;
|
3683
3947
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
3684
3948
|
const maxGas = getMaxGas({
|
3685
3949
|
gasPerByte,
|
@@ -3702,45 +3966,12 @@ var calculateTXFeeForSummary = (params) => {
|
|
3702
3966
|
var import_configs11 = require("@fuel-ts/address/configs");
|
3703
3967
|
var import_errors16 = require("@fuel-ts/errors");
|
3704
3968
|
var import_math15 = require("@fuel-ts/math");
|
3705
|
-
var
|
3706
|
-
|
3707
|
-
// src/providers/transaction-summary/call.ts
|
3708
|
-
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3709
|
-
var getFunctionCall = ({ abi, receipt }) => {
|
3710
|
-
const abiInterface = new import_abi_coder5.Interface(abi);
|
3711
|
-
const callFunctionSelector = receipt.param1.toHex(8);
|
3712
|
-
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
3713
|
-
const inputs = functionFragment.jsonFn.inputs;
|
3714
|
-
const encodedArgs = receipt.param2.toHex();
|
3715
|
-
let argumentsProvided;
|
3716
|
-
const data = functionFragment.decodeArguments(encodedArgs);
|
3717
|
-
if (data) {
|
3718
|
-
argumentsProvided = inputs.reduce((prev, input, index) => {
|
3719
|
-
const value = data[index];
|
3720
|
-
const name = input.name;
|
3721
|
-
if (name) {
|
3722
|
-
return {
|
3723
|
-
...prev,
|
3724
|
-
// reparse to remove bn
|
3725
|
-
[name]: JSON.parse(JSON.stringify(value))
|
3726
|
-
};
|
3727
|
-
}
|
3728
|
-
return prev;
|
3729
|
-
}, {});
|
3730
|
-
}
|
3731
|
-
const call = {
|
3732
|
-
functionSignature: functionFragment.signature,
|
3733
|
-
functionName: functionFragment.name,
|
3734
|
-
argumentsProvided,
|
3735
|
-
...receipt.amount?.isZero() ? {} : { amount: receipt.amount, assetId: receipt.assetId }
|
3736
|
-
};
|
3737
|
-
return call;
|
3738
|
-
};
|
3969
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
3739
3970
|
|
3740
3971
|
// src/providers/transaction-summary/input.ts
|
3741
3972
|
var import_errors15 = require("@fuel-ts/errors");
|
3742
3973
|
var import_math14 = require("@fuel-ts/math");
|
3743
|
-
var
|
3974
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3744
3975
|
function getInputsByTypes(inputs, types) {
|
3745
3976
|
return inputs.filter((i) => types.includes(i.type));
|
3746
3977
|
}
|
@@ -3748,19 +3979,19 @@ function getInputsByType(inputs, type) {
|
|
3748
3979
|
return inputs.filter((i) => i.type === type);
|
3749
3980
|
}
|
3750
3981
|
function getInputsCoin(inputs) {
|
3751
|
-
return getInputsByType(inputs,
|
3982
|
+
return getInputsByType(inputs, import_transactions16.InputType.Coin);
|
3752
3983
|
}
|
3753
3984
|
function getInputsMessage(inputs) {
|
3754
|
-
return getInputsByType(inputs,
|
3985
|
+
return getInputsByType(inputs, import_transactions16.InputType.Message);
|
3755
3986
|
}
|
3756
3987
|
function getInputsCoinAndMessage(inputs) {
|
3757
|
-
return getInputsByTypes(inputs, [
|
3988
|
+
return getInputsByTypes(inputs, [import_transactions16.InputType.Coin, import_transactions16.InputType.Message]);
|
3758
3989
|
}
|
3759
3990
|
function isInputCoin(input) {
|
3760
|
-
return input.type ===
|
3991
|
+
return input.type === import_transactions16.InputType.Coin;
|
3761
3992
|
}
|
3762
3993
|
function getInputsContract(inputs) {
|
3763
|
-
return getInputsByType(inputs,
|
3994
|
+
return getInputsByType(inputs, import_transactions16.InputType.Contract);
|
3764
3995
|
}
|
3765
3996
|
function findCoinInput(inputs, assetId) {
|
3766
3997
|
const coinInputs = getInputsCoin(inputs);
|
@@ -3806,7 +4037,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
3806
4037
|
if (!contractInput) {
|
3807
4038
|
return void 0;
|
3808
4039
|
}
|
3809
|
-
if (contractInput.type !==
|
4040
|
+
if (contractInput.type !== import_transactions16.InputType.Contract) {
|
3810
4041
|
throw new import_errors15.FuelError(
|
3811
4042
|
import_errors15.ErrorCode.INVALID_TRANSACTION_INPUT,
|
3812
4043
|
`Contract input should be of type 'contract'.`
|
@@ -3815,31 +4046,31 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
3815
4046
|
return contractInput;
|
3816
4047
|
}
|
3817
4048
|
function getInputAccountAddress(input) {
|
3818
|
-
if (input.type ===
|
4049
|
+
if (input.type === import_transactions16.InputType.Coin) {
|
3819
4050
|
return input.owner.toString();
|
3820
4051
|
}
|
3821
|
-
if (input.type ===
|
4052
|
+
if (input.type === import_transactions16.InputType.Message) {
|
3822
4053
|
return input.recipient.toString();
|
3823
4054
|
}
|
3824
4055
|
return "";
|
3825
4056
|
}
|
3826
4057
|
|
3827
4058
|
// src/providers/transaction-summary/output.ts
|
3828
|
-
var
|
4059
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3829
4060
|
function getOutputsByType(outputs, type) {
|
3830
4061
|
return outputs.filter((o) => o.type === type);
|
3831
4062
|
}
|
3832
4063
|
function getOutputsContractCreated(outputs) {
|
3833
|
-
return getOutputsByType(outputs,
|
4064
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.ContractCreated);
|
3834
4065
|
}
|
3835
4066
|
function getOutputsCoin(outputs) {
|
3836
|
-
return getOutputsByType(outputs,
|
4067
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.Coin);
|
3837
4068
|
}
|
3838
4069
|
function getOutputsChange(outputs) {
|
3839
|
-
return getOutputsByType(outputs,
|
4070
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.Change);
|
3840
4071
|
}
|
3841
4072
|
function getOutputsContract(outputs) {
|
3842
|
-
return getOutputsByType(outputs,
|
4073
|
+
return getOutputsByType(outputs, import_transactions17.OutputType.Contract);
|
3843
4074
|
}
|
3844
4075
|
|
3845
4076
|
// src/providers/transaction-summary/operations.ts
|
@@ -3848,17 +4079,17 @@ function getReceiptsByType(receipts, type) {
|
|
3848
4079
|
}
|
3849
4080
|
function getTransactionTypeName(transactionType) {
|
3850
4081
|
switch (transactionType) {
|
3851
|
-
case
|
4082
|
+
case import_transactions18.TransactionType.Mint:
|
3852
4083
|
return "Mint" /* Mint */;
|
3853
|
-
case
|
4084
|
+
case import_transactions18.TransactionType.Create:
|
3854
4085
|
return "Create" /* Create */;
|
3855
|
-
case
|
4086
|
+
case import_transactions18.TransactionType.Script:
|
3856
4087
|
return "Script" /* Script */;
|
3857
|
-
case
|
4088
|
+
case import_transactions18.TransactionType.Blob:
|
3858
4089
|
return "Blob" /* Blob */;
|
3859
|
-
case
|
4090
|
+
case import_transactions18.TransactionType.Upgrade:
|
3860
4091
|
return "Upgrade" /* Upgrade */;
|
3861
|
-
case
|
4092
|
+
case import_transactions18.TransactionType.Upload:
|
3862
4093
|
return "Upload" /* Upload */;
|
3863
4094
|
default:
|
3864
4095
|
throw new import_errors16.FuelError(
|
@@ -3890,10 +4121,10 @@ function isTypeBlob(transactionType) {
|
|
3890
4121
|
return isType(transactionType, "Blob" /* Blob */);
|
3891
4122
|
}
|
3892
4123
|
function getReceiptsCall(receipts) {
|
3893
|
-
return getReceiptsByType(receipts,
|
4124
|
+
return getReceiptsByType(receipts, import_transactions18.ReceiptType.Call);
|
3894
4125
|
}
|
3895
4126
|
function getReceiptsMessageOut(receipts) {
|
3896
|
-
return getReceiptsByType(receipts,
|
4127
|
+
return getReceiptsByType(receipts, import_transactions18.ReceiptType.MessageOut);
|
3897
4128
|
}
|
3898
4129
|
function mergeAssets(op1, op2) {
|
3899
4130
|
const assets1 = op1.assetsSent || [];
|
@@ -3931,7 +4162,11 @@ function mergeOperations(existing, toAdd) {
|
|
3931
4162
|
return {
|
3932
4163
|
...existing,
|
3933
4164
|
assetsSent: mergeAssetsSent(existing, toAdd),
|
3934
|
-
calls: mergeCalls(existing, toAdd)
|
4165
|
+
calls: mergeCalls(existing, toAdd),
|
4166
|
+
receipts: [
|
4167
|
+
...existing.receipts || [],
|
4168
|
+
...toAdd.receipts?.filter((r) => !existing.receipts?.some((er) => er === r)) || []
|
4169
|
+
]
|
3935
4170
|
};
|
3936
4171
|
}
|
3937
4172
|
function addOperation(operations, toAdd) {
|
@@ -3968,7 +4203,8 @@ function getWithdrawFromFuelOperations({
|
|
3968
4203
|
amount: receipt.amount,
|
3969
4204
|
assetId: baseAssetId
|
3970
4205
|
}
|
3971
|
-
]
|
4206
|
+
],
|
4207
|
+
receipts: [receipt]
|
3972
4208
|
});
|
3973
4209
|
return newWithdrawFromFuelOps;
|
3974
4210
|
}
|
@@ -3978,19 +4214,12 @@ function getWithdrawFromFuelOperations({
|
|
3978
4214
|
);
|
3979
4215
|
return withdrawFromFuelOperations;
|
3980
4216
|
}
|
3981
|
-
function getContractCalls(contractInput, abiMap,
|
4217
|
+
function getContractCalls(contractInput, abiMap, _receipt, _rawPayload, _maxInputs) {
|
3982
4218
|
const abi = abiMap?.[contractInput.contractID];
|
3983
4219
|
if (!abi) {
|
3984
4220
|
return [];
|
3985
4221
|
}
|
3986
|
-
return [
|
3987
|
-
getFunctionCall({
|
3988
|
-
abi,
|
3989
|
-
receipt,
|
3990
|
-
rawPayload,
|
3991
|
-
maxInputs
|
3992
|
-
})
|
3993
|
-
];
|
4222
|
+
return [];
|
3994
4223
|
}
|
3995
4224
|
function getAssetsSent(receipt) {
|
3996
4225
|
return receipt.amount?.isZero() ? void 0 : [
|
@@ -4020,7 +4249,8 @@ function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload,
|
|
4020
4249
|
address: receipt.to
|
4021
4250
|
},
|
4022
4251
|
assetsSent: getAssetsSent(receipt),
|
4023
|
-
calls
|
4252
|
+
calls,
|
4253
|
+
receipts: [receipt]
|
4024
4254
|
}
|
4025
4255
|
];
|
4026
4256
|
}
|
@@ -4077,7 +4307,8 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
4077
4307
|
assetId: assetId.toString(),
|
4078
4308
|
amount
|
4079
4309
|
}
|
4080
|
-
]
|
4310
|
+
],
|
4311
|
+
receipts: [receipt]
|
4081
4312
|
};
|
4082
4313
|
}
|
4083
4314
|
function getTransferOperations({
|
@@ -4122,11 +4353,11 @@ function getTransferOperations({
|
|
4122
4353
|
});
|
4123
4354
|
const transferReceipts = getReceiptsByType(
|
4124
4355
|
receipts,
|
4125
|
-
|
4356
|
+
import_transactions18.ReceiptType.Transfer
|
4126
4357
|
);
|
4127
4358
|
const transferOutReceipts = getReceiptsByType(
|
4128
4359
|
receipts,
|
4129
|
-
|
4360
|
+
import_transactions18.ReceiptType.TransferOut
|
4130
4361
|
);
|
4131
4362
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
4132
4363
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -4210,12 +4441,11 @@ function getOperations({
|
|
4210
4441
|
}
|
4211
4442
|
|
4212
4443
|
// src/providers/transaction-summary/receipt.ts
|
4213
|
-
var
|
4214
|
-
var processGqlReceipt = (gqlReceipt) => assembleReceiptByType(gqlReceipt);
|
4444
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4215
4445
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
4216
4446
|
const mintedAssets = [];
|
4217
4447
|
receipts.forEach((receipt) => {
|
4218
|
-
if (receipt.type ===
|
4448
|
+
if (receipt.type === import_transactions19.ReceiptType.Mint) {
|
4219
4449
|
mintedAssets.push({
|
4220
4450
|
subId: receipt.subId,
|
4221
4451
|
contractId: receipt.contractId,
|
@@ -4229,7 +4459,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
4229
4459
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
4230
4460
|
const burnedAssets = [];
|
4231
4461
|
receipts.forEach((receipt) => {
|
4232
|
-
if (receipt.type ===
|
4462
|
+
if (receipt.type === import_transactions19.ReceiptType.Burn) {
|
4233
4463
|
burnedAssets.push({
|
4234
4464
|
subId: receipt.subId,
|
4235
4465
|
contractId: receipt.contractId,
|
@@ -4338,7 +4568,7 @@ function assembleTransactionSummary(params) {
|
|
4338
4568
|
baseAssetId
|
4339
4569
|
});
|
4340
4570
|
const typeName = getTransactionTypeName(transaction.type);
|
4341
|
-
const tip = (0, import_math17.bn)(transaction.policies?.find((policy) => policy.type ===
|
4571
|
+
const tip = (0, import_math17.bn)(transaction.policies?.find((policy) => policy.type === import_transactions20.PolicyType.Tip)?.data);
|
4342
4572
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
4343
4573
|
const fee = totalFee ?? calculateTXFeeForSummary({
|
4344
4574
|
gasPrice,
|
@@ -4388,13 +4618,13 @@ function assembleTransactionSummary(params) {
|
|
4388
4618
|
}
|
4389
4619
|
|
4390
4620
|
// src/providers/transaction-response/getDecodedLogs.ts
|
4391
|
-
var
|
4392
|
-
var
|
4621
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
4622
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
4393
4623
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
4394
4624
|
return receipts.reduce((logs, receipt) => {
|
4395
|
-
if (receipt.type ===
|
4396
|
-
const interfaceToUse = new
|
4397
|
-
const data = receipt.type ===
|
4625
|
+
if (receipt.type === import_transactions21.ReceiptType.LogData || receipt.type === import_transactions21.ReceiptType.Log) {
|
4626
|
+
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
4627
|
+
const data = receipt.type === import_transactions21.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
4398
4628
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
4399
4629
|
logs.push(decodedLog);
|
4400
4630
|
}
|
@@ -4408,24 +4638,24 @@ function mapGqlOutputsToTxOutputs(outputs) {
|
|
4408
4638
|
const obj = "amount" in o ? { ...o, amount: (0, import_math18.bn)(o.amount) } : o;
|
4409
4639
|
switch (obj.type) {
|
4410
4640
|
case "CoinOutput":
|
4411
|
-
return { ...obj, type:
|
4641
|
+
return { ...obj, type: import_transactions22.OutputType.Coin };
|
4412
4642
|
case "ContractOutput":
|
4413
4643
|
return {
|
4414
4644
|
...obj,
|
4415
|
-
type:
|
4645
|
+
type: import_transactions22.OutputType.Contract,
|
4416
4646
|
inputIndex: parseInt(obj.inputIndex, 10)
|
4417
4647
|
};
|
4418
4648
|
case "ChangeOutput":
|
4419
4649
|
return {
|
4420
4650
|
...obj,
|
4421
|
-
type:
|
4651
|
+
type: import_transactions22.OutputType.Change
|
4422
4652
|
};
|
4423
4653
|
case "VariableOutput":
|
4424
|
-
return { ...obj, type:
|
4654
|
+
return { ...obj, type: import_transactions22.OutputType.Variable };
|
4425
4655
|
case "ContractCreated":
|
4426
4656
|
return {
|
4427
4657
|
...obj,
|
4428
|
-
type:
|
4658
|
+
type: import_transactions22.OutputType.ContractCreated,
|
4429
4659
|
contractId: obj.contract
|
4430
4660
|
};
|
4431
4661
|
default:
|
@@ -4485,7 +4715,7 @@ var TransactionResponse = class {
|
|
4485
4715
|
const correspondingInput = status.transaction.inputs?.[idx];
|
4486
4716
|
return {
|
4487
4717
|
...input,
|
4488
|
-
txPointer:
|
4718
|
+
txPointer: import_transactions22.TxPointerCoder.decodeFromGqlScalar(correspondingInput.txPointer)
|
4489
4719
|
};
|
4490
4720
|
}
|
4491
4721
|
return input;
|
@@ -4516,7 +4746,7 @@ var TransactionResponse = class {
|
|
4516
4746
|
switch (status?.type) {
|
4517
4747
|
case "SuccessStatus":
|
4518
4748
|
case "FailureStatus":
|
4519
|
-
return status.receipts.map(
|
4749
|
+
return status.receipts.map(deserializeReceipt);
|
4520
4750
|
default:
|
4521
4751
|
return [];
|
4522
4752
|
}
|
@@ -4552,7 +4782,7 @@ var TransactionResponse = class {
|
|
4552
4782
|
* @returns The decoded transaction.
|
4553
4783
|
*/
|
4554
4784
|
decodeTransaction(transactionWithReceipts) {
|
4555
|
-
return new
|
4785
|
+
return new import_transactions22.TransactionCoder().decode(
|
4556
4786
|
(0, import_utils27.arrayify)(transactionWithReceipts.rawPayload),
|
4557
4787
|
0
|
4558
4788
|
)?.[0];
|
@@ -4640,7 +4870,6 @@ var TransactionResponse = class {
|
|
4640
4870
|
const { receipts } = transactionResult;
|
4641
4871
|
const status = this.status ?? this.gqlTransaction?.status;
|
4642
4872
|
if (status?.type === "FailureStatus") {
|
4643
|
-
this.unsetResourceCache();
|
4644
4873
|
const { reason } = status;
|
4645
4874
|
throw extractTxError({
|
4646
4875
|
receipts,
|
@@ -4657,6 +4886,7 @@ var TransactionResponse = class {
|
|
4657
4886
|
*/
|
4658
4887
|
async waitForResult(contractsAbiMap) {
|
4659
4888
|
await this.waitForStatusChange();
|
4889
|
+
this.unsetResourceCache();
|
4660
4890
|
return this.assembleResult(contractsAbiMap);
|
4661
4891
|
}
|
4662
4892
|
/**
|
@@ -4709,6 +4939,22 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4709
4939
|
};
|
4710
4940
|
}
|
4711
4941
|
|
4942
|
+
// src/providers/utils/helpers.ts
|
4943
|
+
var adjustResourcesToExclude = (params) => {
|
4944
|
+
const { userInput, cached, maxInputs } = params;
|
4945
|
+
const final = { ...userInput };
|
4946
|
+
let total = final.utxos.length + final.messages.length;
|
4947
|
+
if (total >= maxInputs) {
|
4948
|
+
return final;
|
4949
|
+
}
|
4950
|
+
final.utxos = [...final.utxos, ...cached.utxos.slice(0, maxInputs - total)];
|
4951
|
+
total = final.utxos.length + final.messages.length;
|
4952
|
+
if (total < maxInputs) {
|
4953
|
+
final.messages = [...final.messages, ...cached.messages.slice(0, maxInputs - total)];
|
4954
|
+
}
|
4955
|
+
return final;
|
4956
|
+
};
|
4957
|
+
|
4712
4958
|
// src/providers/utils/validate-pagination-args.ts
|
4713
4959
|
var import_errors19 = require("@fuel-ts/errors");
|
4714
4960
|
var validatePaginationArgs = (params) => {
|
@@ -4748,64 +4994,10 @@ var validatePaginationArgs = (params) => {
|
|
4748
4994
|
var MAX_RETRIES = 10;
|
4749
4995
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
4750
4996
|
var TRANSACTIONS_PAGE_SIZE_LIMIT = 60;
|
4997
|
+
var BALANCES_PAGE_SIZE_LIMIT = 100;
|
4751
4998
|
var BLOCKS_PAGE_SIZE_LIMIT = 5;
|
4752
4999
|
var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
|
4753
5000
|
var GAS_USED_MODIFIER = 1.2;
|
4754
|
-
var processGqlChain = (chain) => {
|
4755
|
-
const { name, daHeight, consensusParameters } = chain;
|
4756
|
-
const {
|
4757
|
-
contractParams,
|
4758
|
-
feeParams,
|
4759
|
-
predicateParams,
|
4760
|
-
scriptParams,
|
4761
|
-
txParams,
|
4762
|
-
gasCosts,
|
4763
|
-
baseAssetId,
|
4764
|
-
chainId,
|
4765
|
-
version
|
4766
|
-
} = consensusParameters;
|
4767
|
-
return {
|
4768
|
-
name,
|
4769
|
-
baseChainHeight: (0, import_math19.bn)(daHeight),
|
4770
|
-
consensusParameters: {
|
4771
|
-
version,
|
4772
|
-
chainId: (0, import_math19.bn)(chainId),
|
4773
|
-
baseAssetId,
|
4774
|
-
feeParameters: {
|
4775
|
-
version: feeParams.version,
|
4776
|
-
gasPerByte: (0, import_math19.bn)(feeParams.gasPerByte),
|
4777
|
-
gasPriceFactor: (0, import_math19.bn)(feeParams.gasPriceFactor)
|
4778
|
-
},
|
4779
|
-
contractParameters: {
|
4780
|
-
version: contractParams.version,
|
4781
|
-
contractMaxSize: (0, import_math19.bn)(contractParams.contractMaxSize),
|
4782
|
-
maxStorageSlots: (0, import_math19.bn)(contractParams.maxStorageSlots)
|
4783
|
-
},
|
4784
|
-
txParameters: {
|
4785
|
-
version: txParams.version,
|
4786
|
-
maxInputs: (0, import_math19.bn)(txParams.maxInputs),
|
4787
|
-
maxOutputs: (0, import_math19.bn)(txParams.maxOutputs),
|
4788
|
-
maxWitnesses: (0, import_math19.bn)(txParams.maxWitnesses),
|
4789
|
-
maxGasPerTx: (0, import_math19.bn)(txParams.maxGasPerTx),
|
4790
|
-
maxSize: (0, import_math19.bn)(txParams.maxSize),
|
4791
|
-
maxBytecodeSubsections: (0, import_math19.bn)(txParams.maxBytecodeSubsections)
|
4792
|
-
},
|
4793
|
-
predicateParameters: {
|
4794
|
-
version: predicateParams.version,
|
4795
|
-
maxPredicateLength: (0, import_math19.bn)(predicateParams.maxPredicateLength),
|
4796
|
-
maxPredicateDataLength: (0, import_math19.bn)(predicateParams.maxPredicateDataLength),
|
4797
|
-
maxGasPerPredicate: (0, import_math19.bn)(predicateParams.maxGasPerPredicate),
|
4798
|
-
maxMessageDataLength: (0, import_math19.bn)(predicateParams.maxMessageDataLength)
|
4799
|
-
},
|
4800
|
-
scriptParameters: {
|
4801
|
-
version: scriptParams.version,
|
4802
|
-
maxScriptLength: (0, import_math19.bn)(scriptParams.maxScriptLength),
|
4803
|
-
maxScriptDataLength: (0, import_math19.bn)(scriptParams.maxScriptDataLength)
|
4804
|
-
},
|
4805
|
-
gasCosts
|
4806
|
-
}
|
4807
|
-
};
|
4808
|
-
};
|
4809
5001
|
var _cacheInputs, cacheInputs_fn;
|
4810
5002
|
var _Provider = class {
|
4811
5003
|
/**
|
@@ -4827,13 +5019,19 @@ var _Provider = class {
|
|
4827
5019
|
/** @hidden */
|
4828
5020
|
__publicField(this, "urlWithoutAuth");
|
4829
5021
|
/** @hidden */
|
5022
|
+
__publicField(this, "features", {
|
5023
|
+
balancePagination: false,
|
5024
|
+
amount128: false
|
5025
|
+
});
|
5026
|
+
/** @hidden */
|
4830
5027
|
__publicField(this, "consensusParametersTimestamp");
|
4831
5028
|
__publicField(this, "options", {
|
4832
5029
|
timeout: void 0,
|
4833
5030
|
resourceCacheTTL: void 0,
|
4834
5031
|
fetch: void 0,
|
4835
5032
|
retryOptions: void 0,
|
4836
|
-
headers: void 0
|
5033
|
+
headers: void 0,
|
5034
|
+
cache: void 0
|
4837
5035
|
});
|
4838
5036
|
const { url: rawUrl, urlWithoutAuth, headers: authHeaders } = _Provider.extractBasicAuth(url);
|
4839
5037
|
this.url = rawUrl;
|
@@ -4847,7 +5045,13 @@ var _Provider = class {
|
|
4847
5045
|
headers
|
4848
5046
|
};
|
4849
5047
|
this.operations = this.createOperations();
|
4850
|
-
const { resourceCacheTTL } = this.options;
|
5048
|
+
const { resourceCacheTTL, cache: cache2 } = this.options;
|
5049
|
+
if (cache2) {
|
5050
|
+
const { consensusParametersTimestamp, chain, nodeInfo } = deserializeProviderCache(cache2);
|
5051
|
+
this.consensusParametersTimestamp = consensusParametersTimestamp;
|
5052
|
+
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
5053
|
+
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
5054
|
+
}
|
4851
5055
|
if ((0, import_utils30.isDefined)(resourceCacheTTL)) {
|
4852
5056
|
if (resourceCacheTTL !== -1) {
|
4853
5057
|
this.cache = new ResourceCache(resourceCacheTTL);
|
@@ -4906,7 +5110,8 @@ var _Provider = class {
|
|
4906
5110
|
* Initialize Provider async stuff
|
4907
5111
|
*/
|
4908
5112
|
async init() {
|
4909
|
-
await this.fetchChainAndNodeInfo();
|
5113
|
+
const { nodeInfo } = await this.fetchChainAndNodeInfo();
|
5114
|
+
this.setupFeatures(nodeInfo.nodeVersion);
|
4910
5115
|
return this;
|
4911
5116
|
}
|
4912
5117
|
/**
|
@@ -4977,15 +5182,9 @@ var _Provider = class {
|
|
4977
5182
|
}
|
4978
5183
|
} catch (_err) {
|
4979
5184
|
const data = await this.operations.getChainAndNodeInfo();
|
4980
|
-
nodeInfo =
|
4981
|
-
maxDepth: (0, import_math19.bn)(data.nodeInfo.maxDepth),
|
4982
|
-
maxTx: (0, import_math19.bn)(data.nodeInfo.maxTx),
|
4983
|
-
nodeVersion: data.nodeInfo.nodeVersion,
|
4984
|
-
utxoValidation: data.nodeInfo.utxoValidation,
|
4985
|
-
vmBacktrace: data.nodeInfo.vmBacktrace
|
4986
|
-
};
|
5185
|
+
nodeInfo = deserializeNodeInfo(data.nodeInfo);
|
4987
5186
|
_Provider.setIncompatibleNodeVersionMessage(nodeInfo);
|
4988
|
-
chain =
|
5187
|
+
chain = deserializeChain(data.chain);
|
4989
5188
|
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
4990
5189
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
4991
5190
|
this.consensusParametersTimestamp = Date.now();
|
@@ -5063,6 +5262,15 @@ var _Provider = class {
|
|
5063
5262
|
});
|
5064
5263
|
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
5065
5264
|
}
|
5265
|
+
/**
|
5266
|
+
* @hidden
|
5267
|
+
*/
|
5268
|
+
setupFeatures(nodeVersion) {
|
5269
|
+
if ((0, import_versions.gte)(nodeVersion, "0.41.0")) {
|
5270
|
+
this.features.balancePagination = true;
|
5271
|
+
this.features.amount128 = true;
|
5272
|
+
}
|
5273
|
+
}
|
5066
5274
|
/**
|
5067
5275
|
* Returns the version of the connected node.
|
5068
5276
|
*
|
@@ -5094,13 +5302,7 @@ var _Provider = class {
|
|
5094
5302
|
*/
|
5095
5303
|
async fetchNode() {
|
5096
5304
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
5097
|
-
const processedNodeInfo =
|
5098
|
-
maxDepth: (0, import_math19.bn)(nodeInfo.maxDepth),
|
5099
|
-
maxTx: (0, import_math19.bn)(nodeInfo.maxTx),
|
5100
|
-
nodeVersion: nodeInfo.nodeVersion,
|
5101
|
-
utxoValidation: nodeInfo.utxoValidation,
|
5102
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
5103
|
-
};
|
5305
|
+
const processedNodeInfo = deserializeNodeInfo(nodeInfo);
|
5104
5306
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = processedNodeInfo;
|
5105
5307
|
return processedNodeInfo;
|
5106
5308
|
}
|
@@ -5111,7 +5313,7 @@ var _Provider = class {
|
|
5111
5313
|
*/
|
5112
5314
|
async fetchChain() {
|
5113
5315
|
const { chain } = await this.operations.getChain();
|
5114
|
-
const processedChain =
|
5316
|
+
const processedChain = deserializeChain(chain);
|
5115
5317
|
_Provider.chainInfoCache[this.urlWithoutAuth] = processedChain;
|
5116
5318
|
return processedChain;
|
5117
5319
|
}
|
@@ -5138,6 +5340,21 @@ var _Provider = class {
|
|
5138
5340
|
} = all;
|
5139
5341
|
return baseAssetId;
|
5140
5342
|
}
|
5343
|
+
/**
|
5344
|
+
* Retrieves the details of an asset given its ID.
|
5345
|
+
*
|
5346
|
+
* @param assetId - The unique identifier of the asset.
|
5347
|
+
* @returns A promise that resolves to an object containing the asset details.
|
5348
|
+
*/
|
5349
|
+
async getAssetDetails(assetId) {
|
5350
|
+
const { assetDetails } = await this.operations.getAssetDetails({ assetId });
|
5351
|
+
const { contractId, subId, totalSupply } = assetDetails;
|
5352
|
+
return {
|
5353
|
+
subId,
|
5354
|
+
contractId,
|
5355
|
+
totalSupply: (0, import_math19.bn)(totalSupply)
|
5356
|
+
};
|
5357
|
+
}
|
5141
5358
|
/**
|
5142
5359
|
* @hidden
|
5143
5360
|
*/
|
@@ -5212,22 +5429,20 @@ var _Provider = class {
|
|
5212
5429
|
utxoValidation: utxoValidation || false
|
5213
5430
|
});
|
5214
5431
|
const [{ receipts: rawReceipts, status: dryRunStatus }] = dryRunStatuses;
|
5215
|
-
const receipts = rawReceipts.map(
|
5432
|
+
const receipts = rawReceipts.map(deserializeReceipt);
|
5216
5433
|
return { receipts, dryRunStatus };
|
5217
5434
|
}
|
5218
5435
|
/**
|
5219
|
-
*
|
5436
|
+
* Estimates the gas usage for predicates in a transaction request.
|
5220
5437
|
*
|
5221
5438
|
* @template T - The type of the transaction request object.
|
5222
5439
|
*
|
5223
|
-
* @param transactionRequest - The transaction request
|
5224
|
-
* @returns A promise that resolves to the
|
5440
|
+
* @param transactionRequest - The transaction request to estimate predicates for.
|
5441
|
+
* @returns A promise that resolves to the updated transaction request with estimated gas usage for predicates.
|
5225
5442
|
*/
|
5226
5443
|
async estimatePredicates(transactionRequest) {
|
5227
|
-
const shouldEstimatePredicates =
|
5228
|
-
|
5229
|
-
(input) => "predicate" in input && input.predicate && !(0, import_utils31.equalBytes)((0, import_utils30.arrayify)(input.predicate), (0, import_utils30.arrayify)("0x")) && new import_math19.BN(input.predicateGasUsed).isZero()
|
5230
|
-
)
|
5444
|
+
const shouldEstimatePredicates = transactionRequest.inputs.some(
|
5445
|
+
(input) => isPredicate(input) && (0, import_math19.bn)(input.predicateGasUsed).isZero()
|
5231
5446
|
);
|
5232
5447
|
if (!shouldEstimatePredicates) {
|
5233
5448
|
return transactionRequest;
|
@@ -5236,18 +5451,42 @@ var _Provider = class {
|
|
5236
5451
|
const response = await this.operations.estimatePredicates({
|
5237
5452
|
encodedTransaction
|
5238
5453
|
});
|
5239
|
-
const {
|
5240
|
-
|
5241
|
-
|
5242
|
-
|
5243
|
-
|
5244
|
-
if ("predicateGasUsed" in input && (0, import_math19.bn)(input.predicateGasUsed).gt(0)) {
|
5245
|
-
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
5246
|
-
}
|
5247
|
-
});
|
5248
|
-
}
|
5454
|
+
const { estimatePredicates } = response;
|
5455
|
+
transactionRequest = this.parseEstimatePredicatesResponse(
|
5456
|
+
transactionRequest,
|
5457
|
+
estimatePredicates
|
5458
|
+
);
|
5249
5459
|
return transactionRequest;
|
5250
5460
|
}
|
5461
|
+
/**
|
5462
|
+
* Estimates the gas price and predicates for a given transaction request and block horizon.
|
5463
|
+
*
|
5464
|
+
* @param transactionRequest - The transaction request to estimate predicates and gas price for.
|
5465
|
+
* @param blockHorizon - The block horizon to use for gas price estimation.
|
5466
|
+
* @returns A promise that resolves to an object containing the updated transaction
|
5467
|
+
* request and the estimated gas price.
|
5468
|
+
*/
|
5469
|
+
async estimatePredicatesAndGasPrice(transactionRequest, blockHorizon) {
|
5470
|
+
const shouldEstimatePredicates = transactionRequest.inputs.some(
|
5471
|
+
(input) => isPredicate(input) && (0, import_math19.bn)(input.predicateGasUsed).isZero()
|
5472
|
+
);
|
5473
|
+
if (!shouldEstimatePredicates) {
|
5474
|
+
const gasPrice2 = await this.estimateGasPrice(blockHorizon);
|
5475
|
+
return { transactionRequest, gasPrice: gasPrice2 };
|
5476
|
+
}
|
5477
|
+
const {
|
5478
|
+
estimateGasPrice: { gasPrice },
|
5479
|
+
estimatePredicates
|
5480
|
+
} = await this.operations.estimatePredicatesAndGasPrice({
|
5481
|
+
blockHorizon: String(blockHorizon),
|
5482
|
+
encodedTransaction: (0, import_utils30.hexlify)(transactionRequest.toTransactionBytes())
|
5483
|
+
});
|
5484
|
+
transactionRequest = this.parseEstimatePredicatesResponse(
|
5485
|
+
transactionRequest,
|
5486
|
+
estimatePredicates
|
5487
|
+
);
|
5488
|
+
return { transactionRequest, gasPrice: (0, import_math19.bn)(gasPrice) };
|
5489
|
+
}
|
5251
5490
|
/**
|
5252
5491
|
* Will dryRun a transaction and check for missing dependencies.
|
5253
5492
|
*
|
@@ -5261,11 +5500,13 @@ var _Provider = class {
|
|
5261
5500
|
async estimateTxDependencies(transactionRequest, { gasPrice: gasPriceParam } = {}) {
|
5262
5501
|
if (isTransactionTypeCreate(transactionRequest)) {
|
5263
5502
|
return {
|
5503
|
+
rawReceipts: [],
|
5264
5504
|
receipts: [],
|
5265
5505
|
outputVariables: 0,
|
5266
5506
|
missingContractIds: []
|
5267
5507
|
};
|
5268
5508
|
}
|
5509
|
+
let rawReceipts = [];
|
5269
5510
|
let receipts = [];
|
5270
5511
|
const missingContractIds = [];
|
5271
5512
|
let outputVariables = 0;
|
@@ -5274,13 +5515,14 @@ var _Provider = class {
|
|
5274
5515
|
const gasPrice = gasPriceParam ?? await this.estimateGasPrice(10);
|
5275
5516
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
5276
5517
|
const {
|
5277
|
-
dryRun: [{ receipts:
|
5518
|
+
dryRun: [{ receipts: serializedReceipts, status }]
|
5278
5519
|
} = await this.operations.dryRun({
|
5279
5520
|
encodedTransactions: [(0, import_utils30.hexlify)(transactionRequest.toTransactionBytes())],
|
5280
5521
|
utxoValidation: false,
|
5281
5522
|
gasPrice: gasPrice.toString()
|
5282
5523
|
});
|
5283
|
-
|
5524
|
+
rawReceipts = serializedReceipts;
|
5525
|
+
receipts = serializedReceipts.map(deserializeReceipt);
|
5284
5526
|
dryRunStatus = status;
|
5285
5527
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
5286
5528
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
@@ -5301,6 +5543,7 @@ var _Provider = class {
|
|
5301
5543
|
}
|
5302
5544
|
}
|
5303
5545
|
return {
|
5546
|
+
rawReceipts,
|
5304
5547
|
receipts,
|
5305
5548
|
outputVariables,
|
5306
5549
|
missingContractIds,
|
@@ -5319,6 +5562,7 @@ var _Provider = class {
|
|
5319
5562
|
*/
|
5320
5563
|
async estimateMultipleTxDependencies(transactionRequests) {
|
5321
5564
|
const results = transactionRequests.map(() => ({
|
5565
|
+
rawReceipts: [],
|
5322
5566
|
receipts: [],
|
5323
5567
|
outputVariables: 0,
|
5324
5568
|
missingContractIds: [],
|
@@ -5346,7 +5590,7 @@ var _Provider = class {
|
|
5346
5590
|
const requestIdx = transactionsToProcess[i];
|
5347
5591
|
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
5348
5592
|
const result = results[requestIdx];
|
5349
|
-
result.receipts = rawReceipts.map(
|
5593
|
+
result.receipts = rawReceipts.map(deserializeReceipt);
|
5350
5594
|
result.dryRunStatus = status;
|
5351
5595
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
5352
5596
|
result.receipts
|
@@ -5391,7 +5635,7 @@ var _Provider = class {
|
|
5391
5635
|
utxoValidation: utxoValidation || false
|
5392
5636
|
});
|
5393
5637
|
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
5394
|
-
const receipts = rawReceipts.map(
|
5638
|
+
const receipts = rawReceipts.map(deserializeReceipt);
|
5395
5639
|
return { receipts, dryRunStatus: status };
|
5396
5640
|
});
|
5397
5641
|
return results;
|
@@ -5492,7 +5736,7 @@ var _Provider = class {
|
|
5492
5736
|
});
|
5493
5737
|
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
5494
5738
|
const { id, receipts, status } = dryRunStatus;
|
5495
|
-
const processedReceipts = receipts.map(
|
5739
|
+
const processedReceipts = receipts.map(deserializeReceipt);
|
5496
5740
|
return { id, receipts: processedReceipts, status };
|
5497
5741
|
});
|
5498
5742
|
return { receipts: callResult[0].receipts };
|
@@ -5523,14 +5767,20 @@ var _Provider = class {
|
|
5523
5767
|
await signatureCallback(signedRequest);
|
5524
5768
|
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
5525
5769
|
}
|
5526
|
-
|
5770
|
+
let gasPrice;
|
5771
|
+
if (gasPriceParam) {
|
5772
|
+
gasPrice = gasPriceParam;
|
5773
|
+
await this.estimatePredicates(signedRequest);
|
5774
|
+
} else {
|
5775
|
+
({ gasPrice } = await this.estimatePredicatesAndGasPrice(signedRequest, 10));
|
5776
|
+
}
|
5527
5777
|
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
5528
|
-
const gasPrice = gasPriceParam ?? await this.estimateGasPrice(10);
|
5529
5778
|
let { maxFee, maxGas, minFee, minGas, gasLimit } = await this.estimateTxGasAndFee({
|
5530
5779
|
// Fetches and returns a gas price
|
5531
5780
|
transactionRequest: signedRequest,
|
5532
5781
|
gasPrice
|
5533
5782
|
});
|
5783
|
+
let rawReceipts = [];
|
5534
5784
|
let receipts = [];
|
5535
5785
|
let dryRunStatus;
|
5536
5786
|
let missingContractIds = [];
|
@@ -5542,7 +5792,7 @@ var _Provider = class {
|
|
5542
5792
|
if (signatureCallback) {
|
5543
5793
|
await signatureCallback(txRequestClone);
|
5544
5794
|
}
|
5545
|
-
({ receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone, { gasPrice }));
|
5795
|
+
({ rawReceipts, receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone, { gasPrice }));
|
5546
5796
|
if (dryRunStatus && "reason" in dryRunStatus) {
|
5547
5797
|
throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
|
5548
5798
|
}
|
@@ -5555,7 +5805,12 @@ var _Provider = class {
|
|
5555
5805
|
gasPrice
|
5556
5806
|
}));
|
5557
5807
|
}
|
5808
|
+
const transactionSummary = {
|
5809
|
+
gasPrice: gasPrice.toString(),
|
5810
|
+
receipts: rawReceipts
|
5811
|
+
};
|
5558
5812
|
return {
|
5813
|
+
rawReceipts,
|
5559
5814
|
receipts,
|
5560
5815
|
gasUsed,
|
5561
5816
|
gasPrice,
|
@@ -5568,7 +5823,8 @@ var _Provider = class {
|
|
5568
5823
|
addedSignatures,
|
5569
5824
|
estimatedPredicates: txRequestClone.inputs,
|
5570
5825
|
dryRunStatus,
|
5571
|
-
updateMaxFee
|
5826
|
+
updateMaxFee,
|
5827
|
+
transactionSummary
|
5572
5828
|
};
|
5573
5829
|
}
|
5574
5830
|
/**
|
@@ -5614,23 +5870,33 @@ var _Provider = class {
|
|
5614
5870
|
*/
|
5615
5871
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
5616
5872
|
const ownerAddress = new import_address4.Address(owner);
|
5617
|
-
|
5873
|
+
let idsToExclude = {
|
5618
5874
|
messages: excludedIds?.messages?.map((nonce) => (0, import_utils30.hexlify)(nonce)) || [],
|
5619
5875
|
utxos: excludedIds?.utxos?.map((id) => (0, import_utils30.hexlify)(id)) || []
|
5620
5876
|
};
|
5621
5877
|
if (this.cache) {
|
5622
|
-
const cached = this.cache.getActiveData();
|
5623
|
-
|
5624
|
-
|
5878
|
+
const cached = this.cache.getActiveData(ownerAddress.toB256());
|
5879
|
+
if (cached.utxos.length || cached.messages.length) {
|
5880
|
+
const {
|
5881
|
+
consensusParameters: {
|
5882
|
+
txParameters: { maxInputs }
|
5883
|
+
}
|
5884
|
+
} = await this.getChain();
|
5885
|
+
idsToExclude = adjustResourcesToExclude({
|
5886
|
+
userInput: idsToExclude,
|
5887
|
+
cached,
|
5888
|
+
maxInputs: maxInputs.toNumber()
|
5889
|
+
});
|
5890
|
+
}
|
5625
5891
|
}
|
5626
5892
|
const coinsQuery = {
|
5627
5893
|
owner: ownerAddress.toB256(),
|
5628
5894
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
5629
5895
|
assetId: (0, import_utils30.hexlify)(assetId),
|
5630
|
-
amount: amount.toString(10),
|
5896
|
+
amount: (amount.eqn(0) ? (0, import_math19.bn)(1) : amount).toString(10),
|
5631
5897
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
5632
5898
|
})),
|
5633
|
-
excludedIds:
|
5899
|
+
excludedIds: idsToExclude
|
5634
5900
|
};
|
5635
5901
|
const result = await this.operations.getCoinsToSpend(coinsQuery);
|
5636
5902
|
const coins = result.coinsToSpend.flat().map((coin) => {
|
@@ -5688,7 +5954,7 @@ var _Provider = class {
|
|
5688
5954
|
} = await this.operations.getLatestBlock();
|
5689
5955
|
block = latestBlock;
|
5690
5956
|
} else {
|
5691
|
-
const isblockId = typeof idOrHeight === "string" && idOrHeight
|
5957
|
+
const isblockId = typeof idOrHeight === "string" && (0, import_address4.isB256)(idOrHeight);
|
5692
5958
|
const variables = isblockId ? { blockId: idOrHeight } : { height: (0, import_math19.bn)(idOrHeight).toString(10) };
|
5693
5959
|
const response = await this.operations.getBlock(variables);
|
5694
5960
|
block = response.block;
|
@@ -5759,8 +6025,10 @@ var _Provider = class {
|
|
5759
6025
|
variables = { blockHeight: (0, import_math19.bn)(idOrHeight).toString(10) };
|
5760
6026
|
} else if (idOrHeight === "latest") {
|
5761
6027
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
5762
|
-
} else {
|
6028
|
+
} else if (typeof idOrHeight === "string" && (0, import_address4.isB256)(idOrHeight)) {
|
5763
6029
|
variables = { blockId: idOrHeight };
|
6030
|
+
} else {
|
6031
|
+
variables = { blockHeight: (0, import_math19.bn)(idOrHeight).toString() };
|
5764
6032
|
}
|
5765
6033
|
const { block } = await this.operations.getBlockWithTransactions(variables);
|
5766
6034
|
if (!block) {
|
@@ -5782,7 +6050,7 @@ var _Provider = class {
|
|
5782
6050
|
},
|
5783
6051
|
transactionIds: block.transactions.map((tx) => tx.id),
|
5784
6052
|
transactions: block.transactions.map(
|
5785
|
-
(tx) => new
|
6053
|
+
(tx) => new import_transactions23.TransactionCoder().decode((0, import_utils30.arrayify)(tx.rawPayload), 0)?.[0]
|
5786
6054
|
)
|
5787
6055
|
};
|
5788
6056
|
}
|
@@ -5798,7 +6066,7 @@ var _Provider = class {
|
|
5798
6066
|
return null;
|
5799
6067
|
}
|
5800
6068
|
try {
|
5801
|
-
return new
|
6069
|
+
return new import_transactions23.TransactionCoder().decode(
|
5802
6070
|
(0, import_utils30.arrayify)(transaction.rawPayload),
|
5803
6071
|
0
|
5804
6072
|
)?.[0];
|
@@ -5824,7 +6092,7 @@ var _Provider = class {
|
|
5824
6092
|
paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
|
5825
6093
|
})
|
5826
6094
|
});
|
5827
|
-
const coder = new
|
6095
|
+
const coder = new import_transactions23.TransactionCoder();
|
5828
6096
|
const transactions = edges.map(({ node: { rawPayload } }) => {
|
5829
6097
|
try {
|
5830
6098
|
return coder.decode((0, import_utils30.arrayify)(rawPayload), 0)[0];
|
@@ -5888,11 +6156,20 @@ var _Provider = class {
|
|
5888
6156
|
* @returns A promise that resolves to the balance.
|
5889
6157
|
*/
|
5890
6158
|
async getBalance(owner, assetId) {
|
5891
|
-
const
|
5892
|
-
|
5893
|
-
|
6159
|
+
const ownerStr = new import_address4.Address(owner).toB256();
|
6160
|
+
const assetIdStr = (0, import_utils30.hexlify)(assetId);
|
6161
|
+
if (!this.features.amount128) {
|
6162
|
+
const { balance: balance2 } = await this.operations.getBalance({
|
6163
|
+
owner: ownerStr,
|
6164
|
+
assetId: assetIdStr
|
6165
|
+
});
|
6166
|
+
return (0, import_math19.bn)(balance2.amount, 10);
|
6167
|
+
}
|
6168
|
+
const { balance } = await this.operations.getBalanceV2({
|
6169
|
+
owner: ownerStr,
|
6170
|
+
assetId: assetIdStr
|
5894
6171
|
});
|
5895
|
-
return (0, import_math19.bn)(balance.
|
6172
|
+
return (0, import_math19.bn)(balance.amountU128, 10);
|
5896
6173
|
}
|
5897
6174
|
/**
|
5898
6175
|
* Returns balances for the given owner.
|
@@ -5901,7 +6178,16 @@ var _Provider = class {
|
|
5901
6178
|
* @param paginationArgs - Pagination arguments (optional).
|
5902
6179
|
* @returns A promise that resolves to the balances.
|
5903
6180
|
*/
|
5904
|
-
async getBalances(owner) {
|
6181
|
+
async getBalances(owner, paginationArgs) {
|
6182
|
+
if (!this.features.balancePagination) {
|
6183
|
+
return this.getBalancesV1(owner, paginationArgs);
|
6184
|
+
}
|
6185
|
+
return this.getBalancesV2(owner, paginationArgs);
|
6186
|
+
}
|
6187
|
+
/**
|
6188
|
+
* @hidden
|
6189
|
+
*/
|
6190
|
+
async getBalancesV1(owner, _paginationArgs) {
|
5905
6191
|
const {
|
5906
6192
|
balances: { edges }
|
5907
6193
|
} = await this.operations.getBalances({
|
@@ -5918,6 +6204,25 @@ var _Provider = class {
|
|
5918
6204
|
}));
|
5919
6205
|
return { balances };
|
5920
6206
|
}
|
6207
|
+
/**
|
6208
|
+
* @hidden
|
6209
|
+
*/
|
6210
|
+
async getBalancesV2(owner, paginationArgs) {
|
6211
|
+
const {
|
6212
|
+
balances: { edges, pageInfo }
|
6213
|
+
} = await this.operations.getBalancesV2({
|
6214
|
+
...validatePaginationArgs({
|
6215
|
+
inputArgs: paginationArgs,
|
6216
|
+
paginationLimit: BALANCES_PAGE_SIZE_LIMIT
|
6217
|
+
}),
|
6218
|
+
filter: { owner: new import_address4.Address(owner).toB256() }
|
6219
|
+
});
|
6220
|
+
const balances = edges.map(({ node }) => ({
|
6221
|
+
assetId: node.assetId,
|
6222
|
+
amount: (0, import_math19.bn)(node.amountU128)
|
6223
|
+
}));
|
6224
|
+
return { balances, pageInfo };
|
6225
|
+
}
|
5921
6226
|
/**
|
5922
6227
|
* Returns message for the given address.
|
5923
6228
|
*
|
@@ -5936,7 +6241,7 @@ var _Provider = class {
|
|
5936
6241
|
owner: new import_address4.Address(address).toB256()
|
5937
6242
|
});
|
5938
6243
|
const messages = edges.map(({ node }) => ({
|
5939
|
-
messageId:
|
6244
|
+
messageId: import_transactions23.InputMessageCoder.getMessageId({
|
5940
6245
|
sender: node.sender,
|
5941
6246
|
recipient: node.recipient,
|
5942
6247
|
nonce: node.nonce,
|
@@ -5947,7 +6252,7 @@ var _Provider = class {
|
|
5947
6252
|
recipient: new import_address4.Address(node.recipient),
|
5948
6253
|
nonce: node.nonce,
|
5949
6254
|
amount: (0, import_math19.bn)(node.amount),
|
5950
|
-
data:
|
6255
|
+
data: import_transactions23.InputMessageCoder.decodeData(node.data),
|
5951
6256
|
daHeight: (0, import_math19.bn)(node.daHeight)
|
5952
6257
|
}));
|
5953
6258
|
return {
|
@@ -5984,15 +6289,12 @@ var _Provider = class {
|
|
5984
6289
|
if (commitBlockHeight) {
|
5985
6290
|
inputObject = {
|
5986
6291
|
...inputObject,
|
5987
|
-
//
|
5988
|
-
// This should
|
6292
|
+
// Convert BN into a number string required on the query
|
6293
|
+
// This should probably be fixed on the fuel client side
|
5989
6294
|
commitBlockHeight: commitBlockHeight.toNumber().toString()
|
5990
6295
|
};
|
5991
6296
|
}
|
5992
6297
|
const result = await this.operations.getMessageProof(inputObject);
|
5993
|
-
if (!result.messageProof) {
|
5994
|
-
return null;
|
5995
|
-
}
|
5996
6298
|
const {
|
5997
6299
|
messageProof,
|
5998
6300
|
messageBlockHeader,
|
@@ -6101,16 +6403,15 @@ var _Provider = class {
|
|
6101
6403
|
* @returns A promise that resolves to the result of the check.
|
6102
6404
|
*/
|
6103
6405
|
async isUserAccount(id) {
|
6104
|
-
const
|
6105
|
-
|
6106
|
-
contractId: id,
|
6107
|
-
transactionId: id
|
6108
|
-
});
|
6109
|
-
if (contract || blob || transaction) {
|
6110
|
-
return false;
|
6111
|
-
}
|
6112
|
-
return true;
|
6406
|
+
const type = await this.getAddressType(id);
|
6407
|
+
return type === "Account";
|
6113
6408
|
}
|
6409
|
+
/**
|
6410
|
+
* Determines the type of address based on the provided ID.
|
6411
|
+
*
|
6412
|
+
* @param id - The ID to be checked.
|
6413
|
+
* @returns A promise that resolves to a string indicating the type of address.
|
6414
|
+
*/
|
6114
6415
|
async getAddressType(id) {
|
6115
6416
|
const { contract, blob, transaction } = await this.operations.isUserAccount({
|
6116
6417
|
blobId: id,
|
@@ -6126,6 +6427,13 @@ var _Provider = class {
|
|
6126
6427
|
if (transaction) {
|
6127
6428
|
return "Transaction";
|
6128
6429
|
}
|
6430
|
+
try {
|
6431
|
+
const asset = await this.getAssetDetails(id);
|
6432
|
+
if (asset) {
|
6433
|
+
return "Asset";
|
6434
|
+
}
|
6435
|
+
} catch (e) {
|
6436
|
+
}
|
6129
6437
|
return "Account";
|
6130
6438
|
}
|
6131
6439
|
/**
|
@@ -6150,7 +6458,7 @@ var _Provider = class {
|
|
6150
6458
|
return null;
|
6151
6459
|
}
|
6152
6460
|
const message = {
|
6153
|
-
messageId:
|
6461
|
+
messageId: import_transactions23.InputMessageCoder.getMessageId({
|
6154
6462
|
sender: rawMessage.sender,
|
6155
6463
|
recipient: rawMessage.recipient,
|
6156
6464
|
nonce,
|
@@ -6161,7 +6469,7 @@ var _Provider = class {
|
|
6161
6469
|
recipient: new import_address4.Address(rawMessage.recipient),
|
6162
6470
|
nonce,
|
6163
6471
|
amount: (0, import_math19.bn)(rawMessage.amount),
|
6164
|
-
data:
|
6472
|
+
data: import_transactions23.InputMessageCoder.decodeData(rawMessage.data),
|
6165
6473
|
daHeight: (0, import_math19.bn)(rawMessage.daHeight)
|
6166
6474
|
};
|
6167
6475
|
return message;
|
@@ -6200,6 +6508,19 @@ var _Provider = class {
|
|
6200
6508
|
statusReason: status.reason
|
6201
6509
|
});
|
6202
6510
|
}
|
6511
|
+
/**
|
6512
|
+
* @hidden
|
6513
|
+
*/
|
6514
|
+
parseEstimatePredicatesResponse(transactionRequest, { inputs }) {
|
6515
|
+
if (inputs) {
|
6516
|
+
inputs.forEach((input, i) => {
|
6517
|
+
if (input && "predicateGasUsed" in input && (0, import_math19.bn)(input.predicateGasUsed).gt(0)) {
|
6518
|
+
transactionRequest.inputs[i].predicateGasUsed = input.predicateGasUsed;
|
6519
|
+
}
|
6520
|
+
});
|
6521
|
+
}
|
6522
|
+
return transactionRequest;
|
6523
|
+
}
|
6203
6524
|
};
|
6204
6525
|
var Provider = _Provider;
|
6205
6526
|
_cacheInputs = new WeakSet();
|
@@ -6207,18 +6528,7 @@ cacheInputs_fn = function(inputs, transactionId) {
|
|
6207
6528
|
if (!this.cache) {
|
6208
6529
|
return;
|
6209
6530
|
}
|
6210
|
-
|
6211
|
-
(acc, input) => {
|
6212
|
-
if (input.type === import_transactions22.InputType.Coin) {
|
6213
|
-
acc.utxos.push(input.id);
|
6214
|
-
} else if (input.type === import_transactions22.InputType.Message) {
|
6215
|
-
acc.messages.push(input.nonce);
|
6216
|
-
}
|
6217
|
-
return acc;
|
6218
|
-
},
|
6219
|
-
{ utxos: [], messages: [] }
|
6220
|
-
);
|
6221
|
-
this.cache.set(transactionId, inputsToCache);
|
6531
|
+
this.cache.set(transactionId, inputs);
|
6222
6532
|
};
|
6223
6533
|
/** @hidden */
|
6224
6534
|
__publicField(Provider, "chainInfoCache", {});
|
@@ -6230,7 +6540,12 @@ __publicField(Provider, "incompatibleNodeVersionMessage", "");
|
|
6230
6540
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
6231
6541
|
var import_errors21 = require("@fuel-ts/errors");
|
6232
6542
|
var import_math20 = require("@fuel-ts/math");
|
6233
|
-
var
|
6543
|
+
var import_transactions24 = require("@fuel-ts/transactions");
|
6544
|
+
var import_utils32 = require("@fuel-ts/utils");
|
6545
|
+
|
6546
|
+
// src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
|
6547
|
+
var import_math21 = require("@fuel-ts/math");
|
6548
|
+
var import_transactions25 = require("@fuel-ts/transactions");
|
6234
6549
|
var import_utils33 = require("@fuel-ts/utils");
|
6235
6550
|
|
6236
6551
|
// src/test-utils/test-asset-id.ts
|
@@ -6259,7 +6574,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
6259
6574
|
// src/test-utils/wallet-config.ts
|
6260
6575
|
var import_crypto9 = require("@fuel-ts/crypto");
|
6261
6576
|
var import_errors27 = require("@fuel-ts/errors");
|
6262
|
-
var
|
6577
|
+
var import_math24 = require("@fuel-ts/math");
|
6263
6578
|
var import_utils43 = require("@fuel-ts/utils");
|
6264
6579
|
|
6265
6580
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -6267,12 +6582,12 @@ var import_hasher4 = require("@fuel-ts/hasher");
|
|
6267
6582
|
var import_utils38 = require("@fuel-ts/utils");
|
6268
6583
|
|
6269
6584
|
// src/account.ts
|
6270
|
-
var
|
6585
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
6271
6586
|
var import_address6 = require("@fuel-ts/address");
|
6272
6587
|
var import_crypto5 = require("@fuel-ts/crypto");
|
6273
6588
|
var import_errors22 = require("@fuel-ts/errors");
|
6274
|
-
var
|
6275
|
-
var
|
6589
|
+
var import_math22 = require("@fuel-ts/math");
|
6590
|
+
var import_transactions26 = require("@fuel-ts/transactions");
|
6276
6591
|
var import_utils36 = require("@fuel-ts/utils");
|
6277
6592
|
var import_ramda9 = require("ramda");
|
6278
6593
|
|
@@ -6295,12 +6610,12 @@ var AbstractAccount = class {
|
|
6295
6610
|
};
|
6296
6611
|
|
6297
6612
|
// src/utils/formatTransferToContractScriptData.ts
|
6298
|
-
var
|
6613
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
6299
6614
|
var import_address5 = require("@fuel-ts/address");
|
6300
6615
|
var import_utils35 = require("@fuel-ts/utils");
|
6301
6616
|
var asm = __toESM(require("@fuels/vm-asm"));
|
6302
6617
|
var formatTransferToContractScriptData = (transferParams) => {
|
6303
|
-
const numberCoder = new
|
6618
|
+
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
6304
6619
|
return transferParams.reduce((acc, transferParam) => {
|
6305
6620
|
const { assetId, amount, contractId } = transferParam;
|
6306
6621
|
const encoded = numberCoder.encode(amount);
|
@@ -6313,7 +6628,7 @@ var assembleTransferToContractScript = async (transferParams) => {
|
|
6313
6628
|
await asm.initWasm();
|
6314
6629
|
let script = new Uint8Array();
|
6315
6630
|
transferParams.forEach((_, i) => {
|
6316
|
-
const offset = (
|
6631
|
+
const offset = (import_abi_coder6.CONTRACT_ID_LEN + import_abi_coder6.WORD_SIZE + import_abi_coder6.ASSET_ID_LEN) * i;
|
6317
6632
|
script = (0, import_utils35.concat)([
|
6318
6633
|
script,
|
6319
6634
|
// Load ScriptData into register 0x10.
|
@@ -6321,11 +6636,11 @@ var assembleTransferToContractScript = async (transferParams) => {
|
|
6321
6636
|
// Add the offset to 0x10 so it will point to the current contract ID, store in 0x11.
|
6322
6637
|
asm.addi(17, 16, offset).to_bytes(),
|
6323
6638
|
// Add CONTRACT_ID_LEN to 0x11 to point to the amount in the ScriptData, store in 0x12.
|
6324
|
-
asm.addi(18, 17,
|
6639
|
+
asm.addi(18, 17, import_abi_coder6.CONTRACT_ID_LEN).to_bytes(),
|
6325
6640
|
// Load word to the amount at 0x12 into register 0x13.
|
6326
6641
|
asm.lw(19, 18, 0).to_bytes(),
|
6327
6642
|
// Add WORD_SIZE to 0x12 to point to the asset ID in the ScriptData, store in 0x14.
|
6328
|
-
asm.addi(20, 18,
|
6643
|
+
asm.addi(20, 18, import_abi_coder6.WORD_SIZE).to_bytes(),
|
6329
6644
|
// Perform the transfer using contract ID in 0x11, amount in 0x13, and asset ID in 0x14.
|
6330
6645
|
asm.tr(17, 19, 20).to_bytes()
|
6331
6646
|
]);
|
@@ -6448,12 +6763,20 @@ var Account = class extends AbstractAccount {
|
|
6448
6763
|
* @returns A promise that resolves to the funded transaction request.
|
6449
6764
|
*/
|
6450
6765
|
async fund(request, params) {
|
6451
|
-
const {
|
6766
|
+
const {
|
6767
|
+
addedSignatures,
|
6768
|
+
estimatedPredicates,
|
6769
|
+
requiredQuantities,
|
6770
|
+
updateMaxFee,
|
6771
|
+
gasPrice,
|
6772
|
+
transactionSummary
|
6773
|
+
} = params;
|
6774
|
+
const chainId = await this.provider.getChainId();
|
6452
6775
|
const fee = request.maxFee;
|
6453
6776
|
const baseAssetId = await this.provider.getBaseAssetId();
|
6454
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0,
|
6777
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math22.bn)(0);
|
6455
6778
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
6456
|
-
amount: (0,
|
6779
|
+
amount: (0, import_math22.bn)(fee),
|
6457
6780
|
assetId: baseAssetId,
|
6458
6781
|
coinQuantities: requiredQuantities
|
6459
6782
|
});
|
@@ -6461,7 +6784,7 @@ var Account = class extends AbstractAccount {
|
|
6461
6784
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
6462
6785
|
quantitiesDict[assetId] = {
|
6463
6786
|
required: amount,
|
6464
|
-
owned: (0,
|
6787
|
+
owned: (0, import_math22.bn)(0)
|
6465
6788
|
};
|
6466
6789
|
});
|
6467
6790
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -6523,10 +6846,11 @@ var Account = class extends AbstractAccount {
|
|
6523
6846
|
}
|
6524
6847
|
if (needsToBeFunded) {
|
6525
6848
|
throw new import_errors22.FuelError(
|
6526
|
-
import_errors22.ErrorCode.
|
6849
|
+
import_errors22.ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
|
6527
6850
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
6528
6851
|
);
|
6529
6852
|
}
|
6853
|
+
request.updateState(chainId, "funded", transactionSummary);
|
6530
6854
|
await this.provider.validateTransaction(request);
|
6531
6855
|
request.updatePredicateGasUsed(estimatedPredicates);
|
6532
6856
|
const requestToReestimate = (0, import_ramda9.clone)(request);
|
@@ -6637,7 +6961,7 @@ var Account = class extends AbstractAccount {
|
|
6637
6961
|
const quantities = [];
|
6638
6962
|
const defaultAssetId = await this.provider.getBaseAssetId();
|
6639
6963
|
const transferParams = contractTransferParams.map((transferParam) => {
|
6640
|
-
const amount = (0,
|
6964
|
+
const amount = (0, import_math22.bn)(transferParam.amount);
|
6641
6965
|
const contractAddress = new import_address6.Address(transferParam.contractId);
|
6642
6966
|
const assetId = transferParam.assetId ? (0, import_utils36.hexlify)(transferParam.assetId) : defaultAssetId;
|
6643
6967
|
if (amount.lte(0)) {
|
@@ -6674,7 +6998,7 @@ var Account = class extends AbstractAccount {
|
|
6674
6998
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
6675
6999
|
);
|
6676
7000
|
const amountDataArray = (0, import_utils36.arrayify)(
|
6677
|
-
"0x".concat((0,
|
7001
|
+
"0x".concat((0, import_math22.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
6678
7002
|
);
|
6679
7003
|
const script = new Uint8Array([
|
6680
7004
|
...(0, import_utils36.arrayify)(withdrawScript.bytes),
|
@@ -6684,7 +7008,7 @@ var Account = class extends AbstractAccount {
|
|
6684
7008
|
const params = { script, ...txParams };
|
6685
7009
|
const baseAssetId = await this.provider.getBaseAssetId();
|
6686
7010
|
let request = new ScriptTransactionRequest(params);
|
6687
|
-
const quantities = [{ amount: (0,
|
7011
|
+
const quantities = [{ amount: (0, import_math22.bn)(amount), assetId: baseAssetId }];
|
6688
7012
|
const txCost = await this.getTransactionCost(request, { quantities });
|
6689
7013
|
request = this.validateGasLimitAndMaxFee({
|
6690
7014
|
transactionRequest: request,
|
@@ -6710,9 +7034,9 @@ var Account = class extends AbstractAccount {
|
|
6710
7034
|
const baseAssetId = await this.provider.getBaseAssetId();
|
6711
7035
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
6712
7036
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
6713
|
-
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0,
|
7037
|
+
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math22.bn)("100000000000000000") }];
|
6714
7038
|
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
6715
|
-
if (input.type ===
|
7039
|
+
if (input.type === import_transactions26.InputType.Coin) {
|
6716
7040
|
return input.assetId === assetId;
|
6717
7041
|
}
|
6718
7042
|
if (isRequestInputMessageWithoutData(input)) {
|
@@ -6784,16 +7108,28 @@ var Account = class extends AbstractAccount {
|
|
6784
7108
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
6785
7109
|
* @returns A promise that resolves to the transaction response.
|
6786
7110
|
*/
|
6787
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true,
|
7111
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, ...connectorOptions } = {}) {
|
7112
|
+
let transactionRequest = transactionRequestify(transactionRequestLike);
|
6788
7113
|
if (this._connector) {
|
6789
|
-
|
6790
|
-
|
6791
|
-
|
6792
|
-
|
6793
|
-
|
7114
|
+
const { onBeforeSend, skipCustomFee = false } = connectorOptions;
|
7115
|
+
transactionRequest = await this.prepareTransactionForSend(transactionRequest);
|
7116
|
+
const params = {
|
7117
|
+
onBeforeSend,
|
7118
|
+
skipCustomFee,
|
7119
|
+
provider: {
|
7120
|
+
url: this.provider.url,
|
7121
|
+
cache: await serializeProviderCache(this.provider)
|
7122
|
+
},
|
7123
|
+
transactionState: transactionRequest.flag.state,
|
7124
|
+
transactionSummary: await this.prepareTransactionSummary(transactionRequest)
|
7125
|
+
};
|
7126
|
+
const transaction = await this._connector.sendTransaction(
|
7127
|
+
this.address.toString(),
|
7128
|
+
transactionRequest,
|
7129
|
+
params
|
6794
7130
|
);
|
7131
|
+
return typeof transaction === "string" ? this.provider.getTransactionResponse(transaction) : transaction;
|
6795
7132
|
}
|
6796
|
-
const transactionRequest = transactionRequestify(transactionRequestLike);
|
6797
7133
|
if (estimateTxDependencies) {
|
6798
7134
|
await this.provider.estimateTxDependencies(transactionRequest);
|
6799
7135
|
}
|
@@ -6823,16 +7159,38 @@ var Account = class extends AbstractAccount {
|
|
6823
7159
|
*/
|
6824
7160
|
generateFakeResources(coins) {
|
6825
7161
|
return coins.map((coin) => ({
|
6826
|
-
id: (0, import_utils36.hexlify)((0, import_crypto5.randomBytes)(
|
7162
|
+
id: (0, import_utils36.hexlify)((0, import_crypto5.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
6827
7163
|
owner: this.address,
|
6828
|
-
blockCreated: (0,
|
6829
|
-
txCreatedIdx: (0,
|
7164
|
+
blockCreated: (0, import_math22.bn)(1),
|
7165
|
+
txCreatedIdx: (0, import_math22.bn)(1),
|
6830
7166
|
...coin
|
6831
7167
|
}));
|
6832
7168
|
}
|
7169
|
+
/** @hidden */
|
7170
|
+
async prepareTransactionForSend(request) {
|
7171
|
+
const { transactionId } = request.flag;
|
7172
|
+
if (!(0, import_utils36.isDefined)(transactionId)) {
|
7173
|
+
return request;
|
7174
|
+
}
|
7175
|
+
const chainId = await this.provider.getChainId();
|
7176
|
+
const currentTransactionId = request.getTransactionId(chainId);
|
7177
|
+
if (transactionId !== currentTransactionId) {
|
7178
|
+
request.updateState(chainId);
|
7179
|
+
}
|
7180
|
+
return request;
|
7181
|
+
}
|
7182
|
+
/** @hidden */
|
7183
|
+
async prepareTransactionSummary(request) {
|
7184
|
+
const chainId = await this.provider.getChainId();
|
7185
|
+
return (0, import_utils36.isDefined)(request.flag.summary) ? {
|
7186
|
+
...request.flag.summary,
|
7187
|
+
id: request.getTransactionId(chainId),
|
7188
|
+
transactionBytes: (0, import_utils36.hexlify)(request.toTransactionBytes())
|
7189
|
+
} : void 0;
|
7190
|
+
}
|
6833
7191
|
/** @hidden * */
|
6834
7192
|
validateTransferAmount(amount) {
|
6835
|
-
if ((0,
|
7193
|
+
if ((0, import_math22.bn)(amount).lte(0)) {
|
6836
7194
|
throw new import_errors22.FuelError(
|
6837
7195
|
import_errors22.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
6838
7196
|
"Transfer amount must be a positive number."
|
@@ -7098,7 +7456,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
7098
7456
|
var import_crypto8 = require("@fuel-ts/crypto");
|
7099
7457
|
var import_errors26 = require("@fuel-ts/errors");
|
7100
7458
|
var import_hasher7 = require("@fuel-ts/hasher");
|
7101
|
-
var
|
7459
|
+
var import_math23 = require("@fuel-ts/math");
|
7102
7460
|
var import_utils42 = require("@fuel-ts/utils");
|
7103
7461
|
|
7104
7462
|
// src/mnemonic/mnemonic.ts
|
@@ -9524,13 +9882,13 @@ var HDWallet = class {
|
|
9524
9882
|
} else {
|
9525
9883
|
data.set((0, import_utils42.arrayify)(this.publicKey));
|
9526
9884
|
}
|
9527
|
-
data.set((0,
|
9885
|
+
data.set((0, import_math23.toBytes)(index, 4), 33);
|
9528
9886
|
const bytes = (0, import_utils42.arrayify)((0, import_crypto8.computeHmac)("sha512", chainCode, data));
|
9529
9887
|
const IL = bytes.slice(0, 32);
|
9530
9888
|
const IR = bytes.slice(32);
|
9531
9889
|
if (privateKey) {
|
9532
9890
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
9533
|
-
const ki = (0,
|
9891
|
+
const ki = (0, import_math23.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
9534
9892
|
return new HDWallet({
|
9535
9893
|
privateKey: ki,
|
9536
9894
|
chainCode: IR,
|
@@ -9576,7 +9934,7 @@ var HDWallet = class {
|
|
9576
9934
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
9577
9935
|
const depth = (0, import_utils42.hexlify)(Uint8Array.from([this.depth]));
|
9578
9936
|
const parentFingerprint = this.parentFingerprint;
|
9579
|
-
const index = (0,
|
9937
|
+
const index = (0, import_math23.toHex)(this.index, 4);
|
9580
9938
|
const chainCode = this.chainCode;
|
9581
9939
|
const key = this.privateKey != null && !isPublic ? (0, import_utils42.concat)(["0x00", this.privateKey]) : this.publicKey;
|
9582
9940
|
const extendedKey = (0, import_utils42.arrayify)((0, import_utils42.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
@@ -9596,7 +9954,7 @@ var HDWallet = class {
|
|
9596
9954
|
});
|
9597
9955
|
}
|
9598
9956
|
static fromExtendedKey(extendedKey) {
|
9599
|
-
const decoded = (0, import_utils42.hexlify)((0,
|
9957
|
+
const decoded = (0, import_utils42.hexlify)((0, import_math23.toBytes)((0, import_utils42.decodeBase58)(extendedKey)));
|
9600
9958
|
const bytes = (0, import_utils42.arrayify)(decoded);
|
9601
9959
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
9602
9960
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
@@ -9853,7 +10211,7 @@ var WalletsConfig = class {
|
|
9853
10211
|
assetIds.forEach((assetId) => {
|
9854
10212
|
for (let index = 0; index < coinsPerAsset; index++) {
|
9855
10213
|
coins.push({
|
9856
|
-
amount: (0,
|
10214
|
+
amount: (0, import_math24.bn)(amountPerCoin).toString(),
|
9857
10215
|
asset_id: assetId,
|
9858
10216
|
owner: walletAddress,
|
9859
10217
|
tx_pointer_block_height: 0,
|
@@ -9890,7 +10248,7 @@ var WalletsConfig = class {
|
|
9890
10248
|
"Number of coins per asset must be greater than zero."
|
9891
10249
|
);
|
9892
10250
|
}
|
9893
|
-
if ((0,
|
10251
|
+
if ((0, import_math24.bn)(amountPerCoin).lt(0)) {
|
9894
10252
|
throw new import_errors27.FuelError(
|
9895
10253
|
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
9896
10254
|
"Amount per coin must be greater than or equal to zero."
|
@@ -9966,7 +10324,7 @@ async function setupTestProviderAndWallets({
|
|
9966
10324
|
// src/test-utils/test-message.ts
|
9967
10325
|
var import_address8 = require("@fuel-ts/address");
|
9968
10326
|
var import_crypto10 = require("@fuel-ts/crypto");
|
9969
|
-
var
|
10327
|
+
var import_math25 = require("@fuel-ts/math");
|
9970
10328
|
var import_utils45 = require("@fuel-ts/utils");
|
9971
10329
|
var TestMessage = class {
|
9972
10330
|
sender;
|
@@ -10003,7 +10361,7 @@ var TestMessage = class {
|
|
10003
10361
|
sender: this.sender.toB256(),
|
10004
10362
|
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
10005
10363
|
nonce: this.nonce,
|
10006
|
-
amount: (0,
|
10364
|
+
amount: (0, import_math25.bn)(this.amount).toNumber(),
|
10007
10365
|
data,
|
10008
10366
|
da_height: this.da_height
|
10009
10367
|
};
|