@fuel-ts/account 0.0.0-rc-2021-20240418170033 → 0.0.0-rc-2037-20240418195040
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 +596 -797
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +633 -825
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +451 -648
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +18 -11
- 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 +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +1 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -6
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +27 -37
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +10 -0
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
- package/dist/providers/transaction-request/index.d.ts +1 -0
- package/dist/providers/transaction-request/index.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +7 -6
- 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/index.d.ts +1 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/resources.d.ts +4 -0
- package/dist/test-utils/resources.d.ts.map +1 -0
- package/dist/test-utils/seedTestWallet.d.ts +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils/transactionRequest.d.ts +5 -0
- package/dist/test-utils/transactionRequest.d.ts.map +1 -0
- package/dist/test-utils.global.js +1085 -1547
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +608 -804
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +442 -641
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -48,6 +48,9 @@ var __privateMethod = (obj, member, method) => {
|
|
48
48
|
// src/test-utils/index.ts
|
49
49
|
var test_utils_exports = {};
|
50
50
|
__export(test_utils_exports, {
|
51
|
+
generateFakeRequestInputCoin: () => generateFakeRequestInputCoin,
|
52
|
+
generateFakeRequestInputContract: () => generateFakeRequestInputContract,
|
53
|
+
generateFakeRequestInputMessage: () => generateFakeRequestInputMessage,
|
51
54
|
generateTestWallet: () => generateTestWallet,
|
52
55
|
killNode: () => killNode,
|
53
56
|
launchNode: () => launchNode,
|
@@ -58,16 +61,15 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
61
|
|
59
62
|
// src/wallet/base-wallet-unlocked.ts
|
60
63
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
64
|
+
var import_utils31 = require("@fuel-ts/utils");
|
62
65
|
|
63
66
|
// src/account.ts
|
64
67
|
var import_address4 = require("@fuel-ts/address");
|
65
68
|
var import_configs12 = require("@fuel-ts/address/configs");
|
66
69
|
var import_errors16 = require("@fuel-ts/errors");
|
67
70
|
var import_interfaces = require("@fuel-ts/interfaces");
|
68
|
-
var
|
69
|
-
var
|
70
|
-
var import_ramda4 = require("ramda");
|
71
|
+
var import_math18 = require("@fuel-ts/math");
|
72
|
+
var import_utils28 = require("@fuel-ts/utils");
|
71
73
|
|
72
74
|
// src/providers/coin-quantity.ts
|
73
75
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -76,24 +78,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
76
78
|
var coinQuantityfy = (coinQuantityLike) => {
|
77
79
|
let assetId;
|
78
80
|
let amount;
|
79
|
-
let
|
81
|
+
let max2;
|
80
82
|
if (Array.isArray(coinQuantityLike)) {
|
81
83
|
amount = coinQuantityLike[0];
|
82
84
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
83
|
-
|
85
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
84
86
|
} else {
|
85
87
|
amount = coinQuantityLike.amount;
|
86
88
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
87
|
-
|
89
|
+
max2 = coinQuantityLike.max ?? void 0;
|
88
90
|
}
|
89
91
|
const bnAmount = (0, import_math.bn)(amount);
|
90
92
|
return {
|
91
93
|
assetId: (0, import_utils.hexlify)(assetId),
|
92
94
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
93
|
-
max:
|
95
|
+
max: max2 ? (0, import_math.bn)(max2) : void 0
|
94
96
|
};
|
95
97
|
};
|
96
|
-
var
|
98
|
+
var addAmountToAsset = (params) => {
|
97
99
|
const { amount, assetId } = params;
|
98
100
|
const coinQuantities = [...params.coinQuantities];
|
99
101
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -108,11 +110,11 @@ var addAmountToCoinQuantities = (params) => {
|
|
108
110
|
// src/providers/provider.ts
|
109
111
|
var import_address3 = require("@fuel-ts/address");
|
110
112
|
var import_errors14 = require("@fuel-ts/errors");
|
111
|
-
var
|
113
|
+
var import_math15 = require("@fuel-ts/math");
|
112
114
|
var import_transactions19 = require("@fuel-ts/transactions");
|
113
|
-
var
|
115
|
+
var import_utils23 = require("@fuel-ts/utils");
|
114
116
|
var import_versions = require("@fuel-ts/versions");
|
115
|
-
var
|
117
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
116
118
|
var import_ethers = require("ethers");
|
117
119
|
var import_graphql_request = require("graphql-request");
|
118
120
|
var import_ramda3 = require("ramda");
|
@@ -121,10 +123,14 @@ var import_ramda3 = require("ramda");
|
|
121
123
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
122
124
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
123
125
|
fragment receiptFragment on Receipt {
|
124
|
-
|
126
|
+
contract {
|
127
|
+
id
|
128
|
+
}
|
125
129
|
pc
|
126
130
|
is
|
127
|
-
to
|
131
|
+
to {
|
132
|
+
id
|
133
|
+
}
|
128
134
|
toAddress
|
129
135
|
amount
|
130
136
|
assetId
|
@@ -162,16 +168,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
162
168
|
id
|
163
169
|
}
|
164
170
|
time
|
165
|
-
receipts {
|
166
|
-
...receiptFragment
|
167
|
-
}
|
168
171
|
programState {
|
169
172
|
returnType
|
170
173
|
data
|
171
174
|
}
|
172
|
-
receipts {
|
173
|
-
...receiptFragment
|
174
|
-
}
|
175
175
|
}
|
176
176
|
... on FailureStatus {
|
177
177
|
block {
|
@@ -179,24 +179,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
179
179
|
}
|
180
180
|
time
|
181
181
|
reason
|
182
|
-
receipts {
|
183
|
-
...receiptFragment
|
184
|
-
}
|
185
182
|
}
|
186
183
|
... on SqueezedOutStatus {
|
187
184
|
reason
|
188
185
|
}
|
189
186
|
}
|
190
|
-
|
187
|
+
`;
|
191
188
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
192
189
|
fragment transactionFragment on Transaction {
|
193
190
|
id
|
194
191
|
rawPayload
|
192
|
+
gasPrice
|
193
|
+
receipts {
|
194
|
+
...receiptFragment
|
195
|
+
}
|
195
196
|
status {
|
196
197
|
...transactionStatusFragment
|
197
198
|
}
|
198
199
|
}
|
199
|
-
${
|
200
|
+
${ReceiptFragmentFragmentDoc}
|
201
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
200
202
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
201
203
|
fragment inputEstimatePredicatesFragment on Input {
|
202
204
|
... on InputCoin {
|
@@ -214,46 +216,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
214
216
|
}
|
215
217
|
}
|
216
218
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
217
|
-
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
218
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
219
|
-
reason
|
220
|
-
programState {
|
221
|
-
returnType
|
222
|
-
data
|
223
|
-
}
|
224
|
-
}
|
225
|
-
`;
|
226
|
-
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
227
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
228
|
-
programState {
|
229
|
-
returnType
|
230
|
-
data
|
231
|
-
}
|
232
|
-
}
|
233
|
-
`;
|
234
|
-
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
235
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
236
|
-
... on DryRunFailureStatus {
|
237
|
-
...dryRunFailureStatusFragment
|
238
|
-
}
|
239
|
-
... on DryRunSuccessStatus {
|
240
|
-
...dryRunSuccessStatusFragment
|
241
|
-
}
|
242
|
-
}
|
243
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
244
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
245
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
246
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
247
|
-
id
|
248
|
-
status {
|
249
|
-
...dryRunTransactionStatusFragment
|
250
|
-
}
|
251
|
-
receipts {
|
252
|
-
...receiptFragment
|
253
|
-
}
|
254
|
-
}
|
255
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
256
|
-
${ReceiptFragmentFragmentDoc}`;
|
257
219
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
258
220
|
fragment coinFragment on Coin {
|
259
221
|
__typename
|
@@ -261,6 +223,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
261
223
|
owner
|
262
224
|
amount
|
263
225
|
assetId
|
226
|
+
maturity
|
264
227
|
blockCreated
|
265
228
|
txCreatedIdx
|
266
229
|
}
|
@@ -299,32 +262,26 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
299
262
|
messageBlockHeader {
|
300
263
|
id
|
301
264
|
daHeight
|
302
|
-
consensusParametersVersion
|
303
|
-
stateTransitionBytecodeVersion
|
304
265
|
transactionsCount
|
305
|
-
messageReceiptCount
|
306
266
|
transactionsRoot
|
307
|
-
messageOutboxRoot
|
308
|
-
eventInboxRoot
|
309
267
|
height
|
310
268
|
prevRoot
|
311
269
|
time
|
312
270
|
applicationHash
|
271
|
+
messageReceiptRoot
|
272
|
+
messageReceiptCount
|
313
273
|
}
|
314
274
|
commitBlockHeader {
|
315
275
|
id
|
316
276
|
daHeight
|
317
|
-
consensusParametersVersion
|
318
|
-
stateTransitionBytecodeVersion
|
319
277
|
transactionsCount
|
320
|
-
messageReceiptCount
|
321
278
|
transactionsRoot
|
322
|
-
messageOutboxRoot
|
323
|
-
eventInboxRoot
|
324
279
|
height
|
325
280
|
prevRoot
|
326
281
|
time
|
327
282
|
applicationHash
|
283
|
+
messageReceiptRoot
|
284
|
+
messageReceiptCount
|
328
285
|
}
|
329
286
|
sender
|
330
287
|
recipient
|
@@ -343,8 +300,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
343
300
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
344
301
|
fragment blockFragment on Block {
|
345
302
|
id
|
346
|
-
height
|
347
303
|
header {
|
304
|
+
height
|
348
305
|
time
|
349
306
|
}
|
350
307
|
transactions {
|
@@ -402,11 +359,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
402
359
|
`;
|
403
360
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
404
361
|
fragment GasCostsFragment on GasCosts {
|
405
|
-
version {
|
406
|
-
... on Version {
|
407
|
-
value
|
408
|
-
}
|
409
|
-
}
|
410
362
|
add
|
411
363
|
addi
|
412
364
|
aloc
|
@@ -419,6 +371,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
419
371
|
cb
|
420
372
|
cfei
|
421
373
|
cfsi
|
374
|
+
croo
|
422
375
|
div
|
423
376
|
divi
|
424
377
|
ecr1
|
@@ -501,9 +454,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
501
454
|
ccp {
|
502
455
|
...DependentCostFragment
|
503
456
|
}
|
504
|
-
croo {
|
505
|
-
...DependentCostFragment
|
506
|
-
}
|
507
457
|
csiz {
|
508
458
|
...DependentCostFragment
|
509
459
|
}
|
@@ -563,11 +513,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
563
513
|
${DependentCostFragmentFragmentDoc}`;
|
564
514
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
565
515
|
fragment consensusParametersFragment on ConsensusParameters {
|
566
|
-
version {
|
567
|
-
... on Version {
|
568
|
-
value
|
569
|
-
}
|
570
|
-
}
|
571
516
|
txParams {
|
572
517
|
...TxParametersFragment
|
573
518
|
}
|
@@ -627,9 +572,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
627
572
|
fragment nodeInfoFragment on NodeInfo {
|
628
573
|
utxoValidation
|
629
574
|
vmBacktrace
|
575
|
+
minGasPrice
|
630
576
|
maxTx
|
631
577
|
maxDepth
|
632
578
|
nodeVersion
|
579
|
+
peers {
|
580
|
+
id
|
581
|
+
addresses
|
582
|
+
clientVersion
|
583
|
+
blockHeight
|
584
|
+
lastHeartbeatMs
|
585
|
+
appScore
|
586
|
+
}
|
633
587
|
}
|
634
588
|
`;
|
635
589
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -664,9 +618,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
664
618
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
665
619
|
transaction(id: $transactionId) {
|
666
620
|
...transactionFragment
|
621
|
+
receipts {
|
622
|
+
...receiptFragment
|
623
|
+
}
|
667
624
|
}
|
668
625
|
}
|
669
|
-
${TransactionFragmentFragmentDoc}
|
626
|
+
${TransactionFragmentFragmentDoc}
|
627
|
+
${ReceiptFragmentFragmentDoc}`;
|
670
628
|
var GetTransactionsDocument = import_graphql_tag.default`
|
671
629
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
672
630
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -794,20 +752,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
794
752
|
}
|
795
753
|
}
|
796
754
|
${BalanceFragmentFragmentDoc}`;
|
797
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
798
|
-
query getLatestGasPrice {
|
799
|
-
latestGasPrice {
|
800
|
-
gasPrice
|
801
|
-
}
|
802
|
-
}
|
803
|
-
`;
|
804
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
805
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
806
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
807
|
-
gasPrice
|
808
|
-
}
|
809
|
-
}
|
810
|
-
`;
|
811
755
|
var GetBalancesDocument = import_graphql_tag.default`
|
812
756
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
813
757
|
balances(
|
@@ -862,12 +806,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
862
806
|
}
|
863
807
|
`;
|
864
808
|
var DryRunDocument = import_graphql_tag.default`
|
865
|
-
mutation dryRun($
|
866
|
-
dryRun(
|
867
|
-
...
|
809
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
810
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
811
|
+
...receiptFragment
|
868
812
|
}
|
869
813
|
}
|
870
|
-
${
|
814
|
+
${ReceiptFragmentFragmentDoc}`;
|
871
815
|
var SubmitDocument = import_graphql_tag.default`
|
872
816
|
mutation submit($encodedTransaction: HexString!) {
|
873
817
|
submit(tx: $encodedTransaction) {
|
@@ -950,12 +894,6 @@ function getSdk(requester) {
|
|
950
894
|
getBalance(variables, options) {
|
951
895
|
return requester(GetBalanceDocument, variables, options);
|
952
896
|
},
|
953
|
-
getLatestGasPrice(variables, options) {
|
954
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
955
|
-
},
|
956
|
-
estimateGasPrice(variables, options) {
|
957
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
958
|
-
},
|
959
897
|
getBalances(variables, options) {
|
960
898
|
return requester(GetBalancesDocument, variables, options);
|
961
899
|
},
|
@@ -1149,9 +1087,10 @@ var inputify = (value) => {
|
|
1149
1087
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1150
1088
|
},
|
1151
1089
|
witnessIndex: value.witnessIndex,
|
1090
|
+
maturity: value.maturity ?? 0,
|
1152
1091
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1153
|
-
predicateLength:
|
1154
|
-
predicateDataLength:
|
1092
|
+
predicateLength: predicate.length,
|
1093
|
+
predicateDataLength: predicateData.length,
|
1155
1094
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1156
1095
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1157
1096
|
};
|
@@ -1182,8 +1121,8 @@ var inputify = (value) => {
|
|
1182
1121
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1183
1122
|
witnessIndex: value.witnessIndex,
|
1184
1123
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1185
|
-
predicateLength:
|
1186
|
-
predicateDataLength:
|
1124
|
+
predicateLength: predicate.length,
|
1125
|
+
predicateDataLength: predicateData.length,
|
1187
1126
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1188
1127
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1189
1128
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1262,7 +1201,7 @@ var import_address = require("@fuel-ts/address");
|
|
1262
1201
|
var import_configs7 = require("@fuel-ts/address/configs");
|
1263
1202
|
var import_crypto = require("@fuel-ts/crypto");
|
1264
1203
|
var import_math7 = require("@fuel-ts/math");
|
1265
|
-
var
|
1204
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
1266
1205
|
var import_utils9 = require("@fuel-ts/utils");
|
1267
1206
|
|
1268
1207
|
// src/providers/resource.ts
|
@@ -1299,8 +1238,8 @@ function assembleReceiptByType(receipt) {
|
|
1299
1238
|
case "CALL" /* Call */: {
|
1300
1239
|
const callReceipt = {
|
1301
1240
|
type: import_transactions3.ReceiptType.Call,
|
1302
|
-
from: hexOrZero(receipt.id
|
1303
|
-
to: hexOrZero(receipt?.to),
|
1241
|
+
from: hexOrZero(receipt.contract?.id),
|
1242
|
+
to: hexOrZero(receipt?.to?.id),
|
1304
1243
|
amount: (0, import_math4.bn)(receipt.amount),
|
1305
1244
|
assetId: hexOrZero(receipt.assetId),
|
1306
1245
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1314,7 +1253,7 @@ function assembleReceiptByType(receipt) {
|
|
1314
1253
|
case "RETURN" /* Return */: {
|
1315
1254
|
const returnReceipt = {
|
1316
1255
|
type: import_transactions3.ReceiptType.Return,
|
1317
|
-
id: hexOrZero(receipt.id
|
1256
|
+
id: hexOrZero(receipt.contract?.id),
|
1318
1257
|
val: (0, import_math4.bn)(receipt.val),
|
1319
1258
|
pc: (0, import_math4.bn)(receipt.pc),
|
1320
1259
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1324,7 +1263,7 @@ function assembleReceiptByType(receipt) {
|
|
1324
1263
|
case "RETURN_DATA" /* ReturnData */: {
|
1325
1264
|
const returnDataReceipt = {
|
1326
1265
|
type: import_transactions3.ReceiptType.ReturnData,
|
1327
|
-
id: hexOrZero(receipt.id
|
1266
|
+
id: hexOrZero(receipt.contract?.id),
|
1328
1267
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1329
1268
|
len: (0, import_math4.bn)(receipt.len),
|
1330
1269
|
digest: hexOrZero(receipt.digest),
|
@@ -1336,7 +1275,7 @@ function assembleReceiptByType(receipt) {
|
|
1336
1275
|
case "PANIC" /* Panic */: {
|
1337
1276
|
const panicReceipt = {
|
1338
1277
|
type: import_transactions3.ReceiptType.Panic,
|
1339
|
-
id: hexOrZero(receipt.id),
|
1278
|
+
id: hexOrZero(receipt.contract?.id),
|
1340
1279
|
reason: (0, import_math4.bn)(receipt.reason),
|
1341
1280
|
pc: (0, import_math4.bn)(receipt.pc),
|
1342
1281
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1347,7 +1286,7 @@ function assembleReceiptByType(receipt) {
|
|
1347
1286
|
case "REVERT" /* Revert */: {
|
1348
1287
|
const revertReceipt = {
|
1349
1288
|
type: import_transactions3.ReceiptType.Revert,
|
1350
|
-
id: hexOrZero(receipt.id
|
1289
|
+
id: hexOrZero(receipt.contract?.id),
|
1351
1290
|
val: (0, import_math4.bn)(receipt.ra),
|
1352
1291
|
pc: (0, import_math4.bn)(receipt.pc),
|
1353
1292
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1357,7 +1296,7 @@ function assembleReceiptByType(receipt) {
|
|
1357
1296
|
case "LOG" /* Log */: {
|
1358
1297
|
const logReceipt = {
|
1359
1298
|
type: import_transactions3.ReceiptType.Log,
|
1360
|
-
id: hexOrZero(receipt.id
|
1299
|
+
id: hexOrZero(receipt.contract?.id),
|
1361
1300
|
val0: (0, import_math4.bn)(receipt.ra),
|
1362
1301
|
val1: (0, import_math4.bn)(receipt.rb),
|
1363
1302
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1370,7 +1309,7 @@ function assembleReceiptByType(receipt) {
|
|
1370
1309
|
case "LOG_DATA" /* LogData */: {
|
1371
1310
|
const logDataReceipt = {
|
1372
1311
|
type: import_transactions3.ReceiptType.LogData,
|
1373
|
-
id: hexOrZero(receipt.id
|
1312
|
+
id: hexOrZero(receipt.contract?.id),
|
1374
1313
|
val0: (0, import_math4.bn)(receipt.ra),
|
1375
1314
|
val1: (0, import_math4.bn)(receipt.rb),
|
1376
1315
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1384,8 +1323,8 @@ function assembleReceiptByType(receipt) {
|
|
1384
1323
|
case "TRANSFER" /* Transfer */: {
|
1385
1324
|
const transferReceipt = {
|
1386
1325
|
type: import_transactions3.ReceiptType.Transfer,
|
1387
|
-
from: hexOrZero(receipt.id
|
1388
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1326
|
+
from: hexOrZero(receipt.contract?.id),
|
1327
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1389
1328
|
amount: (0, import_math4.bn)(receipt.amount),
|
1390
1329
|
assetId: hexOrZero(receipt.assetId),
|
1391
1330
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1396,8 +1335,8 @@ function assembleReceiptByType(receipt) {
|
|
1396
1335
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1397
1336
|
const transferOutReceipt = {
|
1398
1337
|
type: import_transactions3.ReceiptType.TransferOut,
|
1399
|
-
from: hexOrZero(receipt.id
|
1400
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1338
|
+
from: hexOrZero(receipt.contract?.id),
|
1339
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1401
1340
|
amount: (0, import_math4.bn)(receipt.amount),
|
1402
1341
|
assetId: hexOrZero(receipt.assetId),
|
1403
1342
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1440,7 +1379,7 @@ function assembleReceiptByType(receipt) {
|
|
1440
1379
|
return receiptMessageOut;
|
1441
1380
|
}
|
1442
1381
|
case "MINT" /* Mint */: {
|
1443
|
-
const contractId = hexOrZero(receipt.id
|
1382
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1444
1383
|
const subId = hexOrZero(receipt.subId);
|
1445
1384
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1446
1385
|
const mintReceipt = {
|
@@ -1455,7 +1394,7 @@ function assembleReceiptByType(receipt) {
|
|
1455
1394
|
return mintReceipt;
|
1456
1395
|
}
|
1457
1396
|
case "BURN" /* Burn */: {
|
1458
|
-
const contractId = hexOrZero(receipt.id
|
1397
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1459
1398
|
const subId = hexOrZero(receipt.subId);
|
1460
1399
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1461
1400
|
const burnReceipt = {
|
@@ -1481,6 +1420,7 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1481
1420
|
var import_math5 = require("@fuel-ts/math");
|
1482
1421
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1483
1422
|
var import_utils6 = require("@fuel-ts/utils");
|
1423
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1484
1424
|
var getGasUsedFromReceipts = (receipts) => {
|
1485
1425
|
const scriptResult = receipts.filter(
|
1486
1426
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1501,28 +1441,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1501
1441
|
}
|
1502
1442
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1503
1443
|
const witnessCache = [];
|
1504
|
-
const
|
1505
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1506
|
-
if (isCoinOrMessage) {
|
1507
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1508
|
-
return true;
|
1509
|
-
}
|
1510
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1511
|
-
witnessCache.push(input.witnessIndex);
|
1512
|
-
return true;
|
1513
|
-
}
|
1514
|
-
}
|
1515
|
-
return false;
|
1516
|
-
});
|
1517
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1518
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1444
|
+
const totalGas = inputs.reduce((total, input) => {
|
1519
1445
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1520
1446
|
return total.add(
|
1521
|
-
|
1447
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1522
1448
|
);
|
1523
1449
|
}
|
1524
|
-
|
1525
|
-
|
1450
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1451
|
+
witnessCache.push(input.witnessIndex);
|
1452
|
+
return total.add(gasCosts.ecr1);
|
1453
|
+
}
|
1454
|
+
return total;
|
1455
|
+
}, (0, import_math5.bn)());
|
1526
1456
|
return totalGas;
|
1527
1457
|
}
|
1528
1458
|
function getMinGas(params) {
|
@@ -1534,20 +1464,12 @@ function getMinGas(params) {
|
|
1534
1464
|
return minGas;
|
1535
1465
|
}
|
1536
1466
|
function getMaxGas(params) {
|
1537
|
-
const {
|
1538
|
-
gasPerByte,
|
1539
|
-
witnessesLength,
|
1540
|
-
witnessLimit,
|
1541
|
-
minGas,
|
1542
|
-
gasLimit = (0, import_math5.bn)(0),
|
1543
|
-
maxGasPerTx
|
1544
|
-
} = params;
|
1467
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1545
1468
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1546
1469
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1547
1470
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1548
1471
|
}
|
1549
|
-
|
1550
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1472
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1551
1473
|
}
|
1552
1474
|
function calculateMetadataGasForTxCreate({
|
1553
1475
|
gasCosts,
|
@@ -1569,10 +1491,6 @@ function calculateMetadataGasForTxScript({
|
|
1569
1491
|
}) {
|
1570
1492
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1571
1493
|
}
|
1572
|
-
var calculateGasFee = (params) => {
|
1573
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1574
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1575
|
-
};
|
1576
1494
|
|
1577
1495
|
// src/providers/utils/json.ts
|
1578
1496
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1696,6 +1614,12 @@ var NoWitnessAtIndexError = class extends Error {
|
|
1696
1614
|
name = "NoWitnessAtIndexError";
|
1697
1615
|
};
|
1698
1616
|
|
1617
|
+
// src/providers/transaction-request/helpers.ts
|
1618
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1619
|
+
var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
|
1620
|
+
var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
|
1621
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1622
|
+
|
1699
1623
|
// src/providers/transaction-request/witness.ts
|
1700
1624
|
var import_utils8 = require("@fuel-ts/utils");
|
1701
1625
|
var witnessify = (value) => {
|
@@ -1709,7 +1633,7 @@ var witnessify = (value) => {
|
|
1709
1633
|
// src/providers/transaction-request/transaction-request.ts
|
1710
1634
|
var BaseTransactionRequest = class {
|
1711
1635
|
/** Gas price for transaction */
|
1712
|
-
|
1636
|
+
gasPrice;
|
1713
1637
|
/** Block until which tx cannot be included */
|
1714
1638
|
maturity;
|
1715
1639
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1728,7 +1652,7 @@ var BaseTransactionRequest = class {
|
|
1728
1652
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1729
1653
|
*/
|
1730
1654
|
constructor({
|
1731
|
-
|
1655
|
+
gasPrice,
|
1732
1656
|
maturity,
|
1733
1657
|
maxFee,
|
1734
1658
|
witnessLimit,
|
@@ -1736,7 +1660,7 @@ var BaseTransactionRequest = class {
|
|
1736
1660
|
outputs,
|
1737
1661
|
witnesses
|
1738
1662
|
} = {}) {
|
1739
|
-
this.
|
1663
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1740
1664
|
this.maturity = maturity ?? 0;
|
1741
1665
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1742
1666
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1747,21 +1671,21 @@ var BaseTransactionRequest = class {
|
|
1747
1671
|
static getPolicyMeta(req) {
|
1748
1672
|
let policyTypes = 0;
|
1749
1673
|
const policies = [];
|
1750
|
-
if (req.
|
1751
|
-
policyTypes +=
|
1752
|
-
policies.push({ data: req.
|
1674
|
+
if (req.gasPrice) {
|
1675
|
+
policyTypes += import_transactions7.PolicyType.GasPrice;
|
1676
|
+
policies.push({ data: req.gasPrice, type: import_transactions7.PolicyType.GasPrice });
|
1753
1677
|
}
|
1754
1678
|
if (req.witnessLimit) {
|
1755
|
-
policyTypes +=
|
1756
|
-
policies.push({ data: req.witnessLimit, type:
|
1679
|
+
policyTypes += import_transactions7.PolicyType.WitnessLimit;
|
1680
|
+
policies.push({ data: req.witnessLimit, type: import_transactions7.PolicyType.WitnessLimit });
|
1757
1681
|
}
|
1758
1682
|
if (req.maturity > 0) {
|
1759
|
-
policyTypes +=
|
1760
|
-
policies.push({ data: req.maturity, type:
|
1683
|
+
policyTypes += import_transactions7.PolicyType.Maturity;
|
1684
|
+
policies.push({ data: req.maturity, type: import_transactions7.PolicyType.Maturity });
|
1761
1685
|
}
|
1762
1686
|
if (req.maxFee) {
|
1763
|
-
policyTypes +=
|
1764
|
-
policies.push({ data: req.maxFee, type:
|
1687
|
+
policyTypes += import_transactions7.PolicyType.MaxFee;
|
1688
|
+
policies.push({ data: req.maxFee, type: import_transactions7.PolicyType.MaxFee });
|
1765
1689
|
}
|
1766
1690
|
return {
|
1767
1691
|
policyTypes,
|
@@ -1795,7 +1719,7 @@ var BaseTransactionRequest = class {
|
|
1795
1719
|
* @returns The transaction bytes.
|
1796
1720
|
*/
|
1797
1721
|
toTransactionBytes() {
|
1798
|
-
return new
|
1722
|
+
return new import_transactions7.TransactionCoder().encode(this.toTransaction());
|
1799
1723
|
}
|
1800
1724
|
/**
|
1801
1725
|
* @hidden
|
@@ -1886,7 +1810,7 @@ var BaseTransactionRequest = class {
|
|
1886
1810
|
*/
|
1887
1811
|
getCoinInputs() {
|
1888
1812
|
return this.inputs.filter(
|
1889
|
-
(input) => input.type ===
|
1813
|
+
(input) => input.type === import_transactions7.InputType.Coin
|
1890
1814
|
);
|
1891
1815
|
}
|
1892
1816
|
/**
|
@@ -1896,7 +1820,7 @@ var BaseTransactionRequest = class {
|
|
1896
1820
|
*/
|
1897
1821
|
getCoinOutputs() {
|
1898
1822
|
return this.outputs.filter(
|
1899
|
-
(output) => output.type ===
|
1823
|
+
(output) => output.type === import_transactions7.OutputType.Coin
|
1900
1824
|
);
|
1901
1825
|
}
|
1902
1826
|
/**
|
@@ -1906,7 +1830,7 @@ var BaseTransactionRequest = class {
|
|
1906
1830
|
*/
|
1907
1831
|
getChangeOutputs() {
|
1908
1832
|
return this.outputs.filter(
|
1909
|
-
(output) => output.type ===
|
1833
|
+
(output) => output.type === import_transactions7.OutputType.Change
|
1910
1834
|
);
|
1911
1835
|
}
|
1912
1836
|
/**
|
@@ -1918,9 +1842,9 @@ var BaseTransactionRequest = class {
|
|
1918
1842
|
const ownerAddress = (0, import_address.addressify)(owner);
|
1919
1843
|
const found = this.inputs.find((input) => {
|
1920
1844
|
switch (input.type) {
|
1921
|
-
case
|
1845
|
+
case import_transactions7.InputType.Coin:
|
1922
1846
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1923
|
-
case
|
1847
|
+
case import_transactions7.InputType.Message:
|
1924
1848
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1925
1849
|
default:
|
1926
1850
|
return false;
|
@@ -1937,9 +1861,9 @@ var BaseTransactionRequest = class {
|
|
1937
1861
|
* @param predicateData - Predicate data bytes.
|
1938
1862
|
*/
|
1939
1863
|
addCoinInput(coin) {
|
1940
|
-
const { assetId, owner, amount } = coin;
|
1864
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
1941
1865
|
let witnessIndex;
|
1942
|
-
if (
|
1866
|
+
if (predicate) {
|
1943
1867
|
witnessIndex = 0;
|
1944
1868
|
} else {
|
1945
1869
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1948,13 +1872,14 @@ var BaseTransactionRequest = class {
|
|
1948
1872
|
}
|
1949
1873
|
}
|
1950
1874
|
const input = {
|
1951
|
-
|
1952
|
-
type:
|
1875
|
+
id,
|
1876
|
+
type: import_transactions7.InputType.Coin,
|
1953
1877
|
owner: owner.toB256(),
|
1954
1878
|
amount,
|
1955
1879
|
assetId,
|
1956
1880
|
txPointer: "0x00000000000000000000000000000000",
|
1957
|
-
witnessIndex
|
1881
|
+
witnessIndex,
|
1882
|
+
predicate
|
1958
1883
|
};
|
1959
1884
|
this.pushInput(input);
|
1960
1885
|
this.addChangeOutput(owner, assetId);
|
@@ -1968,10 +1893,10 @@ var BaseTransactionRequest = class {
|
|
1968
1893
|
* @param predicateData - Predicate data bytes.
|
1969
1894
|
*/
|
1970
1895
|
addMessageInput(message) {
|
1971
|
-
const { recipient, sender, amount } = message;
|
1896
|
+
const { recipient, sender, amount, predicate, nonce } = message;
|
1972
1897
|
const assetId = import_configs7.BaseAssetId;
|
1973
1898
|
let witnessIndex;
|
1974
|
-
if (
|
1899
|
+
if (predicate) {
|
1975
1900
|
witnessIndex = 0;
|
1976
1901
|
} else {
|
1977
1902
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1980,12 +1905,13 @@ var BaseTransactionRequest = class {
|
|
1980
1905
|
}
|
1981
1906
|
}
|
1982
1907
|
const input = {
|
1983
|
-
|
1984
|
-
type:
|
1908
|
+
nonce,
|
1909
|
+
type: import_transactions7.InputType.Message,
|
1985
1910
|
sender: sender.toB256(),
|
1986
1911
|
recipient: recipient.toB256(),
|
1987
1912
|
amount,
|
1988
|
-
witnessIndex
|
1913
|
+
witnessIndex,
|
1914
|
+
predicate
|
1989
1915
|
};
|
1990
1916
|
this.pushInput(input);
|
1991
1917
|
this.addChangeOutput(recipient, assetId);
|
@@ -2025,7 +1951,7 @@ var BaseTransactionRequest = class {
|
|
2025
1951
|
*/
|
2026
1952
|
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
2027
1953
|
this.pushOutput({
|
2028
|
-
type:
|
1954
|
+
type: import_transactions7.OutputType.Coin,
|
2029
1955
|
to: (0, import_address.addressify)(to).toB256(),
|
2030
1956
|
amount,
|
2031
1957
|
assetId
|
@@ -2041,7 +1967,7 @@ var BaseTransactionRequest = class {
|
|
2041
1967
|
addCoinOutputs(to, quantities) {
|
2042
1968
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
2043
1969
|
this.pushOutput({
|
2044
|
-
type:
|
1970
|
+
type: import_transactions7.OutputType.Coin,
|
2045
1971
|
to: (0, import_address.addressify)(to).toB256(),
|
2046
1972
|
amount: quantity.amount,
|
2047
1973
|
assetId: quantity.assetId
|
@@ -2061,7 +1987,7 @@ var BaseTransactionRequest = class {
|
|
2061
1987
|
);
|
2062
1988
|
if (!changeOutput) {
|
2063
1989
|
this.pushOutput({
|
2064
|
-
type:
|
1990
|
+
type: import_transactions7.OutputType.Change,
|
2065
1991
|
to: (0, import_address.addressify)(to).toB256(),
|
2066
1992
|
assetId
|
2067
1993
|
});
|
@@ -2095,7 +2021,7 @@ var BaseTransactionRequest = class {
|
|
2095
2021
|
}
|
2096
2022
|
calculateMaxGas(chainInfo, minGas) {
|
2097
2023
|
const { consensusParameters } = chainInfo;
|
2098
|
-
const { gasPerByte
|
2024
|
+
const { gasPerByte } = consensusParameters;
|
2099
2025
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2100
2026
|
(acc, wit) => acc + wit.dataLength,
|
2101
2027
|
0
|
@@ -2104,8 +2030,7 @@ var BaseTransactionRequest = class {
|
|
2104
2030
|
gasPerByte,
|
2105
2031
|
minGas,
|
2106
2032
|
witnessesLength,
|
2107
|
-
witnessLimit: this.witnessLimit
|
2108
|
-
maxGasPerTx
|
2033
|
+
witnessLimit: this.witnessLimit
|
2109
2034
|
});
|
2110
2035
|
}
|
2111
2036
|
/**
|
@@ -2123,20 +2048,17 @@ var BaseTransactionRequest = class {
|
|
2123
2048
|
});
|
2124
2049
|
const updateAssetInput = (assetId, quantity) => {
|
2125
2050
|
const assetInput = findAssetInput(assetId);
|
2126
|
-
let usedQuantity = quantity;
|
2127
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2128
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2129
|
-
}
|
2130
2051
|
if (assetInput && "assetId" in assetInput) {
|
2131
2052
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2132
|
-
assetInput.amount =
|
2053
|
+
assetInput.amount = quantity;
|
2133
2054
|
} else {
|
2134
2055
|
this.addResources([
|
2135
2056
|
{
|
2136
2057
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2137
|
-
amount:
|
2058
|
+
amount: quantity,
|
2138
2059
|
assetId,
|
2139
2060
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2061
|
+
maturity: 0,
|
2140
2062
|
blockCreated: (0, import_math7.bn)(1),
|
2141
2063
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2142
2064
|
}
|
@@ -2168,16 +2090,20 @@ var BaseTransactionRequest = class {
|
|
2168
2090
|
toJSON() {
|
2169
2091
|
return normalizeJSON(this);
|
2170
2092
|
}
|
2171
|
-
|
2093
|
+
removeWitness(index) {
|
2094
|
+
this.witnesses.splice(index, 1);
|
2095
|
+
this.adjustWitnessIndexes(index);
|
2096
|
+
}
|
2097
|
+
updatePredicateInputs(inputs) {
|
2172
2098
|
this.inputs.forEach((i) => {
|
2173
2099
|
let correspondingInput;
|
2174
2100
|
switch (i.type) {
|
2175
|
-
case
|
2176
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2101
|
+
case import_transactions7.InputType.Coin:
|
2102
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions7.InputType.Coin && x.owner === i.owner);
|
2177
2103
|
break;
|
2178
|
-
case
|
2104
|
+
case import_transactions7.InputType.Message:
|
2179
2105
|
correspondingInput = inputs.find(
|
2180
|
-
(x) => x.type ===
|
2106
|
+
(x) => x.type === import_transactions7.InputType.Message && x.sender === i.sender
|
2181
2107
|
);
|
2182
2108
|
break;
|
2183
2109
|
default:
|
@@ -2190,12 +2116,10 @@ var BaseTransactionRequest = class {
|
|
2190
2116
|
}
|
2191
2117
|
});
|
2192
2118
|
}
|
2193
|
-
|
2194
|
-
this.inputs.forEach((input) => {
|
2195
|
-
if (
|
2196
|
-
input.
|
2197
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2198
|
-
);
|
2119
|
+
adjustWitnessIndexes(removedIndex) {
|
2120
|
+
this.inputs.filter(isRequestInputResource).forEach((input) => {
|
2121
|
+
if (input.witnessIndex > removedIndex) {
|
2122
|
+
input.witnessIndex -= 1;
|
2199
2123
|
}
|
2200
2124
|
});
|
2201
2125
|
}
|
@@ -2204,25 +2128,25 @@ var BaseTransactionRequest = class {
|
|
2204
2128
|
// src/providers/transaction-request/create-transaction-request.ts
|
2205
2129
|
var import_configs9 = require("@fuel-ts/address/configs");
|
2206
2130
|
var import_math9 = require("@fuel-ts/math");
|
2207
|
-
var
|
2131
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2208
2132
|
var import_utils13 = require("@fuel-ts/utils");
|
2209
2133
|
|
2210
2134
|
// src/providers/transaction-request/hash-transaction.ts
|
2211
2135
|
var import_configs8 = require("@fuel-ts/address/configs");
|
2212
2136
|
var import_hasher = require("@fuel-ts/hasher");
|
2213
2137
|
var import_math8 = require("@fuel-ts/math");
|
2214
|
-
var
|
2138
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2215
2139
|
var import_utils11 = require("@fuel-ts/utils");
|
2216
2140
|
var import_ramda2 = require("ramda");
|
2217
2141
|
function hashTransaction(transactionRequest, chainId) {
|
2218
2142
|
const transaction = transactionRequest.toTransaction();
|
2219
|
-
if (transaction.type ===
|
2143
|
+
if (transaction.type === import_transactions8.TransactionType.Script) {
|
2220
2144
|
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2221
2145
|
}
|
2222
2146
|
transaction.inputs = transaction.inputs.map((input) => {
|
2223
2147
|
const inputClone = (0, import_ramda2.clone)(input);
|
2224
2148
|
switch (inputClone.type) {
|
2225
|
-
case
|
2149
|
+
case import_transactions8.InputType.Coin: {
|
2226
2150
|
inputClone.txPointer = {
|
2227
2151
|
blockHeight: 0,
|
2228
2152
|
txIndex: 0
|
@@ -2230,11 +2154,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2230
2154
|
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2231
2155
|
return inputClone;
|
2232
2156
|
}
|
2233
|
-
case
|
2157
|
+
case import_transactions8.InputType.Message: {
|
2234
2158
|
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2235
2159
|
return inputClone;
|
2236
2160
|
}
|
2237
|
-
case
|
2161
|
+
case import_transactions8.InputType.Contract: {
|
2238
2162
|
inputClone.txPointer = {
|
2239
2163
|
blockHeight: 0,
|
2240
2164
|
txIndex: 0
|
@@ -2252,16 +2176,16 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2252
2176
|
transaction.outputs = transaction.outputs.map((output) => {
|
2253
2177
|
const outputClone = (0, import_ramda2.clone)(output);
|
2254
2178
|
switch (outputClone.type) {
|
2255
|
-
case
|
2179
|
+
case import_transactions8.OutputType.Contract: {
|
2256
2180
|
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2257
2181
|
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2258
2182
|
return outputClone;
|
2259
2183
|
}
|
2260
|
-
case
|
2184
|
+
case import_transactions8.OutputType.Change: {
|
2261
2185
|
outputClone.amount = (0, import_math8.bn)(0);
|
2262
2186
|
return outputClone;
|
2263
2187
|
}
|
2264
|
-
case
|
2188
|
+
case import_transactions8.OutputType.Variable: {
|
2265
2189
|
outputClone.to = import_configs8.ZeroBytes32;
|
2266
2190
|
outputClone.amount = (0, import_math8.bn)(0);
|
2267
2191
|
outputClone.assetId = import_configs8.ZeroBytes32;
|
@@ -2274,7 +2198,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2274
2198
|
transaction.witnessesCount = 0;
|
2275
2199
|
transaction.witnesses = [];
|
2276
2200
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2277
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2201
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions8.TransactionCoder().encode(transaction)]);
|
2278
2202
|
return (0, import_hasher.sha256)(concatenatedData);
|
2279
2203
|
}
|
2280
2204
|
|
@@ -2310,7 +2234,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2310
2234
|
return new this(obj);
|
2311
2235
|
}
|
2312
2236
|
/** Type of the transaction */
|
2313
|
-
type =
|
2237
|
+
type = import_transactions9.TransactionType.Create;
|
2314
2238
|
/** Witness index of contract bytecode to create */
|
2315
2239
|
bytecodeWitnessIndex;
|
2316
2240
|
/** Salt */
|
@@ -2343,10 +2267,11 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2343
2267
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2344
2268
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2345
2269
|
return {
|
2346
|
-
type:
|
2270
|
+
type: import_transactions9.TransactionType.Create,
|
2347
2271
|
...baseTransaction,
|
2272
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2348
2273
|
bytecodeWitnessIndex,
|
2349
|
-
storageSlotsCount:
|
2274
|
+
storageSlotsCount: storageSlots.length,
|
2350
2275
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2351
2276
|
storageSlots
|
2352
2277
|
};
|
@@ -2358,7 +2283,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2358
2283
|
*/
|
2359
2284
|
getContractCreatedOutputs() {
|
2360
2285
|
return this.outputs.filter(
|
2361
|
-
(output) => output.type ===
|
2286
|
+
(output) => output.type === import_transactions9.OutputType.ContractCreated
|
2362
2287
|
);
|
2363
2288
|
}
|
2364
2289
|
/**
|
@@ -2379,7 +2304,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2379
2304
|
*/
|
2380
2305
|
addContractCreatedOutput(contractId, stateRoot) {
|
2381
2306
|
this.pushOutput({
|
2382
|
-
type:
|
2307
|
+
type: import_transactions9.OutputType.ContractCreated,
|
2383
2308
|
contractId,
|
2384
2309
|
stateRoot
|
2385
2310
|
});
|
@@ -2399,7 +2324,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
2399
2324
|
var import_address2 = require("@fuel-ts/address");
|
2400
2325
|
var import_configs10 = require("@fuel-ts/address/configs");
|
2401
2326
|
var import_math10 = require("@fuel-ts/math");
|
2402
|
-
var
|
2327
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2403
2328
|
var import_utils15 = require("@fuel-ts/utils");
|
2404
2329
|
|
2405
2330
|
// src/providers/transaction-request/scripts.ts
|
@@ -2437,7 +2362,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2437
2362
|
return new this(obj);
|
2438
2363
|
}
|
2439
2364
|
/** Type of the transaction */
|
2440
|
-
type =
|
2365
|
+
type = import_transactions10.TransactionType.Script;
|
2441
2366
|
/** Gas limit for transaction */
|
2442
2367
|
gasLimit;
|
2443
2368
|
/** Script to execute */
|
@@ -2466,11 +2391,11 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2466
2391
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2467
2392
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2468
2393
|
return {
|
2469
|
-
type:
|
2394
|
+
type: import_transactions10.TransactionType.Script,
|
2470
2395
|
scriptGasLimit: this.gasLimit,
|
2471
2396
|
...super.getBaseTransaction(),
|
2472
|
-
scriptLength:
|
2473
|
-
scriptDataLength:
|
2397
|
+
scriptLength: script.length,
|
2398
|
+
scriptDataLength: scriptData.length,
|
2474
2399
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2475
2400
|
script: (0, import_utils15.hexlify)(script),
|
2476
2401
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2483,7 +2408,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2483
2408
|
*/
|
2484
2409
|
getContractInputs() {
|
2485
2410
|
return this.inputs.filter(
|
2486
|
-
(input) => input.type ===
|
2411
|
+
(input) => input.type === import_transactions10.InputType.Contract
|
2487
2412
|
);
|
2488
2413
|
}
|
2489
2414
|
/**
|
@@ -2493,7 +2418,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2493
2418
|
*/
|
2494
2419
|
getContractOutputs() {
|
2495
2420
|
return this.outputs.filter(
|
2496
|
-
(output) => output.type ===
|
2421
|
+
(output) => output.type === import_transactions10.OutputType.Contract
|
2497
2422
|
);
|
2498
2423
|
}
|
2499
2424
|
/**
|
@@ -2503,7 +2428,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2503
2428
|
*/
|
2504
2429
|
getVariableOutputs() {
|
2505
2430
|
return this.outputs.filter(
|
2506
|
-
(output) => output.type ===
|
2431
|
+
(output) => output.type === import_transactions10.OutputType.Variable
|
2507
2432
|
);
|
2508
2433
|
}
|
2509
2434
|
/**
|
@@ -2526,7 +2451,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2526
2451
|
let outputsNumber = numberOfVariables;
|
2527
2452
|
while (outputsNumber) {
|
2528
2453
|
this.pushOutput({
|
2529
|
-
type:
|
2454
|
+
type: import_transactions10.OutputType.Variable
|
2530
2455
|
});
|
2531
2456
|
outputsNumber -= 1;
|
2532
2457
|
}
|
@@ -2534,7 +2459,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2534
2459
|
}
|
2535
2460
|
calculateMaxGas(chainInfo, minGas) {
|
2536
2461
|
const { consensusParameters } = chainInfo;
|
2537
|
-
const { gasPerByte
|
2462
|
+
const { gasPerByte } = consensusParameters;
|
2538
2463
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2539
2464
|
(acc, wit) => acc + wit.dataLength,
|
2540
2465
|
0
|
@@ -2544,8 +2469,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2544
2469
|
minGas,
|
2545
2470
|
witnessesLength,
|
2546
2471
|
witnessLimit: this.witnessLimit,
|
2547
|
-
gasLimit: this.gasLimit
|
2548
|
-
maxGasPerTx
|
2472
|
+
gasLimit: this.gasLimit
|
2549
2473
|
});
|
2550
2474
|
}
|
2551
2475
|
/**
|
@@ -2560,12 +2484,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2560
2484
|
return this;
|
2561
2485
|
}
|
2562
2486
|
const inputIndex = super.pushInput({
|
2563
|
-
type:
|
2487
|
+
type: import_transactions10.InputType.Contract,
|
2564
2488
|
contractId: contractAddress.toB256(),
|
2565
2489
|
txPointer: "0x00000000000000000000000000000000"
|
2566
2490
|
});
|
2567
2491
|
this.pushOutput({
|
2568
|
-
type:
|
2492
|
+
type: import_transactions10.OutputType.Contract,
|
2569
2493
|
inputIndex
|
2570
2494
|
});
|
2571
2495
|
return this;
|
@@ -2602,17 +2526,17 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2602
2526
|
|
2603
2527
|
// src/providers/transaction-request/utils.ts
|
2604
2528
|
var import_errors9 = require("@fuel-ts/errors");
|
2605
|
-
var
|
2529
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2606
2530
|
var transactionRequestify = (obj) => {
|
2607
2531
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2608
2532
|
return obj;
|
2609
2533
|
}
|
2610
2534
|
const { type } = obj;
|
2611
2535
|
switch (obj.type) {
|
2612
|
-
case
|
2536
|
+
case import_transactions11.TransactionType.Script: {
|
2613
2537
|
return ScriptTransactionRequest.from(obj);
|
2614
2538
|
}
|
2615
|
-
case
|
2539
|
+
case import_transactions11.TransactionType.Create: {
|
2616
2540
|
return CreateTransactionRequest.from(obj);
|
2617
2541
|
}
|
2618
2542
|
default: {
|
@@ -2620,59 +2544,42 @@ var transactionRequestify = (obj) => {
|
|
2620
2544
|
}
|
2621
2545
|
}
|
2622
2546
|
};
|
2623
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2624
|
-
(acc, input) => {
|
2625
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2626
|
-
acc.utxos.push(input.id);
|
2627
|
-
}
|
2628
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2629
|
-
acc.messages.push(input.nonce);
|
2630
|
-
}
|
2631
|
-
return acc;
|
2632
|
-
},
|
2633
|
-
{
|
2634
|
-
utxos: [],
|
2635
|
-
messages: []
|
2636
|
-
}
|
2637
|
-
);
|
2638
2547
|
|
2639
2548
|
// src/providers/transaction-response/transaction-response.ts
|
2640
2549
|
var import_errors13 = require("@fuel-ts/errors");
|
2641
|
-
var
|
2550
|
+
var import_math14 = require("@fuel-ts/math");
|
2642
2551
|
var import_transactions18 = require("@fuel-ts/transactions");
|
2643
|
-
var
|
2552
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2644
2553
|
|
2645
2554
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2646
|
-
var
|
2647
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2648
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2555
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2649
2556
|
|
2650
2557
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2651
2558
|
var import_math11 = require("@fuel-ts/math");
|
2652
|
-
var
|
2559
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2653
2560
|
var import_utils16 = require("@fuel-ts/utils");
|
2654
2561
|
var calculateTransactionFee = (params) => {
|
2655
2562
|
const {
|
2656
|
-
|
2563
|
+
gasUsed,
|
2657
2564
|
rawPayload,
|
2658
|
-
|
2659
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2565
|
+
consensusParameters: { gasCosts, feeParams }
|
2660
2566
|
} = params;
|
2661
2567
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2662
2568
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
2663
2569
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2664
|
-
const [transaction] = new
|
2665
|
-
if (transaction.type ===
|
2570
|
+
const [transaction] = new import_transactions12.TransactionCoder().decode(transactionBytes, 0);
|
2571
|
+
if (transaction.type === import_transactions12.TransactionType.Mint) {
|
2666
2572
|
return {
|
2667
2573
|
fee: (0, import_math11.bn)(0),
|
2668
2574
|
minFee: (0, import_math11.bn)(0),
|
2669
|
-
maxFee: (0, import_math11.bn)(0)
|
2575
|
+
maxFee: (0, import_math11.bn)(0),
|
2576
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2670
2577
|
};
|
2671
2578
|
}
|
2672
2579
|
const { type, witnesses, inputs, policies } = transaction;
|
2673
2580
|
let metadataGas = (0, import_math11.bn)(0);
|
2674
2581
|
let gasLimit = (0, import_math11.bn)(0);
|
2675
|
-
if (type ===
|
2582
|
+
if (type === import_transactions12.TransactionType.Create) {
|
2676
2583
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2677
2584
|
const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2678
2585
|
metadataGas = calculateMetadataGasForTxCreate({
|
@@ -2698,32 +2605,25 @@ var calculateTransactionFee = (params) => {
|
|
2698
2605
|
metadataGas,
|
2699
2606
|
txBytesSize: transactionBytes.length
|
2700
2607
|
});
|
2701
|
-
const
|
2608
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions12.PolicyType.GasPrice)?.data);
|
2609
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions12.PolicyType.WitnessLimit)?.data;
|
2702
2610
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2703
2611
|
const maxGas = getMaxGas({
|
2704
2612
|
gasPerByte,
|
2705
2613
|
minGas,
|
2706
2614
|
witnessesLength,
|
2707
2615
|
gasLimit,
|
2708
|
-
witnessLimit
|
2709
|
-
maxGasPerTx
|
2710
|
-
});
|
2711
|
-
const minFee = calculateGasFee({
|
2712
|
-
gasPrice,
|
2713
|
-
gas: minGas,
|
2714
|
-
priceFactor: gasPriceFactor,
|
2715
|
-
tip
|
2716
|
-
});
|
2717
|
-
const maxFee = calculateGasFee({
|
2718
|
-
gasPrice,
|
2719
|
-
gas: maxGas,
|
2720
|
-
priceFactor: gasPriceFactor,
|
2721
|
-
tip
|
2616
|
+
witnessLimit
|
2722
2617
|
});
|
2618
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2619
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2620
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2621
|
+
const fee = minFee.add(feeFromGasUsed);
|
2723
2622
|
return {
|
2623
|
+
fee,
|
2724
2624
|
minFee,
|
2725
2625
|
maxFee,
|
2726
|
-
|
2626
|
+
feeFromGasUsed
|
2727
2627
|
};
|
2728
2628
|
};
|
2729
2629
|
|
@@ -2731,7 +2631,7 @@ var calculateTransactionFee = (params) => {
|
|
2731
2631
|
var import_configs11 = require("@fuel-ts/address/configs");
|
2732
2632
|
var import_errors11 = require("@fuel-ts/errors");
|
2733
2633
|
var import_math13 = require("@fuel-ts/math");
|
2734
|
-
var
|
2634
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
2735
2635
|
|
2736
2636
|
// src/providers/transaction-summary/call.ts
|
2737
2637
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
@@ -2779,7 +2679,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2779
2679
|
|
2780
2680
|
// src/providers/transaction-summary/input.ts
|
2781
2681
|
var import_errors10 = require("@fuel-ts/errors");
|
2782
|
-
var
|
2682
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2783
2683
|
function getInputsByTypes(inputs, types) {
|
2784
2684
|
return inputs.filter((i) => types.includes(i.type));
|
2785
2685
|
}
|
@@ -2787,16 +2687,16 @@ function getInputsByType(inputs, type) {
|
|
2787
2687
|
return inputs.filter((i) => i.type === type);
|
2788
2688
|
}
|
2789
2689
|
function getInputsCoin(inputs) {
|
2790
|
-
return getInputsByType(inputs,
|
2690
|
+
return getInputsByType(inputs, import_transactions13.InputType.Coin);
|
2791
2691
|
}
|
2792
2692
|
function getInputsMessage(inputs) {
|
2793
|
-
return getInputsByType(inputs,
|
2693
|
+
return getInputsByType(inputs, import_transactions13.InputType.Message);
|
2794
2694
|
}
|
2795
2695
|
function getInputsCoinAndMessage(inputs) {
|
2796
|
-
return getInputsByTypes(inputs, [
|
2696
|
+
return getInputsByTypes(inputs, [import_transactions13.InputType.Coin, import_transactions13.InputType.Message]);
|
2797
2697
|
}
|
2798
2698
|
function getInputsContract(inputs) {
|
2799
|
-
return getInputsByType(inputs,
|
2699
|
+
return getInputsByType(inputs, import_transactions13.InputType.Contract);
|
2800
2700
|
}
|
2801
2701
|
function getInputFromAssetId(inputs, assetId) {
|
2802
2702
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2815,7 +2715,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2815
2715
|
if (!contractInput) {
|
2816
2716
|
return void 0;
|
2817
2717
|
}
|
2818
|
-
if (contractInput.type !==
|
2718
|
+
if (contractInput.type !== import_transactions13.InputType.Contract) {
|
2819
2719
|
throw new import_errors10.FuelError(
|
2820
2720
|
import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2821
2721
|
`Contract input should be of type 'contract'.`
|
@@ -2824,31 +2724,31 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2824
2724
|
return contractInput;
|
2825
2725
|
}
|
2826
2726
|
function getInputAccountAddress(input) {
|
2827
|
-
if (input.type ===
|
2727
|
+
if (input.type === import_transactions13.InputType.Coin) {
|
2828
2728
|
return input.owner.toString();
|
2829
2729
|
}
|
2830
|
-
if (input.type ===
|
2730
|
+
if (input.type === import_transactions13.InputType.Message) {
|
2831
2731
|
return input.recipient.toString();
|
2832
2732
|
}
|
2833
2733
|
return "";
|
2834
2734
|
}
|
2835
2735
|
|
2836
2736
|
// src/providers/transaction-summary/output.ts
|
2837
|
-
var
|
2737
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
2838
2738
|
function getOutputsByType(outputs, type) {
|
2839
2739
|
return outputs.filter((o) => o.type === type);
|
2840
2740
|
}
|
2841
2741
|
function getOutputsContractCreated(outputs) {
|
2842
|
-
return getOutputsByType(outputs,
|
2742
|
+
return getOutputsByType(outputs, import_transactions14.OutputType.ContractCreated);
|
2843
2743
|
}
|
2844
2744
|
function getOutputsCoin(outputs) {
|
2845
|
-
return getOutputsByType(outputs,
|
2745
|
+
return getOutputsByType(outputs, import_transactions14.OutputType.Coin);
|
2846
2746
|
}
|
2847
2747
|
function getOutputsChange(outputs) {
|
2848
|
-
return getOutputsByType(outputs,
|
2748
|
+
return getOutputsByType(outputs, import_transactions14.OutputType.Change);
|
2849
2749
|
}
|
2850
2750
|
function getOutputsContract(outputs) {
|
2851
|
-
return getOutputsByType(outputs,
|
2751
|
+
return getOutputsByType(outputs, import_transactions14.OutputType.Contract);
|
2852
2752
|
}
|
2853
2753
|
|
2854
2754
|
// src/providers/transaction-summary/operations.ts
|
@@ -2857,11 +2757,11 @@ function getReceiptsByType(receipts, type) {
|
|
2857
2757
|
}
|
2858
2758
|
function getTransactionTypeName(transactionType) {
|
2859
2759
|
switch (transactionType) {
|
2860
|
-
case
|
2760
|
+
case import_transactions15.TransactionType.Mint:
|
2861
2761
|
return "Mint" /* Mint */;
|
2862
|
-
case
|
2762
|
+
case import_transactions15.TransactionType.Create:
|
2863
2763
|
return "Create" /* Create */;
|
2864
|
-
case
|
2764
|
+
case import_transactions15.TransactionType.Script:
|
2865
2765
|
return "Script" /* Script */;
|
2866
2766
|
default:
|
2867
2767
|
throw new import_errors11.FuelError(
|
@@ -2884,10 +2784,10 @@ function isTypeScript(transactionType) {
|
|
2884
2784
|
return isType(transactionType, "Script" /* Script */);
|
2885
2785
|
}
|
2886
2786
|
function getReceiptsCall(receipts) {
|
2887
|
-
return getReceiptsByType(receipts,
|
2787
|
+
return getReceiptsByType(receipts, import_transactions15.ReceiptType.Call);
|
2888
2788
|
}
|
2889
2789
|
function getReceiptsMessageOut(receipts) {
|
2890
|
-
return getReceiptsByType(receipts,
|
2790
|
+
return getReceiptsByType(receipts, import_transactions15.ReceiptType.MessageOut);
|
2891
2791
|
}
|
2892
2792
|
var mergeAssets = (op1, op2) => {
|
2893
2793
|
const assets1 = op1.assetsSent || [];
|
@@ -3083,11 +2983,11 @@ function getTransferOperations({
|
|
3083
2983
|
});
|
3084
2984
|
const transferReceipts = getReceiptsByType(
|
3085
2985
|
receipts,
|
3086
|
-
|
2986
|
+
import_transactions15.ReceiptType.Transfer
|
3087
2987
|
);
|
3088
2988
|
const transferOutReceipts = getReceiptsByType(
|
3089
2989
|
receipts,
|
3090
|
-
|
2990
|
+
import_transactions15.ReceiptType.TransferOut
|
3091
2991
|
);
|
3092
2992
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3093
2993
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3172,17 +3072,17 @@ function getOperations({
|
|
3172
3072
|
}
|
3173
3073
|
|
3174
3074
|
// src/providers/transaction-summary/receipt.ts
|
3175
|
-
var
|
3075
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3176
3076
|
var processGqlReceipt = (gqlReceipt) => {
|
3177
3077
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3178
3078
|
switch (receipt.type) {
|
3179
|
-
case
|
3079
|
+
case import_transactions16.ReceiptType.ReturnData: {
|
3180
3080
|
return {
|
3181
3081
|
...receipt,
|
3182
3082
|
data: gqlReceipt.data || "0x"
|
3183
3083
|
};
|
3184
3084
|
}
|
3185
|
-
case
|
3085
|
+
case import_transactions16.ReceiptType.LogData: {
|
3186
3086
|
return {
|
3187
3087
|
...receipt,
|
3188
3088
|
data: gqlReceipt.data || "0x"
|
@@ -3195,7 +3095,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3195
3095
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3196
3096
|
const mintedAssets = [];
|
3197
3097
|
receipts.forEach((receipt) => {
|
3198
|
-
if (receipt.type ===
|
3098
|
+
if (receipt.type === import_transactions16.ReceiptType.Mint) {
|
3199
3099
|
mintedAssets.push({
|
3200
3100
|
subId: receipt.subId,
|
3201
3101
|
contractId: receipt.contractId,
|
@@ -3209,7 +3109,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3209
3109
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3210
3110
|
const burnedAssets = [];
|
3211
3111
|
receipts.forEach((receipt) => {
|
3212
|
-
if (receipt.type ===
|
3112
|
+
if (receipt.type === import_transactions16.ReceiptType.Burn) {
|
3213
3113
|
burnedAssets.push({
|
3214
3114
|
subId: receipt.subId,
|
3215
3115
|
contractId: receipt.contractId,
|
@@ -3290,12 +3190,10 @@ function assembleTransactionSummary(params) {
|
|
3290
3190
|
gqlTransactionStatus,
|
3291
3191
|
abiMap = {},
|
3292
3192
|
maxInputs,
|
3293
|
-
gasCosts
|
3294
|
-
maxGasPerTx,
|
3295
|
-
gasPrice
|
3193
|
+
gasCosts
|
3296
3194
|
} = params;
|
3297
3195
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3298
|
-
const rawPayload = (0,
|
3196
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3299
3197
|
const operations = getOperations({
|
3300
3198
|
transactionType: transaction.type,
|
3301
3199
|
inputs: transaction.inputs || [],
|
@@ -3306,14 +3204,11 @@ function assembleTransactionSummary(params) {
|
|
3306
3204
|
maxInputs
|
3307
3205
|
});
|
3308
3206
|
const typeName = getTransactionTypeName(transaction.type);
|
3309
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3310
3207
|
const { fee } = calculateTransactionFee({
|
3311
|
-
|
3208
|
+
gasUsed,
|
3312
3209
|
rawPayload,
|
3313
|
-
tip,
|
3314
3210
|
consensusParameters: {
|
3315
3211
|
gasCosts,
|
3316
|
-
maxGasPerTx,
|
3317
3212
|
feeParams: {
|
3318
3213
|
gasPerByte,
|
3319
3214
|
gasPriceFactor
|
@@ -3325,7 +3220,7 @@ function assembleTransactionSummary(params) {
|
|
3325
3220
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3326
3221
|
let date;
|
3327
3222
|
if (time) {
|
3328
|
-
date =
|
3223
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3329
3224
|
}
|
3330
3225
|
const transactionSummary = {
|
3331
3226
|
id,
|
@@ -3373,7 +3268,7 @@ var TransactionResponse = class {
|
|
3373
3268
|
/** Current provider */
|
3374
3269
|
provider;
|
3375
3270
|
/** Gas used on the transaction */
|
3376
|
-
gasUsed = (0,
|
3271
|
+
gasUsed = (0, import_math14.bn)(0);
|
3377
3272
|
/** The graphql Transaction with receipts object. */
|
3378
3273
|
gqlTransaction;
|
3379
3274
|
abis;
|
@@ -3432,7 +3327,7 @@ var TransactionResponse = class {
|
|
3432
3327
|
*/
|
3433
3328
|
decodeTransaction(transactionWithReceipts) {
|
3434
3329
|
return new import_transactions18.TransactionCoder().decode(
|
3435
|
-
(0,
|
3330
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3436
3331
|
0
|
3437
3332
|
)?.[0];
|
3438
3333
|
}
|
@@ -3451,27 +3346,20 @@ var TransactionResponse = class {
|
|
3451
3346
|
const decodedTransaction = this.decodeTransaction(
|
3452
3347
|
transaction
|
3453
3348
|
);
|
3454
|
-
|
3455
|
-
|
3456
|
-
txReceipts = transaction.status.receipts;
|
3457
|
-
}
|
3458
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3459
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3460
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3349
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3350
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3461
3351
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3462
3352
|
const transactionSummary = assembleTransactionSummary({
|
3463
3353
|
id: this.id,
|
3464
3354
|
receipts,
|
3465
3355
|
transaction: decodedTransaction,
|
3466
|
-
transactionBytes: (0,
|
3356
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3467
3357
|
gqlTransactionStatus: transaction.status,
|
3468
3358
|
gasPerByte,
|
3469
3359
|
gasPriceFactor,
|
3470
3360
|
abiMap: contractsAbiMap,
|
3471
3361
|
maxInputs,
|
3472
|
-
gasCosts
|
3473
|
-
maxGasPerTx,
|
3474
|
-
gasPrice
|
3362
|
+
gasCosts
|
3475
3363
|
});
|
3476
3364
|
return transactionSummary;
|
3477
3365
|
}
|
@@ -3598,29 +3486,29 @@ var processGqlChain = (chain) => {
|
|
3598
3486
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3599
3487
|
return {
|
3600
3488
|
name,
|
3601
|
-
baseChainHeight: (0,
|
3489
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3602
3490
|
consensusParameters: {
|
3603
|
-
contractMaxSize: (0,
|
3604
|
-
maxInputs: (0,
|
3605
|
-
maxOutputs: (0,
|
3606
|
-
maxWitnesses: (0,
|
3607
|
-
maxGasPerTx: (0,
|
3608
|
-
maxScriptLength: (0,
|
3609
|
-
maxScriptDataLength: (0,
|
3610
|
-
maxStorageSlots: (0,
|
3611
|
-
maxPredicateLength: (0,
|
3612
|
-
maxPredicateDataLength: (0,
|
3613
|
-
maxGasPerPredicate: (0,
|
3614
|
-
gasPriceFactor: (0,
|
3615
|
-
gasPerByte: (0,
|
3616
|
-
maxMessageDataLength: (0,
|
3617
|
-
chainId: (0,
|
3491
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3492
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3493
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3494
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3495
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3496
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3497
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3498
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3499
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3500
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3501
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3502
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3503
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3504
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3505
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3618
3506
|
gasCosts
|
3619
3507
|
},
|
3620
3508
|
gasCosts,
|
3621
3509
|
latestBlock: {
|
3622
3510
|
id: latestBlock.id,
|
3623
|
-
height: (0,
|
3511
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3624
3512
|
time: latestBlock.header.time,
|
3625
3513
|
transactions: latestBlock.transactions.map((i) => ({
|
3626
3514
|
id: i.id
|
@@ -3714,8 +3602,10 @@ var _Provider = class {
|
|
3714
3602
|
* Returns some helpful parameters related to gas fees.
|
3715
3603
|
*/
|
3716
3604
|
getGasConfig() {
|
3605
|
+
const { minGasPrice } = this.getNode();
|
3717
3606
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3718
3607
|
return {
|
3608
|
+
minGasPrice,
|
3719
3609
|
maxGasPerTx,
|
3720
3610
|
maxGasPerPredicate,
|
3721
3611
|
gasPriceFactor,
|
@@ -3813,7 +3703,7 @@ var _Provider = class {
|
|
3813
3703
|
*/
|
3814
3704
|
async getBlockNumber() {
|
3815
3705
|
const { chain } = await this.operations.getChain();
|
3816
|
-
return (0,
|
3706
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3817
3707
|
}
|
3818
3708
|
/**
|
3819
3709
|
* Returns the chain information.
|
@@ -3823,11 +3713,13 @@ var _Provider = class {
|
|
3823
3713
|
async fetchNode() {
|
3824
3714
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3825
3715
|
const processedNodeInfo = {
|
3826
|
-
maxDepth: (0,
|
3827
|
-
maxTx: (0,
|
3716
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3717
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3718
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3828
3719
|
nodeVersion: nodeInfo.nodeVersion,
|
3829
3720
|
utxoValidation: nodeInfo.utxoValidation,
|
3830
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3721
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3722
|
+
peers: nodeInfo.peers
|
3831
3723
|
};
|
3832
3724
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3833
3725
|
return processedNodeInfo;
|
@@ -3869,7 +3761,7 @@ var _Provider = class {
|
|
3869
3761
|
if (estimateTxDependencies) {
|
3870
3762
|
await this.estimateTxDependencies(transactionRequest);
|
3871
3763
|
}
|
3872
|
-
const encodedTransaction = (0,
|
3764
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3873
3765
|
let abis;
|
3874
3766
|
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
3875
3767
|
abis = transactionRequest.abis;
|
@@ -3912,14 +3804,15 @@ var _Provider = class {
|
|
3912
3804
|
if (estimateTxDependencies) {
|
3913
3805
|
return this.estimateTxDependencies(transactionRequest);
|
3914
3806
|
}
|
3915
|
-
const encodedTransaction = (0,
|
3916
|
-
const { dryRun:
|
3917
|
-
|
3807
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3808
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3809
|
+
encodedTransaction,
|
3918
3810
|
utxoValidation: utxoValidation || false
|
3919
3811
|
});
|
3920
|
-
const
|
3921
|
-
|
3922
|
-
|
3812
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3813
|
+
return {
|
3814
|
+
receipts
|
3815
|
+
};
|
3923
3816
|
}
|
3924
3817
|
/**
|
3925
3818
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3930,13 +3823,13 @@ var _Provider = class {
|
|
3930
3823
|
async estimatePredicates(transactionRequest) {
|
3931
3824
|
const shouldEstimatePredicates = Boolean(
|
3932
3825
|
transactionRequest.inputs.find(
|
3933
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3826
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
|
3934
3827
|
)
|
3935
3828
|
);
|
3936
3829
|
if (!shouldEstimatePredicates) {
|
3937
3830
|
return transactionRequest;
|
3938
3831
|
}
|
3939
|
-
const encodedTransaction = (0,
|
3832
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3940
3833
|
const response = await this.operations.estimatePredicates({
|
3941
3834
|
encodedTransaction
|
3942
3835
|
});
|
@@ -3945,7 +3838,7 @@ var _Provider = class {
|
|
3945
3838
|
} = response;
|
3946
3839
|
if (inputs) {
|
3947
3840
|
inputs.forEach((input, index) => {
|
3948
|
-
if ("predicateGasUsed" in input && (0,
|
3841
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3949
3842
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3950
3843
|
}
|
3951
3844
|
});
|
@@ -3958,6 +3851,9 @@ var _Provider = class {
|
|
3958
3851
|
* If there are missing variable outputs,
|
3959
3852
|
* `addVariableOutputs` is called on the transaction.
|
3960
3853
|
*
|
3854
|
+
* @privateRemarks
|
3855
|
+
* TODO: Investigate support for missing contract IDs
|
3856
|
+
* TODO: Add support for missing output messages
|
3961
3857
|
*
|
3962
3858
|
* @param transactionRequest - The transaction request object.
|
3963
3859
|
* @returns A promise.
|
@@ -3970,19 +3866,16 @@ var _Provider = class {
|
|
3970
3866
|
missingContractIds: []
|
3971
3867
|
};
|
3972
3868
|
}
|
3869
|
+
await this.estimatePredicates(transactionRequest);
|
3973
3870
|
let receipts = [];
|
3974
3871
|
const missingContractIds = [];
|
3975
3872
|
let outputVariables = 0;
|
3976
|
-
let dryrunStatus;
|
3977
3873
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3978
|
-
const {
|
3979
|
-
|
3980
|
-
} = await this.operations.dryRun({
|
3981
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3874
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3875
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3982
3876
|
utxoValidation: false
|
3983
3877
|
});
|
3984
|
-
receipts =
|
3985
|
-
dryrunStatus = status;
|
3878
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3986
3879
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3987
3880
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3988
3881
|
if (hasMissingOutputs) {
|
@@ -3992,10 +3885,6 @@ var _Provider = class {
|
|
3992
3885
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3993
3886
|
missingContractIds.push(contractId);
|
3994
3887
|
});
|
3995
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3996
|
-
transactionRequest
|
3997
|
-
});
|
3998
|
-
transactionRequest.maxFee = maxFee;
|
3999
3888
|
} else {
|
4000
3889
|
break;
|
4001
3890
|
}
|
@@ -4003,139 +3892,37 @@ var _Provider = class {
|
|
4003
3892
|
return {
|
4004
3893
|
receipts,
|
4005
3894
|
outputVariables,
|
4006
|
-
missingContractIds
|
4007
|
-
dryrunStatus
|
3895
|
+
missingContractIds
|
4008
3896
|
};
|
4009
3897
|
}
|
4010
|
-
/**
|
4011
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4012
|
-
*
|
4013
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4014
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4015
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4016
|
-
*
|
4017
|
-
* @param transactionRequests - Array of transaction request objects.
|
4018
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4019
|
-
*/
|
4020
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4021
|
-
const results = transactionRequests.map(() => ({
|
4022
|
-
receipts: [],
|
4023
|
-
outputVariables: 0,
|
4024
|
-
missingContractIds: [],
|
4025
|
-
dryrunStatus: void 0
|
4026
|
-
}));
|
4027
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4028
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4029
|
-
allRequests.forEach((req, index) => {
|
4030
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4031
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4032
|
-
}
|
4033
|
-
});
|
4034
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4035
|
-
let attempt = 0;
|
4036
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4037
|
-
const encodedTransactions = transactionsToProcess.map(
|
4038
|
-
(index) => serializedTransactionsMap.get(index)
|
4039
|
-
);
|
4040
|
-
const dryRunResults = await this.operations.dryRun({
|
4041
|
-
encodedTransactions,
|
4042
|
-
utxoValidation: false
|
4043
|
-
});
|
4044
|
-
const nextRoundTransactions = [];
|
4045
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4046
|
-
const currentResultIndex = transactionsToProcess[i];
|
4047
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4048
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4049
|
-
results[currentResultIndex].dryrunStatus = status;
|
4050
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4051
|
-
results[currentResultIndex].receipts
|
4052
|
-
);
|
4053
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4054
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4055
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4056
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4057
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4058
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4059
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4060
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4061
|
-
});
|
4062
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4063
|
-
transactionRequest: requestToProcess
|
4064
|
-
});
|
4065
|
-
requestToProcess.maxFee = maxFee;
|
4066
|
-
serializedTransactionsMap.set(
|
4067
|
-
currentResultIndex,
|
4068
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4069
|
-
);
|
4070
|
-
nextRoundTransactions.push(currentResultIndex);
|
4071
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4072
|
-
}
|
4073
|
-
}
|
4074
|
-
transactionsToProcess = nextRoundTransactions;
|
4075
|
-
attempt += 1;
|
4076
|
-
}
|
4077
|
-
return results;
|
4078
|
-
}
|
4079
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4080
|
-
if (estimateTxDependencies) {
|
4081
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4082
|
-
}
|
4083
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4084
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4085
|
-
encodedTransactions,
|
4086
|
-
utxoValidation: utxoValidation || false
|
4087
|
-
});
|
4088
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4089
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4090
|
-
return { receipts, dryrunStatus: status };
|
4091
|
-
});
|
4092
|
-
return results;
|
4093
|
-
}
|
4094
3898
|
/**
|
4095
3899
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4096
3900
|
* @param transactionRequest - The transaction request object.
|
4097
3901
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4098
3902
|
*/
|
4099
|
-
|
3903
|
+
estimateTxGasAndFee(params) {
|
4100
3904
|
const { transactionRequest } = params;
|
4101
|
-
|
3905
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4102
3906
|
const chainInfo = this.getChain();
|
4103
|
-
const
|
3907
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3908
|
+
transactionRequest.gasPrice = gasPrice;
|
4104
3909
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4105
|
-
|
4106
|
-
gasPrice = await this.estimateGasPrice(10);
|
4107
|
-
}
|
4108
|
-
const minFee = calculateGasFee({
|
4109
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4110
|
-
gas: minGas,
|
4111
|
-
priceFactor: gasPriceFactor,
|
4112
|
-
tip: transactionRequest.tip
|
4113
|
-
}).add(1);
|
4114
|
-
let gasLimit = (0, import_math16.bn)(0);
|
3910
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4115
3911
|
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4116
|
-
gasLimit = transactionRequest.gasLimit;
|
4117
3912
|
if (transactionRequest.gasLimit.eq(0)) {
|
4118
3913
|
transactionRequest.gasLimit = minGas;
|
4119
3914
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4120
3915
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4121
3916
|
);
|
4122
|
-
gasLimit = transactionRequest.gasLimit;
|
4123
3917
|
}
|
4124
3918
|
}
|
4125
3919
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4126
|
-
const maxFee =
|
4127
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4128
|
-
gas: maxGas,
|
4129
|
-
priceFactor: gasPriceFactor,
|
4130
|
-
tip: transactionRequest.tip
|
4131
|
-
}).add(1);
|
3920
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4132
3921
|
return {
|
4133
3922
|
minGas,
|
4134
3923
|
minFee,
|
4135
3924
|
maxGas,
|
4136
|
-
maxFee
|
4137
|
-
gasPrice,
|
4138
|
-
gasLimit
|
3925
|
+
maxFee
|
4139
3926
|
};
|
4140
3927
|
}
|
4141
3928
|
/**
|
@@ -4153,17 +3940,15 @@ var _Provider = class {
|
|
4153
3940
|
if (estimateTxDependencies) {
|
4154
3941
|
return this.estimateTxDependencies(transactionRequest);
|
4155
3942
|
}
|
4156
|
-
const
|
4157
|
-
const { dryRun:
|
4158
|
-
|
3943
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3944
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3945
|
+
encodedTransaction,
|
4159
3946
|
utxoValidation: true
|
4160
3947
|
});
|
4161
|
-
const
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
4165
|
-
});
|
4166
|
-
return { receipts: callResult[0].receipts };
|
3948
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3949
|
+
return {
|
3950
|
+
receipts
|
3951
|
+
};
|
4167
3952
|
}
|
4168
3953
|
/**
|
4169
3954
|
* Returns a transaction cost to enable user
|
@@ -4180,79 +3965,77 @@ var _Provider = class {
|
|
4180
3965
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4181
3966
|
* @returns A promise that resolves to the transaction cost object.
|
4182
3967
|
*/
|
4183
|
-
async getTransactionCost(transactionRequestLike,
|
3968
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3969
|
+
estimateTxDependencies = true,
|
3970
|
+
estimatePredicates = true,
|
3971
|
+
resourcesOwner,
|
3972
|
+
signatureCallback
|
3973
|
+
} = {}) {
|
4184
3974
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3975
|
+
const { minGasPrice } = this.getGasConfig();
|
3976
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4185
3977
|
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
4186
3978
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4187
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3979
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4188
3980
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4189
|
-
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4190
3981
|
if (isScriptTransaction) {
|
4191
|
-
txRequestClone.gasLimit = (0,
|
3982
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4192
3983
|
}
|
4193
|
-
if (
|
4194
|
-
resourcesOwner
|
3984
|
+
if (estimatePredicates) {
|
3985
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3986
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3987
|
+
}
|
3988
|
+
await this.estimatePredicates(txRequestClone);
|
4195
3989
|
}
|
4196
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4197
|
-
let addedSignatures = 0;
|
4198
3990
|
if (signatureCallback && isScriptTransaction) {
|
4199
|
-
|
4200
|
-
await signatureCallback(signedRequest);
|
4201
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3991
|
+
await signatureCallback(txRequestClone);
|
4202
3992
|
}
|
4203
|
-
|
4204
|
-
|
4205
|
-
transactionRequest: signedRequest
|
3993
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3994
|
+
transactionRequest: txRequestClone
|
4206
3995
|
});
|
4207
3996
|
let receipts = [];
|
4208
3997
|
let missingContractIds = [];
|
4209
3998
|
let outputVariables = 0;
|
4210
|
-
let gasUsed = (0,
|
4211
|
-
|
4212
|
-
|
4213
|
-
if (isScriptTransaction) {
|
4214
|
-
txRequestClone.gasLimit = gasLimit;
|
4215
|
-
if (signatureCallback) {
|
4216
|
-
await signatureCallback(txRequestClone);
|
4217
|
-
}
|
3999
|
+
let gasUsed = (0, import_math15.bn)(0);
|
4000
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4001
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4218
4002
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4219
4003
|
receipts = result.receipts;
|
4220
4004
|
outputVariables = result.outputVariables;
|
4221
4005
|
missingContractIds = result.missingContractIds;
|
4222
4006
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4223
4007
|
txRequestClone.gasLimit = gasUsed;
|
4224
|
-
|
4225
|
-
|
4226
|
-
|
4008
|
+
txRequestClone.gasPrice = setGasPrice;
|
4009
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4010
|
+
transactionRequest: txRequestClone
|
4227
4011
|
}));
|
4228
4012
|
}
|
4229
4013
|
return {
|
4230
4014
|
requiredQuantities: allQuantities,
|
4231
4015
|
receipts,
|
4232
4016
|
gasUsed,
|
4233
|
-
|
4017
|
+
minGasPrice,
|
4018
|
+
gasPrice: setGasPrice,
|
4234
4019
|
minGas,
|
4235
4020
|
maxGas,
|
4236
4021
|
minFee,
|
4237
4022
|
maxFee,
|
4023
|
+
estimatedInputs: txRequestClone.inputs,
|
4238
4024
|
outputVariables,
|
4239
|
-
missingContractIds
|
4240
|
-
addedSignatures,
|
4241
|
-
estimatedPredicates: txRequestClone.inputs
|
4025
|
+
missingContractIds
|
4242
4026
|
};
|
4243
4027
|
}
|
4244
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4028
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4245
4029
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4246
4030
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4247
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4248
|
-
quantitiesToContract
|
4249
|
-
});
|
4031
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4250
4032
|
transactionRequest.addResources(
|
4251
4033
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4252
4034
|
);
|
4253
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4254
|
-
|
4255
|
-
|
4035
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4036
|
+
transactionRequest,
|
4037
|
+
forwardingQuantities
|
4038
|
+
);
|
4256
4039
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4257
4040
|
return {
|
4258
4041
|
resources,
|
@@ -4268,16 +4051,17 @@ var _Provider = class {
|
|
4268
4051
|
const result = await this.operations.getCoins({
|
4269
4052
|
first: 10,
|
4270
4053
|
...paginationArgs,
|
4271
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4054
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4272
4055
|
});
|
4273
4056
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4274
4057
|
return coins.map((coin) => ({
|
4275
4058
|
id: coin.utxoId,
|
4276
4059
|
assetId: coin.assetId,
|
4277
|
-
amount: (0,
|
4060
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4278
4061
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4279
|
-
|
4280
|
-
|
4062
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4063
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4064
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4281
4065
|
}));
|
4282
4066
|
}
|
4283
4067
|
/**
|
@@ -4291,19 +4075,19 @@ var _Provider = class {
|
|
4291
4075
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4292
4076
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4293
4077
|
const excludeInput = {
|
4294
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4295
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4078
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4079
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4296
4080
|
};
|
4297
4081
|
if (this.cache) {
|
4298
4082
|
const uniqueUtxos = new Set(
|
4299
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4083
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4300
4084
|
);
|
4301
4085
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4302
4086
|
}
|
4303
4087
|
const coinsQuery = {
|
4304
4088
|
owner: ownerAddress.toB256(),
|
4305
4089
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4306
|
-
assetId: (0,
|
4090
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4307
4091
|
amount: amount.toString(10),
|
4308
4092
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4309
4093
|
})),
|
@@ -4314,9 +4098,9 @@ var _Provider = class {
|
|
4314
4098
|
switch (coin.__typename) {
|
4315
4099
|
case "MessageCoin":
|
4316
4100
|
return {
|
4317
|
-
amount: (0,
|
4101
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4318
4102
|
assetId: coin.assetId,
|
4319
|
-
daHeight: (0,
|
4103
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4320
4104
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4321
4105
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4322
4106
|
nonce: coin.nonce
|
@@ -4324,11 +4108,12 @@ var _Provider = class {
|
|
4324
4108
|
case "Coin":
|
4325
4109
|
return {
|
4326
4110
|
id: coin.utxoId,
|
4327
|
-
amount: (0,
|
4111
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4328
4112
|
assetId: coin.assetId,
|
4329
4113
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4330
|
-
|
4331
|
-
|
4114
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4115
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4116
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4332
4117
|
};
|
4333
4118
|
default:
|
4334
4119
|
return null;
|
@@ -4345,13 +4130,13 @@ var _Provider = class {
|
|
4345
4130
|
async getBlock(idOrHeight) {
|
4346
4131
|
let variables;
|
4347
4132
|
if (typeof idOrHeight === "number") {
|
4348
|
-
variables = { height: (0,
|
4133
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4349
4134
|
} else if (idOrHeight === "latest") {
|
4350
4135
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4351
4136
|
} else if (idOrHeight.length === 66) {
|
4352
4137
|
variables = { blockId: idOrHeight };
|
4353
4138
|
} else {
|
4354
|
-
variables = { blockId: (0,
|
4139
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4355
4140
|
}
|
4356
4141
|
const { block } = await this.operations.getBlock(variables);
|
4357
4142
|
if (!block) {
|
@@ -4359,7 +4144,7 @@ var _Provider = class {
|
|
4359
4144
|
}
|
4360
4145
|
return {
|
4361
4146
|
id: block.id,
|
4362
|
-
height: (0,
|
4147
|
+
height: (0, import_math15.bn)(block.header.height),
|
4363
4148
|
time: block.header.time,
|
4364
4149
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4365
4150
|
};
|
@@ -4374,7 +4159,7 @@ var _Provider = class {
|
|
4374
4159
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4375
4160
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4376
4161
|
id: block.id,
|
4377
|
-
height: (0,
|
4162
|
+
height: (0, import_math15.bn)(block.header.height),
|
4378
4163
|
time: block.header.time,
|
4379
4164
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4380
4165
|
}));
|
@@ -4389,7 +4174,7 @@ var _Provider = class {
|
|
4389
4174
|
async getBlockWithTransactions(idOrHeight) {
|
4390
4175
|
let variables;
|
4391
4176
|
if (typeof idOrHeight === "number") {
|
4392
|
-
variables = { blockHeight: (0,
|
4177
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4393
4178
|
} else if (idOrHeight === "latest") {
|
4394
4179
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4395
4180
|
} else {
|
@@ -4401,11 +4186,11 @@ var _Provider = class {
|
|
4401
4186
|
}
|
4402
4187
|
return {
|
4403
4188
|
id: block.id,
|
4404
|
-
height: (0,
|
4189
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4405
4190
|
time: block.header.time,
|
4406
4191
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4407
4192
|
transactions: block.transactions.map(
|
4408
|
-
(tx) => new import_transactions19.TransactionCoder().decode((0,
|
4193
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4409
4194
|
)
|
4410
4195
|
};
|
4411
4196
|
}
|
@@ -4421,7 +4206,7 @@ var _Provider = class {
|
|
4421
4206
|
return null;
|
4422
4207
|
}
|
4423
4208
|
return new import_transactions19.TransactionCoder().decode(
|
4424
|
-
(0,
|
4209
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4425
4210
|
0
|
4426
4211
|
)?.[0];
|
4427
4212
|
}
|
@@ -4448,9 +4233,9 @@ var _Provider = class {
|
|
4448
4233
|
async getContractBalance(contractId, assetId) {
|
4449
4234
|
const { contractBalance } = await this.operations.getContractBalance({
|
4450
4235
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4451
|
-
asset: (0,
|
4236
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4452
4237
|
});
|
4453
|
-
return (0,
|
4238
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4454
4239
|
}
|
4455
4240
|
/**
|
4456
4241
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4462,9 +4247,9 @@ var _Provider = class {
|
|
4462
4247
|
async getBalance(owner, assetId) {
|
4463
4248
|
const { balance } = await this.operations.getBalance({
|
4464
4249
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4465
|
-
assetId: (0,
|
4250
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4466
4251
|
});
|
4467
|
-
return (0,
|
4252
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4468
4253
|
}
|
4469
4254
|
/**
|
4470
4255
|
* Returns balances for the given owner.
|
@@ -4482,7 +4267,7 @@ var _Provider = class {
|
|
4482
4267
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4483
4268
|
return balances.map((balance) => ({
|
4484
4269
|
assetId: balance.assetId,
|
4485
|
-
amount: (0,
|
4270
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4486
4271
|
}));
|
4487
4272
|
}
|
4488
4273
|
/**
|
@@ -4504,15 +4289,15 @@ var _Provider = class {
|
|
4504
4289
|
sender: message.sender,
|
4505
4290
|
recipient: message.recipient,
|
4506
4291
|
nonce: message.nonce,
|
4507
|
-
amount: (0,
|
4292
|
+
amount: (0, import_math15.bn)(message.amount),
|
4508
4293
|
data: message.data
|
4509
4294
|
}),
|
4510
4295
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4511
4296
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4512
4297
|
nonce: message.nonce,
|
4513
|
-
amount: (0,
|
4298
|
+
amount: (0, import_math15.bn)(message.amount),
|
4514
4299
|
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4515
|
-
daHeight: (0,
|
4300
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4516
4301
|
}));
|
4517
4302
|
}
|
4518
4303
|
/**
|
@@ -4565,60 +4350,44 @@ var _Provider = class {
|
|
4565
4350
|
} = result.messageProof;
|
4566
4351
|
return {
|
4567
4352
|
messageProof: {
|
4568
|
-
proofIndex: (0,
|
4353
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4569
4354
|
proofSet: messageProof.proofSet
|
4570
4355
|
},
|
4571
4356
|
blockProof: {
|
4572
|
-
proofIndex: (0,
|
4357
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4573
4358
|
proofSet: blockProof.proofSet
|
4574
4359
|
},
|
4575
4360
|
messageBlockHeader: {
|
4576
4361
|
id: messageBlockHeader.id,
|
4577
|
-
daHeight: (0,
|
4578
|
-
transactionsCount: (0,
|
4362
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4363
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4579
4364
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4580
|
-
height: (0,
|
4365
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4581
4366
|
prevRoot: messageBlockHeader.prevRoot,
|
4582
4367
|
time: messageBlockHeader.time,
|
4583
4368
|
applicationHash: messageBlockHeader.applicationHash,
|
4584
|
-
|
4585
|
-
|
4586
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4587
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4588
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4369
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4370
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4589
4371
|
},
|
4590
4372
|
commitBlockHeader: {
|
4591
4373
|
id: commitBlockHeader.id,
|
4592
|
-
daHeight: (0,
|
4593
|
-
transactionsCount: (0,
|
4374
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4375
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4594
4376
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4595
|
-
height: (0,
|
4377
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4596
4378
|
prevRoot: commitBlockHeader.prevRoot,
|
4597
4379
|
time: commitBlockHeader.time,
|
4598
4380
|
applicationHash: commitBlockHeader.applicationHash,
|
4599
|
-
|
4600
|
-
|
4601
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4602
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4603
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4381
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4382
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4604
4383
|
},
|
4605
4384
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4606
4385
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4607
4386
|
nonce,
|
4608
|
-
amount: (0,
|
4387
|
+
amount: (0, import_math15.bn)(amount),
|
4609
4388
|
data
|
4610
4389
|
};
|
4611
4390
|
}
|
4612
|
-
async getLatestGasPrice() {
|
4613
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4614
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4615
|
-
}
|
4616
|
-
async estimateGasPrice(blockHorizon) {
|
4617
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4618
|
-
blockHorizon: String(blockHorizon)
|
4619
|
-
});
|
4620
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4621
|
-
}
|
4622
4391
|
/**
|
4623
4392
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4624
4393
|
*
|
@@ -4638,10 +4407,10 @@ var _Provider = class {
|
|
4638
4407
|
*/
|
4639
4408
|
async produceBlocks(amount, startTime) {
|
4640
4409
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4641
|
-
blocksToProduce: (0,
|
4642
|
-
startTimestamp: startTime ?
|
4410
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4411
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4643
4412
|
});
|
4644
|
-
return (0,
|
4413
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4645
4414
|
}
|
4646
4415
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4647
4416
|
async getTransactionResponse(transactionId) {
|
@@ -4665,9 +4434,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4665
4434
|
|
4666
4435
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4667
4436
|
var import_errors15 = require("@fuel-ts/errors");
|
4668
|
-
var
|
4437
|
+
var import_math16 = require("@fuel-ts/math");
|
4669
4438
|
var import_transactions20 = require("@fuel-ts/transactions");
|
4670
|
-
var
|
4439
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4671
4440
|
|
4672
4441
|
// src/providers/chains.ts
|
4673
4442
|
var CHAIN_IDS = {
|
@@ -4716,17 +4485,17 @@ var assets = [
|
|
4716
4485
|
|
4717
4486
|
// src/utils/formatTransferToContractScriptData.ts
|
4718
4487
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4719
|
-
var
|
4720
|
-
var
|
4488
|
+
var import_math17 = require("@fuel-ts/math");
|
4489
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4721
4490
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4722
4491
|
var formatTransferToContractScriptData = (params) => {
|
4723
4492
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4724
4493
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4725
|
-
const encoded = numberCoder.encode(new
|
4494
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4726
4495
|
const scriptData = Uint8Array.from([
|
4727
|
-
...(0,
|
4496
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4728
4497
|
...encoded,
|
4729
|
-
...(0,
|
4498
|
+
...(0, import_utils27.arrayify)(assetId)
|
4730
4499
|
]);
|
4731
4500
|
return scriptData;
|
4732
4501
|
};
|
@@ -4911,33 +4680,36 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4911
4680
|
* @param fee - The estimated transaction fee.
|
4912
4681
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4913
4682
|
*/
|
4914
|
-
async fund(request,
|
4915
|
-
const
|
4916
|
-
|
4917
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4918
|
-
amount: (0, import_math19.bn)(fee),
|
4683
|
+
async fund(request, coinQuantities, fee) {
|
4684
|
+
const updatedQuantities = addAmountToAsset({
|
4685
|
+
amount: (0, import_math18.bn)(fee),
|
4919
4686
|
assetId: import_configs12.BaseAssetId,
|
4920
|
-
coinQuantities
|
4687
|
+
coinQuantities
|
4921
4688
|
});
|
4922
4689
|
const quantitiesDict = {};
|
4923
|
-
|
4690
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4924
4691
|
quantitiesDict[assetId] = {
|
4925
4692
|
required: amount,
|
4926
|
-
owned: (0,
|
4693
|
+
owned: (0, import_math18.bn)(0)
|
4927
4694
|
};
|
4928
4695
|
});
|
4929
|
-
|
4696
|
+
const cachedUtxos = [];
|
4697
|
+
const cachedMessages = [];
|
4698
|
+
const owner = this.address.toB256();
|
4699
|
+
request.inputs.forEach((input) => {
|
4930
4700
|
const isResource = "amount" in input;
|
4931
4701
|
if (isResource) {
|
4932
4702
|
const isCoin2 = "owner" in input;
|
4933
4703
|
if (isCoin2) {
|
4934
4704
|
const assetId = String(input.assetId);
|
4935
|
-
if (quantitiesDict[assetId]) {
|
4936
|
-
const amount = (0,
|
4705
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4706
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4937
4707
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4708
|
+
cachedUtxos.push(input.id);
|
4938
4709
|
}
|
4939
|
-
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4710
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4940
4711
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4712
|
+
cachedMessages.push(input.nonce);
|
4941
4713
|
}
|
4942
4714
|
}
|
4943
4715
|
});
|
@@ -4952,23 +4724,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4952
4724
|
});
|
4953
4725
|
const needsToBeFunded = missingQuantities.length;
|
4954
4726
|
if (needsToBeFunded) {
|
4955
|
-
const
|
4956
|
-
|
4957
|
-
|
4958
|
-
|
4959
|
-
|
4960
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4961
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4962
|
-
if (addedSignatures) {
|
4963
|
-
Array.from({ length: addedSignatures }).forEach(
|
4964
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4965
|
-
);
|
4727
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4728
|
+
messages: cachedMessages,
|
4729
|
+
utxos: cachedUtxos
|
4730
|
+
});
|
4731
|
+
request.addResources(resources);
|
4966
4732
|
}
|
4967
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4968
|
-
transactionRequest: requestToBeReEstimate
|
4969
|
-
});
|
4970
|
-
txRequest.maxFee = maxFee;
|
4971
|
-
return txRequest;
|
4972
4733
|
}
|
4973
4734
|
/**
|
4974
4735
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4976,25 +4737,28 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4976
4737
|
* @param destination - The address of the destination.
|
4977
4738
|
* @param amount - The amount of coins to transfer.
|
4978
4739
|
* @param assetId - The asset ID of the coins to transfer.
|
4979
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4740
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4980
4741
|
* @returns A promise that resolves to the prepared transaction request.
|
4981
4742
|
*/
|
4982
4743
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4983
|
-
const
|
4744
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4745
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4746
|
+
const request = new ScriptTransactionRequest(params);
|
4984
4747
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4985
|
-
const
|
4748
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4986
4749
|
estimateTxDependencies: true,
|
4987
4750
|
resourcesOwner: this
|
4988
4751
|
});
|
4989
|
-
|
4990
|
-
|
4991
|
-
|
4992
|
-
|
4993
|
-
|
4994
|
-
|
4995
|
-
|
4996
|
-
|
4997
|
-
await this.fund(request,
|
4752
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4753
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4754
|
+
this.validateGas({
|
4755
|
+
gasUsed,
|
4756
|
+
gasPrice: request.gasPrice,
|
4757
|
+
gasLimit: request.gasLimit,
|
4758
|
+
minGasPrice
|
4759
|
+
});
|
4760
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4761
|
+
request.updatePredicateInputs(estimatedInputs);
|
4998
4762
|
return request;
|
4999
4763
|
}
|
5000
4764
|
/**
|
@@ -5007,7 +4771,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5007
4771
|
* @returns A promise that resolves to the transaction response.
|
5008
4772
|
*/
|
5009
4773
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5010
|
-
if ((0,
|
4774
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5011
4775
|
throw new import_errors16.FuelError(
|
5012
4776
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5013
4777
|
"Transfer amount must be a positive number."
|
@@ -5026,37 +4790,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5026
4790
|
* @returns A promise that resolves to the transaction response.
|
5027
4791
|
*/
|
5028
4792
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5029
|
-
if ((0,
|
4793
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5030
4794
|
throw new import_errors16.FuelError(
|
5031
4795
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5032
4796
|
"Transfer amount must be a positive number."
|
5033
4797
|
);
|
5034
4798
|
}
|
5035
4799
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4800
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4801
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5036
4802
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5037
4803
|
hexlifiedContractId: contractAddress.toB256(),
|
5038
|
-
amountToTransfer: (0,
|
4804
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5039
4805
|
assetId
|
5040
4806
|
});
|
5041
4807
|
const request = new ScriptTransactionRequest({
|
5042
|
-
...
|
4808
|
+
...params,
|
5043
4809
|
script,
|
5044
4810
|
scriptData
|
5045
4811
|
});
|
5046
4812
|
request.addContractInputAndOutput(contractAddress);
|
5047
|
-
const
|
5048
|
-
|
5049
|
-
|
4813
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4814
|
+
request,
|
4815
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4816
|
+
);
|
4817
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4818
|
+
this.validateGas({
|
4819
|
+
gasUsed,
|
4820
|
+
gasPrice: request.gasPrice,
|
4821
|
+
gasLimit: request.gasLimit,
|
4822
|
+
minGasPrice
|
5050
4823
|
});
|
5051
|
-
|
5052
|
-
this.validateGas({
|
5053
|
-
gasUsed: txCost.gasUsed,
|
5054
|
-
gasLimit: request.gasLimit
|
5055
|
-
});
|
5056
|
-
}
|
5057
|
-
request.gasLimit = txCost.gasUsed;
|
5058
|
-
request.maxFee = txCost.maxFee;
|
5059
|
-
await this.fund(request, txCost);
|
4824
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5060
4825
|
return this.sendTransaction(request);
|
5061
4826
|
}
|
5062
4827
|
/**
|
@@ -5068,31 +4833,34 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5068
4833
|
* @returns A promise that resolves to the transaction response.
|
5069
4834
|
*/
|
5070
4835
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4836
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5071
4837
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5072
|
-
const recipientDataArray = (0,
|
4838
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5073
4839
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5074
4840
|
);
|
5075
|
-
const amountDataArray = (0,
|
5076
|
-
"0x".concat((0,
|
4841
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4842
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5077
4843
|
);
|
5078
4844
|
const script = new Uint8Array([
|
5079
|
-
...(0,
|
4845
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5080
4846
|
...recipientDataArray,
|
5081
4847
|
...amountDataArray
|
5082
4848
|
]);
|
5083
|
-
const params = { script, ...txParams };
|
4849
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5084
4850
|
const request = new ScriptTransactionRequest(params);
|
5085
|
-
const
|
5086
|
-
const
|
5087
|
-
|
5088
|
-
|
5089
|
-
|
5090
|
-
|
5091
|
-
|
5092
|
-
|
5093
|
-
|
5094
|
-
|
5095
|
-
|
4851
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4852
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4853
|
+
request,
|
4854
|
+
forwardingQuantities
|
4855
|
+
);
|
4856
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4857
|
+
this.validateGas({
|
4858
|
+
gasUsed,
|
4859
|
+
gasPrice: request.gasPrice,
|
4860
|
+
gasLimit: request.gasLimit,
|
4861
|
+
minGasPrice
|
4862
|
+
});
|
4863
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5096
4864
|
return this.sendTransaction(request);
|
5097
4865
|
}
|
5098
4866
|
async signMessage(message) {
|
@@ -5150,7 +4918,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5150
4918
|
}
|
5151
4919
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5152
4920
|
}
|
5153
|
-
validateGas({
|
4921
|
+
validateGas({
|
4922
|
+
gasUsed,
|
4923
|
+
gasPrice,
|
4924
|
+
gasLimit,
|
4925
|
+
minGasPrice
|
4926
|
+
}) {
|
4927
|
+
if (minGasPrice.gt(gasPrice)) {
|
4928
|
+
throw new import_errors16.FuelError(
|
4929
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4930
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4931
|
+
);
|
4932
|
+
}
|
5154
4933
|
if (gasUsed.gt(gasLimit)) {
|
5155
4934
|
throw new import_errors16.FuelError(
|
5156
4935
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5164,8 +4943,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5164
4943
|
var import_address5 = require("@fuel-ts/address");
|
5165
4944
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5166
4945
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5167
|
-
var
|
5168
|
-
var
|
4946
|
+
var import_math19 = require("@fuel-ts/math");
|
4947
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5169
4948
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5170
4949
|
var Signer = class {
|
5171
4950
|
address;
|
@@ -5184,10 +4963,10 @@ var Signer = class {
|
|
5184
4963
|
privateKey = `0x${privateKey}`;
|
5185
4964
|
}
|
5186
4965
|
}
|
5187
|
-
const privateKeyBytes = (0,
|
5188
|
-
this.privateKey = (0,
|
5189
|
-
this.publicKey = (0,
|
5190
|
-
this.compressedPublicKey = (0,
|
4966
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4967
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4968
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4969
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5191
4970
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5192
4971
|
}
|
5193
4972
|
/**
|
@@ -5201,11 +4980,11 @@ var Signer = class {
|
|
5201
4980
|
* @returns hashed signature
|
5202
4981
|
*/
|
5203
4982
|
sign(data) {
|
5204
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5205
|
-
const r = (0,
|
5206
|
-
const s = (0,
|
4983
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4984
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4985
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5207
4986
|
s[0] |= (signature.recovery || 0) << 7;
|
5208
|
-
return (0,
|
4987
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5209
4988
|
}
|
5210
4989
|
/**
|
5211
4990
|
* Add point on the current elliptic curve
|
@@ -5214,8 +4993,8 @@ var Signer = class {
|
|
5214
4993
|
* @returns compressed point on the curve
|
5215
4994
|
*/
|
5216
4995
|
addPoint(point) {
|
5217
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5218
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4996
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4997
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5219
4998
|
const result = p0.add(p1);
|
5220
4999
|
return `0x${result.toHex(true)}`;
|
5221
5000
|
}
|
@@ -5227,16 +5006,16 @@ var Signer = class {
|
|
5227
5006
|
* @returns public key from signature from the
|
5228
5007
|
*/
|
5229
5008
|
static recoverPublicKey(data, signature) {
|
5230
|
-
const signedMessageBytes = (0,
|
5009
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5231
5010
|
const r = signedMessageBytes.slice(0, 32);
|
5232
5011
|
const s = signedMessageBytes.slice(32, 64);
|
5233
5012
|
const recoveryParam = (s[0] & 128) >> 7;
|
5234
5013
|
s[0] &= 127;
|
5235
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5014
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5236
5015
|
recoveryParam
|
5237
5016
|
);
|
5238
|
-
const publicKey = sig.recoverPublicKey((0,
|
5239
|
-
return (0,
|
5017
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5018
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5240
5019
|
}
|
5241
5020
|
/**
|
5242
5021
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5255,7 +5034,7 @@ var Signer = class {
|
|
5255
5034
|
* @returns random 32-byte hashed
|
5256
5035
|
*/
|
5257
5036
|
static generatePrivateKey(entropy) {
|
5258
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5037
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5259
5038
|
}
|
5260
5039
|
/**
|
5261
5040
|
* Extended publicKey from a compact publicKey
|
@@ -5264,8 +5043,8 @@ var Signer = class {
|
|
5264
5043
|
* @returns extended publicKey
|
5265
5044
|
*/
|
5266
5045
|
static extendPublicKey(publicKey) {
|
5267
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5268
|
-
return (0,
|
5046
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5047
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5269
5048
|
}
|
5270
5049
|
};
|
5271
5050
|
|
@@ -5273,7 +5052,7 @@ var Signer = class {
|
|
5273
5052
|
var import_address6 = require("@fuel-ts/address");
|
5274
5053
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5275
5054
|
var import_errors17 = require("@fuel-ts/errors");
|
5276
|
-
var
|
5055
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5277
5056
|
var import_uuid = require("uuid");
|
5278
5057
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5279
5058
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5356,7 +5135,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5356
5135
|
);
|
5357
5136
|
}
|
5358
5137
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5359
|
-
const privateKey = (0,
|
5138
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5360
5139
|
return privateKey;
|
5361
5140
|
}
|
5362
5141
|
|
@@ -5401,7 +5180,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5401
5180
|
*/
|
5402
5181
|
async signMessage(message) {
|
5403
5182
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5404
|
-
return (0,
|
5183
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5405
5184
|
}
|
5406
5185
|
/**
|
5407
5186
|
* Signs a transaction with the wallet's private key.
|
@@ -5414,7 +5193,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5414
5193
|
const chainId = this.provider.getChainId();
|
5415
5194
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5416
5195
|
const signature = await this.signer().sign(hashedTransaction);
|
5417
|
-
return (0,
|
5196
|
+
return (0, import_utils31.hexlify)(signature);
|
5418
5197
|
}
|
5419
5198
|
/**
|
5420
5199
|
* Populates a transaction with the witnesses signature.
|
@@ -5434,7 +5213,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5434
5213
|
* @param transactionRequestLike - The transaction request to send.
|
5435
5214
|
* @returns A promise that resolves to the TransactionResponse object.
|
5436
5215
|
*/
|
5437
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5216
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5438
5217
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5439
5218
|
if (estimateTxDependencies) {
|
5440
5219
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5475,15 +5254,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5475
5254
|
// src/hdwallet/hdwallet.ts
|
5476
5255
|
var import_errors20 = require("@fuel-ts/errors");
|
5477
5256
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5478
|
-
var
|
5479
|
-
var
|
5257
|
+
var import_math20 = require("@fuel-ts/math");
|
5258
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5480
5259
|
var import_ethers3 = require("ethers");
|
5481
5260
|
|
5482
5261
|
// src/mnemonic/mnemonic.ts
|
5483
5262
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5484
5263
|
var import_errors19 = require("@fuel-ts/errors");
|
5485
5264
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5486
|
-
var
|
5265
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5487
5266
|
var import_ethers2 = require("ethers");
|
5488
5267
|
|
5489
5268
|
// src/wordlists/words/english.ts
|
@@ -7541,7 +7320,7 @@ var english = [
|
|
7541
7320
|
// src/mnemonic/utils.ts
|
7542
7321
|
var import_errors18 = require("@fuel-ts/errors");
|
7543
7322
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7544
|
-
var
|
7323
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7545
7324
|
function toUtf8Bytes(stri) {
|
7546
7325
|
const str = stri.normalize("NFKD");
|
7547
7326
|
const result = [];
|
@@ -7608,14 +7387,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7608
7387
|
}
|
7609
7388
|
}
|
7610
7389
|
const checksumBits = entropy.length / 4;
|
7611
|
-
const checksum = (0,
|
7390
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7612
7391
|
indices[indices.length - 1] <<= checksumBits;
|
7613
7392
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7614
7393
|
return indices;
|
7615
7394
|
}
|
7616
7395
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7617
7396
|
const size = Math.ceil(11 * words.length / 8);
|
7618
|
-
const entropy = (0,
|
7397
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7619
7398
|
let offset = 0;
|
7620
7399
|
for (let i = 0; i < words.length; i += 1) {
|
7621
7400
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7635,7 +7414,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7635
7414
|
const entropyBits = 32 * words.length / 3;
|
7636
7415
|
const checksumBits = words.length / 3;
|
7637
7416
|
const checksumMask = getUpperMask(checksumBits);
|
7638
|
-
const checksum = (0,
|
7417
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7639
7418
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7640
7419
|
throw new import_errors18.FuelError(
|
7641
7420
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7710,7 +7489,7 @@ var Mnemonic = class {
|
|
7710
7489
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7711
7490
|
const words = getWords(phrase);
|
7712
7491
|
assertMnemonic(words);
|
7713
|
-
return (0,
|
7492
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7714
7493
|
}
|
7715
7494
|
/**
|
7716
7495
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7718,7 +7497,7 @@ var Mnemonic = class {
|
|
7718
7497
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7719
7498
|
*/
|
7720
7499
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7721
|
-
const entropyBytes = (0,
|
7500
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7722
7501
|
assertWordList(wordlist);
|
7723
7502
|
assertEntropy(entropyBytes);
|
7724
7503
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7787,14 +7566,14 @@ var Mnemonic = class {
|
|
7787
7566
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7788
7567
|
*/
|
7789
7568
|
static masterKeysFromSeed(seed) {
|
7790
|
-
const seedArray = (0,
|
7569
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7791
7570
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7792
7571
|
throw new import_errors19.FuelError(
|
7793
7572
|
import_errors19.ErrorCode.INVALID_SEED,
|
7794
7573
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7795
7574
|
);
|
7796
7575
|
}
|
7797
|
-
return (0,
|
7576
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7798
7577
|
}
|
7799
7578
|
/**
|
7800
7579
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7805,22 +7584,22 @@ var Mnemonic = class {
|
|
7805
7584
|
*/
|
7806
7585
|
static seedToExtendedKey(seed, testnet = false) {
|
7807
7586
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7808
|
-
const prefix = (0,
|
7587
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7809
7588
|
const depth = "0x00";
|
7810
7589
|
const fingerprint = "0x00000000";
|
7811
7590
|
const index = "0x00000000";
|
7812
7591
|
const chainCode = masterKey.slice(32);
|
7813
7592
|
const privateKey = masterKey.slice(0, 32);
|
7814
|
-
const extendedKey = (0,
|
7593
|
+
const extendedKey = (0, import_utils33.concat)([
|
7815
7594
|
prefix,
|
7816
7595
|
depth,
|
7817
7596
|
fingerprint,
|
7818
7597
|
index,
|
7819
7598
|
chainCode,
|
7820
|
-
(0,
|
7599
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7821
7600
|
]);
|
7822
7601
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7823
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7602
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7824
7603
|
}
|
7825
7604
|
/**
|
7826
7605
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7835,7 +7614,7 @@ var Mnemonic = class {
|
|
7835
7614
|
* @returns A randomly generated mnemonic
|
7836
7615
|
*/
|
7837
7616
|
static generate(size = 32, extraEntropy = "") {
|
7838
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7617
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7839
7618
|
return Mnemonic.entropyToMnemonic(entropy);
|
7840
7619
|
}
|
7841
7620
|
};
|
@@ -7843,12 +7622,12 @@ var mnemonic_default = Mnemonic;
|
|
7843
7622
|
|
7844
7623
|
// src/hdwallet/hdwallet.ts
|
7845
7624
|
var HARDENED_INDEX = 2147483648;
|
7846
|
-
var MainnetPRV2 = (0,
|
7847
|
-
var MainnetPUB = (0,
|
7848
|
-
var TestnetPRV2 = (0,
|
7849
|
-
var TestnetPUB = (0,
|
7625
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7626
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7627
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7628
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7850
7629
|
function base58check(data) {
|
7851
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7630
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7852
7631
|
}
|
7853
7632
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7854
7633
|
if (isPublic) {
|
@@ -7857,11 +7636,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7857
7636
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7858
7637
|
}
|
7859
7638
|
function isPublicExtendedKey(extendedKey) {
|
7860
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7639
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7861
7640
|
}
|
7862
7641
|
function isValidExtendedKey(extendedKey) {
|
7863
7642
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7864
|
-
(0,
|
7643
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7865
7644
|
);
|
7866
7645
|
}
|
7867
7646
|
function parsePath(path2, depth = 0) {
|
@@ -7879,8 +7658,8 @@ function parsePath(path2, depth = 0) {
|
|
7879
7658
|
var HDWallet = class {
|
7880
7659
|
depth = 0;
|
7881
7660
|
index = 0;
|
7882
|
-
fingerprint = (0,
|
7883
|
-
parentFingerprint = (0,
|
7661
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7662
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7884
7663
|
privateKey;
|
7885
7664
|
publicKey;
|
7886
7665
|
chainCode;
|
@@ -7892,8 +7671,8 @@ var HDWallet = class {
|
|
7892
7671
|
constructor(config) {
|
7893
7672
|
if (config.privateKey) {
|
7894
7673
|
const signer = new Signer(config.privateKey);
|
7895
|
-
this.publicKey = (0,
|
7896
|
-
this.privateKey = (0,
|
7674
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7675
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7897
7676
|
} else {
|
7898
7677
|
if (!config.publicKey) {
|
7899
7678
|
throw new import_errors20.FuelError(
|
@@ -7901,7 +7680,7 @@ var HDWallet = class {
|
|
7901
7680
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7902
7681
|
);
|
7903
7682
|
}
|
7904
|
-
this.publicKey = (0,
|
7683
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7905
7684
|
}
|
7906
7685
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7907
7686
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7920,9 +7699,9 @@ var HDWallet = class {
|
|
7920
7699
|
* @returns A new instance of HDWallet on the derived index
|
7921
7700
|
*/
|
7922
7701
|
deriveIndex(index) {
|
7923
|
-
const privateKey = this.privateKey && (0,
|
7924
|
-
const publicKey = (0,
|
7925
|
-
const chainCode = (0,
|
7702
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7703
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7704
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7926
7705
|
const data = new Uint8Array(37);
|
7927
7706
|
if (index & HARDENED_INDEX) {
|
7928
7707
|
if (!privateKey) {
|
@@ -7933,15 +7712,15 @@ var HDWallet = class {
|
|
7933
7712
|
}
|
7934
7713
|
data.set(privateKey, 1);
|
7935
7714
|
} else {
|
7936
|
-
data.set((0,
|
7715
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7937
7716
|
}
|
7938
|
-
data.set((0,
|
7939
|
-
const bytes = (0,
|
7717
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7718
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7940
7719
|
const IL = bytes.slice(0, 32);
|
7941
7720
|
const IR = bytes.slice(32);
|
7942
7721
|
if (privateKey) {
|
7943
7722
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7944
|
-
const ki = (0,
|
7723
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7945
7724
|
return new HDWallet({
|
7946
7725
|
privateKey: ki,
|
7947
7726
|
chainCode: IR,
|
@@ -7950,7 +7729,7 @@ var HDWallet = class {
|
|
7950
7729
|
parentFingerprint: this.fingerprint
|
7951
7730
|
});
|
7952
7731
|
}
|
7953
|
-
const signer = new Signer((0,
|
7732
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7954
7733
|
const Ki = signer.addPoint(publicKey);
|
7955
7734
|
return new HDWallet({
|
7956
7735
|
publicKey: Ki,
|
@@ -7985,12 +7764,12 @@ var HDWallet = class {
|
|
7985
7764
|
);
|
7986
7765
|
}
|
7987
7766
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7988
|
-
const depth = (0,
|
7767
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7989
7768
|
const parentFingerprint = this.parentFingerprint;
|
7990
|
-
const index = (0,
|
7769
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7991
7770
|
const chainCode = this.chainCode;
|
7992
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7993
|
-
const extendedKey = (0,
|
7771
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7772
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7994
7773
|
return base58check(extendedKey);
|
7995
7774
|
}
|
7996
7775
|
/**
|
@@ -8002,13 +7781,13 @@ var HDWallet = class {
|
|
8002
7781
|
static fromSeed(seed) {
|
8003
7782
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8004
7783
|
return new HDWallet({
|
8005
|
-
chainCode: (0,
|
8006
|
-
privateKey: (0,
|
7784
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7785
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8007
7786
|
});
|
8008
7787
|
}
|
8009
7788
|
static fromExtendedKey(extendedKey) {
|
8010
7789
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8011
|
-
const bytes = (0,
|
7790
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8012
7791
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8013
7792
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8014
7793
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8017,9 +7796,9 @@ var HDWallet = class {
|
|
8017
7796
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8018
7797
|
}
|
8019
7798
|
const depth = bytes[4];
|
8020
|
-
const parentFingerprint = (0,
|
8021
|
-
const index = parseInt((0,
|
8022
|
-
const chainCode = (0,
|
7799
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7800
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7801
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8023
7802
|
const key = bytes.slice(45, 78);
|
8024
7803
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8025
7804
|
throw new import_errors20.FuelError(
|
@@ -8207,20 +7986,26 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8207
7986
|
|
8208
7987
|
// src/test-utils/seedTestWallet.ts
|
8209
7988
|
var import_crypto5 = require("@fuel-ts/crypto");
|
8210
|
-
var seedTestWallet = async (wallet, quantities) => {
|
7989
|
+
var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
|
7990
|
+
const toFundAccounts = Array.isArray(wallet) ? wallet : [wallet];
|
8211
7991
|
const genesisWallet = new WalletUnlocked(
|
8212
7992
|
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
8213
|
-
|
7993
|
+
toFundAccounts[0].provider
|
8214
7994
|
);
|
8215
|
-
const
|
8216
|
-
|
8217
|
-
|
8218
|
-
|
7995
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7996
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7997
|
+
const request = new ScriptTransactionRequest({
|
7998
|
+
gasLimit: 1e4,
|
7999
|
+
gasPrice: minGasPrice
|
8219
8000
|
});
|
8220
|
-
|
8221
|
-
|
8222
|
-
|
8223
|
-
|
8001
|
+
request.addResources(resources);
|
8002
|
+
quantities.map(coinQuantityfy).forEach(
|
8003
|
+
({ amount, assetId }) => toFundAccounts.forEach(({ address }) => {
|
8004
|
+
for (let i = 0; i < utxosAmount; i++) {
|
8005
|
+
request.addCoinOutput(address, amount.div(utxosAmount), assetId);
|
8006
|
+
}
|
8007
|
+
})
|
8008
|
+
);
|
8224
8009
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8225
8010
|
};
|
8226
8011
|
|
@@ -8235,11 +8020,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8235
8020
|
|
8236
8021
|
// src/test-utils/launchNode.ts
|
8237
8022
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8238
|
-
var
|
8023
|
+
var import_math21 = require("@fuel-ts/math");
|
8024
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8239
8025
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8240
8026
|
var import_child_process = require("child_process");
|
8241
8027
|
var import_crypto6 = require("crypto");
|
8242
|
-
var import_ethers4 = require("ethers");
|
8243
8028
|
var import_fs = require("fs");
|
8244
8029
|
var import_os = __toESM(require("os"));
|
8245
8030
|
var import_path = __toESM(require("path"));
|
@@ -8288,13 +8073,13 @@ var launchNode = async ({
|
|
8288
8073
|
// eslint-disable-next-line no-async-promise-executor
|
8289
8074
|
new Promise(async (resolve, reject) => {
|
8290
8075
|
const remainingArgs = extractRemainingArgs(args, [
|
8291
|
-
"--
|
8076
|
+
"--chain",
|
8292
8077
|
"--consensus-key",
|
8293
8078
|
"--db-type",
|
8294
8079
|
"--poa-instant"
|
8295
8080
|
]);
|
8296
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8297
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8081
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8082
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8298
8083
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8299
8084
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8300
8085
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8312,54 +8097,36 @@ var launchNode = async ({
|
|
8312
8097
|
let chainConfigPathToUse;
|
8313
8098
|
const prefix = basePath || import_os.default.tmpdir();
|
8314
8099
|
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8315
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix
|
8100
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8316
8101
|
if (chainConfigPath) {
|
8317
8102
|
chainConfigPathToUse = chainConfigPath;
|
8318
8103
|
} else {
|
8319
8104
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8320
8105
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8321
8106
|
}
|
8322
|
-
|
8323
|
-
|
8324
|
-
stateConfigJson = {
|
8325
|
-
...stateConfigJson,
|
8326
|
-
coins: [
|
8327
|
-
...stateConfigJson.coins.map((coin) => ({
|
8328
|
-
...coin,
|
8329
|
-
amount: "18446744073709551615"
|
8330
|
-
}))
|
8331
|
-
],
|
8332
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8333
|
-
...message,
|
8334
|
-
amount: "18446744073709551615"
|
8335
|
-
}))
|
8336
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8337
|
-
};
|
8107
|
+
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8108
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8338
8109
|
if (!process.env.GENESIS_SECRET) {
|
8339
8110
|
const pk = Signer.generatePrivateKey();
|
8340
8111
|
const signer = new Signer(pk);
|
8341
|
-
process.env.GENESIS_SECRET = (0,
|
8342
|
-
|
8343
|
-
|
8344
|
-
|
8345
|
-
|
8346
|
-
|
8347
|
-
|
8348
|
-
|
8349
|
-
|
8350
|
-
|
8351
|
-
|
8112
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8113
|
+
chainConfig = {
|
8114
|
+
...import_utils36.defaultChainConfig,
|
8115
|
+
initial_state: {
|
8116
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8117
|
+
coins: [
|
8118
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8119
|
+
{
|
8120
|
+
owner: signer.address.toHexString(),
|
8121
|
+
amount: (0, import_math21.toHex)(1e9),
|
8122
|
+
asset_id: import_configs13.BaseAssetId
|
8123
|
+
}
|
8124
|
+
]
|
8125
|
+
}
|
8126
|
+
};
|
8352
8127
|
}
|
8353
|
-
|
8354
|
-
|
8355
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8356
|
-
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8357
|
-
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8358
|
-
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8359
|
-
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8360
|
-
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8361
|
-
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8362
|
-
chainConfigPathToUse = tempDirPath;
|
8128
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8129
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8363
8130
|
}
|
8364
8131
|
const child = (0, import_child_process.spawn)(
|
8365
8132
|
command,
|
@@ -8368,10 +8135,10 @@ var launchNode = async ({
|
|
8368
8135
|
["--ip", ipToUse],
|
8369
8136
|
["--port", portToUse],
|
8370
8137
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8371
|
-
["--min-gas-price", "
|
8138
|
+
["--min-gas-price", "0"],
|
8372
8139
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8373
8140
|
["--consensus-key", consensusKey],
|
8374
|
-
["--
|
8141
|
+
["--chain", chainConfigPathToUse],
|
8375
8142
|
"--vm-backtrace",
|
8376
8143
|
"--utxo-validation",
|
8377
8144
|
"--debug",
|
@@ -8430,15 +8197,52 @@ var launchNodeAndGetWallets = async ({
|
|
8430
8197
|
walletCount = 10
|
8431
8198
|
} = {}) => {
|
8432
8199
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8433
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8200
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8434
8201
|
const wallets = await generateWallets(walletCount, provider);
|
8435
8202
|
const cleanup = () => {
|
8436
8203
|
closeNode();
|
8437
8204
|
};
|
8438
8205
|
return { wallets, stop: cleanup, provider };
|
8439
8206
|
};
|
8207
|
+
|
8208
|
+
// src/test-utils/transactionRequest.ts
|
8209
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8210
|
+
var import_address7 = require("@fuel-ts/address");
|
8211
|
+
var import_configs14 = require("@fuel-ts/address/configs");
|
8212
|
+
var import_crypto7 = require("@fuel-ts/crypto");
|
8213
|
+
var import_math22 = require("@fuel-ts/math");
|
8214
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
8215
|
+
var import_utils37 = require("@fuel-ts/utils");
|
8216
|
+
var generateFakeRequestInputCoin = (partial = {}) => ({
|
8217
|
+
id: (0, import_utils37.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8218
|
+
type: import_transactions21.InputType.Coin,
|
8219
|
+
owner: (0, import_address7.getRandomB256)(),
|
8220
|
+
amount: (0, import_math22.bn)(100),
|
8221
|
+
assetId: import_configs14.ZeroBytes32,
|
8222
|
+
txPointer: "0x00000000000000000000000000000000",
|
8223
|
+
witnessIndex: 0,
|
8224
|
+
...partial
|
8225
|
+
});
|
8226
|
+
var generateFakeRequestInputMessage = (partial = {}) => ({
|
8227
|
+
nonce: (0, import_address7.getRandomB256)(),
|
8228
|
+
type: import_transactions21.InputType.Message,
|
8229
|
+
sender: (0, import_address7.getRandomB256)(),
|
8230
|
+
recipient: (0, import_address7.getRandomB256)(),
|
8231
|
+
amount: (0, import_math22.bn)(100),
|
8232
|
+
witnessIndex: 0,
|
8233
|
+
...partial
|
8234
|
+
});
|
8235
|
+
var generateFakeRequestInputContract = (partial = {}) => ({
|
8236
|
+
contractId: (0, import_address7.getRandomB256)(),
|
8237
|
+
type: import_transactions21.InputType.Contract,
|
8238
|
+
txPointer: "0x00000000000000000000000000000000",
|
8239
|
+
...partial
|
8240
|
+
});
|
8440
8241
|
// Annotate the CommonJS export names for ESM import in node:
|
8441
8242
|
0 && (module.exports = {
|
8243
|
+
generateFakeRequestInputCoin,
|
8244
|
+
generateFakeRequestInputContract,
|
8245
|
+
generateFakeRequestInputMessage,
|
8442
8246
|
generateTestWallet,
|
8443
8247
|
killNode,
|
8444
8248
|
launchNode,
|