@fuel-ts/account 0.82.0 → 0.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +18 -15
- package/dist/account.d.ts +8 -7
- 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 +2445 -2185
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1074 -667
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +909 -505
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +12 -24
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +950 -376
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +9 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +72 -54
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource.d.ts +0 -1
- package/dist/providers/resource.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +8 -0
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
- 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 +2 -3
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +17 -38
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +4 -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 +4 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts +20 -0
- package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts.map +1 -0
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/index.d.ts +1 -1
- package/dist/providers/transaction-summary/index.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +4 -0
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/transaction-summary/status.d.ts +5 -1
- package/dist/providers/transaction-summary/status.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +6 -1
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +14 -7
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/providers/utils/merge-quantities.d.ts +1 -1
- package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/resources.d.ts +4 -0
- package/dist/test-utils/resources.d.ts.map +1 -0
- package/dist/test-utils/transactionRequest.d.ts +5 -0
- package/dist/test-utils/transactionRequest.d.ts.map +1 -0
- package/dist/test-utils.global.js +3171 -2680
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +1046 -655
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +896 -505
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +18 -18
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +0 -21
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -24,37 +24,36 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
31
|
-
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
29
|
+
import { bn as bn20 } from "@fuel-ts/math";
|
30
|
+
import { arrayify as arrayify14, isDefined as isDefined2 } from "@fuel-ts/utils";
|
31
|
+
import { clone as clone4 } from "ramda";
|
32
32
|
|
33
33
|
// src/providers/coin-quantity.ts
|
34
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
35
34
|
import { bn } from "@fuel-ts/math";
|
36
35
|
import { hexlify } from "@fuel-ts/utils";
|
37
36
|
var coinQuantityfy = (coinQuantityLike) => {
|
38
37
|
let assetId;
|
39
38
|
let amount;
|
40
|
-
let
|
39
|
+
let max;
|
41
40
|
if (Array.isArray(coinQuantityLike)) {
|
42
41
|
amount = coinQuantityLike[0];
|
43
|
-
assetId = coinQuantityLike[1]
|
44
|
-
|
42
|
+
assetId = coinQuantityLike[1];
|
43
|
+
max = coinQuantityLike[2] ?? void 0;
|
45
44
|
} else {
|
46
45
|
amount = coinQuantityLike.amount;
|
47
|
-
assetId = coinQuantityLike.assetId
|
48
|
-
|
46
|
+
assetId = coinQuantityLike.assetId;
|
47
|
+
max = coinQuantityLike.max ?? void 0;
|
49
48
|
}
|
50
49
|
const bnAmount = bn(amount);
|
51
50
|
return {
|
52
51
|
assetId: hexlify(assetId),
|
53
52
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
54
|
-
max:
|
53
|
+
max: max ? bn(max) : void 0
|
55
54
|
};
|
56
55
|
};
|
57
|
-
var
|
56
|
+
var addAmountToCoinQuantities = (params) => {
|
58
57
|
const { amount, assetId } = params;
|
59
58
|
const coinQuantities = [...params.coinQuantities];
|
60
59
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -69,9 +68,9 @@ var addAmountToAsset = (params) => {
|
|
69
68
|
// src/providers/provider.ts
|
70
69
|
import { Address as Address2 } from "@fuel-ts/address";
|
71
70
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
72
|
-
import { BN, bn as
|
71
|
+
import { BN, bn as bn17 } from "@fuel-ts/math";
|
73
72
|
import {
|
74
|
-
InputType as
|
73
|
+
InputType as InputType7,
|
75
74
|
TransactionType as TransactionType8,
|
76
75
|
InputMessageCoder,
|
77
76
|
TransactionCoder as TransactionCoder5
|
@@ -79,22 +78,25 @@ import {
|
|
79
78
|
import { arrayify as arrayify11, hexlify as hexlify12, DateTime as DateTime2 } from "@fuel-ts/utils";
|
80
79
|
import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
|
81
80
|
import { equalBytes } from "@noble/curves/abstract/utils";
|
82
|
-
import { Network } from "ethers";
|
83
81
|
import { GraphQLClient } from "graphql-request";
|
84
82
|
import { clone as clone3 } from "ramda";
|
85
83
|
|
86
84
|
// src/providers/__generated__/operations.ts
|
87
85
|
import gql from "graphql-tag";
|
86
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
|
87
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
88
|
+
type: __typename
|
89
|
+
... on SqueezedOutStatus {
|
90
|
+
reason
|
91
|
+
}
|
92
|
+
}
|
93
|
+
`;
|
88
94
|
var ReceiptFragmentFragmentDoc = gql`
|
89
95
|
fragment receiptFragment on Receipt {
|
90
|
-
|
91
|
-
id
|
92
|
-
}
|
96
|
+
id
|
93
97
|
pc
|
94
98
|
is
|
95
|
-
to
|
96
|
-
id
|
97
|
-
}
|
99
|
+
to
|
98
100
|
toAddress
|
99
101
|
amount
|
100
102
|
assetId
|
@@ -136,33 +138,38 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
136
138
|
returnType
|
137
139
|
data
|
138
140
|
}
|
141
|
+
receipts {
|
142
|
+
...receiptFragment
|
143
|
+
}
|
144
|
+
totalGas
|
145
|
+
totalFee
|
139
146
|
}
|
140
147
|
... on FailureStatus {
|
141
148
|
block {
|
142
149
|
id
|
143
150
|
}
|
151
|
+
totalGas
|
152
|
+
totalFee
|
144
153
|
time
|
145
154
|
reason
|
155
|
+
receipts {
|
156
|
+
...receiptFragment
|
157
|
+
}
|
146
158
|
}
|
147
159
|
... on SqueezedOutStatus {
|
148
160
|
reason
|
149
161
|
}
|
150
162
|
}
|
151
|
-
`;
|
163
|
+
${ReceiptFragmentFragmentDoc}`;
|
152
164
|
var TransactionFragmentFragmentDoc = gql`
|
153
165
|
fragment transactionFragment on Transaction {
|
154
166
|
id
|
155
167
|
rawPayload
|
156
|
-
gasPrice
|
157
|
-
receipts {
|
158
|
-
...receiptFragment
|
159
|
-
}
|
160
168
|
status {
|
161
169
|
...transactionStatusFragment
|
162
170
|
}
|
163
171
|
}
|
164
|
-
${
|
165
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
172
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
166
173
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
167
174
|
fragment inputEstimatePredicatesFragment on Input {
|
168
175
|
... on InputCoin {
|
@@ -180,6 +187,50 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
180
187
|
}
|
181
188
|
}
|
182
189
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
190
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
191
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
192
|
+
totalGas
|
193
|
+
totalFee
|
194
|
+
reason
|
195
|
+
programState {
|
196
|
+
returnType
|
197
|
+
data
|
198
|
+
}
|
199
|
+
}
|
200
|
+
`;
|
201
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
202
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
203
|
+
totalGas
|
204
|
+
totalFee
|
205
|
+
programState {
|
206
|
+
returnType
|
207
|
+
data
|
208
|
+
}
|
209
|
+
}
|
210
|
+
`;
|
211
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
212
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
213
|
+
... on DryRunFailureStatus {
|
214
|
+
...dryRunFailureStatusFragment
|
215
|
+
}
|
216
|
+
... on DryRunSuccessStatus {
|
217
|
+
...dryRunSuccessStatusFragment
|
218
|
+
}
|
219
|
+
}
|
220
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
221
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
222
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
223
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
224
|
+
id
|
225
|
+
status {
|
226
|
+
...dryRunTransactionStatusFragment
|
227
|
+
}
|
228
|
+
receipts {
|
229
|
+
...receiptFragment
|
230
|
+
}
|
231
|
+
}
|
232
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
233
|
+
${ReceiptFragmentFragmentDoc}`;
|
183
234
|
var CoinFragmentFragmentDoc = gql`
|
184
235
|
fragment coinFragment on Coin {
|
185
236
|
__typename
|
@@ -187,7 +238,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
187
238
|
owner
|
188
239
|
amount
|
189
240
|
assetId
|
190
|
-
maturity
|
191
241
|
blockCreated
|
192
242
|
txCreatedIdx
|
193
243
|
}
|
@@ -226,26 +276,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
226
276
|
messageBlockHeader {
|
227
277
|
id
|
228
278
|
daHeight
|
279
|
+
consensusParametersVersion
|
280
|
+
stateTransitionBytecodeVersion
|
229
281
|
transactionsCount
|
282
|
+
messageReceiptCount
|
230
283
|
transactionsRoot
|
284
|
+
messageOutboxRoot
|
285
|
+
eventInboxRoot
|
231
286
|
height
|
232
287
|
prevRoot
|
233
288
|
time
|
234
289
|
applicationHash
|
235
|
-
messageReceiptRoot
|
236
|
-
messageReceiptCount
|
237
290
|
}
|
238
291
|
commitBlockHeader {
|
239
292
|
id
|
240
293
|
daHeight
|
294
|
+
consensusParametersVersion
|
295
|
+
stateTransitionBytecodeVersion
|
241
296
|
transactionsCount
|
297
|
+
messageReceiptCount
|
242
298
|
transactionsRoot
|
299
|
+
messageOutboxRoot
|
300
|
+
eventInboxRoot
|
243
301
|
height
|
244
302
|
prevRoot
|
245
303
|
time
|
246
304
|
applicationHash
|
247
|
-
messageReceiptRoot
|
248
|
-
messageReceiptCount
|
249
305
|
}
|
250
306
|
sender
|
251
307
|
recipient
|
@@ -264,8 +320,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
264
320
|
var BlockFragmentFragmentDoc = gql`
|
265
321
|
fragment blockFragment on Block {
|
266
322
|
id
|
323
|
+
height
|
267
324
|
header {
|
268
|
-
height
|
269
325
|
time
|
270
326
|
}
|
271
327
|
transactions {
|
@@ -275,15 +331,18 @@ var BlockFragmentFragmentDoc = gql`
|
|
275
331
|
`;
|
276
332
|
var TxParametersFragmentFragmentDoc = gql`
|
277
333
|
fragment TxParametersFragment on TxParameters {
|
334
|
+
version
|
278
335
|
maxInputs
|
279
336
|
maxOutputs
|
280
337
|
maxWitnesses
|
281
338
|
maxGasPerTx
|
282
339
|
maxSize
|
340
|
+
maxBytecodeSubsections
|
283
341
|
}
|
284
342
|
`;
|
285
343
|
var PredicateParametersFragmentFragmentDoc = gql`
|
286
344
|
fragment PredicateParametersFragment on PredicateParameters {
|
345
|
+
version
|
287
346
|
maxPredicateLength
|
288
347
|
maxPredicateDataLength
|
289
348
|
maxGasPerPredicate
|
@@ -292,18 +351,21 @@ var PredicateParametersFragmentFragmentDoc = gql`
|
|
292
351
|
`;
|
293
352
|
var ScriptParametersFragmentFragmentDoc = gql`
|
294
353
|
fragment ScriptParametersFragment on ScriptParameters {
|
354
|
+
version
|
295
355
|
maxScriptLength
|
296
356
|
maxScriptDataLength
|
297
357
|
}
|
298
358
|
`;
|
299
359
|
var ContractParametersFragmentFragmentDoc = gql`
|
300
360
|
fragment ContractParametersFragment on ContractParameters {
|
361
|
+
version
|
301
362
|
contractMaxSize
|
302
363
|
maxStorageSlots
|
303
364
|
}
|
304
365
|
`;
|
305
366
|
var FeeParametersFragmentFragmentDoc = gql`
|
306
367
|
fragment FeeParametersFragment on FeeParameters {
|
368
|
+
version
|
307
369
|
gasPriceFactor
|
308
370
|
gasPerByte
|
309
371
|
}
|
@@ -323,6 +385,7 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
323
385
|
`;
|
324
386
|
var GasCostsFragmentFragmentDoc = gql`
|
325
387
|
fragment GasCostsFragment on GasCosts {
|
388
|
+
version
|
326
389
|
add
|
327
390
|
addi
|
328
391
|
aloc
|
@@ -335,7 +398,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
335
398
|
cb
|
336
399
|
cfei
|
337
400
|
cfsi
|
338
|
-
croo
|
339
401
|
div
|
340
402
|
divi
|
341
403
|
ecr1
|
@@ -418,6 +480,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
418
480
|
ccp {
|
419
481
|
...DependentCostFragment
|
420
482
|
}
|
483
|
+
croo {
|
484
|
+
...DependentCostFragment
|
485
|
+
}
|
421
486
|
csiz {
|
422
487
|
...DependentCostFragment
|
423
488
|
}
|
@@ -477,6 +542,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
477
542
|
${DependentCostFragmentFragmentDoc}`;
|
478
543
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
479
544
|
fragment consensusParametersFragment on ConsensusParameters {
|
545
|
+
version
|
480
546
|
txParams {
|
481
547
|
...TxParametersFragment
|
482
548
|
}
|
@@ -536,17 +602,16 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
536
602
|
fragment nodeInfoFragment on NodeInfo {
|
537
603
|
utxoValidation
|
538
604
|
vmBacktrace
|
539
|
-
minGasPrice
|
540
605
|
maxTx
|
541
606
|
maxDepth
|
542
607
|
nodeVersion
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
608
|
+
}
|
609
|
+
`;
|
610
|
+
var RelayedTransactionStatusFragmentFragmentDoc = gql`
|
611
|
+
fragment relayedTransactionStatusFragment on RelayedTransactionStatus {
|
612
|
+
... on RelayedTransactionFailed {
|
547
613
|
blockHeight
|
548
|
-
|
549
|
-
appScore
|
614
|
+
failure
|
550
615
|
}
|
551
616
|
}
|
552
617
|
`;
|
@@ -582,13 +647,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
582
647
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
583
648
|
transaction(id: $transactionId) {
|
584
649
|
...transactionFragment
|
585
|
-
receipts {
|
586
|
-
...receiptFragment
|
587
|
-
}
|
588
650
|
}
|
589
651
|
}
|
590
|
-
${TransactionFragmentFragmentDoc}
|
591
|
-
${ReceiptFragmentFragmentDoc}`;
|
652
|
+
${TransactionFragmentFragmentDoc}`;
|
592
653
|
var GetTransactionsDocument = gql`
|
593
654
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
594
655
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -716,6 +777,20 @@ var GetBalanceDocument = gql`
|
|
716
777
|
}
|
717
778
|
}
|
718
779
|
${BalanceFragmentFragmentDoc}`;
|
780
|
+
var GetLatestGasPriceDocument = gql`
|
781
|
+
query getLatestGasPrice {
|
782
|
+
latestGasPrice {
|
783
|
+
gasPrice
|
784
|
+
}
|
785
|
+
}
|
786
|
+
`;
|
787
|
+
var EstimateGasPriceDocument = gql`
|
788
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
789
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
790
|
+
gasPrice
|
791
|
+
}
|
792
|
+
}
|
793
|
+
`;
|
719
794
|
var GetBalancesDocument = gql`
|
720
795
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
721
796
|
balances(
|
@@ -769,13 +844,20 @@ var GetMessageStatusDocument = gql`
|
|
769
844
|
}
|
770
845
|
}
|
771
846
|
`;
|
847
|
+
var GetRelayedTransactionStatusDocument = gql`
|
848
|
+
query getRelayedTransactionStatus($relayedTransactionId: RelayedTransactionId!) {
|
849
|
+
relayedTransactionStatus(id: $relayedTransactionId) {
|
850
|
+
...relayedTransactionStatusFragment
|
851
|
+
}
|
852
|
+
}
|
853
|
+
${RelayedTransactionStatusFragmentFragmentDoc}`;
|
772
854
|
var DryRunDocument = gql`
|
773
|
-
mutation dryRun($
|
774
|
-
dryRun(
|
775
|
-
...
|
855
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
856
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
857
|
+
...dryRunTransactionExecutionStatusFragment
|
776
858
|
}
|
777
859
|
}
|
778
|
-
${
|
860
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
779
861
|
var SubmitDocument = gql`
|
780
862
|
mutation submit($encodedTransaction: HexString!) {
|
781
863
|
submit(tx: $encodedTransaction) {
|
@@ -791,20 +873,27 @@ var ProduceBlocksDocument = gql`
|
|
791
873
|
)
|
792
874
|
}
|
793
875
|
`;
|
876
|
+
var GetMessageByNonceDocument = gql`
|
877
|
+
query getMessageByNonce($nonce: Nonce!) {
|
878
|
+
message(nonce: $nonce) {
|
879
|
+
...messageFragment
|
880
|
+
}
|
881
|
+
}
|
882
|
+
${MessageFragmentFragmentDoc}`;
|
794
883
|
var SubmitAndAwaitDocument = gql`
|
795
884
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
796
885
|
submitAndAwait(tx: $encodedTransaction) {
|
797
|
-
...
|
886
|
+
...transactionStatusSubscriptionFragment
|
798
887
|
}
|
799
888
|
}
|
800
|
-
${
|
889
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
801
890
|
var StatusChangeDocument = gql`
|
802
891
|
subscription statusChange($transactionId: TransactionId!) {
|
803
892
|
statusChange(id: $transactionId) {
|
804
|
-
...
|
893
|
+
...transactionStatusSubscriptionFragment
|
805
894
|
}
|
806
895
|
}
|
807
|
-
${
|
896
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
808
897
|
function getSdk(requester) {
|
809
898
|
return {
|
810
899
|
getVersion(variables, options) {
|
@@ -858,6 +947,12 @@ function getSdk(requester) {
|
|
858
947
|
getBalance(variables, options) {
|
859
948
|
return requester(GetBalanceDocument, variables, options);
|
860
949
|
},
|
950
|
+
getLatestGasPrice(variables, options) {
|
951
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
952
|
+
},
|
953
|
+
estimateGasPrice(variables, options) {
|
954
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
955
|
+
},
|
861
956
|
getBalances(variables, options) {
|
862
957
|
return requester(GetBalancesDocument, variables, options);
|
863
958
|
},
|
@@ -870,6 +965,9 @@ function getSdk(requester) {
|
|
870
965
|
getMessageStatus(variables, options) {
|
871
966
|
return requester(GetMessageStatusDocument, variables, options);
|
872
967
|
},
|
968
|
+
getRelayedTransactionStatus(variables, options) {
|
969
|
+
return requester(GetRelayedTransactionStatusDocument, variables, options);
|
970
|
+
},
|
873
971
|
dryRun(variables, options) {
|
874
972
|
return requester(DryRunDocument, variables, options);
|
875
973
|
},
|
@@ -879,6 +977,9 @@ function getSdk(requester) {
|
|
879
977
|
produceBlocks(variables, options) {
|
880
978
|
return requester(ProduceBlocksDocument, variables, options);
|
881
979
|
},
|
980
|
+
getMessageByNonce(variables, options) {
|
981
|
+
return requester(GetMessageByNonceDocument, variables, options);
|
982
|
+
},
|
882
983
|
submitAndAwait(variables, options) {
|
883
984
|
return requester(SubmitAndAwaitDocument, variables, options);
|
884
985
|
},
|
@@ -1051,10 +1152,9 @@ var inputify = (value) => {
|
|
1051
1152
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1052
1153
|
},
|
1053
1154
|
witnessIndex: value.witnessIndex,
|
1054
|
-
maturity: value.maturity ?? 0,
|
1055
1155
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1056
|
-
predicateLength: predicate.length,
|
1057
|
-
predicateDataLength: predicateData.length,
|
1156
|
+
predicateLength: bn2(predicate.length),
|
1157
|
+
predicateDataLength: bn2(predicateData.length),
|
1058
1158
|
predicate: hexlify3(predicate),
|
1059
1159
|
predicateData: hexlify3(predicateData)
|
1060
1160
|
};
|
@@ -1085,8 +1185,8 @@ var inputify = (value) => {
|
|
1085
1185
|
nonce: hexlify3(value.nonce),
|
1086
1186
|
witnessIndex: value.witnessIndex,
|
1087
1187
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1088
|
-
predicateLength: predicate.length,
|
1089
|
-
predicateDataLength: predicateData.length,
|
1188
|
+
predicateLength: bn2(predicate.length),
|
1189
|
+
predicateDataLength: bn2(predicateData.length),
|
1090
1190
|
predicate: hexlify3(predicate),
|
1091
1191
|
predicateData: hexlify3(predicateData),
|
1092
1192
|
data: hexlify3(data),
|
@@ -1162,7 +1262,7 @@ var outputify = (value) => {
|
|
1162
1262
|
// src/providers/transaction-request/transaction-request.ts
|
1163
1263
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1164
1264
|
import { Address, addressify } from "@fuel-ts/address";
|
1165
|
-
import {
|
1265
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1166
1266
|
import { randomBytes } from "@fuel-ts/crypto";
|
1167
1267
|
import { bn as bn7 } from "@fuel-ts/math";
|
1168
1268
|
import {
|
@@ -1172,7 +1272,7 @@ import {
|
|
1172
1272
|
OutputType as OutputType2,
|
1173
1273
|
TransactionType
|
1174
1274
|
} from "@fuel-ts/transactions";
|
1175
|
-
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1275
|
+
import { concat, hexlify as hexlify7, isDefined } from "@fuel-ts/utils";
|
1176
1276
|
|
1177
1277
|
// src/providers/resource.ts
|
1178
1278
|
var isCoin = (resource) => "id" in resource;
|
@@ -1213,8 +1313,8 @@ function assembleReceiptByType(receipt) {
|
|
1213
1313
|
case "CALL" /* Call */: {
|
1214
1314
|
const callReceipt = {
|
1215
1315
|
type: ReceiptType.Call,
|
1216
|
-
from: hexOrZero(receipt.
|
1217
|
-
to: hexOrZero(receipt?.to
|
1316
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1317
|
+
to: hexOrZero(receipt?.to),
|
1218
1318
|
amount: bn4(receipt.amount),
|
1219
1319
|
assetId: hexOrZero(receipt.assetId),
|
1220
1320
|
gas: bn4(receipt.gas),
|
@@ -1228,7 +1328,7 @@ function assembleReceiptByType(receipt) {
|
|
1228
1328
|
case "RETURN" /* Return */: {
|
1229
1329
|
const returnReceipt = {
|
1230
1330
|
type: ReceiptType.Return,
|
1231
|
-
id: hexOrZero(receipt.
|
1331
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1232
1332
|
val: bn4(receipt.val),
|
1233
1333
|
pc: bn4(receipt.pc),
|
1234
1334
|
is: bn4(receipt.is)
|
@@ -1238,7 +1338,7 @@ function assembleReceiptByType(receipt) {
|
|
1238
1338
|
case "RETURN_DATA" /* ReturnData */: {
|
1239
1339
|
const returnDataReceipt = {
|
1240
1340
|
type: ReceiptType.ReturnData,
|
1241
|
-
id: hexOrZero(receipt.
|
1341
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1242
1342
|
ptr: bn4(receipt.ptr),
|
1243
1343
|
len: bn4(receipt.len),
|
1244
1344
|
digest: hexOrZero(receipt.digest),
|
@@ -1250,7 +1350,7 @@ function assembleReceiptByType(receipt) {
|
|
1250
1350
|
case "PANIC" /* Panic */: {
|
1251
1351
|
const panicReceipt = {
|
1252
1352
|
type: ReceiptType.Panic,
|
1253
|
-
id: hexOrZero(receipt.
|
1353
|
+
id: hexOrZero(receipt.id),
|
1254
1354
|
reason: bn4(receipt.reason),
|
1255
1355
|
pc: bn4(receipt.pc),
|
1256
1356
|
is: bn4(receipt.is),
|
@@ -1261,7 +1361,7 @@ function assembleReceiptByType(receipt) {
|
|
1261
1361
|
case "REVERT" /* Revert */: {
|
1262
1362
|
const revertReceipt = {
|
1263
1363
|
type: ReceiptType.Revert,
|
1264
|
-
id: hexOrZero(receipt.
|
1364
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1265
1365
|
val: bn4(receipt.ra),
|
1266
1366
|
pc: bn4(receipt.pc),
|
1267
1367
|
is: bn4(receipt.is)
|
@@ -1271,7 +1371,7 @@ function assembleReceiptByType(receipt) {
|
|
1271
1371
|
case "LOG" /* Log */: {
|
1272
1372
|
const logReceipt = {
|
1273
1373
|
type: ReceiptType.Log,
|
1274
|
-
id: hexOrZero(receipt.
|
1374
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1275
1375
|
val0: bn4(receipt.ra),
|
1276
1376
|
val1: bn4(receipt.rb),
|
1277
1377
|
val2: bn4(receipt.rc),
|
@@ -1284,7 +1384,7 @@ function assembleReceiptByType(receipt) {
|
|
1284
1384
|
case "LOG_DATA" /* LogData */: {
|
1285
1385
|
const logDataReceipt = {
|
1286
1386
|
type: ReceiptType.LogData,
|
1287
|
-
id: hexOrZero(receipt.
|
1387
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1288
1388
|
val0: bn4(receipt.ra),
|
1289
1389
|
val1: bn4(receipt.rb),
|
1290
1390
|
ptr: bn4(receipt.ptr),
|
@@ -1298,8 +1398,8 @@ function assembleReceiptByType(receipt) {
|
|
1298
1398
|
case "TRANSFER" /* Transfer */: {
|
1299
1399
|
const transferReceipt = {
|
1300
1400
|
type: ReceiptType.Transfer,
|
1301
|
-
from: hexOrZero(receipt.
|
1302
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1401
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1402
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1303
1403
|
amount: bn4(receipt.amount),
|
1304
1404
|
assetId: hexOrZero(receipt.assetId),
|
1305
1405
|
pc: bn4(receipt.pc),
|
@@ -1310,8 +1410,8 @@ function assembleReceiptByType(receipt) {
|
|
1310
1410
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1311
1411
|
const transferOutReceipt = {
|
1312
1412
|
type: ReceiptType.TransferOut,
|
1313
|
-
from: hexOrZero(receipt.
|
1314
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1413
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1414
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1315
1415
|
amount: bn4(receipt.amount),
|
1316
1416
|
assetId: hexOrZero(receipt.assetId),
|
1317
1417
|
pc: bn4(receipt.pc),
|
@@ -1354,7 +1454,7 @@ function assembleReceiptByType(receipt) {
|
|
1354
1454
|
return receiptMessageOut;
|
1355
1455
|
}
|
1356
1456
|
case "MINT" /* Mint */: {
|
1357
|
-
const contractId = hexOrZero(receipt.
|
1457
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1358
1458
|
const subId = hexOrZero(receipt.subId);
|
1359
1459
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1360
1460
|
const mintReceipt = {
|
@@ -1369,7 +1469,7 @@ function assembleReceiptByType(receipt) {
|
|
1369
1469
|
return mintReceipt;
|
1370
1470
|
}
|
1371
1471
|
case "BURN" /* Burn */: {
|
1372
|
-
const contractId = hexOrZero(receipt.
|
1472
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1373
1473
|
const subId = hexOrZero(receipt.subId);
|
1374
1474
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1375
1475
|
const burnReceipt = {
|
@@ -1395,7 +1495,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1395
1495
|
import { bn as bn5 } from "@fuel-ts/math";
|
1396
1496
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1397
1497
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1398
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1399
1498
|
var getGasUsedFromReceipts = (receipts) => {
|
1400
1499
|
const scriptResult = receipts.filter(
|
1401
1500
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1416,18 +1515,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1416
1515
|
}
|
1417
1516
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1418
1517
|
const witnessCache = [];
|
1419
|
-
const
|
1518
|
+
const chargeableInputs = inputs.filter((input) => {
|
1519
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1520
|
+
if (isCoinOrMessage) {
|
1521
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1522
|
+
return true;
|
1523
|
+
}
|
1524
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1525
|
+
witnessCache.push(input.witnessIndex);
|
1526
|
+
return true;
|
1527
|
+
}
|
1528
|
+
}
|
1529
|
+
return false;
|
1530
|
+
});
|
1531
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1532
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1420
1533
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1421
1534
|
return total.add(
|
1422
|
-
|
1535
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1423
1536
|
);
|
1424
1537
|
}
|
1425
|
-
|
1426
|
-
|
1427
|
-
return total.add(gasCosts.ecr1);
|
1428
|
-
}
|
1429
|
-
return total;
|
1430
|
-
}, bn5());
|
1538
|
+
return total.add(gasCosts.ecr1);
|
1539
|
+
}, bn5(0));
|
1431
1540
|
return totalGas;
|
1432
1541
|
}
|
1433
1542
|
function getMinGas(params) {
|
@@ -1439,12 +1548,20 @@ function getMinGas(params) {
|
|
1439
1548
|
return minGas;
|
1440
1549
|
}
|
1441
1550
|
function getMaxGas(params) {
|
1442
|
-
const {
|
1551
|
+
const {
|
1552
|
+
gasPerByte,
|
1553
|
+
witnessesLength,
|
1554
|
+
witnessLimit,
|
1555
|
+
minGas,
|
1556
|
+
gasLimit = bn5(0),
|
1557
|
+
maxGasPerTx
|
1558
|
+
} = params;
|
1443
1559
|
let remainingAllowedWitnessGas = bn5(0);
|
1444
1560
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1445
1561
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1446
1562
|
}
|
1447
|
-
|
1563
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1564
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1448
1565
|
}
|
1449
1566
|
function calculateMetadataGasForTxCreate({
|
1450
1567
|
gasCosts,
|
@@ -1466,6 +1583,10 @@ function calculateMetadataGasForTxScript({
|
|
1466
1583
|
}) {
|
1467
1584
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1468
1585
|
}
|
1586
|
+
var calculateGasFee = (params) => {
|
1587
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1588
|
+
return gas.mul(gasPrice).div(priceFactor).add(bn5(tip));
|
1589
|
+
};
|
1469
1590
|
|
1470
1591
|
// src/providers/utils/json.ts
|
1471
1592
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1610,7 +1731,7 @@ var witnessify = (value) => {
|
|
1610
1731
|
// src/providers/transaction-request/transaction-request.ts
|
1611
1732
|
var BaseTransactionRequest = class {
|
1612
1733
|
/** Gas price for transaction */
|
1613
|
-
|
1734
|
+
tip;
|
1614
1735
|
/** Block until which tx cannot be included */
|
1615
1736
|
maturity;
|
1616
1737
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1629,7 +1750,7 @@ var BaseTransactionRequest = class {
|
|
1629
1750
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1630
1751
|
*/
|
1631
1752
|
constructor({
|
1632
|
-
|
1753
|
+
tip,
|
1633
1754
|
maturity,
|
1634
1755
|
maxFee,
|
1635
1756
|
witnessLimit,
|
@@ -1637,10 +1758,10 @@ var BaseTransactionRequest = class {
|
|
1637
1758
|
outputs,
|
1638
1759
|
witnesses
|
1639
1760
|
} = {}) {
|
1640
|
-
this.
|
1641
|
-
this.maturity = maturity
|
1642
|
-
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1643
|
-
this.maxFee =
|
1761
|
+
this.tip = tip ? bn7(tip) : void 0;
|
1762
|
+
this.maturity = maturity && maturity > 0 ? maturity : void 0;
|
1763
|
+
this.witnessLimit = isDefined(witnessLimit) ? bn7(witnessLimit) : void 0;
|
1764
|
+
this.maxFee = bn7(maxFee);
|
1644
1765
|
this.inputs = inputs ?? [];
|
1645
1766
|
this.outputs = outputs ?? [];
|
1646
1767
|
this.witnesses = witnesses ?? [];
|
@@ -1648,22 +1769,21 @@ var BaseTransactionRequest = class {
|
|
1648
1769
|
static getPolicyMeta(req) {
|
1649
1770
|
let policyTypes = 0;
|
1650
1771
|
const policies = [];
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1772
|
+
const { tip, witnessLimit, maturity } = req;
|
1773
|
+
if (bn7(tip).gt(0)) {
|
1774
|
+
policyTypes += PolicyType.Tip;
|
1775
|
+
policies.push({ data: bn7(tip), type: PolicyType.Tip });
|
1654
1776
|
}
|
1655
|
-
if (
|
1777
|
+
if (isDefined(witnessLimit) && bn7(witnessLimit).gte(0)) {
|
1656
1778
|
policyTypes += PolicyType.WitnessLimit;
|
1657
|
-
policies.push({ data:
|
1779
|
+
policies.push({ data: bn7(witnessLimit), type: PolicyType.WitnessLimit });
|
1658
1780
|
}
|
1659
|
-
if (
|
1781
|
+
if (maturity && maturity > 0) {
|
1660
1782
|
policyTypes += PolicyType.Maturity;
|
1661
|
-
policies.push({ data:
|
1662
|
-
}
|
1663
|
-
if (req.maxFee) {
|
1664
|
-
policyTypes += PolicyType.MaxFee;
|
1665
|
-
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
|
1783
|
+
policies.push({ data: maturity, type: PolicyType.Maturity });
|
1666
1784
|
}
|
1785
|
+
policyTypes += PolicyType.MaxFee;
|
1786
|
+
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
|
1667
1787
|
return {
|
1668
1788
|
policyTypes,
|
1669
1789
|
policies
|
@@ -1834,13 +1954,11 @@ var BaseTransactionRequest = class {
|
|
1834
1954
|
* assetId, if one it was not added yet.
|
1835
1955
|
*
|
1836
1956
|
* @param coin - Coin resource.
|
1837
|
-
* @param predicate - Predicate bytes.
|
1838
|
-
* @param predicateData - Predicate data bytes.
|
1839
1957
|
*/
|
1840
|
-
addCoinInput(coin
|
1958
|
+
addCoinInput(coin) {
|
1841
1959
|
const { assetId, owner, amount } = coin;
|
1842
1960
|
let witnessIndex;
|
1843
|
-
if (predicate) {
|
1961
|
+
if (coin.predicate) {
|
1844
1962
|
witnessIndex = 0;
|
1845
1963
|
} else {
|
1846
1964
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1855,25 +1973,21 @@ var BaseTransactionRequest = class {
|
|
1855
1973
|
amount,
|
1856
1974
|
assetId,
|
1857
1975
|
txPointer: "0x00000000000000000000000000000000",
|
1858
|
-
witnessIndex
|
1859
|
-
predicate: predicate?.bytes
|
1976
|
+
witnessIndex
|
1860
1977
|
};
|
1861
1978
|
this.pushInput(input);
|
1862
1979
|
this.addChangeOutput(owner, assetId);
|
1863
1980
|
}
|
1864
1981
|
/**
|
1865
1982
|
* Adds a single message input to the transaction and a change output for the
|
1866
|
-
*
|
1983
|
+
* asset against the message
|
1867
1984
|
*
|
1868
1985
|
* @param message - Message resource.
|
1869
|
-
* @param predicate - Predicate bytes.
|
1870
|
-
* @param predicateData - Predicate data bytes.
|
1871
1986
|
*/
|
1872
|
-
addMessageInput(message
|
1873
|
-
const { recipient, sender, amount } = message;
|
1874
|
-
const assetId = BaseAssetId2;
|
1987
|
+
addMessageInput(message) {
|
1988
|
+
const { recipient, sender, amount, assetId } = message;
|
1875
1989
|
let witnessIndex;
|
1876
|
-
if (predicate) {
|
1990
|
+
if (message.predicate) {
|
1877
1991
|
witnessIndex = 0;
|
1878
1992
|
} else {
|
1879
1993
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1887,8 +2001,7 @@ var BaseTransactionRequest = class {
|
|
1887
2001
|
sender: sender.toB256(),
|
1888
2002
|
recipient: recipient.toB256(),
|
1889
2003
|
amount,
|
1890
|
-
witnessIndex
|
1891
|
-
predicate: predicate?.bytes
|
2004
|
+
witnessIndex
|
1892
2005
|
};
|
1893
2006
|
this.pushInput(input);
|
1894
2007
|
this.addChangeOutput(recipient, assetId);
|
@@ -1919,32 +2032,6 @@ var BaseTransactionRequest = class {
|
|
1919
2032
|
resources.forEach((resource) => this.addResource(resource));
|
1920
2033
|
return this;
|
1921
2034
|
}
|
1922
|
-
/**
|
1923
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1924
|
-
* outputs from the related assetIds.
|
1925
|
-
*
|
1926
|
-
* @param resources - The resources to add.
|
1927
|
-
* @returns This transaction.
|
1928
|
-
*/
|
1929
|
-
addPredicateResource(resource, predicate) {
|
1930
|
-
if (isCoin(resource)) {
|
1931
|
-
this.addCoinInput(resource, predicate);
|
1932
|
-
} else {
|
1933
|
-
this.addMessageInput(resource, predicate);
|
1934
|
-
}
|
1935
|
-
return this;
|
1936
|
-
}
|
1937
|
-
/**
|
1938
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1939
|
-
* from the related assetIds.
|
1940
|
-
*
|
1941
|
-
* @param resources - The resources to add.
|
1942
|
-
* @returns This transaction.
|
1943
|
-
*/
|
1944
|
-
addPredicateResources(resources, predicate) {
|
1945
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1946
|
-
return this;
|
1947
|
-
}
|
1948
2035
|
/**
|
1949
2036
|
* Adds a coin output to the transaction.
|
1950
2037
|
*
|
@@ -1952,7 +2039,7 @@ var BaseTransactionRequest = class {
|
|
1952
2039
|
* @param amount - Amount of coin.
|
1953
2040
|
* @param assetId - Asset ID of coin.
|
1954
2041
|
*/
|
1955
|
-
addCoinOutput(to, amount, assetId
|
2042
|
+
addCoinOutput(to, amount, assetId) {
|
1956
2043
|
this.pushOutput({
|
1957
2044
|
type: OutputType2.Coin,
|
1958
2045
|
to: addressify(to).toB256(),
|
@@ -1984,7 +2071,7 @@ var BaseTransactionRequest = class {
|
|
1984
2071
|
* @param to - Address of the owner.
|
1985
2072
|
* @param assetId - Asset ID of coin.
|
1986
2073
|
*/
|
1987
|
-
addChangeOutput(to, assetId
|
2074
|
+
addChangeOutput(to, assetId) {
|
1988
2075
|
const changeOutput = this.getChangeOutputs().find(
|
1989
2076
|
(output) => hexlify7(output.assetId) === assetId
|
1990
2077
|
);
|
@@ -2012,8 +2099,11 @@ var BaseTransactionRequest = class {
|
|
2012
2099
|
* @hidden
|
2013
2100
|
*/
|
2014
2101
|
calculateMinGas(chainInfo) {
|
2015
|
-
const {
|
2016
|
-
const {
|
2102
|
+
const { consensusParameters } = chainInfo;
|
2103
|
+
const {
|
2104
|
+
gasCosts,
|
2105
|
+
feeParameters: { gasPerByte }
|
2106
|
+
} = consensusParameters;
|
2017
2107
|
return getMinGas({
|
2018
2108
|
gasPerByte,
|
2019
2109
|
gasCosts,
|
@@ -2024,7 +2114,10 @@ var BaseTransactionRequest = class {
|
|
2024
2114
|
}
|
2025
2115
|
calculateMaxGas(chainInfo, minGas) {
|
2026
2116
|
const { consensusParameters } = chainInfo;
|
2027
|
-
const {
|
2117
|
+
const {
|
2118
|
+
feeParameters: { gasPerByte },
|
2119
|
+
txParameters: { maxGasPerTx }
|
2120
|
+
} = consensusParameters;
|
2028
2121
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2029
2122
|
(acc, wit) => acc + wit.dataLength,
|
2030
2123
|
0
|
@@ -2033,7 +2126,8 @@ var BaseTransactionRequest = class {
|
|
2033
2126
|
gasPerByte,
|
2034
2127
|
minGas,
|
2035
2128
|
witnessesLength,
|
2036
|
-
witnessLimit: this.witnessLimit
|
2129
|
+
witnessLimit: this.witnessLimit,
|
2130
|
+
maxGasPerTx
|
2037
2131
|
});
|
2038
2132
|
}
|
2039
2133
|
/**
|
@@ -2041,8 +2135,9 @@ var BaseTransactionRequest = class {
|
|
2041
2135
|
* quantities array.
|
2042
2136
|
*
|
2043
2137
|
* @param quantities - CoinQuantity Array.
|
2138
|
+
* @param baseAssetId - The base asset to fund the transaction.
|
2044
2139
|
*/
|
2045
|
-
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2140
|
+
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2046
2141
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2047
2142
|
if ("assetId" in input) {
|
2048
2143
|
return input.assetId === assetId;
|
@@ -2051,24 +2146,27 @@ var BaseTransactionRequest = class {
|
|
2051
2146
|
});
|
2052
2147
|
const updateAssetInput = (assetId, quantity) => {
|
2053
2148
|
const assetInput = findAssetInput(assetId);
|
2149
|
+
let usedQuantity = quantity;
|
2150
|
+
if (assetId === baseAssetId) {
|
2151
|
+
usedQuantity = bn7("1000000000000000000");
|
2152
|
+
}
|
2054
2153
|
if (assetInput && "assetId" in assetInput) {
|
2055
2154
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2056
|
-
assetInput.amount =
|
2155
|
+
assetInput.amount = usedQuantity;
|
2057
2156
|
} else {
|
2058
2157
|
this.addResources([
|
2059
2158
|
{
|
2060
2159
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2061
|
-
amount:
|
2160
|
+
amount: usedQuantity,
|
2062
2161
|
assetId,
|
2063
2162
|
owner: resourcesOwner || Address.fromRandom(),
|
2064
|
-
maturity: 0,
|
2065
2163
|
blockCreated: bn7(1),
|
2066
2164
|
txCreatedIdx: bn7(1)
|
2067
2165
|
}
|
2068
2166
|
]);
|
2069
2167
|
}
|
2070
2168
|
};
|
2071
|
-
updateAssetInput(
|
2169
|
+
updateAssetInput(baseAssetId, bn7(1e11));
|
2072
2170
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2073
2171
|
}
|
2074
2172
|
/**
|
@@ -2093,7 +2191,7 @@ var BaseTransactionRequest = class {
|
|
2093
2191
|
toJSON() {
|
2094
2192
|
return normalizeJSON(this);
|
2095
2193
|
}
|
2096
|
-
|
2194
|
+
updatePredicateGasUsed(inputs) {
|
2097
2195
|
this.inputs.forEach((i) => {
|
2098
2196
|
let correspondingInput;
|
2099
2197
|
switch (i.type) {
|
@@ -2115,6 +2213,15 @@ var BaseTransactionRequest = class {
|
|
2115
2213
|
}
|
2116
2214
|
});
|
2117
2215
|
}
|
2216
|
+
shiftPredicateData() {
|
2217
|
+
this.inputs.forEach((input) => {
|
2218
|
+
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2219
|
+
input.predicateData = input.padPredicateData(
|
2220
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2221
|
+
);
|
2222
|
+
}
|
2223
|
+
});
|
2224
|
+
}
|
2118
2225
|
};
|
2119
2226
|
|
2120
2227
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2238,12 +2345,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2238
2345
|
*
|
2239
2346
|
* @param createTransactionRequestLike - The initial values for the instance
|
2240
2347
|
*/
|
2241
|
-
constructor({
|
2242
|
-
bytecodeWitnessIndex,
|
2243
|
-
salt,
|
2244
|
-
storageSlots,
|
2245
|
-
...rest
|
2246
|
-
} = {}) {
|
2348
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2247
2349
|
super(rest);
|
2248
2350
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2249
2351
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2261,9 +2363,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2261
2363
|
return {
|
2262
2364
|
type: TransactionType3.Create,
|
2263
2365
|
...baseTransaction,
|
2264
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2265
2366
|
bytecodeWitnessIndex,
|
2266
|
-
storageSlotsCount: storageSlots.length,
|
2367
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2267
2368
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2268
2369
|
storageSlots
|
2269
2370
|
};
|
@@ -2386,8 +2487,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2386
2487
|
type: TransactionType4.Script,
|
2387
2488
|
scriptGasLimit: this.gasLimit,
|
2388
2489
|
...super.getBaseTransaction(),
|
2389
|
-
scriptLength: script.length,
|
2390
|
-
scriptDataLength: scriptData.length,
|
2490
|
+
scriptLength: bn10(script.length),
|
2491
|
+
scriptDataLength: bn10(scriptData.length),
|
2391
2492
|
receiptsRoot: ZeroBytes327,
|
2392
2493
|
script: hexlify10(script),
|
2393
2494
|
scriptData: hexlify10(scriptData)
|
@@ -2451,7 +2552,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2451
2552
|
}
|
2452
2553
|
calculateMaxGas(chainInfo, minGas) {
|
2453
2554
|
const { consensusParameters } = chainInfo;
|
2454
|
-
const {
|
2555
|
+
const {
|
2556
|
+
feeParameters: { gasPerByte },
|
2557
|
+
txParameters: { maxGasPerTx }
|
2558
|
+
} = consensusParameters;
|
2455
2559
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2456
2560
|
(acc, wit) => acc + wit.dataLength,
|
2457
2561
|
0
|
@@ -2461,7 +2565,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2461
2565
|
minGas,
|
2462
2566
|
witnessesLength,
|
2463
2567
|
witnessLimit: this.witnessLimit,
|
2464
|
-
gasLimit: this.gasLimit
|
2568
|
+
gasLimit: this.gasLimit,
|
2569
|
+
maxGasPerTx
|
2465
2570
|
});
|
2466
2571
|
}
|
2467
2572
|
/**
|
@@ -2518,7 +2623,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2518
2623
|
|
2519
2624
|
// src/providers/transaction-request/utils.ts
|
2520
2625
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2521
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2626
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2522
2627
|
var transactionRequestify = (obj) => {
|
2523
2628
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2524
2629
|
return obj;
|
@@ -2536,41 +2641,58 @@ var transactionRequestify = (obj) => {
|
|
2536
2641
|
}
|
2537
2642
|
}
|
2538
2643
|
};
|
2644
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2645
|
+
(acc, input) => {
|
2646
|
+
if (input.type === InputType5.Coin && input.owner === owner.toB256()) {
|
2647
|
+
acc.utxos.push(input.id);
|
2648
|
+
}
|
2649
|
+
if (input.type === InputType5.Message && input.recipient === owner.toB256()) {
|
2650
|
+
acc.messages.push(input.nonce);
|
2651
|
+
}
|
2652
|
+
return acc;
|
2653
|
+
},
|
2654
|
+
{
|
2655
|
+
utxos: [],
|
2656
|
+
messages: []
|
2657
|
+
}
|
2658
|
+
);
|
2539
2659
|
|
2540
2660
|
// src/providers/transaction-response/transaction-response.ts
|
2541
2661
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2542
|
-
import { bn as
|
2662
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
2543
2663
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2544
2664
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2545
2665
|
|
2546
2666
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2667
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2668
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2547
2669
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2548
2670
|
|
2549
|
-
// src/providers/transaction-summary/calculate-
|
2671
|
+
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
2550
2672
|
import { bn as bn11 } from "@fuel-ts/math";
|
2551
2673
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2552
2674
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2553
|
-
var
|
2675
|
+
var calculateTXFeeForSummary = (params) => {
|
2554
2676
|
const {
|
2555
|
-
|
2677
|
+
gasPrice,
|
2556
2678
|
rawPayload,
|
2557
|
-
|
2679
|
+
tip,
|
2680
|
+
totalFee,
|
2681
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2558
2682
|
} = params;
|
2683
|
+
if (totalFee) {
|
2684
|
+
return totalFee;
|
2685
|
+
}
|
2559
2686
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2560
2687
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
2561
2688
|
const transactionBytes = arrayify9(rawPayload);
|
2562
2689
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2563
|
-
if (transaction.type === TransactionType6.Mint) {
|
2564
|
-
return {
|
2565
|
-
fee: bn11(0),
|
2566
|
-
minFee: bn11(0),
|
2567
|
-
maxFee: bn11(0),
|
2568
|
-
feeFromGasUsed: bn11(0)
|
2569
|
-
};
|
2570
|
-
}
|
2571
2690
|
const { type, witnesses, inputs, policies } = transaction;
|
2572
2691
|
let metadataGas = bn11(0);
|
2573
2692
|
let gasLimit = bn11(0);
|
2693
|
+
if (type !== TransactionType6.Create && type !== TransactionType6.Script) {
|
2694
|
+
return bn11(0);
|
2695
|
+
}
|
2574
2696
|
if (type === TransactionType6.Create) {
|
2575
2697
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2576
2698
|
const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
@@ -2597,7 +2719,6 @@ var calculateTransactionFee = (params) => {
|
|
2597
2719
|
metadataGas,
|
2598
2720
|
txBytesSize: transactionBytes.length
|
2599
2721
|
});
|
2600
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2601
2722
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2602
2723
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2603
2724
|
const maxGas = getMaxGas({
|
@@ -2605,18 +2726,16 @@ var calculateTransactionFee = (params) => {
|
|
2605
2726
|
minGas,
|
2606
2727
|
witnessesLength,
|
2607
2728
|
gasLimit,
|
2608
|
-
witnessLimit
|
2729
|
+
witnessLimit,
|
2730
|
+
maxGasPerTx
|
2609
2731
|
});
|
2610
|
-
const
|
2611
|
-
|
2612
|
-
|
2613
|
-
|
2614
|
-
|
2615
|
-
|
2616
|
-
|
2617
|
-
maxFee,
|
2618
|
-
feeFromGasUsed
|
2619
|
-
};
|
2732
|
+
const maxFee = calculateGasFee({
|
2733
|
+
gasPrice,
|
2734
|
+
gas: maxGas,
|
2735
|
+
priceFactor: gasPriceFactor,
|
2736
|
+
tip
|
2737
|
+
});
|
2738
|
+
return maxFee;
|
2620
2739
|
};
|
2621
2740
|
|
2622
2741
|
// src/providers/transaction-summary/operations.ts
|
@@ -2671,7 +2790,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2671
2790
|
|
2672
2791
|
// src/providers/transaction-summary/input.ts
|
2673
2792
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2674
|
-
import { InputType as
|
2793
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2675
2794
|
function getInputsByTypes(inputs, types) {
|
2676
2795
|
return inputs.filter((i) => types.includes(i.type));
|
2677
2796
|
}
|
@@ -2679,16 +2798,16 @@ function getInputsByType(inputs, type) {
|
|
2679
2798
|
return inputs.filter((i) => i.type === type);
|
2680
2799
|
}
|
2681
2800
|
function getInputsCoin(inputs) {
|
2682
|
-
return getInputsByType(inputs,
|
2801
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2683
2802
|
}
|
2684
2803
|
function getInputsMessage(inputs) {
|
2685
|
-
return getInputsByType(inputs,
|
2804
|
+
return getInputsByType(inputs, InputType6.Message);
|
2686
2805
|
}
|
2687
2806
|
function getInputsCoinAndMessage(inputs) {
|
2688
|
-
return getInputsByTypes(inputs, [
|
2807
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2689
2808
|
}
|
2690
2809
|
function getInputsContract(inputs) {
|
2691
|
-
return getInputsByType(inputs,
|
2810
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2692
2811
|
}
|
2693
2812
|
function getInputFromAssetId(inputs, assetId) {
|
2694
2813
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2707,7 +2826,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2707
2826
|
if (!contractInput) {
|
2708
2827
|
return void 0;
|
2709
2828
|
}
|
2710
|
-
if (contractInput.type !==
|
2829
|
+
if (contractInput.type !== InputType6.Contract) {
|
2711
2830
|
throw new FuelError9(
|
2712
2831
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2713
2832
|
`Contract input should be of type 'contract'.`
|
@@ -2716,10 +2835,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2716
2835
|
return contractInput;
|
2717
2836
|
}
|
2718
2837
|
function getInputAccountAddress(input) {
|
2719
|
-
if (input.type ===
|
2838
|
+
if (input.type === InputType6.Coin) {
|
2720
2839
|
return input.owner.toString();
|
2721
2840
|
}
|
2722
|
-
if (input.type ===
|
2841
|
+
if (input.type === InputType6.Message) {
|
2723
2842
|
return input.recipient.toString();
|
2724
2843
|
}
|
2725
2844
|
return "";
|
@@ -2775,6 +2894,12 @@ function isTypeCreate(transactionType) {
|
|
2775
2894
|
function isTypeScript(transactionType) {
|
2776
2895
|
return isType(transactionType, "Script" /* Script */);
|
2777
2896
|
}
|
2897
|
+
function isTypeUpgrade(transactionType) {
|
2898
|
+
return isType(transactionType, "Upgrade" /* Upgrade */);
|
2899
|
+
}
|
2900
|
+
function isTypeUpload(transactionType) {
|
2901
|
+
return isType(transactionType, "Upload" /* Upload */);
|
2902
|
+
}
|
2778
2903
|
function getReceiptsCall(receipts) {
|
2779
2904
|
return getReceiptsByType(receipts, ReceiptType4.Call);
|
2780
2905
|
}
|
@@ -3115,6 +3240,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3115
3240
|
|
3116
3241
|
// src/providers/transaction-summary/status.ts
|
3117
3242
|
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3243
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
3118
3244
|
var getTransactionStatusName = (gqlStatus) => {
|
3119
3245
|
switch (gqlStatus) {
|
3120
3246
|
case "FailureStatus":
|
@@ -3136,6 +3262,8 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
3136
3262
|
let time;
|
3137
3263
|
let blockId;
|
3138
3264
|
let status;
|
3265
|
+
let totalFee;
|
3266
|
+
let totalGas;
|
3139
3267
|
let isStatusFailure = false;
|
3140
3268
|
let isStatusSuccess = false;
|
3141
3269
|
let isStatusPending = false;
|
@@ -3146,11 +3274,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
3146
3274
|
time = gqlTransactionStatus.time;
|
3147
3275
|
blockId = gqlTransactionStatus.block.id;
|
3148
3276
|
isStatusSuccess = true;
|
3277
|
+
totalFee = bn14(gqlTransactionStatus.totalFee);
|
3278
|
+
totalGas = bn14(gqlTransactionStatus.totalGas);
|
3149
3279
|
break;
|
3150
3280
|
case "FailureStatus":
|
3151
3281
|
time = gqlTransactionStatus.time;
|
3152
3282
|
blockId = gqlTransactionStatus.block.id;
|
3153
3283
|
isStatusFailure = true;
|
3284
|
+
totalFee = bn14(gqlTransactionStatus.totalFee);
|
3285
|
+
totalGas = bn14(gqlTransactionStatus.totalGas);
|
3154
3286
|
break;
|
3155
3287
|
case "SubmittedStatus":
|
3156
3288
|
time = gqlTransactionStatus.time;
|
@@ -3163,6 +3295,8 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
3163
3295
|
time,
|
3164
3296
|
blockId,
|
3165
3297
|
status,
|
3298
|
+
totalFee,
|
3299
|
+
totalGas,
|
3166
3300
|
isStatusFailure,
|
3167
3301
|
isStatusSuccess,
|
3168
3302
|
isStatusPending
|
@@ -3182,7 +3316,9 @@ function assembleTransactionSummary(params) {
|
|
3182
3316
|
gqlTransactionStatus,
|
3183
3317
|
abiMap = {},
|
3184
3318
|
maxInputs,
|
3185
|
-
gasCosts
|
3319
|
+
gasCosts,
|
3320
|
+
maxGasPerTx,
|
3321
|
+
gasPrice
|
3186
3322
|
} = params;
|
3187
3323
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3188
3324
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3196,18 +3332,22 @@ function assembleTransactionSummary(params) {
|
|
3196
3332
|
maxInputs
|
3197
3333
|
});
|
3198
3334
|
const typeName = getTransactionTypeName(transaction.type);
|
3199
|
-
const
|
3200
|
-
|
3335
|
+
const tip = bn15(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3336
|
+
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
3337
|
+
const fee = calculateTXFeeForSummary({
|
3338
|
+
totalFee,
|
3339
|
+
gasPrice,
|
3201
3340
|
rawPayload,
|
3341
|
+
tip,
|
3202
3342
|
consensusParameters: {
|
3203
3343
|
gasCosts,
|
3344
|
+
maxGasPerTx,
|
3204
3345
|
feeParams: {
|
3205
3346
|
gasPerByte,
|
3206
3347
|
gasPriceFactor
|
3207
3348
|
}
|
3208
3349
|
}
|
3209
3350
|
});
|
3210
|
-
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time } = processGraphqlStatus(gqlTransactionStatus);
|
3211
3351
|
const mintedAssets = extractMintedAssetsFromReceipts(receipts);
|
3212
3352
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3213
3353
|
let date;
|
@@ -3216,6 +3356,7 @@ function assembleTransactionSummary(params) {
|
|
3216
3356
|
}
|
3217
3357
|
const transactionSummary = {
|
3218
3358
|
id,
|
3359
|
+
tip,
|
3219
3360
|
fee,
|
3220
3361
|
gasUsed,
|
3221
3362
|
operations,
|
@@ -3229,6 +3370,8 @@ function assembleTransactionSummary(params) {
|
|
3229
3370
|
isTypeMint: isTypeMint(transaction.type),
|
3230
3371
|
isTypeCreate: isTypeCreate(transaction.type),
|
3231
3372
|
isTypeScript: isTypeScript(transaction.type),
|
3373
|
+
isTypeUpgrade: isTypeUpgrade(transaction.type),
|
3374
|
+
isTypeUpload: isTypeUpload(transaction.type),
|
3232
3375
|
isStatusFailure,
|
3233
3376
|
isStatusSuccess,
|
3234
3377
|
isStatusPending,
|
@@ -3260,7 +3403,7 @@ var TransactionResponse = class {
|
|
3260
3403
|
/** Current provider */
|
3261
3404
|
provider;
|
3262
3405
|
/** Gas used on the transaction */
|
3263
|
-
gasUsed =
|
3406
|
+
gasUsed = bn16(0);
|
3264
3407
|
/** The graphql Transaction with receipts object. */
|
3265
3408
|
gqlTransaction;
|
3266
3409
|
abis;
|
@@ -3338,9 +3481,14 @@ var TransactionResponse = class {
|
|
3338
3481
|
const decodedTransaction = this.decodeTransaction(
|
3339
3482
|
transaction
|
3340
3483
|
);
|
3341
|
-
|
3342
|
-
|
3343
|
-
|
3484
|
+
let txReceipts = [];
|
3485
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3486
|
+
txReceipts = transaction.status.receipts;
|
3487
|
+
}
|
3488
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3489
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3490
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3491
|
+
const maxInputs = this.provider.getChain().consensusParameters.txParameters.maxInputs;
|
3344
3492
|
const transactionSummary = assembleTransactionSummary({
|
3345
3493
|
id: this.id,
|
3346
3494
|
receipts,
|
@@ -3351,7 +3499,9 @@ var TransactionResponse = class {
|
|
3351
3499
|
gasPriceFactor,
|
3352
3500
|
abiMap: contractsAbiMap,
|
3353
3501
|
maxInputs,
|
3354
|
-
gasCosts
|
3502
|
+
gasCosts,
|
3503
|
+
maxGasPerTx,
|
3504
|
+
gasPrice
|
3355
3505
|
});
|
3356
3506
|
return transactionSummary;
|
3357
3507
|
}
|
@@ -3457,7 +3607,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3457
3607
|
}
|
3458
3608
|
|
3459
3609
|
// src/providers/utils/merge-quantities.ts
|
3460
|
-
var mergeQuantities = (
|
3610
|
+
var mergeQuantities = (...coinQuantities) => {
|
3461
3611
|
const resultMap = {};
|
3462
3612
|
function addToMap({ amount, assetId }) {
|
3463
3613
|
if (resultMap[assetId]) {
|
@@ -3466,8 +3616,7 @@ var mergeQuantities = (arr1, arr2) => {
|
|
3466
3616
|
resultMap[assetId] = amount;
|
3467
3617
|
}
|
3468
3618
|
}
|
3469
|
-
|
3470
|
-
arr2.forEach(addToMap);
|
3619
|
+
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
3471
3620
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
3472
3621
|
};
|
3473
3622
|
|
@@ -3475,32 +3624,60 @@ var mergeQuantities = (arr1, arr2) => {
|
|
3475
3624
|
var MAX_RETRIES = 10;
|
3476
3625
|
var processGqlChain = (chain) => {
|
3477
3626
|
const { name, daHeight, consensusParameters, latestBlock } = chain;
|
3478
|
-
const {
|
3627
|
+
const {
|
3628
|
+
contractParams,
|
3629
|
+
feeParams,
|
3630
|
+
predicateParams,
|
3631
|
+
scriptParams,
|
3632
|
+
txParams,
|
3633
|
+
gasCosts,
|
3634
|
+
baseAssetId,
|
3635
|
+
chainId,
|
3636
|
+
version
|
3637
|
+
} = consensusParameters;
|
3479
3638
|
return {
|
3480
3639
|
name,
|
3481
|
-
baseChainHeight:
|
3640
|
+
baseChainHeight: bn17(daHeight),
|
3482
3641
|
consensusParameters: {
|
3483
|
-
|
3484
|
-
|
3485
|
-
|
3486
|
-
|
3487
|
-
|
3488
|
-
|
3489
|
-
|
3490
|
-
|
3491
|
-
|
3492
|
-
|
3493
|
-
|
3494
|
-
|
3495
|
-
|
3496
|
-
|
3497
|
-
|
3642
|
+
version,
|
3643
|
+
chainId: bn17(chainId),
|
3644
|
+
baseAssetId,
|
3645
|
+
feeParameters: {
|
3646
|
+
version: feeParams.version,
|
3647
|
+
gasPerByte: bn17(feeParams.gasPerByte),
|
3648
|
+
gasPriceFactor: bn17(feeParams.gasPriceFactor)
|
3649
|
+
},
|
3650
|
+
contractParameters: {
|
3651
|
+
version: contractParams.version,
|
3652
|
+
contractMaxSize: bn17(contractParams.contractMaxSize),
|
3653
|
+
maxStorageSlots: bn17(contractParams.maxStorageSlots)
|
3654
|
+
},
|
3655
|
+
txParameters: {
|
3656
|
+
version: txParams.version,
|
3657
|
+
maxInputs: bn17(txParams.maxInputs),
|
3658
|
+
maxOutputs: bn17(txParams.maxOutputs),
|
3659
|
+
maxWitnesses: bn17(txParams.maxWitnesses),
|
3660
|
+
maxGasPerTx: bn17(txParams.maxGasPerTx),
|
3661
|
+
maxSize: bn17(txParams.maxSize),
|
3662
|
+
maxBytecodeSubsections: bn17(txParams.maxBytecodeSubsections)
|
3663
|
+
},
|
3664
|
+
predicateParameters: {
|
3665
|
+
version: predicateParams.version,
|
3666
|
+
maxPredicateLength: bn17(predicateParams.maxPredicateLength),
|
3667
|
+
maxPredicateDataLength: bn17(predicateParams.maxPredicateDataLength),
|
3668
|
+
maxGasPerPredicate: bn17(predicateParams.maxGasPerPredicate),
|
3669
|
+
maxMessageDataLength: bn17(predicateParams.maxMessageDataLength)
|
3670
|
+
},
|
3671
|
+
scriptParameters: {
|
3672
|
+
version: scriptParams.version,
|
3673
|
+
maxScriptLength: bn17(scriptParams.maxScriptLength),
|
3674
|
+
maxScriptDataLength: bn17(scriptParams.maxScriptDataLength)
|
3675
|
+
},
|
3498
3676
|
gasCosts
|
3499
3677
|
},
|
3500
|
-
gasCosts,
|
3501
3678
|
latestBlock: {
|
3502
3679
|
id: latestBlock.id,
|
3503
|
-
height:
|
3680
|
+
height: bn17(latestBlock.height),
|
3504
3681
|
time: latestBlock.header.time,
|
3505
3682
|
transactions: latestBlock.transactions.map((i) => ({
|
3506
3683
|
id: i.id
|
@@ -3594,10 +3771,13 @@ var _Provider = class {
|
|
3594
3771
|
* Returns some helpful parameters related to gas fees.
|
3595
3772
|
*/
|
3596
3773
|
getGasConfig() {
|
3597
|
-
const {
|
3598
|
-
|
3774
|
+
const {
|
3775
|
+
txParameters: { maxGasPerTx },
|
3776
|
+
predicateParameters: { maxGasPerPredicate },
|
3777
|
+
feeParameters: { gasPriceFactor, gasPerByte },
|
3778
|
+
gasCosts
|
3779
|
+
} = this.getChain().consensusParameters;
|
3599
3780
|
return {
|
3600
|
-
minGasPrice,
|
3601
3781
|
maxGasPerTx,
|
3602
3782
|
maxGasPerPredicate,
|
3603
3783
|
gasPriceFactor,
|
@@ -3645,7 +3825,18 @@ var _Provider = class {
|
|
3645
3825
|
createOperations() {
|
3646
3826
|
const fetchFn = _Provider.getFetchFn(this.options);
|
3647
3827
|
const gqlClient = new GraphQLClient(this.url, {
|
3648
|
-
fetch: (url, requestInit) => fetchFn(url, requestInit, this.options)
|
3828
|
+
fetch: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
3829
|
+
responseMiddleware: (response) => {
|
3830
|
+
if ("response" in response) {
|
3831
|
+
const graphQlResponse = response.response;
|
3832
|
+
if (Array.isArray(graphQlResponse?.errors)) {
|
3833
|
+
throw new FuelError13(
|
3834
|
+
FuelError13.CODES.INVALID_REQUEST,
|
3835
|
+
graphQlResponse.errors.map((err) => err.message).join("\n\n")
|
3836
|
+
);
|
3837
|
+
}
|
3838
|
+
}
|
3839
|
+
}
|
3649
3840
|
});
|
3650
3841
|
const executeQuery = (query, vars) => {
|
3651
3842
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
@@ -3673,21 +3864,6 @@ var _Provider = class {
|
|
3673
3864
|
} = await this.operations.getVersion();
|
3674
3865
|
return nodeVersion;
|
3675
3866
|
}
|
3676
|
-
/**
|
3677
|
-
* @hidden
|
3678
|
-
*
|
3679
|
-
* Returns the network configuration of the connected Fuel node.
|
3680
|
-
*
|
3681
|
-
* @returns A promise that resolves to the network configuration object
|
3682
|
-
*/
|
3683
|
-
async getNetwork() {
|
3684
|
-
const {
|
3685
|
-
name,
|
3686
|
-
consensusParameters: { chainId }
|
3687
|
-
} = await this.getChain();
|
3688
|
-
const network = new Network(name, chainId.toNumber());
|
3689
|
-
return Promise.resolve(network);
|
3690
|
-
}
|
3691
3867
|
/**
|
3692
3868
|
* Returns the block number.
|
3693
3869
|
*
|
@@ -3695,7 +3871,7 @@ var _Provider = class {
|
|
3695
3871
|
*/
|
3696
3872
|
async getBlockNumber() {
|
3697
3873
|
const { chain } = await this.operations.getChain();
|
3698
|
-
return
|
3874
|
+
return bn17(chain.latestBlock.height, 10);
|
3699
3875
|
}
|
3700
3876
|
/**
|
3701
3877
|
* Returns the chain information.
|
@@ -3705,13 +3881,11 @@ var _Provider = class {
|
|
3705
3881
|
async fetchNode() {
|
3706
3882
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3707
3883
|
const processedNodeInfo = {
|
3708
|
-
maxDepth:
|
3709
|
-
maxTx:
|
3710
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3884
|
+
maxDepth: bn17(nodeInfo.maxDepth),
|
3885
|
+
maxTx: bn17(nodeInfo.maxTx),
|
3711
3886
|
nodeVersion: nodeInfo.nodeVersion,
|
3712
3887
|
utxoValidation: nodeInfo.utxoValidation,
|
3713
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3714
|
-
peers: nodeInfo.peers
|
3888
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3715
3889
|
};
|
3716
3890
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3717
3891
|
return processedNodeInfo;
|
@@ -3737,6 +3911,17 @@ var _Provider = class {
|
|
3737
3911
|
} = this.getChain();
|
3738
3912
|
return chainId.toNumber();
|
3739
3913
|
}
|
3914
|
+
/**
|
3915
|
+
* Returns the base asset ID for the current provider network
|
3916
|
+
*
|
3917
|
+
* @returns the base asset ID
|
3918
|
+
*/
|
3919
|
+
getBaseAssetId() {
|
3920
|
+
const {
|
3921
|
+
consensusParameters: { baseAssetId }
|
3922
|
+
} = this.getChain();
|
3923
|
+
return baseAssetId;
|
3924
|
+
}
|
3740
3925
|
/**
|
3741
3926
|
* Submits a transaction to the chain to be executed.
|
3742
3927
|
*
|
@@ -3797,14 +3982,13 @@ var _Provider = class {
|
|
3797
3982
|
return this.estimateTxDependencies(transactionRequest);
|
3798
3983
|
}
|
3799
3984
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3800
|
-
const { dryRun:
|
3801
|
-
encodedTransaction,
|
3985
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3986
|
+
encodedTransactions: encodedTransaction,
|
3802
3987
|
utxoValidation: utxoValidation || false
|
3803
3988
|
});
|
3804
|
-
const receipts =
|
3805
|
-
|
3806
|
-
|
3807
|
-
};
|
3989
|
+
const [{ receipts: rawReceipts, status: dryRunStatus }] = dryRunStatuses;
|
3990
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3991
|
+
return { receipts, dryRunStatus };
|
3808
3992
|
}
|
3809
3993
|
/**
|
3810
3994
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3830,7 +4014,7 @@ var _Provider = class {
|
|
3830
4014
|
} = response;
|
3831
4015
|
if (inputs) {
|
3832
4016
|
inputs.forEach((input, index) => {
|
3833
|
-
if ("predicateGasUsed" in input &&
|
4017
|
+
if ("predicateGasUsed" in input && bn17(input.predicateGasUsed).gt(0)) {
|
3834
4018
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3835
4019
|
}
|
3836
4020
|
});
|
@@ -3843,9 +4027,6 @@ var _Provider = class {
|
|
3843
4027
|
* If there are missing variable outputs,
|
3844
4028
|
* `addVariableOutputs` is called on the transaction.
|
3845
4029
|
*
|
3846
|
-
* @privateRemarks
|
3847
|
-
* TODO: Investigate support for missing contract IDs
|
3848
|
-
* TODO: Add support for missing output messages
|
3849
4030
|
*
|
3850
4031
|
* @param transactionRequest - The transaction request object.
|
3851
4032
|
* @returns A promise.
|
@@ -3858,16 +4039,19 @@ var _Provider = class {
|
|
3858
4039
|
missingContractIds: []
|
3859
4040
|
};
|
3860
4041
|
}
|
3861
|
-
await this.estimatePredicates(transactionRequest);
|
3862
4042
|
let receipts = [];
|
3863
4043
|
const missingContractIds = [];
|
3864
4044
|
let outputVariables = 0;
|
4045
|
+
let dryRunStatus;
|
3865
4046
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3866
|
-
const {
|
3867
|
-
|
4047
|
+
const {
|
4048
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4049
|
+
} = await this.operations.dryRun({
|
4050
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3868
4051
|
utxoValidation: false
|
3869
4052
|
});
|
3870
|
-
receipts =
|
4053
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4054
|
+
dryRunStatus = status;
|
3871
4055
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3872
4056
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3873
4057
|
if (hasMissingOutputs) {
|
@@ -3877,6 +4061,10 @@ var _Provider = class {
|
|
3877
4061
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3878
4062
|
missingContractIds.push(contractId);
|
3879
4063
|
});
|
4064
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4065
|
+
transactionRequest
|
4066
|
+
});
|
4067
|
+
transactionRequest.maxFee = maxFee;
|
3880
4068
|
} else {
|
3881
4069
|
break;
|
3882
4070
|
}
|
@@ -3884,37 +4072,136 @@ var _Provider = class {
|
|
3884
4072
|
return {
|
3885
4073
|
receipts,
|
3886
4074
|
outputVariables,
|
3887
|
-
missingContractIds
|
4075
|
+
missingContractIds,
|
4076
|
+
dryRunStatus
|
3888
4077
|
};
|
3889
4078
|
}
|
4079
|
+
/**
|
4080
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4081
|
+
*
|
4082
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4083
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4084
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4085
|
+
*
|
4086
|
+
* @param transactionRequests - Array of transaction request objects.
|
4087
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4088
|
+
*/
|
4089
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4090
|
+
const results = transactionRequests.map(() => ({
|
4091
|
+
receipts: [],
|
4092
|
+
outputVariables: 0,
|
4093
|
+
missingContractIds: [],
|
4094
|
+
dryRunStatus: void 0
|
4095
|
+
}));
|
4096
|
+
const allRequests = clone3(transactionRequests);
|
4097
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4098
|
+
allRequests.forEach((req, index) => {
|
4099
|
+
if (req.type === TransactionType8.Script) {
|
4100
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4101
|
+
}
|
4102
|
+
});
|
4103
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4104
|
+
let attempt = 0;
|
4105
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4106
|
+
const encodedTransactions = transactionsToProcess.map(
|
4107
|
+
(index) => serializedTransactionsMap.get(index)
|
4108
|
+
);
|
4109
|
+
const dryRunResults = await this.operations.dryRun({
|
4110
|
+
encodedTransactions,
|
4111
|
+
utxoValidation: false
|
4112
|
+
});
|
4113
|
+
const nextRoundTransactions = [];
|
4114
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4115
|
+
const requestIdx = transactionsToProcess[i];
|
4116
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4117
|
+
const result = results[requestIdx];
|
4118
|
+
result.receipts = rawReceipts.map(processGqlReceipt);
|
4119
|
+
result.dryRunStatus = status;
|
4120
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4121
|
+
result.receipts
|
4122
|
+
);
|
4123
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4124
|
+
const request = allRequests[requestIdx];
|
4125
|
+
if (hasMissingOutputs && request?.type === TransactionType8.Script) {
|
4126
|
+
result.outputVariables += missingOutputVariables.length;
|
4127
|
+
request.addVariableOutputs(missingOutputVariables.length);
|
4128
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4129
|
+
request.addContractInputAndOutput(Address2.fromString(contractId));
|
4130
|
+
result.missingContractIds.push(contractId);
|
4131
|
+
});
|
4132
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4133
|
+
transactionRequest: request
|
4134
|
+
});
|
4135
|
+
request.maxFee = maxFee;
|
4136
|
+
serializedTransactionsMap.set(requestIdx, hexlify12(request.toTransactionBytes()));
|
4137
|
+
nextRoundTransactions.push(requestIdx);
|
4138
|
+
}
|
4139
|
+
}
|
4140
|
+
transactionsToProcess = nextRoundTransactions;
|
4141
|
+
attempt += 1;
|
4142
|
+
}
|
4143
|
+
return results;
|
4144
|
+
}
|
4145
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4146
|
+
if (estimateTxDependencies) {
|
4147
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4148
|
+
}
|
4149
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4150
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4151
|
+
encodedTransactions,
|
4152
|
+
utxoValidation: utxoValidation || false
|
4153
|
+
});
|
4154
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4155
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4156
|
+
return { receipts, dryRunStatus: status };
|
4157
|
+
});
|
4158
|
+
return results;
|
4159
|
+
}
|
3890
4160
|
/**
|
3891
4161
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3892
4162
|
* @param transactionRequest - The transaction request object.
|
3893
4163
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3894
4164
|
*/
|
3895
|
-
estimateTxGasAndFee(params) {
|
4165
|
+
async estimateTxGasAndFee(params) {
|
3896
4166
|
const { transactionRequest } = params;
|
3897
|
-
|
4167
|
+
let { gasPrice } = params;
|
3898
4168
|
const chainInfo = this.getChain();
|
3899
|
-
const
|
3900
|
-
transactionRequest.gasPrice = gasPrice;
|
4169
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3901
4170
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3902
|
-
|
4171
|
+
if (!gasPrice) {
|
4172
|
+
gasPrice = await this.estimateGasPrice(10);
|
4173
|
+
}
|
4174
|
+
const minFee = calculateGasFee({
|
4175
|
+
gasPrice: bn17(gasPrice),
|
4176
|
+
gas: minGas,
|
4177
|
+
priceFactor: gasPriceFactor,
|
4178
|
+
tip: transactionRequest.tip
|
4179
|
+
}).add(1);
|
4180
|
+
let gasLimit = bn17(0);
|
3903
4181
|
if (transactionRequest.type === TransactionType8.Script) {
|
4182
|
+
gasLimit = transactionRequest.gasLimit;
|
3904
4183
|
if (transactionRequest.gasLimit.eq(0)) {
|
3905
4184
|
transactionRequest.gasLimit = minGas;
|
3906
4185
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3907
4186
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3908
4187
|
);
|
4188
|
+
gasLimit = transactionRequest.gasLimit;
|
3909
4189
|
}
|
3910
4190
|
}
|
3911
4191
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3912
|
-
const maxFee =
|
4192
|
+
const maxFee = calculateGasFee({
|
4193
|
+
gasPrice: bn17(gasPrice),
|
4194
|
+
gas: maxGas,
|
4195
|
+
priceFactor: gasPriceFactor,
|
4196
|
+
tip: transactionRequest.tip
|
4197
|
+
}).add(1);
|
3913
4198
|
return {
|
3914
4199
|
minGas,
|
3915
4200
|
minFee,
|
3916
4201
|
maxGas,
|
3917
|
-
maxFee
|
4202
|
+
maxFee,
|
4203
|
+
gasPrice,
|
4204
|
+
gasLimit
|
3918
4205
|
};
|
3919
4206
|
}
|
3920
4207
|
/**
|
@@ -3932,15 +4219,17 @@ var _Provider = class {
|
|
3932
4219
|
if (estimateTxDependencies) {
|
3933
4220
|
return this.estimateTxDependencies(transactionRequest);
|
3934
4221
|
}
|
3935
|
-
const
|
3936
|
-
const { dryRun:
|
3937
|
-
|
4222
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4223
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4224
|
+
encodedTransactions,
|
3938
4225
|
utxoValidation: true
|
3939
4226
|
});
|
3940
|
-
const
|
3941
|
-
|
3942
|
-
receipts
|
3943
|
-
|
4227
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4228
|
+
const { id, receipts, status } = dryRunStatus;
|
4229
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4230
|
+
return { id, receipts: processedReceipts, status };
|
4231
|
+
});
|
4232
|
+
return { receipts: callResult[0].receipts };
|
3944
4233
|
}
|
3945
4234
|
/**
|
3946
4235
|
* Returns a transaction cost to enable user
|
@@ -3957,77 +4246,79 @@ var _Provider = class {
|
|
3957
4246
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3958
4247
|
* @returns A promise that resolves to the transaction cost object.
|
3959
4248
|
*/
|
3960
|
-
async getTransactionCost(transactionRequestLike,
|
3961
|
-
estimateTxDependencies = true,
|
3962
|
-
estimatePredicates = true,
|
3963
|
-
resourcesOwner,
|
3964
|
-
signatureCallback
|
3965
|
-
} = {}) {
|
4249
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3966
4250
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3967
|
-
const { minGasPrice } = this.getGasConfig();
|
3968
|
-
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3969
4251
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4252
|
+
const baseAssetId = this.getBaseAssetId();
|
3970
4253
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3971
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3972
|
-
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4254
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4255
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4256
|
+
txRequestClone.maxFee = bn17(0);
|
3973
4257
|
if (isScriptTransaction) {
|
3974
|
-
txRequestClone.gasLimit =
|
4258
|
+
txRequestClone.gasLimit = bn17(0);
|
3975
4259
|
}
|
3976
|
-
if (
|
3977
|
-
|
3978
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3979
|
-
}
|
3980
|
-
await this.estimatePredicates(txRequestClone);
|
4260
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4261
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3981
4262
|
}
|
4263
|
+
const signedRequest = clone3(txRequestClone);
|
4264
|
+
let addedSignatures = 0;
|
3982
4265
|
if (signatureCallback && isScriptTransaction) {
|
3983
|
-
|
4266
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4267
|
+
await signatureCallback(signedRequest);
|
4268
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3984
4269
|
}
|
3985
|
-
|
3986
|
-
|
4270
|
+
await this.estimatePredicates(signedRequest);
|
4271
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4272
|
+
transactionRequest: signedRequest
|
3987
4273
|
});
|
3988
4274
|
let receipts = [];
|
4275
|
+
let dryRunStatus;
|
3989
4276
|
let missingContractIds = [];
|
3990
4277
|
let outputVariables = 0;
|
3991
|
-
let gasUsed =
|
3992
|
-
|
3993
|
-
|
3994
|
-
|
3995
|
-
|
3996
|
-
|
3997
|
-
|
4278
|
+
let gasUsed = bn17(0);
|
4279
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4280
|
+
txRequestClone.maxFee = maxFee;
|
4281
|
+
if (isScriptTransaction) {
|
4282
|
+
txRequestClone.gasLimit = gasLimit;
|
4283
|
+
if (signatureCallback) {
|
4284
|
+
await signatureCallback(txRequestClone);
|
4285
|
+
}
|
4286
|
+
({ receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone));
|
3998
4287
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
3999
4288
|
txRequestClone.gasLimit = gasUsed;
|
4000
|
-
|
4001
|
-
|
4002
|
-
|
4289
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4290
|
+
transactionRequest: txRequestClone,
|
4291
|
+
gasPrice
|
4003
4292
|
}));
|
4004
4293
|
}
|
4005
4294
|
return {
|
4006
4295
|
requiredQuantities: allQuantities,
|
4007
4296
|
receipts,
|
4008
4297
|
gasUsed,
|
4009
|
-
|
4010
|
-
gasPrice: setGasPrice,
|
4298
|
+
gasPrice,
|
4011
4299
|
minGas,
|
4012
4300
|
maxGas,
|
4013
4301
|
minFee,
|
4014
4302
|
maxFee,
|
4015
|
-
estimatedInputs: txRequestClone.inputs,
|
4016
4303
|
outputVariables,
|
4017
|
-
missingContractIds
|
4304
|
+
missingContractIds,
|
4305
|
+
addedSignatures,
|
4306
|
+
estimatedPredicates: txRequestClone.inputs,
|
4307
|
+
dryRunStatus
|
4018
4308
|
};
|
4019
4309
|
}
|
4020
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4310
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4021
4311
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4022
4312
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4023
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4313
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4314
|
+
quantitiesToContract
|
4315
|
+
});
|
4024
4316
|
transactionRequest.addResources(
|
4025
4317
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4026
4318
|
);
|
4027
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4028
|
-
|
4029
|
-
|
4030
|
-
);
|
4319
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4320
|
+
quantitiesToContract
|
4321
|
+
});
|
4031
4322
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4032
4323
|
return {
|
4033
4324
|
resources,
|
@@ -4049,11 +4340,10 @@ var _Provider = class {
|
|
4049
4340
|
return coins.map((coin) => ({
|
4050
4341
|
id: coin.utxoId,
|
4051
4342
|
assetId: coin.assetId,
|
4052
|
-
amount:
|
4343
|
+
amount: bn17(coin.amount),
|
4053
4344
|
owner: Address2.fromAddressOrString(coin.owner),
|
4054
|
-
|
4055
|
-
|
4056
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4345
|
+
blockCreated: bn17(coin.blockCreated),
|
4346
|
+
txCreatedIdx: bn17(coin.txCreatedIdx)
|
4057
4347
|
}));
|
4058
4348
|
}
|
4059
4349
|
/**
|
@@ -4090,9 +4380,9 @@ var _Provider = class {
|
|
4090
4380
|
switch (coin.__typename) {
|
4091
4381
|
case "MessageCoin":
|
4092
4382
|
return {
|
4093
|
-
amount:
|
4383
|
+
amount: bn17(coin.amount),
|
4094
4384
|
assetId: coin.assetId,
|
4095
|
-
daHeight:
|
4385
|
+
daHeight: bn17(coin.daHeight),
|
4096
4386
|
sender: Address2.fromAddressOrString(coin.sender),
|
4097
4387
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4098
4388
|
nonce: coin.nonce
|
@@ -4100,12 +4390,11 @@ var _Provider = class {
|
|
4100
4390
|
case "Coin":
|
4101
4391
|
return {
|
4102
4392
|
id: coin.utxoId,
|
4103
|
-
amount:
|
4393
|
+
amount: bn17(coin.amount),
|
4104
4394
|
assetId: coin.assetId,
|
4105
4395
|
owner: Address2.fromAddressOrString(coin.owner),
|
4106
|
-
|
4107
|
-
|
4108
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4396
|
+
blockCreated: bn17(coin.blockCreated),
|
4397
|
+
txCreatedIdx: bn17(coin.txCreatedIdx)
|
4109
4398
|
};
|
4110
4399
|
default:
|
4111
4400
|
return null;
|
@@ -4122,13 +4411,13 @@ var _Provider = class {
|
|
4122
4411
|
async getBlock(idOrHeight) {
|
4123
4412
|
let variables;
|
4124
4413
|
if (typeof idOrHeight === "number") {
|
4125
|
-
variables = { height:
|
4414
|
+
variables = { height: bn17(idOrHeight).toString(10) };
|
4126
4415
|
} else if (idOrHeight === "latest") {
|
4127
4416
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4128
4417
|
} else if (idOrHeight.length === 66) {
|
4129
4418
|
variables = { blockId: idOrHeight };
|
4130
4419
|
} else {
|
4131
|
-
variables = { blockId:
|
4420
|
+
variables = { blockId: bn17(idOrHeight).toString(10) };
|
4132
4421
|
}
|
4133
4422
|
const { block } = await this.operations.getBlock(variables);
|
4134
4423
|
if (!block) {
|
@@ -4136,7 +4425,7 @@ var _Provider = class {
|
|
4136
4425
|
}
|
4137
4426
|
return {
|
4138
4427
|
id: block.id,
|
4139
|
-
height:
|
4428
|
+
height: bn17(block.height),
|
4140
4429
|
time: block.header.time,
|
4141
4430
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4142
4431
|
};
|
@@ -4151,7 +4440,7 @@ var _Provider = class {
|
|
4151
4440
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4152
4441
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4153
4442
|
id: block.id,
|
4154
|
-
height:
|
4443
|
+
height: bn17(block.height),
|
4155
4444
|
time: block.header.time,
|
4156
4445
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4157
4446
|
}));
|
@@ -4166,7 +4455,7 @@ var _Provider = class {
|
|
4166
4455
|
async getBlockWithTransactions(idOrHeight) {
|
4167
4456
|
let variables;
|
4168
4457
|
if (typeof idOrHeight === "number") {
|
4169
|
-
variables = { blockHeight:
|
4458
|
+
variables = { blockHeight: bn17(idOrHeight).toString(10) };
|
4170
4459
|
} else if (idOrHeight === "latest") {
|
4171
4460
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4172
4461
|
} else {
|
@@ -4178,7 +4467,7 @@ var _Provider = class {
|
|
4178
4467
|
}
|
4179
4468
|
return {
|
4180
4469
|
id: block.id,
|
4181
|
-
height:
|
4470
|
+
height: bn17(block.height, 10),
|
4182
4471
|
time: block.header.time,
|
4183
4472
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4184
4473
|
transactions: block.transactions.map(
|
@@ -4227,7 +4516,7 @@ var _Provider = class {
|
|
4227
4516
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4228
4517
|
asset: hexlify12(assetId)
|
4229
4518
|
});
|
4230
|
-
return
|
4519
|
+
return bn17(contractBalance.amount, 10);
|
4231
4520
|
}
|
4232
4521
|
/**
|
4233
4522
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4241,7 +4530,7 @@ var _Provider = class {
|
|
4241
4530
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4242
4531
|
assetId: hexlify12(assetId)
|
4243
4532
|
});
|
4244
|
-
return
|
4533
|
+
return bn17(balance.amount, 10);
|
4245
4534
|
}
|
4246
4535
|
/**
|
4247
4536
|
* Returns balances for the given owner.
|
@@ -4259,7 +4548,7 @@ var _Provider = class {
|
|
4259
4548
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4260
4549
|
return balances.map((balance) => ({
|
4261
4550
|
assetId: balance.assetId,
|
4262
|
-
amount:
|
4551
|
+
amount: bn17(balance.amount)
|
4263
4552
|
}));
|
4264
4553
|
}
|
4265
4554
|
/**
|
@@ -4281,15 +4570,15 @@ var _Provider = class {
|
|
4281
4570
|
sender: message.sender,
|
4282
4571
|
recipient: message.recipient,
|
4283
4572
|
nonce: message.nonce,
|
4284
|
-
amount:
|
4573
|
+
amount: bn17(message.amount),
|
4285
4574
|
data: message.data
|
4286
4575
|
}),
|
4287
4576
|
sender: Address2.fromAddressOrString(message.sender),
|
4288
4577
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4289
4578
|
nonce: message.nonce,
|
4290
|
-
amount:
|
4579
|
+
amount: bn17(message.amount),
|
4291
4580
|
data: InputMessageCoder.decodeData(message.data),
|
4292
|
-
daHeight:
|
4581
|
+
daHeight: bn17(message.daHeight)
|
4293
4582
|
}));
|
4294
4583
|
}
|
4295
4584
|
/**
|
@@ -4342,44 +4631,60 @@ var _Provider = class {
|
|
4342
4631
|
} = result.messageProof;
|
4343
4632
|
return {
|
4344
4633
|
messageProof: {
|
4345
|
-
proofIndex:
|
4634
|
+
proofIndex: bn17(messageProof.proofIndex),
|
4346
4635
|
proofSet: messageProof.proofSet
|
4347
4636
|
},
|
4348
4637
|
blockProof: {
|
4349
|
-
proofIndex:
|
4638
|
+
proofIndex: bn17(blockProof.proofIndex),
|
4350
4639
|
proofSet: blockProof.proofSet
|
4351
4640
|
},
|
4352
4641
|
messageBlockHeader: {
|
4353
4642
|
id: messageBlockHeader.id,
|
4354
|
-
daHeight:
|
4355
|
-
transactionsCount:
|
4643
|
+
daHeight: bn17(messageBlockHeader.daHeight),
|
4644
|
+
transactionsCount: Number(messageBlockHeader.transactionsCount),
|
4356
4645
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4357
|
-
height:
|
4646
|
+
height: bn17(messageBlockHeader.height),
|
4358
4647
|
prevRoot: messageBlockHeader.prevRoot,
|
4359
4648
|
time: messageBlockHeader.time,
|
4360
4649
|
applicationHash: messageBlockHeader.applicationHash,
|
4361
|
-
|
4362
|
-
|
4650
|
+
messageReceiptCount: Number(messageBlockHeader.messageReceiptCount),
|
4651
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4652
|
+
consensusParametersVersion: Number(messageBlockHeader.consensusParametersVersion),
|
4653
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4654
|
+
stateTransitionBytecodeVersion: Number(messageBlockHeader.stateTransitionBytecodeVersion)
|
4363
4655
|
},
|
4364
4656
|
commitBlockHeader: {
|
4365
4657
|
id: commitBlockHeader.id,
|
4366
|
-
daHeight:
|
4367
|
-
transactionsCount:
|
4658
|
+
daHeight: bn17(commitBlockHeader.daHeight),
|
4659
|
+
transactionsCount: Number(commitBlockHeader.transactionsCount),
|
4368
4660
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4369
|
-
height:
|
4661
|
+
height: bn17(commitBlockHeader.height),
|
4370
4662
|
prevRoot: commitBlockHeader.prevRoot,
|
4371
4663
|
time: commitBlockHeader.time,
|
4372
4664
|
applicationHash: commitBlockHeader.applicationHash,
|
4373
|
-
|
4374
|
-
|
4665
|
+
messageReceiptCount: Number(commitBlockHeader.messageReceiptCount),
|
4666
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4667
|
+
consensusParametersVersion: Number(commitBlockHeader.consensusParametersVersion),
|
4668
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4669
|
+
stateTransitionBytecodeVersion: Number(commitBlockHeader.stateTransitionBytecodeVersion)
|
4375
4670
|
},
|
4376
4671
|
sender: Address2.fromAddressOrString(sender),
|
4377
4672
|
recipient: Address2.fromAddressOrString(recipient),
|
4378
4673
|
nonce,
|
4379
|
-
amount:
|
4674
|
+
amount: bn17(amount),
|
4380
4675
|
data
|
4381
4676
|
};
|
4382
4677
|
}
|
4678
|
+
async getLatestGasPrice() {
|
4679
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4680
|
+
return bn17(latestGasPrice.gasPrice);
|
4681
|
+
}
|
4682
|
+
async estimateGasPrice(blockHorizon) {
|
4683
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4684
|
+
blockHorizon: String(blockHorizon)
|
4685
|
+
});
|
4686
|
+
return bn17(estimateGasPrice.gasPrice);
|
4687
|
+
}
|
4383
4688
|
/**
|
4384
4689
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4385
4690
|
*
|
@@ -4399,15 +4704,37 @@ var _Provider = class {
|
|
4399
4704
|
*/
|
4400
4705
|
async produceBlocks(amount, startTime) {
|
4401
4706
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4402
|
-
blocksToProduce:
|
4707
|
+
blocksToProduce: bn17(amount).toString(10),
|
4403
4708
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4404
4709
|
});
|
4405
|
-
return
|
4710
|
+
return bn17(latestBlockHeight);
|
4406
4711
|
}
|
4407
4712
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4408
4713
|
async getTransactionResponse(transactionId) {
|
4409
4714
|
return new TransactionResponse(transactionId, this);
|
4410
4715
|
}
|
4716
|
+
/**
|
4717
|
+
* Returns Message for given nonce.
|
4718
|
+
*
|
4719
|
+
* @param nonce - The nonce of the message to retrieve.
|
4720
|
+
* @returns A promise that resolves to the Message object.
|
4721
|
+
*/
|
4722
|
+
async getMessageByNonce(nonce) {
|
4723
|
+
const { message } = await this.operations.getMessageByNonce({ nonce });
|
4724
|
+
if (!message) {
|
4725
|
+
return null;
|
4726
|
+
}
|
4727
|
+
return message;
|
4728
|
+
}
|
4729
|
+
async getRelayedTransactionStatus(relayedTransactionId) {
|
4730
|
+
const { relayedTransactionStatus } = await this.operations.getRelayedTransactionStatus({
|
4731
|
+
relayedTransactionId
|
4732
|
+
});
|
4733
|
+
if (!relayedTransactionStatus) {
|
4734
|
+
return null;
|
4735
|
+
}
|
4736
|
+
return relayedTransactionStatus;
|
4737
|
+
}
|
4411
4738
|
};
|
4412
4739
|
var Provider = _Provider;
|
4413
4740
|
_cacheInputs = new WeakSet();
|
@@ -4416,7 +4743,7 @@ cacheInputs_fn = function(inputs) {
|
|
4416
4743
|
return;
|
4417
4744
|
}
|
4418
4745
|
inputs.forEach((input) => {
|
4419
|
-
if (input.type ===
|
4746
|
+
if (input.type === InputType7.Coin) {
|
4420
4747
|
this.cache?.set(input.id);
|
4421
4748
|
}
|
4422
4749
|
});
|
@@ -4426,7 +4753,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4426
4753
|
|
4427
4754
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4428
4755
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4429
|
-
import { bn as
|
4756
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
4430
4757
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4431
4758
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4432
4759
|
|
@@ -4475,6 +4802,22 @@ var assets = [
|
|
4475
4802
|
}
|
4476
4803
|
];
|
4477
4804
|
|
4805
|
+
// src/providers/transaction-request/helpers.ts
|
4806
|
+
import { bn as bn19 } from "@fuel-ts/math";
|
4807
|
+
import { InputType as InputType8 } from "@fuel-ts/transactions";
|
4808
|
+
var isRequestInputCoin = (input) => input.type === InputType8.Coin;
|
4809
|
+
var isRequestInputMessage = (input) => input.type === InputType8.Message;
|
4810
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
4811
|
+
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
4812
|
+
if (isRequestInputCoin(input) && input.assetId === assetId) {
|
4813
|
+
return acc.add(input.amount);
|
4814
|
+
}
|
4815
|
+
if (isRequestInputMessage(input) && assetId === baseAsset) {
|
4816
|
+
return acc.add(input.amount);
|
4817
|
+
}
|
4818
|
+
return acc;
|
4819
|
+
}, bn19(0));
|
4820
|
+
|
4478
4821
|
// src/utils/formatTransferToContractScriptData.ts
|
4479
4822
|
import { BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
|
4480
4823
|
import { BN as BN2 } from "@fuel-ts/math";
|
@@ -4512,6 +4855,7 @@ var assembleTransferToContractScript = async (params) => {
|
|
4512
4855
|
};
|
4513
4856
|
|
4514
4857
|
// src/account.ts
|
4858
|
+
var MAX_FUNDING_ATTEMPTS = 2;
|
4515
4859
|
var Account = class extends AbstractAccount {
|
4516
4860
|
/**
|
4517
4861
|
* The address associated with the account.
|
@@ -4634,8 +4978,9 @@ var Account = class extends AbstractAccount {
|
|
4634
4978
|
* @param assetId - The asset ID to check the balance for.
|
4635
4979
|
* @returns A promise that resolves to the balance amount.
|
4636
4980
|
*/
|
4637
|
-
async getBalance(assetId
|
4638
|
-
const
|
4981
|
+
async getBalance(assetId) {
|
4982
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4983
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4639
4984
|
return amount;
|
4640
4985
|
}
|
4641
4986
|
/**
|
@@ -4668,44 +5013,35 @@ var Account = class extends AbstractAccount {
|
|
4668
5013
|
* Adds resources to the transaction enough to fund it.
|
4669
5014
|
*
|
4670
5015
|
* @param request - The transaction request.
|
4671
|
-
* @param
|
5016
|
+
* @param requiredQuantities - The coin quantities required to execute the transaction.
|
4672
5017
|
* @param fee - The estimated transaction fee.
|
4673
5018
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4674
5019
|
*/
|
4675
|
-
async fund(request,
|
4676
|
-
const
|
4677
|
-
|
4678
|
-
|
4679
|
-
|
5020
|
+
async fund(request, params) {
|
5021
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5022
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5023
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn20(0);
|
5024
|
+
const txRequest = request;
|
5025
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5026
|
+
amount: bn20(fee),
|
5027
|
+
assetId: baseAssetId,
|
5028
|
+
coinQuantities: requiredQuantities
|
4680
5029
|
});
|
4681
5030
|
const quantitiesDict = {};
|
4682
|
-
|
5031
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4683
5032
|
quantitiesDict[assetId] = {
|
4684
5033
|
required: amount,
|
4685
|
-
owned:
|
5034
|
+
owned: bn20(0)
|
4686
5035
|
};
|
4687
5036
|
});
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
if (isResource) {
|
4694
|
-
const isCoin2 = "owner" in input;
|
4695
|
-
if (isCoin2) {
|
4696
|
-
const assetId = String(input.assetId);
|
4697
|
-
if (input.owner === owner && quantitiesDict[assetId]) {
|
4698
|
-
const amount = bn17(input.amount);
|
4699
|
-
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4700
|
-
cachedUtxos.push(input.id);
|
4701
|
-
}
|
4702
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4703
|
-
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4704
|
-
cachedMessages.push(input.nonce);
|
4705
|
-
}
|
5037
|
+
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
5038
|
+
const isCoin2 = isRequestInputCoin(input);
|
5039
|
+
const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
|
5040
|
+
if (quantitiesDict[assetId]) {
|
5041
|
+
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
|
4706
5042
|
}
|
4707
5043
|
});
|
4708
|
-
|
5044
|
+
let missingQuantities = [];
|
4709
5045
|
Object.entries(quantitiesDict).forEach(([assetId, { owned, required }]) => {
|
4710
5046
|
if (owned.lt(required)) {
|
4711
5047
|
missingQuantities.push({
|
@@ -4714,14 +5050,54 @@ var Account = class extends AbstractAccount {
|
|
4714
5050
|
});
|
4715
5051
|
}
|
4716
5052
|
});
|
4717
|
-
|
4718
|
-
|
4719
|
-
|
4720
|
-
|
4721
|
-
|
4722
|
-
|
5053
|
+
let needsToBeFunded = missingQuantities.length > 0;
|
5054
|
+
let fundingAttempts = 0;
|
5055
|
+
while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
|
5056
|
+
const resources = await this.getResourcesToSpend(
|
5057
|
+
missingQuantities,
|
5058
|
+
cacheTxInputsFromOwner(request.inputs, this.address)
|
5059
|
+
);
|
4723
5060
|
request.addResources(resources);
|
5061
|
+
txRequest.shiftPredicateData();
|
5062
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5063
|
+
const requestToReestimate2 = clone4(txRequest);
|
5064
|
+
if (addedSignatures) {
|
5065
|
+
Array.from({ length: addedSignatures }).forEach(
|
5066
|
+
() => requestToReestimate2.addEmptyWitness()
|
5067
|
+
);
|
5068
|
+
}
|
5069
|
+
const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
|
5070
|
+
transactionRequest: requestToReestimate2
|
5071
|
+
});
|
5072
|
+
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
5073
|
+
request.inputs,
|
5074
|
+
baseAssetId,
|
5075
|
+
baseAssetId
|
5076
|
+
);
|
5077
|
+
const totalBaseAssetRequiredWithFee = requiredInBaseAsset.add(newFee);
|
5078
|
+
if (totalBaseAssetOnInputs.gt(totalBaseAssetRequiredWithFee)) {
|
5079
|
+
needsToBeFunded = false;
|
5080
|
+
} else {
|
5081
|
+
missingQuantities = [
|
5082
|
+
{
|
5083
|
+
amount: totalBaseAssetRequiredWithFee.sub(totalBaseAssetOnInputs),
|
5084
|
+
assetId: baseAssetId
|
5085
|
+
}
|
5086
|
+
];
|
5087
|
+
}
|
5088
|
+
fundingAttempts += 1;
|
5089
|
+
}
|
5090
|
+
txRequest.shiftPredicateData();
|
5091
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5092
|
+
const requestToReestimate = clone4(txRequest);
|
5093
|
+
if (addedSignatures) {
|
5094
|
+
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
4724
5095
|
}
|
5096
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5097
|
+
transactionRequest: requestToReestimate
|
5098
|
+
});
|
5099
|
+
txRequest.maxFee = maxFee;
|
5100
|
+
return txRequest;
|
4725
5101
|
}
|
4726
5102
|
/**
|
4727
5103
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4729,28 +5105,25 @@ var Account = class extends AbstractAccount {
|
|
4729
5105
|
* @param destination - The address of the destination.
|
4730
5106
|
* @param amount - The amount of coins to transfer.
|
4731
5107
|
* @param assetId - The asset ID of the coins to transfer.
|
4732
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5108
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4733
5109
|
* @returns A promise that resolves to the prepared transaction request.
|
4734
5110
|
*/
|
4735
|
-
async createTransfer(destination, amount, assetId
|
4736
|
-
const
|
4737
|
-
const
|
4738
|
-
|
4739
|
-
|
4740
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5111
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5112
|
+
const request = new ScriptTransactionRequest(txParams);
|
5113
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5114
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5115
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4741
5116
|
estimateTxDependencies: true,
|
4742
5117
|
resourcesOwner: this
|
4743
5118
|
});
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
gasPrice: request.gasPrice,
|
4749
|
-
gasLimit: request.gasLimit,
|
4750
|
-
minGasPrice
|
5119
|
+
this.validateGasLimitAndMaxFee({
|
5120
|
+
gasUsed: txCost.gasUsed,
|
5121
|
+
maxFee: txCost.maxFee,
|
5122
|
+
txParams
|
4751
5123
|
});
|
4752
|
-
|
4753
|
-
request.
|
5124
|
+
request.gasLimit = txCost.gasUsed;
|
5125
|
+
request.maxFee = txCost.maxFee;
|
5126
|
+
await this.fund(request, txCost);
|
4754
5127
|
return request;
|
4755
5128
|
}
|
4756
5129
|
/**
|
@@ -4759,17 +5132,18 @@ var Account = class extends AbstractAccount {
|
|
4759
5132
|
* @param destination - The address of the destination.
|
4760
5133
|
* @param amount - The amount of coins to transfer.
|
4761
5134
|
* @param assetId - The asset ID of the coins to transfer.
|
4762
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5135
|
+
* @param txParams - The transaction parameters (gasLimit, maturity).
|
4763
5136
|
* @returns A promise that resolves to the transaction response.
|
4764
5137
|
*/
|
4765
|
-
async transfer(destination, amount, assetId
|
4766
|
-
if (
|
5138
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5139
|
+
if (bn20(amount).lte(0)) {
|
4767
5140
|
throw new FuelError15(
|
4768
5141
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4769
5142
|
"Transfer amount must be a positive number."
|
4770
5143
|
);
|
4771
5144
|
}
|
4772
|
-
const
|
5145
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5146
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4773
5147
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4774
5148
|
}
|
4775
5149
|
/**
|
@@ -4781,39 +5155,38 @@ var Account = class extends AbstractAccount {
|
|
4781
5155
|
* @param txParams - The optional transaction parameters.
|
4782
5156
|
* @returns A promise that resolves to the transaction response.
|
4783
5157
|
*/
|
4784
|
-
async transferToContract(contractId, amount, assetId
|
4785
|
-
if (
|
5158
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5159
|
+
if (bn20(amount).lte(0)) {
|
4786
5160
|
throw new FuelError15(
|
4787
5161
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4788
5162
|
"Transfer amount must be a positive number."
|
4789
5163
|
);
|
4790
5164
|
}
|
4791
5165
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4792
|
-
const
|
4793
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5166
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4794
5167
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4795
5168
|
hexlifiedContractId: contractAddress.toB256(),
|
4796
|
-
amountToTransfer:
|
4797
|
-
assetId
|
5169
|
+
amountToTransfer: bn20(amount),
|
5170
|
+
assetId: assetIdToTransfer
|
4798
5171
|
});
|
4799
5172
|
const request = new ScriptTransactionRequest({
|
4800
|
-
...
|
5173
|
+
...txParams,
|
4801
5174
|
script,
|
4802
5175
|
scriptData
|
4803
5176
|
});
|
4804
5177
|
request.addContractInputAndOutput(contractAddress);
|
4805
|
-
const
|
4806
|
-
|
4807
|
-
[{ amount:
|
4808
|
-
);
|
4809
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4810
|
-
this.validateGas({
|
4811
|
-
gasUsed,
|
4812
|
-
gasPrice: request.gasPrice,
|
4813
|
-
gasLimit: request.gasLimit,
|
4814
|
-
minGasPrice
|
5178
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5179
|
+
resourcesOwner: this,
|
5180
|
+
quantitiesToContract: [{ amount: bn20(amount), assetId: String(assetIdToTransfer) }]
|
4815
5181
|
});
|
4816
|
-
|
5182
|
+
this.validateGasLimitAndMaxFee({
|
5183
|
+
gasUsed: txCost.gasUsed,
|
5184
|
+
maxFee: txCost.maxFee,
|
5185
|
+
txParams
|
5186
|
+
});
|
5187
|
+
request.gasLimit = txCost.gasUsed;
|
5188
|
+
request.maxFee = txCost.maxFee;
|
5189
|
+
await this.fund(request, txCost);
|
4817
5190
|
return this.sendTransaction(request);
|
4818
5191
|
}
|
4819
5192
|
/**
|
@@ -4825,34 +5198,31 @@ var Account = class extends AbstractAccount {
|
|
4825
5198
|
* @returns A promise that resolves to the transaction response.
|
4826
5199
|
*/
|
4827
5200
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4828
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4829
5201
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4830
5202
|
const recipientDataArray = arrayify14(
|
4831
5203
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4832
5204
|
);
|
4833
5205
|
const amountDataArray = arrayify14(
|
4834
|
-
"0x".concat(
|
5206
|
+
"0x".concat(bn20(amount).toHex().substring(2).padStart(16, "0"))
|
4835
5207
|
);
|
4836
5208
|
const script = new Uint8Array([
|
4837
5209
|
...arrayify14(withdrawScript.bytes),
|
4838
5210
|
...recipientDataArray,
|
4839
5211
|
...amountDataArray
|
4840
5212
|
]);
|
4841
|
-
const params = { script,
|
5213
|
+
const params = { script, ...txParams };
|
5214
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4842
5215
|
const request = new ScriptTransactionRequest(params);
|
4843
|
-
const
|
4844
|
-
const
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
this.validateGas({
|
4850
|
-
gasUsed,
|
4851
|
-
gasPrice: request.gasPrice,
|
4852
|
-
gasLimit: request.gasLimit,
|
4853
|
-
minGasPrice
|
5216
|
+
const quantitiesToContract = [{ amount: bn20(amount), assetId: baseAssetId }];
|
5217
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5218
|
+
this.validateGasLimitAndMaxFee({
|
5219
|
+
gasUsed: txCost.gasUsed,
|
5220
|
+
maxFee: txCost.maxFee,
|
5221
|
+
txParams
|
4854
5222
|
});
|
4855
|
-
|
5223
|
+
request.maxFee = txCost.maxFee;
|
5224
|
+
request.gasLimit = txCost.gasUsed;
|
5225
|
+
await this.fund(request, txCost);
|
4856
5226
|
return this.sendTransaction(request);
|
4857
5227
|
}
|
4858
5228
|
async signMessage(message) {
|
@@ -4910,22 +5280,21 @@ var Account = class extends AbstractAccount {
|
|
4910
5280
|
}
|
4911
5281
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4912
5282
|
}
|
4913
|
-
|
5283
|
+
validateGasLimitAndMaxFee({
|
5284
|
+
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
4914
5285
|
gasUsed,
|
4915
|
-
|
4916
|
-
gasLimit,
|
4917
|
-
minGasPrice
|
5286
|
+
maxFee
|
4918
5287
|
}) {
|
4919
|
-
if (
|
5288
|
+
if (isDefined2(setGasLimit) && gasUsed.gt(setGasLimit)) {
|
4920
5289
|
throw new FuelError15(
|
4921
|
-
ErrorCode15.
|
4922
|
-
`Gas
|
5290
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
5291
|
+
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
4923
5292
|
);
|
4924
5293
|
}
|
4925
|
-
if (
|
5294
|
+
if (isDefined2(setMaxFee) && maxFee.gt(setMaxFee)) {
|
4926
5295
|
throw new FuelError15(
|
4927
|
-
ErrorCode15.
|
4928
|
-
`
|
5296
|
+
ErrorCode15.MAX_FEE_TOO_LOW,
|
5297
|
+
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
4929
5298
|
);
|
4930
5299
|
}
|
4931
5300
|
}
|
@@ -5213,7 +5582,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5213
5582
|
* @param transactionRequestLike - The transaction request to send.
|
5214
5583
|
* @returns A promise that resolves to the TransactionResponse object.
|
5215
5584
|
*/
|
5216
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5585
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5217
5586
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5218
5587
|
if (estimateTxDependencies) {
|
5219
5588
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5254,7 +5623,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5254
5623
|
// src/hdwallet/hdwallet.ts
|
5255
5624
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5256
5625
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5257
|
-
import { bn as
|
5626
|
+
import { bn as bn21, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5258
5627
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5259
5628
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5260
5629
|
|
@@ -7720,7 +8089,7 @@ var HDWallet = class {
|
|
7720
8089
|
const IR = bytes.slice(32);
|
7721
8090
|
if (privateKey) {
|
7722
8091
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7723
|
-
const ki =
|
8092
|
+
const ki = bn21(IL).add(privateKey).mod(N).toBytes(32);
|
7724
8093
|
return new HDWallet({
|
7725
8094
|
privateKey: ki,
|
7726
8095
|
chainCode: IR,
|
@@ -7991,14 +8360,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7991
8360
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
7992
8361
|
wallet.provider
|
7993
8362
|
);
|
7994
|
-
const
|
7995
|
-
|
7996
|
-
|
7997
|
-
|
7998
|
-
gasPrice: minGasPrice
|
8363
|
+
const request = new ScriptTransactionRequest();
|
8364
|
+
quantities.forEach((quantity) => {
|
8365
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8366
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7999
8367
|
});
|
8000
|
-
|
8001
|
-
|
8368
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8369
|
+
request.gasLimit = txCost.gasUsed;
|
8370
|
+
request.maxFee = txCost.maxFee;
|
8371
|
+
await genesisWallet.fund(request, txCost);
|
8002
8372
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8003
8373
|
};
|
8004
8374
|
|
@@ -8012,9 +8382,9 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8012
8382
|
};
|
8013
8383
|
|
8014
8384
|
// src/test-utils/launchNode.ts
|
8015
|
-
import {
|
8016
|
-
import {
|
8017
|
-
import {
|
8385
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8386
|
+
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8387
|
+
import { defaultSnapshotConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8018
8388
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8019
8389
|
import { spawn } from "child_process";
|
8020
8390
|
import { randomUUID } from "crypto";
|
@@ -8066,12 +8436,12 @@ var launchNode = async ({
|
|
8066
8436
|
// eslint-disable-next-line no-async-promise-executor
|
8067
8437
|
new Promise(async (resolve, reject) => {
|
8068
8438
|
const remainingArgs = extractRemainingArgs(args, [
|
8069
|
-
"--
|
8439
|
+
"--snapshot",
|
8070
8440
|
"--consensus-key",
|
8071
8441
|
"--db-type",
|
8072
8442
|
"--poa-instant"
|
8073
8443
|
]);
|
8074
|
-
const
|
8444
|
+
const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
|
8075
8445
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8076
8446
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8077
8447
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8087,39 +8457,59 @@ var launchNode = async ({
|
|
8087
8457
|
stopPort: 5e3
|
8088
8458
|
// don't try ports above 5000
|
8089
8459
|
})).toString();
|
8090
|
-
let
|
8460
|
+
let snapshotDirToUse;
|
8091
8461
|
const prefix = basePath || os.tmpdir();
|
8092
8462
|
const suffix = basePath ? "" : randomUUID();
|
8093
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8094
|
-
if (
|
8095
|
-
|
8463
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8464
|
+
if (snapshotDir) {
|
8465
|
+
snapshotDirToUse = snapshotDir;
|
8096
8466
|
} else {
|
8097
8467
|
if (!existsSync(tempDirPath)) {
|
8098
8468
|
mkdirSync(tempDirPath, { recursive: true });
|
8099
8469
|
}
|
8100
|
-
|
8101
|
-
|
8470
|
+
let { stateConfigJson } = defaultSnapshotConfigs;
|
8471
|
+
const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
|
8472
|
+
stateConfigJson = {
|
8473
|
+
...stateConfigJson,
|
8474
|
+
coins: [
|
8475
|
+
...stateConfigJson.coins.map((coin) => ({
|
8476
|
+
...coin,
|
8477
|
+
amount: "18446744073709551615"
|
8478
|
+
}))
|
8479
|
+
],
|
8480
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8481
|
+
...message,
|
8482
|
+
amount: "18446744073709551615"
|
8483
|
+
}))
|
8484
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8485
|
+
};
|
8102
8486
|
if (!process.env.GENESIS_SECRET) {
|
8103
8487
|
const pk = Signer.generatePrivateKey();
|
8104
8488
|
const signer = new Signer(pk);
|
8105
8489
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8106
|
-
|
8107
|
-
|
8108
|
-
|
8109
|
-
|
8110
|
-
|
8111
|
-
|
8112
|
-
|
8113
|
-
|
8114
|
-
|
8115
|
-
|
8116
|
-
}
|
8117
|
-
]
|
8118
|
-
}
|
8119
|
-
};
|
8490
|
+
stateConfigJson.coins.push({
|
8491
|
+
tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
|
8492
|
+
owner: signer.address.toHexString(),
|
8493
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8494
|
+
amount: "18446744073709551615",
|
8495
|
+
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8496
|
+
output_index: 0,
|
8497
|
+
tx_pointer_block_height: 0,
|
8498
|
+
tx_pointer_tx_idx: 0
|
8499
|
+
});
|
8120
8500
|
}
|
8121
|
-
|
8122
|
-
|
8501
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8502
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8503
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8504
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8505
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8506
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8507
|
+
const stateTransitionWritePath = path.join(tempDirPath, "state_transition_bytecode.wasm");
|
8508
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8509
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8510
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8511
|
+
writeFileSync(stateTransitionWritePath, JSON.stringify(""));
|
8512
|
+
snapshotDirToUse = tempDirPath;
|
8123
8513
|
}
|
8124
8514
|
const child = spawn(
|
8125
8515
|
command,
|
@@ -8128,10 +8518,10 @@ var launchNode = async ({
|
|
8128
8518
|
["--ip", ipToUse],
|
8129
8519
|
["--port", portToUse],
|
8130
8520
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8131
|
-
["--min-gas-price", "
|
8521
|
+
["--min-gas-price", "1"],
|
8132
8522
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8133
8523
|
["--consensus-key", consensusKey],
|
8134
|
-
["--
|
8524
|
+
["--snapshot", snapshotDirToUse],
|
8135
8525
|
"--vm-backtrace",
|
8136
8526
|
"--utxo-validation",
|
8137
8527
|
"--debug",
|
@@ -8161,7 +8551,7 @@ var launchNode = async ({
|
|
8161
8551
|
cleanup: () => killNode(cleanupConfig),
|
8162
8552
|
ip: ipToUse,
|
8163
8553
|
port: portToUse,
|
8164
|
-
|
8554
|
+
snapshotDir: snapshotDirToUse
|
8165
8555
|
});
|
8166
8556
|
}
|
8167
8557
|
if (/error/i.test(chunk)) {
|
@@ -8178,9 +8568,10 @@ var launchNode = async ({
|
|
8178
8568
|
})
|
8179
8569
|
);
|
8180
8570
|
var generateWallets = async (count, provider) => {
|
8571
|
+
const baseAssetId = provider.getBaseAssetId();
|
8181
8572
|
const wallets = [];
|
8182
8573
|
for (let i = 0; i < count; i += 1) {
|
8183
|
-
const wallet = await generateTestWallet(provider, [[
|
8574
|
+
const wallet = await generateTestWallet(provider, [[1e5, baseAssetId]]);
|
8184
8575
|
wallets.push(wallet);
|
8185
8576
|
}
|
8186
8577
|
return wallets;
|
@@ -8190,7 +8581,7 @@ var launchNodeAndGetWallets = async ({
|
|
8190
8581
|
walletCount = 10
|
8191
8582
|
} = {}) => {
|
8192
8583
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8193
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8584
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8194
8585
|
const wallets = await generateWallets(walletCount, provider);
|
8195
8586
|
const cleanup = () => {
|
8196
8587
|
closeNode();
|