@fuel-ts/account 0.0.0-pr-2930-20240813211727 → 0.0.0-pr-2942-20240816061339
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.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +9 -29
- package/dist/account.d.ts +15 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts +0 -2
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +0 -2
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +0 -6
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +0 -4
- package/dist/configs.mjs.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +24 -1
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/fuel.d.ts +14 -4
- package/dist/connectors/fuel.d.ts.map +1 -1
- package/dist/connectors/types/connector-metadata.d.ts.map +1 -1
- package/dist/connectors/utils/promises.d.ts.map +1 -1
- package/dist/index.global.js +1387 -1033
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +705 -528
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +533 -367
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +15 -9
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +119 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts +1 -0
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +14 -47
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource-cache.d.ts +14 -0
- package/dist/providers/resource-cache.d.ts.map +1 -0
- package/dist/providers/transaction-request/blob-transaction-request.d.ts +48 -0
- package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -0
- package/dist/providers/transaction-request/index.d.ts +1 -0
- package/dist/providers/transaction-request/index.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +4 -3
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/types.d.ts +5 -2
- package/dist/providers/transaction-request/types.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +9 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +3 -0
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/call.d.ts +4 -3
- package/dist/providers/transaction-summary/call.d.ts.map +1 -1
- package/dist/providers/transaction-summary/input.d.ts +1 -1
- package/dist/providers/transaction-summary/input.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +3 -1
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +3 -1
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +6 -0
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +0 -16
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -1
- package/dist/test-utils/test-asset-id.d.ts +8 -0
- package/dist/test-utils/test-asset-id.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +4 -2
- package/dist/test-utils/test-message.d.ts.map +1 -1
- package/dist/test-utils/wallet-config.d.ts +3 -3
- package/dist/test-utils/wallet-config.d.ts.map +1 -1
- package/dist/test-utils.d.ts +1 -3
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/test-utils.global.js +39070 -38743
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +1314 -1201
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +1031 -919
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +1 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/dist/wallet/keystore-wallet.d.ts.map +1 -1
- package/package.json +19 -21
- package/dist/providers/memory-cache.d.ts +0 -11
- package/dist/providers/memory-cache.d.ts.map +0 -1
- package/dist/test-utils/asset-id.d.ts +0 -8
- package/dist/test-utils/asset-id.d.ts.map +0 -1
- package/dist/test-utils/generateTestWallet.d.ts +0 -4
- package/dist/test-utils/generateTestWallet.d.ts.map +0 -1
- package/dist/test-utils/seedTestWallet.d.ts +0 -4
- package/dist/test-utils/seedTestWallet.d.ts.map +0 -1
package/dist/index.js
CHANGED
@@ -62,10 +62,12 @@ __export(src_exports, {
|
|
62
62
|
BLOCKS_PAGE_SIZE_LIMIT: () => BLOCKS_PAGE_SIZE_LIMIT,
|
63
63
|
BaseTransactionRequest: () => BaseTransactionRequest,
|
64
64
|
BaseWalletUnlocked: () => BaseWalletUnlocked,
|
65
|
+
BlobTransactionRequest: () => BlobTransactionRequest,
|
65
66
|
CHAIN_IDS: () => CHAIN_IDS,
|
66
67
|
ChainName: () => ChainName,
|
67
68
|
ChangeOutputCollisionError: () => ChangeOutputCollisionError,
|
68
69
|
CreateTransactionRequest: () => CreateTransactionRequest,
|
70
|
+
DEFAULT_RESOURCE_CACHE_TTL: () => DEFAULT_RESOURCE_CACHE_TTL,
|
69
71
|
Fuel: () => Fuel,
|
70
72
|
FuelConnector: () => FuelConnector,
|
71
73
|
FuelConnectorEventType: () => FuelConnectorEventType,
|
@@ -109,6 +111,7 @@ __export(src_exports, {
|
|
109
111
|
cacheRequestInputsResources: () => cacheRequestInputsResources,
|
110
112
|
cacheRequestInputsResourcesFromOwner: () => cacheRequestInputsResourcesFromOwner,
|
111
113
|
calculateGasFee: () => calculateGasFee,
|
114
|
+
calculateMetadataGasForTxBlob: () => calculateMetadataGasForTxBlob,
|
112
115
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
113
116
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
114
117
|
calculateTXFeeForSummary: () => calculateTXFeeForSummary,
|
@@ -174,7 +177,11 @@ __export(src_exports, {
|
|
174
177
|
isRequestInputMessage: () => isRequestInputMessage,
|
175
178
|
isRequestInputResource: () => isRequestInputResource,
|
176
179
|
isRequestInputResourceFromOwner: () => isRequestInputResourceFromOwner,
|
180
|
+
isTransactionTypeBlob: () => isTransactionTypeBlob,
|
181
|
+
isTransactionTypeCreate: () => isTransactionTypeCreate,
|
182
|
+
isTransactionTypeScript: () => isTransactionTypeScript,
|
177
183
|
isType: () => isType,
|
184
|
+
isTypeBlob: () => isTypeBlob,
|
178
185
|
isTypeCreate: () => isTypeCreate,
|
179
186
|
isTypeMint: () => isTypeMint,
|
180
187
|
isTypeScript: () => isTypeScript,
|
@@ -199,10 +206,10 @@ module.exports = __toCommonJS(src_exports);
|
|
199
206
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
200
207
|
var import_address4 = require("@fuel-ts/address");
|
201
208
|
var import_crypto2 = require("@fuel-ts/crypto");
|
202
|
-
var
|
209
|
+
var import_errors17 = require("@fuel-ts/errors");
|
203
210
|
var import_interfaces = require("@fuel-ts/interfaces");
|
204
211
|
var import_math20 = require("@fuel-ts/math");
|
205
|
-
var
|
212
|
+
var import_utils30 = require("@fuel-ts/utils");
|
206
213
|
var import_ramda4 = require("ramda");
|
207
214
|
|
208
215
|
// src/providers/coin-quantity.ts
|
@@ -242,12 +249,12 @@ var addAmountToCoinQuantities = (params) => {
|
|
242
249
|
|
243
250
|
// src/providers/provider.ts
|
244
251
|
var import_address3 = require("@fuel-ts/address");
|
245
|
-
var
|
252
|
+
var import_errors15 = require("@fuel-ts/errors");
|
246
253
|
var import_math17 = require("@fuel-ts/math");
|
247
254
|
var import_transactions20 = require("@fuel-ts/transactions");
|
248
|
-
var
|
255
|
+
var import_utils24 = require("@fuel-ts/utils");
|
249
256
|
var import_versions = require("@fuel-ts/versions");
|
250
|
-
var
|
257
|
+
var import_utils25 = require("@noble/curves/abstract/utils");
|
251
258
|
var import_graphql_request = require("graphql-request");
|
252
259
|
var import_ramda3 = require("ramda");
|
253
260
|
|
@@ -678,6 +685,12 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
|
|
678
685
|
alocDependentCost {
|
679
686
|
...DependentCostFragment
|
680
687
|
}
|
688
|
+
bldd {
|
689
|
+
...DependentCostFragment
|
690
|
+
}
|
691
|
+
bsiz {
|
692
|
+
...DependentCostFragment
|
693
|
+
}
|
681
694
|
cfe {
|
682
695
|
...DependentCostFragment
|
683
696
|
}
|
@@ -696,6 +709,9 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
|
|
696
709
|
csiz {
|
697
710
|
...DependentCostFragment
|
698
711
|
}
|
712
|
+
ed19DependentCost {
|
713
|
+
...DependentCostFragment
|
714
|
+
}
|
699
715
|
k256 {
|
700
716
|
...DependentCostFragment
|
701
717
|
}
|
@@ -1302,62 +1318,65 @@ var _FuelGraphqlSubscriber = class {
|
|
1302
1318
|
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
1303
1319
|
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
1304
1320
|
|
1305
|
-
// src/providers/
|
1321
|
+
// src/providers/resource-cache.ts
|
1306
1322
|
var import_errors2 = require("@fuel-ts/errors");
|
1307
1323
|
var import_utils2 = require("@fuel-ts/utils");
|
1308
|
-
var cache =
|
1309
|
-
var
|
1310
|
-
var MemoryCache = class {
|
1324
|
+
var cache = /* @__PURE__ */ new Map();
|
1325
|
+
var ResourceCache = class {
|
1311
1326
|
ttl;
|
1312
|
-
constructor(
|
1313
|
-
this.ttl =
|
1314
|
-
if (typeof
|
1327
|
+
constructor(ttl) {
|
1328
|
+
this.ttl = ttl;
|
1329
|
+
if (typeof ttl !== "number" || this.ttl <= 0) {
|
1315
1330
|
throw new import_errors2.FuelError(
|
1316
1331
|
import_errors2.ErrorCode.INVALID_TTL,
|
1317
1332
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
1318
1333
|
);
|
1319
1334
|
}
|
1320
1335
|
}
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
}
|
1329
|
-
return void 0;
|
1330
|
-
}
|
1331
|
-
set(value) {
|
1332
|
-
const expiresAt = Date.now() + this.ttl;
|
1333
|
-
const key = (0, import_utils2.hexlify)(value);
|
1334
|
-
cache[key] = {
|
1335
|
-
expires: expiresAt,
|
1336
|
-
value
|
1336
|
+
// Add resources to the cache
|
1337
|
+
set(transactionId, resources) {
|
1338
|
+
const currentTime = Date.now();
|
1339
|
+
const existingResources = cache.get(transactionId) || {
|
1340
|
+
utxos: /* @__PURE__ */ new Set(),
|
1341
|
+
messages: /* @__PURE__ */ new Set(),
|
1342
|
+
timestamp: currentTime
|
1337
1343
|
};
|
1338
|
-
|
1344
|
+
resources.utxos.forEach((utxo) => existingResources.utxos.add((0, import_utils2.hexlify)(utxo)));
|
1345
|
+
resources.messages.forEach((message) => existingResources.messages.add((0, import_utils2.hexlify)(message)));
|
1346
|
+
cache.set(transactionId, existingResources);
|
1339
1347
|
}
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
if (data) {
|
1344
|
-
list.push(data);
|
1345
|
-
}
|
1346
|
-
return list;
|
1347
|
-
}, []);
|
1348
|
+
// Remove resources from the cache for a given transaction ID
|
1349
|
+
unset(transactionId) {
|
1350
|
+
cache.delete(transactionId);
|
1348
1351
|
}
|
1352
|
+
// Get all cached resources and remove expired ones
|
1349
1353
|
getActiveData() {
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
+
const allResources = { utxos: [], messages: [] };
|
1355
|
+
const currentTime = Date.now();
|
1356
|
+
cache.forEach((resource, transactionId) => {
|
1357
|
+
if (currentTime - resource.timestamp < this.ttl) {
|
1358
|
+
allResources.utxos.push(...resource.utxos);
|
1359
|
+
allResources.messages.push(...resource.messages);
|
1360
|
+
} else {
|
1361
|
+
cache.delete(transactionId);
|
1354
1362
|
}
|
1355
|
-
|
1356
|
-
|
1363
|
+
});
|
1364
|
+
return allResources;
|
1365
|
+
}
|
1366
|
+
// Check if a UTXO ID or message nonce is already cached and not expired
|
1367
|
+
isCached(key) {
|
1368
|
+
const currentTime = Date.now();
|
1369
|
+
for (const [transactionId, resourceData] of cache.entries()) {
|
1370
|
+
if (currentTime - resourceData.timestamp > this.ttl) {
|
1371
|
+
cache.delete(transactionId);
|
1372
|
+
} else if (resourceData.utxos.has(key) || resourceData.messages.has(key)) {
|
1373
|
+
return true;
|
1374
|
+
}
|
1375
|
+
}
|
1376
|
+
return false;
|
1357
1377
|
}
|
1358
|
-
|
1359
|
-
|
1360
|
-
delete cache[key];
|
1378
|
+
clear() {
|
1379
|
+
cache.clear();
|
1361
1380
|
}
|
1362
1381
|
};
|
1363
1382
|
|
@@ -1498,6 +1517,7 @@ var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
|
1498
1517
|
var import_address = require("@fuel-ts/address");
|
1499
1518
|
var import_configs6 = require("@fuel-ts/address/configs");
|
1500
1519
|
var import_crypto = require("@fuel-ts/crypto");
|
1520
|
+
var import_errors8 = require("@fuel-ts/errors");
|
1501
1521
|
var import_math8 = require("@fuel-ts/math");
|
1502
1522
|
var import_transactions7 = require("@fuel-ts/transactions");
|
1503
1523
|
var import_utils9 = require("@fuel-ts/utils");
|
@@ -1867,6 +1887,15 @@ function calculateMetadataGasForTxScript({
|
|
1867
1887
|
}) {
|
1868
1888
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1869
1889
|
}
|
1890
|
+
function calculateMetadataGasForTxBlob({
|
1891
|
+
gasCosts,
|
1892
|
+
txBytesSize,
|
1893
|
+
witnessBytesSize
|
1894
|
+
}) {
|
1895
|
+
const txId = resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1896
|
+
const blobLen = resolveGasDependentCosts(witnessBytesSize, gasCosts.s256);
|
1897
|
+
return txId.add(blobLen);
|
1898
|
+
}
|
1870
1899
|
var calculateGasFee = (params) => {
|
1871
1900
|
const { gas, gasPrice, priceFactor, tip } = params;
|
1872
1901
|
return gas.mul(gasPrice).div(priceFactor).add((0, import_math5.bn)(tip));
|
@@ -2435,7 +2464,7 @@ var BaseTransactionRequest = class {
|
|
2435
2464
|
* @hidden
|
2436
2465
|
*/
|
2437
2466
|
metadataGas(_gasCosts) {
|
2438
|
-
throw new
|
2467
|
+
throw new import_errors8.FuelError(import_errors8.FuelError.CODES.NOT_IMPLEMENTED, "Not implemented");
|
2439
2468
|
}
|
2440
2469
|
/**
|
2441
2470
|
* @hidden
|
@@ -2510,6 +2539,7 @@ var BaseTransactionRequest = class {
|
|
2510
2539
|
};
|
2511
2540
|
updateAssetInput(baseAssetId, (0, import_math8.bn)(1e11));
|
2512
2541
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2542
|
+
return this;
|
2513
2543
|
}
|
2514
2544
|
/**
|
2515
2545
|
* Retrieves an array of CoinQuantity for each coin output present in the transaction.
|
@@ -2556,14 +2586,11 @@ var BaseTransactionRequest = class {
|
|
2556
2586
|
}
|
2557
2587
|
});
|
2558
2588
|
}
|
2589
|
+
byteLength() {
|
2590
|
+
return this.toTransactionBytes().byteLength;
|
2591
|
+
}
|
2559
2592
|
};
|
2560
2593
|
|
2561
|
-
// src/providers/transaction-request/create-transaction-request.ts
|
2562
|
-
var import_configs8 = require("@fuel-ts/address/configs");
|
2563
|
-
var import_math10 = require("@fuel-ts/math");
|
2564
|
-
var import_transactions9 = require("@fuel-ts/transactions");
|
2565
|
-
var import_utils13 = require("@fuel-ts/utils");
|
2566
|
-
|
2567
2594
|
// src/providers/transaction-request/hash-transaction.ts
|
2568
2595
|
var import_configs7 = require("@fuel-ts/address/configs");
|
2569
2596
|
var import_hasher = require("@fuel-ts/hasher");
|
@@ -2635,11 +2662,81 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2635
2662
|
return (0, import_hasher.sha256)(concatenatedData);
|
2636
2663
|
}
|
2637
2664
|
|
2665
|
+
// src/providers/transaction-request/blob-transaction-request.ts
|
2666
|
+
var BlobTransactionRequest = class extends BaseTransactionRequest {
|
2667
|
+
static from(obj) {
|
2668
|
+
if (obj instanceof this) {
|
2669
|
+
return obj;
|
2670
|
+
}
|
2671
|
+
return new this(obj);
|
2672
|
+
}
|
2673
|
+
/** Type of the transaction */
|
2674
|
+
type = import_transactions7.TransactionType.Blob;
|
2675
|
+
/** Blob ID */
|
2676
|
+
blobId;
|
2677
|
+
/** Witness index of contract bytecode to create */
|
2678
|
+
witnessIndex;
|
2679
|
+
/**
|
2680
|
+
* Creates an instance `BlobTransactionRequest`.
|
2681
|
+
*
|
2682
|
+
* @param blobTransactionRequestLike - The initial values for the instance
|
2683
|
+
*/
|
2684
|
+
constructor({ witnessIndex, blobId, ...rest }) {
|
2685
|
+
super(rest);
|
2686
|
+
this.blobId = blobId;
|
2687
|
+
this.witnessIndex = witnessIndex ?? 0;
|
2688
|
+
}
|
2689
|
+
/**
|
2690
|
+
* Converts the transaction request to a `TransactionBlob`.
|
2691
|
+
*
|
2692
|
+
* @returns The transaction create object.
|
2693
|
+
*/
|
2694
|
+
toTransaction() {
|
2695
|
+
const baseTransaction = this.getBaseTransaction();
|
2696
|
+
const { witnessIndex, blobId } = this;
|
2697
|
+
return {
|
2698
|
+
type: import_transactions7.TransactionType.Blob,
|
2699
|
+
...baseTransaction,
|
2700
|
+
blobId,
|
2701
|
+
witnessIndex
|
2702
|
+
};
|
2703
|
+
}
|
2704
|
+
/**
|
2705
|
+
* Gets the Transaction Request by hashing the transaction.
|
2706
|
+
*
|
2707
|
+
* @param chainId - The chain ID.
|
2708
|
+
*
|
2709
|
+
* @returns - A hash of the transaction, which is the transaction ID.
|
2710
|
+
*/
|
2711
|
+
getTransactionId(chainId) {
|
2712
|
+
return hashTransaction(this, chainId);
|
2713
|
+
}
|
2714
|
+
/**
|
2715
|
+
* Calculates the metadata gas cost for a blob transaction.
|
2716
|
+
*
|
2717
|
+
* @param gasCosts - gas costs passed from the chain.
|
2718
|
+
* @returns metadata gas cost for the blob transaction.
|
2719
|
+
*/
|
2720
|
+
metadataGas(gasCosts) {
|
2721
|
+
return calculateMetadataGasForTxBlob({
|
2722
|
+
gasCosts,
|
2723
|
+
txBytesSize: this.byteSize(),
|
2724
|
+
witnessBytesSize: this.witnesses[this.witnessIndex].length
|
2725
|
+
});
|
2726
|
+
}
|
2727
|
+
};
|
2728
|
+
|
2729
|
+
// src/providers/transaction-request/create-transaction-request.ts
|
2730
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2731
|
+
var import_math10 = require("@fuel-ts/math");
|
2732
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2733
|
+
var import_utils14 = require("@fuel-ts/utils");
|
2734
|
+
|
2638
2735
|
// src/providers/transaction-request/storage-slot.ts
|
2639
|
-
var
|
2736
|
+
var import_utils13 = require("@fuel-ts/utils");
|
2640
2737
|
var getStorageValue = (value) => {
|
2641
2738
|
const v = new Uint8Array(32);
|
2642
|
-
v.set((0,
|
2739
|
+
v.set((0, import_utils13.arrayify)(value));
|
2643
2740
|
return v;
|
2644
2741
|
};
|
2645
2742
|
var storageSlotify = (storageSlot) => {
|
@@ -2653,8 +2750,8 @@ var storageSlotify = (storageSlot) => {
|
|
2653
2750
|
value = storageSlot.value;
|
2654
2751
|
}
|
2655
2752
|
return {
|
2656
|
-
key: (0,
|
2657
|
-
value: (0,
|
2753
|
+
key: (0, import_utils13.hexlify)(key),
|
2754
|
+
value: (0, import_utils13.hexlify)(getStorageValue(value))
|
2658
2755
|
};
|
2659
2756
|
};
|
2660
2757
|
|
@@ -2682,7 +2779,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2682
2779
|
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2683
2780
|
super(rest);
|
2684
2781
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2685
|
-
this.salt = (0,
|
2782
|
+
this.salt = (0, import_utils14.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2686
2783
|
this.storageSlots = [...storageSlots ?? []];
|
2687
2784
|
}
|
2688
2785
|
/**
|
@@ -2699,7 +2796,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2699
2796
|
...baseTransaction,
|
2700
2797
|
bytecodeWitnessIndex,
|
2701
2798
|
storageSlotsCount: (0, import_math10.bn)(storageSlots.length),
|
2702
|
-
salt: this.salt ? (0,
|
2799
|
+
salt: this.salt ? (0, import_utils14.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2703
2800
|
storageSlots
|
2704
2801
|
};
|
2705
2802
|
}
|
@@ -2738,7 +2835,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2738
2835
|
}
|
2739
2836
|
metadataGas(gasCosts) {
|
2740
2837
|
return calculateMetadataGasForTxCreate({
|
2741
|
-
contractBytesSize: (0, import_math10.bn)((0,
|
2838
|
+
contractBytesSize: (0, import_math10.bn)((0, import_utils14.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2742
2839
|
gasCosts,
|
2743
2840
|
stateRootSize: this.storageSlots.length,
|
2744
2841
|
txBytesSize: this.byteSize()
|
@@ -2752,17 +2849,17 @@ var import_address2 = require("@fuel-ts/address");
|
|
2752
2849
|
var import_configs9 = require("@fuel-ts/address/configs");
|
2753
2850
|
var import_math11 = require("@fuel-ts/math");
|
2754
2851
|
var import_transactions10 = require("@fuel-ts/transactions");
|
2755
|
-
var
|
2852
|
+
var import_utils16 = require("@fuel-ts/utils");
|
2756
2853
|
|
2757
2854
|
// src/providers/transaction-request/scripts.ts
|
2758
|
-
var
|
2855
|
+
var import_utils15 = require("@fuel-ts/utils");
|
2759
2856
|
var returnZeroScript = {
|
2760
2857
|
/*
|
2761
2858
|
Opcode::RET(REG_ZERO)
|
2762
2859
|
Opcode::NOOP
|
2763
2860
|
*/
|
2764
2861
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2765
|
-
bytes: (0,
|
2862
|
+
bytes: (0, import_utils15.arrayify)("0x24000000"),
|
2766
2863
|
encodeScriptData: () => new Uint8Array(0)
|
2767
2864
|
};
|
2768
2865
|
var withdrawScript = {
|
@@ -2776,7 +2873,7 @@ var withdrawScript = {
|
|
2776
2873
|
00000000 00000000 [amount value]
|
2777
2874
|
*/
|
2778
2875
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2779
|
-
bytes: (0,
|
2876
|
+
bytes: (0, import_utils15.arrayify)("0x5040C0105D44C0064C40001124000000"),
|
2780
2877
|
encodeScriptData: () => new Uint8Array(0)
|
2781
2878
|
};
|
2782
2879
|
|
@@ -2805,8 +2902,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2805
2902
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2806
2903
|
super(rest);
|
2807
2904
|
this.gasLimit = (0, import_math11.bn)(gasLimit);
|
2808
|
-
this.script = (0,
|
2809
|
-
this.scriptData = (0,
|
2905
|
+
this.script = (0, import_utils16.arrayify)(script ?? returnZeroScript.bytes);
|
2906
|
+
this.scriptData = (0, import_utils16.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2810
2907
|
this.abis = rest.abis;
|
2811
2908
|
}
|
2812
2909
|
/**
|
@@ -2815,8 +2912,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2815
2912
|
* @returns The transaction script object.
|
2816
2913
|
*/
|
2817
2914
|
toTransaction() {
|
2818
|
-
const script = (0,
|
2819
|
-
const scriptData = (0,
|
2915
|
+
const script = (0, import_utils16.arrayify)(this.script ?? "0x");
|
2916
|
+
const scriptData = (0, import_utils16.arrayify)(this.scriptData ?? "0x");
|
2820
2917
|
return {
|
2821
2918
|
type: import_transactions10.TransactionType.Script,
|
2822
2919
|
scriptGasLimit: this.gasLimit,
|
@@ -2824,8 +2921,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2824
2921
|
scriptLength: (0, import_math11.bn)(script.length),
|
2825
2922
|
scriptDataLength: (0, import_math11.bn)(scriptData.length),
|
2826
2923
|
receiptsRoot: import_configs9.ZeroBytes32,
|
2827
|
-
script: (0,
|
2828
|
-
scriptData: (0,
|
2924
|
+
script: (0, import_utils16.hexlify)(script),
|
2925
|
+
scriptData: (0, import_utils16.hexlify)(scriptData)
|
2829
2926
|
};
|
2830
2927
|
}
|
2831
2928
|
/**
|
@@ -2963,10 +3060,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2963
3060
|
};
|
2964
3061
|
|
2965
3062
|
// src/providers/transaction-request/utils.ts
|
2966
|
-
var
|
3063
|
+
var import_errors10 = require("@fuel-ts/errors");
|
2967
3064
|
var import_transactions11 = require("@fuel-ts/transactions");
|
2968
3065
|
var transactionRequestify = (obj) => {
|
2969
|
-
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
3066
|
+
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest) {
|
2970
3067
|
return obj;
|
2971
3068
|
}
|
2972
3069
|
const { type } = obj;
|
@@ -2977,27 +3074,36 @@ var transactionRequestify = (obj) => {
|
|
2977
3074
|
case import_transactions11.TransactionType.Create: {
|
2978
3075
|
return CreateTransactionRequest.from(obj);
|
2979
3076
|
}
|
3077
|
+
case import_transactions11.TransactionType.Blob: {
|
3078
|
+
return BlobTransactionRequest.from(obj);
|
3079
|
+
}
|
2980
3080
|
default: {
|
2981
|
-
throw new
|
3081
|
+
throw new import_errors10.FuelError(
|
3082
|
+
import_errors10.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
3083
|
+
`Unsupported transaction type: ${type}.`
|
3084
|
+
);
|
2982
3085
|
}
|
2983
3086
|
}
|
2984
3087
|
};
|
3088
|
+
var isTransactionTypeScript = (request) => request.type === import_transactions11.TransactionType.Script;
|
3089
|
+
var isTransactionTypeCreate = (request) => request.type === import_transactions11.TransactionType.Create;
|
3090
|
+
var isTransactionTypeBlob = (request) => request.type === import_transactions11.TransactionType.Blob;
|
2985
3091
|
|
2986
3092
|
// src/providers/transaction-response/transaction-response.ts
|
2987
|
-
var
|
3093
|
+
var import_errors14 = require("@fuel-ts/errors");
|
2988
3094
|
var import_math16 = require("@fuel-ts/math");
|
2989
3095
|
var import_transactions19 = require("@fuel-ts/transactions");
|
2990
|
-
var
|
3096
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2991
3097
|
|
2992
3098
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2993
3099
|
var import_math15 = require("@fuel-ts/math");
|
2994
3100
|
var import_transactions17 = require("@fuel-ts/transactions");
|
2995
|
-
var
|
3101
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2996
3102
|
|
2997
3103
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
2998
3104
|
var import_math12 = require("@fuel-ts/math");
|
2999
3105
|
var import_transactions12 = require("@fuel-ts/transactions");
|
3000
|
-
var
|
3106
|
+
var import_utils17 = require("@fuel-ts/utils");
|
3001
3107
|
var calculateTXFeeForSummary = (params) => {
|
3002
3108
|
const {
|
3003
3109
|
gasPrice,
|
@@ -3011,7 +3117,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3011
3117
|
}
|
3012
3118
|
const gasPerByte = (0, import_math12.bn)(feeParams.gasPerByte);
|
3013
3119
|
const gasPriceFactor = (0, import_math12.bn)(feeParams.gasPriceFactor);
|
3014
|
-
const transactionBytes = (0,
|
3120
|
+
const transactionBytes = (0, import_utils17.arrayify)(rawPayload);
|
3015
3121
|
const [transaction] = new import_transactions12.TransactionCoder().decode(transactionBytes, 0);
|
3016
3122
|
const { type, witnesses, inputs, policies } = transaction;
|
3017
3123
|
let metadataGas = (0, import_math12.bn)(0);
|
@@ -3021,7 +3127,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3021
3127
|
}
|
3022
3128
|
if (type === import_transactions12.TransactionType.Create) {
|
3023
3129
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
3024
|
-
const contractBytesSize = (0, import_math12.bn)((0,
|
3130
|
+
const contractBytesSize = (0, import_math12.bn)((0, import_utils17.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
3025
3131
|
metadataGas = calculateMetadataGasForTxCreate({
|
3026
3132
|
contractBytesSize,
|
3027
3133
|
gasCosts,
|
@@ -3066,7 +3172,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3066
3172
|
|
3067
3173
|
// src/providers/transaction-summary/operations.ts
|
3068
3174
|
var import_configs10 = require("@fuel-ts/address/configs");
|
3069
|
-
var
|
3175
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3070
3176
|
var import_math13 = require("@fuel-ts/math");
|
3071
3177
|
var import_transactions15 = require("@fuel-ts/transactions");
|
3072
3178
|
|
@@ -3104,7 +3210,7 @@ var getFunctionCall = ({ abi, receipt }) => {
|
|
3104
3210
|
};
|
3105
3211
|
|
3106
3212
|
// src/providers/transaction-summary/input.ts
|
3107
|
-
var
|
3213
|
+
var import_errors11 = require("@fuel-ts/errors");
|
3108
3214
|
var import_transactions13 = require("@fuel-ts/transactions");
|
3109
3215
|
function getInputsByTypes(inputs, types) {
|
3110
3216
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -3124,14 +3230,22 @@ function getInputsCoinAndMessage(inputs) {
|
|
3124
3230
|
function getInputsContract(inputs) {
|
3125
3231
|
return getInputsByType(inputs, import_transactions13.InputType.Contract);
|
3126
3232
|
}
|
3127
|
-
function
|
3233
|
+
function findCoinInput(inputs, assetId) {
|
3128
3234
|
const coinInputs = getInputsCoin(inputs);
|
3129
|
-
|
3130
|
-
|
3131
|
-
|
3132
|
-
|
3133
|
-
|
3134
|
-
|
3235
|
+
return coinInputs.find((i) => i.assetId === assetId);
|
3236
|
+
}
|
3237
|
+
function findMessageInput(inputs) {
|
3238
|
+
return getInputsMessage(inputs)?.[0];
|
3239
|
+
}
|
3240
|
+
function getInputFromAssetId(inputs, assetId, isBaseAsset = false) {
|
3241
|
+
const coinInput = findCoinInput(inputs, assetId);
|
3242
|
+
if (coinInput) {
|
3243
|
+
return coinInput;
|
3244
|
+
}
|
3245
|
+
if (isBaseAsset) {
|
3246
|
+
return findMessageInput(inputs);
|
3247
|
+
}
|
3248
|
+
return void 0;
|
3135
3249
|
}
|
3136
3250
|
function getInputContractFromIndex(inputs, inputIndex) {
|
3137
3251
|
if (inputIndex == null) {
|
@@ -3142,8 +3256,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
3142
3256
|
return void 0;
|
3143
3257
|
}
|
3144
3258
|
if (contractInput.type !== import_transactions13.InputType.Contract) {
|
3145
|
-
throw new
|
3146
|
-
|
3259
|
+
throw new import_errors11.FuelError(
|
3260
|
+
import_errors11.ErrorCode.INVALID_TRANSACTION_INPUT,
|
3147
3261
|
`Contract input should be of type 'contract'.`
|
3148
3262
|
);
|
3149
3263
|
}
|
@@ -3187,6 +3301,7 @@ var TransactionTypeName = /* @__PURE__ */ ((TransactionTypeName2) => {
|
|
3187
3301
|
TransactionTypeName2["Script"] = "Script";
|
3188
3302
|
TransactionTypeName2["Upgrade"] = "Upgrade";
|
3189
3303
|
TransactionTypeName2["Upload"] = "Upload";
|
3304
|
+
TransactionTypeName2["Blob"] = "Blob";
|
3190
3305
|
return TransactionTypeName2;
|
3191
3306
|
})(TransactionTypeName || {});
|
3192
3307
|
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
@@ -3232,10 +3347,12 @@ function getTransactionTypeName(transactionType) {
|
|
3232
3347
|
return "Create" /* Create */;
|
3233
3348
|
case import_transactions15.TransactionType.Script:
|
3234
3349
|
return "Script" /* Script */;
|
3350
|
+
case import_transactions15.TransactionType.Blob:
|
3351
|
+
return "Blob" /* Blob */;
|
3235
3352
|
default:
|
3236
|
-
throw new
|
3237
|
-
|
3238
|
-
`
|
3353
|
+
throw new import_errors12.FuelError(
|
3354
|
+
import_errors12.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
3355
|
+
`Unsupported transaction type: ${transactionType}.`
|
3239
3356
|
);
|
3240
3357
|
}
|
3241
3358
|
}
|
@@ -3258,6 +3375,9 @@ function isTypeUpgrade(transactionType) {
|
|
3258
3375
|
function isTypeUpload(transactionType) {
|
3259
3376
|
return isType(transactionType, "Upload" /* Upload */);
|
3260
3377
|
}
|
3378
|
+
function isTypeBlob(transactionType) {
|
3379
|
+
return isType(transactionType, "Blob" /* Blob */);
|
3380
|
+
}
|
3261
3381
|
function hasSameAssetId(a) {
|
3262
3382
|
return (b) => a.assetId === b.assetId;
|
3263
3383
|
}
|
@@ -3267,41 +3387,51 @@ function getReceiptsCall(receipts) {
|
|
3267
3387
|
function getReceiptsMessageOut(receipts) {
|
3268
3388
|
return getReceiptsByType(receipts, import_transactions15.ReceiptType.MessageOut);
|
3269
3389
|
}
|
3270
|
-
|
3390
|
+
function mergeAssets(op1, op2) {
|
3271
3391
|
const assets1 = op1.assetsSent || [];
|
3272
3392
|
const assets2 = op2.assetsSent || [];
|
3273
|
-
const
|
3274
|
-
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3393
|
+
const assetMap = /* @__PURE__ */ new Map();
|
3394
|
+
assets1.forEach((asset) => {
|
3395
|
+
assetMap.set(asset.assetId, { ...asset });
|
3396
|
+
});
|
3397
|
+
assets2.forEach((asset) => {
|
3398
|
+
const existingAsset = assetMap.get(asset.assetId);
|
3399
|
+
if (existingAsset) {
|
3400
|
+
existingAsset.amount = (0, import_math13.bn)(existingAsset.amount).add(asset.amount);
|
3401
|
+
} else {
|
3402
|
+
assetMap.set(asset.assetId, { ...asset });
|
3280
3403
|
}
|
3281
|
-
const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
|
3282
|
-
return { ...asset1, amount: mergedAmount };
|
3283
3404
|
});
|
3284
|
-
return
|
3285
|
-
}
|
3405
|
+
return Array.from(assetMap.values());
|
3406
|
+
}
|
3286
3407
|
function isSameOperation(a, b) {
|
3287
3408
|
return a.name === b.name && a.from?.address === b.from?.address && a.to?.address === b.to?.address && a.from?.type === b.from?.type && a.to?.type === b.to?.type;
|
3288
3409
|
}
|
3410
|
+
function mergeAssetsSent(existing, toAdd) {
|
3411
|
+
if (!toAdd.assetsSent?.length) {
|
3412
|
+
return existing.assetsSent;
|
3413
|
+
}
|
3414
|
+
return existing.assetsSent?.length ? mergeAssets(existing, toAdd) : toAdd.assetsSent;
|
3415
|
+
}
|
3416
|
+
function mergeCalls(existing, toAdd) {
|
3417
|
+
if (!toAdd.calls?.length) {
|
3418
|
+
return existing.calls;
|
3419
|
+
}
|
3420
|
+
return [...existing.calls || [], ...toAdd.calls];
|
3421
|
+
}
|
3422
|
+
function mergeOperations(existing, toAdd) {
|
3423
|
+
return {
|
3424
|
+
...existing,
|
3425
|
+
assetsSent: mergeAssetsSent(existing, toAdd),
|
3426
|
+
calls: mergeCalls(existing, toAdd)
|
3427
|
+
};
|
3428
|
+
}
|
3289
3429
|
function addOperation(operations, toAdd) {
|
3290
|
-
const
|
3291
|
-
|
3292
|
-
|
3293
|
-
const existentOperation = { ...allOperations[index] };
|
3294
|
-
if (toAdd.assetsSent?.length) {
|
3295
|
-
existentOperation.assetsSent = existentOperation.assetsSent?.length ? mergeAssets(existentOperation, toAdd) : toAdd.assetsSent;
|
3296
|
-
}
|
3297
|
-
if (toAdd.calls?.length) {
|
3298
|
-
existentOperation.calls = [...existentOperation.calls || [], ...toAdd.calls];
|
3299
|
-
}
|
3300
|
-
allOperations[index] = existentOperation;
|
3301
|
-
} else {
|
3302
|
-
allOperations.push(toAdd);
|
3430
|
+
const existingIndex = operations.findIndex((op) => isSameOperation(op, toAdd));
|
3431
|
+
if (existingIndex === -1) {
|
3432
|
+
return [...operations, toAdd];
|
3303
3433
|
}
|
3304
|
-
return
|
3434
|
+
return operations.map((op, index) => index === existingIndex ? mergeOperations(op, toAdd) : op);
|
3305
3435
|
}
|
3306
3436
|
function getReceiptsTransferOut(receipts) {
|
3307
3437
|
return getReceiptsByType(receipts, import_transactions15.ReceiptType.TransferOut);
|
@@ -3314,7 +3444,7 @@ function getWithdrawFromFuelOperations({
|
|
3314
3444
|
const messageOutReceipts = getReceiptsMessageOut(receipts);
|
3315
3445
|
const withdrawFromFuelOperations = messageOutReceipts.reduce(
|
3316
3446
|
(prevWithdrawFromFuelOps, receipt) => {
|
3317
|
-
const input = getInputFromAssetId(inputs, baseAssetId);
|
3447
|
+
const input = getInputFromAssetId(inputs, baseAssetId, true);
|
3318
3448
|
if (input) {
|
3319
3449
|
const inputAddress = getInputAccountAddress(input);
|
3320
3450
|
const newWithdrawFromFuelOps = addOperation(prevWithdrawFromFuelOps, {
|
@@ -3343,65 +3473,80 @@ function getWithdrawFromFuelOperations({
|
|
3343
3473
|
);
|
3344
3474
|
return withdrawFromFuelOperations;
|
3345
3475
|
}
|
3476
|
+
function getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs) {
|
3477
|
+
const abi = abiMap?.[contractInput.contractID];
|
3478
|
+
if (!abi) {
|
3479
|
+
return [];
|
3480
|
+
}
|
3481
|
+
return [
|
3482
|
+
getFunctionCall({
|
3483
|
+
abi,
|
3484
|
+
receipt,
|
3485
|
+
rawPayload,
|
3486
|
+
maxInputs
|
3487
|
+
})
|
3488
|
+
];
|
3489
|
+
}
|
3490
|
+
function getAssetsSent(receipt) {
|
3491
|
+
return receipt.amount?.isZero() ? void 0 : [
|
3492
|
+
{
|
3493
|
+
amount: receipt.amount,
|
3494
|
+
assetId: receipt.assetId
|
3495
|
+
}
|
3496
|
+
];
|
3497
|
+
}
|
3498
|
+
function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload, maxInputs, baseAssetId) {
|
3499
|
+
const assetId = receipt.assetId === import_configs10.ZeroBytes32 ? baseAssetId : receipt.assetId;
|
3500
|
+
const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
|
3501
|
+
if (!input) {
|
3502
|
+
return [];
|
3503
|
+
}
|
3504
|
+
const inputAddress = getInputAccountAddress(input);
|
3505
|
+
const calls = getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs);
|
3506
|
+
return [
|
3507
|
+
{
|
3508
|
+
name: "Contract call" /* contractCall */,
|
3509
|
+
from: {
|
3510
|
+
type: 1 /* account */,
|
3511
|
+
address: inputAddress
|
3512
|
+
},
|
3513
|
+
to: {
|
3514
|
+
type: 0 /* contract */,
|
3515
|
+
address: receipt.to
|
3516
|
+
},
|
3517
|
+
assetsSent: getAssetsSent(receipt),
|
3518
|
+
calls
|
3519
|
+
}
|
3520
|
+
];
|
3521
|
+
}
|
3346
3522
|
function getContractCallOperations({
|
3347
3523
|
inputs,
|
3348
3524
|
outputs,
|
3349
3525
|
receipts,
|
3350
3526
|
abiMap,
|
3351
3527
|
rawPayload,
|
3352
|
-
maxInputs
|
3528
|
+
maxInputs,
|
3529
|
+
baseAssetId
|
3353
3530
|
}) {
|
3354
3531
|
const contractCallReceipts = getReceiptsCall(receipts);
|
3355
3532
|
const contractOutputs = getOutputsContract(outputs);
|
3356
|
-
|
3533
|
+
return contractOutputs.flatMap((output) => {
|
3357
3534
|
const contractInput = getInputContractFromIndex(inputs, output.inputIndex);
|
3358
|
-
if (contractInput) {
|
3359
|
-
|
3360
|
-
if (receipt.to === contractInput.contractID) {
|
3361
|
-
const input = getInputFromAssetId(inputs, receipt.assetId);
|
3362
|
-
if (input) {
|
3363
|
-
const inputAddress = getInputAccountAddress(input);
|
3364
|
-
const calls = [];
|
3365
|
-
const abi = abiMap?.[contractInput.contractID];
|
3366
|
-
if (abi) {
|
3367
|
-
calls.push(
|
3368
|
-
getFunctionCall({
|
3369
|
-
abi,
|
3370
|
-
receipt,
|
3371
|
-
rawPayload,
|
3372
|
-
maxInputs
|
3373
|
-
})
|
3374
|
-
);
|
3375
|
-
}
|
3376
|
-
const newContractCallOps = addOperation(prevContractCallOps, {
|
3377
|
-
name: "Contract call" /* contractCall */,
|
3378
|
-
from: {
|
3379
|
-
type: 1 /* account */,
|
3380
|
-
address: inputAddress
|
3381
|
-
},
|
3382
|
-
to: {
|
3383
|
-
type: 0 /* contract */,
|
3384
|
-
address: receipt.to
|
3385
|
-
},
|
3386
|
-
// if no amount is forwarded to the contract, skip showing assetsSent
|
3387
|
-
assetsSent: receipt.amount?.isZero() ? void 0 : [
|
3388
|
-
{
|
3389
|
-
amount: receipt.amount,
|
3390
|
-
assetId: receipt.assetId
|
3391
|
-
}
|
3392
|
-
],
|
3393
|
-
calls
|
3394
|
-
});
|
3395
|
-
return newContractCallOps;
|
3396
|
-
}
|
3397
|
-
}
|
3398
|
-
return prevContractCallOps;
|
3399
|
-
}, prevOutputCallOps);
|
3400
|
-
return newCallOps;
|
3535
|
+
if (!contractInput) {
|
3536
|
+
return [];
|
3401
3537
|
}
|
3402
|
-
return
|
3403
|
-
|
3404
|
-
|
3538
|
+
return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
|
3539
|
+
(receipt) => processCallReceipt(
|
3540
|
+
receipt,
|
3541
|
+
contractInput,
|
3542
|
+
inputs,
|
3543
|
+
abiMap,
|
3544
|
+
rawPayload,
|
3545
|
+
maxInputs,
|
3546
|
+
baseAssetId
|
3547
|
+
)
|
3548
|
+
);
|
3549
|
+
});
|
3405
3550
|
}
|
3406
3551
|
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
3407
3552
|
const { to: toAddress, assetId, amount } = receipt;
|
@@ -3545,7 +3690,8 @@ function getOperations({
|
|
3545
3690
|
receipts,
|
3546
3691
|
abiMap,
|
3547
3692
|
rawPayload,
|
3548
|
-
maxInputs
|
3693
|
+
maxInputs,
|
3694
|
+
baseAssetId
|
3549
3695
|
}),
|
3550
3696
|
...getWithdrawFromFuelOperations({ inputs, receipts, baseAssetId })
|
3551
3697
|
];
|
@@ -3604,7 +3750,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3604
3750
|
};
|
3605
3751
|
|
3606
3752
|
// src/providers/transaction-summary/status.ts
|
3607
|
-
var
|
3753
|
+
var import_errors13 = require("@fuel-ts/errors");
|
3608
3754
|
var import_math14 = require("@fuel-ts/math");
|
3609
3755
|
var getTransactionStatusName = (gqlStatus) => {
|
3610
3756
|
switch (gqlStatus) {
|
@@ -3617,8 +3763,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3617
3763
|
case "SqueezedOutStatus":
|
3618
3764
|
return "squeezedout" /* squeezedout */;
|
3619
3765
|
default:
|
3620
|
-
throw new
|
3621
|
-
|
3766
|
+
throw new import_errors13.FuelError(
|
3767
|
+
import_errors13.ErrorCode.INVALID_TRANSACTION_STATUS,
|
3622
3768
|
`Invalid transaction status: ${gqlStatus}.`
|
3623
3769
|
);
|
3624
3770
|
}
|
@@ -3687,7 +3833,7 @@ function assembleTransactionSummary(params) {
|
|
3687
3833
|
baseAssetId
|
3688
3834
|
} = params;
|
3689
3835
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3690
|
-
const rawPayload = (0,
|
3836
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3691
3837
|
const operations = getOperations({
|
3692
3838
|
transactionType: transaction.type,
|
3693
3839
|
inputs: transaction.inputs || [],
|
@@ -3719,7 +3865,7 @@ function assembleTransactionSummary(params) {
|
|
3719
3865
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3720
3866
|
let date;
|
3721
3867
|
if (time) {
|
3722
|
-
date =
|
3868
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3723
3869
|
}
|
3724
3870
|
const transactionSummary = {
|
3725
3871
|
id,
|
@@ -3739,6 +3885,7 @@ function assembleTransactionSummary(params) {
|
|
3739
3885
|
isTypeScript: isTypeScript(transaction.type),
|
3740
3886
|
isTypeUpgrade: isTypeUpgrade(transaction.type),
|
3741
3887
|
isTypeUpload: isTypeUpload(transaction.type),
|
3888
|
+
isTypeBlob: isTypeBlob(transaction.type),
|
3742
3889
|
isStatusFailure,
|
3743
3890
|
isStatusSuccess,
|
3744
3891
|
isStatusPending,
|
@@ -3774,6 +3921,8 @@ var TransactionResponse = class {
|
|
3774
3921
|
/** The graphql Transaction with receipts object. */
|
3775
3922
|
gqlTransaction;
|
3776
3923
|
abis;
|
3924
|
+
/** The expected status from the getTransactionWithReceipts response */
|
3925
|
+
expectedStatus;
|
3777
3926
|
/**
|
3778
3927
|
* Constructor for `TransactionResponse`.
|
3779
3928
|
*
|
@@ -3813,11 +3962,16 @@ var TransactionResponse = class {
|
|
3813
3962
|
});
|
3814
3963
|
for await (const { statusChange } of subscription) {
|
3815
3964
|
if (statusChange) {
|
3965
|
+
this.expectedStatus = statusChange.type;
|
3816
3966
|
break;
|
3817
3967
|
}
|
3818
3968
|
}
|
3819
3969
|
return this.fetch();
|
3820
3970
|
}
|
3971
|
+
if (this.expectedStatus && response.transaction.status?.type !== this.expectedStatus) {
|
3972
|
+
await (0, import_utils21.sleep)(100);
|
3973
|
+
return this.fetch();
|
3974
|
+
}
|
3821
3975
|
this.gqlTransaction = response.transaction;
|
3822
3976
|
return response.transaction;
|
3823
3977
|
}
|
@@ -3829,7 +3983,7 @@ var TransactionResponse = class {
|
|
3829
3983
|
*/
|
3830
3984
|
decodeTransaction(transactionWithReceipts) {
|
3831
3985
|
return new import_transactions19.TransactionCoder().decode(
|
3832
|
-
(0,
|
3986
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3833
3987
|
0
|
3834
3988
|
)?.[0];
|
3835
3989
|
}
|
@@ -3861,7 +4015,7 @@ var TransactionResponse = class {
|
|
3861
4015
|
id: this.id,
|
3862
4016
|
receipts,
|
3863
4017
|
transaction: decodedTransaction,
|
3864
|
-
transactionBytes: (0,
|
4018
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3865
4019
|
gqlTransactionStatus: transaction.status,
|
3866
4020
|
gasPerByte,
|
3867
4021
|
gasPriceFactor,
|
@@ -3884,12 +4038,14 @@ var TransactionResponse = class {
|
|
3884
4038
|
});
|
3885
4039
|
for await (const { statusChange } of subscription) {
|
3886
4040
|
if (statusChange.type === "SqueezedOutStatus") {
|
3887
|
-
|
3888
|
-
|
4041
|
+
this.unsetResourceCache();
|
4042
|
+
throw new import_errors14.FuelError(
|
4043
|
+
import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3889
4044
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3890
4045
|
);
|
3891
4046
|
}
|
3892
4047
|
if (statusChange.type !== "SubmittedStatus") {
|
4048
|
+
this.expectedStatus = statusChange.type;
|
3893
4049
|
break;
|
3894
4050
|
}
|
3895
4051
|
}
|
@@ -3924,6 +4080,7 @@ var TransactionResponse = class {
|
|
3924
4080
|
}
|
3925
4081
|
const { gqlTransaction, receipts } = transactionResult;
|
3926
4082
|
if (gqlTransaction.status?.type === "FailureStatus") {
|
4083
|
+
this.unsetResourceCache();
|
3927
4084
|
const { reason } = gqlTransaction.status;
|
3928
4085
|
throw extractTxError({
|
3929
4086
|
receipts,
|
@@ -3950,10 +4107,13 @@ var TransactionResponse = class {
|
|
3950
4107
|
async wait(contractsAbiMap) {
|
3951
4108
|
return this.waitForResult(contractsAbiMap);
|
3952
4109
|
}
|
4110
|
+
unsetResourceCache() {
|
4111
|
+
this.provider.cache?.unset(this.id);
|
4112
|
+
}
|
3953
4113
|
};
|
3954
4114
|
|
3955
4115
|
// src/providers/utils/auto-retry-fetch.ts
|
3956
|
-
var
|
4116
|
+
var import_utils23 = require("@fuel-ts/utils");
|
3957
4117
|
function getWaitDelay(options, retryAttemptNum) {
|
3958
4118
|
const duration = options.baseDelay ?? 150;
|
3959
4119
|
switch (options.backoff) {
|
@@ -3983,30 +4143,17 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3983
4143
|
throw error;
|
3984
4144
|
}
|
3985
4145
|
const delay = getWaitDelay(options, retryNum);
|
3986
|
-
await (0,
|
4146
|
+
await (0, import_utils23.sleep)(delay);
|
3987
4147
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
3988
4148
|
}
|
3989
4149
|
};
|
3990
4150
|
}
|
3991
4151
|
|
3992
|
-
// src/providers/utils/merge-quantities.ts
|
3993
|
-
var mergeQuantities = (...coinQuantities) => {
|
3994
|
-
const resultMap = {};
|
3995
|
-
function addToMap({ amount, assetId }) {
|
3996
|
-
if (resultMap[assetId]) {
|
3997
|
-
resultMap[assetId] = resultMap[assetId].add(amount);
|
3998
|
-
} else {
|
3999
|
-
resultMap[assetId] = amount;
|
4000
|
-
}
|
4001
|
-
}
|
4002
|
-
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
4003
|
-
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
4004
|
-
};
|
4005
|
-
|
4006
4152
|
// src/providers/provider.ts
|
4007
4153
|
var MAX_RETRIES = 10;
|
4008
4154
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
4009
4155
|
var BLOCKS_PAGE_SIZE_LIMIT = 5;
|
4156
|
+
var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
|
4010
4157
|
var processGqlChain = (chain) => {
|
4011
4158
|
const { name, daHeight, consensusParameters, latestBlock } = chain;
|
4012
4159
|
const {
|
@@ -4089,14 +4236,23 @@ var _Provider = class {
|
|
4089
4236
|
__publicField(this, "cache");
|
4090
4237
|
__publicField(this, "options", {
|
4091
4238
|
timeout: void 0,
|
4092
|
-
|
4239
|
+
resourceCacheTTL: void 0,
|
4093
4240
|
fetch: void 0,
|
4094
4241
|
retryOptions: void 0
|
4095
4242
|
});
|
4096
4243
|
this.options = { ...this.options, ...options };
|
4097
4244
|
this.url = url;
|
4098
4245
|
this.operations = this.createOperations();
|
4099
|
-
|
4246
|
+
const { resourceCacheTTL } = this.options;
|
4247
|
+
if ((0, import_utils24.isDefined)(resourceCacheTTL)) {
|
4248
|
+
if (resourceCacheTTL !== -1) {
|
4249
|
+
this.cache = new ResourceCache(resourceCacheTTL);
|
4250
|
+
} else {
|
4251
|
+
this.cache = void 0;
|
4252
|
+
}
|
4253
|
+
} else {
|
4254
|
+
this.cache = new ResourceCache(DEFAULT_RESOURCE_CACHE_TTL);
|
4255
|
+
}
|
4100
4256
|
}
|
4101
4257
|
/** @hidden */
|
4102
4258
|
static clearChainAndNodeCaches() {
|
@@ -4140,8 +4296,8 @@ var _Provider = class {
|
|
4140
4296
|
getChain() {
|
4141
4297
|
const chain = _Provider.chainInfoCache[this.url];
|
4142
4298
|
if (!chain) {
|
4143
|
-
throw new
|
4144
|
-
|
4299
|
+
throw new import_errors15.FuelError(
|
4300
|
+
import_errors15.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
4145
4301
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4146
4302
|
);
|
4147
4303
|
}
|
@@ -4155,8 +4311,8 @@ var _Provider = class {
|
|
4155
4311
|
getNode() {
|
4156
4312
|
const node = _Provider.nodeInfoCache[this.url];
|
4157
4313
|
if (!node) {
|
4158
|
-
throw new
|
4159
|
-
|
4314
|
+
throw new import_errors15.FuelError(
|
4315
|
+
import_errors15.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
4160
4316
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4161
4317
|
);
|
4162
4318
|
}
|
@@ -4234,8 +4390,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4234
4390
|
if ("response" in response) {
|
4235
4391
|
const graphQlResponse = response.response;
|
4236
4392
|
if (Array.isArray(graphQlResponse?.errors)) {
|
4237
|
-
throw new
|
4238
|
-
|
4393
|
+
throw new import_errors15.FuelError(
|
4394
|
+
import_errors15.FuelError.CODES.INVALID_REQUEST,
|
4239
4395
|
graphQlResponse.errors.map((err) => err.message).join("\n\n")
|
4240
4396
|
);
|
4241
4397
|
}
|
@@ -4327,6 +4483,21 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4327
4483
|
} = this.getChain();
|
4328
4484
|
return baseAssetId;
|
4329
4485
|
}
|
4486
|
+
validateTransaction(tx, consensusParameters) {
|
4487
|
+
const { maxOutputs, maxInputs } = consensusParameters.txParameters;
|
4488
|
+
if ((0, import_math17.bn)(tx.inputs.length).gt(maxInputs)) {
|
4489
|
+
throw new import_errors15.FuelError(
|
4490
|
+
import_errors15.ErrorCode.MAX_INPUTS_EXCEEDED,
|
4491
|
+
"The transaction exceeds the maximum allowed number of inputs."
|
4492
|
+
);
|
4493
|
+
}
|
4494
|
+
if ((0, import_math17.bn)(tx.outputs.length).gt(maxOutputs)) {
|
4495
|
+
throw new import_errors15.FuelError(
|
4496
|
+
import_errors15.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
4497
|
+
"The transaction exceeds the maximum allowed number of outputs."
|
4498
|
+
);
|
4499
|
+
}
|
4500
|
+
}
|
4330
4501
|
/**
|
4331
4502
|
* Submits a transaction to the chain to be executed.
|
4332
4503
|
*
|
@@ -4338,38 +4509,22 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4338
4509
|
* @returns A promise that resolves to the transaction response object.
|
4339
4510
|
*/
|
4340
4511
|
// #region Provider-sendTransaction
|
4341
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true
|
4512
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
4342
4513
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4343
|
-
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs);
|
4344
4514
|
if (estimateTxDependencies) {
|
4345
4515
|
await this.estimateTxDependencies(transactionRequest);
|
4346
4516
|
}
|
4347
|
-
const
|
4517
|
+
const { consensusParameters } = this.getChain();
|
4518
|
+
this.validateTransaction(transactionRequest, consensusParameters);
|
4519
|
+
const encodedTransaction = (0, import_utils24.hexlify)(transactionRequest.toTransactionBytes());
|
4348
4520
|
let abis;
|
4349
|
-
if (transactionRequest
|
4521
|
+
if (isTransactionTypeScript(transactionRequest)) {
|
4350
4522
|
abis = transactionRequest.abis;
|
4351
4523
|
}
|
4352
|
-
if (awaitExecution) {
|
4353
|
-
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
4354
|
-
for await (const { submitAndAwait } of subscription) {
|
4355
|
-
if (submitAndAwait.type === "SqueezedOutStatus") {
|
4356
|
-
throw new import_errors14.FuelError(
|
4357
|
-
import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
4358
|
-
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
4359
|
-
);
|
4360
|
-
}
|
4361
|
-
if (submitAndAwait.type !== "SubmittedStatus") {
|
4362
|
-
break;
|
4363
|
-
}
|
4364
|
-
}
|
4365
|
-
const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
|
4366
|
-
const response = new TransactionResponse(transactionId2, this, abis);
|
4367
|
-
await response.fetch();
|
4368
|
-
return response;
|
4369
|
-
}
|
4370
4524
|
const {
|
4371
4525
|
submit: { id: transactionId }
|
4372
4526
|
} = await this.operations.submit({ encodedTransaction });
|
4527
|
+
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionId);
|
4373
4528
|
return new TransactionResponse(transactionId, this, abis);
|
4374
4529
|
}
|
4375
4530
|
/**
|
@@ -4387,7 +4542,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4387
4542
|
if (estimateTxDependencies) {
|
4388
4543
|
return this.estimateTxDependencies(transactionRequest);
|
4389
4544
|
}
|
4390
|
-
const encodedTransaction = (0,
|
4545
|
+
const encodedTransaction = (0, import_utils24.hexlify)(transactionRequest.toTransactionBytes());
|
4391
4546
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4392
4547
|
encodedTransactions: encodedTransaction,
|
4393
4548
|
utxoValidation: utxoValidation || false
|
@@ -4407,13 +4562,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4407
4562
|
async estimatePredicates(transactionRequest) {
|
4408
4563
|
const shouldEstimatePredicates = Boolean(
|
4409
4564
|
transactionRequest.inputs.find(
|
4410
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4565
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils25.equalBytes)((0, import_utils24.arrayify)(input.predicate), (0, import_utils24.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
|
4411
4566
|
)
|
4412
4567
|
);
|
4413
4568
|
if (!shouldEstimatePredicates) {
|
4414
4569
|
return transactionRequest;
|
4415
4570
|
}
|
4416
|
-
const encodedTransaction = (0,
|
4571
|
+
const encodedTransaction = (0, import_utils24.hexlify)(transactionRequest.toTransactionBytes());
|
4417
4572
|
const response = await this.operations.estimatePredicates({
|
4418
4573
|
encodedTransaction
|
4419
4574
|
});
|
@@ -4439,7 +4594,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4439
4594
|
* @returns A promise that resolves to the estimate transaction dependencies.
|
4440
4595
|
*/
|
4441
4596
|
async estimateTxDependencies(transactionRequest) {
|
4442
|
-
if (transactionRequest
|
4597
|
+
if (isTransactionTypeCreate(transactionRequest)) {
|
4443
4598
|
return {
|
4444
4599
|
receipts: [],
|
4445
4600
|
outputVariables: 0,
|
@@ -4454,14 +4609,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4454
4609
|
const {
|
4455
4610
|
dryRun: [{ receipts: rawReceipts, status }]
|
4456
4611
|
} = await this.operations.dryRun({
|
4457
|
-
encodedTransactions: [(0,
|
4612
|
+
encodedTransactions: [(0, import_utils24.hexlify)(transactionRequest.toTransactionBytes())],
|
4458
4613
|
utxoValidation: false
|
4459
4614
|
});
|
4460
4615
|
receipts = rawReceipts.map(processGqlReceipt);
|
4461
4616
|
dryRunStatus = status;
|
4462
4617
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4463
4618
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4464
|
-
if (hasMissingOutputs) {
|
4619
|
+
if (hasMissingOutputs && isTransactionTypeScript(transactionRequest)) {
|
4465
4620
|
outputVariables += missingOutputVariables.length;
|
4466
4621
|
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
4467
4622
|
missingOutputContractIds.forEach(({ contractId }) => {
|
@@ -4503,8 +4658,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4503
4658
|
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4504
4659
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4505
4660
|
allRequests.forEach((req, index) => {
|
4506
|
-
if (req
|
4507
|
-
serializedTransactionsMap.set(index, (0,
|
4661
|
+
if (isTransactionTypeScript(req)) {
|
4662
|
+
serializedTransactionsMap.set(index, (0, import_utils24.hexlify)(req.toTransactionBytes()));
|
4508
4663
|
}
|
4509
4664
|
});
|
4510
4665
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -4529,7 +4684,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4529
4684
|
);
|
4530
4685
|
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4531
4686
|
const request = allRequests[requestIdx];
|
4532
|
-
if (hasMissingOutputs && request
|
4687
|
+
if (hasMissingOutputs && isTransactionTypeScript(request)) {
|
4533
4688
|
result.outputVariables += missingOutputVariables.length;
|
4534
4689
|
request.addVariableOutputs(missingOutputVariables.length);
|
4535
4690
|
missingOutputContractIds.forEach(({ contractId }) => {
|
@@ -4540,7 +4695,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4540
4695
|
transactionRequest: request
|
4541
4696
|
});
|
4542
4697
|
request.maxFee = maxFee;
|
4543
|
-
serializedTransactionsMap.set(requestIdx, (0,
|
4698
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils24.hexlify)(request.toTransactionBytes()));
|
4544
4699
|
nextRoundTransactions.push(requestIdx);
|
4545
4700
|
}
|
4546
4701
|
}
|
@@ -4561,7 +4716,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4561
4716
|
if (estimateTxDependencies) {
|
4562
4717
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
4563
4718
|
}
|
4564
|
-
const encodedTransactions = transactionRequests.map((tx) => (0,
|
4719
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils24.hexlify)(tx.toTransactionBytes()));
|
4565
4720
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4566
4721
|
encodedTransactions,
|
4567
4722
|
utxoValidation: utxoValidation || false
|
@@ -4593,7 +4748,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4593
4748
|
tip: transactionRequest.tip
|
4594
4749
|
}).add(1);
|
4595
4750
|
let gasLimit = (0, import_math17.bn)(0);
|
4596
|
-
if (transactionRequest
|
4751
|
+
if (isTransactionTypeScript(transactionRequest)) {
|
4597
4752
|
gasLimit = transactionRequest.gasLimit;
|
4598
4753
|
if (transactionRequest.gasLimit.eq(0)) {
|
4599
4754
|
transactionRequest.gasLimit = minGas;
|
@@ -4635,7 +4790,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4635
4790
|
if (estimateTxDependencies) {
|
4636
4791
|
return this.estimateTxDependencies(transactionRequest);
|
4637
4792
|
}
|
4638
|
-
const encodedTransactions = [(0,
|
4793
|
+
const encodedTransactions = [(0, import_utils24.hexlify)(transactionRequest.toTransactionBytes())];
|
4639
4794
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4640
4795
|
encodedTransactions,
|
4641
4796
|
utxoValidation: true
|
@@ -4648,6 +4803,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4648
4803
|
return { receipts: callResult[0].receipts };
|
4649
4804
|
}
|
4650
4805
|
/**
|
4806
|
+
* @hidden
|
4807
|
+
*
|
4651
4808
|
* Returns a transaction cost to enable user
|
4652
4809
|
* to set gasLimit and also reserve balance amounts
|
4653
4810
|
* on the transaction.
|
@@ -4657,23 +4814,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4657
4814
|
*
|
4658
4815
|
* @returns A promise that resolves to the transaction cost object.
|
4659
4816
|
*/
|
4660
|
-
async getTransactionCost(transactionRequestLike, {
|
4817
|
+
async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
|
4661
4818
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4662
|
-
const isScriptTransaction = txRequestClone.type === import_transactions20.TransactionType.Script;
|
4663
|
-
const baseAssetId = this.getBaseAssetId();
|
4664
4819
|
const updateMaxFee = txRequestClone.maxFee.eq(0);
|
4665
|
-
const
|
4666
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4667
|
-
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4820
|
+
const isScriptTransaction = isTransactionTypeScript(txRequestClone);
|
4668
4821
|
if (isScriptTransaction) {
|
4669
4822
|
txRequestClone.gasLimit = (0, import_math17.bn)(0);
|
4670
4823
|
}
|
4671
|
-
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4672
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4673
|
-
}
|
4674
4824
|
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4675
4825
|
let addedSignatures = 0;
|
4676
|
-
if (signatureCallback &&
|
4826
|
+
if (signatureCallback && isTransactionTypeScript(signedRequest)) {
|
4677
4827
|
const lengthBefore = signedRequest.witnesses.length;
|
4678
4828
|
await signatureCallback(signedRequest);
|
4679
4829
|
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
@@ -4706,7 +4856,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4706
4856
|
}));
|
4707
4857
|
}
|
4708
4858
|
return {
|
4709
|
-
requiredQuantities: allQuantities,
|
4710
4859
|
receipts,
|
4711
4860
|
gasUsed,
|
4712
4861
|
gasPrice,
|
@@ -4722,34 +4871,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4722
4871
|
updateMaxFee
|
4723
4872
|
};
|
4724
4873
|
}
|
4725
|
-
/**
|
4726
|
-
* Get the required quantities and associated resources for a transaction.
|
4727
|
-
*
|
4728
|
-
* @param owner - address to add resources from.
|
4729
|
-
* @param transactionRequestLike - transaction request to populate resources for.
|
4730
|
-
* @param quantitiesToContract - quantities for the contract (optional).
|
4731
|
-
*
|
4732
|
-
* @returns a promise resolving to the required quantities for the transaction.
|
4733
|
-
*/
|
4734
|
-
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4735
|
-
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4736
|
-
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4737
|
-
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4738
|
-
quantitiesToContract
|
4739
|
-
});
|
4740
|
-
transactionRequest.addResources(
|
4741
|
-
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4742
|
-
);
|
4743
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4744
|
-
quantitiesToContract
|
4745
|
-
});
|
4746
|
-
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4747
|
-
return {
|
4748
|
-
resources,
|
4749
|
-
requiredQuantities,
|
4750
|
-
...txCost
|
4751
|
-
};
|
4752
|
-
}
|
4753
4874
|
/**
|
4754
4875
|
* Returns coins for the given owner.
|
4755
4876
|
*
|
@@ -4768,7 +4889,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4768
4889
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
4769
4890
|
inputArgs: paginationArgs
|
4770
4891
|
}),
|
4771
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4892
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils24.hexlify)(assetId) }
|
4772
4893
|
});
|
4773
4894
|
const coins = edges.map(({ node }) => ({
|
4774
4895
|
id: node.utxoId,
|
@@ -4794,19 +4915,18 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4794
4915
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4795
4916
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4796
4917
|
const excludeInput = {
|
4797
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4798
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4918
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils24.hexlify)(nonce)) || [],
|
4919
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils24.hexlify)(id)) || []
|
4799
4920
|
};
|
4800
4921
|
if (this.cache) {
|
4801
|
-
const
|
4802
|
-
|
4803
|
-
);
|
4804
|
-
excludeInput.utxos = Array.from(uniqueUtxos);
|
4922
|
+
const cached = this.cache.getActiveData();
|
4923
|
+
excludeInput.messages.push(...cached.messages);
|
4924
|
+
excludeInput.utxos.push(...cached.utxos);
|
4805
4925
|
}
|
4806
4926
|
const coinsQuery = {
|
4807
4927
|
owner: ownerAddress.toB256(),
|
4808
4928
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4809
|
-
assetId: (0,
|
4929
|
+
assetId: (0, import_utils24.hexlify)(assetId),
|
4810
4930
|
amount: amount.toString(10),
|
4811
4931
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4812
4932
|
})),
|
@@ -4915,7 +5035,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4915
5035
|
time: block.header.time,
|
4916
5036
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4917
5037
|
transactions: block.transactions.map(
|
4918
|
-
(tx) => new import_transactions20.TransactionCoder().decode((0,
|
5038
|
+
(tx) => new import_transactions20.TransactionCoder().decode((0, import_utils24.arrayify)(tx.rawPayload), 0)?.[0]
|
4919
5039
|
)
|
4920
5040
|
};
|
4921
5041
|
}
|
@@ -4931,7 +5051,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4931
5051
|
return null;
|
4932
5052
|
}
|
4933
5053
|
return new import_transactions20.TransactionCoder().decode(
|
4934
|
-
(0,
|
5054
|
+
(0, import_utils24.arrayify)(transaction.rawPayload),
|
4935
5055
|
0
|
4936
5056
|
)?.[0];
|
4937
5057
|
}
|
@@ -4946,7 +5066,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4946
5066
|
} = await this.operations.getTransactions(paginationArgs);
|
4947
5067
|
const coder = new import_transactions20.TransactionCoder();
|
4948
5068
|
const transactions = edges.map(
|
4949
|
-
({ node: { rawPayload } }) => coder.decode((0,
|
5069
|
+
({ node: { rawPayload } }) => coder.decode((0, import_utils24.arrayify)(rawPayload), 0)[0]
|
4950
5070
|
);
|
4951
5071
|
return { transactions, pageInfo };
|
4952
5072
|
}
|
@@ -4973,7 +5093,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4973
5093
|
async getContractBalance(contractId, assetId) {
|
4974
5094
|
const { contractBalance } = await this.operations.getContractBalance({
|
4975
5095
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4976
|
-
asset: (0,
|
5096
|
+
asset: (0, import_utils24.hexlify)(assetId)
|
4977
5097
|
});
|
4978
5098
|
return (0, import_math17.bn)(contractBalance.amount, 10);
|
4979
5099
|
}
|
@@ -4987,7 +5107,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4987
5107
|
async getBalance(owner, assetId) {
|
4988
5108
|
const { balance } = await this.operations.getBalance({
|
4989
5109
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4990
|
-
assetId: (0,
|
5110
|
+
assetId: (0, import_utils24.hexlify)(assetId)
|
4991
5111
|
});
|
4992
5112
|
return (0, import_math17.bn)(balance.amount, 10);
|
4993
5113
|
}
|
@@ -5067,8 +5187,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5067
5187
|
nonce
|
5068
5188
|
};
|
5069
5189
|
if (commitBlockId && commitBlockHeight) {
|
5070
|
-
throw new
|
5071
|
-
|
5190
|
+
throw new import_errors15.FuelError(
|
5191
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5072
5192
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5073
5193
|
);
|
5074
5194
|
}
|
@@ -5187,7 +5307,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5187
5307
|
async produceBlocks(amount, startTime) {
|
5188
5308
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
5189
5309
|
blocksToProduce: (0, import_math17.bn)(amount).toString(10),
|
5190
|
-
startTimestamp: startTime ?
|
5310
|
+
startTimestamp: startTime ? import_utils24.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
5191
5311
|
});
|
5192
5312
|
return (0, import_math17.bn)(latestBlockHeight);
|
5193
5313
|
}
|
@@ -5236,26 +5356,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5236
5356
|
const { paginationLimit, inputArgs = {} } = params;
|
5237
5357
|
const { first, last, after, before } = inputArgs;
|
5238
5358
|
if (after && before) {
|
5239
|
-
throw new
|
5240
|
-
|
5359
|
+
throw new import_errors15.FuelError(
|
5360
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5241
5361
|
'Pagination arguments "after" and "before" cannot be used together'
|
5242
5362
|
);
|
5243
5363
|
}
|
5244
5364
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5245
|
-
throw new
|
5246
|
-
|
5365
|
+
throw new import_errors15.FuelError(
|
5366
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5247
5367
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5248
5368
|
);
|
5249
5369
|
}
|
5250
5370
|
if (first && before) {
|
5251
|
-
throw new
|
5252
|
-
|
5371
|
+
throw new import_errors15.FuelError(
|
5372
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5253
5373
|
'The use of pagination argument "first" with "before" is not supported'
|
5254
5374
|
);
|
5255
5375
|
}
|
5256
5376
|
if (last && after) {
|
5257
|
-
throw new
|
5258
|
-
|
5377
|
+
throw new import_errors15.FuelError(
|
5378
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5259
5379
|
'The use of pagination argument "last" with "after" is not supported'
|
5260
5380
|
);
|
5261
5381
|
}
|
@@ -5286,15 +5406,22 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5286
5406
|
};
|
5287
5407
|
var Provider = _Provider;
|
5288
5408
|
_cacheInputs = new WeakSet();
|
5289
|
-
cacheInputs_fn = function(inputs) {
|
5409
|
+
cacheInputs_fn = function(inputs, transactionId) {
|
5290
5410
|
if (!this.cache) {
|
5291
5411
|
return;
|
5292
5412
|
}
|
5293
|
-
inputs.
|
5294
|
-
|
5295
|
-
|
5296
|
-
|
5297
|
-
|
5413
|
+
const inputsToCache = inputs.reduce(
|
5414
|
+
(acc, input) => {
|
5415
|
+
if (input.type === import_transactions20.InputType.Coin) {
|
5416
|
+
acc.utxos.push(input.id);
|
5417
|
+
} else if (input.type === import_transactions20.InputType.Message) {
|
5418
|
+
acc.messages.push(input.nonce);
|
5419
|
+
}
|
5420
|
+
return acc;
|
5421
|
+
},
|
5422
|
+
{ utxos: [], messages: [] }
|
5423
|
+
);
|
5424
|
+
this.cache.set(transactionId, inputsToCache);
|
5298
5425
|
};
|
5299
5426
|
/** @hidden */
|
5300
5427
|
__publicField(Provider, "chainInfoCache", {});
|
@@ -5302,23 +5429,23 @@ __publicField(Provider, "chainInfoCache", {});
|
|
5302
5429
|
__publicField(Provider, "nodeInfoCache", {});
|
5303
5430
|
|
5304
5431
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
5305
|
-
var
|
5432
|
+
var import_errors16 = require("@fuel-ts/errors");
|
5306
5433
|
var import_math18 = require("@fuel-ts/math");
|
5307
5434
|
var import_transactions21 = require("@fuel-ts/transactions");
|
5308
|
-
var
|
5435
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5309
5436
|
async function getTransactionSummary(params) {
|
5310
5437
|
const { id, provider, abiMap } = params;
|
5311
5438
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
5312
5439
|
transactionId: id
|
5313
5440
|
});
|
5314
5441
|
if (!gqlTransaction) {
|
5315
|
-
throw new
|
5316
|
-
|
5442
|
+
throw new import_errors16.FuelError(
|
5443
|
+
import_errors16.ErrorCode.TRANSACTION_NOT_FOUND,
|
5317
5444
|
`Transaction not found for given id: ${id}.`
|
5318
5445
|
);
|
5319
5446
|
}
|
5320
5447
|
const [decodedTransaction] = new import_transactions21.TransactionCoder().decode(
|
5321
|
-
(0,
|
5448
|
+
(0, import_utils27.arrayify)(gqlTransaction.rawPayload),
|
5322
5449
|
0
|
5323
5450
|
);
|
5324
5451
|
let txReceipts = [];
|
@@ -5339,7 +5466,7 @@ async function getTransactionSummary(params) {
|
|
5339
5466
|
id: gqlTransaction.id,
|
5340
5467
|
receipts,
|
5341
5468
|
transaction: decodedTransaction,
|
5342
|
-
transactionBytes: (0,
|
5469
|
+
transactionBytes: (0, import_utils27.arrayify)(gqlTransaction.rawPayload),
|
5343
5470
|
gqlTransactionStatus: gqlTransaction.status,
|
5344
5471
|
gasPerByte: (0, import_math18.bn)(gasPerByte),
|
5345
5472
|
gasPriceFactor: (0, import_math18.bn)(gasPriceFactor),
|
@@ -5395,7 +5522,7 @@ async function getTransactionsSummaries(params) {
|
|
5395
5522
|
const transactions = edges.map((edge) => {
|
5396
5523
|
const { node: gqlTransaction } = edge;
|
5397
5524
|
const { id, rawPayload, status } = gqlTransaction;
|
5398
|
-
const [decodedTransaction] = new import_transactions21.TransactionCoder().decode((0,
|
5525
|
+
const [decodedTransaction] = new import_transactions21.TransactionCoder().decode((0, import_utils27.arrayify)(rawPayload), 0);
|
5399
5526
|
let txReceipts = [];
|
5400
5527
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
5401
5528
|
txReceipts = gqlTransaction.status.receipts;
|
@@ -5405,7 +5532,7 @@ async function getTransactionsSummaries(params) {
|
|
5405
5532
|
id,
|
5406
5533
|
receipts,
|
5407
5534
|
transaction: decodedTransaction,
|
5408
|
-
transactionBytes: (0,
|
5535
|
+
transactionBytes: (0, import_utils27.arrayify)(rawPayload),
|
5409
5536
|
gqlTransactionStatus: status,
|
5410
5537
|
abiMap,
|
5411
5538
|
gasPerByte,
|
@@ -5553,19 +5680,33 @@ var rawAssets = [
|
|
5553
5680
|
];
|
5554
5681
|
var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
|
5555
5682
|
|
5683
|
+
// src/providers/utils/merge-quantities.ts
|
5684
|
+
var mergeQuantities = (...coinQuantities) => {
|
5685
|
+
const resultMap = {};
|
5686
|
+
function addToMap({ amount, assetId }) {
|
5687
|
+
if (resultMap[assetId]) {
|
5688
|
+
resultMap[assetId] = resultMap[assetId].add(amount);
|
5689
|
+
} else {
|
5690
|
+
resultMap[assetId] = amount;
|
5691
|
+
}
|
5692
|
+
}
|
5693
|
+
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
5694
|
+
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
5695
|
+
};
|
5696
|
+
|
5556
5697
|
// src/utils/formatTransferToContractScriptData.ts
|
5557
5698
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
5558
5699
|
var import_math19 = require("@fuel-ts/math");
|
5559
|
-
var
|
5700
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5560
5701
|
var asm = __toESM(require("@fuels/vm-asm"));
|
5561
5702
|
var formatTransferToContractScriptData = (params) => {
|
5562
5703
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
5563
5704
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
5564
5705
|
const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
|
5565
5706
|
const scriptData = Uint8Array.from([
|
5566
|
-
...(0,
|
5707
|
+
...(0, import_utils29.arrayify)(hexlifiedContractId),
|
5567
5708
|
...encoded,
|
5568
|
-
...(0,
|
5709
|
+
...(0, import_utils29.arrayify)(assetId)
|
5569
5710
|
]);
|
5570
5711
|
return scriptData;
|
5571
5712
|
};
|
@@ -5590,7 +5731,7 @@ var assembleTransferToContractScript = async (params) => {
|
|
5590
5731
|
};
|
5591
5732
|
|
5592
5733
|
// src/account.ts
|
5593
|
-
var MAX_FUNDING_ATTEMPTS =
|
5734
|
+
var MAX_FUNDING_ATTEMPTS = 5;
|
5594
5735
|
var Account = class extends import_interfaces.AbstractAccount {
|
5595
5736
|
/**
|
5596
5737
|
* The address associated with the account.
|
@@ -5626,7 +5767,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5626
5767
|
*/
|
5627
5768
|
get provider() {
|
5628
5769
|
if (!this._provider) {
|
5629
|
-
throw new
|
5770
|
+
throw new import_errors17.FuelError(import_errors17.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
5630
5771
|
}
|
5631
5772
|
return this._provider;
|
5632
5773
|
}
|
@@ -5703,7 +5844,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5703
5844
|
* @returns A promise that resolves to the funded transaction request.
|
5704
5845
|
*/
|
5705
5846
|
async fund(request, params) {
|
5706
|
-
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee } = params;
|
5847
|
+
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee, gasPrice } = params;
|
5707
5848
|
const fee = request.maxFee;
|
5708
5849
|
const baseAssetId = this.provider.getBaseAssetId();
|
5709
5850
|
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math20.bn)(0);
|
@@ -5751,10 +5892,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5751
5892
|
);
|
5752
5893
|
}
|
5753
5894
|
if (!updateMaxFee) {
|
5895
|
+
needsToBeFunded = false;
|
5754
5896
|
break;
|
5755
5897
|
}
|
5756
5898
|
const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
|
5757
|
-
transactionRequest: requestToReestimate2
|
5899
|
+
transactionRequest: requestToReestimate2,
|
5900
|
+
gasPrice
|
5758
5901
|
});
|
5759
5902
|
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
5760
5903
|
request.inputs,
|
@@ -5774,6 +5917,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5774
5917
|
}
|
5775
5918
|
fundingAttempts += 1;
|
5776
5919
|
}
|
5920
|
+
if (needsToBeFunded) {
|
5921
|
+
throw new import_errors17.FuelError(
|
5922
|
+
import_errors17.ErrorCode.NOT_ENOUGH_FUNDS,
|
5923
|
+
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
5924
|
+
);
|
5925
|
+
}
|
5777
5926
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5778
5927
|
const requestToReestimate = (0, import_ramda4.clone)(request);
|
5779
5928
|
if (addedSignatures) {
|
@@ -5875,8 +6024,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5875
6024
|
*/
|
5876
6025
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5877
6026
|
if ((0, import_math20.bn)(amount).lte(0)) {
|
5878
|
-
throw new
|
5879
|
-
|
6027
|
+
throw new import_errors17.FuelError(
|
6028
|
+
import_errors17.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5880
6029
|
"Transfer amount must be a positive number."
|
5881
6030
|
);
|
5882
6031
|
}
|
@@ -5893,9 +6042,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5893
6042
|
scriptData
|
5894
6043
|
});
|
5895
6044
|
request.addContractInputAndOutput(contractAddress);
|
5896
|
-
const txCost = await this.
|
5897
|
-
|
5898
|
-
quantitiesToContract: [{ amount: (0, import_math20.bn)(amount), assetId: String(assetIdToTransfer) }]
|
6045
|
+
const txCost = await this.getTransactionCost(request, {
|
6046
|
+
quantities: [{ amount: (0, import_math20.bn)(amount), assetId: String(assetIdToTransfer) }]
|
5899
6047
|
});
|
5900
6048
|
request = this.validateGasLimitAndMaxFee({
|
5901
6049
|
transactionRequest: request,
|
@@ -5916,22 +6064,22 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5916
6064
|
*/
|
5917
6065
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5918
6066
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5919
|
-
const recipientDataArray = (0,
|
6067
|
+
const recipientDataArray = (0, import_utils30.arrayify)(
|
5920
6068
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5921
6069
|
);
|
5922
|
-
const amountDataArray = (0,
|
6070
|
+
const amountDataArray = (0, import_utils30.arrayify)(
|
5923
6071
|
"0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5924
6072
|
);
|
5925
6073
|
const script = new Uint8Array([
|
5926
|
-
...(0,
|
6074
|
+
...(0, import_utils30.arrayify)(withdrawScript.bytes),
|
5927
6075
|
...recipientDataArray,
|
5928
6076
|
...amountDataArray
|
5929
6077
|
]);
|
5930
6078
|
const params = { script, ...txParams };
|
5931
6079
|
const baseAssetId = this.provider.getBaseAssetId();
|
5932
6080
|
let request = new ScriptTransactionRequest(params);
|
5933
|
-
const
|
5934
|
-
const txCost = await this.
|
6081
|
+
const quantities = [{ amount: (0, import_math20.bn)(amount), assetId: baseAssetId }];
|
6082
|
+
const txCost = await this.getTransactionCost(request, { quantities });
|
5935
6083
|
request = this.validateGasLimitAndMaxFee({
|
5936
6084
|
transactionRequest: request,
|
5937
6085
|
gasUsed: txCost.gasUsed,
|
@@ -5941,6 +6089,34 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5941
6089
|
await this.fund(request, txCost);
|
5942
6090
|
return this.sendTransaction(request);
|
5943
6091
|
}
|
6092
|
+
/**
|
6093
|
+
* Returns a transaction cost to enable user
|
6094
|
+
* to set gasLimit and also reserve balance amounts
|
6095
|
+
* on the transaction.
|
6096
|
+
*
|
6097
|
+
* @param transactionRequestLike - The transaction request object.
|
6098
|
+
* @param transactionCostParams - The transaction cost parameters (optional).
|
6099
|
+
*
|
6100
|
+
* @returns A promise that resolves to the transaction cost object.
|
6101
|
+
*/
|
6102
|
+
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
|
6103
|
+
const txRequestClone = (0, import_ramda4.clone)(transactionRequestify(transactionRequestLike));
|
6104
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
6105
|
+
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
6106
|
+
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
6107
|
+
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math20.bn)("100000000000000000") }];
|
6108
|
+
const resources = this.generateFakeResources(
|
6109
|
+
mergeQuantities(requiredQuantities, transactionFeeForDryRun)
|
6110
|
+
);
|
6111
|
+
txRequestClone.addResources(resources);
|
6112
|
+
const txCost = await this.provider.getTransactionCost(txRequestClone, {
|
6113
|
+
signatureCallback
|
6114
|
+
});
|
6115
|
+
return {
|
6116
|
+
...txCost,
|
6117
|
+
requiredQuantities
|
6118
|
+
};
|
6119
|
+
}
|
5944
6120
|
/**
|
5945
6121
|
* Sign a message from the account via the connector.
|
5946
6122
|
*
|
@@ -5951,7 +6127,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5951
6127
|
*/
|
5952
6128
|
async signMessage(message) {
|
5953
6129
|
if (!this._connector) {
|
5954
|
-
throw new
|
6130
|
+
throw new import_errors17.FuelError(import_errors17.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5955
6131
|
}
|
5956
6132
|
return this._connector.signMessage(this.address.toString(), message);
|
5957
6133
|
}
|
@@ -5963,8 +6139,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5963
6139
|
*/
|
5964
6140
|
async signTransaction(transactionRequestLike) {
|
5965
6141
|
if (!this._connector) {
|
5966
|
-
throw new
|
5967
|
-
|
6142
|
+
throw new import_errors17.FuelError(
|
6143
|
+
import_errors17.ErrorCode.MISSING_CONNECTOR,
|
5968
6144
|
"A connector is required to sign transactions."
|
5969
6145
|
);
|
5970
6146
|
}
|
@@ -5977,7 +6153,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5977
6153
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
5978
6154
|
* @returns A promise that resolves to the transaction response.
|
5979
6155
|
*/
|
5980
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true
|
6156
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
5981
6157
|
if (this._connector) {
|
5982
6158
|
return this.provider.getTransactionResponse(
|
5983
6159
|
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike)
|
@@ -5988,7 +6164,6 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5988
6164
|
await this.provider.estimateTxDependencies(transactionRequest);
|
5989
6165
|
}
|
5990
6166
|
return this.provider.sendTransaction(transactionRequest, {
|
5991
|
-
awaitExecution,
|
5992
6167
|
estimateTxDependencies: false
|
5993
6168
|
});
|
5994
6169
|
}
|
@@ -6014,7 +6189,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6014
6189
|
*/
|
6015
6190
|
generateFakeResources(coins) {
|
6016
6191
|
return coins.map((coin) => ({
|
6017
|
-
id: (0,
|
6192
|
+
id: (0, import_utils30.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
6018
6193
|
owner: this.address,
|
6019
6194
|
blockCreated: (0, import_math20.bn)(1),
|
6020
6195
|
txCreatedIdx: (0, import_math20.bn)(1),
|
@@ -6024,8 +6199,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6024
6199
|
/** @hidden * */
|
6025
6200
|
validateTransferAmount(amount) {
|
6026
6201
|
if ((0, import_math20.bn)(amount).lte(0)) {
|
6027
|
-
throw new
|
6028
|
-
|
6202
|
+
throw new import_errors17.FuelError(
|
6203
|
+
import_errors17.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
6029
6204
|
"Transfer amount must be a positive number."
|
6030
6205
|
);
|
6031
6206
|
}
|
@@ -6033,9 +6208,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6033
6208
|
/** @hidden * */
|
6034
6209
|
async estimateAndFundTransaction(transactionRequest, txParams) {
|
6035
6210
|
let request = transactionRequest;
|
6036
|
-
const txCost = await this.
|
6037
|
-
resourcesOwner: this
|
6038
|
-
});
|
6211
|
+
const txCost = await this.getTransactionCost(request);
|
6039
6212
|
request = this.validateGasLimitAndMaxFee({
|
6040
6213
|
transactionRequest: request,
|
6041
6214
|
gasUsed: txCost.gasUsed,
|
@@ -6053,19 +6226,19 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6053
6226
|
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
6054
6227
|
}) {
|
6055
6228
|
const request = transactionRequestify(transactionRequest);
|
6056
|
-
if (!(0,
|
6229
|
+
if (!(0, import_utils30.isDefined)(setGasLimit)) {
|
6057
6230
|
request.gasLimit = gasUsed;
|
6058
6231
|
} else if (gasUsed.gt(setGasLimit)) {
|
6059
|
-
throw new
|
6060
|
-
|
6232
|
+
throw new import_errors17.FuelError(
|
6233
|
+
import_errors17.ErrorCode.GAS_LIMIT_TOO_LOW,
|
6061
6234
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
6062
6235
|
);
|
6063
6236
|
}
|
6064
|
-
if (!(0,
|
6237
|
+
if (!(0, import_utils30.isDefined)(setMaxFee)) {
|
6065
6238
|
request.maxFee = maxFee;
|
6066
6239
|
} else if (maxFee.gt(setMaxFee)) {
|
6067
|
-
throw new
|
6068
|
-
|
6240
|
+
throw new import_errors17.FuelError(
|
6241
|
+
import_errors17.ErrorCode.MAX_FEE_TOO_LOW,
|
6069
6242
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
6070
6243
|
);
|
6071
6244
|
}
|
@@ -6075,14 +6248,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6075
6248
|
|
6076
6249
|
// src/wallet/base-wallet-unlocked.ts
|
6077
6250
|
var import_hasher3 = require("@fuel-ts/hasher");
|
6078
|
-
var
|
6251
|
+
var import_utils33 = require("@fuel-ts/utils");
|
6079
6252
|
|
6080
6253
|
// src/signer/signer.ts
|
6081
6254
|
var import_address5 = require("@fuel-ts/address");
|
6082
6255
|
var import_crypto3 = require("@fuel-ts/crypto");
|
6083
6256
|
var import_hasher2 = require("@fuel-ts/hasher");
|
6084
6257
|
var import_math21 = require("@fuel-ts/math");
|
6085
|
-
var
|
6258
|
+
var import_utils31 = require("@fuel-ts/utils");
|
6086
6259
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
6087
6260
|
var Signer = class {
|
6088
6261
|
address;
|
@@ -6102,9 +6275,9 @@ var Signer = class {
|
|
6102
6275
|
}
|
6103
6276
|
}
|
6104
6277
|
const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
|
6105
|
-
this.privateKey = (0,
|
6106
|
-
this.publicKey = (0,
|
6107
|
-
this.compressedPublicKey = (0,
|
6278
|
+
this.privateKey = (0, import_utils31.hexlify)(privateKeyBytes);
|
6279
|
+
this.publicKey = (0, import_utils31.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
6280
|
+
this.compressedPublicKey = (0, import_utils31.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
6108
6281
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
6109
6282
|
}
|
6110
6283
|
/**
|
@@ -6118,11 +6291,11 @@ var Signer = class {
|
|
6118
6291
|
* @returns hashed signature
|
6119
6292
|
*/
|
6120
6293
|
sign(data) {
|
6121
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
6294
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils31.arrayify)(data), (0, import_utils31.arrayify)(this.privateKey));
|
6122
6295
|
const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
6123
6296
|
const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
6124
6297
|
s[0] |= (signature.recovery || 0) << 7;
|
6125
|
-
return (0,
|
6298
|
+
return (0, import_utils31.hexlify)((0, import_utils31.concat)([r, s]));
|
6126
6299
|
}
|
6127
6300
|
/**
|
6128
6301
|
* Add point on the current elliptic curve
|
@@ -6131,8 +6304,8 @@ var Signer = class {
|
|
6131
6304
|
* @returns compressed point on the curve
|
6132
6305
|
*/
|
6133
6306
|
addPoint(point) {
|
6134
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
6135
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
6307
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils31.arrayify)(this.compressedPublicKey));
|
6308
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils31.arrayify)(point));
|
6136
6309
|
const result = p0.add(p1);
|
6137
6310
|
return `0x${result.toHex(true)}`;
|
6138
6311
|
}
|
@@ -6144,16 +6317,16 @@ var Signer = class {
|
|
6144
6317
|
* @returns public key from signature from the
|
6145
6318
|
*/
|
6146
6319
|
static recoverPublicKey(data, signature) {
|
6147
|
-
const signedMessageBytes = (0,
|
6320
|
+
const signedMessageBytes = (0, import_utils31.arrayify)(signature);
|
6148
6321
|
const r = signedMessageBytes.slice(0, 32);
|
6149
6322
|
const s = signedMessageBytes.slice(32, 64);
|
6150
6323
|
const recoveryParam = (s[0] & 128) >> 7;
|
6151
6324
|
s[0] &= 127;
|
6152
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
6325
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils31.hexlify)(r)), BigInt((0, import_utils31.hexlify)(s))).addRecoveryBit(
|
6153
6326
|
recoveryParam
|
6154
6327
|
);
|
6155
|
-
const publicKey = sig.recoverPublicKey((0,
|
6156
|
-
return (0,
|
6328
|
+
const publicKey = sig.recoverPublicKey((0, import_utils31.arrayify)(data)).toRawBytes(false).slice(1);
|
6329
|
+
return (0, import_utils31.hexlify)(publicKey);
|
6157
6330
|
}
|
6158
6331
|
/**
|
6159
6332
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -6172,7 +6345,7 @@ var Signer = class {
|
|
6172
6345
|
* @returns random 32-byte hashed
|
6173
6346
|
*/
|
6174
6347
|
static generatePrivateKey(entropy) {
|
6175
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
6348
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils31.concat)([(0, import_crypto3.randomBytes)(32), (0, import_utils31.arrayify)(entropy)])) : (0, import_crypto3.randomBytes)(32);
|
6176
6349
|
}
|
6177
6350
|
/**
|
6178
6351
|
* Extended publicKey from a compact publicKey
|
@@ -6181,17 +6354,16 @@ var Signer = class {
|
|
6181
6354
|
* @returns extended publicKey
|
6182
6355
|
*/
|
6183
6356
|
static extendPublicKey(publicKey) {
|
6184
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
6185
|
-
return (0,
|
6357
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils31.arrayify)(publicKey));
|
6358
|
+
return (0, import_utils31.hexlify)(point.toRawBytes(false).slice(1));
|
6186
6359
|
}
|
6187
6360
|
};
|
6188
6361
|
|
6189
6362
|
// src/wallet/keystore-wallet.ts
|
6190
6363
|
var import_address6 = require("@fuel-ts/address");
|
6191
6364
|
var import_crypto4 = require("@fuel-ts/crypto");
|
6192
|
-
var
|
6193
|
-
var
|
6194
|
-
var import_uuid = require("uuid");
|
6365
|
+
var import_errors18 = require("@fuel-ts/errors");
|
6366
|
+
var import_utils32 = require("@fuel-ts/utils");
|
6195
6367
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
6196
6368
|
var DEFAULT_KDF_PARAMS_R = 8;
|
6197
6369
|
var DEFAULT_KDF_PARAMS_P = 1;
|
@@ -6221,7 +6393,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
6221
6393
|
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
6222
6394
|
const mac = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
6223
6395
|
const keystore = {
|
6224
|
-
id: (0,
|
6396
|
+
id: (0, import_crypto4.randomUUID)(),
|
6225
6397
|
version: 3,
|
6226
6398
|
address: removeHexPrefix(ownerAddress.toHexString()),
|
6227
6399
|
crypto: {
|
@@ -6267,13 +6439,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
6267
6439
|
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
6268
6440
|
const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
6269
6441
|
if (mac !== macHash) {
|
6270
|
-
throw new
|
6271
|
-
|
6442
|
+
throw new import_errors18.FuelError(
|
6443
|
+
import_errors18.ErrorCode.INVALID_PASSWORD,
|
6272
6444
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
6273
6445
|
);
|
6274
6446
|
}
|
6275
6447
|
const buffer = await (0, import_crypto4.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
6276
|
-
const privateKey = (0,
|
6448
|
+
const privateKey = (0, import_utils32.hexlify)(buffer);
|
6277
6449
|
return privateKey;
|
6278
6450
|
}
|
6279
6451
|
|
@@ -6318,7 +6490,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
6318
6490
|
*/
|
6319
6491
|
async signMessage(message) {
|
6320
6492
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
6321
|
-
return (0,
|
6493
|
+
return (0, import_utils33.hexlify)(signedMessage);
|
6322
6494
|
}
|
6323
6495
|
/**
|
6324
6496
|
* Signs a transaction with the wallet's private key.
|
@@ -6331,7 +6503,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
6331
6503
|
const chainId = this.provider.getChainId();
|
6332
6504
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
6333
6505
|
const signature = await this.signer().sign(hashedTransaction);
|
6334
|
-
return (0,
|
6506
|
+
return (0, import_utils33.hexlify)(signature);
|
6335
6507
|
}
|
6336
6508
|
/**
|
6337
6509
|
* Populates a transaction with the witnesses signature.
|
@@ -6350,17 +6522,16 @@ var BaseWalletUnlocked = class extends Account {
|
|
6350
6522
|
*
|
6351
6523
|
* @param transactionRequestLike - The transaction request to send.
|
6352
6524
|
* @param estimateTxDependencies - Whether to estimate the transaction dependencies.
|
6353
|
-
* @param awaitExecution - Whether to wait for the transaction to be executed.
|
6354
6525
|
* @returns A promise that resolves to the TransactionResponse object.
|
6355
6526
|
*/
|
6356
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false
|
6527
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false } = {}) {
|
6357
6528
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
6358
6529
|
if (estimateTxDependencies) {
|
6359
6530
|
await this.provider.estimateTxDependencies(transactionRequest);
|
6360
6531
|
}
|
6361
6532
|
return this.provider.sendTransaction(
|
6362
6533
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
6363
|
-
{
|
6534
|
+
{ estimateTxDependencies: false }
|
6364
6535
|
);
|
6365
6536
|
}
|
6366
6537
|
/**
|
@@ -6399,16 +6570,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
6399
6570
|
|
6400
6571
|
// src/hdwallet/hdwallet.ts
|
6401
6572
|
var import_crypto6 = require("@fuel-ts/crypto");
|
6402
|
-
var
|
6573
|
+
var import_errors21 = require("@fuel-ts/errors");
|
6403
6574
|
var import_hasher6 = require("@fuel-ts/hasher");
|
6404
6575
|
var import_math22 = require("@fuel-ts/math");
|
6405
|
-
var
|
6576
|
+
var import_utils37 = require("@fuel-ts/utils");
|
6406
6577
|
|
6407
6578
|
// src/mnemonic/mnemonic.ts
|
6408
6579
|
var import_crypto5 = require("@fuel-ts/crypto");
|
6409
|
-
var
|
6580
|
+
var import_errors20 = require("@fuel-ts/errors");
|
6410
6581
|
var import_hasher5 = require("@fuel-ts/hasher");
|
6411
|
-
var
|
6582
|
+
var import_utils35 = require("@fuel-ts/utils");
|
6412
6583
|
|
6413
6584
|
// src/wordlists/words/english.ts
|
6414
6585
|
var english = [
|
@@ -8469,9 +8640,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
8469
8640
|
})(Language || {});
|
8470
8641
|
|
8471
8642
|
// src/mnemonic/utils.ts
|
8472
|
-
var
|
8643
|
+
var import_errors19 = require("@fuel-ts/errors");
|
8473
8644
|
var import_hasher4 = require("@fuel-ts/hasher");
|
8474
|
-
var
|
8645
|
+
var import_utils34 = require("@fuel-ts/utils");
|
8475
8646
|
function getLowerMask(bits) {
|
8476
8647
|
return (1 << bits) - 1;
|
8477
8648
|
}
|
@@ -8506,20 +8677,20 @@ function entropyToMnemonicIndices(entropy) {
|
|
8506
8677
|
}
|
8507
8678
|
}
|
8508
8679
|
const checksumBits = entropy.length / 4;
|
8509
|
-
const checksum = (0,
|
8680
|
+
const checksum = (0, import_utils34.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
8510
8681
|
indices[indices.length - 1] <<= checksumBits;
|
8511
8682
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
8512
8683
|
return indices;
|
8513
8684
|
}
|
8514
8685
|
function mnemonicWordsToEntropy(words, wordlist) {
|
8515
8686
|
const size = Math.ceil(11 * words.length / 8);
|
8516
|
-
const entropy = (0,
|
8687
|
+
const entropy = (0, import_utils34.arrayify)(new Uint8Array(size));
|
8517
8688
|
let offset = 0;
|
8518
8689
|
for (let i = 0; i < words.length; i += 1) {
|
8519
8690
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
8520
8691
|
if (index === -1) {
|
8521
|
-
throw new
|
8522
|
-
|
8692
|
+
throw new import_errors19.FuelError(
|
8693
|
+
import_errors19.ErrorCode.INVALID_MNEMONIC,
|
8523
8694
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
8524
8695
|
);
|
8525
8696
|
}
|
@@ -8533,10 +8704,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8533
8704
|
const entropyBits = 32 * words.length / 3;
|
8534
8705
|
const checksumBits = words.length / 3;
|
8535
8706
|
const checksumMask = getUpperMask(checksumBits);
|
8536
|
-
const checksum = (0,
|
8707
|
+
const checksum = (0, import_utils34.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8537
8708
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8538
|
-
throw new
|
8539
|
-
|
8709
|
+
throw new import_errors19.FuelError(
|
8710
|
+
import_errors19.ErrorCode.INVALID_CHECKSUM,
|
8540
8711
|
"Checksum validation failed for the provided mnemonic."
|
8541
8712
|
);
|
8542
8713
|
}
|
@@ -8544,22 +8715,22 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8544
8715
|
}
|
8545
8716
|
|
8546
8717
|
// src/mnemonic/mnemonic.ts
|
8547
|
-
var MasterSecret = (0,
|
8718
|
+
var MasterSecret = (0, import_utils35.toUtf8Bytes)("Bitcoin seed");
|
8548
8719
|
var MainnetPRV = "0x0488ade4";
|
8549
8720
|
var TestnetPRV = "0x04358394";
|
8550
8721
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
8551
8722
|
function assertWordList(wordlist) {
|
8552
8723
|
if (wordlist.length !== 2048) {
|
8553
|
-
throw new
|
8554
|
-
|
8724
|
+
throw new import_errors20.FuelError(
|
8725
|
+
import_errors20.ErrorCode.INVALID_WORD_LIST,
|
8555
8726
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
8556
8727
|
);
|
8557
8728
|
}
|
8558
8729
|
}
|
8559
8730
|
function assertEntropy(entropy) {
|
8560
8731
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
8561
|
-
throw new
|
8562
|
-
|
8732
|
+
throw new import_errors20.FuelError(
|
8733
|
+
import_errors20.ErrorCode.INVALID_ENTROPY,
|
8563
8734
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
8564
8735
|
);
|
8565
8736
|
}
|
@@ -8569,7 +8740,7 @@ function assertMnemonic(words) {
|
|
8569
8740
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
8570
8741
|
", "
|
8571
8742
|
)}] words, but got ${words.length}.`;
|
8572
|
-
throw new
|
8743
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
8573
8744
|
}
|
8574
8745
|
}
|
8575
8746
|
var Mnemonic = class {
|
@@ -8608,7 +8779,7 @@ var Mnemonic = class {
|
|
8608
8779
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8609
8780
|
const words = getWords(phrase);
|
8610
8781
|
assertMnemonic(words);
|
8611
|
-
return (0,
|
8782
|
+
return (0, import_utils35.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
8612
8783
|
}
|
8613
8784
|
/**
|
8614
8785
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8616,7 +8787,7 @@ var Mnemonic = class {
|
|
8616
8787
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8617
8788
|
*/
|
8618
8789
|
static entropyToMnemonic(entropy, wordlist = english) {
|
8619
|
-
const entropyBytes = (0,
|
8790
|
+
const entropyBytes = (0, import_utils35.arrayify)(entropy);
|
8620
8791
|
assertWordList(wordlist);
|
8621
8792
|
assertEntropy(entropyBytes);
|
8622
8793
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8628,8 +8799,8 @@ var Mnemonic = class {
|
|
8628
8799
|
*/
|
8629
8800
|
static mnemonicToSeed(phrase, passphrase = "") {
|
8630
8801
|
assertMnemonic(getWords(phrase));
|
8631
|
-
const phraseBytes = (0,
|
8632
|
-
const salt = (0,
|
8802
|
+
const phraseBytes = (0, import_utils35.toUtf8Bytes)(getPhrase(phrase));
|
8803
|
+
const salt = (0, import_utils35.toUtf8Bytes)(`mnemonic${passphrase}`);
|
8633
8804
|
return (0, import_crypto5.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
8634
8805
|
}
|
8635
8806
|
/**
|
@@ -8685,14 +8856,14 @@ var Mnemonic = class {
|
|
8685
8856
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8686
8857
|
*/
|
8687
8858
|
static masterKeysFromSeed(seed) {
|
8688
|
-
const seedArray = (0,
|
8859
|
+
const seedArray = (0, import_utils35.arrayify)(seed);
|
8689
8860
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8690
|
-
throw new
|
8691
|
-
|
8861
|
+
throw new import_errors20.FuelError(
|
8862
|
+
import_errors20.ErrorCode.INVALID_SEED,
|
8692
8863
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8693
8864
|
);
|
8694
8865
|
}
|
8695
|
-
return (0,
|
8866
|
+
return (0, import_utils35.arrayify)((0, import_crypto5.computeHmac)("sha512", MasterSecret, seedArray));
|
8696
8867
|
}
|
8697
8868
|
/**
|
8698
8869
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8703,22 +8874,22 @@ var Mnemonic = class {
|
|
8703
8874
|
*/
|
8704
8875
|
static seedToExtendedKey(seed, testnet = false) {
|
8705
8876
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8706
|
-
const prefix = (0,
|
8877
|
+
const prefix = (0, import_utils35.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8707
8878
|
const depth = "0x00";
|
8708
8879
|
const fingerprint = "0x00000000";
|
8709
8880
|
const index = "0x00000000";
|
8710
8881
|
const chainCode = masterKey.slice(32);
|
8711
8882
|
const privateKey = masterKey.slice(0, 32);
|
8712
|
-
const extendedKey = (0,
|
8883
|
+
const extendedKey = (0, import_utils35.concat)([
|
8713
8884
|
prefix,
|
8714
8885
|
depth,
|
8715
8886
|
fingerprint,
|
8716
8887
|
index,
|
8717
8888
|
chainCode,
|
8718
|
-
(0,
|
8889
|
+
(0, import_utils35.concat)(["0x00", privateKey])
|
8719
8890
|
]);
|
8720
|
-
const checksum = (0,
|
8721
|
-
return (0,
|
8891
|
+
const checksum = (0, import_utils35.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8892
|
+
return (0, import_utils35.encodeBase58)((0, import_utils35.concat)([extendedKey, checksum]));
|
8722
8893
|
}
|
8723
8894
|
/**
|
8724
8895
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8733,7 +8904,7 @@ var Mnemonic = class {
|
|
8733
8904
|
* @returns A randomly generated mnemonic
|
8734
8905
|
*/
|
8735
8906
|
static generate(size = 32, extraEntropy = "") {
|
8736
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8907
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils35.concat)([(0, import_crypto5.randomBytes)(size), (0, import_utils35.arrayify)(extraEntropy)])) : (0, import_crypto5.randomBytes)(size);
|
8737
8908
|
return Mnemonic.entropyToMnemonic(entropy);
|
8738
8909
|
}
|
8739
8910
|
};
|
@@ -8741,12 +8912,12 @@ var mnemonic_default = Mnemonic;
|
|
8741
8912
|
|
8742
8913
|
// src/hdwallet/hdwallet.ts
|
8743
8914
|
var HARDENED_INDEX = 2147483648;
|
8744
|
-
var MainnetPRV2 = (0,
|
8745
|
-
var MainnetPUB = (0,
|
8746
|
-
var TestnetPRV2 = (0,
|
8747
|
-
var TestnetPUB = (0,
|
8915
|
+
var MainnetPRV2 = (0, import_utils37.hexlify)("0x0488ade4");
|
8916
|
+
var MainnetPUB = (0, import_utils37.hexlify)("0x0488b21e");
|
8917
|
+
var TestnetPRV2 = (0, import_utils37.hexlify)("0x04358394");
|
8918
|
+
var TestnetPUB = (0, import_utils37.hexlify)("0x043587cf");
|
8748
8919
|
function base58check(data) {
|
8749
|
-
return (0,
|
8920
|
+
return (0, import_utils37.encodeBase58)((0, import_utils37.concat)([data, (0, import_utils37.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8750
8921
|
}
|
8751
8922
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8752
8923
|
if (isPublic) {
|
@@ -8755,17 +8926,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8755
8926
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8756
8927
|
}
|
8757
8928
|
function isPublicExtendedKey(extendedKey) {
|
8758
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8929
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils37.hexlify)(extendedKey.slice(0, 4)));
|
8759
8930
|
}
|
8760
8931
|
function isValidExtendedKey(extendedKey) {
|
8761
8932
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8762
|
-
(0,
|
8933
|
+
(0, import_utils37.hexlify)(extendedKey.slice(0, 4))
|
8763
8934
|
);
|
8764
8935
|
}
|
8765
8936
|
function parsePath(path, depth = 0) {
|
8766
8937
|
const components = path.split("/");
|
8767
8938
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
8768
|
-
throw new
|
8939
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
|
8769
8940
|
}
|
8770
8941
|
if (components[0] === "m") {
|
8771
8942
|
components.shift();
|
@@ -8777,8 +8948,8 @@ function parsePath(path, depth = 0) {
|
|
8777
8948
|
var HDWallet = class {
|
8778
8949
|
depth = 0;
|
8779
8950
|
index = 0;
|
8780
|
-
fingerprint = (0,
|
8781
|
-
parentFingerprint = (0,
|
8951
|
+
fingerprint = (0, import_utils37.hexlify)("0x00000000");
|
8952
|
+
parentFingerprint = (0, import_utils37.hexlify)("0x00000000");
|
8782
8953
|
privateKey;
|
8783
8954
|
publicKey;
|
8784
8955
|
chainCode;
|
@@ -8790,19 +8961,19 @@ var HDWallet = class {
|
|
8790
8961
|
constructor(config) {
|
8791
8962
|
if (config.privateKey) {
|
8792
8963
|
const signer = new Signer(config.privateKey);
|
8793
|
-
this.publicKey = (0,
|
8794
|
-
this.privateKey = (0,
|
8964
|
+
this.publicKey = (0, import_utils37.hexlify)(signer.compressedPublicKey);
|
8965
|
+
this.privateKey = (0, import_utils37.hexlify)(config.privateKey);
|
8795
8966
|
} else {
|
8796
8967
|
if (!config.publicKey) {
|
8797
|
-
throw new
|
8798
|
-
|
8968
|
+
throw new import_errors21.FuelError(
|
8969
|
+
import_errors21.ErrorCode.HD_WALLET_ERROR,
|
8799
8970
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8800
8971
|
);
|
8801
8972
|
}
|
8802
|
-
this.publicKey = (0,
|
8973
|
+
this.publicKey = (0, import_utils37.hexlify)(config.publicKey);
|
8803
8974
|
}
|
8804
8975
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8805
|
-
this.fingerprint = (0,
|
8976
|
+
this.fingerprint = (0, import_utils37.dataSlice)((0, import_crypto6.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
8806
8977
|
this.depth = config.depth || this.depth;
|
8807
8978
|
this.index = config.index || this.index;
|
8808
8979
|
this.chainCode = config.chainCode;
|
@@ -8818,23 +8989,23 @@ var HDWallet = class {
|
|
8818
8989
|
* @returns A new instance of HDWallet on the derived index
|
8819
8990
|
*/
|
8820
8991
|
deriveIndex(index) {
|
8821
|
-
const privateKey = this.privateKey && (0,
|
8822
|
-
const publicKey = (0,
|
8823
|
-
const chainCode = (0,
|
8992
|
+
const privateKey = this.privateKey && (0, import_utils37.arrayify)(this.privateKey);
|
8993
|
+
const publicKey = (0, import_utils37.arrayify)(this.publicKey);
|
8994
|
+
const chainCode = (0, import_utils37.arrayify)(this.chainCode);
|
8824
8995
|
const data = new Uint8Array(37);
|
8825
8996
|
if (index & HARDENED_INDEX) {
|
8826
8997
|
if (!privateKey) {
|
8827
|
-
throw new
|
8828
|
-
|
8998
|
+
throw new import_errors21.FuelError(
|
8999
|
+
import_errors21.ErrorCode.HD_WALLET_ERROR,
|
8829
9000
|
"Cannot derive a hardened index without a private Key."
|
8830
9001
|
);
|
8831
9002
|
}
|
8832
9003
|
data.set(privateKey, 1);
|
8833
9004
|
} else {
|
8834
|
-
data.set((0,
|
9005
|
+
data.set((0, import_utils37.arrayify)(this.publicKey));
|
8835
9006
|
}
|
8836
9007
|
data.set((0, import_math22.toBytes)(index, 4), 33);
|
8837
|
-
const bytes = (0,
|
9008
|
+
const bytes = (0, import_utils37.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
|
8838
9009
|
const IL = bytes.slice(0, 32);
|
8839
9010
|
const IR = bytes.slice(32);
|
8840
9011
|
if (privateKey) {
|
@@ -8848,7 +9019,7 @@ var HDWallet = class {
|
|
8848
9019
|
parentFingerprint: this.fingerprint
|
8849
9020
|
});
|
8850
9021
|
}
|
8851
|
-
const signer = new Signer((0,
|
9022
|
+
const signer = new Signer((0, import_utils37.hexlify)(IL));
|
8852
9023
|
const Ki = signer.addPoint(publicKey);
|
8853
9024
|
return new HDWallet({
|
8854
9025
|
publicKey: Ki,
|
@@ -8877,18 +9048,18 @@ var HDWallet = class {
|
|
8877
9048
|
*/
|
8878
9049
|
toExtendedKey(isPublic = false, testnet = false) {
|
8879
9050
|
if (this.depth >= 256) {
|
8880
|
-
throw new
|
8881
|
-
|
9051
|
+
throw new import_errors21.FuelError(
|
9052
|
+
import_errors21.ErrorCode.HD_WALLET_ERROR,
|
8882
9053
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
8883
9054
|
);
|
8884
9055
|
}
|
8885
9056
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8886
|
-
const depth = (0,
|
9057
|
+
const depth = (0, import_utils37.hexlify)(Uint8Array.from([this.depth]));
|
8887
9058
|
const parentFingerprint = this.parentFingerprint;
|
8888
9059
|
const index = (0, import_math22.toHex)(this.index, 4);
|
8889
9060
|
const chainCode = this.chainCode;
|
8890
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8891
|
-
const extendedKey = (0,
|
9061
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils37.concat)(["0x00", this.privateKey]) : this.publicKey;
|
9062
|
+
const extendedKey = (0, import_utils37.arrayify)((0, import_utils37.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8892
9063
|
return base58check(extendedKey);
|
8893
9064
|
}
|
8894
9065
|
/**
|
@@ -8900,34 +9071,34 @@ var HDWallet = class {
|
|
8900
9071
|
static fromSeed(seed) {
|
8901
9072
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8902
9073
|
return new HDWallet({
|
8903
|
-
chainCode: (0,
|
8904
|
-
privateKey: (0,
|
9074
|
+
chainCode: (0, import_utils37.arrayify)(masterKey.slice(32)),
|
9075
|
+
privateKey: (0, import_utils37.arrayify)(masterKey.slice(0, 32))
|
8905
9076
|
});
|
8906
9077
|
}
|
8907
9078
|
static fromExtendedKey(extendedKey) {
|
8908
|
-
const decoded = (0,
|
8909
|
-
const bytes = (0,
|
9079
|
+
const decoded = (0, import_utils37.hexlify)((0, import_math22.toBytes)((0, import_utils37.decodeBase58)(extendedKey)));
|
9080
|
+
const bytes = (0, import_utils37.arrayify)(decoded);
|
8910
9081
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8911
9082
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8912
|
-
throw new
|
9083
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
8913
9084
|
}
|
8914
9085
|
if (!validChecksum) {
|
8915
|
-
throw new
|
9086
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8916
9087
|
}
|
8917
9088
|
const depth = bytes[4];
|
8918
|
-
const parentFingerprint = (0,
|
8919
|
-
const index = parseInt((0,
|
8920
|
-
const chainCode = (0,
|
9089
|
+
const parentFingerprint = (0, import_utils37.hexlify)(bytes.slice(5, 9));
|
9090
|
+
const index = parseInt((0, import_utils37.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
9091
|
+
const chainCode = (0, import_utils37.hexlify)(bytes.slice(13, 45));
|
8921
9092
|
const key = bytes.slice(45, 78);
|
8922
9093
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8923
|
-
throw new
|
8924
|
-
|
9094
|
+
throw new import_errors21.FuelError(
|
9095
|
+
import_errors21.ErrorCode.HD_WALLET_ERROR,
|
8925
9096
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
8926
9097
|
);
|
8927
9098
|
}
|
8928
9099
|
if (isPublicExtendedKey(bytes)) {
|
8929
9100
|
if (key[0] !== 3) {
|
8930
|
-
throw new
|
9101
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
8931
9102
|
}
|
8932
9103
|
return new HDWallet({
|
8933
9104
|
publicKey: key,
|
@@ -8938,7 +9109,7 @@ var HDWallet = class {
|
|
8938
9109
|
});
|
8939
9110
|
}
|
8940
9111
|
if (key[0] !== 0) {
|
8941
|
-
throw new
|
9112
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
8942
9113
|
}
|
8943
9114
|
return new HDWallet({
|
8944
9115
|
privateKey: key.slice(1),
|
@@ -9106,7 +9277,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
9106
9277
|
// src/wallet-manager/wallet-manager.ts
|
9107
9278
|
var import_address9 = require("@fuel-ts/address");
|
9108
9279
|
var import_crypto7 = require("@fuel-ts/crypto");
|
9109
|
-
var
|
9280
|
+
var import_errors24 = require("@fuel-ts/errors");
|
9110
9281
|
var import_events = require("events");
|
9111
9282
|
|
9112
9283
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -9129,7 +9300,7 @@ var MemoryStorage = class {
|
|
9129
9300
|
|
9130
9301
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
9131
9302
|
var import_address7 = require("@fuel-ts/address");
|
9132
|
-
var
|
9303
|
+
var import_errors22 = require("@fuel-ts/errors");
|
9133
9304
|
var _secret;
|
9134
9305
|
var MnemonicVault = class {
|
9135
9306
|
constructor(options) {
|
@@ -9185,8 +9356,8 @@ var MnemonicVault = class {
|
|
9185
9356
|
}
|
9186
9357
|
numberOfAccounts += 1;
|
9187
9358
|
} while (numberOfAccounts < this.numberOfAccounts);
|
9188
|
-
throw new
|
9189
|
-
|
9359
|
+
throw new import_errors22.FuelError(
|
9360
|
+
import_errors22.ErrorCode.WALLET_MANAGER_ERROR,
|
9190
9361
|
`Account with address '${address}' not found in derived wallets.`
|
9191
9362
|
);
|
9192
9363
|
}
|
@@ -9200,7 +9371,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
9200
9371
|
|
9201
9372
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
9202
9373
|
var import_address8 = require("@fuel-ts/address");
|
9203
|
-
var
|
9374
|
+
var import_errors23 = require("@fuel-ts/errors");
|
9204
9375
|
var _privateKeys;
|
9205
9376
|
var PrivateKeyVault = class {
|
9206
9377
|
/**
|
@@ -9241,8 +9412,8 @@ var PrivateKeyVault = class {
|
|
9241
9412
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
9242
9413
|
);
|
9243
9414
|
if (!privateKey) {
|
9244
|
-
throw new
|
9245
|
-
|
9415
|
+
throw new import_errors23.FuelError(
|
9416
|
+
import_errors23.ErrorCode.WALLET_MANAGER_ERROR,
|
9246
9417
|
`No private key found for address '${address}'.`
|
9247
9418
|
);
|
9248
9419
|
}
|
@@ -9266,7 +9437,7 @@ var ERROR_MESSAGES = {
|
|
9266
9437
|
};
|
9267
9438
|
function assert(condition, message) {
|
9268
9439
|
if (!condition) {
|
9269
|
-
throw new
|
9440
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.WALLET_MANAGER_ERROR, message);
|
9270
9441
|
}
|
9271
9442
|
}
|
9272
9443
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -9492,25 +9663,25 @@ deserializeVaults_fn = function(vaults) {
|
|
9492
9663
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
9493
9664
|
|
9494
9665
|
// src/wallet-manager/types.ts
|
9495
|
-
var
|
9666
|
+
var import_errors25 = require("@fuel-ts/errors");
|
9496
9667
|
var Vault = class {
|
9497
9668
|
constructor(_options) {
|
9498
|
-
throw new
|
9669
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9499
9670
|
}
|
9500
9671
|
serialize() {
|
9501
|
-
throw new
|
9672
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9502
9673
|
}
|
9503
9674
|
getAccounts() {
|
9504
|
-
throw new
|
9675
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9505
9676
|
}
|
9506
9677
|
addAccount() {
|
9507
|
-
throw new
|
9678
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9508
9679
|
}
|
9509
9680
|
exportAccount(_address) {
|
9510
|
-
throw new
|
9681
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9511
9682
|
}
|
9512
9683
|
getWallet(_address) {
|
9513
|
-
throw new
|
9684
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9514
9685
|
}
|
9515
9686
|
};
|
9516
9687
|
__publicField(Vault, "type");
|
@@ -9520,19 +9691,19 @@ var StorageAbstract = class {
|
|
9520
9691
|
// src/predicate/predicate.ts
|
9521
9692
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
9522
9693
|
var import_address10 = require("@fuel-ts/address");
|
9523
|
-
var
|
9524
|
-
var
|
9694
|
+
var import_errors26 = require("@fuel-ts/errors");
|
9695
|
+
var import_utils39 = require("@fuel-ts/utils");
|
9525
9696
|
|
9526
9697
|
// src/predicate/utils/getPredicateRoot.ts
|
9527
9698
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9528
9699
|
var import_merkle = require("@fuel-ts/merkle");
|
9529
|
-
var
|
9700
|
+
var import_utils38 = require("@fuel-ts/utils");
|
9530
9701
|
var getPredicateRoot = (bytecode) => {
|
9531
9702
|
const chunkSize = 16 * 1024;
|
9532
|
-
const bytes = (0,
|
9533
|
-
const chunks = (0,
|
9534
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
9535
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
9703
|
+
const bytes = (0, import_utils38.arrayify)(bytecode);
|
9704
|
+
const chunks = (0, import_utils38.chunkAndPadBytes)(bytes, chunkSize);
|
9705
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils38.hexlify)(c)));
|
9706
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils38.concat)(["0x4655454C", codeRoot]));
|
9536
9707
|
return predicateRoot;
|
9537
9708
|
};
|
9538
9709
|
|
@@ -9547,14 +9718,14 @@ var Predicate = class extends Account {
|
|
9547
9718
|
* @param bytecode - The bytecode of the predicate.
|
9548
9719
|
* @param abi - The JSON ABI of the predicate.
|
9549
9720
|
* @param provider - The provider used to interact with the blockchain.
|
9550
|
-
* @param
|
9721
|
+
* @param data - The predicate input data (optional).
|
9551
9722
|
* @param configurableConstants - Optional configurable constants for the predicate.
|
9552
9723
|
*/
|
9553
9724
|
constructor({
|
9554
9725
|
bytecode,
|
9555
9726
|
abi,
|
9556
9727
|
provider,
|
9557
|
-
|
9728
|
+
data,
|
9558
9729
|
configurableConstants
|
9559
9730
|
}) {
|
9560
9731
|
const { predicateBytes, predicateInterface } = Predicate.processPredicateData(
|
@@ -9566,8 +9737,8 @@ var Predicate = class extends Account {
|
|
9566
9737
|
super(address, provider);
|
9567
9738
|
this.bytes = predicateBytes;
|
9568
9739
|
this.interface = predicateInterface;
|
9569
|
-
if (
|
9570
|
-
this.predicateData =
|
9740
|
+
if (data !== void 0 && data.length > 0) {
|
9741
|
+
this.predicateData = data;
|
9571
9742
|
}
|
9572
9743
|
}
|
9573
9744
|
/**
|
@@ -9584,8 +9755,8 @@ var Predicate = class extends Account {
|
|
9584
9755
|
}
|
9585
9756
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
9586
9757
|
if (isRequestInputResourceFromOwner(input, this.address)) {
|
9587
|
-
input.predicate = (0,
|
9588
|
-
input.predicateData = (0,
|
9758
|
+
input.predicate = (0, import_utils39.hexlify)(this.bytes);
|
9759
|
+
input.predicateData = (0, import_utils39.hexlify)(this.getPredicateData());
|
9589
9760
|
input.witnessIndex = 0;
|
9590
9761
|
}
|
9591
9762
|
});
|
@@ -9627,13 +9798,13 @@ var Predicate = class extends Account {
|
|
9627
9798
|
* @returns An object containing the new predicate bytes and interface.
|
9628
9799
|
*/
|
9629
9800
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
9630
|
-
let predicateBytes = (0,
|
9801
|
+
let predicateBytes = (0, import_utils39.arrayify)(bytes);
|
9631
9802
|
let abiInterface;
|
9632
9803
|
if (jsonAbi) {
|
9633
9804
|
abiInterface = new import_abi_coder8.Interface(jsonAbi);
|
9634
9805
|
if (abiInterface.functions.main === void 0) {
|
9635
|
-
throw new
|
9636
|
-
|
9806
|
+
throw new import_errors26.FuelError(
|
9807
|
+
import_errors26.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
9637
9808
|
'Cannot use ABI without "main" function.'
|
9638
9809
|
);
|
9639
9810
|
}
|
@@ -9665,8 +9836,8 @@ var Predicate = class extends Account {
|
|
9665
9836
|
);
|
9666
9837
|
return resources.map((resource) => ({
|
9667
9838
|
...resource,
|
9668
|
-
predicate: (0,
|
9669
|
-
predicateData: (0,
|
9839
|
+
predicate: (0, import_utils39.hexlify)(this.bytes),
|
9840
|
+
predicateData: (0, import_utils39.hexlify)(this.getPredicateData())
|
9670
9841
|
}));
|
9671
9842
|
}
|
9672
9843
|
/**
|
@@ -9678,8 +9849,8 @@ var Predicate = class extends Account {
|
|
9678
9849
|
generateFakeResources(coins) {
|
9679
9850
|
return super.generateFakeResources(coins).map((coin) => ({
|
9680
9851
|
...coin,
|
9681
|
-
predicate: (0,
|
9682
|
-
predicateData: (0,
|
9852
|
+
predicate: (0, import_utils39.hexlify)(this.bytes),
|
9853
|
+
predicateData: (0, import_utils39.hexlify)(this.getPredicateData())
|
9683
9854
|
}));
|
9684
9855
|
}
|
9685
9856
|
/**
|
@@ -9694,24 +9865,31 @@ var Predicate = class extends Account {
|
|
9694
9865
|
const mutatedBytes = bytes;
|
9695
9866
|
try {
|
9696
9867
|
if (!abiInterface) {
|
9697
|
-
throw new
|
9868
|
+
throw new import_errors26.FuelError(
|
9869
|
+
import_errors26.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
9698
9870
|
"Cannot validate configurable constants because the Predicate was instantiated without a JSON ABI"
|
9699
9871
|
);
|
9700
9872
|
}
|
9701
9873
|
if (Object.keys(abiInterface.configurables).length === 0) {
|
9702
|
-
throw new
|
9874
|
+
throw new import_errors26.FuelError(
|
9875
|
+
import_errors26.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
9876
|
+
"Predicate has no configurable constants to be set"
|
9877
|
+
);
|
9703
9878
|
}
|
9704
9879
|
Object.entries(configurableConstants).forEach(([key, value]) => {
|
9705
9880
|
if (!abiInterface?.configurables[key]) {
|
9706
|
-
throw new
|
9881
|
+
throw new import_errors26.FuelError(
|
9882
|
+
import_errors26.ErrorCode.CONFIGURABLE_NOT_FOUND,
|
9883
|
+
`No configurable constant named '${key}' found in the Predicate`
|
9884
|
+
);
|
9707
9885
|
}
|
9708
9886
|
const { offset } = abiInterface.configurables[key];
|
9709
9887
|
const encoded = abiInterface.encodeConfigurable(key, value);
|
9710
9888
|
mutatedBytes.set(encoded, offset);
|
9711
9889
|
});
|
9712
9890
|
} catch (err) {
|
9713
|
-
throw new
|
9714
|
-
|
9891
|
+
throw new import_errors26.FuelError(
|
9892
|
+
import_errors26.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
9715
9893
|
`Error setting configurable constants: ${err.message}.`
|
9716
9894
|
);
|
9717
9895
|
}
|
@@ -9742,9 +9920,10 @@ var Predicate = class extends Account {
|
|
9742
9920
|
};
|
9743
9921
|
|
9744
9922
|
// src/connectors/fuel.ts
|
9745
|
-
var
|
9923
|
+
var import_errors29 = require("@fuel-ts/errors");
|
9746
9924
|
|
9747
9925
|
// src/connectors/fuel-connector.ts
|
9926
|
+
var import_errors27 = require("@fuel-ts/errors");
|
9748
9927
|
var import_events2 = require("events");
|
9749
9928
|
|
9750
9929
|
// src/connectors/types/connector-types.ts
|
@@ -9818,7 +9997,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9818
9997
|
* @returns Always true.
|
9819
9998
|
*/
|
9820
9999
|
async ping() {
|
9821
|
-
throw new
|
10000
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9822
10001
|
}
|
9823
10002
|
/**
|
9824
10003
|
* Should return the current version of the connector
|
@@ -9827,7 +10006,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9827
10006
|
* @returns boolean - connection status.
|
9828
10007
|
*/
|
9829
10008
|
async version() {
|
9830
|
-
throw new
|
10009
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9831
10010
|
}
|
9832
10011
|
/**
|
9833
10012
|
* Should return true if the connector is connected
|
@@ -9836,7 +10015,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9836
10015
|
* @returns The connection status.
|
9837
10016
|
*/
|
9838
10017
|
async isConnected() {
|
9839
|
-
throw new
|
10018
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9840
10019
|
}
|
9841
10020
|
/**
|
9842
10021
|
* Should return all the accounts authorized for the
|
@@ -9845,7 +10024,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9845
10024
|
* @returns The accounts addresses strings
|
9846
10025
|
*/
|
9847
10026
|
async accounts() {
|
9848
|
-
throw new
|
10027
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9849
10028
|
}
|
9850
10029
|
/**
|
9851
10030
|
* Should start the connection process and return
|
@@ -9857,7 +10036,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9857
10036
|
* @returns boolean - connection status.
|
9858
10037
|
*/
|
9859
10038
|
async connect() {
|
9860
|
-
throw new
|
10039
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9861
10040
|
}
|
9862
10041
|
/**
|
9863
10042
|
* Should disconnect the current connection and
|
@@ -9867,7 +10046,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9867
10046
|
* @returns The connection status.
|
9868
10047
|
*/
|
9869
10048
|
async disconnect() {
|
9870
|
-
throw new
|
10049
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9871
10050
|
}
|
9872
10051
|
/**
|
9873
10052
|
* Should start the sign message process and return
|
@@ -9879,7 +10058,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9879
10058
|
* @returns Message signature
|
9880
10059
|
*/
|
9881
10060
|
async signMessage(_address, _message) {
|
9882
|
-
throw new
|
10061
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9883
10062
|
}
|
9884
10063
|
/**
|
9885
10064
|
* Should start the sign transaction process and return
|
@@ -9891,7 +10070,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9891
10070
|
* @returns Transaction signature
|
9892
10071
|
*/
|
9893
10072
|
async signTransaction(_address, _transaction) {
|
9894
|
-
throw new
|
10073
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9895
10074
|
}
|
9896
10075
|
/**
|
9897
10076
|
* Should start the send transaction process and return
|
@@ -9907,7 +10086,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9907
10086
|
* @returns The transaction id
|
9908
10087
|
*/
|
9909
10088
|
async sendTransaction(_address, _transaction) {
|
9910
|
-
throw new
|
10089
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9911
10090
|
}
|
9912
10091
|
/**
|
9913
10092
|
* Should return the current account selected inside the connector, if the account
|
@@ -9918,7 +10097,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9918
10097
|
* @returns The current account selected otherwise null.
|
9919
10098
|
*/
|
9920
10099
|
async currentAccount() {
|
9921
|
-
throw new
|
10100
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9922
10101
|
}
|
9923
10102
|
/**
|
9924
10103
|
* Should add the assets metadata to the connector and return true if the asset
|
@@ -9932,7 +10111,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9932
10111
|
* @returns True if the asset was added successfully
|
9933
10112
|
*/
|
9934
10113
|
async addAssets(_assets) {
|
9935
|
-
throw new
|
10114
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9936
10115
|
}
|
9937
10116
|
/**
|
9938
10117
|
* Should add the asset metadata to the connector and return true if the asset
|
@@ -9946,7 +10125,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9946
10125
|
* @returns True if the asset was added successfully
|
9947
10126
|
*/
|
9948
10127
|
async addAsset(_asset) {
|
9949
|
-
throw new
|
10128
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9950
10129
|
}
|
9951
10130
|
/**
|
9952
10131
|
* Should return all the assets added to the connector. If a connection is already established.
|
@@ -9954,7 +10133,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9954
10133
|
* @returns Array of assets metadata from the connector vinculated to the all accounts from a specific Wallet.
|
9955
10134
|
*/
|
9956
10135
|
async assets() {
|
9957
|
-
throw new
|
10136
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9958
10137
|
}
|
9959
10138
|
/**
|
9960
10139
|
* Should start the add network process and return true if the network was added successfully.
|
@@ -9965,7 +10144,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9965
10144
|
* @returns Return true if the network was added successfully
|
9966
10145
|
*/
|
9967
10146
|
async addNetwork(_networkUrl) {
|
9968
|
-
throw new
|
10147
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9969
10148
|
}
|
9970
10149
|
/**
|
9971
10150
|
* Should start the select network process and return true if the network has change successfully.
|
@@ -9976,7 +10155,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9976
10155
|
* @returns Return true if the network was added successfully
|
9977
10156
|
*/
|
9978
10157
|
async selectNetwork(_network) {
|
9979
|
-
throw new
|
10158
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9980
10159
|
}
|
9981
10160
|
/**
|
9982
10161
|
* Should return all the networks available from the connector. If the connection is already established.
|
@@ -9984,7 +10163,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9984
10163
|
* @returns Return all the networks added to the connector.
|
9985
10164
|
*/
|
9986
10165
|
async networks() {
|
9987
|
-
throw new
|
10166
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9988
10167
|
}
|
9989
10168
|
/**
|
9990
10169
|
* Should return the current network selected inside the connector. Even if the connection is not established.
|
@@ -9992,7 +10171,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9992
10171
|
* @returns Return the current network selected inside the connector.
|
9993
10172
|
*/
|
9994
10173
|
async currentNetwork() {
|
9995
|
-
throw new
|
10174
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9996
10175
|
}
|
9997
10176
|
/**
|
9998
10177
|
* Should add the ABI to the connector and return true if the ABI was added successfully.
|
@@ -10002,7 +10181,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
10002
10181
|
* @returns Return true if the ABI was added successfully.
|
10003
10182
|
*/
|
10004
10183
|
async addABI(_contractId, _abi) {
|
10005
|
-
throw new
|
10184
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
10006
10185
|
}
|
10007
10186
|
/**
|
10008
10187
|
* Should return the ABI from the connector vinculated to the all accounts from a specific Wallet.
|
@@ -10011,7 +10190,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
10011
10190
|
* @returns The ABI if it exists, otherwise return null.
|
10012
10191
|
*/
|
10013
10192
|
async getABI(_id) {
|
10014
|
-
throw new
|
10193
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
10015
10194
|
}
|
10016
10195
|
/**
|
10017
10196
|
* Should return true if the abi exists in the connector vinculated to the all accounts from a specific Wallet.
|
@@ -10020,7 +10199,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
10020
10199
|
* @returns Returns true if the abi exists or false if not.
|
10021
10200
|
*/
|
10022
10201
|
async hasABI(_id) {
|
10023
|
-
throw new
|
10202
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
10024
10203
|
}
|
10025
10204
|
/**
|
10026
10205
|
* Event listener for the connector.
|
@@ -10064,6 +10243,7 @@ function dispatchFuelConnectorEvent(connector) {
|
|
10064
10243
|
}
|
10065
10244
|
|
10066
10245
|
// src/connectors/utils/promises.ts
|
10246
|
+
var import_errors28 = require("@fuel-ts/errors");
|
10067
10247
|
function deferPromise() {
|
10068
10248
|
const defer = {};
|
10069
10249
|
defer.promise = new Promise((resolve, reject) => {
|
@@ -10075,7 +10255,7 @@ function deferPromise() {
|
|
10075
10255
|
async function withTimeout(promise, timeout = 1050) {
|
10076
10256
|
const timeoutPromise = new Promise((resolve, reject) => {
|
10077
10257
|
setTimeout(() => {
|
10078
|
-
reject(new
|
10258
|
+
reject(new import_errors28.FuelError(import_errors28.FuelError.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
10079
10259
|
}, timeout);
|
10080
10260
|
});
|
10081
10261
|
return Promise.race([timeoutPromise, promise]);
|
@@ -10093,7 +10273,6 @@ var _Fuel = class extends FuelConnector {
|
|
10093
10273
|
_targetUnsubscribe;
|
10094
10274
|
_pingCache = {};
|
10095
10275
|
_currentConnector;
|
10096
|
-
_initializationPromise;
|
10097
10276
|
constructor(config = _Fuel.defaultConfig) {
|
10098
10277
|
super();
|
10099
10278
|
this.setMaxListeners(1e3);
|
@@ -10101,15 +10280,9 @@ var _Fuel = class extends FuelConnector {
|
|
10101
10280
|
this._targetObject = this.getTargetObject(config.targetObject);
|
10102
10281
|
this._storage = config.storage === void 0 ? this.getStorage() : config.storage;
|
10103
10282
|
this.setupMethods();
|
10104
|
-
this.
|
10283
|
+
this.setDefaultConnector();
|
10105
10284
|
this._targetUnsubscribe = this.setupConnectorListener();
|
10106
10285
|
}
|
10107
|
-
async initialize() {
|
10108
|
-
await this.setDefaultConnector();
|
10109
|
-
}
|
10110
|
-
async ensureInitialized() {
|
10111
|
-
await this._initializationPromise;
|
10112
|
-
}
|
10113
10286
|
/**
|
10114
10287
|
* Return the target object to listen for global events.
|
10115
10288
|
*/
|
@@ -10169,7 +10342,8 @@ var _Fuel = class extends FuelConnector {
|
|
10169
10342
|
const hasConnector = await this.hasConnector();
|
10170
10343
|
await this.pingConnector();
|
10171
10344
|
if (!this._currentConnector || !hasConnector) {
|
10172
|
-
throw new
|
10345
|
+
throw new import_errors29.FuelError(
|
10346
|
+
import_errors29.ErrorCode.MISSING_CONNECTOR,
|
10173
10347
|
`No connector selected for calling ${method}. Use hasConnector before executing other methods.`
|
10174
10348
|
);
|
10175
10349
|
}
|
@@ -10233,7 +10407,7 @@ var _Fuel = class extends FuelConnector {
|
|
10233
10407
|
cacheTime: PING_CACHE_TIME
|
10234
10408
|
})();
|
10235
10409
|
} catch {
|
10236
|
-
throw new
|
10410
|
+
throw new import_errors29.FuelError(import_errors29.ErrorCode.INVALID_PROVIDER, "Current connector is not available.");
|
10237
10411
|
}
|
10238
10412
|
}
|
10239
10413
|
/**
|
@@ -10305,7 +10479,6 @@ var _Fuel = class extends FuelConnector {
|
|
10305
10479
|
* Return the list of connectors with the status of installed and connected.
|
10306
10480
|
*/
|
10307
10481
|
async connectors() {
|
10308
|
-
await this.ensureInitialized();
|
10309
10482
|
await this.fetchConnectorsStatus();
|
10310
10483
|
return this._connectors;
|
10311
10484
|
}
|
@@ -10315,7 +10488,6 @@ var _Fuel = class extends FuelConnector {
|
|
10315
10488
|
async selectConnector(connectorName, options = {
|
10316
10489
|
emitEvents: true
|
10317
10490
|
}) {
|
10318
|
-
await this.ensureInitialized();
|
10319
10491
|
const connector = this.getConnector(connectorName);
|
10320
10492
|
if (!connector) {
|
10321
10493
|
return false;
|
@@ -10346,7 +10518,6 @@ var _Fuel = class extends FuelConnector {
|
|
10346
10518
|
* Return true if any connector is available.
|
10347
10519
|
*/
|
10348
10520
|
async hasConnector() {
|
10349
|
-
await this.ensureInitialized();
|
10350
10521
|
if (this._currentConnector) {
|
10351
10522
|
return true;
|
10352
10523
|
}
|
@@ -10357,7 +10528,6 @@ var _Fuel = class extends FuelConnector {
|
|
10357
10528
|
return withTimeout(defer.promise, HAS_CONNECTOR_TIMEOUT).then(() => true).catch(() => false);
|
10358
10529
|
}
|
10359
10530
|
async hasWallet() {
|
10360
|
-
await this.ensureInitialized();
|
10361
10531
|
return this.hasConnector();
|
10362
10532
|
}
|
10363
10533
|
/**
|
@@ -10386,7 +10556,7 @@ var _Fuel = class extends FuelConnector {
|
|
10386
10556
|
const currentNetwork = await this.currentNetwork();
|
10387
10557
|
provider = await Provider.create(currentNetwork.url);
|
10388
10558
|
} else {
|
10389
|
-
throw new
|
10559
|
+
throw new import_errors29.FuelError(import_errors29.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
|
10390
10560
|
}
|
10391
10561
|
return provider;
|
10392
10562
|
}
|
@@ -10431,10 +10601,12 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10431
10601
|
BLOCKS_PAGE_SIZE_LIMIT,
|
10432
10602
|
BaseTransactionRequest,
|
10433
10603
|
BaseWalletUnlocked,
|
10604
|
+
BlobTransactionRequest,
|
10434
10605
|
CHAIN_IDS,
|
10435
10606
|
ChainName,
|
10436
10607
|
ChangeOutputCollisionError,
|
10437
10608
|
CreateTransactionRequest,
|
10609
|
+
DEFAULT_RESOURCE_CACHE_TTL,
|
10438
10610
|
Fuel,
|
10439
10611
|
FuelConnector,
|
10440
10612
|
FuelConnectorEventType,
|
@@ -10478,6 +10650,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10478
10650
|
cacheRequestInputsResources,
|
10479
10651
|
cacheRequestInputsResourcesFromOwner,
|
10480
10652
|
calculateGasFee,
|
10653
|
+
calculateMetadataGasForTxBlob,
|
10481
10654
|
calculateMetadataGasForTxCreate,
|
10482
10655
|
calculateMetadataGasForTxScript,
|
10483
10656
|
calculateTXFeeForSummary,
|
@@ -10543,7 +10716,11 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10543
10716
|
isRequestInputMessage,
|
10544
10717
|
isRequestInputResource,
|
10545
10718
|
isRequestInputResourceFromOwner,
|
10719
|
+
isTransactionTypeBlob,
|
10720
|
+
isTransactionTypeCreate,
|
10721
|
+
isTransactionTypeScript,
|
10546
10722
|
isType,
|
10723
|
+
isTypeBlob,
|
10547
10724
|
isTypeCreate,
|
10548
10725
|
isTypeMint,
|
10549
10726
|
isTypeScript,
|