@fuel-ts/account 0.93.0 → 0.94.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -29
- package/dist/account.d.ts +2 -2
- 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.map +1 -1
- package/dist/connectors/fuel.d.ts.map +1 -1
- package/dist/connectors/utils/promises.d.ts.map +1 -1
- package/dist/index.global.js +1628 -930
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +978 -603
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +706 -343
- 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 +614 -1
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts +2 -3
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +12 -6
- 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 +10 -5
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +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/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/input.d.ts +6 -1
- package/dist/providers/transaction-summary/input.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +4 -2
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +5 -2
- 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 -18
- 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 +40829 -40167
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +1500 -1200
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +1209 -910
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/keystore-wallet.d.ts.map +1 -1
- package/package.json +17 -19
- 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,11 +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,
|
69
|
-
|
70
|
+
DEFAULT_RESOURCE_CACHE_TTL: () => DEFAULT_RESOURCE_CACHE_TTL,
|
70
71
|
Fuel: () => Fuel,
|
71
72
|
FuelConnector: () => FuelConnector,
|
72
73
|
FuelConnectorEventType: () => FuelConnectorEventType,
|
@@ -100,6 +101,7 @@ __export(src_exports, {
|
|
100
101
|
WalletUnlocked: () => WalletUnlocked,
|
101
102
|
addAmountToCoinQuantities: () => addAmountToCoinQuantities,
|
102
103
|
addOperation: () => addOperation,
|
104
|
+
aggregateInputsAmountsByAssetAndOwner: () => aggregateInputsAmountsByAssetAndOwner,
|
103
105
|
assemblePanicError: () => assemblePanicError,
|
104
106
|
assembleReceiptByType: () => assembleReceiptByType,
|
105
107
|
assembleRevertError: () => assembleRevertError,
|
@@ -110,6 +112,7 @@ __export(src_exports, {
|
|
110
112
|
cacheRequestInputsResources: () => cacheRequestInputsResources,
|
111
113
|
cacheRequestInputsResourcesFromOwner: () => cacheRequestInputsResourcesFromOwner,
|
112
114
|
calculateGasFee: () => calculateGasFee,
|
115
|
+
calculateMetadataGasForTxBlob: () => calculateMetadataGasForTxBlob,
|
113
116
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
114
117
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
115
118
|
calculateTXFeeForSummary: () => calculateTXFeeForSummary,
|
@@ -168,6 +171,7 @@ __export(src_exports, {
|
|
168
171
|
hasSameAssetId: () => hasSameAssetId,
|
169
172
|
inputify: () => inputify,
|
170
173
|
isCoin: () => isCoin,
|
174
|
+
isInputCoin: () => isInputCoin,
|
171
175
|
isMessage: () => isMessage,
|
172
176
|
isRawCoin: () => isRawCoin,
|
173
177
|
isRawMessage: () => isRawMessage,
|
@@ -175,7 +179,11 @@ __export(src_exports, {
|
|
175
179
|
isRequestInputMessage: () => isRequestInputMessage,
|
176
180
|
isRequestInputResource: () => isRequestInputResource,
|
177
181
|
isRequestInputResourceFromOwner: () => isRequestInputResourceFromOwner,
|
182
|
+
isTransactionTypeBlob: () => isTransactionTypeBlob,
|
183
|
+
isTransactionTypeCreate: () => isTransactionTypeCreate,
|
184
|
+
isTransactionTypeScript: () => isTransactionTypeScript,
|
178
185
|
isType: () => isType,
|
186
|
+
isTypeBlob: () => isTypeBlob,
|
179
187
|
isTypeCreate: () => isTypeCreate,
|
180
188
|
isTypeMint: () => isTypeMint,
|
181
189
|
isTypeScript: () => isTypeScript,
|
@@ -200,10 +208,10 @@ module.exports = __toCommonJS(src_exports);
|
|
200
208
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
201
209
|
var import_address4 = require("@fuel-ts/address");
|
202
210
|
var import_crypto2 = require("@fuel-ts/crypto");
|
203
|
-
var
|
211
|
+
var import_errors17 = require("@fuel-ts/errors");
|
204
212
|
var import_interfaces = require("@fuel-ts/interfaces");
|
205
|
-
var
|
206
|
-
var
|
213
|
+
var import_math21 = require("@fuel-ts/math");
|
214
|
+
var import_utils30 = require("@fuel-ts/utils");
|
207
215
|
var import_ramda4 = require("ramda");
|
208
216
|
|
209
217
|
// src/providers/coin-quantity.ts
|
@@ -243,25 +251,17 @@ var addAmountToCoinQuantities = (params) => {
|
|
243
251
|
|
244
252
|
// src/providers/provider.ts
|
245
253
|
var import_address3 = require("@fuel-ts/address");
|
246
|
-
var
|
247
|
-
var
|
254
|
+
var import_errors15 = require("@fuel-ts/errors");
|
255
|
+
var import_math18 = require("@fuel-ts/math");
|
248
256
|
var import_transactions20 = require("@fuel-ts/transactions");
|
249
|
-
var
|
257
|
+
var import_utils24 = require("@fuel-ts/utils");
|
250
258
|
var import_versions = require("@fuel-ts/versions");
|
251
|
-
var
|
259
|
+
var import_utils25 = require("@noble/curves/abstract/utils");
|
252
260
|
var import_graphql_request = require("graphql-request");
|
253
261
|
var import_ramda3 = require("ramda");
|
254
262
|
|
255
263
|
// src/providers/__generated__/operations.ts
|
256
264
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
257
|
-
var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
|
258
|
-
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
259
|
-
type: __typename
|
260
|
-
... on SqueezedOutStatus {
|
261
|
-
reason
|
262
|
-
}
|
263
|
-
}
|
264
|
-
`;
|
265
265
|
var SubmittedStatusFragmentDoc = import_graphql_tag.default`
|
266
266
|
fragment SubmittedStatusFragment on SubmittedStatus {
|
267
267
|
type: __typename
|
@@ -318,6 +318,47 @@ var SuccessStatusFragmentDoc = import_graphql_tag.default`
|
|
318
318
|
totalFee
|
319
319
|
}
|
320
320
|
${ReceiptFragmentDoc}`;
|
321
|
+
var MalleableTransactionFieldsFragmentDoc = import_graphql_tag.default`
|
322
|
+
fragment malleableTransactionFieldsFragment on Transaction {
|
323
|
+
receiptsRoot
|
324
|
+
inputs {
|
325
|
+
type: __typename
|
326
|
+
... on InputCoin {
|
327
|
+
txPointer
|
328
|
+
}
|
329
|
+
... on InputContract {
|
330
|
+
txPointer
|
331
|
+
}
|
332
|
+
}
|
333
|
+
outputs {
|
334
|
+
type: __typename
|
335
|
+
... on CoinOutput {
|
336
|
+
to
|
337
|
+
amount
|
338
|
+
assetId
|
339
|
+
}
|
340
|
+
... on ContractOutput {
|
341
|
+
inputIndex
|
342
|
+
balanceRoot
|
343
|
+
stateRoot
|
344
|
+
}
|
345
|
+
... on ChangeOutput {
|
346
|
+
to
|
347
|
+
amount
|
348
|
+
assetId
|
349
|
+
}
|
350
|
+
... on VariableOutput {
|
351
|
+
to
|
352
|
+
amount
|
353
|
+
assetId
|
354
|
+
}
|
355
|
+
... on ContractCreated {
|
356
|
+
contract
|
357
|
+
stateRoot
|
358
|
+
}
|
359
|
+
}
|
360
|
+
}
|
361
|
+
`;
|
321
362
|
var FailureStatusFragmentDoc = import_graphql_tag.default`
|
322
363
|
fragment FailureStatusFragment on FailureStatus {
|
323
364
|
type: __typename
|
@@ -339,6 +380,32 @@ var SqueezedOutStatusFragmentDoc = import_graphql_tag.default`
|
|
339
380
|
reason
|
340
381
|
}
|
341
382
|
`;
|
383
|
+
var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
|
384
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
385
|
+
... on SubmittedStatus {
|
386
|
+
...SubmittedStatusFragment
|
387
|
+
}
|
388
|
+
... on SuccessStatus {
|
389
|
+
...SuccessStatusFragment
|
390
|
+
transaction {
|
391
|
+
...malleableTransactionFieldsFragment
|
392
|
+
}
|
393
|
+
}
|
394
|
+
... on FailureStatus {
|
395
|
+
...FailureStatusFragment
|
396
|
+
transaction {
|
397
|
+
...malleableTransactionFieldsFragment
|
398
|
+
}
|
399
|
+
}
|
400
|
+
... on SqueezedOutStatus {
|
401
|
+
...SqueezedOutStatusFragment
|
402
|
+
}
|
403
|
+
}
|
404
|
+
${SubmittedStatusFragmentDoc}
|
405
|
+
${SuccessStatusFragmentDoc}
|
406
|
+
${MalleableTransactionFieldsFragmentDoc}
|
407
|
+
${FailureStatusFragmentDoc}
|
408
|
+
${SqueezedOutStatusFragmentDoc}`;
|
342
409
|
var TransactionStatusFragmentDoc = import_graphql_tag.default`
|
343
410
|
fragment transactionStatusFragment on TransactionStatus {
|
344
411
|
... on SubmittedStatus {
|
@@ -679,6 +746,12 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
|
|
679
746
|
alocDependentCost {
|
680
747
|
...DependentCostFragment
|
681
748
|
}
|
749
|
+
bldd {
|
750
|
+
...DependentCostFragment
|
751
|
+
}
|
752
|
+
bsiz {
|
753
|
+
...DependentCostFragment
|
754
|
+
}
|
682
755
|
cfe {
|
683
756
|
...DependentCostFragment
|
684
757
|
}
|
@@ -697,6 +770,9 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
|
|
697
770
|
csiz {
|
698
771
|
...DependentCostFragment
|
699
772
|
}
|
773
|
+
ed19DependentCost {
|
774
|
+
...DependentCostFragment
|
775
|
+
}
|
700
776
|
k256 {
|
701
777
|
...DependentCostFragment
|
702
778
|
}
|
@@ -1228,12 +1304,11 @@ function getSdk(requester) {
|
|
1228
1304
|
var import_errors = require("@fuel-ts/errors");
|
1229
1305
|
var import_graphql = require("graphql");
|
1230
1306
|
var _FuelGraphqlSubscriber = class {
|
1231
|
-
constructor(
|
1232
|
-
this.
|
1307
|
+
constructor(stream) {
|
1308
|
+
this.stream = stream;
|
1233
1309
|
}
|
1234
|
-
|
1235
|
-
|
1236
|
-
const { url, query, variables, fetchFn } = this.options;
|
1310
|
+
static async create(options) {
|
1311
|
+
const { url, query, variables, fetchFn } = options;
|
1237
1312
|
const response = await fetchFn(`${url}-sub`, {
|
1238
1313
|
method: "POST",
|
1239
1314
|
body: JSON.stringify({
|
@@ -1245,14 +1320,11 @@ var _FuelGraphqlSubscriber = class {
|
|
1245
1320
|
Accept: "text/event-stream"
|
1246
1321
|
}
|
1247
1322
|
});
|
1248
|
-
|
1323
|
+
return new _FuelGraphqlSubscriber(response.body.getReader());
|
1249
1324
|
}
|
1250
1325
|
events = [];
|
1251
1326
|
parsingLeftover = "";
|
1252
1327
|
async next() {
|
1253
|
-
if (!this.stream) {
|
1254
|
-
await this.setStream();
|
1255
|
-
}
|
1256
1328
|
while (true) {
|
1257
1329
|
if (this.events.length > 0) {
|
1258
1330
|
const { data, errors } = this.events.shift();
|
@@ -1303,62 +1375,65 @@ var _FuelGraphqlSubscriber = class {
|
|
1303
1375
|
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
1304
1376
|
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
1305
1377
|
|
1306
|
-
// src/providers/
|
1378
|
+
// src/providers/resource-cache.ts
|
1307
1379
|
var import_errors2 = require("@fuel-ts/errors");
|
1308
1380
|
var import_utils2 = require("@fuel-ts/utils");
|
1309
|
-
var cache =
|
1310
|
-
var
|
1311
|
-
var MemoryCache = class {
|
1381
|
+
var cache = /* @__PURE__ */ new Map();
|
1382
|
+
var ResourceCache = class {
|
1312
1383
|
ttl;
|
1313
|
-
constructor(
|
1314
|
-
this.ttl =
|
1315
|
-
if (typeof
|
1384
|
+
constructor(ttl) {
|
1385
|
+
this.ttl = ttl;
|
1386
|
+
if (typeof ttl !== "number" || this.ttl <= 0) {
|
1316
1387
|
throw new import_errors2.FuelError(
|
1317
1388
|
import_errors2.ErrorCode.INVALID_TTL,
|
1318
1389
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
1319
1390
|
);
|
1320
1391
|
}
|
1321
1392
|
}
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
}
|
1330
|
-
return void 0;
|
1331
|
-
}
|
1332
|
-
set(value) {
|
1333
|
-
const expiresAt = Date.now() + this.ttl;
|
1334
|
-
const key = (0, import_utils2.hexlify)(value);
|
1335
|
-
cache[key] = {
|
1336
|
-
expires: expiresAt,
|
1337
|
-
value
|
1393
|
+
// Add resources to the cache
|
1394
|
+
set(transactionId, resources) {
|
1395
|
+
const currentTime = Date.now();
|
1396
|
+
const existingResources = cache.get(transactionId) || {
|
1397
|
+
utxos: /* @__PURE__ */ new Set(),
|
1398
|
+
messages: /* @__PURE__ */ new Set(),
|
1399
|
+
timestamp: currentTime
|
1338
1400
|
};
|
1339
|
-
|
1401
|
+
resources.utxos.forEach((utxo) => existingResources.utxos.add((0, import_utils2.hexlify)(utxo)));
|
1402
|
+
resources.messages.forEach((message) => existingResources.messages.add((0, import_utils2.hexlify)(message)));
|
1403
|
+
cache.set(transactionId, existingResources);
|
1340
1404
|
}
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
if (data) {
|
1345
|
-
list.push(data);
|
1346
|
-
}
|
1347
|
-
return list;
|
1348
|
-
}, []);
|
1405
|
+
// Remove resources from the cache for a given transaction ID
|
1406
|
+
unset(transactionId) {
|
1407
|
+
cache.delete(transactionId);
|
1349
1408
|
}
|
1409
|
+
// Get all cached resources and remove expired ones
|
1350
1410
|
getActiveData() {
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1411
|
+
const allResources = { utxos: [], messages: [] };
|
1412
|
+
const currentTime = Date.now();
|
1413
|
+
cache.forEach((resource, transactionId) => {
|
1414
|
+
if (currentTime - resource.timestamp < this.ttl) {
|
1415
|
+
allResources.utxos.push(...resource.utxos);
|
1416
|
+
allResources.messages.push(...resource.messages);
|
1417
|
+
} else {
|
1418
|
+
cache.delete(transactionId);
|
1355
1419
|
}
|
1356
|
-
|
1357
|
-
|
1420
|
+
});
|
1421
|
+
return allResources;
|
1422
|
+
}
|
1423
|
+
// Check if a UTXO ID or message nonce is already cached and not expired
|
1424
|
+
isCached(key) {
|
1425
|
+
const currentTime = Date.now();
|
1426
|
+
for (const [transactionId, resourceData] of cache.entries()) {
|
1427
|
+
if (currentTime - resourceData.timestamp > this.ttl) {
|
1428
|
+
cache.delete(transactionId);
|
1429
|
+
} else if (resourceData.utxos.has(key) || resourceData.messages.has(key)) {
|
1430
|
+
return true;
|
1431
|
+
}
|
1432
|
+
}
|
1433
|
+
return false;
|
1358
1434
|
}
|
1359
|
-
|
1360
|
-
|
1361
|
-
delete cache[key];
|
1435
|
+
clear() {
|
1436
|
+
cache.clear();
|
1362
1437
|
}
|
1363
1438
|
};
|
1364
1439
|
|
@@ -1499,6 +1574,7 @@ var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
|
1499
1574
|
var import_address = require("@fuel-ts/address");
|
1500
1575
|
var import_configs6 = require("@fuel-ts/address/configs");
|
1501
1576
|
var import_crypto = require("@fuel-ts/crypto");
|
1577
|
+
var import_errors8 = require("@fuel-ts/errors");
|
1502
1578
|
var import_math8 = require("@fuel-ts/math");
|
1503
1579
|
var import_transactions7 = require("@fuel-ts/transactions");
|
1504
1580
|
var import_utils9 = require("@fuel-ts/utils");
|
@@ -1868,6 +1944,15 @@ function calculateMetadataGasForTxScript({
|
|
1868
1944
|
}) {
|
1869
1945
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1870
1946
|
}
|
1947
|
+
function calculateMetadataGasForTxBlob({
|
1948
|
+
gasCosts,
|
1949
|
+
txBytesSize,
|
1950
|
+
witnessBytesSize
|
1951
|
+
}) {
|
1952
|
+
const txId = resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1953
|
+
const blobLen = resolveGasDependentCosts(witnessBytesSize, gasCosts.s256);
|
1954
|
+
return txId.add(blobLen);
|
1955
|
+
}
|
1871
1956
|
var calculateGasFee = (params) => {
|
1872
1957
|
const { gas, gasPrice, priceFactor, tip } = params;
|
1873
1958
|
return gas.mul(gasPrice).div(priceFactor).add((0, import_math5.bn)(tip));
|
@@ -2436,7 +2521,7 @@ var BaseTransactionRequest = class {
|
|
2436
2521
|
* @hidden
|
2437
2522
|
*/
|
2438
2523
|
metadataGas(_gasCosts) {
|
2439
|
-
throw new
|
2524
|
+
throw new import_errors8.FuelError(import_errors8.FuelError.CODES.NOT_IMPLEMENTED, "Not implemented");
|
2440
2525
|
}
|
2441
2526
|
/**
|
2442
2527
|
* @hidden
|
@@ -2511,6 +2596,7 @@ var BaseTransactionRequest = class {
|
|
2511
2596
|
};
|
2512
2597
|
updateAssetInput(baseAssetId, (0, import_math8.bn)(1e11));
|
2513
2598
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2599
|
+
return this;
|
2514
2600
|
}
|
2515
2601
|
/**
|
2516
2602
|
* Retrieves an array of CoinQuantity for each coin output present in the transaction.
|
@@ -2557,14 +2643,11 @@ var BaseTransactionRequest = class {
|
|
2557
2643
|
}
|
2558
2644
|
});
|
2559
2645
|
}
|
2646
|
+
byteLength() {
|
2647
|
+
return this.toTransactionBytes().byteLength;
|
2648
|
+
}
|
2560
2649
|
};
|
2561
2650
|
|
2562
|
-
// src/providers/transaction-request/create-transaction-request.ts
|
2563
|
-
var import_configs8 = require("@fuel-ts/address/configs");
|
2564
|
-
var import_math10 = require("@fuel-ts/math");
|
2565
|
-
var import_transactions9 = require("@fuel-ts/transactions");
|
2566
|
-
var import_utils13 = require("@fuel-ts/utils");
|
2567
|
-
|
2568
2651
|
// src/providers/transaction-request/hash-transaction.ts
|
2569
2652
|
var import_configs7 = require("@fuel-ts/address/configs");
|
2570
2653
|
var import_hasher = require("@fuel-ts/hasher");
|
@@ -2636,11 +2719,81 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2636
2719
|
return (0, import_hasher.sha256)(concatenatedData);
|
2637
2720
|
}
|
2638
2721
|
|
2722
|
+
// src/providers/transaction-request/blob-transaction-request.ts
|
2723
|
+
var BlobTransactionRequest = class extends BaseTransactionRequest {
|
2724
|
+
static from(obj) {
|
2725
|
+
if (obj instanceof this) {
|
2726
|
+
return obj;
|
2727
|
+
}
|
2728
|
+
return new this(obj);
|
2729
|
+
}
|
2730
|
+
/** Type of the transaction */
|
2731
|
+
type = import_transactions7.TransactionType.Blob;
|
2732
|
+
/** Blob ID */
|
2733
|
+
blobId;
|
2734
|
+
/** Witness index of contract bytecode to create */
|
2735
|
+
witnessIndex;
|
2736
|
+
/**
|
2737
|
+
* Creates an instance `BlobTransactionRequest`.
|
2738
|
+
*
|
2739
|
+
* @param blobTransactionRequestLike - The initial values for the instance
|
2740
|
+
*/
|
2741
|
+
constructor({ witnessIndex, blobId, ...rest }) {
|
2742
|
+
super(rest);
|
2743
|
+
this.blobId = blobId;
|
2744
|
+
this.witnessIndex = witnessIndex ?? 0;
|
2745
|
+
}
|
2746
|
+
/**
|
2747
|
+
* Converts the transaction request to a `TransactionBlob`.
|
2748
|
+
*
|
2749
|
+
* @returns The transaction create object.
|
2750
|
+
*/
|
2751
|
+
toTransaction() {
|
2752
|
+
const baseTransaction = this.getBaseTransaction();
|
2753
|
+
const { witnessIndex, blobId } = this;
|
2754
|
+
return {
|
2755
|
+
type: import_transactions7.TransactionType.Blob,
|
2756
|
+
...baseTransaction,
|
2757
|
+
blobId,
|
2758
|
+
witnessIndex
|
2759
|
+
};
|
2760
|
+
}
|
2761
|
+
/**
|
2762
|
+
* Gets the Transaction Request by hashing the transaction.
|
2763
|
+
*
|
2764
|
+
* @param chainId - The chain ID.
|
2765
|
+
*
|
2766
|
+
* @returns - A hash of the transaction, which is the transaction ID.
|
2767
|
+
*/
|
2768
|
+
getTransactionId(chainId) {
|
2769
|
+
return hashTransaction(this, chainId);
|
2770
|
+
}
|
2771
|
+
/**
|
2772
|
+
* Calculates the metadata gas cost for a blob transaction.
|
2773
|
+
*
|
2774
|
+
* @param gasCosts - gas costs passed from the chain.
|
2775
|
+
* @returns metadata gas cost for the blob transaction.
|
2776
|
+
*/
|
2777
|
+
metadataGas(gasCosts) {
|
2778
|
+
return calculateMetadataGasForTxBlob({
|
2779
|
+
gasCosts,
|
2780
|
+
txBytesSize: this.byteSize(),
|
2781
|
+
witnessBytesSize: this.witnesses[this.witnessIndex].length
|
2782
|
+
});
|
2783
|
+
}
|
2784
|
+
};
|
2785
|
+
|
2786
|
+
// src/providers/transaction-request/create-transaction-request.ts
|
2787
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2788
|
+
var import_math10 = require("@fuel-ts/math");
|
2789
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2790
|
+
var import_utils14 = require("@fuel-ts/utils");
|
2791
|
+
|
2639
2792
|
// src/providers/transaction-request/storage-slot.ts
|
2640
|
-
var
|
2793
|
+
var import_utils13 = require("@fuel-ts/utils");
|
2641
2794
|
var getStorageValue = (value) => {
|
2642
2795
|
const v = new Uint8Array(32);
|
2643
|
-
v.set((0,
|
2796
|
+
v.set((0, import_utils13.arrayify)(value));
|
2644
2797
|
return v;
|
2645
2798
|
};
|
2646
2799
|
var storageSlotify = (storageSlot) => {
|
@@ -2654,8 +2807,8 @@ var storageSlotify = (storageSlot) => {
|
|
2654
2807
|
value = storageSlot.value;
|
2655
2808
|
}
|
2656
2809
|
return {
|
2657
|
-
key: (0,
|
2658
|
-
value: (0,
|
2810
|
+
key: (0, import_utils13.hexlify)(key),
|
2811
|
+
value: (0, import_utils13.hexlify)(getStorageValue(value))
|
2659
2812
|
};
|
2660
2813
|
};
|
2661
2814
|
|
@@ -2683,7 +2836,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2683
2836
|
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2684
2837
|
super(rest);
|
2685
2838
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2686
|
-
this.salt = (0,
|
2839
|
+
this.salt = (0, import_utils14.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2687
2840
|
this.storageSlots = [...storageSlots ?? []];
|
2688
2841
|
}
|
2689
2842
|
/**
|
@@ -2700,7 +2853,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2700
2853
|
...baseTransaction,
|
2701
2854
|
bytecodeWitnessIndex,
|
2702
2855
|
storageSlotsCount: (0, import_math10.bn)(storageSlots.length),
|
2703
|
-
salt: this.salt ? (0,
|
2856
|
+
salt: this.salt ? (0, import_utils14.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2704
2857
|
storageSlots
|
2705
2858
|
};
|
2706
2859
|
}
|
@@ -2739,7 +2892,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2739
2892
|
}
|
2740
2893
|
metadataGas(gasCosts) {
|
2741
2894
|
return calculateMetadataGasForTxCreate({
|
2742
|
-
contractBytesSize: (0, import_math10.bn)((0,
|
2895
|
+
contractBytesSize: (0, import_math10.bn)((0, import_utils14.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2743
2896
|
gasCosts,
|
2744
2897
|
stateRootSize: this.storageSlots.length,
|
2745
2898
|
txBytesSize: this.byteSize()
|
@@ -2753,17 +2906,17 @@ var import_address2 = require("@fuel-ts/address");
|
|
2753
2906
|
var import_configs9 = require("@fuel-ts/address/configs");
|
2754
2907
|
var import_math11 = require("@fuel-ts/math");
|
2755
2908
|
var import_transactions10 = require("@fuel-ts/transactions");
|
2756
|
-
var
|
2909
|
+
var import_utils16 = require("@fuel-ts/utils");
|
2757
2910
|
|
2758
2911
|
// src/providers/transaction-request/scripts.ts
|
2759
|
-
var
|
2912
|
+
var import_utils15 = require("@fuel-ts/utils");
|
2760
2913
|
var returnZeroScript = {
|
2761
2914
|
/*
|
2762
2915
|
Opcode::RET(REG_ZERO)
|
2763
2916
|
Opcode::NOOP
|
2764
2917
|
*/
|
2765
2918
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2766
|
-
bytes: (0,
|
2919
|
+
bytes: (0, import_utils15.arrayify)("0x24000000"),
|
2767
2920
|
encodeScriptData: () => new Uint8Array(0)
|
2768
2921
|
};
|
2769
2922
|
var withdrawScript = {
|
@@ -2777,7 +2930,7 @@ var withdrawScript = {
|
|
2777
2930
|
00000000 00000000 [amount value]
|
2778
2931
|
*/
|
2779
2932
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2780
|
-
bytes: (0,
|
2933
|
+
bytes: (0, import_utils15.arrayify)("0x5040C0105D44C0064C40001124000000"),
|
2781
2934
|
encodeScriptData: () => new Uint8Array(0)
|
2782
2935
|
};
|
2783
2936
|
|
@@ -2806,8 +2959,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2806
2959
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2807
2960
|
super(rest);
|
2808
2961
|
this.gasLimit = (0, import_math11.bn)(gasLimit);
|
2809
|
-
this.script = (0,
|
2810
|
-
this.scriptData = (0,
|
2962
|
+
this.script = (0, import_utils16.arrayify)(script ?? returnZeroScript.bytes);
|
2963
|
+
this.scriptData = (0, import_utils16.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2811
2964
|
this.abis = rest.abis;
|
2812
2965
|
}
|
2813
2966
|
/**
|
@@ -2816,8 +2969,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2816
2969
|
* @returns The transaction script object.
|
2817
2970
|
*/
|
2818
2971
|
toTransaction() {
|
2819
|
-
const script = (0,
|
2820
|
-
const scriptData = (0,
|
2972
|
+
const script = (0, import_utils16.arrayify)(this.script ?? "0x");
|
2973
|
+
const scriptData = (0, import_utils16.arrayify)(this.scriptData ?? "0x");
|
2821
2974
|
return {
|
2822
2975
|
type: import_transactions10.TransactionType.Script,
|
2823
2976
|
scriptGasLimit: this.gasLimit,
|
@@ -2825,8 +2978,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2825
2978
|
scriptLength: (0, import_math11.bn)(script.length),
|
2826
2979
|
scriptDataLength: (0, import_math11.bn)(scriptData.length),
|
2827
2980
|
receiptsRoot: import_configs9.ZeroBytes32,
|
2828
|
-
script: (0,
|
2829
|
-
scriptData: (0,
|
2981
|
+
script: (0, import_utils16.hexlify)(script),
|
2982
|
+
scriptData: (0, import_utils16.hexlify)(scriptData)
|
2830
2983
|
};
|
2831
2984
|
}
|
2832
2985
|
/**
|
@@ -2964,10 +3117,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2964
3117
|
};
|
2965
3118
|
|
2966
3119
|
// src/providers/transaction-request/utils.ts
|
2967
|
-
var
|
3120
|
+
var import_errors10 = require("@fuel-ts/errors");
|
2968
3121
|
var import_transactions11 = require("@fuel-ts/transactions");
|
2969
3122
|
var transactionRequestify = (obj) => {
|
2970
|
-
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
3123
|
+
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest) {
|
2971
3124
|
return obj;
|
2972
3125
|
}
|
2973
3126
|
const { type } = obj;
|
@@ -2978,30 +3131,36 @@ var transactionRequestify = (obj) => {
|
|
2978
3131
|
case import_transactions11.TransactionType.Create: {
|
2979
3132
|
return CreateTransactionRequest.from(obj);
|
2980
3133
|
}
|
3134
|
+
case import_transactions11.TransactionType.Blob: {
|
3135
|
+
return BlobTransactionRequest.from(obj);
|
3136
|
+
}
|
2981
3137
|
default: {
|
2982
|
-
throw new
|
2983
|
-
|
3138
|
+
throw new import_errors10.FuelError(
|
3139
|
+
import_errors10.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
2984
3140
|
`Unsupported transaction type: ${type}.`
|
2985
3141
|
);
|
2986
3142
|
}
|
2987
3143
|
}
|
2988
3144
|
};
|
3145
|
+
var isTransactionTypeScript = (request) => request.type === import_transactions11.TransactionType.Script;
|
3146
|
+
var isTransactionTypeCreate = (request) => request.type === import_transactions11.TransactionType.Create;
|
3147
|
+
var isTransactionTypeBlob = (request) => request.type === import_transactions11.TransactionType.Blob;
|
2989
3148
|
|
2990
3149
|
// src/providers/transaction-response/transaction-response.ts
|
2991
|
-
var
|
2992
|
-
var
|
3150
|
+
var import_errors14 = require("@fuel-ts/errors");
|
3151
|
+
var import_math17 = require("@fuel-ts/math");
|
2993
3152
|
var import_transactions19 = require("@fuel-ts/transactions");
|
2994
|
-
var
|
3153
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2995
3154
|
|
2996
3155
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2997
|
-
var
|
3156
|
+
var import_math16 = require("@fuel-ts/math");
|
2998
3157
|
var import_transactions17 = require("@fuel-ts/transactions");
|
2999
|
-
var
|
3158
|
+
var import_utils19 = require("@fuel-ts/utils");
|
3000
3159
|
|
3001
3160
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
3002
3161
|
var import_math12 = require("@fuel-ts/math");
|
3003
3162
|
var import_transactions12 = require("@fuel-ts/transactions");
|
3004
|
-
var
|
3163
|
+
var import_utils17 = require("@fuel-ts/utils");
|
3005
3164
|
var calculateTXFeeForSummary = (params) => {
|
3006
3165
|
const {
|
3007
3166
|
gasPrice,
|
@@ -3015,7 +3174,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3015
3174
|
}
|
3016
3175
|
const gasPerByte = (0, import_math12.bn)(feeParams.gasPerByte);
|
3017
3176
|
const gasPriceFactor = (0, import_math12.bn)(feeParams.gasPriceFactor);
|
3018
|
-
const transactionBytes = (0,
|
3177
|
+
const transactionBytes = (0, import_utils17.arrayify)(rawPayload);
|
3019
3178
|
const [transaction] = new import_transactions12.TransactionCoder().decode(transactionBytes, 0);
|
3020
3179
|
const { type, witnesses, inputs, policies } = transaction;
|
3021
3180
|
let metadataGas = (0, import_math12.bn)(0);
|
@@ -3025,7 +3184,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3025
3184
|
}
|
3026
3185
|
if (type === import_transactions12.TransactionType.Create) {
|
3027
3186
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
3028
|
-
const contractBytesSize = (0, import_math12.bn)((0,
|
3187
|
+
const contractBytesSize = (0, import_math12.bn)((0, import_utils17.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
3029
3188
|
metadataGas = calculateMetadataGasForTxCreate({
|
3030
3189
|
contractBytesSize,
|
3031
3190
|
gasCosts,
|
@@ -3070,8 +3229,8 @@ var calculateTXFeeForSummary = (params) => {
|
|
3070
3229
|
|
3071
3230
|
// src/providers/transaction-summary/operations.ts
|
3072
3231
|
var import_configs10 = require("@fuel-ts/address/configs");
|
3073
|
-
var
|
3074
|
-
var
|
3232
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3233
|
+
var import_math14 = require("@fuel-ts/math");
|
3075
3234
|
var import_transactions15 = require("@fuel-ts/transactions");
|
3076
3235
|
|
3077
3236
|
// src/providers/transaction-summary/call.ts
|
@@ -3108,7 +3267,8 @@ var getFunctionCall = ({ abi, receipt }) => {
|
|
3108
3267
|
};
|
3109
3268
|
|
3110
3269
|
// src/providers/transaction-summary/input.ts
|
3111
|
-
var
|
3270
|
+
var import_errors11 = require("@fuel-ts/errors");
|
3271
|
+
var import_math13 = require("@fuel-ts/math");
|
3112
3272
|
var import_transactions13 = require("@fuel-ts/transactions");
|
3113
3273
|
function getInputsByTypes(inputs, types) {
|
3114
3274
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -3125,17 +3285,47 @@ function getInputsMessage(inputs) {
|
|
3125
3285
|
function getInputsCoinAndMessage(inputs) {
|
3126
3286
|
return getInputsByTypes(inputs, [import_transactions13.InputType.Coin, import_transactions13.InputType.Message]);
|
3127
3287
|
}
|
3288
|
+
function isInputCoin(input) {
|
3289
|
+
return input.type === import_transactions13.InputType.Coin;
|
3290
|
+
}
|
3128
3291
|
function getInputsContract(inputs) {
|
3129
3292
|
return getInputsByType(inputs, import_transactions13.InputType.Contract);
|
3130
3293
|
}
|
3131
|
-
function
|
3294
|
+
function findCoinInput(inputs, assetId) {
|
3132
3295
|
const coinInputs = getInputsCoin(inputs);
|
3133
|
-
|
3134
|
-
|
3135
|
-
|
3136
|
-
|
3137
|
-
)
|
3138
|
-
|
3296
|
+
return coinInputs.find((i) => i.assetId === assetId);
|
3297
|
+
}
|
3298
|
+
function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetID) {
|
3299
|
+
const aggregated = /* @__PURE__ */ new Map();
|
3300
|
+
getInputsCoinAndMessage(inputs).forEach((input) => {
|
3301
|
+
const assetId = isInputCoin(input) ? input.assetId : baseAssetID;
|
3302
|
+
const owner = isInputCoin(input) ? input.owner : input.recipient;
|
3303
|
+
let ownersMap = aggregated.get(assetId);
|
3304
|
+
if (!ownersMap) {
|
3305
|
+
ownersMap = /* @__PURE__ */ new Map();
|
3306
|
+
aggregated.set(assetId, ownersMap);
|
3307
|
+
}
|
3308
|
+
let ownerBalance = ownersMap.get(owner);
|
3309
|
+
if (!ownerBalance) {
|
3310
|
+
ownerBalance = new import_math13.BN(0);
|
3311
|
+
ownersMap.set(owner, ownerBalance);
|
3312
|
+
}
|
3313
|
+
ownersMap.set(owner, ownerBalance.add(input.amount));
|
3314
|
+
});
|
3315
|
+
return aggregated;
|
3316
|
+
}
|
3317
|
+
function findMessageInput(inputs) {
|
3318
|
+
return getInputsMessage(inputs)?.[0];
|
3319
|
+
}
|
3320
|
+
function getInputFromAssetId(inputs, assetId, isBaseAsset = false) {
|
3321
|
+
const coinInput = findCoinInput(inputs, assetId);
|
3322
|
+
if (coinInput) {
|
3323
|
+
return coinInput;
|
3324
|
+
}
|
3325
|
+
if (isBaseAsset) {
|
3326
|
+
return findMessageInput(inputs);
|
3327
|
+
}
|
3328
|
+
return void 0;
|
3139
3329
|
}
|
3140
3330
|
function getInputContractFromIndex(inputs, inputIndex) {
|
3141
3331
|
if (inputIndex == null) {
|
@@ -3146,8 +3336,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
3146
3336
|
return void 0;
|
3147
3337
|
}
|
3148
3338
|
if (contractInput.type !== import_transactions13.InputType.Contract) {
|
3149
|
-
throw new
|
3150
|
-
|
3339
|
+
throw new import_errors11.FuelError(
|
3340
|
+
import_errors11.ErrorCode.INVALID_TRANSACTION_INPUT,
|
3151
3341
|
`Contract input should be of type 'contract'.`
|
3152
3342
|
);
|
3153
3343
|
}
|
@@ -3191,6 +3381,7 @@ var TransactionTypeName = /* @__PURE__ */ ((TransactionTypeName2) => {
|
|
3191
3381
|
TransactionTypeName2["Script"] = "Script";
|
3192
3382
|
TransactionTypeName2["Upgrade"] = "Upgrade";
|
3193
3383
|
TransactionTypeName2["Upload"] = "Upload";
|
3384
|
+
TransactionTypeName2["Blob"] = "Blob";
|
3194
3385
|
return TransactionTypeName2;
|
3195
3386
|
})(TransactionTypeName || {});
|
3196
3387
|
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
@@ -3236,9 +3427,11 @@ function getTransactionTypeName(transactionType) {
|
|
3236
3427
|
return "Create" /* Create */;
|
3237
3428
|
case import_transactions15.TransactionType.Script:
|
3238
3429
|
return "Script" /* Script */;
|
3430
|
+
case import_transactions15.TransactionType.Blob:
|
3431
|
+
return "Blob" /* Blob */;
|
3239
3432
|
default:
|
3240
|
-
throw new
|
3241
|
-
|
3433
|
+
throw new import_errors12.FuelError(
|
3434
|
+
import_errors12.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
3242
3435
|
`Unsupported transaction type: ${transactionType}.`
|
3243
3436
|
);
|
3244
3437
|
}
|
@@ -3262,6 +3455,9 @@ function isTypeUpgrade(transactionType) {
|
|
3262
3455
|
function isTypeUpload(transactionType) {
|
3263
3456
|
return isType(transactionType, "Upload" /* Upload */);
|
3264
3457
|
}
|
3458
|
+
function isTypeBlob(transactionType) {
|
3459
|
+
return isType(transactionType, "Blob" /* Blob */);
|
3460
|
+
}
|
3265
3461
|
function hasSameAssetId(a) {
|
3266
3462
|
return (b) => a.assetId === b.assetId;
|
3267
3463
|
}
|
@@ -3271,41 +3467,51 @@ function getReceiptsCall(receipts) {
|
|
3271
3467
|
function getReceiptsMessageOut(receipts) {
|
3272
3468
|
return getReceiptsByType(receipts, import_transactions15.ReceiptType.MessageOut);
|
3273
3469
|
}
|
3274
|
-
|
3470
|
+
function mergeAssets(op1, op2) {
|
3275
3471
|
const assets1 = op1.assetsSent || [];
|
3276
3472
|
const assets2 = op2.assetsSent || [];
|
3277
|
-
const
|
3278
|
-
|
3279
|
-
|
3280
|
-
|
3281
|
-
|
3282
|
-
|
3283
|
-
|
3473
|
+
const assetMap = /* @__PURE__ */ new Map();
|
3474
|
+
assets1.forEach((asset) => {
|
3475
|
+
assetMap.set(asset.assetId, { ...asset });
|
3476
|
+
});
|
3477
|
+
assets2.forEach((asset) => {
|
3478
|
+
const existingAsset = assetMap.get(asset.assetId);
|
3479
|
+
if (existingAsset) {
|
3480
|
+
existingAsset.amount = (0, import_math14.bn)(existingAsset.amount).add(asset.amount);
|
3481
|
+
} else {
|
3482
|
+
assetMap.set(asset.assetId, { ...asset });
|
3284
3483
|
}
|
3285
|
-
const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
|
3286
|
-
return { ...asset1, amount: mergedAmount };
|
3287
3484
|
});
|
3288
|
-
return
|
3289
|
-
}
|
3485
|
+
return Array.from(assetMap.values());
|
3486
|
+
}
|
3290
3487
|
function isSameOperation(a, b) {
|
3291
3488
|
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;
|
3292
3489
|
}
|
3490
|
+
function mergeAssetsSent(existing, toAdd) {
|
3491
|
+
if (!toAdd.assetsSent?.length) {
|
3492
|
+
return existing.assetsSent;
|
3493
|
+
}
|
3494
|
+
return existing.assetsSent?.length ? mergeAssets(existing, toAdd) : toAdd.assetsSent;
|
3495
|
+
}
|
3496
|
+
function mergeCalls(existing, toAdd) {
|
3497
|
+
if (!toAdd.calls?.length) {
|
3498
|
+
return existing.calls;
|
3499
|
+
}
|
3500
|
+
return [...existing.calls || [], ...toAdd.calls];
|
3501
|
+
}
|
3502
|
+
function mergeOperations(existing, toAdd) {
|
3503
|
+
return {
|
3504
|
+
...existing,
|
3505
|
+
assetsSent: mergeAssetsSent(existing, toAdd),
|
3506
|
+
calls: mergeCalls(existing, toAdd)
|
3507
|
+
};
|
3508
|
+
}
|
3293
3509
|
function addOperation(operations, toAdd) {
|
3294
|
-
const
|
3295
|
-
|
3296
|
-
|
3297
|
-
const existentOperation = { ...allOperations[index] };
|
3298
|
-
if (toAdd.assetsSent?.length) {
|
3299
|
-
existentOperation.assetsSent = existentOperation.assetsSent?.length ? mergeAssets(existentOperation, toAdd) : toAdd.assetsSent;
|
3300
|
-
}
|
3301
|
-
if (toAdd.calls?.length) {
|
3302
|
-
existentOperation.calls = [...existentOperation.calls || [], ...toAdd.calls];
|
3303
|
-
}
|
3304
|
-
allOperations[index] = existentOperation;
|
3305
|
-
} else {
|
3306
|
-
allOperations.push(toAdd);
|
3510
|
+
const existingIndex = operations.findIndex((op) => isSameOperation(op, toAdd));
|
3511
|
+
if (existingIndex === -1) {
|
3512
|
+
return [...operations, toAdd];
|
3307
3513
|
}
|
3308
|
-
return
|
3514
|
+
return operations.map((op, index) => index === existingIndex ? mergeOperations(op, toAdd) : op);
|
3309
3515
|
}
|
3310
3516
|
function getReceiptsTransferOut(receipts) {
|
3311
3517
|
return getReceiptsByType(receipts, import_transactions15.ReceiptType.TransferOut);
|
@@ -3318,7 +3524,7 @@ function getWithdrawFromFuelOperations({
|
|
3318
3524
|
const messageOutReceipts = getReceiptsMessageOut(receipts);
|
3319
3525
|
const withdrawFromFuelOperations = messageOutReceipts.reduce(
|
3320
3526
|
(prevWithdrawFromFuelOps, receipt) => {
|
3321
|
-
const input = getInputFromAssetId(inputs, baseAssetId);
|
3527
|
+
const input = getInputFromAssetId(inputs, baseAssetId, true);
|
3322
3528
|
if (input) {
|
3323
3529
|
const inputAddress = getInputAccountAddress(input);
|
3324
3530
|
const newWithdrawFromFuelOps = addOperation(prevWithdrawFromFuelOps, {
|
@@ -3347,65 +3553,80 @@ function getWithdrawFromFuelOperations({
|
|
3347
3553
|
);
|
3348
3554
|
return withdrawFromFuelOperations;
|
3349
3555
|
}
|
3556
|
+
function getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs) {
|
3557
|
+
const abi = abiMap?.[contractInput.contractID];
|
3558
|
+
if (!abi) {
|
3559
|
+
return [];
|
3560
|
+
}
|
3561
|
+
return [
|
3562
|
+
getFunctionCall({
|
3563
|
+
abi,
|
3564
|
+
receipt,
|
3565
|
+
rawPayload,
|
3566
|
+
maxInputs
|
3567
|
+
})
|
3568
|
+
];
|
3569
|
+
}
|
3570
|
+
function getAssetsSent(receipt) {
|
3571
|
+
return receipt.amount?.isZero() ? void 0 : [
|
3572
|
+
{
|
3573
|
+
amount: receipt.amount,
|
3574
|
+
assetId: receipt.assetId
|
3575
|
+
}
|
3576
|
+
];
|
3577
|
+
}
|
3578
|
+
function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload, maxInputs, baseAssetId) {
|
3579
|
+
const assetId = receipt.assetId === import_configs10.ZeroBytes32 ? baseAssetId : receipt.assetId;
|
3580
|
+
const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
|
3581
|
+
if (!input) {
|
3582
|
+
return [];
|
3583
|
+
}
|
3584
|
+
const inputAddress = getInputAccountAddress(input);
|
3585
|
+
const calls = getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs);
|
3586
|
+
return [
|
3587
|
+
{
|
3588
|
+
name: "Contract call" /* contractCall */,
|
3589
|
+
from: {
|
3590
|
+
type: 1 /* account */,
|
3591
|
+
address: inputAddress
|
3592
|
+
},
|
3593
|
+
to: {
|
3594
|
+
type: 0 /* contract */,
|
3595
|
+
address: receipt.to
|
3596
|
+
},
|
3597
|
+
assetsSent: getAssetsSent(receipt),
|
3598
|
+
calls
|
3599
|
+
}
|
3600
|
+
];
|
3601
|
+
}
|
3350
3602
|
function getContractCallOperations({
|
3351
3603
|
inputs,
|
3352
3604
|
outputs,
|
3353
3605
|
receipts,
|
3354
3606
|
abiMap,
|
3355
3607
|
rawPayload,
|
3356
|
-
maxInputs
|
3608
|
+
maxInputs,
|
3609
|
+
baseAssetId
|
3357
3610
|
}) {
|
3358
3611
|
const contractCallReceipts = getReceiptsCall(receipts);
|
3359
3612
|
const contractOutputs = getOutputsContract(outputs);
|
3360
|
-
|
3613
|
+
return contractOutputs.flatMap((output) => {
|
3361
3614
|
const contractInput = getInputContractFromIndex(inputs, output.inputIndex);
|
3362
|
-
if (contractInput) {
|
3363
|
-
|
3364
|
-
if (receipt.to === contractInput.contractID) {
|
3365
|
-
const input = getInputFromAssetId(inputs, receipt.assetId);
|
3366
|
-
if (input) {
|
3367
|
-
const inputAddress = getInputAccountAddress(input);
|
3368
|
-
const calls = [];
|
3369
|
-
const abi = abiMap?.[contractInput.contractID];
|
3370
|
-
if (abi) {
|
3371
|
-
calls.push(
|
3372
|
-
getFunctionCall({
|
3373
|
-
abi,
|
3374
|
-
receipt,
|
3375
|
-
rawPayload,
|
3376
|
-
maxInputs
|
3377
|
-
})
|
3378
|
-
);
|
3379
|
-
}
|
3380
|
-
const newContractCallOps = addOperation(prevContractCallOps, {
|
3381
|
-
name: "Contract call" /* contractCall */,
|
3382
|
-
from: {
|
3383
|
-
type: 1 /* account */,
|
3384
|
-
address: inputAddress
|
3385
|
-
},
|
3386
|
-
to: {
|
3387
|
-
type: 0 /* contract */,
|
3388
|
-
address: receipt.to
|
3389
|
-
},
|
3390
|
-
// if no amount is forwarded to the contract, skip showing assetsSent
|
3391
|
-
assetsSent: receipt.amount?.isZero() ? void 0 : [
|
3392
|
-
{
|
3393
|
-
amount: receipt.amount,
|
3394
|
-
assetId: receipt.assetId
|
3395
|
-
}
|
3396
|
-
],
|
3397
|
-
calls
|
3398
|
-
});
|
3399
|
-
return newContractCallOps;
|
3400
|
-
}
|
3401
|
-
}
|
3402
|
-
return prevContractCallOps;
|
3403
|
-
}, prevOutputCallOps);
|
3404
|
-
return newCallOps;
|
3615
|
+
if (!contractInput) {
|
3616
|
+
return [];
|
3405
3617
|
}
|
3406
|
-
return
|
3407
|
-
|
3408
|
-
|
3618
|
+
return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
|
3619
|
+
(receipt) => processCallReceipt(
|
3620
|
+
receipt,
|
3621
|
+
contractInput,
|
3622
|
+
inputs,
|
3623
|
+
abiMap,
|
3624
|
+
rawPayload,
|
3625
|
+
maxInputs,
|
3626
|
+
baseAssetId
|
3627
|
+
)
|
3628
|
+
);
|
3629
|
+
});
|
3409
3630
|
}
|
3410
3631
|
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
3411
3632
|
const { to: toAddress, assetId, amount } = receipt;
|
@@ -3437,32 +3658,40 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3437
3658
|
function getTransferOperations({
|
3438
3659
|
inputs,
|
3439
3660
|
outputs,
|
3440
|
-
receipts
|
3661
|
+
receipts,
|
3662
|
+
baseAssetId
|
3441
3663
|
}) {
|
3442
3664
|
let operations = [];
|
3443
3665
|
const coinOutputs = getOutputsCoin(outputs);
|
3444
3666
|
const contractInputs = getInputsContract(inputs);
|
3445
3667
|
const changeOutputs = getOutputsChange(outputs);
|
3446
|
-
|
3447
|
-
|
3448
|
-
const
|
3449
|
-
|
3668
|
+
const aggregated = aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId);
|
3669
|
+
coinOutputs.forEach(({ amount, assetId, to }) => {
|
3670
|
+
const txPayers = aggregated.get(assetId) || /* @__PURE__ */ new Map();
|
3671
|
+
let selectedPayer;
|
3672
|
+
let fallbackPayer;
|
3673
|
+
for (const [address, payedAmount] of txPayers) {
|
3674
|
+
if (!fallbackPayer) {
|
3675
|
+
fallbackPayer = address;
|
3676
|
+
}
|
3677
|
+
if (payedAmount.gte(amount)) {
|
3678
|
+
selectedPayer = address;
|
3679
|
+
break;
|
3680
|
+
}
|
3681
|
+
}
|
3682
|
+
selectedPayer = selectedPayer || fallbackPayer;
|
3683
|
+
if (selectedPayer) {
|
3450
3684
|
operations = addOperation(operations, {
|
3451
3685
|
name: "Transfer asset" /* transfer */,
|
3452
3686
|
from: {
|
3453
3687
|
type: 1 /* account */,
|
3454
|
-
address:
|
3688
|
+
address: selectedPayer
|
3455
3689
|
},
|
3456
3690
|
to: {
|
3457
3691
|
type: 1 /* account */,
|
3458
3692
|
address: to
|
3459
3693
|
},
|
3460
|
-
assetsSent: [
|
3461
|
-
{
|
3462
|
-
assetId,
|
3463
|
-
amount
|
3464
|
-
}
|
3465
|
-
]
|
3694
|
+
assetsSent: [{ assetId, amount }]
|
3466
3695
|
});
|
3467
3696
|
}
|
3468
3697
|
});
|
@@ -3535,21 +3764,19 @@ function getOperations({
|
|
3535
3764
|
baseAssetId
|
3536
3765
|
}) {
|
3537
3766
|
if (isTypeCreate(transactionType)) {
|
3538
|
-
return [
|
3539
|
-
...getContractCreatedOperations({ inputs, outputs }),
|
3540
|
-
...getTransferOperations({ inputs, outputs, receipts })
|
3541
|
-
];
|
3767
|
+
return [...getContractCreatedOperations({ inputs, outputs })];
|
3542
3768
|
}
|
3543
3769
|
if (isTypeScript(transactionType)) {
|
3544
3770
|
return [
|
3545
|
-
...getTransferOperations({ inputs, outputs, receipts }),
|
3771
|
+
...getTransferOperations({ inputs, outputs, receipts, baseAssetId }),
|
3546
3772
|
...getContractCallOperations({
|
3547
3773
|
inputs,
|
3548
3774
|
outputs,
|
3549
3775
|
receipts,
|
3550
3776
|
abiMap,
|
3551
3777
|
rawPayload,
|
3552
|
-
maxInputs
|
3778
|
+
maxInputs,
|
3779
|
+
baseAssetId
|
3553
3780
|
}),
|
3554
3781
|
...getWithdrawFromFuelOperations({ inputs, receipts, baseAssetId })
|
3555
3782
|
];
|
@@ -3608,8 +3835,8 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3608
3835
|
};
|
3609
3836
|
|
3610
3837
|
// src/providers/transaction-summary/status.ts
|
3611
|
-
var
|
3612
|
-
var
|
3838
|
+
var import_errors13 = require("@fuel-ts/errors");
|
3839
|
+
var import_math15 = require("@fuel-ts/math");
|
3613
3840
|
var getTransactionStatusName = (gqlStatus) => {
|
3614
3841
|
switch (gqlStatus) {
|
3615
3842
|
case "FailureStatus":
|
@@ -3621,8 +3848,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3621
3848
|
case "SqueezedOutStatus":
|
3622
3849
|
return "squeezedout" /* squeezedout */;
|
3623
3850
|
default:
|
3624
|
-
throw new
|
3625
|
-
|
3851
|
+
throw new import_errors13.FuelError(
|
3852
|
+
import_errors13.ErrorCode.INVALID_TRANSACTION_STATUS,
|
3626
3853
|
`Invalid transaction status: ${gqlStatus}.`
|
3627
3854
|
);
|
3628
3855
|
}
|
@@ -3643,15 +3870,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
3643
3870
|
time = gqlTransactionStatus.time;
|
3644
3871
|
blockId = gqlTransactionStatus.block.id;
|
3645
3872
|
isStatusSuccess = true;
|
3646
|
-
totalFee = (0,
|
3647
|
-
totalGas = (0,
|
3873
|
+
totalFee = (0, import_math15.bn)(gqlTransactionStatus.totalFee);
|
3874
|
+
totalGas = (0, import_math15.bn)(gqlTransactionStatus.totalGas);
|
3648
3875
|
break;
|
3649
3876
|
case "FailureStatus":
|
3650
3877
|
time = gqlTransactionStatus.time;
|
3651
3878
|
blockId = gqlTransactionStatus.block.id;
|
3652
3879
|
isStatusFailure = true;
|
3653
|
-
totalFee = (0,
|
3654
|
-
totalGas = (0,
|
3880
|
+
totalFee = (0, import_math15.bn)(gqlTransactionStatus.totalFee);
|
3881
|
+
totalGas = (0, import_math15.bn)(gqlTransactionStatus.totalGas);
|
3655
3882
|
break;
|
3656
3883
|
case "SubmittedStatus":
|
3657
3884
|
time = gqlTransactionStatus.time;
|
@@ -3691,7 +3918,7 @@ function assembleTransactionSummary(params) {
|
|
3691
3918
|
baseAssetId
|
3692
3919
|
} = params;
|
3693
3920
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3694
|
-
const rawPayload = (0,
|
3921
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3695
3922
|
const operations = getOperations({
|
3696
3923
|
transactionType: transaction.type,
|
3697
3924
|
inputs: transaction.inputs || [],
|
@@ -3703,7 +3930,7 @@ function assembleTransactionSummary(params) {
|
|
3703
3930
|
baseAssetId
|
3704
3931
|
});
|
3705
3932
|
const typeName = getTransactionTypeName(transaction.type);
|
3706
|
-
const tip = (0,
|
3933
|
+
const tip = (0, import_math16.bn)(transaction.policies?.find((policy) => policy.type === import_transactions17.PolicyType.Tip)?.data);
|
3707
3934
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
3708
3935
|
const fee = calculateTXFeeForSummary({
|
3709
3936
|
totalFee,
|
@@ -3723,7 +3950,7 @@ function assembleTransactionSummary(params) {
|
|
3723
3950
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3724
3951
|
let date;
|
3725
3952
|
if (time) {
|
3726
|
-
date =
|
3953
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3727
3954
|
}
|
3728
3955
|
const transactionSummary = {
|
3729
3956
|
id,
|
@@ -3743,6 +3970,7 @@ function assembleTransactionSummary(params) {
|
|
3743
3970
|
isTypeScript: isTypeScript(transaction.type),
|
3744
3971
|
isTypeUpgrade: isTypeUpgrade(transaction.type),
|
3745
3972
|
isTypeUpload: isTypeUpload(transaction.type),
|
3973
|
+
isTypeBlob: isTypeBlob(transaction.type),
|
3746
3974
|
isStatusFailure,
|
3747
3975
|
isStatusSuccess,
|
3748
3976
|
isStatusPending,
|
@@ -3768,26 +3996,59 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
3768
3996
|
}
|
3769
3997
|
|
3770
3998
|
// src/providers/transaction-response/transaction-response.ts
|
3999
|
+
function mapGqlOutputsToTxOutputs(outputs) {
|
4000
|
+
return outputs.map((o) => {
|
4001
|
+
const obj = "amount" in o ? { ...o, amount: (0, import_math17.bn)(o.amount) } : o;
|
4002
|
+
switch (obj.type) {
|
4003
|
+
case "CoinOutput":
|
4004
|
+
return { ...obj, type: import_transactions19.OutputType.Coin };
|
4005
|
+
case "ContractOutput":
|
4006
|
+
return {
|
4007
|
+
...obj,
|
4008
|
+
type: import_transactions19.OutputType.Contract,
|
4009
|
+
inputIndex: parseInt(obj.inputIndex, 10)
|
4010
|
+
};
|
4011
|
+
case "ChangeOutput":
|
4012
|
+
return {
|
4013
|
+
...obj,
|
4014
|
+
type: import_transactions19.OutputType.Change
|
4015
|
+
};
|
4016
|
+
case "VariableOutput":
|
4017
|
+
return { ...obj, type: import_transactions19.OutputType.Variable };
|
4018
|
+
case "ContractCreated":
|
4019
|
+
return {
|
4020
|
+
...obj,
|
4021
|
+
type: import_transactions19.OutputType.ContractCreated,
|
4022
|
+
contractId: obj.contract
|
4023
|
+
};
|
4024
|
+
default:
|
4025
|
+
return (0, import_utils21.assertUnreachable)(obj);
|
4026
|
+
}
|
4027
|
+
});
|
4028
|
+
}
|
3771
4029
|
var TransactionResponse = class {
|
3772
4030
|
/** Transaction ID */
|
3773
4031
|
id;
|
3774
4032
|
/** Current provider */
|
3775
4033
|
provider;
|
3776
4034
|
/** Gas used on the transaction */
|
3777
|
-
gasUsed = (0,
|
4035
|
+
gasUsed = (0, import_math17.bn)(0);
|
3778
4036
|
/** The graphql Transaction with receipts object. */
|
3779
4037
|
gqlTransaction;
|
4038
|
+
request;
|
4039
|
+
status;
|
3780
4040
|
abis;
|
3781
4041
|
/**
|
3782
4042
|
* Constructor for `TransactionResponse`.
|
3783
4043
|
*
|
3784
|
-
* @param
|
4044
|
+
* @param tx - The transaction ID or TransactionRequest.
|
3785
4045
|
* @param provider - The provider.
|
3786
4046
|
*/
|
3787
|
-
constructor(
|
3788
|
-
this.id =
|
4047
|
+
constructor(tx, provider, abis) {
|
4048
|
+
this.id = typeof tx === "string" ? tx : tx.getTransactionId(provider.getChainId());
|
3789
4049
|
this.provider = provider;
|
3790
4050
|
this.abis = abis;
|
4051
|
+
this.request = typeof tx === "string" ? void 0 : tx;
|
3791
4052
|
}
|
3792
4053
|
/**
|
3793
4054
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
@@ -3802,6 +4063,54 @@ var TransactionResponse = class {
|
|
3802
4063
|
await response.fetch();
|
3803
4064
|
return response;
|
3804
4065
|
}
|
4066
|
+
applyMalleableSubscriptionFields(transaction) {
|
4067
|
+
const status = this.status;
|
4068
|
+
if (!status) {
|
4069
|
+
return;
|
4070
|
+
}
|
4071
|
+
const tx = transaction;
|
4072
|
+
if (status.type === "SuccessStatus" || status.type === "FailureStatus") {
|
4073
|
+
tx.inputs = tx.inputs.map((input, idx) => {
|
4074
|
+
if ("txPointer" in input) {
|
4075
|
+
const correspondingInput = status.transaction.inputs?.[idx];
|
4076
|
+
return {
|
4077
|
+
...input,
|
4078
|
+
txPointer: import_transactions19.TxPointerCoder.decodeFromGqlScalar(correspondingInput.txPointer)
|
4079
|
+
};
|
4080
|
+
}
|
4081
|
+
return input;
|
4082
|
+
});
|
4083
|
+
tx.outputs = mapGqlOutputsToTxOutputs(status.transaction.outputs);
|
4084
|
+
if ("receiptsRoot" in status.transaction) {
|
4085
|
+
tx.receiptsRoot = status.transaction.receiptsRoot;
|
4086
|
+
}
|
4087
|
+
}
|
4088
|
+
}
|
4089
|
+
async getTransaction() {
|
4090
|
+
if (this.request) {
|
4091
|
+
const tx = this.request.toTransaction();
|
4092
|
+
this.applyMalleableSubscriptionFields(tx);
|
4093
|
+
return {
|
4094
|
+
tx,
|
4095
|
+
bytes: this.request.toTransactionBytes()
|
4096
|
+
};
|
4097
|
+
}
|
4098
|
+
const gqlTransaction = this.gqlTransaction ?? await this.fetch();
|
4099
|
+
return {
|
4100
|
+
tx: this.decodeTransaction(gqlTransaction),
|
4101
|
+
bytes: (0, import_utils21.arrayify)(gqlTransaction.rawPayload)
|
4102
|
+
};
|
4103
|
+
}
|
4104
|
+
getReceipts() {
|
4105
|
+
const status = this.status ?? this.gqlTransaction?.status;
|
4106
|
+
switch (status?.type) {
|
4107
|
+
case "SuccessStatus":
|
4108
|
+
case "FailureStatus":
|
4109
|
+
return status.receipts.map(processGqlReceipt);
|
4110
|
+
default:
|
4111
|
+
return [];
|
4112
|
+
}
|
4113
|
+
}
|
3805
4114
|
/**
|
3806
4115
|
* Fetch the transaction with receipts from the provider.
|
3807
4116
|
*
|
@@ -3812,11 +4121,12 @@ var TransactionResponse = class {
|
|
3812
4121
|
transactionId: this.id
|
3813
4122
|
});
|
3814
4123
|
if (!response.transaction) {
|
3815
|
-
const subscription = this.provider.operations.statusChange({
|
4124
|
+
const subscription = await this.provider.operations.statusChange({
|
3816
4125
|
transactionId: this.id
|
3817
4126
|
});
|
3818
4127
|
for await (const { statusChange } of subscription) {
|
3819
4128
|
if (statusChange) {
|
4129
|
+
this.status = statusChange;
|
3820
4130
|
break;
|
3821
4131
|
}
|
3822
4132
|
}
|
@@ -3833,7 +4143,7 @@ var TransactionResponse = class {
|
|
3833
4143
|
*/
|
3834
4144
|
decodeTransaction(transactionWithReceipts) {
|
3835
4145
|
return new import_transactions19.TransactionCoder().decode(
|
3836
|
-
(0,
|
4146
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3837
4147
|
0
|
3838
4148
|
)?.[0];
|
3839
4149
|
}
|
@@ -3845,28 +4155,17 @@ var TransactionResponse = class {
|
|
3845
4155
|
* @returns
|
3846
4156
|
*/
|
3847
4157
|
async getTransactionSummary(contractsAbiMap) {
|
3848
|
-
|
3849
|
-
if (!transaction) {
|
3850
|
-
transaction = await this.fetch();
|
3851
|
-
}
|
3852
|
-
const decodedTransaction = this.decodeTransaction(
|
3853
|
-
transaction
|
3854
|
-
);
|
3855
|
-
let txReceipts = [];
|
3856
|
-
if (transaction?.status && "receipts" in transaction.status) {
|
3857
|
-
txReceipts = transaction.status.receipts;
|
3858
|
-
}
|
3859
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
4158
|
+
const { tx: transaction, bytes: transactionBytes } = await this.getTransaction();
|
3860
4159
|
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3861
4160
|
const gasPrice = await this.provider.getLatestGasPrice();
|
3862
4161
|
const maxInputs = this.provider.getChain().consensusParameters.txParameters.maxInputs;
|
3863
4162
|
const baseAssetId = this.provider.getBaseAssetId();
|
3864
4163
|
const transactionSummary = assembleTransactionSummary({
|
3865
4164
|
id: this.id,
|
3866
|
-
receipts,
|
3867
|
-
transaction
|
3868
|
-
transactionBytes
|
3869
|
-
gqlTransactionStatus:
|
4165
|
+
receipts: this.getReceipts(),
|
4166
|
+
transaction,
|
4167
|
+
transactionBytes,
|
4168
|
+
gqlTransactionStatus: this.status ?? this.gqlTransaction?.status,
|
3870
4169
|
gasPerByte,
|
3871
4170
|
gasPriceFactor,
|
3872
4171
|
abiMap: contractsAbiMap,
|
@@ -3883,13 +4182,15 @@ var TransactionResponse = class {
|
|
3883
4182
|
if (status && status !== "SubmittedStatus") {
|
3884
4183
|
return;
|
3885
4184
|
}
|
3886
|
-
const subscription = this.provider.operations.statusChange({
|
4185
|
+
const subscription = await this.provider.operations.statusChange({
|
3887
4186
|
transactionId: this.id
|
3888
4187
|
});
|
3889
4188
|
for await (const { statusChange } of subscription) {
|
4189
|
+
this.status = statusChange;
|
3890
4190
|
if (statusChange.type === "SqueezedOutStatus") {
|
3891
|
-
|
3892
|
-
|
4191
|
+
this.unsetResourceCache();
|
4192
|
+
throw new import_errors14.FuelError(
|
4193
|
+
import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3893
4194
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3894
4195
|
);
|
3895
4196
|
}
|
@@ -3897,7 +4198,6 @@ var TransactionResponse = class {
|
|
3897
4198
|
break;
|
3898
4199
|
}
|
3899
4200
|
}
|
3900
|
-
await this.fetch();
|
3901
4201
|
}
|
3902
4202
|
/**
|
3903
4203
|
* Assembles the result of a transaction by retrieving the transaction summary,
|
@@ -3914,7 +4214,6 @@ var TransactionResponse = class {
|
|
3914
4214
|
async assembleResult(contractsAbiMap) {
|
3915
4215
|
const transactionSummary = await this.getTransactionSummary(contractsAbiMap);
|
3916
4216
|
const transactionResult = {
|
3917
|
-
gqlTransaction: this.gqlTransaction,
|
3918
4217
|
...transactionSummary
|
3919
4218
|
};
|
3920
4219
|
let logs = [];
|
@@ -3926,9 +4225,11 @@ var TransactionResponse = class {
|
|
3926
4225
|
);
|
3927
4226
|
transactionResult.logs = logs;
|
3928
4227
|
}
|
3929
|
-
const {
|
3930
|
-
|
3931
|
-
|
4228
|
+
const { receipts } = transactionResult;
|
4229
|
+
const status = this.status ?? this.gqlTransaction?.status;
|
4230
|
+
if (status?.type === "FailureStatus") {
|
4231
|
+
this.unsetResourceCache();
|
4232
|
+
const { reason } = status;
|
3932
4233
|
throw extractTxError({
|
3933
4234
|
receipts,
|
3934
4235
|
statusReason: reason,
|
@@ -3954,10 +4255,13 @@ var TransactionResponse = class {
|
|
3954
4255
|
async wait(contractsAbiMap) {
|
3955
4256
|
return this.waitForResult(contractsAbiMap);
|
3956
4257
|
}
|
4258
|
+
unsetResourceCache() {
|
4259
|
+
this.provider.cache?.unset(this.id);
|
4260
|
+
}
|
3957
4261
|
};
|
3958
4262
|
|
3959
4263
|
// src/providers/utils/auto-retry-fetch.ts
|
3960
|
-
var
|
4264
|
+
var import_utils23 = require("@fuel-ts/utils");
|
3961
4265
|
function getWaitDelay(options, retryAttemptNum) {
|
3962
4266
|
const duration = options.baseDelay ?? 150;
|
3963
4267
|
switch (options.backoff) {
|
@@ -3987,7 +4291,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3987
4291
|
throw error;
|
3988
4292
|
}
|
3989
4293
|
const delay = getWaitDelay(options, retryNum);
|
3990
|
-
await (0,
|
4294
|
+
await (0, import_utils23.sleep)(delay);
|
3991
4295
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
3992
4296
|
}
|
3993
4297
|
};
|
@@ -3997,7 +4301,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3997
4301
|
var MAX_RETRIES = 10;
|
3998
4302
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
3999
4303
|
var BLOCKS_PAGE_SIZE_LIMIT = 5;
|
4000
|
-
var
|
4304
|
+
var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
|
4001
4305
|
var processGqlChain = (chain) => {
|
4002
4306
|
const { name, daHeight, consensusParameters, latestBlock } = chain;
|
4003
4307
|
const {
|
@@ -4013,47 +4317,47 @@ var processGqlChain = (chain) => {
|
|
4013
4317
|
} = consensusParameters;
|
4014
4318
|
return {
|
4015
4319
|
name,
|
4016
|
-
baseChainHeight: (0,
|
4320
|
+
baseChainHeight: (0, import_math18.bn)(daHeight),
|
4017
4321
|
consensusParameters: {
|
4018
4322
|
version,
|
4019
|
-
chainId: (0,
|
4323
|
+
chainId: (0, import_math18.bn)(chainId),
|
4020
4324
|
baseAssetId,
|
4021
4325
|
feeParameters: {
|
4022
4326
|
version: feeParams.version,
|
4023
|
-
gasPerByte: (0,
|
4024
|
-
gasPriceFactor: (0,
|
4327
|
+
gasPerByte: (0, import_math18.bn)(feeParams.gasPerByte),
|
4328
|
+
gasPriceFactor: (0, import_math18.bn)(feeParams.gasPriceFactor)
|
4025
4329
|
},
|
4026
4330
|
contractParameters: {
|
4027
4331
|
version: contractParams.version,
|
4028
|
-
contractMaxSize: (0,
|
4029
|
-
maxStorageSlots: (0,
|
4332
|
+
contractMaxSize: (0, import_math18.bn)(contractParams.contractMaxSize),
|
4333
|
+
maxStorageSlots: (0, import_math18.bn)(contractParams.maxStorageSlots)
|
4030
4334
|
},
|
4031
4335
|
txParameters: {
|
4032
4336
|
version: txParams.version,
|
4033
|
-
maxInputs: (0,
|
4034
|
-
maxOutputs: (0,
|
4035
|
-
maxWitnesses: (0,
|
4036
|
-
maxGasPerTx: (0,
|
4037
|
-
maxSize: (0,
|
4038
|
-
maxBytecodeSubsections: (0,
|
4337
|
+
maxInputs: (0, import_math18.bn)(txParams.maxInputs),
|
4338
|
+
maxOutputs: (0, import_math18.bn)(txParams.maxOutputs),
|
4339
|
+
maxWitnesses: (0, import_math18.bn)(txParams.maxWitnesses),
|
4340
|
+
maxGasPerTx: (0, import_math18.bn)(txParams.maxGasPerTx),
|
4341
|
+
maxSize: (0, import_math18.bn)(txParams.maxSize),
|
4342
|
+
maxBytecodeSubsections: (0, import_math18.bn)(txParams.maxBytecodeSubsections)
|
4039
4343
|
},
|
4040
4344
|
predicateParameters: {
|
4041
4345
|
version: predicateParams.version,
|
4042
|
-
maxPredicateLength: (0,
|
4043
|
-
maxPredicateDataLength: (0,
|
4044
|
-
maxGasPerPredicate: (0,
|
4045
|
-
maxMessageDataLength: (0,
|
4346
|
+
maxPredicateLength: (0, import_math18.bn)(predicateParams.maxPredicateLength),
|
4347
|
+
maxPredicateDataLength: (0, import_math18.bn)(predicateParams.maxPredicateDataLength),
|
4348
|
+
maxGasPerPredicate: (0, import_math18.bn)(predicateParams.maxGasPerPredicate),
|
4349
|
+
maxMessageDataLength: (0, import_math18.bn)(predicateParams.maxMessageDataLength)
|
4046
4350
|
},
|
4047
4351
|
scriptParameters: {
|
4048
4352
|
version: scriptParams.version,
|
4049
|
-
maxScriptLength: (0,
|
4050
|
-
maxScriptDataLength: (0,
|
4353
|
+
maxScriptLength: (0, import_math18.bn)(scriptParams.maxScriptLength),
|
4354
|
+
maxScriptDataLength: (0, import_math18.bn)(scriptParams.maxScriptDataLength)
|
4051
4355
|
},
|
4052
4356
|
gasCosts
|
4053
4357
|
},
|
4054
4358
|
latestBlock: {
|
4055
4359
|
id: latestBlock.id,
|
4056
|
-
height: (0,
|
4360
|
+
height: (0, import_math18.bn)(latestBlock.height),
|
4057
4361
|
time: latestBlock.header.time,
|
4058
4362
|
transactions: latestBlock.transactions.map((i) => ({
|
4059
4363
|
id: i.id
|
@@ -4080,22 +4384,22 @@ var _Provider = class {
|
|
4080
4384
|
__publicField(this, "cache");
|
4081
4385
|
__publicField(this, "options", {
|
4082
4386
|
timeout: void 0,
|
4083
|
-
|
4387
|
+
resourceCacheTTL: void 0,
|
4084
4388
|
fetch: void 0,
|
4085
4389
|
retryOptions: void 0
|
4086
4390
|
});
|
4087
4391
|
this.options = { ...this.options, ...options };
|
4088
4392
|
this.url = url;
|
4089
4393
|
this.operations = this.createOperations();
|
4090
|
-
const {
|
4091
|
-
if ((0,
|
4092
|
-
if (
|
4093
|
-
this.cache = new
|
4394
|
+
const { resourceCacheTTL } = this.options;
|
4395
|
+
if ((0, import_utils24.isDefined)(resourceCacheTTL)) {
|
4396
|
+
if (resourceCacheTTL !== -1) {
|
4397
|
+
this.cache = new ResourceCache(resourceCacheTTL);
|
4094
4398
|
} else {
|
4095
4399
|
this.cache = void 0;
|
4096
4400
|
}
|
4097
4401
|
} else {
|
4098
|
-
this.cache = new
|
4402
|
+
this.cache = new ResourceCache(DEFAULT_RESOURCE_CACHE_TTL);
|
4099
4403
|
}
|
4100
4404
|
}
|
4101
4405
|
/** @hidden */
|
@@ -4140,8 +4444,8 @@ var _Provider = class {
|
|
4140
4444
|
getChain() {
|
4141
4445
|
const chain = _Provider.chainInfoCache[this.url];
|
4142
4446
|
if (!chain) {
|
4143
|
-
throw new
|
4144
|
-
|
4447
|
+
throw new import_errors15.FuelError(
|
4448
|
+
import_errors15.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
4145
4449
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4146
4450
|
);
|
4147
4451
|
}
|
@@ -4155,8 +4459,8 @@ var _Provider = class {
|
|
4155
4459
|
getNode() {
|
4156
4460
|
const node = _Provider.nodeInfoCache[this.url];
|
4157
4461
|
if (!node) {
|
4158
|
-
throw new
|
4159
|
-
|
4462
|
+
throw new import_errors15.FuelError(
|
4463
|
+
import_errors15.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
4160
4464
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4161
4465
|
);
|
4162
4466
|
}
|
@@ -4198,9 +4502,9 @@ var _Provider = class {
|
|
4198
4502
|
* @returns A promise that resolves to the Chain and NodeInfo.
|
4199
4503
|
*/
|
4200
4504
|
async fetchChainAndNodeInfo() {
|
4201
|
-
const chain = await this.fetchChain();
|
4202
4505
|
const nodeInfo = await this.fetchNode();
|
4203
4506
|
_Provider.ensureClientVersionIsSupported(nodeInfo);
|
4507
|
+
const chain = await this.fetchChain();
|
4204
4508
|
return {
|
4205
4509
|
chain,
|
4206
4510
|
nodeInfo
|
@@ -4234,8 +4538,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4234
4538
|
if ("response" in response) {
|
4235
4539
|
const graphQlResponse = response.response;
|
4236
4540
|
if (Array.isArray(graphQlResponse?.errors)) {
|
4237
|
-
throw new
|
4238
|
-
|
4541
|
+
throw new import_errors15.FuelError(
|
4542
|
+
import_errors15.FuelError.CODES.INVALID_REQUEST,
|
4239
4543
|
graphQlResponse.errors.map((err) => err.message).join("\n\n")
|
4240
4544
|
);
|
4241
4545
|
}
|
@@ -4246,7 +4550,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4246
4550
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
4247
4551
|
const isSubscription = opDefinition?.operation === "subscription";
|
4248
4552
|
if (isSubscription) {
|
4249
|
-
return
|
4553
|
+
return FuelGraphqlSubscriber.create({
|
4250
4554
|
url: this.url,
|
4251
4555
|
query,
|
4252
4556
|
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
@@ -4275,7 +4579,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4275
4579
|
*/
|
4276
4580
|
async getBlockNumber() {
|
4277
4581
|
const { chain } = await this.operations.getChain();
|
4278
|
-
return (0,
|
4582
|
+
return (0, import_math18.bn)(chain.latestBlock.height, 10);
|
4279
4583
|
}
|
4280
4584
|
/**
|
4281
4585
|
* Returns the node information for the current provider network.
|
@@ -4285,8 +4589,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4285
4589
|
async fetchNode() {
|
4286
4590
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
4287
4591
|
const processedNodeInfo = {
|
4288
|
-
maxDepth: (0,
|
4289
|
-
maxTx: (0,
|
4592
|
+
maxDepth: (0, import_math18.bn)(nodeInfo.maxDepth),
|
4593
|
+
maxTx: (0, import_math18.bn)(nodeInfo.maxTx),
|
4290
4594
|
nodeVersion: nodeInfo.nodeVersion,
|
4291
4595
|
utxoValidation: nodeInfo.utxoValidation,
|
4292
4596
|
vmBacktrace: nodeInfo.vmBacktrace
|
@@ -4327,6 +4631,21 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4327
4631
|
} = this.getChain();
|
4328
4632
|
return baseAssetId;
|
4329
4633
|
}
|
4634
|
+
validateTransaction(tx, consensusParameters) {
|
4635
|
+
const { maxOutputs, maxInputs } = consensusParameters.txParameters;
|
4636
|
+
if ((0, import_math18.bn)(tx.inputs.length).gt(maxInputs)) {
|
4637
|
+
throw new import_errors15.FuelError(
|
4638
|
+
import_errors15.ErrorCode.MAX_INPUTS_EXCEEDED,
|
4639
|
+
"The transaction exceeds the maximum allowed number of inputs."
|
4640
|
+
);
|
4641
|
+
}
|
4642
|
+
if ((0, import_math18.bn)(tx.outputs.length).gt(maxOutputs)) {
|
4643
|
+
throw new import_errors15.FuelError(
|
4644
|
+
import_errors15.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
4645
|
+
"The transaction exceeds the maximum allowed number of outputs."
|
4646
|
+
);
|
4647
|
+
}
|
4648
|
+
}
|
4330
4649
|
/**
|
4331
4650
|
* Submits a transaction to the chain to be executed.
|
4332
4651
|
*
|
@@ -4343,16 +4662,18 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4343
4662
|
if (estimateTxDependencies) {
|
4344
4663
|
await this.estimateTxDependencies(transactionRequest);
|
4345
4664
|
}
|
4346
|
-
const
|
4665
|
+
const { consensusParameters } = this.getChain();
|
4666
|
+
this.validateTransaction(transactionRequest, consensusParameters);
|
4667
|
+
const encodedTransaction = (0, import_utils24.hexlify)(transactionRequest.toTransactionBytes());
|
4347
4668
|
let abis;
|
4348
|
-
if (transactionRequest
|
4669
|
+
if (isTransactionTypeScript(transactionRequest)) {
|
4349
4670
|
abis = transactionRequest.abis;
|
4350
4671
|
}
|
4351
4672
|
const {
|
4352
4673
|
submit: { id: transactionId }
|
4353
4674
|
} = await this.operations.submit({ encodedTransaction });
|
4354
|
-
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs);
|
4355
|
-
return new TransactionResponse(
|
4675
|
+
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionId);
|
4676
|
+
return new TransactionResponse(transactionRequest, this, abis);
|
4356
4677
|
}
|
4357
4678
|
/**
|
4358
4679
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -4369,7 +4690,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4369
4690
|
if (estimateTxDependencies) {
|
4370
4691
|
return this.estimateTxDependencies(transactionRequest);
|
4371
4692
|
}
|
4372
|
-
const encodedTransaction = (0,
|
4693
|
+
const encodedTransaction = (0, import_utils24.hexlify)(transactionRequest.toTransactionBytes());
|
4373
4694
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4374
4695
|
encodedTransactions: encodedTransaction,
|
4375
4696
|
utxoValidation: utxoValidation || false
|
@@ -4389,13 +4710,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4389
4710
|
async estimatePredicates(transactionRequest) {
|
4390
4711
|
const shouldEstimatePredicates = Boolean(
|
4391
4712
|
transactionRequest.inputs.find(
|
4392
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4713
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils25.equalBytes)((0, import_utils24.arrayify)(input.predicate), (0, import_utils24.arrayify)("0x")) && new import_math18.BN(input.predicateGasUsed).isZero()
|
4393
4714
|
)
|
4394
4715
|
);
|
4395
4716
|
if (!shouldEstimatePredicates) {
|
4396
4717
|
return transactionRequest;
|
4397
4718
|
}
|
4398
|
-
const encodedTransaction = (0,
|
4719
|
+
const encodedTransaction = (0, import_utils24.hexlify)(transactionRequest.toTransactionBytes());
|
4399
4720
|
const response = await this.operations.estimatePredicates({
|
4400
4721
|
encodedTransaction
|
4401
4722
|
});
|
@@ -4404,7 +4725,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4404
4725
|
} = response;
|
4405
4726
|
if (inputs) {
|
4406
4727
|
inputs.forEach((input, index) => {
|
4407
|
-
if ("predicateGasUsed" in input && (0,
|
4728
|
+
if ("predicateGasUsed" in input && (0, import_math18.bn)(input.predicateGasUsed).gt(0)) {
|
4408
4729
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4409
4730
|
}
|
4410
4731
|
});
|
@@ -4421,7 +4742,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4421
4742
|
* @returns A promise that resolves to the estimate transaction dependencies.
|
4422
4743
|
*/
|
4423
4744
|
async estimateTxDependencies(transactionRequest) {
|
4424
|
-
if (transactionRequest
|
4745
|
+
if (isTransactionTypeCreate(transactionRequest)) {
|
4425
4746
|
return {
|
4426
4747
|
receipts: [],
|
4427
4748
|
outputVariables: 0,
|
@@ -4436,14 +4757,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4436
4757
|
const {
|
4437
4758
|
dryRun: [{ receipts: rawReceipts, status }]
|
4438
4759
|
} = await this.operations.dryRun({
|
4439
|
-
encodedTransactions: [(0,
|
4760
|
+
encodedTransactions: [(0, import_utils24.hexlify)(transactionRequest.toTransactionBytes())],
|
4440
4761
|
utxoValidation: false
|
4441
4762
|
});
|
4442
4763
|
receipts = rawReceipts.map(processGqlReceipt);
|
4443
4764
|
dryRunStatus = status;
|
4444
4765
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4445
4766
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4446
|
-
if (hasMissingOutputs) {
|
4767
|
+
if (hasMissingOutputs && isTransactionTypeScript(transactionRequest)) {
|
4447
4768
|
outputVariables += missingOutputVariables.length;
|
4448
4769
|
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
4449
4770
|
missingOutputContractIds.forEach(({ contractId }) => {
|
@@ -4485,8 +4806,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4485
4806
|
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4486
4807
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4487
4808
|
allRequests.forEach((req, index) => {
|
4488
|
-
if (req
|
4489
|
-
serializedTransactionsMap.set(index, (0,
|
4809
|
+
if (isTransactionTypeScript(req)) {
|
4810
|
+
serializedTransactionsMap.set(index, (0, import_utils24.hexlify)(req.toTransactionBytes()));
|
4490
4811
|
}
|
4491
4812
|
});
|
4492
4813
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -4511,7 +4832,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4511
4832
|
);
|
4512
4833
|
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4513
4834
|
const request = allRequests[requestIdx];
|
4514
|
-
if (hasMissingOutputs && request
|
4835
|
+
if (hasMissingOutputs && isTransactionTypeScript(request)) {
|
4515
4836
|
result.outputVariables += missingOutputVariables.length;
|
4516
4837
|
request.addVariableOutputs(missingOutputVariables.length);
|
4517
4838
|
missingOutputContractIds.forEach(({ contractId }) => {
|
@@ -4522,7 +4843,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4522
4843
|
transactionRequest: request
|
4523
4844
|
});
|
4524
4845
|
request.maxFee = maxFee;
|
4525
|
-
serializedTransactionsMap.set(requestIdx, (0,
|
4846
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils24.hexlify)(request.toTransactionBytes()));
|
4526
4847
|
nextRoundTransactions.push(requestIdx);
|
4527
4848
|
}
|
4528
4849
|
}
|
@@ -4543,7 +4864,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4543
4864
|
if (estimateTxDependencies) {
|
4544
4865
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
4545
4866
|
}
|
4546
|
-
const encodedTransactions = transactionRequests.map((tx) => (0,
|
4867
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils24.hexlify)(tx.toTransactionBytes()));
|
4547
4868
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4548
4869
|
encodedTransactions,
|
4549
4870
|
utxoValidation: utxoValidation || false
|
@@ -4569,13 +4890,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4569
4890
|
gasPrice = await this.estimateGasPrice(10);
|
4570
4891
|
}
|
4571
4892
|
const minFee = calculateGasFee({
|
4572
|
-
gasPrice: (0,
|
4893
|
+
gasPrice: (0, import_math18.bn)(gasPrice),
|
4573
4894
|
gas: minGas,
|
4574
4895
|
priceFactor: gasPriceFactor,
|
4575
4896
|
tip: transactionRequest.tip
|
4576
4897
|
}).add(1);
|
4577
|
-
let gasLimit = (0,
|
4578
|
-
if (transactionRequest
|
4898
|
+
let gasLimit = (0, import_math18.bn)(0);
|
4899
|
+
if (isTransactionTypeScript(transactionRequest)) {
|
4579
4900
|
gasLimit = transactionRequest.gasLimit;
|
4580
4901
|
if (transactionRequest.gasLimit.eq(0)) {
|
4581
4902
|
transactionRequest.gasLimit = minGas;
|
@@ -4587,7 +4908,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4587
4908
|
}
|
4588
4909
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4589
4910
|
const maxFee = calculateGasFee({
|
4590
|
-
gasPrice: (0,
|
4911
|
+
gasPrice: (0, import_math18.bn)(gasPrice),
|
4591
4912
|
gas: maxGas,
|
4592
4913
|
priceFactor: gasPriceFactor,
|
4593
4914
|
tip: transactionRequest.tip
|
@@ -4617,7 +4938,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4617
4938
|
if (estimateTxDependencies) {
|
4618
4939
|
return this.estimateTxDependencies(transactionRequest);
|
4619
4940
|
}
|
4620
|
-
const encodedTransactions = [(0,
|
4941
|
+
const encodedTransactions = [(0, import_utils24.hexlify)(transactionRequest.toTransactionBytes())];
|
4621
4942
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4622
4943
|
encodedTransactions,
|
4623
4944
|
utxoValidation: true
|
@@ -4643,14 +4964,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4643
4964
|
*/
|
4644
4965
|
async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
|
4645
4966
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4646
|
-
const isScriptTransaction = txRequestClone.type === import_transactions20.TransactionType.Script;
|
4647
4967
|
const updateMaxFee = txRequestClone.maxFee.eq(0);
|
4968
|
+
const isScriptTransaction = isTransactionTypeScript(txRequestClone);
|
4648
4969
|
if (isScriptTransaction) {
|
4649
|
-
txRequestClone.gasLimit = (0,
|
4970
|
+
txRequestClone.gasLimit = (0, import_math18.bn)(0);
|
4650
4971
|
}
|
4651
4972
|
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4652
4973
|
let addedSignatures = 0;
|
4653
|
-
if (signatureCallback &&
|
4974
|
+
if (signatureCallback && isTransactionTypeScript(signedRequest)) {
|
4654
4975
|
const lengthBefore = signedRequest.witnesses.length;
|
4655
4976
|
await signatureCallback(signedRequest);
|
4656
4977
|
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
@@ -4664,7 +4985,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4664
4985
|
let dryRunStatus;
|
4665
4986
|
let missingContractIds = [];
|
4666
4987
|
let outputVariables = 0;
|
4667
|
-
let gasUsed = (0,
|
4988
|
+
let gasUsed = (0, import_math18.bn)(0);
|
4668
4989
|
txRequestClone.maxFee = maxFee;
|
4669
4990
|
if (isScriptTransaction) {
|
4670
4991
|
txRequestClone.gasLimit = gasLimit;
|
@@ -4716,15 +5037,15 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4716
5037
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
4717
5038
|
inputArgs: paginationArgs
|
4718
5039
|
}),
|
4719
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
5040
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils24.hexlify)(assetId) }
|
4720
5041
|
});
|
4721
5042
|
const coins = edges.map(({ node }) => ({
|
4722
5043
|
id: node.utxoId,
|
4723
5044
|
assetId: node.assetId,
|
4724
|
-
amount: (0,
|
5045
|
+
amount: (0, import_math18.bn)(node.amount),
|
4725
5046
|
owner: import_address3.Address.fromAddressOrString(node.owner),
|
4726
|
-
blockCreated: (0,
|
4727
|
-
txCreatedIdx: (0,
|
5047
|
+
blockCreated: (0, import_math18.bn)(node.blockCreated),
|
5048
|
+
txCreatedIdx: (0, import_math18.bn)(node.txCreatedIdx)
|
4728
5049
|
}));
|
4729
5050
|
return {
|
4730
5051
|
coins,
|
@@ -4742,19 +5063,18 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4742
5063
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4743
5064
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4744
5065
|
const excludeInput = {
|
4745
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4746
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
5066
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils24.hexlify)(nonce)) || [],
|
5067
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils24.hexlify)(id)) || []
|
4747
5068
|
};
|
4748
5069
|
if (this.cache) {
|
4749
|
-
const
|
4750
|
-
|
4751
|
-
);
|
4752
|
-
excludeInput.utxos = Array.from(uniqueUtxos);
|
5070
|
+
const cached = this.cache.getActiveData();
|
5071
|
+
excludeInput.messages.push(...cached.messages);
|
5072
|
+
excludeInput.utxos.push(...cached.utxos);
|
4753
5073
|
}
|
4754
5074
|
const coinsQuery = {
|
4755
5075
|
owner: ownerAddress.toB256(),
|
4756
5076
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4757
|
-
assetId: (0,
|
5077
|
+
assetId: (0, import_utils24.hexlify)(assetId),
|
4758
5078
|
amount: amount.toString(10),
|
4759
5079
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4760
5080
|
})),
|
@@ -4765,9 +5085,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4765
5085
|
switch (coin.type) {
|
4766
5086
|
case "MessageCoin":
|
4767
5087
|
return {
|
4768
|
-
amount: (0,
|
5088
|
+
amount: (0, import_math18.bn)(coin.amount),
|
4769
5089
|
assetId: coin.assetId,
|
4770
|
-
daHeight: (0,
|
5090
|
+
daHeight: (0, import_math18.bn)(coin.daHeight),
|
4771
5091
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4772
5092
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4773
5093
|
nonce: coin.nonce
|
@@ -4775,11 +5095,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4775
5095
|
case "Coin":
|
4776
5096
|
return {
|
4777
5097
|
id: coin.utxoId,
|
4778
|
-
amount: (0,
|
5098
|
+
amount: (0, import_math18.bn)(coin.amount),
|
4779
5099
|
assetId: coin.assetId,
|
4780
5100
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4781
|
-
blockCreated: (0,
|
4782
|
-
txCreatedIdx: (0,
|
5101
|
+
blockCreated: (0, import_math18.bn)(coin.blockCreated),
|
5102
|
+
txCreatedIdx: (0, import_math18.bn)(coin.txCreatedIdx)
|
4783
5103
|
};
|
4784
5104
|
default:
|
4785
5105
|
return null;
|
@@ -4796,13 +5116,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4796
5116
|
async getBlock(idOrHeight) {
|
4797
5117
|
let variables;
|
4798
5118
|
if (typeof idOrHeight === "number") {
|
4799
|
-
variables = { height: (0,
|
5119
|
+
variables = { height: (0, import_math18.bn)(idOrHeight).toString(10) };
|
4800
5120
|
} else if (idOrHeight === "latest") {
|
4801
5121
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4802
5122
|
} else if (idOrHeight.length === 66) {
|
4803
5123
|
variables = { blockId: idOrHeight };
|
4804
5124
|
} else {
|
4805
|
-
variables = { blockId: (0,
|
5125
|
+
variables = { blockId: (0, import_math18.bn)(idOrHeight).toString(10) };
|
4806
5126
|
}
|
4807
5127
|
const { block } = await this.operations.getBlock(variables);
|
4808
5128
|
if (!block) {
|
@@ -4810,7 +5130,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4810
5130
|
}
|
4811
5131
|
return {
|
4812
5132
|
id: block.id,
|
4813
|
-
height: (0,
|
5133
|
+
height: (0, import_math18.bn)(block.height),
|
4814
5134
|
time: block.header.time,
|
4815
5135
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4816
5136
|
};
|
@@ -4832,7 +5152,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4832
5152
|
});
|
4833
5153
|
const blocks = edges.map(({ node: block }) => ({
|
4834
5154
|
id: block.id,
|
4835
|
-
height: (0,
|
5155
|
+
height: (0, import_math18.bn)(block.height),
|
4836
5156
|
time: block.header.time,
|
4837
5157
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4838
5158
|
}));
|
@@ -4847,7 +5167,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4847
5167
|
async getBlockWithTransactions(idOrHeight) {
|
4848
5168
|
let variables;
|
4849
5169
|
if (typeof idOrHeight === "number") {
|
4850
|
-
variables = { blockHeight: (0,
|
5170
|
+
variables = { blockHeight: (0, import_math18.bn)(idOrHeight).toString(10) };
|
4851
5171
|
} else if (idOrHeight === "latest") {
|
4852
5172
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4853
5173
|
} else {
|
@@ -4859,11 +5179,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4859
5179
|
}
|
4860
5180
|
return {
|
4861
5181
|
id: block.id,
|
4862
|
-
height: (0,
|
5182
|
+
height: (0, import_math18.bn)(block.height, 10),
|
4863
5183
|
time: block.header.time,
|
4864
5184
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4865
5185
|
transactions: block.transactions.map(
|
4866
|
-
(tx) => new import_transactions20.TransactionCoder().decode((0,
|
5186
|
+
(tx) => new import_transactions20.TransactionCoder().decode((0, import_utils24.arrayify)(tx.rawPayload), 0)?.[0]
|
4867
5187
|
)
|
4868
5188
|
};
|
4869
5189
|
}
|
@@ -4879,7 +5199,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4879
5199
|
return null;
|
4880
5200
|
}
|
4881
5201
|
return new import_transactions20.TransactionCoder().decode(
|
4882
|
-
(0,
|
5202
|
+
(0, import_utils24.arrayify)(transaction.rawPayload),
|
4883
5203
|
0
|
4884
5204
|
)?.[0];
|
4885
5205
|
}
|
@@ -4894,7 +5214,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4894
5214
|
} = await this.operations.getTransactions(paginationArgs);
|
4895
5215
|
const coder = new import_transactions20.TransactionCoder();
|
4896
5216
|
const transactions = edges.map(
|
4897
|
-
({ node: { rawPayload } }) => coder.decode((0,
|
5217
|
+
({ node: { rawPayload } }) => coder.decode((0, import_utils24.arrayify)(rawPayload), 0)[0]
|
4898
5218
|
);
|
4899
5219
|
return { transactions, pageInfo };
|
4900
5220
|
}
|
@@ -4921,9 +5241,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4921
5241
|
async getContractBalance(contractId, assetId) {
|
4922
5242
|
const { contractBalance } = await this.operations.getContractBalance({
|
4923
5243
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4924
|
-
asset: (0,
|
5244
|
+
asset: (0, import_utils24.hexlify)(assetId)
|
4925
5245
|
});
|
4926
|
-
return (0,
|
5246
|
+
return (0, import_math18.bn)(contractBalance.amount, 10);
|
4927
5247
|
}
|
4928
5248
|
/**
|
4929
5249
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4935,9 +5255,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4935
5255
|
async getBalance(owner, assetId) {
|
4936
5256
|
const { balance } = await this.operations.getBalance({
|
4937
5257
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4938
|
-
assetId: (0,
|
5258
|
+
assetId: (0, import_utils24.hexlify)(assetId)
|
4939
5259
|
});
|
4940
|
-
return (0,
|
5260
|
+
return (0, import_math18.bn)(balance.amount, 10);
|
4941
5261
|
}
|
4942
5262
|
/**
|
4943
5263
|
* Returns balances for the given owner.
|
@@ -4959,7 +5279,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4959
5279
|
});
|
4960
5280
|
const balances = edges.map(({ node }) => ({
|
4961
5281
|
assetId: node.assetId,
|
4962
|
-
amount: (0,
|
5282
|
+
amount: (0, import_math18.bn)(node.amount)
|
4963
5283
|
}));
|
4964
5284
|
return { balances };
|
4965
5285
|
}
|
@@ -4985,15 +5305,15 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4985
5305
|
sender: node.sender,
|
4986
5306
|
recipient: node.recipient,
|
4987
5307
|
nonce: node.nonce,
|
4988
|
-
amount: (0,
|
5308
|
+
amount: (0, import_math18.bn)(node.amount),
|
4989
5309
|
data: node.data
|
4990
5310
|
}),
|
4991
5311
|
sender: import_address3.Address.fromAddressOrString(node.sender),
|
4992
5312
|
recipient: import_address3.Address.fromAddressOrString(node.recipient),
|
4993
5313
|
nonce: node.nonce,
|
4994
|
-
amount: (0,
|
5314
|
+
amount: (0, import_math18.bn)(node.amount),
|
4995
5315
|
data: import_transactions20.InputMessageCoder.decodeData(node.data),
|
4996
|
-
daHeight: (0,
|
5316
|
+
daHeight: (0, import_math18.bn)(node.daHeight)
|
4997
5317
|
}));
|
4998
5318
|
return {
|
4999
5319
|
messages,
|
@@ -5015,8 +5335,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5015
5335
|
nonce
|
5016
5336
|
};
|
5017
5337
|
if (commitBlockId && commitBlockHeight) {
|
5018
|
-
throw new
|
5019
|
-
|
5338
|
+
throw new import_errors15.FuelError(
|
5339
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5020
5340
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5021
5341
|
);
|
5022
5342
|
}
|
@@ -5050,19 +5370,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5050
5370
|
} = result.messageProof;
|
5051
5371
|
return {
|
5052
5372
|
messageProof: {
|
5053
|
-
proofIndex: (0,
|
5373
|
+
proofIndex: (0, import_math18.bn)(messageProof.proofIndex),
|
5054
5374
|
proofSet: messageProof.proofSet
|
5055
5375
|
},
|
5056
5376
|
blockProof: {
|
5057
|
-
proofIndex: (0,
|
5377
|
+
proofIndex: (0, import_math18.bn)(blockProof.proofIndex),
|
5058
5378
|
proofSet: blockProof.proofSet
|
5059
5379
|
},
|
5060
5380
|
messageBlockHeader: {
|
5061
5381
|
id: messageBlockHeader.id,
|
5062
|
-
daHeight: (0,
|
5382
|
+
daHeight: (0, import_math18.bn)(messageBlockHeader.daHeight),
|
5063
5383
|
transactionsCount: Number(messageBlockHeader.transactionsCount),
|
5064
5384
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
5065
|
-
height: (0,
|
5385
|
+
height: (0, import_math18.bn)(messageBlockHeader.height),
|
5066
5386
|
prevRoot: messageBlockHeader.prevRoot,
|
5067
5387
|
time: messageBlockHeader.time,
|
5068
5388
|
applicationHash: messageBlockHeader.applicationHash,
|
@@ -5074,10 +5394,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5074
5394
|
},
|
5075
5395
|
commitBlockHeader: {
|
5076
5396
|
id: commitBlockHeader.id,
|
5077
|
-
daHeight: (0,
|
5397
|
+
daHeight: (0, import_math18.bn)(commitBlockHeader.daHeight),
|
5078
5398
|
transactionsCount: Number(commitBlockHeader.transactionsCount),
|
5079
5399
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
5080
|
-
height: (0,
|
5400
|
+
height: (0, import_math18.bn)(commitBlockHeader.height),
|
5081
5401
|
prevRoot: commitBlockHeader.prevRoot,
|
5082
5402
|
time: commitBlockHeader.time,
|
5083
5403
|
applicationHash: commitBlockHeader.applicationHash,
|
@@ -5090,7 +5410,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5090
5410
|
sender: import_address3.Address.fromAddressOrString(sender),
|
5091
5411
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
5092
5412
|
nonce,
|
5093
|
-
amount: (0,
|
5413
|
+
amount: (0, import_math18.bn)(amount),
|
5094
5414
|
data
|
5095
5415
|
};
|
5096
5416
|
}
|
@@ -5101,7 +5421,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5101
5421
|
*/
|
5102
5422
|
async getLatestGasPrice() {
|
5103
5423
|
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
5104
|
-
return (0,
|
5424
|
+
return (0, import_math18.bn)(latestGasPrice.gasPrice);
|
5105
5425
|
}
|
5106
5426
|
/**
|
5107
5427
|
* Returns the estimate gas price for the given block horizon.
|
@@ -5113,7 +5433,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5113
5433
|
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
5114
5434
|
blockHorizon: String(blockHorizon)
|
5115
5435
|
});
|
5116
|
-
return (0,
|
5436
|
+
return (0, import_math18.bn)(estimateGasPrice.gasPrice);
|
5117
5437
|
}
|
5118
5438
|
/**
|
5119
5439
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
@@ -5134,10 +5454,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5134
5454
|
*/
|
5135
5455
|
async produceBlocks(amount, startTime) {
|
5136
5456
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
5137
|
-
blocksToProduce: (0,
|
5138
|
-
startTimestamp: startTime ?
|
5457
|
+
blocksToProduce: (0, import_math18.bn)(amount).toString(10),
|
5458
|
+
startTimestamp: startTime ? import_utils24.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
5139
5459
|
});
|
5140
|
-
return (0,
|
5460
|
+
return (0, import_math18.bn)(latestBlockHeight);
|
5141
5461
|
}
|
5142
5462
|
/**
|
5143
5463
|
* Get the transaction response for the given transaction ID.
|
@@ -5184,26 +5504,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5184
5504
|
const { paginationLimit, inputArgs = {} } = params;
|
5185
5505
|
const { first, last, after, before } = inputArgs;
|
5186
5506
|
if (after && before) {
|
5187
|
-
throw new
|
5188
|
-
|
5507
|
+
throw new import_errors15.FuelError(
|
5508
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5189
5509
|
'Pagination arguments "after" and "before" cannot be used together'
|
5190
5510
|
);
|
5191
5511
|
}
|
5192
5512
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5193
|
-
throw new
|
5194
|
-
|
5513
|
+
throw new import_errors15.FuelError(
|
5514
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5195
5515
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5196
5516
|
);
|
5197
5517
|
}
|
5198
5518
|
if (first && before) {
|
5199
|
-
throw new
|
5200
|
-
|
5519
|
+
throw new import_errors15.FuelError(
|
5520
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5201
5521
|
'The use of pagination argument "first" with "before" is not supported'
|
5202
5522
|
);
|
5203
5523
|
}
|
5204
5524
|
if (last && after) {
|
5205
|
-
throw new
|
5206
|
-
|
5525
|
+
throw new import_errors15.FuelError(
|
5526
|
+
import_errors15.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5207
5527
|
'The use of pagination argument "last" with "after" is not supported'
|
5208
5528
|
);
|
5209
5529
|
}
|
@@ -5234,15 +5554,22 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5234
5554
|
};
|
5235
5555
|
var Provider = _Provider;
|
5236
5556
|
_cacheInputs = new WeakSet();
|
5237
|
-
cacheInputs_fn = function(inputs) {
|
5557
|
+
cacheInputs_fn = function(inputs, transactionId) {
|
5238
5558
|
if (!this.cache) {
|
5239
5559
|
return;
|
5240
5560
|
}
|
5241
|
-
inputs.
|
5242
|
-
|
5243
|
-
|
5244
|
-
|
5245
|
-
|
5561
|
+
const inputsToCache = inputs.reduce(
|
5562
|
+
(acc, input) => {
|
5563
|
+
if (input.type === import_transactions20.InputType.Coin) {
|
5564
|
+
acc.utxos.push(input.id);
|
5565
|
+
} else if (input.type === import_transactions20.InputType.Message) {
|
5566
|
+
acc.messages.push(input.nonce);
|
5567
|
+
}
|
5568
|
+
return acc;
|
5569
|
+
},
|
5570
|
+
{ utxos: [], messages: [] }
|
5571
|
+
);
|
5572
|
+
this.cache.set(transactionId, inputsToCache);
|
5246
5573
|
};
|
5247
5574
|
/** @hidden */
|
5248
5575
|
__publicField(Provider, "chainInfoCache", {});
|
@@ -5250,23 +5577,23 @@ __publicField(Provider, "chainInfoCache", {});
|
|
5250
5577
|
__publicField(Provider, "nodeInfoCache", {});
|
5251
5578
|
|
5252
5579
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
5253
|
-
var
|
5254
|
-
var
|
5580
|
+
var import_errors16 = require("@fuel-ts/errors");
|
5581
|
+
var import_math19 = require("@fuel-ts/math");
|
5255
5582
|
var import_transactions21 = require("@fuel-ts/transactions");
|
5256
|
-
var
|
5583
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5257
5584
|
async function getTransactionSummary(params) {
|
5258
5585
|
const { id, provider, abiMap } = params;
|
5259
5586
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
5260
5587
|
transactionId: id
|
5261
5588
|
});
|
5262
5589
|
if (!gqlTransaction) {
|
5263
|
-
throw new
|
5264
|
-
|
5590
|
+
throw new import_errors16.FuelError(
|
5591
|
+
import_errors16.ErrorCode.TRANSACTION_NOT_FOUND,
|
5265
5592
|
`Transaction not found for given id: ${id}.`
|
5266
5593
|
);
|
5267
5594
|
}
|
5268
5595
|
const [decodedTransaction] = new import_transactions21.TransactionCoder().decode(
|
5269
|
-
(0,
|
5596
|
+
(0, import_utils27.arrayify)(gqlTransaction.rawPayload),
|
5270
5597
|
0
|
5271
5598
|
);
|
5272
5599
|
let txReceipts = [];
|
@@ -5287,10 +5614,10 @@ async function getTransactionSummary(params) {
|
|
5287
5614
|
id: gqlTransaction.id,
|
5288
5615
|
receipts,
|
5289
5616
|
transaction: decodedTransaction,
|
5290
|
-
transactionBytes: (0,
|
5617
|
+
transactionBytes: (0, import_utils27.arrayify)(gqlTransaction.rawPayload),
|
5291
5618
|
gqlTransactionStatus: gqlTransaction.status,
|
5292
|
-
gasPerByte: (0,
|
5293
|
-
gasPriceFactor: (0,
|
5619
|
+
gasPerByte: (0, import_math19.bn)(gasPerByte),
|
5620
|
+
gasPriceFactor: (0, import_math19.bn)(gasPriceFactor),
|
5294
5621
|
abiMap,
|
5295
5622
|
maxInputs,
|
5296
5623
|
gasCosts,
|
@@ -5299,7 +5626,6 @@ async function getTransactionSummary(params) {
|
|
5299
5626
|
baseAssetId
|
5300
5627
|
});
|
5301
5628
|
return {
|
5302
|
-
gqlTransaction,
|
5303
5629
|
...transactionInfo
|
5304
5630
|
};
|
5305
5631
|
}
|
@@ -5313,6 +5639,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
5313
5639
|
const gasPrice = await provider.getLatestGasPrice();
|
5314
5640
|
const baseAssetId = provider.getBaseAssetId();
|
5315
5641
|
const transactionSummary = assembleTransactionSummary({
|
5642
|
+
id: transactionRequest.getTransactionId(provider.getChainId()),
|
5316
5643
|
receipts,
|
5317
5644
|
transaction,
|
5318
5645
|
transactionBytes,
|
@@ -5343,7 +5670,7 @@ async function getTransactionsSummaries(params) {
|
|
5343
5670
|
const transactions = edges.map((edge) => {
|
5344
5671
|
const { node: gqlTransaction } = edge;
|
5345
5672
|
const { id, rawPayload, status } = gqlTransaction;
|
5346
|
-
const [decodedTransaction] = new import_transactions21.TransactionCoder().decode((0,
|
5673
|
+
const [decodedTransaction] = new import_transactions21.TransactionCoder().decode((0, import_utils27.arrayify)(rawPayload), 0);
|
5347
5674
|
let txReceipts = [];
|
5348
5675
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
5349
5676
|
txReceipts = gqlTransaction.status.receipts;
|
@@ -5353,7 +5680,7 @@ async function getTransactionsSummaries(params) {
|
|
5353
5680
|
id,
|
5354
5681
|
receipts,
|
5355
5682
|
transaction: decodedTransaction,
|
5356
|
-
transactionBytes: (0,
|
5683
|
+
transactionBytes: (0, import_utils27.arrayify)(rawPayload),
|
5357
5684
|
gqlTransactionStatus: status,
|
5358
5685
|
abiMap,
|
5359
5686
|
gasPerByte,
|
@@ -5365,7 +5692,6 @@ async function getTransactionsSummaries(params) {
|
|
5365
5692
|
baseAssetId
|
5366
5693
|
});
|
5367
5694
|
const output = {
|
5368
|
-
gqlTransaction,
|
5369
5695
|
...transactionSummary
|
5370
5696
|
};
|
5371
5697
|
return output;
|
@@ -5517,17 +5843,17 @@ var mergeQuantities = (...coinQuantities) => {
|
|
5517
5843
|
|
5518
5844
|
// src/utils/formatTransferToContractScriptData.ts
|
5519
5845
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
5520
|
-
var
|
5521
|
-
var
|
5846
|
+
var import_math20 = require("@fuel-ts/math");
|
5847
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5522
5848
|
var asm = __toESM(require("@fuels/vm-asm"));
|
5523
5849
|
var formatTransferToContractScriptData = (params) => {
|
5524
5850
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
5525
5851
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
5526
|
-
const encoded = numberCoder.encode(new
|
5852
|
+
const encoded = numberCoder.encode(new import_math20.BN(amountToTransfer).toNumber());
|
5527
5853
|
const scriptData = Uint8Array.from([
|
5528
|
-
...(0,
|
5854
|
+
...(0, import_utils29.arrayify)(hexlifiedContractId),
|
5529
5855
|
...encoded,
|
5530
|
-
...(0,
|
5856
|
+
...(0, import_utils29.arrayify)(assetId)
|
5531
5857
|
]);
|
5532
5858
|
return scriptData;
|
5533
5859
|
};
|
@@ -5552,7 +5878,7 @@ var assembleTransferToContractScript = async (params) => {
|
|
5552
5878
|
};
|
5553
5879
|
|
5554
5880
|
// src/account.ts
|
5555
|
-
var MAX_FUNDING_ATTEMPTS =
|
5881
|
+
var MAX_FUNDING_ATTEMPTS = 5;
|
5556
5882
|
var Account = class extends import_interfaces.AbstractAccount {
|
5557
5883
|
/**
|
5558
5884
|
* The address associated with the account.
|
@@ -5588,7 +5914,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5588
5914
|
*/
|
5589
5915
|
get provider() {
|
5590
5916
|
if (!this._provider) {
|
5591
|
-
throw new
|
5917
|
+
throw new import_errors17.FuelError(import_errors17.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
5592
5918
|
}
|
5593
5919
|
return this._provider;
|
5594
5920
|
}
|
@@ -5665,12 +5991,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5665
5991
|
* @returns A promise that resolves to the funded transaction request.
|
5666
5992
|
*/
|
5667
5993
|
async fund(request, params) {
|
5668
|
-
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee } = params;
|
5994
|
+
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee, gasPrice } = params;
|
5669
5995
|
const fee = request.maxFee;
|
5670
5996
|
const baseAssetId = this.provider.getBaseAssetId();
|
5671
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0,
|
5997
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math21.bn)(0);
|
5672
5998
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5673
|
-
amount: (0,
|
5999
|
+
amount: (0, import_math21.bn)(fee),
|
5674
6000
|
assetId: baseAssetId,
|
5675
6001
|
coinQuantities: requiredQuantities
|
5676
6002
|
});
|
@@ -5678,7 +6004,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5678
6004
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5679
6005
|
quantitiesDict[assetId] = {
|
5680
6006
|
required: amount,
|
5681
|
-
owned: (0,
|
6007
|
+
owned: (0, import_math21.bn)(0)
|
5682
6008
|
};
|
5683
6009
|
});
|
5684
6010
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -5713,10 +6039,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5713
6039
|
);
|
5714
6040
|
}
|
5715
6041
|
if (!updateMaxFee) {
|
6042
|
+
needsToBeFunded = false;
|
5716
6043
|
break;
|
5717
6044
|
}
|
5718
6045
|
const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
|
5719
|
-
transactionRequest: requestToReestimate2
|
6046
|
+
transactionRequest: requestToReestimate2,
|
6047
|
+
gasPrice
|
5720
6048
|
});
|
5721
6049
|
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
5722
6050
|
request.inputs,
|
@@ -5736,6 +6064,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5736
6064
|
}
|
5737
6065
|
fundingAttempts += 1;
|
5738
6066
|
}
|
6067
|
+
if (needsToBeFunded) {
|
6068
|
+
throw new import_errors17.FuelError(
|
6069
|
+
import_errors17.ErrorCode.NOT_ENOUGH_FUNDS,
|
6070
|
+
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
6071
|
+
);
|
6072
|
+
}
|
5739
6073
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5740
6074
|
const requestToReestimate = (0, import_ramda4.clone)(request);
|
5741
6075
|
if (addedSignatures) {
|
@@ -5836,9 +6170,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5836
6170
|
* @returns A promise that resolves to the transaction response.
|
5837
6171
|
*/
|
5838
6172
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5839
|
-
if ((0,
|
5840
|
-
throw new
|
5841
|
-
|
6173
|
+
if ((0, import_math21.bn)(amount).lte(0)) {
|
6174
|
+
throw new import_errors17.FuelError(
|
6175
|
+
import_errors17.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5842
6176
|
"Transfer amount must be a positive number."
|
5843
6177
|
);
|
5844
6178
|
}
|
@@ -5846,7 +6180,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5846
6180
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5847
6181
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5848
6182
|
hexlifiedContractId: contractAddress.toB256(),
|
5849
|
-
amountToTransfer: (0,
|
6183
|
+
amountToTransfer: (0, import_math21.bn)(amount),
|
5850
6184
|
assetId: assetIdToTransfer
|
5851
6185
|
});
|
5852
6186
|
let request = new ScriptTransactionRequest({
|
@@ -5856,7 +6190,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5856
6190
|
});
|
5857
6191
|
request.addContractInputAndOutput(contractAddress);
|
5858
6192
|
const txCost = await this.getTransactionCost(request, {
|
5859
|
-
quantities: [{ amount: (0,
|
6193
|
+
quantities: [{ amount: (0, import_math21.bn)(amount), assetId: String(assetIdToTransfer) }]
|
5860
6194
|
});
|
5861
6195
|
request = this.validateGasLimitAndMaxFee({
|
5862
6196
|
transactionRequest: request,
|
@@ -5877,21 +6211,21 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5877
6211
|
*/
|
5878
6212
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5879
6213
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5880
|
-
const recipientDataArray = (0,
|
6214
|
+
const recipientDataArray = (0, import_utils30.arrayify)(
|
5881
6215
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5882
6216
|
);
|
5883
|
-
const amountDataArray = (0,
|
5884
|
-
"0x".concat((0,
|
6217
|
+
const amountDataArray = (0, import_utils30.arrayify)(
|
6218
|
+
"0x".concat((0, import_math21.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5885
6219
|
);
|
5886
6220
|
const script = new Uint8Array([
|
5887
|
-
...(0,
|
6221
|
+
...(0, import_utils30.arrayify)(withdrawScript.bytes),
|
5888
6222
|
...recipientDataArray,
|
5889
6223
|
...amountDataArray
|
5890
6224
|
]);
|
5891
6225
|
const params = { script, ...txParams };
|
5892
6226
|
const baseAssetId = this.provider.getBaseAssetId();
|
5893
6227
|
let request = new ScriptTransactionRequest(params);
|
5894
|
-
const quantities = [{ amount: (0,
|
6228
|
+
const quantities = [{ amount: (0, import_math21.bn)(amount), assetId: baseAssetId }];
|
5895
6229
|
const txCost = await this.getTransactionCost(request, { quantities });
|
5896
6230
|
request = this.validateGasLimitAndMaxFee({
|
5897
6231
|
transactionRequest: request,
|
@@ -5917,11 +6251,35 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5917
6251
|
const baseAssetId = this.provider.getBaseAssetId();
|
5918
6252
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
5919
6253
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
5920
|
-
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0,
|
5921
|
-
const
|
5922
|
-
|
6254
|
+
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math21.bn)("100000000000000000") }];
|
6255
|
+
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
6256
|
+
if ("assetId" in input) {
|
6257
|
+
return input.assetId === assetId;
|
6258
|
+
}
|
6259
|
+
if ("recipient" in input) {
|
6260
|
+
return baseAssetId === assetId;
|
6261
|
+
}
|
6262
|
+
return false;
|
6263
|
+
});
|
6264
|
+
const updateAssetInput = (assetId, quantity) => {
|
6265
|
+
const assetInput = findAssetInput(assetId);
|
6266
|
+
const usedQuantity = quantity;
|
6267
|
+
if (assetInput && "amount" in assetInput) {
|
6268
|
+
assetInput.amount = usedQuantity;
|
6269
|
+
} else {
|
6270
|
+
txRequestClone.addResources(
|
6271
|
+
this.generateFakeResources([
|
6272
|
+
{
|
6273
|
+
amount: quantity,
|
6274
|
+
assetId
|
6275
|
+
}
|
6276
|
+
])
|
6277
|
+
);
|
6278
|
+
}
|
6279
|
+
};
|
6280
|
+
mergeQuantities(requiredQuantities, transactionFeeForDryRun).forEach(
|
6281
|
+
({ amount, assetId }) => updateAssetInput(assetId, amount)
|
5923
6282
|
);
|
5924
|
-
txRequestClone.addResources(resources);
|
5925
6283
|
const txCost = await this.provider.getTransactionCost(txRequestClone, {
|
5926
6284
|
signatureCallback
|
5927
6285
|
});
|
@@ -5940,7 +6298,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5940
6298
|
*/
|
5941
6299
|
async signMessage(message) {
|
5942
6300
|
if (!this._connector) {
|
5943
|
-
throw new
|
6301
|
+
throw new import_errors17.FuelError(import_errors17.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5944
6302
|
}
|
5945
6303
|
return this._connector.signMessage(this.address.toString(), message);
|
5946
6304
|
}
|
@@ -5952,8 +6310,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5952
6310
|
*/
|
5953
6311
|
async signTransaction(transactionRequestLike) {
|
5954
6312
|
if (!this._connector) {
|
5955
|
-
throw new
|
5956
|
-
|
6313
|
+
throw new import_errors17.FuelError(
|
6314
|
+
import_errors17.ErrorCode.MISSING_CONNECTOR,
|
5957
6315
|
"A connector is required to sign transactions."
|
5958
6316
|
);
|
5959
6317
|
}
|
@@ -6002,18 +6360,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6002
6360
|
*/
|
6003
6361
|
generateFakeResources(coins) {
|
6004
6362
|
return coins.map((coin) => ({
|
6005
|
-
id: (0,
|
6363
|
+
id: (0, import_utils30.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
6006
6364
|
owner: this.address,
|
6007
|
-
blockCreated: (0,
|
6008
|
-
txCreatedIdx: (0,
|
6365
|
+
blockCreated: (0, import_math21.bn)(1),
|
6366
|
+
txCreatedIdx: (0, import_math21.bn)(1),
|
6009
6367
|
...coin
|
6010
6368
|
}));
|
6011
6369
|
}
|
6012
6370
|
/** @hidden * */
|
6013
6371
|
validateTransferAmount(amount) {
|
6014
|
-
if ((0,
|
6015
|
-
throw new
|
6016
|
-
|
6372
|
+
if ((0, import_math21.bn)(amount).lte(0)) {
|
6373
|
+
throw new import_errors17.FuelError(
|
6374
|
+
import_errors17.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
6017
6375
|
"Transfer amount must be a positive number."
|
6018
6376
|
);
|
6019
6377
|
}
|
@@ -6039,19 +6397,19 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6039
6397
|
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
6040
6398
|
}) {
|
6041
6399
|
const request = transactionRequestify(transactionRequest);
|
6042
|
-
if (!(0,
|
6400
|
+
if (!(0, import_utils30.isDefined)(setGasLimit)) {
|
6043
6401
|
request.gasLimit = gasUsed;
|
6044
6402
|
} else if (gasUsed.gt(setGasLimit)) {
|
6045
|
-
throw new
|
6046
|
-
|
6403
|
+
throw new import_errors17.FuelError(
|
6404
|
+
import_errors17.ErrorCode.GAS_LIMIT_TOO_LOW,
|
6047
6405
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
6048
6406
|
);
|
6049
6407
|
}
|
6050
|
-
if (!(0,
|
6408
|
+
if (!(0, import_utils30.isDefined)(setMaxFee)) {
|
6051
6409
|
request.maxFee = maxFee;
|
6052
6410
|
} else if (maxFee.gt(setMaxFee)) {
|
6053
|
-
throw new
|
6054
|
-
|
6411
|
+
throw new import_errors17.FuelError(
|
6412
|
+
import_errors17.ErrorCode.MAX_FEE_TOO_LOW,
|
6055
6413
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
6056
6414
|
);
|
6057
6415
|
}
|
@@ -6061,14 +6419,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6061
6419
|
|
6062
6420
|
// src/wallet/base-wallet-unlocked.ts
|
6063
6421
|
var import_hasher3 = require("@fuel-ts/hasher");
|
6064
|
-
var
|
6422
|
+
var import_utils33 = require("@fuel-ts/utils");
|
6065
6423
|
|
6066
6424
|
// src/signer/signer.ts
|
6067
6425
|
var import_address5 = require("@fuel-ts/address");
|
6068
6426
|
var import_crypto3 = require("@fuel-ts/crypto");
|
6069
6427
|
var import_hasher2 = require("@fuel-ts/hasher");
|
6070
|
-
var
|
6071
|
-
var
|
6428
|
+
var import_math22 = require("@fuel-ts/math");
|
6429
|
+
var import_utils31 = require("@fuel-ts/utils");
|
6072
6430
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
6073
6431
|
var Signer = class {
|
6074
6432
|
address;
|
@@ -6087,10 +6445,10 @@ var Signer = class {
|
|
6087
6445
|
privateKey = `0x${privateKey}`;
|
6088
6446
|
}
|
6089
6447
|
}
|
6090
|
-
const privateKeyBytes = (0,
|
6091
|
-
this.privateKey = (0,
|
6092
|
-
this.publicKey = (0,
|
6093
|
-
this.compressedPublicKey = (0,
|
6448
|
+
const privateKeyBytes = (0, import_math22.toBytes)(privateKey, 32);
|
6449
|
+
this.privateKey = (0, import_utils31.hexlify)(privateKeyBytes);
|
6450
|
+
this.publicKey = (0, import_utils31.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
6451
|
+
this.compressedPublicKey = (0, import_utils31.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
6094
6452
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
6095
6453
|
}
|
6096
6454
|
/**
|
@@ -6104,11 +6462,11 @@ var Signer = class {
|
|
6104
6462
|
* @returns hashed signature
|
6105
6463
|
*/
|
6106
6464
|
sign(data) {
|
6107
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
6108
|
-
const r = (0,
|
6109
|
-
const s = (0,
|
6465
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils31.arrayify)(data), (0, import_utils31.arrayify)(this.privateKey));
|
6466
|
+
const r = (0, import_math22.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
6467
|
+
const s = (0, import_math22.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
6110
6468
|
s[0] |= (signature.recovery || 0) << 7;
|
6111
|
-
return (0,
|
6469
|
+
return (0, import_utils31.hexlify)((0, import_utils31.concat)([r, s]));
|
6112
6470
|
}
|
6113
6471
|
/**
|
6114
6472
|
* Add point on the current elliptic curve
|
@@ -6117,8 +6475,8 @@ var Signer = class {
|
|
6117
6475
|
* @returns compressed point on the curve
|
6118
6476
|
*/
|
6119
6477
|
addPoint(point) {
|
6120
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
6121
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
6478
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils31.arrayify)(this.compressedPublicKey));
|
6479
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils31.arrayify)(point));
|
6122
6480
|
const result = p0.add(p1);
|
6123
6481
|
return `0x${result.toHex(true)}`;
|
6124
6482
|
}
|
@@ -6130,16 +6488,16 @@ var Signer = class {
|
|
6130
6488
|
* @returns public key from signature from the
|
6131
6489
|
*/
|
6132
6490
|
static recoverPublicKey(data, signature) {
|
6133
|
-
const signedMessageBytes = (0,
|
6491
|
+
const signedMessageBytes = (0, import_utils31.arrayify)(signature);
|
6134
6492
|
const r = signedMessageBytes.slice(0, 32);
|
6135
6493
|
const s = signedMessageBytes.slice(32, 64);
|
6136
6494
|
const recoveryParam = (s[0] & 128) >> 7;
|
6137
6495
|
s[0] &= 127;
|
6138
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
6496
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils31.hexlify)(r)), BigInt((0, import_utils31.hexlify)(s))).addRecoveryBit(
|
6139
6497
|
recoveryParam
|
6140
6498
|
);
|
6141
|
-
const publicKey = sig.recoverPublicKey((0,
|
6142
|
-
return (0,
|
6499
|
+
const publicKey = sig.recoverPublicKey((0, import_utils31.arrayify)(data)).toRawBytes(false).slice(1);
|
6500
|
+
return (0, import_utils31.hexlify)(publicKey);
|
6143
6501
|
}
|
6144
6502
|
/**
|
6145
6503
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -6158,7 +6516,7 @@ var Signer = class {
|
|
6158
6516
|
* @returns random 32-byte hashed
|
6159
6517
|
*/
|
6160
6518
|
static generatePrivateKey(entropy) {
|
6161
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
6519
|
+
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);
|
6162
6520
|
}
|
6163
6521
|
/**
|
6164
6522
|
* Extended publicKey from a compact publicKey
|
@@ -6167,17 +6525,16 @@ var Signer = class {
|
|
6167
6525
|
* @returns extended publicKey
|
6168
6526
|
*/
|
6169
6527
|
static extendPublicKey(publicKey) {
|
6170
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
6171
|
-
return (0,
|
6528
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils31.arrayify)(publicKey));
|
6529
|
+
return (0, import_utils31.hexlify)(point.toRawBytes(false).slice(1));
|
6172
6530
|
}
|
6173
6531
|
};
|
6174
6532
|
|
6175
6533
|
// src/wallet/keystore-wallet.ts
|
6176
6534
|
var import_address6 = require("@fuel-ts/address");
|
6177
6535
|
var import_crypto4 = require("@fuel-ts/crypto");
|
6178
|
-
var
|
6179
|
-
var
|
6180
|
-
var import_uuid = require("uuid");
|
6536
|
+
var import_errors18 = require("@fuel-ts/errors");
|
6537
|
+
var import_utils32 = require("@fuel-ts/utils");
|
6181
6538
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
6182
6539
|
var DEFAULT_KDF_PARAMS_R = 8;
|
6183
6540
|
var DEFAULT_KDF_PARAMS_P = 1;
|
@@ -6207,7 +6564,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
6207
6564
|
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
6208
6565
|
const mac = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
6209
6566
|
const keystore = {
|
6210
|
-
id: (0,
|
6567
|
+
id: (0, import_crypto4.randomUUID)(),
|
6211
6568
|
version: 3,
|
6212
6569
|
address: removeHexPrefix(ownerAddress.toHexString()),
|
6213
6570
|
crypto: {
|
@@ -6253,13 +6610,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
6253
6610
|
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
6254
6611
|
const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
6255
6612
|
if (mac !== macHash) {
|
6256
|
-
throw new
|
6257
|
-
|
6613
|
+
throw new import_errors18.FuelError(
|
6614
|
+
import_errors18.ErrorCode.INVALID_PASSWORD,
|
6258
6615
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
6259
6616
|
);
|
6260
6617
|
}
|
6261
6618
|
const buffer = await (0, import_crypto4.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
6262
|
-
const privateKey = (0,
|
6619
|
+
const privateKey = (0, import_utils32.hexlify)(buffer);
|
6263
6620
|
return privateKey;
|
6264
6621
|
}
|
6265
6622
|
|
@@ -6304,7 +6661,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
6304
6661
|
*/
|
6305
6662
|
async signMessage(message) {
|
6306
6663
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
6307
|
-
return (0,
|
6664
|
+
return (0, import_utils33.hexlify)(signedMessage);
|
6308
6665
|
}
|
6309
6666
|
/**
|
6310
6667
|
* Signs a transaction with the wallet's private key.
|
@@ -6317,7 +6674,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
6317
6674
|
const chainId = this.provider.getChainId();
|
6318
6675
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
6319
6676
|
const signature = await this.signer().sign(hashedTransaction);
|
6320
|
-
return (0,
|
6677
|
+
return (0, import_utils33.hexlify)(signature);
|
6321
6678
|
}
|
6322
6679
|
/**
|
6323
6680
|
* Populates a transaction with the witnesses signature.
|
@@ -6384,16 +6741,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
6384
6741
|
|
6385
6742
|
// src/hdwallet/hdwallet.ts
|
6386
6743
|
var import_crypto6 = require("@fuel-ts/crypto");
|
6387
|
-
var
|
6744
|
+
var import_errors21 = require("@fuel-ts/errors");
|
6388
6745
|
var import_hasher6 = require("@fuel-ts/hasher");
|
6389
|
-
var
|
6390
|
-
var
|
6746
|
+
var import_math23 = require("@fuel-ts/math");
|
6747
|
+
var import_utils37 = require("@fuel-ts/utils");
|
6391
6748
|
|
6392
6749
|
// src/mnemonic/mnemonic.ts
|
6393
6750
|
var import_crypto5 = require("@fuel-ts/crypto");
|
6394
|
-
var
|
6751
|
+
var import_errors20 = require("@fuel-ts/errors");
|
6395
6752
|
var import_hasher5 = require("@fuel-ts/hasher");
|
6396
|
-
var
|
6753
|
+
var import_utils35 = require("@fuel-ts/utils");
|
6397
6754
|
|
6398
6755
|
// src/wordlists/words/english.ts
|
6399
6756
|
var english = [
|
@@ -8454,9 +8811,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
8454
8811
|
})(Language || {});
|
8455
8812
|
|
8456
8813
|
// src/mnemonic/utils.ts
|
8457
|
-
var
|
8814
|
+
var import_errors19 = require("@fuel-ts/errors");
|
8458
8815
|
var import_hasher4 = require("@fuel-ts/hasher");
|
8459
|
-
var
|
8816
|
+
var import_utils34 = require("@fuel-ts/utils");
|
8460
8817
|
function getLowerMask(bits) {
|
8461
8818
|
return (1 << bits) - 1;
|
8462
8819
|
}
|
@@ -8491,20 +8848,20 @@ function entropyToMnemonicIndices(entropy) {
|
|
8491
8848
|
}
|
8492
8849
|
}
|
8493
8850
|
const checksumBits = entropy.length / 4;
|
8494
|
-
const checksum = (0,
|
8851
|
+
const checksum = (0, import_utils34.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
8495
8852
|
indices[indices.length - 1] <<= checksumBits;
|
8496
8853
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
8497
8854
|
return indices;
|
8498
8855
|
}
|
8499
8856
|
function mnemonicWordsToEntropy(words, wordlist) {
|
8500
8857
|
const size = Math.ceil(11 * words.length / 8);
|
8501
|
-
const entropy = (0,
|
8858
|
+
const entropy = (0, import_utils34.arrayify)(new Uint8Array(size));
|
8502
8859
|
let offset = 0;
|
8503
8860
|
for (let i = 0; i < words.length; i += 1) {
|
8504
8861
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
8505
8862
|
if (index === -1) {
|
8506
|
-
throw new
|
8507
|
-
|
8863
|
+
throw new import_errors19.FuelError(
|
8864
|
+
import_errors19.ErrorCode.INVALID_MNEMONIC,
|
8508
8865
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
8509
8866
|
);
|
8510
8867
|
}
|
@@ -8518,10 +8875,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8518
8875
|
const entropyBits = 32 * words.length / 3;
|
8519
8876
|
const checksumBits = words.length / 3;
|
8520
8877
|
const checksumMask = getUpperMask(checksumBits);
|
8521
|
-
const checksum = (0,
|
8878
|
+
const checksum = (0, import_utils34.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8522
8879
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8523
|
-
throw new
|
8524
|
-
|
8880
|
+
throw new import_errors19.FuelError(
|
8881
|
+
import_errors19.ErrorCode.INVALID_CHECKSUM,
|
8525
8882
|
"Checksum validation failed for the provided mnemonic."
|
8526
8883
|
);
|
8527
8884
|
}
|
@@ -8529,22 +8886,22 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8529
8886
|
}
|
8530
8887
|
|
8531
8888
|
// src/mnemonic/mnemonic.ts
|
8532
|
-
var MasterSecret = (0,
|
8889
|
+
var MasterSecret = (0, import_utils35.toUtf8Bytes)("Bitcoin seed");
|
8533
8890
|
var MainnetPRV = "0x0488ade4";
|
8534
8891
|
var TestnetPRV = "0x04358394";
|
8535
8892
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
8536
8893
|
function assertWordList(wordlist) {
|
8537
8894
|
if (wordlist.length !== 2048) {
|
8538
|
-
throw new
|
8539
|
-
|
8895
|
+
throw new import_errors20.FuelError(
|
8896
|
+
import_errors20.ErrorCode.INVALID_WORD_LIST,
|
8540
8897
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
8541
8898
|
);
|
8542
8899
|
}
|
8543
8900
|
}
|
8544
8901
|
function assertEntropy(entropy) {
|
8545
8902
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
8546
|
-
throw new
|
8547
|
-
|
8903
|
+
throw new import_errors20.FuelError(
|
8904
|
+
import_errors20.ErrorCode.INVALID_ENTROPY,
|
8548
8905
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
8549
8906
|
);
|
8550
8907
|
}
|
@@ -8554,7 +8911,7 @@ function assertMnemonic(words) {
|
|
8554
8911
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
8555
8912
|
", "
|
8556
8913
|
)}] words, but got ${words.length}.`;
|
8557
|
-
throw new
|
8914
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
8558
8915
|
}
|
8559
8916
|
}
|
8560
8917
|
var Mnemonic = class {
|
@@ -8593,7 +8950,7 @@ var Mnemonic = class {
|
|
8593
8950
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8594
8951
|
const words = getWords(phrase);
|
8595
8952
|
assertMnemonic(words);
|
8596
|
-
return (0,
|
8953
|
+
return (0, import_utils35.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
8597
8954
|
}
|
8598
8955
|
/**
|
8599
8956
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8601,7 +8958,7 @@ var Mnemonic = class {
|
|
8601
8958
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8602
8959
|
*/
|
8603
8960
|
static entropyToMnemonic(entropy, wordlist = english) {
|
8604
|
-
const entropyBytes = (0,
|
8961
|
+
const entropyBytes = (0, import_utils35.arrayify)(entropy);
|
8605
8962
|
assertWordList(wordlist);
|
8606
8963
|
assertEntropy(entropyBytes);
|
8607
8964
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8613,8 +8970,8 @@ var Mnemonic = class {
|
|
8613
8970
|
*/
|
8614
8971
|
static mnemonicToSeed(phrase, passphrase = "") {
|
8615
8972
|
assertMnemonic(getWords(phrase));
|
8616
|
-
const phraseBytes = (0,
|
8617
|
-
const salt = (0,
|
8973
|
+
const phraseBytes = (0, import_utils35.toUtf8Bytes)(getPhrase(phrase));
|
8974
|
+
const salt = (0, import_utils35.toUtf8Bytes)(`mnemonic${passphrase}`);
|
8618
8975
|
return (0, import_crypto5.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
8619
8976
|
}
|
8620
8977
|
/**
|
@@ -8670,14 +9027,14 @@ var Mnemonic = class {
|
|
8670
9027
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8671
9028
|
*/
|
8672
9029
|
static masterKeysFromSeed(seed) {
|
8673
|
-
const seedArray = (0,
|
9030
|
+
const seedArray = (0, import_utils35.arrayify)(seed);
|
8674
9031
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8675
|
-
throw new
|
8676
|
-
|
9032
|
+
throw new import_errors20.FuelError(
|
9033
|
+
import_errors20.ErrorCode.INVALID_SEED,
|
8677
9034
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8678
9035
|
);
|
8679
9036
|
}
|
8680
|
-
return (0,
|
9037
|
+
return (0, import_utils35.arrayify)((0, import_crypto5.computeHmac)("sha512", MasterSecret, seedArray));
|
8681
9038
|
}
|
8682
9039
|
/**
|
8683
9040
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8688,22 +9045,22 @@ var Mnemonic = class {
|
|
8688
9045
|
*/
|
8689
9046
|
static seedToExtendedKey(seed, testnet = false) {
|
8690
9047
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8691
|
-
const prefix = (0,
|
9048
|
+
const prefix = (0, import_utils35.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8692
9049
|
const depth = "0x00";
|
8693
9050
|
const fingerprint = "0x00000000";
|
8694
9051
|
const index = "0x00000000";
|
8695
9052
|
const chainCode = masterKey.slice(32);
|
8696
9053
|
const privateKey = masterKey.slice(0, 32);
|
8697
|
-
const extendedKey = (0,
|
9054
|
+
const extendedKey = (0, import_utils35.concat)([
|
8698
9055
|
prefix,
|
8699
9056
|
depth,
|
8700
9057
|
fingerprint,
|
8701
9058
|
index,
|
8702
9059
|
chainCode,
|
8703
|
-
(0,
|
9060
|
+
(0, import_utils35.concat)(["0x00", privateKey])
|
8704
9061
|
]);
|
8705
|
-
const checksum = (0,
|
8706
|
-
return (0,
|
9062
|
+
const checksum = (0, import_utils35.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
9063
|
+
return (0, import_utils35.encodeBase58)((0, import_utils35.concat)([extendedKey, checksum]));
|
8707
9064
|
}
|
8708
9065
|
/**
|
8709
9066
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8718,7 +9075,7 @@ var Mnemonic = class {
|
|
8718
9075
|
* @returns A randomly generated mnemonic
|
8719
9076
|
*/
|
8720
9077
|
static generate(size = 32, extraEntropy = "") {
|
8721
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
9078
|
+
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);
|
8722
9079
|
return Mnemonic.entropyToMnemonic(entropy);
|
8723
9080
|
}
|
8724
9081
|
};
|
@@ -8726,12 +9083,12 @@ var mnemonic_default = Mnemonic;
|
|
8726
9083
|
|
8727
9084
|
// src/hdwallet/hdwallet.ts
|
8728
9085
|
var HARDENED_INDEX = 2147483648;
|
8729
|
-
var MainnetPRV2 = (0,
|
8730
|
-
var MainnetPUB = (0,
|
8731
|
-
var TestnetPRV2 = (0,
|
8732
|
-
var TestnetPUB = (0,
|
9086
|
+
var MainnetPRV2 = (0, import_utils37.hexlify)("0x0488ade4");
|
9087
|
+
var MainnetPUB = (0, import_utils37.hexlify)("0x0488b21e");
|
9088
|
+
var TestnetPRV2 = (0, import_utils37.hexlify)("0x04358394");
|
9089
|
+
var TestnetPUB = (0, import_utils37.hexlify)("0x043587cf");
|
8733
9090
|
function base58check(data) {
|
8734
|
-
return (0,
|
9091
|
+
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)]));
|
8735
9092
|
}
|
8736
9093
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8737
9094
|
if (isPublic) {
|
@@ -8740,17 +9097,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8740
9097
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8741
9098
|
}
|
8742
9099
|
function isPublicExtendedKey(extendedKey) {
|
8743
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
9100
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils37.hexlify)(extendedKey.slice(0, 4)));
|
8744
9101
|
}
|
8745
9102
|
function isValidExtendedKey(extendedKey) {
|
8746
9103
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8747
|
-
(0,
|
9104
|
+
(0, import_utils37.hexlify)(extendedKey.slice(0, 4))
|
8748
9105
|
);
|
8749
9106
|
}
|
8750
9107
|
function parsePath(path, depth = 0) {
|
8751
9108
|
const components = path.split("/");
|
8752
9109
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
8753
|
-
throw new
|
9110
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
|
8754
9111
|
}
|
8755
9112
|
if (components[0] === "m") {
|
8756
9113
|
components.shift();
|
@@ -8762,8 +9119,8 @@ function parsePath(path, depth = 0) {
|
|
8762
9119
|
var HDWallet = class {
|
8763
9120
|
depth = 0;
|
8764
9121
|
index = 0;
|
8765
|
-
fingerprint = (0,
|
8766
|
-
parentFingerprint = (0,
|
9122
|
+
fingerprint = (0, import_utils37.hexlify)("0x00000000");
|
9123
|
+
parentFingerprint = (0, import_utils37.hexlify)("0x00000000");
|
8767
9124
|
privateKey;
|
8768
9125
|
publicKey;
|
8769
9126
|
chainCode;
|
@@ -8775,19 +9132,19 @@ var HDWallet = class {
|
|
8775
9132
|
constructor(config) {
|
8776
9133
|
if (config.privateKey) {
|
8777
9134
|
const signer = new Signer(config.privateKey);
|
8778
|
-
this.publicKey = (0,
|
8779
|
-
this.privateKey = (0,
|
9135
|
+
this.publicKey = (0, import_utils37.hexlify)(signer.compressedPublicKey);
|
9136
|
+
this.privateKey = (0, import_utils37.hexlify)(config.privateKey);
|
8780
9137
|
} else {
|
8781
9138
|
if (!config.publicKey) {
|
8782
|
-
throw new
|
8783
|
-
|
9139
|
+
throw new import_errors21.FuelError(
|
9140
|
+
import_errors21.ErrorCode.HD_WALLET_ERROR,
|
8784
9141
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8785
9142
|
);
|
8786
9143
|
}
|
8787
|
-
this.publicKey = (0,
|
9144
|
+
this.publicKey = (0, import_utils37.hexlify)(config.publicKey);
|
8788
9145
|
}
|
8789
9146
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8790
|
-
this.fingerprint = (0,
|
9147
|
+
this.fingerprint = (0, import_utils37.dataSlice)((0, import_crypto6.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
8791
9148
|
this.depth = config.depth || this.depth;
|
8792
9149
|
this.index = config.index || this.index;
|
8793
9150
|
this.chainCode = config.chainCode;
|
@@ -8803,28 +9160,28 @@ var HDWallet = class {
|
|
8803
9160
|
* @returns A new instance of HDWallet on the derived index
|
8804
9161
|
*/
|
8805
9162
|
deriveIndex(index) {
|
8806
|
-
const privateKey = this.privateKey && (0,
|
8807
|
-
const publicKey = (0,
|
8808
|
-
const chainCode = (0,
|
9163
|
+
const privateKey = this.privateKey && (0, import_utils37.arrayify)(this.privateKey);
|
9164
|
+
const publicKey = (0, import_utils37.arrayify)(this.publicKey);
|
9165
|
+
const chainCode = (0, import_utils37.arrayify)(this.chainCode);
|
8809
9166
|
const data = new Uint8Array(37);
|
8810
9167
|
if (index & HARDENED_INDEX) {
|
8811
9168
|
if (!privateKey) {
|
8812
|
-
throw new
|
8813
|
-
|
9169
|
+
throw new import_errors21.FuelError(
|
9170
|
+
import_errors21.ErrorCode.HD_WALLET_ERROR,
|
8814
9171
|
"Cannot derive a hardened index without a private Key."
|
8815
9172
|
);
|
8816
9173
|
}
|
8817
9174
|
data.set(privateKey, 1);
|
8818
9175
|
} else {
|
8819
|
-
data.set((0,
|
9176
|
+
data.set((0, import_utils37.arrayify)(this.publicKey));
|
8820
9177
|
}
|
8821
|
-
data.set((0,
|
8822
|
-
const bytes = (0,
|
9178
|
+
data.set((0, import_math23.toBytes)(index, 4), 33);
|
9179
|
+
const bytes = (0, import_utils37.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
|
8823
9180
|
const IL = bytes.slice(0, 32);
|
8824
9181
|
const IR = bytes.slice(32);
|
8825
9182
|
if (privateKey) {
|
8826
9183
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8827
|
-
const ki = (0,
|
9184
|
+
const ki = (0, import_math23.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8828
9185
|
return new HDWallet({
|
8829
9186
|
privateKey: ki,
|
8830
9187
|
chainCode: IR,
|
@@ -8833,7 +9190,7 @@ var HDWallet = class {
|
|
8833
9190
|
parentFingerprint: this.fingerprint
|
8834
9191
|
});
|
8835
9192
|
}
|
8836
|
-
const signer = new Signer((0,
|
9193
|
+
const signer = new Signer((0, import_utils37.hexlify)(IL));
|
8837
9194
|
const Ki = signer.addPoint(publicKey);
|
8838
9195
|
return new HDWallet({
|
8839
9196
|
publicKey: Ki,
|
@@ -8862,18 +9219,18 @@ var HDWallet = class {
|
|
8862
9219
|
*/
|
8863
9220
|
toExtendedKey(isPublic = false, testnet = false) {
|
8864
9221
|
if (this.depth >= 256) {
|
8865
|
-
throw new
|
8866
|
-
|
9222
|
+
throw new import_errors21.FuelError(
|
9223
|
+
import_errors21.ErrorCode.HD_WALLET_ERROR,
|
8867
9224
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
8868
9225
|
);
|
8869
9226
|
}
|
8870
9227
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8871
|
-
const depth = (0,
|
9228
|
+
const depth = (0, import_utils37.hexlify)(Uint8Array.from([this.depth]));
|
8872
9229
|
const parentFingerprint = this.parentFingerprint;
|
8873
|
-
const index = (0,
|
9230
|
+
const index = (0, import_math23.toHex)(this.index, 4);
|
8874
9231
|
const chainCode = this.chainCode;
|
8875
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8876
|
-
const extendedKey = (0,
|
9232
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils37.concat)(["0x00", this.privateKey]) : this.publicKey;
|
9233
|
+
const extendedKey = (0, import_utils37.arrayify)((0, import_utils37.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8877
9234
|
return base58check(extendedKey);
|
8878
9235
|
}
|
8879
9236
|
/**
|
@@ -8885,34 +9242,34 @@ var HDWallet = class {
|
|
8885
9242
|
static fromSeed(seed) {
|
8886
9243
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8887
9244
|
return new HDWallet({
|
8888
|
-
chainCode: (0,
|
8889
|
-
privateKey: (0,
|
9245
|
+
chainCode: (0, import_utils37.arrayify)(masterKey.slice(32)),
|
9246
|
+
privateKey: (0, import_utils37.arrayify)(masterKey.slice(0, 32))
|
8890
9247
|
});
|
8891
9248
|
}
|
8892
9249
|
static fromExtendedKey(extendedKey) {
|
8893
|
-
const decoded = (0,
|
8894
|
-
const bytes = (0,
|
9250
|
+
const decoded = (0, import_utils37.hexlify)((0, import_math23.toBytes)((0, import_utils37.decodeBase58)(extendedKey)));
|
9251
|
+
const bytes = (0, import_utils37.arrayify)(decoded);
|
8895
9252
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8896
9253
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8897
|
-
throw new
|
9254
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
8898
9255
|
}
|
8899
9256
|
if (!validChecksum) {
|
8900
|
-
throw new
|
9257
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8901
9258
|
}
|
8902
9259
|
const depth = bytes[4];
|
8903
|
-
const parentFingerprint = (0,
|
8904
|
-
const index = parseInt((0,
|
8905
|
-
const chainCode = (0,
|
9260
|
+
const parentFingerprint = (0, import_utils37.hexlify)(bytes.slice(5, 9));
|
9261
|
+
const index = parseInt((0, import_utils37.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
9262
|
+
const chainCode = (0, import_utils37.hexlify)(bytes.slice(13, 45));
|
8906
9263
|
const key = bytes.slice(45, 78);
|
8907
9264
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8908
|
-
throw new
|
8909
|
-
|
9265
|
+
throw new import_errors21.FuelError(
|
9266
|
+
import_errors21.ErrorCode.HD_WALLET_ERROR,
|
8910
9267
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
8911
9268
|
);
|
8912
9269
|
}
|
8913
9270
|
if (isPublicExtendedKey(bytes)) {
|
8914
9271
|
if (key[0] !== 3) {
|
8915
|
-
throw new
|
9272
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
8916
9273
|
}
|
8917
9274
|
return new HDWallet({
|
8918
9275
|
publicKey: key,
|
@@ -8923,7 +9280,7 @@ var HDWallet = class {
|
|
8923
9280
|
});
|
8924
9281
|
}
|
8925
9282
|
if (key[0] !== 0) {
|
8926
|
-
throw new
|
9283
|
+
throw new import_errors21.FuelError(import_errors21.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
8927
9284
|
}
|
8928
9285
|
return new HDWallet({
|
8929
9286
|
privateKey: key.slice(1),
|
@@ -9091,7 +9448,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
9091
9448
|
// src/wallet-manager/wallet-manager.ts
|
9092
9449
|
var import_address9 = require("@fuel-ts/address");
|
9093
9450
|
var import_crypto7 = require("@fuel-ts/crypto");
|
9094
|
-
var
|
9451
|
+
var import_errors24 = require("@fuel-ts/errors");
|
9095
9452
|
var import_events = require("events");
|
9096
9453
|
|
9097
9454
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -9114,7 +9471,7 @@ var MemoryStorage = class {
|
|
9114
9471
|
|
9115
9472
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
9116
9473
|
var import_address7 = require("@fuel-ts/address");
|
9117
|
-
var
|
9474
|
+
var import_errors22 = require("@fuel-ts/errors");
|
9118
9475
|
var _secret;
|
9119
9476
|
var MnemonicVault = class {
|
9120
9477
|
constructor(options) {
|
@@ -9170,8 +9527,8 @@ var MnemonicVault = class {
|
|
9170
9527
|
}
|
9171
9528
|
numberOfAccounts += 1;
|
9172
9529
|
} while (numberOfAccounts < this.numberOfAccounts);
|
9173
|
-
throw new
|
9174
|
-
|
9530
|
+
throw new import_errors22.FuelError(
|
9531
|
+
import_errors22.ErrorCode.WALLET_MANAGER_ERROR,
|
9175
9532
|
`Account with address '${address}' not found in derived wallets.`
|
9176
9533
|
);
|
9177
9534
|
}
|
@@ -9185,7 +9542,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
9185
9542
|
|
9186
9543
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
9187
9544
|
var import_address8 = require("@fuel-ts/address");
|
9188
|
-
var
|
9545
|
+
var import_errors23 = require("@fuel-ts/errors");
|
9189
9546
|
var _privateKeys;
|
9190
9547
|
var PrivateKeyVault = class {
|
9191
9548
|
/**
|
@@ -9226,8 +9583,8 @@ var PrivateKeyVault = class {
|
|
9226
9583
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
9227
9584
|
);
|
9228
9585
|
if (!privateKey) {
|
9229
|
-
throw new
|
9230
|
-
|
9586
|
+
throw new import_errors23.FuelError(
|
9587
|
+
import_errors23.ErrorCode.WALLET_MANAGER_ERROR,
|
9231
9588
|
`No private key found for address '${address}'.`
|
9232
9589
|
);
|
9233
9590
|
}
|
@@ -9251,7 +9608,7 @@ var ERROR_MESSAGES = {
|
|
9251
9608
|
};
|
9252
9609
|
function assert(condition, message) {
|
9253
9610
|
if (!condition) {
|
9254
|
-
throw new
|
9611
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.WALLET_MANAGER_ERROR, message);
|
9255
9612
|
}
|
9256
9613
|
}
|
9257
9614
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -9477,25 +9834,25 @@ deserializeVaults_fn = function(vaults) {
|
|
9477
9834
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
9478
9835
|
|
9479
9836
|
// src/wallet-manager/types.ts
|
9480
|
-
var
|
9837
|
+
var import_errors25 = require("@fuel-ts/errors");
|
9481
9838
|
var Vault = class {
|
9482
9839
|
constructor(_options) {
|
9483
|
-
throw new
|
9840
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9484
9841
|
}
|
9485
9842
|
serialize() {
|
9486
|
-
throw new
|
9843
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9487
9844
|
}
|
9488
9845
|
getAccounts() {
|
9489
|
-
throw new
|
9846
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9490
9847
|
}
|
9491
9848
|
addAccount() {
|
9492
|
-
throw new
|
9849
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9493
9850
|
}
|
9494
9851
|
exportAccount(_address) {
|
9495
|
-
throw new
|
9852
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9496
9853
|
}
|
9497
9854
|
getWallet(_address) {
|
9498
|
-
throw new
|
9855
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
9499
9856
|
}
|
9500
9857
|
};
|
9501
9858
|
__publicField(Vault, "type");
|
@@ -9505,19 +9862,19 @@ var StorageAbstract = class {
|
|
9505
9862
|
// src/predicate/predicate.ts
|
9506
9863
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
9507
9864
|
var import_address10 = require("@fuel-ts/address");
|
9508
|
-
var
|
9509
|
-
var
|
9865
|
+
var import_errors26 = require("@fuel-ts/errors");
|
9866
|
+
var import_utils39 = require("@fuel-ts/utils");
|
9510
9867
|
|
9511
9868
|
// src/predicate/utils/getPredicateRoot.ts
|
9512
9869
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9513
9870
|
var import_merkle = require("@fuel-ts/merkle");
|
9514
|
-
var
|
9871
|
+
var import_utils38 = require("@fuel-ts/utils");
|
9515
9872
|
var getPredicateRoot = (bytecode) => {
|
9516
9873
|
const chunkSize = 16 * 1024;
|
9517
|
-
const bytes = (0,
|
9518
|
-
const chunks = (0,
|
9519
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
9520
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
9874
|
+
const bytes = (0, import_utils38.arrayify)(bytecode);
|
9875
|
+
const chunks = (0, import_utils38.chunkAndPadBytes)(bytes, chunkSize);
|
9876
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils38.hexlify)(c)));
|
9877
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils38.concat)(["0x4655454C", codeRoot]));
|
9521
9878
|
return predicateRoot;
|
9522
9879
|
};
|
9523
9880
|
|
@@ -9532,14 +9889,14 @@ var Predicate = class extends Account {
|
|
9532
9889
|
* @param bytecode - The bytecode of the predicate.
|
9533
9890
|
* @param abi - The JSON ABI of the predicate.
|
9534
9891
|
* @param provider - The provider used to interact with the blockchain.
|
9535
|
-
* @param
|
9892
|
+
* @param data - The predicate input data (optional).
|
9536
9893
|
* @param configurableConstants - Optional configurable constants for the predicate.
|
9537
9894
|
*/
|
9538
9895
|
constructor({
|
9539
9896
|
bytecode,
|
9540
9897
|
abi,
|
9541
9898
|
provider,
|
9542
|
-
|
9899
|
+
data,
|
9543
9900
|
configurableConstants
|
9544
9901
|
}) {
|
9545
9902
|
const { predicateBytes, predicateInterface } = Predicate.processPredicateData(
|
@@ -9551,8 +9908,8 @@ var Predicate = class extends Account {
|
|
9551
9908
|
super(address, provider);
|
9552
9909
|
this.bytes = predicateBytes;
|
9553
9910
|
this.interface = predicateInterface;
|
9554
|
-
if (
|
9555
|
-
this.predicateData =
|
9911
|
+
if (data !== void 0 && data.length > 0) {
|
9912
|
+
this.predicateData = data;
|
9556
9913
|
}
|
9557
9914
|
}
|
9558
9915
|
/**
|
@@ -9569,8 +9926,8 @@ var Predicate = class extends Account {
|
|
9569
9926
|
}
|
9570
9927
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
9571
9928
|
if (isRequestInputResourceFromOwner(input, this.address)) {
|
9572
|
-
input.predicate = (0,
|
9573
|
-
input.predicateData = (0,
|
9929
|
+
input.predicate = (0, import_utils39.hexlify)(this.bytes);
|
9930
|
+
input.predicateData = (0, import_utils39.hexlify)(this.getPredicateData());
|
9574
9931
|
input.witnessIndex = 0;
|
9575
9932
|
}
|
9576
9933
|
});
|
@@ -9612,13 +9969,13 @@ var Predicate = class extends Account {
|
|
9612
9969
|
* @returns An object containing the new predicate bytes and interface.
|
9613
9970
|
*/
|
9614
9971
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
9615
|
-
let predicateBytes = (0,
|
9972
|
+
let predicateBytes = (0, import_utils39.arrayify)(bytes);
|
9616
9973
|
let abiInterface;
|
9617
9974
|
if (jsonAbi) {
|
9618
9975
|
abiInterface = new import_abi_coder8.Interface(jsonAbi);
|
9619
9976
|
if (abiInterface.functions.main === void 0) {
|
9620
|
-
throw new
|
9621
|
-
|
9977
|
+
throw new import_errors26.FuelError(
|
9978
|
+
import_errors26.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
9622
9979
|
'Cannot use ABI without "main" function.'
|
9623
9980
|
);
|
9624
9981
|
}
|
@@ -9650,8 +10007,8 @@ var Predicate = class extends Account {
|
|
9650
10007
|
);
|
9651
10008
|
return resources.map((resource) => ({
|
9652
10009
|
...resource,
|
9653
|
-
predicate: (0,
|
9654
|
-
predicateData: (0,
|
10010
|
+
predicate: (0, import_utils39.hexlify)(this.bytes),
|
10011
|
+
predicateData: (0, import_utils39.hexlify)(this.getPredicateData())
|
9655
10012
|
}));
|
9656
10013
|
}
|
9657
10014
|
/**
|
@@ -9663,8 +10020,8 @@ var Predicate = class extends Account {
|
|
9663
10020
|
generateFakeResources(coins) {
|
9664
10021
|
return super.generateFakeResources(coins).map((coin) => ({
|
9665
10022
|
...coin,
|
9666
|
-
predicate: (0,
|
9667
|
-
predicateData: (0,
|
10023
|
+
predicate: (0, import_utils39.hexlify)(this.bytes),
|
10024
|
+
predicateData: (0, import_utils39.hexlify)(this.getPredicateData())
|
9668
10025
|
}));
|
9669
10026
|
}
|
9670
10027
|
/**
|
@@ -9679,24 +10036,31 @@ var Predicate = class extends Account {
|
|
9679
10036
|
const mutatedBytes = bytes;
|
9680
10037
|
try {
|
9681
10038
|
if (!abiInterface) {
|
9682
|
-
throw new
|
10039
|
+
throw new import_errors26.FuelError(
|
10040
|
+
import_errors26.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
9683
10041
|
"Cannot validate configurable constants because the Predicate was instantiated without a JSON ABI"
|
9684
10042
|
);
|
9685
10043
|
}
|
9686
10044
|
if (Object.keys(abiInterface.configurables).length === 0) {
|
9687
|
-
throw new
|
10045
|
+
throw new import_errors26.FuelError(
|
10046
|
+
import_errors26.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
10047
|
+
"Predicate has no configurable constants to be set"
|
10048
|
+
);
|
9688
10049
|
}
|
9689
10050
|
Object.entries(configurableConstants).forEach(([key, value]) => {
|
9690
10051
|
if (!abiInterface?.configurables[key]) {
|
9691
|
-
throw new
|
10052
|
+
throw new import_errors26.FuelError(
|
10053
|
+
import_errors26.ErrorCode.CONFIGURABLE_NOT_FOUND,
|
10054
|
+
`No configurable constant named '${key}' found in the Predicate`
|
10055
|
+
);
|
9692
10056
|
}
|
9693
10057
|
const { offset } = abiInterface.configurables[key];
|
9694
10058
|
const encoded = abiInterface.encodeConfigurable(key, value);
|
9695
10059
|
mutatedBytes.set(encoded, offset);
|
9696
10060
|
});
|
9697
10061
|
} catch (err) {
|
9698
|
-
throw new
|
9699
|
-
|
10062
|
+
throw new import_errors26.FuelError(
|
10063
|
+
import_errors26.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
9700
10064
|
`Error setting configurable constants: ${err.message}.`
|
9701
10065
|
);
|
9702
10066
|
}
|
@@ -9727,9 +10091,10 @@ var Predicate = class extends Account {
|
|
9727
10091
|
};
|
9728
10092
|
|
9729
10093
|
// src/connectors/fuel.ts
|
9730
|
-
var
|
10094
|
+
var import_errors29 = require("@fuel-ts/errors");
|
9731
10095
|
|
9732
10096
|
// src/connectors/fuel-connector.ts
|
10097
|
+
var import_errors27 = require("@fuel-ts/errors");
|
9733
10098
|
var import_events2 = require("events");
|
9734
10099
|
|
9735
10100
|
// src/connectors/types/connector-types.ts
|
@@ -9803,7 +10168,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9803
10168
|
* @returns Always true.
|
9804
10169
|
*/
|
9805
10170
|
async ping() {
|
9806
|
-
throw new
|
10171
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9807
10172
|
}
|
9808
10173
|
/**
|
9809
10174
|
* Should return the current version of the connector
|
@@ -9812,7 +10177,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9812
10177
|
* @returns boolean - connection status.
|
9813
10178
|
*/
|
9814
10179
|
async version() {
|
9815
|
-
throw new
|
10180
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9816
10181
|
}
|
9817
10182
|
/**
|
9818
10183
|
* Should return true if the connector is connected
|
@@ -9821,7 +10186,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9821
10186
|
* @returns The connection status.
|
9822
10187
|
*/
|
9823
10188
|
async isConnected() {
|
9824
|
-
throw new
|
10189
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9825
10190
|
}
|
9826
10191
|
/**
|
9827
10192
|
* Should return all the accounts authorized for the
|
@@ -9830,7 +10195,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9830
10195
|
* @returns The accounts addresses strings
|
9831
10196
|
*/
|
9832
10197
|
async accounts() {
|
9833
|
-
throw new
|
10198
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9834
10199
|
}
|
9835
10200
|
/**
|
9836
10201
|
* Should start the connection process and return
|
@@ -9842,7 +10207,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9842
10207
|
* @returns boolean - connection status.
|
9843
10208
|
*/
|
9844
10209
|
async connect() {
|
9845
|
-
throw new
|
10210
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9846
10211
|
}
|
9847
10212
|
/**
|
9848
10213
|
* Should disconnect the current connection and
|
@@ -9852,7 +10217,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9852
10217
|
* @returns The connection status.
|
9853
10218
|
*/
|
9854
10219
|
async disconnect() {
|
9855
|
-
throw new
|
10220
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9856
10221
|
}
|
9857
10222
|
/**
|
9858
10223
|
* Should start the sign message process and return
|
@@ -9864,7 +10229,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9864
10229
|
* @returns Message signature
|
9865
10230
|
*/
|
9866
10231
|
async signMessage(_address, _message) {
|
9867
|
-
throw new
|
10232
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9868
10233
|
}
|
9869
10234
|
/**
|
9870
10235
|
* Should start the sign transaction process and return
|
@@ -9876,7 +10241,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9876
10241
|
* @returns Transaction signature
|
9877
10242
|
*/
|
9878
10243
|
async signTransaction(_address, _transaction) {
|
9879
|
-
throw new
|
10244
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9880
10245
|
}
|
9881
10246
|
/**
|
9882
10247
|
* Should start the send transaction process and return
|
@@ -9892,7 +10257,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9892
10257
|
* @returns The transaction id
|
9893
10258
|
*/
|
9894
10259
|
async sendTransaction(_address, _transaction) {
|
9895
|
-
throw new
|
10260
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9896
10261
|
}
|
9897
10262
|
/**
|
9898
10263
|
* Should return the current account selected inside the connector, if the account
|
@@ -9903,7 +10268,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9903
10268
|
* @returns The current account selected otherwise null.
|
9904
10269
|
*/
|
9905
10270
|
async currentAccount() {
|
9906
|
-
throw new
|
10271
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9907
10272
|
}
|
9908
10273
|
/**
|
9909
10274
|
* Should add the assets metadata to the connector and return true if the asset
|
@@ -9917,7 +10282,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9917
10282
|
* @returns True if the asset was added successfully
|
9918
10283
|
*/
|
9919
10284
|
async addAssets(_assets) {
|
9920
|
-
throw new
|
10285
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9921
10286
|
}
|
9922
10287
|
/**
|
9923
10288
|
* Should add the asset metadata to the connector and return true if the asset
|
@@ -9931,7 +10296,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9931
10296
|
* @returns True if the asset was added successfully
|
9932
10297
|
*/
|
9933
10298
|
async addAsset(_asset) {
|
9934
|
-
throw new
|
10299
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9935
10300
|
}
|
9936
10301
|
/**
|
9937
10302
|
* Should return all the assets added to the connector. If a connection is already established.
|
@@ -9939,7 +10304,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9939
10304
|
* @returns Array of assets metadata from the connector vinculated to the all accounts from a specific Wallet.
|
9940
10305
|
*/
|
9941
10306
|
async assets() {
|
9942
|
-
throw new
|
10307
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9943
10308
|
}
|
9944
10309
|
/**
|
9945
10310
|
* Should start the add network process and return true if the network was added successfully.
|
@@ -9950,7 +10315,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9950
10315
|
* @returns Return true if the network was added successfully
|
9951
10316
|
*/
|
9952
10317
|
async addNetwork(_networkUrl) {
|
9953
|
-
throw new
|
10318
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9954
10319
|
}
|
9955
10320
|
/**
|
9956
10321
|
* Should start the select network process and return true if the network has change successfully.
|
@@ -9961,7 +10326,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9961
10326
|
* @returns Return true if the network was added successfully
|
9962
10327
|
*/
|
9963
10328
|
async selectNetwork(_network) {
|
9964
|
-
throw new
|
10329
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9965
10330
|
}
|
9966
10331
|
/**
|
9967
10332
|
* Should return all the networks available from the connector. If the connection is already established.
|
@@ -9969,7 +10334,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9969
10334
|
* @returns Return all the networks added to the connector.
|
9970
10335
|
*/
|
9971
10336
|
async networks() {
|
9972
|
-
throw new
|
10337
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9973
10338
|
}
|
9974
10339
|
/**
|
9975
10340
|
* Should return the current network selected inside the connector. Even if the connection is not established.
|
@@ -9977,7 +10342,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9977
10342
|
* @returns Return the current network selected inside the connector.
|
9978
10343
|
*/
|
9979
10344
|
async currentNetwork() {
|
9980
|
-
throw new
|
10345
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9981
10346
|
}
|
9982
10347
|
/**
|
9983
10348
|
* Should add the ABI to the connector and return true if the ABI was added successfully.
|
@@ -9987,7 +10352,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9987
10352
|
* @returns Return true if the ABI was added successfully.
|
9988
10353
|
*/
|
9989
10354
|
async addABI(_contractId, _abi) {
|
9990
|
-
throw new
|
10355
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
9991
10356
|
}
|
9992
10357
|
/**
|
9993
10358
|
* Should return the ABI from the connector vinculated to the all accounts from a specific Wallet.
|
@@ -9996,7 +10361,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
9996
10361
|
* @returns The ABI if it exists, otherwise return null.
|
9997
10362
|
*/
|
9998
10363
|
async getABI(_id) {
|
9999
|
-
throw new
|
10364
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
10000
10365
|
}
|
10001
10366
|
/**
|
10002
10367
|
* Should return true if the abi exists in the connector vinculated to the all accounts from a specific Wallet.
|
@@ -10005,7 +10370,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
10005
10370
|
* @returns Returns true if the abi exists or false if not.
|
10006
10371
|
*/
|
10007
10372
|
async hasABI(_id) {
|
10008
|
-
throw new
|
10373
|
+
throw new import_errors27.FuelError(import_errors27.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
10009
10374
|
}
|
10010
10375
|
/**
|
10011
10376
|
* Event listener for the connector.
|
@@ -10049,6 +10414,7 @@ function dispatchFuelConnectorEvent(connector) {
|
|
10049
10414
|
}
|
10050
10415
|
|
10051
10416
|
// src/connectors/utils/promises.ts
|
10417
|
+
var import_errors28 = require("@fuel-ts/errors");
|
10052
10418
|
function deferPromise() {
|
10053
10419
|
const defer = {};
|
10054
10420
|
defer.promise = new Promise((resolve, reject) => {
|
@@ -10060,7 +10426,7 @@ function deferPromise() {
|
|
10060
10426
|
async function withTimeout(promise, timeout = 1050) {
|
10061
10427
|
const timeoutPromise = new Promise((resolve, reject) => {
|
10062
10428
|
setTimeout(() => {
|
10063
|
-
reject(new
|
10429
|
+
reject(new import_errors28.FuelError(import_errors28.FuelError.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
10064
10430
|
}, timeout);
|
10065
10431
|
});
|
10066
10432
|
return Promise.race([timeoutPromise, promise]);
|
@@ -10147,7 +10513,8 @@ var _Fuel = class extends FuelConnector {
|
|
10147
10513
|
const hasConnector = await this.hasConnector();
|
10148
10514
|
await this.pingConnector();
|
10149
10515
|
if (!this._currentConnector || !hasConnector) {
|
10150
|
-
throw new
|
10516
|
+
throw new import_errors29.FuelError(
|
10517
|
+
import_errors29.ErrorCode.MISSING_CONNECTOR,
|
10151
10518
|
`No connector selected for calling ${method}. Use hasConnector before executing other methods.`
|
10152
10519
|
);
|
10153
10520
|
}
|
@@ -10211,7 +10578,7 @@ var _Fuel = class extends FuelConnector {
|
|
10211
10578
|
cacheTime: PING_CACHE_TIME
|
10212
10579
|
})();
|
10213
10580
|
} catch {
|
10214
|
-
throw new
|
10581
|
+
throw new import_errors29.FuelError(import_errors29.ErrorCode.INVALID_PROVIDER, "Current connector is not available.");
|
10215
10582
|
}
|
10216
10583
|
}
|
10217
10584
|
/**
|
@@ -10360,7 +10727,7 @@ var _Fuel = class extends FuelConnector {
|
|
10360
10727
|
const currentNetwork = await this.currentNetwork();
|
10361
10728
|
provider = await Provider.create(currentNetwork.url);
|
10362
10729
|
} else {
|
10363
|
-
throw new
|
10730
|
+
throw new import_errors29.FuelError(import_errors29.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
|
10364
10731
|
}
|
10365
10732
|
return provider;
|
10366
10733
|
}
|
@@ -10405,11 +10772,12 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10405
10772
|
BLOCKS_PAGE_SIZE_LIMIT,
|
10406
10773
|
BaseTransactionRequest,
|
10407
10774
|
BaseWalletUnlocked,
|
10775
|
+
BlobTransactionRequest,
|
10408
10776
|
CHAIN_IDS,
|
10409
10777
|
ChainName,
|
10410
10778
|
ChangeOutputCollisionError,
|
10411
10779
|
CreateTransactionRequest,
|
10412
|
-
|
10780
|
+
DEFAULT_RESOURCE_CACHE_TTL,
|
10413
10781
|
Fuel,
|
10414
10782
|
FuelConnector,
|
10415
10783
|
FuelConnectorEventType,
|
@@ -10443,6 +10811,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10443
10811
|
WalletUnlocked,
|
10444
10812
|
addAmountToCoinQuantities,
|
10445
10813
|
addOperation,
|
10814
|
+
aggregateInputsAmountsByAssetAndOwner,
|
10446
10815
|
assemblePanicError,
|
10447
10816
|
assembleReceiptByType,
|
10448
10817
|
assembleRevertError,
|
@@ -10453,6 +10822,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10453
10822
|
cacheRequestInputsResources,
|
10454
10823
|
cacheRequestInputsResourcesFromOwner,
|
10455
10824
|
calculateGasFee,
|
10825
|
+
calculateMetadataGasForTxBlob,
|
10456
10826
|
calculateMetadataGasForTxCreate,
|
10457
10827
|
calculateMetadataGasForTxScript,
|
10458
10828
|
calculateTXFeeForSummary,
|
@@ -10511,6 +10881,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10511
10881
|
hasSameAssetId,
|
10512
10882
|
inputify,
|
10513
10883
|
isCoin,
|
10884
|
+
isInputCoin,
|
10514
10885
|
isMessage,
|
10515
10886
|
isRawCoin,
|
10516
10887
|
isRawMessage,
|
@@ -10518,7 +10889,11 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10518
10889
|
isRequestInputMessage,
|
10519
10890
|
isRequestInputResource,
|
10520
10891
|
isRequestInputResourceFromOwner,
|
10892
|
+
isTransactionTypeBlob,
|
10893
|
+
isTransactionTypeCreate,
|
10894
|
+
isTransactionTypeScript,
|
10521
10895
|
isType,
|
10896
|
+
isTypeBlob,
|
10522
10897
|
isTypeCreate,
|
10523
10898
|
isTypeMint,
|
10524
10899
|
isTypeScript,
|