@fuel-ts/account 0.0.0-rc-2021-20240408141516 → 0.0.0-rc-1976-20240409133547
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 +619 -869
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +609 -845
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +452 -687
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +328 -894
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -45
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +29 -9
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1120 -1584
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +606 -821
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +464 -679
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/test-utils.mjs
CHANGED
@@ -24,38 +24,35 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
29
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
31
30
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
|
-
import { clone as clone4 } from "ramda";
|
33
31
|
|
34
32
|
// src/providers/coin-quantity.ts
|
35
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
36
33
|
import { bn } from "@fuel-ts/math";
|
37
34
|
import { hexlify } from "@fuel-ts/utils";
|
38
35
|
var coinQuantityfy = (coinQuantityLike) => {
|
39
36
|
let assetId;
|
40
37
|
let amount;
|
41
|
-
let
|
38
|
+
let max2;
|
42
39
|
if (Array.isArray(coinQuantityLike)) {
|
43
40
|
amount = coinQuantityLike[0];
|
44
|
-
assetId = coinQuantityLike[1]
|
45
|
-
|
41
|
+
assetId = coinQuantityLike[1];
|
42
|
+
max2 = coinQuantityLike[2];
|
46
43
|
} else {
|
47
44
|
amount = coinQuantityLike.amount;
|
48
|
-
assetId = coinQuantityLike.assetId
|
49
|
-
|
45
|
+
assetId = coinQuantityLike.assetId;
|
46
|
+
max2 = coinQuantityLike.max ?? void 0;
|
50
47
|
}
|
51
48
|
const bnAmount = bn(amount);
|
52
49
|
return {
|
53
50
|
assetId: hexlify(assetId),
|
54
51
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
55
|
-
max:
|
52
|
+
max: max2 ? bn(max2) : void 0
|
56
53
|
};
|
57
54
|
};
|
58
|
-
var
|
55
|
+
var addAmountToAsset = (params) => {
|
59
56
|
const { amount, assetId } = params;
|
60
57
|
const coinQuantities = [...params.coinQuantities];
|
61
58
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -70,9 +67,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
70
67
|
// src/providers/provider.ts
|
71
68
|
import { Address as Address2 } from "@fuel-ts/address";
|
72
69
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
73
|
-
import { BN, bn as
|
70
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
74
71
|
import {
|
75
|
-
InputType as
|
72
|
+
InputType as InputType6,
|
76
73
|
TransactionType as TransactionType8,
|
77
74
|
InputMessageCoder,
|
78
75
|
TransactionCoder as TransactionCoder5
|
@@ -88,10 +85,14 @@ import { clone as clone3 } from "ramda";
|
|
88
85
|
import gql from "graphql-tag";
|
89
86
|
var ReceiptFragmentFragmentDoc = gql`
|
90
87
|
fragment receiptFragment on Receipt {
|
91
|
-
|
88
|
+
contract {
|
89
|
+
id
|
90
|
+
}
|
92
91
|
pc
|
93
92
|
is
|
94
|
-
to
|
93
|
+
to {
|
94
|
+
id
|
95
|
+
}
|
95
96
|
toAddress
|
96
97
|
amount
|
97
98
|
assetId
|
@@ -129,16 +130,10 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
129
130
|
id
|
130
131
|
}
|
131
132
|
time
|
132
|
-
receipts {
|
133
|
-
...receiptFragment
|
134
|
-
}
|
135
133
|
programState {
|
136
134
|
returnType
|
137
135
|
data
|
138
136
|
}
|
139
|
-
receipts {
|
140
|
-
...receiptFragment
|
141
|
-
}
|
142
137
|
}
|
143
138
|
... on FailureStatus {
|
144
139
|
block {
|
@@ -146,24 +141,26 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
146
141
|
}
|
147
142
|
time
|
148
143
|
reason
|
149
|
-
receipts {
|
150
|
-
...receiptFragment
|
151
|
-
}
|
152
144
|
}
|
153
145
|
... on SqueezedOutStatus {
|
154
146
|
reason
|
155
147
|
}
|
156
148
|
}
|
157
|
-
|
149
|
+
`;
|
158
150
|
var TransactionFragmentFragmentDoc = gql`
|
159
151
|
fragment transactionFragment on Transaction {
|
160
152
|
id
|
161
153
|
rawPayload
|
154
|
+
gasPrice
|
155
|
+
receipts {
|
156
|
+
...receiptFragment
|
157
|
+
}
|
162
158
|
status {
|
163
159
|
...transactionStatusFragment
|
164
160
|
}
|
165
161
|
}
|
166
|
-
${
|
162
|
+
${ReceiptFragmentFragmentDoc}
|
163
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
167
164
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
168
165
|
fragment inputEstimatePredicatesFragment on Input {
|
169
166
|
... on InputCoin {
|
@@ -181,46 +178,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
181
178
|
}
|
182
179
|
}
|
183
180
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
184
|
-
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
185
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
186
|
-
reason
|
187
|
-
programState {
|
188
|
-
returnType
|
189
|
-
data
|
190
|
-
}
|
191
|
-
}
|
192
|
-
`;
|
193
|
-
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
194
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
195
|
-
programState {
|
196
|
-
returnType
|
197
|
-
data
|
198
|
-
}
|
199
|
-
}
|
200
|
-
`;
|
201
|
-
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
202
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
203
|
-
... on DryRunFailureStatus {
|
204
|
-
...dryRunFailureStatusFragment
|
205
|
-
}
|
206
|
-
... on DryRunSuccessStatus {
|
207
|
-
...dryRunSuccessStatusFragment
|
208
|
-
}
|
209
|
-
}
|
210
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
211
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
212
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
213
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
214
|
-
id
|
215
|
-
status {
|
216
|
-
...dryRunTransactionStatusFragment
|
217
|
-
}
|
218
|
-
receipts {
|
219
|
-
...receiptFragment
|
220
|
-
}
|
221
|
-
}
|
222
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
223
|
-
${ReceiptFragmentFragmentDoc}`;
|
224
181
|
var CoinFragmentFragmentDoc = gql`
|
225
182
|
fragment coinFragment on Coin {
|
226
183
|
__typename
|
@@ -228,6 +185,7 @@ var CoinFragmentFragmentDoc = gql`
|
|
228
185
|
owner
|
229
186
|
amount
|
230
187
|
assetId
|
188
|
+
maturity
|
231
189
|
blockCreated
|
232
190
|
txCreatedIdx
|
233
191
|
}
|
@@ -272,6 +230,7 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
272
230
|
prevRoot
|
273
231
|
time
|
274
232
|
applicationHash
|
233
|
+
messageReceiptRoot
|
275
234
|
messageReceiptCount
|
276
235
|
}
|
277
236
|
commitBlockHeader {
|
@@ -283,6 +242,7 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
283
242
|
prevRoot
|
284
243
|
time
|
285
244
|
applicationHash
|
245
|
+
messageReceiptRoot
|
286
246
|
messageReceiptCount
|
287
247
|
}
|
288
248
|
sender
|
@@ -302,8 +262,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
302
262
|
var BlockFragmentFragmentDoc = gql`
|
303
263
|
fragment blockFragment on Block {
|
304
264
|
id
|
305
|
-
height
|
306
265
|
header {
|
266
|
+
height
|
307
267
|
time
|
308
268
|
}
|
309
269
|
transactions {
|
@@ -361,11 +321,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
361
321
|
`;
|
362
322
|
var GasCostsFragmentFragmentDoc = gql`
|
363
323
|
fragment GasCostsFragment on GasCosts {
|
364
|
-
version {
|
365
|
-
... on Version {
|
366
|
-
value
|
367
|
-
}
|
368
|
-
}
|
369
324
|
add
|
370
325
|
addi
|
371
326
|
aloc
|
@@ -378,6 +333,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
378
333
|
cb
|
379
334
|
cfei
|
380
335
|
cfsi
|
336
|
+
croo
|
381
337
|
div
|
382
338
|
divi
|
383
339
|
ecr1
|
@@ -460,9 +416,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
460
416
|
ccp {
|
461
417
|
...DependentCostFragment
|
462
418
|
}
|
463
|
-
croo {
|
464
|
-
...DependentCostFragment
|
465
|
-
}
|
466
419
|
csiz {
|
467
420
|
...DependentCostFragment
|
468
421
|
}
|
@@ -522,11 +475,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
522
475
|
${DependentCostFragmentFragmentDoc}`;
|
523
476
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
524
477
|
fragment consensusParametersFragment on ConsensusParameters {
|
525
|
-
version {
|
526
|
-
... on Version {
|
527
|
-
value
|
528
|
-
}
|
529
|
-
}
|
530
478
|
txParams {
|
531
479
|
...TxParametersFragment
|
532
480
|
}
|
@@ -586,9 +534,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
586
534
|
fragment nodeInfoFragment on NodeInfo {
|
587
535
|
utxoValidation
|
588
536
|
vmBacktrace
|
537
|
+
minGasPrice
|
589
538
|
maxTx
|
590
539
|
maxDepth
|
591
540
|
nodeVersion
|
541
|
+
peers {
|
542
|
+
id
|
543
|
+
addresses
|
544
|
+
clientVersion
|
545
|
+
blockHeight
|
546
|
+
lastHeartbeatMs
|
547
|
+
appScore
|
548
|
+
}
|
592
549
|
}
|
593
550
|
`;
|
594
551
|
var GetVersionDocument = gql`
|
@@ -623,9 +580,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
623
580
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
624
581
|
transaction(id: $transactionId) {
|
625
582
|
...transactionFragment
|
583
|
+
receipts {
|
584
|
+
...receiptFragment
|
585
|
+
}
|
626
586
|
}
|
627
587
|
}
|
628
|
-
${TransactionFragmentFragmentDoc}
|
588
|
+
${TransactionFragmentFragmentDoc}
|
589
|
+
${ReceiptFragmentFragmentDoc}`;
|
629
590
|
var GetTransactionsDocument = gql`
|
630
591
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
631
592
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -753,20 +714,6 @@ var GetBalanceDocument = gql`
|
|
753
714
|
}
|
754
715
|
}
|
755
716
|
${BalanceFragmentFragmentDoc}`;
|
756
|
-
var GetLatestGasPriceDocument = gql`
|
757
|
-
query getLatestGasPrice {
|
758
|
-
latestGasPrice {
|
759
|
-
gasPrice
|
760
|
-
}
|
761
|
-
}
|
762
|
-
`;
|
763
|
-
var EstimateGasPriceDocument = gql`
|
764
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
765
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
766
|
-
gasPrice
|
767
|
-
}
|
768
|
-
}
|
769
|
-
`;
|
770
717
|
var GetBalancesDocument = gql`
|
771
718
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
772
719
|
balances(
|
@@ -821,12 +768,12 @@ var GetMessageStatusDocument = gql`
|
|
821
768
|
}
|
822
769
|
`;
|
823
770
|
var DryRunDocument = gql`
|
824
|
-
mutation dryRun($
|
825
|
-
dryRun(
|
826
|
-
...
|
771
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
772
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
773
|
+
...receiptFragment
|
827
774
|
}
|
828
775
|
}
|
829
|
-
${
|
776
|
+
${ReceiptFragmentFragmentDoc}`;
|
830
777
|
var SubmitDocument = gql`
|
831
778
|
mutation submit($encodedTransaction: HexString!) {
|
832
779
|
submit(tx: $encodedTransaction) {
|
@@ -909,12 +856,6 @@ function getSdk(requester) {
|
|
909
856
|
getBalance(variables, options) {
|
910
857
|
return requester(GetBalanceDocument, variables, options);
|
911
858
|
},
|
912
|
-
getLatestGasPrice(variables, options) {
|
913
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
914
|
-
},
|
915
|
-
estimateGasPrice(variables, options) {
|
916
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
917
|
-
},
|
918
859
|
getBalances(variables, options) {
|
919
860
|
return requester(GetBalancesDocument, variables, options);
|
920
861
|
},
|
@@ -1089,7 +1030,7 @@ var inputify = (value) => {
|
|
1089
1030
|
return {
|
1090
1031
|
type: InputType.Coin,
|
1091
1032
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1092
|
-
outputIndex:
|
1033
|
+
outputIndex: arrayify(value.id)[32],
|
1093
1034
|
owner: hexlify3(value.owner),
|
1094
1035
|
amount: bn2(value.amount),
|
1095
1036
|
assetId: hexlify3(value.assetId),
|
@@ -1098,9 +1039,10 @@ var inputify = (value) => {
|
|
1098
1039
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1099
1040
|
},
|
1100
1041
|
witnessIndex: value.witnessIndex,
|
1042
|
+
maturity: value.maturity ?? 0,
|
1101
1043
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1102
|
-
predicateLength:
|
1103
|
-
predicateDataLength:
|
1044
|
+
predicateLength: predicate.length,
|
1045
|
+
predicateDataLength: predicateData.length,
|
1104
1046
|
predicate: hexlify3(predicate),
|
1105
1047
|
predicateData: hexlify3(predicateData)
|
1106
1048
|
};
|
@@ -1131,8 +1073,8 @@ var inputify = (value) => {
|
|
1131
1073
|
nonce: hexlify3(value.nonce),
|
1132
1074
|
witnessIndex: value.witnessIndex,
|
1133
1075
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1134
|
-
predicateLength:
|
1135
|
-
predicateDataLength:
|
1076
|
+
predicateLength: predicate.length,
|
1077
|
+
predicateDataLength: predicateData.length,
|
1136
1078
|
predicate: hexlify3(predicate),
|
1137
1079
|
predicateData: hexlify3(predicateData),
|
1138
1080
|
data: hexlify3(data),
|
@@ -1207,7 +1149,7 @@ var outputify = (value) => {
|
|
1207
1149
|
|
1208
1150
|
// src/providers/transaction-request/transaction-request.ts
|
1209
1151
|
import { Address, addressify } from "@fuel-ts/address";
|
1210
|
-
import {
|
1152
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1211
1153
|
import { bn as bn7 } from "@fuel-ts/math";
|
1212
1154
|
import {
|
1213
1155
|
PolicyType,
|
@@ -1217,7 +1159,6 @@ import {
|
|
1217
1159
|
TransactionType
|
1218
1160
|
} from "@fuel-ts/transactions";
|
1219
1161
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1220
|
-
import { randomBytes } from "ethers";
|
1221
1162
|
|
1222
1163
|
// src/providers/resource.ts
|
1223
1164
|
var isCoin = (resource) => "id" in resource;
|
@@ -1258,8 +1199,8 @@ function assembleReceiptByType(receipt) {
|
|
1258
1199
|
case "CALL" /* Call */: {
|
1259
1200
|
const callReceipt = {
|
1260
1201
|
type: ReceiptType.Call,
|
1261
|
-
from: hexOrZero(receipt.id
|
1262
|
-
to: hexOrZero(receipt?.to),
|
1202
|
+
from: hexOrZero(receipt.contract?.id),
|
1203
|
+
to: hexOrZero(receipt?.to?.id),
|
1263
1204
|
amount: bn4(receipt.amount),
|
1264
1205
|
assetId: hexOrZero(receipt.assetId),
|
1265
1206
|
gas: bn4(receipt.gas),
|
@@ -1273,7 +1214,7 @@ function assembleReceiptByType(receipt) {
|
|
1273
1214
|
case "RETURN" /* Return */: {
|
1274
1215
|
const returnReceipt = {
|
1275
1216
|
type: ReceiptType.Return,
|
1276
|
-
id: hexOrZero(receipt.id
|
1217
|
+
id: hexOrZero(receipt.contract?.id),
|
1277
1218
|
val: bn4(receipt.val),
|
1278
1219
|
pc: bn4(receipt.pc),
|
1279
1220
|
is: bn4(receipt.is)
|
@@ -1283,7 +1224,7 @@ function assembleReceiptByType(receipt) {
|
|
1283
1224
|
case "RETURN_DATA" /* ReturnData */: {
|
1284
1225
|
const returnDataReceipt = {
|
1285
1226
|
type: ReceiptType.ReturnData,
|
1286
|
-
id: hexOrZero(receipt.id
|
1227
|
+
id: hexOrZero(receipt.contract?.id),
|
1287
1228
|
ptr: bn4(receipt.ptr),
|
1288
1229
|
len: bn4(receipt.len),
|
1289
1230
|
digest: hexOrZero(receipt.digest),
|
@@ -1295,7 +1236,7 @@ function assembleReceiptByType(receipt) {
|
|
1295
1236
|
case "PANIC" /* Panic */: {
|
1296
1237
|
const panicReceipt = {
|
1297
1238
|
type: ReceiptType.Panic,
|
1298
|
-
id: hexOrZero(receipt.id),
|
1239
|
+
id: hexOrZero(receipt.contract?.id),
|
1299
1240
|
reason: bn4(receipt.reason),
|
1300
1241
|
pc: bn4(receipt.pc),
|
1301
1242
|
is: bn4(receipt.is),
|
@@ -1306,7 +1247,7 @@ function assembleReceiptByType(receipt) {
|
|
1306
1247
|
case "REVERT" /* Revert */: {
|
1307
1248
|
const revertReceipt = {
|
1308
1249
|
type: ReceiptType.Revert,
|
1309
|
-
id: hexOrZero(receipt.id
|
1250
|
+
id: hexOrZero(receipt.contract?.id),
|
1310
1251
|
val: bn4(receipt.ra),
|
1311
1252
|
pc: bn4(receipt.pc),
|
1312
1253
|
is: bn4(receipt.is)
|
@@ -1316,7 +1257,7 @@ function assembleReceiptByType(receipt) {
|
|
1316
1257
|
case "LOG" /* Log */: {
|
1317
1258
|
const logReceipt = {
|
1318
1259
|
type: ReceiptType.Log,
|
1319
|
-
id: hexOrZero(receipt.id
|
1260
|
+
id: hexOrZero(receipt.contract?.id),
|
1320
1261
|
val0: bn4(receipt.ra),
|
1321
1262
|
val1: bn4(receipt.rb),
|
1322
1263
|
val2: bn4(receipt.rc),
|
@@ -1329,7 +1270,7 @@ function assembleReceiptByType(receipt) {
|
|
1329
1270
|
case "LOG_DATA" /* LogData */: {
|
1330
1271
|
const logDataReceipt = {
|
1331
1272
|
type: ReceiptType.LogData,
|
1332
|
-
id: hexOrZero(receipt.id
|
1273
|
+
id: hexOrZero(receipt.contract?.id),
|
1333
1274
|
val0: bn4(receipt.ra),
|
1334
1275
|
val1: bn4(receipt.rb),
|
1335
1276
|
ptr: bn4(receipt.ptr),
|
@@ -1343,8 +1284,8 @@ function assembleReceiptByType(receipt) {
|
|
1343
1284
|
case "TRANSFER" /* Transfer */: {
|
1344
1285
|
const transferReceipt = {
|
1345
1286
|
type: ReceiptType.Transfer,
|
1346
|
-
from: hexOrZero(receipt.id
|
1347
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1287
|
+
from: hexOrZero(receipt.contract?.id),
|
1288
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1348
1289
|
amount: bn4(receipt.amount),
|
1349
1290
|
assetId: hexOrZero(receipt.assetId),
|
1350
1291
|
pc: bn4(receipt.pc),
|
@@ -1355,8 +1296,8 @@ function assembleReceiptByType(receipt) {
|
|
1355
1296
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1356
1297
|
const transferOutReceipt = {
|
1357
1298
|
type: ReceiptType.TransferOut,
|
1358
|
-
from: hexOrZero(receipt.id
|
1359
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1299
|
+
from: hexOrZero(receipt.contract?.id),
|
1300
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1360
1301
|
amount: bn4(receipt.amount),
|
1361
1302
|
assetId: hexOrZero(receipt.assetId),
|
1362
1303
|
pc: bn4(receipt.pc),
|
@@ -1399,7 +1340,7 @@ function assembleReceiptByType(receipt) {
|
|
1399
1340
|
return receiptMessageOut;
|
1400
1341
|
}
|
1401
1342
|
case "MINT" /* Mint */: {
|
1402
|
-
const contractId = hexOrZero(receipt.id
|
1343
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1403
1344
|
const subId = hexOrZero(receipt.subId);
|
1404
1345
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1405
1346
|
const mintReceipt = {
|
@@ -1414,7 +1355,7 @@ function assembleReceiptByType(receipt) {
|
|
1414
1355
|
return mintReceipt;
|
1415
1356
|
}
|
1416
1357
|
case "BURN" /* Burn */: {
|
1417
|
-
const contractId = hexOrZero(receipt.id
|
1358
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1418
1359
|
const subId = hexOrZero(receipt.subId);
|
1419
1360
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1420
1361
|
const burnReceipt = {
|
@@ -1440,6 +1381,7 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1440
1381
|
import { bn as bn5 } from "@fuel-ts/math";
|
1441
1382
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1442
1383
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1384
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1443
1385
|
var getGasUsedFromReceipts = (receipts) => {
|
1444
1386
|
const scriptResult = receipts.filter(
|
1445
1387
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1460,28 +1402,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1460
1402
|
}
|
1461
1403
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1462
1404
|
const witnessCache = [];
|
1463
|
-
const
|
1464
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1465
|
-
if (isCoinOrMessage) {
|
1466
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1467
|
-
return true;
|
1468
|
-
}
|
1469
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1470
|
-
witnessCache.push(input.witnessIndex);
|
1471
|
-
return true;
|
1472
|
-
}
|
1473
|
-
}
|
1474
|
-
return false;
|
1475
|
-
});
|
1476
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1477
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1405
|
+
const totalGas = inputs.reduce((total, input) => {
|
1478
1406
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1479
1407
|
return total.add(
|
1480
|
-
|
1408
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1481
1409
|
);
|
1482
1410
|
}
|
1483
|
-
|
1484
|
-
|
1411
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1412
|
+
witnessCache.push(input.witnessIndex);
|
1413
|
+
return total.add(gasCosts.ecr1);
|
1414
|
+
}
|
1415
|
+
return total;
|
1416
|
+
}, bn5());
|
1485
1417
|
return totalGas;
|
1486
1418
|
}
|
1487
1419
|
function getMinGas(params) {
|
@@ -1493,20 +1425,12 @@ function getMinGas(params) {
|
|
1493
1425
|
return minGas;
|
1494
1426
|
}
|
1495
1427
|
function getMaxGas(params) {
|
1496
|
-
const {
|
1497
|
-
gasPerByte,
|
1498
|
-
witnessesLength,
|
1499
|
-
witnessLimit,
|
1500
|
-
minGas,
|
1501
|
-
gasLimit = bn5(0),
|
1502
|
-
maxGasPerTx
|
1503
|
-
} = params;
|
1428
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1504
1429
|
let remainingAllowedWitnessGas = bn5(0);
|
1505
1430
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1506
1431
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1507
1432
|
}
|
1508
|
-
|
1509
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1433
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1510
1434
|
}
|
1511
1435
|
function calculateMetadataGasForTxCreate({
|
1512
1436
|
gasCosts,
|
@@ -1528,10 +1452,6 @@ function calculateMetadataGasForTxScript({
|
|
1528
1452
|
}) {
|
1529
1453
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1530
1454
|
}
|
1531
|
-
var calculateGasFee = (params) => {
|
1532
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1533
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1534
|
-
};
|
1535
1455
|
|
1536
1456
|
// src/providers/utils/json.ts
|
1537
1457
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1676,7 +1596,7 @@ var witnessify = (value) => {
|
|
1676
1596
|
// src/providers/transaction-request/transaction-request.ts
|
1677
1597
|
var BaseTransactionRequest = class {
|
1678
1598
|
/** Gas price for transaction */
|
1679
|
-
|
1599
|
+
gasPrice;
|
1680
1600
|
/** Block until which tx cannot be included */
|
1681
1601
|
maturity;
|
1682
1602
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1689,34 +1609,38 @@ var BaseTransactionRequest = class {
|
|
1689
1609
|
outputs = [];
|
1690
1610
|
/** List of witnesses */
|
1691
1611
|
witnesses = [];
|
1612
|
+
/** Base asset ID - should be fetched from the chain */
|
1613
|
+
baseAssetId = ZeroBytes324;
|
1692
1614
|
/**
|
1693
1615
|
* Constructor for initializing a base transaction request.
|
1694
1616
|
*
|
1695
1617
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1696
1618
|
*/
|
1697
1619
|
constructor({
|
1698
|
-
|
1620
|
+
gasPrice,
|
1699
1621
|
maturity,
|
1700
1622
|
maxFee,
|
1701
1623
|
witnessLimit,
|
1702
1624
|
inputs,
|
1703
1625
|
outputs,
|
1704
|
-
witnesses
|
1626
|
+
witnesses,
|
1627
|
+
baseAssetId
|
1705
1628
|
} = {}) {
|
1706
|
-
this.
|
1629
|
+
this.gasPrice = bn7(gasPrice);
|
1707
1630
|
this.maturity = maturity ?? 0;
|
1708
1631
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1709
1632
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1710
1633
|
this.inputs = inputs ?? [];
|
1711
1634
|
this.outputs = outputs ?? [];
|
1712
1635
|
this.witnesses = witnesses ?? [];
|
1636
|
+
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1713
1637
|
}
|
1714
1638
|
static getPolicyMeta(req) {
|
1715
1639
|
let policyTypes = 0;
|
1716
1640
|
const policies = [];
|
1717
|
-
if (req.
|
1718
|
-
policyTypes += PolicyType.
|
1719
|
-
policies.push({ data: req.
|
1641
|
+
if (req.gasPrice) {
|
1642
|
+
policyTypes += PolicyType.GasPrice;
|
1643
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1720
1644
|
}
|
1721
1645
|
if (req.witnessLimit) {
|
1722
1646
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1903,10 +1827,10 @@ var BaseTransactionRequest = class {
|
|
1903
1827
|
* @param predicate - Predicate bytes.
|
1904
1828
|
* @param predicateData - Predicate data bytes.
|
1905
1829
|
*/
|
1906
|
-
addCoinInput(coin) {
|
1830
|
+
addCoinInput(coin, predicate) {
|
1907
1831
|
const { assetId, owner, amount } = coin;
|
1908
1832
|
let witnessIndex;
|
1909
|
-
if (
|
1833
|
+
if (predicate) {
|
1910
1834
|
witnessIndex = 0;
|
1911
1835
|
} else {
|
1912
1836
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1921,7 +1845,9 @@ var BaseTransactionRequest = class {
|
|
1921
1845
|
amount,
|
1922
1846
|
assetId,
|
1923
1847
|
txPointer: "0x00000000000000000000000000000000",
|
1924
|
-
witnessIndex
|
1848
|
+
witnessIndex,
|
1849
|
+
predicate: predicate?.bytes,
|
1850
|
+
predicateData: predicate?.predicateDataBytes
|
1925
1851
|
};
|
1926
1852
|
this.pushInput(input);
|
1927
1853
|
this.addChangeOutput(owner, assetId);
|
@@ -1932,13 +1858,11 @@ var BaseTransactionRequest = class {
|
|
1932
1858
|
*
|
1933
1859
|
* @param message - Message resource.
|
1934
1860
|
* @param predicate - Predicate bytes.
|
1935
|
-
* @param predicateData - Predicate data bytes.
|
1936
1861
|
*/
|
1937
|
-
addMessageInput(message) {
|
1862
|
+
addMessageInput(message, predicate) {
|
1938
1863
|
const { recipient, sender, amount } = message;
|
1939
|
-
const assetId = BaseAssetId2;
|
1940
1864
|
let witnessIndex;
|
1941
|
-
if (
|
1865
|
+
if (predicate) {
|
1942
1866
|
witnessIndex = 0;
|
1943
1867
|
} else {
|
1944
1868
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1952,10 +1876,12 @@ var BaseTransactionRequest = class {
|
|
1952
1876
|
sender: sender.toB256(),
|
1953
1877
|
recipient: recipient.toB256(),
|
1954
1878
|
amount,
|
1955
|
-
witnessIndex
|
1879
|
+
witnessIndex,
|
1880
|
+
predicate: predicate?.bytes,
|
1881
|
+
predicateData: predicate?.predicateDataBytes
|
1956
1882
|
};
|
1957
1883
|
this.pushInput(input);
|
1958
|
-
this.addChangeOutput(recipient,
|
1884
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1959
1885
|
}
|
1960
1886
|
/**
|
1961
1887
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1983,6 +1909,32 @@ var BaseTransactionRequest = class {
|
|
1983
1909
|
resources.forEach((resource) => this.addResource(resource));
|
1984
1910
|
return this;
|
1985
1911
|
}
|
1912
|
+
/**
|
1913
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1914
|
+
* outputs from the related assetIds.
|
1915
|
+
*
|
1916
|
+
* @param resources - The resources to add.
|
1917
|
+
* @returns This transaction.
|
1918
|
+
*/
|
1919
|
+
addPredicateResource(resource, predicate) {
|
1920
|
+
if (isCoin(resource)) {
|
1921
|
+
this.addCoinInput(resource, predicate);
|
1922
|
+
} else {
|
1923
|
+
this.addMessageInput(resource, predicate);
|
1924
|
+
}
|
1925
|
+
return this;
|
1926
|
+
}
|
1927
|
+
/**
|
1928
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1929
|
+
* from the related assetIds.
|
1930
|
+
*
|
1931
|
+
* @param resources - The resources to add.
|
1932
|
+
* @returns This transaction.
|
1933
|
+
*/
|
1934
|
+
addPredicateResources(resources, predicate) {
|
1935
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1936
|
+
return this;
|
1937
|
+
}
|
1986
1938
|
/**
|
1987
1939
|
* Adds a coin output to the transaction.
|
1988
1940
|
*
|
@@ -1990,12 +1942,12 @@ var BaseTransactionRequest = class {
|
|
1990
1942
|
* @param amount - Amount of coin.
|
1991
1943
|
* @param assetId - Asset ID of coin.
|
1992
1944
|
*/
|
1993
|
-
addCoinOutput(to, amount, assetId
|
1945
|
+
addCoinOutput(to, amount, assetId) {
|
1994
1946
|
this.pushOutput({
|
1995
1947
|
type: OutputType2.Coin,
|
1996
1948
|
to: addressify(to).toB256(),
|
1997
1949
|
amount,
|
1998
|
-
assetId
|
1950
|
+
assetId: assetId ?? this.baseAssetId
|
1999
1951
|
});
|
2000
1952
|
return this;
|
2001
1953
|
}
|
@@ -2022,7 +1974,7 @@ var BaseTransactionRequest = class {
|
|
2022
1974
|
* @param to - Address of the owner.
|
2023
1975
|
* @param assetId - Asset ID of coin.
|
2024
1976
|
*/
|
2025
|
-
addChangeOutput(to, assetId
|
1977
|
+
addChangeOutput(to, assetId) {
|
2026
1978
|
const changeOutput = this.getChangeOutputs().find(
|
2027
1979
|
(output) => hexlify7(output.assetId) === assetId
|
2028
1980
|
);
|
@@ -2030,7 +1982,7 @@ var BaseTransactionRequest = class {
|
|
2030
1982
|
this.pushOutput({
|
2031
1983
|
type: OutputType2.Change,
|
2032
1984
|
to: addressify(to).toB256(),
|
2033
|
-
assetId
|
1985
|
+
assetId: assetId ?? this.baseAssetId
|
2034
1986
|
});
|
2035
1987
|
}
|
2036
1988
|
}
|
@@ -2062,7 +2014,7 @@ var BaseTransactionRequest = class {
|
|
2062
2014
|
}
|
2063
2015
|
calculateMaxGas(chainInfo, minGas) {
|
2064
2016
|
const { consensusParameters } = chainInfo;
|
2065
|
-
const { gasPerByte
|
2017
|
+
const { gasPerByte } = consensusParameters;
|
2066
2018
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2067
2019
|
(acc, wit) => acc + wit.dataLength,
|
2068
2020
|
0
|
@@ -2071,8 +2023,7 @@ var BaseTransactionRequest = class {
|
|
2071
2023
|
gasPerByte,
|
2072
2024
|
minGas,
|
2073
2025
|
witnessesLength,
|
2074
|
-
witnessLimit: this.witnessLimit
|
2075
|
-
maxGasPerTx
|
2026
|
+
witnessLimit: this.witnessLimit
|
2076
2027
|
});
|
2077
2028
|
}
|
2078
2029
|
/**
|
@@ -2082,6 +2033,12 @@ var BaseTransactionRequest = class {
|
|
2082
2033
|
* @param quantities - CoinQuantity Array.
|
2083
2034
|
*/
|
2084
2035
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2036
|
+
let idCounter = 0;
|
2037
|
+
const generateId = () => {
|
2038
|
+
const counterString = String(idCounter++);
|
2039
|
+
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2040
|
+
return id;
|
2041
|
+
};
|
2085
2042
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2086
2043
|
if ("assetId" in input) {
|
2087
2044
|
return input.assetId === assetId;
|
@@ -2090,27 +2047,24 @@ var BaseTransactionRequest = class {
|
|
2090
2047
|
});
|
2091
2048
|
const updateAssetInput = (assetId, quantity) => {
|
2092
2049
|
const assetInput = findAssetInput(assetId);
|
2093
|
-
let usedQuantity = quantity;
|
2094
|
-
if (assetId === BaseAssetId2) {
|
2095
|
-
usedQuantity = bn7("1000000000000000000");
|
2096
|
-
}
|
2097
2050
|
if (assetInput && "assetId" in assetInput) {
|
2098
|
-
assetInput.id =
|
2099
|
-
assetInput.amount =
|
2051
|
+
assetInput.id = generateId();
|
2052
|
+
assetInput.amount = quantity;
|
2100
2053
|
} else {
|
2101
2054
|
this.addResources([
|
2102
2055
|
{
|
2103
|
-
id:
|
2104
|
-
amount:
|
2056
|
+
id: generateId(),
|
2057
|
+
amount: quantity,
|
2105
2058
|
assetId,
|
2106
2059
|
owner: resourcesOwner || Address.fromRandom(),
|
2060
|
+
maturity: 0,
|
2107
2061
|
blockCreated: bn7(1),
|
2108
2062
|
txCreatedIdx: bn7(1)
|
2109
2063
|
}
|
2110
2064
|
]);
|
2111
2065
|
}
|
2112
2066
|
};
|
2113
|
-
updateAssetInput(
|
2067
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2114
2068
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2115
2069
|
}
|
2116
2070
|
/**
|
@@ -2135,7 +2089,7 @@ var BaseTransactionRequest = class {
|
|
2135
2089
|
toJSON() {
|
2136
2090
|
return normalizeJSON(this);
|
2137
2091
|
}
|
2138
|
-
|
2092
|
+
updatePredicateInputs(inputs) {
|
2139
2093
|
this.inputs.forEach((i) => {
|
2140
2094
|
let correspondingInput;
|
2141
2095
|
switch (i.type) {
|
@@ -2157,15 +2111,6 @@ var BaseTransactionRequest = class {
|
|
2157
2111
|
}
|
2158
2112
|
});
|
2159
2113
|
}
|
2160
|
-
shiftPredicateData() {
|
2161
|
-
this.inputs.forEach((input) => {
|
2162
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2163
|
-
input.predicateData = input.paddPredicateData(
|
2164
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2165
|
-
);
|
2166
|
-
}
|
2167
|
-
});
|
2168
|
-
}
|
2169
2114
|
};
|
2170
2115
|
|
2171
2116
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2312,8 +2257,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2312
2257
|
return {
|
2313
2258
|
type: TransactionType3.Create,
|
2314
2259
|
...baseTransaction,
|
2260
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2315
2261
|
bytecodeWitnessIndex,
|
2316
|
-
storageSlotsCount:
|
2262
|
+
storageSlotsCount: storageSlots.length,
|
2317
2263
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2318
2264
|
storageSlots
|
2319
2265
|
};
|
@@ -2436,8 +2382,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2436
2382
|
type: TransactionType4.Script,
|
2437
2383
|
scriptGasLimit: this.gasLimit,
|
2438
2384
|
...super.getBaseTransaction(),
|
2439
|
-
scriptLength:
|
2440
|
-
scriptDataLength:
|
2385
|
+
scriptLength: script.length,
|
2386
|
+
scriptDataLength: scriptData.length,
|
2441
2387
|
receiptsRoot: ZeroBytes327,
|
2442
2388
|
script: hexlify10(script),
|
2443
2389
|
scriptData: hexlify10(scriptData)
|
@@ -2501,7 +2447,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2501
2447
|
}
|
2502
2448
|
calculateMaxGas(chainInfo, minGas) {
|
2503
2449
|
const { consensusParameters } = chainInfo;
|
2504
|
-
const { gasPerByte
|
2450
|
+
const { gasPerByte } = consensusParameters;
|
2505
2451
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2506
2452
|
(acc, wit) => acc + wit.dataLength,
|
2507
2453
|
0
|
@@ -2511,8 +2457,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2511
2457
|
minGas,
|
2512
2458
|
witnessesLength,
|
2513
2459
|
witnessLimit: this.witnessLimit,
|
2514
|
-
gasLimit: this.gasLimit
|
2515
|
-
maxGasPerTx
|
2460
|
+
gasLimit: this.gasLimit
|
2516
2461
|
});
|
2517
2462
|
}
|
2518
2463
|
/**
|
@@ -2569,7 +2514,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2569
2514
|
|
2570
2515
|
// src/providers/transaction-request/utils.ts
|
2571
2516
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2572
|
-
import { TransactionType as TransactionType5
|
2517
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2573
2518
|
var transactionRequestify = (obj) => {
|
2574
2519
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2575
2520
|
return obj;
|
@@ -2587,31 +2532,14 @@ var transactionRequestify = (obj) => {
|
|
2587
2532
|
}
|
2588
2533
|
}
|
2589
2534
|
};
|
2590
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2591
|
-
(acc, input) => {
|
2592
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2593
|
-
acc.utxos.push(input.id);
|
2594
|
-
}
|
2595
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2596
|
-
acc.messages.push(input.nonce);
|
2597
|
-
}
|
2598
|
-
return acc;
|
2599
|
-
},
|
2600
|
-
{
|
2601
|
-
utxos: [],
|
2602
|
-
messages: []
|
2603
|
-
}
|
2604
|
-
);
|
2605
2535
|
|
2606
2536
|
// src/providers/transaction-response/transaction-response.ts
|
2607
2537
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2608
|
-
import { bn as
|
2538
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2609
2539
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2610
2540
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2611
2541
|
|
2612
2542
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2613
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2614
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2615
2543
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2616
2544
|
|
2617
2545
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2620,10 +2548,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2620
2548
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2621
2549
|
var calculateTransactionFee = (params) => {
|
2622
2550
|
const {
|
2623
|
-
|
2551
|
+
gasUsed,
|
2624
2552
|
rawPayload,
|
2625
|
-
|
2626
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2553
|
+
consensusParameters: { gasCosts, feeParams }
|
2627
2554
|
} = params;
|
2628
2555
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2629
2556
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2633,7 +2560,8 @@ var calculateTransactionFee = (params) => {
|
|
2633
2560
|
return {
|
2634
2561
|
fee: bn11(0),
|
2635
2562
|
minFee: bn11(0),
|
2636
|
-
maxFee: bn11(0)
|
2563
|
+
maxFee: bn11(0),
|
2564
|
+
feeFromGasUsed: bn11(0)
|
2637
2565
|
};
|
2638
2566
|
}
|
2639
2567
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2665,6 +2593,7 @@ var calculateTransactionFee = (params) => {
|
|
2665
2593
|
metadataGas,
|
2666
2594
|
txBytesSize: transactionBytes.length
|
2667
2595
|
});
|
2596
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2668
2597
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2669
2598
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2670
2599
|
const maxGas = getMaxGas({
|
@@ -2672,25 +2601,17 @@ var calculateTransactionFee = (params) => {
|
|
2672
2601
|
minGas,
|
2673
2602
|
witnessesLength,
|
2674
2603
|
gasLimit,
|
2675
|
-
witnessLimit
|
2676
|
-
maxGasPerTx
|
2677
|
-
});
|
2678
|
-
const minFee = calculateGasFee({
|
2679
|
-
gasPrice,
|
2680
|
-
gas: minGas,
|
2681
|
-
priceFactor: gasPriceFactor,
|
2682
|
-
tip
|
2683
|
-
});
|
2684
|
-
const maxFee = calculateGasFee({
|
2685
|
-
gasPrice,
|
2686
|
-
gas: maxGas,
|
2687
|
-
priceFactor: gasPriceFactor,
|
2688
|
-
tip
|
2604
|
+
witnessLimit
|
2689
2605
|
});
|
2606
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2607
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2608
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2609
|
+
const fee = minFee.add(feeFromGasUsed);
|
2690
2610
|
return {
|
2611
|
+
fee,
|
2691
2612
|
minFee,
|
2692
2613
|
maxFee,
|
2693
|
-
|
2614
|
+
feeFromGasUsed
|
2694
2615
|
};
|
2695
2616
|
};
|
2696
2617
|
|
@@ -2746,7 +2667,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2746
2667
|
|
2747
2668
|
// src/providers/transaction-summary/input.ts
|
2748
2669
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2749
|
-
import { InputType as
|
2670
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2750
2671
|
function getInputsByTypes(inputs, types) {
|
2751
2672
|
return inputs.filter((i) => types.includes(i.type));
|
2752
2673
|
}
|
@@ -2754,16 +2675,16 @@ function getInputsByType(inputs, type) {
|
|
2754
2675
|
return inputs.filter((i) => i.type === type);
|
2755
2676
|
}
|
2756
2677
|
function getInputsCoin(inputs) {
|
2757
|
-
return getInputsByType(inputs,
|
2678
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2758
2679
|
}
|
2759
2680
|
function getInputsMessage(inputs) {
|
2760
|
-
return getInputsByType(inputs,
|
2681
|
+
return getInputsByType(inputs, InputType5.Message);
|
2761
2682
|
}
|
2762
2683
|
function getInputsCoinAndMessage(inputs) {
|
2763
|
-
return getInputsByTypes(inputs, [
|
2684
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2764
2685
|
}
|
2765
2686
|
function getInputsContract(inputs) {
|
2766
|
-
return getInputsByType(inputs,
|
2687
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2767
2688
|
}
|
2768
2689
|
function getInputFromAssetId(inputs, assetId) {
|
2769
2690
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2782,7 +2703,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2782
2703
|
if (!contractInput) {
|
2783
2704
|
return void 0;
|
2784
2705
|
}
|
2785
|
-
if (contractInput.type !==
|
2706
|
+
if (contractInput.type !== InputType5.Contract) {
|
2786
2707
|
throw new FuelError9(
|
2787
2708
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2788
2709
|
`Contract input should be of type 'contract'.`
|
@@ -2791,10 +2712,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2791
2712
|
return contractInput;
|
2792
2713
|
}
|
2793
2714
|
function getInputAccountAddress(input) {
|
2794
|
-
if (input.type ===
|
2715
|
+
if (input.type === InputType5.Coin) {
|
2795
2716
|
return input.owner.toString();
|
2796
2717
|
}
|
2797
|
-
if (input.type ===
|
2718
|
+
if (input.type === InputType5.Message) {
|
2798
2719
|
return input.recipient.toString();
|
2799
2720
|
}
|
2800
2721
|
return "";
|
@@ -3257,9 +3178,7 @@ function assembleTransactionSummary(params) {
|
|
3257
3178
|
gqlTransactionStatus,
|
3258
3179
|
abiMap = {},
|
3259
3180
|
maxInputs,
|
3260
|
-
gasCosts
|
3261
|
-
maxGasPerTx,
|
3262
|
-
gasPrice
|
3181
|
+
gasCosts
|
3263
3182
|
} = params;
|
3264
3183
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3265
3184
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3273,14 +3192,11 @@ function assembleTransactionSummary(params) {
|
|
3273
3192
|
maxInputs
|
3274
3193
|
});
|
3275
3194
|
const typeName = getTransactionTypeName(transaction.type);
|
3276
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3277
3195
|
const { fee } = calculateTransactionFee({
|
3278
|
-
|
3196
|
+
gasUsed,
|
3279
3197
|
rawPayload,
|
3280
|
-
tip,
|
3281
3198
|
consensusParameters: {
|
3282
3199
|
gasCosts,
|
3283
|
-
maxGasPerTx,
|
3284
3200
|
feeParams: {
|
3285
3201
|
gasPerByte,
|
3286
3202
|
gasPriceFactor
|
@@ -3340,7 +3256,7 @@ var TransactionResponse = class {
|
|
3340
3256
|
/** Current provider */
|
3341
3257
|
provider;
|
3342
3258
|
/** Gas used on the transaction */
|
3343
|
-
gasUsed =
|
3259
|
+
gasUsed = bn14(0);
|
3344
3260
|
/** The graphql Transaction with receipts object. */
|
3345
3261
|
gqlTransaction;
|
3346
3262
|
abis;
|
@@ -3418,13 +3334,8 @@ var TransactionResponse = class {
|
|
3418
3334
|
const decodedTransaction = this.decodeTransaction(
|
3419
3335
|
transaction
|
3420
3336
|
);
|
3421
|
-
|
3422
|
-
|
3423
|
-
txReceipts = transaction.status.receipts;
|
3424
|
-
}
|
3425
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3426
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3427
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3337
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3338
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3428
3339
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3429
3340
|
const transactionSummary = assembleTransactionSummary({
|
3430
3341
|
id: this.id,
|
@@ -3436,9 +3347,7 @@ var TransactionResponse = class {
|
|
3436
3347
|
gasPriceFactor,
|
3437
3348
|
abiMap: contractsAbiMap,
|
3438
3349
|
maxInputs,
|
3439
|
-
gasCosts
|
3440
|
-
maxGasPerTx,
|
3441
|
-
gasPrice
|
3350
|
+
gasCosts
|
3442
3351
|
});
|
3443
3352
|
return transactionSummary;
|
3444
3353
|
}
|
@@ -3565,29 +3474,30 @@ var processGqlChain = (chain) => {
|
|
3565
3474
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3566
3475
|
return {
|
3567
3476
|
name,
|
3568
|
-
baseChainHeight:
|
3477
|
+
baseChainHeight: bn15(daHeight),
|
3569
3478
|
consensusParameters: {
|
3570
|
-
contractMaxSize:
|
3571
|
-
maxInputs:
|
3572
|
-
maxOutputs:
|
3573
|
-
maxWitnesses:
|
3574
|
-
maxGasPerTx:
|
3575
|
-
maxScriptLength:
|
3576
|
-
maxScriptDataLength:
|
3577
|
-
maxStorageSlots:
|
3578
|
-
maxPredicateLength:
|
3579
|
-
maxPredicateDataLength:
|
3580
|
-
maxGasPerPredicate:
|
3581
|
-
gasPriceFactor:
|
3582
|
-
gasPerByte:
|
3583
|
-
maxMessageDataLength:
|
3584
|
-
chainId:
|
3479
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3480
|
+
maxInputs: bn15(txParams.maxInputs),
|
3481
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3482
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3483
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3484
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3485
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3486
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3487
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3488
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3489
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3490
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3491
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3492
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3493
|
+
chainId: bn15(consensusParameters.chainId),
|
3494
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3585
3495
|
gasCosts
|
3586
3496
|
},
|
3587
3497
|
gasCosts,
|
3588
3498
|
latestBlock: {
|
3589
3499
|
id: latestBlock.id,
|
3590
|
-
height:
|
3500
|
+
height: bn15(latestBlock.header.height),
|
3591
3501
|
time: latestBlock.header.time,
|
3592
3502
|
transactions: latestBlock.transactions.map((i) => ({
|
3593
3503
|
id: i.id
|
@@ -3681,8 +3591,10 @@ var _Provider = class {
|
|
3681
3591
|
* Returns some helpful parameters related to gas fees.
|
3682
3592
|
*/
|
3683
3593
|
getGasConfig() {
|
3594
|
+
const { minGasPrice } = this.getNode();
|
3684
3595
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3685
3596
|
return {
|
3597
|
+
minGasPrice,
|
3686
3598
|
maxGasPerTx,
|
3687
3599
|
maxGasPerPredicate,
|
3688
3600
|
gasPriceFactor,
|
@@ -3780,7 +3692,7 @@ var _Provider = class {
|
|
3780
3692
|
*/
|
3781
3693
|
async getBlockNumber() {
|
3782
3694
|
const { chain } = await this.operations.getChain();
|
3783
|
-
return
|
3695
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3784
3696
|
}
|
3785
3697
|
/**
|
3786
3698
|
* Returns the chain information.
|
@@ -3790,11 +3702,13 @@ var _Provider = class {
|
|
3790
3702
|
async fetchNode() {
|
3791
3703
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3792
3704
|
const processedNodeInfo = {
|
3793
|
-
maxDepth:
|
3794
|
-
maxTx:
|
3705
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3706
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3707
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3795
3708
|
nodeVersion: nodeInfo.nodeVersion,
|
3796
3709
|
utxoValidation: nodeInfo.utxoValidation,
|
3797
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3710
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3711
|
+
peers: nodeInfo.peers
|
3798
3712
|
};
|
3799
3713
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3800
3714
|
return processedNodeInfo;
|
@@ -3820,6 +3734,17 @@ var _Provider = class {
|
|
3820
3734
|
} = this.getChain();
|
3821
3735
|
return chainId.toNumber();
|
3822
3736
|
}
|
3737
|
+
/**
|
3738
|
+
* Returns the base asset ID
|
3739
|
+
*
|
3740
|
+
* @returns A promise that resolves to the base asset ID
|
3741
|
+
*/
|
3742
|
+
getBaseAssetId() {
|
3743
|
+
const {
|
3744
|
+
consensusParameters: { baseAssetId }
|
3745
|
+
} = this.getChain();
|
3746
|
+
return baseAssetId;
|
3747
|
+
}
|
3823
3748
|
/**
|
3824
3749
|
* Submits a transaction to the chain to be executed.
|
3825
3750
|
*
|
@@ -3880,13 +3805,14 @@ var _Provider = class {
|
|
3880
3805
|
return this.estimateTxDependencies(transactionRequest);
|
3881
3806
|
}
|
3882
3807
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3883
|
-
const { dryRun:
|
3884
|
-
|
3808
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3809
|
+
encodedTransaction,
|
3885
3810
|
utxoValidation: utxoValidation || false
|
3886
3811
|
});
|
3887
|
-
const
|
3888
|
-
|
3889
|
-
|
3812
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3813
|
+
return {
|
3814
|
+
receipts
|
3815
|
+
};
|
3890
3816
|
}
|
3891
3817
|
/**
|
3892
3818
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3912,7 +3838,7 @@ var _Provider = class {
|
|
3912
3838
|
} = response;
|
3913
3839
|
if (inputs) {
|
3914
3840
|
inputs.forEach((input, index) => {
|
3915
|
-
if ("predicateGasUsed" in input &&
|
3841
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3916
3842
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3917
3843
|
}
|
3918
3844
|
});
|
@@ -3925,6 +3851,9 @@ var _Provider = class {
|
|
3925
3851
|
* If there are missing variable outputs,
|
3926
3852
|
* `addVariableOutputs` is called on the transaction.
|
3927
3853
|
*
|
3854
|
+
* @privateRemarks
|
3855
|
+
* TODO: Investigate support for missing contract IDs
|
3856
|
+
* TODO: Add support for missing output messages
|
3928
3857
|
*
|
3929
3858
|
* @param transactionRequest - The transaction request object.
|
3930
3859
|
* @returns A promise.
|
@@ -3937,19 +3866,16 @@ var _Provider = class {
|
|
3937
3866
|
missingContractIds: []
|
3938
3867
|
};
|
3939
3868
|
}
|
3869
|
+
await this.estimatePredicates(transactionRequest);
|
3940
3870
|
let receipts = [];
|
3941
3871
|
const missingContractIds = [];
|
3942
3872
|
let outputVariables = 0;
|
3943
|
-
let dryrunStatus;
|
3944
3873
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3945
|
-
const {
|
3946
|
-
|
3947
|
-
} = await this.operations.dryRun({
|
3948
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3874
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3875
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3949
3876
|
utxoValidation: false
|
3950
3877
|
});
|
3951
|
-
receipts =
|
3952
|
-
dryrunStatus = status;
|
3878
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3953
3879
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3954
3880
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3955
3881
|
if (hasMissingOutputs) {
|
@@ -3959,11 +3885,6 @@ var _Provider = class {
|
|
3959
3885
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3960
3886
|
missingContractIds.push(contractId);
|
3961
3887
|
});
|
3962
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3963
|
-
transactionRequest,
|
3964
|
-
optimizeGas: false
|
3965
|
-
});
|
3966
|
-
transactionRequest.maxFee = maxFee;
|
3967
3888
|
} else {
|
3968
3889
|
break;
|
3969
3890
|
}
|
@@ -3971,133 +3892,7 @@ var _Provider = class {
|
|
3971
3892
|
return {
|
3972
3893
|
receipts,
|
3973
3894
|
outputVariables,
|
3974
|
-
missingContractIds
|
3975
|
-
dryrunStatus
|
3976
|
-
};
|
3977
|
-
}
|
3978
|
-
/**
|
3979
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3980
|
-
*
|
3981
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3982
|
-
* further modifications are identified. The method iteratively updates these transactions
|
3983
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3984
|
-
*
|
3985
|
-
* @param transactionRequests - Array of transaction request objects.
|
3986
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
3987
|
-
*/
|
3988
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
3989
|
-
const results = transactionRequests.map(() => ({
|
3990
|
-
receipts: [],
|
3991
|
-
outputVariables: 0,
|
3992
|
-
missingContractIds: [],
|
3993
|
-
dryrunStatus: void 0
|
3994
|
-
}));
|
3995
|
-
const allRequests = clone3(transactionRequests);
|
3996
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
3997
|
-
allRequests.forEach((req, index) => {
|
3998
|
-
if (req.type === TransactionType8.Script) {
|
3999
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4000
|
-
}
|
4001
|
-
});
|
4002
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4003
|
-
let attempt = 0;
|
4004
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4005
|
-
const encodedTransactions = transactionsToProcess.map(
|
4006
|
-
(index) => serializedTransactionsMap.get(index)
|
4007
|
-
);
|
4008
|
-
const dryRunResults = await this.operations.dryRun({
|
4009
|
-
encodedTransactions,
|
4010
|
-
utxoValidation: false
|
4011
|
-
});
|
4012
|
-
const nextRoundTransactions = [];
|
4013
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4014
|
-
const currentResultIndex = transactionsToProcess[i];
|
4015
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4016
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4017
|
-
results[currentResultIndex].dryrunStatus = status;
|
4018
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4019
|
-
results[currentResultIndex].receipts
|
4020
|
-
);
|
4021
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4022
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4023
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4024
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4025
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4026
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4027
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4028
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4029
|
-
});
|
4030
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4031
|
-
transactionRequest: requestToProcess,
|
4032
|
-
optimizeGas: false
|
4033
|
-
});
|
4034
|
-
requestToProcess.maxFee = maxFee;
|
4035
|
-
serializedTransactionsMap.set(
|
4036
|
-
currentResultIndex,
|
4037
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4038
|
-
);
|
4039
|
-
nextRoundTransactions.push(currentResultIndex);
|
4040
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4041
|
-
}
|
4042
|
-
}
|
4043
|
-
transactionsToProcess = nextRoundTransactions;
|
4044
|
-
attempt += 1;
|
4045
|
-
}
|
4046
|
-
return results;
|
4047
|
-
}
|
4048
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4049
|
-
if (estimateTxDependencies) {
|
4050
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4051
|
-
}
|
4052
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4053
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4054
|
-
encodedTransactions,
|
4055
|
-
utxoValidation: utxoValidation || false
|
4056
|
-
});
|
4057
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4058
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4059
|
-
return { receipts, dryrunStatus: status };
|
4060
|
-
});
|
4061
|
-
return results;
|
4062
|
-
}
|
4063
|
-
async estimateTxGasAndFee(params) {
|
4064
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4065
|
-
let { gasPrice } = params;
|
4066
|
-
const chainInfo = this.getChain();
|
4067
|
-
const { gasPriceFactor } = this.getGasConfig();
|
4068
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4069
|
-
if (!gasPrice) {
|
4070
|
-
gasPrice = await this.estimateGasPrice(10);
|
4071
|
-
}
|
4072
|
-
const minFee = calculateGasFee({
|
4073
|
-
gasPrice: bn16(gasPrice),
|
4074
|
-
gas: minGas,
|
4075
|
-
priceFactor: gasPriceFactor,
|
4076
|
-
tip: transactionRequest.tip
|
4077
|
-
}).add(1);
|
4078
|
-
let gasLimit = bn16(0);
|
4079
|
-
if (transactionRequest.type === TransactionType8.Script) {
|
4080
|
-
gasLimit = transactionRequest.gasLimit;
|
4081
|
-
if (!optimizeGas) {
|
4082
|
-
transactionRequest.gasLimit = minGas;
|
4083
|
-
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4084
|
-
transactionRequest.gasLimit = gasLimit;
|
4085
|
-
}
|
4086
|
-
}
|
4087
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4088
|
-
const maxFee = calculateGasFee({
|
4089
|
-
gasPrice: bn16(gasPrice),
|
4090
|
-
gas: maxGas,
|
4091
|
-
priceFactor: gasPriceFactor,
|
4092
|
-
tip: transactionRequest.tip
|
4093
|
-
}).add(1);
|
4094
|
-
return {
|
4095
|
-
minGas,
|
4096
|
-
minFee,
|
4097
|
-
maxGas,
|
4098
|
-
maxFee,
|
4099
|
-
gasPrice,
|
4100
|
-
gasLimit
|
3895
|
+
missingContractIds
|
4101
3896
|
};
|
4102
3897
|
}
|
4103
3898
|
/**
|
@@ -4115,17 +3910,15 @@ var _Provider = class {
|
|
4115
3910
|
if (estimateTxDependencies) {
|
4116
3911
|
return this.estimateTxDependencies(transactionRequest);
|
4117
3912
|
}
|
4118
|
-
const
|
4119
|
-
const { dryRun:
|
4120
|
-
|
3913
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3914
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3915
|
+
encodedTransaction,
|
4121
3916
|
utxoValidation: true
|
4122
3917
|
});
|
4123
|
-
const
|
4124
|
-
|
4125
|
-
|
4126
|
-
|
4127
|
-
});
|
4128
|
-
return { receipts: callResult[0].receipts };
|
3918
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3919
|
+
return {
|
3920
|
+
receipts
|
3921
|
+
};
|
4129
3922
|
}
|
4130
3923
|
/**
|
4131
3924
|
* Returns a transaction cost to enable user
|
@@ -4142,80 +3935,80 @@ var _Provider = class {
|
|
4142
3935
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4143
3936
|
* @returns A promise that resolves to the transaction cost object.
|
4144
3937
|
*/
|
4145
|
-
async getTransactionCost(transactionRequestLike,
|
3938
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3939
|
+
estimateTxDependencies = true,
|
3940
|
+
estimatePredicates = true,
|
3941
|
+
resourcesOwner,
|
3942
|
+
signatureCallback
|
3943
|
+
} = {}) {
|
4146
3944
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3945
|
+
const chainInfo = this.getChain();
|
3946
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3947
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4147
3948
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4148
3949
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4149
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3950
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4150
3951
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4151
|
-
|
4152
|
-
|
4153
|
-
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
3952
|
+
if (estimatePredicates) {
|
3953
|
+
if (isScriptTransaction) {
|
3954
|
+
txRequestClone.gasLimit = bn15(0);
|
3955
|
+
}
|
3956
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3957
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3958
|
+
}
|
3959
|
+
await this.estimatePredicates(txRequestClone);
|
4157
3960
|
}
|
4158
|
-
const signedRequest = clone3(txRequestClone);
|
4159
|
-
let addedSignatures = 0;
|
4160
3961
|
if (signatureCallback && isScriptTransaction) {
|
4161
|
-
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
4165
|
-
await this.estimatePredicates(signedRequest);
|
4166
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4167
|
-
transactionRequest: signedRequest,
|
4168
|
-
optimizeGas: false
|
4169
|
-
});
|
4170
|
-
txRequestClone.maxFee = maxFee;
|
3962
|
+
await signatureCallback(txRequestClone);
|
3963
|
+
}
|
3964
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3965
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4171
3966
|
let receipts = [];
|
4172
3967
|
let missingContractIds = [];
|
4173
3968
|
let outputVariables = 0;
|
4174
|
-
|
4175
|
-
|
4176
|
-
|
4177
|
-
if (signatureCallback) {
|
4178
|
-
await signatureCallback(txRequestClone);
|
4179
|
-
}
|
4180
|
-
txRequestClone.gasLimit = gasLimit;
|
3969
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3970
|
+
txRequestClone.gasPrice = bn15(0);
|
3971
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4181
3972
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4182
3973
|
receipts = result.receipts;
|
4183
3974
|
outputVariables = result.outputVariables;
|
4184
3975
|
missingContractIds = result.missingContractIds;
|
4185
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4186
|
-
txRequestClone.gasLimit = gasUsed;
|
4187
|
-
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4188
|
-
transactionRequest: txRequestClone,
|
4189
|
-
gasPrice
|
4190
|
-
}));
|
4191
3976
|
}
|
3977
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3978
|
+
const usedFee = calculatePriceWithFactor(
|
3979
|
+
gasUsed,
|
3980
|
+
gasPrice,
|
3981
|
+
gasPriceFactor
|
3982
|
+
).normalizeZeroToOne();
|
3983
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3984
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4192
3985
|
return {
|
4193
3986
|
requiredQuantities: allQuantities,
|
4194
3987
|
receipts,
|
4195
3988
|
gasUsed,
|
3989
|
+
minGasPrice,
|
4196
3990
|
gasPrice,
|
4197
3991
|
minGas,
|
4198
3992
|
maxGas,
|
3993
|
+
usedFee,
|
4199
3994
|
minFee,
|
4200
3995
|
maxFee,
|
3996
|
+
estimatedInputs: txRequestClone.inputs,
|
4201
3997
|
outputVariables,
|
4202
|
-
missingContractIds
|
4203
|
-
addedSignatures,
|
4204
|
-
estimatedPredicates: txRequestClone.inputs
|
3998
|
+
missingContractIds
|
4205
3999
|
};
|
4206
4000
|
}
|
4207
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4001
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4208
4002
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4209
4003
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4210
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4211
|
-
quantitiesToContract
|
4212
|
-
});
|
4004
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4213
4005
|
transactionRequest.addResources(
|
4214
4006
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4215
4007
|
);
|
4216
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4217
|
-
|
4218
|
-
|
4008
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4009
|
+
transactionRequest,
|
4010
|
+
forwardingQuantities
|
4011
|
+
);
|
4219
4012
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4220
4013
|
return {
|
4221
4014
|
resources,
|
@@ -4237,10 +4030,11 @@ var _Provider = class {
|
|
4237
4030
|
return coins.map((coin) => ({
|
4238
4031
|
id: coin.utxoId,
|
4239
4032
|
assetId: coin.assetId,
|
4240
|
-
amount:
|
4033
|
+
amount: bn15(coin.amount),
|
4241
4034
|
owner: Address2.fromAddressOrString(coin.owner),
|
4242
|
-
|
4243
|
-
|
4035
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4036
|
+
blockCreated: bn15(coin.blockCreated),
|
4037
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4244
4038
|
}));
|
4245
4039
|
}
|
4246
4040
|
/**
|
@@ -4277,9 +4071,9 @@ var _Provider = class {
|
|
4277
4071
|
switch (coin.__typename) {
|
4278
4072
|
case "MessageCoin":
|
4279
4073
|
return {
|
4280
|
-
amount:
|
4074
|
+
amount: bn15(coin.amount),
|
4281
4075
|
assetId: coin.assetId,
|
4282
|
-
daHeight:
|
4076
|
+
daHeight: bn15(coin.daHeight),
|
4283
4077
|
sender: Address2.fromAddressOrString(coin.sender),
|
4284
4078
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4285
4079
|
nonce: coin.nonce
|
@@ -4287,11 +4081,12 @@ var _Provider = class {
|
|
4287
4081
|
case "Coin":
|
4288
4082
|
return {
|
4289
4083
|
id: coin.utxoId,
|
4290
|
-
amount:
|
4084
|
+
amount: bn15(coin.amount),
|
4291
4085
|
assetId: coin.assetId,
|
4292
4086
|
owner: Address2.fromAddressOrString(coin.owner),
|
4293
|
-
|
4294
|
-
|
4087
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4088
|
+
blockCreated: bn15(coin.blockCreated),
|
4089
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4295
4090
|
};
|
4296
4091
|
default:
|
4297
4092
|
return null;
|
@@ -4308,13 +4103,13 @@ var _Provider = class {
|
|
4308
4103
|
async getBlock(idOrHeight) {
|
4309
4104
|
let variables;
|
4310
4105
|
if (typeof idOrHeight === "number") {
|
4311
|
-
variables = { height:
|
4106
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4312
4107
|
} else if (idOrHeight === "latest") {
|
4313
4108
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4314
4109
|
} else if (idOrHeight.length === 66) {
|
4315
4110
|
variables = { blockId: idOrHeight };
|
4316
4111
|
} else {
|
4317
|
-
variables = { blockId:
|
4112
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4318
4113
|
}
|
4319
4114
|
const { block } = await this.operations.getBlock(variables);
|
4320
4115
|
if (!block) {
|
@@ -4322,7 +4117,7 @@ var _Provider = class {
|
|
4322
4117
|
}
|
4323
4118
|
return {
|
4324
4119
|
id: block.id,
|
4325
|
-
height:
|
4120
|
+
height: bn15(block.header.height),
|
4326
4121
|
time: block.header.time,
|
4327
4122
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4328
4123
|
};
|
@@ -4337,7 +4132,7 @@ var _Provider = class {
|
|
4337
4132
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4338
4133
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4339
4134
|
id: block.id,
|
4340
|
-
height:
|
4135
|
+
height: bn15(block.header.height),
|
4341
4136
|
time: block.header.time,
|
4342
4137
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4343
4138
|
}));
|
@@ -4352,7 +4147,7 @@ var _Provider = class {
|
|
4352
4147
|
async getBlockWithTransactions(idOrHeight) {
|
4353
4148
|
let variables;
|
4354
4149
|
if (typeof idOrHeight === "number") {
|
4355
|
-
variables = { blockHeight:
|
4150
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4356
4151
|
} else if (idOrHeight === "latest") {
|
4357
4152
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4358
4153
|
} else {
|
@@ -4364,7 +4159,7 @@ var _Provider = class {
|
|
4364
4159
|
}
|
4365
4160
|
return {
|
4366
4161
|
id: block.id,
|
4367
|
-
height:
|
4162
|
+
height: bn15(block.header.height, 10),
|
4368
4163
|
time: block.header.time,
|
4369
4164
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4370
4165
|
transactions: block.transactions.map(
|
@@ -4413,7 +4208,7 @@ var _Provider = class {
|
|
4413
4208
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4414
4209
|
asset: hexlify12(assetId)
|
4415
4210
|
});
|
4416
|
-
return
|
4211
|
+
return bn15(contractBalance.amount, 10);
|
4417
4212
|
}
|
4418
4213
|
/**
|
4419
4214
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4427,7 +4222,7 @@ var _Provider = class {
|
|
4427
4222
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4428
4223
|
assetId: hexlify12(assetId)
|
4429
4224
|
});
|
4430
|
-
return
|
4225
|
+
return bn15(balance.amount, 10);
|
4431
4226
|
}
|
4432
4227
|
/**
|
4433
4228
|
* Returns balances for the given owner.
|
@@ -4445,7 +4240,7 @@ var _Provider = class {
|
|
4445
4240
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4446
4241
|
return balances.map((balance) => ({
|
4447
4242
|
assetId: balance.assetId,
|
4448
|
-
amount:
|
4243
|
+
amount: bn15(balance.amount)
|
4449
4244
|
}));
|
4450
4245
|
}
|
4451
4246
|
/**
|
@@ -4467,15 +4262,15 @@ var _Provider = class {
|
|
4467
4262
|
sender: message.sender,
|
4468
4263
|
recipient: message.recipient,
|
4469
4264
|
nonce: message.nonce,
|
4470
|
-
amount:
|
4265
|
+
amount: bn15(message.amount),
|
4471
4266
|
data: message.data
|
4472
4267
|
}),
|
4473
4268
|
sender: Address2.fromAddressOrString(message.sender),
|
4474
4269
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4475
4270
|
nonce: message.nonce,
|
4476
|
-
amount:
|
4271
|
+
amount: bn15(message.amount),
|
4477
4272
|
data: InputMessageCoder.decodeData(message.data),
|
4478
|
-
daHeight:
|
4273
|
+
daHeight: bn15(message.daHeight)
|
4479
4274
|
}));
|
4480
4275
|
}
|
4481
4276
|
/**
|
@@ -4528,52 +4323,44 @@ var _Provider = class {
|
|
4528
4323
|
} = result.messageProof;
|
4529
4324
|
return {
|
4530
4325
|
messageProof: {
|
4531
|
-
proofIndex:
|
4326
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4532
4327
|
proofSet: messageProof.proofSet
|
4533
4328
|
},
|
4534
4329
|
blockProof: {
|
4535
|
-
proofIndex:
|
4330
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4536
4331
|
proofSet: blockProof.proofSet
|
4537
4332
|
},
|
4538
4333
|
messageBlockHeader: {
|
4539
4334
|
id: messageBlockHeader.id,
|
4540
|
-
daHeight:
|
4541
|
-
transactionsCount:
|
4335
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4336
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4542
4337
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4543
|
-
height:
|
4338
|
+
height: bn15(messageBlockHeader.height),
|
4544
4339
|
prevRoot: messageBlockHeader.prevRoot,
|
4545
4340
|
time: messageBlockHeader.time,
|
4546
4341
|
applicationHash: messageBlockHeader.applicationHash,
|
4547
|
-
|
4342
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4343
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4548
4344
|
},
|
4549
4345
|
commitBlockHeader: {
|
4550
4346
|
id: commitBlockHeader.id,
|
4551
|
-
daHeight:
|
4552
|
-
transactionsCount:
|
4347
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4348
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4553
4349
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4554
|
-
height:
|
4350
|
+
height: bn15(commitBlockHeader.height),
|
4555
4351
|
prevRoot: commitBlockHeader.prevRoot,
|
4556
4352
|
time: commitBlockHeader.time,
|
4557
4353
|
applicationHash: commitBlockHeader.applicationHash,
|
4558
|
-
|
4354
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4355
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4559
4356
|
},
|
4560
4357
|
sender: Address2.fromAddressOrString(sender),
|
4561
4358
|
recipient: Address2.fromAddressOrString(recipient),
|
4562
4359
|
nonce,
|
4563
|
-
amount:
|
4360
|
+
amount: bn15(amount),
|
4564
4361
|
data
|
4565
4362
|
};
|
4566
4363
|
}
|
4567
|
-
async getLatestGasPrice() {
|
4568
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4569
|
-
return bn16(latestGasPrice.gasPrice);
|
4570
|
-
}
|
4571
|
-
async estimateGasPrice(blockHorizon) {
|
4572
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4573
|
-
blockHorizon: String(blockHorizon)
|
4574
|
-
});
|
4575
|
-
return bn16(estimateGasPrice.gasPrice);
|
4576
|
-
}
|
4577
4364
|
/**
|
4578
4365
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4579
4366
|
*
|
@@ -4593,10 +4380,10 @@ var _Provider = class {
|
|
4593
4380
|
*/
|
4594
4381
|
async produceBlocks(amount, startTime) {
|
4595
4382
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4596
|
-
blocksToProduce:
|
4383
|
+
blocksToProduce: bn15(amount).toString(10),
|
4597
4384
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4598
4385
|
});
|
4599
|
-
return
|
4386
|
+
return bn15(latestBlockHeight);
|
4600
4387
|
}
|
4601
4388
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4602
4389
|
async getTransactionResponse(transactionId) {
|
@@ -4610,7 +4397,7 @@ cacheInputs_fn = function(inputs) {
|
|
4610
4397
|
return;
|
4611
4398
|
}
|
4612
4399
|
inputs.forEach((input) => {
|
4613
|
-
if (input.type ===
|
4400
|
+
if (input.type === InputType6.Coin) {
|
4614
4401
|
this.cache?.set(input.id);
|
4615
4402
|
}
|
4616
4403
|
});
|
@@ -4620,7 +4407,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4620
4407
|
|
4621
4408
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4622
4409
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4623
|
-
import { bn as
|
4410
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4624
4411
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4625
4412
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4626
4413
|
|
@@ -4828,8 +4615,9 @@ var Account = class extends AbstractAccount {
|
|
4828
4615
|
* @param assetId - The asset ID to check the balance for.
|
4829
4616
|
* @returns A promise that resolves to the balance amount.
|
4830
4617
|
*/
|
4831
|
-
async getBalance(assetId
|
4832
|
-
const
|
4618
|
+
async getBalance(assetId) {
|
4619
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4620
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4833
4621
|
return amount;
|
4834
4622
|
}
|
4835
4623
|
/**
|
@@ -4866,33 +4654,37 @@ var Account = class extends AbstractAccount {
|
|
4866
4654
|
* @param fee - The estimated transaction fee.
|
4867
4655
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4868
4656
|
*/
|
4869
|
-
async fund(request,
|
4870
|
-
const
|
4871
|
-
const
|
4872
|
-
|
4873
|
-
|
4874
|
-
|
4875
|
-
coinQuantities: requiredQuantities
|
4657
|
+
async fund(request, coinQuantities, fee) {
|
4658
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4659
|
+
const updatedQuantities = addAmountToAsset({
|
4660
|
+
amount: bn17(fee),
|
4661
|
+
assetId: baseAssetId,
|
4662
|
+
coinQuantities
|
4876
4663
|
});
|
4877
4664
|
const quantitiesDict = {};
|
4878
|
-
|
4665
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4879
4666
|
quantitiesDict[assetId] = {
|
4880
4667
|
required: amount,
|
4881
|
-
owned:
|
4668
|
+
owned: bn17(0)
|
4882
4669
|
};
|
4883
4670
|
});
|
4884
|
-
|
4671
|
+
const cachedUtxos = [];
|
4672
|
+
const cachedMessages = [];
|
4673
|
+
const owner = this.address.toB256();
|
4674
|
+
request.inputs.forEach((input) => {
|
4885
4675
|
const isResource = "amount" in input;
|
4886
4676
|
if (isResource) {
|
4887
4677
|
const isCoin2 = "owner" in input;
|
4888
4678
|
if (isCoin2) {
|
4889
4679
|
const assetId = String(input.assetId);
|
4890
|
-
if (quantitiesDict[assetId]) {
|
4891
|
-
const amount =
|
4680
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4681
|
+
const amount = bn17(input.amount);
|
4892
4682
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4683
|
+
cachedUtxos.push(input.id);
|
4893
4684
|
}
|
4894
|
-
} else if (input.amount && quantitiesDict[
|
4895
|
-
quantitiesDict[
|
4685
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4686
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4687
|
+
cachedMessages.push(input.nonce);
|
4896
4688
|
}
|
4897
4689
|
}
|
4898
4690
|
});
|
@@ -4907,23 +4699,12 @@ var Account = class extends AbstractAccount {
|
|
4907
4699
|
});
|
4908
4700
|
const needsToBeFunded = missingQuantities.length;
|
4909
4701
|
if (needsToBeFunded) {
|
4910
|
-
const
|
4911
|
-
|
4912
|
-
|
4913
|
-
|
4914
|
-
|
4915
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4916
|
-
const requestToBeReEstimate = clone4(txRequest);
|
4917
|
-
if (addedSignatures) {
|
4918
|
-
Array.from({ length: addedSignatures }).forEach(
|
4919
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4920
|
-
);
|
4702
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4703
|
+
messages: cachedMessages,
|
4704
|
+
utxos: cachedUtxos
|
4705
|
+
});
|
4706
|
+
request.addResources(resources);
|
4921
4707
|
}
|
4922
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4923
|
-
transactionRequest: requestToBeReEstimate
|
4924
|
-
});
|
4925
|
-
txRequest.maxFee = maxFee;
|
4926
|
-
return txRequest;
|
4927
4708
|
}
|
4928
4709
|
/**
|
4929
4710
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4931,25 +4712,29 @@ var Account = class extends AbstractAccount {
|
|
4931
4712
|
* @param destination - The address of the destination.
|
4932
4713
|
* @param amount - The amount of coins to transfer.
|
4933
4714
|
* @param assetId - The asset ID of the coins to transfer.
|
4934
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4715
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4935
4716
|
* @returns A promise that resolves to the prepared transaction request.
|
4936
4717
|
*/
|
4937
|
-
async createTransfer(destination, amount, assetId
|
4938
|
-
const
|
4939
|
-
|
4940
|
-
const
|
4718
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4719
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4720
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4721
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4722
|
+
const request = new ScriptTransactionRequest(params);
|
4723
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4724
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4941
4725
|
estimateTxDependencies: true,
|
4942
4726
|
resourcesOwner: this
|
4943
4727
|
});
|
4944
|
-
|
4945
|
-
|
4946
|
-
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
4951
|
-
|
4952
|
-
await this.fund(request,
|
4728
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4729
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4730
|
+
this.validateGas({
|
4731
|
+
gasUsed,
|
4732
|
+
gasPrice: request.gasPrice,
|
4733
|
+
gasLimit: request.gasLimit,
|
4734
|
+
minGasPrice
|
4735
|
+
});
|
4736
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4737
|
+
request.updatePredicateInputs(estimatedInputs);
|
4953
4738
|
return request;
|
4954
4739
|
}
|
4955
4740
|
/**
|
@@ -4961,14 +4746,15 @@ var Account = class extends AbstractAccount {
|
|
4961
4746
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4962
4747
|
* @returns A promise that resolves to the transaction response.
|
4963
4748
|
*/
|
4964
|
-
async transfer(destination, amount, assetId
|
4965
|
-
if (
|
4749
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4750
|
+
if (bn17(amount).lte(0)) {
|
4966
4751
|
throw new FuelError15(
|
4967
4752
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4968
4753
|
"Transfer amount must be a positive number."
|
4969
4754
|
);
|
4970
4755
|
}
|
4971
|
-
const
|
4756
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4757
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4972
4758
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4973
4759
|
}
|
4974
4760
|
/**
|
@@ -4980,38 +4766,40 @@ var Account = class extends AbstractAccount {
|
|
4980
4766
|
* @param txParams - The optional transaction parameters.
|
4981
4767
|
* @returns A promise that resolves to the transaction response.
|
4982
4768
|
*/
|
4983
|
-
async transferToContract(contractId, amount, assetId
|
4984
|
-
if (
|
4769
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4770
|
+
if (bn17(amount).lte(0)) {
|
4985
4771
|
throw new FuelError15(
|
4986
4772
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4987
4773
|
"Transfer amount must be a positive number."
|
4988
4774
|
);
|
4989
4775
|
}
|
4990
4776
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4777
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4778
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4779
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4991
4780
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4992
4781
|
hexlifiedContractId: contractAddress.toB256(),
|
4993
|
-
amountToTransfer:
|
4994
|
-
assetId
|
4782
|
+
amountToTransfer: bn17(amount),
|
4783
|
+
assetId: assetIdToTransfer
|
4995
4784
|
});
|
4996
4785
|
const request = new ScriptTransactionRequest({
|
4997
|
-
...
|
4786
|
+
...params,
|
4998
4787
|
script,
|
4999
4788
|
scriptData
|
5000
4789
|
});
|
5001
4790
|
request.addContractInputAndOutput(contractAddress);
|
5002
|
-
const
|
5003
|
-
|
5004
|
-
|
4791
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4792
|
+
request,
|
4793
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4794
|
+
);
|
4795
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4796
|
+
this.validateGas({
|
4797
|
+
gasUsed,
|
4798
|
+
gasPrice: request.gasPrice,
|
4799
|
+
gasLimit: request.gasLimit,
|
4800
|
+
minGasPrice
|
5005
4801
|
});
|
5006
|
-
|
5007
|
-
this.validateGas({
|
5008
|
-
gasUsed: txCost.gasUsed,
|
5009
|
-
gasLimit: request.gasLimit
|
5010
|
-
});
|
5011
|
-
}
|
5012
|
-
request.gasLimit = txCost.gasUsed;
|
5013
|
-
request.maxFee = txCost.maxFee;
|
5014
|
-
await this.fund(request, txCost);
|
4802
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5015
4803
|
return this.sendTransaction(request);
|
5016
4804
|
}
|
5017
4805
|
/**
|
@@ -5023,31 +4811,35 @@ var Account = class extends AbstractAccount {
|
|
5023
4811
|
* @returns A promise that resolves to the transaction response.
|
5024
4812
|
*/
|
5025
4813
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4814
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4815
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5026
4816
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5027
4817
|
const recipientDataArray = arrayify14(
|
5028
4818
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5029
4819
|
);
|
5030
4820
|
const amountDataArray = arrayify14(
|
5031
|
-
"0x".concat(
|
4821
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5032
4822
|
);
|
5033
4823
|
const script = new Uint8Array([
|
5034
4824
|
...arrayify14(withdrawScript.bytes),
|
5035
4825
|
...recipientDataArray,
|
5036
4826
|
...amountDataArray
|
5037
4827
|
]);
|
5038
|
-
const params = { script, ...txParams };
|
4828
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5039
4829
|
const request = new ScriptTransactionRequest(params);
|
5040
|
-
const
|
5041
|
-
const
|
5042
|
-
|
5043
|
-
|
5044
|
-
|
5045
|
-
|
5046
|
-
|
5047
|
-
|
5048
|
-
|
5049
|
-
|
5050
|
-
|
4830
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4831
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4832
|
+
request,
|
4833
|
+
forwardingQuantities
|
4834
|
+
);
|
4835
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4836
|
+
this.validateGas({
|
4837
|
+
gasUsed,
|
4838
|
+
gasPrice: request.gasPrice,
|
4839
|
+
gasLimit: request.gasLimit,
|
4840
|
+
minGasPrice
|
4841
|
+
});
|
4842
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5051
4843
|
return this.sendTransaction(request);
|
5052
4844
|
}
|
5053
4845
|
async signMessage(message) {
|
@@ -5105,7 +4897,18 @@ var Account = class extends AbstractAccount {
|
|
5105
4897
|
}
|
5106
4898
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5107
4899
|
}
|
5108
|
-
validateGas({
|
4900
|
+
validateGas({
|
4901
|
+
gasUsed,
|
4902
|
+
gasPrice,
|
4903
|
+
gasLimit,
|
4904
|
+
minGasPrice
|
4905
|
+
}) {
|
4906
|
+
if (minGasPrice.gt(gasPrice)) {
|
4907
|
+
throw new FuelError15(
|
4908
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4909
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4910
|
+
);
|
4911
|
+
}
|
5109
4912
|
if (gasUsed.gt(gasLimit)) {
|
5110
4913
|
throw new FuelError15(
|
5111
4914
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5117,7 +4920,7 @@ var Account = class extends AbstractAccount {
|
|
5117
4920
|
|
5118
4921
|
// src/signer/signer.ts
|
5119
4922
|
import { Address as Address4 } from "@fuel-ts/address";
|
5120
|
-
import { randomBytes
|
4923
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
5121
4924
|
import { hash } from "@fuel-ts/hasher";
|
5122
4925
|
import { toBytes } from "@fuel-ts/math";
|
5123
4926
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5210,7 +5013,7 @@ var Signer = class {
|
|
5210
5013
|
* @returns random 32-byte hashed
|
5211
5014
|
*/
|
5212
5015
|
static generatePrivateKey(entropy) {
|
5213
|
-
return entropy ? hash(concat3([
|
5016
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5214
5017
|
}
|
5215
5018
|
/**
|
5216
5019
|
* Extended publicKey from a compact publicKey
|
@@ -5229,7 +5032,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5229
5032
|
import {
|
5230
5033
|
bufferFromString,
|
5231
5034
|
keccak256,
|
5232
|
-
randomBytes as
|
5035
|
+
randomBytes as randomBytes2,
|
5233
5036
|
scrypt,
|
5234
5037
|
stringFromBuffer,
|
5235
5038
|
decryptJsonWalletData,
|
@@ -5252,7 +5055,7 @@ var removeHexPrefix = (hexString) => {
|
|
5252
5055
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5253
5056
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5254
5057
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5255
|
-
const salt =
|
5058
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5256
5059
|
const key = scrypt({
|
5257
5060
|
password: bufferFromString(password),
|
5258
5061
|
salt,
|
@@ -5261,7 +5064,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5261
5064
|
r: DEFAULT_KDF_PARAMS_R,
|
5262
5065
|
p: DEFAULT_KDF_PARAMS_P
|
5263
5066
|
});
|
5264
|
-
const iv =
|
5067
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5265
5068
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5266
5069
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5267
5070
|
const macHashUint8Array = keccak256(data);
|
@@ -5397,7 +5200,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5397
5200
|
* @param transactionRequestLike - The transaction request to send.
|
5398
5201
|
* @returns A promise that resolves to the TransactionResponse object.
|
5399
5202
|
*/
|
5400
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5203
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5401
5204
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5402
5205
|
if (estimateTxDependencies) {
|
5403
5206
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5438,12 +5241,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5438
5241
|
// src/hdwallet/hdwallet.ts
|
5439
5242
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5440
5243
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5441
|
-
import { bn as
|
5244
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5442
5245
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5443
5246
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5444
5247
|
|
5445
5248
|
// src/mnemonic/mnemonic.ts
|
5446
|
-
import { randomBytes as
|
5249
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5447
5250
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5448
5251
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5449
5252
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7798,7 +7601,7 @@ var Mnemonic = class {
|
|
7798
7601
|
* @returns A randomly generated mnemonic
|
7799
7602
|
*/
|
7800
7603
|
static generate(size = 32, extraEntropy = "") {
|
7801
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7604
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7802
7605
|
return Mnemonic.entropyToMnemonic(entropy);
|
7803
7606
|
}
|
7804
7607
|
};
|
@@ -7904,7 +7707,7 @@ var HDWallet = class {
|
|
7904
7707
|
const IR = bytes.slice(32);
|
7905
7708
|
if (privateKey) {
|
7906
7709
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7907
|
-
const ki =
|
7710
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7908
7711
|
return new HDWallet({
|
7909
7712
|
privateKey: ki,
|
7910
7713
|
chainCode: IR,
|
@@ -8169,21 +7972,20 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
8169
7972
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
8170
7973
|
|
8171
7974
|
// src/test-utils/seedTestWallet.ts
|
8172
|
-
import { randomBytes as
|
7975
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
8173
7976
|
var seedTestWallet = async (wallet, quantities) => {
|
8174
7977
|
const genesisWallet = new WalletUnlocked(
|
8175
|
-
process.env.GENESIS_SECRET ||
|
7978
|
+
process.env.GENESIS_SECRET || randomBytes4(32),
|
8176
7979
|
wallet.provider
|
8177
7980
|
);
|
8178
|
-
const
|
8179
|
-
|
8180
|
-
|
8181
|
-
|
7981
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7982
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7983
|
+
const request = new ScriptTransactionRequest({
|
7984
|
+
gasLimit: 1e4,
|
7985
|
+
gasPrice: minGasPrice
|
8182
7986
|
});
|
8183
|
-
|
8184
|
-
request.
|
8185
|
-
request.maxFee = txCost.maxFee;
|
8186
|
-
await genesisWallet.fund(request, txCost);
|
7987
|
+
request.addResources(resources);
|
7988
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8187
7989
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8188
7990
|
};
|
8189
7991
|
|
@@ -8197,12 +7999,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8197
7999
|
};
|
8198
8000
|
|
8199
8001
|
// src/test-utils/launchNode.ts
|
8200
|
-
import {
|
8201
|
-
import {
|
8002
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8003
|
+
import { toHex as toHex2 } from "@fuel-ts/math";
|
8004
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8202
8005
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8203
8006
|
import { spawn } from "child_process";
|
8204
8007
|
import { randomUUID } from "crypto";
|
8205
|
-
import { randomBytes as randomBytes6 } from "ethers";
|
8206
8008
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8207
8009
|
import os from "os";
|
8208
8010
|
import path from "path";
|
@@ -8251,12 +8053,12 @@ var launchNode = async ({
|
|
8251
8053
|
// eslint-disable-next-line no-async-promise-executor
|
8252
8054
|
new Promise(async (resolve, reject) => {
|
8253
8055
|
const remainingArgs = extractRemainingArgs(args, [
|
8254
|
-
"--
|
8056
|
+
"--chain",
|
8255
8057
|
"--consensus-key",
|
8256
8058
|
"--db-type",
|
8257
8059
|
"--poa-instant"
|
8258
8060
|
]);
|
8259
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8061
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8260
8062
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8261
8063
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8262
8064
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8275,54 +8077,36 @@ var launchNode = async ({
|
|
8275
8077
|
let chainConfigPathToUse;
|
8276
8078
|
const prefix = basePath || os.tmpdir();
|
8277
8079
|
const suffix = basePath ? "" : randomUUID();
|
8278
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix
|
8080
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8279
8081
|
if (chainConfigPath) {
|
8280
8082
|
chainConfigPathToUse = chainConfigPath;
|
8281
8083
|
} else {
|
8282
8084
|
if (!existsSync(tempDirPath)) {
|
8283
8085
|
mkdirSync(tempDirPath, { recursive: true });
|
8284
8086
|
}
|
8285
|
-
|
8286
|
-
|
8287
|
-
stateConfigJson = {
|
8288
|
-
...stateConfigJson,
|
8289
|
-
coins: [
|
8290
|
-
...stateConfigJson.coins.map((coin) => ({
|
8291
|
-
...coin,
|
8292
|
-
amount: "18446744073709551615"
|
8293
|
-
}))
|
8294
|
-
],
|
8295
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8296
|
-
...message,
|
8297
|
-
amount: "18446744073709551615"
|
8298
|
-
}))
|
8299
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8300
|
-
};
|
8087
|
+
const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
|
8088
|
+
let chainConfig = defaultChainConfig;
|
8301
8089
|
if (!process.env.GENESIS_SECRET) {
|
8302
8090
|
const pk = Signer.generatePrivateKey();
|
8303
8091
|
const signer = new Signer(pk);
|
8304
8092
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8305
|
-
|
8306
|
-
|
8307
|
-
|
8308
|
-
|
8309
|
-
|
8310
|
-
|
8311
|
-
|
8312
|
-
|
8313
|
-
|
8314
|
-
|
8093
|
+
chainConfig = {
|
8094
|
+
...defaultChainConfig,
|
8095
|
+
initial_state: {
|
8096
|
+
...defaultChainConfig.initial_state,
|
8097
|
+
coins: [
|
8098
|
+
...defaultChainConfig.initial_state.coins,
|
8099
|
+
{
|
8100
|
+
owner: signer.address.toHexString(),
|
8101
|
+
amount: toHex2(1e9),
|
8102
|
+
asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
|
8103
|
+
}
|
8104
|
+
]
|
8105
|
+
}
|
8106
|
+
};
|
8315
8107
|
}
|
8316
|
-
|
8317
|
-
|
8318
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8319
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8320
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8321
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8322
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8323
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8324
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8325
|
-
chainConfigPathToUse = tempDirPath;
|
8108
|
+
writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8109
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8326
8110
|
}
|
8327
8111
|
const child = spawn(
|
8328
8112
|
command,
|
@@ -8331,10 +8115,10 @@ var launchNode = async ({
|
|
8331
8115
|
["--ip", ipToUse],
|
8332
8116
|
["--port", portToUse],
|
8333
8117
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8334
|
-
["--min-gas-price", "
|
8118
|
+
["--min-gas-price", "0"],
|
8335
8119
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8336
8120
|
["--consensus-key", consensusKey],
|
8337
|
-
["--
|
8121
|
+
["--chain", chainConfigPathToUse],
|
8338
8122
|
"--vm-backtrace",
|
8339
8123
|
"--utxo-validation",
|
8340
8124
|
"--debug",
|
@@ -8381,9 +8165,10 @@ var launchNode = async ({
|
|
8381
8165
|
})
|
8382
8166
|
);
|
8383
8167
|
var generateWallets = async (count, provider) => {
|
8168
|
+
const baseAssetId = provider.getBaseAssetId();
|
8384
8169
|
const wallets = [];
|
8385
8170
|
for (let i = 0; i < count; i += 1) {
|
8386
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8171
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8387
8172
|
wallets.push(wallet);
|
8388
8173
|
}
|
8389
8174
|
return wallets;
|
@@ -8393,7 +8178,7 @@ var launchNodeAndGetWallets = async ({
|
|
8393
8178
|
walletCount = 10
|
8394
8179
|
} = {}) => {
|
8395
8180
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8396
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8181
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8397
8182
|
const wallets = await generateWallets(walletCount, provider);
|
8398
8183
|
const cleanup = () => {
|
8399
8184
|
closeNode();
|