@fuel-ts/account 0.0.0-rc-2021-20240424160726 → 0.0.0-rc-2143-20240424161332
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -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 +583 -863
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +513 -793
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +395 -674
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +326 -828
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +27 -37
- 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 +29 -8
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- 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 +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- 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 +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +4 -2
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1055 -1551
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +513 -775
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +406 -668
- 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
@@ -27,9 +27,8 @@ import { Address as Address3 } from "@fuel-ts/address";
|
|
27
27
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
31
|
-
import { arrayify as arrayify14
|
32
|
-
import { clone as clone4 } from "ramda";
|
30
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
31
|
+
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
33
32
|
|
34
33
|
// src/providers/coin-quantity.ts
|
35
34
|
import { BaseAssetId } from "@fuel-ts/address/configs";
|
@@ -38,24 +37,24 @@ import { hexlify } from "@fuel-ts/utils";
|
|
38
37
|
var coinQuantityfy = (coinQuantityLike) => {
|
39
38
|
let assetId;
|
40
39
|
let amount;
|
41
|
-
let
|
40
|
+
let max2;
|
42
41
|
if (Array.isArray(coinQuantityLike)) {
|
43
42
|
amount = coinQuantityLike[0];
|
44
43
|
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
45
|
-
|
44
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
46
45
|
} else {
|
47
46
|
amount = coinQuantityLike.amount;
|
48
47
|
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
49
|
-
|
48
|
+
max2 = coinQuantityLike.max ?? void 0;
|
50
49
|
}
|
51
50
|
const bnAmount = bn(amount);
|
52
51
|
return {
|
53
52
|
assetId: hexlify(assetId),
|
54
53
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
55
|
-
max:
|
54
|
+
max: max2 ? bn(max2) : void 0
|
56
55
|
};
|
57
56
|
};
|
58
|
-
var
|
57
|
+
var addAmountToAsset = (params) => {
|
59
58
|
const { amount, assetId } = params;
|
60
59
|
const coinQuantities = [...params.coinQuantities];
|
61
60
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -70,9 +69,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
70
69
|
// src/providers/provider.ts
|
71
70
|
import { Address as Address2 } from "@fuel-ts/address";
|
72
71
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
73
|
-
import { BN, bn as
|
72
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
74
73
|
import {
|
75
|
-
InputType as
|
74
|
+
InputType as InputType6,
|
76
75
|
TransactionType as TransactionType8,
|
77
76
|
InputMessageCoder,
|
78
77
|
TransactionCoder as TransactionCoder5
|
@@ -86,40 +85,16 @@ import { clone as clone3 } from "ramda";
|
|
86
85
|
|
87
86
|
// src/providers/__generated__/operations.ts
|
88
87
|
import gql from "graphql-tag";
|
89
|
-
var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
|
90
|
-
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
91
|
-
type: __typename
|
92
|
-
... on SubmittedStatus {
|
93
|
-
time
|
94
|
-
}
|
95
|
-
... on SuccessStatus {
|
96
|
-
block {
|
97
|
-
id
|
98
|
-
}
|
99
|
-
time
|
100
|
-
programState {
|
101
|
-
returnType
|
102
|
-
data
|
103
|
-
}
|
104
|
-
}
|
105
|
-
... on FailureStatus {
|
106
|
-
block {
|
107
|
-
id
|
108
|
-
}
|
109
|
-
time
|
110
|
-
reason
|
111
|
-
}
|
112
|
-
... on SqueezedOutStatus {
|
113
|
-
reason
|
114
|
-
}
|
115
|
-
}
|
116
|
-
`;
|
117
88
|
var ReceiptFragmentFragmentDoc = gql`
|
118
89
|
fragment receiptFragment on Receipt {
|
119
|
-
|
90
|
+
contract {
|
91
|
+
id
|
92
|
+
}
|
120
93
|
pc
|
121
94
|
is
|
122
|
-
to
|
95
|
+
to {
|
96
|
+
id
|
97
|
+
}
|
123
98
|
toAddress
|
124
99
|
amount
|
125
100
|
assetId
|
@@ -157,16 +132,10 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
157
132
|
id
|
158
133
|
}
|
159
134
|
time
|
160
|
-
receipts {
|
161
|
-
...receiptFragment
|
162
|
-
}
|
163
135
|
programState {
|
164
136
|
returnType
|
165
137
|
data
|
166
138
|
}
|
167
|
-
receipts {
|
168
|
-
...receiptFragment
|
169
|
-
}
|
170
139
|
}
|
171
140
|
... on FailureStatus {
|
172
141
|
block {
|
@@ -174,24 +143,26 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
174
143
|
}
|
175
144
|
time
|
176
145
|
reason
|
177
|
-
receipts {
|
178
|
-
...receiptFragment
|
179
|
-
}
|
180
146
|
}
|
181
147
|
... on SqueezedOutStatus {
|
182
148
|
reason
|
183
149
|
}
|
184
150
|
}
|
185
|
-
|
151
|
+
`;
|
186
152
|
var TransactionFragmentFragmentDoc = gql`
|
187
153
|
fragment transactionFragment on Transaction {
|
188
154
|
id
|
189
155
|
rawPayload
|
156
|
+
gasPrice
|
157
|
+
receipts {
|
158
|
+
...receiptFragment
|
159
|
+
}
|
190
160
|
status {
|
191
161
|
...transactionStatusFragment
|
192
162
|
}
|
193
163
|
}
|
194
|
-
${
|
164
|
+
${ReceiptFragmentFragmentDoc}
|
165
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
195
166
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
196
167
|
fragment inputEstimatePredicatesFragment on Input {
|
197
168
|
... on InputCoin {
|
@@ -209,46 +180,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
209
180
|
}
|
210
181
|
}
|
211
182
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
212
|
-
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
213
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
214
|
-
reason
|
215
|
-
programState {
|
216
|
-
returnType
|
217
|
-
data
|
218
|
-
}
|
219
|
-
}
|
220
|
-
`;
|
221
|
-
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
222
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
223
|
-
programState {
|
224
|
-
returnType
|
225
|
-
data
|
226
|
-
}
|
227
|
-
}
|
228
|
-
`;
|
229
|
-
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
230
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
231
|
-
... on DryRunFailureStatus {
|
232
|
-
...dryRunFailureStatusFragment
|
233
|
-
}
|
234
|
-
... on DryRunSuccessStatus {
|
235
|
-
...dryRunSuccessStatusFragment
|
236
|
-
}
|
237
|
-
}
|
238
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
239
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
240
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
241
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
242
|
-
id
|
243
|
-
status {
|
244
|
-
...dryRunTransactionStatusFragment
|
245
|
-
}
|
246
|
-
receipts {
|
247
|
-
...receiptFragment
|
248
|
-
}
|
249
|
-
}
|
250
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
251
|
-
${ReceiptFragmentFragmentDoc}`;
|
252
183
|
var CoinFragmentFragmentDoc = gql`
|
253
184
|
fragment coinFragment on Coin {
|
254
185
|
__typename
|
@@ -256,6 +187,7 @@ var CoinFragmentFragmentDoc = gql`
|
|
256
187
|
owner
|
257
188
|
amount
|
258
189
|
assetId
|
190
|
+
maturity
|
259
191
|
blockCreated
|
260
192
|
txCreatedIdx
|
261
193
|
}
|
@@ -294,32 +226,26 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
294
226
|
messageBlockHeader {
|
295
227
|
id
|
296
228
|
daHeight
|
297
|
-
consensusParametersVersion
|
298
|
-
stateTransitionBytecodeVersion
|
299
229
|
transactionsCount
|
300
|
-
messageReceiptCount
|
301
230
|
transactionsRoot
|
302
|
-
messageOutboxRoot
|
303
|
-
eventInboxRoot
|
304
231
|
height
|
305
232
|
prevRoot
|
306
233
|
time
|
307
234
|
applicationHash
|
235
|
+
messageReceiptRoot
|
236
|
+
messageReceiptCount
|
308
237
|
}
|
309
238
|
commitBlockHeader {
|
310
239
|
id
|
311
240
|
daHeight
|
312
|
-
consensusParametersVersion
|
313
|
-
stateTransitionBytecodeVersion
|
314
241
|
transactionsCount
|
315
|
-
messageReceiptCount
|
316
242
|
transactionsRoot
|
317
|
-
messageOutboxRoot
|
318
|
-
eventInboxRoot
|
319
243
|
height
|
320
244
|
prevRoot
|
321
245
|
time
|
322
246
|
applicationHash
|
247
|
+
messageReceiptRoot
|
248
|
+
messageReceiptCount
|
323
249
|
}
|
324
250
|
sender
|
325
251
|
recipient
|
@@ -338,8 +264,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
338
264
|
var BlockFragmentFragmentDoc = gql`
|
339
265
|
fragment blockFragment on Block {
|
340
266
|
id
|
341
|
-
height
|
342
267
|
header {
|
268
|
+
height
|
343
269
|
time
|
344
270
|
}
|
345
271
|
transactions {
|
@@ -349,7 +275,6 @@ var BlockFragmentFragmentDoc = gql`
|
|
349
275
|
`;
|
350
276
|
var TxParametersFragmentFragmentDoc = gql`
|
351
277
|
fragment TxParametersFragment on TxParameters {
|
352
|
-
version
|
353
278
|
maxInputs
|
354
279
|
maxOutputs
|
355
280
|
maxWitnesses
|
@@ -359,7 +284,6 @@ var TxParametersFragmentFragmentDoc = gql`
|
|
359
284
|
`;
|
360
285
|
var PredicateParametersFragmentFragmentDoc = gql`
|
361
286
|
fragment PredicateParametersFragment on PredicateParameters {
|
362
|
-
version
|
363
287
|
maxPredicateLength
|
364
288
|
maxPredicateDataLength
|
365
289
|
maxGasPerPredicate
|
@@ -368,21 +292,18 @@ var PredicateParametersFragmentFragmentDoc = gql`
|
|
368
292
|
`;
|
369
293
|
var ScriptParametersFragmentFragmentDoc = gql`
|
370
294
|
fragment ScriptParametersFragment on ScriptParameters {
|
371
|
-
version
|
372
295
|
maxScriptLength
|
373
296
|
maxScriptDataLength
|
374
297
|
}
|
375
298
|
`;
|
376
299
|
var ContractParametersFragmentFragmentDoc = gql`
|
377
300
|
fragment ContractParametersFragment on ContractParameters {
|
378
|
-
version
|
379
301
|
contractMaxSize
|
380
302
|
maxStorageSlots
|
381
303
|
}
|
382
304
|
`;
|
383
305
|
var FeeParametersFragmentFragmentDoc = gql`
|
384
306
|
fragment FeeParametersFragment on FeeParameters {
|
385
|
-
version
|
386
307
|
gasPriceFactor
|
387
308
|
gasPerByte
|
388
309
|
}
|
@@ -402,7 +323,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
402
323
|
`;
|
403
324
|
var GasCostsFragmentFragmentDoc = gql`
|
404
325
|
fragment GasCostsFragment on GasCosts {
|
405
|
-
version
|
406
326
|
add
|
407
327
|
addi
|
408
328
|
aloc
|
@@ -415,6 +335,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
415
335
|
cb
|
416
336
|
cfei
|
417
337
|
cfsi
|
338
|
+
croo
|
418
339
|
div
|
419
340
|
divi
|
420
341
|
ecr1
|
@@ -497,9 +418,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
497
418
|
ccp {
|
498
419
|
...DependentCostFragment
|
499
420
|
}
|
500
|
-
croo {
|
501
|
-
...DependentCostFragment
|
502
|
-
}
|
503
421
|
csiz {
|
504
422
|
...DependentCostFragment
|
505
423
|
}
|
@@ -559,7 +477,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
559
477
|
${DependentCostFragmentFragmentDoc}`;
|
560
478
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
561
479
|
fragment consensusParametersFragment on ConsensusParameters {
|
562
|
-
version
|
563
480
|
txParams {
|
564
481
|
...TxParametersFragment
|
565
482
|
}
|
@@ -619,9 +536,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
619
536
|
fragment nodeInfoFragment on NodeInfo {
|
620
537
|
utxoValidation
|
621
538
|
vmBacktrace
|
539
|
+
minGasPrice
|
622
540
|
maxTx
|
623
541
|
maxDepth
|
624
542
|
nodeVersion
|
543
|
+
peers {
|
544
|
+
id
|
545
|
+
addresses
|
546
|
+
clientVersion
|
547
|
+
blockHeight
|
548
|
+
lastHeartbeatMs
|
549
|
+
appScore
|
550
|
+
}
|
625
551
|
}
|
626
552
|
`;
|
627
553
|
var GetVersionDocument = gql`
|
@@ -656,9 +582,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
656
582
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
657
583
|
transaction(id: $transactionId) {
|
658
584
|
...transactionFragment
|
585
|
+
receipts {
|
586
|
+
...receiptFragment
|
587
|
+
}
|
659
588
|
}
|
660
589
|
}
|
661
|
-
${TransactionFragmentFragmentDoc}
|
590
|
+
${TransactionFragmentFragmentDoc}
|
591
|
+
${ReceiptFragmentFragmentDoc}`;
|
662
592
|
var GetTransactionsDocument = gql`
|
663
593
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
664
594
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -786,20 +716,6 @@ var GetBalanceDocument = gql`
|
|
786
716
|
}
|
787
717
|
}
|
788
718
|
${BalanceFragmentFragmentDoc}`;
|
789
|
-
var GetLatestGasPriceDocument = gql`
|
790
|
-
query getLatestGasPrice {
|
791
|
-
latestGasPrice {
|
792
|
-
gasPrice
|
793
|
-
}
|
794
|
-
}
|
795
|
-
`;
|
796
|
-
var EstimateGasPriceDocument = gql`
|
797
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
798
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
799
|
-
gasPrice
|
800
|
-
}
|
801
|
-
}
|
802
|
-
`;
|
803
719
|
var GetBalancesDocument = gql`
|
804
720
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
805
721
|
balances(
|
@@ -854,12 +770,12 @@ var GetMessageStatusDocument = gql`
|
|
854
770
|
}
|
855
771
|
`;
|
856
772
|
var DryRunDocument = gql`
|
857
|
-
mutation dryRun($
|
858
|
-
dryRun(
|
859
|
-
...
|
773
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
774
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
775
|
+
...receiptFragment
|
860
776
|
}
|
861
777
|
}
|
862
|
-
${
|
778
|
+
${ReceiptFragmentFragmentDoc}`;
|
863
779
|
var SubmitDocument = gql`
|
864
780
|
mutation submit($encodedTransaction: HexString!) {
|
865
781
|
submit(tx: $encodedTransaction) {
|
@@ -878,17 +794,17 @@ var ProduceBlocksDocument = gql`
|
|
878
794
|
var SubmitAndAwaitDocument = gql`
|
879
795
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
880
796
|
submitAndAwait(tx: $encodedTransaction) {
|
881
|
-
...
|
797
|
+
...transactionStatusFragment
|
882
798
|
}
|
883
799
|
}
|
884
|
-
${
|
800
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
885
801
|
var StatusChangeDocument = gql`
|
886
802
|
subscription statusChange($transactionId: TransactionId!) {
|
887
803
|
statusChange(id: $transactionId) {
|
888
|
-
...
|
804
|
+
...transactionStatusFragment
|
889
805
|
}
|
890
806
|
}
|
891
|
-
${
|
807
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
892
808
|
function getSdk(requester) {
|
893
809
|
return {
|
894
810
|
getVersion(variables, options) {
|
@@ -942,12 +858,6 @@ function getSdk(requester) {
|
|
942
858
|
getBalance(variables, options) {
|
943
859
|
return requester(GetBalanceDocument, variables, options);
|
944
860
|
},
|
945
|
-
getLatestGasPrice(variables, options) {
|
946
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
947
|
-
},
|
948
|
-
estimateGasPrice(variables, options) {
|
949
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
950
|
-
},
|
951
861
|
getBalances(variables, options) {
|
952
862
|
return requester(GetBalancesDocument, variables, options);
|
953
863
|
},
|
@@ -1141,9 +1051,10 @@ var inputify = (value) => {
|
|
1141
1051
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1142
1052
|
},
|
1143
1053
|
witnessIndex: value.witnessIndex,
|
1054
|
+
maturity: value.maturity ?? 0,
|
1144
1055
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1145
|
-
predicateLength:
|
1146
|
-
predicateDataLength:
|
1056
|
+
predicateLength: predicate.length,
|
1057
|
+
predicateDataLength: predicateData.length,
|
1147
1058
|
predicate: hexlify3(predicate),
|
1148
1059
|
predicateData: hexlify3(predicateData)
|
1149
1060
|
};
|
@@ -1174,8 +1085,8 @@ var inputify = (value) => {
|
|
1174
1085
|
nonce: hexlify3(value.nonce),
|
1175
1086
|
witnessIndex: value.witnessIndex,
|
1176
1087
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1177
|
-
predicateLength:
|
1178
|
-
predicateDataLength:
|
1088
|
+
predicateLength: predicate.length,
|
1089
|
+
predicateDataLength: predicateData.length,
|
1179
1090
|
predicate: hexlify3(predicate),
|
1180
1091
|
predicateData: hexlify3(predicateData),
|
1181
1092
|
data: hexlify3(data),
|
@@ -1302,8 +1213,8 @@ function assembleReceiptByType(receipt) {
|
|
1302
1213
|
case "CALL" /* Call */: {
|
1303
1214
|
const callReceipt = {
|
1304
1215
|
type: ReceiptType.Call,
|
1305
|
-
from: hexOrZero(receipt.id
|
1306
|
-
to: hexOrZero(receipt?.to),
|
1216
|
+
from: hexOrZero(receipt.contract?.id),
|
1217
|
+
to: hexOrZero(receipt?.to?.id),
|
1307
1218
|
amount: bn4(receipt.amount),
|
1308
1219
|
assetId: hexOrZero(receipt.assetId),
|
1309
1220
|
gas: bn4(receipt.gas),
|
@@ -1317,7 +1228,7 @@ function assembleReceiptByType(receipt) {
|
|
1317
1228
|
case "RETURN" /* Return */: {
|
1318
1229
|
const returnReceipt = {
|
1319
1230
|
type: ReceiptType.Return,
|
1320
|
-
id: hexOrZero(receipt.id
|
1231
|
+
id: hexOrZero(receipt.contract?.id),
|
1321
1232
|
val: bn4(receipt.val),
|
1322
1233
|
pc: bn4(receipt.pc),
|
1323
1234
|
is: bn4(receipt.is)
|
@@ -1327,7 +1238,7 @@ function assembleReceiptByType(receipt) {
|
|
1327
1238
|
case "RETURN_DATA" /* ReturnData */: {
|
1328
1239
|
const returnDataReceipt = {
|
1329
1240
|
type: ReceiptType.ReturnData,
|
1330
|
-
id: hexOrZero(receipt.id
|
1241
|
+
id: hexOrZero(receipt.contract?.id),
|
1331
1242
|
ptr: bn4(receipt.ptr),
|
1332
1243
|
len: bn4(receipt.len),
|
1333
1244
|
digest: hexOrZero(receipt.digest),
|
@@ -1339,7 +1250,7 @@ function assembleReceiptByType(receipt) {
|
|
1339
1250
|
case "PANIC" /* Panic */: {
|
1340
1251
|
const panicReceipt = {
|
1341
1252
|
type: ReceiptType.Panic,
|
1342
|
-
id: hexOrZero(receipt.id),
|
1253
|
+
id: hexOrZero(receipt.contract?.id),
|
1343
1254
|
reason: bn4(receipt.reason),
|
1344
1255
|
pc: bn4(receipt.pc),
|
1345
1256
|
is: bn4(receipt.is),
|
@@ -1350,7 +1261,7 @@ function assembleReceiptByType(receipt) {
|
|
1350
1261
|
case "REVERT" /* Revert */: {
|
1351
1262
|
const revertReceipt = {
|
1352
1263
|
type: ReceiptType.Revert,
|
1353
|
-
id: hexOrZero(receipt.id
|
1264
|
+
id: hexOrZero(receipt.contract?.id),
|
1354
1265
|
val: bn4(receipt.ra),
|
1355
1266
|
pc: bn4(receipt.pc),
|
1356
1267
|
is: bn4(receipt.is)
|
@@ -1360,7 +1271,7 @@ function assembleReceiptByType(receipt) {
|
|
1360
1271
|
case "LOG" /* Log */: {
|
1361
1272
|
const logReceipt = {
|
1362
1273
|
type: ReceiptType.Log,
|
1363
|
-
id: hexOrZero(receipt.id
|
1274
|
+
id: hexOrZero(receipt.contract?.id),
|
1364
1275
|
val0: bn4(receipt.ra),
|
1365
1276
|
val1: bn4(receipt.rb),
|
1366
1277
|
val2: bn4(receipt.rc),
|
@@ -1373,7 +1284,7 @@ function assembleReceiptByType(receipt) {
|
|
1373
1284
|
case "LOG_DATA" /* LogData */: {
|
1374
1285
|
const logDataReceipt = {
|
1375
1286
|
type: ReceiptType.LogData,
|
1376
|
-
id: hexOrZero(receipt.id
|
1287
|
+
id: hexOrZero(receipt.contract?.id),
|
1377
1288
|
val0: bn4(receipt.ra),
|
1378
1289
|
val1: bn4(receipt.rb),
|
1379
1290
|
ptr: bn4(receipt.ptr),
|
@@ -1387,8 +1298,8 @@ function assembleReceiptByType(receipt) {
|
|
1387
1298
|
case "TRANSFER" /* Transfer */: {
|
1388
1299
|
const transferReceipt = {
|
1389
1300
|
type: ReceiptType.Transfer,
|
1390
|
-
from: hexOrZero(receipt.id
|
1391
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1301
|
+
from: hexOrZero(receipt.contract?.id),
|
1302
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1392
1303
|
amount: bn4(receipt.amount),
|
1393
1304
|
assetId: hexOrZero(receipt.assetId),
|
1394
1305
|
pc: bn4(receipt.pc),
|
@@ -1399,8 +1310,8 @@ function assembleReceiptByType(receipt) {
|
|
1399
1310
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1400
1311
|
const transferOutReceipt = {
|
1401
1312
|
type: ReceiptType.TransferOut,
|
1402
|
-
from: hexOrZero(receipt.id
|
1403
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1313
|
+
from: hexOrZero(receipt.contract?.id),
|
1314
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1404
1315
|
amount: bn4(receipt.amount),
|
1405
1316
|
assetId: hexOrZero(receipt.assetId),
|
1406
1317
|
pc: bn4(receipt.pc),
|
@@ -1443,7 +1354,7 @@ function assembleReceiptByType(receipt) {
|
|
1443
1354
|
return receiptMessageOut;
|
1444
1355
|
}
|
1445
1356
|
case "MINT" /* Mint */: {
|
1446
|
-
const contractId = hexOrZero(receipt.id
|
1357
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1447
1358
|
const subId = hexOrZero(receipt.subId);
|
1448
1359
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1449
1360
|
const mintReceipt = {
|
@@ -1458,7 +1369,7 @@ function assembleReceiptByType(receipt) {
|
|
1458
1369
|
return mintReceipt;
|
1459
1370
|
}
|
1460
1371
|
case "BURN" /* Burn */: {
|
1461
|
-
const contractId = hexOrZero(receipt.id
|
1372
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1462
1373
|
const subId = hexOrZero(receipt.subId);
|
1463
1374
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1464
1375
|
const burnReceipt = {
|
@@ -1484,6 +1395,7 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1484
1395
|
import { bn as bn5 } from "@fuel-ts/math";
|
1485
1396
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1486
1397
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1398
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1487
1399
|
var getGasUsedFromReceipts = (receipts) => {
|
1488
1400
|
const scriptResult = receipts.filter(
|
1489
1401
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1504,28 +1416,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1504
1416
|
}
|
1505
1417
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1506
1418
|
const witnessCache = [];
|
1507
|
-
const
|
1508
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1509
|
-
if (isCoinOrMessage) {
|
1510
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1511
|
-
return true;
|
1512
|
-
}
|
1513
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1514
|
-
witnessCache.push(input.witnessIndex);
|
1515
|
-
return true;
|
1516
|
-
}
|
1517
|
-
}
|
1518
|
-
return false;
|
1519
|
-
});
|
1520
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1521
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1419
|
+
const totalGas = inputs.reduce((total, input) => {
|
1522
1420
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1523
1421
|
return total.add(
|
1524
|
-
|
1422
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1525
1423
|
);
|
1526
1424
|
}
|
1527
|
-
|
1528
|
-
|
1425
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1426
|
+
witnessCache.push(input.witnessIndex);
|
1427
|
+
return total.add(gasCosts.ecr1);
|
1428
|
+
}
|
1429
|
+
return total;
|
1430
|
+
}, bn5());
|
1529
1431
|
return totalGas;
|
1530
1432
|
}
|
1531
1433
|
function getMinGas(params) {
|
@@ -1537,20 +1439,12 @@ function getMinGas(params) {
|
|
1537
1439
|
return minGas;
|
1538
1440
|
}
|
1539
1441
|
function getMaxGas(params) {
|
1540
|
-
const {
|
1541
|
-
gasPerByte,
|
1542
|
-
witnessesLength,
|
1543
|
-
witnessLimit,
|
1544
|
-
minGas,
|
1545
|
-
gasLimit = bn5(0),
|
1546
|
-
maxGasPerTx
|
1547
|
-
} = params;
|
1442
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1548
1443
|
let remainingAllowedWitnessGas = bn5(0);
|
1549
1444
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1550
1445
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1551
1446
|
}
|
1552
|
-
|
1553
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1447
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1554
1448
|
}
|
1555
1449
|
function calculateMetadataGasForTxCreate({
|
1556
1450
|
gasCosts,
|
@@ -1572,10 +1466,6 @@ function calculateMetadataGasForTxScript({
|
|
1572
1466
|
}) {
|
1573
1467
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1574
1468
|
}
|
1575
|
-
var calculateGasFee = (params) => {
|
1576
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1577
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1578
|
-
};
|
1579
1469
|
|
1580
1470
|
// src/providers/utils/json.ts
|
1581
1471
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1720,7 +1610,7 @@ var witnessify = (value) => {
|
|
1720
1610
|
// src/providers/transaction-request/transaction-request.ts
|
1721
1611
|
var BaseTransactionRequest = class {
|
1722
1612
|
/** Gas price for transaction */
|
1723
|
-
|
1613
|
+
gasPrice;
|
1724
1614
|
/** Block until which tx cannot be included */
|
1725
1615
|
maturity;
|
1726
1616
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1739,7 +1629,7 @@ var BaseTransactionRequest = class {
|
|
1739
1629
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1740
1630
|
*/
|
1741
1631
|
constructor({
|
1742
|
-
|
1632
|
+
gasPrice,
|
1743
1633
|
maturity,
|
1744
1634
|
maxFee,
|
1745
1635
|
witnessLimit,
|
@@ -1747,7 +1637,7 @@ var BaseTransactionRequest = class {
|
|
1747
1637
|
outputs,
|
1748
1638
|
witnesses
|
1749
1639
|
} = {}) {
|
1750
|
-
this.
|
1640
|
+
this.gasPrice = bn7(gasPrice);
|
1751
1641
|
this.maturity = maturity ?? 0;
|
1752
1642
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1753
1643
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1758,9 +1648,9 @@ var BaseTransactionRequest = class {
|
|
1758
1648
|
static getPolicyMeta(req) {
|
1759
1649
|
let policyTypes = 0;
|
1760
1650
|
const policies = [];
|
1761
|
-
if (req.
|
1762
|
-
policyTypes += PolicyType.
|
1763
|
-
policies.push({ data: req.
|
1651
|
+
if (req.gasPrice) {
|
1652
|
+
policyTypes += PolicyType.GasPrice;
|
1653
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1764
1654
|
}
|
1765
1655
|
if (req.witnessLimit) {
|
1766
1656
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1944,11 +1834,13 @@ var BaseTransactionRequest = class {
|
|
1944
1834
|
* assetId, if one it was not added yet.
|
1945
1835
|
*
|
1946
1836
|
* @param coin - Coin resource.
|
1837
|
+
* @param predicate - Predicate bytes.
|
1838
|
+
* @param predicateData - Predicate data bytes.
|
1947
1839
|
*/
|
1948
|
-
addCoinInput(coin) {
|
1840
|
+
addCoinInput(coin, predicate) {
|
1949
1841
|
const { assetId, owner, amount } = coin;
|
1950
1842
|
let witnessIndex;
|
1951
|
-
if (
|
1843
|
+
if (predicate) {
|
1952
1844
|
witnessIndex = 0;
|
1953
1845
|
} else {
|
1954
1846
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1963,7 +1855,8 @@ var BaseTransactionRequest = class {
|
|
1963
1855
|
amount,
|
1964
1856
|
assetId,
|
1965
1857
|
txPointer: "0x00000000000000000000000000000000",
|
1966
|
-
witnessIndex
|
1858
|
+
witnessIndex,
|
1859
|
+
predicate: predicate?.bytes
|
1967
1860
|
};
|
1968
1861
|
this.pushInput(input);
|
1969
1862
|
this.addChangeOutput(owner, assetId);
|
@@ -1973,12 +1866,14 @@ var BaseTransactionRequest = class {
|
|
1973
1866
|
* baseAssetId, if one it was not added yet.
|
1974
1867
|
*
|
1975
1868
|
* @param message - Message resource.
|
1869
|
+
* @param predicate - Predicate bytes.
|
1870
|
+
* @param predicateData - Predicate data bytes.
|
1976
1871
|
*/
|
1977
|
-
addMessageInput(message) {
|
1872
|
+
addMessageInput(message, predicate) {
|
1978
1873
|
const { recipient, sender, amount } = message;
|
1979
1874
|
const assetId = BaseAssetId2;
|
1980
1875
|
let witnessIndex;
|
1981
|
-
if (
|
1876
|
+
if (predicate) {
|
1982
1877
|
witnessIndex = 0;
|
1983
1878
|
} else {
|
1984
1879
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1992,7 +1887,8 @@ var BaseTransactionRequest = class {
|
|
1992
1887
|
sender: sender.toB256(),
|
1993
1888
|
recipient: recipient.toB256(),
|
1994
1889
|
amount,
|
1995
|
-
witnessIndex
|
1890
|
+
witnessIndex,
|
1891
|
+
predicate: predicate?.bytes
|
1996
1892
|
};
|
1997
1893
|
this.pushInput(input);
|
1998
1894
|
this.addChangeOutput(recipient, assetId);
|
@@ -2023,6 +1919,32 @@ var BaseTransactionRequest = class {
|
|
2023
1919
|
resources.forEach((resource) => this.addResource(resource));
|
2024
1920
|
return this;
|
2025
1921
|
}
|
1922
|
+
/**
|
1923
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1924
|
+
* outputs from the related assetIds.
|
1925
|
+
*
|
1926
|
+
* @param resources - The resources to add.
|
1927
|
+
* @returns This transaction.
|
1928
|
+
*/
|
1929
|
+
addPredicateResource(resource, predicate) {
|
1930
|
+
if (isCoin(resource)) {
|
1931
|
+
this.addCoinInput(resource, predicate);
|
1932
|
+
} else {
|
1933
|
+
this.addMessageInput(resource, predicate);
|
1934
|
+
}
|
1935
|
+
return this;
|
1936
|
+
}
|
1937
|
+
/**
|
1938
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1939
|
+
* from the related assetIds.
|
1940
|
+
*
|
1941
|
+
* @param resources - The resources to add.
|
1942
|
+
* @returns This transaction.
|
1943
|
+
*/
|
1944
|
+
addPredicateResources(resources, predicate) {
|
1945
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1946
|
+
return this;
|
1947
|
+
}
|
2026
1948
|
/**
|
2027
1949
|
* Adds a coin output to the transaction.
|
2028
1950
|
*
|
@@ -2102,7 +2024,7 @@ var BaseTransactionRequest = class {
|
|
2102
2024
|
}
|
2103
2025
|
calculateMaxGas(chainInfo, minGas) {
|
2104
2026
|
const { consensusParameters } = chainInfo;
|
2105
|
-
const { gasPerByte
|
2027
|
+
const { gasPerByte } = consensusParameters;
|
2106
2028
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2107
2029
|
(acc, wit) => acc + wit.dataLength,
|
2108
2030
|
0
|
@@ -2111,8 +2033,7 @@ var BaseTransactionRequest = class {
|
|
2111
2033
|
gasPerByte,
|
2112
2034
|
minGas,
|
2113
2035
|
witnessesLength,
|
2114
|
-
witnessLimit: this.witnessLimit
|
2115
|
-
maxGasPerTx
|
2036
|
+
witnessLimit: this.witnessLimit
|
2116
2037
|
});
|
2117
2038
|
}
|
2118
2039
|
/**
|
@@ -2130,20 +2051,17 @@ var BaseTransactionRequest = class {
|
|
2130
2051
|
});
|
2131
2052
|
const updateAssetInput = (assetId, quantity) => {
|
2132
2053
|
const assetInput = findAssetInput(assetId);
|
2133
|
-
let usedQuantity = quantity;
|
2134
|
-
if (assetId === BaseAssetId2) {
|
2135
|
-
usedQuantity = bn7("1000000000000000000");
|
2136
|
-
}
|
2137
2054
|
if (assetInput && "assetId" in assetInput) {
|
2138
2055
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2139
|
-
assetInput.amount =
|
2056
|
+
assetInput.amount = quantity;
|
2140
2057
|
} else {
|
2141
2058
|
this.addResources([
|
2142
2059
|
{
|
2143
2060
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2144
|
-
amount:
|
2061
|
+
amount: quantity,
|
2145
2062
|
assetId,
|
2146
2063
|
owner: resourcesOwner || Address.fromRandom(),
|
2064
|
+
maturity: 0,
|
2147
2065
|
blockCreated: bn7(1),
|
2148
2066
|
txCreatedIdx: bn7(1)
|
2149
2067
|
}
|
@@ -2175,7 +2093,7 @@ var BaseTransactionRequest = class {
|
|
2175
2093
|
toJSON() {
|
2176
2094
|
return normalizeJSON(this);
|
2177
2095
|
}
|
2178
|
-
|
2096
|
+
updatePredicateInputs(inputs) {
|
2179
2097
|
this.inputs.forEach((i) => {
|
2180
2098
|
let correspondingInput;
|
2181
2099
|
switch (i.type) {
|
@@ -2197,15 +2115,6 @@ var BaseTransactionRequest = class {
|
|
2197
2115
|
}
|
2198
2116
|
});
|
2199
2117
|
}
|
2200
|
-
shiftPredicateData() {
|
2201
|
-
this.inputs.forEach((input) => {
|
2202
|
-
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2203
|
-
input.predicateData = input.padPredicateData(
|
2204
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2205
|
-
);
|
2206
|
-
}
|
2207
|
-
});
|
2208
|
-
}
|
2209
2118
|
};
|
2210
2119
|
|
2211
2120
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2352,8 +2261,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2352
2261
|
return {
|
2353
2262
|
type: TransactionType3.Create,
|
2354
2263
|
...baseTransaction,
|
2264
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2355
2265
|
bytecodeWitnessIndex,
|
2356
|
-
storageSlotsCount:
|
2266
|
+
storageSlotsCount: storageSlots.length,
|
2357
2267
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2358
2268
|
storageSlots
|
2359
2269
|
};
|
@@ -2476,8 +2386,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2476
2386
|
type: TransactionType4.Script,
|
2477
2387
|
scriptGasLimit: this.gasLimit,
|
2478
2388
|
...super.getBaseTransaction(),
|
2479
|
-
scriptLength:
|
2480
|
-
scriptDataLength:
|
2389
|
+
scriptLength: script.length,
|
2390
|
+
scriptDataLength: scriptData.length,
|
2481
2391
|
receiptsRoot: ZeroBytes327,
|
2482
2392
|
script: hexlify10(script),
|
2483
2393
|
scriptData: hexlify10(scriptData)
|
@@ -2541,7 +2451,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2541
2451
|
}
|
2542
2452
|
calculateMaxGas(chainInfo, minGas) {
|
2543
2453
|
const { consensusParameters } = chainInfo;
|
2544
|
-
const { gasPerByte
|
2454
|
+
const { gasPerByte } = consensusParameters;
|
2545
2455
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2546
2456
|
(acc, wit) => acc + wit.dataLength,
|
2547
2457
|
0
|
@@ -2551,8 +2461,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2551
2461
|
minGas,
|
2552
2462
|
witnessesLength,
|
2553
2463
|
witnessLimit: this.witnessLimit,
|
2554
|
-
gasLimit: this.gasLimit
|
2555
|
-
maxGasPerTx
|
2464
|
+
gasLimit: this.gasLimit
|
2556
2465
|
});
|
2557
2466
|
}
|
2558
2467
|
/**
|
@@ -2609,7 +2518,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2609
2518
|
|
2610
2519
|
// src/providers/transaction-request/utils.ts
|
2611
2520
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2612
|
-
import { TransactionType as TransactionType5
|
2521
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2613
2522
|
var transactionRequestify = (obj) => {
|
2614
2523
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2615
2524
|
return obj;
|
@@ -2627,31 +2536,14 @@ var transactionRequestify = (obj) => {
|
|
2627
2536
|
}
|
2628
2537
|
}
|
2629
2538
|
};
|
2630
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2631
|
-
(acc, input) => {
|
2632
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2633
|
-
acc.utxos.push(input.id);
|
2634
|
-
}
|
2635
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2636
|
-
acc.messages.push(input.nonce);
|
2637
|
-
}
|
2638
|
-
return acc;
|
2639
|
-
},
|
2640
|
-
{
|
2641
|
-
utxos: [],
|
2642
|
-
messages: []
|
2643
|
-
}
|
2644
|
-
);
|
2645
2539
|
|
2646
2540
|
// src/providers/transaction-response/transaction-response.ts
|
2647
2541
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2648
|
-
import { bn as
|
2542
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2649
2543
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2650
2544
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2651
2545
|
|
2652
2546
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2653
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2654
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2655
2547
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2656
2548
|
|
2657
2549
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2660,10 +2552,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2660
2552
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2661
2553
|
var calculateTransactionFee = (params) => {
|
2662
2554
|
const {
|
2663
|
-
|
2555
|
+
gasUsed,
|
2664
2556
|
rawPayload,
|
2665
|
-
|
2666
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2557
|
+
consensusParameters: { gasCosts, feeParams }
|
2667
2558
|
} = params;
|
2668
2559
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2669
2560
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2673,7 +2564,8 @@ var calculateTransactionFee = (params) => {
|
|
2673
2564
|
return {
|
2674
2565
|
fee: bn11(0),
|
2675
2566
|
minFee: bn11(0),
|
2676
|
-
maxFee: bn11(0)
|
2567
|
+
maxFee: bn11(0),
|
2568
|
+
feeFromGasUsed: bn11(0)
|
2677
2569
|
};
|
2678
2570
|
}
|
2679
2571
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2705,6 +2597,7 @@ var calculateTransactionFee = (params) => {
|
|
2705
2597
|
metadataGas,
|
2706
2598
|
txBytesSize: transactionBytes.length
|
2707
2599
|
});
|
2600
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2708
2601
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2709
2602
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2710
2603
|
const maxGas = getMaxGas({
|
@@ -2712,25 +2605,17 @@ var calculateTransactionFee = (params) => {
|
|
2712
2605
|
minGas,
|
2713
2606
|
witnessesLength,
|
2714
2607
|
gasLimit,
|
2715
|
-
witnessLimit
|
2716
|
-
maxGasPerTx
|
2717
|
-
});
|
2718
|
-
const minFee = calculateGasFee({
|
2719
|
-
gasPrice,
|
2720
|
-
gas: minGas,
|
2721
|
-
priceFactor: gasPriceFactor,
|
2722
|
-
tip
|
2723
|
-
});
|
2724
|
-
const maxFee = calculateGasFee({
|
2725
|
-
gasPrice,
|
2726
|
-
gas: maxGas,
|
2727
|
-
priceFactor: gasPriceFactor,
|
2728
|
-
tip
|
2608
|
+
witnessLimit
|
2729
2609
|
});
|
2610
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2611
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2612
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2613
|
+
const fee = minFee.add(feeFromGasUsed);
|
2730
2614
|
return {
|
2615
|
+
fee,
|
2731
2616
|
minFee,
|
2732
2617
|
maxFee,
|
2733
|
-
|
2618
|
+
feeFromGasUsed
|
2734
2619
|
};
|
2735
2620
|
};
|
2736
2621
|
|
@@ -2786,7 +2671,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2786
2671
|
|
2787
2672
|
// src/providers/transaction-summary/input.ts
|
2788
2673
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2789
|
-
import { InputType as
|
2674
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2790
2675
|
function getInputsByTypes(inputs, types) {
|
2791
2676
|
return inputs.filter((i) => types.includes(i.type));
|
2792
2677
|
}
|
@@ -2794,16 +2679,16 @@ function getInputsByType(inputs, type) {
|
|
2794
2679
|
return inputs.filter((i) => i.type === type);
|
2795
2680
|
}
|
2796
2681
|
function getInputsCoin(inputs) {
|
2797
|
-
return getInputsByType(inputs,
|
2682
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2798
2683
|
}
|
2799
2684
|
function getInputsMessage(inputs) {
|
2800
|
-
return getInputsByType(inputs,
|
2685
|
+
return getInputsByType(inputs, InputType5.Message);
|
2801
2686
|
}
|
2802
2687
|
function getInputsCoinAndMessage(inputs) {
|
2803
|
-
return getInputsByTypes(inputs, [
|
2688
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2804
2689
|
}
|
2805
2690
|
function getInputsContract(inputs) {
|
2806
|
-
return getInputsByType(inputs,
|
2691
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2807
2692
|
}
|
2808
2693
|
function getInputFromAssetId(inputs, assetId) {
|
2809
2694
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2822,7 +2707,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2822
2707
|
if (!contractInput) {
|
2823
2708
|
return void 0;
|
2824
2709
|
}
|
2825
|
-
if (contractInput.type !==
|
2710
|
+
if (contractInput.type !== InputType5.Contract) {
|
2826
2711
|
throw new FuelError9(
|
2827
2712
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2828
2713
|
`Contract input should be of type 'contract'.`
|
@@ -2831,10 +2716,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2831
2716
|
return contractInput;
|
2832
2717
|
}
|
2833
2718
|
function getInputAccountAddress(input) {
|
2834
|
-
if (input.type ===
|
2719
|
+
if (input.type === InputType5.Coin) {
|
2835
2720
|
return input.owner.toString();
|
2836
2721
|
}
|
2837
|
-
if (input.type ===
|
2722
|
+
if (input.type === InputType5.Message) {
|
2838
2723
|
return input.recipient.toString();
|
2839
2724
|
}
|
2840
2725
|
return "";
|
@@ -3297,9 +3182,7 @@ function assembleTransactionSummary(params) {
|
|
3297
3182
|
gqlTransactionStatus,
|
3298
3183
|
abiMap = {},
|
3299
3184
|
maxInputs,
|
3300
|
-
gasCosts
|
3301
|
-
maxGasPerTx,
|
3302
|
-
gasPrice
|
3185
|
+
gasCosts
|
3303
3186
|
} = params;
|
3304
3187
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3305
3188
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3313,14 +3196,11 @@ function assembleTransactionSummary(params) {
|
|
3313
3196
|
maxInputs
|
3314
3197
|
});
|
3315
3198
|
const typeName = getTransactionTypeName(transaction.type);
|
3316
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3317
3199
|
const { fee } = calculateTransactionFee({
|
3318
|
-
|
3200
|
+
gasUsed,
|
3319
3201
|
rawPayload,
|
3320
|
-
tip,
|
3321
3202
|
consensusParameters: {
|
3322
3203
|
gasCosts,
|
3323
|
-
maxGasPerTx,
|
3324
3204
|
feeParams: {
|
3325
3205
|
gasPerByte,
|
3326
3206
|
gasPriceFactor
|
@@ -3380,7 +3260,7 @@ var TransactionResponse = class {
|
|
3380
3260
|
/** Current provider */
|
3381
3261
|
provider;
|
3382
3262
|
/** Gas used on the transaction */
|
3383
|
-
gasUsed =
|
3263
|
+
gasUsed = bn14(0);
|
3384
3264
|
/** The graphql Transaction with receipts object. */
|
3385
3265
|
gqlTransaction;
|
3386
3266
|
abis;
|
@@ -3458,13 +3338,8 @@ var TransactionResponse = class {
|
|
3458
3338
|
const decodedTransaction = this.decodeTransaction(
|
3459
3339
|
transaction
|
3460
3340
|
);
|
3461
|
-
|
3462
|
-
|
3463
|
-
txReceipts = transaction.status.receipts;
|
3464
|
-
}
|
3465
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3466
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3467
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3341
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3342
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3468
3343
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3469
3344
|
const transactionSummary = assembleTransactionSummary({
|
3470
3345
|
id: this.id,
|
@@ -3476,9 +3351,7 @@ var TransactionResponse = class {
|
|
3476
3351
|
gasPriceFactor,
|
3477
3352
|
abiMap: contractsAbiMap,
|
3478
3353
|
maxInputs,
|
3479
|
-
gasCosts
|
3480
|
-
maxGasPerTx,
|
3481
|
-
gasPrice
|
3354
|
+
gasCosts
|
3482
3355
|
});
|
3483
3356
|
return transactionSummary;
|
3484
3357
|
}
|
@@ -3605,29 +3478,29 @@ var processGqlChain = (chain) => {
|
|
3605
3478
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3606
3479
|
return {
|
3607
3480
|
name,
|
3608
|
-
baseChainHeight:
|
3481
|
+
baseChainHeight: bn15(daHeight),
|
3609
3482
|
consensusParameters: {
|
3610
|
-
contractMaxSize:
|
3611
|
-
maxInputs:
|
3612
|
-
maxOutputs:
|
3613
|
-
maxWitnesses:
|
3614
|
-
maxGasPerTx:
|
3615
|
-
maxScriptLength:
|
3616
|
-
maxScriptDataLength:
|
3617
|
-
maxStorageSlots:
|
3618
|
-
maxPredicateLength:
|
3619
|
-
maxPredicateDataLength:
|
3620
|
-
maxGasPerPredicate:
|
3621
|
-
gasPriceFactor:
|
3622
|
-
gasPerByte:
|
3623
|
-
maxMessageDataLength:
|
3624
|
-
chainId:
|
3483
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3484
|
+
maxInputs: bn15(txParams.maxInputs),
|
3485
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3486
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3487
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3488
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3489
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3490
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3491
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3492
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3493
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3494
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3495
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3496
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3497
|
+
chainId: bn15(consensusParameters.chainId),
|
3625
3498
|
gasCosts
|
3626
3499
|
},
|
3627
3500
|
gasCosts,
|
3628
3501
|
latestBlock: {
|
3629
3502
|
id: latestBlock.id,
|
3630
|
-
height:
|
3503
|
+
height: bn15(latestBlock.header.height),
|
3631
3504
|
time: latestBlock.header.time,
|
3632
3505
|
transactions: latestBlock.transactions.map((i) => ({
|
3633
3506
|
id: i.id
|
@@ -3721,8 +3594,10 @@ var _Provider = class {
|
|
3721
3594
|
* Returns some helpful parameters related to gas fees.
|
3722
3595
|
*/
|
3723
3596
|
getGasConfig() {
|
3597
|
+
const { minGasPrice } = this.getNode();
|
3724
3598
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3725
3599
|
return {
|
3600
|
+
minGasPrice,
|
3726
3601
|
maxGasPerTx,
|
3727
3602
|
maxGasPerPredicate,
|
3728
3603
|
gasPriceFactor,
|
@@ -3820,7 +3695,7 @@ var _Provider = class {
|
|
3820
3695
|
*/
|
3821
3696
|
async getBlockNumber() {
|
3822
3697
|
const { chain } = await this.operations.getChain();
|
3823
|
-
return
|
3698
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3824
3699
|
}
|
3825
3700
|
/**
|
3826
3701
|
* Returns the chain information.
|
@@ -3830,11 +3705,13 @@ var _Provider = class {
|
|
3830
3705
|
async fetchNode() {
|
3831
3706
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3832
3707
|
const processedNodeInfo = {
|
3833
|
-
maxDepth:
|
3834
|
-
maxTx:
|
3708
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3709
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3710
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3835
3711
|
nodeVersion: nodeInfo.nodeVersion,
|
3836
3712
|
utxoValidation: nodeInfo.utxoValidation,
|
3837
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3713
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3714
|
+
peers: nodeInfo.peers
|
3838
3715
|
};
|
3839
3716
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3840
3717
|
return processedNodeInfo;
|
@@ -3920,13 +3797,14 @@ var _Provider = class {
|
|
3920
3797
|
return this.estimateTxDependencies(transactionRequest);
|
3921
3798
|
}
|
3922
3799
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3923
|
-
const { dryRun:
|
3924
|
-
|
3800
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3801
|
+
encodedTransaction,
|
3925
3802
|
utxoValidation: utxoValidation || false
|
3926
3803
|
});
|
3927
|
-
const
|
3928
|
-
|
3929
|
-
|
3804
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3805
|
+
return {
|
3806
|
+
receipts
|
3807
|
+
};
|
3930
3808
|
}
|
3931
3809
|
/**
|
3932
3810
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3952,7 +3830,7 @@ var _Provider = class {
|
|
3952
3830
|
} = response;
|
3953
3831
|
if (inputs) {
|
3954
3832
|
inputs.forEach((input, index) => {
|
3955
|
-
if ("predicateGasUsed" in input &&
|
3833
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3956
3834
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3957
3835
|
}
|
3958
3836
|
});
|
@@ -3965,6 +3843,9 @@ var _Provider = class {
|
|
3965
3843
|
* If there are missing variable outputs,
|
3966
3844
|
* `addVariableOutputs` is called on the transaction.
|
3967
3845
|
*
|
3846
|
+
* @privateRemarks
|
3847
|
+
* TODO: Investigate support for missing contract IDs
|
3848
|
+
* TODO: Add support for missing output messages
|
3968
3849
|
*
|
3969
3850
|
* @param transactionRequest - The transaction request object.
|
3970
3851
|
* @returns A promise.
|
@@ -3977,19 +3858,16 @@ var _Provider = class {
|
|
3977
3858
|
missingContractIds: []
|
3978
3859
|
};
|
3979
3860
|
}
|
3861
|
+
await this.estimatePredicates(transactionRequest);
|
3980
3862
|
let receipts = [];
|
3981
3863
|
const missingContractIds = [];
|
3982
3864
|
let outputVariables = 0;
|
3983
|
-
let dryrunStatus;
|
3984
3865
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3985
|
-
const {
|
3986
|
-
|
3987
|
-
} = await this.operations.dryRun({
|
3988
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3866
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3867
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3989
3868
|
utxoValidation: false
|
3990
3869
|
});
|
3991
|
-
receipts =
|
3992
|
-
dryrunStatus = status;
|
3870
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3993
3871
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3994
3872
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3995
3873
|
if (hasMissingOutputs) {
|
@@ -3999,10 +3877,6 @@ var _Provider = class {
|
|
3999
3877
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
4000
3878
|
missingContractIds.push(contractId);
|
4001
3879
|
});
|
4002
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4003
|
-
transactionRequest
|
4004
|
-
});
|
4005
|
-
transactionRequest.maxFee = maxFee;
|
4006
3880
|
} else {
|
4007
3881
|
break;
|
4008
3882
|
}
|
@@ -4010,139 +3884,37 @@ var _Provider = class {
|
|
4010
3884
|
return {
|
4011
3885
|
receipts,
|
4012
3886
|
outputVariables,
|
4013
|
-
missingContractIds
|
4014
|
-
dryrunStatus
|
3887
|
+
missingContractIds
|
4015
3888
|
};
|
4016
3889
|
}
|
4017
|
-
/**
|
4018
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4019
|
-
*
|
4020
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4021
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4022
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4023
|
-
*
|
4024
|
-
* @param transactionRequests - Array of transaction request objects.
|
4025
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4026
|
-
*/
|
4027
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4028
|
-
const results = transactionRequests.map(() => ({
|
4029
|
-
receipts: [],
|
4030
|
-
outputVariables: 0,
|
4031
|
-
missingContractIds: [],
|
4032
|
-
dryrunStatus: void 0
|
4033
|
-
}));
|
4034
|
-
const allRequests = clone3(transactionRequests);
|
4035
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4036
|
-
allRequests.forEach((req, index) => {
|
4037
|
-
if (req.type === TransactionType8.Script) {
|
4038
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4039
|
-
}
|
4040
|
-
});
|
4041
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4042
|
-
let attempt = 0;
|
4043
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4044
|
-
const encodedTransactions = transactionsToProcess.map(
|
4045
|
-
(index) => serializedTransactionsMap.get(index)
|
4046
|
-
);
|
4047
|
-
const dryRunResults = await this.operations.dryRun({
|
4048
|
-
encodedTransactions,
|
4049
|
-
utxoValidation: false
|
4050
|
-
});
|
4051
|
-
const nextRoundTransactions = [];
|
4052
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4053
|
-
const currentResultIndex = transactionsToProcess[i];
|
4054
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4055
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4056
|
-
results[currentResultIndex].dryrunStatus = status;
|
4057
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4058
|
-
results[currentResultIndex].receipts
|
4059
|
-
);
|
4060
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4061
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4062
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4063
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4064
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4065
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4066
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4067
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4068
|
-
});
|
4069
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4070
|
-
transactionRequest: requestToProcess
|
4071
|
-
});
|
4072
|
-
requestToProcess.maxFee = maxFee;
|
4073
|
-
serializedTransactionsMap.set(
|
4074
|
-
currentResultIndex,
|
4075
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4076
|
-
);
|
4077
|
-
nextRoundTransactions.push(currentResultIndex);
|
4078
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4079
|
-
}
|
4080
|
-
}
|
4081
|
-
transactionsToProcess = nextRoundTransactions;
|
4082
|
-
attempt += 1;
|
4083
|
-
}
|
4084
|
-
return results;
|
4085
|
-
}
|
4086
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4087
|
-
if (estimateTxDependencies) {
|
4088
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4089
|
-
}
|
4090
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4091
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4092
|
-
encodedTransactions,
|
4093
|
-
utxoValidation: utxoValidation || false
|
4094
|
-
});
|
4095
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4096
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4097
|
-
return { receipts, dryrunStatus: status };
|
4098
|
-
});
|
4099
|
-
return results;
|
4100
|
-
}
|
4101
3890
|
/**
|
4102
3891
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4103
3892
|
* @param transactionRequest - The transaction request object.
|
4104
3893
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4105
3894
|
*/
|
4106
|
-
|
3895
|
+
estimateTxGasAndFee(params) {
|
4107
3896
|
const { transactionRequest } = params;
|
4108
|
-
|
3897
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4109
3898
|
const chainInfo = this.getChain();
|
4110
|
-
const
|
3899
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3900
|
+
transactionRequest.gasPrice = gasPrice;
|
4111
3901
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4112
|
-
|
4113
|
-
gasPrice = await this.estimateGasPrice(10);
|
4114
|
-
}
|
4115
|
-
const minFee = calculateGasFee({
|
4116
|
-
gasPrice: bn16(gasPrice),
|
4117
|
-
gas: minGas,
|
4118
|
-
priceFactor: gasPriceFactor,
|
4119
|
-
tip: transactionRequest.tip
|
4120
|
-
}).add(1);
|
4121
|
-
let gasLimit = bn16(0);
|
3902
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4122
3903
|
if (transactionRequest.type === TransactionType8.Script) {
|
4123
|
-
gasLimit = transactionRequest.gasLimit;
|
4124
3904
|
if (transactionRequest.gasLimit.eq(0)) {
|
4125
3905
|
transactionRequest.gasLimit = minGas;
|
4126
3906
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4127
3907
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4128
3908
|
);
|
4129
|
-
gasLimit = transactionRequest.gasLimit;
|
4130
3909
|
}
|
4131
3910
|
}
|
4132
3911
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4133
|
-
const maxFee =
|
4134
|
-
gasPrice: bn16(gasPrice),
|
4135
|
-
gas: maxGas,
|
4136
|
-
priceFactor: gasPriceFactor,
|
4137
|
-
tip: transactionRequest.tip
|
4138
|
-
}).add(1);
|
3912
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4139
3913
|
return {
|
4140
3914
|
minGas,
|
4141
3915
|
minFee,
|
4142
3916
|
maxGas,
|
4143
|
-
maxFee
|
4144
|
-
gasPrice,
|
4145
|
-
gasLimit
|
3917
|
+
maxFee
|
4146
3918
|
};
|
4147
3919
|
}
|
4148
3920
|
/**
|
@@ -4160,17 +3932,15 @@ var _Provider = class {
|
|
4160
3932
|
if (estimateTxDependencies) {
|
4161
3933
|
return this.estimateTxDependencies(transactionRequest);
|
4162
3934
|
}
|
4163
|
-
const
|
4164
|
-
const { dryRun:
|
4165
|
-
|
3935
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3936
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3937
|
+
encodedTransaction,
|
4166
3938
|
utxoValidation: true
|
4167
3939
|
});
|
4168
|
-
const
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
});
|
4173
|
-
return { receipts: callResult[0].receipts };
|
3940
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3941
|
+
return {
|
3942
|
+
receipts
|
3943
|
+
};
|
4174
3944
|
}
|
4175
3945
|
/**
|
4176
3946
|
* Returns a transaction cost to enable user
|
@@ -4187,79 +3957,77 @@ var _Provider = class {
|
|
4187
3957
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4188
3958
|
* @returns A promise that resolves to the transaction cost object.
|
4189
3959
|
*/
|
4190
|
-
async getTransactionCost(transactionRequestLike,
|
3960
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3961
|
+
estimateTxDependencies = true,
|
3962
|
+
estimatePredicates = true,
|
3963
|
+
resourcesOwner,
|
3964
|
+
signatureCallback
|
3965
|
+
} = {}) {
|
4191
3966
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3967
|
+
const { minGasPrice } = this.getGasConfig();
|
3968
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4192
3969
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4193
3970
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4194
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3971
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4195
3972
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4196
|
-
txRequestClone.maxFee = bn16(0);
|
4197
3973
|
if (isScriptTransaction) {
|
4198
|
-
txRequestClone.gasLimit =
|
3974
|
+
txRequestClone.gasLimit = bn15(0);
|
4199
3975
|
}
|
4200
|
-
if (
|
4201
|
-
resourcesOwner
|
3976
|
+
if (estimatePredicates) {
|
3977
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3978
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3979
|
+
}
|
3980
|
+
await this.estimatePredicates(txRequestClone);
|
4202
3981
|
}
|
4203
|
-
const signedRequest = clone3(txRequestClone);
|
4204
|
-
let addedSignatures = 0;
|
4205
3982
|
if (signatureCallback && isScriptTransaction) {
|
4206
|
-
|
4207
|
-
await signatureCallback(signedRequest);
|
4208
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3983
|
+
await signatureCallback(txRequestClone);
|
4209
3984
|
}
|
4210
|
-
|
4211
|
-
|
4212
|
-
transactionRequest: signedRequest
|
3985
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3986
|
+
transactionRequest: txRequestClone
|
4213
3987
|
});
|
4214
3988
|
let receipts = [];
|
4215
3989
|
let missingContractIds = [];
|
4216
3990
|
let outputVariables = 0;
|
4217
|
-
let gasUsed =
|
4218
|
-
|
4219
|
-
|
4220
|
-
if (isScriptTransaction) {
|
4221
|
-
txRequestClone.gasLimit = gasLimit;
|
4222
|
-
if (signatureCallback) {
|
4223
|
-
await signatureCallback(txRequestClone);
|
4224
|
-
}
|
3991
|
+
let gasUsed = bn15(0);
|
3992
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3993
|
+
txRequestClone.gasPrice = bn15(0);
|
4225
3994
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4226
3995
|
receipts = result.receipts;
|
4227
3996
|
outputVariables = result.outputVariables;
|
4228
3997
|
missingContractIds = result.missingContractIds;
|
4229
3998
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4230
3999
|
txRequestClone.gasLimit = gasUsed;
|
4231
|
-
|
4232
|
-
|
4233
|
-
|
4000
|
+
txRequestClone.gasPrice = setGasPrice;
|
4001
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4002
|
+
transactionRequest: txRequestClone
|
4234
4003
|
}));
|
4235
4004
|
}
|
4236
4005
|
return {
|
4237
4006
|
requiredQuantities: allQuantities,
|
4238
4007
|
receipts,
|
4239
4008
|
gasUsed,
|
4240
|
-
|
4009
|
+
minGasPrice,
|
4010
|
+
gasPrice: setGasPrice,
|
4241
4011
|
minGas,
|
4242
4012
|
maxGas,
|
4243
4013
|
minFee,
|
4244
4014
|
maxFee,
|
4015
|
+
estimatedInputs: txRequestClone.inputs,
|
4245
4016
|
outputVariables,
|
4246
|
-
missingContractIds
|
4247
|
-
addedSignatures,
|
4248
|
-
estimatedPredicates: txRequestClone.inputs
|
4017
|
+
missingContractIds
|
4249
4018
|
};
|
4250
4019
|
}
|
4251
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4020
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4252
4021
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4253
4022
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4254
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4255
|
-
quantitiesToContract
|
4256
|
-
});
|
4023
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4257
4024
|
transactionRequest.addResources(
|
4258
4025
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4259
4026
|
);
|
4260
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4261
|
-
|
4262
|
-
|
4027
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4028
|
+
transactionRequest,
|
4029
|
+
forwardingQuantities
|
4030
|
+
);
|
4263
4031
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4264
4032
|
return {
|
4265
4033
|
resources,
|
@@ -4281,10 +4049,11 @@ var _Provider = class {
|
|
4281
4049
|
return coins.map((coin) => ({
|
4282
4050
|
id: coin.utxoId,
|
4283
4051
|
assetId: coin.assetId,
|
4284
|
-
amount:
|
4052
|
+
amount: bn15(coin.amount),
|
4285
4053
|
owner: Address2.fromAddressOrString(coin.owner),
|
4286
|
-
|
4287
|
-
|
4054
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4055
|
+
blockCreated: bn15(coin.blockCreated),
|
4056
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4288
4057
|
}));
|
4289
4058
|
}
|
4290
4059
|
/**
|
@@ -4321,9 +4090,9 @@ var _Provider = class {
|
|
4321
4090
|
switch (coin.__typename) {
|
4322
4091
|
case "MessageCoin":
|
4323
4092
|
return {
|
4324
|
-
amount:
|
4093
|
+
amount: bn15(coin.amount),
|
4325
4094
|
assetId: coin.assetId,
|
4326
|
-
daHeight:
|
4095
|
+
daHeight: bn15(coin.daHeight),
|
4327
4096
|
sender: Address2.fromAddressOrString(coin.sender),
|
4328
4097
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4329
4098
|
nonce: coin.nonce
|
@@ -4331,11 +4100,12 @@ var _Provider = class {
|
|
4331
4100
|
case "Coin":
|
4332
4101
|
return {
|
4333
4102
|
id: coin.utxoId,
|
4334
|
-
amount:
|
4103
|
+
amount: bn15(coin.amount),
|
4335
4104
|
assetId: coin.assetId,
|
4336
4105
|
owner: Address2.fromAddressOrString(coin.owner),
|
4337
|
-
|
4338
|
-
|
4106
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4107
|
+
blockCreated: bn15(coin.blockCreated),
|
4108
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4339
4109
|
};
|
4340
4110
|
default:
|
4341
4111
|
return null;
|
@@ -4352,13 +4122,13 @@ var _Provider = class {
|
|
4352
4122
|
async getBlock(idOrHeight) {
|
4353
4123
|
let variables;
|
4354
4124
|
if (typeof idOrHeight === "number") {
|
4355
|
-
variables = { height:
|
4125
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4356
4126
|
} else if (idOrHeight === "latest") {
|
4357
4127
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4358
4128
|
} else if (idOrHeight.length === 66) {
|
4359
4129
|
variables = { blockId: idOrHeight };
|
4360
4130
|
} else {
|
4361
|
-
variables = { blockId:
|
4131
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4362
4132
|
}
|
4363
4133
|
const { block } = await this.operations.getBlock(variables);
|
4364
4134
|
if (!block) {
|
@@ -4366,7 +4136,7 @@ var _Provider = class {
|
|
4366
4136
|
}
|
4367
4137
|
return {
|
4368
4138
|
id: block.id,
|
4369
|
-
height:
|
4139
|
+
height: bn15(block.header.height),
|
4370
4140
|
time: block.header.time,
|
4371
4141
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4372
4142
|
};
|
@@ -4381,7 +4151,7 @@ var _Provider = class {
|
|
4381
4151
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4382
4152
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4383
4153
|
id: block.id,
|
4384
|
-
height:
|
4154
|
+
height: bn15(block.header.height),
|
4385
4155
|
time: block.header.time,
|
4386
4156
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4387
4157
|
}));
|
@@ -4396,7 +4166,7 @@ var _Provider = class {
|
|
4396
4166
|
async getBlockWithTransactions(idOrHeight) {
|
4397
4167
|
let variables;
|
4398
4168
|
if (typeof idOrHeight === "number") {
|
4399
|
-
variables = { blockHeight:
|
4169
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4400
4170
|
} else if (idOrHeight === "latest") {
|
4401
4171
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4402
4172
|
} else {
|
@@ -4408,7 +4178,7 @@ var _Provider = class {
|
|
4408
4178
|
}
|
4409
4179
|
return {
|
4410
4180
|
id: block.id,
|
4411
|
-
height:
|
4181
|
+
height: bn15(block.header.height, 10),
|
4412
4182
|
time: block.header.time,
|
4413
4183
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4414
4184
|
transactions: block.transactions.map(
|
@@ -4457,7 +4227,7 @@ var _Provider = class {
|
|
4457
4227
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4458
4228
|
asset: hexlify12(assetId)
|
4459
4229
|
});
|
4460
|
-
return
|
4230
|
+
return bn15(contractBalance.amount, 10);
|
4461
4231
|
}
|
4462
4232
|
/**
|
4463
4233
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4471,7 +4241,7 @@ var _Provider = class {
|
|
4471
4241
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4472
4242
|
assetId: hexlify12(assetId)
|
4473
4243
|
});
|
4474
|
-
return
|
4244
|
+
return bn15(balance.amount, 10);
|
4475
4245
|
}
|
4476
4246
|
/**
|
4477
4247
|
* Returns balances for the given owner.
|
@@ -4489,7 +4259,7 @@ var _Provider = class {
|
|
4489
4259
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4490
4260
|
return balances.map((balance) => ({
|
4491
4261
|
assetId: balance.assetId,
|
4492
|
-
amount:
|
4262
|
+
amount: bn15(balance.amount)
|
4493
4263
|
}));
|
4494
4264
|
}
|
4495
4265
|
/**
|
@@ -4511,15 +4281,15 @@ var _Provider = class {
|
|
4511
4281
|
sender: message.sender,
|
4512
4282
|
recipient: message.recipient,
|
4513
4283
|
nonce: message.nonce,
|
4514
|
-
amount:
|
4284
|
+
amount: bn15(message.amount),
|
4515
4285
|
data: message.data
|
4516
4286
|
}),
|
4517
4287
|
sender: Address2.fromAddressOrString(message.sender),
|
4518
4288
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4519
4289
|
nonce: message.nonce,
|
4520
|
-
amount:
|
4290
|
+
amount: bn15(message.amount),
|
4521
4291
|
data: InputMessageCoder.decodeData(message.data),
|
4522
|
-
daHeight:
|
4292
|
+
daHeight: bn15(message.daHeight)
|
4523
4293
|
}));
|
4524
4294
|
}
|
4525
4295
|
/**
|
@@ -4572,60 +4342,44 @@ var _Provider = class {
|
|
4572
4342
|
} = result.messageProof;
|
4573
4343
|
return {
|
4574
4344
|
messageProof: {
|
4575
|
-
proofIndex:
|
4345
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4576
4346
|
proofSet: messageProof.proofSet
|
4577
4347
|
},
|
4578
4348
|
blockProof: {
|
4579
|
-
proofIndex:
|
4349
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4580
4350
|
proofSet: blockProof.proofSet
|
4581
4351
|
},
|
4582
4352
|
messageBlockHeader: {
|
4583
4353
|
id: messageBlockHeader.id,
|
4584
|
-
daHeight:
|
4585
|
-
transactionsCount:
|
4354
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4355
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4586
4356
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4587
|
-
height:
|
4357
|
+
height: bn15(messageBlockHeader.height),
|
4588
4358
|
prevRoot: messageBlockHeader.prevRoot,
|
4589
4359
|
time: messageBlockHeader.time,
|
4590
4360
|
applicationHash: messageBlockHeader.applicationHash,
|
4591
|
-
|
4592
|
-
|
4593
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4594
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4595
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4361
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4362
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4596
4363
|
},
|
4597
4364
|
commitBlockHeader: {
|
4598
4365
|
id: commitBlockHeader.id,
|
4599
|
-
daHeight:
|
4600
|
-
transactionsCount:
|
4366
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4367
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4601
4368
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4602
|
-
height:
|
4369
|
+
height: bn15(commitBlockHeader.height),
|
4603
4370
|
prevRoot: commitBlockHeader.prevRoot,
|
4604
4371
|
time: commitBlockHeader.time,
|
4605
4372
|
applicationHash: commitBlockHeader.applicationHash,
|
4606
|
-
|
4607
|
-
|
4608
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4609
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4610
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4373
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4374
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4611
4375
|
},
|
4612
4376
|
sender: Address2.fromAddressOrString(sender),
|
4613
4377
|
recipient: Address2.fromAddressOrString(recipient),
|
4614
4378
|
nonce,
|
4615
|
-
amount:
|
4379
|
+
amount: bn15(amount),
|
4616
4380
|
data
|
4617
4381
|
};
|
4618
4382
|
}
|
4619
|
-
async getLatestGasPrice() {
|
4620
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4621
|
-
return bn16(latestGasPrice.gasPrice);
|
4622
|
-
}
|
4623
|
-
async estimateGasPrice(blockHorizon) {
|
4624
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4625
|
-
blockHorizon: String(blockHorizon)
|
4626
|
-
});
|
4627
|
-
return bn16(estimateGasPrice.gasPrice);
|
4628
|
-
}
|
4629
4383
|
/**
|
4630
4384
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4631
4385
|
*
|
@@ -4645,10 +4399,10 @@ var _Provider = class {
|
|
4645
4399
|
*/
|
4646
4400
|
async produceBlocks(amount, startTime) {
|
4647
4401
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4648
|
-
blocksToProduce:
|
4402
|
+
blocksToProduce: bn15(amount).toString(10),
|
4649
4403
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4650
4404
|
});
|
4651
|
-
return
|
4405
|
+
return bn15(latestBlockHeight);
|
4652
4406
|
}
|
4653
4407
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4654
4408
|
async getTransactionResponse(transactionId) {
|
@@ -4662,7 +4416,7 @@ cacheInputs_fn = function(inputs) {
|
|
4662
4416
|
return;
|
4663
4417
|
}
|
4664
4418
|
inputs.forEach((input) => {
|
4665
|
-
if (input.type ===
|
4419
|
+
if (input.type === InputType6.Coin) {
|
4666
4420
|
this.cache?.set(input.id);
|
4667
4421
|
}
|
4668
4422
|
});
|
@@ -4672,7 +4426,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4672
4426
|
|
4673
4427
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4674
4428
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4675
|
-
import { bn as
|
4429
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4676
4430
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4677
4431
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4678
4432
|
|
@@ -4918,33 +4672,36 @@ var Account = class extends AbstractAccount {
|
|
4918
4672
|
* @param fee - The estimated transaction fee.
|
4919
4673
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4920
4674
|
*/
|
4921
|
-
async fund(request,
|
4922
|
-
const
|
4923
|
-
|
4924
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4925
|
-
amount: bn18(fee),
|
4675
|
+
async fund(request, coinQuantities, fee) {
|
4676
|
+
const updatedQuantities = addAmountToAsset({
|
4677
|
+
amount: bn17(fee),
|
4926
4678
|
assetId: BaseAssetId3,
|
4927
|
-
coinQuantities
|
4679
|
+
coinQuantities
|
4928
4680
|
});
|
4929
4681
|
const quantitiesDict = {};
|
4930
|
-
|
4682
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4931
4683
|
quantitiesDict[assetId] = {
|
4932
4684
|
required: amount,
|
4933
|
-
owned:
|
4685
|
+
owned: bn17(0)
|
4934
4686
|
};
|
4935
4687
|
});
|
4936
|
-
|
4688
|
+
const cachedUtxos = [];
|
4689
|
+
const cachedMessages = [];
|
4690
|
+
const owner = this.address.toB256();
|
4691
|
+
request.inputs.forEach((input) => {
|
4937
4692
|
const isResource = "amount" in input;
|
4938
4693
|
if (isResource) {
|
4939
4694
|
const isCoin2 = "owner" in input;
|
4940
4695
|
if (isCoin2) {
|
4941
4696
|
const assetId = String(input.assetId);
|
4942
|
-
if (quantitiesDict[assetId]) {
|
4943
|
-
const amount =
|
4697
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4698
|
+
const amount = bn17(input.amount);
|
4944
4699
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4700
|
+
cachedUtxos.push(input.id);
|
4945
4701
|
}
|
4946
|
-
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4702
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4947
4703
|
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4704
|
+
cachedMessages.push(input.nonce);
|
4948
4705
|
}
|
4949
4706
|
}
|
4950
4707
|
});
|
@@ -4959,23 +4716,12 @@ var Account = class extends AbstractAccount {
|
|
4959
4716
|
});
|
4960
4717
|
const needsToBeFunded = missingQuantities.length;
|
4961
4718
|
if (needsToBeFunded) {
|
4962
|
-
const
|
4963
|
-
|
4964
|
-
|
4965
|
-
|
4966
|
-
|
4967
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4968
|
-
const requestToBeReEstimate = clone4(txRequest);
|
4969
|
-
if (addedSignatures) {
|
4970
|
-
Array.from({ length: addedSignatures }).forEach(
|
4971
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4972
|
-
);
|
4719
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4720
|
+
messages: cachedMessages,
|
4721
|
+
utxos: cachedUtxos
|
4722
|
+
});
|
4723
|
+
request.addResources(resources);
|
4973
4724
|
}
|
4974
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4975
|
-
transactionRequest: requestToBeReEstimate
|
4976
|
-
});
|
4977
|
-
txRequest.maxFee = maxFee;
|
4978
|
-
return txRequest;
|
4979
4725
|
}
|
4980
4726
|
/**
|
4981
4727
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4983,24 +4729,28 @@ var Account = class extends AbstractAccount {
|
|
4983
4729
|
* @param destination - The address of the destination.
|
4984
4730
|
* @param amount - The amount of coins to transfer.
|
4985
4731
|
* @param assetId - The asset ID of the coins to transfer.
|
4986
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4732
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4987
4733
|
* @returns A promise that resolves to the prepared transaction request.
|
4988
4734
|
*/
|
4989
4735
|
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4990
|
-
const
|
4736
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4737
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4738
|
+
const request = new ScriptTransactionRequest(params);
|
4991
4739
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4992
|
-
const
|
4740
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4993
4741
|
estimateTxDependencies: true,
|
4994
4742
|
resourcesOwner: this
|
4995
4743
|
});
|
4996
|
-
|
4997
|
-
|
4998
|
-
|
4999
|
-
|
4744
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4745
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4746
|
+
this.validateGas({
|
4747
|
+
gasUsed,
|
4748
|
+
gasPrice: request.gasPrice,
|
4749
|
+
gasLimit: request.gasLimit,
|
4750
|
+
minGasPrice
|
5000
4751
|
});
|
5001
|
-
request
|
5002
|
-
request.
|
5003
|
-
await this.fund(request, txCost);
|
4752
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4753
|
+
request.updatePredicateInputs(estimatedInputs);
|
5004
4754
|
return request;
|
5005
4755
|
}
|
5006
4756
|
/**
|
@@ -5013,7 +4763,7 @@ var Account = class extends AbstractAccount {
|
|
5013
4763
|
* @returns A promise that resolves to the transaction response.
|
5014
4764
|
*/
|
5015
4765
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5016
|
-
if (
|
4766
|
+
if (bn17(amount).lte(0)) {
|
5017
4767
|
throw new FuelError15(
|
5018
4768
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5019
4769
|
"Transfer amount must be a positive number."
|
@@ -5032,36 +4782,38 @@ var Account = class extends AbstractAccount {
|
|
5032
4782
|
* @returns A promise that resolves to the transaction response.
|
5033
4783
|
*/
|
5034
4784
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5035
|
-
if (
|
4785
|
+
if (bn17(amount).lte(0)) {
|
5036
4786
|
throw new FuelError15(
|
5037
4787
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5038
4788
|
"Transfer amount must be a positive number."
|
5039
4789
|
);
|
5040
4790
|
}
|
5041
4791
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4792
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4793
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5042
4794
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5043
4795
|
hexlifiedContractId: contractAddress.toB256(),
|
5044
|
-
amountToTransfer:
|
4796
|
+
amountToTransfer: bn17(amount),
|
5045
4797
|
assetId
|
5046
4798
|
});
|
5047
4799
|
const request = new ScriptTransactionRequest({
|
5048
|
-
...
|
4800
|
+
...params,
|
5049
4801
|
script,
|
5050
4802
|
scriptData
|
5051
4803
|
});
|
5052
4804
|
request.addContractInputAndOutput(contractAddress);
|
5053
|
-
const
|
5054
|
-
|
5055
|
-
|
5056
|
-
|
5057
|
-
|
5058
|
-
|
5059
|
-
|
5060
|
-
|
4805
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4806
|
+
request,
|
4807
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4808
|
+
);
|
4809
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4810
|
+
this.validateGas({
|
4811
|
+
gasUsed,
|
4812
|
+
gasPrice: request.gasPrice,
|
4813
|
+
gasLimit: request.gasLimit,
|
4814
|
+
minGasPrice
|
5061
4815
|
});
|
5062
|
-
request
|
5063
|
-
request.maxFee = txCost.maxFee;
|
5064
|
-
await this.fund(request, txCost);
|
4816
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5065
4817
|
return this.sendTransaction(request);
|
5066
4818
|
}
|
5067
4819
|
/**
|
@@ -5073,30 +4825,34 @@ var Account = class extends AbstractAccount {
|
|
5073
4825
|
* @returns A promise that resolves to the transaction response.
|
5074
4826
|
*/
|
5075
4827
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4828
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5076
4829
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5077
4830
|
const recipientDataArray = arrayify14(
|
5078
4831
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5079
4832
|
);
|
5080
4833
|
const amountDataArray = arrayify14(
|
5081
|
-
"0x".concat(
|
4834
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5082
4835
|
);
|
5083
4836
|
const script = new Uint8Array([
|
5084
4837
|
...arrayify14(withdrawScript.bytes),
|
5085
4838
|
...recipientDataArray,
|
5086
4839
|
...amountDataArray
|
5087
4840
|
]);
|
5088
|
-
const params = { script, ...txParams };
|
4841
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5089
4842
|
const request = new ScriptTransactionRequest(params);
|
5090
|
-
const
|
5091
|
-
const
|
5092
|
-
|
5093
|
-
|
5094
|
-
|
5095
|
-
|
4843
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4844
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4845
|
+
request,
|
4846
|
+
forwardingQuantities
|
4847
|
+
);
|
4848
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4849
|
+
this.validateGas({
|
4850
|
+
gasUsed,
|
4851
|
+
gasPrice: request.gasPrice,
|
4852
|
+
gasLimit: request.gasLimit,
|
4853
|
+
minGasPrice
|
5096
4854
|
});
|
5097
|
-
request
|
5098
|
-
request.gasLimit = txCost.gasUsed;
|
5099
|
-
await this.fund(request, txCost);
|
4855
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5100
4856
|
return this.sendTransaction(request);
|
5101
4857
|
}
|
5102
4858
|
async signMessage(message) {
|
@@ -5154,21 +4910,22 @@ var Account = class extends AbstractAccount {
|
|
5154
4910
|
}
|
5155
4911
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5156
4912
|
}
|
5157
|
-
|
5158
|
-
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
4913
|
+
validateGas({
|
5159
4914
|
gasUsed,
|
5160
|
-
|
4915
|
+
gasPrice,
|
4916
|
+
gasLimit,
|
4917
|
+
minGasPrice
|
5161
4918
|
}) {
|
5162
|
-
if (
|
4919
|
+
if (minGasPrice.gt(gasPrice)) {
|
5163
4920
|
throw new FuelError15(
|
5164
|
-
ErrorCode15.
|
5165
|
-
`Gas
|
4921
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4922
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5166
4923
|
);
|
5167
4924
|
}
|
5168
|
-
if (
|
4925
|
+
if (gasUsed.gt(gasLimit)) {
|
5169
4926
|
throw new FuelError15(
|
5170
|
-
ErrorCode15.
|
5171
|
-
`
|
4927
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
4928
|
+
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5172
4929
|
);
|
5173
4930
|
}
|
5174
4931
|
}
|
@@ -5456,7 +5213,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5456
5213
|
* @param transactionRequestLike - The transaction request to send.
|
5457
5214
|
* @returns A promise that resolves to the TransactionResponse object.
|
5458
5215
|
*/
|
5459
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5216
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5460
5217
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5461
5218
|
if (estimateTxDependencies) {
|
5462
5219
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5497,7 +5254,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5497
5254
|
// src/hdwallet/hdwallet.ts
|
5498
5255
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5499
5256
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5500
|
-
import { bn as
|
5257
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5501
5258
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5502
5259
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5503
5260
|
|
@@ -7963,7 +7720,7 @@ var HDWallet = class {
|
|
7963
7720
|
const IR = bytes.slice(32);
|
7964
7721
|
if (privateKey) {
|
7965
7722
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7966
|
-
const ki =
|
7723
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7967
7724
|
return new HDWallet({
|
7968
7725
|
privateKey: ki,
|
7969
7726
|
chainCode: IR,
|
@@ -8234,15 +7991,14 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8234
7991
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
8235
7992
|
wallet.provider
|
8236
7993
|
);
|
8237
|
-
const
|
8238
|
-
|
8239
|
-
|
8240
|
-
|
7994
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7995
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7996
|
+
const request = new ScriptTransactionRequest({
|
7997
|
+
gasLimit: 1e4,
|
7998
|
+
gasPrice: minGasPrice
|
8241
7999
|
});
|
8242
|
-
|
8243
|
-
request.
|
8244
|
-
request.maxFee = txCost.maxFee;
|
8245
|
-
await genesisWallet.fund(request, txCost);
|
8000
|
+
request.addResources(resources);
|
8001
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8246
8002
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8247
8003
|
};
|
8248
8004
|
|
@@ -8256,10 +8012,9 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8256
8012
|
};
|
8257
8013
|
|
8258
8014
|
// src/test-utils/launchNode.ts
|
8259
|
-
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8260
8015
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8261
|
-
import {
|
8262
|
-
import {
|
8016
|
+
import { toHex as toHex2 } from "@fuel-ts/math";
|
8017
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8263
8018
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8264
8019
|
import { spawn } from "child_process";
|
8265
8020
|
import { randomUUID } from "crypto";
|
@@ -8303,6 +8058,7 @@ var launchNode = async ({
|
|
8303
8058
|
ip,
|
8304
8059
|
port,
|
8305
8060
|
args = [],
|
8061
|
+
fuelCorePath = void 0,
|
8306
8062
|
useSystemFuelCore = false,
|
8307
8063
|
loggingEnabled = true,
|
8308
8064
|
debugEnabled = false,
|
@@ -8311,19 +8067,19 @@ var launchNode = async ({
|
|
8311
8067
|
// eslint-disable-next-line no-async-promise-executor
|
8312
8068
|
new Promise(async (resolve, reject) => {
|
8313
8069
|
const remainingArgs = extractRemainingArgs(args, [
|
8314
|
-
"--
|
8070
|
+
"--chain",
|
8315
8071
|
"--consensus-key",
|
8316
8072
|
"--db-type",
|
8317
8073
|
"--poa-instant"
|
8318
8074
|
]);
|
8319
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8075
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8320
8076
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8321
8077
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8322
8078
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8323
8079
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
8324
8080
|
const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
|
8325
8081
|
const graphQLStartSubstring = "Binding GraphQL provider to";
|
8326
|
-
const binPath = findBinPath("fuels-core", __dirname);
|
8082
|
+
const binPath = fuelCorePath ?? findBinPath("fuels-core", __dirname);
|
8327
8083
|
const command = useSystemFuelCore ? "fuel-core" : binPath;
|
8328
8084
|
const ipToUse = ip || "0.0.0.0";
|
8329
8085
|
const portToUse = port || (await getPortPromise({
|
@@ -8335,54 +8091,36 @@ var launchNode = async ({
|
|
8335
8091
|
let chainConfigPathToUse;
|
8336
8092
|
const prefix = basePath || os.tmpdir();
|
8337
8093
|
const suffix = basePath ? "" : randomUUID();
|
8338
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix
|
8094
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8339
8095
|
if (chainConfigPath) {
|
8340
8096
|
chainConfigPathToUse = chainConfigPath;
|
8341
8097
|
} else {
|
8342
8098
|
if (!existsSync(tempDirPath)) {
|
8343
8099
|
mkdirSync(tempDirPath, { recursive: true });
|
8344
8100
|
}
|
8345
|
-
|
8346
|
-
|
8347
|
-
stateConfigJson = {
|
8348
|
-
...stateConfigJson,
|
8349
|
-
coins: [
|
8350
|
-
...stateConfigJson.coins.map((coin) => ({
|
8351
|
-
...coin,
|
8352
|
-
amount: "18446744073709551615"
|
8353
|
-
}))
|
8354
|
-
],
|
8355
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8356
|
-
...message,
|
8357
|
-
amount: "18446744073709551615"
|
8358
|
-
}))
|
8359
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8360
|
-
};
|
8101
|
+
const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
|
8102
|
+
let chainConfig = defaultChainConfig;
|
8361
8103
|
if (!process.env.GENESIS_SECRET) {
|
8362
8104
|
const pk = Signer.generatePrivateKey();
|
8363
8105
|
const signer = new Signer(pk);
|
8364
8106
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8365
|
-
|
8366
|
-
|
8367
|
-
|
8368
|
-
|
8369
|
-
|
8370
|
-
|
8371
|
-
|
8372
|
-
|
8373
|
-
|
8374
|
-
|
8107
|
+
chainConfig = {
|
8108
|
+
...defaultChainConfig,
|
8109
|
+
initial_state: {
|
8110
|
+
...defaultChainConfig.initial_state,
|
8111
|
+
coins: [
|
8112
|
+
...defaultChainConfig.initial_state.coins,
|
8113
|
+
{
|
8114
|
+
owner: signer.address.toHexString(),
|
8115
|
+
amount: toHex2(1e9),
|
8116
|
+
asset_id: BaseAssetId4
|
8117
|
+
}
|
8118
|
+
]
|
8119
|
+
}
|
8120
|
+
};
|
8375
8121
|
}
|
8376
|
-
|
8377
|
-
|
8378
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8379
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8380
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8381
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8382
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8383
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8384
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8385
|
-
chainConfigPathToUse = tempDirPath;
|
8122
|
+
writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8123
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8386
8124
|
}
|
8387
8125
|
const child = spawn(
|
8388
8126
|
command,
|
@@ -8391,10 +8129,10 @@ var launchNode = async ({
|
|
8391
8129
|
["--ip", ipToUse],
|
8392
8130
|
["--port", portToUse],
|
8393
8131
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8394
|
-
["--min-gas-price", "
|
8132
|
+
["--min-gas-price", "0"],
|
8395
8133
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8396
8134
|
["--consensus-key", consensusKey],
|
8397
|
-
["--
|
8135
|
+
["--chain", chainConfigPathToUse],
|
8398
8136
|
"--vm-backtrace",
|
8399
8137
|
"--utxo-validation",
|
8400
8138
|
"--debug",
|
@@ -8453,7 +8191,7 @@ var launchNodeAndGetWallets = async ({
|
|
8453
8191
|
walletCount = 10
|
8454
8192
|
} = {}) => {
|
8455
8193
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8456
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8194
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8457
8195
|
const wallets = await generateWallets(walletCount, provider);
|
8458
8196
|
const cleanup = () => {
|
8459
8197
|
closeNode();
|