@fuel-ts/account 0.0.0-rc-2021-20240415193305 → 0.0.0-rc-1976-20240416161016
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 +4 -5
- 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 +600 -829
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +600 -835
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +443 -677
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +329 -911
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- 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 +1 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -37
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +29 -9
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1114 -1578
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +599 -813
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +455 -669
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +22 -27
package/dist/test-utils.mjs
CHANGED
@@ -24,15 +24,12 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
29
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
31
30
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
-
import { clone as clone4 } from "ramda";
|
33
31
|
|
34
32
|
// src/providers/coin-quantity.ts
|
35
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
36
33
|
import { bn } from "@fuel-ts/math";
|
37
34
|
import { hexlify } from "@fuel-ts/utils";
|
38
35
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -41,11 +38,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
41
38
|
let max2;
|
42
39
|
if (Array.isArray(coinQuantityLike)) {
|
43
40
|
amount = coinQuantityLike[0];
|
44
|
-
assetId = coinQuantityLike[1]
|
45
|
-
max2 = coinQuantityLike[2]
|
41
|
+
assetId = coinQuantityLike[1];
|
42
|
+
max2 = coinQuantityLike[2];
|
46
43
|
} else {
|
47
44
|
amount = coinQuantityLike.amount;
|
48
|
-
assetId = coinQuantityLike.assetId
|
45
|
+
assetId = coinQuantityLike.assetId;
|
49
46
|
max2 = coinQuantityLike.max ?? void 0;
|
50
47
|
}
|
51
48
|
const bnAmount = bn(amount);
|
@@ -55,7 +52,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
55
52
|
max: max2 ? bn(max2) : void 0
|
56
53
|
};
|
57
54
|
};
|
58
|
-
var
|
55
|
+
var addAmountToAsset = (params) => {
|
59
56
|
const { amount, assetId } = params;
|
60
57
|
const coinQuantities = [...params.coinQuantities];
|
61
58
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -70,9 +67,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
70
67
|
// src/providers/provider.ts
|
71
68
|
import { Address as Address2 } from "@fuel-ts/address";
|
72
69
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
73
|
-
import { BN, bn as
|
70
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
74
71
|
import {
|
75
|
-
InputType as
|
72
|
+
InputType as InputType6,
|
76
73
|
TransactionType as TransactionType8,
|
77
74
|
InputMessageCoder,
|
78
75
|
TransactionCoder as TransactionCoder5
|
@@ -88,10 +85,14 @@ import { clone as clone3 } from "ramda";
|
|
88
85
|
import gql from "graphql-tag";
|
89
86
|
var ReceiptFragmentFragmentDoc = gql`
|
90
87
|
fragment receiptFragment on Receipt {
|
91
|
-
|
88
|
+
contract {
|
89
|
+
id
|
90
|
+
}
|
92
91
|
pc
|
93
92
|
is
|
94
|
-
to
|
93
|
+
to {
|
94
|
+
id
|
95
|
+
}
|
95
96
|
toAddress
|
96
97
|
amount
|
97
98
|
assetId
|
@@ -129,16 +130,10 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
129
130
|
id
|
130
131
|
}
|
131
132
|
time
|
132
|
-
receipts {
|
133
|
-
...receiptFragment
|
134
|
-
}
|
135
133
|
programState {
|
136
134
|
returnType
|
137
135
|
data
|
138
136
|
}
|
139
|
-
receipts {
|
140
|
-
...receiptFragment
|
141
|
-
}
|
142
137
|
}
|
143
138
|
... on FailureStatus {
|
144
139
|
block {
|
@@ -146,24 +141,26 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
146
141
|
}
|
147
142
|
time
|
148
143
|
reason
|
149
|
-
receipts {
|
150
|
-
...receiptFragment
|
151
|
-
}
|
152
144
|
}
|
153
145
|
... on SqueezedOutStatus {
|
154
146
|
reason
|
155
147
|
}
|
156
148
|
}
|
157
|
-
|
149
|
+
`;
|
158
150
|
var TransactionFragmentFragmentDoc = gql`
|
159
151
|
fragment transactionFragment on Transaction {
|
160
152
|
id
|
161
153
|
rawPayload
|
154
|
+
gasPrice
|
155
|
+
receipts {
|
156
|
+
...receiptFragment
|
157
|
+
}
|
162
158
|
status {
|
163
159
|
...transactionStatusFragment
|
164
160
|
}
|
165
161
|
}
|
166
|
-
${
|
162
|
+
${ReceiptFragmentFragmentDoc}
|
163
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
167
164
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
168
165
|
fragment inputEstimatePredicatesFragment on Input {
|
169
166
|
... on InputCoin {
|
@@ -181,46 +178,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
181
178
|
}
|
182
179
|
}
|
183
180
|
${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}`;
|
224
181
|
var CoinFragmentFragmentDoc = gql`
|
225
182
|
fragment coinFragment on Coin {
|
226
183
|
__typename
|
@@ -228,6 +185,7 @@ var CoinFragmentFragmentDoc = gql`
|
|
228
185
|
owner
|
229
186
|
amount
|
230
187
|
assetId
|
188
|
+
maturity
|
231
189
|
blockCreated
|
232
190
|
txCreatedIdx
|
233
191
|
}
|
@@ -266,32 +224,26 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
266
224
|
messageBlockHeader {
|
267
225
|
id
|
268
226
|
daHeight
|
269
|
-
consensusParametersVersion
|
270
|
-
stateTransitionBytecodeVersion
|
271
227
|
transactionsCount
|
272
|
-
messageReceiptCount
|
273
228
|
transactionsRoot
|
274
|
-
messageOutboxRoot
|
275
|
-
eventInboxRoot
|
276
229
|
height
|
277
230
|
prevRoot
|
278
231
|
time
|
279
232
|
applicationHash
|
233
|
+
messageReceiptRoot
|
234
|
+
messageReceiptCount
|
280
235
|
}
|
281
236
|
commitBlockHeader {
|
282
237
|
id
|
283
238
|
daHeight
|
284
|
-
consensusParametersVersion
|
285
|
-
stateTransitionBytecodeVersion
|
286
239
|
transactionsCount
|
287
|
-
messageReceiptCount
|
288
240
|
transactionsRoot
|
289
|
-
messageOutboxRoot
|
290
|
-
eventInboxRoot
|
291
241
|
height
|
292
242
|
prevRoot
|
293
243
|
time
|
294
244
|
applicationHash
|
245
|
+
messageReceiptRoot
|
246
|
+
messageReceiptCount
|
295
247
|
}
|
296
248
|
sender
|
297
249
|
recipient
|
@@ -310,8 +262,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
310
262
|
var BlockFragmentFragmentDoc = gql`
|
311
263
|
fragment blockFragment on Block {
|
312
264
|
id
|
313
|
-
height
|
314
265
|
header {
|
266
|
+
height
|
315
267
|
time
|
316
268
|
}
|
317
269
|
transactions {
|
@@ -369,11 +321,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
369
321
|
`;
|
370
322
|
var GasCostsFragmentFragmentDoc = gql`
|
371
323
|
fragment GasCostsFragment on GasCosts {
|
372
|
-
version {
|
373
|
-
... on Version {
|
374
|
-
value
|
375
|
-
}
|
376
|
-
}
|
377
324
|
add
|
378
325
|
addi
|
379
326
|
aloc
|
@@ -386,6 +333,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
386
333
|
cb
|
387
334
|
cfei
|
388
335
|
cfsi
|
336
|
+
croo
|
389
337
|
div
|
390
338
|
divi
|
391
339
|
ecr1
|
@@ -468,9 +416,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
468
416
|
ccp {
|
469
417
|
...DependentCostFragment
|
470
418
|
}
|
471
|
-
croo {
|
472
|
-
...DependentCostFragment
|
473
|
-
}
|
474
419
|
csiz {
|
475
420
|
...DependentCostFragment
|
476
421
|
}
|
@@ -530,11 +475,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
530
475
|
${DependentCostFragmentFragmentDoc}`;
|
531
476
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
532
477
|
fragment consensusParametersFragment on ConsensusParameters {
|
533
|
-
version {
|
534
|
-
... on Version {
|
535
|
-
value
|
536
|
-
}
|
537
|
-
}
|
538
478
|
txParams {
|
539
479
|
...TxParametersFragment
|
540
480
|
}
|
@@ -594,9 +534,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
594
534
|
fragment nodeInfoFragment on NodeInfo {
|
595
535
|
utxoValidation
|
596
536
|
vmBacktrace
|
537
|
+
minGasPrice
|
597
538
|
maxTx
|
598
539
|
maxDepth
|
599
540
|
nodeVersion
|
541
|
+
peers {
|
542
|
+
id
|
543
|
+
addresses
|
544
|
+
clientVersion
|
545
|
+
blockHeight
|
546
|
+
lastHeartbeatMs
|
547
|
+
appScore
|
548
|
+
}
|
600
549
|
}
|
601
550
|
`;
|
602
551
|
var GetVersionDocument = gql`
|
@@ -631,9 +580,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
631
580
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
632
581
|
transaction(id: $transactionId) {
|
633
582
|
...transactionFragment
|
583
|
+
receipts {
|
584
|
+
...receiptFragment
|
585
|
+
}
|
634
586
|
}
|
635
587
|
}
|
636
|
-
${TransactionFragmentFragmentDoc}
|
588
|
+
${TransactionFragmentFragmentDoc}
|
589
|
+
${ReceiptFragmentFragmentDoc}`;
|
637
590
|
var GetTransactionsDocument = gql`
|
638
591
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
639
592
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -761,20 +714,6 @@ var GetBalanceDocument = gql`
|
|
761
714
|
}
|
762
715
|
}
|
763
716
|
${BalanceFragmentFragmentDoc}`;
|
764
|
-
var GetLatestGasPriceDocument = gql`
|
765
|
-
query getLatestGasPrice {
|
766
|
-
latestGasPrice {
|
767
|
-
gasPrice
|
768
|
-
}
|
769
|
-
}
|
770
|
-
`;
|
771
|
-
var EstimateGasPriceDocument = gql`
|
772
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
773
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
774
|
-
gasPrice
|
775
|
-
}
|
776
|
-
}
|
777
|
-
`;
|
778
717
|
var GetBalancesDocument = gql`
|
779
718
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
780
719
|
balances(
|
@@ -829,12 +768,12 @@ var GetMessageStatusDocument = gql`
|
|
829
768
|
}
|
830
769
|
`;
|
831
770
|
var DryRunDocument = gql`
|
832
|
-
mutation dryRun($
|
833
|
-
dryRun(
|
834
|
-
...
|
771
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
772
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
773
|
+
...receiptFragment
|
835
774
|
}
|
836
775
|
}
|
837
|
-
${
|
776
|
+
${ReceiptFragmentFragmentDoc}`;
|
838
777
|
var SubmitDocument = gql`
|
839
778
|
mutation submit($encodedTransaction: HexString!) {
|
840
779
|
submit(tx: $encodedTransaction) {
|
@@ -917,12 +856,6 @@ function getSdk(requester) {
|
|
917
856
|
getBalance(variables, options) {
|
918
857
|
return requester(GetBalanceDocument, variables, options);
|
919
858
|
},
|
920
|
-
getLatestGasPrice(variables, options) {
|
921
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
922
|
-
},
|
923
|
-
estimateGasPrice(variables, options) {
|
924
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
925
|
-
},
|
926
859
|
getBalances(variables, options) {
|
927
860
|
return requester(GetBalancesDocument, variables, options);
|
928
861
|
},
|
@@ -992,14 +925,11 @@ var _FuelGraphqlSubscriber = class {
|
|
992
925
|
let data;
|
993
926
|
let errors;
|
994
927
|
try {
|
995
|
-
|
996
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
928
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
997
929
|
} catch (e) {
|
998
930
|
throw new FuelError(
|
999
931
|
ErrorCode.STREAM_PARSING_ERROR,
|
1000
|
-
`Error while parsing stream data response: ${text}
|
1001
|
-
|
1002
|
-
Thrown error: ${e}`
|
932
|
+
`Error while parsing stream data response: ${text}`
|
1003
933
|
);
|
1004
934
|
}
|
1005
935
|
if (Array.isArray(errors)) {
|
@@ -1110,9 +1040,10 @@ var inputify = (value) => {
|
|
1110
1040
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1111
1041
|
},
|
1112
1042
|
witnessIndex: value.witnessIndex,
|
1043
|
+
maturity: value.maturity ?? 0,
|
1113
1044
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1114
|
-
predicateLength:
|
1115
|
-
predicateDataLength:
|
1045
|
+
predicateLength: predicate.length,
|
1046
|
+
predicateDataLength: predicateData.length,
|
1116
1047
|
predicate: hexlify3(predicate),
|
1117
1048
|
predicateData: hexlify3(predicateData)
|
1118
1049
|
};
|
@@ -1143,8 +1074,8 @@ var inputify = (value) => {
|
|
1143
1074
|
nonce: hexlify3(value.nonce),
|
1144
1075
|
witnessIndex: value.witnessIndex,
|
1145
1076
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1146
|
-
predicateLength:
|
1147
|
-
predicateDataLength:
|
1077
|
+
predicateLength: predicate.length,
|
1078
|
+
predicateDataLength: predicateData.length,
|
1148
1079
|
predicate: hexlify3(predicate),
|
1149
1080
|
predicateData: hexlify3(predicateData),
|
1150
1081
|
data: hexlify3(data),
|
@@ -1220,7 +1151,7 @@ var outputify = (value) => {
|
|
1220
1151
|
// src/providers/transaction-request/transaction-request.ts
|
1221
1152
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1222
1153
|
import { Address, addressify } from "@fuel-ts/address";
|
1223
|
-
import {
|
1154
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1224
1155
|
import { randomBytes } from "@fuel-ts/crypto";
|
1225
1156
|
import { bn as bn7 } from "@fuel-ts/math";
|
1226
1157
|
import {
|
@@ -1271,8 +1202,8 @@ function assembleReceiptByType(receipt) {
|
|
1271
1202
|
case "CALL" /* Call */: {
|
1272
1203
|
const callReceipt = {
|
1273
1204
|
type: ReceiptType.Call,
|
1274
|
-
from: hexOrZero(receipt.id
|
1275
|
-
to: hexOrZero(receipt?.to),
|
1205
|
+
from: hexOrZero(receipt.contract?.id),
|
1206
|
+
to: hexOrZero(receipt?.to?.id),
|
1276
1207
|
amount: bn4(receipt.amount),
|
1277
1208
|
assetId: hexOrZero(receipt.assetId),
|
1278
1209
|
gas: bn4(receipt.gas),
|
@@ -1286,7 +1217,7 @@ function assembleReceiptByType(receipt) {
|
|
1286
1217
|
case "RETURN" /* Return */: {
|
1287
1218
|
const returnReceipt = {
|
1288
1219
|
type: ReceiptType.Return,
|
1289
|
-
id: hexOrZero(receipt.id
|
1220
|
+
id: hexOrZero(receipt.contract?.id),
|
1290
1221
|
val: bn4(receipt.val),
|
1291
1222
|
pc: bn4(receipt.pc),
|
1292
1223
|
is: bn4(receipt.is)
|
@@ -1296,7 +1227,7 @@ function assembleReceiptByType(receipt) {
|
|
1296
1227
|
case "RETURN_DATA" /* ReturnData */: {
|
1297
1228
|
const returnDataReceipt = {
|
1298
1229
|
type: ReceiptType.ReturnData,
|
1299
|
-
id: hexOrZero(receipt.id
|
1230
|
+
id: hexOrZero(receipt.contract?.id),
|
1300
1231
|
ptr: bn4(receipt.ptr),
|
1301
1232
|
len: bn4(receipt.len),
|
1302
1233
|
digest: hexOrZero(receipt.digest),
|
@@ -1308,7 +1239,7 @@ function assembleReceiptByType(receipt) {
|
|
1308
1239
|
case "PANIC" /* Panic */: {
|
1309
1240
|
const panicReceipt = {
|
1310
1241
|
type: ReceiptType.Panic,
|
1311
|
-
id: hexOrZero(receipt.id),
|
1242
|
+
id: hexOrZero(receipt.contract?.id),
|
1312
1243
|
reason: bn4(receipt.reason),
|
1313
1244
|
pc: bn4(receipt.pc),
|
1314
1245
|
is: bn4(receipt.is),
|
@@ -1319,7 +1250,7 @@ function assembleReceiptByType(receipt) {
|
|
1319
1250
|
case "REVERT" /* Revert */: {
|
1320
1251
|
const revertReceipt = {
|
1321
1252
|
type: ReceiptType.Revert,
|
1322
|
-
id: hexOrZero(receipt.id
|
1253
|
+
id: hexOrZero(receipt.contract?.id),
|
1323
1254
|
val: bn4(receipt.ra),
|
1324
1255
|
pc: bn4(receipt.pc),
|
1325
1256
|
is: bn4(receipt.is)
|
@@ -1329,7 +1260,7 @@ function assembleReceiptByType(receipt) {
|
|
1329
1260
|
case "LOG" /* Log */: {
|
1330
1261
|
const logReceipt = {
|
1331
1262
|
type: ReceiptType.Log,
|
1332
|
-
id: hexOrZero(receipt.id
|
1263
|
+
id: hexOrZero(receipt.contract?.id),
|
1333
1264
|
val0: bn4(receipt.ra),
|
1334
1265
|
val1: bn4(receipt.rb),
|
1335
1266
|
val2: bn4(receipt.rc),
|
@@ -1342,7 +1273,7 @@ function assembleReceiptByType(receipt) {
|
|
1342
1273
|
case "LOG_DATA" /* LogData */: {
|
1343
1274
|
const logDataReceipt = {
|
1344
1275
|
type: ReceiptType.LogData,
|
1345
|
-
id: hexOrZero(receipt.id
|
1276
|
+
id: hexOrZero(receipt.contract?.id),
|
1346
1277
|
val0: bn4(receipt.ra),
|
1347
1278
|
val1: bn4(receipt.rb),
|
1348
1279
|
ptr: bn4(receipt.ptr),
|
@@ -1356,8 +1287,8 @@ function assembleReceiptByType(receipt) {
|
|
1356
1287
|
case "TRANSFER" /* Transfer */: {
|
1357
1288
|
const transferReceipt = {
|
1358
1289
|
type: ReceiptType.Transfer,
|
1359
|
-
from: hexOrZero(receipt.id
|
1360
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1290
|
+
from: hexOrZero(receipt.contract?.id),
|
1291
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1361
1292
|
amount: bn4(receipt.amount),
|
1362
1293
|
assetId: hexOrZero(receipt.assetId),
|
1363
1294
|
pc: bn4(receipt.pc),
|
@@ -1368,8 +1299,8 @@ function assembleReceiptByType(receipt) {
|
|
1368
1299
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1369
1300
|
const transferOutReceipt = {
|
1370
1301
|
type: ReceiptType.TransferOut,
|
1371
|
-
from: hexOrZero(receipt.id
|
1372
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1302
|
+
from: hexOrZero(receipt.contract?.id),
|
1303
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1373
1304
|
amount: bn4(receipt.amount),
|
1374
1305
|
assetId: hexOrZero(receipt.assetId),
|
1375
1306
|
pc: bn4(receipt.pc),
|
@@ -1412,7 +1343,7 @@ function assembleReceiptByType(receipt) {
|
|
1412
1343
|
return receiptMessageOut;
|
1413
1344
|
}
|
1414
1345
|
case "MINT" /* Mint */: {
|
1415
|
-
const contractId = hexOrZero(receipt.id
|
1346
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1416
1347
|
const subId = hexOrZero(receipt.subId);
|
1417
1348
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1418
1349
|
const mintReceipt = {
|
@@ -1427,7 +1358,7 @@ function assembleReceiptByType(receipt) {
|
|
1427
1358
|
return mintReceipt;
|
1428
1359
|
}
|
1429
1360
|
case "BURN" /* Burn */: {
|
1430
|
-
const contractId = hexOrZero(receipt.id
|
1361
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1431
1362
|
const subId = hexOrZero(receipt.subId);
|
1432
1363
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1433
1364
|
const burnReceipt = {
|
@@ -1453,6 +1384,7 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1453
1384
|
import { bn as bn5 } from "@fuel-ts/math";
|
1454
1385
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1455
1386
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1387
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1456
1388
|
var getGasUsedFromReceipts = (receipts) => {
|
1457
1389
|
const scriptResult = receipts.filter(
|
1458
1390
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1473,28 +1405,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1473
1405
|
}
|
1474
1406
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1475
1407
|
const witnessCache = [];
|
1476
|
-
const
|
1477
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1478
|
-
if (isCoinOrMessage) {
|
1479
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1480
|
-
return true;
|
1481
|
-
}
|
1482
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1483
|
-
witnessCache.push(input.witnessIndex);
|
1484
|
-
return true;
|
1485
|
-
}
|
1486
|
-
}
|
1487
|
-
return false;
|
1488
|
-
});
|
1489
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1490
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1408
|
+
const totalGas = inputs.reduce((total, input) => {
|
1491
1409
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1492
1410
|
return total.add(
|
1493
|
-
|
1411
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1494
1412
|
);
|
1495
1413
|
}
|
1496
|
-
|
1497
|
-
|
1414
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1415
|
+
witnessCache.push(input.witnessIndex);
|
1416
|
+
return total.add(gasCosts.ecr1);
|
1417
|
+
}
|
1418
|
+
return total;
|
1419
|
+
}, bn5());
|
1498
1420
|
return totalGas;
|
1499
1421
|
}
|
1500
1422
|
function getMinGas(params) {
|
@@ -1506,20 +1428,12 @@ function getMinGas(params) {
|
|
1506
1428
|
return minGas;
|
1507
1429
|
}
|
1508
1430
|
function getMaxGas(params) {
|
1509
|
-
const {
|
1510
|
-
gasPerByte,
|
1511
|
-
witnessesLength,
|
1512
|
-
witnessLimit,
|
1513
|
-
minGas,
|
1514
|
-
gasLimit = bn5(0),
|
1515
|
-
maxGasPerTx
|
1516
|
-
} = params;
|
1431
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1517
1432
|
let remainingAllowedWitnessGas = bn5(0);
|
1518
1433
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1519
1434
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1520
1435
|
}
|
1521
|
-
|
1522
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1436
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1523
1437
|
}
|
1524
1438
|
function calculateMetadataGasForTxCreate({
|
1525
1439
|
gasCosts,
|
@@ -1541,10 +1455,6 @@ function calculateMetadataGasForTxScript({
|
|
1541
1455
|
}) {
|
1542
1456
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1543
1457
|
}
|
1544
|
-
var calculateGasFee = (params) => {
|
1545
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1546
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1547
|
-
};
|
1548
1458
|
|
1549
1459
|
// src/providers/utils/json.ts
|
1550
1460
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1689,7 +1599,7 @@ var witnessify = (value) => {
|
|
1689
1599
|
// src/providers/transaction-request/transaction-request.ts
|
1690
1600
|
var BaseTransactionRequest = class {
|
1691
1601
|
/** Gas price for transaction */
|
1692
|
-
|
1602
|
+
gasPrice;
|
1693
1603
|
/** Block until which tx cannot be included */
|
1694
1604
|
maturity;
|
1695
1605
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1702,34 +1612,38 @@ var BaseTransactionRequest = class {
|
|
1702
1612
|
outputs = [];
|
1703
1613
|
/** List of witnesses */
|
1704
1614
|
witnesses = [];
|
1615
|
+
/** Base asset ID - should be fetched from the chain */
|
1616
|
+
baseAssetId;
|
1705
1617
|
/**
|
1706
1618
|
* Constructor for initializing a base transaction request.
|
1707
1619
|
*
|
1708
1620
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1709
1621
|
*/
|
1710
1622
|
constructor({
|
1711
|
-
|
1623
|
+
gasPrice,
|
1712
1624
|
maturity,
|
1713
1625
|
maxFee,
|
1714
1626
|
witnessLimit,
|
1715
1627
|
inputs,
|
1716
1628
|
outputs,
|
1717
|
-
witnesses
|
1718
|
-
|
1719
|
-
|
1629
|
+
witnesses,
|
1630
|
+
baseAssetId
|
1631
|
+
}) {
|
1632
|
+
this.gasPrice = bn7(gasPrice);
|
1720
1633
|
this.maturity = maturity ?? 0;
|
1721
1634
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1722
1635
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1723
1636
|
this.inputs = inputs ?? [];
|
1724
1637
|
this.outputs = outputs ?? [];
|
1725
1638
|
this.witnesses = witnesses ?? [];
|
1639
|
+
this.baseAssetId = baseAssetId;
|
1726
1640
|
}
|
1727
1641
|
static getPolicyMeta(req) {
|
1728
1642
|
let policyTypes = 0;
|
1729
1643
|
const policies = [];
|
1730
|
-
if (req.
|
1731
|
-
policyTypes += PolicyType.
|
1732
|
-
policies.push({ data: req.
|
1644
|
+
if (req.gasPrice) {
|
1645
|
+
policyTypes += PolicyType.GasPrice;
|
1646
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1733
1647
|
}
|
1734
1648
|
if (req.witnessLimit) {
|
1735
1649
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1916,10 +1830,10 @@ var BaseTransactionRequest = class {
|
|
1916
1830
|
* @param predicate - Predicate bytes.
|
1917
1831
|
* @param predicateData - Predicate data bytes.
|
1918
1832
|
*/
|
1919
|
-
addCoinInput(coin) {
|
1833
|
+
addCoinInput(coin, predicate) {
|
1920
1834
|
const { assetId, owner, amount } = coin;
|
1921
1835
|
let witnessIndex;
|
1922
|
-
if (
|
1836
|
+
if (predicate) {
|
1923
1837
|
witnessIndex = 0;
|
1924
1838
|
} else {
|
1925
1839
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1934,7 +1848,8 @@ var BaseTransactionRequest = class {
|
|
1934
1848
|
amount,
|
1935
1849
|
assetId,
|
1936
1850
|
txPointer: "0x00000000000000000000000000000000",
|
1937
|
-
witnessIndex
|
1851
|
+
witnessIndex,
|
1852
|
+
predicate: predicate?.bytes
|
1938
1853
|
};
|
1939
1854
|
this.pushInput(input);
|
1940
1855
|
this.addChangeOutput(owner, assetId);
|
@@ -1945,13 +1860,11 @@ var BaseTransactionRequest = class {
|
|
1945
1860
|
*
|
1946
1861
|
* @param message - Message resource.
|
1947
1862
|
* @param predicate - Predicate bytes.
|
1948
|
-
* @param predicateData - Predicate data bytes.
|
1949
1863
|
*/
|
1950
|
-
addMessageInput(message) {
|
1864
|
+
addMessageInput(message, predicate) {
|
1951
1865
|
const { recipient, sender, amount } = message;
|
1952
|
-
const assetId = BaseAssetId2;
|
1953
1866
|
let witnessIndex;
|
1954
|
-
if (
|
1867
|
+
if (predicate) {
|
1955
1868
|
witnessIndex = 0;
|
1956
1869
|
} else {
|
1957
1870
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1965,10 +1878,11 @@ var BaseTransactionRequest = class {
|
|
1965
1878
|
sender: sender.toB256(),
|
1966
1879
|
recipient: recipient.toB256(),
|
1967
1880
|
amount,
|
1968
|
-
witnessIndex
|
1881
|
+
witnessIndex,
|
1882
|
+
predicate: predicate?.bytes
|
1969
1883
|
};
|
1970
1884
|
this.pushInput(input);
|
1971
|
-
this.addChangeOutput(recipient,
|
1885
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1972
1886
|
}
|
1973
1887
|
/**
|
1974
1888
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1996,6 +1910,32 @@ var BaseTransactionRequest = class {
|
|
1996
1910
|
resources.forEach((resource) => this.addResource(resource));
|
1997
1911
|
return this;
|
1998
1912
|
}
|
1913
|
+
/**
|
1914
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1915
|
+
* outputs from the related assetIds.
|
1916
|
+
*
|
1917
|
+
* @param resources - The resources to add.
|
1918
|
+
* @returns This transaction.
|
1919
|
+
*/
|
1920
|
+
addPredicateResource(resource, predicate) {
|
1921
|
+
if (isCoin(resource)) {
|
1922
|
+
this.addCoinInput(resource, predicate);
|
1923
|
+
} else {
|
1924
|
+
this.addMessageInput(resource, predicate);
|
1925
|
+
}
|
1926
|
+
return this;
|
1927
|
+
}
|
1928
|
+
/**
|
1929
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1930
|
+
* from the related assetIds.
|
1931
|
+
*
|
1932
|
+
* @param resources - The resources to add.
|
1933
|
+
* @returns This transaction.
|
1934
|
+
*/
|
1935
|
+
addPredicateResources(resources, predicate) {
|
1936
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1937
|
+
return this;
|
1938
|
+
}
|
1999
1939
|
/**
|
2000
1940
|
* Adds a coin output to the transaction.
|
2001
1941
|
*
|
@@ -2003,12 +1943,12 @@ var BaseTransactionRequest = class {
|
|
2003
1943
|
* @param amount - Amount of coin.
|
2004
1944
|
* @param assetId - Asset ID of coin.
|
2005
1945
|
*/
|
2006
|
-
addCoinOutput(to, amount, assetId
|
1946
|
+
addCoinOutput(to, amount, assetId) {
|
2007
1947
|
this.pushOutput({
|
2008
1948
|
type: OutputType2.Coin,
|
2009
1949
|
to: addressify(to).toB256(),
|
2010
1950
|
amount,
|
2011
|
-
assetId
|
1951
|
+
assetId: assetId ?? this.baseAssetId
|
2012
1952
|
});
|
2013
1953
|
return this;
|
2014
1954
|
}
|
@@ -2035,7 +1975,7 @@ var BaseTransactionRequest = class {
|
|
2035
1975
|
* @param to - Address of the owner.
|
2036
1976
|
* @param assetId - Asset ID of coin.
|
2037
1977
|
*/
|
2038
|
-
addChangeOutput(to, assetId
|
1978
|
+
addChangeOutput(to, assetId) {
|
2039
1979
|
const changeOutput = this.getChangeOutputs().find(
|
2040
1980
|
(output) => hexlify7(output.assetId) === assetId
|
2041
1981
|
);
|
@@ -2043,7 +1983,7 @@ var BaseTransactionRequest = class {
|
|
2043
1983
|
this.pushOutput({
|
2044
1984
|
type: OutputType2.Change,
|
2045
1985
|
to: addressify(to).toB256(),
|
2046
|
-
assetId
|
1986
|
+
assetId: assetId ?? this.baseAssetId
|
2047
1987
|
});
|
2048
1988
|
}
|
2049
1989
|
}
|
@@ -2075,7 +2015,7 @@ var BaseTransactionRequest = class {
|
|
2075
2015
|
}
|
2076
2016
|
calculateMaxGas(chainInfo, minGas) {
|
2077
2017
|
const { consensusParameters } = chainInfo;
|
2078
|
-
const { gasPerByte
|
2018
|
+
const { gasPerByte } = consensusParameters;
|
2079
2019
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2080
2020
|
(acc, wit) => acc + wit.dataLength,
|
2081
2021
|
0
|
@@ -2084,8 +2024,7 @@ var BaseTransactionRequest = class {
|
|
2084
2024
|
gasPerByte,
|
2085
2025
|
minGas,
|
2086
2026
|
witnessesLength,
|
2087
|
-
witnessLimit: this.witnessLimit
|
2088
|
-
maxGasPerTx
|
2027
|
+
witnessLimit: this.witnessLimit
|
2089
2028
|
});
|
2090
2029
|
}
|
2091
2030
|
/**
|
@@ -2103,27 +2042,24 @@ var BaseTransactionRequest = class {
|
|
2103
2042
|
});
|
2104
2043
|
const updateAssetInput = (assetId, quantity) => {
|
2105
2044
|
const assetInput = findAssetInput(assetId);
|
2106
|
-
let usedQuantity = quantity;
|
2107
|
-
if (assetId === BaseAssetId2) {
|
2108
|
-
usedQuantity = bn7("1000000000000000000");
|
2109
|
-
}
|
2110
2045
|
if (assetInput && "assetId" in assetInput) {
|
2111
2046
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2112
|
-
assetInput.amount =
|
2047
|
+
assetInput.amount = quantity;
|
2113
2048
|
} else {
|
2114
2049
|
this.addResources([
|
2115
2050
|
{
|
2116
2051
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2117
|
-
amount:
|
2052
|
+
amount: quantity,
|
2118
2053
|
assetId,
|
2119
2054
|
owner: resourcesOwner || Address.fromRandom(),
|
2055
|
+
maturity: 0,
|
2120
2056
|
blockCreated: bn7(1),
|
2121
2057
|
txCreatedIdx: bn7(1)
|
2122
2058
|
}
|
2123
2059
|
]);
|
2124
2060
|
}
|
2125
2061
|
};
|
2126
|
-
updateAssetInput(
|
2062
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2127
2063
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2128
2064
|
}
|
2129
2065
|
/**
|
@@ -2148,7 +2084,7 @@ var BaseTransactionRequest = class {
|
|
2148
2084
|
toJSON() {
|
2149
2085
|
return normalizeJSON(this);
|
2150
2086
|
}
|
2151
|
-
|
2087
|
+
updatePredicateInputs(inputs) {
|
2152
2088
|
this.inputs.forEach((i) => {
|
2153
2089
|
let correspondingInput;
|
2154
2090
|
switch (i.type) {
|
@@ -2170,15 +2106,6 @@ var BaseTransactionRequest = class {
|
|
2170
2106
|
}
|
2171
2107
|
});
|
2172
2108
|
}
|
2173
|
-
shiftPredicateData() {
|
2174
|
-
this.inputs.forEach((input) => {
|
2175
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2176
|
-
input.predicateData = input.paddPredicateData(
|
2177
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2178
|
-
);
|
2179
|
-
}
|
2180
|
-
});
|
2181
|
-
}
|
2182
2109
|
};
|
2183
2110
|
|
2184
2111
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2302,12 +2229,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2302
2229
|
*
|
2303
2230
|
* @param createTransactionRequestLike - The initial values for the instance
|
2304
2231
|
*/
|
2305
|
-
constructor({
|
2306
|
-
bytecodeWitnessIndex,
|
2307
|
-
salt,
|
2308
|
-
storageSlots,
|
2309
|
-
...rest
|
2310
|
-
} = {}) {
|
2232
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2311
2233
|
super(rest);
|
2312
2234
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2313
2235
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2325,8 +2247,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2325
2247
|
return {
|
2326
2248
|
type: TransactionType3.Create,
|
2327
2249
|
...baseTransaction,
|
2250
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2328
2251
|
bytecodeWitnessIndex,
|
2329
|
-
storageSlotsCount:
|
2252
|
+
storageSlotsCount: storageSlots.length,
|
2330
2253
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2331
2254
|
storageSlots
|
2332
2255
|
};
|
@@ -2430,7 +2353,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2430
2353
|
*
|
2431
2354
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2432
2355
|
*/
|
2433
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2356
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2434
2357
|
super(rest);
|
2435
2358
|
this.gasLimit = bn10(gasLimit);
|
2436
2359
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -2449,8 +2372,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2449
2372
|
type: TransactionType4.Script,
|
2450
2373
|
scriptGasLimit: this.gasLimit,
|
2451
2374
|
...super.getBaseTransaction(),
|
2452
|
-
scriptLength:
|
2453
|
-
scriptDataLength:
|
2375
|
+
scriptLength: script.length,
|
2376
|
+
scriptDataLength: scriptData.length,
|
2454
2377
|
receiptsRoot: ZeroBytes327,
|
2455
2378
|
script: hexlify10(script),
|
2456
2379
|
scriptData: hexlify10(scriptData)
|
@@ -2514,7 +2437,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2514
2437
|
}
|
2515
2438
|
calculateMaxGas(chainInfo, minGas) {
|
2516
2439
|
const { consensusParameters } = chainInfo;
|
2517
|
-
const { gasPerByte
|
2440
|
+
const { gasPerByte } = consensusParameters;
|
2518
2441
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2519
2442
|
(acc, wit) => acc + wit.dataLength,
|
2520
2443
|
0
|
@@ -2524,8 +2447,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2524
2447
|
minGas,
|
2525
2448
|
witnessesLength,
|
2526
2449
|
witnessLimit: this.witnessLimit,
|
2527
|
-
gasLimit: this.gasLimit
|
2528
|
-
maxGasPerTx
|
2450
|
+
gasLimit: this.gasLimit
|
2529
2451
|
});
|
2530
2452
|
}
|
2531
2453
|
/**
|
@@ -2582,7 +2504,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2582
2504
|
|
2583
2505
|
// src/providers/transaction-request/utils.ts
|
2584
2506
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2585
|
-
import { TransactionType as TransactionType5
|
2507
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2586
2508
|
var transactionRequestify = (obj) => {
|
2587
2509
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2588
2510
|
return obj;
|
@@ -2600,31 +2522,14 @@ var transactionRequestify = (obj) => {
|
|
2600
2522
|
}
|
2601
2523
|
}
|
2602
2524
|
};
|
2603
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2604
|
-
(acc, input) => {
|
2605
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2606
|
-
acc.utxos.push(input.id);
|
2607
|
-
}
|
2608
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2609
|
-
acc.messages.push(input.nonce);
|
2610
|
-
}
|
2611
|
-
return acc;
|
2612
|
-
},
|
2613
|
-
{
|
2614
|
-
utxos: [],
|
2615
|
-
messages: []
|
2616
|
-
}
|
2617
|
-
);
|
2618
2525
|
|
2619
2526
|
// src/providers/transaction-response/transaction-response.ts
|
2620
2527
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2621
|
-
import { bn as
|
2528
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2622
2529
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2623
2530
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2624
2531
|
|
2625
2532
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2626
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2627
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2628
2533
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2629
2534
|
|
2630
2535
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2633,10 +2538,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2633
2538
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2634
2539
|
var calculateTransactionFee = (params) => {
|
2635
2540
|
const {
|
2636
|
-
|
2541
|
+
gasUsed,
|
2637
2542
|
rawPayload,
|
2638
|
-
|
2639
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2543
|
+
consensusParameters: { gasCosts, feeParams }
|
2640
2544
|
} = params;
|
2641
2545
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2642
2546
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2646,7 +2550,8 @@ var calculateTransactionFee = (params) => {
|
|
2646
2550
|
return {
|
2647
2551
|
fee: bn11(0),
|
2648
2552
|
minFee: bn11(0),
|
2649
|
-
maxFee: bn11(0)
|
2553
|
+
maxFee: bn11(0),
|
2554
|
+
feeFromGasUsed: bn11(0)
|
2650
2555
|
};
|
2651
2556
|
}
|
2652
2557
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2678,6 +2583,7 @@ var calculateTransactionFee = (params) => {
|
|
2678
2583
|
metadataGas,
|
2679
2584
|
txBytesSize: transactionBytes.length
|
2680
2585
|
});
|
2586
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2681
2587
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2682
2588
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2683
2589
|
const maxGas = getMaxGas({
|
@@ -2685,25 +2591,17 @@ var calculateTransactionFee = (params) => {
|
|
2685
2591
|
minGas,
|
2686
2592
|
witnessesLength,
|
2687
2593
|
gasLimit,
|
2688
|
-
witnessLimit
|
2689
|
-
maxGasPerTx
|
2690
|
-
});
|
2691
|
-
const minFee = calculateGasFee({
|
2692
|
-
gasPrice,
|
2693
|
-
gas: minGas,
|
2694
|
-
priceFactor: gasPriceFactor,
|
2695
|
-
tip
|
2696
|
-
});
|
2697
|
-
const maxFee = calculateGasFee({
|
2698
|
-
gasPrice,
|
2699
|
-
gas: maxGas,
|
2700
|
-
priceFactor: gasPriceFactor,
|
2701
|
-
tip
|
2594
|
+
witnessLimit
|
2702
2595
|
});
|
2596
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2597
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2598
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2599
|
+
const fee = minFee.add(feeFromGasUsed);
|
2703
2600
|
return {
|
2601
|
+
fee,
|
2704
2602
|
minFee,
|
2705
2603
|
maxFee,
|
2706
|
-
|
2604
|
+
feeFromGasUsed
|
2707
2605
|
};
|
2708
2606
|
};
|
2709
2607
|
|
@@ -2759,7 +2657,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2759
2657
|
|
2760
2658
|
// src/providers/transaction-summary/input.ts
|
2761
2659
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2762
|
-
import { InputType as
|
2660
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2763
2661
|
function getInputsByTypes(inputs, types) {
|
2764
2662
|
return inputs.filter((i) => types.includes(i.type));
|
2765
2663
|
}
|
@@ -2767,16 +2665,16 @@ function getInputsByType(inputs, type) {
|
|
2767
2665
|
return inputs.filter((i) => i.type === type);
|
2768
2666
|
}
|
2769
2667
|
function getInputsCoin(inputs) {
|
2770
|
-
return getInputsByType(inputs,
|
2668
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2771
2669
|
}
|
2772
2670
|
function getInputsMessage(inputs) {
|
2773
|
-
return getInputsByType(inputs,
|
2671
|
+
return getInputsByType(inputs, InputType5.Message);
|
2774
2672
|
}
|
2775
2673
|
function getInputsCoinAndMessage(inputs) {
|
2776
|
-
return getInputsByTypes(inputs, [
|
2674
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2777
2675
|
}
|
2778
2676
|
function getInputsContract(inputs) {
|
2779
|
-
return getInputsByType(inputs,
|
2677
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2780
2678
|
}
|
2781
2679
|
function getInputFromAssetId(inputs, assetId) {
|
2782
2680
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2795,7 +2693,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2795
2693
|
if (!contractInput) {
|
2796
2694
|
return void 0;
|
2797
2695
|
}
|
2798
|
-
if (contractInput.type !==
|
2696
|
+
if (contractInput.type !== InputType5.Contract) {
|
2799
2697
|
throw new FuelError9(
|
2800
2698
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2801
2699
|
`Contract input should be of type 'contract'.`
|
@@ -2804,10 +2702,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2804
2702
|
return contractInput;
|
2805
2703
|
}
|
2806
2704
|
function getInputAccountAddress(input) {
|
2807
|
-
if (input.type ===
|
2705
|
+
if (input.type === InputType5.Coin) {
|
2808
2706
|
return input.owner.toString();
|
2809
2707
|
}
|
2810
|
-
if (input.type ===
|
2708
|
+
if (input.type === InputType5.Message) {
|
2811
2709
|
return input.recipient.toString();
|
2812
2710
|
}
|
2813
2711
|
return "";
|
@@ -3270,9 +3168,7 @@ function assembleTransactionSummary(params) {
|
|
3270
3168
|
gqlTransactionStatus,
|
3271
3169
|
abiMap = {},
|
3272
3170
|
maxInputs,
|
3273
|
-
gasCosts
|
3274
|
-
maxGasPerTx,
|
3275
|
-
gasPrice
|
3171
|
+
gasCosts
|
3276
3172
|
} = params;
|
3277
3173
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3278
3174
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3286,14 +3182,11 @@ function assembleTransactionSummary(params) {
|
|
3286
3182
|
maxInputs
|
3287
3183
|
});
|
3288
3184
|
const typeName = getTransactionTypeName(transaction.type);
|
3289
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3290
3185
|
const { fee } = calculateTransactionFee({
|
3291
|
-
|
3186
|
+
gasUsed,
|
3292
3187
|
rawPayload,
|
3293
|
-
tip,
|
3294
3188
|
consensusParameters: {
|
3295
3189
|
gasCosts,
|
3296
|
-
maxGasPerTx,
|
3297
3190
|
feeParams: {
|
3298
3191
|
gasPerByte,
|
3299
3192
|
gasPriceFactor
|
@@ -3353,7 +3246,7 @@ var TransactionResponse = class {
|
|
3353
3246
|
/** Current provider */
|
3354
3247
|
provider;
|
3355
3248
|
/** Gas used on the transaction */
|
3356
|
-
gasUsed =
|
3249
|
+
gasUsed = bn14(0);
|
3357
3250
|
/** The graphql Transaction with receipts object. */
|
3358
3251
|
gqlTransaction;
|
3359
3252
|
abis;
|
@@ -3431,13 +3324,8 @@ var TransactionResponse = class {
|
|
3431
3324
|
const decodedTransaction = this.decodeTransaction(
|
3432
3325
|
transaction
|
3433
3326
|
);
|
3434
|
-
|
3435
|
-
|
3436
|
-
txReceipts = transaction.status.receipts;
|
3437
|
-
}
|
3438
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3439
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3440
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3327
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3328
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3441
3329
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3442
3330
|
const transactionSummary = assembleTransactionSummary({
|
3443
3331
|
id: this.id,
|
@@ -3449,9 +3337,7 @@ var TransactionResponse = class {
|
|
3449
3337
|
gasPriceFactor,
|
3450
3338
|
abiMap: contractsAbiMap,
|
3451
3339
|
maxInputs,
|
3452
|
-
gasCosts
|
3453
|
-
maxGasPerTx,
|
3454
|
-
gasPrice
|
3340
|
+
gasCosts
|
3455
3341
|
});
|
3456
3342
|
return transactionSummary;
|
3457
3343
|
}
|
@@ -3578,29 +3464,30 @@ var processGqlChain = (chain) => {
|
|
3578
3464
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3579
3465
|
return {
|
3580
3466
|
name,
|
3581
|
-
baseChainHeight:
|
3467
|
+
baseChainHeight: bn15(daHeight),
|
3582
3468
|
consensusParameters: {
|
3583
|
-
contractMaxSize:
|
3584
|
-
maxInputs:
|
3585
|
-
maxOutputs:
|
3586
|
-
maxWitnesses:
|
3587
|
-
maxGasPerTx:
|
3588
|
-
maxScriptLength:
|
3589
|
-
maxScriptDataLength:
|
3590
|
-
maxStorageSlots:
|
3591
|
-
maxPredicateLength:
|
3592
|
-
maxPredicateDataLength:
|
3593
|
-
maxGasPerPredicate:
|
3594
|
-
gasPriceFactor:
|
3595
|
-
gasPerByte:
|
3596
|
-
maxMessageDataLength:
|
3597
|
-
chainId:
|
3469
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3470
|
+
maxInputs: bn15(txParams.maxInputs),
|
3471
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3472
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3473
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3474
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3475
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3476
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3477
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3478
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3479
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3480
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3481
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3482
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3483
|
+
chainId: bn15(consensusParameters.chainId),
|
3484
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3598
3485
|
gasCosts
|
3599
3486
|
},
|
3600
3487
|
gasCosts,
|
3601
3488
|
latestBlock: {
|
3602
3489
|
id: latestBlock.id,
|
3603
|
-
height:
|
3490
|
+
height: bn15(latestBlock.header.height),
|
3604
3491
|
time: latestBlock.header.time,
|
3605
3492
|
transactions: latestBlock.transactions.map((i) => ({
|
3606
3493
|
id: i.id
|
@@ -3694,8 +3581,10 @@ var _Provider = class {
|
|
3694
3581
|
* Returns some helpful parameters related to gas fees.
|
3695
3582
|
*/
|
3696
3583
|
getGasConfig() {
|
3584
|
+
const { minGasPrice } = this.getNode();
|
3697
3585
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3698
3586
|
return {
|
3587
|
+
minGasPrice,
|
3699
3588
|
maxGasPerTx,
|
3700
3589
|
maxGasPerPredicate,
|
3701
3590
|
gasPriceFactor,
|
@@ -3793,7 +3682,7 @@ var _Provider = class {
|
|
3793
3682
|
*/
|
3794
3683
|
async getBlockNumber() {
|
3795
3684
|
const { chain } = await this.operations.getChain();
|
3796
|
-
return
|
3685
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3797
3686
|
}
|
3798
3687
|
/**
|
3799
3688
|
* Returns the chain information.
|
@@ -3803,11 +3692,13 @@ var _Provider = class {
|
|
3803
3692
|
async fetchNode() {
|
3804
3693
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3805
3694
|
const processedNodeInfo = {
|
3806
|
-
maxDepth:
|
3807
|
-
maxTx:
|
3695
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3696
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3697
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3808
3698
|
nodeVersion: nodeInfo.nodeVersion,
|
3809
3699
|
utxoValidation: nodeInfo.utxoValidation,
|
3810
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3700
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3701
|
+
peers: nodeInfo.peers
|
3811
3702
|
};
|
3812
3703
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3813
3704
|
return processedNodeInfo;
|
@@ -3833,6 +3724,17 @@ var _Provider = class {
|
|
3833
3724
|
} = this.getChain();
|
3834
3725
|
return chainId.toNumber();
|
3835
3726
|
}
|
3727
|
+
/**
|
3728
|
+
* Returns the base asset ID
|
3729
|
+
*
|
3730
|
+
* @returns A promise that resolves to the base asset ID
|
3731
|
+
*/
|
3732
|
+
getBaseAssetId() {
|
3733
|
+
const {
|
3734
|
+
consensusParameters: { baseAssetId }
|
3735
|
+
} = this.getChain();
|
3736
|
+
return baseAssetId;
|
3737
|
+
}
|
3836
3738
|
/**
|
3837
3739
|
* Submits a transaction to the chain to be executed.
|
3838
3740
|
*
|
@@ -3893,13 +3795,14 @@ var _Provider = class {
|
|
3893
3795
|
return this.estimateTxDependencies(transactionRequest);
|
3894
3796
|
}
|
3895
3797
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3896
|
-
const { dryRun:
|
3897
|
-
|
3798
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3799
|
+
encodedTransaction,
|
3898
3800
|
utxoValidation: utxoValidation || false
|
3899
3801
|
});
|
3900
|
-
const
|
3901
|
-
|
3902
|
-
|
3802
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3803
|
+
return {
|
3804
|
+
receipts
|
3805
|
+
};
|
3903
3806
|
}
|
3904
3807
|
/**
|
3905
3808
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3925,7 +3828,7 @@ var _Provider = class {
|
|
3925
3828
|
} = response;
|
3926
3829
|
if (inputs) {
|
3927
3830
|
inputs.forEach((input, index) => {
|
3928
|
-
if ("predicateGasUsed" in input &&
|
3831
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3929
3832
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3930
3833
|
}
|
3931
3834
|
});
|
@@ -3938,6 +3841,9 @@ var _Provider = class {
|
|
3938
3841
|
* If there are missing variable outputs,
|
3939
3842
|
* `addVariableOutputs` is called on the transaction.
|
3940
3843
|
*
|
3844
|
+
* @privateRemarks
|
3845
|
+
* TODO: Investigate support for missing contract IDs
|
3846
|
+
* TODO: Add support for missing output messages
|
3941
3847
|
*
|
3942
3848
|
* @param transactionRequest - The transaction request object.
|
3943
3849
|
* @returns A promise.
|
@@ -3950,19 +3856,16 @@ var _Provider = class {
|
|
3950
3856
|
missingContractIds: []
|
3951
3857
|
};
|
3952
3858
|
}
|
3859
|
+
await this.estimatePredicates(transactionRequest);
|
3953
3860
|
let receipts = [];
|
3954
3861
|
const missingContractIds = [];
|
3955
3862
|
let outputVariables = 0;
|
3956
|
-
let dryrunStatus;
|
3957
3863
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3958
|
-
const {
|
3959
|
-
|
3960
|
-
} = await this.operations.dryRun({
|
3961
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3864
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3865
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3962
3866
|
utxoValidation: false
|
3963
3867
|
});
|
3964
|
-
receipts =
|
3965
|
-
dryrunStatus = status;
|
3868
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3966
3869
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3967
3870
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3968
3871
|
if (hasMissingOutputs) {
|
@@ -3972,10 +3875,6 @@ var _Provider = class {
|
|
3972
3875
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3973
3876
|
missingContractIds.push(contractId);
|
3974
3877
|
});
|
3975
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3976
|
-
transactionRequest
|
3977
|
-
});
|
3978
|
-
transactionRequest.maxFee = maxFee;
|
3979
3878
|
} else {
|
3980
3879
|
break;
|
3981
3880
|
}
|
@@ -3983,139 +3882,37 @@ var _Provider = class {
|
|
3983
3882
|
return {
|
3984
3883
|
receipts,
|
3985
3884
|
outputVariables,
|
3986
|
-
missingContractIds
|
3987
|
-
dryrunStatus
|
3885
|
+
missingContractIds
|
3988
3886
|
};
|
3989
3887
|
}
|
3990
|
-
/**
|
3991
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3992
|
-
*
|
3993
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3994
|
-
* further modifications are identified. The method iteratively updates these transactions
|
3995
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3996
|
-
*
|
3997
|
-
* @param transactionRequests - Array of transaction request objects.
|
3998
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
3999
|
-
*/
|
4000
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4001
|
-
const results = transactionRequests.map(() => ({
|
4002
|
-
receipts: [],
|
4003
|
-
outputVariables: 0,
|
4004
|
-
missingContractIds: [],
|
4005
|
-
dryrunStatus: void 0
|
4006
|
-
}));
|
4007
|
-
const allRequests = clone3(transactionRequests);
|
4008
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4009
|
-
allRequests.forEach((req, index) => {
|
4010
|
-
if (req.type === TransactionType8.Script) {
|
4011
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4012
|
-
}
|
4013
|
-
});
|
4014
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4015
|
-
let attempt = 0;
|
4016
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4017
|
-
const encodedTransactions = transactionsToProcess.map(
|
4018
|
-
(index) => serializedTransactionsMap.get(index)
|
4019
|
-
);
|
4020
|
-
const dryRunResults = await this.operations.dryRun({
|
4021
|
-
encodedTransactions,
|
4022
|
-
utxoValidation: false
|
4023
|
-
});
|
4024
|
-
const nextRoundTransactions = [];
|
4025
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4026
|
-
const currentResultIndex = transactionsToProcess[i];
|
4027
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4028
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4029
|
-
results[currentResultIndex].dryrunStatus = status;
|
4030
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4031
|
-
results[currentResultIndex].receipts
|
4032
|
-
);
|
4033
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4034
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4035
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4036
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4037
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4038
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4039
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4040
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4041
|
-
});
|
4042
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4043
|
-
transactionRequest: requestToProcess
|
4044
|
-
});
|
4045
|
-
requestToProcess.maxFee = maxFee;
|
4046
|
-
serializedTransactionsMap.set(
|
4047
|
-
currentResultIndex,
|
4048
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4049
|
-
);
|
4050
|
-
nextRoundTransactions.push(currentResultIndex);
|
4051
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4052
|
-
}
|
4053
|
-
}
|
4054
|
-
transactionsToProcess = nextRoundTransactions;
|
4055
|
-
attempt += 1;
|
4056
|
-
}
|
4057
|
-
return results;
|
4058
|
-
}
|
4059
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4060
|
-
if (estimateTxDependencies) {
|
4061
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4062
|
-
}
|
4063
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4064
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4065
|
-
encodedTransactions,
|
4066
|
-
utxoValidation: utxoValidation || false
|
4067
|
-
});
|
4068
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4069
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4070
|
-
return { receipts, dryrunStatus: status };
|
4071
|
-
});
|
4072
|
-
return results;
|
4073
|
-
}
|
4074
3888
|
/**
|
4075
3889
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4076
3890
|
* @param transactionRequest - The transaction request object.
|
4077
3891
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4078
3892
|
*/
|
4079
|
-
|
3893
|
+
estimateTxGasAndFee(params) {
|
4080
3894
|
const { transactionRequest } = params;
|
4081
|
-
|
3895
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4082
3896
|
const chainInfo = this.getChain();
|
4083
|
-
const
|
3897
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3898
|
+
transactionRequest.gasPrice = gasPrice;
|
4084
3899
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4085
|
-
|
4086
|
-
gasPrice = await this.estimateGasPrice(10);
|
4087
|
-
}
|
4088
|
-
const minFee = calculateGasFee({
|
4089
|
-
gasPrice: bn16(gasPrice),
|
4090
|
-
gas: minGas,
|
4091
|
-
priceFactor: gasPriceFactor,
|
4092
|
-
tip: transactionRequest.tip
|
4093
|
-
}).add(1);
|
4094
|
-
let gasLimit = bn16(0);
|
3900
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4095
3901
|
if (transactionRequest.type === TransactionType8.Script) {
|
4096
|
-
gasLimit = transactionRequest.gasLimit;
|
4097
3902
|
if (transactionRequest.gasLimit.eq(0)) {
|
4098
3903
|
transactionRequest.gasLimit = minGas;
|
4099
3904
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4100
3905
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4101
3906
|
);
|
4102
|
-
gasLimit = transactionRequest.gasLimit;
|
4103
3907
|
}
|
4104
3908
|
}
|
4105
3909
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4106
|
-
const maxFee =
|
4107
|
-
gasPrice: bn16(gasPrice),
|
4108
|
-
gas: maxGas,
|
4109
|
-
priceFactor: gasPriceFactor,
|
4110
|
-
tip: transactionRequest.tip
|
4111
|
-
}).add(1);
|
3910
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4112
3911
|
return {
|
4113
3912
|
minGas,
|
4114
3913
|
minFee,
|
4115
3914
|
maxGas,
|
4116
|
-
maxFee
|
4117
|
-
gasPrice,
|
4118
|
-
gasLimit
|
3915
|
+
maxFee
|
4119
3916
|
};
|
4120
3917
|
}
|
4121
3918
|
/**
|
@@ -4133,17 +3930,15 @@ var _Provider = class {
|
|
4133
3930
|
if (estimateTxDependencies) {
|
4134
3931
|
return this.estimateTxDependencies(transactionRequest);
|
4135
3932
|
}
|
4136
|
-
const
|
4137
|
-
const { dryRun:
|
4138
|
-
|
3933
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3934
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3935
|
+
encodedTransaction,
|
4139
3936
|
utxoValidation: true
|
4140
3937
|
});
|
4141
|
-
const
|
4142
|
-
|
4143
|
-
|
4144
|
-
|
4145
|
-
});
|
4146
|
-
return { receipts: callResult[0].receipts };
|
3938
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3939
|
+
return {
|
3940
|
+
receipts
|
3941
|
+
};
|
4147
3942
|
}
|
4148
3943
|
/**
|
4149
3944
|
* Returns a transaction cost to enable user
|
@@ -4160,79 +3955,77 @@ var _Provider = class {
|
|
4160
3955
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4161
3956
|
* @returns A promise that resolves to the transaction cost object.
|
4162
3957
|
*/
|
4163
|
-
async getTransactionCost(transactionRequestLike,
|
3958
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3959
|
+
estimateTxDependencies = true,
|
3960
|
+
estimatePredicates = true,
|
3961
|
+
resourcesOwner,
|
3962
|
+
signatureCallback
|
3963
|
+
} = {}) {
|
4164
3964
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3965
|
+
const { minGasPrice } = this.getGasConfig();
|
3966
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4165
3967
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4166
3968
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4167
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3969
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4168
3970
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4169
|
-
txRequestClone.maxFee = bn16(0);
|
4170
3971
|
if (isScriptTransaction) {
|
4171
|
-
txRequestClone.gasLimit =
|
3972
|
+
txRequestClone.gasLimit = bn15(0);
|
4172
3973
|
}
|
4173
|
-
if (
|
4174
|
-
resourcesOwner
|
3974
|
+
if (estimatePredicates) {
|
3975
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3976
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3977
|
+
}
|
3978
|
+
await this.estimatePredicates(txRequestClone);
|
4175
3979
|
}
|
4176
|
-
const signedRequest = clone3(txRequestClone);
|
4177
|
-
let addedSignatures = 0;
|
4178
3980
|
if (signatureCallback && isScriptTransaction) {
|
4179
|
-
|
4180
|
-
await signatureCallback(signedRequest);
|
4181
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3981
|
+
await signatureCallback(txRequestClone);
|
4182
3982
|
}
|
4183
|
-
|
4184
|
-
|
4185
|
-
transactionRequest: signedRequest
|
3983
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3984
|
+
transactionRequest: txRequestClone
|
4186
3985
|
});
|
4187
3986
|
let receipts = [];
|
4188
3987
|
let missingContractIds = [];
|
4189
3988
|
let outputVariables = 0;
|
4190
|
-
let gasUsed =
|
4191
|
-
|
4192
|
-
|
4193
|
-
if (isScriptTransaction) {
|
4194
|
-
txRequestClone.gasLimit = gasLimit;
|
4195
|
-
if (signatureCallback) {
|
4196
|
-
await signatureCallback(txRequestClone);
|
4197
|
-
}
|
3989
|
+
let gasUsed = bn15(0);
|
3990
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3991
|
+
txRequestClone.gasPrice = bn15(0);
|
4198
3992
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4199
3993
|
receipts = result.receipts;
|
4200
3994
|
outputVariables = result.outputVariables;
|
4201
3995
|
missingContractIds = result.missingContractIds;
|
4202
3996
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4203
3997
|
txRequestClone.gasLimit = gasUsed;
|
4204
|
-
|
4205
|
-
|
4206
|
-
|
3998
|
+
txRequestClone.gasPrice = setGasPrice;
|
3999
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4000
|
+
transactionRequest: txRequestClone
|
4207
4001
|
}));
|
4208
4002
|
}
|
4209
4003
|
return {
|
4210
4004
|
requiredQuantities: allQuantities,
|
4211
4005
|
receipts,
|
4212
4006
|
gasUsed,
|
4213
|
-
|
4007
|
+
minGasPrice,
|
4008
|
+
gasPrice: setGasPrice,
|
4214
4009
|
minGas,
|
4215
4010
|
maxGas,
|
4216
4011
|
minFee,
|
4217
4012
|
maxFee,
|
4013
|
+
estimatedInputs: txRequestClone.inputs,
|
4218
4014
|
outputVariables,
|
4219
|
-
missingContractIds
|
4220
|
-
addedSignatures,
|
4221
|
-
estimatedPredicates: txRequestClone.inputs
|
4015
|
+
missingContractIds
|
4222
4016
|
};
|
4223
4017
|
}
|
4224
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4018
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4225
4019
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4226
4020
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4227
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4228
|
-
quantitiesToContract
|
4229
|
-
});
|
4021
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4230
4022
|
transactionRequest.addResources(
|
4231
4023
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4232
4024
|
);
|
4233
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4234
|
-
|
4235
|
-
|
4025
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4026
|
+
transactionRequest,
|
4027
|
+
forwardingQuantities
|
4028
|
+
);
|
4236
4029
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4237
4030
|
return {
|
4238
4031
|
resources,
|
@@ -4254,10 +4047,11 @@ var _Provider = class {
|
|
4254
4047
|
return coins.map((coin) => ({
|
4255
4048
|
id: coin.utxoId,
|
4256
4049
|
assetId: coin.assetId,
|
4257
|
-
amount:
|
4050
|
+
amount: bn15(coin.amount),
|
4258
4051
|
owner: Address2.fromAddressOrString(coin.owner),
|
4259
|
-
|
4260
|
-
|
4052
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4053
|
+
blockCreated: bn15(coin.blockCreated),
|
4054
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4261
4055
|
}));
|
4262
4056
|
}
|
4263
4057
|
/**
|
@@ -4294,9 +4088,9 @@ var _Provider = class {
|
|
4294
4088
|
switch (coin.__typename) {
|
4295
4089
|
case "MessageCoin":
|
4296
4090
|
return {
|
4297
|
-
amount:
|
4091
|
+
amount: bn15(coin.amount),
|
4298
4092
|
assetId: coin.assetId,
|
4299
|
-
daHeight:
|
4093
|
+
daHeight: bn15(coin.daHeight),
|
4300
4094
|
sender: Address2.fromAddressOrString(coin.sender),
|
4301
4095
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4302
4096
|
nonce: coin.nonce
|
@@ -4304,11 +4098,12 @@ var _Provider = class {
|
|
4304
4098
|
case "Coin":
|
4305
4099
|
return {
|
4306
4100
|
id: coin.utxoId,
|
4307
|
-
amount:
|
4101
|
+
amount: bn15(coin.amount),
|
4308
4102
|
assetId: coin.assetId,
|
4309
4103
|
owner: Address2.fromAddressOrString(coin.owner),
|
4310
|
-
|
4311
|
-
|
4104
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4105
|
+
blockCreated: bn15(coin.blockCreated),
|
4106
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4312
4107
|
};
|
4313
4108
|
default:
|
4314
4109
|
return null;
|
@@ -4325,13 +4120,13 @@ var _Provider = class {
|
|
4325
4120
|
async getBlock(idOrHeight) {
|
4326
4121
|
let variables;
|
4327
4122
|
if (typeof idOrHeight === "number") {
|
4328
|
-
variables = { height:
|
4123
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4329
4124
|
} else if (idOrHeight === "latest") {
|
4330
4125
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4331
4126
|
} else if (idOrHeight.length === 66) {
|
4332
4127
|
variables = { blockId: idOrHeight };
|
4333
4128
|
} else {
|
4334
|
-
variables = { blockId:
|
4129
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4335
4130
|
}
|
4336
4131
|
const { block } = await this.operations.getBlock(variables);
|
4337
4132
|
if (!block) {
|
@@ -4339,7 +4134,7 @@ var _Provider = class {
|
|
4339
4134
|
}
|
4340
4135
|
return {
|
4341
4136
|
id: block.id,
|
4342
|
-
height:
|
4137
|
+
height: bn15(block.header.height),
|
4343
4138
|
time: block.header.time,
|
4344
4139
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4345
4140
|
};
|
@@ -4354,7 +4149,7 @@ var _Provider = class {
|
|
4354
4149
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4355
4150
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4356
4151
|
id: block.id,
|
4357
|
-
height:
|
4152
|
+
height: bn15(block.header.height),
|
4358
4153
|
time: block.header.time,
|
4359
4154
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4360
4155
|
}));
|
@@ -4369,7 +4164,7 @@ var _Provider = class {
|
|
4369
4164
|
async getBlockWithTransactions(idOrHeight) {
|
4370
4165
|
let variables;
|
4371
4166
|
if (typeof idOrHeight === "number") {
|
4372
|
-
variables = { blockHeight:
|
4167
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4373
4168
|
} else if (idOrHeight === "latest") {
|
4374
4169
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4375
4170
|
} else {
|
@@ -4381,7 +4176,7 @@ var _Provider = class {
|
|
4381
4176
|
}
|
4382
4177
|
return {
|
4383
4178
|
id: block.id,
|
4384
|
-
height:
|
4179
|
+
height: bn15(block.header.height, 10),
|
4385
4180
|
time: block.header.time,
|
4386
4181
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4387
4182
|
transactions: block.transactions.map(
|
@@ -4430,7 +4225,7 @@ var _Provider = class {
|
|
4430
4225
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4431
4226
|
asset: hexlify12(assetId)
|
4432
4227
|
});
|
4433
|
-
return
|
4228
|
+
return bn15(contractBalance.amount, 10);
|
4434
4229
|
}
|
4435
4230
|
/**
|
4436
4231
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4444,7 +4239,7 @@ var _Provider = class {
|
|
4444
4239
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4445
4240
|
assetId: hexlify12(assetId)
|
4446
4241
|
});
|
4447
|
-
return
|
4242
|
+
return bn15(balance.amount, 10);
|
4448
4243
|
}
|
4449
4244
|
/**
|
4450
4245
|
* Returns balances for the given owner.
|
@@ -4462,7 +4257,7 @@ var _Provider = class {
|
|
4462
4257
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4463
4258
|
return balances.map((balance) => ({
|
4464
4259
|
assetId: balance.assetId,
|
4465
|
-
amount:
|
4260
|
+
amount: bn15(balance.amount)
|
4466
4261
|
}));
|
4467
4262
|
}
|
4468
4263
|
/**
|
@@ -4484,15 +4279,15 @@ var _Provider = class {
|
|
4484
4279
|
sender: message.sender,
|
4485
4280
|
recipient: message.recipient,
|
4486
4281
|
nonce: message.nonce,
|
4487
|
-
amount:
|
4282
|
+
amount: bn15(message.amount),
|
4488
4283
|
data: message.data
|
4489
4284
|
}),
|
4490
4285
|
sender: Address2.fromAddressOrString(message.sender),
|
4491
4286
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4492
4287
|
nonce: message.nonce,
|
4493
|
-
amount:
|
4288
|
+
amount: bn15(message.amount),
|
4494
4289
|
data: InputMessageCoder.decodeData(message.data),
|
4495
|
-
daHeight:
|
4290
|
+
daHeight: bn15(message.daHeight)
|
4496
4291
|
}));
|
4497
4292
|
}
|
4498
4293
|
/**
|
@@ -4545,60 +4340,44 @@ var _Provider = class {
|
|
4545
4340
|
} = result.messageProof;
|
4546
4341
|
return {
|
4547
4342
|
messageProof: {
|
4548
|
-
proofIndex:
|
4343
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4549
4344
|
proofSet: messageProof.proofSet
|
4550
4345
|
},
|
4551
4346
|
blockProof: {
|
4552
|
-
proofIndex:
|
4347
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4553
4348
|
proofSet: blockProof.proofSet
|
4554
4349
|
},
|
4555
4350
|
messageBlockHeader: {
|
4556
4351
|
id: messageBlockHeader.id,
|
4557
|
-
daHeight:
|
4558
|
-
transactionsCount:
|
4352
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4353
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4559
4354
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4560
|
-
height:
|
4355
|
+
height: bn15(messageBlockHeader.height),
|
4561
4356
|
prevRoot: messageBlockHeader.prevRoot,
|
4562
4357
|
time: messageBlockHeader.time,
|
4563
4358
|
applicationHash: messageBlockHeader.applicationHash,
|
4564
|
-
|
4565
|
-
|
4566
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4567
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4568
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4359
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4360
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4569
4361
|
},
|
4570
4362
|
commitBlockHeader: {
|
4571
4363
|
id: commitBlockHeader.id,
|
4572
|
-
daHeight:
|
4573
|
-
transactionsCount:
|
4364
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4365
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4574
4366
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4575
|
-
height:
|
4367
|
+
height: bn15(commitBlockHeader.height),
|
4576
4368
|
prevRoot: commitBlockHeader.prevRoot,
|
4577
4369
|
time: commitBlockHeader.time,
|
4578
4370
|
applicationHash: commitBlockHeader.applicationHash,
|
4579
|
-
|
4580
|
-
|
4581
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4582
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4583
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4371
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4372
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4584
4373
|
},
|
4585
4374
|
sender: Address2.fromAddressOrString(sender),
|
4586
4375
|
recipient: Address2.fromAddressOrString(recipient),
|
4587
4376
|
nonce,
|
4588
|
-
amount:
|
4377
|
+
amount: bn15(amount),
|
4589
4378
|
data
|
4590
4379
|
};
|
4591
4380
|
}
|
4592
|
-
async getLatestGasPrice() {
|
4593
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4594
|
-
return bn16(latestGasPrice.gasPrice);
|
4595
|
-
}
|
4596
|
-
async estimateGasPrice(blockHorizon) {
|
4597
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4598
|
-
blockHorizon: String(blockHorizon)
|
4599
|
-
});
|
4600
|
-
return bn16(estimateGasPrice.gasPrice);
|
4601
|
-
}
|
4602
4381
|
/**
|
4603
4382
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4604
4383
|
*
|
@@ -4618,10 +4397,10 @@ var _Provider = class {
|
|
4618
4397
|
*/
|
4619
4398
|
async produceBlocks(amount, startTime) {
|
4620
4399
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4621
|
-
blocksToProduce:
|
4400
|
+
blocksToProduce: bn15(amount).toString(10),
|
4622
4401
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4623
4402
|
});
|
4624
|
-
return
|
4403
|
+
return bn15(latestBlockHeight);
|
4625
4404
|
}
|
4626
4405
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4627
4406
|
async getTransactionResponse(transactionId) {
|
@@ -4635,7 +4414,7 @@ cacheInputs_fn = function(inputs) {
|
|
4635
4414
|
return;
|
4636
4415
|
}
|
4637
4416
|
inputs.forEach((input) => {
|
4638
|
-
if (input.type ===
|
4417
|
+
if (input.type === InputType6.Coin) {
|
4639
4418
|
this.cache?.set(input.id);
|
4640
4419
|
}
|
4641
4420
|
});
|
@@ -4645,7 +4424,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4645
4424
|
|
4646
4425
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4647
4426
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4648
|
-
import { bn as
|
4427
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4649
4428
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4650
4429
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4651
4430
|
|
@@ -4853,8 +4632,9 @@ var Account = class extends AbstractAccount {
|
|
4853
4632
|
* @param assetId - The asset ID to check the balance for.
|
4854
4633
|
* @returns A promise that resolves to the balance amount.
|
4855
4634
|
*/
|
4856
|
-
async getBalance(assetId
|
4857
|
-
const
|
4635
|
+
async getBalance(assetId) {
|
4636
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4637
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4858
4638
|
return amount;
|
4859
4639
|
}
|
4860
4640
|
/**
|
@@ -4891,33 +4671,37 @@ var Account = class extends AbstractAccount {
|
|
4891
4671
|
* @param fee - The estimated transaction fee.
|
4892
4672
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4893
4673
|
*/
|
4894
|
-
async fund(request,
|
4895
|
-
const
|
4896
|
-
const
|
4897
|
-
|
4898
|
-
|
4899
|
-
|
4900
|
-
coinQuantities: requiredQuantities
|
4674
|
+
async fund(request, coinQuantities, fee) {
|
4675
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4676
|
+
const updatedQuantities = addAmountToAsset({
|
4677
|
+
amount: bn17(fee),
|
4678
|
+
assetId: baseAssetId,
|
4679
|
+
coinQuantities
|
4901
4680
|
});
|
4902
4681
|
const quantitiesDict = {};
|
4903
|
-
|
4682
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4904
4683
|
quantitiesDict[assetId] = {
|
4905
4684
|
required: amount,
|
4906
|
-
owned:
|
4685
|
+
owned: bn17(0)
|
4907
4686
|
};
|
4908
4687
|
});
|
4909
|
-
|
4688
|
+
const cachedUtxos = [];
|
4689
|
+
const cachedMessages = [];
|
4690
|
+
const owner = this.address.toB256();
|
4691
|
+
request.inputs.forEach((input) => {
|
4910
4692
|
const isResource = "amount" in input;
|
4911
4693
|
if (isResource) {
|
4912
4694
|
const isCoin2 = "owner" in input;
|
4913
4695
|
if (isCoin2) {
|
4914
4696
|
const assetId = String(input.assetId);
|
4915
|
-
if (quantitiesDict[assetId]) {
|
4916
|
-
const amount =
|
4697
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4698
|
+
const amount = bn17(input.amount);
|
4917
4699
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4700
|
+
cachedUtxos.push(input.id);
|
4918
4701
|
}
|
4919
|
-
} else if (input.amount && quantitiesDict[
|
4920
|
-
quantitiesDict[
|
4702
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4703
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4704
|
+
cachedMessages.push(input.nonce);
|
4921
4705
|
}
|
4922
4706
|
}
|
4923
4707
|
});
|
@@ -4932,23 +4716,12 @@ var Account = class extends AbstractAccount {
|
|
4932
4716
|
});
|
4933
4717
|
const needsToBeFunded = missingQuantities.length;
|
4934
4718
|
if (needsToBeFunded) {
|
4935
|
-
const
|
4936
|
-
|
4937
|
-
|
4938
|
-
|
4939
|
-
|
4940
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4941
|
-
const requestToBeReEstimate = clone4(txRequest);
|
4942
|
-
if (addedSignatures) {
|
4943
|
-
Array.from({ length: addedSignatures }).forEach(
|
4944
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4945
|
-
);
|
4719
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4720
|
+
messages: cachedMessages,
|
4721
|
+
utxos: cachedUtxos
|
4722
|
+
});
|
4723
|
+
request.addResources(resources);
|
4946
4724
|
}
|
4947
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4948
|
-
transactionRequest: requestToBeReEstimate
|
4949
|
-
});
|
4950
|
-
txRequest.maxFee = maxFee;
|
4951
|
-
return txRequest;
|
4952
4725
|
}
|
4953
4726
|
/**
|
4954
4727
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4956,25 +4729,30 @@ var Account = class extends AbstractAccount {
|
|
4956
4729
|
* @param destination - The address of the destination.
|
4957
4730
|
* @param amount - The amount of coins to transfer.
|
4958
4731
|
* @param assetId - The asset ID of the coins to transfer.
|
4959
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4732
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4960
4733
|
* @returns A promise that resolves to the prepared transaction request.
|
4961
4734
|
*/
|
4962
|
-
async createTransfer(destination, amount, assetId
|
4963
|
-
const
|
4964
|
-
|
4965
|
-
const
|
4735
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4736
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4737
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4738
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4739
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4740
|
+
const request = new ScriptTransactionRequest(params);
|
4741
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4742
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4966
4743
|
estimateTxDependencies: true,
|
4967
4744
|
resourcesOwner: this
|
4968
4745
|
});
|
4969
|
-
|
4970
|
-
|
4971
|
-
|
4972
|
-
|
4973
|
-
|
4974
|
-
|
4975
|
-
|
4976
|
-
|
4977
|
-
await this.fund(request,
|
4746
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4747
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4748
|
+
this.validateGas({
|
4749
|
+
gasUsed,
|
4750
|
+
gasPrice: request.gasPrice,
|
4751
|
+
gasLimit: request.gasLimit,
|
4752
|
+
minGasPrice
|
4753
|
+
});
|
4754
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4755
|
+
request.updatePredicateInputs(estimatedInputs);
|
4978
4756
|
return request;
|
4979
4757
|
}
|
4980
4758
|
/**
|
@@ -4986,14 +4764,15 @@ var Account = class extends AbstractAccount {
|
|
4986
4764
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4987
4765
|
* @returns A promise that resolves to the transaction response.
|
4988
4766
|
*/
|
4989
|
-
async transfer(destination, amount, assetId
|
4990
|
-
if (
|
4767
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4768
|
+
if (bn17(amount).lte(0)) {
|
4991
4769
|
throw new FuelError15(
|
4992
4770
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4993
4771
|
"Transfer amount must be a positive number."
|
4994
4772
|
);
|
4995
4773
|
}
|
4996
|
-
const
|
4774
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4775
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4997
4776
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4998
4777
|
}
|
4999
4778
|
/**
|
@@ -5005,38 +4784,41 @@ var Account = class extends AbstractAccount {
|
|
5005
4784
|
* @param txParams - The optional transaction parameters.
|
5006
4785
|
* @returns A promise that resolves to the transaction response.
|
5007
4786
|
*/
|
5008
|
-
async transferToContract(contractId, amount, assetId
|
5009
|
-
if (
|
4787
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4788
|
+
if (bn17(amount).lte(0)) {
|
5010
4789
|
throw new FuelError15(
|
5011
4790
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5012
4791
|
"Transfer amount must be a positive number."
|
5013
4792
|
);
|
5014
4793
|
}
|
5015
4794
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4795
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4796
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4797
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4798
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5016
4799
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5017
4800
|
hexlifiedContractId: contractAddress.toB256(),
|
5018
|
-
amountToTransfer:
|
5019
|
-
assetId
|
4801
|
+
amountToTransfer: bn17(amount),
|
4802
|
+
assetId: assetIdToTransfer
|
5020
4803
|
});
|
5021
4804
|
const request = new ScriptTransactionRequest({
|
5022
|
-
...
|
4805
|
+
...params,
|
5023
4806
|
script,
|
5024
4807
|
scriptData
|
5025
4808
|
});
|
5026
4809
|
request.addContractInputAndOutput(contractAddress);
|
5027
|
-
const
|
5028
|
-
|
5029
|
-
|
4810
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4811
|
+
request,
|
4812
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4813
|
+
);
|
4814
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4815
|
+
this.validateGas({
|
4816
|
+
gasUsed,
|
4817
|
+
gasPrice: request.gasPrice,
|
4818
|
+
gasLimit: request.gasLimit,
|
4819
|
+
minGasPrice
|
5030
4820
|
});
|
5031
|
-
|
5032
|
-
this.validateGas({
|
5033
|
-
gasUsed: txCost.gasUsed,
|
5034
|
-
gasLimit: request.gasLimit
|
5035
|
-
});
|
5036
|
-
}
|
5037
|
-
request.gasLimit = txCost.gasUsed;
|
5038
|
-
request.maxFee = txCost.maxFee;
|
5039
|
-
await this.fund(request, txCost);
|
4821
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5040
4822
|
return this.sendTransaction(request);
|
5041
4823
|
}
|
5042
4824
|
/**
|
@@ -5048,31 +4830,40 @@ var Account = class extends AbstractAccount {
|
|
5048
4830
|
* @returns A promise that resolves to the transaction response.
|
5049
4831
|
*/
|
5050
4832
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4833
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4834
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5051
4835
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5052
4836
|
const recipientDataArray = arrayify14(
|
5053
4837
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5054
4838
|
);
|
5055
4839
|
const amountDataArray = arrayify14(
|
5056
|
-
"0x".concat(
|
4840
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5057
4841
|
);
|
5058
4842
|
const script = new Uint8Array([
|
5059
4843
|
...arrayify14(withdrawScript.bytes),
|
5060
4844
|
...recipientDataArray,
|
5061
4845
|
...amountDataArray
|
5062
4846
|
]);
|
5063
|
-
const params = {
|
4847
|
+
const params = {
|
4848
|
+
script,
|
4849
|
+
gasPrice: minGasPrice,
|
4850
|
+
baseAssetId,
|
4851
|
+
...txParams
|
4852
|
+
};
|
5064
4853
|
const request = new ScriptTransactionRequest(params);
|
5065
|
-
const
|
5066
|
-
const
|
5067
|
-
|
5068
|
-
|
5069
|
-
|
5070
|
-
|
5071
|
-
|
5072
|
-
|
5073
|
-
|
5074
|
-
|
5075
|
-
|
4854
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4855
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4856
|
+
request,
|
4857
|
+
forwardingQuantities
|
4858
|
+
);
|
4859
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4860
|
+
this.validateGas({
|
4861
|
+
gasUsed,
|
4862
|
+
gasPrice: request.gasPrice,
|
4863
|
+
gasLimit: request.gasLimit,
|
4864
|
+
minGasPrice
|
4865
|
+
});
|
4866
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5076
4867
|
return this.sendTransaction(request);
|
5077
4868
|
}
|
5078
4869
|
async signMessage(message) {
|
@@ -5130,7 +4921,18 @@ var Account = class extends AbstractAccount {
|
|
5130
4921
|
}
|
5131
4922
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5132
4923
|
}
|
5133
|
-
validateGas({
|
4924
|
+
validateGas({
|
4925
|
+
gasUsed,
|
4926
|
+
gasPrice,
|
4927
|
+
gasLimit,
|
4928
|
+
minGasPrice
|
4929
|
+
}) {
|
4930
|
+
if (minGasPrice.gt(gasPrice)) {
|
4931
|
+
throw new FuelError15(
|
4932
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4933
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4934
|
+
);
|
4935
|
+
}
|
5134
4936
|
if (gasUsed.gt(gasLimit)) {
|
5135
4937
|
throw new FuelError15(
|
5136
4938
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5422,7 +5224,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5422
5224
|
* @param transactionRequestLike - The transaction request to send.
|
5423
5225
|
* @returns A promise that resolves to the TransactionResponse object.
|
5424
5226
|
*/
|
5425
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5227
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5426
5228
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5427
5229
|
if (estimateTxDependencies) {
|
5428
5230
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5463,7 +5265,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5463
5265
|
// src/hdwallet/hdwallet.ts
|
5464
5266
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5465
5267
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5466
|
-
import { bn as
|
5268
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5467
5269
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5468
5270
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5469
5271
|
|
@@ -7929,7 +7731,7 @@ var HDWallet = class {
|
|
7929
7731
|
const IR = bytes.slice(32);
|
7930
7732
|
if (privateKey) {
|
7931
7733
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7932
|
-
const ki =
|
7734
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7933
7735
|
return new HDWallet({
|
7934
7736
|
privateKey: ki,
|
7935
7737
|
chainCode: IR,
|
@@ -8200,15 +8002,16 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8200
8002
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
8201
8003
|
wallet.provider
|
8202
8004
|
);
|
8203
|
-
const
|
8204
|
-
|
8205
|
-
|
8206
|
-
|
8005
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
8006
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
8007
|
+
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
8008
|
+
const request = new ScriptTransactionRequest({
|
8009
|
+
baseAssetId,
|
8010
|
+
gasLimit: 1e4,
|
8011
|
+
gasPrice: minGasPrice
|
8207
8012
|
});
|
8208
|
-
|
8209
|
-
request.
|
8210
|
-
request.maxFee = txCost.maxFee;
|
8211
|
-
await genesisWallet.fund(request, txCost);
|
8013
|
+
request.addResources(resources);
|
8014
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8212
8015
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8213
8016
|
};
|
8214
8017
|
|
@@ -8222,12 +8025,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8222
8025
|
};
|
8223
8026
|
|
8224
8027
|
// src/test-utils/launchNode.ts
|
8225
|
-
import {
|
8226
|
-
import {
|
8028
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8029
|
+
import { toHex as toHex2 } from "@fuel-ts/math";
|
8030
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8227
8031
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8228
8032
|
import { spawn } from "child_process";
|
8229
8033
|
import { randomUUID } from "crypto";
|
8230
|
-
import { randomBytes as randomBytes6 } from "ethers";
|
8231
8034
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8232
8035
|
import os from "os";
|
8233
8036
|
import path from "path";
|
@@ -8276,12 +8079,12 @@ var launchNode = async ({
|
|
8276
8079
|
// eslint-disable-next-line no-async-promise-executor
|
8277
8080
|
new Promise(async (resolve, reject) => {
|
8278
8081
|
const remainingArgs = extractRemainingArgs(args, [
|
8279
|
-
"--
|
8082
|
+
"--chain",
|
8280
8083
|
"--consensus-key",
|
8281
8084
|
"--db-type",
|
8282
8085
|
"--poa-instant"
|
8283
8086
|
]);
|
8284
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8087
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8285
8088
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8286
8089
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8287
8090
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8300,54 +8103,36 @@ var launchNode = async ({
|
|
8300
8103
|
let chainConfigPathToUse;
|
8301
8104
|
const prefix = basePath || os.tmpdir();
|
8302
8105
|
const suffix = basePath ? "" : randomUUID();
|
8303
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix
|
8106
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8304
8107
|
if (chainConfigPath) {
|
8305
8108
|
chainConfigPathToUse = chainConfigPath;
|
8306
8109
|
} else {
|
8307
8110
|
if (!existsSync(tempDirPath)) {
|
8308
8111
|
mkdirSync(tempDirPath, { recursive: true });
|
8309
8112
|
}
|
8310
|
-
|
8311
|
-
|
8312
|
-
stateConfigJson = {
|
8313
|
-
...stateConfigJson,
|
8314
|
-
coins: [
|
8315
|
-
...stateConfigJson.coins.map((coin) => ({
|
8316
|
-
...coin,
|
8317
|
-
amount: "18446744073709551615"
|
8318
|
-
}))
|
8319
|
-
],
|
8320
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8321
|
-
...message,
|
8322
|
-
amount: "18446744073709551615"
|
8323
|
-
}))
|
8324
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8325
|
-
};
|
8113
|
+
const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
|
8114
|
+
let chainConfig = defaultChainConfig;
|
8326
8115
|
if (!process.env.GENESIS_SECRET) {
|
8327
8116
|
const pk = Signer.generatePrivateKey();
|
8328
8117
|
const signer = new Signer(pk);
|
8329
8118
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8330
|
-
|
8331
|
-
|
8332
|
-
|
8333
|
-
|
8334
|
-
|
8335
|
-
|
8336
|
-
|
8337
|
-
|
8338
|
-
|
8339
|
-
|
8119
|
+
chainConfig = {
|
8120
|
+
...defaultChainConfig,
|
8121
|
+
initial_state: {
|
8122
|
+
...defaultChainConfig.initial_state,
|
8123
|
+
coins: [
|
8124
|
+
...defaultChainConfig.initial_state.coins,
|
8125
|
+
{
|
8126
|
+
owner: signer.address.toHexString(),
|
8127
|
+
amount: toHex2(1e9),
|
8128
|
+
asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
|
8129
|
+
}
|
8130
|
+
]
|
8131
|
+
}
|
8132
|
+
};
|
8340
8133
|
}
|
8341
|
-
|
8342
|
-
|
8343
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8344
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8345
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8346
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8347
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8348
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8349
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8350
|
-
chainConfigPathToUse = tempDirPath;
|
8134
|
+
writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8135
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8351
8136
|
}
|
8352
8137
|
const child = spawn(
|
8353
8138
|
command,
|
@@ -8356,10 +8141,10 @@ var launchNode = async ({
|
|
8356
8141
|
["--ip", ipToUse],
|
8357
8142
|
["--port", portToUse],
|
8358
8143
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8359
|
-
["--min-gas-price", "
|
8144
|
+
["--min-gas-price", "0"],
|
8360
8145
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8361
8146
|
["--consensus-key", consensusKey],
|
8362
|
-
["--
|
8147
|
+
["--chain", chainConfigPathToUse],
|
8363
8148
|
"--vm-backtrace",
|
8364
8149
|
"--utxo-validation",
|
8365
8150
|
"--debug",
|
@@ -8406,9 +8191,10 @@ var launchNode = async ({
|
|
8406
8191
|
})
|
8407
8192
|
);
|
8408
8193
|
var generateWallets = async (count, provider) => {
|
8194
|
+
const baseAssetId = provider.getBaseAssetId();
|
8409
8195
|
const wallets = [];
|
8410
8196
|
for (let i = 0; i < count; i += 1) {
|
8411
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8197
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8412
8198
|
wallets.push(wallet);
|
8413
8199
|
}
|
8414
8200
|
return wallets;
|
@@ -8418,7 +8204,7 @@ var launchNodeAndGetWallets = async ({
|
|
8418
8204
|
walletCount = 10
|
8419
8205
|
} = {}) => {
|
8420
8206
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8421
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8207
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8422
8208
|
const wallets = await generateWallets(walletCount, provider);
|
8423
8209
|
const cleanup = () => {
|
8424
8210
|
closeNode();
|