@fuel-ts/account 0.0.0-rc-2037-20240423134048 → 0.0.0-rc-2021-20240423134551
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +829 -600
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +857 -637
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +680 -455
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +11 -18
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +822 -328
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +6 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/index.d.ts +0 -1
- package/dist/providers/transaction-request/index.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +6 -7
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/index.d.ts +0 -1
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1545 -1076
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +837 -612
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +674 -446
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
- package/dist/providers/transaction-request/helpers.d.ts +0 -10
- package/dist/providers/transaction-request/helpers.d.ts.map +0 -1
- package/dist/test-utils/resources.d.ts +0 -4
- package/dist/test-utils/resources.d.ts.map +0 -1
- package/dist/test-utils/transactionRequest.d.ts +0 -5
- package/dist/test-utils/transactionRequest.d.ts.map +0 -1
package/dist/index.js
CHANGED
@@ -88,14 +88,14 @@ __export(src_exports, {
|
|
88
88
|
StorageAbstract: () => StorageAbstract,
|
89
89
|
TransactionResponse: () => TransactionResponse,
|
90
90
|
TransactionStatus: () => TransactionStatus,
|
91
|
-
TransactionType: () =>
|
91
|
+
TransactionType: () => import_transactions6.TransactionType,
|
92
92
|
TransactionTypeName: () => TransactionTypeName,
|
93
93
|
Vault: () => Vault,
|
94
94
|
Wallet: () => Wallet,
|
95
95
|
WalletLocked: () => WalletLocked,
|
96
96
|
WalletManager: () => WalletManager,
|
97
97
|
WalletUnlocked: () => WalletUnlocked,
|
98
|
-
|
98
|
+
addAmountToCoinQuantities: () => addAmountToCoinQuantities,
|
99
99
|
addOperation: () => addOperation,
|
100
100
|
assemblePanicError: () => assemblePanicError,
|
101
101
|
assembleReceiptByType: () => assembleReceiptByType,
|
@@ -104,10 +104,10 @@ __export(src_exports, {
|
|
104
104
|
assets: () => assets,
|
105
105
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
106
106
|
cacheFor: () => cacheFor,
|
107
|
-
|
107
|
+
cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
|
108
|
+
calculateGasFee: () => calculateGasFee,
|
108
109
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
109
110
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
110
|
-
calculatePriceWithFactor: () => calculatePriceWithFactor,
|
111
111
|
calculateTransactionFee: () => calculateTransactionFee,
|
112
112
|
coinQuantityfy: () => coinQuantityfy,
|
113
113
|
deferPromise: () => deferPromise,
|
@@ -151,7 +151,6 @@ __export(src_exports, {
|
|
151
151
|
getReceiptsMessageOut: () => getReceiptsMessageOut,
|
152
152
|
getReceiptsTransferOut: () => getReceiptsTransferOut,
|
153
153
|
getReceiptsWithMissingData: () => getReceiptsWithMissingData,
|
154
|
-
getRequestInputResourceOwner: () => getRequestInputResourceOwner,
|
155
154
|
getTransactionStatusName: () => getTransactionStatusName,
|
156
155
|
getTransactionSummary: () => getTransactionSummary,
|
157
156
|
getTransactionSummaryFromRequest: () => getTransactionSummaryFromRequest,
|
@@ -165,10 +164,6 @@ __export(src_exports, {
|
|
165
164
|
isMessage: () => isMessage,
|
166
165
|
isRawCoin: () => isRawCoin,
|
167
166
|
isRawMessage: () => isRawMessage,
|
168
|
-
isRequestInputCoin: () => isRequestInputCoin,
|
169
|
-
isRequestInputMessage: () => isRequestInputMessage,
|
170
|
-
isRequestInputResource: () => isRequestInputResource,
|
171
|
-
isRequestInputResourceFromOwner: () => isRequestInputResourceFromOwner,
|
172
167
|
isType: () => isType,
|
173
168
|
isTypeCreate: () => isTypeCreate,
|
174
169
|
isTypeMint: () => isTypeMint,
|
@@ -193,8 +188,9 @@ var import_address4 = require("@fuel-ts/address");
|
|
193
188
|
var import_configs12 = require("@fuel-ts/address/configs");
|
194
189
|
var import_errors16 = require("@fuel-ts/errors");
|
195
190
|
var import_interfaces = require("@fuel-ts/interfaces");
|
196
|
-
var
|
197
|
-
var
|
191
|
+
var import_math19 = require("@fuel-ts/math");
|
192
|
+
var import_utils27 = require("@fuel-ts/utils");
|
193
|
+
var import_ramda4 = require("ramda");
|
198
194
|
|
199
195
|
// src/providers/coin-quantity.ts
|
200
196
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -203,24 +199,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
203
199
|
var coinQuantityfy = (coinQuantityLike) => {
|
204
200
|
let assetId;
|
205
201
|
let amount;
|
206
|
-
let
|
202
|
+
let max;
|
207
203
|
if (Array.isArray(coinQuantityLike)) {
|
208
204
|
amount = coinQuantityLike[0];
|
209
205
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
210
|
-
|
206
|
+
max = coinQuantityLike[2] ?? void 0;
|
211
207
|
} else {
|
212
208
|
amount = coinQuantityLike.amount;
|
213
209
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
214
|
-
|
210
|
+
max = coinQuantityLike.max ?? void 0;
|
215
211
|
}
|
216
212
|
const bnAmount = (0, import_math.bn)(amount);
|
217
213
|
return {
|
218
214
|
assetId: (0, import_utils.hexlify)(assetId),
|
219
215
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
220
|
-
max:
|
216
|
+
max: max ? (0, import_math.bn)(max) : void 0
|
221
217
|
};
|
222
218
|
};
|
223
|
-
var
|
219
|
+
var addAmountToCoinQuantities = (params) => {
|
224
220
|
const { amount, assetId } = params;
|
225
221
|
const coinQuantities = [...params.coinQuantities];
|
226
222
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -235,27 +231,51 @@ var addAmountToAsset = (params) => {
|
|
235
231
|
// src/providers/provider.ts
|
236
232
|
var import_address3 = require("@fuel-ts/address");
|
237
233
|
var import_errors14 = require("@fuel-ts/errors");
|
238
|
-
var
|
234
|
+
var import_math16 = require("@fuel-ts/math");
|
239
235
|
var import_transactions19 = require("@fuel-ts/transactions");
|
240
|
-
var
|
236
|
+
var import_utils22 = require("@fuel-ts/utils");
|
241
237
|
var import_versions = require("@fuel-ts/versions");
|
242
|
-
var
|
238
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
243
239
|
var import_ethers = require("ethers");
|
244
240
|
var import_graphql_request = require("graphql-request");
|
245
241
|
var import_ramda3 = require("ramda");
|
246
242
|
|
247
243
|
// src/providers/__generated__/operations.ts
|
248
244
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
245
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
|
246
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
247
|
+
type: __typename
|
248
|
+
... on SubmittedStatus {
|
249
|
+
time
|
250
|
+
}
|
251
|
+
... on SuccessStatus {
|
252
|
+
block {
|
253
|
+
id
|
254
|
+
}
|
255
|
+
time
|
256
|
+
programState {
|
257
|
+
returnType
|
258
|
+
data
|
259
|
+
}
|
260
|
+
}
|
261
|
+
... on FailureStatus {
|
262
|
+
block {
|
263
|
+
id
|
264
|
+
}
|
265
|
+
time
|
266
|
+
reason
|
267
|
+
}
|
268
|
+
... on SqueezedOutStatus {
|
269
|
+
reason
|
270
|
+
}
|
271
|
+
}
|
272
|
+
`;
|
249
273
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
250
274
|
fragment receiptFragment on Receipt {
|
251
|
-
|
252
|
-
id
|
253
|
-
}
|
275
|
+
id
|
254
276
|
pc
|
255
277
|
is
|
256
|
-
to
|
257
|
-
id
|
258
|
-
}
|
278
|
+
to
|
259
279
|
toAddress
|
260
280
|
amount
|
261
281
|
assetId
|
@@ -293,10 +313,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
293
313
|
id
|
294
314
|
}
|
295
315
|
time
|
316
|
+
receipts {
|
317
|
+
...receiptFragment
|
318
|
+
}
|
296
319
|
programState {
|
297
320
|
returnType
|
298
321
|
data
|
299
322
|
}
|
323
|
+
receipts {
|
324
|
+
...receiptFragment
|
325
|
+
}
|
300
326
|
}
|
301
327
|
... on FailureStatus {
|
302
328
|
block {
|
@@ -304,26 +330,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
304
330
|
}
|
305
331
|
time
|
306
332
|
reason
|
333
|
+
receipts {
|
334
|
+
...receiptFragment
|
335
|
+
}
|
307
336
|
}
|
308
337
|
... on SqueezedOutStatus {
|
309
338
|
reason
|
310
339
|
}
|
311
340
|
}
|
312
|
-
`;
|
341
|
+
${ReceiptFragmentFragmentDoc}`;
|
313
342
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
314
343
|
fragment transactionFragment on Transaction {
|
315
344
|
id
|
316
345
|
rawPayload
|
317
|
-
gasPrice
|
318
|
-
receipts {
|
319
|
-
...receiptFragment
|
320
|
-
}
|
321
346
|
status {
|
322
347
|
...transactionStatusFragment
|
323
348
|
}
|
324
349
|
}
|
325
|
-
${
|
326
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
350
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
327
351
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
328
352
|
fragment inputEstimatePredicatesFragment on Input {
|
329
353
|
... on InputCoin {
|
@@ -341,6 +365,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
341
365
|
}
|
342
366
|
}
|
343
367
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
368
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
369
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
370
|
+
reason
|
371
|
+
programState {
|
372
|
+
returnType
|
373
|
+
data
|
374
|
+
}
|
375
|
+
}
|
376
|
+
`;
|
377
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
378
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
379
|
+
programState {
|
380
|
+
returnType
|
381
|
+
data
|
382
|
+
}
|
383
|
+
}
|
384
|
+
`;
|
385
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
386
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
387
|
+
... on DryRunFailureStatus {
|
388
|
+
...dryRunFailureStatusFragment
|
389
|
+
}
|
390
|
+
... on DryRunSuccessStatus {
|
391
|
+
...dryRunSuccessStatusFragment
|
392
|
+
}
|
393
|
+
}
|
394
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
395
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
396
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
397
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
398
|
+
id
|
399
|
+
status {
|
400
|
+
...dryRunTransactionStatusFragment
|
401
|
+
}
|
402
|
+
receipts {
|
403
|
+
...receiptFragment
|
404
|
+
}
|
405
|
+
}
|
406
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
407
|
+
${ReceiptFragmentFragmentDoc}`;
|
344
408
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
345
409
|
fragment coinFragment on Coin {
|
346
410
|
__typename
|
@@ -348,7 +412,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
348
412
|
owner
|
349
413
|
amount
|
350
414
|
assetId
|
351
|
-
maturity
|
352
415
|
blockCreated
|
353
416
|
txCreatedIdx
|
354
417
|
}
|
@@ -387,26 +450,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
387
450
|
messageBlockHeader {
|
388
451
|
id
|
389
452
|
daHeight
|
453
|
+
consensusParametersVersion
|
454
|
+
stateTransitionBytecodeVersion
|
390
455
|
transactionsCount
|
456
|
+
messageReceiptCount
|
391
457
|
transactionsRoot
|
458
|
+
messageOutboxRoot
|
459
|
+
eventInboxRoot
|
392
460
|
height
|
393
461
|
prevRoot
|
394
462
|
time
|
395
463
|
applicationHash
|
396
|
-
messageReceiptRoot
|
397
|
-
messageReceiptCount
|
398
464
|
}
|
399
465
|
commitBlockHeader {
|
400
466
|
id
|
401
467
|
daHeight
|
468
|
+
consensusParametersVersion
|
469
|
+
stateTransitionBytecodeVersion
|
402
470
|
transactionsCount
|
471
|
+
messageReceiptCount
|
403
472
|
transactionsRoot
|
473
|
+
messageOutboxRoot
|
474
|
+
eventInboxRoot
|
404
475
|
height
|
405
476
|
prevRoot
|
406
477
|
time
|
407
478
|
applicationHash
|
408
|
-
messageReceiptRoot
|
409
|
-
messageReceiptCount
|
410
479
|
}
|
411
480
|
sender
|
412
481
|
recipient
|
@@ -425,8 +494,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
425
494
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
426
495
|
fragment blockFragment on Block {
|
427
496
|
id
|
497
|
+
height
|
428
498
|
header {
|
429
|
-
height
|
430
499
|
time
|
431
500
|
}
|
432
501
|
transactions {
|
@@ -484,6 +553,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
484
553
|
`;
|
485
554
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
486
555
|
fragment GasCostsFragment on GasCosts {
|
556
|
+
version {
|
557
|
+
... on Version {
|
558
|
+
value
|
559
|
+
}
|
560
|
+
}
|
487
561
|
add
|
488
562
|
addi
|
489
563
|
aloc
|
@@ -496,7 +570,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
496
570
|
cb
|
497
571
|
cfei
|
498
572
|
cfsi
|
499
|
-
croo
|
500
573
|
div
|
501
574
|
divi
|
502
575
|
ecr1
|
@@ -579,6 +652,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
579
652
|
ccp {
|
580
653
|
...DependentCostFragment
|
581
654
|
}
|
655
|
+
croo {
|
656
|
+
...DependentCostFragment
|
657
|
+
}
|
582
658
|
csiz {
|
583
659
|
...DependentCostFragment
|
584
660
|
}
|
@@ -638,6 +714,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
638
714
|
${DependentCostFragmentFragmentDoc}`;
|
639
715
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
640
716
|
fragment consensusParametersFragment on ConsensusParameters {
|
717
|
+
version {
|
718
|
+
... on Version {
|
719
|
+
value
|
720
|
+
}
|
721
|
+
}
|
641
722
|
txParams {
|
642
723
|
...TxParametersFragment
|
643
724
|
}
|
@@ -697,18 +778,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
697
778
|
fragment nodeInfoFragment on NodeInfo {
|
698
779
|
utxoValidation
|
699
780
|
vmBacktrace
|
700
|
-
minGasPrice
|
701
781
|
maxTx
|
702
782
|
maxDepth
|
703
783
|
nodeVersion
|
704
|
-
peers {
|
705
|
-
id
|
706
|
-
addresses
|
707
|
-
clientVersion
|
708
|
-
blockHeight
|
709
|
-
lastHeartbeatMs
|
710
|
-
appScore
|
711
|
-
}
|
712
784
|
}
|
713
785
|
`;
|
714
786
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -743,13 +815,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
743
815
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
744
816
|
transaction(id: $transactionId) {
|
745
817
|
...transactionFragment
|
746
|
-
receipts {
|
747
|
-
...receiptFragment
|
748
|
-
}
|
749
818
|
}
|
750
819
|
}
|
751
|
-
${TransactionFragmentFragmentDoc}
|
752
|
-
${ReceiptFragmentFragmentDoc}`;
|
820
|
+
${TransactionFragmentFragmentDoc}`;
|
753
821
|
var GetTransactionsDocument = import_graphql_tag.default`
|
754
822
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
755
823
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -877,6 +945,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
877
945
|
}
|
878
946
|
}
|
879
947
|
${BalanceFragmentFragmentDoc}`;
|
948
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
949
|
+
query getLatestGasPrice {
|
950
|
+
latestGasPrice {
|
951
|
+
gasPrice
|
952
|
+
}
|
953
|
+
}
|
954
|
+
`;
|
955
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
956
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
957
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
958
|
+
gasPrice
|
959
|
+
}
|
960
|
+
}
|
961
|
+
`;
|
880
962
|
var GetBalancesDocument = import_graphql_tag.default`
|
881
963
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
882
964
|
balances(
|
@@ -931,12 +1013,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
931
1013
|
}
|
932
1014
|
`;
|
933
1015
|
var DryRunDocument = import_graphql_tag.default`
|
934
|
-
mutation dryRun($
|
935
|
-
dryRun(
|
936
|
-
...
|
1016
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
1017
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
1018
|
+
...dryRunTransactionExecutionStatusFragment
|
937
1019
|
}
|
938
1020
|
}
|
939
|
-
${
|
1021
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
940
1022
|
var SubmitDocument = import_graphql_tag.default`
|
941
1023
|
mutation submit($encodedTransaction: HexString!) {
|
942
1024
|
submit(tx: $encodedTransaction) {
|
@@ -955,17 +1037,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
|
|
955
1037
|
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
956
1038
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
957
1039
|
submitAndAwait(tx: $encodedTransaction) {
|
958
|
-
...
|
1040
|
+
...transactionStatusSubscriptionFragment
|
959
1041
|
}
|
960
1042
|
}
|
961
|
-
${
|
1043
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
962
1044
|
var StatusChangeDocument = import_graphql_tag.default`
|
963
1045
|
subscription statusChange($transactionId: TransactionId!) {
|
964
1046
|
statusChange(id: $transactionId) {
|
965
|
-
...
|
1047
|
+
...transactionStatusSubscriptionFragment
|
966
1048
|
}
|
967
1049
|
}
|
968
|
-
${
|
1050
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
969
1051
|
function getSdk(requester) {
|
970
1052
|
return {
|
971
1053
|
getVersion(variables, options) {
|
@@ -1019,6 +1101,12 @@ function getSdk(requester) {
|
|
1019
1101
|
getBalance(variables, options) {
|
1020
1102
|
return requester(GetBalanceDocument, variables, options);
|
1021
1103
|
},
|
1104
|
+
getLatestGasPrice(variables, options) {
|
1105
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
1106
|
+
},
|
1107
|
+
estimateGasPrice(variables, options) {
|
1108
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
1109
|
+
},
|
1022
1110
|
getBalances(variables, options) {
|
1023
1111
|
return requester(GetBalancesDocument, variables, options);
|
1024
1112
|
},
|
@@ -1212,10 +1300,9 @@ var inputify = (value) => {
|
|
1212
1300
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1213
1301
|
},
|
1214
1302
|
witnessIndex: value.witnessIndex,
|
1215
|
-
maturity: value.maturity ?? 0,
|
1216
1303
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1217
|
-
predicateLength: predicate.length,
|
1218
|
-
predicateDataLength: predicateData.length,
|
1304
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1305
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1219
1306
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1220
1307
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1221
1308
|
};
|
@@ -1246,8 +1333,8 @@ var inputify = (value) => {
|
|
1246
1333
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1247
1334
|
witnessIndex: value.witnessIndex,
|
1248
1335
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1249
|
-
predicateLength: predicate.length,
|
1250
|
-
predicateDataLength: predicateData.length,
|
1336
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1337
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1251
1338
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1252
1339
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1253
1340
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1326,7 +1413,7 @@ var import_address = require("@fuel-ts/address");
|
|
1326
1413
|
var import_configs7 = require("@fuel-ts/address/configs");
|
1327
1414
|
var import_crypto = require("@fuel-ts/crypto");
|
1328
1415
|
var import_math7 = require("@fuel-ts/math");
|
1329
|
-
var
|
1416
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1330
1417
|
var import_utils9 = require("@fuel-ts/utils");
|
1331
1418
|
|
1332
1419
|
// src/providers/resource.ts
|
@@ -1366,8 +1453,8 @@ function assembleReceiptByType(receipt) {
|
|
1366
1453
|
case "CALL" /* Call */: {
|
1367
1454
|
const callReceipt = {
|
1368
1455
|
type: import_transactions3.ReceiptType.Call,
|
1369
|
-
from: hexOrZero(receipt.
|
1370
|
-
to: hexOrZero(receipt?.to
|
1456
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1457
|
+
to: hexOrZero(receipt?.to),
|
1371
1458
|
amount: (0, import_math4.bn)(receipt.amount),
|
1372
1459
|
assetId: hexOrZero(receipt.assetId),
|
1373
1460
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1381,7 +1468,7 @@ function assembleReceiptByType(receipt) {
|
|
1381
1468
|
case "RETURN" /* Return */: {
|
1382
1469
|
const returnReceipt = {
|
1383
1470
|
type: import_transactions3.ReceiptType.Return,
|
1384
|
-
id: hexOrZero(receipt.
|
1471
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1385
1472
|
val: (0, import_math4.bn)(receipt.val),
|
1386
1473
|
pc: (0, import_math4.bn)(receipt.pc),
|
1387
1474
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1391,7 +1478,7 @@ function assembleReceiptByType(receipt) {
|
|
1391
1478
|
case "RETURN_DATA" /* ReturnData */: {
|
1392
1479
|
const returnDataReceipt = {
|
1393
1480
|
type: import_transactions3.ReceiptType.ReturnData,
|
1394
|
-
id: hexOrZero(receipt.
|
1481
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1395
1482
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1396
1483
|
len: (0, import_math4.bn)(receipt.len),
|
1397
1484
|
digest: hexOrZero(receipt.digest),
|
@@ -1403,7 +1490,7 @@ function assembleReceiptByType(receipt) {
|
|
1403
1490
|
case "PANIC" /* Panic */: {
|
1404
1491
|
const panicReceipt = {
|
1405
1492
|
type: import_transactions3.ReceiptType.Panic,
|
1406
|
-
id: hexOrZero(receipt.
|
1493
|
+
id: hexOrZero(receipt.id),
|
1407
1494
|
reason: (0, import_math4.bn)(receipt.reason),
|
1408
1495
|
pc: (0, import_math4.bn)(receipt.pc),
|
1409
1496
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1414,7 +1501,7 @@ function assembleReceiptByType(receipt) {
|
|
1414
1501
|
case "REVERT" /* Revert */: {
|
1415
1502
|
const revertReceipt = {
|
1416
1503
|
type: import_transactions3.ReceiptType.Revert,
|
1417
|
-
id: hexOrZero(receipt.
|
1504
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1418
1505
|
val: (0, import_math4.bn)(receipt.ra),
|
1419
1506
|
pc: (0, import_math4.bn)(receipt.pc),
|
1420
1507
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1424,7 +1511,7 @@ function assembleReceiptByType(receipt) {
|
|
1424
1511
|
case "LOG" /* Log */: {
|
1425
1512
|
const logReceipt = {
|
1426
1513
|
type: import_transactions3.ReceiptType.Log,
|
1427
|
-
id: hexOrZero(receipt.
|
1514
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1428
1515
|
val0: (0, import_math4.bn)(receipt.ra),
|
1429
1516
|
val1: (0, import_math4.bn)(receipt.rb),
|
1430
1517
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1437,7 +1524,7 @@ function assembleReceiptByType(receipt) {
|
|
1437
1524
|
case "LOG_DATA" /* LogData */: {
|
1438
1525
|
const logDataReceipt = {
|
1439
1526
|
type: import_transactions3.ReceiptType.LogData,
|
1440
|
-
id: hexOrZero(receipt.
|
1527
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1441
1528
|
val0: (0, import_math4.bn)(receipt.ra),
|
1442
1529
|
val1: (0, import_math4.bn)(receipt.rb),
|
1443
1530
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1451,8 +1538,8 @@ function assembleReceiptByType(receipt) {
|
|
1451
1538
|
case "TRANSFER" /* Transfer */: {
|
1452
1539
|
const transferReceipt = {
|
1453
1540
|
type: import_transactions3.ReceiptType.Transfer,
|
1454
|
-
from: hexOrZero(receipt.
|
1455
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1541
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1542
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1456
1543
|
amount: (0, import_math4.bn)(receipt.amount),
|
1457
1544
|
assetId: hexOrZero(receipt.assetId),
|
1458
1545
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1463,8 +1550,8 @@ function assembleReceiptByType(receipt) {
|
|
1463
1550
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1464
1551
|
const transferOutReceipt = {
|
1465
1552
|
type: import_transactions3.ReceiptType.TransferOut,
|
1466
|
-
from: hexOrZero(receipt.
|
1467
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1553
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1554
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1468
1555
|
amount: (0, import_math4.bn)(receipt.amount),
|
1469
1556
|
assetId: hexOrZero(receipt.assetId),
|
1470
1557
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1507,7 +1594,7 @@ function assembleReceiptByType(receipt) {
|
|
1507
1594
|
return receiptMessageOut;
|
1508
1595
|
}
|
1509
1596
|
case "MINT" /* Mint */: {
|
1510
|
-
const contractId = hexOrZero(receipt.
|
1597
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1511
1598
|
const subId = hexOrZero(receipt.subId);
|
1512
1599
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1513
1600
|
const mintReceipt = {
|
@@ -1522,7 +1609,7 @@ function assembleReceiptByType(receipt) {
|
|
1522
1609
|
return mintReceipt;
|
1523
1610
|
}
|
1524
1611
|
case "BURN" /* Burn */: {
|
1525
|
-
const contractId = hexOrZero(receipt.
|
1612
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1526
1613
|
const subId = hexOrZero(receipt.subId);
|
1527
1614
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1528
1615
|
const burnReceipt = {
|
@@ -1607,7 +1694,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1607
1694
|
var import_math5 = require("@fuel-ts/math");
|
1608
1695
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1609
1696
|
var import_utils6 = require("@fuel-ts/utils");
|
1610
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1611
1697
|
var getGasUsedFromReceipts = (receipts) => {
|
1612
1698
|
const scriptResult = receipts.filter(
|
1613
1699
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1628,18 +1714,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1628
1714
|
}
|
1629
1715
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1630
1716
|
const witnessCache = [];
|
1631
|
-
const
|
1717
|
+
const chargeableInputs = inputs.filter((input) => {
|
1718
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1719
|
+
if (isCoinOrMessage) {
|
1720
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1721
|
+
return true;
|
1722
|
+
}
|
1723
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1724
|
+
witnessCache.push(input.witnessIndex);
|
1725
|
+
return true;
|
1726
|
+
}
|
1727
|
+
}
|
1728
|
+
return false;
|
1729
|
+
});
|
1730
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1731
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1632
1732
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1633
1733
|
return total.add(
|
1634
|
-
|
1734
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1635
1735
|
);
|
1636
1736
|
}
|
1637
|
-
|
1638
|
-
|
1639
|
-
return total.add(gasCosts.ecr1);
|
1640
|
-
}
|
1641
|
-
return total;
|
1642
|
-
}, (0, import_math5.bn)());
|
1737
|
+
return total.add(gasCosts.ecr1);
|
1738
|
+
}, (0, import_math5.bn)(0));
|
1643
1739
|
return totalGas;
|
1644
1740
|
}
|
1645
1741
|
function getMinGas(params) {
|
@@ -1651,12 +1747,20 @@ function getMinGas(params) {
|
|
1651
1747
|
return minGas;
|
1652
1748
|
}
|
1653
1749
|
function getMaxGas(params) {
|
1654
|
-
const {
|
1750
|
+
const {
|
1751
|
+
gasPerByte,
|
1752
|
+
witnessesLength,
|
1753
|
+
witnessLimit,
|
1754
|
+
minGas,
|
1755
|
+
gasLimit = (0, import_math5.bn)(0),
|
1756
|
+
maxGasPerTx
|
1757
|
+
} = params;
|
1655
1758
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1656
1759
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1657
1760
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1658
1761
|
}
|
1659
|
-
|
1762
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1763
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1660
1764
|
}
|
1661
1765
|
function calculateMetadataGasForTxCreate({
|
1662
1766
|
gasCosts,
|
@@ -1678,6 +1782,10 @@ function calculateMetadataGasForTxScript({
|
|
1678
1782
|
}) {
|
1679
1783
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1680
1784
|
}
|
1785
|
+
var calculateGasFee = (params) => {
|
1786
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1787
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1788
|
+
};
|
1681
1789
|
|
1682
1790
|
// src/providers/utils/json.ts
|
1683
1791
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1813,28 +1921,6 @@ var NoWitnessByOwnerError = class extends Error {
|
|
1813
1921
|
name = "NoWitnessByOwnerError";
|
1814
1922
|
};
|
1815
1923
|
|
1816
|
-
// src/providers/transaction-request/helpers.ts
|
1817
|
-
var import_transactions6 = require("@fuel-ts/transactions");
|
1818
|
-
var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
|
1819
|
-
var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
|
1820
|
-
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1821
|
-
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
1822
|
-
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
1823
|
-
var cacheResources = (resources) => resources.reduce(
|
1824
|
-
(cache2, resource) => {
|
1825
|
-
if (isCoin(resource)) {
|
1826
|
-
cache2.utxos.push(resource.id);
|
1827
|
-
} else {
|
1828
|
-
cache2.messages.push(resource.nonce);
|
1829
|
-
}
|
1830
|
-
return cache2;
|
1831
|
-
},
|
1832
|
-
{
|
1833
|
-
utxos: [],
|
1834
|
-
messages: []
|
1835
|
-
}
|
1836
|
-
);
|
1837
|
-
|
1838
1924
|
// src/providers/transaction-request/witness.ts
|
1839
1925
|
var import_utils8 = require("@fuel-ts/utils");
|
1840
1926
|
var witnessify = (value) => {
|
@@ -1848,7 +1934,7 @@ var witnessify = (value) => {
|
|
1848
1934
|
// src/providers/transaction-request/transaction-request.ts
|
1849
1935
|
var BaseTransactionRequest = class {
|
1850
1936
|
/** Gas price for transaction */
|
1851
|
-
|
1937
|
+
tip;
|
1852
1938
|
/** Block until which tx cannot be included */
|
1853
1939
|
maturity;
|
1854
1940
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1867,7 +1953,7 @@ var BaseTransactionRequest = class {
|
|
1867
1953
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1868
1954
|
*/
|
1869
1955
|
constructor({
|
1870
|
-
|
1956
|
+
tip,
|
1871
1957
|
maturity,
|
1872
1958
|
maxFee,
|
1873
1959
|
witnessLimit,
|
@@ -1875,7 +1961,7 @@ var BaseTransactionRequest = class {
|
|
1875
1961
|
outputs,
|
1876
1962
|
witnesses
|
1877
1963
|
} = {}) {
|
1878
|
-
this.
|
1964
|
+
this.tip = (0, import_math7.bn)(tip);
|
1879
1965
|
this.maturity = maturity ?? 0;
|
1880
1966
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1881
1967
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1886,21 +1972,21 @@ var BaseTransactionRequest = class {
|
|
1886
1972
|
static getPolicyMeta(req) {
|
1887
1973
|
let policyTypes = 0;
|
1888
1974
|
const policies = [];
|
1889
|
-
if (req.
|
1890
|
-
policyTypes +=
|
1891
|
-
policies.push({ data: req.
|
1975
|
+
if (req.tip) {
|
1976
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1977
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1892
1978
|
}
|
1893
1979
|
if (req.witnessLimit) {
|
1894
|
-
policyTypes +=
|
1895
|
-
policies.push({ data: req.witnessLimit, type:
|
1980
|
+
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
1981
|
+
policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
|
1896
1982
|
}
|
1897
1983
|
if (req.maturity > 0) {
|
1898
|
-
policyTypes +=
|
1899
|
-
policies.push({ data: req.maturity, type:
|
1984
|
+
policyTypes += import_transactions6.PolicyType.Maturity;
|
1985
|
+
policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
|
1900
1986
|
}
|
1901
1987
|
if (req.maxFee) {
|
1902
|
-
policyTypes +=
|
1903
|
-
policies.push({ data: req.maxFee, type:
|
1988
|
+
policyTypes += import_transactions6.PolicyType.MaxFee;
|
1989
|
+
policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
|
1904
1990
|
}
|
1905
1991
|
return {
|
1906
1992
|
policyTypes,
|
@@ -1934,7 +2020,7 @@ var BaseTransactionRequest = class {
|
|
1934
2020
|
* @returns The transaction bytes.
|
1935
2021
|
*/
|
1936
2022
|
toTransactionBytes() {
|
1937
|
-
return new
|
2023
|
+
return new import_transactions6.TransactionCoder().encode(this.toTransaction());
|
1938
2024
|
}
|
1939
2025
|
/**
|
1940
2026
|
* @hidden
|
@@ -2025,7 +2111,7 @@ var BaseTransactionRequest = class {
|
|
2025
2111
|
*/
|
2026
2112
|
getCoinInputs() {
|
2027
2113
|
return this.inputs.filter(
|
2028
|
-
(input) => input.type ===
|
2114
|
+
(input) => input.type === import_transactions6.InputType.Coin
|
2029
2115
|
);
|
2030
2116
|
}
|
2031
2117
|
/**
|
@@ -2035,7 +2121,7 @@ var BaseTransactionRequest = class {
|
|
2035
2121
|
*/
|
2036
2122
|
getCoinOutputs() {
|
2037
2123
|
return this.outputs.filter(
|
2038
|
-
(output) => output.type ===
|
2124
|
+
(output) => output.type === import_transactions6.OutputType.Coin
|
2039
2125
|
);
|
2040
2126
|
}
|
2041
2127
|
/**
|
@@ -2045,7 +2131,7 @@ var BaseTransactionRequest = class {
|
|
2045
2131
|
*/
|
2046
2132
|
getChangeOutputs() {
|
2047
2133
|
return this.outputs.filter(
|
2048
|
-
(output) => output.type ===
|
2134
|
+
(output) => output.type === import_transactions6.OutputType.Change
|
2049
2135
|
);
|
2050
2136
|
}
|
2051
2137
|
/**
|
@@ -2057,9 +2143,9 @@ var BaseTransactionRequest = class {
|
|
2057
2143
|
const ownerAddress = (0, import_address.addressify)(owner);
|
2058
2144
|
const found = this.inputs.find((input) => {
|
2059
2145
|
switch (input.type) {
|
2060
|
-
case
|
2146
|
+
case import_transactions6.InputType.Coin:
|
2061
2147
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
2062
|
-
case
|
2148
|
+
case import_transactions6.InputType.Message:
|
2063
2149
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
2064
2150
|
default:
|
2065
2151
|
return false;
|
@@ -2076,9 +2162,9 @@ var BaseTransactionRequest = class {
|
|
2076
2162
|
* @param predicateData - Predicate data bytes.
|
2077
2163
|
*/
|
2078
2164
|
addCoinInput(coin) {
|
2079
|
-
const { assetId, owner, amount
|
2165
|
+
const { assetId, owner, amount } = coin;
|
2080
2166
|
let witnessIndex;
|
2081
|
-
if (predicate) {
|
2167
|
+
if (coin.predicate) {
|
2082
2168
|
witnessIndex = 0;
|
2083
2169
|
} else {
|
2084
2170
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2087,14 +2173,13 @@ var BaseTransactionRequest = class {
|
|
2087
2173
|
}
|
2088
2174
|
}
|
2089
2175
|
const input = {
|
2090
|
-
|
2091
|
-
type:
|
2176
|
+
...coin,
|
2177
|
+
type: import_transactions6.InputType.Coin,
|
2092
2178
|
owner: owner.toB256(),
|
2093
2179
|
amount,
|
2094
2180
|
assetId,
|
2095
2181
|
txPointer: "0x00000000000000000000000000000000",
|
2096
|
-
witnessIndex
|
2097
|
-
predicate
|
2182
|
+
witnessIndex
|
2098
2183
|
};
|
2099
2184
|
this.pushInput(input);
|
2100
2185
|
this.addChangeOutput(owner, assetId);
|
@@ -2108,10 +2193,10 @@ var BaseTransactionRequest = class {
|
|
2108
2193
|
* @param predicateData - Predicate data bytes.
|
2109
2194
|
*/
|
2110
2195
|
addMessageInput(message) {
|
2111
|
-
const { recipient, sender, amount
|
2196
|
+
const { recipient, sender, amount } = message;
|
2112
2197
|
const assetId = import_configs7.BaseAssetId;
|
2113
2198
|
let witnessIndex;
|
2114
|
-
if (predicate) {
|
2199
|
+
if (message.predicate) {
|
2115
2200
|
witnessIndex = 0;
|
2116
2201
|
} else {
|
2117
2202
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2120,13 +2205,12 @@ var BaseTransactionRequest = class {
|
|
2120
2205
|
}
|
2121
2206
|
}
|
2122
2207
|
const input = {
|
2123
|
-
|
2124
|
-
type:
|
2208
|
+
...message,
|
2209
|
+
type: import_transactions6.InputType.Message,
|
2125
2210
|
sender: sender.toB256(),
|
2126
2211
|
recipient: recipient.toB256(),
|
2127
2212
|
amount,
|
2128
|
-
witnessIndex
|
2129
|
-
predicate
|
2213
|
+
witnessIndex
|
2130
2214
|
};
|
2131
2215
|
this.pushInput(input);
|
2132
2216
|
this.addChangeOutput(recipient, assetId);
|
@@ -2166,7 +2250,7 @@ var BaseTransactionRequest = class {
|
|
2166
2250
|
*/
|
2167
2251
|
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
2168
2252
|
this.pushOutput({
|
2169
|
-
type:
|
2253
|
+
type: import_transactions6.OutputType.Coin,
|
2170
2254
|
to: (0, import_address.addressify)(to).toB256(),
|
2171
2255
|
amount,
|
2172
2256
|
assetId
|
@@ -2182,7 +2266,7 @@ var BaseTransactionRequest = class {
|
|
2182
2266
|
addCoinOutputs(to, quantities) {
|
2183
2267
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
2184
2268
|
this.pushOutput({
|
2185
|
-
type:
|
2269
|
+
type: import_transactions6.OutputType.Coin,
|
2186
2270
|
to: (0, import_address.addressify)(to).toB256(),
|
2187
2271
|
amount: quantity.amount,
|
2188
2272
|
assetId: quantity.assetId
|
@@ -2202,7 +2286,7 @@ var BaseTransactionRequest = class {
|
|
2202
2286
|
);
|
2203
2287
|
if (!changeOutput) {
|
2204
2288
|
this.pushOutput({
|
2205
|
-
type:
|
2289
|
+
type: import_transactions6.OutputType.Change,
|
2206
2290
|
to: (0, import_address.addressify)(to).toB256(),
|
2207
2291
|
assetId
|
2208
2292
|
});
|
@@ -2236,7 +2320,7 @@ var BaseTransactionRequest = class {
|
|
2236
2320
|
}
|
2237
2321
|
calculateMaxGas(chainInfo, minGas) {
|
2238
2322
|
const { consensusParameters } = chainInfo;
|
2239
|
-
const { gasPerByte } = consensusParameters;
|
2323
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2240
2324
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2241
2325
|
(acc, wit) => acc + wit.dataLength,
|
2242
2326
|
0
|
@@ -2245,7 +2329,8 @@ var BaseTransactionRequest = class {
|
|
2245
2329
|
gasPerByte,
|
2246
2330
|
minGas,
|
2247
2331
|
witnessesLength,
|
2248
|
-
witnessLimit: this.witnessLimit
|
2332
|
+
witnessLimit: this.witnessLimit,
|
2333
|
+
maxGasPerTx
|
2249
2334
|
});
|
2250
2335
|
}
|
2251
2336
|
/**
|
@@ -2263,17 +2348,20 @@ var BaseTransactionRequest = class {
|
|
2263
2348
|
});
|
2264
2349
|
const updateAssetInput = (assetId, quantity) => {
|
2265
2350
|
const assetInput = findAssetInput(assetId);
|
2351
|
+
let usedQuantity = quantity;
|
2352
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2353
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2354
|
+
}
|
2266
2355
|
if (assetInput && "assetId" in assetInput) {
|
2267
2356
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2268
|
-
assetInput.amount =
|
2357
|
+
assetInput.amount = usedQuantity;
|
2269
2358
|
} else {
|
2270
2359
|
this.addResources([
|
2271
2360
|
{
|
2272
2361
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2273
|
-
amount:
|
2362
|
+
amount: usedQuantity,
|
2274
2363
|
assetId,
|
2275
2364
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2276
|
-
maturity: 0,
|
2277
2365
|
blockCreated: (0, import_math7.bn)(1),
|
2278
2366
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2279
2367
|
}
|
@@ -2305,20 +2393,16 @@ var BaseTransactionRequest = class {
|
|
2305
2393
|
toJSON() {
|
2306
2394
|
return normalizeJSON(this);
|
2307
2395
|
}
|
2308
|
-
|
2309
|
-
this.witnesses.splice(index, 1);
|
2310
|
-
this.adjustWitnessIndexes(index);
|
2311
|
-
}
|
2312
|
-
updatePredicateInputs(inputs) {
|
2396
|
+
updatePredicateGasUsed(inputs) {
|
2313
2397
|
this.inputs.forEach((i) => {
|
2314
2398
|
let correspondingInput;
|
2315
2399
|
switch (i.type) {
|
2316
|
-
case
|
2317
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2400
|
+
case import_transactions6.InputType.Coin:
|
2401
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions6.InputType.Coin && x.owner === i.owner);
|
2318
2402
|
break;
|
2319
|
-
case
|
2403
|
+
case import_transactions6.InputType.Message:
|
2320
2404
|
correspondingInput = inputs.find(
|
2321
|
-
(x) => x.type ===
|
2405
|
+
(x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
|
2322
2406
|
);
|
2323
2407
|
break;
|
2324
2408
|
default:
|
@@ -2331,10 +2415,12 @@ var BaseTransactionRequest = class {
|
|
2331
2415
|
}
|
2332
2416
|
});
|
2333
2417
|
}
|
2334
|
-
|
2335
|
-
this.inputs.
|
2336
|
-
if (input.
|
2337
|
-
input.
|
2418
|
+
shiftPredicateData() {
|
2419
|
+
this.inputs.forEach((input) => {
|
2420
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2421
|
+
input.predicateData = input.paddPredicateData(
|
2422
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2423
|
+
);
|
2338
2424
|
}
|
2339
2425
|
});
|
2340
2426
|
}
|
@@ -2343,25 +2429,25 @@ var BaseTransactionRequest = class {
|
|
2343
2429
|
// src/providers/transaction-request/create-transaction-request.ts
|
2344
2430
|
var import_configs9 = require("@fuel-ts/address/configs");
|
2345
2431
|
var import_math9 = require("@fuel-ts/math");
|
2346
|
-
var
|
2432
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2347
2433
|
var import_utils13 = require("@fuel-ts/utils");
|
2348
2434
|
|
2349
2435
|
// src/providers/transaction-request/hash-transaction.ts
|
2350
2436
|
var import_configs8 = require("@fuel-ts/address/configs");
|
2351
2437
|
var import_hasher = require("@fuel-ts/hasher");
|
2352
2438
|
var import_math8 = require("@fuel-ts/math");
|
2353
|
-
var
|
2439
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2354
2440
|
var import_utils11 = require("@fuel-ts/utils");
|
2355
2441
|
var import_ramda2 = require("ramda");
|
2356
2442
|
function hashTransaction(transactionRequest, chainId) {
|
2357
2443
|
const transaction = transactionRequest.toTransaction();
|
2358
|
-
if (transaction.type ===
|
2444
|
+
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2359
2445
|
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2360
2446
|
}
|
2361
2447
|
transaction.inputs = transaction.inputs.map((input) => {
|
2362
2448
|
const inputClone = (0, import_ramda2.clone)(input);
|
2363
2449
|
switch (inputClone.type) {
|
2364
|
-
case
|
2450
|
+
case import_transactions7.InputType.Coin: {
|
2365
2451
|
inputClone.txPointer = {
|
2366
2452
|
blockHeight: 0,
|
2367
2453
|
txIndex: 0
|
@@ -2369,11 +2455,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2369
2455
|
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2370
2456
|
return inputClone;
|
2371
2457
|
}
|
2372
|
-
case
|
2458
|
+
case import_transactions7.InputType.Message: {
|
2373
2459
|
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2374
2460
|
return inputClone;
|
2375
2461
|
}
|
2376
|
-
case
|
2462
|
+
case import_transactions7.InputType.Contract: {
|
2377
2463
|
inputClone.txPointer = {
|
2378
2464
|
blockHeight: 0,
|
2379
2465
|
txIndex: 0
|
@@ -2391,16 +2477,16 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2391
2477
|
transaction.outputs = transaction.outputs.map((output) => {
|
2392
2478
|
const outputClone = (0, import_ramda2.clone)(output);
|
2393
2479
|
switch (outputClone.type) {
|
2394
|
-
case
|
2480
|
+
case import_transactions7.OutputType.Contract: {
|
2395
2481
|
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2396
2482
|
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2397
2483
|
return outputClone;
|
2398
2484
|
}
|
2399
|
-
case
|
2485
|
+
case import_transactions7.OutputType.Change: {
|
2400
2486
|
outputClone.amount = (0, import_math8.bn)(0);
|
2401
2487
|
return outputClone;
|
2402
2488
|
}
|
2403
|
-
case
|
2489
|
+
case import_transactions7.OutputType.Variable: {
|
2404
2490
|
outputClone.to = import_configs8.ZeroBytes32;
|
2405
2491
|
outputClone.amount = (0, import_math8.bn)(0);
|
2406
2492
|
outputClone.assetId = import_configs8.ZeroBytes32;
|
@@ -2413,7 +2499,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2413
2499
|
transaction.witnessesCount = 0;
|
2414
2500
|
transaction.witnesses = [];
|
2415
2501
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2416
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2502
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions7.TransactionCoder().encode(transaction)]);
|
2417
2503
|
return (0, import_hasher.sha256)(concatenatedData);
|
2418
2504
|
}
|
2419
2505
|
|
@@ -2449,7 +2535,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2449
2535
|
return new this(obj);
|
2450
2536
|
}
|
2451
2537
|
/** Type of the transaction */
|
2452
|
-
type =
|
2538
|
+
type = import_transactions8.TransactionType.Create;
|
2453
2539
|
/** Witness index of contract bytecode to create */
|
2454
2540
|
bytecodeWitnessIndex;
|
2455
2541
|
/** Salt */
|
@@ -2482,11 +2568,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2482
2568
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2483
2569
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2484
2570
|
return {
|
2485
|
-
type:
|
2571
|
+
type: import_transactions8.TransactionType.Create,
|
2486
2572
|
...baseTransaction,
|
2487
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2488
2573
|
bytecodeWitnessIndex,
|
2489
|
-
storageSlotsCount: storageSlots.length,
|
2574
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2490
2575
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2491
2576
|
storageSlots
|
2492
2577
|
};
|
@@ -2498,7 +2583,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2498
2583
|
*/
|
2499
2584
|
getContractCreatedOutputs() {
|
2500
2585
|
return this.outputs.filter(
|
2501
|
-
(output) => output.type ===
|
2586
|
+
(output) => output.type === import_transactions8.OutputType.ContractCreated
|
2502
2587
|
);
|
2503
2588
|
}
|
2504
2589
|
/**
|
@@ -2519,7 +2604,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2519
2604
|
*/
|
2520
2605
|
addContractCreatedOutput(contractId, stateRoot) {
|
2521
2606
|
this.pushOutput({
|
2522
|
-
type:
|
2607
|
+
type: import_transactions8.OutputType.ContractCreated,
|
2523
2608
|
contractId,
|
2524
2609
|
stateRoot
|
2525
2610
|
});
|
@@ -2539,7 +2624,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
2539
2624
|
var import_address2 = require("@fuel-ts/address");
|
2540
2625
|
var import_configs10 = require("@fuel-ts/address/configs");
|
2541
2626
|
var import_math10 = require("@fuel-ts/math");
|
2542
|
-
var
|
2627
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2543
2628
|
var import_utils15 = require("@fuel-ts/utils");
|
2544
2629
|
|
2545
2630
|
// src/providers/transaction-request/scripts.ts
|
@@ -2577,7 +2662,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2577
2662
|
return new this(obj);
|
2578
2663
|
}
|
2579
2664
|
/** Type of the transaction */
|
2580
|
-
type =
|
2665
|
+
type = import_transactions9.TransactionType.Script;
|
2581
2666
|
/** Gas limit for transaction */
|
2582
2667
|
gasLimit;
|
2583
2668
|
/** Script to execute */
|
@@ -2606,11 +2691,11 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2606
2691
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2607
2692
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2608
2693
|
return {
|
2609
|
-
type:
|
2694
|
+
type: import_transactions9.TransactionType.Script,
|
2610
2695
|
scriptGasLimit: this.gasLimit,
|
2611
2696
|
...super.getBaseTransaction(),
|
2612
|
-
scriptLength: script.length,
|
2613
|
-
scriptDataLength: scriptData.length,
|
2697
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2698
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2614
2699
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2615
2700
|
script: (0, import_utils15.hexlify)(script),
|
2616
2701
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2623,7 +2708,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2623
2708
|
*/
|
2624
2709
|
getContractInputs() {
|
2625
2710
|
return this.inputs.filter(
|
2626
|
-
(input) => input.type ===
|
2711
|
+
(input) => input.type === import_transactions9.InputType.Contract
|
2627
2712
|
);
|
2628
2713
|
}
|
2629
2714
|
/**
|
@@ -2633,7 +2718,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2633
2718
|
*/
|
2634
2719
|
getContractOutputs() {
|
2635
2720
|
return this.outputs.filter(
|
2636
|
-
(output) => output.type ===
|
2721
|
+
(output) => output.type === import_transactions9.OutputType.Contract
|
2637
2722
|
);
|
2638
2723
|
}
|
2639
2724
|
/**
|
@@ -2643,7 +2728,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2643
2728
|
*/
|
2644
2729
|
getVariableOutputs() {
|
2645
2730
|
return this.outputs.filter(
|
2646
|
-
(output) => output.type ===
|
2731
|
+
(output) => output.type === import_transactions9.OutputType.Variable
|
2647
2732
|
);
|
2648
2733
|
}
|
2649
2734
|
/**
|
@@ -2666,7 +2751,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2666
2751
|
let outputsNumber = numberOfVariables;
|
2667
2752
|
while (outputsNumber) {
|
2668
2753
|
this.pushOutput({
|
2669
|
-
type:
|
2754
|
+
type: import_transactions9.OutputType.Variable
|
2670
2755
|
});
|
2671
2756
|
outputsNumber -= 1;
|
2672
2757
|
}
|
@@ -2674,7 +2759,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2674
2759
|
}
|
2675
2760
|
calculateMaxGas(chainInfo, minGas) {
|
2676
2761
|
const { consensusParameters } = chainInfo;
|
2677
|
-
const { gasPerByte } = consensusParameters;
|
2762
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2678
2763
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2679
2764
|
(acc, wit) => acc + wit.dataLength,
|
2680
2765
|
0
|
@@ -2684,7 +2769,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2684
2769
|
minGas,
|
2685
2770
|
witnessesLength,
|
2686
2771
|
witnessLimit: this.witnessLimit,
|
2687
|
-
gasLimit: this.gasLimit
|
2772
|
+
gasLimit: this.gasLimit,
|
2773
|
+
maxGasPerTx
|
2688
2774
|
});
|
2689
2775
|
}
|
2690
2776
|
/**
|
@@ -2699,12 +2785,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2699
2785
|
return this;
|
2700
2786
|
}
|
2701
2787
|
const inputIndex = super.pushInput({
|
2702
|
-
type:
|
2788
|
+
type: import_transactions9.InputType.Contract,
|
2703
2789
|
contractId: contractAddress.toB256(),
|
2704
2790
|
txPointer: "0x00000000000000000000000000000000"
|
2705
2791
|
});
|
2706
2792
|
this.pushOutput({
|
2707
|
-
type:
|
2793
|
+
type: import_transactions9.OutputType.Contract,
|
2708
2794
|
inputIndex
|
2709
2795
|
});
|
2710
2796
|
return this;
|
@@ -2741,17 +2827,17 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2741
2827
|
|
2742
2828
|
// src/providers/transaction-request/utils.ts
|
2743
2829
|
var import_errors9 = require("@fuel-ts/errors");
|
2744
|
-
var
|
2830
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2745
2831
|
var transactionRequestify = (obj) => {
|
2746
2832
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2747
2833
|
return obj;
|
2748
2834
|
}
|
2749
2835
|
const { type } = obj;
|
2750
2836
|
switch (obj.type) {
|
2751
|
-
case
|
2837
|
+
case import_transactions10.TransactionType.Script: {
|
2752
2838
|
return ScriptTransactionRequest.from(obj);
|
2753
2839
|
}
|
2754
|
-
case
|
2840
|
+
case import_transactions10.TransactionType.Create: {
|
2755
2841
|
return CreateTransactionRequest.from(obj);
|
2756
2842
|
}
|
2757
2843
|
default: {
|
@@ -2759,42 +2845,59 @@ var transactionRequestify = (obj) => {
|
|
2759
2845
|
}
|
2760
2846
|
}
|
2761
2847
|
};
|
2848
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2849
|
+
(acc, input) => {
|
2850
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2851
|
+
acc.utxos.push(input.id);
|
2852
|
+
}
|
2853
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2854
|
+
acc.messages.push(input.nonce);
|
2855
|
+
}
|
2856
|
+
return acc;
|
2857
|
+
},
|
2858
|
+
{
|
2859
|
+
utxos: [],
|
2860
|
+
messages: []
|
2861
|
+
}
|
2862
|
+
);
|
2762
2863
|
|
2763
2864
|
// src/providers/transaction-response/transaction-response.ts
|
2764
2865
|
var import_errors13 = require("@fuel-ts/errors");
|
2765
|
-
var
|
2866
|
+
var import_math15 = require("@fuel-ts/math");
|
2766
2867
|
var import_transactions18 = require("@fuel-ts/transactions");
|
2767
|
-
var
|
2868
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2768
2869
|
|
2769
2870
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2770
|
-
var
|
2871
|
+
var import_math14 = require("@fuel-ts/math");
|
2872
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2873
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2771
2874
|
|
2772
2875
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2773
2876
|
var import_math11 = require("@fuel-ts/math");
|
2774
|
-
var
|
2877
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2775
2878
|
var import_utils16 = require("@fuel-ts/utils");
|
2776
2879
|
var calculateTransactionFee = (params) => {
|
2777
2880
|
const {
|
2778
|
-
|
2881
|
+
gasPrice,
|
2779
2882
|
rawPayload,
|
2780
|
-
|
2883
|
+
tip,
|
2884
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2781
2885
|
} = params;
|
2782
2886
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2783
2887
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
2784
2888
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2785
|
-
const [transaction] = new
|
2786
|
-
if (transaction.type ===
|
2889
|
+
const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
|
2890
|
+
if (transaction.type === import_transactions11.TransactionType.Mint) {
|
2787
2891
|
return {
|
2788
2892
|
fee: (0, import_math11.bn)(0),
|
2789
2893
|
minFee: (0, import_math11.bn)(0),
|
2790
|
-
maxFee: (0, import_math11.bn)(0)
|
2791
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2894
|
+
maxFee: (0, import_math11.bn)(0)
|
2792
2895
|
};
|
2793
2896
|
}
|
2794
2897
|
const { type, witnesses, inputs, policies } = transaction;
|
2795
2898
|
let metadataGas = (0, import_math11.bn)(0);
|
2796
2899
|
let gasLimit = (0, import_math11.bn)(0);
|
2797
|
-
if (type ===
|
2900
|
+
if (type === import_transactions11.TransactionType.Create) {
|
2798
2901
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2799
2902
|
const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2800
2903
|
metadataGas = calculateMetadataGasForTxCreate({
|
@@ -2820,25 +2923,32 @@ var calculateTransactionFee = (params) => {
|
|
2820
2923
|
metadataGas,
|
2821
2924
|
txBytesSize: transactionBytes.length
|
2822
2925
|
});
|
2823
|
-
const
|
2824
|
-
const witnessLimit = policies.find((policy) => policy.type === import_transactions12.PolicyType.WitnessLimit)?.data;
|
2926
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2825
2927
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2826
2928
|
const maxGas = getMaxGas({
|
2827
2929
|
gasPerByte,
|
2828
2930
|
minGas,
|
2829
2931
|
witnessesLength,
|
2830
2932
|
gasLimit,
|
2831
|
-
witnessLimit
|
2933
|
+
witnessLimit,
|
2934
|
+
maxGasPerTx
|
2935
|
+
});
|
2936
|
+
const minFee = calculateGasFee({
|
2937
|
+
gasPrice,
|
2938
|
+
gas: minGas,
|
2939
|
+
priceFactor: gasPriceFactor,
|
2940
|
+
tip
|
2941
|
+
});
|
2942
|
+
const maxFee = calculateGasFee({
|
2943
|
+
gasPrice,
|
2944
|
+
gas: maxGas,
|
2945
|
+
priceFactor: gasPriceFactor,
|
2946
|
+
tip
|
2832
2947
|
});
|
2833
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2834
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2835
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2836
|
-
const fee = minFee.add(feeFromGasUsed);
|
2837
2948
|
return {
|
2838
|
-
fee,
|
2839
2949
|
minFee,
|
2840
2950
|
maxFee,
|
2841
|
-
|
2951
|
+
fee: maxFee
|
2842
2952
|
};
|
2843
2953
|
};
|
2844
2954
|
|
@@ -2846,7 +2956,7 @@ var calculateTransactionFee = (params) => {
|
|
2846
2956
|
var import_configs11 = require("@fuel-ts/address/configs");
|
2847
2957
|
var import_errors11 = require("@fuel-ts/errors");
|
2848
2958
|
var import_math13 = require("@fuel-ts/math");
|
2849
|
-
var
|
2959
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
2850
2960
|
|
2851
2961
|
// src/providers/transaction-summary/call.ts
|
2852
2962
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
@@ -2894,7 +3004,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2894
3004
|
|
2895
3005
|
// src/providers/transaction-summary/input.ts
|
2896
3006
|
var import_errors10 = require("@fuel-ts/errors");
|
2897
|
-
var
|
3007
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2898
3008
|
function getInputsByTypes(inputs, types) {
|
2899
3009
|
return inputs.filter((i) => types.includes(i.type));
|
2900
3010
|
}
|
@@ -2902,16 +3012,16 @@ function getInputsByType(inputs, type) {
|
|
2902
3012
|
return inputs.filter((i) => i.type === type);
|
2903
3013
|
}
|
2904
3014
|
function getInputsCoin(inputs) {
|
2905
|
-
return getInputsByType(inputs,
|
3015
|
+
return getInputsByType(inputs, import_transactions12.InputType.Coin);
|
2906
3016
|
}
|
2907
3017
|
function getInputsMessage(inputs) {
|
2908
|
-
return getInputsByType(inputs,
|
3018
|
+
return getInputsByType(inputs, import_transactions12.InputType.Message);
|
2909
3019
|
}
|
2910
3020
|
function getInputsCoinAndMessage(inputs) {
|
2911
|
-
return getInputsByTypes(inputs, [
|
3021
|
+
return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
|
2912
3022
|
}
|
2913
3023
|
function getInputsContract(inputs) {
|
2914
|
-
return getInputsByType(inputs,
|
3024
|
+
return getInputsByType(inputs, import_transactions12.InputType.Contract);
|
2915
3025
|
}
|
2916
3026
|
function getInputFromAssetId(inputs, assetId) {
|
2917
3027
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2930,7 +3040,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2930
3040
|
if (!contractInput) {
|
2931
3041
|
return void 0;
|
2932
3042
|
}
|
2933
|
-
if (contractInput.type !==
|
3043
|
+
if (contractInput.type !== import_transactions12.InputType.Contract) {
|
2934
3044
|
throw new import_errors10.FuelError(
|
2935
3045
|
import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2936
3046
|
`Contract input should be of type 'contract'.`
|
@@ -2939,34 +3049,34 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2939
3049
|
return contractInput;
|
2940
3050
|
}
|
2941
3051
|
function getInputAccountAddress(input) {
|
2942
|
-
if (input.type ===
|
3052
|
+
if (input.type === import_transactions12.InputType.Coin) {
|
2943
3053
|
return input.owner.toString();
|
2944
3054
|
}
|
2945
|
-
if (input.type ===
|
3055
|
+
if (input.type === import_transactions12.InputType.Message) {
|
2946
3056
|
return input.recipient.toString();
|
2947
3057
|
}
|
2948
3058
|
return "";
|
2949
3059
|
}
|
2950
3060
|
|
2951
3061
|
// src/providers/transaction-summary/output.ts
|
2952
|
-
var
|
3062
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2953
3063
|
function getOutputsByType(outputs, type) {
|
2954
3064
|
return outputs.filter((o) => o.type === type);
|
2955
3065
|
}
|
2956
3066
|
function getOutputsContractCreated(outputs) {
|
2957
|
-
return getOutputsByType(outputs,
|
3067
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
|
2958
3068
|
}
|
2959
3069
|
function getOutputsCoin(outputs) {
|
2960
|
-
return getOutputsByType(outputs,
|
3070
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
|
2961
3071
|
}
|
2962
3072
|
function getOutputsChange(outputs) {
|
2963
|
-
return getOutputsByType(outputs,
|
3073
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Change);
|
2964
3074
|
}
|
2965
3075
|
function getOutputsContract(outputs) {
|
2966
|
-
return getOutputsByType(outputs,
|
3076
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
|
2967
3077
|
}
|
2968
3078
|
function getOutputsVariable(outputs) {
|
2969
|
-
return getOutputsByType(outputs,
|
3079
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Variable);
|
2970
3080
|
}
|
2971
3081
|
|
2972
3082
|
// src/providers/transaction-summary/types.ts
|
@@ -3013,11 +3123,11 @@ function getReceiptsByType(receipts, type) {
|
|
3013
3123
|
}
|
3014
3124
|
function getTransactionTypeName(transactionType) {
|
3015
3125
|
switch (transactionType) {
|
3016
|
-
case
|
3126
|
+
case import_transactions14.TransactionType.Mint:
|
3017
3127
|
return "Mint" /* Mint */;
|
3018
|
-
case
|
3128
|
+
case import_transactions14.TransactionType.Create:
|
3019
3129
|
return "Create" /* Create */;
|
3020
|
-
case
|
3130
|
+
case import_transactions14.TransactionType.Script:
|
3021
3131
|
return "Script" /* Script */;
|
3022
3132
|
default:
|
3023
3133
|
throw new import_errors11.FuelError(
|
@@ -3043,10 +3153,10 @@ function hasSameAssetId(a) {
|
|
3043
3153
|
return (b) => a.assetId === b.assetId;
|
3044
3154
|
}
|
3045
3155
|
function getReceiptsCall(receipts) {
|
3046
|
-
return getReceiptsByType(receipts,
|
3156
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
|
3047
3157
|
}
|
3048
3158
|
function getReceiptsMessageOut(receipts) {
|
3049
|
-
return getReceiptsByType(receipts,
|
3159
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
|
3050
3160
|
}
|
3051
3161
|
var mergeAssets = (op1, op2) => {
|
3052
3162
|
const assets1 = op1.assetsSent || [];
|
@@ -3085,7 +3195,7 @@ function addOperation(operations, toAdd) {
|
|
3085
3195
|
return allOperations;
|
3086
3196
|
}
|
3087
3197
|
function getReceiptsTransferOut(receipts) {
|
3088
|
-
return getReceiptsByType(receipts,
|
3198
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.TransferOut);
|
3089
3199
|
}
|
3090
3200
|
function getWithdrawFromFuelOperations({
|
3091
3201
|
inputs,
|
@@ -3245,11 +3355,11 @@ function getTransferOperations({
|
|
3245
3355
|
});
|
3246
3356
|
const transferReceipts = getReceiptsByType(
|
3247
3357
|
receipts,
|
3248
|
-
|
3358
|
+
import_transactions14.ReceiptType.Transfer
|
3249
3359
|
);
|
3250
3360
|
const transferOutReceipts = getReceiptsByType(
|
3251
3361
|
receipts,
|
3252
|
-
|
3362
|
+
import_transactions14.ReceiptType.TransferOut
|
3253
3363
|
);
|
3254
3364
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3255
3365
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3334,17 +3444,17 @@ function getOperations({
|
|
3334
3444
|
}
|
3335
3445
|
|
3336
3446
|
// src/providers/transaction-summary/receipt.ts
|
3337
|
-
var
|
3447
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3338
3448
|
var processGqlReceipt = (gqlReceipt) => {
|
3339
3449
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3340
3450
|
switch (receipt.type) {
|
3341
|
-
case
|
3451
|
+
case import_transactions15.ReceiptType.ReturnData: {
|
3342
3452
|
return {
|
3343
3453
|
...receipt,
|
3344
3454
|
data: gqlReceipt.data || "0x"
|
3345
3455
|
};
|
3346
3456
|
}
|
3347
|
-
case
|
3457
|
+
case import_transactions15.ReceiptType.LogData: {
|
3348
3458
|
return {
|
3349
3459
|
...receipt,
|
3350
3460
|
data: gqlReceipt.data || "0x"
|
@@ -3357,7 +3467,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3357
3467
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3358
3468
|
const mintedAssets = [];
|
3359
3469
|
receipts.forEach((receipt) => {
|
3360
|
-
if (receipt.type ===
|
3470
|
+
if (receipt.type === import_transactions15.ReceiptType.Mint) {
|
3361
3471
|
mintedAssets.push({
|
3362
3472
|
subId: receipt.subId,
|
3363
3473
|
contractId: receipt.contractId,
|
@@ -3371,7 +3481,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3371
3481
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3372
3482
|
const burnedAssets = [];
|
3373
3483
|
receipts.forEach((receipt) => {
|
3374
|
-
if (receipt.type ===
|
3484
|
+
if (receipt.type === import_transactions15.ReceiptType.Burn) {
|
3375
3485
|
burnedAssets.push({
|
3376
3486
|
subId: receipt.subId,
|
3377
3487
|
contractId: receipt.contractId,
|
@@ -3452,10 +3562,12 @@ function assembleTransactionSummary(params) {
|
|
3452
3562
|
gqlTransactionStatus,
|
3453
3563
|
abiMap = {},
|
3454
3564
|
maxInputs,
|
3455
|
-
gasCosts
|
3565
|
+
gasCosts,
|
3566
|
+
maxGasPerTx,
|
3567
|
+
gasPrice
|
3456
3568
|
} = params;
|
3457
3569
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3458
|
-
const rawPayload = (0,
|
3570
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3459
3571
|
const operations = getOperations({
|
3460
3572
|
transactionType: transaction.type,
|
3461
3573
|
inputs: transaction.inputs || [],
|
@@ -3466,11 +3578,14 @@ function assembleTransactionSummary(params) {
|
|
3466
3578
|
maxInputs
|
3467
3579
|
});
|
3468
3580
|
const typeName = getTransactionTypeName(transaction.type);
|
3581
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3469
3582
|
const { fee } = calculateTransactionFee({
|
3470
|
-
|
3583
|
+
gasPrice,
|
3471
3584
|
rawPayload,
|
3585
|
+
tip,
|
3472
3586
|
consensusParameters: {
|
3473
3587
|
gasCosts,
|
3588
|
+
maxGasPerTx,
|
3474
3589
|
feeParams: {
|
3475
3590
|
gasPerByte,
|
3476
3591
|
gasPriceFactor
|
@@ -3482,7 +3597,7 @@ function assembleTransactionSummary(params) {
|
|
3482
3597
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3483
3598
|
let date;
|
3484
3599
|
if (time) {
|
3485
|
-
date =
|
3600
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3486
3601
|
}
|
3487
3602
|
const transactionSummary = {
|
3488
3603
|
id,
|
@@ -3530,7 +3645,7 @@ var TransactionResponse = class {
|
|
3530
3645
|
/** Current provider */
|
3531
3646
|
provider;
|
3532
3647
|
/** Gas used on the transaction */
|
3533
|
-
gasUsed = (0,
|
3648
|
+
gasUsed = (0, import_math15.bn)(0);
|
3534
3649
|
/** The graphql Transaction with receipts object. */
|
3535
3650
|
gqlTransaction;
|
3536
3651
|
abis;
|
@@ -3589,7 +3704,7 @@ var TransactionResponse = class {
|
|
3589
3704
|
*/
|
3590
3705
|
decodeTransaction(transactionWithReceipts) {
|
3591
3706
|
return new import_transactions18.TransactionCoder().decode(
|
3592
|
-
(0,
|
3707
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3593
3708
|
0
|
3594
3709
|
)?.[0];
|
3595
3710
|
}
|
@@ -3608,20 +3723,27 @@ var TransactionResponse = class {
|
|
3608
3723
|
const decodedTransaction = this.decodeTransaction(
|
3609
3724
|
transaction
|
3610
3725
|
);
|
3611
|
-
|
3612
|
-
|
3726
|
+
let txReceipts = [];
|
3727
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3728
|
+
txReceipts = transaction.status.receipts;
|
3729
|
+
}
|
3730
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3731
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3732
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3613
3733
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3614
3734
|
const transactionSummary = assembleTransactionSummary({
|
3615
3735
|
id: this.id,
|
3616
3736
|
receipts,
|
3617
3737
|
transaction: decodedTransaction,
|
3618
|
-
transactionBytes: (0,
|
3738
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3619
3739
|
gqlTransactionStatus: transaction.status,
|
3620
3740
|
gasPerByte,
|
3621
3741
|
gasPriceFactor,
|
3622
3742
|
abiMap: contractsAbiMap,
|
3623
3743
|
maxInputs,
|
3624
|
-
gasCosts
|
3744
|
+
gasCosts,
|
3745
|
+
maxGasPerTx,
|
3746
|
+
gasPrice
|
3625
3747
|
});
|
3626
3748
|
return transactionSummary;
|
3627
3749
|
}
|
@@ -3748,29 +3870,29 @@ var processGqlChain = (chain) => {
|
|
3748
3870
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3749
3871
|
return {
|
3750
3872
|
name,
|
3751
|
-
baseChainHeight: (0,
|
3873
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3752
3874
|
consensusParameters: {
|
3753
|
-
contractMaxSize: (0,
|
3754
|
-
maxInputs: (0,
|
3755
|
-
maxOutputs: (0,
|
3756
|
-
maxWitnesses: (0,
|
3757
|
-
maxGasPerTx: (0,
|
3758
|
-
maxScriptLength: (0,
|
3759
|
-
maxScriptDataLength: (0,
|
3760
|
-
maxStorageSlots: (0,
|
3761
|
-
maxPredicateLength: (0,
|
3762
|
-
maxPredicateDataLength: (0,
|
3763
|
-
maxGasPerPredicate: (0,
|
3764
|
-
gasPriceFactor: (0,
|
3765
|
-
gasPerByte: (0,
|
3766
|
-
maxMessageDataLength: (0,
|
3767
|
-
chainId: (0,
|
3875
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3876
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3877
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3878
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3879
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3880
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3881
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3882
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3883
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3884
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3885
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3886
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3887
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3888
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3889
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3768
3890
|
gasCosts
|
3769
3891
|
},
|
3770
3892
|
gasCosts,
|
3771
3893
|
latestBlock: {
|
3772
3894
|
id: latestBlock.id,
|
3773
|
-
height: (0,
|
3895
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3774
3896
|
time: latestBlock.header.time,
|
3775
3897
|
transactions: latestBlock.transactions.map((i) => ({
|
3776
3898
|
id: i.id
|
@@ -3864,10 +3986,8 @@ var _Provider = class {
|
|
3864
3986
|
* Returns some helpful parameters related to gas fees.
|
3865
3987
|
*/
|
3866
3988
|
getGasConfig() {
|
3867
|
-
const { minGasPrice } = this.getNode();
|
3868
3989
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3869
3990
|
return {
|
3870
|
-
minGasPrice,
|
3871
3991
|
maxGasPerTx,
|
3872
3992
|
maxGasPerPredicate,
|
3873
3993
|
gasPriceFactor,
|
@@ -3965,7 +4085,7 @@ var _Provider = class {
|
|
3965
4085
|
*/
|
3966
4086
|
async getBlockNumber() {
|
3967
4087
|
const { chain } = await this.operations.getChain();
|
3968
|
-
return (0,
|
4088
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3969
4089
|
}
|
3970
4090
|
/**
|
3971
4091
|
* Returns the chain information.
|
@@ -3975,13 +4095,11 @@ var _Provider = class {
|
|
3975
4095
|
async fetchNode() {
|
3976
4096
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3977
4097
|
const processedNodeInfo = {
|
3978
|
-
maxDepth: (0,
|
3979
|
-
maxTx: (0,
|
3980
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4098
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
4099
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3981
4100
|
nodeVersion: nodeInfo.nodeVersion,
|
3982
4101
|
utxoValidation: nodeInfo.utxoValidation,
|
3983
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3984
|
-
peers: nodeInfo.peers
|
4102
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3985
4103
|
};
|
3986
4104
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3987
4105
|
return processedNodeInfo;
|
@@ -4023,7 +4141,7 @@ var _Provider = class {
|
|
4023
4141
|
if (estimateTxDependencies) {
|
4024
4142
|
await this.estimateTxDependencies(transactionRequest);
|
4025
4143
|
}
|
4026
|
-
const encodedTransaction = (0,
|
4144
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4027
4145
|
let abis;
|
4028
4146
|
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4029
4147
|
abis = transactionRequest.abis;
|
@@ -4066,15 +4184,14 @@ var _Provider = class {
|
|
4066
4184
|
if (estimateTxDependencies) {
|
4067
4185
|
return this.estimateTxDependencies(transactionRequest);
|
4068
4186
|
}
|
4069
|
-
const encodedTransaction = (0,
|
4070
|
-
const { dryRun:
|
4071
|
-
encodedTransaction,
|
4187
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4188
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4189
|
+
encodedTransactions: encodedTransaction,
|
4072
4190
|
utxoValidation: utxoValidation || false
|
4073
4191
|
});
|
4074
|
-
const receipts =
|
4075
|
-
|
4076
|
-
|
4077
|
-
};
|
4192
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4193
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4194
|
+
return { receipts, dryrunStatus: status };
|
4078
4195
|
}
|
4079
4196
|
/**
|
4080
4197
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4085,13 +4202,13 @@ var _Provider = class {
|
|
4085
4202
|
async estimatePredicates(transactionRequest) {
|
4086
4203
|
const shouldEstimatePredicates = Boolean(
|
4087
4204
|
transactionRequest.inputs.find(
|
4088
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4205
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
|
4089
4206
|
)
|
4090
4207
|
);
|
4091
4208
|
if (!shouldEstimatePredicates) {
|
4092
4209
|
return transactionRequest;
|
4093
4210
|
}
|
4094
|
-
const encodedTransaction = (0,
|
4211
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4095
4212
|
const response = await this.operations.estimatePredicates({
|
4096
4213
|
encodedTransaction
|
4097
4214
|
});
|
@@ -4100,7 +4217,7 @@ var _Provider = class {
|
|
4100
4217
|
} = response;
|
4101
4218
|
if (inputs) {
|
4102
4219
|
inputs.forEach((input, index) => {
|
4103
|
-
if ("predicateGasUsed" in input && (0,
|
4220
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
4104
4221
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4105
4222
|
}
|
4106
4223
|
});
|
@@ -4113,9 +4230,6 @@ var _Provider = class {
|
|
4113
4230
|
* If there are missing variable outputs,
|
4114
4231
|
* `addVariableOutputs` is called on the transaction.
|
4115
4232
|
*
|
4116
|
-
* @privateRemarks
|
4117
|
-
* TODO: Investigate support for missing contract IDs
|
4118
|
-
* TODO: Add support for missing output messages
|
4119
4233
|
*
|
4120
4234
|
* @param transactionRequest - The transaction request object.
|
4121
4235
|
* @returns A promise.
|
@@ -4128,16 +4242,19 @@ var _Provider = class {
|
|
4128
4242
|
missingContractIds: []
|
4129
4243
|
};
|
4130
4244
|
}
|
4131
|
-
await this.estimatePredicates(transactionRequest);
|
4132
4245
|
let receipts = [];
|
4133
4246
|
const missingContractIds = [];
|
4134
4247
|
let outputVariables = 0;
|
4248
|
+
let dryrunStatus;
|
4135
4249
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4136
|
-
const {
|
4137
|
-
|
4250
|
+
const {
|
4251
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4252
|
+
} = await this.operations.dryRun({
|
4253
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4138
4254
|
utxoValidation: false
|
4139
4255
|
});
|
4140
|
-
receipts =
|
4256
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4257
|
+
dryrunStatus = status;
|
4141
4258
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4142
4259
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4143
4260
|
if (hasMissingOutputs) {
|
@@ -4147,6 +4264,10 @@ var _Provider = class {
|
|
4147
4264
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4148
4265
|
missingContractIds.push(contractId);
|
4149
4266
|
});
|
4267
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4268
|
+
transactionRequest
|
4269
|
+
});
|
4270
|
+
transactionRequest.maxFee = maxFee;
|
4150
4271
|
} else {
|
4151
4272
|
break;
|
4152
4273
|
}
|
@@ -4154,37 +4275,139 @@ var _Provider = class {
|
|
4154
4275
|
return {
|
4155
4276
|
receipts,
|
4156
4277
|
outputVariables,
|
4157
|
-
missingContractIds
|
4278
|
+
missingContractIds,
|
4279
|
+
dryrunStatus
|
4158
4280
|
};
|
4159
4281
|
}
|
4282
|
+
/**
|
4283
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4284
|
+
*
|
4285
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4286
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4287
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4288
|
+
*
|
4289
|
+
* @param transactionRequests - Array of transaction request objects.
|
4290
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4291
|
+
*/
|
4292
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4293
|
+
const results = transactionRequests.map(() => ({
|
4294
|
+
receipts: [],
|
4295
|
+
outputVariables: 0,
|
4296
|
+
missingContractIds: [],
|
4297
|
+
dryrunStatus: void 0
|
4298
|
+
}));
|
4299
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4300
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4301
|
+
allRequests.forEach((req, index) => {
|
4302
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4303
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4304
|
+
}
|
4305
|
+
});
|
4306
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4307
|
+
let attempt = 0;
|
4308
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4309
|
+
const encodedTransactions = transactionsToProcess.map(
|
4310
|
+
(index) => serializedTransactionsMap.get(index)
|
4311
|
+
);
|
4312
|
+
const dryRunResults = await this.operations.dryRun({
|
4313
|
+
encodedTransactions,
|
4314
|
+
utxoValidation: false
|
4315
|
+
});
|
4316
|
+
const nextRoundTransactions = [];
|
4317
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4318
|
+
const currentResultIndex = transactionsToProcess[i];
|
4319
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4320
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4321
|
+
results[currentResultIndex].dryrunStatus = status;
|
4322
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4323
|
+
results[currentResultIndex].receipts
|
4324
|
+
);
|
4325
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4326
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4327
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4328
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4329
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4330
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4331
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4332
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4333
|
+
});
|
4334
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4335
|
+
transactionRequest: requestToProcess
|
4336
|
+
});
|
4337
|
+
requestToProcess.maxFee = maxFee;
|
4338
|
+
serializedTransactionsMap.set(
|
4339
|
+
currentResultIndex,
|
4340
|
+
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4341
|
+
);
|
4342
|
+
nextRoundTransactions.push(currentResultIndex);
|
4343
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4344
|
+
}
|
4345
|
+
}
|
4346
|
+
transactionsToProcess = nextRoundTransactions;
|
4347
|
+
attempt += 1;
|
4348
|
+
}
|
4349
|
+
return results;
|
4350
|
+
}
|
4351
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4352
|
+
if (estimateTxDependencies) {
|
4353
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4354
|
+
}
|
4355
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4356
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4357
|
+
encodedTransactions,
|
4358
|
+
utxoValidation: utxoValidation || false
|
4359
|
+
});
|
4360
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4361
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4362
|
+
return { receipts, dryrunStatus: status };
|
4363
|
+
});
|
4364
|
+
return results;
|
4365
|
+
}
|
4160
4366
|
/**
|
4161
4367
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4162
4368
|
* @param transactionRequest - The transaction request object.
|
4163
4369
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4164
4370
|
*/
|
4165
|
-
estimateTxGasAndFee(params) {
|
4371
|
+
async estimateTxGasAndFee(params) {
|
4166
4372
|
const { transactionRequest } = params;
|
4167
|
-
|
4373
|
+
let { gasPrice } = params;
|
4168
4374
|
const chainInfo = this.getChain();
|
4169
|
-
const
|
4170
|
-
transactionRequest.gasPrice = gasPrice;
|
4375
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4171
4376
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4172
|
-
|
4377
|
+
if (!gasPrice) {
|
4378
|
+
gasPrice = await this.estimateGasPrice(10);
|
4379
|
+
}
|
4380
|
+
const minFee = calculateGasFee({
|
4381
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4382
|
+
gas: minGas,
|
4383
|
+
priceFactor: gasPriceFactor,
|
4384
|
+
tip: transactionRequest.tip
|
4385
|
+
}).add(1);
|
4386
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4173
4387
|
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4388
|
+
gasLimit = transactionRequest.gasLimit;
|
4174
4389
|
if (transactionRequest.gasLimit.eq(0)) {
|
4175
4390
|
transactionRequest.gasLimit = minGas;
|
4176
4391
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4177
4392
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4178
4393
|
);
|
4394
|
+
gasLimit = transactionRequest.gasLimit;
|
4179
4395
|
}
|
4180
4396
|
}
|
4181
4397
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4182
|
-
const maxFee =
|
4398
|
+
const maxFee = calculateGasFee({
|
4399
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4400
|
+
gas: maxGas,
|
4401
|
+
priceFactor: gasPriceFactor,
|
4402
|
+
tip: transactionRequest.tip
|
4403
|
+
}).add(1);
|
4183
4404
|
return {
|
4184
4405
|
minGas,
|
4185
4406
|
minFee,
|
4186
4407
|
maxGas,
|
4187
|
-
maxFee
|
4408
|
+
maxFee,
|
4409
|
+
gasPrice,
|
4410
|
+
gasLimit
|
4188
4411
|
};
|
4189
4412
|
}
|
4190
4413
|
/**
|
@@ -4202,15 +4425,17 @@ var _Provider = class {
|
|
4202
4425
|
if (estimateTxDependencies) {
|
4203
4426
|
return this.estimateTxDependencies(transactionRequest);
|
4204
4427
|
}
|
4205
|
-
const
|
4206
|
-
const { dryRun:
|
4207
|
-
|
4428
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4429
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4430
|
+
encodedTransactions,
|
4208
4431
|
utxoValidation: true
|
4209
4432
|
});
|
4210
|
-
const
|
4211
|
-
|
4212
|
-
receipts
|
4213
|
-
|
4433
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4434
|
+
const { id, receipts, status } = dryRunStatus;
|
4435
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4436
|
+
return { id, receipts: processedReceipts, status };
|
4437
|
+
});
|
4438
|
+
return { receipts: callResult[0].receipts };
|
4214
4439
|
}
|
4215
4440
|
/**
|
4216
4441
|
* Returns a transaction cost to enable user
|
@@ -4227,77 +4452,79 @@ var _Provider = class {
|
|
4227
4452
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4228
4453
|
* @returns A promise that resolves to the transaction cost object.
|
4229
4454
|
*/
|
4230
|
-
async getTransactionCost(transactionRequestLike,
|
4231
|
-
estimateTxDependencies = true,
|
4232
|
-
estimatePredicates = true,
|
4233
|
-
resourcesOwner,
|
4234
|
-
signatureCallback
|
4235
|
-
} = {}) {
|
4455
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4236
4456
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4237
|
-
const { minGasPrice } = this.getGasConfig();
|
4238
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4239
4457
|
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
4240
4458
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4241
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4459
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4242
4460
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4461
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4243
4462
|
if (isScriptTransaction) {
|
4244
|
-
txRequestClone.gasLimit = (0,
|
4463
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
4245
4464
|
}
|
4246
|
-
if (
|
4247
|
-
|
4248
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4249
|
-
}
|
4250
|
-
await this.estimatePredicates(txRequestClone);
|
4465
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4466
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4251
4467
|
}
|
4468
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4469
|
+
let addedSignatures = 0;
|
4252
4470
|
if (signatureCallback && isScriptTransaction) {
|
4253
|
-
|
4471
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4472
|
+
await signatureCallback(signedRequest);
|
4473
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4254
4474
|
}
|
4255
|
-
|
4256
|
-
|
4475
|
+
await this.estimatePredicates(signedRequest);
|
4476
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4477
|
+
transactionRequest: signedRequest
|
4257
4478
|
});
|
4258
4479
|
let receipts = [];
|
4259
4480
|
let missingContractIds = [];
|
4260
4481
|
let outputVariables = 0;
|
4261
|
-
let gasUsed = (0,
|
4262
|
-
|
4263
|
-
|
4482
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4483
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4484
|
+
txRequestClone.maxFee = maxFee;
|
4485
|
+
if (isScriptTransaction) {
|
4486
|
+
txRequestClone.gasLimit = gasLimit;
|
4487
|
+
if (signatureCallback) {
|
4488
|
+
await signatureCallback(txRequestClone);
|
4489
|
+
}
|
4264
4490
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4265
4491
|
receipts = result.receipts;
|
4266
4492
|
outputVariables = result.outputVariables;
|
4267
4493
|
missingContractIds = result.missingContractIds;
|
4268
4494
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4269
4495
|
txRequestClone.gasLimit = gasUsed;
|
4270
|
-
|
4271
|
-
|
4272
|
-
|
4496
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4497
|
+
transactionRequest: txRequestClone,
|
4498
|
+
gasPrice
|
4273
4499
|
}));
|
4274
4500
|
}
|
4275
4501
|
return {
|
4276
4502
|
requiredQuantities: allQuantities,
|
4277
4503
|
receipts,
|
4278
4504
|
gasUsed,
|
4279
|
-
|
4280
|
-
gasPrice: setGasPrice,
|
4505
|
+
gasPrice,
|
4281
4506
|
minGas,
|
4282
4507
|
maxGas,
|
4283
4508
|
minFee,
|
4284
4509
|
maxFee,
|
4285
|
-
estimatedInputs: txRequestClone.inputs,
|
4286
4510
|
outputVariables,
|
4287
|
-
missingContractIds
|
4511
|
+
missingContractIds,
|
4512
|
+
addedSignatures,
|
4513
|
+
estimatedPredicates: txRequestClone.inputs
|
4288
4514
|
};
|
4289
4515
|
}
|
4290
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4516
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4291
4517
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4292
4518
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4293
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4519
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4520
|
+
quantitiesToContract
|
4521
|
+
});
|
4294
4522
|
transactionRequest.addResources(
|
4295
4523
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4296
4524
|
);
|
4297
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4298
|
-
|
4299
|
-
|
4300
|
-
);
|
4525
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4526
|
+
quantitiesToContract
|
4527
|
+
});
|
4301
4528
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4302
4529
|
return {
|
4303
4530
|
resources,
|
@@ -4313,17 +4540,16 @@ var _Provider = class {
|
|
4313
4540
|
const result = await this.operations.getCoins({
|
4314
4541
|
first: 10,
|
4315
4542
|
...paginationArgs,
|
4316
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4543
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4317
4544
|
});
|
4318
4545
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4319
4546
|
return coins.map((coin) => ({
|
4320
4547
|
id: coin.utxoId,
|
4321
4548
|
assetId: coin.assetId,
|
4322
|
-
amount: (0,
|
4549
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4323
4550
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4324
|
-
|
4325
|
-
|
4326
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4551
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4552
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4327
4553
|
}));
|
4328
4554
|
}
|
4329
4555
|
/**
|
@@ -4337,19 +4563,19 @@ var _Provider = class {
|
|
4337
4563
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4338
4564
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4339
4565
|
const excludeInput = {
|
4340
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4341
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4566
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4567
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4342
4568
|
};
|
4343
4569
|
if (this.cache) {
|
4344
4570
|
const uniqueUtxos = new Set(
|
4345
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4571
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4346
4572
|
);
|
4347
4573
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4348
4574
|
}
|
4349
4575
|
const coinsQuery = {
|
4350
4576
|
owner: ownerAddress.toB256(),
|
4351
4577
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4352
|
-
assetId: (0,
|
4578
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4353
4579
|
amount: amount.toString(10),
|
4354
4580
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4355
4581
|
})),
|
@@ -4360,9 +4586,9 @@ var _Provider = class {
|
|
4360
4586
|
switch (coin.__typename) {
|
4361
4587
|
case "MessageCoin":
|
4362
4588
|
return {
|
4363
|
-
amount: (0,
|
4589
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4364
4590
|
assetId: coin.assetId,
|
4365
|
-
daHeight: (0,
|
4591
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4366
4592
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4367
4593
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4368
4594
|
nonce: coin.nonce
|
@@ -4370,12 +4596,11 @@ var _Provider = class {
|
|
4370
4596
|
case "Coin":
|
4371
4597
|
return {
|
4372
4598
|
id: coin.utxoId,
|
4373
|
-
amount: (0,
|
4599
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4374
4600
|
assetId: coin.assetId,
|
4375
4601
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4376
|
-
|
4377
|
-
|
4378
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4602
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4603
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4379
4604
|
};
|
4380
4605
|
default:
|
4381
4606
|
return null;
|
@@ -4392,13 +4617,13 @@ var _Provider = class {
|
|
4392
4617
|
async getBlock(idOrHeight) {
|
4393
4618
|
let variables;
|
4394
4619
|
if (typeof idOrHeight === "number") {
|
4395
|
-
variables = { height: (0,
|
4620
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4396
4621
|
} else if (idOrHeight === "latest") {
|
4397
4622
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4398
4623
|
} else if (idOrHeight.length === 66) {
|
4399
4624
|
variables = { blockId: idOrHeight };
|
4400
4625
|
} else {
|
4401
|
-
variables = { blockId: (0,
|
4626
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4402
4627
|
}
|
4403
4628
|
const { block } = await this.operations.getBlock(variables);
|
4404
4629
|
if (!block) {
|
@@ -4406,7 +4631,7 @@ var _Provider = class {
|
|
4406
4631
|
}
|
4407
4632
|
return {
|
4408
4633
|
id: block.id,
|
4409
|
-
height: (0,
|
4634
|
+
height: (0, import_math16.bn)(block.height),
|
4410
4635
|
time: block.header.time,
|
4411
4636
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4412
4637
|
};
|
@@ -4421,7 +4646,7 @@ var _Provider = class {
|
|
4421
4646
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4422
4647
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4423
4648
|
id: block.id,
|
4424
|
-
height: (0,
|
4649
|
+
height: (0, import_math16.bn)(block.height),
|
4425
4650
|
time: block.header.time,
|
4426
4651
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4427
4652
|
}));
|
@@ -4436,7 +4661,7 @@ var _Provider = class {
|
|
4436
4661
|
async getBlockWithTransactions(idOrHeight) {
|
4437
4662
|
let variables;
|
4438
4663
|
if (typeof idOrHeight === "number") {
|
4439
|
-
variables = { blockHeight: (0,
|
4664
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4440
4665
|
} else if (idOrHeight === "latest") {
|
4441
4666
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4442
4667
|
} else {
|
@@ -4448,11 +4673,11 @@ var _Provider = class {
|
|
4448
4673
|
}
|
4449
4674
|
return {
|
4450
4675
|
id: block.id,
|
4451
|
-
height: (0,
|
4676
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4452
4677
|
time: block.header.time,
|
4453
4678
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4454
4679
|
transactions: block.transactions.map(
|
4455
|
-
(tx) => new import_transactions19.TransactionCoder().decode((0,
|
4680
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4456
4681
|
)
|
4457
4682
|
};
|
4458
4683
|
}
|
@@ -4468,7 +4693,7 @@ var _Provider = class {
|
|
4468
4693
|
return null;
|
4469
4694
|
}
|
4470
4695
|
return new import_transactions19.TransactionCoder().decode(
|
4471
|
-
(0,
|
4696
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4472
4697
|
0
|
4473
4698
|
)?.[0];
|
4474
4699
|
}
|
@@ -4495,9 +4720,9 @@ var _Provider = class {
|
|
4495
4720
|
async getContractBalance(contractId, assetId) {
|
4496
4721
|
const { contractBalance } = await this.operations.getContractBalance({
|
4497
4722
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4498
|
-
asset: (0,
|
4723
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4499
4724
|
});
|
4500
|
-
return (0,
|
4725
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4501
4726
|
}
|
4502
4727
|
/**
|
4503
4728
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4509,9 +4734,9 @@ var _Provider = class {
|
|
4509
4734
|
async getBalance(owner, assetId) {
|
4510
4735
|
const { balance } = await this.operations.getBalance({
|
4511
4736
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4512
|
-
assetId: (0,
|
4737
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4513
4738
|
});
|
4514
|
-
return (0,
|
4739
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4515
4740
|
}
|
4516
4741
|
/**
|
4517
4742
|
* Returns balances for the given owner.
|
@@ -4529,7 +4754,7 @@ var _Provider = class {
|
|
4529
4754
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4530
4755
|
return balances.map((balance) => ({
|
4531
4756
|
assetId: balance.assetId,
|
4532
|
-
amount: (0,
|
4757
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4533
4758
|
}));
|
4534
4759
|
}
|
4535
4760
|
/**
|
@@ -4551,15 +4776,15 @@ var _Provider = class {
|
|
4551
4776
|
sender: message.sender,
|
4552
4777
|
recipient: message.recipient,
|
4553
4778
|
nonce: message.nonce,
|
4554
|
-
amount: (0,
|
4779
|
+
amount: (0, import_math16.bn)(message.amount),
|
4555
4780
|
data: message.data
|
4556
4781
|
}),
|
4557
4782
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4558
4783
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4559
4784
|
nonce: message.nonce,
|
4560
|
-
amount: (0,
|
4785
|
+
amount: (0, import_math16.bn)(message.amount),
|
4561
4786
|
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4562
|
-
daHeight: (0,
|
4787
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4563
4788
|
}));
|
4564
4789
|
}
|
4565
4790
|
/**
|
@@ -4612,44 +4837,60 @@ var _Provider = class {
|
|
4612
4837
|
} = result.messageProof;
|
4613
4838
|
return {
|
4614
4839
|
messageProof: {
|
4615
|
-
proofIndex: (0,
|
4840
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4616
4841
|
proofSet: messageProof.proofSet
|
4617
4842
|
},
|
4618
4843
|
blockProof: {
|
4619
|
-
proofIndex: (0,
|
4844
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4620
4845
|
proofSet: blockProof.proofSet
|
4621
4846
|
},
|
4622
4847
|
messageBlockHeader: {
|
4623
4848
|
id: messageBlockHeader.id,
|
4624
|
-
daHeight: (0,
|
4625
|
-
transactionsCount: (0,
|
4849
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4850
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4626
4851
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4627
|
-
height: (0,
|
4852
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4628
4853
|
prevRoot: messageBlockHeader.prevRoot,
|
4629
4854
|
time: messageBlockHeader.time,
|
4630
4855
|
applicationHash: messageBlockHeader.applicationHash,
|
4631
|
-
|
4632
|
-
|
4856
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4857
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4858
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4859
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4860
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4633
4861
|
},
|
4634
4862
|
commitBlockHeader: {
|
4635
4863
|
id: commitBlockHeader.id,
|
4636
|
-
daHeight: (0,
|
4637
|
-
transactionsCount: (0,
|
4864
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4865
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4638
4866
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4639
|
-
height: (0,
|
4867
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4640
4868
|
prevRoot: commitBlockHeader.prevRoot,
|
4641
4869
|
time: commitBlockHeader.time,
|
4642
4870
|
applicationHash: commitBlockHeader.applicationHash,
|
4643
|
-
|
4644
|
-
|
4871
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4872
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4873
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4874
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4875
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4645
4876
|
},
|
4646
4877
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4647
4878
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4648
4879
|
nonce,
|
4649
|
-
amount: (0,
|
4880
|
+
amount: (0, import_math16.bn)(amount),
|
4650
4881
|
data
|
4651
4882
|
};
|
4652
4883
|
}
|
4884
|
+
async getLatestGasPrice() {
|
4885
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4886
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4887
|
+
}
|
4888
|
+
async estimateGasPrice(blockHorizon) {
|
4889
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4890
|
+
blockHorizon: String(blockHorizon)
|
4891
|
+
});
|
4892
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4893
|
+
}
|
4653
4894
|
/**
|
4654
4895
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4655
4896
|
*
|
@@ -4669,10 +4910,10 @@ var _Provider = class {
|
|
4669
4910
|
*/
|
4670
4911
|
async produceBlocks(amount, startTime) {
|
4671
4912
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4672
|
-
blocksToProduce: (0,
|
4673
|
-
startTimestamp: startTime ?
|
4913
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4914
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4674
4915
|
});
|
4675
|
-
return (0,
|
4916
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4676
4917
|
}
|
4677
4918
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4678
4919
|
async getTransactionResponse(transactionId) {
|
@@ -4696,9 +4937,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4696
4937
|
|
4697
4938
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4698
4939
|
var import_errors15 = require("@fuel-ts/errors");
|
4699
|
-
var
|
4940
|
+
var import_math17 = require("@fuel-ts/math");
|
4700
4941
|
var import_transactions20 = require("@fuel-ts/transactions");
|
4701
|
-
var
|
4942
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4702
4943
|
async function getTransactionSummary(params) {
|
4703
4944
|
const { id, provider, abiMap } = params;
|
4704
4945
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4711,24 +4952,31 @@ async function getTransactionSummary(params) {
|
|
4711
4952
|
);
|
4712
4953
|
}
|
4713
4954
|
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
|
4714
|
-
(0,
|
4955
|
+
(0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4715
4956
|
0
|
4716
4957
|
);
|
4717
|
-
|
4958
|
+
let txReceipts = [];
|
4959
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4960
|
+
txReceipts = gqlTransaction.status.receipts;
|
4961
|
+
}
|
4962
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4718
4963
|
const {
|
4719
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4964
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4720
4965
|
} = provider.getChain();
|
4966
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4721
4967
|
const transactionInfo = assembleTransactionSummary({
|
4722
4968
|
id: gqlTransaction.id,
|
4723
4969
|
receipts,
|
4724
4970
|
transaction: decodedTransaction,
|
4725
|
-
transactionBytes: (0,
|
4971
|
+
transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4726
4972
|
gqlTransactionStatus: gqlTransaction.status,
|
4727
|
-
gasPerByte: (0,
|
4728
|
-
gasPriceFactor: (0,
|
4973
|
+
gasPerByte: (0, import_math17.bn)(gasPerByte),
|
4974
|
+
gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
|
4729
4975
|
abiMap,
|
4730
4976
|
maxInputs,
|
4731
|
-
gasCosts
|
4977
|
+
gasCosts,
|
4978
|
+
maxGasPerTx,
|
4979
|
+
gasPrice
|
4732
4980
|
});
|
4733
4981
|
return {
|
4734
4982
|
gqlTransaction,
|
@@ -4738,10 +4986,11 @@ async function getTransactionSummary(params) {
|
|
4738
4986
|
async function getTransactionSummaryFromRequest(params) {
|
4739
4987
|
const { provider, transactionRequest, abiMap } = params;
|
4740
4988
|
const { receipts } = await provider.call(transactionRequest);
|
4741
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4989
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4742
4990
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4743
4991
|
const transaction = transactionRequest.toTransaction();
|
4744
4992
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4993
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4745
4994
|
const transactionSummary = assembleTransactionSummary({
|
4746
4995
|
receipts,
|
4747
4996
|
transaction,
|
@@ -4750,7 +4999,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4750
4999
|
gasPerByte,
|
4751
5000
|
gasPriceFactor,
|
4752
5001
|
maxInputs,
|
4753
|
-
gasCosts
|
5002
|
+
gasCosts,
|
5003
|
+
maxGasPerTx,
|
5004
|
+
gasPrice
|
4754
5005
|
});
|
4755
5006
|
return transactionSummary;
|
4756
5007
|
}
|
@@ -4759,24 +5010,31 @@ async function getTransactionsSummaries(params) {
|
|
4759
5010
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4760
5011
|
const { edges, pageInfo } = transactionsByOwner;
|
4761
5012
|
const {
|
4762
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
5013
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4763
5014
|
} = provider.getChain();
|
5015
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4764
5016
|
const transactions = edges.map((edge) => {
|
4765
5017
|
const { node: gqlTransaction } = edge;
|
4766
|
-
const { id, rawPayload,
|
4767
|
-
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0,
|
4768
|
-
|
5018
|
+
const { id, rawPayload, status } = gqlTransaction;
|
5019
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
5020
|
+
let txReceipts = [];
|
5021
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
5022
|
+
txReceipts = gqlTransaction.status.receipts;
|
5023
|
+
}
|
5024
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4769
5025
|
const transactionSummary = assembleTransactionSummary({
|
4770
5026
|
id,
|
4771
5027
|
receipts,
|
4772
5028
|
transaction: decodedTransaction,
|
4773
|
-
transactionBytes: (0,
|
5029
|
+
transactionBytes: (0, import_utils25.arrayify)(rawPayload),
|
4774
5030
|
gqlTransactionStatus: status,
|
4775
5031
|
abiMap,
|
4776
5032
|
gasPerByte,
|
4777
5033
|
gasPriceFactor,
|
4778
5034
|
maxInputs,
|
4779
|
-
gasCosts
|
5035
|
+
gasCosts,
|
5036
|
+
maxGasPerTx,
|
5037
|
+
gasPrice
|
4780
5038
|
});
|
4781
5039
|
const output = {
|
4782
5040
|
gqlTransaction,
|
@@ -4913,17 +5171,17 @@ var assets = [
|
|
4913
5171
|
|
4914
5172
|
// src/utils/formatTransferToContractScriptData.ts
|
4915
5173
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4916
|
-
var
|
4917
|
-
var
|
5174
|
+
var import_math18 = require("@fuel-ts/math");
|
5175
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4918
5176
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4919
5177
|
var formatTransferToContractScriptData = (params) => {
|
4920
5178
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4921
5179
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4922
|
-
const encoded = numberCoder.encode(new
|
5180
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4923
5181
|
const scriptData = Uint8Array.from([
|
4924
|
-
...(0,
|
5182
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4925
5183
|
...encoded,
|
4926
|
-
...(0,
|
5184
|
+
...(0, import_utils26.arrayify)(assetId)
|
4927
5185
|
]);
|
4928
5186
|
return scriptData;
|
4929
5187
|
};
|
@@ -5108,36 +5366,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5108
5366
|
* @param fee - The estimated transaction fee.
|
5109
5367
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5110
5368
|
*/
|
5111
|
-
async fund(request,
|
5112
|
-
const
|
5113
|
-
|
5369
|
+
async fund(request, params) {
|
5370
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5371
|
+
const txRequest = request;
|
5372
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5373
|
+
amount: (0, import_math19.bn)(fee),
|
5114
5374
|
assetId: import_configs12.BaseAssetId,
|
5115
|
-
coinQuantities
|
5375
|
+
coinQuantities: requiredQuantities
|
5116
5376
|
});
|
5117
5377
|
const quantitiesDict = {};
|
5118
|
-
|
5378
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5119
5379
|
quantitiesDict[assetId] = {
|
5120
5380
|
required: amount,
|
5121
|
-
owned: (0,
|
5381
|
+
owned: (0, import_math19.bn)(0)
|
5122
5382
|
};
|
5123
5383
|
});
|
5124
|
-
|
5125
|
-
const cachedMessages = [];
|
5126
|
-
const owner = this.address.toB256();
|
5127
|
-
request.inputs.forEach((input) => {
|
5384
|
+
txRequest.inputs.forEach((input) => {
|
5128
5385
|
const isResource = "amount" in input;
|
5129
5386
|
if (isResource) {
|
5130
5387
|
const isCoin2 = "owner" in input;
|
5131
5388
|
if (isCoin2) {
|
5132
5389
|
const assetId = String(input.assetId);
|
5133
|
-
if (
|
5134
|
-
const amount = (0,
|
5390
|
+
if (quantitiesDict[assetId]) {
|
5391
|
+
const amount = (0, import_math19.bn)(input.amount);
|
5135
5392
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5136
|
-
cachedUtxos.push(input.id);
|
5137
5393
|
}
|
5138
|
-
} else if (input.
|
5394
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5139
5395
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5140
|
-
cachedMessages.push(input.nonce);
|
5141
5396
|
}
|
5142
5397
|
}
|
5143
5398
|
});
|
@@ -5152,12 +5407,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5152
5407
|
});
|
5153
5408
|
const needsToBeFunded = missingQuantities.length;
|
5154
5409
|
if (needsToBeFunded) {
|
5155
|
-
const
|
5156
|
-
|
5157
|
-
|
5158
|
-
|
5159
|
-
|
5410
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5411
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5412
|
+
txRequest.addResources(resources);
|
5413
|
+
}
|
5414
|
+
txRequest.shiftPredicateData();
|
5415
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5416
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
5417
|
+
if (addedSignatures) {
|
5418
|
+
Array.from({ length: addedSignatures }).forEach(
|
5419
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5420
|
+
);
|
5160
5421
|
}
|
5422
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5423
|
+
transactionRequest: requestToBeReEstimate
|
5424
|
+
});
|
5425
|
+
txRequest.maxFee = maxFee;
|
5426
|
+
return txRequest;
|
5161
5427
|
}
|
5162
5428
|
/**
|
5163
5429
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5165,28 +5431,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5165
5431
|
* @param destination - The address of the destination.
|
5166
5432
|
* @param amount - The amount of coins to transfer.
|
5167
5433
|
* @param assetId - The asset ID of the coins to transfer.
|
5168
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5434
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5169
5435
|
* @returns A promise that resolves to the prepared transaction request.
|
5170
5436
|
*/
|
5171
5437
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5172
|
-
const
|
5173
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5174
|
-
const request = new ScriptTransactionRequest(params);
|
5438
|
+
const request = new ScriptTransactionRequest(txParams);
|
5175
5439
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5176
|
-
const
|
5440
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5177
5441
|
estimateTxDependencies: true,
|
5178
5442
|
resourcesOwner: this
|
5179
5443
|
});
|
5180
|
-
|
5181
|
-
|
5182
|
-
|
5183
|
-
|
5184
|
-
|
5185
|
-
|
5186
|
-
|
5187
|
-
|
5188
|
-
await this.fund(request,
|
5189
|
-
request.updatePredicateInputs(estimatedInputs);
|
5444
|
+
if ("gasLimit" in txParams) {
|
5445
|
+
this.validateGas({
|
5446
|
+
gasUsed: txCost.gasUsed,
|
5447
|
+
gasLimit: request.gasLimit
|
5448
|
+
});
|
5449
|
+
}
|
5450
|
+
request.gasLimit = txCost.gasUsed;
|
5451
|
+
request.maxFee = txCost.maxFee;
|
5452
|
+
await this.fund(request, txCost);
|
5190
5453
|
return request;
|
5191
5454
|
}
|
5192
5455
|
/**
|
@@ -5199,7 +5462,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5199
5462
|
* @returns A promise that resolves to the transaction response.
|
5200
5463
|
*/
|
5201
5464
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5202
|
-
if ((0,
|
5465
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5203
5466
|
throw new import_errors16.FuelError(
|
5204
5467
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5205
5468
|
"Transfer amount must be a positive number."
|
@@ -5218,38 +5481,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5218
5481
|
* @returns A promise that resolves to the transaction response.
|
5219
5482
|
*/
|
5220
5483
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5221
|
-
if ((0,
|
5484
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5222
5485
|
throw new import_errors16.FuelError(
|
5223
5486
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5224
5487
|
"Transfer amount must be a positive number."
|
5225
5488
|
);
|
5226
5489
|
}
|
5227
5490
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5228
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5229
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5230
5491
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5231
5492
|
hexlifiedContractId: contractAddress.toB256(),
|
5232
|
-
amountToTransfer: (0,
|
5493
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
5233
5494
|
assetId
|
5234
5495
|
});
|
5235
5496
|
const request = new ScriptTransactionRequest({
|
5236
|
-
...
|
5497
|
+
...txParams,
|
5237
5498
|
script,
|
5238
5499
|
scriptData
|
5239
5500
|
});
|
5240
5501
|
request.addContractInputAndOutput(contractAddress);
|
5241
|
-
const
|
5242
|
-
|
5243
|
-
[{ amount: (0,
|
5244
|
-
);
|
5245
|
-
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5246
|
-
this.validateGas({
|
5247
|
-
gasUsed,
|
5248
|
-
gasPrice: request.gasPrice,
|
5249
|
-
gasLimit: request.gasLimit,
|
5250
|
-
minGasPrice
|
5502
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5503
|
+
resourcesOwner: this,
|
5504
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
5251
5505
|
});
|
5252
|
-
|
5506
|
+
if (txParams.gasLimit) {
|
5507
|
+
this.validateGas({
|
5508
|
+
gasUsed: txCost.gasUsed,
|
5509
|
+
gasLimit: request.gasLimit
|
5510
|
+
});
|
5511
|
+
}
|
5512
|
+
request.gasLimit = txCost.gasUsed;
|
5513
|
+
request.maxFee = txCost.maxFee;
|
5514
|
+
await this.fund(request, txCost);
|
5253
5515
|
return this.sendTransaction(request);
|
5254
5516
|
}
|
5255
5517
|
/**
|
@@ -5261,34 +5523,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5261
5523
|
* @returns A promise that resolves to the transaction response.
|
5262
5524
|
*/
|
5263
5525
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5264
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5265
5526
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5266
|
-
const recipientDataArray = (0,
|
5527
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
5267
5528
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5268
5529
|
);
|
5269
|
-
const amountDataArray = (0,
|
5270
|
-
"0x".concat((0,
|
5530
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5531
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5271
5532
|
);
|
5272
5533
|
const script = new Uint8Array([
|
5273
|
-
...(0,
|
5534
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
5274
5535
|
...recipientDataArray,
|
5275
5536
|
...amountDataArray
|
5276
5537
|
]);
|
5277
|
-
const params = { script,
|
5538
|
+
const params = { script, ...txParams };
|
5278
5539
|
const request = new ScriptTransactionRequest(params);
|
5279
|
-
const
|
5280
|
-
const
|
5281
|
-
|
5282
|
-
|
5283
|
-
|
5284
|
-
|
5285
|
-
|
5286
|
-
|
5287
|
-
|
5288
|
-
|
5289
|
-
|
5290
|
-
});
|
5291
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5540
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5541
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5542
|
+
if (txParams.gasLimit) {
|
5543
|
+
this.validateGas({
|
5544
|
+
gasUsed: txCost.gasUsed,
|
5545
|
+
gasLimit: request.gasLimit
|
5546
|
+
});
|
5547
|
+
}
|
5548
|
+
request.maxFee = txCost.maxFee;
|
5549
|
+
request.gasLimit = txCost.gasUsed;
|
5550
|
+
await this.fund(request, txCost);
|
5292
5551
|
return this.sendTransaction(request);
|
5293
5552
|
}
|
5294
5553
|
async signMessage(message) {
|
@@ -5346,18 +5605,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5346
5605
|
}
|
5347
5606
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5348
5607
|
}
|
5349
|
-
validateGas({
|
5350
|
-
gasUsed,
|
5351
|
-
gasPrice,
|
5352
|
-
gasLimit,
|
5353
|
-
minGasPrice
|
5354
|
-
}) {
|
5355
|
-
if (minGasPrice.gt(gasPrice)) {
|
5356
|
-
throw new import_errors16.FuelError(
|
5357
|
-
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5358
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5359
|
-
);
|
5360
|
-
}
|
5608
|
+
validateGas({ gasUsed, gasLimit }) {
|
5361
5609
|
if (gasUsed.gt(gasLimit)) {
|
5362
5610
|
throw new import_errors16.FuelError(
|
5363
5611
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5369,14 +5617,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5369
5617
|
|
5370
5618
|
// src/wallet/base-wallet-unlocked.ts
|
5371
5619
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5372
|
-
var
|
5620
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5373
5621
|
|
5374
5622
|
// src/signer/signer.ts
|
5375
5623
|
var import_address5 = require("@fuel-ts/address");
|
5376
5624
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5377
5625
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5378
|
-
var
|
5379
|
-
var
|
5626
|
+
var import_math20 = require("@fuel-ts/math");
|
5627
|
+
var import_utils28 = require("@fuel-ts/utils");
|
5380
5628
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5381
5629
|
var Signer = class {
|
5382
5630
|
address;
|
@@ -5395,10 +5643,10 @@ var Signer = class {
|
|
5395
5643
|
privateKey = `0x${privateKey}`;
|
5396
5644
|
}
|
5397
5645
|
}
|
5398
|
-
const privateKeyBytes = (0,
|
5399
|
-
this.privateKey = (0,
|
5400
|
-
this.publicKey = (0,
|
5401
|
-
this.compressedPublicKey = (0,
|
5646
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5647
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5648
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5649
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5402
5650
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5403
5651
|
}
|
5404
5652
|
/**
|
@@ -5412,11 +5660,11 @@ var Signer = class {
|
|
5412
5660
|
* @returns hashed signature
|
5413
5661
|
*/
|
5414
5662
|
sign(data) {
|
5415
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5416
|
-
const r = (0,
|
5417
|
-
const s = (0,
|
5663
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5664
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5665
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5418
5666
|
s[0] |= (signature.recovery || 0) << 7;
|
5419
|
-
return (0,
|
5667
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
5420
5668
|
}
|
5421
5669
|
/**
|
5422
5670
|
* Add point on the current elliptic curve
|
@@ -5425,8 +5673,8 @@ var Signer = class {
|
|
5425
5673
|
* @returns compressed point on the curve
|
5426
5674
|
*/
|
5427
5675
|
addPoint(point) {
|
5428
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5429
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5676
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5677
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5430
5678
|
const result = p0.add(p1);
|
5431
5679
|
return `0x${result.toHex(true)}`;
|
5432
5680
|
}
|
@@ -5438,16 +5686,16 @@ var Signer = class {
|
|
5438
5686
|
* @returns public key from signature from the
|
5439
5687
|
*/
|
5440
5688
|
static recoverPublicKey(data, signature) {
|
5441
|
-
const signedMessageBytes = (0,
|
5689
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5442
5690
|
const r = signedMessageBytes.slice(0, 32);
|
5443
5691
|
const s = signedMessageBytes.slice(32, 64);
|
5444
5692
|
const recoveryParam = (s[0] & 128) >> 7;
|
5445
5693
|
s[0] &= 127;
|
5446
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5694
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5447
5695
|
recoveryParam
|
5448
5696
|
);
|
5449
|
-
const publicKey = sig.recoverPublicKey((0,
|
5450
|
-
return (0,
|
5697
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5698
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5451
5699
|
}
|
5452
5700
|
/**
|
5453
5701
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5466,7 +5714,7 @@ var Signer = class {
|
|
5466
5714
|
* @returns random 32-byte hashed
|
5467
5715
|
*/
|
5468
5716
|
static generatePrivateKey(entropy) {
|
5469
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5717
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5470
5718
|
}
|
5471
5719
|
/**
|
5472
5720
|
* Extended publicKey from a compact publicKey
|
@@ -5475,8 +5723,8 @@ var Signer = class {
|
|
5475
5723
|
* @returns extended publicKey
|
5476
5724
|
*/
|
5477
5725
|
static extendPublicKey(publicKey) {
|
5478
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5479
|
-
return (0,
|
5726
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5727
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5480
5728
|
}
|
5481
5729
|
};
|
5482
5730
|
|
@@ -5484,7 +5732,7 @@ var Signer = class {
|
|
5484
5732
|
var import_address6 = require("@fuel-ts/address");
|
5485
5733
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5486
5734
|
var import_errors17 = require("@fuel-ts/errors");
|
5487
|
-
var
|
5735
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5488
5736
|
var import_uuid = require("uuid");
|
5489
5737
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5490
5738
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5567,7 +5815,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5567
5815
|
);
|
5568
5816
|
}
|
5569
5817
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5570
|
-
const privateKey = (0,
|
5818
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5571
5819
|
return privateKey;
|
5572
5820
|
}
|
5573
5821
|
|
@@ -5612,7 +5860,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5612
5860
|
*/
|
5613
5861
|
async signMessage(message) {
|
5614
5862
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5615
|
-
return (0,
|
5863
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5616
5864
|
}
|
5617
5865
|
/**
|
5618
5866
|
* Signs a transaction with the wallet's private key.
|
@@ -5625,7 +5873,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5625
5873
|
const chainId = this.provider.getChainId();
|
5626
5874
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5627
5875
|
const signature = await this.signer().sign(hashedTransaction);
|
5628
|
-
return (0,
|
5876
|
+
return (0, import_utils30.hexlify)(signature);
|
5629
5877
|
}
|
5630
5878
|
/**
|
5631
5879
|
* Populates a transaction with the witnesses signature.
|
@@ -5645,7 +5893,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5645
5893
|
* @param transactionRequestLike - The transaction request to send.
|
5646
5894
|
* @returns A promise that resolves to the TransactionResponse object.
|
5647
5895
|
*/
|
5648
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5896
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5649
5897
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5650
5898
|
if (estimateTxDependencies) {
|
5651
5899
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5686,15 +5934,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5686
5934
|
// src/hdwallet/hdwallet.ts
|
5687
5935
|
var import_errors20 = require("@fuel-ts/errors");
|
5688
5936
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5689
|
-
var
|
5690
|
-
var
|
5937
|
+
var import_math21 = require("@fuel-ts/math");
|
5938
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5691
5939
|
var import_ethers3 = require("ethers");
|
5692
5940
|
|
5693
5941
|
// src/mnemonic/mnemonic.ts
|
5694
5942
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5695
5943
|
var import_errors19 = require("@fuel-ts/errors");
|
5696
5944
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5697
|
-
var
|
5945
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5698
5946
|
var import_ethers2 = require("ethers");
|
5699
5947
|
|
5700
5948
|
// src/wordlists/words/english.ts
|
@@ -7758,7 +8006,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7758
8006
|
// src/mnemonic/utils.ts
|
7759
8007
|
var import_errors18 = require("@fuel-ts/errors");
|
7760
8008
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7761
|
-
var
|
8009
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7762
8010
|
function toUtf8Bytes(stri) {
|
7763
8011
|
const str = stri.normalize("NFKD");
|
7764
8012
|
const result = [];
|
@@ -7825,14 +8073,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7825
8073
|
}
|
7826
8074
|
}
|
7827
8075
|
const checksumBits = entropy.length / 4;
|
7828
|
-
const checksum = (0,
|
8076
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7829
8077
|
indices[indices.length - 1] <<= checksumBits;
|
7830
8078
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7831
8079
|
return indices;
|
7832
8080
|
}
|
7833
8081
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7834
8082
|
const size = Math.ceil(11 * words.length / 8);
|
7835
|
-
const entropy = (0,
|
8083
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7836
8084
|
let offset = 0;
|
7837
8085
|
for (let i = 0; i < words.length; i += 1) {
|
7838
8086
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7852,7 +8100,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7852
8100
|
const entropyBits = 32 * words.length / 3;
|
7853
8101
|
const checksumBits = words.length / 3;
|
7854
8102
|
const checksumMask = getUpperMask(checksumBits);
|
7855
|
-
const checksum = (0,
|
8103
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7856
8104
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7857
8105
|
throw new import_errors18.FuelError(
|
7858
8106
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7927,7 +8175,7 @@ var Mnemonic = class {
|
|
7927
8175
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7928
8176
|
const words = getWords(phrase);
|
7929
8177
|
assertMnemonic(words);
|
7930
|
-
return (0,
|
8178
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7931
8179
|
}
|
7932
8180
|
/**
|
7933
8181
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7935,7 +8183,7 @@ var Mnemonic = class {
|
|
7935
8183
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7936
8184
|
*/
|
7937
8185
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7938
|
-
const entropyBytes = (0,
|
8186
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7939
8187
|
assertWordList(wordlist);
|
7940
8188
|
assertEntropy(entropyBytes);
|
7941
8189
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8004,14 +8252,14 @@ var Mnemonic = class {
|
|
8004
8252
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8005
8253
|
*/
|
8006
8254
|
static masterKeysFromSeed(seed) {
|
8007
|
-
const seedArray = (0,
|
8255
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
8008
8256
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8009
8257
|
throw new import_errors19.FuelError(
|
8010
8258
|
import_errors19.ErrorCode.INVALID_SEED,
|
8011
8259
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8012
8260
|
);
|
8013
8261
|
}
|
8014
|
-
return (0,
|
8262
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
8015
8263
|
}
|
8016
8264
|
/**
|
8017
8265
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8022,22 +8270,22 @@ var Mnemonic = class {
|
|
8022
8270
|
*/
|
8023
8271
|
static seedToExtendedKey(seed, testnet = false) {
|
8024
8272
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8025
|
-
const prefix = (0,
|
8273
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8026
8274
|
const depth = "0x00";
|
8027
8275
|
const fingerprint = "0x00000000";
|
8028
8276
|
const index = "0x00000000";
|
8029
8277
|
const chainCode = masterKey.slice(32);
|
8030
8278
|
const privateKey = masterKey.slice(0, 32);
|
8031
|
-
const extendedKey = (0,
|
8279
|
+
const extendedKey = (0, import_utils32.concat)([
|
8032
8280
|
prefix,
|
8033
8281
|
depth,
|
8034
8282
|
fingerprint,
|
8035
8283
|
index,
|
8036
8284
|
chainCode,
|
8037
|
-
(0,
|
8285
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
8038
8286
|
]);
|
8039
8287
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8040
|
-
return (0, import_ethers2.encodeBase58)((0,
|
8288
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
8041
8289
|
}
|
8042
8290
|
/**
|
8043
8291
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8052,7 +8300,7 @@ var Mnemonic = class {
|
|
8052
8300
|
* @returns A randomly generated mnemonic
|
8053
8301
|
*/
|
8054
8302
|
static generate(size = 32, extraEntropy = "") {
|
8055
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8303
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
8056
8304
|
return Mnemonic.entropyToMnemonic(entropy);
|
8057
8305
|
}
|
8058
8306
|
};
|
@@ -8060,12 +8308,12 @@ var mnemonic_default = Mnemonic;
|
|
8060
8308
|
|
8061
8309
|
// src/hdwallet/hdwallet.ts
|
8062
8310
|
var HARDENED_INDEX = 2147483648;
|
8063
|
-
var MainnetPRV2 = (0,
|
8064
|
-
var MainnetPUB = (0,
|
8065
|
-
var TestnetPRV2 = (0,
|
8066
|
-
var TestnetPUB = (0,
|
8311
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
8312
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
8313
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
8314
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
8067
8315
|
function base58check(data) {
|
8068
|
-
return (0, import_ethers3.encodeBase58)((0,
|
8316
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8069
8317
|
}
|
8070
8318
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8071
8319
|
if (isPublic) {
|
@@ -8074,11 +8322,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8074
8322
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8075
8323
|
}
|
8076
8324
|
function isPublicExtendedKey(extendedKey) {
|
8077
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8325
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
8078
8326
|
}
|
8079
8327
|
function isValidExtendedKey(extendedKey) {
|
8080
8328
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8081
|
-
(0,
|
8329
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
8082
8330
|
);
|
8083
8331
|
}
|
8084
8332
|
function parsePath(path, depth = 0) {
|
@@ -8096,8 +8344,8 @@ function parsePath(path, depth = 0) {
|
|
8096
8344
|
var HDWallet = class {
|
8097
8345
|
depth = 0;
|
8098
8346
|
index = 0;
|
8099
|
-
fingerprint = (0,
|
8100
|
-
parentFingerprint = (0,
|
8347
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8348
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8101
8349
|
privateKey;
|
8102
8350
|
publicKey;
|
8103
8351
|
chainCode;
|
@@ -8109,8 +8357,8 @@ var HDWallet = class {
|
|
8109
8357
|
constructor(config) {
|
8110
8358
|
if (config.privateKey) {
|
8111
8359
|
const signer = new Signer(config.privateKey);
|
8112
|
-
this.publicKey = (0,
|
8113
|
-
this.privateKey = (0,
|
8360
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
8361
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
8114
8362
|
} else {
|
8115
8363
|
if (!config.publicKey) {
|
8116
8364
|
throw new import_errors20.FuelError(
|
@@ -8118,7 +8366,7 @@ var HDWallet = class {
|
|
8118
8366
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8119
8367
|
);
|
8120
8368
|
}
|
8121
|
-
this.publicKey = (0,
|
8369
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
8122
8370
|
}
|
8123
8371
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8124
8372
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8137,9 +8385,9 @@ var HDWallet = class {
|
|
8137
8385
|
* @returns A new instance of HDWallet on the derived index
|
8138
8386
|
*/
|
8139
8387
|
deriveIndex(index) {
|
8140
|
-
const privateKey = this.privateKey && (0,
|
8141
|
-
const publicKey = (0,
|
8142
|
-
const chainCode = (0,
|
8388
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
8389
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
8390
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
8143
8391
|
const data = new Uint8Array(37);
|
8144
8392
|
if (index & HARDENED_INDEX) {
|
8145
8393
|
if (!privateKey) {
|
@@ -8150,15 +8398,15 @@ var HDWallet = class {
|
|
8150
8398
|
}
|
8151
8399
|
data.set(privateKey, 1);
|
8152
8400
|
} else {
|
8153
|
-
data.set((0,
|
8401
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
8154
8402
|
}
|
8155
|
-
data.set((0,
|
8156
|
-
const bytes = (0,
|
8403
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
8404
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8157
8405
|
const IL = bytes.slice(0, 32);
|
8158
8406
|
const IR = bytes.slice(32);
|
8159
8407
|
if (privateKey) {
|
8160
8408
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8161
|
-
const ki = (0,
|
8409
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8162
8410
|
return new HDWallet({
|
8163
8411
|
privateKey: ki,
|
8164
8412
|
chainCode: IR,
|
@@ -8167,7 +8415,7 @@ var HDWallet = class {
|
|
8167
8415
|
parentFingerprint: this.fingerprint
|
8168
8416
|
});
|
8169
8417
|
}
|
8170
|
-
const signer = new Signer((0,
|
8418
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
8171
8419
|
const Ki = signer.addPoint(publicKey);
|
8172
8420
|
return new HDWallet({
|
8173
8421
|
publicKey: Ki,
|
@@ -8202,12 +8450,12 @@ var HDWallet = class {
|
|
8202
8450
|
);
|
8203
8451
|
}
|
8204
8452
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8205
|
-
const depth = (0,
|
8453
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
8206
8454
|
const parentFingerprint = this.parentFingerprint;
|
8207
|
-
const index = (0,
|
8455
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
8208
8456
|
const chainCode = this.chainCode;
|
8209
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8210
|
-
const extendedKey = (0,
|
8457
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8458
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8211
8459
|
return base58check(extendedKey);
|
8212
8460
|
}
|
8213
8461
|
/**
|
@@ -8219,13 +8467,13 @@ var HDWallet = class {
|
|
8219
8467
|
static fromSeed(seed) {
|
8220
8468
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8221
8469
|
return new HDWallet({
|
8222
|
-
chainCode: (0,
|
8223
|
-
privateKey: (0,
|
8470
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8471
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
8224
8472
|
});
|
8225
8473
|
}
|
8226
8474
|
static fromExtendedKey(extendedKey) {
|
8227
8475
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8228
|
-
const bytes = (0,
|
8476
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
8229
8477
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8230
8478
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8231
8479
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8234,9 +8482,9 @@ var HDWallet = class {
|
|
8234
8482
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8235
8483
|
}
|
8236
8484
|
const depth = bytes[4];
|
8237
|
-
const parentFingerprint = (0,
|
8238
|
-
const index = parseInt((0,
|
8239
|
-
const chainCode = (0,
|
8485
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8486
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8487
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
8240
8488
|
const key = bytes.slice(45, 78);
|
8241
8489
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8242
8490
|
throw new import_errors20.FuelError(
|
@@ -8842,18 +9090,18 @@ var import_address10 = require("@fuel-ts/address");
|
|
8842
9090
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8843
9091
|
var import_errors25 = require("@fuel-ts/errors");
|
8844
9092
|
var import_transactions21 = require("@fuel-ts/transactions");
|
8845
|
-
var
|
9093
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8846
9094
|
|
8847
9095
|
// src/predicate/utils/getPredicateRoot.ts
|
8848
9096
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8849
9097
|
var import_merkle = require("@fuel-ts/merkle");
|
8850
|
-
var
|
9098
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8851
9099
|
var getPredicateRoot = (bytecode) => {
|
8852
9100
|
const chunkSize = 16 * 1024;
|
8853
|
-
const bytes = (0,
|
8854
|
-
const chunks = (0,
|
8855
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
8856
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
9101
|
+
const bytes = (0, import_utils35.arrayify)(bytecode);
|
9102
|
+
const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
|
9103
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
|
9104
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
|
8857
9105
|
return predicateRoot;
|
8858
9106
|
};
|
8859
9107
|
|
@@ -8900,15 +9148,10 @@ var Predicate = class extends Account {
|
|
8900
9148
|
populateTransactionPredicateData(transactionRequestLike) {
|
8901
9149
|
const request = transactionRequestify(transactionRequestLike);
|
8902
9150
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8903
|
-
|
8904
|
-
|
8905
|
-
|
8906
|
-
|
8907
|
-
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
8908
|
-
if (isRequestInputResourceFromOwner(input, this.address)) {
|
8909
|
-
input.predicate = this.bytes;
|
8910
|
-
input.predicateData = this.getPredicateData(policies.length);
|
8911
|
-
input.witnessIndex = 0;
|
9151
|
+
request.inputs?.forEach((input) => {
|
9152
|
+
if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
|
9153
|
+
input.predicate = (0, import_utils36.hexlify)(this.bytes);
|
9154
|
+
input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
|
8912
9155
|
}
|
8913
9156
|
});
|
8914
9157
|
return request;
|
@@ -8923,8 +9166,7 @@ var Predicate = class extends Account {
|
|
8923
9166
|
* @returns A promise that resolves to the prepared transaction request.
|
8924
9167
|
*/
|
8925
9168
|
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
8926
|
-
|
8927
|
-
return this.populateTransactionPredicateData(request);
|
9169
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8928
9170
|
}
|
8929
9171
|
/**
|
8930
9172
|
* Sends a transaction with the populated predicate data.
|
@@ -8932,9 +9174,9 @@ var Predicate = class extends Account {
|
|
8932
9174
|
* @param transactionRequestLike - The transaction request-like object.
|
8933
9175
|
* @returns A promise that resolves to the transaction response.
|
8934
9176
|
*/
|
8935
|
-
sendTransaction(transactionRequestLike
|
8936
|
-
const transactionRequest =
|
8937
|
-
return super.sendTransaction(transactionRequest,
|
9177
|
+
sendTransaction(transactionRequestLike) {
|
9178
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9179
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8938
9180
|
}
|
8939
9181
|
/**
|
8940
9182
|
* Simulates a transaction with the populated predicate data.
|
@@ -8943,22 +9185,8 @@ var Predicate = class extends Account {
|
|
8943
9185
|
* @returns A promise that resolves to the call result.
|
8944
9186
|
*/
|
8945
9187
|
simulateTransaction(transactionRequestLike) {
|
8946
|
-
const transactionRequest =
|
8947
|
-
return super.simulateTransaction(transactionRequest);
|
8948
|
-
}
|
8949
|
-
/**
|
8950
|
-
* Retrieves resources satisfying the spend query for the account.
|
8951
|
-
*
|
8952
|
-
* @param quantities - Coins to retrieve.
|
8953
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
8954
|
-
* @returns A promise that resolves to an array of Resources.
|
8955
|
-
*/
|
8956
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
8957
|
-
const resources = await super.getResourcesToSpend(quantities, excludedIds);
|
8958
|
-
return resources.map((resource) => ({
|
8959
|
-
...resource,
|
8960
|
-
predicate: (0, import_utils37.hexlify)(this.bytes)
|
8961
|
-
}));
|
9188
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9189
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8962
9190
|
}
|
8963
9191
|
getPredicateData(policiesLength) {
|
8964
9192
|
if (!this.predicateData.length) {
|
@@ -8981,7 +9209,7 @@ var Predicate = class extends Account {
|
|
8981
9209
|
* @returns An object containing the new predicate bytes and interface.
|
8982
9210
|
*/
|
8983
9211
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
8984
|
-
let predicateBytes = (0,
|
9212
|
+
let predicateBytes = (0, import_utils36.arrayify)(bytes);
|
8985
9213
|
let abiInterface;
|
8986
9214
|
if (jsonAbi) {
|
8987
9215
|
abiInterface = new import_abi_coder7.Interface(jsonAbi);
|
@@ -9004,6 +9232,25 @@ var Predicate = class extends Account {
|
|
9004
9232
|
predicateInterface: abiInterface
|
9005
9233
|
};
|
9006
9234
|
}
|
9235
|
+
/**
|
9236
|
+
* Retrieves resources satisfying the spend query for the account.
|
9237
|
+
*
|
9238
|
+
* @param quantities - IDs of coins to exclude.
|
9239
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9240
|
+
* @returns A promise that resolves to an array of Resources.
|
9241
|
+
*/
|
9242
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9243
|
+
const resources = await this.provider.getResourcesToSpend(
|
9244
|
+
this.address,
|
9245
|
+
quantities,
|
9246
|
+
excludedIds
|
9247
|
+
);
|
9248
|
+
return resources.map((resource) => ({
|
9249
|
+
...resource,
|
9250
|
+
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9251
|
+
paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9252
|
+
}));
|
9253
|
+
}
|
9007
9254
|
/**
|
9008
9255
|
* Sets the configurable constants for the predicate.
|
9009
9256
|
*
|
@@ -9039,28 +9286,6 @@ var Predicate = class extends Account {
|
|
9039
9286
|
}
|
9040
9287
|
return mutatedBytes;
|
9041
9288
|
}
|
9042
|
-
/**
|
9043
|
-
* Returns the index of the witness placeholder that was added to this predicate.
|
9044
|
-
* If no witness placeholder was added, it returns -1.
|
9045
|
-
* @param request - The transaction request.
|
9046
|
-
* @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
|
9047
|
-
*/
|
9048
|
-
getIndexFromPlaceholderWitness(request) {
|
9049
|
-
const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
|
9050
|
-
let index = -1;
|
9051
|
-
const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
|
9052
|
-
if (hasEmptyPredicateInputs) {
|
9053
|
-
index = hasEmptyPredicateInputs.witnessIndex;
|
9054
|
-
const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
|
9055
|
-
if (!allInputsAreEmpty) {
|
9056
|
-
const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
|
9057
|
-
if (wasFilledInputAddedFirst) {
|
9058
|
-
index = -1;
|
9059
|
-
}
|
9060
|
-
}
|
9061
|
-
}
|
9062
|
-
return index;
|
9063
|
-
}
|
9064
9289
|
};
|
9065
9290
|
|
9066
9291
|
// src/connectors/fuel.ts
|
@@ -9775,7 +10000,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9775
10000
|
WalletLocked,
|
9776
10001
|
WalletManager,
|
9777
10002
|
WalletUnlocked,
|
9778
|
-
|
10003
|
+
addAmountToCoinQuantities,
|
9779
10004
|
addOperation,
|
9780
10005
|
assemblePanicError,
|
9781
10006
|
assembleReceiptByType,
|
@@ -9784,10 +10009,10 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9784
10009
|
assets,
|
9785
10010
|
buildBlockExplorerUrl,
|
9786
10011
|
cacheFor,
|
9787
|
-
|
10012
|
+
cacheTxInputsFromOwner,
|
10013
|
+
calculateGasFee,
|
9788
10014
|
calculateMetadataGasForTxCreate,
|
9789
10015
|
calculateMetadataGasForTxScript,
|
9790
|
-
calculatePriceWithFactor,
|
9791
10016
|
calculateTransactionFee,
|
9792
10017
|
coinQuantityfy,
|
9793
10018
|
deferPromise,
|
@@ -9831,7 +10056,6 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9831
10056
|
getReceiptsMessageOut,
|
9832
10057
|
getReceiptsTransferOut,
|
9833
10058
|
getReceiptsWithMissingData,
|
9834
|
-
getRequestInputResourceOwner,
|
9835
10059
|
getTransactionStatusName,
|
9836
10060
|
getTransactionSummary,
|
9837
10061
|
getTransactionSummaryFromRequest,
|
@@ -9845,10 +10069,6 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9845
10069
|
isMessage,
|
9846
10070
|
isRawCoin,
|
9847
10071
|
isRawMessage,
|
9848
|
-
isRequestInputCoin,
|
9849
|
-
isRequestInputMessage,
|
9850
|
-
isRequestInputResource,
|
9851
|
-
isRequestInputResourceFromOwner,
|
9852
10072
|
isType,
|
9853
10073
|
isTypeCreate,
|
9854
10074
|
isTypeMint,
|