@fuel-ts/account 0.0.0-rc-1976-20240419101644 → 0.0.0-rc-2021-20240419145341
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 +830 -604
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +833 -601
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +675 -444
- 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 +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/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 +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +9 -29
- 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/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1579 -1118
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +811 -600
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +667 -456
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -24,35 +24,38 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
+
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
27
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
|
-
import { bn as
|
30
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
30
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
+
import { clone as clone4 } from "ramda";
|
31
33
|
|
32
34
|
// src/providers/coin-quantity.ts
|
35
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
33
36
|
import { bn } from "@fuel-ts/math";
|
34
37
|
import { hexlify } from "@fuel-ts/utils";
|
35
38
|
var coinQuantityfy = (coinQuantityLike) => {
|
36
39
|
let assetId;
|
37
40
|
let amount;
|
38
|
-
let
|
41
|
+
let max;
|
39
42
|
if (Array.isArray(coinQuantityLike)) {
|
40
43
|
amount = coinQuantityLike[0];
|
41
|
-
assetId = coinQuantityLike[1];
|
42
|
-
|
44
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
45
|
+
max = coinQuantityLike[2] ?? void 0;
|
43
46
|
} else {
|
44
47
|
amount = coinQuantityLike.amount;
|
45
|
-
assetId = coinQuantityLike.assetId;
|
46
|
-
|
48
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
49
|
+
max = coinQuantityLike.max ?? void 0;
|
47
50
|
}
|
48
51
|
const bnAmount = bn(amount);
|
49
52
|
return {
|
50
53
|
assetId: hexlify(assetId),
|
51
54
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
52
|
-
max:
|
55
|
+
max: max ? bn(max) : void 0
|
53
56
|
};
|
54
57
|
};
|
55
|
-
var
|
58
|
+
var addAmountToCoinQuantities = (params) => {
|
56
59
|
const { amount, assetId } = params;
|
57
60
|
const coinQuantities = [...params.coinQuantities];
|
58
61
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -67,9 +70,9 @@ var addAmountToAsset = (params) => {
|
|
67
70
|
// src/providers/provider.ts
|
68
71
|
import { Address as Address2 } from "@fuel-ts/address";
|
69
72
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
70
|
-
import { BN, bn as
|
73
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
71
74
|
import {
|
72
|
-
InputType as
|
75
|
+
InputType as InputType7,
|
73
76
|
TransactionType as TransactionType8,
|
74
77
|
InputMessageCoder,
|
75
78
|
TransactionCoder as TransactionCoder5
|
@@ -85,14 +88,10 @@ import { clone as clone3 } from "ramda";
|
|
85
88
|
import gql from "graphql-tag";
|
86
89
|
var ReceiptFragmentFragmentDoc = gql`
|
87
90
|
fragment receiptFragment on Receipt {
|
88
|
-
|
89
|
-
id
|
90
|
-
}
|
91
|
+
id
|
91
92
|
pc
|
92
93
|
is
|
93
|
-
to
|
94
|
-
id
|
95
|
-
}
|
94
|
+
to
|
96
95
|
toAddress
|
97
96
|
amount
|
98
97
|
assetId
|
@@ -130,10 +129,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
130
129
|
id
|
131
130
|
}
|
132
131
|
time
|
132
|
+
receipts {
|
133
|
+
...receiptFragment
|
134
|
+
}
|
133
135
|
programState {
|
134
136
|
returnType
|
135
137
|
data
|
136
138
|
}
|
139
|
+
receipts {
|
140
|
+
...receiptFragment
|
141
|
+
}
|
137
142
|
}
|
138
143
|
... on FailureStatus {
|
139
144
|
block {
|
@@ -141,26 +146,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
141
146
|
}
|
142
147
|
time
|
143
148
|
reason
|
149
|
+
receipts {
|
150
|
+
...receiptFragment
|
151
|
+
}
|
144
152
|
}
|
145
153
|
... on SqueezedOutStatus {
|
146
154
|
reason
|
147
155
|
}
|
148
156
|
}
|
149
|
-
`;
|
157
|
+
${ReceiptFragmentFragmentDoc}`;
|
150
158
|
var TransactionFragmentFragmentDoc = gql`
|
151
159
|
fragment transactionFragment on Transaction {
|
152
160
|
id
|
153
161
|
rawPayload
|
154
|
-
gasPrice
|
155
|
-
receipts {
|
156
|
-
...receiptFragment
|
157
|
-
}
|
158
162
|
status {
|
159
163
|
...transactionStatusFragment
|
160
164
|
}
|
161
165
|
}
|
162
|
-
${
|
163
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
166
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
164
167
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
165
168
|
fragment inputEstimatePredicatesFragment on Input {
|
166
169
|
... on InputCoin {
|
@@ -178,6 +181,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
178
181
|
}
|
179
182
|
}
|
180
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}`;
|
181
224
|
var CoinFragmentFragmentDoc = gql`
|
182
225
|
fragment coinFragment on Coin {
|
183
226
|
__typename
|
@@ -185,7 +228,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
185
228
|
owner
|
186
229
|
amount
|
187
230
|
assetId
|
188
|
-
maturity
|
189
231
|
blockCreated
|
190
232
|
txCreatedIdx
|
191
233
|
}
|
@@ -224,26 +266,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
224
266
|
messageBlockHeader {
|
225
267
|
id
|
226
268
|
daHeight
|
269
|
+
consensusParametersVersion
|
270
|
+
stateTransitionBytecodeVersion
|
227
271
|
transactionsCount
|
272
|
+
messageReceiptCount
|
228
273
|
transactionsRoot
|
274
|
+
messageOutboxRoot
|
275
|
+
eventInboxRoot
|
229
276
|
height
|
230
277
|
prevRoot
|
231
278
|
time
|
232
279
|
applicationHash
|
233
|
-
messageReceiptRoot
|
234
|
-
messageReceiptCount
|
235
280
|
}
|
236
281
|
commitBlockHeader {
|
237
282
|
id
|
238
283
|
daHeight
|
284
|
+
consensusParametersVersion
|
285
|
+
stateTransitionBytecodeVersion
|
239
286
|
transactionsCount
|
287
|
+
messageReceiptCount
|
240
288
|
transactionsRoot
|
289
|
+
messageOutboxRoot
|
290
|
+
eventInboxRoot
|
241
291
|
height
|
242
292
|
prevRoot
|
243
293
|
time
|
244
294
|
applicationHash
|
245
|
-
messageReceiptRoot
|
246
|
-
messageReceiptCount
|
247
295
|
}
|
248
296
|
sender
|
249
297
|
recipient
|
@@ -262,8 +310,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
262
310
|
var BlockFragmentFragmentDoc = gql`
|
263
311
|
fragment blockFragment on Block {
|
264
312
|
id
|
313
|
+
height
|
265
314
|
header {
|
266
|
-
height
|
267
315
|
time
|
268
316
|
}
|
269
317
|
transactions {
|
@@ -321,6 +369,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
321
369
|
`;
|
322
370
|
var GasCostsFragmentFragmentDoc = gql`
|
323
371
|
fragment GasCostsFragment on GasCosts {
|
372
|
+
version {
|
373
|
+
... on Version {
|
374
|
+
value
|
375
|
+
}
|
376
|
+
}
|
324
377
|
add
|
325
378
|
addi
|
326
379
|
aloc
|
@@ -333,7 +386,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
333
386
|
cb
|
334
387
|
cfei
|
335
388
|
cfsi
|
336
|
-
croo
|
337
389
|
div
|
338
390
|
divi
|
339
391
|
ecr1
|
@@ -416,6 +468,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
416
468
|
ccp {
|
417
469
|
...DependentCostFragment
|
418
470
|
}
|
471
|
+
croo {
|
472
|
+
...DependentCostFragment
|
473
|
+
}
|
419
474
|
csiz {
|
420
475
|
...DependentCostFragment
|
421
476
|
}
|
@@ -475,6 +530,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
475
530
|
${DependentCostFragmentFragmentDoc}`;
|
476
531
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
477
532
|
fragment consensusParametersFragment on ConsensusParameters {
|
533
|
+
version {
|
534
|
+
... on Version {
|
535
|
+
value
|
536
|
+
}
|
537
|
+
}
|
478
538
|
txParams {
|
479
539
|
...TxParametersFragment
|
480
540
|
}
|
@@ -534,18 +594,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
534
594
|
fragment nodeInfoFragment on NodeInfo {
|
535
595
|
utxoValidation
|
536
596
|
vmBacktrace
|
537
|
-
minGasPrice
|
538
597
|
maxTx
|
539
598
|
maxDepth
|
540
599
|
nodeVersion
|
541
|
-
peers {
|
542
|
-
id
|
543
|
-
addresses
|
544
|
-
clientVersion
|
545
|
-
blockHeight
|
546
|
-
lastHeartbeatMs
|
547
|
-
appScore
|
548
|
-
}
|
549
600
|
}
|
550
601
|
`;
|
551
602
|
var GetVersionDocument = gql`
|
@@ -580,13 +631,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
580
631
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
581
632
|
transaction(id: $transactionId) {
|
582
633
|
...transactionFragment
|
583
|
-
receipts {
|
584
|
-
...receiptFragment
|
585
|
-
}
|
586
634
|
}
|
587
635
|
}
|
588
|
-
${TransactionFragmentFragmentDoc}
|
589
|
-
${ReceiptFragmentFragmentDoc}`;
|
636
|
+
${TransactionFragmentFragmentDoc}`;
|
590
637
|
var GetTransactionsDocument = gql`
|
591
638
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
592
639
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -714,6 +761,20 @@ var GetBalanceDocument = gql`
|
|
714
761
|
}
|
715
762
|
}
|
716
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
|
+
`;
|
717
778
|
var GetBalancesDocument = gql`
|
718
779
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
719
780
|
balances(
|
@@ -768,12 +829,12 @@ var GetMessageStatusDocument = gql`
|
|
768
829
|
}
|
769
830
|
`;
|
770
831
|
var DryRunDocument = gql`
|
771
|
-
mutation dryRun($
|
772
|
-
dryRun(
|
773
|
-
...
|
832
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
833
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
834
|
+
...dryRunTransactionExecutionStatusFragment
|
774
835
|
}
|
775
836
|
}
|
776
|
-
${
|
837
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
777
838
|
var SubmitDocument = gql`
|
778
839
|
mutation submit($encodedTransaction: HexString!) {
|
779
840
|
submit(tx: $encodedTransaction) {
|
@@ -856,6 +917,12 @@ function getSdk(requester) {
|
|
856
917
|
getBalance(variables, options) {
|
857
918
|
return requester(GetBalanceDocument, variables, options);
|
858
919
|
},
|
920
|
+
getLatestGasPrice(variables, options) {
|
921
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
922
|
+
},
|
923
|
+
estimateGasPrice(variables, options) {
|
924
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
925
|
+
},
|
859
926
|
getBalances(variables, options) {
|
860
927
|
return requester(GetBalancesDocument, variables, options);
|
861
928
|
},
|
@@ -1049,10 +1116,9 @@ var inputify = (value) => {
|
|
1049
1116
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1050
1117
|
},
|
1051
1118
|
witnessIndex: value.witnessIndex,
|
1052
|
-
maturity: value.maturity ?? 0,
|
1053
1119
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1054
|
-
predicateLength: predicate.length,
|
1055
|
-
predicateDataLength: predicateData.length,
|
1120
|
+
predicateLength: bn2(predicate.length),
|
1121
|
+
predicateDataLength: bn2(predicateData.length),
|
1056
1122
|
predicate: hexlify3(predicate),
|
1057
1123
|
predicateData: hexlify3(predicateData)
|
1058
1124
|
};
|
@@ -1083,8 +1149,8 @@ var inputify = (value) => {
|
|
1083
1149
|
nonce: hexlify3(value.nonce),
|
1084
1150
|
witnessIndex: value.witnessIndex,
|
1085
1151
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1086
|
-
predicateLength: predicate.length,
|
1087
|
-
predicateDataLength: predicateData.length,
|
1152
|
+
predicateLength: bn2(predicate.length),
|
1153
|
+
predicateDataLength: bn2(predicateData.length),
|
1088
1154
|
predicate: hexlify3(predicate),
|
1089
1155
|
predicateData: hexlify3(predicateData),
|
1090
1156
|
data: hexlify3(data),
|
@@ -1160,7 +1226,7 @@ var outputify = (value) => {
|
|
1160
1226
|
// src/providers/transaction-request/transaction-request.ts
|
1161
1227
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1162
1228
|
import { Address, addressify } from "@fuel-ts/address";
|
1163
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1229
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1164
1230
|
import { randomBytes } from "@fuel-ts/crypto";
|
1165
1231
|
import { bn as bn7 } from "@fuel-ts/math";
|
1166
1232
|
import {
|
@@ -1211,8 +1277,8 @@ function assembleReceiptByType(receipt) {
|
|
1211
1277
|
case "CALL" /* Call */: {
|
1212
1278
|
const callReceipt = {
|
1213
1279
|
type: ReceiptType.Call,
|
1214
|
-
from: hexOrZero(receipt.
|
1215
|
-
to: hexOrZero(receipt?.to
|
1280
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1281
|
+
to: hexOrZero(receipt?.to),
|
1216
1282
|
amount: bn4(receipt.amount),
|
1217
1283
|
assetId: hexOrZero(receipt.assetId),
|
1218
1284
|
gas: bn4(receipt.gas),
|
@@ -1226,7 +1292,7 @@ function assembleReceiptByType(receipt) {
|
|
1226
1292
|
case "RETURN" /* Return */: {
|
1227
1293
|
const returnReceipt = {
|
1228
1294
|
type: ReceiptType.Return,
|
1229
|
-
id: hexOrZero(receipt.
|
1295
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1230
1296
|
val: bn4(receipt.val),
|
1231
1297
|
pc: bn4(receipt.pc),
|
1232
1298
|
is: bn4(receipt.is)
|
@@ -1236,7 +1302,7 @@ function assembleReceiptByType(receipt) {
|
|
1236
1302
|
case "RETURN_DATA" /* ReturnData */: {
|
1237
1303
|
const returnDataReceipt = {
|
1238
1304
|
type: ReceiptType.ReturnData,
|
1239
|
-
id: hexOrZero(receipt.
|
1305
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1240
1306
|
ptr: bn4(receipt.ptr),
|
1241
1307
|
len: bn4(receipt.len),
|
1242
1308
|
digest: hexOrZero(receipt.digest),
|
@@ -1248,7 +1314,7 @@ function assembleReceiptByType(receipt) {
|
|
1248
1314
|
case "PANIC" /* Panic */: {
|
1249
1315
|
const panicReceipt = {
|
1250
1316
|
type: ReceiptType.Panic,
|
1251
|
-
id: hexOrZero(receipt.
|
1317
|
+
id: hexOrZero(receipt.id),
|
1252
1318
|
reason: bn4(receipt.reason),
|
1253
1319
|
pc: bn4(receipt.pc),
|
1254
1320
|
is: bn4(receipt.is),
|
@@ -1259,7 +1325,7 @@ function assembleReceiptByType(receipt) {
|
|
1259
1325
|
case "REVERT" /* Revert */: {
|
1260
1326
|
const revertReceipt = {
|
1261
1327
|
type: ReceiptType.Revert,
|
1262
|
-
id: hexOrZero(receipt.
|
1328
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1263
1329
|
val: bn4(receipt.ra),
|
1264
1330
|
pc: bn4(receipt.pc),
|
1265
1331
|
is: bn4(receipt.is)
|
@@ -1269,7 +1335,7 @@ function assembleReceiptByType(receipt) {
|
|
1269
1335
|
case "LOG" /* Log */: {
|
1270
1336
|
const logReceipt = {
|
1271
1337
|
type: ReceiptType.Log,
|
1272
|
-
id: hexOrZero(receipt.
|
1338
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1273
1339
|
val0: bn4(receipt.ra),
|
1274
1340
|
val1: bn4(receipt.rb),
|
1275
1341
|
val2: bn4(receipt.rc),
|
@@ -1282,7 +1348,7 @@ function assembleReceiptByType(receipt) {
|
|
1282
1348
|
case "LOG_DATA" /* LogData */: {
|
1283
1349
|
const logDataReceipt = {
|
1284
1350
|
type: ReceiptType.LogData,
|
1285
|
-
id: hexOrZero(receipt.
|
1351
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1286
1352
|
val0: bn4(receipt.ra),
|
1287
1353
|
val1: bn4(receipt.rb),
|
1288
1354
|
ptr: bn4(receipt.ptr),
|
@@ -1296,8 +1362,8 @@ function assembleReceiptByType(receipt) {
|
|
1296
1362
|
case "TRANSFER" /* Transfer */: {
|
1297
1363
|
const transferReceipt = {
|
1298
1364
|
type: ReceiptType.Transfer,
|
1299
|
-
from: hexOrZero(receipt.
|
1300
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1365
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1366
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1301
1367
|
amount: bn4(receipt.amount),
|
1302
1368
|
assetId: hexOrZero(receipt.assetId),
|
1303
1369
|
pc: bn4(receipt.pc),
|
@@ -1308,8 +1374,8 @@ function assembleReceiptByType(receipt) {
|
|
1308
1374
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1309
1375
|
const transferOutReceipt = {
|
1310
1376
|
type: ReceiptType.TransferOut,
|
1311
|
-
from: hexOrZero(receipt.
|
1312
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1377
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1378
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1313
1379
|
amount: bn4(receipt.amount),
|
1314
1380
|
assetId: hexOrZero(receipt.assetId),
|
1315
1381
|
pc: bn4(receipt.pc),
|
@@ -1352,7 +1418,7 @@ function assembleReceiptByType(receipt) {
|
|
1352
1418
|
return receiptMessageOut;
|
1353
1419
|
}
|
1354
1420
|
case "MINT" /* Mint */: {
|
1355
|
-
const contractId = hexOrZero(receipt.
|
1421
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1356
1422
|
const subId = hexOrZero(receipt.subId);
|
1357
1423
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1358
1424
|
const mintReceipt = {
|
@@ -1367,7 +1433,7 @@ function assembleReceiptByType(receipt) {
|
|
1367
1433
|
return mintReceipt;
|
1368
1434
|
}
|
1369
1435
|
case "BURN" /* Burn */: {
|
1370
|
-
const contractId = hexOrZero(receipt.
|
1436
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1371
1437
|
const subId = hexOrZero(receipt.subId);
|
1372
1438
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1373
1439
|
const burnReceipt = {
|
@@ -1393,7 +1459,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1393
1459
|
import { bn as bn5 } from "@fuel-ts/math";
|
1394
1460
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1395
1461
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1396
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1397
1462
|
var getGasUsedFromReceipts = (receipts) => {
|
1398
1463
|
const scriptResult = receipts.filter(
|
1399
1464
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1414,18 +1479,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1414
1479
|
}
|
1415
1480
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1416
1481
|
const witnessCache = [];
|
1417
|
-
const
|
1482
|
+
const chargeableInputs = inputs.filter((input) => {
|
1483
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1484
|
+
if (isCoinOrMessage) {
|
1485
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1486
|
+
return true;
|
1487
|
+
}
|
1488
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1489
|
+
witnessCache.push(input.witnessIndex);
|
1490
|
+
return true;
|
1491
|
+
}
|
1492
|
+
}
|
1493
|
+
return false;
|
1494
|
+
});
|
1495
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1496
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1418
1497
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1419
1498
|
return total.add(
|
1420
|
-
|
1499
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1421
1500
|
);
|
1422
1501
|
}
|
1423
|
-
|
1424
|
-
|
1425
|
-
return total.add(gasCosts.ecr1);
|
1426
|
-
}
|
1427
|
-
return total;
|
1428
|
-
}, bn5());
|
1502
|
+
return total.add(gasCosts.ecr1);
|
1503
|
+
}, bn5(0));
|
1429
1504
|
return totalGas;
|
1430
1505
|
}
|
1431
1506
|
function getMinGas(params) {
|
@@ -1437,12 +1512,20 @@ function getMinGas(params) {
|
|
1437
1512
|
return minGas;
|
1438
1513
|
}
|
1439
1514
|
function getMaxGas(params) {
|
1440
|
-
const {
|
1515
|
+
const {
|
1516
|
+
gasPerByte,
|
1517
|
+
witnessesLength,
|
1518
|
+
witnessLimit,
|
1519
|
+
minGas,
|
1520
|
+
gasLimit = bn5(0),
|
1521
|
+
maxGasPerTx
|
1522
|
+
} = params;
|
1441
1523
|
let remainingAllowedWitnessGas = bn5(0);
|
1442
1524
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1443
1525
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1444
1526
|
}
|
1445
|
-
|
1527
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1528
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1446
1529
|
}
|
1447
1530
|
function calculateMetadataGasForTxCreate({
|
1448
1531
|
gasCosts,
|
@@ -1464,6 +1547,10 @@ function calculateMetadataGasForTxScript({
|
|
1464
1547
|
}) {
|
1465
1548
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1466
1549
|
}
|
1550
|
+
var calculateGasFee = (params) => {
|
1551
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1552
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1553
|
+
};
|
1467
1554
|
|
1468
1555
|
// src/providers/utils/json.ts
|
1469
1556
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1608,7 +1695,7 @@ var witnessify = (value) => {
|
|
1608
1695
|
// src/providers/transaction-request/transaction-request.ts
|
1609
1696
|
var BaseTransactionRequest = class {
|
1610
1697
|
/** Gas price for transaction */
|
1611
|
-
|
1698
|
+
tip;
|
1612
1699
|
/** Block until which tx cannot be included */
|
1613
1700
|
maturity;
|
1614
1701
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1621,38 +1708,34 @@ var BaseTransactionRequest = class {
|
|
1621
1708
|
outputs = [];
|
1622
1709
|
/** List of witnesses */
|
1623
1710
|
witnesses = [];
|
1624
|
-
/** Base asset ID - should be fetched from the chain */
|
1625
|
-
baseAssetId;
|
1626
1711
|
/**
|
1627
1712
|
* Constructor for initializing a base transaction request.
|
1628
1713
|
*
|
1629
1714
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1630
1715
|
*/
|
1631
1716
|
constructor({
|
1632
|
-
|
1717
|
+
tip,
|
1633
1718
|
maturity,
|
1634
1719
|
maxFee,
|
1635
1720
|
witnessLimit,
|
1636
1721
|
inputs,
|
1637
1722
|
outputs,
|
1638
|
-
witnesses
|
1639
|
-
|
1640
|
-
|
1641
|
-
this.gasPrice = bn7(gasPrice);
|
1723
|
+
witnesses
|
1724
|
+
} = {}) {
|
1725
|
+
this.tip = bn7(tip);
|
1642
1726
|
this.maturity = maturity ?? 0;
|
1643
1727
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1644
1728
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1645
1729
|
this.inputs = inputs ?? [];
|
1646
1730
|
this.outputs = outputs ?? [];
|
1647
1731
|
this.witnesses = witnesses ?? [];
|
1648
|
-
this.baseAssetId = baseAssetId;
|
1649
1732
|
}
|
1650
1733
|
static getPolicyMeta(req) {
|
1651
1734
|
let policyTypes = 0;
|
1652
1735
|
const policies = [];
|
1653
|
-
if (req.
|
1654
|
-
policyTypes += PolicyType.
|
1655
|
-
policies.push({ data: req.
|
1736
|
+
if (req.tip) {
|
1737
|
+
policyTypes += PolicyType.Tip;
|
1738
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1656
1739
|
}
|
1657
1740
|
if (req.witnessLimit) {
|
1658
1741
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1839,10 +1922,10 @@ var BaseTransactionRequest = class {
|
|
1839
1922
|
* @param predicate - Predicate bytes.
|
1840
1923
|
* @param predicateData - Predicate data bytes.
|
1841
1924
|
*/
|
1842
|
-
addCoinInput(coin
|
1925
|
+
addCoinInput(coin) {
|
1843
1926
|
const { assetId, owner, amount } = coin;
|
1844
1927
|
let witnessIndex;
|
1845
|
-
if (predicate) {
|
1928
|
+
if (coin.predicate) {
|
1846
1929
|
witnessIndex = 0;
|
1847
1930
|
} else {
|
1848
1931
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1857,8 +1940,7 @@ var BaseTransactionRequest = class {
|
|
1857
1940
|
amount,
|
1858
1941
|
assetId,
|
1859
1942
|
txPointer: "0x00000000000000000000000000000000",
|
1860
|
-
witnessIndex
|
1861
|
-
predicate: predicate?.bytes
|
1943
|
+
witnessIndex
|
1862
1944
|
};
|
1863
1945
|
this.pushInput(input);
|
1864
1946
|
this.addChangeOutput(owner, assetId);
|
@@ -1869,11 +1951,13 @@ var BaseTransactionRequest = class {
|
|
1869
1951
|
*
|
1870
1952
|
* @param message - Message resource.
|
1871
1953
|
* @param predicate - Predicate bytes.
|
1954
|
+
* @param predicateData - Predicate data bytes.
|
1872
1955
|
*/
|
1873
|
-
addMessageInput(message
|
1956
|
+
addMessageInput(message) {
|
1874
1957
|
const { recipient, sender, amount } = message;
|
1958
|
+
const assetId = BaseAssetId2;
|
1875
1959
|
let witnessIndex;
|
1876
|
-
if (predicate) {
|
1960
|
+
if (message.predicate) {
|
1877
1961
|
witnessIndex = 0;
|
1878
1962
|
} else {
|
1879
1963
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1887,11 +1971,10 @@ var BaseTransactionRequest = class {
|
|
1887
1971
|
sender: sender.toB256(),
|
1888
1972
|
recipient: recipient.toB256(),
|
1889
1973
|
amount,
|
1890
|
-
witnessIndex
|
1891
|
-
predicate: predicate?.bytes
|
1974
|
+
witnessIndex
|
1892
1975
|
};
|
1893
1976
|
this.pushInput(input);
|
1894
|
-
this.addChangeOutput(recipient,
|
1977
|
+
this.addChangeOutput(recipient, assetId);
|
1895
1978
|
}
|
1896
1979
|
/**
|
1897
1980
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1919,32 +2002,6 @@ var BaseTransactionRequest = class {
|
|
1919
2002
|
resources.forEach((resource) => this.addResource(resource));
|
1920
2003
|
return this;
|
1921
2004
|
}
|
1922
|
-
/**
|
1923
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1924
|
-
* outputs from the related assetIds.
|
1925
|
-
*
|
1926
|
-
* @param resources - The resources to add.
|
1927
|
-
* @returns This transaction.
|
1928
|
-
*/
|
1929
|
-
addPredicateResource(resource, predicate) {
|
1930
|
-
if (isCoin(resource)) {
|
1931
|
-
this.addCoinInput(resource, predicate);
|
1932
|
-
} else {
|
1933
|
-
this.addMessageInput(resource, predicate);
|
1934
|
-
}
|
1935
|
-
return this;
|
1936
|
-
}
|
1937
|
-
/**
|
1938
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1939
|
-
* from the related assetIds.
|
1940
|
-
*
|
1941
|
-
* @param resources - The resources to add.
|
1942
|
-
* @returns This transaction.
|
1943
|
-
*/
|
1944
|
-
addPredicateResources(resources, predicate) {
|
1945
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1946
|
-
return this;
|
1947
|
-
}
|
1948
2005
|
/**
|
1949
2006
|
* Adds a coin output to the transaction.
|
1950
2007
|
*
|
@@ -1952,12 +2009,12 @@ var BaseTransactionRequest = class {
|
|
1952
2009
|
* @param amount - Amount of coin.
|
1953
2010
|
* @param assetId - Asset ID of coin.
|
1954
2011
|
*/
|
1955
|
-
addCoinOutput(to, amount, assetId) {
|
2012
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
1956
2013
|
this.pushOutput({
|
1957
2014
|
type: OutputType2.Coin,
|
1958
2015
|
to: addressify(to).toB256(),
|
1959
2016
|
amount,
|
1960
|
-
assetId
|
2017
|
+
assetId
|
1961
2018
|
});
|
1962
2019
|
return this;
|
1963
2020
|
}
|
@@ -1984,7 +2041,7 @@ var BaseTransactionRequest = class {
|
|
1984
2041
|
* @param to - Address of the owner.
|
1985
2042
|
* @param assetId - Asset ID of coin.
|
1986
2043
|
*/
|
1987
|
-
addChangeOutput(to, assetId) {
|
2044
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
1988
2045
|
const changeOutput = this.getChangeOutputs().find(
|
1989
2046
|
(output) => hexlify7(output.assetId) === assetId
|
1990
2047
|
);
|
@@ -1992,7 +2049,7 @@ var BaseTransactionRequest = class {
|
|
1992
2049
|
this.pushOutput({
|
1993
2050
|
type: OutputType2.Change,
|
1994
2051
|
to: addressify(to).toB256(),
|
1995
|
-
assetId
|
2052
|
+
assetId
|
1996
2053
|
});
|
1997
2054
|
}
|
1998
2055
|
}
|
@@ -2024,7 +2081,7 @@ var BaseTransactionRequest = class {
|
|
2024
2081
|
}
|
2025
2082
|
calculateMaxGas(chainInfo, minGas) {
|
2026
2083
|
const { consensusParameters } = chainInfo;
|
2027
|
-
const { gasPerByte } = consensusParameters;
|
2084
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2028
2085
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2029
2086
|
(acc, wit) => acc + wit.dataLength,
|
2030
2087
|
0
|
@@ -2033,7 +2090,8 @@ var BaseTransactionRequest = class {
|
|
2033
2090
|
gasPerByte,
|
2034
2091
|
minGas,
|
2035
2092
|
witnessesLength,
|
2036
|
-
witnessLimit: this.witnessLimit
|
2093
|
+
witnessLimit: this.witnessLimit,
|
2094
|
+
maxGasPerTx
|
2037
2095
|
});
|
2038
2096
|
}
|
2039
2097
|
/**
|
@@ -2051,24 +2109,27 @@ var BaseTransactionRequest = class {
|
|
2051
2109
|
});
|
2052
2110
|
const updateAssetInput = (assetId, quantity) => {
|
2053
2111
|
const assetInput = findAssetInput(assetId);
|
2112
|
+
let usedQuantity = quantity;
|
2113
|
+
if (assetId === BaseAssetId2) {
|
2114
|
+
usedQuantity = bn7("1000000000000000000");
|
2115
|
+
}
|
2054
2116
|
if (assetInput && "assetId" in assetInput) {
|
2055
2117
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2056
|
-
assetInput.amount =
|
2118
|
+
assetInput.amount = usedQuantity;
|
2057
2119
|
} else {
|
2058
2120
|
this.addResources([
|
2059
2121
|
{
|
2060
2122
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2061
|
-
amount:
|
2123
|
+
amount: usedQuantity,
|
2062
2124
|
assetId,
|
2063
2125
|
owner: resourcesOwner || Address.fromRandom(),
|
2064
|
-
maturity: 0,
|
2065
2126
|
blockCreated: bn7(1),
|
2066
2127
|
txCreatedIdx: bn7(1)
|
2067
2128
|
}
|
2068
2129
|
]);
|
2069
2130
|
}
|
2070
2131
|
};
|
2071
|
-
updateAssetInput(
|
2132
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2072
2133
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2073
2134
|
}
|
2074
2135
|
/**
|
@@ -2093,7 +2154,7 @@ var BaseTransactionRequest = class {
|
|
2093
2154
|
toJSON() {
|
2094
2155
|
return normalizeJSON(this);
|
2095
2156
|
}
|
2096
|
-
|
2157
|
+
updatePredicateGasUsed(inputs) {
|
2097
2158
|
this.inputs.forEach((i) => {
|
2098
2159
|
let correspondingInput;
|
2099
2160
|
switch (i.type) {
|
@@ -2115,6 +2176,15 @@ var BaseTransactionRequest = class {
|
|
2115
2176
|
}
|
2116
2177
|
});
|
2117
2178
|
}
|
2179
|
+
shiftPredicateData() {
|
2180
|
+
this.inputs.forEach((input) => {
|
2181
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2182
|
+
input.predicateData = input.paddPredicateData(
|
2183
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2184
|
+
);
|
2185
|
+
}
|
2186
|
+
});
|
2187
|
+
}
|
2118
2188
|
};
|
2119
2189
|
|
2120
2190
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2238,7 +2308,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2238
2308
|
*
|
2239
2309
|
* @param createTransactionRequestLike - The initial values for the instance
|
2240
2310
|
*/
|
2241
|
-
constructor({
|
2311
|
+
constructor({
|
2312
|
+
bytecodeWitnessIndex,
|
2313
|
+
salt,
|
2314
|
+
storageSlots,
|
2315
|
+
...rest
|
2316
|
+
} = {}) {
|
2242
2317
|
super(rest);
|
2243
2318
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2244
2319
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2256,9 +2331,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2256
2331
|
return {
|
2257
2332
|
type: TransactionType3.Create,
|
2258
2333
|
...baseTransaction,
|
2259
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2260
2334
|
bytecodeWitnessIndex,
|
2261
|
-
storageSlotsCount: storageSlots.length,
|
2335
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2262
2336
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2263
2337
|
storageSlots
|
2264
2338
|
};
|
@@ -2362,7 +2436,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2362
2436
|
*
|
2363
2437
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2364
2438
|
*/
|
2365
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2439
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2366
2440
|
super(rest);
|
2367
2441
|
this.gasLimit = bn10(gasLimit);
|
2368
2442
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -2381,8 +2455,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2381
2455
|
type: TransactionType4.Script,
|
2382
2456
|
scriptGasLimit: this.gasLimit,
|
2383
2457
|
...super.getBaseTransaction(),
|
2384
|
-
scriptLength: script.length,
|
2385
|
-
scriptDataLength: scriptData.length,
|
2458
|
+
scriptLength: bn10(script.length),
|
2459
|
+
scriptDataLength: bn10(scriptData.length),
|
2386
2460
|
receiptsRoot: ZeroBytes327,
|
2387
2461
|
script: hexlify10(script),
|
2388
2462
|
scriptData: hexlify10(scriptData)
|
@@ -2446,7 +2520,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2446
2520
|
}
|
2447
2521
|
calculateMaxGas(chainInfo, minGas) {
|
2448
2522
|
const { consensusParameters } = chainInfo;
|
2449
|
-
const { gasPerByte } = consensusParameters;
|
2523
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2450
2524
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2451
2525
|
(acc, wit) => acc + wit.dataLength,
|
2452
2526
|
0
|
@@ -2456,7 +2530,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2456
2530
|
minGas,
|
2457
2531
|
witnessesLength,
|
2458
2532
|
witnessLimit: this.witnessLimit,
|
2459
|
-
gasLimit: this.gasLimit
|
2533
|
+
gasLimit: this.gasLimit,
|
2534
|
+
maxGasPerTx
|
2460
2535
|
});
|
2461
2536
|
}
|
2462
2537
|
/**
|
@@ -2513,7 +2588,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2513
2588
|
|
2514
2589
|
// src/providers/transaction-request/utils.ts
|
2515
2590
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2516
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2591
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2517
2592
|
var transactionRequestify = (obj) => {
|
2518
2593
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2519
2594
|
return obj;
|
@@ -2531,14 +2606,31 @@ var transactionRequestify = (obj) => {
|
|
2531
2606
|
}
|
2532
2607
|
}
|
2533
2608
|
};
|
2609
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2610
|
+
(acc, input) => {
|
2611
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2612
|
+
acc.utxos.push(input.id);
|
2613
|
+
}
|
2614
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2615
|
+
acc.messages.push(input.nonce);
|
2616
|
+
}
|
2617
|
+
return acc;
|
2618
|
+
},
|
2619
|
+
{
|
2620
|
+
utxos: [],
|
2621
|
+
messages: []
|
2622
|
+
}
|
2623
|
+
);
|
2534
2624
|
|
2535
2625
|
// src/providers/transaction-response/transaction-response.ts
|
2536
2626
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2537
|
-
import { bn as
|
2627
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2538
2628
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2539
2629
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2540
2630
|
|
2541
2631
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2632
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2633
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2542
2634
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2543
2635
|
|
2544
2636
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2547,9 +2639,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2547
2639
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2548
2640
|
var calculateTransactionFee = (params) => {
|
2549
2641
|
const {
|
2550
|
-
|
2642
|
+
gasPrice,
|
2551
2643
|
rawPayload,
|
2552
|
-
|
2644
|
+
tip,
|
2645
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2553
2646
|
} = params;
|
2554
2647
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2555
2648
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2559,8 +2652,7 @@ var calculateTransactionFee = (params) => {
|
|
2559
2652
|
return {
|
2560
2653
|
fee: bn11(0),
|
2561
2654
|
minFee: bn11(0),
|
2562
|
-
maxFee: bn11(0)
|
2563
|
-
feeFromGasUsed: bn11(0)
|
2655
|
+
maxFee: bn11(0)
|
2564
2656
|
};
|
2565
2657
|
}
|
2566
2658
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2592,7 +2684,6 @@ var calculateTransactionFee = (params) => {
|
|
2592
2684
|
metadataGas,
|
2593
2685
|
txBytesSize: transactionBytes.length
|
2594
2686
|
});
|
2595
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2596
2687
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2597
2688
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2598
2689
|
const maxGas = getMaxGas({
|
@@ -2600,17 +2691,25 @@ var calculateTransactionFee = (params) => {
|
|
2600
2691
|
minGas,
|
2601
2692
|
witnessesLength,
|
2602
2693
|
gasLimit,
|
2603
|
-
witnessLimit
|
2694
|
+
witnessLimit,
|
2695
|
+
maxGasPerTx
|
2696
|
+
});
|
2697
|
+
const minFee = calculateGasFee({
|
2698
|
+
gasPrice,
|
2699
|
+
gas: minGas,
|
2700
|
+
priceFactor: gasPriceFactor,
|
2701
|
+
tip
|
2702
|
+
});
|
2703
|
+
const maxFee = calculateGasFee({
|
2704
|
+
gasPrice,
|
2705
|
+
gas: maxGas,
|
2706
|
+
priceFactor: gasPriceFactor,
|
2707
|
+
tip
|
2604
2708
|
});
|
2605
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2606
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2607
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2608
|
-
const fee = minFee.add(feeFromGasUsed);
|
2609
2709
|
return {
|
2610
|
-
fee,
|
2611
2710
|
minFee,
|
2612
2711
|
maxFee,
|
2613
|
-
|
2712
|
+
fee: maxFee
|
2614
2713
|
};
|
2615
2714
|
};
|
2616
2715
|
|
@@ -2666,7 +2765,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2666
2765
|
|
2667
2766
|
// src/providers/transaction-summary/input.ts
|
2668
2767
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2669
|
-
import { InputType as
|
2768
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2670
2769
|
function getInputsByTypes(inputs, types) {
|
2671
2770
|
return inputs.filter((i) => types.includes(i.type));
|
2672
2771
|
}
|
@@ -2674,16 +2773,16 @@ function getInputsByType(inputs, type) {
|
|
2674
2773
|
return inputs.filter((i) => i.type === type);
|
2675
2774
|
}
|
2676
2775
|
function getInputsCoin(inputs) {
|
2677
|
-
return getInputsByType(inputs,
|
2776
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2678
2777
|
}
|
2679
2778
|
function getInputsMessage(inputs) {
|
2680
|
-
return getInputsByType(inputs,
|
2779
|
+
return getInputsByType(inputs, InputType6.Message);
|
2681
2780
|
}
|
2682
2781
|
function getInputsCoinAndMessage(inputs) {
|
2683
|
-
return getInputsByTypes(inputs, [
|
2782
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2684
2783
|
}
|
2685
2784
|
function getInputsContract(inputs) {
|
2686
|
-
return getInputsByType(inputs,
|
2785
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2687
2786
|
}
|
2688
2787
|
function getInputFromAssetId(inputs, assetId) {
|
2689
2788
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2702,7 +2801,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2702
2801
|
if (!contractInput) {
|
2703
2802
|
return void 0;
|
2704
2803
|
}
|
2705
|
-
if (contractInput.type !==
|
2804
|
+
if (contractInput.type !== InputType6.Contract) {
|
2706
2805
|
throw new FuelError9(
|
2707
2806
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2708
2807
|
`Contract input should be of type 'contract'.`
|
@@ -2711,10 +2810,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2711
2810
|
return contractInput;
|
2712
2811
|
}
|
2713
2812
|
function getInputAccountAddress(input) {
|
2714
|
-
if (input.type ===
|
2813
|
+
if (input.type === InputType6.Coin) {
|
2715
2814
|
return input.owner.toString();
|
2716
2815
|
}
|
2717
|
-
if (input.type ===
|
2816
|
+
if (input.type === InputType6.Message) {
|
2718
2817
|
return input.recipient.toString();
|
2719
2818
|
}
|
2720
2819
|
return "";
|
@@ -3177,7 +3276,9 @@ function assembleTransactionSummary(params) {
|
|
3177
3276
|
gqlTransactionStatus,
|
3178
3277
|
abiMap = {},
|
3179
3278
|
maxInputs,
|
3180
|
-
gasCosts
|
3279
|
+
gasCosts,
|
3280
|
+
maxGasPerTx,
|
3281
|
+
gasPrice
|
3181
3282
|
} = params;
|
3182
3283
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3183
3284
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3191,11 +3292,14 @@ function assembleTransactionSummary(params) {
|
|
3191
3292
|
maxInputs
|
3192
3293
|
});
|
3193
3294
|
const typeName = getTransactionTypeName(transaction.type);
|
3295
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3194
3296
|
const { fee } = calculateTransactionFee({
|
3195
|
-
|
3297
|
+
gasPrice,
|
3196
3298
|
rawPayload,
|
3299
|
+
tip,
|
3197
3300
|
consensusParameters: {
|
3198
3301
|
gasCosts,
|
3302
|
+
maxGasPerTx,
|
3199
3303
|
feeParams: {
|
3200
3304
|
gasPerByte,
|
3201
3305
|
gasPriceFactor
|
@@ -3255,7 +3359,7 @@ var TransactionResponse = class {
|
|
3255
3359
|
/** Current provider */
|
3256
3360
|
provider;
|
3257
3361
|
/** Gas used on the transaction */
|
3258
|
-
gasUsed =
|
3362
|
+
gasUsed = bn15(0);
|
3259
3363
|
/** The graphql Transaction with receipts object. */
|
3260
3364
|
gqlTransaction;
|
3261
3365
|
abis;
|
@@ -3333,8 +3437,13 @@ var TransactionResponse = class {
|
|
3333
3437
|
const decodedTransaction = this.decodeTransaction(
|
3334
3438
|
transaction
|
3335
3439
|
);
|
3336
|
-
|
3337
|
-
|
3440
|
+
let txReceipts = [];
|
3441
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3442
|
+
txReceipts = transaction.status.receipts;
|
3443
|
+
}
|
3444
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3445
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3446
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3338
3447
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3339
3448
|
const transactionSummary = assembleTransactionSummary({
|
3340
3449
|
id: this.id,
|
@@ -3346,7 +3455,9 @@ var TransactionResponse = class {
|
|
3346
3455
|
gasPriceFactor,
|
3347
3456
|
abiMap: contractsAbiMap,
|
3348
3457
|
maxInputs,
|
3349
|
-
gasCosts
|
3458
|
+
gasCosts,
|
3459
|
+
maxGasPerTx,
|
3460
|
+
gasPrice
|
3350
3461
|
});
|
3351
3462
|
return transactionSummary;
|
3352
3463
|
}
|
@@ -3473,30 +3584,29 @@ var processGqlChain = (chain) => {
|
|
3473
3584
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3474
3585
|
return {
|
3475
3586
|
name,
|
3476
|
-
baseChainHeight:
|
3587
|
+
baseChainHeight: bn16(daHeight),
|
3477
3588
|
consensusParameters: {
|
3478
|
-
contractMaxSize:
|
3479
|
-
maxInputs:
|
3480
|
-
maxOutputs:
|
3481
|
-
maxWitnesses:
|
3482
|
-
maxGasPerTx:
|
3483
|
-
maxScriptLength:
|
3484
|
-
maxScriptDataLength:
|
3485
|
-
maxStorageSlots:
|
3486
|
-
maxPredicateLength:
|
3487
|
-
maxPredicateDataLength:
|
3488
|
-
maxGasPerPredicate:
|
3489
|
-
gasPriceFactor:
|
3490
|
-
gasPerByte:
|
3491
|
-
maxMessageDataLength:
|
3492
|
-
chainId:
|
3493
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3589
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3590
|
+
maxInputs: bn16(txParams.maxInputs),
|
3591
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3592
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3593
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3594
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3595
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3596
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3597
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3598
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3599
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3600
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3601
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3602
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3603
|
+
chainId: bn16(consensusParameters.chainId),
|
3494
3604
|
gasCosts
|
3495
3605
|
},
|
3496
3606
|
gasCosts,
|
3497
3607
|
latestBlock: {
|
3498
3608
|
id: latestBlock.id,
|
3499
|
-
height:
|
3609
|
+
height: bn16(latestBlock.height),
|
3500
3610
|
time: latestBlock.header.time,
|
3501
3611
|
transactions: latestBlock.transactions.map((i) => ({
|
3502
3612
|
id: i.id
|
@@ -3590,10 +3700,8 @@ var _Provider = class {
|
|
3590
3700
|
* Returns some helpful parameters related to gas fees.
|
3591
3701
|
*/
|
3592
3702
|
getGasConfig() {
|
3593
|
-
const { minGasPrice } = this.getNode();
|
3594
3703
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3595
3704
|
return {
|
3596
|
-
minGasPrice,
|
3597
3705
|
maxGasPerTx,
|
3598
3706
|
maxGasPerPredicate,
|
3599
3707
|
gasPriceFactor,
|
@@ -3691,7 +3799,7 @@ var _Provider = class {
|
|
3691
3799
|
*/
|
3692
3800
|
async getBlockNumber() {
|
3693
3801
|
const { chain } = await this.operations.getChain();
|
3694
|
-
return
|
3802
|
+
return bn16(chain.latestBlock.height, 10);
|
3695
3803
|
}
|
3696
3804
|
/**
|
3697
3805
|
* Returns the chain information.
|
@@ -3701,13 +3809,11 @@ var _Provider = class {
|
|
3701
3809
|
async fetchNode() {
|
3702
3810
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3703
3811
|
const processedNodeInfo = {
|
3704
|
-
maxDepth:
|
3705
|
-
maxTx:
|
3706
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3812
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3813
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3707
3814
|
nodeVersion: nodeInfo.nodeVersion,
|
3708
3815
|
utxoValidation: nodeInfo.utxoValidation,
|
3709
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3710
|
-
peers: nodeInfo.peers
|
3816
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3711
3817
|
};
|
3712
3818
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3713
3819
|
return processedNodeInfo;
|
@@ -3733,17 +3839,6 @@ var _Provider = class {
|
|
3733
3839
|
} = this.getChain();
|
3734
3840
|
return chainId.toNumber();
|
3735
3841
|
}
|
3736
|
-
/**
|
3737
|
-
* Returns the base asset ID
|
3738
|
-
*
|
3739
|
-
* @returns A promise that resolves to the base asset ID
|
3740
|
-
*/
|
3741
|
-
getBaseAssetId() {
|
3742
|
-
const {
|
3743
|
-
consensusParameters: { baseAssetId }
|
3744
|
-
} = this.getChain();
|
3745
|
-
return baseAssetId;
|
3746
|
-
}
|
3747
3842
|
/**
|
3748
3843
|
* Submits a transaction to the chain to be executed.
|
3749
3844
|
*
|
@@ -3804,14 +3899,13 @@ var _Provider = class {
|
|
3804
3899
|
return this.estimateTxDependencies(transactionRequest);
|
3805
3900
|
}
|
3806
3901
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3807
|
-
const { dryRun:
|
3808
|
-
encodedTransaction,
|
3902
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3903
|
+
encodedTransactions: encodedTransaction,
|
3809
3904
|
utxoValidation: utxoValidation || false
|
3810
3905
|
});
|
3811
|
-
const receipts =
|
3812
|
-
|
3813
|
-
|
3814
|
-
};
|
3906
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3907
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3908
|
+
return { receipts, dryrunStatus: status };
|
3815
3909
|
}
|
3816
3910
|
/**
|
3817
3911
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3837,7 +3931,7 @@ var _Provider = class {
|
|
3837
3931
|
} = response;
|
3838
3932
|
if (inputs) {
|
3839
3933
|
inputs.forEach((input, index) => {
|
3840
|
-
if ("predicateGasUsed" in input &&
|
3934
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3841
3935
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3842
3936
|
}
|
3843
3937
|
});
|
@@ -3850,9 +3944,6 @@ var _Provider = class {
|
|
3850
3944
|
* If there are missing variable outputs,
|
3851
3945
|
* `addVariableOutputs` is called on the transaction.
|
3852
3946
|
*
|
3853
|
-
* @privateRemarks
|
3854
|
-
* TODO: Investigate support for missing contract IDs
|
3855
|
-
* TODO: Add support for missing output messages
|
3856
3947
|
*
|
3857
3948
|
* @param transactionRequest - The transaction request object.
|
3858
3949
|
* @returns A promise.
|
@@ -3865,16 +3956,19 @@ var _Provider = class {
|
|
3865
3956
|
missingContractIds: []
|
3866
3957
|
};
|
3867
3958
|
}
|
3868
|
-
await this.estimatePredicates(transactionRequest);
|
3869
3959
|
let receipts = [];
|
3870
3960
|
const missingContractIds = [];
|
3871
3961
|
let outputVariables = 0;
|
3962
|
+
let dryrunStatus;
|
3872
3963
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3873
|
-
const {
|
3874
|
-
|
3964
|
+
const {
|
3965
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3966
|
+
} = await this.operations.dryRun({
|
3967
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3875
3968
|
utxoValidation: false
|
3876
3969
|
});
|
3877
|
-
receipts =
|
3970
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3971
|
+
dryrunStatus = status;
|
3878
3972
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3879
3973
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3880
3974
|
if (hasMissingOutputs) {
|
@@ -3884,6 +3978,10 @@ var _Provider = class {
|
|
3884
3978
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3885
3979
|
missingContractIds.push(contractId);
|
3886
3980
|
});
|
3981
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3982
|
+
transactionRequest
|
3983
|
+
});
|
3984
|
+
transactionRequest.maxFee = maxFee;
|
3887
3985
|
} else {
|
3888
3986
|
break;
|
3889
3987
|
}
|
@@ -3891,37 +3989,139 @@ var _Provider = class {
|
|
3891
3989
|
return {
|
3892
3990
|
receipts,
|
3893
3991
|
outputVariables,
|
3894
|
-
missingContractIds
|
3992
|
+
missingContractIds,
|
3993
|
+
dryrunStatus
|
3895
3994
|
};
|
3896
3995
|
}
|
3996
|
+
/**
|
3997
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3998
|
+
*
|
3999
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4000
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4001
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4002
|
+
*
|
4003
|
+
* @param transactionRequests - Array of transaction request objects.
|
4004
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4005
|
+
*/
|
4006
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4007
|
+
const results = transactionRequests.map(() => ({
|
4008
|
+
receipts: [],
|
4009
|
+
outputVariables: 0,
|
4010
|
+
missingContractIds: [],
|
4011
|
+
dryrunStatus: void 0
|
4012
|
+
}));
|
4013
|
+
const allRequests = clone3(transactionRequests);
|
4014
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4015
|
+
allRequests.forEach((req, index) => {
|
4016
|
+
if (req.type === TransactionType8.Script) {
|
4017
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4018
|
+
}
|
4019
|
+
});
|
4020
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4021
|
+
let attempt = 0;
|
4022
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4023
|
+
const encodedTransactions = transactionsToProcess.map(
|
4024
|
+
(index) => serializedTransactionsMap.get(index)
|
4025
|
+
);
|
4026
|
+
const dryRunResults = await this.operations.dryRun({
|
4027
|
+
encodedTransactions,
|
4028
|
+
utxoValidation: false
|
4029
|
+
});
|
4030
|
+
const nextRoundTransactions = [];
|
4031
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4032
|
+
const currentResultIndex = transactionsToProcess[i];
|
4033
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4034
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4035
|
+
results[currentResultIndex].dryrunStatus = status;
|
4036
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4037
|
+
results[currentResultIndex].receipts
|
4038
|
+
);
|
4039
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4040
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4041
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4042
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4043
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4044
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4045
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4046
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4047
|
+
});
|
4048
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4049
|
+
transactionRequest: requestToProcess
|
4050
|
+
});
|
4051
|
+
requestToProcess.maxFee = maxFee;
|
4052
|
+
serializedTransactionsMap.set(
|
4053
|
+
currentResultIndex,
|
4054
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4055
|
+
);
|
4056
|
+
nextRoundTransactions.push(currentResultIndex);
|
4057
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4058
|
+
}
|
4059
|
+
}
|
4060
|
+
transactionsToProcess = nextRoundTransactions;
|
4061
|
+
attempt += 1;
|
4062
|
+
}
|
4063
|
+
return results;
|
4064
|
+
}
|
4065
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4066
|
+
if (estimateTxDependencies) {
|
4067
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4068
|
+
}
|
4069
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4070
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4071
|
+
encodedTransactions,
|
4072
|
+
utxoValidation: utxoValidation || false
|
4073
|
+
});
|
4074
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4075
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4076
|
+
return { receipts, dryrunStatus: status };
|
4077
|
+
});
|
4078
|
+
return results;
|
4079
|
+
}
|
3897
4080
|
/**
|
3898
4081
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3899
4082
|
* @param transactionRequest - The transaction request object.
|
3900
4083
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3901
4084
|
*/
|
3902
|
-
estimateTxGasAndFee(params) {
|
4085
|
+
async estimateTxGasAndFee(params) {
|
3903
4086
|
const { transactionRequest } = params;
|
3904
|
-
|
4087
|
+
let { gasPrice } = params;
|
3905
4088
|
const chainInfo = this.getChain();
|
3906
|
-
const
|
3907
|
-
transactionRequest.gasPrice = gasPrice;
|
4089
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3908
4090
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3909
|
-
|
4091
|
+
if (!gasPrice) {
|
4092
|
+
gasPrice = await this.estimateGasPrice(10);
|
4093
|
+
}
|
4094
|
+
const minFee = calculateGasFee({
|
4095
|
+
gasPrice: bn16(gasPrice),
|
4096
|
+
gas: minGas,
|
4097
|
+
priceFactor: gasPriceFactor,
|
4098
|
+
tip: transactionRequest.tip
|
4099
|
+
}).add(1);
|
4100
|
+
let gasLimit = bn16(0);
|
3910
4101
|
if (transactionRequest.type === TransactionType8.Script) {
|
4102
|
+
gasLimit = transactionRequest.gasLimit;
|
3911
4103
|
if (transactionRequest.gasLimit.eq(0)) {
|
3912
4104
|
transactionRequest.gasLimit = minGas;
|
3913
4105
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3914
4106
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3915
4107
|
);
|
4108
|
+
gasLimit = transactionRequest.gasLimit;
|
3916
4109
|
}
|
3917
4110
|
}
|
3918
4111
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3919
|
-
const maxFee =
|
4112
|
+
const maxFee = calculateGasFee({
|
4113
|
+
gasPrice: bn16(gasPrice),
|
4114
|
+
gas: maxGas,
|
4115
|
+
priceFactor: gasPriceFactor,
|
4116
|
+
tip: transactionRequest.tip
|
4117
|
+
}).add(1);
|
3920
4118
|
return {
|
3921
4119
|
minGas,
|
3922
4120
|
minFee,
|
3923
4121
|
maxGas,
|
3924
|
-
maxFee
|
4122
|
+
maxFee,
|
4123
|
+
gasPrice,
|
4124
|
+
gasLimit
|
3925
4125
|
};
|
3926
4126
|
}
|
3927
4127
|
/**
|
@@ -3939,15 +4139,17 @@ var _Provider = class {
|
|
3939
4139
|
if (estimateTxDependencies) {
|
3940
4140
|
return this.estimateTxDependencies(transactionRequest);
|
3941
4141
|
}
|
3942
|
-
const
|
3943
|
-
const { dryRun:
|
3944
|
-
|
4142
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4143
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4144
|
+
encodedTransactions,
|
3945
4145
|
utxoValidation: true
|
3946
4146
|
});
|
3947
|
-
const
|
3948
|
-
|
3949
|
-
receipts
|
3950
|
-
|
4147
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4148
|
+
const { id, receipts, status } = dryRunStatus;
|
4149
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4150
|
+
return { id, receipts: processedReceipts, status };
|
4151
|
+
});
|
4152
|
+
return { receipts: callResult[0].receipts };
|
3951
4153
|
}
|
3952
4154
|
/**
|
3953
4155
|
* Returns a transaction cost to enable user
|
@@ -3964,77 +4166,79 @@ var _Provider = class {
|
|
3964
4166
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3965
4167
|
* @returns A promise that resolves to the transaction cost object.
|
3966
4168
|
*/
|
3967
|
-
async getTransactionCost(transactionRequestLike,
|
3968
|
-
estimateTxDependencies = true,
|
3969
|
-
estimatePredicates = true,
|
3970
|
-
resourcesOwner,
|
3971
|
-
signatureCallback
|
3972
|
-
} = {}) {
|
4169
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3973
4170
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3974
|
-
const { minGasPrice } = this.getGasConfig();
|
3975
|
-
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3976
4171
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3977
4172
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3978
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4173
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3979
4174
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4175
|
+
txRequestClone.maxFee = bn16(0);
|
3980
4176
|
if (isScriptTransaction) {
|
3981
|
-
txRequestClone.gasLimit =
|
4177
|
+
txRequestClone.gasLimit = bn16(0);
|
3982
4178
|
}
|
3983
|
-
if (
|
3984
|
-
|
3985
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3986
|
-
}
|
3987
|
-
await this.estimatePredicates(txRequestClone);
|
4179
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4180
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3988
4181
|
}
|
4182
|
+
const signedRequest = clone3(txRequestClone);
|
4183
|
+
let addedSignatures = 0;
|
3989
4184
|
if (signatureCallback && isScriptTransaction) {
|
3990
|
-
|
4185
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4186
|
+
await signatureCallback(signedRequest);
|
4187
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3991
4188
|
}
|
3992
|
-
|
3993
|
-
|
4189
|
+
await this.estimatePredicates(signedRequest);
|
4190
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4191
|
+
transactionRequest: signedRequest
|
3994
4192
|
});
|
3995
4193
|
let receipts = [];
|
3996
4194
|
let missingContractIds = [];
|
3997
4195
|
let outputVariables = 0;
|
3998
|
-
let gasUsed =
|
3999
|
-
|
4000
|
-
|
4196
|
+
let gasUsed = bn16(0);
|
4197
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4198
|
+
txRequestClone.maxFee = maxFee;
|
4199
|
+
if (isScriptTransaction) {
|
4200
|
+
txRequestClone.gasLimit = gasLimit;
|
4201
|
+
if (signatureCallback) {
|
4202
|
+
await signatureCallback(txRequestClone);
|
4203
|
+
}
|
4001
4204
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4002
4205
|
receipts = result.receipts;
|
4003
4206
|
outputVariables = result.outputVariables;
|
4004
4207
|
missingContractIds = result.missingContractIds;
|
4005
4208
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4006
4209
|
txRequestClone.gasLimit = gasUsed;
|
4007
|
-
|
4008
|
-
|
4009
|
-
|
4210
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4211
|
+
transactionRequest: txRequestClone,
|
4212
|
+
gasPrice
|
4010
4213
|
}));
|
4011
4214
|
}
|
4012
4215
|
return {
|
4013
4216
|
requiredQuantities: allQuantities,
|
4014
4217
|
receipts,
|
4015
4218
|
gasUsed,
|
4016
|
-
|
4017
|
-
gasPrice: setGasPrice,
|
4219
|
+
gasPrice,
|
4018
4220
|
minGas,
|
4019
4221
|
maxGas,
|
4020
4222
|
minFee,
|
4021
4223
|
maxFee,
|
4022
|
-
estimatedInputs: txRequestClone.inputs,
|
4023
4224
|
outputVariables,
|
4024
|
-
missingContractIds
|
4225
|
+
missingContractIds,
|
4226
|
+
addedSignatures,
|
4227
|
+
estimatedPredicates: txRequestClone.inputs
|
4025
4228
|
};
|
4026
4229
|
}
|
4027
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4230
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4028
4231
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4029
4232
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4030
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4233
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4234
|
+
quantitiesToContract
|
4235
|
+
});
|
4031
4236
|
transactionRequest.addResources(
|
4032
4237
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4033
4238
|
);
|
4034
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4035
|
-
|
4036
|
-
|
4037
|
-
);
|
4239
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4240
|
+
quantitiesToContract
|
4241
|
+
});
|
4038
4242
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4039
4243
|
return {
|
4040
4244
|
resources,
|
@@ -4056,11 +4260,10 @@ var _Provider = class {
|
|
4056
4260
|
return coins.map((coin) => ({
|
4057
4261
|
id: coin.utxoId,
|
4058
4262
|
assetId: coin.assetId,
|
4059
|
-
amount:
|
4263
|
+
amount: bn16(coin.amount),
|
4060
4264
|
owner: Address2.fromAddressOrString(coin.owner),
|
4061
|
-
|
4062
|
-
|
4063
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4265
|
+
blockCreated: bn16(coin.blockCreated),
|
4266
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4064
4267
|
}));
|
4065
4268
|
}
|
4066
4269
|
/**
|
@@ -4097,9 +4300,9 @@ var _Provider = class {
|
|
4097
4300
|
switch (coin.__typename) {
|
4098
4301
|
case "MessageCoin":
|
4099
4302
|
return {
|
4100
|
-
amount:
|
4303
|
+
amount: bn16(coin.amount),
|
4101
4304
|
assetId: coin.assetId,
|
4102
|
-
daHeight:
|
4305
|
+
daHeight: bn16(coin.daHeight),
|
4103
4306
|
sender: Address2.fromAddressOrString(coin.sender),
|
4104
4307
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4105
4308
|
nonce: coin.nonce
|
@@ -4107,12 +4310,11 @@ var _Provider = class {
|
|
4107
4310
|
case "Coin":
|
4108
4311
|
return {
|
4109
4312
|
id: coin.utxoId,
|
4110
|
-
amount:
|
4313
|
+
amount: bn16(coin.amount),
|
4111
4314
|
assetId: coin.assetId,
|
4112
4315
|
owner: Address2.fromAddressOrString(coin.owner),
|
4113
|
-
|
4114
|
-
|
4115
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4316
|
+
blockCreated: bn16(coin.blockCreated),
|
4317
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4116
4318
|
};
|
4117
4319
|
default:
|
4118
4320
|
return null;
|
@@ -4129,13 +4331,13 @@ var _Provider = class {
|
|
4129
4331
|
async getBlock(idOrHeight) {
|
4130
4332
|
let variables;
|
4131
4333
|
if (typeof idOrHeight === "number") {
|
4132
|
-
variables = { height:
|
4334
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4133
4335
|
} else if (idOrHeight === "latest") {
|
4134
4336
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4135
4337
|
} else if (idOrHeight.length === 66) {
|
4136
4338
|
variables = { blockId: idOrHeight };
|
4137
4339
|
} else {
|
4138
|
-
variables = { blockId:
|
4340
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4139
4341
|
}
|
4140
4342
|
const { block } = await this.operations.getBlock(variables);
|
4141
4343
|
if (!block) {
|
@@ -4143,7 +4345,7 @@ var _Provider = class {
|
|
4143
4345
|
}
|
4144
4346
|
return {
|
4145
4347
|
id: block.id,
|
4146
|
-
height:
|
4348
|
+
height: bn16(block.height),
|
4147
4349
|
time: block.header.time,
|
4148
4350
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4149
4351
|
};
|
@@ -4158,7 +4360,7 @@ var _Provider = class {
|
|
4158
4360
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4159
4361
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4160
4362
|
id: block.id,
|
4161
|
-
height:
|
4363
|
+
height: bn16(block.height),
|
4162
4364
|
time: block.header.time,
|
4163
4365
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4164
4366
|
}));
|
@@ -4173,7 +4375,7 @@ var _Provider = class {
|
|
4173
4375
|
async getBlockWithTransactions(idOrHeight) {
|
4174
4376
|
let variables;
|
4175
4377
|
if (typeof idOrHeight === "number") {
|
4176
|
-
variables = { blockHeight:
|
4378
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4177
4379
|
} else if (idOrHeight === "latest") {
|
4178
4380
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4179
4381
|
} else {
|
@@ -4185,7 +4387,7 @@ var _Provider = class {
|
|
4185
4387
|
}
|
4186
4388
|
return {
|
4187
4389
|
id: block.id,
|
4188
|
-
height:
|
4390
|
+
height: bn16(block.height, 10),
|
4189
4391
|
time: block.header.time,
|
4190
4392
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4191
4393
|
transactions: block.transactions.map(
|
@@ -4234,7 +4436,7 @@ var _Provider = class {
|
|
4234
4436
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4235
4437
|
asset: hexlify12(assetId)
|
4236
4438
|
});
|
4237
|
-
return
|
4439
|
+
return bn16(contractBalance.amount, 10);
|
4238
4440
|
}
|
4239
4441
|
/**
|
4240
4442
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4248,7 +4450,7 @@ var _Provider = class {
|
|
4248
4450
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4249
4451
|
assetId: hexlify12(assetId)
|
4250
4452
|
});
|
4251
|
-
return
|
4453
|
+
return bn16(balance.amount, 10);
|
4252
4454
|
}
|
4253
4455
|
/**
|
4254
4456
|
* Returns balances for the given owner.
|
@@ -4266,7 +4468,7 @@ var _Provider = class {
|
|
4266
4468
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4267
4469
|
return balances.map((balance) => ({
|
4268
4470
|
assetId: balance.assetId,
|
4269
|
-
amount:
|
4471
|
+
amount: bn16(balance.amount)
|
4270
4472
|
}));
|
4271
4473
|
}
|
4272
4474
|
/**
|
@@ -4288,15 +4490,15 @@ var _Provider = class {
|
|
4288
4490
|
sender: message.sender,
|
4289
4491
|
recipient: message.recipient,
|
4290
4492
|
nonce: message.nonce,
|
4291
|
-
amount:
|
4493
|
+
amount: bn16(message.amount),
|
4292
4494
|
data: message.data
|
4293
4495
|
}),
|
4294
4496
|
sender: Address2.fromAddressOrString(message.sender),
|
4295
4497
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4296
4498
|
nonce: message.nonce,
|
4297
|
-
amount:
|
4499
|
+
amount: bn16(message.amount),
|
4298
4500
|
data: InputMessageCoder.decodeData(message.data),
|
4299
|
-
daHeight:
|
4501
|
+
daHeight: bn16(message.daHeight)
|
4300
4502
|
}));
|
4301
4503
|
}
|
4302
4504
|
/**
|
@@ -4349,44 +4551,60 @@ var _Provider = class {
|
|
4349
4551
|
} = result.messageProof;
|
4350
4552
|
return {
|
4351
4553
|
messageProof: {
|
4352
|
-
proofIndex:
|
4554
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4353
4555
|
proofSet: messageProof.proofSet
|
4354
4556
|
},
|
4355
4557
|
blockProof: {
|
4356
|
-
proofIndex:
|
4558
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4357
4559
|
proofSet: blockProof.proofSet
|
4358
4560
|
},
|
4359
4561
|
messageBlockHeader: {
|
4360
4562
|
id: messageBlockHeader.id,
|
4361
|
-
daHeight:
|
4362
|
-
transactionsCount:
|
4563
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4564
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4363
4565
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4364
|
-
height:
|
4566
|
+
height: bn16(messageBlockHeader.height),
|
4365
4567
|
prevRoot: messageBlockHeader.prevRoot,
|
4366
4568
|
time: messageBlockHeader.time,
|
4367
4569
|
applicationHash: messageBlockHeader.applicationHash,
|
4368
|
-
|
4369
|
-
|
4570
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4571
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4572
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4573
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4574
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4370
4575
|
},
|
4371
4576
|
commitBlockHeader: {
|
4372
4577
|
id: commitBlockHeader.id,
|
4373
|
-
daHeight:
|
4374
|
-
transactionsCount:
|
4578
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4579
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4375
4580
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4376
|
-
height:
|
4581
|
+
height: bn16(commitBlockHeader.height),
|
4377
4582
|
prevRoot: commitBlockHeader.prevRoot,
|
4378
4583
|
time: commitBlockHeader.time,
|
4379
4584
|
applicationHash: commitBlockHeader.applicationHash,
|
4380
|
-
|
4381
|
-
|
4585
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4586
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4587
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4588
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4589
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4382
4590
|
},
|
4383
4591
|
sender: Address2.fromAddressOrString(sender),
|
4384
4592
|
recipient: Address2.fromAddressOrString(recipient),
|
4385
4593
|
nonce,
|
4386
|
-
amount:
|
4594
|
+
amount: bn16(amount),
|
4387
4595
|
data
|
4388
4596
|
};
|
4389
4597
|
}
|
4598
|
+
async getLatestGasPrice() {
|
4599
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4600
|
+
return bn16(latestGasPrice.gasPrice);
|
4601
|
+
}
|
4602
|
+
async estimateGasPrice(blockHorizon) {
|
4603
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4604
|
+
blockHorizon: String(blockHorizon)
|
4605
|
+
});
|
4606
|
+
return bn16(estimateGasPrice.gasPrice);
|
4607
|
+
}
|
4390
4608
|
/**
|
4391
4609
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4392
4610
|
*
|
@@ -4406,10 +4624,10 @@ var _Provider = class {
|
|
4406
4624
|
*/
|
4407
4625
|
async produceBlocks(amount, startTime) {
|
4408
4626
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4409
|
-
blocksToProduce:
|
4627
|
+
blocksToProduce: bn16(amount).toString(10),
|
4410
4628
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4411
4629
|
});
|
4412
|
-
return
|
4630
|
+
return bn16(latestBlockHeight);
|
4413
4631
|
}
|
4414
4632
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4415
4633
|
async getTransactionResponse(transactionId) {
|
@@ -4423,7 +4641,7 @@ cacheInputs_fn = function(inputs) {
|
|
4423
4641
|
return;
|
4424
4642
|
}
|
4425
4643
|
inputs.forEach((input) => {
|
4426
|
-
if (input.type ===
|
4644
|
+
if (input.type === InputType7.Coin) {
|
4427
4645
|
this.cache?.set(input.id);
|
4428
4646
|
}
|
4429
4647
|
});
|
@@ -4433,7 +4651,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4433
4651
|
|
4434
4652
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4435
4653
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4436
|
-
import { bn as
|
4654
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4437
4655
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4438
4656
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4439
4657
|
|
@@ -4641,9 +4859,8 @@ var Account = class extends AbstractAccount {
|
|
4641
4859
|
* @param assetId - The asset ID to check the balance for.
|
4642
4860
|
* @returns A promise that resolves to the balance amount.
|
4643
4861
|
*/
|
4644
|
-
async getBalance(assetId) {
|
4645
|
-
const
|
4646
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4862
|
+
async getBalance(assetId = BaseAssetId3) {
|
4863
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4647
4864
|
return amount;
|
4648
4865
|
}
|
4649
4866
|
/**
|
@@ -4680,37 +4897,33 @@ var Account = class extends AbstractAccount {
|
|
4680
4897
|
* @param fee - The estimated transaction fee.
|
4681
4898
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4682
4899
|
*/
|
4683
|
-
async fund(request,
|
4684
|
-
const
|
4685
|
-
const
|
4686
|
-
|
4687
|
-
|
4688
|
-
|
4900
|
+
async fund(request, params) {
|
4901
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4902
|
+
const txRequest = request;
|
4903
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4904
|
+
amount: bn18(fee),
|
4905
|
+
assetId: BaseAssetId3,
|
4906
|
+
coinQuantities: requiredQuantities
|
4689
4907
|
});
|
4690
4908
|
const quantitiesDict = {};
|
4691
|
-
|
4909
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4692
4910
|
quantitiesDict[assetId] = {
|
4693
4911
|
required: amount,
|
4694
|
-
owned:
|
4912
|
+
owned: bn18(0)
|
4695
4913
|
};
|
4696
4914
|
});
|
4697
|
-
|
4698
|
-
const cachedMessages = [];
|
4699
|
-
const owner = this.address.toB256();
|
4700
|
-
request.inputs.forEach((input) => {
|
4915
|
+
txRequest.inputs.forEach((input) => {
|
4701
4916
|
const isResource = "amount" in input;
|
4702
4917
|
if (isResource) {
|
4703
4918
|
const isCoin2 = "owner" in input;
|
4704
4919
|
if (isCoin2) {
|
4705
4920
|
const assetId = String(input.assetId);
|
4706
|
-
if (
|
4707
|
-
const amount =
|
4921
|
+
if (quantitiesDict[assetId]) {
|
4922
|
+
const amount = bn18(input.amount);
|
4708
4923
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4709
|
-
cachedUtxos.push(input.id);
|
4710
4924
|
}
|
4711
|
-
} else if (input.
|
4712
|
-
quantitiesDict[
|
4713
|
-
cachedMessages.push(input.nonce);
|
4925
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4926
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4714
4927
|
}
|
4715
4928
|
}
|
4716
4929
|
});
|
@@ -4725,12 +4938,23 @@ var Account = class extends AbstractAccount {
|
|
4725
4938
|
});
|
4726
4939
|
const needsToBeFunded = missingQuantities.length;
|
4727
4940
|
if (needsToBeFunded) {
|
4728
|
-
const
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4941
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4942
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4943
|
+
txRequest.addResources(resources);
|
4944
|
+
}
|
4945
|
+
txRequest.shiftPredicateData();
|
4946
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4947
|
+
const requestToBeReEstimate = clone4(txRequest);
|
4948
|
+
if (addedSignatures) {
|
4949
|
+
Array.from({ length: addedSignatures }).forEach(
|
4950
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4951
|
+
);
|
4733
4952
|
}
|
4953
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4954
|
+
transactionRequest: requestToBeReEstimate
|
4955
|
+
});
|
4956
|
+
txRequest.maxFee = maxFee;
|
4957
|
+
return txRequest;
|
4734
4958
|
}
|
4735
4959
|
/**
|
4736
4960
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4738,30 +4962,25 @@ var Account = class extends AbstractAccount {
|
|
4738
4962
|
* @param destination - The address of the destination.
|
4739
4963
|
* @param amount - The amount of coins to transfer.
|
4740
4964
|
* @param assetId - The asset ID of the coins to transfer.
|
4741
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4965
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4742
4966
|
* @returns A promise that resolves to the prepared transaction request.
|
4743
4967
|
*/
|
4744
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4745
|
-
const
|
4746
|
-
|
4747
|
-
const
|
4748
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4749
|
-
const request = new ScriptTransactionRequest(params);
|
4750
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4751
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4968
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4969
|
+
const request = new ScriptTransactionRequest(txParams);
|
4970
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4971
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4752
4972
|
estimateTxDependencies: true,
|
4753
4973
|
resourcesOwner: this
|
4754
4974
|
});
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4760
|
-
|
4761
|
-
|
4762
|
-
|
4763
|
-
await this.fund(request,
|
4764
|
-
request.updatePredicateInputs(estimatedInputs);
|
4975
|
+
if ("gasLimit" in txParams) {
|
4976
|
+
this.validateGas({
|
4977
|
+
gasUsed: txCost.gasUsed,
|
4978
|
+
gasLimit: request.gasLimit
|
4979
|
+
});
|
4980
|
+
}
|
4981
|
+
request.gasLimit = txCost.gasUsed;
|
4982
|
+
request.maxFee = txCost.maxFee;
|
4983
|
+
await this.fund(request, txCost);
|
4765
4984
|
return request;
|
4766
4985
|
}
|
4767
4986
|
/**
|
@@ -4773,15 +4992,14 @@ var Account = class extends AbstractAccount {
|
|
4773
4992
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4774
4993
|
* @returns A promise that resolves to the transaction response.
|
4775
4994
|
*/
|
4776
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4777
|
-
if (
|
4995
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4996
|
+
if (bn18(amount).lte(0)) {
|
4778
4997
|
throw new FuelError15(
|
4779
4998
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4780
4999
|
"Transfer amount must be a positive number."
|
4781
5000
|
);
|
4782
5001
|
}
|
4783
|
-
const
|
4784
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5002
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4785
5003
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4786
5004
|
}
|
4787
5005
|
/**
|
@@ -4793,41 +5011,38 @@ var Account = class extends AbstractAccount {
|
|
4793
5011
|
* @param txParams - The optional transaction parameters.
|
4794
5012
|
* @returns A promise that resolves to the transaction response.
|
4795
5013
|
*/
|
4796
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4797
|
-
if (
|
5014
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5015
|
+
if (bn18(amount).lte(0)) {
|
4798
5016
|
throw new FuelError15(
|
4799
5017
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4800
5018
|
"Transfer amount must be a positive number."
|
4801
5019
|
);
|
4802
5020
|
}
|
4803
5021
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4804
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4805
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4806
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4807
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4808
5022
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4809
5023
|
hexlifiedContractId: contractAddress.toB256(),
|
4810
|
-
amountToTransfer:
|
4811
|
-
assetId
|
5024
|
+
amountToTransfer: bn18(amount),
|
5025
|
+
assetId
|
4812
5026
|
});
|
4813
5027
|
const request = new ScriptTransactionRequest({
|
4814
|
-
...
|
5028
|
+
...txParams,
|
4815
5029
|
script,
|
4816
5030
|
scriptData
|
4817
5031
|
});
|
4818
5032
|
request.addContractInputAndOutput(contractAddress);
|
4819
|
-
const
|
4820
|
-
|
4821
|
-
[{ amount:
|
4822
|
-
);
|
4823
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4824
|
-
this.validateGas({
|
4825
|
-
gasUsed,
|
4826
|
-
gasPrice: request.gasPrice,
|
4827
|
-
gasLimit: request.gasLimit,
|
4828
|
-
minGasPrice
|
5033
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5034
|
+
resourcesOwner: this,
|
5035
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
4829
5036
|
});
|
4830
|
-
|
5037
|
+
if (txParams.gasLimit) {
|
5038
|
+
this.validateGas({
|
5039
|
+
gasUsed: txCost.gasUsed,
|
5040
|
+
gasLimit: request.gasLimit
|
5041
|
+
});
|
5042
|
+
}
|
5043
|
+
request.gasLimit = txCost.gasUsed;
|
5044
|
+
request.maxFee = txCost.maxFee;
|
5045
|
+
await this.fund(request, txCost);
|
4831
5046
|
return this.sendTransaction(request);
|
4832
5047
|
}
|
4833
5048
|
/**
|
@@ -4839,40 +5054,31 @@ var Account = class extends AbstractAccount {
|
|
4839
5054
|
* @returns A promise that resolves to the transaction response.
|
4840
5055
|
*/
|
4841
5056
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4842
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4843
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4844
5057
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4845
5058
|
const recipientDataArray = arrayify14(
|
4846
5059
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4847
5060
|
);
|
4848
5061
|
const amountDataArray = arrayify14(
|
4849
|
-
"0x".concat(
|
5062
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
4850
5063
|
);
|
4851
5064
|
const script = new Uint8Array([
|
4852
5065
|
...arrayify14(withdrawScript.bytes),
|
4853
5066
|
...recipientDataArray,
|
4854
5067
|
...amountDataArray
|
4855
5068
|
]);
|
4856
|
-
const params = {
|
4857
|
-
script,
|
4858
|
-
gasPrice: minGasPrice,
|
4859
|
-
baseAssetId,
|
4860
|
-
...txParams
|
4861
|
-
};
|
5069
|
+
const params = { script, ...txParams };
|
4862
5070
|
const request = new ScriptTransactionRequest(params);
|
4863
|
-
const
|
4864
|
-
const
|
4865
|
-
|
4866
|
-
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
4870
|
-
|
4871
|
-
|
4872
|
-
|
4873
|
-
|
4874
|
-
});
|
4875
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5071
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5072
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5073
|
+
if (txParams.gasLimit) {
|
5074
|
+
this.validateGas({
|
5075
|
+
gasUsed: txCost.gasUsed,
|
5076
|
+
gasLimit: request.gasLimit
|
5077
|
+
});
|
5078
|
+
}
|
5079
|
+
request.maxFee = txCost.maxFee;
|
5080
|
+
request.gasLimit = txCost.gasUsed;
|
5081
|
+
await this.fund(request, txCost);
|
4876
5082
|
return this.sendTransaction(request);
|
4877
5083
|
}
|
4878
5084
|
async signMessage(message) {
|
@@ -4930,18 +5136,7 @@ var Account = class extends AbstractAccount {
|
|
4930
5136
|
}
|
4931
5137
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4932
5138
|
}
|
4933
|
-
validateGas({
|
4934
|
-
gasUsed,
|
4935
|
-
gasPrice,
|
4936
|
-
gasLimit,
|
4937
|
-
minGasPrice
|
4938
|
-
}) {
|
4939
|
-
if (minGasPrice.gt(gasPrice)) {
|
4940
|
-
throw new FuelError15(
|
4941
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4942
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4943
|
-
);
|
4944
|
-
}
|
5139
|
+
validateGas({ gasUsed, gasLimit }) {
|
4945
5140
|
if (gasUsed.gt(gasLimit)) {
|
4946
5141
|
throw new FuelError15(
|
4947
5142
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5233,7 +5428,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5233
5428
|
* @param transactionRequestLike - The transaction request to send.
|
5234
5429
|
* @returns A promise that resolves to the TransactionResponse object.
|
5235
5430
|
*/
|
5236
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5431
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5237
5432
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5238
5433
|
if (estimateTxDependencies) {
|
5239
5434
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5274,7 +5469,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5274
5469
|
// src/hdwallet/hdwallet.ts
|
5275
5470
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5276
5471
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5277
|
-
import { bn as
|
5472
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5278
5473
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5279
5474
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5280
5475
|
|
@@ -7740,7 +7935,7 @@ var HDWallet = class {
|
|
7740
7935
|
const IR = bytes.slice(32);
|
7741
7936
|
if (privateKey) {
|
7742
7937
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7743
|
-
const ki =
|
7938
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7744
7939
|
return new HDWallet({
|
7745
7940
|
privateKey: ki,
|
7746
7941
|
chainCode: IR,
|
@@ -8011,16 +8206,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8011
8206
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
8012
8207
|
wallet.provider
|
8013
8208
|
);
|
8014
|
-
const
|
8015
|
-
|
8016
|
-
|
8017
|
-
|
8018
|
-
baseAssetId,
|
8019
|
-
gasLimit: 1e4,
|
8020
|
-
gasPrice: minGasPrice
|
8209
|
+
const request = new ScriptTransactionRequest();
|
8210
|
+
quantities.forEach((quantity) => {
|
8211
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8212
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
8021
8213
|
});
|
8022
|
-
|
8023
|
-
|
8214
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8215
|
+
request.gasLimit = txCost.gasUsed;
|
8216
|
+
request.maxFee = txCost.maxFee;
|
8217
|
+
await genesisWallet.fund(request, txCost);
|
8024
8218
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8025
8219
|
};
|
8026
8220
|
|
@@ -8034,12 +8228,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8034
8228
|
};
|
8035
8229
|
|
8036
8230
|
// src/test-utils/launchNode.ts
|
8037
|
-
import {
|
8038
|
-
import {
|
8039
|
-
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8231
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8232
|
+
import { defaultChainConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8040
8233
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8041
8234
|
import { spawn } from "child_process";
|
8042
8235
|
import { randomUUID } from "crypto";
|
8236
|
+
import { randomBytes as randomBytes6 } from "ethers";
|
8043
8237
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8044
8238
|
import os from "os";
|
8045
8239
|
import path from "path";
|
@@ -8088,12 +8282,12 @@ var launchNode = async ({
|
|
8088
8282
|
// eslint-disable-next-line no-async-promise-executor
|
8089
8283
|
new Promise(async (resolve, reject) => {
|
8090
8284
|
const remainingArgs = extractRemainingArgs(args, [
|
8091
|
-
"--
|
8285
|
+
"--snapshot",
|
8092
8286
|
"--consensus-key",
|
8093
8287
|
"--db-type",
|
8094
8288
|
"--poa-instant"
|
8095
8289
|
]);
|
8096
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8290
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8097
8291
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8098
8292
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8099
8293
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8112,36 +8306,54 @@ var launchNode = async ({
|
|
8112
8306
|
let chainConfigPathToUse;
|
8113
8307
|
const prefix = basePath || os.tmpdir();
|
8114
8308
|
const suffix = basePath ? "" : randomUUID();
|
8115
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8309
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "chainConfigs");
|
8116
8310
|
if (chainConfigPath) {
|
8117
8311
|
chainConfigPathToUse = chainConfigPath;
|
8118
8312
|
} else {
|
8119
8313
|
if (!existsSync(tempDirPath)) {
|
8120
8314
|
mkdirSync(tempDirPath, { recursive: true });
|
8121
8315
|
}
|
8122
|
-
|
8123
|
-
|
8316
|
+
let { stateConfigJson } = defaultChainConfigs;
|
8317
|
+
const { chainConfigJson, metadataJson } = defaultChainConfigs;
|
8318
|
+
stateConfigJson = {
|
8319
|
+
...stateConfigJson,
|
8320
|
+
coins: [
|
8321
|
+
...stateConfigJson.coins.map((coin) => ({
|
8322
|
+
...coin,
|
8323
|
+
amount: "18446744073709551615"
|
8324
|
+
}))
|
8325
|
+
],
|
8326
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8327
|
+
...message,
|
8328
|
+
amount: "18446744073709551615"
|
8329
|
+
}))
|
8330
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8331
|
+
};
|
8124
8332
|
if (!process.env.GENESIS_SECRET) {
|
8125
8333
|
const pk = Signer.generatePrivateKey();
|
8126
8334
|
const signer = new Signer(pk);
|
8127
8335
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8128
|
-
|
8129
|
-
|
8130
|
-
|
8131
|
-
|
8132
|
-
|
8133
|
-
|
8134
|
-
|
8135
|
-
|
8136
|
-
|
8137
|
-
|
8138
|
-
}
|
8139
|
-
]
|
8140
|
-
}
|
8141
|
-
};
|
8336
|
+
stateConfigJson.coins.push({
|
8337
|
+
tx_id: hexlify18(randomBytes6(34)),
|
8338
|
+
owner: signer.address.toHexString(),
|
8339
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8340
|
+
amount: "18446744073709551615",
|
8341
|
+
asset_id: BaseAssetId4,
|
8342
|
+
output_index: 0,
|
8343
|
+
tx_pointer_block_height: 0,
|
8344
|
+
tx_pointer_tx_idx: 0
|
8345
|
+
});
|
8142
8346
|
}
|
8143
|
-
|
8144
|
-
|
8347
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8348
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8349
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8350
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8351
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8352
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8353
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8354
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8355
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8356
|
+
chainConfigPathToUse = tempDirPath;
|
8145
8357
|
}
|
8146
8358
|
const child = spawn(
|
8147
8359
|
command,
|
@@ -8150,10 +8362,10 @@ var launchNode = async ({
|
|
8150
8362
|
["--ip", ipToUse],
|
8151
8363
|
["--port", portToUse],
|
8152
8364
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8153
|
-
["--min-gas-price", "
|
8365
|
+
["--min-gas-price", "1"],
|
8154
8366
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8155
8367
|
["--consensus-key", consensusKey],
|
8156
|
-
["--
|
8368
|
+
["--snapshot", chainConfigPathToUse],
|
8157
8369
|
"--vm-backtrace",
|
8158
8370
|
"--utxo-validation",
|
8159
8371
|
"--debug",
|
@@ -8200,10 +8412,9 @@ var launchNode = async ({
|
|
8200
8412
|
})
|
8201
8413
|
);
|
8202
8414
|
var generateWallets = async (count, provider) => {
|
8203
|
-
const baseAssetId = provider.getBaseAssetId();
|
8204
8415
|
const wallets = [];
|
8205
8416
|
for (let i = 0; i < count; i += 1) {
|
8206
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8417
|
+
const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
|
8207
8418
|
wallets.push(wallet);
|
8208
8419
|
}
|
8209
8420
|
return wallets;
|
@@ -8213,7 +8424,7 @@ var launchNodeAndGetWallets = async ({
|
|
8213
8424
|
walletCount = 10
|
8214
8425
|
} = {}) => {
|
8215
8426
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8216
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8427
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8217
8428
|
const wallets = await generateWallets(walletCount, provider);
|
8218
8429
|
const cleanup = () => {
|
8219
8430
|
closeNode();
|