@fuel-ts/account 0.0.0-rc-2040-20240415161844 → 0.0.0-rc-2021-20240415193305
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +833 -560
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +834 -555
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +684 -406
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +906 -324
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +48 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +8 -25
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1579 -1068
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +809 -548
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +678 -417
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/test-utils.mjs
CHANGED
@@ -27,8 +27,9 @@ 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
|
30
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
31
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
+
import { clone as clone4 } from "ramda";
|
32
33
|
|
33
34
|
// src/providers/coin-quantity.ts
|
34
35
|
import { BaseAssetId } from "@fuel-ts/address/configs";
|
@@ -54,7 +55,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
54
55
|
max: max2 ? bn(max2) : void 0
|
55
56
|
};
|
56
57
|
};
|
57
|
-
var
|
58
|
+
var addAmountToCoinQuantities = (params) => {
|
58
59
|
const { amount, assetId } = params;
|
59
60
|
const coinQuantities = [...params.coinQuantities];
|
60
61
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -69,9 +70,9 @@ var addAmountToAsset = (params) => {
|
|
69
70
|
// src/providers/provider.ts
|
70
71
|
import { Address as Address2 } from "@fuel-ts/address";
|
71
72
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
72
|
-
import { BN, bn as
|
73
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
73
74
|
import {
|
74
|
-
InputType as
|
75
|
+
InputType as InputType7,
|
75
76
|
TransactionType as TransactionType8,
|
76
77
|
InputMessageCoder,
|
77
78
|
TransactionCoder as TransactionCoder5
|
@@ -87,14 +88,10 @@ import { clone as clone3 } from "ramda";
|
|
87
88
|
import gql from "graphql-tag";
|
88
89
|
var ReceiptFragmentFragmentDoc = gql`
|
89
90
|
fragment receiptFragment on Receipt {
|
90
|
-
|
91
|
-
id
|
92
|
-
}
|
91
|
+
id
|
93
92
|
pc
|
94
93
|
is
|
95
|
-
to
|
96
|
-
id
|
97
|
-
}
|
94
|
+
to
|
98
95
|
toAddress
|
99
96
|
amount
|
100
97
|
assetId
|
@@ -132,10 +129,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
132
129
|
id
|
133
130
|
}
|
134
131
|
time
|
132
|
+
receipts {
|
133
|
+
...receiptFragment
|
134
|
+
}
|
135
135
|
programState {
|
136
136
|
returnType
|
137
137
|
data
|
138
138
|
}
|
139
|
+
receipts {
|
140
|
+
...receiptFragment
|
141
|
+
}
|
139
142
|
}
|
140
143
|
... on FailureStatus {
|
141
144
|
block {
|
@@ -143,26 +146,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
143
146
|
}
|
144
147
|
time
|
145
148
|
reason
|
149
|
+
receipts {
|
150
|
+
...receiptFragment
|
151
|
+
}
|
146
152
|
}
|
147
153
|
... on SqueezedOutStatus {
|
148
154
|
reason
|
149
155
|
}
|
150
156
|
}
|
151
|
-
`;
|
157
|
+
${ReceiptFragmentFragmentDoc}`;
|
152
158
|
var TransactionFragmentFragmentDoc = gql`
|
153
159
|
fragment transactionFragment on Transaction {
|
154
160
|
id
|
155
161
|
rawPayload
|
156
|
-
gasPrice
|
157
|
-
receipts {
|
158
|
-
...receiptFragment
|
159
|
-
}
|
160
162
|
status {
|
161
163
|
...transactionStatusFragment
|
162
164
|
}
|
163
165
|
}
|
164
|
-
${
|
165
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
166
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
166
167
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
167
168
|
fragment inputEstimatePredicatesFragment on Input {
|
168
169
|
... on InputCoin {
|
@@ -180,6 +181,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
180
181
|
}
|
181
182
|
}
|
182
183
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
184
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
185
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
186
|
+
reason
|
187
|
+
programState {
|
188
|
+
returnType
|
189
|
+
data
|
190
|
+
}
|
191
|
+
}
|
192
|
+
`;
|
193
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
194
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
195
|
+
programState {
|
196
|
+
returnType
|
197
|
+
data
|
198
|
+
}
|
199
|
+
}
|
200
|
+
`;
|
201
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
202
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
203
|
+
... on DryRunFailureStatus {
|
204
|
+
...dryRunFailureStatusFragment
|
205
|
+
}
|
206
|
+
... on DryRunSuccessStatus {
|
207
|
+
...dryRunSuccessStatusFragment
|
208
|
+
}
|
209
|
+
}
|
210
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
211
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
212
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
213
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
214
|
+
id
|
215
|
+
status {
|
216
|
+
...dryRunTransactionStatusFragment
|
217
|
+
}
|
218
|
+
receipts {
|
219
|
+
...receiptFragment
|
220
|
+
}
|
221
|
+
}
|
222
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
223
|
+
${ReceiptFragmentFragmentDoc}`;
|
183
224
|
var CoinFragmentFragmentDoc = gql`
|
184
225
|
fragment coinFragment on Coin {
|
185
226
|
__typename
|
@@ -187,7 +228,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
187
228
|
owner
|
188
229
|
amount
|
189
230
|
assetId
|
190
|
-
maturity
|
191
231
|
blockCreated
|
192
232
|
txCreatedIdx
|
193
233
|
}
|
@@ -226,26 +266,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
226
266
|
messageBlockHeader {
|
227
267
|
id
|
228
268
|
daHeight
|
269
|
+
consensusParametersVersion
|
270
|
+
stateTransitionBytecodeVersion
|
229
271
|
transactionsCount
|
272
|
+
messageReceiptCount
|
230
273
|
transactionsRoot
|
274
|
+
messageOutboxRoot
|
275
|
+
eventInboxRoot
|
231
276
|
height
|
232
277
|
prevRoot
|
233
278
|
time
|
234
279
|
applicationHash
|
235
|
-
messageReceiptRoot
|
236
|
-
messageReceiptCount
|
237
280
|
}
|
238
281
|
commitBlockHeader {
|
239
282
|
id
|
240
283
|
daHeight
|
284
|
+
consensusParametersVersion
|
285
|
+
stateTransitionBytecodeVersion
|
241
286
|
transactionsCount
|
287
|
+
messageReceiptCount
|
242
288
|
transactionsRoot
|
289
|
+
messageOutboxRoot
|
290
|
+
eventInboxRoot
|
243
291
|
height
|
244
292
|
prevRoot
|
245
293
|
time
|
246
294
|
applicationHash
|
247
|
-
messageReceiptRoot
|
248
|
-
messageReceiptCount
|
249
295
|
}
|
250
296
|
sender
|
251
297
|
recipient
|
@@ -264,8 +310,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
264
310
|
var BlockFragmentFragmentDoc = gql`
|
265
311
|
fragment blockFragment on Block {
|
266
312
|
id
|
313
|
+
height
|
267
314
|
header {
|
268
|
-
height
|
269
315
|
time
|
270
316
|
}
|
271
317
|
transactions {
|
@@ -323,6 +369,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
323
369
|
`;
|
324
370
|
var GasCostsFragmentFragmentDoc = gql`
|
325
371
|
fragment GasCostsFragment on GasCosts {
|
372
|
+
version {
|
373
|
+
... on Version {
|
374
|
+
value
|
375
|
+
}
|
376
|
+
}
|
326
377
|
add
|
327
378
|
addi
|
328
379
|
aloc
|
@@ -335,7 +386,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
335
386
|
cb
|
336
387
|
cfei
|
337
388
|
cfsi
|
338
|
-
croo
|
339
389
|
div
|
340
390
|
divi
|
341
391
|
ecr1
|
@@ -418,6 +468,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
418
468
|
ccp {
|
419
469
|
...DependentCostFragment
|
420
470
|
}
|
471
|
+
croo {
|
472
|
+
...DependentCostFragment
|
473
|
+
}
|
421
474
|
csiz {
|
422
475
|
...DependentCostFragment
|
423
476
|
}
|
@@ -477,6 +530,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
477
530
|
${DependentCostFragmentFragmentDoc}`;
|
478
531
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
479
532
|
fragment consensusParametersFragment on ConsensusParameters {
|
533
|
+
version {
|
534
|
+
... on Version {
|
535
|
+
value
|
536
|
+
}
|
537
|
+
}
|
480
538
|
txParams {
|
481
539
|
...TxParametersFragment
|
482
540
|
}
|
@@ -536,18 +594,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
536
594
|
fragment nodeInfoFragment on NodeInfo {
|
537
595
|
utxoValidation
|
538
596
|
vmBacktrace
|
539
|
-
minGasPrice
|
540
597
|
maxTx
|
541
598
|
maxDepth
|
542
599
|
nodeVersion
|
543
|
-
peers {
|
544
|
-
id
|
545
|
-
addresses
|
546
|
-
clientVersion
|
547
|
-
blockHeight
|
548
|
-
lastHeartbeatMs
|
549
|
-
appScore
|
550
|
-
}
|
551
600
|
}
|
552
601
|
`;
|
553
602
|
var GetVersionDocument = gql`
|
@@ -582,13 +631,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
582
631
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
583
632
|
transaction(id: $transactionId) {
|
584
633
|
...transactionFragment
|
585
|
-
receipts {
|
586
|
-
...receiptFragment
|
587
|
-
}
|
588
634
|
}
|
589
635
|
}
|
590
|
-
${TransactionFragmentFragmentDoc}
|
591
|
-
${ReceiptFragmentFragmentDoc}`;
|
636
|
+
${TransactionFragmentFragmentDoc}`;
|
592
637
|
var GetTransactionsDocument = gql`
|
593
638
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
594
639
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -716,6 +761,20 @@ var GetBalanceDocument = gql`
|
|
716
761
|
}
|
717
762
|
}
|
718
763
|
${BalanceFragmentFragmentDoc}`;
|
764
|
+
var GetLatestGasPriceDocument = gql`
|
765
|
+
query getLatestGasPrice {
|
766
|
+
latestGasPrice {
|
767
|
+
gasPrice
|
768
|
+
}
|
769
|
+
}
|
770
|
+
`;
|
771
|
+
var EstimateGasPriceDocument = gql`
|
772
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
773
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
774
|
+
gasPrice
|
775
|
+
}
|
776
|
+
}
|
777
|
+
`;
|
719
778
|
var GetBalancesDocument = gql`
|
720
779
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
721
780
|
balances(
|
@@ -770,12 +829,12 @@ var GetMessageStatusDocument = gql`
|
|
770
829
|
}
|
771
830
|
`;
|
772
831
|
var DryRunDocument = gql`
|
773
|
-
mutation dryRun($
|
774
|
-
dryRun(
|
775
|
-
...
|
832
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
833
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
834
|
+
...dryRunTransactionExecutionStatusFragment
|
776
835
|
}
|
777
836
|
}
|
778
|
-
${
|
837
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
779
838
|
var SubmitDocument = gql`
|
780
839
|
mutation submit($encodedTransaction: HexString!) {
|
781
840
|
submit(tx: $encodedTransaction) {
|
@@ -858,6 +917,12 @@ function getSdk(requester) {
|
|
858
917
|
getBalance(variables, options) {
|
859
918
|
return requester(GetBalanceDocument, variables, options);
|
860
919
|
},
|
920
|
+
getLatestGasPrice(variables, options) {
|
921
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
922
|
+
},
|
923
|
+
estimateGasPrice(variables, options) {
|
924
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
925
|
+
},
|
861
926
|
getBalances(variables, options) {
|
862
927
|
return requester(GetBalancesDocument, variables, options);
|
863
928
|
},
|
@@ -927,11 +992,14 @@ var _FuelGraphqlSubscriber = class {
|
|
927
992
|
let data;
|
928
993
|
let errors;
|
929
994
|
try {
|
930
|
-
|
995
|
+
const sanitizedText = text.replace(/\s/g, "");
|
996
|
+
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
931
997
|
} catch (e) {
|
932
998
|
throw new FuelError(
|
933
999
|
ErrorCode.STREAM_PARSING_ERROR,
|
934
|
-
`Error while parsing stream data response: ${text}
|
1000
|
+
`Error while parsing stream data response: ${text}
|
1001
|
+
|
1002
|
+
Thrown error: ${e}`
|
935
1003
|
);
|
936
1004
|
}
|
937
1005
|
if (Array.isArray(errors)) {
|
@@ -1018,6 +1086,7 @@ var MemoryCache = class {
|
|
1018
1086
|
};
|
1019
1087
|
|
1020
1088
|
// src/providers/transaction-request/input.ts
|
1089
|
+
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1021
1090
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1022
1091
|
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1023
1092
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
@@ -1031,8 +1100,8 @@ var inputify = (value) => {
|
|
1031
1100
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1032
1101
|
return {
|
1033
1102
|
type: InputType.Coin,
|
1034
|
-
txID: hexlify3(arrayify(value.id).slice(0,
|
1035
|
-
outputIndex: arrayify(value.id)
|
1103
|
+
txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
|
1104
|
+
outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
|
1036
1105
|
owner: hexlify3(value.owner),
|
1037
1106
|
amount: bn2(value.amount),
|
1038
1107
|
assetId: hexlify3(value.assetId),
|
@@ -1041,10 +1110,9 @@ var inputify = (value) => {
|
|
1041
1110
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1042
1111
|
},
|
1043
1112
|
witnessIndex: value.witnessIndex,
|
1044
|
-
maturity: value.maturity ?? 0,
|
1045
1113
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1046
|
-
predicateLength: predicate.length,
|
1047
|
-
predicateDataLength: predicateData.length,
|
1114
|
+
predicateLength: bn2(predicate.length),
|
1115
|
+
predicateDataLength: bn2(predicateData.length),
|
1048
1116
|
predicate: hexlify3(predicate),
|
1049
1117
|
predicateData: hexlify3(predicateData)
|
1050
1118
|
};
|
@@ -1075,8 +1143,8 @@ var inputify = (value) => {
|
|
1075
1143
|
nonce: hexlify3(value.nonce),
|
1076
1144
|
witnessIndex: value.witnessIndex,
|
1077
1145
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1078
|
-
predicateLength: predicate.length,
|
1079
|
-
predicateDataLength: predicateData.length,
|
1146
|
+
predicateLength: bn2(predicate.length),
|
1147
|
+
predicateDataLength: bn2(predicateData.length),
|
1080
1148
|
predicate: hexlify3(predicate),
|
1081
1149
|
predicateData: hexlify3(predicateData),
|
1082
1150
|
data: hexlify3(data),
|
@@ -1150,8 +1218,10 @@ var outputify = (value) => {
|
|
1150
1218
|
};
|
1151
1219
|
|
1152
1220
|
// src/providers/transaction-request/transaction-request.ts
|
1221
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1153
1222
|
import { Address, addressify } from "@fuel-ts/address";
|
1154
1223
|
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1224
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
1155
1225
|
import { bn as bn7 } from "@fuel-ts/math";
|
1156
1226
|
import {
|
1157
1227
|
PolicyType,
|
@@ -1201,8 +1271,8 @@ function assembleReceiptByType(receipt) {
|
|
1201
1271
|
case "CALL" /* Call */: {
|
1202
1272
|
const callReceipt = {
|
1203
1273
|
type: ReceiptType.Call,
|
1204
|
-
from: hexOrZero(receipt.
|
1205
|
-
to: hexOrZero(receipt?.to
|
1274
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1275
|
+
to: hexOrZero(receipt?.to),
|
1206
1276
|
amount: bn4(receipt.amount),
|
1207
1277
|
assetId: hexOrZero(receipt.assetId),
|
1208
1278
|
gas: bn4(receipt.gas),
|
@@ -1216,7 +1286,7 @@ function assembleReceiptByType(receipt) {
|
|
1216
1286
|
case "RETURN" /* Return */: {
|
1217
1287
|
const returnReceipt = {
|
1218
1288
|
type: ReceiptType.Return,
|
1219
|
-
id: hexOrZero(receipt.
|
1289
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1220
1290
|
val: bn4(receipt.val),
|
1221
1291
|
pc: bn4(receipt.pc),
|
1222
1292
|
is: bn4(receipt.is)
|
@@ -1226,7 +1296,7 @@ function assembleReceiptByType(receipt) {
|
|
1226
1296
|
case "RETURN_DATA" /* ReturnData */: {
|
1227
1297
|
const returnDataReceipt = {
|
1228
1298
|
type: ReceiptType.ReturnData,
|
1229
|
-
id: hexOrZero(receipt.
|
1299
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1230
1300
|
ptr: bn4(receipt.ptr),
|
1231
1301
|
len: bn4(receipt.len),
|
1232
1302
|
digest: hexOrZero(receipt.digest),
|
@@ -1238,7 +1308,7 @@ function assembleReceiptByType(receipt) {
|
|
1238
1308
|
case "PANIC" /* Panic */: {
|
1239
1309
|
const panicReceipt = {
|
1240
1310
|
type: ReceiptType.Panic,
|
1241
|
-
id: hexOrZero(receipt.
|
1311
|
+
id: hexOrZero(receipt.id),
|
1242
1312
|
reason: bn4(receipt.reason),
|
1243
1313
|
pc: bn4(receipt.pc),
|
1244
1314
|
is: bn4(receipt.is),
|
@@ -1249,7 +1319,7 @@ function assembleReceiptByType(receipt) {
|
|
1249
1319
|
case "REVERT" /* Revert */: {
|
1250
1320
|
const revertReceipt = {
|
1251
1321
|
type: ReceiptType.Revert,
|
1252
|
-
id: hexOrZero(receipt.
|
1322
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1253
1323
|
val: bn4(receipt.ra),
|
1254
1324
|
pc: bn4(receipt.pc),
|
1255
1325
|
is: bn4(receipt.is)
|
@@ -1259,7 +1329,7 @@ function assembleReceiptByType(receipt) {
|
|
1259
1329
|
case "LOG" /* Log */: {
|
1260
1330
|
const logReceipt = {
|
1261
1331
|
type: ReceiptType.Log,
|
1262
|
-
id: hexOrZero(receipt.
|
1332
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1263
1333
|
val0: bn4(receipt.ra),
|
1264
1334
|
val1: bn4(receipt.rb),
|
1265
1335
|
val2: bn4(receipt.rc),
|
@@ -1272,7 +1342,7 @@ function assembleReceiptByType(receipt) {
|
|
1272
1342
|
case "LOG_DATA" /* LogData */: {
|
1273
1343
|
const logDataReceipt = {
|
1274
1344
|
type: ReceiptType.LogData,
|
1275
|
-
id: hexOrZero(receipt.
|
1345
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1276
1346
|
val0: bn4(receipt.ra),
|
1277
1347
|
val1: bn4(receipt.rb),
|
1278
1348
|
ptr: bn4(receipt.ptr),
|
@@ -1286,8 +1356,8 @@ function assembleReceiptByType(receipt) {
|
|
1286
1356
|
case "TRANSFER" /* Transfer */: {
|
1287
1357
|
const transferReceipt = {
|
1288
1358
|
type: ReceiptType.Transfer,
|
1289
|
-
from: hexOrZero(receipt.
|
1290
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1359
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1360
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1291
1361
|
amount: bn4(receipt.amount),
|
1292
1362
|
assetId: hexOrZero(receipt.assetId),
|
1293
1363
|
pc: bn4(receipt.pc),
|
@@ -1298,8 +1368,8 @@ function assembleReceiptByType(receipt) {
|
|
1298
1368
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1299
1369
|
const transferOutReceipt = {
|
1300
1370
|
type: ReceiptType.TransferOut,
|
1301
|
-
from: hexOrZero(receipt.
|
1302
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1371
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1372
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1303
1373
|
amount: bn4(receipt.amount),
|
1304
1374
|
assetId: hexOrZero(receipt.assetId),
|
1305
1375
|
pc: bn4(receipt.pc),
|
@@ -1342,7 +1412,7 @@ function assembleReceiptByType(receipt) {
|
|
1342
1412
|
return receiptMessageOut;
|
1343
1413
|
}
|
1344
1414
|
case "MINT" /* Mint */: {
|
1345
|
-
const contractId = hexOrZero(receipt.
|
1415
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1346
1416
|
const subId = hexOrZero(receipt.subId);
|
1347
1417
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1348
1418
|
const mintReceipt = {
|
@@ -1357,7 +1427,7 @@ function assembleReceiptByType(receipt) {
|
|
1357
1427
|
return mintReceipt;
|
1358
1428
|
}
|
1359
1429
|
case "BURN" /* Burn */: {
|
1360
|
-
const contractId = hexOrZero(receipt.
|
1430
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1361
1431
|
const subId = hexOrZero(receipt.subId);
|
1362
1432
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1363
1433
|
const burnReceipt = {
|
@@ -1383,7 +1453,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1383
1453
|
import { bn as bn5 } from "@fuel-ts/math";
|
1384
1454
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1385
1455
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1386
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1387
1456
|
var getGasUsedFromReceipts = (receipts) => {
|
1388
1457
|
const scriptResult = receipts.filter(
|
1389
1458
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1404,18 +1473,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1404
1473
|
}
|
1405
1474
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1406
1475
|
const witnessCache = [];
|
1407
|
-
const
|
1476
|
+
const chargeableInputs = inputs.filter((input) => {
|
1477
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1478
|
+
if (isCoinOrMessage) {
|
1479
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1480
|
+
return true;
|
1481
|
+
}
|
1482
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1483
|
+
witnessCache.push(input.witnessIndex);
|
1484
|
+
return true;
|
1485
|
+
}
|
1486
|
+
}
|
1487
|
+
return false;
|
1488
|
+
});
|
1489
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1490
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1408
1491
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1409
1492
|
return total.add(
|
1410
|
-
|
1493
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1411
1494
|
);
|
1412
1495
|
}
|
1413
|
-
|
1414
|
-
|
1415
|
-
return total.add(gasCosts.ecr1);
|
1416
|
-
}
|
1417
|
-
return total;
|
1418
|
-
}, bn5());
|
1496
|
+
return total.add(gasCosts.ecr1);
|
1497
|
+
}, bn5(0));
|
1419
1498
|
return totalGas;
|
1420
1499
|
}
|
1421
1500
|
function getMinGas(params) {
|
@@ -1427,12 +1506,20 @@ function getMinGas(params) {
|
|
1427
1506
|
return minGas;
|
1428
1507
|
}
|
1429
1508
|
function getMaxGas(params) {
|
1430
|
-
const {
|
1509
|
+
const {
|
1510
|
+
gasPerByte,
|
1511
|
+
witnessesLength,
|
1512
|
+
witnessLimit,
|
1513
|
+
minGas,
|
1514
|
+
gasLimit = bn5(0),
|
1515
|
+
maxGasPerTx
|
1516
|
+
} = params;
|
1431
1517
|
let remainingAllowedWitnessGas = bn5(0);
|
1432
1518
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1433
1519
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1434
1520
|
}
|
1435
|
-
|
1521
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1522
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1436
1523
|
}
|
1437
1524
|
function calculateMetadataGasForTxCreate({
|
1438
1525
|
gasCosts,
|
@@ -1454,6 +1541,10 @@ function calculateMetadataGasForTxScript({
|
|
1454
1541
|
}) {
|
1455
1542
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1456
1543
|
}
|
1544
|
+
var calculateGasFee = (params) => {
|
1545
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1546
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1547
|
+
};
|
1457
1548
|
|
1458
1549
|
// src/providers/utils/json.ts
|
1459
1550
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1598,7 +1689,7 @@ var witnessify = (value) => {
|
|
1598
1689
|
// src/providers/transaction-request/transaction-request.ts
|
1599
1690
|
var BaseTransactionRequest = class {
|
1600
1691
|
/** Gas price for transaction */
|
1601
|
-
|
1692
|
+
tip;
|
1602
1693
|
/** Block until which tx cannot be included */
|
1603
1694
|
maturity;
|
1604
1695
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1617,7 +1708,7 @@ var BaseTransactionRequest = class {
|
|
1617
1708
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1618
1709
|
*/
|
1619
1710
|
constructor({
|
1620
|
-
|
1711
|
+
tip,
|
1621
1712
|
maturity,
|
1622
1713
|
maxFee,
|
1623
1714
|
witnessLimit,
|
@@ -1625,7 +1716,7 @@ var BaseTransactionRequest = class {
|
|
1625
1716
|
outputs,
|
1626
1717
|
witnesses
|
1627
1718
|
} = {}) {
|
1628
|
-
this.
|
1719
|
+
this.tip = bn7(tip);
|
1629
1720
|
this.maturity = maturity ?? 0;
|
1630
1721
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1631
1722
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1636,9 +1727,9 @@ var BaseTransactionRequest = class {
|
|
1636
1727
|
static getPolicyMeta(req) {
|
1637
1728
|
let policyTypes = 0;
|
1638
1729
|
const policies = [];
|
1639
|
-
if (req.
|
1640
|
-
policyTypes += PolicyType.
|
1641
|
-
policies.push({ data: req.
|
1730
|
+
if (req.tip) {
|
1731
|
+
policyTypes += PolicyType.Tip;
|
1732
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1642
1733
|
}
|
1643
1734
|
if (req.witnessLimit) {
|
1644
1735
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1825,10 +1916,10 @@ var BaseTransactionRequest = class {
|
|
1825
1916
|
* @param predicate - Predicate bytes.
|
1826
1917
|
* @param predicateData - Predicate data bytes.
|
1827
1918
|
*/
|
1828
|
-
addCoinInput(coin
|
1919
|
+
addCoinInput(coin) {
|
1829
1920
|
const { assetId, owner, amount } = coin;
|
1830
1921
|
let witnessIndex;
|
1831
|
-
if (predicate) {
|
1922
|
+
if (coin.predicate) {
|
1832
1923
|
witnessIndex = 0;
|
1833
1924
|
} else {
|
1834
1925
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1843,8 +1934,7 @@ var BaseTransactionRequest = class {
|
|
1843
1934
|
amount,
|
1844
1935
|
assetId,
|
1845
1936
|
txPointer: "0x00000000000000000000000000000000",
|
1846
|
-
witnessIndex
|
1847
|
-
predicate: predicate?.bytes
|
1937
|
+
witnessIndex
|
1848
1938
|
};
|
1849
1939
|
this.pushInput(input);
|
1850
1940
|
this.addChangeOutput(owner, assetId);
|
@@ -1857,11 +1947,11 @@ var BaseTransactionRequest = class {
|
|
1857
1947
|
* @param predicate - Predicate bytes.
|
1858
1948
|
* @param predicateData - Predicate data bytes.
|
1859
1949
|
*/
|
1860
|
-
addMessageInput(message
|
1950
|
+
addMessageInput(message) {
|
1861
1951
|
const { recipient, sender, amount } = message;
|
1862
1952
|
const assetId = BaseAssetId2;
|
1863
1953
|
let witnessIndex;
|
1864
|
-
if (predicate) {
|
1954
|
+
if (message.predicate) {
|
1865
1955
|
witnessIndex = 0;
|
1866
1956
|
} else {
|
1867
1957
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1875,8 +1965,7 @@ var BaseTransactionRequest = class {
|
|
1875
1965
|
sender: sender.toB256(),
|
1876
1966
|
recipient: recipient.toB256(),
|
1877
1967
|
amount,
|
1878
|
-
witnessIndex
|
1879
|
-
predicate: predicate?.bytes
|
1968
|
+
witnessIndex
|
1880
1969
|
};
|
1881
1970
|
this.pushInput(input);
|
1882
1971
|
this.addChangeOutput(recipient, assetId);
|
@@ -1907,32 +1996,6 @@ var BaseTransactionRequest = class {
|
|
1907
1996
|
resources.forEach((resource) => this.addResource(resource));
|
1908
1997
|
return this;
|
1909
1998
|
}
|
1910
|
-
/**
|
1911
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1912
|
-
* outputs from the related assetIds.
|
1913
|
-
*
|
1914
|
-
* @param resources - The resources to add.
|
1915
|
-
* @returns This transaction.
|
1916
|
-
*/
|
1917
|
-
addPredicateResource(resource, predicate) {
|
1918
|
-
if (isCoin(resource)) {
|
1919
|
-
this.addCoinInput(resource, predicate);
|
1920
|
-
} else {
|
1921
|
-
this.addMessageInput(resource, predicate);
|
1922
|
-
}
|
1923
|
-
return this;
|
1924
|
-
}
|
1925
|
-
/**
|
1926
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1927
|
-
* from the related assetIds.
|
1928
|
-
*
|
1929
|
-
* @param resources - The resources to add.
|
1930
|
-
* @returns This transaction.
|
1931
|
-
*/
|
1932
|
-
addPredicateResources(resources, predicate) {
|
1933
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1934
|
-
return this;
|
1935
|
-
}
|
1936
1999
|
/**
|
1937
2000
|
* Adds a coin output to the transaction.
|
1938
2001
|
*
|
@@ -2012,7 +2075,7 @@ var BaseTransactionRequest = class {
|
|
2012
2075
|
}
|
2013
2076
|
calculateMaxGas(chainInfo, minGas) {
|
2014
2077
|
const { consensusParameters } = chainInfo;
|
2015
|
-
const { gasPerByte } = consensusParameters;
|
2078
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2016
2079
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2017
2080
|
(acc, wit) => acc + wit.dataLength,
|
2018
2081
|
0
|
@@ -2021,7 +2084,8 @@ var BaseTransactionRequest = class {
|
|
2021
2084
|
gasPerByte,
|
2022
2085
|
minGas,
|
2023
2086
|
witnessesLength,
|
2024
|
-
witnessLimit: this.witnessLimit
|
2087
|
+
witnessLimit: this.witnessLimit,
|
2088
|
+
maxGasPerTx
|
2025
2089
|
});
|
2026
2090
|
}
|
2027
2091
|
/**
|
@@ -2031,12 +2095,6 @@ var BaseTransactionRequest = class {
|
|
2031
2095
|
* @param quantities - CoinQuantity Array.
|
2032
2096
|
*/
|
2033
2097
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2034
|
-
let idCounter = 0;
|
2035
|
-
const generateId = () => {
|
2036
|
-
const counterString = String(idCounter++);
|
2037
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2038
|
-
return id;
|
2039
|
-
};
|
2040
2098
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2041
2099
|
if ("assetId" in input) {
|
2042
2100
|
return input.assetId === assetId;
|
@@ -2045,17 +2103,20 @@ var BaseTransactionRequest = class {
|
|
2045
2103
|
});
|
2046
2104
|
const updateAssetInput = (assetId, quantity) => {
|
2047
2105
|
const assetInput = findAssetInput(assetId);
|
2106
|
+
let usedQuantity = quantity;
|
2107
|
+
if (assetId === BaseAssetId2) {
|
2108
|
+
usedQuantity = bn7("1000000000000000000");
|
2109
|
+
}
|
2048
2110
|
if (assetInput && "assetId" in assetInput) {
|
2049
|
-
assetInput.id =
|
2050
|
-
assetInput.amount =
|
2111
|
+
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2112
|
+
assetInput.amount = usedQuantity;
|
2051
2113
|
} else {
|
2052
2114
|
this.addResources([
|
2053
2115
|
{
|
2054
|
-
id:
|
2055
|
-
amount:
|
2116
|
+
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2117
|
+
amount: usedQuantity,
|
2056
2118
|
assetId,
|
2057
2119
|
owner: resourcesOwner || Address.fromRandom(),
|
2058
|
-
maturity: 0,
|
2059
2120
|
blockCreated: bn7(1),
|
2060
2121
|
txCreatedIdx: bn7(1)
|
2061
2122
|
}
|
@@ -2087,7 +2148,7 @@ var BaseTransactionRequest = class {
|
|
2087
2148
|
toJSON() {
|
2088
2149
|
return normalizeJSON(this);
|
2089
2150
|
}
|
2090
|
-
|
2151
|
+
updatePredicateGasUsed(inputs) {
|
2091
2152
|
this.inputs.forEach((i) => {
|
2092
2153
|
let correspondingInput;
|
2093
2154
|
switch (i.type) {
|
@@ -2109,6 +2170,15 @@ var BaseTransactionRequest = class {
|
|
2109
2170
|
}
|
2110
2171
|
});
|
2111
2172
|
}
|
2173
|
+
shiftPredicateData() {
|
2174
|
+
this.inputs.forEach((input) => {
|
2175
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2176
|
+
input.predicateData = input.paddPredicateData(
|
2177
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2178
|
+
);
|
2179
|
+
}
|
2180
|
+
});
|
2181
|
+
}
|
2112
2182
|
};
|
2113
2183
|
|
2114
2184
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2255,9 +2325,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2255
2325
|
return {
|
2256
2326
|
type: TransactionType3.Create,
|
2257
2327
|
...baseTransaction,
|
2258
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2259
2328
|
bytecodeWitnessIndex,
|
2260
|
-
storageSlotsCount: storageSlots.length,
|
2329
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2261
2330
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2262
2331
|
storageSlots
|
2263
2332
|
};
|
@@ -2380,8 +2449,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2380
2449
|
type: TransactionType4.Script,
|
2381
2450
|
scriptGasLimit: this.gasLimit,
|
2382
2451
|
...super.getBaseTransaction(),
|
2383
|
-
scriptLength: script.length,
|
2384
|
-
scriptDataLength: scriptData.length,
|
2452
|
+
scriptLength: bn10(script.length),
|
2453
|
+
scriptDataLength: bn10(scriptData.length),
|
2385
2454
|
receiptsRoot: ZeroBytes327,
|
2386
2455
|
script: hexlify10(script),
|
2387
2456
|
scriptData: hexlify10(scriptData)
|
@@ -2445,7 +2514,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2445
2514
|
}
|
2446
2515
|
calculateMaxGas(chainInfo, minGas) {
|
2447
2516
|
const { consensusParameters } = chainInfo;
|
2448
|
-
const { gasPerByte } = consensusParameters;
|
2517
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2449
2518
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2450
2519
|
(acc, wit) => acc + wit.dataLength,
|
2451
2520
|
0
|
@@ -2455,7 +2524,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2455
2524
|
minGas,
|
2456
2525
|
witnessesLength,
|
2457
2526
|
witnessLimit: this.witnessLimit,
|
2458
|
-
gasLimit: this.gasLimit
|
2527
|
+
gasLimit: this.gasLimit,
|
2528
|
+
maxGasPerTx
|
2459
2529
|
});
|
2460
2530
|
}
|
2461
2531
|
/**
|
@@ -2512,7 +2582,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2512
2582
|
|
2513
2583
|
// src/providers/transaction-request/utils.ts
|
2514
2584
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2515
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2585
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2516
2586
|
var transactionRequestify = (obj) => {
|
2517
2587
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2518
2588
|
return obj;
|
@@ -2530,14 +2600,31 @@ var transactionRequestify = (obj) => {
|
|
2530
2600
|
}
|
2531
2601
|
}
|
2532
2602
|
};
|
2603
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2604
|
+
(acc, input) => {
|
2605
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2606
|
+
acc.utxos.push(input.id);
|
2607
|
+
}
|
2608
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2609
|
+
acc.messages.push(input.nonce);
|
2610
|
+
}
|
2611
|
+
return acc;
|
2612
|
+
},
|
2613
|
+
{
|
2614
|
+
utxos: [],
|
2615
|
+
messages: []
|
2616
|
+
}
|
2617
|
+
);
|
2533
2618
|
|
2534
2619
|
// src/providers/transaction-response/transaction-response.ts
|
2535
2620
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2536
|
-
import { bn as
|
2621
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2537
2622
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2538
2623
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2539
2624
|
|
2540
2625
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2626
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2627
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2541
2628
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2542
2629
|
|
2543
2630
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2546,9 +2633,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2546
2633
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2547
2634
|
var calculateTransactionFee = (params) => {
|
2548
2635
|
const {
|
2549
|
-
|
2636
|
+
gasPrice,
|
2550
2637
|
rawPayload,
|
2551
|
-
|
2638
|
+
tip,
|
2639
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2552
2640
|
} = params;
|
2553
2641
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2554
2642
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2558,8 +2646,7 @@ var calculateTransactionFee = (params) => {
|
|
2558
2646
|
return {
|
2559
2647
|
fee: bn11(0),
|
2560
2648
|
minFee: bn11(0),
|
2561
|
-
maxFee: bn11(0)
|
2562
|
-
feeFromGasUsed: bn11(0)
|
2649
|
+
maxFee: bn11(0)
|
2563
2650
|
};
|
2564
2651
|
}
|
2565
2652
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2591,7 +2678,6 @@ var calculateTransactionFee = (params) => {
|
|
2591
2678
|
metadataGas,
|
2592
2679
|
txBytesSize: transactionBytes.length
|
2593
2680
|
});
|
2594
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2595
2681
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2596
2682
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2597
2683
|
const maxGas = getMaxGas({
|
@@ -2599,17 +2685,25 @@ var calculateTransactionFee = (params) => {
|
|
2599
2685
|
minGas,
|
2600
2686
|
witnessesLength,
|
2601
2687
|
gasLimit,
|
2602
|
-
witnessLimit
|
2688
|
+
witnessLimit,
|
2689
|
+
maxGasPerTx
|
2690
|
+
});
|
2691
|
+
const minFee = calculateGasFee({
|
2692
|
+
gasPrice,
|
2693
|
+
gas: minGas,
|
2694
|
+
priceFactor: gasPriceFactor,
|
2695
|
+
tip
|
2696
|
+
});
|
2697
|
+
const maxFee = calculateGasFee({
|
2698
|
+
gasPrice,
|
2699
|
+
gas: maxGas,
|
2700
|
+
priceFactor: gasPriceFactor,
|
2701
|
+
tip
|
2603
2702
|
});
|
2604
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2605
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2606
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2607
|
-
const fee = minFee.add(feeFromGasUsed);
|
2608
2703
|
return {
|
2609
|
-
fee,
|
2610
2704
|
minFee,
|
2611
2705
|
maxFee,
|
2612
|
-
|
2706
|
+
fee: maxFee
|
2613
2707
|
};
|
2614
2708
|
};
|
2615
2709
|
|
@@ -2665,7 +2759,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2665
2759
|
|
2666
2760
|
// src/providers/transaction-summary/input.ts
|
2667
2761
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2668
|
-
import { InputType as
|
2762
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2669
2763
|
function getInputsByTypes(inputs, types) {
|
2670
2764
|
return inputs.filter((i) => types.includes(i.type));
|
2671
2765
|
}
|
@@ -2673,16 +2767,16 @@ function getInputsByType(inputs, type) {
|
|
2673
2767
|
return inputs.filter((i) => i.type === type);
|
2674
2768
|
}
|
2675
2769
|
function getInputsCoin(inputs) {
|
2676
|
-
return getInputsByType(inputs,
|
2770
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2677
2771
|
}
|
2678
2772
|
function getInputsMessage(inputs) {
|
2679
|
-
return getInputsByType(inputs,
|
2773
|
+
return getInputsByType(inputs, InputType6.Message);
|
2680
2774
|
}
|
2681
2775
|
function getInputsCoinAndMessage(inputs) {
|
2682
|
-
return getInputsByTypes(inputs, [
|
2776
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2683
2777
|
}
|
2684
2778
|
function getInputsContract(inputs) {
|
2685
|
-
return getInputsByType(inputs,
|
2779
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2686
2780
|
}
|
2687
2781
|
function getInputFromAssetId(inputs, assetId) {
|
2688
2782
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2701,7 +2795,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2701
2795
|
if (!contractInput) {
|
2702
2796
|
return void 0;
|
2703
2797
|
}
|
2704
|
-
if (contractInput.type !==
|
2798
|
+
if (contractInput.type !== InputType6.Contract) {
|
2705
2799
|
throw new FuelError9(
|
2706
2800
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2707
2801
|
`Contract input should be of type 'contract'.`
|
@@ -2710,10 +2804,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2710
2804
|
return contractInput;
|
2711
2805
|
}
|
2712
2806
|
function getInputAccountAddress(input) {
|
2713
|
-
if (input.type ===
|
2807
|
+
if (input.type === InputType6.Coin) {
|
2714
2808
|
return input.owner.toString();
|
2715
2809
|
}
|
2716
|
-
if (input.type ===
|
2810
|
+
if (input.type === InputType6.Message) {
|
2717
2811
|
return input.recipient.toString();
|
2718
2812
|
}
|
2719
2813
|
return "";
|
@@ -3176,7 +3270,9 @@ function assembleTransactionSummary(params) {
|
|
3176
3270
|
gqlTransactionStatus,
|
3177
3271
|
abiMap = {},
|
3178
3272
|
maxInputs,
|
3179
|
-
gasCosts
|
3273
|
+
gasCosts,
|
3274
|
+
maxGasPerTx,
|
3275
|
+
gasPrice
|
3180
3276
|
} = params;
|
3181
3277
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3182
3278
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3190,11 +3286,14 @@ function assembleTransactionSummary(params) {
|
|
3190
3286
|
maxInputs
|
3191
3287
|
});
|
3192
3288
|
const typeName = getTransactionTypeName(transaction.type);
|
3289
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3193
3290
|
const { fee } = calculateTransactionFee({
|
3194
|
-
|
3291
|
+
gasPrice,
|
3195
3292
|
rawPayload,
|
3293
|
+
tip,
|
3196
3294
|
consensusParameters: {
|
3197
3295
|
gasCosts,
|
3296
|
+
maxGasPerTx,
|
3198
3297
|
feeParams: {
|
3199
3298
|
gasPerByte,
|
3200
3299
|
gasPriceFactor
|
@@ -3254,7 +3353,7 @@ var TransactionResponse = class {
|
|
3254
3353
|
/** Current provider */
|
3255
3354
|
provider;
|
3256
3355
|
/** Gas used on the transaction */
|
3257
|
-
gasUsed =
|
3356
|
+
gasUsed = bn15(0);
|
3258
3357
|
/** The graphql Transaction with receipts object. */
|
3259
3358
|
gqlTransaction;
|
3260
3359
|
abis;
|
@@ -3332,8 +3431,13 @@ var TransactionResponse = class {
|
|
3332
3431
|
const decodedTransaction = this.decodeTransaction(
|
3333
3432
|
transaction
|
3334
3433
|
);
|
3335
|
-
|
3336
|
-
|
3434
|
+
let txReceipts = [];
|
3435
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3436
|
+
txReceipts = transaction.status.receipts;
|
3437
|
+
}
|
3438
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3439
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3440
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3337
3441
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3338
3442
|
const transactionSummary = assembleTransactionSummary({
|
3339
3443
|
id: this.id,
|
@@ -3345,7 +3449,9 @@ var TransactionResponse = class {
|
|
3345
3449
|
gasPriceFactor,
|
3346
3450
|
abiMap: contractsAbiMap,
|
3347
3451
|
maxInputs,
|
3348
|
-
gasCosts
|
3452
|
+
gasCosts,
|
3453
|
+
maxGasPerTx,
|
3454
|
+
gasPrice
|
3349
3455
|
});
|
3350
3456
|
return transactionSummary;
|
3351
3457
|
}
|
@@ -3472,29 +3578,29 @@ var processGqlChain = (chain) => {
|
|
3472
3578
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3473
3579
|
return {
|
3474
3580
|
name,
|
3475
|
-
baseChainHeight:
|
3581
|
+
baseChainHeight: bn16(daHeight),
|
3476
3582
|
consensusParameters: {
|
3477
|
-
contractMaxSize:
|
3478
|
-
maxInputs:
|
3479
|
-
maxOutputs:
|
3480
|
-
maxWitnesses:
|
3481
|
-
maxGasPerTx:
|
3482
|
-
maxScriptLength:
|
3483
|
-
maxScriptDataLength:
|
3484
|
-
maxStorageSlots:
|
3485
|
-
maxPredicateLength:
|
3486
|
-
maxPredicateDataLength:
|
3487
|
-
maxGasPerPredicate:
|
3488
|
-
gasPriceFactor:
|
3489
|
-
gasPerByte:
|
3490
|
-
maxMessageDataLength:
|
3491
|
-
chainId:
|
3583
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3584
|
+
maxInputs: bn16(txParams.maxInputs),
|
3585
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3586
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3587
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3588
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3589
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3590
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3591
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3592
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3593
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3594
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3595
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3596
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3597
|
+
chainId: bn16(consensusParameters.chainId),
|
3492
3598
|
gasCosts
|
3493
3599
|
},
|
3494
3600
|
gasCosts,
|
3495
3601
|
latestBlock: {
|
3496
3602
|
id: latestBlock.id,
|
3497
|
-
height:
|
3603
|
+
height: bn16(latestBlock.height),
|
3498
3604
|
time: latestBlock.header.time,
|
3499
3605
|
transactions: latestBlock.transactions.map((i) => ({
|
3500
3606
|
id: i.id
|
@@ -3588,10 +3694,8 @@ var _Provider = class {
|
|
3588
3694
|
* Returns some helpful parameters related to gas fees.
|
3589
3695
|
*/
|
3590
3696
|
getGasConfig() {
|
3591
|
-
const { minGasPrice } = this.getNode();
|
3592
3697
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3593
3698
|
return {
|
3594
|
-
minGasPrice,
|
3595
3699
|
maxGasPerTx,
|
3596
3700
|
maxGasPerPredicate,
|
3597
3701
|
gasPriceFactor,
|
@@ -3689,7 +3793,7 @@ var _Provider = class {
|
|
3689
3793
|
*/
|
3690
3794
|
async getBlockNumber() {
|
3691
3795
|
const { chain } = await this.operations.getChain();
|
3692
|
-
return
|
3796
|
+
return bn16(chain.latestBlock.height, 10);
|
3693
3797
|
}
|
3694
3798
|
/**
|
3695
3799
|
* Returns the chain information.
|
@@ -3699,13 +3803,11 @@ var _Provider = class {
|
|
3699
3803
|
async fetchNode() {
|
3700
3804
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3701
3805
|
const processedNodeInfo = {
|
3702
|
-
maxDepth:
|
3703
|
-
maxTx:
|
3704
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3806
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3807
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3705
3808
|
nodeVersion: nodeInfo.nodeVersion,
|
3706
3809
|
utxoValidation: nodeInfo.utxoValidation,
|
3707
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3708
|
-
peers: nodeInfo.peers
|
3810
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3709
3811
|
};
|
3710
3812
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3711
3813
|
return processedNodeInfo;
|
@@ -3791,14 +3893,13 @@ var _Provider = class {
|
|
3791
3893
|
return this.estimateTxDependencies(transactionRequest);
|
3792
3894
|
}
|
3793
3895
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3794
|
-
const { dryRun:
|
3795
|
-
encodedTransaction,
|
3896
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3897
|
+
encodedTransactions: encodedTransaction,
|
3796
3898
|
utxoValidation: utxoValidation || false
|
3797
3899
|
});
|
3798
|
-
const receipts =
|
3799
|
-
|
3800
|
-
|
3801
|
-
};
|
3900
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3901
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3902
|
+
return { receipts, dryrunStatus: status };
|
3802
3903
|
}
|
3803
3904
|
/**
|
3804
3905
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3824,7 +3925,7 @@ var _Provider = class {
|
|
3824
3925
|
} = response;
|
3825
3926
|
if (inputs) {
|
3826
3927
|
inputs.forEach((input, index) => {
|
3827
|
-
if ("predicateGasUsed" in input &&
|
3928
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3828
3929
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3829
3930
|
}
|
3830
3931
|
});
|
@@ -3837,9 +3938,6 @@ var _Provider = class {
|
|
3837
3938
|
* If there are missing variable outputs,
|
3838
3939
|
* `addVariableOutputs` is called on the transaction.
|
3839
3940
|
*
|
3840
|
-
* @privateRemarks
|
3841
|
-
* TODO: Investigate support for missing contract IDs
|
3842
|
-
* TODO: Add support for missing output messages
|
3843
3941
|
*
|
3844
3942
|
* @param transactionRequest - The transaction request object.
|
3845
3943
|
* @returns A promise.
|
@@ -3852,16 +3950,19 @@ var _Provider = class {
|
|
3852
3950
|
missingContractIds: []
|
3853
3951
|
};
|
3854
3952
|
}
|
3855
|
-
await this.estimatePredicates(transactionRequest);
|
3856
3953
|
let receipts = [];
|
3857
3954
|
const missingContractIds = [];
|
3858
3955
|
let outputVariables = 0;
|
3956
|
+
let dryrunStatus;
|
3859
3957
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3860
|
-
const {
|
3861
|
-
|
3958
|
+
const {
|
3959
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3960
|
+
} = await this.operations.dryRun({
|
3961
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3862
3962
|
utxoValidation: false
|
3863
3963
|
});
|
3864
|
-
receipts =
|
3964
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3965
|
+
dryrunStatus = status;
|
3865
3966
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3866
3967
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3867
3968
|
if (hasMissingOutputs) {
|
@@ -3871,6 +3972,10 @@ var _Provider = class {
|
|
3871
3972
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3872
3973
|
missingContractIds.push(contractId);
|
3873
3974
|
});
|
3975
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3976
|
+
transactionRequest
|
3977
|
+
});
|
3978
|
+
transactionRequest.maxFee = maxFee;
|
3874
3979
|
} else {
|
3875
3980
|
break;
|
3876
3981
|
}
|
@@ -3878,7 +3983,139 @@ var _Provider = class {
|
|
3878
3983
|
return {
|
3879
3984
|
receipts,
|
3880
3985
|
outputVariables,
|
3881
|
-
missingContractIds
|
3986
|
+
missingContractIds,
|
3987
|
+
dryrunStatus
|
3988
|
+
};
|
3989
|
+
}
|
3990
|
+
/**
|
3991
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3992
|
+
*
|
3993
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3994
|
+
* further modifications are identified. The method iteratively updates these transactions
|
3995
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3996
|
+
*
|
3997
|
+
* @param transactionRequests - Array of transaction request objects.
|
3998
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
3999
|
+
*/
|
4000
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4001
|
+
const results = transactionRequests.map(() => ({
|
4002
|
+
receipts: [],
|
4003
|
+
outputVariables: 0,
|
4004
|
+
missingContractIds: [],
|
4005
|
+
dryrunStatus: void 0
|
4006
|
+
}));
|
4007
|
+
const allRequests = clone3(transactionRequests);
|
4008
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4009
|
+
allRequests.forEach((req, index) => {
|
4010
|
+
if (req.type === TransactionType8.Script) {
|
4011
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4012
|
+
}
|
4013
|
+
});
|
4014
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4015
|
+
let attempt = 0;
|
4016
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4017
|
+
const encodedTransactions = transactionsToProcess.map(
|
4018
|
+
(index) => serializedTransactionsMap.get(index)
|
4019
|
+
);
|
4020
|
+
const dryRunResults = await this.operations.dryRun({
|
4021
|
+
encodedTransactions,
|
4022
|
+
utxoValidation: false
|
4023
|
+
});
|
4024
|
+
const nextRoundTransactions = [];
|
4025
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4026
|
+
const currentResultIndex = transactionsToProcess[i];
|
4027
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4028
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4029
|
+
results[currentResultIndex].dryrunStatus = status;
|
4030
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4031
|
+
results[currentResultIndex].receipts
|
4032
|
+
);
|
4033
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4034
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4035
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4036
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4037
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4038
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4039
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4040
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4041
|
+
});
|
4042
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4043
|
+
transactionRequest: requestToProcess
|
4044
|
+
});
|
4045
|
+
requestToProcess.maxFee = maxFee;
|
4046
|
+
serializedTransactionsMap.set(
|
4047
|
+
currentResultIndex,
|
4048
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4049
|
+
);
|
4050
|
+
nextRoundTransactions.push(currentResultIndex);
|
4051
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4052
|
+
}
|
4053
|
+
}
|
4054
|
+
transactionsToProcess = nextRoundTransactions;
|
4055
|
+
attempt += 1;
|
4056
|
+
}
|
4057
|
+
return results;
|
4058
|
+
}
|
4059
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4060
|
+
if (estimateTxDependencies) {
|
4061
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4062
|
+
}
|
4063
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4064
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4065
|
+
encodedTransactions,
|
4066
|
+
utxoValidation: utxoValidation || false
|
4067
|
+
});
|
4068
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4069
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4070
|
+
return { receipts, dryrunStatus: status };
|
4071
|
+
});
|
4072
|
+
return results;
|
4073
|
+
}
|
4074
|
+
/**
|
4075
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
4076
|
+
* @param transactionRequest - The transaction request object.
|
4077
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4078
|
+
*/
|
4079
|
+
async estimateTxGasAndFee(params) {
|
4080
|
+
const { transactionRequest } = params;
|
4081
|
+
let { gasPrice } = params;
|
4082
|
+
const chainInfo = this.getChain();
|
4083
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4084
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4085
|
+
if (!gasPrice) {
|
4086
|
+
gasPrice = await this.estimateGasPrice(10);
|
4087
|
+
}
|
4088
|
+
const minFee = calculateGasFee({
|
4089
|
+
gasPrice: bn16(gasPrice),
|
4090
|
+
gas: minGas,
|
4091
|
+
priceFactor: gasPriceFactor,
|
4092
|
+
tip: transactionRequest.tip
|
4093
|
+
}).add(1);
|
4094
|
+
let gasLimit = bn16(0);
|
4095
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
4096
|
+
gasLimit = transactionRequest.gasLimit;
|
4097
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4098
|
+
transactionRequest.gasLimit = minGas;
|
4099
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4100
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4101
|
+
);
|
4102
|
+
gasLimit = transactionRequest.gasLimit;
|
4103
|
+
}
|
4104
|
+
}
|
4105
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4106
|
+
const maxFee = calculateGasFee({
|
4107
|
+
gasPrice: bn16(gasPrice),
|
4108
|
+
gas: maxGas,
|
4109
|
+
priceFactor: gasPriceFactor,
|
4110
|
+
tip: transactionRequest.tip
|
4111
|
+
}).add(1);
|
4112
|
+
return {
|
4113
|
+
minGas,
|
4114
|
+
minFee,
|
4115
|
+
maxGas,
|
4116
|
+
maxFee,
|
4117
|
+
gasPrice,
|
4118
|
+
gasLimit
|
3882
4119
|
};
|
3883
4120
|
}
|
3884
4121
|
/**
|
@@ -3896,15 +4133,17 @@ var _Provider = class {
|
|
3896
4133
|
if (estimateTxDependencies) {
|
3897
4134
|
return this.estimateTxDependencies(transactionRequest);
|
3898
4135
|
}
|
3899
|
-
const
|
3900
|
-
const { dryRun:
|
3901
|
-
|
4136
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4137
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4138
|
+
encodedTransactions,
|
3902
4139
|
utxoValidation: true
|
3903
4140
|
});
|
3904
|
-
const
|
3905
|
-
|
3906
|
-
receipts
|
3907
|
-
|
4141
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4142
|
+
const { id, receipts, status } = dryRunStatus;
|
4143
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4144
|
+
return { id, receipts: processedReceipts, status };
|
4145
|
+
});
|
4146
|
+
return { receipts: callResult[0].receipts };
|
3908
4147
|
}
|
3909
4148
|
/**
|
3910
4149
|
* Returns a transaction cost to enable user
|
@@ -3921,80 +4160,79 @@ var _Provider = class {
|
|
3921
4160
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3922
4161
|
* @returns A promise that resolves to the transaction cost object.
|
3923
4162
|
*/
|
3924
|
-
async getTransactionCost(transactionRequestLike,
|
3925
|
-
estimateTxDependencies = true,
|
3926
|
-
estimatePredicates = true,
|
3927
|
-
resourcesOwner,
|
3928
|
-
signatureCallback
|
3929
|
-
} = {}) {
|
4163
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3930
4164
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3931
|
-
const chainInfo = this.getChain();
|
3932
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3933
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3934
4165
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3935
4166
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3936
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4167
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3937
4168
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3938
|
-
|
3939
|
-
|
3940
|
-
|
3941
|
-
|
3942
|
-
|
3943
|
-
|
3944
|
-
}
|
3945
|
-
await this.estimatePredicates(txRequestClone);
|
4169
|
+
txRequestClone.maxFee = bn16(0);
|
4170
|
+
if (isScriptTransaction) {
|
4171
|
+
txRequestClone.gasLimit = bn16(0);
|
4172
|
+
}
|
4173
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4174
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3946
4175
|
}
|
4176
|
+
const signedRequest = clone3(txRequestClone);
|
4177
|
+
let addedSignatures = 0;
|
3947
4178
|
if (signatureCallback && isScriptTransaction) {
|
3948
|
-
|
4179
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4180
|
+
await signatureCallback(signedRequest);
|
4181
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3949
4182
|
}
|
3950
|
-
|
3951
|
-
|
4183
|
+
await this.estimatePredicates(signedRequest);
|
4184
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4185
|
+
transactionRequest: signedRequest
|
4186
|
+
});
|
3952
4187
|
let receipts = [];
|
3953
4188
|
let missingContractIds = [];
|
3954
4189
|
let outputVariables = 0;
|
3955
|
-
|
3956
|
-
|
3957
|
-
|
4190
|
+
let gasUsed = bn16(0);
|
4191
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4192
|
+
txRequestClone.maxFee = maxFee;
|
4193
|
+
if (isScriptTransaction) {
|
4194
|
+
txRequestClone.gasLimit = gasLimit;
|
4195
|
+
if (signatureCallback) {
|
4196
|
+
await signatureCallback(txRequestClone);
|
4197
|
+
}
|
3958
4198
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3959
4199
|
receipts = result.receipts;
|
3960
4200
|
outputVariables = result.outputVariables;
|
3961
4201
|
missingContractIds = result.missingContractIds;
|
4202
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4203
|
+
txRequestClone.gasLimit = gasUsed;
|
4204
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4205
|
+
transactionRequest: txRequestClone,
|
4206
|
+
gasPrice
|
4207
|
+
}));
|
3962
4208
|
}
|
3963
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3964
|
-
const usedFee = calculatePriceWithFactor(
|
3965
|
-
gasUsed,
|
3966
|
-
gasPrice,
|
3967
|
-
gasPriceFactor
|
3968
|
-
).normalizeZeroToOne();
|
3969
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3970
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3971
4209
|
return {
|
3972
4210
|
requiredQuantities: allQuantities,
|
3973
4211
|
receipts,
|
3974
4212
|
gasUsed,
|
3975
|
-
minGasPrice,
|
3976
4213
|
gasPrice,
|
3977
4214
|
minGas,
|
3978
4215
|
maxGas,
|
3979
|
-
usedFee,
|
3980
4216
|
minFee,
|
3981
4217
|
maxFee,
|
3982
|
-
estimatedInputs: txRequestClone.inputs,
|
3983
4218
|
outputVariables,
|
3984
|
-
missingContractIds
|
4219
|
+
missingContractIds,
|
4220
|
+
addedSignatures,
|
4221
|
+
estimatedPredicates: txRequestClone.inputs
|
3985
4222
|
};
|
3986
4223
|
}
|
3987
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4224
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
3988
4225
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
3989
4226
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
3990
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4227
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4228
|
+
quantitiesToContract
|
4229
|
+
});
|
3991
4230
|
transactionRequest.addResources(
|
3992
4231
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
3993
4232
|
);
|
3994
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
3995
|
-
|
3996
|
-
|
3997
|
-
);
|
4233
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4234
|
+
quantitiesToContract
|
4235
|
+
});
|
3998
4236
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
3999
4237
|
return {
|
4000
4238
|
resources,
|
@@ -4016,11 +4254,10 @@ var _Provider = class {
|
|
4016
4254
|
return coins.map((coin) => ({
|
4017
4255
|
id: coin.utxoId,
|
4018
4256
|
assetId: coin.assetId,
|
4019
|
-
amount:
|
4257
|
+
amount: bn16(coin.amount),
|
4020
4258
|
owner: Address2.fromAddressOrString(coin.owner),
|
4021
|
-
|
4022
|
-
|
4023
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4259
|
+
blockCreated: bn16(coin.blockCreated),
|
4260
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4024
4261
|
}));
|
4025
4262
|
}
|
4026
4263
|
/**
|
@@ -4057,9 +4294,9 @@ var _Provider = class {
|
|
4057
4294
|
switch (coin.__typename) {
|
4058
4295
|
case "MessageCoin":
|
4059
4296
|
return {
|
4060
|
-
amount:
|
4297
|
+
amount: bn16(coin.amount),
|
4061
4298
|
assetId: coin.assetId,
|
4062
|
-
daHeight:
|
4299
|
+
daHeight: bn16(coin.daHeight),
|
4063
4300
|
sender: Address2.fromAddressOrString(coin.sender),
|
4064
4301
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4065
4302
|
nonce: coin.nonce
|
@@ -4067,12 +4304,11 @@ var _Provider = class {
|
|
4067
4304
|
case "Coin":
|
4068
4305
|
return {
|
4069
4306
|
id: coin.utxoId,
|
4070
|
-
amount:
|
4307
|
+
amount: bn16(coin.amount),
|
4071
4308
|
assetId: coin.assetId,
|
4072
4309
|
owner: Address2.fromAddressOrString(coin.owner),
|
4073
|
-
|
4074
|
-
|
4075
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4310
|
+
blockCreated: bn16(coin.blockCreated),
|
4311
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4076
4312
|
};
|
4077
4313
|
default:
|
4078
4314
|
return null;
|
@@ -4089,13 +4325,13 @@ var _Provider = class {
|
|
4089
4325
|
async getBlock(idOrHeight) {
|
4090
4326
|
let variables;
|
4091
4327
|
if (typeof idOrHeight === "number") {
|
4092
|
-
variables = { height:
|
4328
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4093
4329
|
} else if (idOrHeight === "latest") {
|
4094
4330
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4095
4331
|
} else if (idOrHeight.length === 66) {
|
4096
4332
|
variables = { blockId: idOrHeight };
|
4097
4333
|
} else {
|
4098
|
-
variables = { blockId:
|
4334
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4099
4335
|
}
|
4100
4336
|
const { block } = await this.operations.getBlock(variables);
|
4101
4337
|
if (!block) {
|
@@ -4103,7 +4339,7 @@ var _Provider = class {
|
|
4103
4339
|
}
|
4104
4340
|
return {
|
4105
4341
|
id: block.id,
|
4106
|
-
height:
|
4342
|
+
height: bn16(block.height),
|
4107
4343
|
time: block.header.time,
|
4108
4344
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4109
4345
|
};
|
@@ -4118,7 +4354,7 @@ var _Provider = class {
|
|
4118
4354
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4119
4355
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4120
4356
|
id: block.id,
|
4121
|
-
height:
|
4357
|
+
height: bn16(block.height),
|
4122
4358
|
time: block.header.time,
|
4123
4359
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4124
4360
|
}));
|
@@ -4133,7 +4369,7 @@ var _Provider = class {
|
|
4133
4369
|
async getBlockWithTransactions(idOrHeight) {
|
4134
4370
|
let variables;
|
4135
4371
|
if (typeof idOrHeight === "number") {
|
4136
|
-
variables = { blockHeight:
|
4372
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4137
4373
|
} else if (idOrHeight === "latest") {
|
4138
4374
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4139
4375
|
} else {
|
@@ -4145,7 +4381,7 @@ var _Provider = class {
|
|
4145
4381
|
}
|
4146
4382
|
return {
|
4147
4383
|
id: block.id,
|
4148
|
-
height:
|
4384
|
+
height: bn16(block.height, 10),
|
4149
4385
|
time: block.header.time,
|
4150
4386
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4151
4387
|
transactions: block.transactions.map(
|
@@ -4194,7 +4430,7 @@ var _Provider = class {
|
|
4194
4430
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4195
4431
|
asset: hexlify12(assetId)
|
4196
4432
|
});
|
4197
|
-
return
|
4433
|
+
return bn16(contractBalance.amount, 10);
|
4198
4434
|
}
|
4199
4435
|
/**
|
4200
4436
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4208,7 +4444,7 @@ var _Provider = class {
|
|
4208
4444
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4209
4445
|
assetId: hexlify12(assetId)
|
4210
4446
|
});
|
4211
|
-
return
|
4447
|
+
return bn16(balance.amount, 10);
|
4212
4448
|
}
|
4213
4449
|
/**
|
4214
4450
|
* Returns balances for the given owner.
|
@@ -4226,7 +4462,7 @@ var _Provider = class {
|
|
4226
4462
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4227
4463
|
return balances.map((balance) => ({
|
4228
4464
|
assetId: balance.assetId,
|
4229
|
-
amount:
|
4465
|
+
amount: bn16(balance.amount)
|
4230
4466
|
}));
|
4231
4467
|
}
|
4232
4468
|
/**
|
@@ -4248,15 +4484,15 @@ var _Provider = class {
|
|
4248
4484
|
sender: message.sender,
|
4249
4485
|
recipient: message.recipient,
|
4250
4486
|
nonce: message.nonce,
|
4251
|
-
amount:
|
4487
|
+
amount: bn16(message.amount),
|
4252
4488
|
data: message.data
|
4253
4489
|
}),
|
4254
4490
|
sender: Address2.fromAddressOrString(message.sender),
|
4255
4491
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4256
4492
|
nonce: message.nonce,
|
4257
|
-
amount:
|
4493
|
+
amount: bn16(message.amount),
|
4258
4494
|
data: InputMessageCoder.decodeData(message.data),
|
4259
|
-
daHeight:
|
4495
|
+
daHeight: bn16(message.daHeight)
|
4260
4496
|
}));
|
4261
4497
|
}
|
4262
4498
|
/**
|
@@ -4309,44 +4545,60 @@ var _Provider = class {
|
|
4309
4545
|
} = result.messageProof;
|
4310
4546
|
return {
|
4311
4547
|
messageProof: {
|
4312
|
-
proofIndex:
|
4548
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4313
4549
|
proofSet: messageProof.proofSet
|
4314
4550
|
},
|
4315
4551
|
blockProof: {
|
4316
|
-
proofIndex:
|
4552
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4317
4553
|
proofSet: blockProof.proofSet
|
4318
4554
|
},
|
4319
4555
|
messageBlockHeader: {
|
4320
4556
|
id: messageBlockHeader.id,
|
4321
|
-
daHeight:
|
4322
|
-
transactionsCount:
|
4557
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4558
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4323
4559
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4324
|
-
height:
|
4560
|
+
height: bn16(messageBlockHeader.height),
|
4325
4561
|
prevRoot: messageBlockHeader.prevRoot,
|
4326
4562
|
time: messageBlockHeader.time,
|
4327
4563
|
applicationHash: messageBlockHeader.applicationHash,
|
4328
|
-
|
4329
|
-
|
4564
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4565
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4566
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4567
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4568
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4330
4569
|
},
|
4331
4570
|
commitBlockHeader: {
|
4332
4571
|
id: commitBlockHeader.id,
|
4333
|
-
daHeight:
|
4334
|
-
transactionsCount:
|
4572
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4573
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4335
4574
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4336
|
-
height:
|
4575
|
+
height: bn16(commitBlockHeader.height),
|
4337
4576
|
prevRoot: commitBlockHeader.prevRoot,
|
4338
4577
|
time: commitBlockHeader.time,
|
4339
4578
|
applicationHash: commitBlockHeader.applicationHash,
|
4340
|
-
|
4341
|
-
|
4579
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4580
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4581
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4582
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4583
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4342
4584
|
},
|
4343
4585
|
sender: Address2.fromAddressOrString(sender),
|
4344
4586
|
recipient: Address2.fromAddressOrString(recipient),
|
4345
4587
|
nonce,
|
4346
|
-
amount:
|
4588
|
+
amount: bn16(amount),
|
4347
4589
|
data
|
4348
4590
|
};
|
4349
4591
|
}
|
4592
|
+
async getLatestGasPrice() {
|
4593
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4594
|
+
return bn16(latestGasPrice.gasPrice);
|
4595
|
+
}
|
4596
|
+
async estimateGasPrice(blockHorizon) {
|
4597
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4598
|
+
blockHorizon: String(blockHorizon)
|
4599
|
+
});
|
4600
|
+
return bn16(estimateGasPrice.gasPrice);
|
4601
|
+
}
|
4350
4602
|
/**
|
4351
4603
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4352
4604
|
*
|
@@ -4366,10 +4618,10 @@ var _Provider = class {
|
|
4366
4618
|
*/
|
4367
4619
|
async produceBlocks(amount, startTime) {
|
4368
4620
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4369
|
-
blocksToProduce:
|
4621
|
+
blocksToProduce: bn16(amount).toString(10),
|
4370
4622
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4371
4623
|
});
|
4372
|
-
return
|
4624
|
+
return bn16(latestBlockHeight);
|
4373
4625
|
}
|
4374
4626
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4375
4627
|
async getTransactionResponse(transactionId) {
|
@@ -4383,7 +4635,7 @@ cacheInputs_fn = function(inputs) {
|
|
4383
4635
|
return;
|
4384
4636
|
}
|
4385
4637
|
inputs.forEach((input) => {
|
4386
|
-
if (input.type ===
|
4638
|
+
if (input.type === InputType7.Coin) {
|
4387
4639
|
this.cache?.set(input.id);
|
4388
4640
|
}
|
4389
4641
|
});
|
@@ -4393,7 +4645,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4393
4645
|
|
4394
4646
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4395
4647
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4396
|
-
import { bn as
|
4648
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4397
4649
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4398
4650
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4399
4651
|
|
@@ -4639,36 +4891,33 @@ var Account = class extends AbstractAccount {
|
|
4639
4891
|
* @param fee - The estimated transaction fee.
|
4640
4892
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4641
4893
|
*/
|
4642
|
-
async fund(request,
|
4643
|
-
const
|
4644
|
-
|
4894
|
+
async fund(request, params) {
|
4895
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4896
|
+
const txRequest = request;
|
4897
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4898
|
+
amount: bn18(fee),
|
4645
4899
|
assetId: BaseAssetId3,
|
4646
|
-
coinQuantities
|
4900
|
+
coinQuantities: requiredQuantities
|
4647
4901
|
});
|
4648
4902
|
const quantitiesDict = {};
|
4649
|
-
|
4903
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4650
4904
|
quantitiesDict[assetId] = {
|
4651
4905
|
required: amount,
|
4652
|
-
owned:
|
4906
|
+
owned: bn18(0)
|
4653
4907
|
};
|
4654
4908
|
});
|
4655
|
-
|
4656
|
-
const cachedMessages = [];
|
4657
|
-
const owner = this.address.toB256();
|
4658
|
-
request.inputs.forEach((input) => {
|
4909
|
+
txRequest.inputs.forEach((input) => {
|
4659
4910
|
const isResource = "amount" in input;
|
4660
4911
|
if (isResource) {
|
4661
4912
|
const isCoin2 = "owner" in input;
|
4662
4913
|
if (isCoin2) {
|
4663
4914
|
const assetId = String(input.assetId);
|
4664
|
-
if (
|
4665
|
-
const amount =
|
4915
|
+
if (quantitiesDict[assetId]) {
|
4916
|
+
const amount = bn18(input.amount);
|
4666
4917
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4667
|
-
cachedUtxos.push(input.id);
|
4668
4918
|
}
|
4669
|
-
} else if (input.
|
4919
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4670
4920
|
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4671
|
-
cachedMessages.push(input.nonce);
|
4672
4921
|
}
|
4673
4922
|
}
|
4674
4923
|
});
|
@@ -4683,12 +4932,23 @@ var Account = class extends AbstractAccount {
|
|
4683
4932
|
});
|
4684
4933
|
const needsToBeFunded = missingQuantities.length;
|
4685
4934
|
if (needsToBeFunded) {
|
4686
|
-
const
|
4687
|
-
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4935
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4936
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4937
|
+
txRequest.addResources(resources);
|
4938
|
+
}
|
4939
|
+
txRequest.shiftPredicateData();
|
4940
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4941
|
+
const requestToBeReEstimate = clone4(txRequest);
|
4942
|
+
if (addedSignatures) {
|
4943
|
+
Array.from({ length: addedSignatures }).forEach(
|
4944
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4945
|
+
);
|
4691
4946
|
}
|
4947
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4948
|
+
transactionRequest: requestToBeReEstimate
|
4949
|
+
});
|
4950
|
+
txRequest.maxFee = maxFee;
|
4951
|
+
return txRequest;
|
4692
4952
|
}
|
4693
4953
|
/**
|
4694
4954
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4696,28 +4956,25 @@ var Account = class extends AbstractAccount {
|
|
4696
4956
|
* @param destination - The address of the destination.
|
4697
4957
|
* @param amount - The amount of coins to transfer.
|
4698
4958
|
* @param assetId - The asset ID of the coins to transfer.
|
4699
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4959
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4700
4960
|
* @returns A promise that resolves to the prepared transaction request.
|
4701
4961
|
*/
|
4702
4962
|
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4703
|
-
const
|
4704
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4705
|
-
const request = new ScriptTransactionRequest(params);
|
4963
|
+
const request = new ScriptTransactionRequest(txParams);
|
4706
4964
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4707
|
-
const
|
4965
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4708
4966
|
estimateTxDependencies: true,
|
4709
4967
|
resourcesOwner: this
|
4710
4968
|
});
|
4711
|
-
|
4712
|
-
|
4713
|
-
|
4714
|
-
|
4715
|
-
|
4716
|
-
|
4717
|
-
|
4718
|
-
|
4719
|
-
await this.fund(request,
|
4720
|
-
request.updatePredicateInputs(estimatedInputs);
|
4969
|
+
if ("gasLimit" in txParams) {
|
4970
|
+
this.validateGas({
|
4971
|
+
gasUsed: txCost.gasUsed,
|
4972
|
+
gasLimit: request.gasLimit
|
4973
|
+
});
|
4974
|
+
}
|
4975
|
+
request.gasLimit = txCost.gasUsed;
|
4976
|
+
request.maxFee = txCost.maxFee;
|
4977
|
+
await this.fund(request, txCost);
|
4721
4978
|
return request;
|
4722
4979
|
}
|
4723
4980
|
/**
|
@@ -4730,7 +4987,7 @@ var Account = class extends AbstractAccount {
|
|
4730
4987
|
* @returns A promise that resolves to the transaction response.
|
4731
4988
|
*/
|
4732
4989
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4733
|
-
if (
|
4990
|
+
if (bn18(amount).lte(0)) {
|
4734
4991
|
throw new FuelError15(
|
4735
4992
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4736
4993
|
"Transfer amount must be a positive number."
|
@@ -4749,38 +5006,37 @@ var Account = class extends AbstractAccount {
|
|
4749
5006
|
* @returns A promise that resolves to the transaction response.
|
4750
5007
|
*/
|
4751
5008
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4752
|
-
if (
|
5009
|
+
if (bn18(amount).lte(0)) {
|
4753
5010
|
throw new FuelError15(
|
4754
5011
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4755
5012
|
"Transfer amount must be a positive number."
|
4756
5013
|
);
|
4757
5014
|
}
|
4758
5015
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4759
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4760
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4761
5016
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4762
5017
|
hexlifiedContractId: contractAddress.toB256(),
|
4763
|
-
amountToTransfer:
|
5018
|
+
amountToTransfer: bn18(amount),
|
4764
5019
|
assetId
|
4765
5020
|
});
|
4766
5021
|
const request = new ScriptTransactionRequest({
|
4767
|
-
...
|
5022
|
+
...txParams,
|
4768
5023
|
script,
|
4769
5024
|
scriptData
|
4770
5025
|
});
|
4771
5026
|
request.addContractInputAndOutput(contractAddress);
|
4772
|
-
const
|
4773
|
-
|
4774
|
-
[{ amount:
|
4775
|
-
);
|
4776
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4777
|
-
this.validateGas({
|
4778
|
-
gasUsed,
|
4779
|
-
gasPrice: request.gasPrice,
|
4780
|
-
gasLimit: request.gasLimit,
|
4781
|
-
minGasPrice
|
5027
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5028
|
+
resourcesOwner: this,
|
5029
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
4782
5030
|
});
|
4783
|
-
|
5031
|
+
if (txParams.gasLimit) {
|
5032
|
+
this.validateGas({
|
5033
|
+
gasUsed: txCost.gasUsed,
|
5034
|
+
gasLimit: request.gasLimit
|
5035
|
+
});
|
5036
|
+
}
|
5037
|
+
request.gasLimit = txCost.gasUsed;
|
5038
|
+
request.maxFee = txCost.maxFee;
|
5039
|
+
await this.fund(request, txCost);
|
4784
5040
|
return this.sendTransaction(request);
|
4785
5041
|
}
|
4786
5042
|
/**
|
@@ -4792,34 +5048,31 @@ var Account = class extends AbstractAccount {
|
|
4792
5048
|
* @returns A promise that resolves to the transaction response.
|
4793
5049
|
*/
|
4794
5050
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4795
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4796
5051
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4797
5052
|
const recipientDataArray = arrayify14(
|
4798
5053
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4799
5054
|
);
|
4800
5055
|
const amountDataArray = arrayify14(
|
4801
|
-
"0x".concat(
|
5056
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
4802
5057
|
);
|
4803
5058
|
const script = new Uint8Array([
|
4804
5059
|
...arrayify14(withdrawScript.bytes),
|
4805
5060
|
...recipientDataArray,
|
4806
5061
|
...amountDataArray
|
4807
5062
|
]);
|
4808
|
-
const params = { script,
|
5063
|
+
const params = { script, ...txParams };
|
4809
5064
|
const request = new ScriptTransactionRequest(params);
|
4810
|
-
const
|
4811
|
-
const
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4815
|
-
|
4816
|
-
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4821
|
-
});
|
4822
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5065
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5066
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5067
|
+
if (txParams.gasLimit) {
|
5068
|
+
this.validateGas({
|
5069
|
+
gasUsed: txCost.gasUsed,
|
5070
|
+
gasLimit: request.gasLimit
|
5071
|
+
});
|
5072
|
+
}
|
5073
|
+
request.maxFee = txCost.maxFee;
|
5074
|
+
request.gasLimit = txCost.gasUsed;
|
5075
|
+
await this.fund(request, txCost);
|
4823
5076
|
return this.sendTransaction(request);
|
4824
5077
|
}
|
4825
5078
|
async signMessage(message) {
|
@@ -4877,18 +5130,7 @@ var Account = class extends AbstractAccount {
|
|
4877
5130
|
}
|
4878
5131
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4879
5132
|
}
|
4880
|
-
validateGas({
|
4881
|
-
gasUsed,
|
4882
|
-
gasPrice,
|
4883
|
-
gasLimit,
|
4884
|
-
minGasPrice
|
4885
|
-
}) {
|
4886
|
-
if (minGasPrice.gt(gasPrice)) {
|
4887
|
-
throw new FuelError15(
|
4888
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4889
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4890
|
-
);
|
4891
|
-
}
|
5133
|
+
validateGas({ gasUsed, gasLimit }) {
|
4892
5134
|
if (gasUsed.gt(gasLimit)) {
|
4893
5135
|
throw new FuelError15(
|
4894
5136
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -4900,7 +5142,7 @@ var Account = class extends AbstractAccount {
|
|
4900
5142
|
|
4901
5143
|
// src/signer/signer.ts
|
4902
5144
|
import { Address as Address4 } from "@fuel-ts/address";
|
4903
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5145
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
4904
5146
|
import { hash } from "@fuel-ts/hasher";
|
4905
5147
|
import { toBytes } from "@fuel-ts/math";
|
4906
5148
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -4993,7 +5235,7 @@ var Signer = class {
|
|
4993
5235
|
* @returns random 32-byte hashed
|
4994
5236
|
*/
|
4995
5237
|
static generatePrivateKey(entropy) {
|
4996
|
-
return entropy ? hash(concat3([
|
5238
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
4997
5239
|
}
|
4998
5240
|
/**
|
4999
5241
|
* Extended publicKey from a compact publicKey
|
@@ -5012,7 +5254,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5012
5254
|
import {
|
5013
5255
|
bufferFromString,
|
5014
5256
|
keccak256,
|
5015
|
-
randomBytes as
|
5257
|
+
randomBytes as randomBytes3,
|
5016
5258
|
scrypt,
|
5017
5259
|
stringFromBuffer,
|
5018
5260
|
decryptJsonWalletData,
|
@@ -5035,7 +5277,7 @@ var removeHexPrefix = (hexString) => {
|
|
5035
5277
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5036
5278
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5037
5279
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5038
|
-
const salt =
|
5280
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5039
5281
|
const key = scrypt({
|
5040
5282
|
password: bufferFromString(password),
|
5041
5283
|
salt,
|
@@ -5044,7 +5286,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5044
5286
|
r: DEFAULT_KDF_PARAMS_R,
|
5045
5287
|
p: DEFAULT_KDF_PARAMS_P
|
5046
5288
|
});
|
5047
|
-
const iv =
|
5289
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5048
5290
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5049
5291
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5050
5292
|
const macHashUint8Array = keccak256(data);
|
@@ -5180,7 +5422,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5180
5422
|
* @param transactionRequestLike - The transaction request to send.
|
5181
5423
|
* @returns A promise that resolves to the TransactionResponse object.
|
5182
5424
|
*/
|
5183
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5425
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5184
5426
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5185
5427
|
if (estimateTxDependencies) {
|
5186
5428
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5221,12 +5463,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5221
5463
|
// src/hdwallet/hdwallet.ts
|
5222
5464
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5223
5465
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5224
|
-
import { bn as
|
5466
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5225
5467
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5226
5468
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5227
5469
|
|
5228
5470
|
// src/mnemonic/mnemonic.ts
|
5229
|
-
import { randomBytes as
|
5471
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5230
5472
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5231
5473
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5232
5474
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7581,7 +7823,7 @@ var Mnemonic = class {
|
|
7581
7823
|
* @returns A randomly generated mnemonic
|
7582
7824
|
*/
|
7583
7825
|
static generate(size = 32, extraEntropy = "") {
|
7584
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7826
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7585
7827
|
return Mnemonic.entropyToMnemonic(entropy);
|
7586
7828
|
}
|
7587
7829
|
};
|
@@ -7687,7 +7929,7 @@ var HDWallet = class {
|
|
7687
7929
|
const IR = bytes.slice(32);
|
7688
7930
|
if (privateKey) {
|
7689
7931
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7690
|
-
const ki =
|
7932
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7691
7933
|
return new HDWallet({
|
7692
7934
|
privateKey: ki,
|
7693
7935
|
chainCode: IR,
|
@@ -7952,20 +8194,21 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7952
8194
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7953
8195
|
|
7954
8196
|
// src/test-utils/seedTestWallet.ts
|
7955
|
-
import { randomBytes as
|
8197
|
+
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
7956
8198
|
var seedTestWallet = async (wallet, quantities) => {
|
7957
8199
|
const genesisWallet = new WalletUnlocked(
|
7958
|
-
process.env.GENESIS_SECRET ||
|
8200
|
+
process.env.GENESIS_SECRET || randomBytes5(32),
|
7959
8201
|
wallet.provider
|
7960
8202
|
);
|
7961
|
-
const
|
7962
|
-
|
7963
|
-
|
7964
|
-
|
7965
|
-
gasPrice: minGasPrice
|
8203
|
+
const request = new ScriptTransactionRequest();
|
8204
|
+
quantities.forEach((quantity) => {
|
8205
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8206
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7966
8207
|
});
|
7967
|
-
|
7968
|
-
|
8208
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8209
|
+
request.gasLimit = txCost.gasUsed;
|
8210
|
+
request.maxFee = txCost.maxFee;
|
8211
|
+
await genesisWallet.fund(request, txCost);
|
7969
8212
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
7970
8213
|
};
|
7971
8214
|
|
@@ -7980,11 +8223,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7980
8223
|
|
7981
8224
|
// src/test-utils/launchNode.ts
|
7982
8225
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
7983
|
-
import {
|
7984
|
-
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8226
|
+
import { defaultChainConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
7985
8227
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
7986
8228
|
import { spawn } from "child_process";
|
7987
8229
|
import { randomUUID } from "crypto";
|
8230
|
+
import { randomBytes as randomBytes6 } from "ethers";
|
7988
8231
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
7989
8232
|
import os from "os";
|
7990
8233
|
import path from "path";
|
@@ -8033,12 +8276,12 @@ var launchNode = async ({
|
|
8033
8276
|
// eslint-disable-next-line no-async-promise-executor
|
8034
8277
|
new Promise(async (resolve, reject) => {
|
8035
8278
|
const remainingArgs = extractRemainingArgs(args, [
|
8036
|
-
"--
|
8279
|
+
"--snapshot",
|
8037
8280
|
"--consensus-key",
|
8038
8281
|
"--db-type",
|
8039
8282
|
"--poa-instant"
|
8040
8283
|
]);
|
8041
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8284
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8042
8285
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8043
8286
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8044
8287
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8057,36 +8300,54 @@ var launchNode = async ({
|
|
8057
8300
|
let chainConfigPathToUse;
|
8058
8301
|
const prefix = basePath || os.tmpdir();
|
8059
8302
|
const suffix = basePath ? "" : randomUUID();
|
8060
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8303
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "chainConfigs");
|
8061
8304
|
if (chainConfigPath) {
|
8062
8305
|
chainConfigPathToUse = chainConfigPath;
|
8063
8306
|
} else {
|
8064
8307
|
if (!existsSync(tempDirPath)) {
|
8065
8308
|
mkdirSync(tempDirPath, { recursive: true });
|
8066
8309
|
}
|
8067
|
-
|
8068
|
-
|
8310
|
+
let { stateConfigJson } = defaultChainConfigs;
|
8311
|
+
const { chainConfigJson, metadataJson } = defaultChainConfigs;
|
8312
|
+
stateConfigJson = {
|
8313
|
+
...stateConfigJson,
|
8314
|
+
coins: [
|
8315
|
+
...stateConfigJson.coins.map((coin) => ({
|
8316
|
+
...coin,
|
8317
|
+
amount: "18446744073709551615"
|
8318
|
+
}))
|
8319
|
+
],
|
8320
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8321
|
+
...message,
|
8322
|
+
amount: "18446744073709551615"
|
8323
|
+
}))
|
8324
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8325
|
+
};
|
8069
8326
|
if (!process.env.GENESIS_SECRET) {
|
8070
8327
|
const pk = Signer.generatePrivateKey();
|
8071
8328
|
const signer = new Signer(pk);
|
8072
8329
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8073
|
-
|
8074
|
-
|
8075
|
-
|
8076
|
-
|
8077
|
-
|
8078
|
-
|
8079
|
-
|
8080
|
-
|
8081
|
-
|
8082
|
-
|
8083
|
-
}
|
8084
|
-
]
|
8085
|
-
}
|
8086
|
-
};
|
8330
|
+
stateConfigJson.coins.push({
|
8331
|
+
tx_id: hexlify18(randomBytes6(34)),
|
8332
|
+
owner: signer.address.toHexString(),
|
8333
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8334
|
+
amount: "18446744073709551615",
|
8335
|
+
asset_id: BaseAssetId4,
|
8336
|
+
output_index: 0,
|
8337
|
+
tx_pointer_block_height: 0,
|
8338
|
+
tx_pointer_tx_idx: 0
|
8339
|
+
});
|
8087
8340
|
}
|
8088
|
-
|
8089
|
-
|
8341
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8342
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8343
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8344
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8345
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8346
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8347
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8348
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8349
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8350
|
+
chainConfigPathToUse = tempDirPath;
|
8090
8351
|
}
|
8091
8352
|
const child = spawn(
|
8092
8353
|
command,
|
@@ -8095,10 +8356,10 @@ var launchNode = async ({
|
|
8095
8356
|
["--ip", ipToUse],
|
8096
8357
|
["--port", portToUse],
|
8097
8358
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8098
|
-
["--min-gas-price", "
|
8359
|
+
["--min-gas-price", "1"],
|
8099
8360
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8100
8361
|
["--consensus-key", consensusKey],
|
8101
|
-
["--
|
8362
|
+
["--snapshot", chainConfigPathToUse],
|
8102
8363
|
"--vm-backtrace",
|
8103
8364
|
"--utxo-validation",
|
8104
8365
|
"--debug",
|
@@ -8157,7 +8418,7 @@ var launchNodeAndGetWallets = async ({
|
|
8157
8418
|
walletCount = 10
|
8158
8419
|
} = {}) => {
|
8159
8420
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8160
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8421
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8161
8422
|
const wallets = await generateWallets(walletCount, provider);
|
8162
8423
|
const cleanup = () => {
|
8163
8424
|
closeNode();
|