@fuel-ts/account 0.0.0-rc-2152-20240425194419 → 0.0.0-rc-2021-20240425202957
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +7 -6
- 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 +1818 -696
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +796 -545
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +671 -421
- 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 +810 -359
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +46 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +8 -28
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +2544 -1193
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +782 -536
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +669 -423
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -26,8 +26,9 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
|
-
import { bn as
|
30
|
-
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
29
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
30
|
+
import { arrayify as arrayify14, isDefined } from "@fuel-ts/utils";
|
31
|
+
import { clone as clone4 } from "ramda";
|
31
32
|
|
32
33
|
// src/providers/coin-quantity.ts
|
33
34
|
import { bn } from "@fuel-ts/math";
|
@@ -35,24 +36,24 @@ import { hexlify } from "@fuel-ts/utils";
|
|
35
36
|
var coinQuantityfy = (coinQuantityLike) => {
|
36
37
|
let assetId;
|
37
38
|
let amount;
|
38
|
-
let
|
39
|
+
let max;
|
39
40
|
if (Array.isArray(coinQuantityLike)) {
|
40
41
|
amount = coinQuantityLike[0];
|
41
42
|
assetId = coinQuantityLike[1];
|
42
|
-
|
43
|
+
max = coinQuantityLike[2] ?? void 0;
|
43
44
|
} else {
|
44
45
|
amount = coinQuantityLike.amount;
|
45
46
|
assetId = coinQuantityLike.assetId;
|
46
|
-
|
47
|
+
max = coinQuantityLike.max ?? void 0;
|
47
48
|
}
|
48
49
|
const bnAmount = bn(amount);
|
49
50
|
return {
|
50
51
|
assetId: hexlify(assetId),
|
51
52
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
52
|
-
max:
|
53
|
+
max: max ? bn(max) : void 0
|
53
54
|
};
|
54
55
|
};
|
55
|
-
var
|
56
|
+
var addAmountToCoinQuantities = (params) => {
|
56
57
|
const { amount, assetId } = params;
|
57
58
|
const coinQuantities = [...params.coinQuantities];
|
58
59
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -67,9 +68,9 @@ var addAmountToAsset = (params) => {
|
|
67
68
|
// src/providers/provider.ts
|
68
69
|
import { Address as Address2 } from "@fuel-ts/address";
|
69
70
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
70
|
-
import { BN, bn as
|
71
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
71
72
|
import {
|
72
|
-
InputType as
|
73
|
+
InputType as InputType7,
|
73
74
|
TransactionType as TransactionType8,
|
74
75
|
InputMessageCoder,
|
75
76
|
TransactionCoder as TransactionCoder5
|
@@ -77,21 +78,26 @@ import {
|
|
77
78
|
import { arrayify as arrayify11, hexlify as hexlify12, DateTime as DateTime2 } from "@fuel-ts/utils";
|
78
79
|
import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
|
79
80
|
import { equalBytes } from "@noble/curves/abstract/utils";
|
81
|
+
import { Network } from "ethers";
|
80
82
|
import { GraphQLClient } from "graphql-request";
|
81
83
|
import { clone as clone3 } from "ramda";
|
82
84
|
|
83
85
|
// src/providers/__generated__/operations.ts
|
84
86
|
import gql from "graphql-tag";
|
87
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
|
88
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
89
|
+
type: __typename
|
90
|
+
... on SqueezedOutStatus {
|
91
|
+
reason
|
92
|
+
}
|
93
|
+
}
|
94
|
+
`;
|
85
95
|
var ReceiptFragmentFragmentDoc = gql`
|
86
96
|
fragment receiptFragment on Receipt {
|
87
|
-
|
88
|
-
id
|
89
|
-
}
|
97
|
+
id
|
90
98
|
pc
|
91
99
|
is
|
92
|
-
to
|
93
|
-
id
|
94
|
-
}
|
100
|
+
to
|
95
101
|
toAddress
|
96
102
|
amount
|
97
103
|
assetId
|
@@ -129,10 +135,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
129
135
|
id
|
130
136
|
}
|
131
137
|
time
|
138
|
+
receipts {
|
139
|
+
...receiptFragment
|
140
|
+
}
|
132
141
|
programState {
|
133
142
|
returnType
|
134
143
|
data
|
135
144
|
}
|
145
|
+
receipts {
|
146
|
+
...receiptFragment
|
147
|
+
}
|
136
148
|
}
|
137
149
|
... on FailureStatus {
|
138
150
|
block {
|
@@ -140,26 +152,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
140
152
|
}
|
141
153
|
time
|
142
154
|
reason
|
155
|
+
receipts {
|
156
|
+
...receiptFragment
|
157
|
+
}
|
143
158
|
}
|
144
159
|
... on SqueezedOutStatus {
|
145
160
|
reason
|
146
161
|
}
|
147
162
|
}
|
148
|
-
`;
|
163
|
+
${ReceiptFragmentFragmentDoc}`;
|
149
164
|
var TransactionFragmentFragmentDoc = gql`
|
150
165
|
fragment transactionFragment on Transaction {
|
151
166
|
id
|
152
167
|
rawPayload
|
153
|
-
gasPrice
|
154
|
-
receipts {
|
155
|
-
...receiptFragment
|
156
|
-
}
|
157
168
|
status {
|
158
169
|
...transactionStatusFragment
|
159
170
|
}
|
160
171
|
}
|
161
|
-
${
|
162
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
172
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
163
173
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
164
174
|
fragment inputEstimatePredicatesFragment on Input {
|
165
175
|
... on InputCoin {
|
@@ -177,6 +187,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
177
187
|
}
|
178
188
|
}
|
179
189
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
190
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
191
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
192
|
+
reason
|
193
|
+
programState {
|
194
|
+
returnType
|
195
|
+
data
|
196
|
+
}
|
197
|
+
}
|
198
|
+
`;
|
199
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
200
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
201
|
+
programState {
|
202
|
+
returnType
|
203
|
+
data
|
204
|
+
}
|
205
|
+
}
|
206
|
+
`;
|
207
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
208
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
209
|
+
... on DryRunFailureStatus {
|
210
|
+
...dryRunFailureStatusFragment
|
211
|
+
}
|
212
|
+
... on DryRunSuccessStatus {
|
213
|
+
...dryRunSuccessStatusFragment
|
214
|
+
}
|
215
|
+
}
|
216
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
217
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
218
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
219
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
220
|
+
id
|
221
|
+
status {
|
222
|
+
...dryRunTransactionStatusFragment
|
223
|
+
}
|
224
|
+
receipts {
|
225
|
+
...receiptFragment
|
226
|
+
}
|
227
|
+
}
|
228
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
229
|
+
${ReceiptFragmentFragmentDoc}`;
|
180
230
|
var CoinFragmentFragmentDoc = gql`
|
181
231
|
fragment coinFragment on Coin {
|
182
232
|
__typename
|
@@ -184,7 +234,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
184
234
|
owner
|
185
235
|
amount
|
186
236
|
assetId
|
187
|
-
maturity
|
188
237
|
blockCreated
|
189
238
|
txCreatedIdx
|
190
239
|
}
|
@@ -223,26 +272,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
223
272
|
messageBlockHeader {
|
224
273
|
id
|
225
274
|
daHeight
|
275
|
+
consensusParametersVersion
|
276
|
+
stateTransitionBytecodeVersion
|
226
277
|
transactionsCount
|
278
|
+
messageReceiptCount
|
227
279
|
transactionsRoot
|
280
|
+
messageOutboxRoot
|
281
|
+
eventInboxRoot
|
228
282
|
height
|
229
283
|
prevRoot
|
230
284
|
time
|
231
285
|
applicationHash
|
232
|
-
messageReceiptRoot
|
233
|
-
messageReceiptCount
|
234
286
|
}
|
235
287
|
commitBlockHeader {
|
236
288
|
id
|
237
289
|
daHeight
|
290
|
+
consensusParametersVersion
|
291
|
+
stateTransitionBytecodeVersion
|
238
292
|
transactionsCount
|
293
|
+
messageReceiptCount
|
239
294
|
transactionsRoot
|
295
|
+
messageOutboxRoot
|
296
|
+
eventInboxRoot
|
240
297
|
height
|
241
298
|
prevRoot
|
242
299
|
time
|
243
300
|
applicationHash
|
244
|
-
messageReceiptRoot
|
245
|
-
messageReceiptCount
|
246
301
|
}
|
247
302
|
sender
|
248
303
|
recipient
|
@@ -261,8 +316,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
261
316
|
var BlockFragmentFragmentDoc = gql`
|
262
317
|
fragment blockFragment on Block {
|
263
318
|
id
|
319
|
+
height
|
264
320
|
header {
|
265
|
-
height
|
266
321
|
time
|
267
322
|
}
|
268
323
|
transactions {
|
@@ -272,6 +327,7 @@ var BlockFragmentFragmentDoc = gql`
|
|
272
327
|
`;
|
273
328
|
var TxParametersFragmentFragmentDoc = gql`
|
274
329
|
fragment TxParametersFragment on TxParameters {
|
330
|
+
version
|
275
331
|
maxInputs
|
276
332
|
maxOutputs
|
277
333
|
maxWitnesses
|
@@ -281,6 +337,7 @@ var TxParametersFragmentFragmentDoc = gql`
|
|
281
337
|
`;
|
282
338
|
var PredicateParametersFragmentFragmentDoc = gql`
|
283
339
|
fragment PredicateParametersFragment on PredicateParameters {
|
340
|
+
version
|
284
341
|
maxPredicateLength
|
285
342
|
maxPredicateDataLength
|
286
343
|
maxGasPerPredicate
|
@@ -289,18 +346,21 @@ var PredicateParametersFragmentFragmentDoc = gql`
|
|
289
346
|
`;
|
290
347
|
var ScriptParametersFragmentFragmentDoc = gql`
|
291
348
|
fragment ScriptParametersFragment on ScriptParameters {
|
349
|
+
version
|
292
350
|
maxScriptLength
|
293
351
|
maxScriptDataLength
|
294
352
|
}
|
295
353
|
`;
|
296
354
|
var ContractParametersFragmentFragmentDoc = gql`
|
297
355
|
fragment ContractParametersFragment on ContractParameters {
|
356
|
+
version
|
298
357
|
contractMaxSize
|
299
358
|
maxStorageSlots
|
300
359
|
}
|
301
360
|
`;
|
302
361
|
var FeeParametersFragmentFragmentDoc = gql`
|
303
362
|
fragment FeeParametersFragment on FeeParameters {
|
363
|
+
version
|
304
364
|
gasPriceFactor
|
305
365
|
gasPerByte
|
306
366
|
}
|
@@ -320,6 +380,7 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
320
380
|
`;
|
321
381
|
var GasCostsFragmentFragmentDoc = gql`
|
322
382
|
fragment GasCostsFragment on GasCosts {
|
383
|
+
version
|
323
384
|
add
|
324
385
|
addi
|
325
386
|
aloc
|
@@ -332,7 +393,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
332
393
|
cb
|
333
394
|
cfei
|
334
395
|
cfsi
|
335
|
-
croo
|
336
396
|
div
|
337
397
|
divi
|
338
398
|
ecr1
|
@@ -415,6 +475,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
415
475
|
ccp {
|
416
476
|
...DependentCostFragment
|
417
477
|
}
|
478
|
+
croo {
|
479
|
+
...DependentCostFragment
|
480
|
+
}
|
418
481
|
csiz {
|
419
482
|
...DependentCostFragment
|
420
483
|
}
|
@@ -474,6 +537,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
474
537
|
${DependentCostFragmentFragmentDoc}`;
|
475
538
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
476
539
|
fragment consensusParametersFragment on ConsensusParameters {
|
540
|
+
version
|
477
541
|
txParams {
|
478
542
|
...TxParametersFragment
|
479
543
|
}
|
@@ -533,18 +597,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
533
597
|
fragment nodeInfoFragment on NodeInfo {
|
534
598
|
utxoValidation
|
535
599
|
vmBacktrace
|
536
|
-
minGasPrice
|
537
600
|
maxTx
|
538
601
|
maxDepth
|
539
602
|
nodeVersion
|
540
|
-
peers {
|
541
|
-
id
|
542
|
-
addresses
|
543
|
-
clientVersion
|
544
|
-
blockHeight
|
545
|
-
lastHeartbeatMs
|
546
|
-
appScore
|
547
|
-
}
|
548
603
|
}
|
549
604
|
`;
|
550
605
|
var GetVersionDocument = gql`
|
@@ -579,13 +634,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
579
634
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
580
635
|
transaction(id: $transactionId) {
|
581
636
|
...transactionFragment
|
582
|
-
receipts {
|
583
|
-
...receiptFragment
|
584
|
-
}
|
585
637
|
}
|
586
638
|
}
|
587
|
-
${TransactionFragmentFragmentDoc}
|
588
|
-
${ReceiptFragmentFragmentDoc}`;
|
639
|
+
${TransactionFragmentFragmentDoc}`;
|
589
640
|
var GetTransactionsDocument = gql`
|
590
641
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
591
642
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -713,6 +764,20 @@ var GetBalanceDocument = gql`
|
|
713
764
|
}
|
714
765
|
}
|
715
766
|
${BalanceFragmentFragmentDoc}`;
|
767
|
+
var GetLatestGasPriceDocument = gql`
|
768
|
+
query getLatestGasPrice {
|
769
|
+
latestGasPrice {
|
770
|
+
gasPrice
|
771
|
+
}
|
772
|
+
}
|
773
|
+
`;
|
774
|
+
var EstimateGasPriceDocument = gql`
|
775
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
776
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
777
|
+
gasPrice
|
778
|
+
}
|
779
|
+
}
|
780
|
+
`;
|
716
781
|
var GetBalancesDocument = gql`
|
717
782
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
718
783
|
balances(
|
@@ -767,12 +832,12 @@ var GetMessageStatusDocument = gql`
|
|
767
832
|
}
|
768
833
|
`;
|
769
834
|
var DryRunDocument = gql`
|
770
|
-
mutation dryRun($
|
771
|
-
dryRun(
|
772
|
-
...
|
835
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
836
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
837
|
+
...dryRunTransactionExecutionStatusFragment
|
773
838
|
}
|
774
839
|
}
|
775
|
-
${
|
840
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
776
841
|
var SubmitDocument = gql`
|
777
842
|
mutation submit($encodedTransaction: HexString!) {
|
778
843
|
submit(tx: $encodedTransaction) {
|
@@ -791,17 +856,17 @@ var ProduceBlocksDocument = gql`
|
|
791
856
|
var SubmitAndAwaitDocument = gql`
|
792
857
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
793
858
|
submitAndAwait(tx: $encodedTransaction) {
|
794
|
-
...
|
859
|
+
...transactionStatusSubscriptionFragment
|
795
860
|
}
|
796
861
|
}
|
797
|
-
${
|
862
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
798
863
|
var StatusChangeDocument = gql`
|
799
864
|
subscription statusChange($transactionId: TransactionId!) {
|
800
865
|
statusChange(id: $transactionId) {
|
801
|
-
...
|
866
|
+
...transactionStatusSubscriptionFragment
|
802
867
|
}
|
803
868
|
}
|
804
|
-
${
|
869
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
805
870
|
function getSdk(requester) {
|
806
871
|
return {
|
807
872
|
getVersion(variables, options) {
|
@@ -855,6 +920,12 @@ function getSdk(requester) {
|
|
855
920
|
getBalance(variables, options) {
|
856
921
|
return requester(GetBalanceDocument, variables, options);
|
857
922
|
},
|
923
|
+
getLatestGasPrice(variables, options) {
|
924
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
925
|
+
},
|
926
|
+
estimateGasPrice(variables, options) {
|
927
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
928
|
+
},
|
858
929
|
getBalances(variables, options) {
|
859
930
|
return requester(GetBalancesDocument, variables, options);
|
860
931
|
},
|
@@ -1048,10 +1119,9 @@ var inputify = (value) => {
|
|
1048
1119
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1049
1120
|
},
|
1050
1121
|
witnessIndex: value.witnessIndex,
|
1051
|
-
maturity: value.maturity ?? 0,
|
1052
1122
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1053
|
-
predicateLength: predicate.length,
|
1054
|
-
predicateDataLength: predicateData.length,
|
1123
|
+
predicateLength: bn2(predicate.length),
|
1124
|
+
predicateDataLength: bn2(predicateData.length),
|
1055
1125
|
predicate: hexlify3(predicate),
|
1056
1126
|
predicateData: hexlify3(predicateData)
|
1057
1127
|
};
|
@@ -1082,8 +1152,8 @@ var inputify = (value) => {
|
|
1082
1152
|
nonce: hexlify3(value.nonce),
|
1083
1153
|
witnessIndex: value.witnessIndex,
|
1084
1154
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1085
|
-
predicateLength: predicate.length,
|
1086
|
-
predicateDataLength: predicateData.length,
|
1155
|
+
predicateLength: bn2(predicate.length),
|
1156
|
+
predicateDataLength: bn2(predicateData.length),
|
1087
1157
|
predicate: hexlify3(predicate),
|
1088
1158
|
predicateData: hexlify3(predicateData),
|
1089
1159
|
data: hexlify3(data),
|
@@ -1210,8 +1280,8 @@ function assembleReceiptByType(receipt) {
|
|
1210
1280
|
case "CALL" /* Call */: {
|
1211
1281
|
const callReceipt = {
|
1212
1282
|
type: ReceiptType.Call,
|
1213
|
-
from: hexOrZero(receipt.
|
1214
|
-
to: hexOrZero(receipt?.to
|
1283
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1284
|
+
to: hexOrZero(receipt?.to),
|
1215
1285
|
amount: bn4(receipt.amount),
|
1216
1286
|
assetId: hexOrZero(receipt.assetId),
|
1217
1287
|
gas: bn4(receipt.gas),
|
@@ -1225,7 +1295,7 @@ function assembleReceiptByType(receipt) {
|
|
1225
1295
|
case "RETURN" /* Return */: {
|
1226
1296
|
const returnReceipt = {
|
1227
1297
|
type: ReceiptType.Return,
|
1228
|
-
id: hexOrZero(receipt.
|
1298
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1229
1299
|
val: bn4(receipt.val),
|
1230
1300
|
pc: bn4(receipt.pc),
|
1231
1301
|
is: bn4(receipt.is)
|
@@ -1235,7 +1305,7 @@ function assembleReceiptByType(receipt) {
|
|
1235
1305
|
case "RETURN_DATA" /* ReturnData */: {
|
1236
1306
|
const returnDataReceipt = {
|
1237
1307
|
type: ReceiptType.ReturnData,
|
1238
|
-
id: hexOrZero(receipt.
|
1308
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1239
1309
|
ptr: bn4(receipt.ptr),
|
1240
1310
|
len: bn4(receipt.len),
|
1241
1311
|
digest: hexOrZero(receipt.digest),
|
@@ -1247,7 +1317,7 @@ function assembleReceiptByType(receipt) {
|
|
1247
1317
|
case "PANIC" /* Panic */: {
|
1248
1318
|
const panicReceipt = {
|
1249
1319
|
type: ReceiptType.Panic,
|
1250
|
-
id: hexOrZero(receipt.
|
1320
|
+
id: hexOrZero(receipt.id),
|
1251
1321
|
reason: bn4(receipt.reason),
|
1252
1322
|
pc: bn4(receipt.pc),
|
1253
1323
|
is: bn4(receipt.is),
|
@@ -1258,7 +1328,7 @@ function assembleReceiptByType(receipt) {
|
|
1258
1328
|
case "REVERT" /* Revert */: {
|
1259
1329
|
const revertReceipt = {
|
1260
1330
|
type: ReceiptType.Revert,
|
1261
|
-
id: hexOrZero(receipt.
|
1331
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1262
1332
|
val: bn4(receipt.ra),
|
1263
1333
|
pc: bn4(receipt.pc),
|
1264
1334
|
is: bn4(receipt.is)
|
@@ -1268,7 +1338,7 @@ function assembleReceiptByType(receipt) {
|
|
1268
1338
|
case "LOG" /* Log */: {
|
1269
1339
|
const logReceipt = {
|
1270
1340
|
type: ReceiptType.Log,
|
1271
|
-
id: hexOrZero(receipt.
|
1341
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1272
1342
|
val0: bn4(receipt.ra),
|
1273
1343
|
val1: bn4(receipt.rb),
|
1274
1344
|
val2: bn4(receipt.rc),
|
@@ -1281,7 +1351,7 @@ function assembleReceiptByType(receipt) {
|
|
1281
1351
|
case "LOG_DATA" /* LogData */: {
|
1282
1352
|
const logDataReceipt = {
|
1283
1353
|
type: ReceiptType.LogData,
|
1284
|
-
id: hexOrZero(receipt.
|
1354
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1285
1355
|
val0: bn4(receipt.ra),
|
1286
1356
|
val1: bn4(receipt.rb),
|
1287
1357
|
ptr: bn4(receipt.ptr),
|
@@ -1295,8 +1365,8 @@ function assembleReceiptByType(receipt) {
|
|
1295
1365
|
case "TRANSFER" /* Transfer */: {
|
1296
1366
|
const transferReceipt = {
|
1297
1367
|
type: ReceiptType.Transfer,
|
1298
|
-
from: hexOrZero(receipt.
|
1299
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1368
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1369
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1300
1370
|
amount: bn4(receipt.amount),
|
1301
1371
|
assetId: hexOrZero(receipt.assetId),
|
1302
1372
|
pc: bn4(receipt.pc),
|
@@ -1307,8 +1377,8 @@ function assembleReceiptByType(receipt) {
|
|
1307
1377
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1308
1378
|
const transferOutReceipt = {
|
1309
1379
|
type: ReceiptType.TransferOut,
|
1310
|
-
from: hexOrZero(receipt.
|
1311
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1380
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1381
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1312
1382
|
amount: bn4(receipt.amount),
|
1313
1383
|
assetId: hexOrZero(receipt.assetId),
|
1314
1384
|
pc: bn4(receipt.pc),
|
@@ -1351,7 +1421,7 @@ function assembleReceiptByType(receipt) {
|
|
1351
1421
|
return receiptMessageOut;
|
1352
1422
|
}
|
1353
1423
|
case "MINT" /* Mint */: {
|
1354
|
-
const contractId = hexOrZero(receipt.
|
1424
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1355
1425
|
const subId = hexOrZero(receipt.subId);
|
1356
1426
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1357
1427
|
const mintReceipt = {
|
@@ -1366,7 +1436,7 @@ function assembleReceiptByType(receipt) {
|
|
1366
1436
|
return mintReceipt;
|
1367
1437
|
}
|
1368
1438
|
case "BURN" /* Burn */: {
|
1369
|
-
const contractId = hexOrZero(receipt.
|
1439
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1370
1440
|
const subId = hexOrZero(receipt.subId);
|
1371
1441
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1372
1442
|
const burnReceipt = {
|
@@ -1392,7 +1462,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1392
1462
|
import { bn as bn5 } from "@fuel-ts/math";
|
1393
1463
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1394
1464
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1395
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1396
1465
|
var getGasUsedFromReceipts = (receipts) => {
|
1397
1466
|
const scriptResult = receipts.filter(
|
1398
1467
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1413,18 +1482,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1413
1482
|
}
|
1414
1483
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1415
1484
|
const witnessCache = [];
|
1416
|
-
const
|
1485
|
+
const chargeableInputs = inputs.filter((input) => {
|
1486
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1487
|
+
if (isCoinOrMessage) {
|
1488
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1489
|
+
return true;
|
1490
|
+
}
|
1491
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1492
|
+
witnessCache.push(input.witnessIndex);
|
1493
|
+
return true;
|
1494
|
+
}
|
1495
|
+
}
|
1496
|
+
return false;
|
1497
|
+
});
|
1498
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1499
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1417
1500
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1418
1501
|
return total.add(
|
1419
|
-
|
1502
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1420
1503
|
);
|
1421
1504
|
}
|
1422
|
-
|
1423
|
-
|
1424
|
-
return total.add(gasCosts.ecr1);
|
1425
|
-
}
|
1426
|
-
return total;
|
1427
|
-
}, bn5());
|
1505
|
+
return total.add(gasCosts.ecr1);
|
1506
|
+
}, bn5(0));
|
1428
1507
|
return totalGas;
|
1429
1508
|
}
|
1430
1509
|
function getMinGas(params) {
|
@@ -1436,12 +1515,20 @@ function getMinGas(params) {
|
|
1436
1515
|
return minGas;
|
1437
1516
|
}
|
1438
1517
|
function getMaxGas(params) {
|
1439
|
-
const {
|
1518
|
+
const {
|
1519
|
+
gasPerByte,
|
1520
|
+
witnessesLength,
|
1521
|
+
witnessLimit,
|
1522
|
+
minGas,
|
1523
|
+
gasLimit = bn5(0),
|
1524
|
+
maxGasPerTx
|
1525
|
+
} = params;
|
1440
1526
|
let remainingAllowedWitnessGas = bn5(0);
|
1441
1527
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1442
1528
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1443
1529
|
}
|
1444
|
-
|
1530
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1531
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1445
1532
|
}
|
1446
1533
|
function calculateMetadataGasForTxCreate({
|
1447
1534
|
gasCosts,
|
@@ -1463,6 +1550,10 @@ function calculateMetadataGasForTxScript({
|
|
1463
1550
|
}) {
|
1464
1551
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1465
1552
|
}
|
1553
|
+
var calculateGasFee = (params) => {
|
1554
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1555
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1556
|
+
};
|
1466
1557
|
|
1467
1558
|
// src/providers/utils/json.ts
|
1468
1559
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1607,7 +1698,7 @@ var witnessify = (value) => {
|
|
1607
1698
|
// src/providers/transaction-request/transaction-request.ts
|
1608
1699
|
var BaseTransactionRequest = class {
|
1609
1700
|
/** Gas price for transaction */
|
1610
|
-
|
1701
|
+
tip;
|
1611
1702
|
/** Block until which tx cannot be included */
|
1612
1703
|
maturity;
|
1613
1704
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1626,7 +1717,7 @@ var BaseTransactionRequest = class {
|
|
1626
1717
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1627
1718
|
*/
|
1628
1719
|
constructor({
|
1629
|
-
|
1720
|
+
tip,
|
1630
1721
|
maturity,
|
1631
1722
|
maxFee,
|
1632
1723
|
witnessLimit,
|
@@ -1634,7 +1725,7 @@ var BaseTransactionRequest = class {
|
|
1634
1725
|
outputs,
|
1635
1726
|
witnesses
|
1636
1727
|
} = {}) {
|
1637
|
-
this.
|
1728
|
+
this.tip = bn7(tip);
|
1638
1729
|
this.maturity = maturity ?? 0;
|
1639
1730
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1640
1731
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1645,9 +1736,9 @@ var BaseTransactionRequest = class {
|
|
1645
1736
|
static getPolicyMeta(req) {
|
1646
1737
|
let policyTypes = 0;
|
1647
1738
|
const policies = [];
|
1648
|
-
if (req.
|
1649
|
-
policyTypes += PolicyType.
|
1650
|
-
policies.push({ data: req.
|
1739
|
+
if (req.tip) {
|
1740
|
+
policyTypes += PolicyType.Tip;
|
1741
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1651
1742
|
}
|
1652
1743
|
if (req.witnessLimit) {
|
1653
1744
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1831,13 +1922,11 @@ var BaseTransactionRequest = class {
|
|
1831
1922
|
* assetId, if one it was not added yet.
|
1832
1923
|
*
|
1833
1924
|
* @param coin - Coin resource.
|
1834
|
-
* @param predicate - Predicate bytes.
|
1835
|
-
* @param predicateData - Predicate data bytes.
|
1836
1925
|
*/
|
1837
|
-
addCoinInput(coin
|
1926
|
+
addCoinInput(coin) {
|
1838
1927
|
const { assetId, owner, amount } = coin;
|
1839
1928
|
let witnessIndex;
|
1840
|
-
if (predicate) {
|
1929
|
+
if (coin.predicate) {
|
1841
1930
|
witnessIndex = 0;
|
1842
1931
|
} else {
|
1843
1932
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1852,8 +1941,7 @@ var BaseTransactionRequest = class {
|
|
1852
1941
|
amount,
|
1853
1942
|
assetId,
|
1854
1943
|
txPointer: "0x00000000000000000000000000000000",
|
1855
|
-
witnessIndex
|
1856
|
-
predicate: predicate?.bytes
|
1944
|
+
witnessIndex
|
1857
1945
|
};
|
1858
1946
|
this.pushInput(input);
|
1859
1947
|
this.addChangeOutput(owner, assetId);
|
@@ -1863,12 +1951,11 @@ var BaseTransactionRequest = class {
|
|
1863
1951
|
* asset against the message
|
1864
1952
|
*
|
1865
1953
|
* @param message - Message resource.
|
1866
|
-
* @param predicate - Predicate bytes.
|
1867
1954
|
*/
|
1868
|
-
addMessageInput(message
|
1955
|
+
addMessageInput(message) {
|
1869
1956
|
const { recipient, sender, amount, assetId } = message;
|
1870
1957
|
let witnessIndex;
|
1871
|
-
if (predicate) {
|
1958
|
+
if (message.predicate) {
|
1872
1959
|
witnessIndex = 0;
|
1873
1960
|
} else {
|
1874
1961
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1882,8 +1969,7 @@ var BaseTransactionRequest = class {
|
|
1882
1969
|
sender: sender.toB256(),
|
1883
1970
|
recipient: recipient.toB256(),
|
1884
1971
|
amount,
|
1885
|
-
witnessIndex
|
1886
|
-
predicate: predicate?.bytes
|
1972
|
+
witnessIndex
|
1887
1973
|
};
|
1888
1974
|
this.pushInput(input);
|
1889
1975
|
this.addChangeOutput(recipient, assetId);
|
@@ -1914,32 +2000,6 @@ var BaseTransactionRequest = class {
|
|
1914
2000
|
resources.forEach((resource) => this.addResource(resource));
|
1915
2001
|
return this;
|
1916
2002
|
}
|
1917
|
-
/**
|
1918
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1919
|
-
* outputs from the related assetIds.
|
1920
|
-
*
|
1921
|
-
* @param resources - The resources to add.
|
1922
|
-
* @returns This transaction.
|
1923
|
-
*/
|
1924
|
-
addPredicateResource(resource, predicate) {
|
1925
|
-
if (isCoin(resource)) {
|
1926
|
-
this.addCoinInput(resource, predicate);
|
1927
|
-
} else {
|
1928
|
-
this.addMessageInput(resource, predicate);
|
1929
|
-
}
|
1930
|
-
return this;
|
1931
|
-
}
|
1932
|
-
/**
|
1933
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1934
|
-
* from the related assetIds.
|
1935
|
-
*
|
1936
|
-
* @param resources - The resources to add.
|
1937
|
-
* @returns This transaction.
|
1938
|
-
*/
|
1939
|
-
addPredicateResources(resources, predicate) {
|
1940
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1941
|
-
return this;
|
1942
|
-
}
|
1943
2003
|
/**
|
1944
2004
|
* Adds a coin output to the transaction.
|
1945
2005
|
*
|
@@ -2019,7 +2079,7 @@ var BaseTransactionRequest = class {
|
|
2019
2079
|
}
|
2020
2080
|
calculateMaxGas(chainInfo, minGas) {
|
2021
2081
|
const { consensusParameters } = chainInfo;
|
2022
|
-
const { gasPerByte } = consensusParameters;
|
2082
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2023
2083
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2024
2084
|
(acc, wit) => acc + wit.dataLength,
|
2025
2085
|
0
|
@@ -2028,7 +2088,8 @@ var BaseTransactionRequest = class {
|
|
2028
2088
|
gasPerByte,
|
2029
2089
|
minGas,
|
2030
2090
|
witnessesLength,
|
2031
|
-
witnessLimit: this.witnessLimit
|
2091
|
+
witnessLimit: this.witnessLimit,
|
2092
|
+
maxGasPerTx
|
2032
2093
|
});
|
2033
2094
|
}
|
2034
2095
|
/**
|
@@ -2047,17 +2108,20 @@ var BaseTransactionRequest = class {
|
|
2047
2108
|
});
|
2048
2109
|
const updateAssetInput = (assetId, quantity) => {
|
2049
2110
|
const assetInput = findAssetInput(assetId);
|
2111
|
+
let usedQuantity = quantity;
|
2112
|
+
if (assetId === baseAssetId) {
|
2113
|
+
usedQuantity = bn7("1000000000000000000");
|
2114
|
+
}
|
2050
2115
|
if (assetInput && "assetId" in assetInput) {
|
2051
2116
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2052
|
-
assetInput.amount =
|
2117
|
+
assetInput.amount = usedQuantity;
|
2053
2118
|
} else {
|
2054
2119
|
this.addResources([
|
2055
2120
|
{
|
2056
2121
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2057
|
-
amount:
|
2122
|
+
amount: usedQuantity,
|
2058
2123
|
assetId,
|
2059
2124
|
owner: resourcesOwner || Address.fromRandom(),
|
2060
|
-
maturity: 0,
|
2061
2125
|
blockCreated: bn7(1),
|
2062
2126
|
txCreatedIdx: bn7(1)
|
2063
2127
|
}
|
@@ -2089,7 +2153,7 @@ var BaseTransactionRequest = class {
|
|
2089
2153
|
toJSON() {
|
2090
2154
|
return normalizeJSON(this);
|
2091
2155
|
}
|
2092
|
-
|
2156
|
+
updatePredicateGasUsed(inputs) {
|
2093
2157
|
this.inputs.forEach((i) => {
|
2094
2158
|
let correspondingInput;
|
2095
2159
|
switch (i.type) {
|
@@ -2111,6 +2175,15 @@ var BaseTransactionRequest = class {
|
|
2111
2175
|
}
|
2112
2176
|
});
|
2113
2177
|
}
|
2178
|
+
shiftPredicateData() {
|
2179
|
+
this.inputs.forEach((input) => {
|
2180
|
+
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2181
|
+
input.predicateData = input.padPredicateData(
|
2182
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2183
|
+
);
|
2184
|
+
}
|
2185
|
+
});
|
2186
|
+
}
|
2114
2187
|
};
|
2115
2188
|
|
2116
2189
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2252,9 +2325,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2252
2325
|
return {
|
2253
2326
|
type: TransactionType3.Create,
|
2254
2327
|
...baseTransaction,
|
2255
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2256
2328
|
bytecodeWitnessIndex,
|
2257
|
-
storageSlotsCount: storageSlots.length,
|
2329
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2258
2330
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2259
2331
|
storageSlots
|
2260
2332
|
};
|
@@ -2377,8 +2449,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2377
2449
|
type: TransactionType4.Script,
|
2378
2450
|
scriptGasLimit: this.gasLimit,
|
2379
2451
|
...super.getBaseTransaction(),
|
2380
|
-
scriptLength: script.length,
|
2381
|
-
scriptDataLength: scriptData.length,
|
2452
|
+
scriptLength: bn10(script.length),
|
2453
|
+
scriptDataLength: bn10(scriptData.length),
|
2382
2454
|
receiptsRoot: ZeroBytes327,
|
2383
2455
|
script: hexlify10(script),
|
2384
2456
|
scriptData: hexlify10(scriptData)
|
@@ -2442,7 +2514,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2442
2514
|
}
|
2443
2515
|
calculateMaxGas(chainInfo, minGas) {
|
2444
2516
|
const { consensusParameters } = chainInfo;
|
2445
|
-
const { gasPerByte } = consensusParameters;
|
2517
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2446
2518
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2447
2519
|
(acc, wit) => acc + wit.dataLength,
|
2448
2520
|
0
|
@@ -2452,7 +2524,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2452
2524
|
minGas,
|
2453
2525
|
witnessesLength,
|
2454
2526
|
witnessLimit: this.witnessLimit,
|
2455
|
-
gasLimit: this.gasLimit
|
2527
|
+
gasLimit: this.gasLimit,
|
2528
|
+
maxGasPerTx
|
2456
2529
|
});
|
2457
2530
|
}
|
2458
2531
|
/**
|
@@ -2509,7 +2582,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2509
2582
|
|
2510
2583
|
// src/providers/transaction-request/utils.ts
|
2511
2584
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2512
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2585
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2513
2586
|
var transactionRequestify = (obj) => {
|
2514
2587
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2515
2588
|
return obj;
|
@@ -2527,14 +2600,31 @@ var transactionRequestify = (obj) => {
|
|
2527
2600
|
}
|
2528
2601
|
}
|
2529
2602
|
};
|
2603
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2604
|
+
(acc, input) => {
|
2605
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2606
|
+
acc.utxos.push(input.id);
|
2607
|
+
}
|
2608
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2609
|
+
acc.messages.push(input.nonce);
|
2610
|
+
}
|
2611
|
+
return acc;
|
2612
|
+
},
|
2613
|
+
{
|
2614
|
+
utxos: [],
|
2615
|
+
messages: []
|
2616
|
+
}
|
2617
|
+
);
|
2530
2618
|
|
2531
2619
|
// src/providers/transaction-response/transaction-response.ts
|
2532
2620
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2533
|
-
import { bn as
|
2621
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2534
2622
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2535
2623
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2536
2624
|
|
2537
2625
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2626
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2627
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2538
2628
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2539
2629
|
|
2540
2630
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2543,9 +2633,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2543
2633
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2544
2634
|
var calculateTransactionFee = (params) => {
|
2545
2635
|
const {
|
2546
|
-
|
2636
|
+
gasPrice,
|
2547
2637
|
rawPayload,
|
2548
|
-
|
2638
|
+
tip,
|
2639
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2549
2640
|
} = params;
|
2550
2641
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2551
2642
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2555,8 +2646,7 @@ var calculateTransactionFee = (params) => {
|
|
2555
2646
|
return {
|
2556
2647
|
fee: bn11(0),
|
2557
2648
|
minFee: bn11(0),
|
2558
|
-
maxFee: bn11(0)
|
2559
|
-
feeFromGasUsed: bn11(0)
|
2649
|
+
maxFee: bn11(0)
|
2560
2650
|
};
|
2561
2651
|
}
|
2562
2652
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2588,7 +2678,6 @@ var calculateTransactionFee = (params) => {
|
|
2588
2678
|
metadataGas,
|
2589
2679
|
txBytesSize: transactionBytes.length
|
2590
2680
|
});
|
2591
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2592
2681
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2593
2682
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2594
2683
|
const maxGas = getMaxGas({
|
@@ -2596,17 +2685,25 @@ var calculateTransactionFee = (params) => {
|
|
2596
2685
|
minGas,
|
2597
2686
|
witnessesLength,
|
2598
2687
|
gasLimit,
|
2599
|
-
witnessLimit
|
2688
|
+
witnessLimit,
|
2689
|
+
maxGasPerTx
|
2690
|
+
});
|
2691
|
+
const minFee = calculateGasFee({
|
2692
|
+
gasPrice,
|
2693
|
+
gas: minGas,
|
2694
|
+
priceFactor: gasPriceFactor,
|
2695
|
+
tip
|
2696
|
+
});
|
2697
|
+
const maxFee = calculateGasFee({
|
2698
|
+
gasPrice,
|
2699
|
+
gas: maxGas,
|
2700
|
+
priceFactor: gasPriceFactor,
|
2701
|
+
tip
|
2600
2702
|
});
|
2601
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2602
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2603
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2604
|
-
const fee = minFee.add(feeFromGasUsed);
|
2605
2703
|
return {
|
2606
|
-
fee,
|
2607
2704
|
minFee,
|
2608
2705
|
maxFee,
|
2609
|
-
|
2706
|
+
fee: maxFee
|
2610
2707
|
};
|
2611
2708
|
};
|
2612
2709
|
|
@@ -2662,7 +2759,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2662
2759
|
|
2663
2760
|
// src/providers/transaction-summary/input.ts
|
2664
2761
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2665
|
-
import { InputType as
|
2762
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2666
2763
|
function getInputsByTypes(inputs, types) {
|
2667
2764
|
return inputs.filter((i) => types.includes(i.type));
|
2668
2765
|
}
|
@@ -2670,16 +2767,16 @@ function getInputsByType(inputs, type) {
|
|
2670
2767
|
return inputs.filter((i) => i.type === type);
|
2671
2768
|
}
|
2672
2769
|
function getInputsCoin(inputs) {
|
2673
|
-
return getInputsByType(inputs,
|
2770
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2674
2771
|
}
|
2675
2772
|
function getInputsMessage(inputs) {
|
2676
|
-
return getInputsByType(inputs,
|
2773
|
+
return getInputsByType(inputs, InputType6.Message);
|
2677
2774
|
}
|
2678
2775
|
function getInputsCoinAndMessage(inputs) {
|
2679
|
-
return getInputsByTypes(inputs, [
|
2776
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2680
2777
|
}
|
2681
2778
|
function getInputsContract(inputs) {
|
2682
|
-
return getInputsByType(inputs,
|
2779
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2683
2780
|
}
|
2684
2781
|
function getInputFromAssetId(inputs, assetId) {
|
2685
2782
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2698,7 +2795,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2698
2795
|
if (!contractInput) {
|
2699
2796
|
return void 0;
|
2700
2797
|
}
|
2701
|
-
if (contractInput.type !==
|
2798
|
+
if (contractInput.type !== InputType6.Contract) {
|
2702
2799
|
throw new FuelError9(
|
2703
2800
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2704
2801
|
`Contract input should be of type 'contract'.`
|
@@ -2707,10 +2804,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2707
2804
|
return contractInput;
|
2708
2805
|
}
|
2709
2806
|
function getInputAccountAddress(input) {
|
2710
|
-
if (input.type ===
|
2807
|
+
if (input.type === InputType6.Coin) {
|
2711
2808
|
return input.owner.toString();
|
2712
2809
|
}
|
2713
|
-
if (input.type ===
|
2810
|
+
if (input.type === InputType6.Message) {
|
2714
2811
|
return input.recipient.toString();
|
2715
2812
|
}
|
2716
2813
|
return "";
|
@@ -3173,7 +3270,9 @@ function assembleTransactionSummary(params) {
|
|
3173
3270
|
gqlTransactionStatus,
|
3174
3271
|
abiMap = {},
|
3175
3272
|
maxInputs,
|
3176
|
-
gasCosts
|
3273
|
+
gasCosts,
|
3274
|
+
maxGasPerTx,
|
3275
|
+
gasPrice
|
3177
3276
|
} = params;
|
3178
3277
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3179
3278
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3187,11 +3286,14 @@ function assembleTransactionSummary(params) {
|
|
3187
3286
|
maxInputs
|
3188
3287
|
});
|
3189
3288
|
const typeName = getTransactionTypeName(transaction.type);
|
3289
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3190
3290
|
const { fee } = calculateTransactionFee({
|
3191
|
-
|
3291
|
+
gasPrice,
|
3192
3292
|
rawPayload,
|
3293
|
+
tip,
|
3193
3294
|
consensusParameters: {
|
3194
3295
|
gasCosts,
|
3296
|
+
maxGasPerTx,
|
3195
3297
|
feeParams: {
|
3196
3298
|
gasPerByte,
|
3197
3299
|
gasPriceFactor
|
@@ -3251,7 +3353,7 @@ var TransactionResponse = class {
|
|
3251
3353
|
/** Current provider */
|
3252
3354
|
provider;
|
3253
3355
|
/** Gas used on the transaction */
|
3254
|
-
gasUsed =
|
3356
|
+
gasUsed = bn15(0);
|
3255
3357
|
/** The graphql Transaction with receipts object. */
|
3256
3358
|
gqlTransaction;
|
3257
3359
|
abis;
|
@@ -3329,8 +3431,13 @@ var TransactionResponse = class {
|
|
3329
3431
|
const decodedTransaction = this.decodeTransaction(
|
3330
3432
|
transaction
|
3331
3433
|
);
|
3332
|
-
|
3333
|
-
|
3434
|
+
let txReceipts = [];
|
3435
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3436
|
+
txReceipts = transaction.status.receipts;
|
3437
|
+
}
|
3438
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3439
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3440
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3334
3441
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3335
3442
|
const transactionSummary = assembleTransactionSummary({
|
3336
3443
|
id: this.id,
|
@@ -3342,7 +3449,9 @@ var TransactionResponse = class {
|
|
3342
3449
|
gasPriceFactor,
|
3343
3450
|
abiMap: contractsAbiMap,
|
3344
3451
|
maxInputs,
|
3345
|
-
gasCosts
|
3452
|
+
gasCosts,
|
3453
|
+
maxGasPerTx,
|
3454
|
+
gasPrice
|
3346
3455
|
});
|
3347
3456
|
return transactionSummary;
|
3348
3457
|
}
|
@@ -3468,30 +3577,30 @@ var processGqlChain = (chain) => {
|
|
3468
3577
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3469
3578
|
return {
|
3470
3579
|
name,
|
3471
|
-
baseChainHeight:
|
3580
|
+
baseChainHeight: bn16(daHeight),
|
3472
3581
|
consensusParameters: {
|
3473
|
-
contractMaxSize:
|
3474
|
-
maxInputs:
|
3475
|
-
maxOutputs:
|
3476
|
-
maxWitnesses:
|
3477
|
-
maxGasPerTx:
|
3478
|
-
maxScriptLength:
|
3479
|
-
maxScriptDataLength:
|
3480
|
-
maxStorageSlots:
|
3481
|
-
maxPredicateLength:
|
3482
|
-
maxPredicateDataLength:
|
3483
|
-
maxGasPerPredicate:
|
3484
|
-
gasPriceFactor:
|
3485
|
-
gasPerByte:
|
3486
|
-
maxMessageDataLength:
|
3487
|
-
chainId:
|
3582
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3583
|
+
maxInputs: bn16(txParams.maxInputs),
|
3584
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3585
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3586
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3587
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3588
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3589
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3590
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3591
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3592
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3593
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3594
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3595
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3596
|
+
chainId: bn16(consensusParameters.chainId),
|
3488
3597
|
baseAssetId: consensusParameters.baseAssetId,
|
3489
3598
|
gasCosts
|
3490
3599
|
},
|
3491
3600
|
gasCosts,
|
3492
3601
|
latestBlock: {
|
3493
3602
|
id: latestBlock.id,
|
3494
|
-
height:
|
3603
|
+
height: bn16(latestBlock.height),
|
3495
3604
|
time: latestBlock.header.time,
|
3496
3605
|
transactions: latestBlock.transactions.map((i) => ({
|
3497
3606
|
id: i.id
|
@@ -3585,10 +3694,8 @@ var _Provider = class {
|
|
3585
3694
|
* Returns some helpful parameters related to gas fees.
|
3586
3695
|
*/
|
3587
3696
|
getGasConfig() {
|
3588
|
-
const { minGasPrice } = this.getNode();
|
3589
3697
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3590
3698
|
return {
|
3591
|
-
minGasPrice,
|
3592
3699
|
maxGasPerTx,
|
3593
3700
|
maxGasPerPredicate,
|
3594
3701
|
gasPriceFactor,
|
@@ -3664,6 +3771,21 @@ var _Provider = class {
|
|
3664
3771
|
} = await this.operations.getVersion();
|
3665
3772
|
return nodeVersion;
|
3666
3773
|
}
|
3774
|
+
/**
|
3775
|
+
* @hidden
|
3776
|
+
*
|
3777
|
+
* Returns the network configuration of the connected Fuel node.
|
3778
|
+
*
|
3779
|
+
* @returns A promise that resolves to the network configuration object
|
3780
|
+
*/
|
3781
|
+
async getNetwork() {
|
3782
|
+
const {
|
3783
|
+
name,
|
3784
|
+
consensusParameters: { chainId }
|
3785
|
+
} = await this.getChain();
|
3786
|
+
const network = new Network(name, chainId.toNumber());
|
3787
|
+
return Promise.resolve(network);
|
3788
|
+
}
|
3667
3789
|
/**
|
3668
3790
|
* Returns the block number.
|
3669
3791
|
*
|
@@ -3671,7 +3793,7 @@ var _Provider = class {
|
|
3671
3793
|
*/
|
3672
3794
|
async getBlockNumber() {
|
3673
3795
|
const { chain } = await this.operations.getChain();
|
3674
|
-
return
|
3796
|
+
return bn16(chain.latestBlock.height, 10);
|
3675
3797
|
}
|
3676
3798
|
/**
|
3677
3799
|
* Returns the chain information.
|
@@ -3681,13 +3803,11 @@ var _Provider = class {
|
|
3681
3803
|
async fetchNode() {
|
3682
3804
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3683
3805
|
const processedNodeInfo = {
|
3684
|
-
maxDepth:
|
3685
|
-
maxTx:
|
3686
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3806
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3807
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3687
3808
|
nodeVersion: nodeInfo.nodeVersion,
|
3688
3809
|
utxoValidation: nodeInfo.utxoValidation,
|
3689
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3690
|
-
peers: nodeInfo.peers
|
3810
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3691
3811
|
};
|
3692
3812
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3693
3813
|
return processedNodeInfo;
|
@@ -3784,14 +3904,13 @@ var _Provider = class {
|
|
3784
3904
|
return this.estimateTxDependencies(transactionRequest);
|
3785
3905
|
}
|
3786
3906
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3787
|
-
const { dryRun:
|
3788
|
-
encodedTransaction,
|
3907
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3908
|
+
encodedTransactions: encodedTransaction,
|
3789
3909
|
utxoValidation: utxoValidation || false
|
3790
3910
|
});
|
3791
|
-
const receipts =
|
3792
|
-
|
3793
|
-
|
3794
|
-
};
|
3911
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3912
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3913
|
+
return { receipts, dryrunStatus: status };
|
3795
3914
|
}
|
3796
3915
|
/**
|
3797
3916
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3817,7 +3936,7 @@ var _Provider = class {
|
|
3817
3936
|
} = response;
|
3818
3937
|
if (inputs) {
|
3819
3938
|
inputs.forEach((input, index) => {
|
3820
|
-
if ("predicateGasUsed" in input &&
|
3939
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3821
3940
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3822
3941
|
}
|
3823
3942
|
});
|
@@ -3830,9 +3949,6 @@ var _Provider = class {
|
|
3830
3949
|
* If there are missing variable outputs,
|
3831
3950
|
* `addVariableOutputs` is called on the transaction.
|
3832
3951
|
*
|
3833
|
-
* @privateRemarks
|
3834
|
-
* TODO: Investigate support for missing contract IDs
|
3835
|
-
* TODO: Add support for missing output messages
|
3836
3952
|
*
|
3837
3953
|
* @param transactionRequest - The transaction request object.
|
3838
3954
|
* @returns A promise.
|
@@ -3845,16 +3961,19 @@ var _Provider = class {
|
|
3845
3961
|
missingContractIds: []
|
3846
3962
|
};
|
3847
3963
|
}
|
3848
|
-
await this.estimatePredicates(transactionRequest);
|
3849
3964
|
let receipts = [];
|
3850
3965
|
const missingContractIds = [];
|
3851
3966
|
let outputVariables = 0;
|
3967
|
+
let dryrunStatus;
|
3852
3968
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3853
|
-
const {
|
3854
|
-
|
3969
|
+
const {
|
3970
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3971
|
+
} = await this.operations.dryRun({
|
3972
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3855
3973
|
utxoValidation: false
|
3856
3974
|
});
|
3857
|
-
receipts =
|
3975
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3976
|
+
dryrunStatus = status;
|
3858
3977
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3859
3978
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3860
3979
|
if (hasMissingOutputs) {
|
@@ -3864,6 +3983,10 @@ var _Provider = class {
|
|
3864
3983
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3865
3984
|
missingContractIds.push(contractId);
|
3866
3985
|
});
|
3986
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3987
|
+
transactionRequest
|
3988
|
+
});
|
3989
|
+
transactionRequest.maxFee = maxFee;
|
3867
3990
|
} else {
|
3868
3991
|
break;
|
3869
3992
|
}
|
@@ -3871,37 +3994,136 @@ var _Provider = class {
|
|
3871
3994
|
return {
|
3872
3995
|
receipts,
|
3873
3996
|
outputVariables,
|
3874
|
-
missingContractIds
|
3997
|
+
missingContractIds,
|
3998
|
+
dryrunStatus
|
3875
3999
|
};
|
3876
4000
|
}
|
4001
|
+
/**
|
4002
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4003
|
+
*
|
4004
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4005
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4006
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4007
|
+
*
|
4008
|
+
* @param transactionRequests - Array of transaction request objects.
|
4009
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4010
|
+
*/
|
4011
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4012
|
+
const results = transactionRequests.map(() => ({
|
4013
|
+
receipts: [],
|
4014
|
+
outputVariables: 0,
|
4015
|
+
missingContractIds: [],
|
4016
|
+
dryrunStatus: void 0
|
4017
|
+
}));
|
4018
|
+
const allRequests = clone3(transactionRequests);
|
4019
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4020
|
+
allRequests.forEach((req, index) => {
|
4021
|
+
if (req.type === TransactionType8.Script) {
|
4022
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4023
|
+
}
|
4024
|
+
});
|
4025
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4026
|
+
let attempt = 0;
|
4027
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4028
|
+
const encodedTransactions = transactionsToProcess.map(
|
4029
|
+
(index) => serializedTransactionsMap.get(index)
|
4030
|
+
);
|
4031
|
+
const dryRunResults = await this.operations.dryRun({
|
4032
|
+
encodedTransactions,
|
4033
|
+
utxoValidation: false
|
4034
|
+
});
|
4035
|
+
const nextRoundTransactions = [];
|
4036
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4037
|
+
const requestIdx = transactionsToProcess[i];
|
4038
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4039
|
+
const result = results[requestIdx];
|
4040
|
+
result.receipts = rawReceipts.map(processGqlReceipt);
|
4041
|
+
result.dryrunStatus = status;
|
4042
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4043
|
+
result.receipts
|
4044
|
+
);
|
4045
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4046
|
+
const request = allRequests[requestIdx];
|
4047
|
+
if (hasMissingOutputs && request?.type === TransactionType8.Script) {
|
4048
|
+
result.outputVariables += missingOutputVariables.length;
|
4049
|
+
request.addVariableOutputs(missingOutputVariables.length);
|
4050
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4051
|
+
request.addContractInputAndOutput(Address2.fromString(contractId));
|
4052
|
+
result.missingContractIds.push(contractId);
|
4053
|
+
});
|
4054
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4055
|
+
transactionRequest: request
|
4056
|
+
});
|
4057
|
+
request.maxFee = maxFee;
|
4058
|
+
serializedTransactionsMap.set(requestIdx, hexlify12(request.toTransactionBytes()));
|
4059
|
+
nextRoundTransactions.push(requestIdx);
|
4060
|
+
}
|
4061
|
+
}
|
4062
|
+
transactionsToProcess = nextRoundTransactions;
|
4063
|
+
attempt += 1;
|
4064
|
+
}
|
4065
|
+
return results;
|
4066
|
+
}
|
4067
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4068
|
+
if (estimateTxDependencies) {
|
4069
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4070
|
+
}
|
4071
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4072
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4073
|
+
encodedTransactions,
|
4074
|
+
utxoValidation: utxoValidation || false
|
4075
|
+
});
|
4076
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4077
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4078
|
+
return { receipts, dryrunStatus: status };
|
4079
|
+
});
|
4080
|
+
return results;
|
4081
|
+
}
|
3877
4082
|
/**
|
3878
4083
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3879
4084
|
* @param transactionRequest - The transaction request object.
|
3880
4085
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3881
4086
|
*/
|
3882
|
-
estimateTxGasAndFee(params) {
|
4087
|
+
async estimateTxGasAndFee(params) {
|
3883
4088
|
const { transactionRequest } = params;
|
3884
|
-
|
4089
|
+
let { gasPrice } = params;
|
3885
4090
|
const chainInfo = this.getChain();
|
3886
|
-
const
|
3887
|
-
transactionRequest.gasPrice = gasPrice;
|
4091
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3888
4092
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3889
|
-
|
4093
|
+
if (!gasPrice) {
|
4094
|
+
gasPrice = await this.estimateGasPrice(10);
|
4095
|
+
}
|
4096
|
+
const minFee = calculateGasFee({
|
4097
|
+
gasPrice: bn16(gasPrice),
|
4098
|
+
gas: minGas,
|
4099
|
+
priceFactor: gasPriceFactor,
|
4100
|
+
tip: transactionRequest.tip
|
4101
|
+
}).add(1);
|
4102
|
+
let gasLimit = bn16(0);
|
3890
4103
|
if (transactionRequest.type === TransactionType8.Script) {
|
4104
|
+
gasLimit = transactionRequest.gasLimit;
|
3891
4105
|
if (transactionRequest.gasLimit.eq(0)) {
|
3892
4106
|
transactionRequest.gasLimit = minGas;
|
3893
4107
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3894
4108
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3895
4109
|
);
|
4110
|
+
gasLimit = transactionRequest.gasLimit;
|
3896
4111
|
}
|
3897
4112
|
}
|
3898
4113
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3899
|
-
const maxFee =
|
4114
|
+
const maxFee = calculateGasFee({
|
4115
|
+
gasPrice: bn16(gasPrice),
|
4116
|
+
gas: maxGas,
|
4117
|
+
priceFactor: gasPriceFactor,
|
4118
|
+
tip: transactionRequest.tip
|
4119
|
+
}).add(1);
|
3900
4120
|
return {
|
3901
4121
|
minGas,
|
3902
4122
|
minFee,
|
3903
4123
|
maxGas,
|
3904
|
-
maxFee
|
4124
|
+
maxFee,
|
4125
|
+
gasPrice,
|
4126
|
+
gasLimit
|
3905
4127
|
};
|
3906
4128
|
}
|
3907
4129
|
/**
|
@@ -3919,15 +4141,17 @@ var _Provider = class {
|
|
3919
4141
|
if (estimateTxDependencies) {
|
3920
4142
|
return this.estimateTxDependencies(transactionRequest);
|
3921
4143
|
}
|
3922
|
-
const
|
3923
|
-
const { dryRun:
|
3924
|
-
|
4144
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4145
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4146
|
+
encodedTransactions,
|
3925
4147
|
utxoValidation: true
|
3926
4148
|
});
|
3927
|
-
const
|
3928
|
-
|
3929
|
-
receipts
|
3930
|
-
|
4149
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4150
|
+
const { id, receipts, status } = dryRunStatus;
|
4151
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4152
|
+
return { id, receipts: processedReceipts, status };
|
4153
|
+
});
|
4154
|
+
return { receipts: callResult[0].receipts };
|
3931
4155
|
}
|
3932
4156
|
/**
|
3933
4157
|
* Returns a transaction cost to enable user
|
@@ -3944,78 +4168,80 @@ var _Provider = class {
|
|
3944
4168
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3945
4169
|
* @returns A promise that resolves to the transaction cost object.
|
3946
4170
|
*/
|
3947
|
-
async getTransactionCost(transactionRequestLike,
|
3948
|
-
estimateTxDependencies = true,
|
3949
|
-
estimatePredicates = true,
|
3950
|
-
resourcesOwner,
|
3951
|
-
signatureCallback
|
3952
|
-
} = {}) {
|
4171
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3953
4172
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3954
|
-
const { minGasPrice } = this.getGasConfig();
|
3955
|
-
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3956
4173
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3957
4174
|
const baseAssetId = this.getBaseAssetId();
|
3958
4175
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3959
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4176
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3960
4177
|
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4178
|
+
txRequestClone.maxFee = bn16(0);
|
3961
4179
|
if (isScriptTransaction) {
|
3962
|
-
txRequestClone.gasLimit =
|
4180
|
+
txRequestClone.gasLimit = bn16(0);
|
3963
4181
|
}
|
3964
|
-
if (
|
3965
|
-
|
3966
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3967
|
-
}
|
3968
|
-
await this.estimatePredicates(txRequestClone);
|
4182
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4183
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3969
4184
|
}
|
4185
|
+
const signedRequest = clone3(txRequestClone);
|
4186
|
+
let addedSignatures = 0;
|
3970
4187
|
if (signatureCallback && isScriptTransaction) {
|
3971
|
-
|
4188
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4189
|
+
await signatureCallback(signedRequest);
|
4190
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3972
4191
|
}
|
3973
|
-
|
3974
|
-
|
4192
|
+
await this.estimatePredicates(signedRequest);
|
4193
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4194
|
+
transactionRequest: signedRequest
|
3975
4195
|
});
|
3976
4196
|
let receipts = [];
|
3977
4197
|
let missingContractIds = [];
|
3978
4198
|
let outputVariables = 0;
|
3979
|
-
let gasUsed =
|
3980
|
-
|
3981
|
-
|
4199
|
+
let gasUsed = bn16(0);
|
4200
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4201
|
+
txRequestClone.maxFee = maxFee;
|
4202
|
+
if (isScriptTransaction) {
|
4203
|
+
txRequestClone.gasLimit = gasLimit;
|
4204
|
+
if (signatureCallback) {
|
4205
|
+
await signatureCallback(txRequestClone);
|
4206
|
+
}
|
3982
4207
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3983
4208
|
receipts = result.receipts;
|
3984
4209
|
outputVariables = result.outputVariables;
|
3985
4210
|
missingContractIds = result.missingContractIds;
|
3986
4211
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
3987
4212
|
txRequestClone.gasLimit = gasUsed;
|
3988
|
-
|
3989
|
-
|
3990
|
-
|
4213
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4214
|
+
transactionRequest: txRequestClone,
|
4215
|
+
gasPrice
|
3991
4216
|
}));
|
3992
4217
|
}
|
3993
4218
|
return {
|
3994
4219
|
requiredQuantities: allQuantities,
|
3995
4220
|
receipts,
|
3996
4221
|
gasUsed,
|
3997
|
-
|
3998
|
-
gasPrice: setGasPrice,
|
4222
|
+
gasPrice,
|
3999
4223
|
minGas,
|
4000
4224
|
maxGas,
|
4001
4225
|
minFee,
|
4002
4226
|
maxFee,
|
4003
|
-
estimatedInputs: txRequestClone.inputs,
|
4004
4227
|
outputVariables,
|
4005
|
-
missingContractIds
|
4228
|
+
missingContractIds,
|
4229
|
+
addedSignatures,
|
4230
|
+
estimatedPredicates: txRequestClone.inputs
|
4006
4231
|
};
|
4007
4232
|
}
|
4008
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4233
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4009
4234
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4010
4235
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4011
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4236
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4237
|
+
quantitiesToContract
|
4238
|
+
});
|
4012
4239
|
transactionRequest.addResources(
|
4013
4240
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4014
4241
|
);
|
4015
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4016
|
-
|
4017
|
-
|
4018
|
-
);
|
4242
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4243
|
+
quantitiesToContract
|
4244
|
+
});
|
4019
4245
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4020
4246
|
return {
|
4021
4247
|
resources,
|
@@ -4037,11 +4263,10 @@ var _Provider = class {
|
|
4037
4263
|
return coins.map((coin) => ({
|
4038
4264
|
id: coin.utxoId,
|
4039
4265
|
assetId: coin.assetId,
|
4040
|
-
amount:
|
4266
|
+
amount: bn16(coin.amount),
|
4041
4267
|
owner: Address2.fromAddressOrString(coin.owner),
|
4042
|
-
|
4043
|
-
|
4044
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4268
|
+
blockCreated: bn16(coin.blockCreated),
|
4269
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4045
4270
|
}));
|
4046
4271
|
}
|
4047
4272
|
/**
|
@@ -4078,9 +4303,9 @@ var _Provider = class {
|
|
4078
4303
|
switch (coin.__typename) {
|
4079
4304
|
case "MessageCoin":
|
4080
4305
|
return {
|
4081
|
-
amount:
|
4306
|
+
amount: bn16(coin.amount),
|
4082
4307
|
assetId: coin.assetId,
|
4083
|
-
daHeight:
|
4308
|
+
daHeight: bn16(coin.daHeight),
|
4084
4309
|
sender: Address2.fromAddressOrString(coin.sender),
|
4085
4310
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4086
4311
|
nonce: coin.nonce
|
@@ -4088,12 +4313,11 @@ var _Provider = class {
|
|
4088
4313
|
case "Coin":
|
4089
4314
|
return {
|
4090
4315
|
id: coin.utxoId,
|
4091
|
-
amount:
|
4316
|
+
amount: bn16(coin.amount),
|
4092
4317
|
assetId: coin.assetId,
|
4093
4318
|
owner: Address2.fromAddressOrString(coin.owner),
|
4094
|
-
|
4095
|
-
|
4096
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4319
|
+
blockCreated: bn16(coin.blockCreated),
|
4320
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4097
4321
|
};
|
4098
4322
|
default:
|
4099
4323
|
return null;
|
@@ -4110,13 +4334,13 @@ var _Provider = class {
|
|
4110
4334
|
async getBlock(idOrHeight) {
|
4111
4335
|
let variables;
|
4112
4336
|
if (typeof idOrHeight === "number") {
|
4113
|
-
variables = { height:
|
4337
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4114
4338
|
} else if (idOrHeight === "latest") {
|
4115
4339
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4116
4340
|
} else if (idOrHeight.length === 66) {
|
4117
4341
|
variables = { blockId: idOrHeight };
|
4118
4342
|
} else {
|
4119
|
-
variables = { blockId:
|
4343
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4120
4344
|
}
|
4121
4345
|
const { block } = await this.operations.getBlock(variables);
|
4122
4346
|
if (!block) {
|
@@ -4124,7 +4348,7 @@ var _Provider = class {
|
|
4124
4348
|
}
|
4125
4349
|
return {
|
4126
4350
|
id: block.id,
|
4127
|
-
height:
|
4351
|
+
height: bn16(block.height),
|
4128
4352
|
time: block.header.time,
|
4129
4353
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4130
4354
|
};
|
@@ -4139,7 +4363,7 @@ var _Provider = class {
|
|
4139
4363
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4140
4364
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4141
4365
|
id: block.id,
|
4142
|
-
height:
|
4366
|
+
height: bn16(block.height),
|
4143
4367
|
time: block.header.time,
|
4144
4368
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4145
4369
|
}));
|
@@ -4154,7 +4378,7 @@ var _Provider = class {
|
|
4154
4378
|
async getBlockWithTransactions(idOrHeight) {
|
4155
4379
|
let variables;
|
4156
4380
|
if (typeof idOrHeight === "number") {
|
4157
|
-
variables = { blockHeight:
|
4381
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4158
4382
|
} else if (idOrHeight === "latest") {
|
4159
4383
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4160
4384
|
} else {
|
@@ -4166,7 +4390,7 @@ var _Provider = class {
|
|
4166
4390
|
}
|
4167
4391
|
return {
|
4168
4392
|
id: block.id,
|
4169
|
-
height:
|
4393
|
+
height: bn16(block.height, 10),
|
4170
4394
|
time: block.header.time,
|
4171
4395
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4172
4396
|
transactions: block.transactions.map(
|
@@ -4215,7 +4439,7 @@ var _Provider = class {
|
|
4215
4439
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4216
4440
|
asset: hexlify12(assetId)
|
4217
4441
|
});
|
4218
|
-
return
|
4442
|
+
return bn16(contractBalance.amount, 10);
|
4219
4443
|
}
|
4220
4444
|
/**
|
4221
4445
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4229,7 +4453,7 @@ var _Provider = class {
|
|
4229
4453
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4230
4454
|
assetId: hexlify12(assetId)
|
4231
4455
|
});
|
4232
|
-
return
|
4456
|
+
return bn16(balance.amount, 10);
|
4233
4457
|
}
|
4234
4458
|
/**
|
4235
4459
|
* Returns balances for the given owner.
|
@@ -4247,7 +4471,7 @@ var _Provider = class {
|
|
4247
4471
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4248
4472
|
return balances.map((balance) => ({
|
4249
4473
|
assetId: balance.assetId,
|
4250
|
-
amount:
|
4474
|
+
amount: bn16(balance.amount)
|
4251
4475
|
}));
|
4252
4476
|
}
|
4253
4477
|
/**
|
@@ -4269,15 +4493,15 @@ var _Provider = class {
|
|
4269
4493
|
sender: message.sender,
|
4270
4494
|
recipient: message.recipient,
|
4271
4495
|
nonce: message.nonce,
|
4272
|
-
amount:
|
4496
|
+
amount: bn16(message.amount),
|
4273
4497
|
data: message.data
|
4274
4498
|
}),
|
4275
4499
|
sender: Address2.fromAddressOrString(message.sender),
|
4276
4500
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4277
4501
|
nonce: message.nonce,
|
4278
|
-
amount:
|
4502
|
+
amount: bn16(message.amount),
|
4279
4503
|
data: InputMessageCoder.decodeData(message.data),
|
4280
|
-
daHeight:
|
4504
|
+
daHeight: bn16(message.daHeight)
|
4281
4505
|
}));
|
4282
4506
|
}
|
4283
4507
|
/**
|
@@ -4330,44 +4554,60 @@ var _Provider = class {
|
|
4330
4554
|
} = result.messageProof;
|
4331
4555
|
return {
|
4332
4556
|
messageProof: {
|
4333
|
-
proofIndex:
|
4557
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4334
4558
|
proofSet: messageProof.proofSet
|
4335
4559
|
},
|
4336
4560
|
blockProof: {
|
4337
|
-
proofIndex:
|
4561
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4338
4562
|
proofSet: blockProof.proofSet
|
4339
4563
|
},
|
4340
4564
|
messageBlockHeader: {
|
4341
4565
|
id: messageBlockHeader.id,
|
4342
|
-
daHeight:
|
4343
|
-
transactionsCount:
|
4566
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4567
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4344
4568
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4345
|
-
height:
|
4569
|
+
height: bn16(messageBlockHeader.height),
|
4346
4570
|
prevRoot: messageBlockHeader.prevRoot,
|
4347
4571
|
time: messageBlockHeader.time,
|
4348
4572
|
applicationHash: messageBlockHeader.applicationHash,
|
4349
|
-
|
4350
|
-
|
4573
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4574
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4575
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4576
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4577
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4351
4578
|
},
|
4352
4579
|
commitBlockHeader: {
|
4353
4580
|
id: commitBlockHeader.id,
|
4354
|
-
daHeight:
|
4355
|
-
transactionsCount:
|
4581
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4582
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4356
4583
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4357
|
-
height:
|
4584
|
+
height: bn16(commitBlockHeader.height),
|
4358
4585
|
prevRoot: commitBlockHeader.prevRoot,
|
4359
4586
|
time: commitBlockHeader.time,
|
4360
4587
|
applicationHash: commitBlockHeader.applicationHash,
|
4361
|
-
|
4362
|
-
|
4588
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4589
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4590
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4591
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4592
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4363
4593
|
},
|
4364
4594
|
sender: Address2.fromAddressOrString(sender),
|
4365
4595
|
recipient: Address2.fromAddressOrString(recipient),
|
4366
4596
|
nonce,
|
4367
|
-
amount:
|
4597
|
+
amount: bn16(amount),
|
4368
4598
|
data
|
4369
4599
|
};
|
4370
4600
|
}
|
4601
|
+
async getLatestGasPrice() {
|
4602
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4603
|
+
return bn16(latestGasPrice.gasPrice);
|
4604
|
+
}
|
4605
|
+
async estimateGasPrice(blockHorizon) {
|
4606
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4607
|
+
blockHorizon: String(blockHorizon)
|
4608
|
+
});
|
4609
|
+
return bn16(estimateGasPrice.gasPrice);
|
4610
|
+
}
|
4371
4611
|
/**
|
4372
4612
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4373
4613
|
*
|
@@ -4387,10 +4627,10 @@ var _Provider = class {
|
|
4387
4627
|
*/
|
4388
4628
|
async produceBlocks(amount, startTime) {
|
4389
4629
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4390
|
-
blocksToProduce:
|
4630
|
+
blocksToProduce: bn16(amount).toString(10),
|
4391
4631
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4392
4632
|
});
|
4393
|
-
return
|
4633
|
+
return bn16(latestBlockHeight);
|
4394
4634
|
}
|
4395
4635
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4396
4636
|
async getTransactionResponse(transactionId) {
|
@@ -4404,7 +4644,7 @@ cacheInputs_fn = function(inputs) {
|
|
4404
4644
|
return;
|
4405
4645
|
}
|
4406
4646
|
inputs.forEach((input) => {
|
4407
|
-
if (input.type ===
|
4647
|
+
if (input.type === InputType7.Coin) {
|
4408
4648
|
this.cache?.set(input.id);
|
4409
4649
|
}
|
4410
4650
|
});
|
@@ -4414,7 +4654,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4414
4654
|
|
4415
4655
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4416
4656
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4417
|
-
import { bn as
|
4657
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4418
4658
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4419
4659
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4420
4660
|
|
@@ -4661,38 +4901,31 @@ var Account = class extends AbstractAccount {
|
|
4661
4901
|
* @param fee - The estimated transaction fee.
|
4662
4902
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4663
4903
|
*/
|
4664
|
-
async fund(request,
|
4904
|
+
async fund(request, params) {
|
4905
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4665
4906
|
const baseAssetId = this.provider.getBaseAssetId();
|
4666
|
-
const
|
4667
|
-
|
4907
|
+
const txRequest = request;
|
4908
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4909
|
+
amount: bn18(fee),
|
4668
4910
|
assetId: baseAssetId,
|
4669
|
-
coinQuantities
|
4911
|
+
coinQuantities: requiredQuantities
|
4670
4912
|
});
|
4671
4913
|
const quantitiesDict = {};
|
4672
|
-
|
4914
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4673
4915
|
quantitiesDict[assetId] = {
|
4674
4916
|
required: amount,
|
4675
|
-
owned:
|
4917
|
+
owned: bn18(0)
|
4676
4918
|
};
|
4677
4919
|
});
|
4678
|
-
|
4679
|
-
const cachedMessages = [];
|
4680
|
-
const owner = this.address.toB256();
|
4681
|
-
request.inputs.forEach((input) => {
|
4920
|
+
txRequest.inputs.forEach((input) => {
|
4682
4921
|
const isResource = "amount" in input;
|
4683
|
-
if (isResource) {
|
4684
|
-
|
4685
|
-
|
4686
|
-
|
4687
|
-
|
4688
|
-
|
4689
|
-
|
4690
|
-
cachedUtxos.push(input.id);
|
4691
|
-
}
|
4692
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4693
|
-
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4694
|
-
cachedMessages.push(input.nonce);
|
4695
|
-
}
|
4922
|
+
if (!isResource) {
|
4923
|
+
return;
|
4924
|
+
}
|
4925
|
+
const isCoin2 = "owner" in input;
|
4926
|
+
const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
|
4927
|
+
if (quantitiesDict[assetId]) {
|
4928
|
+
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
|
4696
4929
|
}
|
4697
4930
|
});
|
4698
4931
|
const missingQuantities = [];
|
@@ -4706,12 +4939,21 @@ var Account = class extends AbstractAccount {
|
|
4706
4939
|
});
|
4707
4940
|
const needsToBeFunded = missingQuantities.length;
|
4708
4941
|
if (needsToBeFunded) {
|
4709
|
-
const
|
4710
|
-
|
4711
|
-
|
4712
|
-
|
4713
|
-
|
4714
|
-
|
4942
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4943
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4944
|
+
txRequest.addResources(resources);
|
4945
|
+
}
|
4946
|
+
txRequest.shiftPredicateData();
|
4947
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4948
|
+
const requestToReestimate = clone4(txRequest);
|
4949
|
+
if (addedSignatures) {
|
4950
|
+
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
4951
|
+
}
|
4952
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4953
|
+
transactionRequest: requestToReestimate
|
4954
|
+
});
|
4955
|
+
txRequest.maxFee = maxFee;
|
4956
|
+
return txRequest;
|
4715
4957
|
}
|
4716
4958
|
/**
|
4717
4959
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4719,29 +4961,25 @@ var Account = class extends AbstractAccount {
|
|
4719
4961
|
* @param destination - The address of the destination.
|
4720
4962
|
* @param amount - The amount of coins to transfer.
|
4721
4963
|
* @param assetId - The asset ID of the coins to transfer.
|
4722
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4964
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4723
4965
|
* @returns A promise that resolves to the prepared transaction request.
|
4724
4966
|
*/
|
4725
4967
|
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4726
|
-
const
|
4968
|
+
const request = new ScriptTransactionRequest(txParams);
|
4727
4969
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4728
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4729
|
-
const request = new ScriptTransactionRequest(params);
|
4730
4970
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4731
|
-
const
|
4971
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4732
4972
|
estimateTxDependencies: true,
|
4733
4973
|
resourcesOwner: this
|
4734
4974
|
});
|
4735
|
-
|
4736
|
-
|
4737
|
-
|
4738
|
-
|
4739
|
-
gasPrice: request.gasPrice,
|
4740
|
-
gasLimit: request.gasLimit,
|
4741
|
-
minGasPrice
|
4975
|
+
this.validateGasLimitAndMaxFee({
|
4976
|
+
gasUsed: txCost.gasUsed,
|
4977
|
+
maxFee: txCost.maxFee,
|
4978
|
+
txParams
|
4742
4979
|
});
|
4743
|
-
|
4744
|
-
request.
|
4980
|
+
request.gasLimit = txCost.gasUsed;
|
4981
|
+
request.maxFee = txCost.maxFee;
|
4982
|
+
await this.fund(request, txCost);
|
4745
4983
|
return request;
|
4746
4984
|
}
|
4747
4985
|
/**
|
@@ -4750,11 +4988,11 @@ var Account = class extends AbstractAccount {
|
|
4750
4988
|
* @param destination - The address of the destination.
|
4751
4989
|
* @param amount - The amount of coins to transfer.
|
4752
4990
|
* @param assetId - The asset ID of the coins to transfer.
|
4753
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4991
|
+
* @param txParams - The transaction parameters (gasLimit, maturity).
|
4754
4992
|
* @returns A promise that resolves to the transaction response.
|
4755
4993
|
*/
|
4756
4994
|
async transfer(destination, amount, assetId, txParams = {}) {
|
4757
|
-
if (
|
4995
|
+
if (bn18(amount).lte(0)) {
|
4758
4996
|
throw new FuelError15(
|
4759
4997
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4760
4998
|
"Transfer amount must be a positive number."
|
@@ -4774,39 +5012,37 @@ var Account = class extends AbstractAccount {
|
|
4774
5012
|
* @returns A promise that resolves to the transaction response.
|
4775
5013
|
*/
|
4776
5014
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4777
|
-
if (
|
5015
|
+
if (bn18(amount).lte(0)) {
|
4778
5016
|
throw new FuelError15(
|
4779
5017
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4780
5018
|
"Transfer amount must be a positive number."
|
4781
5019
|
);
|
4782
5020
|
}
|
4783
5021
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4784
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4785
5022
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4786
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4787
5023
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4788
5024
|
hexlifiedContractId: contractAddress.toB256(),
|
4789
|
-
amountToTransfer:
|
5025
|
+
amountToTransfer: bn18(amount),
|
4790
5026
|
assetId: assetIdToTransfer
|
4791
5027
|
});
|
4792
5028
|
const request = new ScriptTransactionRequest({
|
4793
|
-
...
|
5029
|
+
...txParams,
|
4794
5030
|
script,
|
4795
5031
|
scriptData
|
4796
5032
|
});
|
4797
5033
|
request.addContractInputAndOutput(contractAddress);
|
4798
|
-
const
|
4799
|
-
|
4800
|
-
[{ amount:
|
4801
|
-
);
|
4802
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4803
|
-
this.validateGas({
|
4804
|
-
gasUsed,
|
4805
|
-
gasPrice: request.gasPrice,
|
4806
|
-
gasLimit: request.gasLimit,
|
4807
|
-
minGasPrice
|
5034
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5035
|
+
resourcesOwner: this,
|
5036
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetIdToTransfer) }]
|
4808
5037
|
});
|
4809
|
-
|
5038
|
+
this.validateGasLimitAndMaxFee({
|
5039
|
+
gasUsed: txCost.gasUsed,
|
5040
|
+
maxFee: txCost.maxFee,
|
5041
|
+
txParams
|
5042
|
+
});
|
5043
|
+
request.gasLimit = txCost.gasUsed;
|
5044
|
+
request.maxFee = txCost.maxFee;
|
5045
|
+
await this.fund(request, txCost);
|
4810
5046
|
return this.sendTransaction(request);
|
4811
5047
|
}
|
4812
5048
|
/**
|
@@ -4818,39 +5054,31 @@ var Account = class extends AbstractAccount {
|
|
4818
5054
|
* @returns A promise that resolves to the transaction response.
|
4819
5055
|
*/
|
4820
5056
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4821
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4822
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4823
5057
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4824
5058
|
const recipientDataArray = arrayify14(
|
4825
5059
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4826
5060
|
);
|
4827
5061
|
const amountDataArray = arrayify14(
|
4828
|
-
"0x".concat(
|
5062
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
4829
5063
|
);
|
4830
5064
|
const script = new Uint8Array([
|
4831
5065
|
...arrayify14(withdrawScript.bytes),
|
4832
5066
|
...recipientDataArray,
|
4833
5067
|
...amountDataArray
|
4834
5068
|
]);
|
4835
|
-
const params = {
|
4836
|
-
|
4837
|
-
gasPrice: minGasPrice,
|
4838
|
-
...txParams
|
4839
|
-
};
|
5069
|
+
const params = { script, ...txParams };
|
5070
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4840
5071
|
const request = new ScriptTransactionRequest(params);
|
4841
|
-
const
|
4842
|
-
const
|
4843
|
-
|
4844
|
-
|
4845
|
-
|
4846
|
-
|
4847
|
-
this.validateGas({
|
4848
|
-
gasUsed,
|
4849
|
-
gasPrice: request.gasPrice,
|
4850
|
-
gasLimit: request.gasLimit,
|
4851
|
-
minGasPrice
|
5072
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: baseAssetId }];
|
5073
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5074
|
+
this.validateGasLimitAndMaxFee({
|
5075
|
+
gasUsed: txCost.gasUsed,
|
5076
|
+
maxFee: txCost.maxFee,
|
5077
|
+
txParams
|
4852
5078
|
});
|
4853
|
-
|
5079
|
+
request.maxFee = txCost.maxFee;
|
5080
|
+
request.gasLimit = txCost.gasUsed;
|
5081
|
+
await this.fund(request, txCost);
|
4854
5082
|
return this.sendTransaction(request);
|
4855
5083
|
}
|
4856
5084
|
async signMessage(message) {
|
@@ -4908,22 +5136,21 @@ var Account = class extends AbstractAccount {
|
|
4908
5136
|
}
|
4909
5137
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4910
5138
|
}
|
4911
|
-
|
5139
|
+
validateGasLimitAndMaxFee({
|
5140
|
+
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
4912
5141
|
gasUsed,
|
4913
|
-
|
4914
|
-
gasLimit,
|
4915
|
-
minGasPrice
|
5142
|
+
maxFee
|
4916
5143
|
}) {
|
4917
|
-
if (
|
5144
|
+
if (isDefined(setGasLimit) && gasUsed.gt(setGasLimit)) {
|
4918
5145
|
throw new FuelError15(
|
4919
|
-
ErrorCode15.
|
4920
|
-
`Gas
|
5146
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
5147
|
+
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
4921
5148
|
);
|
4922
5149
|
}
|
4923
|
-
if (
|
5150
|
+
if (isDefined(setMaxFee) && maxFee.gt(setMaxFee)) {
|
4924
5151
|
throw new FuelError15(
|
4925
|
-
ErrorCode15.
|
4926
|
-
`
|
5152
|
+
ErrorCode15.MAX_FEE_TOO_LOW,
|
5153
|
+
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
4927
5154
|
);
|
4928
5155
|
}
|
4929
5156
|
}
|
@@ -5211,7 +5438,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5211
5438
|
* @param transactionRequestLike - The transaction request to send.
|
5212
5439
|
* @returns A promise that resolves to the TransactionResponse object.
|
5213
5440
|
*/
|
5214
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5441
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5215
5442
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5216
5443
|
if (estimateTxDependencies) {
|
5217
5444
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5252,7 +5479,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5252
5479
|
// src/hdwallet/hdwallet.ts
|
5253
5480
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5254
5481
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5255
|
-
import { bn as
|
5482
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5256
5483
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5257
5484
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5258
5485
|
|
@@ -7718,7 +7945,7 @@ var HDWallet = class {
|
|
7718
7945
|
const IR = bytes.slice(32);
|
7719
7946
|
if (privateKey) {
|
7720
7947
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7721
|
-
const ki =
|
7948
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7722
7949
|
return new HDWallet({
|
7723
7950
|
privateKey: ki,
|
7724
7951
|
chainCode: IR,
|
@@ -7989,14 +8216,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7989
8216
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
7990
8217
|
wallet.provider
|
7991
8218
|
);
|
7992
|
-
const
|
7993
|
-
|
7994
|
-
|
7995
|
-
|
7996
|
-
gasPrice: minGasPrice
|
8219
|
+
const request = new ScriptTransactionRequest();
|
8220
|
+
quantities.forEach((quantity) => {
|
8221
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8222
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7997
8223
|
});
|
7998
|
-
|
7999
|
-
|
8224
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8225
|
+
request.gasLimit = txCost.gasUsed;
|
8226
|
+
request.maxFee = txCost.maxFee;
|
8227
|
+
await genesisWallet.fund(request, txCost);
|
8000
8228
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8001
8229
|
};
|
8002
8230
|
|
@@ -8010,9 +8238,9 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8010
8238
|
};
|
8011
8239
|
|
8012
8240
|
// src/test-utils/launchNode.ts
|
8013
|
-
import {
|
8014
|
-
import {
|
8015
|
-
import {
|
8241
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8242
|
+
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8243
|
+
import { defaultSnapshotConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8016
8244
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8017
8245
|
import { spawn } from "child_process";
|
8018
8246
|
import { randomUUID } from "crypto";
|
@@ -8064,12 +8292,12 @@ var launchNode = async ({
|
|
8064
8292
|
// eslint-disable-next-line no-async-promise-executor
|
8065
8293
|
new Promise(async (resolve, reject) => {
|
8066
8294
|
const remainingArgs = extractRemainingArgs(args, [
|
8067
|
-
"--
|
8295
|
+
"--snapshot",
|
8068
8296
|
"--consensus-key",
|
8069
8297
|
"--db-type",
|
8070
8298
|
"--poa-instant"
|
8071
8299
|
]);
|
8072
|
-
const
|
8300
|
+
const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
|
8073
8301
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8074
8302
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8075
8303
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8085,39 +8313,57 @@ var launchNode = async ({
|
|
8085
8313
|
stopPort: 5e3
|
8086
8314
|
// don't try ports above 5000
|
8087
8315
|
})).toString();
|
8088
|
-
let
|
8316
|
+
let snapshotDirToUse;
|
8089
8317
|
const prefix = basePath || os.tmpdir();
|
8090
8318
|
const suffix = basePath ? "" : randomUUID();
|
8091
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8092
|
-
if (
|
8093
|
-
|
8319
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8320
|
+
if (snapshotDir) {
|
8321
|
+
snapshotDirToUse = snapshotDir;
|
8094
8322
|
} else {
|
8095
8323
|
if (!existsSync(tempDirPath)) {
|
8096
8324
|
mkdirSync(tempDirPath, { recursive: true });
|
8097
8325
|
}
|
8098
|
-
|
8099
|
-
|
8326
|
+
let { stateConfigJson } = defaultSnapshotConfigs;
|
8327
|
+
const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
|
8328
|
+
stateConfigJson = {
|
8329
|
+
...stateConfigJson,
|
8330
|
+
coins: [
|
8331
|
+
...stateConfigJson.coins.map((coin) => ({
|
8332
|
+
...coin,
|
8333
|
+
amount: "18446744073709551615"
|
8334
|
+
}))
|
8335
|
+
],
|
8336
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8337
|
+
...message,
|
8338
|
+
amount: "18446744073709551615"
|
8339
|
+
}))
|
8340
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8341
|
+
};
|
8100
8342
|
if (!process.env.GENESIS_SECRET) {
|
8101
8343
|
const pk = Signer.generatePrivateKey();
|
8102
8344
|
const signer = new Signer(pk);
|
8103
8345
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8104
|
-
|
8105
|
-
|
8106
|
-
|
8107
|
-
|
8108
|
-
|
8109
|
-
|
8110
|
-
|
8111
|
-
|
8112
|
-
|
8113
|
-
|
8114
|
-
}
|
8115
|
-
]
|
8116
|
-
}
|
8117
|
-
};
|
8346
|
+
stateConfigJson.coins.push({
|
8347
|
+
tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
|
8348
|
+
owner: signer.address.toHexString(),
|
8349
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8350
|
+
amount: "18446744073709551615",
|
8351
|
+
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8352
|
+
output_index: 0,
|
8353
|
+
tx_pointer_block_height: 0,
|
8354
|
+
tx_pointer_tx_idx: 0
|
8355
|
+
});
|
8118
8356
|
}
|
8119
|
-
|
8120
|
-
|
8357
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8358
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8359
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8360
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8361
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8362
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8363
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8364
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8365
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8366
|
+
snapshotDirToUse = tempDirPath;
|
8121
8367
|
}
|
8122
8368
|
const child = spawn(
|
8123
8369
|
command,
|
@@ -8126,10 +8372,10 @@ var launchNode = async ({
|
|
8126
8372
|
["--ip", ipToUse],
|
8127
8373
|
["--port", portToUse],
|
8128
8374
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8129
|
-
["--min-gas-price", "
|
8375
|
+
["--min-gas-price", "1"],
|
8130
8376
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8131
8377
|
["--consensus-key", consensusKey],
|
8132
|
-
["--
|
8378
|
+
["--snapshot", snapshotDirToUse],
|
8133
8379
|
"--vm-backtrace",
|
8134
8380
|
"--utxo-validation",
|
8135
8381
|
"--debug",
|
@@ -8159,7 +8405,7 @@ var launchNode = async ({
|
|
8159
8405
|
cleanup: () => killNode(cleanupConfig),
|
8160
8406
|
ip: ipToUse,
|
8161
8407
|
port: portToUse,
|
8162
|
-
|
8408
|
+
snapshotDir: snapshotDirToUse
|
8163
8409
|
});
|
8164
8410
|
}
|
8165
8411
|
if (/error/i.test(chunk)) {
|
@@ -8189,7 +8435,7 @@ var launchNodeAndGetWallets = async ({
|
|
8189
8435
|
walletCount = 10
|
8190
8436
|
} = {}) => {
|
8191
8437
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8192
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8438
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8193
8439
|
const wallets = await generateWallets(walletCount, provider);
|
8194
8440
|
const cleanup = () => {
|
8195
8441
|
closeNode();
|