@fuel-ts/account 0.0.0-rc-2037-20240411135757 → 0.0.0-rc-2021-20240411141803
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 +844 -560
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +786 -518
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +666 -399
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +888 -322
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +2 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +45 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +6 -5
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1562 -1046
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +764 -499
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +660 -395
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/test-utils.mjs
CHANGED
@@ -27,8 +27,9 @@ import { Address as Address3 } from "@fuel-ts/address";
|
|
27
27
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
30
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
31
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
+
import { clone as clone4 } from "ramda";
|
32
33
|
|
33
34
|
// src/providers/coin-quantity.ts
|
34
35
|
import { BaseAssetId } from "@fuel-ts/address/configs";
|
@@ -37,24 +38,24 @@ import { hexlify } from "@fuel-ts/utils";
|
|
37
38
|
var coinQuantityfy = (coinQuantityLike) => {
|
38
39
|
let assetId;
|
39
40
|
let amount;
|
40
|
-
let
|
41
|
+
let max;
|
41
42
|
if (Array.isArray(coinQuantityLike)) {
|
42
43
|
amount = coinQuantityLike[0];
|
43
44
|
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
44
|
-
|
45
|
+
max = coinQuantityLike[2] ?? void 0;
|
45
46
|
} else {
|
46
47
|
amount = coinQuantityLike.amount;
|
47
48
|
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
48
|
-
|
49
|
+
max = coinQuantityLike.max ?? void 0;
|
49
50
|
}
|
50
51
|
const bnAmount = bn(amount);
|
51
52
|
return {
|
52
53
|
assetId: hexlify(assetId),
|
53
54
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
54
|
-
max:
|
55
|
+
max: max ? bn(max) : void 0
|
55
56
|
};
|
56
57
|
};
|
57
|
-
var
|
58
|
+
var addAmountToCoinQuantities = (params) => {
|
58
59
|
const { amount, assetId } = params;
|
59
60
|
const coinQuantities = [...params.coinQuantities];
|
60
61
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -69,9 +70,9 @@ var addAmountToAsset = (params) => {
|
|
69
70
|
// src/providers/provider.ts
|
70
71
|
import { Address as Address2 } from "@fuel-ts/address";
|
71
72
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
72
|
-
import { BN, bn as
|
73
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
73
74
|
import {
|
74
|
-
InputType as
|
75
|
+
InputType as InputType7,
|
75
76
|
TransactionType as TransactionType8,
|
76
77
|
InputMessageCoder,
|
77
78
|
TransactionCoder as TransactionCoder5
|
@@ -87,14 +88,10 @@ import { clone as clone3 } from "ramda";
|
|
87
88
|
import gql from "graphql-tag";
|
88
89
|
var ReceiptFragmentFragmentDoc = gql`
|
89
90
|
fragment receiptFragment on Receipt {
|
90
|
-
|
91
|
-
id
|
92
|
-
}
|
91
|
+
id
|
93
92
|
pc
|
94
93
|
is
|
95
|
-
to
|
96
|
-
id
|
97
|
-
}
|
94
|
+
to
|
98
95
|
toAddress
|
99
96
|
amount
|
100
97
|
assetId
|
@@ -132,10 +129,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
132
129
|
id
|
133
130
|
}
|
134
131
|
time
|
132
|
+
receipts {
|
133
|
+
...receiptFragment
|
134
|
+
}
|
135
135
|
programState {
|
136
136
|
returnType
|
137
137
|
data
|
138
138
|
}
|
139
|
+
receipts {
|
140
|
+
...receiptFragment
|
141
|
+
}
|
139
142
|
}
|
140
143
|
... on FailureStatus {
|
141
144
|
block {
|
@@ -143,26 +146,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
143
146
|
}
|
144
147
|
time
|
145
148
|
reason
|
149
|
+
receipts {
|
150
|
+
...receiptFragment
|
151
|
+
}
|
146
152
|
}
|
147
153
|
... on SqueezedOutStatus {
|
148
154
|
reason
|
149
155
|
}
|
150
156
|
}
|
151
|
-
`;
|
157
|
+
${ReceiptFragmentFragmentDoc}`;
|
152
158
|
var TransactionFragmentFragmentDoc = gql`
|
153
159
|
fragment transactionFragment on Transaction {
|
154
160
|
id
|
155
161
|
rawPayload
|
156
|
-
gasPrice
|
157
|
-
receipts {
|
158
|
-
...receiptFragment
|
159
|
-
}
|
160
162
|
status {
|
161
163
|
...transactionStatusFragment
|
162
164
|
}
|
163
165
|
}
|
164
|
-
${
|
165
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
166
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
166
167
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
167
168
|
fragment inputEstimatePredicatesFragment on Input {
|
168
169
|
... on InputCoin {
|
@@ -180,6 +181,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
180
181
|
}
|
181
182
|
}
|
182
183
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
184
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
185
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
186
|
+
reason
|
187
|
+
programState {
|
188
|
+
returnType
|
189
|
+
data
|
190
|
+
}
|
191
|
+
}
|
192
|
+
`;
|
193
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
194
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
195
|
+
programState {
|
196
|
+
returnType
|
197
|
+
data
|
198
|
+
}
|
199
|
+
}
|
200
|
+
`;
|
201
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
202
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
203
|
+
... on DryRunFailureStatus {
|
204
|
+
...dryRunFailureStatusFragment
|
205
|
+
}
|
206
|
+
... on DryRunSuccessStatus {
|
207
|
+
...dryRunSuccessStatusFragment
|
208
|
+
}
|
209
|
+
}
|
210
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
211
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
212
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
213
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
214
|
+
id
|
215
|
+
status {
|
216
|
+
...dryRunTransactionStatusFragment
|
217
|
+
}
|
218
|
+
receipts {
|
219
|
+
...receiptFragment
|
220
|
+
}
|
221
|
+
}
|
222
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
223
|
+
${ReceiptFragmentFragmentDoc}`;
|
183
224
|
var CoinFragmentFragmentDoc = gql`
|
184
225
|
fragment coinFragment on Coin {
|
185
226
|
__typename
|
@@ -187,7 +228,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
187
228
|
owner
|
188
229
|
amount
|
189
230
|
assetId
|
190
|
-
maturity
|
191
231
|
blockCreated
|
192
232
|
txCreatedIdx
|
193
233
|
}
|
@@ -232,7 +272,6 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
232
272
|
prevRoot
|
233
273
|
time
|
234
274
|
applicationHash
|
235
|
-
messageReceiptRoot
|
236
275
|
messageReceiptCount
|
237
276
|
}
|
238
277
|
commitBlockHeader {
|
@@ -244,7 +283,6 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
244
283
|
prevRoot
|
245
284
|
time
|
246
285
|
applicationHash
|
247
|
-
messageReceiptRoot
|
248
286
|
messageReceiptCount
|
249
287
|
}
|
250
288
|
sender
|
@@ -264,8 +302,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
264
302
|
var BlockFragmentFragmentDoc = gql`
|
265
303
|
fragment blockFragment on Block {
|
266
304
|
id
|
305
|
+
height
|
267
306
|
header {
|
268
|
-
height
|
269
307
|
time
|
270
308
|
}
|
271
309
|
transactions {
|
@@ -323,6 +361,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
323
361
|
`;
|
324
362
|
var GasCostsFragmentFragmentDoc = gql`
|
325
363
|
fragment GasCostsFragment on GasCosts {
|
364
|
+
version {
|
365
|
+
... on Version {
|
366
|
+
value
|
367
|
+
}
|
368
|
+
}
|
326
369
|
add
|
327
370
|
addi
|
328
371
|
aloc
|
@@ -335,7 +378,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
335
378
|
cb
|
336
379
|
cfei
|
337
380
|
cfsi
|
338
|
-
croo
|
339
381
|
div
|
340
382
|
divi
|
341
383
|
ecr1
|
@@ -418,6 +460,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
418
460
|
ccp {
|
419
461
|
...DependentCostFragment
|
420
462
|
}
|
463
|
+
croo {
|
464
|
+
...DependentCostFragment
|
465
|
+
}
|
421
466
|
csiz {
|
422
467
|
...DependentCostFragment
|
423
468
|
}
|
@@ -477,6 +522,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
477
522
|
${DependentCostFragmentFragmentDoc}`;
|
478
523
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
479
524
|
fragment consensusParametersFragment on ConsensusParameters {
|
525
|
+
version {
|
526
|
+
... on Version {
|
527
|
+
value
|
528
|
+
}
|
529
|
+
}
|
480
530
|
txParams {
|
481
531
|
...TxParametersFragment
|
482
532
|
}
|
@@ -536,18 +586,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
536
586
|
fragment nodeInfoFragment on NodeInfo {
|
537
587
|
utxoValidation
|
538
588
|
vmBacktrace
|
539
|
-
minGasPrice
|
540
589
|
maxTx
|
541
590
|
maxDepth
|
542
591
|
nodeVersion
|
543
|
-
peers {
|
544
|
-
id
|
545
|
-
addresses
|
546
|
-
clientVersion
|
547
|
-
blockHeight
|
548
|
-
lastHeartbeatMs
|
549
|
-
appScore
|
550
|
-
}
|
551
592
|
}
|
552
593
|
`;
|
553
594
|
var GetVersionDocument = gql`
|
@@ -582,13 +623,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
582
623
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
583
624
|
transaction(id: $transactionId) {
|
584
625
|
...transactionFragment
|
585
|
-
receipts {
|
586
|
-
...receiptFragment
|
587
|
-
}
|
588
626
|
}
|
589
627
|
}
|
590
|
-
${TransactionFragmentFragmentDoc}
|
591
|
-
${ReceiptFragmentFragmentDoc}`;
|
628
|
+
${TransactionFragmentFragmentDoc}`;
|
592
629
|
var GetTransactionsDocument = gql`
|
593
630
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
594
631
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -716,6 +753,20 @@ var GetBalanceDocument = gql`
|
|
716
753
|
}
|
717
754
|
}
|
718
755
|
${BalanceFragmentFragmentDoc}`;
|
756
|
+
var GetLatestGasPriceDocument = gql`
|
757
|
+
query getLatestGasPrice {
|
758
|
+
latestGasPrice {
|
759
|
+
gasPrice
|
760
|
+
}
|
761
|
+
}
|
762
|
+
`;
|
763
|
+
var EstimateGasPriceDocument = gql`
|
764
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
765
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
766
|
+
gasPrice
|
767
|
+
}
|
768
|
+
}
|
769
|
+
`;
|
719
770
|
var GetBalancesDocument = gql`
|
720
771
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
721
772
|
balances(
|
@@ -770,12 +821,12 @@ var GetMessageStatusDocument = gql`
|
|
770
821
|
}
|
771
822
|
`;
|
772
823
|
var DryRunDocument = gql`
|
773
|
-
mutation dryRun($
|
774
|
-
dryRun(
|
775
|
-
...
|
824
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
825
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
826
|
+
...dryRunTransactionExecutionStatusFragment
|
776
827
|
}
|
777
828
|
}
|
778
|
-
${
|
829
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
779
830
|
var SubmitDocument = gql`
|
780
831
|
mutation submit($encodedTransaction: HexString!) {
|
781
832
|
submit(tx: $encodedTransaction) {
|
@@ -858,6 +909,12 @@ function getSdk(requester) {
|
|
858
909
|
getBalance(variables, options) {
|
859
910
|
return requester(GetBalanceDocument, variables, options);
|
860
911
|
},
|
912
|
+
getLatestGasPrice(variables, options) {
|
913
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
914
|
+
},
|
915
|
+
estimateGasPrice(variables, options) {
|
916
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
917
|
+
},
|
861
918
|
getBalances(variables, options) {
|
862
919
|
return requester(GetBalancesDocument, variables, options);
|
863
920
|
},
|
@@ -927,11 +984,14 @@ var _FuelGraphqlSubscriber = class {
|
|
927
984
|
let data;
|
928
985
|
let errors;
|
929
986
|
try {
|
930
|
-
|
987
|
+
const sanitizedText = text.replace(/\s/g, "");
|
988
|
+
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
931
989
|
} catch (e) {
|
932
990
|
throw new FuelError(
|
933
991
|
ErrorCode.STREAM_PARSING_ERROR,
|
934
|
-
`Error while parsing stream data response: ${text}
|
992
|
+
`Error while parsing stream data response: ${text}
|
993
|
+
|
994
|
+
Thrown error: ${e}`
|
935
995
|
);
|
936
996
|
}
|
937
997
|
if (Array.isArray(errors)) {
|
@@ -1032,7 +1092,7 @@ var inputify = (value) => {
|
|
1032
1092
|
return {
|
1033
1093
|
type: InputType.Coin,
|
1034
1094
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1035
|
-
outputIndex: arrayify(value.id)
|
1095
|
+
outputIndex: toNumber(arrayify(value.id).slice(32, 34)),
|
1036
1096
|
owner: hexlify3(value.owner),
|
1037
1097
|
amount: bn2(value.amount),
|
1038
1098
|
assetId: hexlify3(value.assetId),
|
@@ -1041,10 +1101,9 @@ var inputify = (value) => {
|
|
1041
1101
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1042
1102
|
},
|
1043
1103
|
witnessIndex: value.witnessIndex,
|
1044
|
-
maturity: value.maturity ?? 0,
|
1045
1104
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1046
|
-
predicateLength: predicate.length,
|
1047
|
-
predicateDataLength: predicateData.length,
|
1105
|
+
predicateLength: bn2(predicate.length),
|
1106
|
+
predicateDataLength: bn2(predicateData.length),
|
1048
1107
|
predicate: hexlify3(predicate),
|
1049
1108
|
predicateData: hexlify3(predicateData)
|
1050
1109
|
};
|
@@ -1075,8 +1134,8 @@ var inputify = (value) => {
|
|
1075
1134
|
nonce: hexlify3(value.nonce),
|
1076
1135
|
witnessIndex: value.witnessIndex,
|
1077
1136
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1078
|
-
predicateLength: predicate.length,
|
1079
|
-
predicateDataLength: predicateData.length,
|
1137
|
+
predicateLength: bn2(predicate.length),
|
1138
|
+
predicateDataLength: bn2(predicateData.length),
|
1080
1139
|
predicate: hexlify3(predicate),
|
1081
1140
|
predicateData: hexlify3(predicateData),
|
1082
1141
|
data: hexlify3(data),
|
@@ -1161,6 +1220,7 @@ import {
|
|
1161
1220
|
TransactionType
|
1162
1221
|
} from "@fuel-ts/transactions";
|
1163
1222
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1223
|
+
import { randomBytes } from "ethers";
|
1164
1224
|
|
1165
1225
|
// src/providers/resource.ts
|
1166
1226
|
var isCoin = (resource) => "id" in resource;
|
@@ -1201,8 +1261,8 @@ function assembleReceiptByType(receipt) {
|
|
1201
1261
|
case "CALL" /* Call */: {
|
1202
1262
|
const callReceipt = {
|
1203
1263
|
type: ReceiptType.Call,
|
1204
|
-
from: hexOrZero(receipt.
|
1205
|
-
to: hexOrZero(receipt?.to
|
1264
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1265
|
+
to: hexOrZero(receipt?.to),
|
1206
1266
|
amount: bn4(receipt.amount),
|
1207
1267
|
assetId: hexOrZero(receipt.assetId),
|
1208
1268
|
gas: bn4(receipt.gas),
|
@@ -1216,7 +1276,7 @@ function assembleReceiptByType(receipt) {
|
|
1216
1276
|
case "RETURN" /* Return */: {
|
1217
1277
|
const returnReceipt = {
|
1218
1278
|
type: ReceiptType.Return,
|
1219
|
-
id: hexOrZero(receipt.
|
1279
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1220
1280
|
val: bn4(receipt.val),
|
1221
1281
|
pc: bn4(receipt.pc),
|
1222
1282
|
is: bn4(receipt.is)
|
@@ -1226,7 +1286,7 @@ function assembleReceiptByType(receipt) {
|
|
1226
1286
|
case "RETURN_DATA" /* ReturnData */: {
|
1227
1287
|
const returnDataReceipt = {
|
1228
1288
|
type: ReceiptType.ReturnData,
|
1229
|
-
id: hexOrZero(receipt.
|
1289
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1230
1290
|
ptr: bn4(receipt.ptr),
|
1231
1291
|
len: bn4(receipt.len),
|
1232
1292
|
digest: hexOrZero(receipt.digest),
|
@@ -1238,7 +1298,7 @@ function assembleReceiptByType(receipt) {
|
|
1238
1298
|
case "PANIC" /* Panic */: {
|
1239
1299
|
const panicReceipt = {
|
1240
1300
|
type: ReceiptType.Panic,
|
1241
|
-
id: hexOrZero(receipt.
|
1301
|
+
id: hexOrZero(receipt.id),
|
1242
1302
|
reason: bn4(receipt.reason),
|
1243
1303
|
pc: bn4(receipt.pc),
|
1244
1304
|
is: bn4(receipt.is),
|
@@ -1249,7 +1309,7 @@ function assembleReceiptByType(receipt) {
|
|
1249
1309
|
case "REVERT" /* Revert */: {
|
1250
1310
|
const revertReceipt = {
|
1251
1311
|
type: ReceiptType.Revert,
|
1252
|
-
id: hexOrZero(receipt.
|
1312
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1253
1313
|
val: bn4(receipt.ra),
|
1254
1314
|
pc: bn4(receipt.pc),
|
1255
1315
|
is: bn4(receipt.is)
|
@@ -1259,7 +1319,7 @@ function assembleReceiptByType(receipt) {
|
|
1259
1319
|
case "LOG" /* Log */: {
|
1260
1320
|
const logReceipt = {
|
1261
1321
|
type: ReceiptType.Log,
|
1262
|
-
id: hexOrZero(receipt.
|
1322
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1263
1323
|
val0: bn4(receipt.ra),
|
1264
1324
|
val1: bn4(receipt.rb),
|
1265
1325
|
val2: bn4(receipt.rc),
|
@@ -1272,7 +1332,7 @@ function assembleReceiptByType(receipt) {
|
|
1272
1332
|
case "LOG_DATA" /* LogData */: {
|
1273
1333
|
const logDataReceipt = {
|
1274
1334
|
type: ReceiptType.LogData,
|
1275
|
-
id: hexOrZero(receipt.
|
1335
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1276
1336
|
val0: bn4(receipt.ra),
|
1277
1337
|
val1: bn4(receipt.rb),
|
1278
1338
|
ptr: bn4(receipt.ptr),
|
@@ -1286,8 +1346,8 @@ function assembleReceiptByType(receipt) {
|
|
1286
1346
|
case "TRANSFER" /* Transfer */: {
|
1287
1347
|
const transferReceipt = {
|
1288
1348
|
type: ReceiptType.Transfer,
|
1289
|
-
from: hexOrZero(receipt.
|
1290
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1349
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1350
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1291
1351
|
amount: bn4(receipt.amount),
|
1292
1352
|
assetId: hexOrZero(receipt.assetId),
|
1293
1353
|
pc: bn4(receipt.pc),
|
@@ -1298,8 +1358,8 @@ function assembleReceiptByType(receipt) {
|
|
1298
1358
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1299
1359
|
const transferOutReceipt = {
|
1300
1360
|
type: ReceiptType.TransferOut,
|
1301
|
-
from: hexOrZero(receipt.
|
1302
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1361
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1362
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1303
1363
|
amount: bn4(receipt.amount),
|
1304
1364
|
assetId: hexOrZero(receipt.assetId),
|
1305
1365
|
pc: bn4(receipt.pc),
|
@@ -1342,7 +1402,7 @@ function assembleReceiptByType(receipt) {
|
|
1342
1402
|
return receiptMessageOut;
|
1343
1403
|
}
|
1344
1404
|
case "MINT" /* Mint */: {
|
1345
|
-
const contractId = hexOrZero(receipt.
|
1405
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1346
1406
|
const subId = hexOrZero(receipt.subId);
|
1347
1407
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1348
1408
|
const mintReceipt = {
|
@@ -1357,7 +1417,7 @@ function assembleReceiptByType(receipt) {
|
|
1357
1417
|
return mintReceipt;
|
1358
1418
|
}
|
1359
1419
|
case "BURN" /* Burn */: {
|
1360
|
-
const contractId = hexOrZero(receipt.
|
1420
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1361
1421
|
const subId = hexOrZero(receipt.subId);
|
1362
1422
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1363
1423
|
const burnReceipt = {
|
@@ -1383,7 +1443,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1383
1443
|
import { bn as bn5 } from "@fuel-ts/math";
|
1384
1444
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1385
1445
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1386
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1387
1446
|
var getGasUsedFromReceipts = (receipts) => {
|
1388
1447
|
const scriptResult = receipts.filter(
|
1389
1448
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1404,18 +1463,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1404
1463
|
}
|
1405
1464
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1406
1465
|
const witnessCache = [];
|
1407
|
-
const
|
1466
|
+
const chargeableInputs = inputs.filter((input) => {
|
1467
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1468
|
+
if (isCoinOrMessage) {
|
1469
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1470
|
+
return true;
|
1471
|
+
}
|
1472
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1473
|
+
witnessCache.push(input.witnessIndex);
|
1474
|
+
return true;
|
1475
|
+
}
|
1476
|
+
}
|
1477
|
+
return false;
|
1478
|
+
});
|
1479
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1480
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1408
1481
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1409
1482
|
return total.add(
|
1410
|
-
|
1483
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1411
1484
|
);
|
1412
1485
|
}
|
1413
|
-
|
1414
|
-
|
1415
|
-
return total.add(gasCosts.ecr1);
|
1416
|
-
}
|
1417
|
-
return total;
|
1418
|
-
}, bn5());
|
1486
|
+
return total.add(gasCosts.ecr1);
|
1487
|
+
}, bn5(0));
|
1419
1488
|
return totalGas;
|
1420
1489
|
}
|
1421
1490
|
function getMinGas(params) {
|
@@ -1427,12 +1496,20 @@ function getMinGas(params) {
|
|
1427
1496
|
return minGas;
|
1428
1497
|
}
|
1429
1498
|
function getMaxGas(params) {
|
1430
|
-
const {
|
1499
|
+
const {
|
1500
|
+
gasPerByte,
|
1501
|
+
witnessesLength,
|
1502
|
+
witnessLimit,
|
1503
|
+
minGas,
|
1504
|
+
gasLimit = bn5(0),
|
1505
|
+
maxGasPerTx
|
1506
|
+
} = params;
|
1431
1507
|
let remainingAllowedWitnessGas = bn5(0);
|
1432
1508
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1433
1509
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1434
1510
|
}
|
1435
|
-
|
1511
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1512
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1436
1513
|
}
|
1437
1514
|
function calculateMetadataGasForTxCreate({
|
1438
1515
|
gasCosts,
|
@@ -1454,6 +1531,10 @@ function calculateMetadataGasForTxScript({
|
|
1454
1531
|
}) {
|
1455
1532
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1456
1533
|
}
|
1534
|
+
var calculateGasFee = (params) => {
|
1535
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1536
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1537
|
+
};
|
1457
1538
|
|
1458
1539
|
// src/providers/utils/json.ts
|
1459
1540
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1598,7 +1679,7 @@ var witnessify = (value) => {
|
|
1598
1679
|
// src/providers/transaction-request/transaction-request.ts
|
1599
1680
|
var BaseTransactionRequest = class {
|
1600
1681
|
/** Gas price for transaction */
|
1601
|
-
|
1682
|
+
tip;
|
1602
1683
|
/** Block until which tx cannot be included */
|
1603
1684
|
maturity;
|
1604
1685
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1617,7 +1698,7 @@ var BaseTransactionRequest = class {
|
|
1617
1698
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1618
1699
|
*/
|
1619
1700
|
constructor({
|
1620
|
-
|
1701
|
+
tip,
|
1621
1702
|
maturity,
|
1622
1703
|
maxFee,
|
1623
1704
|
witnessLimit,
|
@@ -1625,7 +1706,7 @@ var BaseTransactionRequest = class {
|
|
1625
1706
|
outputs,
|
1626
1707
|
witnesses
|
1627
1708
|
} = {}) {
|
1628
|
-
this.
|
1709
|
+
this.tip = bn7(tip);
|
1629
1710
|
this.maturity = maturity ?? 0;
|
1630
1711
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1631
1712
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1636,9 +1717,9 @@ var BaseTransactionRequest = class {
|
|
1636
1717
|
static getPolicyMeta(req) {
|
1637
1718
|
let policyTypes = 0;
|
1638
1719
|
const policies = [];
|
1639
|
-
if (req.
|
1640
|
-
policyTypes += PolicyType.
|
1641
|
-
policies.push({ data: req.
|
1720
|
+
if (req.tip) {
|
1721
|
+
policyTypes += PolicyType.Tip;
|
1722
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1642
1723
|
}
|
1643
1724
|
if (req.witnessLimit) {
|
1644
1725
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1826,9 +1907,9 @@ var BaseTransactionRequest = class {
|
|
1826
1907
|
* @param predicateData - Predicate data bytes.
|
1827
1908
|
*/
|
1828
1909
|
addCoinInput(coin) {
|
1829
|
-
const { assetId, owner, amount
|
1910
|
+
const { assetId, owner, amount } = coin;
|
1830
1911
|
let witnessIndex;
|
1831
|
-
if (predicate) {
|
1912
|
+
if (coin.predicate) {
|
1832
1913
|
witnessIndex = 0;
|
1833
1914
|
} else {
|
1834
1915
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1837,14 +1918,13 @@ var BaseTransactionRequest = class {
|
|
1837
1918
|
}
|
1838
1919
|
}
|
1839
1920
|
const input = {
|
1840
|
-
|
1921
|
+
...coin,
|
1841
1922
|
type: InputType2.Coin,
|
1842
1923
|
owner: owner.toB256(),
|
1843
1924
|
amount,
|
1844
1925
|
assetId,
|
1845
1926
|
txPointer: "0x00000000000000000000000000000000",
|
1846
|
-
witnessIndex
|
1847
|
-
predicate
|
1927
|
+
witnessIndex
|
1848
1928
|
};
|
1849
1929
|
this.pushInput(input);
|
1850
1930
|
this.addChangeOutput(owner, assetId);
|
@@ -1858,10 +1938,10 @@ var BaseTransactionRequest = class {
|
|
1858
1938
|
* @param predicateData - Predicate data bytes.
|
1859
1939
|
*/
|
1860
1940
|
addMessageInput(message) {
|
1861
|
-
const { recipient, sender, amount
|
1941
|
+
const { recipient, sender, amount } = message;
|
1862
1942
|
const assetId = BaseAssetId2;
|
1863
1943
|
let witnessIndex;
|
1864
|
-
if (predicate) {
|
1944
|
+
if (message.predicate) {
|
1865
1945
|
witnessIndex = 0;
|
1866
1946
|
} else {
|
1867
1947
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1870,13 +1950,12 @@ var BaseTransactionRequest = class {
|
|
1870
1950
|
}
|
1871
1951
|
}
|
1872
1952
|
const input = {
|
1873
|
-
|
1953
|
+
...message,
|
1874
1954
|
type: InputType2.Message,
|
1875
1955
|
sender: sender.toB256(),
|
1876
1956
|
recipient: recipient.toB256(),
|
1877
1957
|
amount,
|
1878
|
-
witnessIndex
|
1879
|
-
predicate
|
1958
|
+
witnessIndex
|
1880
1959
|
};
|
1881
1960
|
this.pushInput(input);
|
1882
1961
|
this.addChangeOutput(recipient, assetId);
|
@@ -1986,7 +2065,7 @@ var BaseTransactionRequest = class {
|
|
1986
2065
|
}
|
1987
2066
|
calculateMaxGas(chainInfo, minGas) {
|
1988
2067
|
const { consensusParameters } = chainInfo;
|
1989
|
-
const { gasPerByte } = consensusParameters;
|
2068
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
1990
2069
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
1991
2070
|
(acc, wit) => acc + wit.dataLength,
|
1992
2071
|
0
|
@@ -1995,7 +2074,8 @@ var BaseTransactionRequest = class {
|
|
1995
2074
|
gasPerByte,
|
1996
2075
|
minGas,
|
1997
2076
|
witnessesLength,
|
1998
|
-
witnessLimit: this.witnessLimit
|
2077
|
+
witnessLimit: this.witnessLimit,
|
2078
|
+
maxGasPerTx
|
1999
2079
|
});
|
2000
2080
|
}
|
2001
2081
|
/**
|
@@ -2005,12 +2085,6 @@ var BaseTransactionRequest = class {
|
|
2005
2085
|
* @param quantities - CoinQuantity Array.
|
2006
2086
|
*/
|
2007
2087
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2008
|
-
let idCounter = 0;
|
2009
|
-
const generateId = () => {
|
2010
|
-
const counterString = String(idCounter++);
|
2011
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2012
|
-
return id;
|
2013
|
-
};
|
2014
2088
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2015
2089
|
if ("assetId" in input) {
|
2016
2090
|
return input.assetId === assetId;
|
@@ -2019,17 +2093,20 @@ var BaseTransactionRequest = class {
|
|
2019
2093
|
});
|
2020
2094
|
const updateAssetInput = (assetId, quantity) => {
|
2021
2095
|
const assetInput = findAssetInput(assetId);
|
2096
|
+
let usedQuantity = quantity;
|
2097
|
+
if (assetId === BaseAssetId2) {
|
2098
|
+
usedQuantity = bn7("1000000000000000000");
|
2099
|
+
}
|
2022
2100
|
if (assetInput && "assetId" in assetInput) {
|
2023
|
-
assetInput.id =
|
2024
|
-
assetInput.amount =
|
2101
|
+
assetInput.id = hexlify7(randomBytes(34));
|
2102
|
+
assetInput.amount = usedQuantity;
|
2025
2103
|
} else {
|
2026
2104
|
this.addResources([
|
2027
2105
|
{
|
2028
|
-
id:
|
2029
|
-
amount:
|
2106
|
+
id: hexlify7(randomBytes(34)),
|
2107
|
+
amount: usedQuantity,
|
2030
2108
|
assetId,
|
2031
2109
|
owner: resourcesOwner || Address.fromRandom(),
|
2032
|
-
maturity: 0,
|
2033
2110
|
blockCreated: bn7(1),
|
2034
2111
|
txCreatedIdx: bn7(1)
|
2035
2112
|
}
|
@@ -2061,7 +2138,7 @@ var BaseTransactionRequest = class {
|
|
2061
2138
|
toJSON() {
|
2062
2139
|
return normalizeJSON(this);
|
2063
2140
|
}
|
2064
|
-
|
2141
|
+
updatePredicateGasUsed(inputs) {
|
2065
2142
|
this.inputs.forEach((i) => {
|
2066
2143
|
let correspondingInput;
|
2067
2144
|
switch (i.type) {
|
@@ -2083,6 +2160,15 @@ var BaseTransactionRequest = class {
|
|
2083
2160
|
}
|
2084
2161
|
});
|
2085
2162
|
}
|
2163
|
+
shiftPredicateData() {
|
2164
|
+
this.inputs.forEach((input) => {
|
2165
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2166
|
+
input.predicateData = input.paddPredicateData(
|
2167
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2168
|
+
);
|
2169
|
+
}
|
2170
|
+
});
|
2171
|
+
}
|
2086
2172
|
};
|
2087
2173
|
|
2088
2174
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2229,9 +2315,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2229
2315
|
return {
|
2230
2316
|
type: TransactionType3.Create,
|
2231
2317
|
...baseTransaction,
|
2232
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2233
2318
|
bytecodeWitnessIndex,
|
2234
|
-
storageSlotsCount: storageSlots.length,
|
2319
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2235
2320
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2236
2321
|
storageSlots
|
2237
2322
|
};
|
@@ -2354,8 +2439,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2354
2439
|
type: TransactionType4.Script,
|
2355
2440
|
scriptGasLimit: this.gasLimit,
|
2356
2441
|
...super.getBaseTransaction(),
|
2357
|
-
scriptLength: script.length,
|
2358
|
-
scriptDataLength: scriptData.length,
|
2442
|
+
scriptLength: bn10(script.length),
|
2443
|
+
scriptDataLength: bn10(scriptData.length),
|
2359
2444
|
receiptsRoot: ZeroBytes327,
|
2360
2445
|
script: hexlify10(script),
|
2361
2446
|
scriptData: hexlify10(scriptData)
|
@@ -2419,7 +2504,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2419
2504
|
}
|
2420
2505
|
calculateMaxGas(chainInfo, minGas) {
|
2421
2506
|
const { consensusParameters } = chainInfo;
|
2422
|
-
const { gasPerByte } = consensusParameters;
|
2507
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2423
2508
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2424
2509
|
(acc, wit) => acc + wit.dataLength,
|
2425
2510
|
0
|
@@ -2429,7 +2514,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2429
2514
|
minGas,
|
2430
2515
|
witnessesLength,
|
2431
2516
|
witnessLimit: this.witnessLimit,
|
2432
|
-
gasLimit: this.gasLimit
|
2517
|
+
gasLimit: this.gasLimit,
|
2518
|
+
maxGasPerTx
|
2433
2519
|
});
|
2434
2520
|
}
|
2435
2521
|
/**
|
@@ -2486,7 +2572,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2486
2572
|
|
2487
2573
|
// src/providers/transaction-request/utils.ts
|
2488
2574
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2489
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2575
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2490
2576
|
var transactionRequestify = (obj) => {
|
2491
2577
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2492
2578
|
return obj;
|
@@ -2504,14 +2590,31 @@ var transactionRequestify = (obj) => {
|
|
2504
2590
|
}
|
2505
2591
|
}
|
2506
2592
|
};
|
2593
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2594
|
+
(acc, input) => {
|
2595
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2596
|
+
acc.utxos.push(input.id);
|
2597
|
+
}
|
2598
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2599
|
+
acc.messages.push(input.nonce);
|
2600
|
+
}
|
2601
|
+
return acc;
|
2602
|
+
},
|
2603
|
+
{
|
2604
|
+
utxos: [],
|
2605
|
+
messages: []
|
2606
|
+
}
|
2607
|
+
);
|
2507
2608
|
|
2508
2609
|
// src/providers/transaction-response/transaction-response.ts
|
2509
2610
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2510
|
-
import { bn as
|
2611
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2511
2612
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2512
2613
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2513
2614
|
|
2514
2615
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2616
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2617
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2515
2618
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2516
2619
|
|
2517
2620
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2520,9 +2623,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2520
2623
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2521
2624
|
var calculateTransactionFee = (params) => {
|
2522
2625
|
const {
|
2523
|
-
|
2626
|
+
gasPrice,
|
2524
2627
|
rawPayload,
|
2525
|
-
|
2628
|
+
tip,
|
2629
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2526
2630
|
} = params;
|
2527
2631
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2528
2632
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2532,8 +2636,7 @@ var calculateTransactionFee = (params) => {
|
|
2532
2636
|
return {
|
2533
2637
|
fee: bn11(0),
|
2534
2638
|
minFee: bn11(0),
|
2535
|
-
maxFee: bn11(0)
|
2536
|
-
feeFromGasUsed: bn11(0)
|
2639
|
+
maxFee: bn11(0)
|
2537
2640
|
};
|
2538
2641
|
}
|
2539
2642
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2565,7 +2668,6 @@ var calculateTransactionFee = (params) => {
|
|
2565
2668
|
metadataGas,
|
2566
2669
|
txBytesSize: transactionBytes.length
|
2567
2670
|
});
|
2568
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2569
2671
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2570
2672
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2571
2673
|
const maxGas = getMaxGas({
|
@@ -2573,17 +2675,25 @@ var calculateTransactionFee = (params) => {
|
|
2573
2675
|
minGas,
|
2574
2676
|
witnessesLength,
|
2575
2677
|
gasLimit,
|
2576
|
-
witnessLimit
|
2678
|
+
witnessLimit,
|
2679
|
+
maxGasPerTx
|
2680
|
+
});
|
2681
|
+
const minFee = calculateGasFee({
|
2682
|
+
gasPrice,
|
2683
|
+
gas: minGas,
|
2684
|
+
priceFactor: gasPriceFactor,
|
2685
|
+
tip
|
2686
|
+
});
|
2687
|
+
const maxFee = calculateGasFee({
|
2688
|
+
gasPrice,
|
2689
|
+
gas: maxGas,
|
2690
|
+
priceFactor: gasPriceFactor,
|
2691
|
+
tip
|
2577
2692
|
});
|
2578
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2579
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2580
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2581
|
-
const fee = minFee.add(feeFromGasUsed);
|
2582
2693
|
return {
|
2583
|
-
fee,
|
2584
2694
|
minFee,
|
2585
2695
|
maxFee,
|
2586
|
-
|
2696
|
+
fee: maxFee
|
2587
2697
|
};
|
2588
2698
|
};
|
2589
2699
|
|
@@ -2639,7 +2749,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2639
2749
|
|
2640
2750
|
// src/providers/transaction-summary/input.ts
|
2641
2751
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2642
|
-
import { InputType as
|
2752
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2643
2753
|
function getInputsByTypes(inputs, types) {
|
2644
2754
|
return inputs.filter((i) => types.includes(i.type));
|
2645
2755
|
}
|
@@ -2647,16 +2757,16 @@ function getInputsByType(inputs, type) {
|
|
2647
2757
|
return inputs.filter((i) => i.type === type);
|
2648
2758
|
}
|
2649
2759
|
function getInputsCoin(inputs) {
|
2650
|
-
return getInputsByType(inputs,
|
2760
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2651
2761
|
}
|
2652
2762
|
function getInputsMessage(inputs) {
|
2653
|
-
return getInputsByType(inputs,
|
2763
|
+
return getInputsByType(inputs, InputType6.Message);
|
2654
2764
|
}
|
2655
2765
|
function getInputsCoinAndMessage(inputs) {
|
2656
|
-
return getInputsByTypes(inputs, [
|
2766
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2657
2767
|
}
|
2658
2768
|
function getInputsContract(inputs) {
|
2659
|
-
return getInputsByType(inputs,
|
2769
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2660
2770
|
}
|
2661
2771
|
function getInputFromAssetId(inputs, assetId) {
|
2662
2772
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2675,7 +2785,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2675
2785
|
if (!contractInput) {
|
2676
2786
|
return void 0;
|
2677
2787
|
}
|
2678
|
-
if (contractInput.type !==
|
2788
|
+
if (contractInput.type !== InputType6.Contract) {
|
2679
2789
|
throw new FuelError9(
|
2680
2790
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2681
2791
|
`Contract input should be of type 'contract'.`
|
@@ -2684,10 +2794,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2684
2794
|
return contractInput;
|
2685
2795
|
}
|
2686
2796
|
function getInputAccountAddress(input) {
|
2687
|
-
if (input.type ===
|
2797
|
+
if (input.type === InputType6.Coin) {
|
2688
2798
|
return input.owner.toString();
|
2689
2799
|
}
|
2690
|
-
if (input.type ===
|
2800
|
+
if (input.type === InputType6.Message) {
|
2691
2801
|
return input.recipient.toString();
|
2692
2802
|
}
|
2693
2803
|
return "";
|
@@ -3150,7 +3260,9 @@ function assembleTransactionSummary(params) {
|
|
3150
3260
|
gqlTransactionStatus,
|
3151
3261
|
abiMap = {},
|
3152
3262
|
maxInputs,
|
3153
|
-
gasCosts
|
3263
|
+
gasCosts,
|
3264
|
+
maxGasPerTx,
|
3265
|
+
gasPrice
|
3154
3266
|
} = params;
|
3155
3267
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3156
3268
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3164,11 +3276,14 @@ function assembleTransactionSummary(params) {
|
|
3164
3276
|
maxInputs
|
3165
3277
|
});
|
3166
3278
|
const typeName = getTransactionTypeName(transaction.type);
|
3279
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3167
3280
|
const { fee } = calculateTransactionFee({
|
3168
|
-
|
3281
|
+
gasPrice,
|
3169
3282
|
rawPayload,
|
3283
|
+
tip,
|
3170
3284
|
consensusParameters: {
|
3171
3285
|
gasCosts,
|
3286
|
+
maxGasPerTx,
|
3172
3287
|
feeParams: {
|
3173
3288
|
gasPerByte,
|
3174
3289
|
gasPriceFactor
|
@@ -3228,7 +3343,7 @@ var TransactionResponse = class {
|
|
3228
3343
|
/** Current provider */
|
3229
3344
|
provider;
|
3230
3345
|
/** Gas used on the transaction */
|
3231
|
-
gasUsed =
|
3346
|
+
gasUsed = bn15(0);
|
3232
3347
|
/** The graphql Transaction with receipts object. */
|
3233
3348
|
gqlTransaction;
|
3234
3349
|
abis;
|
@@ -3306,8 +3421,13 @@ var TransactionResponse = class {
|
|
3306
3421
|
const decodedTransaction = this.decodeTransaction(
|
3307
3422
|
transaction
|
3308
3423
|
);
|
3309
|
-
|
3310
|
-
|
3424
|
+
let txReceipts = [];
|
3425
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3426
|
+
txReceipts = transaction.status.receipts;
|
3427
|
+
}
|
3428
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3429
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3430
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3311
3431
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3312
3432
|
const transactionSummary = assembleTransactionSummary({
|
3313
3433
|
id: this.id,
|
@@ -3319,7 +3439,9 @@ var TransactionResponse = class {
|
|
3319
3439
|
gasPriceFactor,
|
3320
3440
|
abiMap: contractsAbiMap,
|
3321
3441
|
maxInputs,
|
3322
|
-
gasCosts
|
3442
|
+
gasCosts,
|
3443
|
+
maxGasPerTx,
|
3444
|
+
gasPrice
|
3323
3445
|
});
|
3324
3446
|
return transactionSummary;
|
3325
3447
|
}
|
@@ -3446,29 +3568,29 @@ var processGqlChain = (chain) => {
|
|
3446
3568
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3447
3569
|
return {
|
3448
3570
|
name,
|
3449
|
-
baseChainHeight:
|
3571
|
+
baseChainHeight: bn16(daHeight),
|
3450
3572
|
consensusParameters: {
|
3451
|
-
contractMaxSize:
|
3452
|
-
maxInputs:
|
3453
|
-
maxOutputs:
|
3454
|
-
maxWitnesses:
|
3455
|
-
maxGasPerTx:
|
3456
|
-
maxScriptLength:
|
3457
|
-
maxScriptDataLength:
|
3458
|
-
maxStorageSlots:
|
3459
|
-
maxPredicateLength:
|
3460
|
-
maxPredicateDataLength:
|
3461
|
-
maxGasPerPredicate:
|
3462
|
-
gasPriceFactor:
|
3463
|
-
gasPerByte:
|
3464
|
-
maxMessageDataLength:
|
3465
|
-
chainId:
|
3573
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3574
|
+
maxInputs: bn16(txParams.maxInputs),
|
3575
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3576
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3577
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3578
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3579
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3580
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3581
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3582
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3583
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3584
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3585
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3586
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3587
|
+
chainId: bn16(consensusParameters.chainId),
|
3466
3588
|
gasCosts
|
3467
3589
|
},
|
3468
3590
|
gasCosts,
|
3469
3591
|
latestBlock: {
|
3470
3592
|
id: latestBlock.id,
|
3471
|
-
height:
|
3593
|
+
height: bn16(latestBlock.height),
|
3472
3594
|
time: latestBlock.header.time,
|
3473
3595
|
transactions: latestBlock.transactions.map((i) => ({
|
3474
3596
|
id: i.id
|
@@ -3562,10 +3684,8 @@ var _Provider = class {
|
|
3562
3684
|
* Returns some helpful parameters related to gas fees.
|
3563
3685
|
*/
|
3564
3686
|
getGasConfig() {
|
3565
|
-
const { minGasPrice } = this.getNode();
|
3566
3687
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3567
3688
|
return {
|
3568
|
-
minGasPrice,
|
3569
3689
|
maxGasPerTx,
|
3570
3690
|
maxGasPerPredicate,
|
3571
3691
|
gasPriceFactor,
|
@@ -3663,7 +3783,7 @@ var _Provider = class {
|
|
3663
3783
|
*/
|
3664
3784
|
async getBlockNumber() {
|
3665
3785
|
const { chain } = await this.operations.getChain();
|
3666
|
-
return
|
3786
|
+
return bn16(chain.latestBlock.height, 10);
|
3667
3787
|
}
|
3668
3788
|
/**
|
3669
3789
|
* Returns the chain information.
|
@@ -3673,13 +3793,11 @@ var _Provider = class {
|
|
3673
3793
|
async fetchNode() {
|
3674
3794
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3675
3795
|
const processedNodeInfo = {
|
3676
|
-
maxDepth:
|
3677
|
-
maxTx:
|
3678
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3796
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3797
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3679
3798
|
nodeVersion: nodeInfo.nodeVersion,
|
3680
3799
|
utxoValidation: nodeInfo.utxoValidation,
|
3681
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3682
|
-
peers: nodeInfo.peers
|
3800
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3683
3801
|
};
|
3684
3802
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3685
3803
|
return processedNodeInfo;
|
@@ -3765,14 +3883,13 @@ var _Provider = class {
|
|
3765
3883
|
return this.estimateTxDependencies(transactionRequest);
|
3766
3884
|
}
|
3767
3885
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3768
|
-
const { dryRun:
|
3769
|
-
encodedTransaction,
|
3886
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3887
|
+
encodedTransactions: encodedTransaction,
|
3770
3888
|
utxoValidation: utxoValidation || false
|
3771
3889
|
});
|
3772
|
-
const receipts =
|
3773
|
-
|
3774
|
-
|
3775
|
-
};
|
3890
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3891
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3892
|
+
return { receipts, dryrunStatus: status };
|
3776
3893
|
}
|
3777
3894
|
/**
|
3778
3895
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3798,7 +3915,7 @@ var _Provider = class {
|
|
3798
3915
|
} = response;
|
3799
3916
|
if (inputs) {
|
3800
3917
|
inputs.forEach((input, index) => {
|
3801
|
-
if ("predicateGasUsed" in input &&
|
3918
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3802
3919
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3803
3920
|
}
|
3804
3921
|
});
|
@@ -3811,9 +3928,6 @@ var _Provider = class {
|
|
3811
3928
|
* If there are missing variable outputs,
|
3812
3929
|
* `addVariableOutputs` is called on the transaction.
|
3813
3930
|
*
|
3814
|
-
* @privateRemarks
|
3815
|
-
* TODO: Investigate support for missing contract IDs
|
3816
|
-
* TODO: Add support for missing output messages
|
3817
3931
|
*
|
3818
3932
|
* @param transactionRequest - The transaction request object.
|
3819
3933
|
* @returns A promise.
|
@@ -3826,16 +3940,19 @@ var _Provider = class {
|
|
3826
3940
|
missingContractIds: []
|
3827
3941
|
};
|
3828
3942
|
}
|
3829
|
-
await this.estimatePredicates(transactionRequest);
|
3830
3943
|
let receipts = [];
|
3831
3944
|
const missingContractIds = [];
|
3832
3945
|
let outputVariables = 0;
|
3946
|
+
let dryrunStatus;
|
3833
3947
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3834
|
-
const {
|
3835
|
-
|
3948
|
+
const {
|
3949
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3950
|
+
} = await this.operations.dryRun({
|
3951
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3836
3952
|
utxoValidation: false
|
3837
3953
|
});
|
3838
|
-
receipts =
|
3954
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3955
|
+
dryrunStatus = status;
|
3839
3956
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3840
3957
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3841
3958
|
if (hasMissingOutputs) {
|
@@ -3845,6 +3962,11 @@ var _Provider = class {
|
|
3845
3962
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3846
3963
|
missingContractIds.push(contractId);
|
3847
3964
|
});
|
3965
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3966
|
+
transactionRequest,
|
3967
|
+
optimizeGas: false
|
3968
|
+
});
|
3969
|
+
transactionRequest.maxFee = maxFee;
|
3848
3970
|
} else {
|
3849
3971
|
break;
|
3850
3972
|
}
|
@@ -3852,7 +3974,133 @@ var _Provider = class {
|
|
3852
3974
|
return {
|
3853
3975
|
receipts,
|
3854
3976
|
outputVariables,
|
3855
|
-
missingContractIds
|
3977
|
+
missingContractIds,
|
3978
|
+
dryrunStatus
|
3979
|
+
};
|
3980
|
+
}
|
3981
|
+
/**
|
3982
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3983
|
+
*
|
3984
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3985
|
+
* further modifications are identified. The method iteratively updates these transactions
|
3986
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3987
|
+
*
|
3988
|
+
* @param transactionRequests - Array of transaction request objects.
|
3989
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
3990
|
+
*/
|
3991
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
3992
|
+
const results = transactionRequests.map(() => ({
|
3993
|
+
receipts: [],
|
3994
|
+
outputVariables: 0,
|
3995
|
+
missingContractIds: [],
|
3996
|
+
dryrunStatus: void 0
|
3997
|
+
}));
|
3998
|
+
const allRequests = clone3(transactionRequests);
|
3999
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4000
|
+
allRequests.forEach((req, index) => {
|
4001
|
+
if (req.type === TransactionType8.Script) {
|
4002
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4003
|
+
}
|
4004
|
+
});
|
4005
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4006
|
+
let attempt = 0;
|
4007
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4008
|
+
const encodedTransactions = transactionsToProcess.map(
|
4009
|
+
(index) => serializedTransactionsMap.get(index)
|
4010
|
+
);
|
4011
|
+
const dryRunResults = await this.operations.dryRun({
|
4012
|
+
encodedTransactions,
|
4013
|
+
utxoValidation: false
|
4014
|
+
});
|
4015
|
+
const nextRoundTransactions = [];
|
4016
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4017
|
+
const currentResultIndex = transactionsToProcess[i];
|
4018
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4019
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4020
|
+
results[currentResultIndex].dryrunStatus = status;
|
4021
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4022
|
+
results[currentResultIndex].receipts
|
4023
|
+
);
|
4024
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4025
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4026
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4027
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4028
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4029
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4030
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4031
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4032
|
+
});
|
4033
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4034
|
+
transactionRequest: requestToProcess,
|
4035
|
+
optimizeGas: false
|
4036
|
+
});
|
4037
|
+
requestToProcess.maxFee = maxFee;
|
4038
|
+
serializedTransactionsMap.set(
|
4039
|
+
currentResultIndex,
|
4040
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4041
|
+
);
|
4042
|
+
nextRoundTransactions.push(currentResultIndex);
|
4043
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4044
|
+
}
|
4045
|
+
}
|
4046
|
+
transactionsToProcess = nextRoundTransactions;
|
4047
|
+
attempt += 1;
|
4048
|
+
}
|
4049
|
+
return results;
|
4050
|
+
}
|
4051
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4052
|
+
if (estimateTxDependencies) {
|
4053
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4054
|
+
}
|
4055
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4056
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4057
|
+
encodedTransactions,
|
4058
|
+
utxoValidation: utxoValidation || false
|
4059
|
+
});
|
4060
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4061
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4062
|
+
return { receipts, dryrunStatus: status };
|
4063
|
+
});
|
4064
|
+
return results;
|
4065
|
+
}
|
4066
|
+
async estimateTxGasAndFee(params) {
|
4067
|
+
const { transactionRequest, optimizeGas = true } = params;
|
4068
|
+
let { gasPrice } = params;
|
4069
|
+
const chainInfo = this.getChain();
|
4070
|
+
const { gasPriceFactor } = this.getGasConfig();
|
4071
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4072
|
+
if (!gasPrice) {
|
4073
|
+
gasPrice = await this.estimateGasPrice(10);
|
4074
|
+
}
|
4075
|
+
const minFee = calculateGasFee({
|
4076
|
+
gasPrice: bn16(gasPrice),
|
4077
|
+
gas: minGas,
|
4078
|
+
priceFactor: gasPriceFactor,
|
4079
|
+
tip: transactionRequest.tip
|
4080
|
+
}).add(1);
|
4081
|
+
let gasLimit = bn16(0);
|
4082
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
4083
|
+
gasLimit = transactionRequest.gasLimit;
|
4084
|
+
if (!optimizeGas) {
|
4085
|
+
transactionRequest.gasLimit = minGas;
|
4086
|
+
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4087
|
+
transactionRequest.gasLimit = gasLimit;
|
4088
|
+
}
|
4089
|
+
}
|
4090
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4091
|
+
const maxFee = calculateGasFee({
|
4092
|
+
gasPrice: bn16(gasPrice),
|
4093
|
+
gas: maxGas,
|
4094
|
+
priceFactor: gasPriceFactor,
|
4095
|
+
tip: transactionRequest.tip
|
4096
|
+
}).add(1);
|
4097
|
+
return {
|
4098
|
+
minGas,
|
4099
|
+
minFee,
|
4100
|
+
maxGas,
|
4101
|
+
maxFee,
|
4102
|
+
gasPrice,
|
4103
|
+
gasLimit
|
3856
4104
|
};
|
3857
4105
|
}
|
3858
4106
|
/**
|
@@ -3870,15 +4118,17 @@ var _Provider = class {
|
|
3870
4118
|
if (estimateTxDependencies) {
|
3871
4119
|
return this.estimateTxDependencies(transactionRequest);
|
3872
4120
|
}
|
3873
|
-
const
|
3874
|
-
const { dryRun:
|
3875
|
-
|
4121
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4122
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4123
|
+
encodedTransactions,
|
3876
4124
|
utxoValidation: true
|
3877
4125
|
});
|
3878
|
-
const
|
3879
|
-
|
3880
|
-
receipts
|
3881
|
-
|
4126
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4127
|
+
const { id, receipts, status } = dryRunStatus;
|
4128
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4129
|
+
return { id, receipts: processedReceipts, status };
|
4130
|
+
});
|
4131
|
+
return { receipts: callResult[0].receipts };
|
3882
4132
|
}
|
3883
4133
|
/**
|
3884
4134
|
* Returns a transaction cost to enable user
|
@@ -3895,80 +4145,80 @@ var _Provider = class {
|
|
3895
4145
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3896
4146
|
* @returns A promise that resolves to the transaction cost object.
|
3897
4147
|
*/
|
3898
|
-
async getTransactionCost(transactionRequestLike,
|
3899
|
-
estimateTxDependencies = true,
|
3900
|
-
estimatePredicates = true,
|
3901
|
-
resourcesOwner,
|
3902
|
-
signatureCallback
|
3903
|
-
} = {}) {
|
4148
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3904
4149
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3905
|
-
const chainInfo = this.getChain();
|
3906
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3907
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3908
4150
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3909
4151
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3910
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4152
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3911
4153
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3912
|
-
|
3913
|
-
|
3914
|
-
|
3915
|
-
}
|
3916
|
-
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3917
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3918
|
-
}
|
3919
|
-
await this.estimatePredicates(txRequestClone);
|
4154
|
+
txRequestClone.maxFee = bn16(0);
|
4155
|
+
if (isScriptTransaction) {
|
4156
|
+
txRequestClone.gasLimit = bn16(0);
|
3920
4157
|
}
|
3921
|
-
if (
|
3922
|
-
|
4158
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4159
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3923
4160
|
}
|
3924
|
-
const
|
3925
|
-
|
4161
|
+
const signedRequest = clone3(txRequestClone);
|
4162
|
+
let addedSignatures = 0;
|
4163
|
+
if (signatureCallback && isScriptTransaction) {
|
4164
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4165
|
+
await signatureCallback(signedRequest);
|
4166
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4167
|
+
}
|
4168
|
+
await this.estimatePredicates(signedRequest);
|
4169
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4170
|
+
transactionRequest: signedRequest,
|
4171
|
+
optimizeGas: false
|
4172
|
+
});
|
4173
|
+
txRequestClone.maxFee = maxFee;
|
3926
4174
|
let receipts = [];
|
3927
4175
|
let missingContractIds = [];
|
3928
4176
|
let outputVariables = 0;
|
3929
|
-
|
3930
|
-
|
3931
|
-
|
4177
|
+
let gasUsed = bn16(0);
|
4178
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4179
|
+
if (isScriptTransaction) {
|
4180
|
+
if (signatureCallback) {
|
4181
|
+
await signatureCallback(txRequestClone);
|
4182
|
+
}
|
4183
|
+
txRequestClone.gasLimit = gasLimit;
|
3932
4184
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3933
4185
|
receipts = result.receipts;
|
3934
4186
|
outputVariables = result.outputVariables;
|
3935
4187
|
missingContractIds = result.missingContractIds;
|
4188
|
+
gasUsed = getGasUsedFromReceipts(receipts);
|
4189
|
+
txRequestClone.gasLimit = gasUsed;
|
4190
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4191
|
+
transactionRequest: txRequestClone,
|
4192
|
+
gasPrice
|
4193
|
+
}));
|
3936
4194
|
}
|
3937
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3938
|
-
const usedFee = calculatePriceWithFactor(
|
3939
|
-
gasUsed,
|
3940
|
-
gasPrice,
|
3941
|
-
gasPriceFactor
|
3942
|
-
).normalizeZeroToOne();
|
3943
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3944
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3945
4195
|
return {
|
3946
4196
|
requiredQuantities: allQuantities,
|
3947
4197
|
receipts,
|
3948
4198
|
gasUsed,
|
3949
|
-
minGasPrice,
|
3950
4199
|
gasPrice,
|
3951
4200
|
minGas,
|
3952
4201
|
maxGas,
|
3953
|
-
usedFee,
|
3954
4202
|
minFee,
|
3955
4203
|
maxFee,
|
3956
|
-
estimatedInputs: txRequestClone.inputs,
|
3957
4204
|
outputVariables,
|
3958
|
-
missingContractIds
|
4205
|
+
missingContractIds,
|
4206
|
+
addedSignatures,
|
4207
|
+
estimatedPredicates: txRequestClone.inputs
|
3959
4208
|
};
|
3960
4209
|
}
|
3961
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4210
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
3962
4211
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
3963
4212
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
3964
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4213
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4214
|
+
quantitiesToContract
|
4215
|
+
});
|
3965
4216
|
transactionRequest.addResources(
|
3966
4217
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
3967
4218
|
);
|
3968
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
3969
|
-
|
3970
|
-
|
3971
|
-
);
|
4219
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4220
|
+
quantitiesToContract
|
4221
|
+
});
|
3972
4222
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
3973
4223
|
return {
|
3974
4224
|
resources,
|
@@ -3990,11 +4240,10 @@ var _Provider = class {
|
|
3990
4240
|
return coins.map((coin) => ({
|
3991
4241
|
id: coin.utxoId,
|
3992
4242
|
assetId: coin.assetId,
|
3993
|
-
amount:
|
4243
|
+
amount: bn16(coin.amount),
|
3994
4244
|
owner: Address2.fromAddressOrString(coin.owner),
|
3995
|
-
|
3996
|
-
|
3997
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4245
|
+
blockCreated: bn16(coin.blockCreated),
|
4246
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
3998
4247
|
}));
|
3999
4248
|
}
|
4000
4249
|
/**
|
@@ -4031,9 +4280,9 @@ var _Provider = class {
|
|
4031
4280
|
switch (coin.__typename) {
|
4032
4281
|
case "MessageCoin":
|
4033
4282
|
return {
|
4034
|
-
amount:
|
4283
|
+
amount: bn16(coin.amount),
|
4035
4284
|
assetId: coin.assetId,
|
4036
|
-
daHeight:
|
4285
|
+
daHeight: bn16(coin.daHeight),
|
4037
4286
|
sender: Address2.fromAddressOrString(coin.sender),
|
4038
4287
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4039
4288
|
nonce: coin.nonce
|
@@ -4041,12 +4290,11 @@ var _Provider = class {
|
|
4041
4290
|
case "Coin":
|
4042
4291
|
return {
|
4043
4292
|
id: coin.utxoId,
|
4044
|
-
amount:
|
4293
|
+
amount: bn16(coin.amount),
|
4045
4294
|
assetId: coin.assetId,
|
4046
4295
|
owner: Address2.fromAddressOrString(coin.owner),
|
4047
|
-
|
4048
|
-
|
4049
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4296
|
+
blockCreated: bn16(coin.blockCreated),
|
4297
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4050
4298
|
};
|
4051
4299
|
default:
|
4052
4300
|
return null;
|
@@ -4063,13 +4311,13 @@ var _Provider = class {
|
|
4063
4311
|
async getBlock(idOrHeight) {
|
4064
4312
|
let variables;
|
4065
4313
|
if (typeof idOrHeight === "number") {
|
4066
|
-
variables = { height:
|
4314
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4067
4315
|
} else if (idOrHeight === "latest") {
|
4068
4316
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4069
4317
|
} else if (idOrHeight.length === 66) {
|
4070
4318
|
variables = { blockId: idOrHeight };
|
4071
4319
|
} else {
|
4072
|
-
variables = { blockId:
|
4320
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4073
4321
|
}
|
4074
4322
|
const { block } = await this.operations.getBlock(variables);
|
4075
4323
|
if (!block) {
|
@@ -4077,7 +4325,7 @@ var _Provider = class {
|
|
4077
4325
|
}
|
4078
4326
|
return {
|
4079
4327
|
id: block.id,
|
4080
|
-
height:
|
4328
|
+
height: bn16(block.height),
|
4081
4329
|
time: block.header.time,
|
4082
4330
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4083
4331
|
};
|
@@ -4092,7 +4340,7 @@ var _Provider = class {
|
|
4092
4340
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4093
4341
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4094
4342
|
id: block.id,
|
4095
|
-
height:
|
4343
|
+
height: bn16(block.height),
|
4096
4344
|
time: block.header.time,
|
4097
4345
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4098
4346
|
}));
|
@@ -4107,7 +4355,7 @@ var _Provider = class {
|
|
4107
4355
|
async getBlockWithTransactions(idOrHeight) {
|
4108
4356
|
let variables;
|
4109
4357
|
if (typeof idOrHeight === "number") {
|
4110
|
-
variables = { blockHeight:
|
4358
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4111
4359
|
} else if (idOrHeight === "latest") {
|
4112
4360
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4113
4361
|
} else {
|
@@ -4119,7 +4367,7 @@ var _Provider = class {
|
|
4119
4367
|
}
|
4120
4368
|
return {
|
4121
4369
|
id: block.id,
|
4122
|
-
height:
|
4370
|
+
height: bn16(block.height, 10),
|
4123
4371
|
time: block.header.time,
|
4124
4372
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4125
4373
|
transactions: block.transactions.map(
|
@@ -4168,7 +4416,7 @@ var _Provider = class {
|
|
4168
4416
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4169
4417
|
asset: hexlify12(assetId)
|
4170
4418
|
});
|
4171
|
-
return
|
4419
|
+
return bn16(contractBalance.amount, 10);
|
4172
4420
|
}
|
4173
4421
|
/**
|
4174
4422
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4182,7 +4430,7 @@ var _Provider = class {
|
|
4182
4430
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4183
4431
|
assetId: hexlify12(assetId)
|
4184
4432
|
});
|
4185
|
-
return
|
4433
|
+
return bn16(balance.amount, 10);
|
4186
4434
|
}
|
4187
4435
|
/**
|
4188
4436
|
* Returns balances for the given owner.
|
@@ -4200,7 +4448,7 @@ var _Provider = class {
|
|
4200
4448
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4201
4449
|
return balances.map((balance) => ({
|
4202
4450
|
assetId: balance.assetId,
|
4203
|
-
amount:
|
4451
|
+
amount: bn16(balance.amount)
|
4204
4452
|
}));
|
4205
4453
|
}
|
4206
4454
|
/**
|
@@ -4222,15 +4470,15 @@ var _Provider = class {
|
|
4222
4470
|
sender: message.sender,
|
4223
4471
|
recipient: message.recipient,
|
4224
4472
|
nonce: message.nonce,
|
4225
|
-
amount:
|
4473
|
+
amount: bn16(message.amount),
|
4226
4474
|
data: message.data
|
4227
4475
|
}),
|
4228
4476
|
sender: Address2.fromAddressOrString(message.sender),
|
4229
4477
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4230
4478
|
nonce: message.nonce,
|
4231
|
-
amount:
|
4479
|
+
amount: bn16(message.amount),
|
4232
4480
|
data: InputMessageCoder.decodeData(message.data),
|
4233
|
-
daHeight:
|
4481
|
+
daHeight: bn16(message.daHeight)
|
4234
4482
|
}));
|
4235
4483
|
}
|
4236
4484
|
/**
|
@@ -4283,44 +4531,52 @@ var _Provider = class {
|
|
4283
4531
|
} = result.messageProof;
|
4284
4532
|
return {
|
4285
4533
|
messageProof: {
|
4286
|
-
proofIndex:
|
4534
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4287
4535
|
proofSet: messageProof.proofSet
|
4288
4536
|
},
|
4289
4537
|
blockProof: {
|
4290
|
-
proofIndex:
|
4538
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4291
4539
|
proofSet: blockProof.proofSet
|
4292
4540
|
},
|
4293
4541
|
messageBlockHeader: {
|
4294
4542
|
id: messageBlockHeader.id,
|
4295
|
-
daHeight:
|
4296
|
-
transactionsCount:
|
4543
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4544
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4297
4545
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4298
|
-
height:
|
4546
|
+
height: bn16(messageBlockHeader.height),
|
4299
4547
|
prevRoot: messageBlockHeader.prevRoot,
|
4300
4548
|
time: messageBlockHeader.time,
|
4301
4549
|
applicationHash: messageBlockHeader.applicationHash,
|
4302
|
-
|
4303
|
-
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4550
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount)
|
4304
4551
|
},
|
4305
4552
|
commitBlockHeader: {
|
4306
4553
|
id: commitBlockHeader.id,
|
4307
|
-
daHeight:
|
4308
|
-
transactionsCount:
|
4554
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4555
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4309
4556
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4310
|
-
height:
|
4557
|
+
height: bn16(commitBlockHeader.height),
|
4311
4558
|
prevRoot: commitBlockHeader.prevRoot,
|
4312
4559
|
time: commitBlockHeader.time,
|
4313
4560
|
applicationHash: commitBlockHeader.applicationHash,
|
4314
|
-
|
4315
|
-
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4561
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount)
|
4316
4562
|
},
|
4317
4563
|
sender: Address2.fromAddressOrString(sender),
|
4318
4564
|
recipient: Address2.fromAddressOrString(recipient),
|
4319
4565
|
nonce,
|
4320
|
-
amount:
|
4566
|
+
amount: bn16(amount),
|
4321
4567
|
data
|
4322
4568
|
};
|
4323
4569
|
}
|
4570
|
+
async getLatestGasPrice() {
|
4571
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4572
|
+
return bn16(latestGasPrice.gasPrice);
|
4573
|
+
}
|
4574
|
+
async estimateGasPrice(blockHorizon) {
|
4575
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4576
|
+
blockHorizon: String(blockHorizon)
|
4577
|
+
});
|
4578
|
+
return bn16(estimateGasPrice.gasPrice);
|
4579
|
+
}
|
4324
4580
|
/**
|
4325
4581
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4326
4582
|
*
|
@@ -4340,10 +4596,10 @@ var _Provider = class {
|
|
4340
4596
|
*/
|
4341
4597
|
async produceBlocks(amount, startTime) {
|
4342
4598
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4343
|
-
blocksToProduce:
|
4599
|
+
blocksToProduce: bn16(amount).toString(10),
|
4344
4600
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4345
4601
|
});
|
4346
|
-
return
|
4602
|
+
return bn16(latestBlockHeight);
|
4347
4603
|
}
|
4348
4604
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4349
4605
|
async getTransactionResponse(transactionId) {
|
@@ -4357,7 +4613,7 @@ cacheInputs_fn = function(inputs) {
|
|
4357
4613
|
return;
|
4358
4614
|
}
|
4359
4615
|
inputs.forEach((input) => {
|
4360
|
-
if (input.type ===
|
4616
|
+
if (input.type === InputType7.Coin) {
|
4361
4617
|
this.cache?.set(input.id);
|
4362
4618
|
}
|
4363
4619
|
});
|
@@ -4367,7 +4623,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4367
4623
|
|
4368
4624
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4369
4625
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4370
|
-
import { bn as
|
4626
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4371
4627
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4372
4628
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4373
4629
|
|
@@ -4613,36 +4869,33 @@ var Account = class extends AbstractAccount {
|
|
4613
4869
|
* @param fee - The estimated transaction fee.
|
4614
4870
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4615
4871
|
*/
|
4616
|
-
async fund(request,
|
4617
|
-
const
|
4618
|
-
|
4872
|
+
async fund(request, params) {
|
4873
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4874
|
+
const txRequest = request;
|
4875
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4876
|
+
amount: bn18(fee),
|
4619
4877
|
assetId: BaseAssetId3,
|
4620
|
-
coinQuantities
|
4878
|
+
coinQuantities: requiredQuantities
|
4621
4879
|
});
|
4622
4880
|
const quantitiesDict = {};
|
4623
|
-
|
4881
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4624
4882
|
quantitiesDict[assetId] = {
|
4625
4883
|
required: amount,
|
4626
|
-
owned:
|
4884
|
+
owned: bn18(0)
|
4627
4885
|
};
|
4628
4886
|
});
|
4629
|
-
|
4630
|
-
const cachedMessages = [];
|
4631
|
-
const owner = this.address.toB256();
|
4632
|
-
request.inputs.forEach((input) => {
|
4887
|
+
txRequest.inputs.forEach((input) => {
|
4633
4888
|
const isResource = "amount" in input;
|
4634
4889
|
if (isResource) {
|
4635
4890
|
const isCoin2 = "owner" in input;
|
4636
4891
|
if (isCoin2) {
|
4637
4892
|
const assetId = String(input.assetId);
|
4638
|
-
if (
|
4639
|
-
const amount =
|
4893
|
+
if (quantitiesDict[assetId]) {
|
4894
|
+
const amount = bn18(input.amount);
|
4640
4895
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4641
|
-
cachedUtxos.push(input.id);
|
4642
4896
|
}
|
4643
|
-
} else if (input.
|
4897
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
4644
4898
|
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4645
|
-
cachedMessages.push(input.nonce);
|
4646
4899
|
}
|
4647
4900
|
}
|
4648
4901
|
});
|
@@ -4657,12 +4910,23 @@ var Account = class extends AbstractAccount {
|
|
4657
4910
|
});
|
4658
4911
|
const needsToBeFunded = missingQuantities.length;
|
4659
4912
|
if (needsToBeFunded) {
|
4660
|
-
const
|
4661
|
-
|
4662
|
-
|
4663
|
-
|
4664
|
-
|
4913
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4914
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4915
|
+
txRequest.addResources(resources);
|
4916
|
+
}
|
4917
|
+
txRequest.shiftPredicateData();
|
4918
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4919
|
+
const requestToBeReEstimate = clone4(txRequest);
|
4920
|
+
if (addedSignatures) {
|
4921
|
+
Array.from({ length: addedSignatures }).forEach(
|
4922
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4923
|
+
);
|
4665
4924
|
}
|
4925
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4926
|
+
transactionRequest: requestToBeReEstimate
|
4927
|
+
});
|
4928
|
+
txRequest.maxFee = maxFee;
|
4929
|
+
return txRequest;
|
4666
4930
|
}
|
4667
4931
|
/**
|
4668
4932
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4670,28 +4934,25 @@ var Account = class extends AbstractAccount {
|
|
4670
4934
|
* @param destination - The address of the destination.
|
4671
4935
|
* @param amount - The amount of coins to transfer.
|
4672
4936
|
* @param assetId - The asset ID of the coins to transfer.
|
4673
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4937
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4674
4938
|
* @returns A promise that resolves to the prepared transaction request.
|
4675
4939
|
*/
|
4676
4940
|
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4677
|
-
const
|
4678
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4679
|
-
const request = new ScriptTransactionRequest(params);
|
4941
|
+
const request = new ScriptTransactionRequest(txParams);
|
4680
4942
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4681
|
-
const
|
4943
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4682
4944
|
estimateTxDependencies: true,
|
4683
4945
|
resourcesOwner: this
|
4684
4946
|
});
|
4685
|
-
|
4686
|
-
|
4687
|
-
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
await this.fund(request,
|
4694
|
-
request.updatePredicateInputs(estimatedInputs);
|
4947
|
+
if ("gasLimit" in txParams) {
|
4948
|
+
this.validateGas({
|
4949
|
+
gasUsed: txCost.gasUsed,
|
4950
|
+
gasLimit: request.gasLimit
|
4951
|
+
});
|
4952
|
+
}
|
4953
|
+
request.gasLimit = txCost.gasUsed;
|
4954
|
+
request.maxFee = txCost.maxFee;
|
4955
|
+
await this.fund(request, txCost);
|
4695
4956
|
return request;
|
4696
4957
|
}
|
4697
4958
|
/**
|
@@ -4704,7 +4965,7 @@ var Account = class extends AbstractAccount {
|
|
4704
4965
|
* @returns A promise that resolves to the transaction response.
|
4705
4966
|
*/
|
4706
4967
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4707
|
-
if (
|
4968
|
+
if (bn18(amount).lte(0)) {
|
4708
4969
|
throw new FuelError15(
|
4709
4970
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4710
4971
|
"Transfer amount must be a positive number."
|
@@ -4723,38 +4984,37 @@ var Account = class extends AbstractAccount {
|
|
4723
4984
|
* @returns A promise that resolves to the transaction response.
|
4724
4985
|
*/
|
4725
4986
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4726
|
-
if (
|
4987
|
+
if (bn18(amount).lte(0)) {
|
4727
4988
|
throw new FuelError15(
|
4728
4989
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4729
4990
|
"Transfer amount must be a positive number."
|
4730
4991
|
);
|
4731
4992
|
}
|
4732
4993
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4733
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4734
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4735
4994
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4736
4995
|
hexlifiedContractId: contractAddress.toB256(),
|
4737
|
-
amountToTransfer:
|
4996
|
+
amountToTransfer: bn18(amount),
|
4738
4997
|
assetId
|
4739
4998
|
});
|
4740
4999
|
const request = new ScriptTransactionRequest({
|
4741
|
-
...
|
5000
|
+
...txParams,
|
4742
5001
|
script,
|
4743
5002
|
scriptData
|
4744
5003
|
});
|
4745
5004
|
request.addContractInputAndOutput(contractAddress);
|
4746
|
-
const
|
4747
|
-
|
4748
|
-
[{ amount:
|
4749
|
-
);
|
4750
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4751
|
-
this.validateGas({
|
4752
|
-
gasUsed,
|
4753
|
-
gasPrice: request.gasPrice,
|
4754
|
-
gasLimit: request.gasLimit,
|
4755
|
-
minGasPrice
|
5005
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5006
|
+
resourcesOwner: this,
|
5007
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
4756
5008
|
});
|
4757
|
-
|
5009
|
+
if (txParams.gasLimit) {
|
5010
|
+
this.validateGas({
|
5011
|
+
gasUsed: txCost.gasUsed,
|
5012
|
+
gasLimit: request.gasLimit
|
5013
|
+
});
|
5014
|
+
}
|
5015
|
+
request.gasLimit = txCost.gasUsed;
|
5016
|
+
request.maxFee = txCost.maxFee;
|
5017
|
+
await this.fund(request, txCost);
|
4758
5018
|
return this.sendTransaction(request);
|
4759
5019
|
}
|
4760
5020
|
/**
|
@@ -4766,34 +5026,31 @@ var Account = class extends AbstractAccount {
|
|
4766
5026
|
* @returns A promise that resolves to the transaction response.
|
4767
5027
|
*/
|
4768
5028
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4769
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4770
5029
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4771
5030
|
const recipientDataArray = arrayify14(
|
4772
5031
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4773
5032
|
);
|
4774
5033
|
const amountDataArray = arrayify14(
|
4775
|
-
"0x".concat(
|
5034
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
4776
5035
|
);
|
4777
5036
|
const script = new Uint8Array([
|
4778
5037
|
...arrayify14(withdrawScript.bytes),
|
4779
5038
|
...recipientDataArray,
|
4780
5039
|
...amountDataArray
|
4781
5040
|
]);
|
4782
|
-
const params = { script,
|
5041
|
+
const params = { script, ...txParams };
|
4783
5042
|
const request = new ScriptTransactionRequest(params);
|
4784
|
-
const
|
4785
|
-
const
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4793
|
-
|
4794
|
-
|
4795
|
-
});
|
4796
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5043
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5044
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5045
|
+
if (txParams.gasLimit) {
|
5046
|
+
this.validateGas({
|
5047
|
+
gasUsed: txCost.gasUsed,
|
5048
|
+
gasLimit: request.gasLimit
|
5049
|
+
});
|
5050
|
+
}
|
5051
|
+
request.maxFee = txCost.maxFee;
|
5052
|
+
request.gasLimit = txCost.gasUsed;
|
5053
|
+
await this.fund(request, txCost);
|
4797
5054
|
return this.sendTransaction(request);
|
4798
5055
|
}
|
4799
5056
|
async signMessage(message) {
|
@@ -4851,18 +5108,7 @@ var Account = class extends AbstractAccount {
|
|
4851
5108
|
}
|
4852
5109
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4853
5110
|
}
|
4854
|
-
validateGas({
|
4855
|
-
gasUsed,
|
4856
|
-
gasPrice,
|
4857
|
-
gasLimit,
|
4858
|
-
minGasPrice
|
4859
|
-
}) {
|
4860
|
-
if (minGasPrice.gt(gasPrice)) {
|
4861
|
-
throw new FuelError15(
|
4862
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4863
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4864
|
-
);
|
4865
|
-
}
|
5111
|
+
validateGas({ gasUsed, gasLimit }) {
|
4866
5112
|
if (gasUsed.gt(gasLimit)) {
|
4867
5113
|
throw new FuelError15(
|
4868
5114
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -4874,7 +5120,7 @@ var Account = class extends AbstractAccount {
|
|
4874
5120
|
|
4875
5121
|
// src/signer/signer.ts
|
4876
5122
|
import { Address as Address4 } from "@fuel-ts/address";
|
4877
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5123
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
4878
5124
|
import { hash } from "@fuel-ts/hasher";
|
4879
5125
|
import { toBytes } from "@fuel-ts/math";
|
4880
5126
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -4967,7 +5213,7 @@ var Signer = class {
|
|
4967
5213
|
* @returns random 32-byte hashed
|
4968
5214
|
*/
|
4969
5215
|
static generatePrivateKey(entropy) {
|
4970
|
-
return entropy ? hash(concat3([
|
5216
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
4971
5217
|
}
|
4972
5218
|
/**
|
4973
5219
|
* Extended publicKey from a compact publicKey
|
@@ -4986,7 +5232,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
4986
5232
|
import {
|
4987
5233
|
bufferFromString,
|
4988
5234
|
keccak256,
|
4989
|
-
randomBytes as
|
5235
|
+
randomBytes as randomBytes3,
|
4990
5236
|
scrypt,
|
4991
5237
|
stringFromBuffer,
|
4992
5238
|
decryptJsonWalletData,
|
@@ -5009,7 +5255,7 @@ var removeHexPrefix = (hexString) => {
|
|
5009
5255
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5010
5256
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5011
5257
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5012
|
-
const salt =
|
5258
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5013
5259
|
const key = scrypt({
|
5014
5260
|
password: bufferFromString(password),
|
5015
5261
|
salt,
|
@@ -5018,7 +5264,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5018
5264
|
r: DEFAULT_KDF_PARAMS_R,
|
5019
5265
|
p: DEFAULT_KDF_PARAMS_P
|
5020
5266
|
});
|
5021
|
-
const iv =
|
5267
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5022
5268
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5023
5269
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5024
5270
|
const macHashUint8Array = keccak256(data);
|
@@ -5154,7 +5400,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5154
5400
|
* @param transactionRequestLike - The transaction request to send.
|
5155
5401
|
* @returns A promise that resolves to the TransactionResponse object.
|
5156
5402
|
*/
|
5157
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5403
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5158
5404
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5159
5405
|
if (estimateTxDependencies) {
|
5160
5406
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5195,12 +5441,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5195
5441
|
// src/hdwallet/hdwallet.ts
|
5196
5442
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5197
5443
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5198
|
-
import { bn as
|
5444
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5199
5445
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5200
5446
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5201
5447
|
|
5202
5448
|
// src/mnemonic/mnemonic.ts
|
5203
|
-
import { randomBytes as
|
5449
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5204
5450
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5205
5451
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5206
5452
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7555,7 +7801,7 @@ var Mnemonic = class {
|
|
7555
7801
|
* @returns A randomly generated mnemonic
|
7556
7802
|
*/
|
7557
7803
|
static generate(size = 32, extraEntropy = "") {
|
7558
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7804
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7559
7805
|
return Mnemonic.entropyToMnemonic(entropy);
|
7560
7806
|
}
|
7561
7807
|
};
|
@@ -7661,7 +7907,7 @@ var HDWallet = class {
|
|
7661
7907
|
const IR = bytes.slice(32);
|
7662
7908
|
if (privateKey) {
|
7663
7909
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7664
|
-
const ki =
|
7910
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7665
7911
|
return new HDWallet({
|
7666
7912
|
privateKey: ki,
|
7667
7913
|
chainCode: IR,
|
@@ -7926,20 +8172,21 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7926
8172
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7927
8173
|
|
7928
8174
|
// src/test-utils/seedTestWallet.ts
|
7929
|
-
import { randomBytes as
|
8175
|
+
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
7930
8176
|
var seedTestWallet = async (wallet, quantities) => {
|
7931
8177
|
const genesisWallet = new WalletUnlocked(
|
7932
|
-
process.env.GENESIS_SECRET ||
|
8178
|
+
process.env.GENESIS_SECRET || randomBytes5(32),
|
7933
8179
|
wallet.provider
|
7934
8180
|
);
|
7935
|
-
const
|
7936
|
-
|
7937
|
-
|
7938
|
-
|
7939
|
-
gasPrice: minGasPrice
|
8181
|
+
const request = new ScriptTransactionRequest();
|
8182
|
+
quantities.forEach((quantity) => {
|
8183
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8184
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7940
8185
|
});
|
7941
|
-
|
7942
|
-
|
8186
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8187
|
+
request.gasLimit = txCost.gasUsed;
|
8188
|
+
request.maxFee = txCost.maxFee;
|
8189
|
+
await genesisWallet.fund(request, txCost);
|
7943
8190
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
7944
8191
|
};
|
7945
8192
|
|
@@ -7954,11 +8201,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7954
8201
|
|
7955
8202
|
// src/test-utils/launchNode.ts
|
7956
8203
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
7957
|
-
import {
|
7958
|
-
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8204
|
+
import { defaultChainConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
7959
8205
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
7960
8206
|
import { spawn } from "child_process";
|
7961
8207
|
import { randomUUID } from "crypto";
|
8208
|
+
import { randomBytes as randomBytes6 } from "ethers";
|
7962
8209
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
7963
8210
|
import os from "os";
|
7964
8211
|
import path from "path";
|
@@ -8007,12 +8254,12 @@ var launchNode = async ({
|
|
8007
8254
|
// eslint-disable-next-line no-async-promise-executor
|
8008
8255
|
new Promise(async (resolve, reject) => {
|
8009
8256
|
const remainingArgs = extractRemainingArgs(args, [
|
8010
|
-
"--
|
8257
|
+
"--snapshot",
|
8011
8258
|
"--consensus-key",
|
8012
8259
|
"--db-type",
|
8013
8260
|
"--poa-instant"
|
8014
8261
|
]);
|
8015
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8262
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8016
8263
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8017
8264
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8018
8265
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8031,36 +8278,54 @@ var launchNode = async ({
|
|
8031
8278
|
let chainConfigPathToUse;
|
8032
8279
|
const prefix = basePath || os.tmpdir();
|
8033
8280
|
const suffix = basePath ? "" : randomUUID();
|
8034
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8281
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "chainConfigs");
|
8035
8282
|
if (chainConfigPath) {
|
8036
8283
|
chainConfigPathToUse = chainConfigPath;
|
8037
8284
|
} else {
|
8038
8285
|
if (!existsSync(tempDirPath)) {
|
8039
8286
|
mkdirSync(tempDirPath, { recursive: true });
|
8040
8287
|
}
|
8041
|
-
|
8042
|
-
|
8288
|
+
let { stateConfigJson } = defaultChainConfigs;
|
8289
|
+
const { chainConfigJson, metadataJson } = defaultChainConfigs;
|
8290
|
+
stateConfigJson = {
|
8291
|
+
...stateConfigJson,
|
8292
|
+
coins: [
|
8293
|
+
...stateConfigJson.coins.map((coin) => ({
|
8294
|
+
...coin,
|
8295
|
+
amount: "18446744073709551615"
|
8296
|
+
}))
|
8297
|
+
],
|
8298
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8299
|
+
...message,
|
8300
|
+
amount: "18446744073709551615"
|
8301
|
+
}))
|
8302
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8303
|
+
};
|
8043
8304
|
if (!process.env.GENESIS_SECRET) {
|
8044
8305
|
const pk = Signer.generatePrivateKey();
|
8045
8306
|
const signer = new Signer(pk);
|
8046
8307
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8047
|
-
|
8048
|
-
|
8049
|
-
|
8050
|
-
|
8051
|
-
|
8052
|
-
|
8053
|
-
|
8054
|
-
|
8055
|
-
|
8056
|
-
|
8057
|
-
}
|
8058
|
-
]
|
8059
|
-
}
|
8060
|
-
};
|
8308
|
+
stateConfigJson.coins.push({
|
8309
|
+
tx_id: hexlify18(randomBytes6(34)),
|
8310
|
+
owner: signer.address.toHexString(),
|
8311
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8312
|
+
amount: "18446744073709551615",
|
8313
|
+
asset_id: BaseAssetId4,
|
8314
|
+
output_index: 0,
|
8315
|
+
tx_pointer_block_height: 0,
|
8316
|
+
tx_pointer_tx_idx: 0
|
8317
|
+
});
|
8061
8318
|
}
|
8062
|
-
|
8063
|
-
|
8319
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8320
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8321
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8322
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8323
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8324
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8325
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8326
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8327
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8328
|
+
chainConfigPathToUse = tempDirPath;
|
8064
8329
|
}
|
8065
8330
|
const child = spawn(
|
8066
8331
|
command,
|
@@ -8069,10 +8334,10 @@ var launchNode = async ({
|
|
8069
8334
|
["--ip", ipToUse],
|
8070
8335
|
["--port", portToUse],
|
8071
8336
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8072
|
-
["--min-gas-price", "
|
8337
|
+
["--min-gas-price", "1"],
|
8073
8338
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8074
8339
|
["--consensus-key", consensusKey],
|
8075
|
-
["--
|
8340
|
+
["--snapshot", chainConfigPathToUse],
|
8076
8341
|
"--vm-backtrace",
|
8077
8342
|
"--utxo-validation",
|
8078
8343
|
"--debug",
|
@@ -8131,7 +8396,7 @@ var launchNodeAndGetWallets = async ({
|
|
8131
8396
|
walletCount = 10
|
8132
8397
|
} = {}) => {
|
8133
8398
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8134
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8399
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8135
8400
|
const wallets = await generateWallets(walletCount, provider);
|
8136
8401
|
const cleanup = () => {
|
8137
8402
|
closeNode();
|