@fuel-ts/account 0.0.0-rc-1976-20240404073406 → 0.0.0-rc-1764-20240404125616
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +912 -544
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1032 -714
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +909 -587
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +822 -303
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +3 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +44 -31
- package/dist/providers/provider.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 +9 -29
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +36 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +871 -540
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +944 -671
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +832 -551
- 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.js
CHANGED
@@ -62,35 +62,38 @@ var import_utils30 = require("@fuel-ts/utils");
|
|
62
62
|
|
63
63
|
// src/account.ts
|
64
64
|
var import_address4 = require("@fuel-ts/address");
|
65
|
-
var
|
65
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
66
|
+
var import_errors16 = require("@fuel-ts/errors");
|
66
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
|
-
var
|
68
|
+
var import_math19 = require("@fuel-ts/math");
|
68
69
|
var import_utils27 = require("@fuel-ts/utils");
|
70
|
+
var import_ramda4 = require("ramda");
|
69
71
|
|
70
72
|
// src/providers/coin-quantity.ts
|
73
|
+
var import_configs = require("@fuel-ts/address/configs");
|
71
74
|
var import_math = require("@fuel-ts/math");
|
72
75
|
var import_utils = require("@fuel-ts/utils");
|
73
76
|
var coinQuantityfy = (coinQuantityLike) => {
|
74
77
|
let assetId;
|
75
78
|
let amount;
|
76
|
-
let
|
79
|
+
let max;
|
77
80
|
if (Array.isArray(coinQuantityLike)) {
|
78
81
|
amount = coinQuantityLike[0];
|
79
|
-
assetId = coinQuantityLike[1];
|
80
|
-
|
82
|
+
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
83
|
+
max = coinQuantityLike[2] ?? void 0;
|
81
84
|
} else {
|
82
85
|
amount = coinQuantityLike.amount;
|
83
|
-
assetId = coinQuantityLike.assetId;
|
84
|
-
|
86
|
+
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
87
|
+
max = coinQuantityLike.max ?? void 0;
|
85
88
|
}
|
86
89
|
const bnAmount = (0, import_math.bn)(amount);
|
87
90
|
return {
|
88
91
|
assetId: (0, import_utils.hexlify)(assetId),
|
89
92
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
90
|
-
max:
|
93
|
+
max: max ? (0, import_math.bn)(max) : void 0
|
91
94
|
};
|
92
95
|
};
|
93
|
-
var
|
96
|
+
var addAmountToCoinQuantities = (params) => {
|
94
97
|
const { amount, assetId } = params;
|
95
98
|
const coinQuantities = [...params.coinQuantities];
|
96
99
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -104,13 +107,13 @@ var addAmountToAsset = (params) => {
|
|
104
107
|
|
105
108
|
// src/providers/provider.ts
|
106
109
|
var import_address3 = require("@fuel-ts/address");
|
107
|
-
var
|
108
|
-
var
|
109
|
-
var
|
110
|
+
var import_errors14 = require("@fuel-ts/errors");
|
111
|
+
var import_math16 = require("@fuel-ts/math");
|
112
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
110
113
|
var import_utils22 = require("@fuel-ts/utils");
|
111
114
|
var import_versions = require("@fuel-ts/versions");
|
112
115
|
var import_utils23 = require("@noble/curves/abstract/utils");
|
113
|
-
var
|
116
|
+
var import_ethers2 = require("ethers");
|
114
117
|
var import_graphql_request = require("graphql-request");
|
115
118
|
var import_ramda3 = require("ramda");
|
116
119
|
|
@@ -118,14 +121,10 @@ var import_ramda3 = require("ramda");
|
|
118
121
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
119
122
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
120
123
|
fragment receiptFragment on Receipt {
|
121
|
-
|
122
|
-
id
|
123
|
-
}
|
124
|
+
id
|
124
125
|
pc
|
125
126
|
is
|
126
|
-
to
|
127
|
-
id
|
128
|
-
}
|
127
|
+
to
|
129
128
|
toAddress
|
130
129
|
amount
|
131
130
|
assetId
|
@@ -163,10 +162,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
163
162
|
id
|
164
163
|
}
|
165
164
|
time
|
165
|
+
receipts {
|
166
|
+
...receiptFragment
|
167
|
+
}
|
166
168
|
programState {
|
167
169
|
returnType
|
168
170
|
data
|
169
171
|
}
|
172
|
+
receipts {
|
173
|
+
...receiptFragment
|
174
|
+
}
|
170
175
|
}
|
171
176
|
... on FailureStatus {
|
172
177
|
block {
|
@@ -174,26 +179,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
174
179
|
}
|
175
180
|
time
|
176
181
|
reason
|
182
|
+
receipts {
|
183
|
+
...receiptFragment
|
184
|
+
}
|
177
185
|
}
|
178
186
|
... on SqueezedOutStatus {
|
179
187
|
reason
|
180
188
|
}
|
181
189
|
}
|
182
|
-
`;
|
190
|
+
${ReceiptFragmentFragmentDoc}`;
|
183
191
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
184
192
|
fragment transactionFragment on Transaction {
|
185
193
|
id
|
186
194
|
rawPayload
|
187
|
-
gasPrice
|
188
|
-
receipts {
|
189
|
-
...receiptFragment
|
190
|
-
}
|
191
195
|
status {
|
192
196
|
...transactionStatusFragment
|
193
197
|
}
|
194
198
|
}
|
195
|
-
${
|
196
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
199
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
197
200
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
198
201
|
fragment inputEstimatePredicatesFragment on Input {
|
199
202
|
... on InputCoin {
|
@@ -211,6 +214,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
211
214
|
}
|
212
215
|
}
|
213
216
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
217
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
218
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
219
|
+
reason
|
220
|
+
programState {
|
221
|
+
returnType
|
222
|
+
data
|
223
|
+
}
|
224
|
+
}
|
225
|
+
`;
|
226
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
227
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
228
|
+
programState {
|
229
|
+
returnType
|
230
|
+
data
|
231
|
+
}
|
232
|
+
}
|
233
|
+
`;
|
234
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
235
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
236
|
+
... on DryRunFailureStatus {
|
237
|
+
...dryRunFailureStatusFragment
|
238
|
+
}
|
239
|
+
... on DryRunSuccessStatus {
|
240
|
+
...dryRunSuccessStatusFragment
|
241
|
+
}
|
242
|
+
}
|
243
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
244
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
245
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
246
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
247
|
+
id
|
248
|
+
status {
|
249
|
+
...dryRunTransactionStatusFragment
|
250
|
+
}
|
251
|
+
receipts {
|
252
|
+
...receiptFragment
|
253
|
+
}
|
254
|
+
}
|
255
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
256
|
+
${ReceiptFragmentFragmentDoc}`;
|
214
257
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
215
258
|
fragment coinFragment on Coin {
|
216
259
|
__typename
|
@@ -218,7 +261,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
218
261
|
owner
|
219
262
|
amount
|
220
263
|
assetId
|
221
|
-
maturity
|
222
264
|
blockCreated
|
223
265
|
txCreatedIdx
|
224
266
|
}
|
@@ -295,8 +337,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
295
337
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
296
338
|
fragment blockFragment on Block {
|
297
339
|
id
|
340
|
+
height
|
298
341
|
header {
|
299
|
-
height
|
300
342
|
time
|
301
343
|
}
|
302
344
|
transactions {
|
@@ -366,7 +408,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
366
408
|
cb
|
367
409
|
cfei
|
368
410
|
cfsi
|
369
|
-
croo
|
370
411
|
div
|
371
412
|
divi
|
372
413
|
ecr1
|
@@ -449,6 +490,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
449
490
|
ccp {
|
450
491
|
...DependentCostFragment
|
451
492
|
}
|
493
|
+
croo {
|
494
|
+
...DependentCostFragment
|
495
|
+
}
|
452
496
|
csiz {
|
453
497
|
...DependentCostFragment
|
454
498
|
}
|
@@ -571,14 +615,6 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
571
615
|
maxTx
|
572
616
|
maxDepth
|
573
617
|
nodeVersion
|
574
|
-
peers {
|
575
|
-
id
|
576
|
-
addresses
|
577
|
-
clientVersion
|
578
|
-
blockHeight
|
579
|
-
lastHeartbeatMs
|
580
|
-
appScore
|
581
|
-
}
|
582
618
|
}
|
583
619
|
`;
|
584
620
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -613,13 +649,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
613
649
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
614
650
|
transaction(id: $transactionId) {
|
615
651
|
...transactionFragment
|
616
|
-
receipts {
|
617
|
-
...receiptFragment
|
618
|
-
}
|
619
652
|
}
|
620
653
|
}
|
621
|
-
${TransactionFragmentFragmentDoc}
|
622
|
-
${ReceiptFragmentFragmentDoc}`;
|
654
|
+
${TransactionFragmentFragmentDoc}`;
|
623
655
|
var GetTransactionsDocument = import_graphql_tag.default`
|
624
656
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
625
657
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -747,6 +779,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
747
779
|
}
|
748
780
|
}
|
749
781
|
${BalanceFragmentFragmentDoc}`;
|
782
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
783
|
+
query getLatestGasPrice {
|
784
|
+
latestGasPrice {
|
785
|
+
gasPrice
|
786
|
+
}
|
787
|
+
}
|
788
|
+
`;
|
789
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
790
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
791
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
792
|
+
gasPrice
|
793
|
+
}
|
794
|
+
}
|
795
|
+
`;
|
750
796
|
var GetBalancesDocument = import_graphql_tag.default`
|
751
797
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
752
798
|
balances(
|
@@ -801,12 +847,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
801
847
|
}
|
802
848
|
`;
|
803
849
|
var DryRunDocument = import_graphql_tag.default`
|
804
|
-
mutation dryRun($
|
805
|
-
dryRun(
|
806
|
-
...
|
850
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
851
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
852
|
+
...dryRunTransactionExecutionStatusFragment
|
807
853
|
}
|
808
854
|
}
|
809
|
-
${
|
855
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
810
856
|
var SubmitDocument = import_graphql_tag.default`
|
811
857
|
mutation submit($encodedTransaction: HexString!) {
|
812
858
|
submit(tx: $encodedTransaction) {
|
@@ -889,6 +935,12 @@ function getSdk(requester) {
|
|
889
935
|
getBalance(variables, options) {
|
890
936
|
return requester(GetBalanceDocument, variables, options);
|
891
937
|
},
|
938
|
+
getLatestGasPrice(variables, options) {
|
939
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
940
|
+
},
|
941
|
+
estimateGasPrice(variables, options) {
|
942
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
943
|
+
},
|
892
944
|
getBalances(variables, options) {
|
893
945
|
return requester(GetBalancesDocument, variables, options);
|
894
946
|
},
|
@@ -1049,7 +1101,7 @@ var MemoryCache = class {
|
|
1049
1101
|
};
|
1050
1102
|
|
1051
1103
|
// src/providers/transaction-request/input.ts
|
1052
|
-
var
|
1104
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1053
1105
|
var import_errors3 = require("@fuel-ts/errors");
|
1054
1106
|
var import_math2 = require("@fuel-ts/math");
|
1055
1107
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1072,7 +1124,6 @@ var inputify = (value) => {
|
|
1072
1124
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1073
1125
|
},
|
1074
1126
|
witnessIndex: value.witnessIndex,
|
1075
|
-
maturity: value.maturity ?? 0,
|
1076
1127
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1077
1128
|
predicateLength: predicate.length,
|
1078
1129
|
predicateDataLength: predicateData.length,
|
@@ -1083,10 +1134,10 @@ var inputify = (value) => {
|
|
1083
1134
|
case import_transactions.InputType.Contract: {
|
1084
1135
|
return {
|
1085
1136
|
type: import_transactions.InputType.Contract,
|
1086
|
-
txID:
|
1137
|
+
txID: import_configs2.ZeroBytes32,
|
1087
1138
|
outputIndex: 0,
|
1088
|
-
balanceRoot:
|
1089
|
-
stateRoot:
|
1139
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1140
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1090
1141
|
txPointer: {
|
1091
1142
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1092
1143
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1124,7 +1175,7 @@ var inputify = (value) => {
|
|
1124
1175
|
};
|
1125
1176
|
|
1126
1177
|
// src/providers/transaction-request/output.ts
|
1127
|
-
var
|
1178
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1128
1179
|
var import_errors4 = require("@fuel-ts/errors");
|
1129
1180
|
var import_math3 = require("@fuel-ts/math");
|
1130
1181
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1144,8 +1195,8 @@ var outputify = (value) => {
|
|
1144
1195
|
return {
|
1145
1196
|
type: import_transactions2.OutputType.Contract,
|
1146
1197
|
inputIndex: value.inputIndex,
|
1147
|
-
balanceRoot:
|
1148
|
-
stateRoot:
|
1198
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1199
|
+
stateRoot: import_configs3.ZeroBytes32
|
1149
1200
|
};
|
1150
1201
|
}
|
1151
1202
|
case import_transactions2.OutputType.Change: {
|
@@ -1159,9 +1210,9 @@ var outputify = (value) => {
|
|
1159
1210
|
case import_transactions2.OutputType.Variable: {
|
1160
1211
|
return {
|
1161
1212
|
type: import_transactions2.OutputType.Variable,
|
1162
|
-
to:
|
1213
|
+
to: import_configs3.ZeroBytes32,
|
1163
1214
|
amount: (0, import_math3.bn)(0),
|
1164
|
-
assetId:
|
1215
|
+
assetId: import_configs3.ZeroBytes32
|
1165
1216
|
};
|
1166
1217
|
}
|
1167
1218
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1182,22 +1233,23 @@ var outputify = (value) => {
|
|
1182
1233
|
|
1183
1234
|
// src/providers/transaction-request/transaction-request.ts
|
1184
1235
|
var import_address = require("@fuel-ts/address");
|
1185
|
-
var
|
1186
|
-
var
|
1187
|
-
var
|
1236
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1237
|
+
var import_math7 = require("@fuel-ts/math");
|
1238
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1188
1239
|
var import_utils9 = require("@fuel-ts/utils");
|
1240
|
+
var import_ethers = require("ethers");
|
1189
1241
|
|
1190
1242
|
// src/providers/resource.ts
|
1191
1243
|
var isCoin = (resource) => "id" in resource;
|
1192
1244
|
|
1193
1245
|
// src/providers/utils/receipts.ts
|
1194
|
-
var
|
1246
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1195
1247
|
var import_errors5 = require("@fuel-ts/errors");
|
1196
1248
|
var import_math4 = require("@fuel-ts/math");
|
1197
1249
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1198
|
-
var
|
1250
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1199
1251
|
var import_utils5 = require("@fuel-ts/utils");
|
1200
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1252
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1201
1253
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1202
1254
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1203
1255
|
(memo, receipt) => {
|
@@ -1214,15 +1266,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1214
1266
|
missingOutputContractIds: []
|
1215
1267
|
}
|
1216
1268
|
);
|
1217
|
-
var hexOrZero = (hex) => hex ||
|
1269
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1218
1270
|
function assembleReceiptByType(receipt) {
|
1219
1271
|
const { receiptType } = receipt;
|
1220
1272
|
switch (receiptType) {
|
1221
1273
|
case "CALL" /* Call */: {
|
1222
1274
|
const callReceipt = {
|
1223
1275
|
type: import_transactions3.ReceiptType.Call,
|
1224
|
-
from: hexOrZero(receipt.
|
1225
|
-
to: hexOrZero(receipt?.to
|
1276
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1277
|
+
to: hexOrZero(receipt?.to),
|
1226
1278
|
amount: (0, import_math4.bn)(receipt.amount),
|
1227
1279
|
assetId: hexOrZero(receipt.assetId),
|
1228
1280
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1236,7 +1288,7 @@ function assembleReceiptByType(receipt) {
|
|
1236
1288
|
case "RETURN" /* Return */: {
|
1237
1289
|
const returnReceipt = {
|
1238
1290
|
type: import_transactions3.ReceiptType.Return,
|
1239
|
-
id: hexOrZero(receipt.
|
1291
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1240
1292
|
val: (0, import_math4.bn)(receipt.val),
|
1241
1293
|
pc: (0, import_math4.bn)(receipt.pc),
|
1242
1294
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1246,7 +1298,7 @@ function assembleReceiptByType(receipt) {
|
|
1246
1298
|
case "RETURN_DATA" /* ReturnData */: {
|
1247
1299
|
const returnDataReceipt = {
|
1248
1300
|
type: import_transactions3.ReceiptType.ReturnData,
|
1249
|
-
id: hexOrZero(receipt.
|
1301
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1250
1302
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1251
1303
|
len: (0, import_math4.bn)(receipt.len),
|
1252
1304
|
digest: hexOrZero(receipt.digest),
|
@@ -1258,7 +1310,7 @@ function assembleReceiptByType(receipt) {
|
|
1258
1310
|
case "PANIC" /* Panic */: {
|
1259
1311
|
const panicReceipt = {
|
1260
1312
|
type: import_transactions3.ReceiptType.Panic,
|
1261
|
-
id: hexOrZero(receipt.
|
1313
|
+
id: hexOrZero(receipt.id),
|
1262
1314
|
reason: (0, import_math4.bn)(receipt.reason),
|
1263
1315
|
pc: (0, import_math4.bn)(receipt.pc),
|
1264
1316
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1269,7 +1321,7 @@ function assembleReceiptByType(receipt) {
|
|
1269
1321
|
case "REVERT" /* Revert */: {
|
1270
1322
|
const revertReceipt = {
|
1271
1323
|
type: import_transactions3.ReceiptType.Revert,
|
1272
|
-
id: hexOrZero(receipt.
|
1324
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1273
1325
|
val: (0, import_math4.bn)(receipt.ra),
|
1274
1326
|
pc: (0, import_math4.bn)(receipt.pc),
|
1275
1327
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1279,7 +1331,7 @@ function assembleReceiptByType(receipt) {
|
|
1279
1331
|
case "LOG" /* Log */: {
|
1280
1332
|
const logReceipt = {
|
1281
1333
|
type: import_transactions3.ReceiptType.Log,
|
1282
|
-
id: hexOrZero(receipt.
|
1334
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1283
1335
|
val0: (0, import_math4.bn)(receipt.ra),
|
1284
1336
|
val1: (0, import_math4.bn)(receipt.rb),
|
1285
1337
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1292,7 +1344,7 @@ function assembleReceiptByType(receipt) {
|
|
1292
1344
|
case "LOG_DATA" /* LogData */: {
|
1293
1345
|
const logDataReceipt = {
|
1294
1346
|
type: import_transactions3.ReceiptType.LogData,
|
1295
|
-
id: hexOrZero(receipt.
|
1347
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1296
1348
|
val0: (0, import_math4.bn)(receipt.ra),
|
1297
1349
|
val1: (0, import_math4.bn)(receipt.rb),
|
1298
1350
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1306,8 +1358,8 @@ function assembleReceiptByType(receipt) {
|
|
1306
1358
|
case "TRANSFER" /* Transfer */: {
|
1307
1359
|
const transferReceipt = {
|
1308
1360
|
type: import_transactions3.ReceiptType.Transfer,
|
1309
|
-
from: hexOrZero(receipt.
|
1310
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1361
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1362
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1311
1363
|
amount: (0, import_math4.bn)(receipt.amount),
|
1312
1364
|
assetId: hexOrZero(receipt.assetId),
|
1313
1365
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1318,8 +1370,8 @@ function assembleReceiptByType(receipt) {
|
|
1318
1370
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1319
1371
|
const transferOutReceipt = {
|
1320
1372
|
type: import_transactions3.ReceiptType.TransferOut,
|
1321
|
-
from: hexOrZero(receipt.
|
1322
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1373
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1374
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1323
1375
|
amount: (0, import_math4.bn)(receipt.amount),
|
1324
1376
|
assetId: hexOrZero(receipt.assetId),
|
1325
1377
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1362,7 +1414,7 @@ function assembleReceiptByType(receipt) {
|
|
1362
1414
|
return receiptMessageOut;
|
1363
1415
|
}
|
1364
1416
|
case "MINT" /* Mint */: {
|
1365
|
-
const contractId = hexOrZero(receipt.
|
1417
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1366
1418
|
const subId = hexOrZero(receipt.subId);
|
1367
1419
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1368
1420
|
const mintReceipt = {
|
@@ -1377,7 +1429,7 @@ function assembleReceiptByType(receipt) {
|
|
1377
1429
|
return mintReceipt;
|
1378
1430
|
}
|
1379
1431
|
case "BURN" /* Burn */: {
|
1380
|
-
const contractId = hexOrZero(receipt.
|
1432
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1381
1433
|
const subId = hexOrZero(receipt.subId);
|
1382
1434
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1383
1435
|
const burnReceipt = {
|
@@ -1403,7 +1455,6 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1403
1455
|
var import_math5 = require("@fuel-ts/math");
|
1404
1456
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1405
1457
|
var import_utils6 = require("@fuel-ts/utils");
|
1406
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1407
1458
|
var getGasUsedFromReceipts = (receipts) => {
|
1408
1459
|
const scriptResult = receipts.filter(
|
1409
1460
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1424,18 +1475,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1424
1475
|
}
|
1425
1476
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1426
1477
|
const witnessCache = [];
|
1427
|
-
const
|
1478
|
+
const chargeableInputs = inputs.filter((input) => {
|
1479
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1480
|
+
if (isCoinOrMessage) {
|
1481
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1482
|
+
return true;
|
1483
|
+
}
|
1484
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1485
|
+
witnessCache.push(input.witnessIndex);
|
1486
|
+
return true;
|
1487
|
+
}
|
1488
|
+
}
|
1489
|
+
return false;
|
1490
|
+
});
|
1491
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1492
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1428
1493
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1429
1494
|
return total.add(
|
1430
|
-
|
1495
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1431
1496
|
);
|
1432
1497
|
}
|
1433
|
-
|
1434
|
-
|
1435
|
-
return total.add(gasCosts.ecr1);
|
1436
|
-
}
|
1437
|
-
return total;
|
1438
|
-
}, (0, import_math5.bn)());
|
1498
|
+
return total.add(gasCosts.ecr1);
|
1499
|
+
}, (0, import_math5.bn)(0));
|
1439
1500
|
return totalGas;
|
1440
1501
|
}
|
1441
1502
|
function getMinGas(params) {
|
@@ -1447,12 +1508,20 @@ function getMinGas(params) {
|
|
1447
1508
|
return minGas;
|
1448
1509
|
}
|
1449
1510
|
function getMaxGas(params) {
|
1450
|
-
const {
|
1511
|
+
const {
|
1512
|
+
gasPerByte,
|
1513
|
+
witnessesLength,
|
1514
|
+
witnessLimit,
|
1515
|
+
minGas,
|
1516
|
+
gasLimit = (0, import_math5.bn)(0),
|
1517
|
+
maxGasPerTx
|
1518
|
+
} = params;
|
1451
1519
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1452
1520
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1453
1521
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1454
1522
|
}
|
1455
|
-
|
1523
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1524
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1456
1525
|
}
|
1457
1526
|
function calculateMetadataGasForTxCreate({
|
1458
1527
|
gasCosts,
|
@@ -1474,6 +1543,10 @@ function calculateMetadataGasForTxScript({
|
|
1474
1543
|
}) {
|
1475
1544
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1476
1545
|
}
|
1546
|
+
var calculateGasFee = (params) => {
|
1547
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1548
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1549
|
+
};
|
1477
1550
|
|
1478
1551
|
// src/providers/utils/json.ts
|
1479
1552
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1515,6 +1588,78 @@ function sleep(time) {
|
|
1515
1588
|
});
|
1516
1589
|
}
|
1517
1590
|
|
1591
|
+
// src/providers/utils/extract-tx-error.ts
|
1592
|
+
var import_errors7 = require("@fuel-ts/errors");
|
1593
|
+
var import_math6 = require("@fuel-ts/math");
|
1594
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
1595
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1596
|
+
var assemblePanicError = (status) => {
|
1597
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1598
|
+
const reason = status.reason;
|
1599
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1600
|
+
errorMessage = `${errorMessage}
|
1601
|
+
|
1602
|
+
You can read more about this error at:
|
1603
|
+
|
1604
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1605
|
+
}
|
1606
|
+
return { errorMessage, reason };
|
1607
|
+
};
|
1608
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1609
|
+
var assembleRevertError = (receipts, logs) => {
|
1610
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1611
|
+
const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1612
|
+
let reason = "";
|
1613
|
+
if (revertReceipt) {
|
1614
|
+
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1615
|
+
switch (reasonHex) {
|
1616
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1617
|
+
reason = "require";
|
1618
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1619
|
+
break;
|
1620
|
+
}
|
1621
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1622
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1623
|
+
reason = "assert_eq";
|
1624
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1625
|
+
break;
|
1626
|
+
}
|
1627
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1628
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1629
|
+
reason = "assert_ne";
|
1630
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1631
|
+
break;
|
1632
|
+
}
|
1633
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1634
|
+
reason = "assert";
|
1635
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1636
|
+
break;
|
1637
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1638
|
+
reason = "MissingOutputChange";
|
1639
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1640
|
+
break;
|
1641
|
+
default:
|
1642
|
+
reason = "unknown";
|
1643
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1644
|
+
}
|
1645
|
+
}
|
1646
|
+
return { errorMessage, reason };
|
1647
|
+
};
|
1648
|
+
var extractTxError = (params) => {
|
1649
|
+
const { receipts, status, logs } = params;
|
1650
|
+
const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
|
1651
|
+
const isRevert = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1652
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1653
|
+
const metadata = {
|
1654
|
+
logs,
|
1655
|
+
receipts,
|
1656
|
+
panic: isPanic,
|
1657
|
+
revert: isRevert,
|
1658
|
+
reason
|
1659
|
+
};
|
1660
|
+
return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
|
1661
|
+
};
|
1662
|
+
|
1518
1663
|
// src/providers/transaction-request/errors.ts
|
1519
1664
|
var NoWitnessAtIndexError = class extends Error {
|
1520
1665
|
constructor(index) {
|
@@ -1538,7 +1683,7 @@ var witnessify = (value) => {
|
|
1538
1683
|
// src/providers/transaction-request/transaction-request.ts
|
1539
1684
|
var BaseTransactionRequest = class {
|
1540
1685
|
/** Gas price for transaction */
|
1541
|
-
|
1686
|
+
tip;
|
1542
1687
|
/** Block until which tx cannot be included */
|
1543
1688
|
maturity;
|
1544
1689
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1551,50 +1696,46 @@ var BaseTransactionRequest = class {
|
|
1551
1696
|
outputs = [];
|
1552
1697
|
/** List of witnesses */
|
1553
1698
|
witnesses = [];
|
1554
|
-
/** Base asset ID - should be fetched from the chain */
|
1555
|
-
baseAssetId = import_configs5.ZeroBytes32;
|
1556
1699
|
/**
|
1557
1700
|
* Constructor for initializing a base transaction request.
|
1558
1701
|
*
|
1559
1702
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1560
1703
|
*/
|
1561
1704
|
constructor({
|
1562
|
-
|
1705
|
+
tip,
|
1563
1706
|
maturity,
|
1564
1707
|
maxFee,
|
1565
1708
|
witnessLimit,
|
1566
1709
|
inputs,
|
1567
1710
|
outputs,
|
1568
|
-
witnesses
|
1569
|
-
baseAssetId
|
1711
|
+
witnesses
|
1570
1712
|
} = {}) {
|
1571
|
-
this.
|
1713
|
+
this.tip = (0, import_math7.bn)(tip);
|
1572
1714
|
this.maturity = maturity ?? 0;
|
1573
|
-
this.witnessLimit = witnessLimit ? (0,
|
1574
|
-
this.maxFee = maxFee ? (0,
|
1715
|
+
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1716
|
+
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1575
1717
|
this.inputs = inputs ?? [];
|
1576
1718
|
this.outputs = outputs ?? [];
|
1577
1719
|
this.witnesses = witnesses ?? [];
|
1578
|
-
this.baseAssetId = baseAssetId ?? import_configs5.ZeroBytes32;
|
1579
1720
|
}
|
1580
1721
|
static getPolicyMeta(req) {
|
1581
1722
|
let policyTypes = 0;
|
1582
1723
|
const policies = [];
|
1583
|
-
if (req.
|
1584
|
-
policyTypes +=
|
1585
|
-
policies.push({ data: req.
|
1724
|
+
if (req.tip) {
|
1725
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1726
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1586
1727
|
}
|
1587
1728
|
if (req.witnessLimit) {
|
1588
|
-
policyTypes +=
|
1589
|
-
policies.push({ data: req.witnessLimit, type:
|
1729
|
+
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
1730
|
+
policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
|
1590
1731
|
}
|
1591
1732
|
if (req.maturity > 0) {
|
1592
|
-
policyTypes +=
|
1593
|
-
policies.push({ data: req.maturity, type:
|
1733
|
+
policyTypes += import_transactions6.PolicyType.Maturity;
|
1734
|
+
policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
|
1594
1735
|
}
|
1595
1736
|
if (req.maxFee) {
|
1596
|
-
policyTypes +=
|
1597
|
-
policies.push({ data: req.maxFee, type:
|
1737
|
+
policyTypes += import_transactions6.PolicyType.MaxFee;
|
1738
|
+
policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
|
1598
1739
|
}
|
1599
1740
|
return {
|
1600
1741
|
policyTypes,
|
@@ -1628,7 +1769,7 @@ var BaseTransactionRequest = class {
|
|
1628
1769
|
* @returns The transaction bytes.
|
1629
1770
|
*/
|
1630
1771
|
toTransactionBytes() {
|
1631
|
-
return new
|
1772
|
+
return new import_transactions6.TransactionCoder().encode(this.toTransaction());
|
1632
1773
|
}
|
1633
1774
|
/**
|
1634
1775
|
* @hidden
|
@@ -1668,7 +1809,7 @@ var BaseTransactionRequest = class {
|
|
1668
1809
|
* @returns The index of the created witness.
|
1669
1810
|
*/
|
1670
1811
|
addEmptyWitness() {
|
1671
|
-
this.addWitness((0, import_utils9.concat)([
|
1812
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1672
1813
|
return this.witnesses.length - 1;
|
1673
1814
|
}
|
1674
1815
|
/**
|
@@ -1719,7 +1860,7 @@ var BaseTransactionRequest = class {
|
|
1719
1860
|
*/
|
1720
1861
|
getCoinInputs() {
|
1721
1862
|
return this.inputs.filter(
|
1722
|
-
(input) => input.type ===
|
1863
|
+
(input) => input.type === import_transactions6.InputType.Coin
|
1723
1864
|
);
|
1724
1865
|
}
|
1725
1866
|
/**
|
@@ -1729,7 +1870,7 @@ var BaseTransactionRequest = class {
|
|
1729
1870
|
*/
|
1730
1871
|
getCoinOutputs() {
|
1731
1872
|
return this.outputs.filter(
|
1732
|
-
(output) => output.type ===
|
1873
|
+
(output) => output.type === import_transactions6.OutputType.Coin
|
1733
1874
|
);
|
1734
1875
|
}
|
1735
1876
|
/**
|
@@ -1739,7 +1880,7 @@ var BaseTransactionRequest = class {
|
|
1739
1880
|
*/
|
1740
1881
|
getChangeOutputs() {
|
1741
1882
|
return this.outputs.filter(
|
1742
|
-
(output) => output.type ===
|
1883
|
+
(output) => output.type === import_transactions6.OutputType.Change
|
1743
1884
|
);
|
1744
1885
|
}
|
1745
1886
|
/**
|
@@ -1751,9 +1892,9 @@ var BaseTransactionRequest = class {
|
|
1751
1892
|
const ownerAddress = (0, import_address.addressify)(owner);
|
1752
1893
|
const found = this.inputs.find((input) => {
|
1753
1894
|
switch (input.type) {
|
1754
|
-
case
|
1895
|
+
case import_transactions6.InputType.Coin:
|
1755
1896
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1756
|
-
case
|
1897
|
+
case import_transactions6.InputType.Message:
|
1757
1898
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1758
1899
|
default:
|
1759
1900
|
return false;
|
@@ -1769,10 +1910,10 @@ var BaseTransactionRequest = class {
|
|
1769
1910
|
* @param predicate - Predicate bytes.
|
1770
1911
|
* @param predicateData - Predicate data bytes.
|
1771
1912
|
*/
|
1772
|
-
addCoinInput(coin
|
1913
|
+
addCoinInput(coin) {
|
1773
1914
|
const { assetId, owner, amount } = coin;
|
1774
1915
|
let witnessIndex;
|
1775
|
-
if (predicate) {
|
1916
|
+
if (coin.predicate) {
|
1776
1917
|
witnessIndex = 0;
|
1777
1918
|
} else {
|
1778
1919
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1782,14 +1923,12 @@ var BaseTransactionRequest = class {
|
|
1782
1923
|
}
|
1783
1924
|
const input = {
|
1784
1925
|
...coin,
|
1785
|
-
type:
|
1926
|
+
type: import_transactions6.InputType.Coin,
|
1786
1927
|
owner: owner.toB256(),
|
1787
1928
|
amount,
|
1788
1929
|
assetId,
|
1789
1930
|
txPointer: "0x00000000000000000000000000000000",
|
1790
|
-
witnessIndex
|
1791
|
-
predicate: predicate?.bytes,
|
1792
|
-
predicateData: predicate?.predicateDataBytes
|
1931
|
+
witnessIndex
|
1793
1932
|
};
|
1794
1933
|
this.pushInput(input);
|
1795
1934
|
this.addChangeOutput(owner, assetId);
|
@@ -1800,11 +1939,13 @@ var BaseTransactionRequest = class {
|
|
1800
1939
|
*
|
1801
1940
|
* @param message - Message resource.
|
1802
1941
|
* @param predicate - Predicate bytes.
|
1942
|
+
* @param predicateData - Predicate data bytes.
|
1803
1943
|
*/
|
1804
|
-
addMessageInput(message
|
1944
|
+
addMessageInput(message) {
|
1805
1945
|
const { recipient, sender, amount } = message;
|
1946
|
+
const assetId = import_configs7.BaseAssetId;
|
1806
1947
|
let witnessIndex;
|
1807
|
-
if (predicate) {
|
1948
|
+
if (message.predicate) {
|
1808
1949
|
witnessIndex = 0;
|
1809
1950
|
} else {
|
1810
1951
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1814,16 +1955,14 @@ var BaseTransactionRequest = class {
|
|
1814
1955
|
}
|
1815
1956
|
const input = {
|
1816
1957
|
...message,
|
1817
|
-
type:
|
1958
|
+
type: import_transactions6.InputType.Message,
|
1818
1959
|
sender: sender.toB256(),
|
1819
1960
|
recipient: recipient.toB256(),
|
1820
1961
|
amount,
|
1821
|
-
witnessIndex
|
1822
|
-
predicate: predicate?.bytes,
|
1823
|
-
predicateData: predicate?.predicateDataBytes
|
1962
|
+
witnessIndex
|
1824
1963
|
};
|
1825
1964
|
this.pushInput(input);
|
1826
|
-
this.addChangeOutput(recipient,
|
1965
|
+
this.addChangeOutput(recipient, assetId);
|
1827
1966
|
}
|
1828
1967
|
/**
|
1829
1968
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1851,32 +1990,6 @@ var BaseTransactionRequest = class {
|
|
1851
1990
|
resources.forEach((resource) => this.addResource(resource));
|
1852
1991
|
return this;
|
1853
1992
|
}
|
1854
|
-
/**
|
1855
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1856
|
-
* outputs from the related assetIds.
|
1857
|
-
*
|
1858
|
-
* @param resources - The resources to add.
|
1859
|
-
* @returns This transaction.
|
1860
|
-
*/
|
1861
|
-
addPredicateResource(resource, predicate) {
|
1862
|
-
if (isCoin(resource)) {
|
1863
|
-
this.addCoinInput(resource, predicate);
|
1864
|
-
} else {
|
1865
|
-
this.addMessageInput(resource, predicate);
|
1866
|
-
}
|
1867
|
-
return this;
|
1868
|
-
}
|
1869
|
-
/**
|
1870
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1871
|
-
* from the related assetIds.
|
1872
|
-
*
|
1873
|
-
* @param resources - The resources to add.
|
1874
|
-
* @returns This transaction.
|
1875
|
-
*/
|
1876
|
-
addPredicateResources(resources, predicate) {
|
1877
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1878
|
-
return this;
|
1879
|
-
}
|
1880
1993
|
/**
|
1881
1994
|
* Adds a coin output to the transaction.
|
1882
1995
|
*
|
@@ -1884,12 +1997,12 @@ var BaseTransactionRequest = class {
|
|
1884
1997
|
* @param amount - Amount of coin.
|
1885
1998
|
* @param assetId - Asset ID of coin.
|
1886
1999
|
*/
|
1887
|
-
addCoinOutput(to, amount, assetId) {
|
2000
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1888
2001
|
this.pushOutput({
|
1889
|
-
type:
|
2002
|
+
type: import_transactions6.OutputType.Coin,
|
1890
2003
|
to: (0, import_address.addressify)(to).toB256(),
|
1891
2004
|
amount,
|
1892
|
-
assetId
|
2005
|
+
assetId
|
1893
2006
|
});
|
1894
2007
|
return this;
|
1895
2008
|
}
|
@@ -1902,7 +2015,7 @@ var BaseTransactionRequest = class {
|
|
1902
2015
|
addCoinOutputs(to, quantities) {
|
1903
2016
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
1904
2017
|
this.pushOutput({
|
1905
|
-
type:
|
2018
|
+
type: import_transactions6.OutputType.Coin,
|
1906
2019
|
to: (0, import_address.addressify)(to).toB256(),
|
1907
2020
|
amount: quantity.amount,
|
1908
2021
|
assetId: quantity.assetId
|
@@ -1916,15 +2029,15 @@ var BaseTransactionRequest = class {
|
|
1916
2029
|
* @param to - Address of the owner.
|
1917
2030
|
* @param assetId - Asset ID of coin.
|
1918
2031
|
*/
|
1919
|
-
addChangeOutput(to, assetId) {
|
2032
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
1920
2033
|
const changeOutput = this.getChangeOutputs().find(
|
1921
2034
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1922
2035
|
);
|
1923
2036
|
if (!changeOutput) {
|
1924
2037
|
this.pushOutput({
|
1925
|
-
type:
|
2038
|
+
type: import_transactions6.OutputType.Change,
|
1926
2039
|
to: (0, import_address.addressify)(to).toB256(),
|
1927
|
-
assetId
|
2040
|
+
assetId
|
1928
2041
|
});
|
1929
2042
|
}
|
1930
2043
|
}
|
@@ -1956,7 +2069,7 @@ var BaseTransactionRequest = class {
|
|
1956
2069
|
}
|
1957
2070
|
calculateMaxGas(chainInfo, minGas) {
|
1958
2071
|
const { consensusParameters } = chainInfo;
|
1959
|
-
const { gasPerByte } = consensusParameters;
|
2072
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
1960
2073
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
1961
2074
|
(acc, wit) => acc + wit.dataLength,
|
1962
2075
|
0
|
@@ -1965,7 +2078,8 @@ var BaseTransactionRequest = class {
|
|
1965
2078
|
gasPerByte,
|
1966
2079
|
minGas,
|
1967
2080
|
witnessesLength,
|
1968
|
-
witnessLimit: this.witnessLimit
|
2081
|
+
witnessLimit: this.witnessLimit,
|
2082
|
+
maxGasPerTx
|
1969
2083
|
});
|
1970
2084
|
}
|
1971
2085
|
/**
|
@@ -1975,12 +2089,6 @@ var BaseTransactionRequest = class {
|
|
1975
2089
|
* @param quantities - CoinQuantity Array.
|
1976
2090
|
*/
|
1977
2091
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
1978
|
-
let idCounter = 0;
|
1979
|
-
const generateId = () => {
|
1980
|
-
const counterString = String(idCounter++);
|
1981
|
-
const id = import_configs5.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
1982
|
-
return id;
|
1983
|
-
};
|
1984
2092
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
1985
2093
|
if ("assetId" in input) {
|
1986
2094
|
return input.assetId === assetId;
|
@@ -1989,24 +2097,27 @@ var BaseTransactionRequest = class {
|
|
1989
2097
|
});
|
1990
2098
|
const updateAssetInput = (assetId, quantity) => {
|
1991
2099
|
const assetInput = findAssetInput(assetId);
|
2100
|
+
let usedQuantity = quantity;
|
2101
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2102
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2103
|
+
}
|
1992
2104
|
if (assetInput && "assetId" in assetInput) {
|
1993
|
-
assetInput.id =
|
1994
|
-
assetInput.amount =
|
2105
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33));
|
2106
|
+
assetInput.amount = usedQuantity;
|
1995
2107
|
} else {
|
1996
2108
|
this.addResources([
|
1997
2109
|
{
|
1998
|
-
id:
|
1999
|
-
amount:
|
2110
|
+
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33)),
|
2111
|
+
amount: usedQuantity,
|
2000
2112
|
assetId,
|
2001
2113
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2002
|
-
|
2003
|
-
|
2004
|
-
txCreatedIdx: (0, import_math6.bn)(1)
|
2114
|
+
blockCreated: (0, import_math7.bn)(1),
|
2115
|
+
txCreatedIdx: (0, import_math7.bn)(1)
|
2005
2116
|
}
|
2006
2117
|
]);
|
2007
2118
|
}
|
2008
2119
|
};
|
2009
|
-
updateAssetInput(
|
2120
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2010
2121
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2011
2122
|
}
|
2012
2123
|
/**
|
@@ -2017,7 +2128,7 @@ var BaseTransactionRequest = class {
|
|
2017
2128
|
*/
|
2018
2129
|
getCoinOutputsQuantities() {
|
2019
2130
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2020
|
-
amount: (0,
|
2131
|
+
amount: (0, import_math7.bn)(amount),
|
2021
2132
|
assetId: assetId.toString()
|
2022
2133
|
}));
|
2023
2134
|
return coinsQuantities;
|
@@ -2031,72 +2142,81 @@ var BaseTransactionRequest = class {
|
|
2031
2142
|
toJSON() {
|
2032
2143
|
return normalizeJSON(this);
|
2033
2144
|
}
|
2034
|
-
|
2145
|
+
updatePredicateGasUsed(inputs) {
|
2035
2146
|
this.inputs.forEach((i) => {
|
2036
2147
|
let correspondingInput;
|
2037
2148
|
switch (i.type) {
|
2038
|
-
case
|
2039
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2149
|
+
case import_transactions6.InputType.Coin:
|
2150
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions6.InputType.Coin && x.owner === i.owner);
|
2040
2151
|
break;
|
2041
|
-
case
|
2152
|
+
case import_transactions6.InputType.Message:
|
2042
2153
|
correspondingInput = inputs.find(
|
2043
|
-
(x) => x.type ===
|
2154
|
+
(x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
|
2044
2155
|
);
|
2045
2156
|
break;
|
2046
2157
|
default:
|
2047
2158
|
return;
|
2048
2159
|
}
|
2049
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0,
|
2160
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math7.bn)(correspondingInput.predicateGasUsed).gt(0)) {
|
2050
2161
|
i.predicate = correspondingInput.predicate;
|
2051
2162
|
i.predicateData = correspondingInput.predicateData;
|
2052
2163
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
2053
2164
|
}
|
2054
2165
|
});
|
2055
2166
|
}
|
2167
|
+
shiftPredicateData() {
|
2168
|
+
this.inputs.forEach((input) => {
|
2169
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2170
|
+
input.predicateData = input.paddPredicateData(
|
2171
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2172
|
+
);
|
2173
|
+
}
|
2174
|
+
});
|
2175
|
+
}
|
2056
2176
|
};
|
2057
2177
|
|
2058
2178
|
// src/providers/transaction-request/create-transaction-request.ts
|
2059
|
-
var
|
2060
|
-
var
|
2061
|
-
var
|
2179
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2180
|
+
var import_math9 = require("@fuel-ts/math");
|
2181
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2062
2182
|
var import_utils13 = require("@fuel-ts/utils");
|
2063
2183
|
|
2064
2184
|
// src/providers/transaction-request/hash-transaction.ts
|
2065
|
-
var
|
2185
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2066
2186
|
var import_hasher = require("@fuel-ts/hasher");
|
2067
|
-
var
|
2068
|
-
var
|
2187
|
+
var import_math8 = require("@fuel-ts/math");
|
2188
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2069
2189
|
var import_utils11 = require("@fuel-ts/utils");
|
2070
2190
|
var import_ramda2 = require("ramda");
|
2071
2191
|
function hashTransaction(transactionRequest, chainId) {
|
2072
2192
|
const transaction = transactionRequest.toTransaction();
|
2073
|
-
if (transaction.type ===
|
2074
|
-
transaction.receiptsRoot =
|
2193
|
+
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2194
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2075
2195
|
}
|
2076
2196
|
transaction.inputs = transaction.inputs.map((input) => {
|
2077
2197
|
const inputClone = (0, import_ramda2.clone)(input);
|
2078
2198
|
switch (inputClone.type) {
|
2079
|
-
case
|
2199
|
+
case import_transactions7.InputType.Coin: {
|
2080
2200
|
inputClone.txPointer = {
|
2081
2201
|
blockHeight: 0,
|
2082
2202
|
txIndex: 0
|
2083
2203
|
};
|
2084
|
-
inputClone.predicateGasUsed = (0,
|
2204
|
+
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2085
2205
|
return inputClone;
|
2086
2206
|
}
|
2087
|
-
case
|
2088
|
-
inputClone.predicateGasUsed = (0,
|
2207
|
+
case import_transactions7.InputType.Message: {
|
2208
|
+
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2089
2209
|
return inputClone;
|
2090
2210
|
}
|
2091
|
-
case
|
2211
|
+
case import_transactions7.InputType.Contract: {
|
2092
2212
|
inputClone.txPointer = {
|
2093
2213
|
blockHeight: 0,
|
2094
2214
|
txIndex: 0
|
2095
2215
|
};
|
2096
|
-
inputClone.txID =
|
2216
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2097
2217
|
inputClone.outputIndex = 0;
|
2098
|
-
inputClone.balanceRoot =
|
2099
|
-
inputClone.stateRoot =
|
2218
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2219
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2100
2220
|
return inputClone;
|
2101
2221
|
}
|
2102
2222
|
default:
|
@@ -2106,19 +2226,19 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2106
2226
|
transaction.outputs = transaction.outputs.map((output) => {
|
2107
2227
|
const outputClone = (0, import_ramda2.clone)(output);
|
2108
2228
|
switch (outputClone.type) {
|
2109
|
-
case
|
2110
|
-
outputClone.balanceRoot =
|
2111
|
-
outputClone.stateRoot =
|
2229
|
+
case import_transactions7.OutputType.Contract: {
|
2230
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2231
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2112
2232
|
return outputClone;
|
2113
2233
|
}
|
2114
|
-
case
|
2115
|
-
outputClone.amount = (0,
|
2234
|
+
case import_transactions7.OutputType.Change: {
|
2235
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2116
2236
|
return outputClone;
|
2117
2237
|
}
|
2118
|
-
case
|
2119
|
-
outputClone.to =
|
2120
|
-
outputClone.amount = (0,
|
2121
|
-
outputClone.assetId =
|
2238
|
+
case import_transactions7.OutputType.Variable: {
|
2239
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2240
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2241
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2122
2242
|
return outputClone;
|
2123
2243
|
}
|
2124
2244
|
default:
|
@@ -2128,7 +2248,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2128
2248
|
transaction.witnessesCount = 0;
|
2129
2249
|
transaction.witnesses = [];
|
2130
2250
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2131
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2251
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions7.TransactionCoder().encode(transaction)]);
|
2132
2252
|
return (0, import_hasher.sha256)(concatenatedData);
|
2133
2253
|
}
|
2134
2254
|
|
@@ -2164,7 +2284,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2164
2284
|
return new this(obj);
|
2165
2285
|
}
|
2166
2286
|
/** Type of the transaction */
|
2167
|
-
type =
|
2287
|
+
type = import_transactions8.TransactionType.Create;
|
2168
2288
|
/** Witness index of contract bytecode to create */
|
2169
2289
|
bytecodeWitnessIndex;
|
2170
2290
|
/** Salt */
|
@@ -2184,7 +2304,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2184
2304
|
} = {}) {
|
2185
2305
|
super(rest);
|
2186
2306
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2187
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2307
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2188
2308
|
this.storageSlots = [...storageSlots ?? []];
|
2189
2309
|
}
|
2190
2310
|
/**
|
@@ -2197,12 +2317,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2197
2317
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2198
2318
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2199
2319
|
return {
|
2200
|
-
type:
|
2320
|
+
type: import_transactions8.TransactionType.Create,
|
2201
2321
|
...baseTransaction,
|
2202
2322
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2203
2323
|
bytecodeWitnessIndex,
|
2204
2324
|
storageSlotsCount: storageSlots.length,
|
2205
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2325
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2206
2326
|
storageSlots
|
2207
2327
|
};
|
2208
2328
|
}
|
@@ -2213,7 +2333,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2213
2333
|
*/
|
2214
2334
|
getContractCreatedOutputs() {
|
2215
2335
|
return this.outputs.filter(
|
2216
|
-
(output) => output.type ===
|
2336
|
+
(output) => output.type === import_transactions8.OutputType.ContractCreated
|
2217
2337
|
);
|
2218
2338
|
}
|
2219
2339
|
/**
|
@@ -2234,14 +2354,14 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2234
2354
|
*/
|
2235
2355
|
addContractCreatedOutput(contractId, stateRoot) {
|
2236
2356
|
this.pushOutput({
|
2237
|
-
type:
|
2357
|
+
type: import_transactions8.OutputType.ContractCreated,
|
2238
2358
|
contractId,
|
2239
2359
|
stateRoot
|
2240
2360
|
});
|
2241
2361
|
}
|
2242
2362
|
metadataGas(gasCosts) {
|
2243
2363
|
return calculateMetadataGasForTxCreate({
|
2244
|
-
contractBytesSize: (0,
|
2364
|
+
contractBytesSize: (0, import_math9.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2245
2365
|
gasCosts,
|
2246
2366
|
stateRootSize: this.storageSlots.length,
|
2247
2367
|
txBytesSize: this.byteSize()
|
@@ -2252,9 +2372,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2252
2372
|
// src/providers/transaction-request/script-transaction-request.ts
|
2253
2373
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2254
2374
|
var import_address2 = require("@fuel-ts/address");
|
2255
|
-
var
|
2256
|
-
var
|
2257
|
-
var
|
2375
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2376
|
+
var import_math10 = require("@fuel-ts/math");
|
2377
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2258
2378
|
var import_utils15 = require("@fuel-ts/utils");
|
2259
2379
|
|
2260
2380
|
// src/providers/transaction-request/scripts.ts
|
@@ -2292,7 +2412,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2292
2412
|
return new this(obj);
|
2293
2413
|
}
|
2294
2414
|
/** Type of the transaction */
|
2295
|
-
type =
|
2415
|
+
type = import_transactions9.TransactionType.Script;
|
2296
2416
|
/** Gas limit for transaction */
|
2297
2417
|
gasLimit;
|
2298
2418
|
/** Script to execute */
|
@@ -2307,7 +2427,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2307
2427
|
*/
|
2308
2428
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2309
2429
|
super(rest);
|
2310
|
-
this.gasLimit = (0,
|
2430
|
+
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2311
2431
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
2312
2432
|
this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2313
2433
|
this.abis = rest.abis;
|
@@ -2321,12 +2441,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2321
2441
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2322
2442
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2323
2443
|
return {
|
2324
|
-
type:
|
2444
|
+
type: import_transactions9.TransactionType.Script,
|
2325
2445
|
scriptGasLimit: this.gasLimit,
|
2326
2446
|
...super.getBaseTransaction(),
|
2327
2447
|
scriptLength: script.length,
|
2328
2448
|
scriptDataLength: scriptData.length,
|
2329
|
-
receiptsRoot:
|
2449
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2330
2450
|
script: (0, import_utils15.hexlify)(script),
|
2331
2451
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2332
2452
|
};
|
@@ -2338,7 +2458,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2338
2458
|
*/
|
2339
2459
|
getContractInputs() {
|
2340
2460
|
return this.inputs.filter(
|
2341
|
-
(input) => input.type ===
|
2461
|
+
(input) => input.type === import_transactions9.InputType.Contract
|
2342
2462
|
);
|
2343
2463
|
}
|
2344
2464
|
/**
|
@@ -2348,7 +2468,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2348
2468
|
*/
|
2349
2469
|
getContractOutputs() {
|
2350
2470
|
return this.outputs.filter(
|
2351
|
-
(output) => output.type ===
|
2471
|
+
(output) => output.type === import_transactions9.OutputType.Contract
|
2352
2472
|
);
|
2353
2473
|
}
|
2354
2474
|
/**
|
@@ -2358,7 +2478,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2358
2478
|
*/
|
2359
2479
|
getVariableOutputs() {
|
2360
2480
|
return this.outputs.filter(
|
2361
|
-
(output) => output.type ===
|
2481
|
+
(output) => output.type === import_transactions9.OutputType.Variable
|
2362
2482
|
);
|
2363
2483
|
}
|
2364
2484
|
/**
|
@@ -2381,7 +2501,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2381
2501
|
let outputsNumber = numberOfVariables;
|
2382
2502
|
while (outputsNumber) {
|
2383
2503
|
this.pushOutput({
|
2384
|
-
type:
|
2504
|
+
type: import_transactions9.OutputType.Variable
|
2385
2505
|
});
|
2386
2506
|
outputsNumber -= 1;
|
2387
2507
|
}
|
@@ -2389,7 +2509,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2389
2509
|
}
|
2390
2510
|
calculateMaxGas(chainInfo, minGas) {
|
2391
2511
|
const { consensusParameters } = chainInfo;
|
2392
|
-
const { gasPerByte } = consensusParameters;
|
2512
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2393
2513
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2394
2514
|
(acc, wit) => acc + wit.dataLength,
|
2395
2515
|
0
|
@@ -2399,7 +2519,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2399
2519
|
minGas,
|
2400
2520
|
witnessesLength,
|
2401
2521
|
witnessLimit: this.witnessLimit,
|
2402
|
-
gasLimit: this.gasLimit
|
2522
|
+
gasLimit: this.gasLimit,
|
2523
|
+
maxGasPerTx
|
2403
2524
|
});
|
2404
2525
|
}
|
2405
2526
|
/**
|
@@ -2414,12 +2535,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2414
2535
|
return this;
|
2415
2536
|
}
|
2416
2537
|
const inputIndex = super.pushInput({
|
2417
|
-
type:
|
2538
|
+
type: import_transactions9.InputType.Contract,
|
2418
2539
|
contractId: contractAddress.toB256(),
|
2419
2540
|
txPointer: "0x00000000000000000000000000000000"
|
2420
2541
|
});
|
2421
2542
|
this.pushOutput({
|
2422
|
-
type:
|
2543
|
+
type: import_transactions9.OutputType.Contract,
|
2423
2544
|
inputIndex
|
2424
2545
|
});
|
2425
2546
|
return this;
|
@@ -2455,63 +2576,80 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2455
2576
|
};
|
2456
2577
|
|
2457
2578
|
// src/providers/transaction-request/utils.ts
|
2458
|
-
var
|
2459
|
-
var
|
2579
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2580
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2460
2581
|
var transactionRequestify = (obj) => {
|
2461
2582
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2462
2583
|
return obj;
|
2463
2584
|
}
|
2464
2585
|
const { type } = obj;
|
2465
2586
|
switch (obj.type) {
|
2466
|
-
case
|
2587
|
+
case import_transactions10.TransactionType.Script: {
|
2467
2588
|
return ScriptTransactionRequest.from(obj);
|
2468
2589
|
}
|
2469
|
-
case
|
2590
|
+
case import_transactions10.TransactionType.Create: {
|
2470
2591
|
return CreateTransactionRequest.from(obj);
|
2471
2592
|
}
|
2472
2593
|
default: {
|
2473
|
-
throw new
|
2594
|
+
throw new import_errors9.FuelError(import_errors9.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2474
2595
|
}
|
2475
2596
|
}
|
2476
2597
|
};
|
2598
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2599
|
+
(acc, input) => {
|
2600
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2601
|
+
acc.utxos.push(input.id);
|
2602
|
+
}
|
2603
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2604
|
+
acc.messages.push(input.nonce);
|
2605
|
+
}
|
2606
|
+
return acc;
|
2607
|
+
},
|
2608
|
+
{
|
2609
|
+
utxos: [],
|
2610
|
+
messages: []
|
2611
|
+
}
|
2612
|
+
);
|
2477
2613
|
|
2478
2614
|
// src/providers/transaction-response/transaction-response.ts
|
2479
|
-
var
|
2480
|
-
var
|
2481
|
-
var
|
2482
|
-
var
|
2615
|
+
var import_errors13 = require("@fuel-ts/errors");
|
2616
|
+
var import_math15 = require("@fuel-ts/math");
|
2617
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2618
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2483
2619
|
|
2484
2620
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2485
|
-
var
|
2621
|
+
var import_math14 = require("@fuel-ts/math");
|
2622
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2623
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2486
2624
|
|
2487
2625
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2488
|
-
var
|
2489
|
-
var
|
2626
|
+
var import_math11 = require("@fuel-ts/math");
|
2627
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2490
2628
|
var import_utils16 = require("@fuel-ts/utils");
|
2491
2629
|
var calculateTransactionFee = (params) => {
|
2492
2630
|
const {
|
2493
|
-
|
2631
|
+
gasPrice,
|
2494
2632
|
rawPayload,
|
2495
|
-
|
2633
|
+
tip,
|
2634
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2496
2635
|
} = params;
|
2497
|
-
const gasPerByte = (0,
|
2498
|
-
const gasPriceFactor = (0,
|
2636
|
+
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2637
|
+
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
2499
2638
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2500
|
-
const [transaction] = new
|
2501
|
-
if (transaction.type ===
|
2639
|
+
const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
|
2640
|
+
if (transaction.type === import_transactions11.TransactionType.Mint) {
|
2502
2641
|
return {
|
2503
|
-
fee: (0,
|
2504
|
-
minFee: (0,
|
2505
|
-
maxFee: (0,
|
2506
|
-
feeFromGasUsed: (0, import_math10.bn)(0)
|
2642
|
+
fee: (0, import_math11.bn)(0),
|
2643
|
+
minFee: (0, import_math11.bn)(0),
|
2644
|
+
maxFee: (0, import_math11.bn)(0)
|
2507
2645
|
};
|
2508
2646
|
}
|
2509
2647
|
const { type, witnesses, inputs, policies } = transaction;
|
2510
|
-
let metadataGas = (0,
|
2511
|
-
let gasLimit = (0,
|
2512
|
-
if (type ===
|
2648
|
+
let metadataGas = (0, import_math11.bn)(0);
|
2649
|
+
let gasLimit = (0, import_math11.bn)(0);
|
2650
|
+
if (type === import_transactions11.TransactionType.Create) {
|
2513
2651
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2514
|
-
const contractBytesSize = (0,
|
2652
|
+
const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2515
2653
|
metadataGas = calculateMetadataGasForTxCreate({
|
2516
2654
|
contractBytesSize,
|
2517
2655
|
gasCosts,
|
@@ -2530,42 +2668,49 @@ var calculateTransactionFee = (params) => {
|
|
2530
2668
|
}
|
2531
2669
|
const minGas = getMinGas({
|
2532
2670
|
gasCosts,
|
2533
|
-
gasPerByte: (0,
|
2671
|
+
gasPerByte: (0, import_math11.bn)(gasPerByte),
|
2534
2672
|
inputs,
|
2535
2673
|
metadataGas,
|
2536
2674
|
txBytesSize: transactionBytes.length
|
2537
2675
|
});
|
2538
|
-
const
|
2539
|
-
const witnessLimit = policies.find((policy) => policy.type === import_transactions10.PolicyType.WitnessLimit)?.data;
|
2676
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2540
2677
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2541
2678
|
const maxGas = getMaxGas({
|
2542
2679
|
gasPerByte,
|
2543
2680
|
minGas,
|
2544
2681
|
witnessesLength,
|
2545
2682
|
gasLimit,
|
2546
|
-
witnessLimit
|
2683
|
+
witnessLimit,
|
2684
|
+
maxGasPerTx
|
2685
|
+
});
|
2686
|
+
const minFee = calculateGasFee({
|
2687
|
+
gasPrice,
|
2688
|
+
gas: minGas,
|
2689
|
+
priceFactor: gasPriceFactor,
|
2690
|
+
tip
|
2691
|
+
});
|
2692
|
+
const maxFee = calculateGasFee({
|
2693
|
+
gasPrice,
|
2694
|
+
gas: maxGas,
|
2695
|
+
priceFactor: gasPriceFactor,
|
2696
|
+
tip
|
2547
2697
|
});
|
2548
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2549
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2550
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2551
|
-
const fee = minFee.add(feeFromGasUsed);
|
2552
2698
|
return {
|
2553
|
-
fee,
|
2554
2699
|
minFee,
|
2555
2700
|
maxFee,
|
2556
|
-
|
2701
|
+
fee: maxFee
|
2557
2702
|
};
|
2558
2703
|
};
|
2559
2704
|
|
2560
2705
|
// src/providers/transaction-summary/operations.ts
|
2561
|
-
var
|
2562
|
-
var
|
2563
|
-
var
|
2564
|
-
var
|
2706
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2707
|
+
var import_errors11 = require("@fuel-ts/errors");
|
2708
|
+
var import_math13 = require("@fuel-ts/math");
|
2709
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
2565
2710
|
|
2566
2711
|
// src/providers/transaction-summary/call.ts
|
2567
2712
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
2568
|
-
var
|
2713
|
+
var import_math12 = require("@fuel-ts/math");
|
2569
2714
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2570
2715
|
const abiInterface = new import_abi_coder2.Interface(abi);
|
2571
2716
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2574,7 +2719,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2574
2719
|
let encodedArgs;
|
2575
2720
|
if (functionFragment.isInputDataPointer) {
|
2576
2721
|
if (rawPayload) {
|
2577
|
-
const argsOffset = (0,
|
2722
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2578
2723
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2579
2724
|
}
|
2580
2725
|
} else {
|
@@ -2608,8 +2753,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2608
2753
|
};
|
2609
2754
|
|
2610
2755
|
// src/providers/transaction-summary/input.ts
|
2611
|
-
var
|
2612
|
-
var
|
2756
|
+
var import_errors10 = require("@fuel-ts/errors");
|
2757
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2613
2758
|
function getInputsByTypes(inputs, types) {
|
2614
2759
|
return inputs.filter((i) => types.includes(i.type));
|
2615
2760
|
}
|
@@ -2617,16 +2762,16 @@ function getInputsByType(inputs, type) {
|
|
2617
2762
|
return inputs.filter((i) => i.type === type);
|
2618
2763
|
}
|
2619
2764
|
function getInputsCoin(inputs) {
|
2620
|
-
return getInputsByType(inputs,
|
2765
|
+
return getInputsByType(inputs, import_transactions12.InputType.Coin);
|
2621
2766
|
}
|
2622
2767
|
function getInputsMessage(inputs) {
|
2623
|
-
return getInputsByType(inputs,
|
2768
|
+
return getInputsByType(inputs, import_transactions12.InputType.Message);
|
2624
2769
|
}
|
2625
2770
|
function getInputsCoinAndMessage(inputs) {
|
2626
|
-
return getInputsByTypes(inputs, [
|
2771
|
+
return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
|
2627
2772
|
}
|
2628
2773
|
function getInputsContract(inputs) {
|
2629
|
-
return getInputsByType(inputs,
|
2774
|
+
return getInputsByType(inputs, import_transactions12.InputType.Contract);
|
2630
2775
|
}
|
2631
2776
|
function getInputFromAssetId(inputs, assetId) {
|
2632
2777
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2645,40 +2790,40 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2645
2790
|
if (!contractInput) {
|
2646
2791
|
return void 0;
|
2647
2792
|
}
|
2648
|
-
if (contractInput.type !==
|
2649
|
-
throw new
|
2650
|
-
|
2793
|
+
if (contractInput.type !== import_transactions12.InputType.Contract) {
|
2794
|
+
throw new import_errors10.FuelError(
|
2795
|
+
import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2651
2796
|
`Contract input should be of type 'contract'.`
|
2652
2797
|
);
|
2653
2798
|
}
|
2654
2799
|
return contractInput;
|
2655
2800
|
}
|
2656
2801
|
function getInputAccountAddress(input) {
|
2657
|
-
if (input.type ===
|
2802
|
+
if (input.type === import_transactions12.InputType.Coin) {
|
2658
2803
|
return input.owner.toString();
|
2659
2804
|
}
|
2660
|
-
if (input.type ===
|
2805
|
+
if (input.type === import_transactions12.InputType.Message) {
|
2661
2806
|
return input.recipient.toString();
|
2662
2807
|
}
|
2663
2808
|
return "";
|
2664
2809
|
}
|
2665
2810
|
|
2666
2811
|
// src/providers/transaction-summary/output.ts
|
2667
|
-
var
|
2812
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2668
2813
|
function getOutputsByType(outputs, type) {
|
2669
2814
|
return outputs.filter((o) => o.type === type);
|
2670
2815
|
}
|
2671
2816
|
function getOutputsContractCreated(outputs) {
|
2672
|
-
return getOutputsByType(outputs,
|
2817
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
|
2673
2818
|
}
|
2674
2819
|
function getOutputsCoin(outputs) {
|
2675
|
-
return getOutputsByType(outputs,
|
2820
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
|
2676
2821
|
}
|
2677
2822
|
function getOutputsChange(outputs) {
|
2678
|
-
return getOutputsByType(outputs,
|
2823
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Change);
|
2679
2824
|
}
|
2680
2825
|
function getOutputsContract(outputs) {
|
2681
|
-
return getOutputsByType(outputs,
|
2826
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
|
2682
2827
|
}
|
2683
2828
|
|
2684
2829
|
// src/providers/transaction-summary/operations.ts
|
@@ -2687,15 +2832,15 @@ function getReceiptsByType(receipts, type) {
|
|
2687
2832
|
}
|
2688
2833
|
function getTransactionTypeName(transactionType) {
|
2689
2834
|
switch (transactionType) {
|
2690
|
-
case
|
2835
|
+
case import_transactions14.TransactionType.Mint:
|
2691
2836
|
return "Mint" /* Mint */;
|
2692
|
-
case
|
2837
|
+
case import_transactions14.TransactionType.Create:
|
2693
2838
|
return "Create" /* Create */;
|
2694
|
-
case
|
2839
|
+
case import_transactions14.TransactionType.Script:
|
2695
2840
|
return "Script" /* Script */;
|
2696
2841
|
default:
|
2697
|
-
throw new
|
2698
|
-
|
2842
|
+
throw new import_errors11.FuelError(
|
2843
|
+
import_errors11.ErrorCode.INVALID_TRANSACTION_TYPE,
|
2699
2844
|
`Invalid transaction type: ${transactionType}.`
|
2700
2845
|
);
|
2701
2846
|
}
|
@@ -2714,10 +2859,10 @@ function isTypeScript(transactionType) {
|
|
2714
2859
|
return isType(transactionType, "Script" /* Script */);
|
2715
2860
|
}
|
2716
2861
|
function getReceiptsCall(receipts) {
|
2717
|
-
return getReceiptsByType(receipts,
|
2862
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
|
2718
2863
|
}
|
2719
2864
|
function getReceiptsMessageOut(receipts) {
|
2720
|
-
return getReceiptsByType(receipts,
|
2865
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
|
2721
2866
|
}
|
2722
2867
|
var mergeAssets = (op1, op2) => {
|
2723
2868
|
const assets1 = op1.assetsSent || [];
|
@@ -2730,7 +2875,7 @@ var mergeAssets = (op1, op2) => {
|
|
2730
2875
|
if (!matchingAsset) {
|
2731
2876
|
return asset1;
|
2732
2877
|
}
|
2733
|
-
const mergedAmount = (0,
|
2878
|
+
const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
|
2734
2879
|
return { ...asset1, amount: mergedAmount };
|
2735
2880
|
});
|
2736
2881
|
return mergedAssets.concat(filteredAssets);
|
@@ -2856,7 +3001,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
2856
3001
|
const { to: toAddress, assetId, amount } = receipt;
|
2857
3002
|
let { from: fromAddress } = receipt;
|
2858
3003
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2859
|
-
if (
|
3004
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
2860
3005
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2861
3006
|
fromAddress = change?.to || fromAddress;
|
2862
3007
|
}
|
@@ -2913,11 +3058,11 @@ function getTransferOperations({
|
|
2913
3058
|
});
|
2914
3059
|
const transferReceipts = getReceiptsByType(
|
2915
3060
|
receipts,
|
2916
|
-
|
3061
|
+
import_transactions14.ReceiptType.Transfer
|
2917
3062
|
);
|
2918
3063
|
const transferOutReceipts = getReceiptsByType(
|
2919
3064
|
receipts,
|
2920
|
-
|
3065
|
+
import_transactions14.ReceiptType.TransferOut
|
2921
3066
|
);
|
2922
3067
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2923
3068
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3002,17 +3147,17 @@ function getOperations({
|
|
3002
3147
|
}
|
3003
3148
|
|
3004
3149
|
// src/providers/transaction-summary/receipt.ts
|
3005
|
-
var
|
3150
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3006
3151
|
var processGqlReceipt = (gqlReceipt) => {
|
3007
3152
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3008
3153
|
switch (receipt.type) {
|
3009
|
-
case
|
3154
|
+
case import_transactions15.ReceiptType.ReturnData: {
|
3010
3155
|
return {
|
3011
3156
|
...receipt,
|
3012
3157
|
data: gqlReceipt.data || "0x"
|
3013
3158
|
};
|
3014
3159
|
}
|
3015
|
-
case
|
3160
|
+
case import_transactions15.ReceiptType.LogData: {
|
3016
3161
|
return {
|
3017
3162
|
...receipt,
|
3018
3163
|
data: gqlReceipt.data || "0x"
|
@@ -3025,7 +3170,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3025
3170
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3026
3171
|
const mintedAssets = [];
|
3027
3172
|
receipts.forEach((receipt) => {
|
3028
|
-
if (receipt.type ===
|
3173
|
+
if (receipt.type === import_transactions15.ReceiptType.Mint) {
|
3029
3174
|
mintedAssets.push({
|
3030
3175
|
subId: receipt.subId,
|
3031
3176
|
contractId: receipt.contractId,
|
@@ -3039,7 +3184,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3039
3184
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3040
3185
|
const burnedAssets = [];
|
3041
3186
|
receipts.forEach((receipt) => {
|
3042
|
-
if (receipt.type ===
|
3187
|
+
if (receipt.type === import_transactions15.ReceiptType.Burn) {
|
3043
3188
|
burnedAssets.push({
|
3044
3189
|
subId: receipt.subId,
|
3045
3190
|
contractId: receipt.contractId,
|
@@ -3052,7 +3197,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3052
3197
|
};
|
3053
3198
|
|
3054
3199
|
// src/providers/transaction-summary/status.ts
|
3055
|
-
var
|
3200
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3056
3201
|
var getTransactionStatusName = (gqlStatus) => {
|
3057
3202
|
switch (gqlStatus) {
|
3058
3203
|
case "FailureStatus":
|
@@ -3064,8 +3209,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3064
3209
|
case "SqueezedOutStatus":
|
3065
3210
|
return "squeezedout" /* squeezedout */;
|
3066
3211
|
default:
|
3067
|
-
throw new
|
3068
|
-
|
3212
|
+
throw new import_errors12.FuelError(
|
3213
|
+
import_errors12.ErrorCode.INVALID_TRANSACTION_STATUS,
|
3069
3214
|
`Invalid transaction status: ${gqlStatus}.`
|
3070
3215
|
);
|
3071
3216
|
}
|
@@ -3120,10 +3265,12 @@ function assembleTransactionSummary(params) {
|
|
3120
3265
|
gqlTransactionStatus,
|
3121
3266
|
abiMap = {},
|
3122
3267
|
maxInputs,
|
3123
|
-
gasCosts
|
3268
|
+
gasCosts,
|
3269
|
+
maxGasPerTx,
|
3270
|
+
gasPrice
|
3124
3271
|
} = params;
|
3125
3272
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3126
|
-
const rawPayload = (0,
|
3273
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3127
3274
|
const operations = getOperations({
|
3128
3275
|
transactionType: transaction.type,
|
3129
3276
|
inputs: transaction.inputs || [],
|
@@ -3134,11 +3281,14 @@ function assembleTransactionSummary(params) {
|
|
3134
3281
|
maxInputs
|
3135
3282
|
});
|
3136
3283
|
const typeName = getTransactionTypeName(transaction.type);
|
3284
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3137
3285
|
const { fee } = calculateTransactionFee({
|
3138
|
-
|
3286
|
+
gasPrice,
|
3139
3287
|
rawPayload,
|
3288
|
+
tip,
|
3140
3289
|
consensusParameters: {
|
3141
3290
|
gasCosts,
|
3291
|
+
maxGasPerTx,
|
3142
3292
|
feeParams: {
|
3143
3293
|
gasPerByte,
|
3144
3294
|
gasPriceFactor
|
@@ -3150,7 +3300,7 @@ function assembleTransactionSummary(params) {
|
|
3150
3300
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3151
3301
|
let date;
|
3152
3302
|
if (time) {
|
3153
|
-
date =
|
3303
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3154
3304
|
}
|
3155
3305
|
const transactionSummary = {
|
3156
3306
|
id,
|
@@ -3178,12 +3328,12 @@ function assembleTransactionSummary(params) {
|
|
3178
3328
|
|
3179
3329
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3180
3330
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3181
|
-
var
|
3331
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3182
3332
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3183
3333
|
return receipts.reduce((logs, receipt) => {
|
3184
|
-
if (receipt.type ===
|
3334
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3185
3335
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3186
|
-
const data = receipt.type ===
|
3336
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3187
3337
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3188
3338
|
logs.push(decodedLog);
|
3189
3339
|
}
|
@@ -3198,7 +3348,7 @@ var TransactionResponse = class {
|
|
3198
3348
|
/** Current provider */
|
3199
3349
|
provider;
|
3200
3350
|
/** Gas used on the transaction */
|
3201
|
-
gasUsed = (0,
|
3351
|
+
gasUsed = (0, import_math15.bn)(0);
|
3202
3352
|
/** The graphql Transaction with receipts object. */
|
3203
3353
|
gqlTransaction;
|
3204
3354
|
abis;
|
@@ -3256,8 +3406,8 @@ var TransactionResponse = class {
|
|
3256
3406
|
* @returns The decoded transaction.
|
3257
3407
|
*/
|
3258
3408
|
decodeTransaction(transactionWithReceipts) {
|
3259
|
-
return new
|
3260
|
-
(0,
|
3409
|
+
return new import_transactions18.TransactionCoder().decode(
|
3410
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3261
3411
|
0
|
3262
3412
|
)?.[0];
|
3263
3413
|
}
|
@@ -3276,20 +3426,27 @@ var TransactionResponse = class {
|
|
3276
3426
|
const decodedTransaction = this.decodeTransaction(
|
3277
3427
|
transaction
|
3278
3428
|
);
|
3279
|
-
|
3280
|
-
|
3429
|
+
let txReceipts = [];
|
3430
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3431
|
+
txReceipts = transaction.status.receipts;
|
3432
|
+
}
|
3433
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3434
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3435
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3281
3436
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3282
3437
|
const transactionSummary = assembleTransactionSummary({
|
3283
3438
|
id: this.id,
|
3284
3439
|
receipts,
|
3285
3440
|
transaction: decodedTransaction,
|
3286
|
-
transactionBytes: (0,
|
3441
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3287
3442
|
gqlTransactionStatus: transaction.status,
|
3288
3443
|
gasPerByte,
|
3289
3444
|
gasPriceFactor,
|
3290
3445
|
abiMap: contractsAbiMap,
|
3291
3446
|
maxInputs,
|
3292
|
-
gasCosts
|
3447
|
+
gasCosts,
|
3448
|
+
maxGasPerTx,
|
3449
|
+
gasPrice
|
3293
3450
|
});
|
3294
3451
|
return transactionSummary;
|
3295
3452
|
}
|
@@ -3303,8 +3460,8 @@ var TransactionResponse = class {
|
|
3303
3460
|
});
|
3304
3461
|
for await (const { statusChange } of subscription) {
|
3305
3462
|
if (statusChange.type === "SqueezedOutStatus") {
|
3306
|
-
throw new
|
3307
|
-
|
3463
|
+
throw new import_errors13.FuelError(
|
3464
|
+
import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3308
3465
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3309
3466
|
);
|
3310
3467
|
}
|
@@ -3326,14 +3483,26 @@ var TransactionResponse = class {
|
|
3326
3483
|
gqlTransaction: this.gqlTransaction,
|
3327
3484
|
...transactionSummary
|
3328
3485
|
};
|
3486
|
+
let logs = [];
|
3329
3487
|
if (this.abis) {
|
3330
|
-
|
3488
|
+
logs = getDecodedLogs(
|
3331
3489
|
transactionSummary.receipts,
|
3332
3490
|
this.abis.main,
|
3333
3491
|
this.abis.otherContractsAbis
|
3334
3492
|
);
|
3335
3493
|
transactionResult.logs = logs;
|
3336
3494
|
}
|
3495
|
+
if (transactionResult.isStatusFailure) {
|
3496
|
+
const {
|
3497
|
+
receipts,
|
3498
|
+
gqlTransaction: { status }
|
3499
|
+
} = transactionResult;
|
3500
|
+
throw extractTxError({
|
3501
|
+
receipts,
|
3502
|
+
status,
|
3503
|
+
logs
|
3504
|
+
});
|
3505
|
+
}
|
3337
3506
|
return transactionResult;
|
3338
3507
|
}
|
3339
3508
|
/**
|
@@ -3342,14 +3511,7 @@ var TransactionResponse = class {
|
|
3342
3511
|
* @param contractsAbiMap - The contracts ABI map.
|
3343
3512
|
*/
|
3344
3513
|
async wait(contractsAbiMap) {
|
3345
|
-
|
3346
|
-
if (result.isStatusFailure) {
|
3347
|
-
throw new import_errors12.FuelError(
|
3348
|
-
import_errors12.ErrorCode.TRANSACTION_FAILED,
|
3349
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3350
|
-
);
|
3351
|
-
}
|
3352
|
-
return result;
|
3514
|
+
return this.waitForResult(contractsAbiMap);
|
3353
3515
|
}
|
3354
3516
|
};
|
3355
3517
|
|
@@ -3411,30 +3573,29 @@ var processGqlChain = (chain) => {
|
|
3411
3573
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3412
3574
|
return {
|
3413
3575
|
name,
|
3414
|
-
baseChainHeight: (0,
|
3576
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3415
3577
|
consensusParameters: {
|
3416
|
-
contractMaxSize: (0,
|
3417
|
-
maxInputs: (0,
|
3418
|
-
maxOutputs: (0,
|
3419
|
-
maxWitnesses: (0,
|
3420
|
-
maxGasPerTx: (0,
|
3421
|
-
maxScriptLength: (0,
|
3422
|
-
maxScriptDataLength: (0,
|
3423
|
-
maxStorageSlots: (0,
|
3424
|
-
maxPredicateLength: (0,
|
3425
|
-
maxPredicateDataLength: (0,
|
3426
|
-
maxGasPerPredicate: (0,
|
3427
|
-
gasPriceFactor: (0,
|
3428
|
-
gasPerByte: (0,
|
3429
|
-
maxMessageDataLength: (0,
|
3430
|
-
chainId: (0,
|
3431
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3578
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3579
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3580
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3581
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3582
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3583
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3584
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3585
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3586
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3587
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3588
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3589
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3590
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3591
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3592
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3432
3593
|
gasCosts
|
3433
3594
|
},
|
3434
3595
|
gasCosts,
|
3435
3596
|
latestBlock: {
|
3436
3597
|
id: latestBlock.id,
|
3437
|
-
height: (0,
|
3598
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3438
3599
|
time: latestBlock.header.time,
|
3439
3600
|
transactions: latestBlock.transactions.map((i) => ({
|
3440
3601
|
id: i.id
|
@@ -3504,8 +3665,8 @@ var _Provider = class {
|
|
3504
3665
|
getChain() {
|
3505
3666
|
const chain = _Provider.chainInfoCache[this.url];
|
3506
3667
|
if (!chain) {
|
3507
|
-
throw new
|
3508
|
-
|
3668
|
+
throw new import_errors14.FuelError(
|
3669
|
+
import_errors14.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
3509
3670
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3510
3671
|
);
|
3511
3672
|
}
|
@@ -3517,8 +3678,8 @@ var _Provider = class {
|
|
3517
3678
|
getNode() {
|
3518
3679
|
const node = _Provider.nodeInfoCache[this.url];
|
3519
3680
|
if (!node) {
|
3520
|
-
throw new
|
3521
|
-
|
3681
|
+
throw new import_errors14.FuelError(
|
3682
|
+
import_errors14.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
3522
3683
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3523
3684
|
);
|
3524
3685
|
}
|
@@ -3565,8 +3726,8 @@ var _Provider = class {
|
|
3565
3726
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3566
3727
|
const { isMajorSupported, isMinorSupported, supportedVersion } = (0, import_versions.checkFuelCoreVersionCompatibility)(nodeInfo.nodeVersion);
|
3567
3728
|
if (!isMajorSupported || !isMinorSupported) {
|
3568
|
-
throw new
|
3569
|
-
|
3729
|
+
throw new import_errors14.FuelError(
|
3730
|
+
import_errors14.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3570
3731
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3571
3732
|
);
|
3572
3733
|
}
|
@@ -3619,7 +3780,7 @@ var _Provider = class {
|
|
3619
3780
|
name,
|
3620
3781
|
consensusParameters: { chainId }
|
3621
3782
|
} = await this.getChain();
|
3622
|
-
const network = new
|
3783
|
+
const network = new import_ethers2.Network(name, chainId.toNumber());
|
3623
3784
|
return Promise.resolve(network);
|
3624
3785
|
}
|
3625
3786
|
/**
|
@@ -3629,7 +3790,7 @@ var _Provider = class {
|
|
3629
3790
|
*/
|
3630
3791
|
async getBlockNumber() {
|
3631
3792
|
const { chain } = await this.operations.getChain();
|
3632
|
-
return (0,
|
3793
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3633
3794
|
}
|
3634
3795
|
/**
|
3635
3796
|
* Returns the chain information.
|
@@ -3639,13 +3800,12 @@ var _Provider = class {
|
|
3639
3800
|
async fetchNode() {
|
3640
3801
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3641
3802
|
const processedNodeInfo = {
|
3642
|
-
maxDepth: (0,
|
3643
|
-
maxTx: (0,
|
3644
|
-
minGasPrice: (0,
|
3803
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
3804
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3805
|
+
minGasPrice: (0, import_math16.bn)(nodeInfo.minGasPrice),
|
3645
3806
|
nodeVersion: nodeInfo.nodeVersion,
|
3646
3807
|
utxoValidation: nodeInfo.utxoValidation,
|
3647
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3648
|
-
peers: nodeInfo.peers
|
3808
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3649
3809
|
};
|
3650
3810
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3651
3811
|
return processedNodeInfo;
|
@@ -3671,17 +3831,6 @@ var _Provider = class {
|
|
3671
3831
|
} = this.getChain();
|
3672
3832
|
return chainId.toNumber();
|
3673
3833
|
}
|
3674
|
-
/**
|
3675
|
-
* Returns the base asset ID
|
3676
|
-
*
|
3677
|
-
* @returns A promise that resolves to the base asset ID
|
3678
|
-
*/
|
3679
|
-
getBaseAssetId() {
|
3680
|
-
const {
|
3681
|
-
consensusParameters: { baseAssetId }
|
3682
|
-
} = this.getChain();
|
3683
|
-
return baseAssetId;
|
3684
|
-
}
|
3685
3834
|
/**
|
3686
3835
|
* Submits a transaction to the chain to be executed.
|
3687
3836
|
*
|
@@ -3700,15 +3849,15 @@ var _Provider = class {
|
|
3700
3849
|
}
|
3701
3850
|
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3702
3851
|
let abis;
|
3703
|
-
if (transactionRequest.type ===
|
3852
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
3704
3853
|
abis = transactionRequest.abis;
|
3705
3854
|
}
|
3706
3855
|
if (awaitExecution) {
|
3707
3856
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3708
3857
|
for await (const { submitAndAwait } of subscription) {
|
3709
3858
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3710
|
-
throw new
|
3711
|
-
|
3859
|
+
throw new import_errors14.FuelError(
|
3860
|
+
import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3712
3861
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3713
3862
|
);
|
3714
3863
|
}
|
@@ -3742,14 +3891,13 @@ var _Provider = class {
|
|
3742
3891
|
return this.estimateTxDependencies(transactionRequest);
|
3743
3892
|
}
|
3744
3893
|
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3745
|
-
const { dryRun:
|
3746
|
-
encodedTransaction,
|
3894
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3895
|
+
encodedTransactions: encodedTransaction,
|
3747
3896
|
utxoValidation: utxoValidation || false
|
3748
3897
|
});
|
3749
|
-
const receipts =
|
3750
|
-
|
3751
|
-
|
3752
|
-
};
|
3898
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3899
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3900
|
+
return { receipts, dryrunStatus: status };
|
3753
3901
|
}
|
3754
3902
|
/**
|
3755
3903
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3760,7 +3908,7 @@ var _Provider = class {
|
|
3760
3908
|
async estimatePredicates(transactionRequest) {
|
3761
3909
|
const shouldEstimatePredicates = Boolean(
|
3762
3910
|
transactionRequest.inputs.find(
|
3763
|
-
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new
|
3911
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
|
3764
3912
|
)
|
3765
3913
|
);
|
3766
3914
|
if (!shouldEstimatePredicates) {
|
@@ -3775,7 +3923,7 @@ var _Provider = class {
|
|
3775
3923
|
} = response;
|
3776
3924
|
if (inputs) {
|
3777
3925
|
inputs.forEach((input, index) => {
|
3778
|
-
if ("predicateGasUsed" in input && (0,
|
3926
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
3779
3927
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3780
3928
|
}
|
3781
3929
|
});
|
@@ -3788,31 +3936,31 @@ var _Provider = class {
|
|
3788
3936
|
* If there are missing variable outputs,
|
3789
3937
|
* `addVariableOutputs` is called on the transaction.
|
3790
3938
|
*
|
3791
|
-
* @privateRemarks
|
3792
|
-
* TODO: Investigate support for missing contract IDs
|
3793
|
-
* TODO: Add support for missing output messages
|
3794
3939
|
*
|
3795
3940
|
* @param transactionRequest - The transaction request object.
|
3796
3941
|
* @returns A promise.
|
3797
3942
|
*/
|
3798
3943
|
async estimateTxDependencies(transactionRequest) {
|
3799
|
-
if (transactionRequest.type ===
|
3944
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
3800
3945
|
return {
|
3801
3946
|
receipts: [],
|
3802
3947
|
outputVariables: 0,
|
3803
3948
|
missingContractIds: []
|
3804
3949
|
};
|
3805
3950
|
}
|
3806
|
-
await this.estimatePredicates(transactionRequest);
|
3807
3951
|
let receipts = [];
|
3808
3952
|
const missingContractIds = [];
|
3809
3953
|
let outputVariables = 0;
|
3954
|
+
let dryrunStatus;
|
3810
3955
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3811
|
-
const {
|
3812
|
-
|
3956
|
+
const {
|
3957
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3958
|
+
} = await this.operations.dryRun({
|
3959
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3813
3960
|
utxoValidation: false
|
3814
3961
|
});
|
3815
|
-
receipts =
|
3962
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3963
|
+
dryrunStatus = status;
|
3816
3964
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3817
3965
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3818
3966
|
if (hasMissingOutputs) {
|
@@ -3822,6 +3970,11 @@ var _Provider = class {
|
|
3822
3970
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3823
3971
|
missingContractIds.push(contractId);
|
3824
3972
|
});
|
3973
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3974
|
+
transactionRequest,
|
3975
|
+
optimizeGas: false
|
3976
|
+
});
|
3977
|
+
transactionRequest.maxFee = maxFee;
|
3825
3978
|
} else {
|
3826
3979
|
break;
|
3827
3980
|
}
|
@@ -3829,7 +3982,133 @@ var _Provider = class {
|
|
3829
3982
|
return {
|
3830
3983
|
receipts,
|
3831
3984
|
outputVariables,
|
3832
|
-
missingContractIds
|
3985
|
+
missingContractIds,
|
3986
|
+
dryrunStatus
|
3987
|
+
};
|
3988
|
+
}
|
3989
|
+
/**
|
3990
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3991
|
+
*
|
3992
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3993
|
+
* further modifications are identified. The method iteratively updates these transactions
|
3994
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3995
|
+
*
|
3996
|
+
* @param transactionRequests - Array of transaction request objects.
|
3997
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
3998
|
+
*/
|
3999
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4000
|
+
const results = transactionRequests.map(() => ({
|
4001
|
+
receipts: [],
|
4002
|
+
outputVariables: 0,
|
4003
|
+
missingContractIds: [],
|
4004
|
+
dryrunStatus: void 0
|
4005
|
+
}));
|
4006
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4007
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4008
|
+
allRequests.forEach((req, index) => {
|
4009
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4010
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4011
|
+
}
|
4012
|
+
});
|
4013
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4014
|
+
let attempt = 0;
|
4015
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4016
|
+
const encodedTransactions = transactionsToProcess.map(
|
4017
|
+
(index) => serializedTransactionsMap.get(index)
|
4018
|
+
);
|
4019
|
+
const dryRunResults = await this.operations.dryRun({
|
4020
|
+
encodedTransactions,
|
4021
|
+
utxoValidation: false
|
4022
|
+
});
|
4023
|
+
const nextRoundTransactions = [];
|
4024
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4025
|
+
const currentResultIndex = transactionsToProcess[i];
|
4026
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4027
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4028
|
+
results[currentResultIndex].dryrunStatus = status;
|
4029
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4030
|
+
results[currentResultIndex].receipts
|
4031
|
+
);
|
4032
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4033
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4034
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4035
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4036
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4037
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4038
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4039
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4040
|
+
});
|
4041
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4042
|
+
transactionRequest: requestToProcess,
|
4043
|
+
optimizeGas: false
|
4044
|
+
});
|
4045
|
+
requestToProcess.maxFee = maxFee;
|
4046
|
+
serializedTransactionsMap.set(
|
4047
|
+
currentResultIndex,
|
4048
|
+
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4049
|
+
);
|
4050
|
+
nextRoundTransactions.push(currentResultIndex);
|
4051
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4052
|
+
}
|
4053
|
+
}
|
4054
|
+
transactionsToProcess = nextRoundTransactions;
|
4055
|
+
attempt += 1;
|
4056
|
+
}
|
4057
|
+
return results;
|
4058
|
+
}
|
4059
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4060
|
+
if (estimateTxDependencies) {
|
4061
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4062
|
+
}
|
4063
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4064
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4065
|
+
encodedTransactions,
|
4066
|
+
utxoValidation: utxoValidation || false
|
4067
|
+
});
|
4068
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4069
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4070
|
+
return { receipts, dryrunStatus: status };
|
4071
|
+
});
|
4072
|
+
return results;
|
4073
|
+
}
|
4074
|
+
async estimateTxGasAndFee(params) {
|
4075
|
+
const { transactionRequest, totalGasUsedByPredicates = (0, import_math16.bn)(0), optimizeGas = true } = params;
|
4076
|
+
let { gasPrice } = params;
|
4077
|
+
const chainInfo = this.getChain();
|
4078
|
+
const { gasPriceFactor } = this.getGasConfig();
|
4079
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4080
|
+
if (!gasPrice) {
|
4081
|
+
gasPrice = await this.estimateGasPrice(10);
|
4082
|
+
}
|
4083
|
+
const shouldSetGaslimit = transactionRequest.type === import_transactions19.TransactionType.Script && !optimizeGas;
|
4084
|
+
const minFee = calculateGasFee({
|
4085
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4086
|
+
gas: minGas,
|
4087
|
+
priceFactor: gasPriceFactor,
|
4088
|
+
tip: transactionRequest.tip
|
4089
|
+
}).add(1);
|
4090
|
+
if (shouldSetGaslimit) {
|
4091
|
+
transactionRequest.gasLimit = chainInfo.consensusParameters.maxGasPerTx.sub(
|
4092
|
+
minGas.add(totalGasUsedByPredicates)
|
4093
|
+
);
|
4094
|
+
}
|
4095
|
+
let maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4096
|
+
const maxFee = calculateGasFee({
|
4097
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4098
|
+
gas: maxGas,
|
4099
|
+
priceFactor: gasPriceFactor,
|
4100
|
+
tip: transactionRequest.tip
|
4101
|
+
}).add(1);
|
4102
|
+
if (shouldSetGaslimit) {
|
4103
|
+
maxGas = chainInfo.consensusParameters.maxGasPerTx.sub(maxFee);
|
4104
|
+
transactionRequest.gasLimit = maxGas;
|
4105
|
+
}
|
4106
|
+
return {
|
4107
|
+
minGas,
|
4108
|
+
minFee,
|
4109
|
+
maxGas,
|
4110
|
+
maxFee,
|
4111
|
+
gasPrice
|
3833
4112
|
};
|
3834
4113
|
}
|
3835
4114
|
/**
|
@@ -3847,15 +4126,17 @@ var _Provider = class {
|
|
3847
4126
|
if (estimateTxDependencies) {
|
3848
4127
|
return this.estimateTxDependencies(transactionRequest);
|
3849
4128
|
}
|
3850
|
-
const
|
3851
|
-
const { dryRun:
|
3852
|
-
|
4129
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4130
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4131
|
+
encodedTransactions,
|
3853
4132
|
utxoValidation: true
|
3854
4133
|
});
|
3855
|
-
const
|
3856
|
-
|
3857
|
-
receipts
|
3858
|
-
|
4134
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4135
|
+
const { id, receipts, status } = dryRunStatus;
|
4136
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4137
|
+
return { id, receipts: processedReceipts, status };
|
4138
|
+
});
|
4139
|
+
return { receipts: callResult[0].receipts };
|
3859
4140
|
}
|
3860
4141
|
/**
|
3861
4142
|
* Returns a transaction cost to enable user
|
@@ -3872,80 +4153,80 @@ var _Provider = class {
|
|
3872
4153
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3873
4154
|
* @returns A promise that resolves to the transaction cost object.
|
3874
4155
|
*/
|
3875
|
-
async getTransactionCost(transactionRequestLike,
|
3876
|
-
estimateTxDependencies = true,
|
3877
|
-
estimatePredicates = true,
|
3878
|
-
resourcesOwner,
|
3879
|
-
signatureCallback
|
3880
|
-
} = {}) {
|
4156
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3881
4157
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3882
|
-
const
|
3883
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3884
|
-
const gasPrice = (0, import_math14.max)(txRequestClone.gasPrice, minGasPrice);
|
3885
|
-
const isScriptTransaction = txRequestClone.type === import_transactions17.TransactionType.Script;
|
4158
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
3886
4159
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3887
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4160
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3888
4161
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3889
|
-
|
3890
|
-
|
3891
|
-
|
3892
|
-
}
|
3893
|
-
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3894
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3895
|
-
}
|
3896
|
-
await this.estimatePredicates(txRequestClone);
|
4162
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4163
|
+
if (isScriptTransaction) {
|
4164
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
3897
4165
|
}
|
3898
|
-
if (
|
3899
|
-
|
4166
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4167
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3900
4168
|
}
|
3901
|
-
const
|
3902
|
-
|
4169
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4170
|
+
let addedSignatures = 0;
|
4171
|
+
if (signatureCallback && isScriptTransaction) {
|
4172
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4173
|
+
await signatureCallback(signedRequest);
|
4174
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4175
|
+
}
|
4176
|
+
await this.estimatePredicates(signedRequest);
|
4177
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4178
|
+
transactionRequest: signedRequest,
|
4179
|
+
optimizeGas: false
|
4180
|
+
});
|
4181
|
+
txRequestClone.maxFee = maxFee;
|
3903
4182
|
let receipts = [];
|
3904
4183
|
let missingContractIds = [];
|
3905
4184
|
let outputVariables = 0;
|
3906
|
-
|
3907
|
-
|
3908
|
-
|
4185
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4186
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4187
|
+
if (isScriptTransaction) {
|
4188
|
+
if (signatureCallback) {
|
4189
|
+
await signatureCallback(txRequestClone);
|
4190
|
+
}
|
4191
|
+
txRequestClone.gasLimit = maxGas;
|
3909
4192
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3910
4193
|
receipts = result.receipts;
|
3911
4194
|
outputVariables = result.outputVariables;
|
3912
4195
|
missingContractIds = result.missingContractIds;
|
4196
|
+
gasUsed = getGasUsedFromReceipts(receipts);
|
4197
|
+
txRequestClone.gasLimit = gasUsed;
|
4198
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4199
|
+
transactionRequest: txRequestClone,
|
4200
|
+
gasPrice
|
4201
|
+
}));
|
3913
4202
|
}
|
3914
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3915
|
-
const usedFee = calculatePriceWithFactor(
|
3916
|
-
gasUsed,
|
3917
|
-
gasPrice,
|
3918
|
-
gasPriceFactor
|
3919
|
-
).normalizeZeroToOne();
|
3920
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3921
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3922
4203
|
return {
|
3923
4204
|
requiredQuantities: allQuantities,
|
3924
4205
|
receipts,
|
3925
4206
|
gasUsed,
|
3926
|
-
minGasPrice,
|
3927
4207
|
gasPrice,
|
3928
4208
|
minGas,
|
3929
4209
|
maxGas,
|
3930
|
-
usedFee,
|
3931
4210
|
minFee,
|
3932
4211
|
maxFee,
|
3933
|
-
estimatedInputs: txRequestClone.inputs,
|
3934
4212
|
outputVariables,
|
3935
|
-
missingContractIds
|
4213
|
+
missingContractIds,
|
4214
|
+
addedSignatures,
|
4215
|
+
estimatedPredicates: txRequestClone.inputs
|
3936
4216
|
};
|
3937
4217
|
}
|
3938
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4218
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
3939
4219
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
3940
4220
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
3941
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4221
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4222
|
+
quantitiesToContract
|
4223
|
+
});
|
3942
4224
|
transactionRequest.addResources(
|
3943
4225
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
3944
4226
|
);
|
3945
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
3946
|
-
|
3947
|
-
|
3948
|
-
);
|
4227
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4228
|
+
quantitiesToContract
|
4229
|
+
});
|
3949
4230
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
3950
4231
|
return {
|
3951
4232
|
resources,
|
@@ -3967,11 +4248,10 @@ var _Provider = class {
|
|
3967
4248
|
return coins.map((coin) => ({
|
3968
4249
|
id: coin.utxoId,
|
3969
4250
|
assetId: coin.assetId,
|
3970
|
-
amount: (0,
|
4251
|
+
amount: (0, import_math16.bn)(coin.amount),
|
3971
4252
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
3972
|
-
|
3973
|
-
|
3974
|
-
txCreatedIdx: (0, import_math14.bn)(coin.txCreatedIdx)
|
4253
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4254
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
3975
4255
|
}));
|
3976
4256
|
}
|
3977
4257
|
/**
|
@@ -4008,9 +4288,9 @@ var _Provider = class {
|
|
4008
4288
|
switch (coin.__typename) {
|
4009
4289
|
case "MessageCoin":
|
4010
4290
|
return {
|
4011
|
-
amount: (0,
|
4291
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4012
4292
|
assetId: coin.assetId,
|
4013
|
-
daHeight: (0,
|
4293
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4014
4294
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4015
4295
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4016
4296
|
nonce: coin.nonce
|
@@ -4018,12 +4298,11 @@ var _Provider = class {
|
|
4018
4298
|
case "Coin":
|
4019
4299
|
return {
|
4020
4300
|
id: coin.utxoId,
|
4021
|
-
amount: (0,
|
4301
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4022
4302
|
assetId: coin.assetId,
|
4023
4303
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4024
|
-
|
4025
|
-
|
4026
|
-
txCreatedIdx: (0, import_math14.bn)(coin.txCreatedIdx)
|
4304
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4305
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4027
4306
|
};
|
4028
4307
|
default:
|
4029
4308
|
return null;
|
@@ -4040,13 +4319,13 @@ var _Provider = class {
|
|
4040
4319
|
async getBlock(idOrHeight) {
|
4041
4320
|
let variables;
|
4042
4321
|
if (typeof idOrHeight === "number") {
|
4043
|
-
variables = { height: (0,
|
4322
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4044
4323
|
} else if (idOrHeight === "latest") {
|
4045
4324
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4046
4325
|
} else if (idOrHeight.length === 66) {
|
4047
4326
|
variables = { blockId: idOrHeight };
|
4048
4327
|
} else {
|
4049
|
-
variables = { blockId: (0,
|
4328
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4050
4329
|
}
|
4051
4330
|
const { block } = await this.operations.getBlock(variables);
|
4052
4331
|
if (!block) {
|
@@ -4054,7 +4333,7 @@ var _Provider = class {
|
|
4054
4333
|
}
|
4055
4334
|
return {
|
4056
4335
|
id: block.id,
|
4057
|
-
height: (0,
|
4336
|
+
height: (0, import_math16.bn)(block.height),
|
4058
4337
|
time: block.header.time,
|
4059
4338
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4060
4339
|
};
|
@@ -4069,7 +4348,7 @@ var _Provider = class {
|
|
4069
4348
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4070
4349
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4071
4350
|
id: block.id,
|
4072
|
-
height: (0,
|
4351
|
+
height: (0, import_math16.bn)(block.height),
|
4073
4352
|
time: block.header.time,
|
4074
4353
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4075
4354
|
}));
|
@@ -4084,7 +4363,7 @@ var _Provider = class {
|
|
4084
4363
|
async getBlockWithTransactions(idOrHeight) {
|
4085
4364
|
let variables;
|
4086
4365
|
if (typeof idOrHeight === "number") {
|
4087
|
-
variables = { blockHeight: (0,
|
4366
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4088
4367
|
} else if (idOrHeight === "latest") {
|
4089
4368
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4090
4369
|
} else {
|
@@ -4096,11 +4375,11 @@ var _Provider = class {
|
|
4096
4375
|
}
|
4097
4376
|
return {
|
4098
4377
|
id: block.id,
|
4099
|
-
height: (0,
|
4378
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4100
4379
|
time: block.header.time,
|
4101
4380
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4102
4381
|
transactions: block.transactions.map(
|
4103
|
-
(tx) => new
|
4382
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4104
4383
|
)
|
4105
4384
|
};
|
4106
4385
|
}
|
@@ -4115,7 +4394,7 @@ var _Provider = class {
|
|
4115
4394
|
if (!transaction) {
|
4116
4395
|
return null;
|
4117
4396
|
}
|
4118
|
-
return new
|
4397
|
+
return new import_transactions19.TransactionCoder().decode(
|
4119
4398
|
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4120
4399
|
0
|
4121
4400
|
)?.[0];
|
@@ -4145,7 +4424,7 @@ var _Provider = class {
|
|
4145
4424
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4146
4425
|
asset: (0, import_utils22.hexlify)(assetId)
|
4147
4426
|
});
|
4148
|
-
return (0,
|
4427
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4149
4428
|
}
|
4150
4429
|
/**
|
4151
4430
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4159,7 +4438,7 @@ var _Provider = class {
|
|
4159
4438
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4160
4439
|
assetId: (0, import_utils22.hexlify)(assetId)
|
4161
4440
|
});
|
4162
|
-
return (0,
|
4441
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4163
4442
|
}
|
4164
4443
|
/**
|
4165
4444
|
* Returns balances for the given owner.
|
@@ -4177,7 +4456,7 @@ var _Provider = class {
|
|
4177
4456
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4178
4457
|
return balances.map((balance) => ({
|
4179
4458
|
assetId: balance.assetId,
|
4180
|
-
amount: (0,
|
4459
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4181
4460
|
}));
|
4182
4461
|
}
|
4183
4462
|
/**
|
@@ -4195,19 +4474,19 @@ var _Provider = class {
|
|
4195
4474
|
});
|
4196
4475
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4197
4476
|
return messages.map((message) => ({
|
4198
|
-
messageId:
|
4477
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4199
4478
|
sender: message.sender,
|
4200
4479
|
recipient: message.recipient,
|
4201
4480
|
nonce: message.nonce,
|
4202
|
-
amount: (0,
|
4481
|
+
amount: (0, import_math16.bn)(message.amount),
|
4203
4482
|
data: message.data
|
4204
4483
|
}),
|
4205
4484
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4206
4485
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4207
4486
|
nonce: message.nonce,
|
4208
|
-
amount: (0,
|
4209
|
-
data:
|
4210
|
-
daHeight: (0,
|
4487
|
+
amount: (0, import_math16.bn)(message.amount),
|
4488
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4489
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4211
4490
|
}));
|
4212
4491
|
}
|
4213
4492
|
/**
|
@@ -4225,8 +4504,8 @@ var _Provider = class {
|
|
4225
4504
|
nonce
|
4226
4505
|
};
|
4227
4506
|
if (commitBlockId && commitBlockHeight) {
|
4228
|
-
throw new
|
4229
|
-
|
4507
|
+
throw new import_errors14.FuelError(
|
4508
|
+
import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4230
4509
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4231
4510
|
);
|
4232
4511
|
}
|
@@ -4260,44 +4539,54 @@ var _Provider = class {
|
|
4260
4539
|
} = result.messageProof;
|
4261
4540
|
return {
|
4262
4541
|
messageProof: {
|
4263
|
-
proofIndex: (0,
|
4542
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4264
4543
|
proofSet: messageProof.proofSet
|
4265
4544
|
},
|
4266
4545
|
blockProof: {
|
4267
|
-
proofIndex: (0,
|
4546
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4268
4547
|
proofSet: blockProof.proofSet
|
4269
4548
|
},
|
4270
4549
|
messageBlockHeader: {
|
4271
4550
|
id: messageBlockHeader.id,
|
4272
|
-
daHeight: (0,
|
4273
|
-
transactionsCount: (0,
|
4551
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4552
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4274
4553
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4275
|
-
height: (0,
|
4554
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4276
4555
|
prevRoot: messageBlockHeader.prevRoot,
|
4277
4556
|
time: messageBlockHeader.time,
|
4278
4557
|
applicationHash: messageBlockHeader.applicationHash,
|
4279
4558
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4280
|
-
messageReceiptCount: (0,
|
4559
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount)
|
4281
4560
|
},
|
4282
4561
|
commitBlockHeader: {
|
4283
4562
|
id: commitBlockHeader.id,
|
4284
|
-
daHeight: (0,
|
4285
|
-
transactionsCount: (0,
|
4563
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4564
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4286
4565
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4287
|
-
height: (0,
|
4566
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4288
4567
|
prevRoot: commitBlockHeader.prevRoot,
|
4289
4568
|
time: commitBlockHeader.time,
|
4290
4569
|
applicationHash: commitBlockHeader.applicationHash,
|
4291
4570
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4292
|
-
messageReceiptCount: (0,
|
4571
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount)
|
4293
4572
|
},
|
4294
4573
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4295
4574
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4296
4575
|
nonce,
|
4297
|
-
amount: (0,
|
4576
|
+
amount: (0, import_math16.bn)(amount),
|
4298
4577
|
data
|
4299
4578
|
};
|
4300
4579
|
}
|
4580
|
+
async getLatestGasPrice() {
|
4581
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4582
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4583
|
+
}
|
4584
|
+
async estimateGasPrice(blockHorizon) {
|
4585
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4586
|
+
blockHorizon: String(blockHorizon)
|
4587
|
+
});
|
4588
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4589
|
+
}
|
4301
4590
|
/**
|
4302
4591
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4303
4592
|
*
|
@@ -4317,10 +4606,10 @@ var _Provider = class {
|
|
4317
4606
|
*/
|
4318
4607
|
async produceBlocks(amount, startTime) {
|
4319
4608
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4320
|
-
blocksToProduce: (0,
|
4609
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4321
4610
|
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4322
4611
|
});
|
4323
|
-
return (0,
|
4612
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4324
4613
|
}
|
4325
4614
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4326
4615
|
async getTransactionResponse(transactionId) {
|
@@ -4334,7 +4623,7 @@ cacheInputs_fn = function(inputs) {
|
|
4334
4623
|
return;
|
4335
4624
|
}
|
4336
4625
|
inputs.forEach((input) => {
|
4337
|
-
if (input.type ===
|
4626
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4338
4627
|
this.cache?.set(input.id);
|
4339
4628
|
}
|
4340
4629
|
});
|
@@ -4343,9 +4632,9 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4343
4632
|
__publicField(Provider, "nodeInfoCache", {});
|
4344
4633
|
|
4345
4634
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4346
|
-
var
|
4347
|
-
var
|
4348
|
-
var
|
4635
|
+
var import_errors15 = require("@fuel-ts/errors");
|
4636
|
+
var import_math17 = require("@fuel-ts/math");
|
4637
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4349
4638
|
var import_utils25 = require("@fuel-ts/utils");
|
4350
4639
|
|
4351
4640
|
// src/providers/chains.ts
|
@@ -4395,13 +4684,13 @@ var assets = [
|
|
4395
4684
|
|
4396
4685
|
// src/utils/formatTransferToContractScriptData.ts
|
4397
4686
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4398
|
-
var
|
4687
|
+
var import_math18 = require("@fuel-ts/math");
|
4399
4688
|
var import_utils26 = require("@fuel-ts/utils");
|
4400
4689
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4401
4690
|
var formatTransferToContractScriptData = (params) => {
|
4402
4691
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4403
4692
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4404
|
-
const encoded = numberCoder.encode(new
|
4693
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4405
4694
|
const scriptData = Uint8Array.from([
|
4406
4695
|
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4407
4696
|
...encoded,
|
@@ -4461,7 +4750,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4461
4750
|
*/
|
4462
4751
|
get provider() {
|
4463
4752
|
if (!this._provider) {
|
4464
|
-
throw new
|
4753
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
4465
4754
|
}
|
4466
4755
|
return this._provider;
|
4467
4756
|
}
|
@@ -4513,8 +4802,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4513
4802
|
if (!hasNextPage) {
|
4514
4803
|
break;
|
4515
4804
|
}
|
4516
|
-
throw new
|
4517
|
-
|
4805
|
+
throw new import_errors16.FuelError(
|
4806
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4518
4807
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4519
4808
|
);
|
4520
4809
|
}
|
@@ -4539,8 +4828,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4539
4828
|
if (!hasNextPage) {
|
4540
4829
|
break;
|
4541
4830
|
}
|
4542
|
-
throw new
|
4543
|
-
|
4831
|
+
throw new import_errors16.FuelError(
|
4832
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4544
4833
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4545
4834
|
);
|
4546
4835
|
}
|
@@ -4552,9 +4841,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4552
4841
|
* @param assetId - The asset ID to check the balance for.
|
4553
4842
|
* @returns A promise that resolves to the balance amount.
|
4554
4843
|
*/
|
4555
|
-
async getBalance(assetId) {
|
4556
|
-
const
|
4557
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4844
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
4845
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4558
4846
|
return amount;
|
4559
4847
|
}
|
4560
4848
|
/**
|
@@ -4576,8 +4864,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4576
4864
|
if (!hasNextPage) {
|
4577
4865
|
break;
|
4578
4866
|
}
|
4579
|
-
throw new
|
4580
|
-
|
4867
|
+
throw new import_errors16.FuelError(
|
4868
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4581
4869
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4582
4870
|
);
|
4583
4871
|
}
|
@@ -4591,37 +4879,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4591
4879
|
* @param fee - The estimated transaction fee.
|
4592
4880
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4593
4881
|
*/
|
4594
|
-
async fund(request,
|
4595
|
-
const
|
4596
|
-
const
|
4597
|
-
|
4598
|
-
|
4599
|
-
|
4882
|
+
async fund(request, params) {
|
4883
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4884
|
+
const txRequest = request;
|
4885
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4886
|
+
amount: (0, import_math19.bn)(fee),
|
4887
|
+
assetId: import_configs12.BaseAssetId,
|
4888
|
+
coinQuantities: requiredQuantities
|
4600
4889
|
});
|
4601
4890
|
const quantitiesDict = {};
|
4602
|
-
|
4891
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4603
4892
|
quantitiesDict[assetId] = {
|
4604
4893
|
required: amount,
|
4605
|
-
owned: (0,
|
4894
|
+
owned: (0, import_math19.bn)(0)
|
4606
4895
|
};
|
4607
4896
|
});
|
4608
|
-
|
4609
|
-
const cachedMessages = [];
|
4610
|
-
const owner = this.address.toB256();
|
4611
|
-
request.inputs.forEach((input) => {
|
4897
|
+
txRequest.inputs.forEach((input) => {
|
4612
4898
|
const isResource = "amount" in input;
|
4613
4899
|
if (isResource) {
|
4614
4900
|
const isCoin2 = "owner" in input;
|
4615
4901
|
if (isCoin2) {
|
4616
4902
|
const assetId = String(input.assetId);
|
4617
|
-
if (
|
4618
|
-
const amount = (0,
|
4903
|
+
if (quantitiesDict[assetId]) {
|
4904
|
+
const amount = (0, import_math19.bn)(input.amount);
|
4619
4905
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4620
|
-
cachedUtxos.push(input.id);
|
4621
4906
|
}
|
4622
|
-
} else if (input.
|
4623
|
-
quantitiesDict[
|
4624
|
-
cachedMessages.push(input.nonce);
|
4907
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4908
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4625
4909
|
}
|
4626
4910
|
}
|
4627
4911
|
});
|
@@ -4636,12 +4920,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4636
4920
|
});
|
4637
4921
|
const needsToBeFunded = missingQuantities.length;
|
4638
4922
|
if (needsToBeFunded) {
|
4639
|
-
const
|
4640
|
-
|
4641
|
-
|
4642
|
-
|
4643
|
-
|
4923
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toString());
|
4924
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4925
|
+
txRequest.addResources(resources);
|
4926
|
+
}
|
4927
|
+
txRequest.shiftPredicateData();
|
4928
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4929
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4930
|
+
if (addedSignatures) {
|
4931
|
+
Array.from({ length: addedSignatures }).forEach(
|
4932
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4933
|
+
);
|
4644
4934
|
}
|
4935
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4936
|
+
transactionRequest: requestToBeReEstimate
|
4937
|
+
});
|
4938
|
+
txRequest.maxFee = maxFee;
|
4939
|
+
return txRequest;
|
4645
4940
|
}
|
4646
4941
|
/**
|
4647
4942
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4649,29 +4944,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4649
4944
|
* @param destination - The address of the destination.
|
4650
4945
|
* @param amount - The amount of coins to transfer.
|
4651
4946
|
* @param assetId - The asset ID of the coins to transfer.
|
4652
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4947
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4653
4948
|
* @returns A promise that resolves to the prepared transaction request.
|
4654
4949
|
*/
|
4655
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4656
|
-
const
|
4657
|
-
|
4658
|
-
const
|
4659
|
-
const request = new ScriptTransactionRequest(params);
|
4660
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4661
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4950
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4951
|
+
const request = new ScriptTransactionRequest(txParams);
|
4952
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4953
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4662
4954
|
estimateTxDependencies: true,
|
4663
4955
|
resourcesOwner: this
|
4664
4956
|
});
|
4665
|
-
|
4666
|
-
|
4667
|
-
|
4668
|
-
|
4669
|
-
|
4670
|
-
|
4671
|
-
|
4672
|
-
|
4673
|
-
await this.fund(request,
|
4674
|
-
request.updatePredicateInputs(estimatedInputs);
|
4957
|
+
if ("gasLimit" in txParams) {
|
4958
|
+
this.validateGas({
|
4959
|
+
gasUsed: txCost.gasUsed,
|
4960
|
+
gasLimit: request.gasLimit
|
4961
|
+
});
|
4962
|
+
}
|
4963
|
+
request.gasLimit = txCost.gasUsed;
|
4964
|
+
request.maxFee = txCost.maxFee;
|
4965
|
+
await this.fund(request, txCost);
|
4675
4966
|
return request;
|
4676
4967
|
}
|
4677
4968
|
/**
|
@@ -4683,15 +4974,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4683
4974
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4684
4975
|
* @returns A promise that resolves to the transaction response.
|
4685
4976
|
*/
|
4686
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4687
|
-
if ((0,
|
4688
|
-
throw new
|
4689
|
-
|
4977
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4978
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4979
|
+
throw new import_errors16.FuelError(
|
4980
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4690
4981
|
"Transfer amount must be a positive number."
|
4691
4982
|
);
|
4692
4983
|
}
|
4693
|
-
const
|
4694
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4984
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4695
4985
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4696
4986
|
}
|
4697
4987
|
/**
|
@@ -4703,40 +4993,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4703
4993
|
* @param txParams - The optional transaction parameters.
|
4704
4994
|
* @returns A promise that resolves to the transaction response.
|
4705
4995
|
*/
|
4706
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4707
|
-
if ((0,
|
4708
|
-
throw new
|
4709
|
-
|
4996
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4997
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4998
|
+
throw new import_errors16.FuelError(
|
4999
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4710
5000
|
"Transfer amount must be a positive number."
|
4711
5001
|
);
|
4712
5002
|
}
|
4713
5003
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4714
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4715
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4716
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4717
5004
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4718
5005
|
hexlifiedContractId: contractAddress.toB256(),
|
4719
|
-
amountToTransfer: (0,
|
4720
|
-
assetId
|
5006
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
5007
|
+
assetId
|
4721
5008
|
});
|
4722
5009
|
const request = new ScriptTransactionRequest({
|
4723
|
-
...
|
5010
|
+
...txParams,
|
4724
5011
|
script,
|
4725
5012
|
scriptData
|
4726
5013
|
});
|
4727
5014
|
request.addContractInputAndOutput(contractAddress);
|
4728
|
-
const
|
4729
|
-
|
4730
|
-
[{ amount: (0,
|
4731
|
-
);
|
4732
|
-
request.gasLimit = (0, import_math17.bn)(params.gasLimit ?? gasUsed);
|
4733
|
-
this.validateGas({
|
4734
|
-
gasUsed,
|
4735
|
-
gasPrice: request.gasPrice,
|
4736
|
-
gasLimit: request.gasLimit,
|
4737
|
-
minGasPrice
|
5015
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5016
|
+
resourcesOwner: this,
|
5017
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
4738
5018
|
});
|
4739
|
-
|
5019
|
+
if (txParams.gasLimit) {
|
5020
|
+
this.validateGas({
|
5021
|
+
gasUsed: txCost.gasUsed,
|
5022
|
+
gasLimit: request.gasLimit
|
5023
|
+
});
|
5024
|
+
}
|
5025
|
+
request.gasLimit = txCost.gasUsed;
|
5026
|
+
request.maxFee = txCost.maxFee;
|
5027
|
+
await this.fund(request, txCost);
|
4740
5028
|
return this.sendTransaction(request);
|
4741
5029
|
}
|
4742
5030
|
/**
|
@@ -4748,40 +5036,36 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4748
5036
|
* @returns A promise that resolves to the transaction response.
|
4749
5037
|
*/
|
4750
5038
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4751
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4752
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4753
5039
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4754
5040
|
const recipientDataArray = (0, import_utils27.arrayify)(
|
4755
5041
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4756
5042
|
);
|
4757
5043
|
const amountDataArray = (0, import_utils27.arrayify)(
|
4758
|
-
"0x".concat((0,
|
5044
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4759
5045
|
);
|
4760
5046
|
const script = new Uint8Array([
|
4761
5047
|
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
4762
5048
|
...recipientDataArray,
|
4763
5049
|
...amountDataArray
|
4764
5050
|
]);
|
4765
|
-
const params = { script,
|
5051
|
+
const params = { script, ...txParams };
|
4766
5052
|
const request = new ScriptTransactionRequest(params);
|
4767
|
-
const
|
4768
|
-
const
|
4769
|
-
|
4770
|
-
|
4771
|
-
|
4772
|
-
|
4773
|
-
|
4774
|
-
|
4775
|
-
|
4776
|
-
|
4777
|
-
|
4778
|
-
});
|
4779
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5053
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5054
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5055
|
+
if (txParams.gasLimit) {
|
5056
|
+
this.validateGas({
|
5057
|
+
gasUsed: txCost.gasUsed,
|
5058
|
+
gasLimit: request.gasLimit
|
5059
|
+
});
|
5060
|
+
}
|
5061
|
+
request.maxFee = txCost.maxFee;
|
5062
|
+
request.gasLimit = txCost.gasUsed;
|
5063
|
+
await this.fund(request, txCost);
|
4780
5064
|
return this.sendTransaction(request);
|
4781
5065
|
}
|
4782
5066
|
async signMessage(message) {
|
4783
5067
|
if (!this._connector) {
|
4784
|
-
throw new
|
5068
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4785
5069
|
}
|
4786
5070
|
return this._connector.signMessage(this.address.toString(), message);
|
4787
5071
|
}
|
@@ -4793,8 +5077,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4793
5077
|
*/
|
4794
5078
|
async signTransaction(transactionRequestLike) {
|
4795
5079
|
if (!this._connector) {
|
4796
|
-
throw new
|
4797
|
-
|
5080
|
+
throw new import_errors16.FuelError(
|
5081
|
+
import_errors16.ErrorCode.MISSING_CONNECTOR,
|
4798
5082
|
"A connector is required to sign transactions."
|
4799
5083
|
);
|
4800
5084
|
}
|
@@ -4834,21 +5118,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4834
5118
|
}
|
4835
5119
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4836
5120
|
}
|
4837
|
-
validateGas({
|
4838
|
-
gasUsed,
|
4839
|
-
gasPrice,
|
4840
|
-
gasLimit,
|
4841
|
-
minGasPrice
|
4842
|
-
}) {
|
4843
|
-
if (minGasPrice.gt(gasPrice)) {
|
4844
|
-
throw new import_errors15.FuelError(
|
4845
|
-
import_errors15.ErrorCode.GAS_PRICE_TOO_LOW,
|
4846
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4847
|
-
);
|
4848
|
-
}
|
5121
|
+
validateGas({ gasUsed, gasLimit }) {
|
4849
5122
|
if (gasUsed.gt(gasLimit)) {
|
4850
|
-
throw new
|
4851
|
-
|
5123
|
+
throw new import_errors16.FuelError(
|
5124
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
4852
5125
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4853
5126
|
);
|
4854
5127
|
}
|
@@ -4859,7 +5132,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4859
5132
|
var import_address5 = require("@fuel-ts/address");
|
4860
5133
|
var import_crypto = require("@fuel-ts/crypto");
|
4861
5134
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4862
|
-
var
|
5135
|
+
var import_math20 = require("@fuel-ts/math");
|
4863
5136
|
var import_utils28 = require("@fuel-ts/utils");
|
4864
5137
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4865
5138
|
var Signer = class {
|
@@ -4879,7 +5152,7 @@ var Signer = class {
|
|
4879
5152
|
privateKey = `0x${privateKey}`;
|
4880
5153
|
}
|
4881
5154
|
}
|
4882
|
-
const privateKeyBytes = (0,
|
5155
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
4883
5156
|
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
4884
5157
|
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4885
5158
|
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
@@ -4897,8 +5170,8 @@ var Signer = class {
|
|
4897
5170
|
*/
|
4898
5171
|
sign(data) {
|
4899
5172
|
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
4900
|
-
const r = (0,
|
4901
|
-
const s = (0,
|
5173
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5174
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4902
5175
|
s[0] |= (signature.recovery || 0) << 7;
|
4903
5176
|
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
4904
5177
|
}
|
@@ -4967,7 +5240,7 @@ var Signer = class {
|
|
4967
5240
|
// src/wallet/keystore-wallet.ts
|
4968
5241
|
var import_address6 = require("@fuel-ts/address");
|
4969
5242
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4970
|
-
var
|
5243
|
+
var import_errors17 = require("@fuel-ts/errors");
|
4971
5244
|
var import_utils29 = require("@fuel-ts/utils");
|
4972
5245
|
var import_uuid = require("uuid");
|
4973
5246
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5045,8 +5318,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5045
5318
|
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5046
5319
|
const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5047
5320
|
if (mac !== macHash) {
|
5048
|
-
throw new
|
5049
|
-
|
5321
|
+
throw new import_errors17.FuelError(
|
5322
|
+
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5050
5323
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5051
5324
|
);
|
5052
5325
|
}
|
@@ -5129,7 +5402,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5129
5402
|
* @param transactionRequestLike - The transaction request to send.
|
5130
5403
|
* @returns A promise that resolves to the TransactionResponse object.
|
5131
5404
|
*/
|
5132
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5405
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5133
5406
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5134
5407
|
if (estimateTxDependencies) {
|
5135
5408
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5168,18 +5441,18 @@ var BaseWalletUnlocked = class extends Account {
|
|
5168
5441
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5169
5442
|
|
5170
5443
|
// src/hdwallet/hdwallet.ts
|
5171
|
-
var
|
5444
|
+
var import_errors20 = require("@fuel-ts/errors");
|
5172
5445
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5173
|
-
var
|
5446
|
+
var import_math21 = require("@fuel-ts/math");
|
5174
5447
|
var import_utils34 = require("@fuel-ts/utils");
|
5175
|
-
var
|
5448
|
+
var import_ethers4 = require("ethers");
|
5176
5449
|
|
5177
5450
|
// src/mnemonic/mnemonic.ts
|
5178
5451
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5179
|
-
var
|
5452
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5180
5453
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5181
5454
|
var import_utils32 = require("@fuel-ts/utils");
|
5182
|
-
var
|
5455
|
+
var import_ethers3 = require("ethers");
|
5183
5456
|
|
5184
5457
|
// src/wordlists/words/english.ts
|
5185
5458
|
var english = [
|
@@ -7234,7 +7507,7 @@ var english = [
|
|
7234
7507
|
];
|
7235
7508
|
|
7236
7509
|
// src/mnemonic/utils.ts
|
7237
|
-
var
|
7510
|
+
var import_errors18 = require("@fuel-ts/errors");
|
7238
7511
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7239
7512
|
var import_utils31 = require("@fuel-ts/utils");
|
7240
7513
|
function toUtf8Bytes(stri) {
|
@@ -7251,8 +7524,8 @@ function toUtf8Bytes(stri) {
|
|
7251
7524
|
i += 1;
|
7252
7525
|
const c2 = str.charCodeAt(i);
|
7253
7526
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7254
|
-
throw new
|
7255
|
-
|
7527
|
+
throw new import_errors18.FuelError(
|
7528
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
7256
7529
|
"Invalid UTF-8 in the input string."
|
7257
7530
|
);
|
7258
7531
|
}
|
@@ -7315,8 +7588,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7315
7588
|
for (let i = 0; i < words.length; i += 1) {
|
7316
7589
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7317
7590
|
if (index === -1) {
|
7318
|
-
throw new
|
7319
|
-
|
7591
|
+
throw new import_errors18.FuelError(
|
7592
|
+
import_errors18.ErrorCode.INVALID_MNEMONIC,
|
7320
7593
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7321
7594
|
);
|
7322
7595
|
}
|
@@ -7332,8 +7605,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7332
7605
|
const checksumMask = getUpperMask(checksumBits);
|
7333
7606
|
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7334
7607
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7335
|
-
throw new
|
7336
|
-
|
7608
|
+
throw new import_errors18.FuelError(
|
7609
|
+
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
7337
7610
|
"Checksum validation failed for the provided mnemonic."
|
7338
7611
|
);
|
7339
7612
|
}
|
@@ -7347,16 +7620,16 @@ var TestnetPRV = "0x04358394";
|
|
7347
7620
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7348
7621
|
function assertWordList(wordlist) {
|
7349
7622
|
if (wordlist.length !== 2048) {
|
7350
|
-
throw new
|
7351
|
-
|
7623
|
+
throw new import_errors19.FuelError(
|
7624
|
+
import_errors19.ErrorCode.INVALID_WORD_LIST,
|
7352
7625
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7353
7626
|
);
|
7354
7627
|
}
|
7355
7628
|
}
|
7356
7629
|
function assertEntropy(entropy) {
|
7357
7630
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7358
|
-
throw new
|
7359
|
-
|
7631
|
+
throw new import_errors19.FuelError(
|
7632
|
+
import_errors19.ErrorCode.INVALID_ENTROPY,
|
7360
7633
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7361
7634
|
);
|
7362
7635
|
}
|
@@ -7366,7 +7639,7 @@ function assertMnemonic(words) {
|
|
7366
7639
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7367
7640
|
", "
|
7368
7641
|
)}] words, but got ${words.length}.`;
|
7369
|
-
throw new
|
7642
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
7370
7643
|
}
|
7371
7644
|
}
|
7372
7645
|
var Mnemonic = class {
|
@@ -7427,7 +7700,7 @@ var Mnemonic = class {
|
|
7427
7700
|
assertMnemonic(getWords(phrase));
|
7428
7701
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7429
7702
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7430
|
-
return (0,
|
7703
|
+
return (0, import_ethers3.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7431
7704
|
}
|
7432
7705
|
/**
|
7433
7706
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7484,12 +7757,12 @@ var Mnemonic = class {
|
|
7484
7757
|
static masterKeysFromSeed(seed) {
|
7485
7758
|
const seedArray = (0, import_utils32.arrayify)(seed);
|
7486
7759
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7487
|
-
throw new
|
7488
|
-
|
7760
|
+
throw new import_errors19.FuelError(
|
7761
|
+
import_errors19.ErrorCode.INVALID_SEED,
|
7489
7762
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7490
7763
|
);
|
7491
7764
|
}
|
7492
|
-
return (0, import_utils32.arrayify)((0,
|
7765
|
+
return (0, import_utils32.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
|
7493
7766
|
}
|
7494
7767
|
/**
|
7495
7768
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7514,8 +7787,8 @@ var Mnemonic = class {
|
|
7514
7787
|
chainCode,
|
7515
7788
|
(0, import_utils32.concat)(["0x00", privateKey])
|
7516
7789
|
]);
|
7517
|
-
const checksum = (0,
|
7518
|
-
return (0,
|
7790
|
+
const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7791
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7519
7792
|
}
|
7520
7793
|
/**
|
7521
7794
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7543,7 +7816,7 @@ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
|
7543
7816
|
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7544
7817
|
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7545
7818
|
function base58check(data) {
|
7546
|
-
return (0,
|
7819
|
+
return (0, import_ethers4.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7547
7820
|
}
|
7548
7821
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7549
7822
|
if (isPublic) {
|
@@ -7562,7 +7835,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7562
7835
|
function parsePath(path2, depth = 0) {
|
7563
7836
|
const components = path2.split("/");
|
7564
7837
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7565
|
-
throw new
|
7838
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7566
7839
|
}
|
7567
7840
|
if (components[0] === "m") {
|
7568
7841
|
components.shift();
|
@@ -7591,15 +7864,15 @@ var HDWallet = class {
|
|
7591
7864
|
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
7592
7865
|
} else {
|
7593
7866
|
if (!config.publicKey) {
|
7594
|
-
throw new
|
7595
|
-
|
7867
|
+
throw new import_errors20.FuelError(
|
7868
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7596
7869
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7597
7870
|
);
|
7598
7871
|
}
|
7599
7872
|
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7600
7873
|
}
|
7601
7874
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7602
|
-
this.fingerprint = (0,
|
7875
|
+
this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
7603
7876
|
this.depth = config.depth || this.depth;
|
7604
7877
|
this.index = config.index || this.index;
|
7605
7878
|
this.chainCode = config.chainCode;
|
@@ -7621,8 +7894,8 @@ var HDWallet = class {
|
|
7621
7894
|
const data = new Uint8Array(37);
|
7622
7895
|
if (index & HARDENED_INDEX) {
|
7623
7896
|
if (!privateKey) {
|
7624
|
-
throw new
|
7625
|
-
|
7897
|
+
throw new import_errors20.FuelError(
|
7898
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7626
7899
|
"Cannot derive a hardened index without a private Key."
|
7627
7900
|
);
|
7628
7901
|
}
|
@@ -7630,13 +7903,13 @@ var HDWallet = class {
|
|
7630
7903
|
} else {
|
7631
7904
|
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7632
7905
|
}
|
7633
|
-
data.set((0,
|
7634
|
-
const bytes = (0, import_utils34.arrayify)((0,
|
7906
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
7907
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
|
7635
7908
|
const IL = bytes.slice(0, 32);
|
7636
7909
|
const IR = bytes.slice(32);
|
7637
7910
|
if (privateKey) {
|
7638
7911
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7639
|
-
const ki = (0,
|
7912
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7640
7913
|
return new HDWallet({
|
7641
7914
|
privateKey: ki,
|
7642
7915
|
chainCode: IR,
|
@@ -7674,15 +7947,15 @@ var HDWallet = class {
|
|
7674
7947
|
*/
|
7675
7948
|
toExtendedKey(isPublic = false, testnet = false) {
|
7676
7949
|
if (this.depth >= 256) {
|
7677
|
-
throw new
|
7678
|
-
|
7950
|
+
throw new import_errors20.FuelError(
|
7951
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7679
7952
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7680
7953
|
);
|
7681
7954
|
}
|
7682
7955
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7683
7956
|
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
7684
7957
|
const parentFingerprint = this.parentFingerprint;
|
7685
|
-
const index = (0,
|
7958
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
7686
7959
|
const chainCode = this.chainCode;
|
7687
7960
|
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7688
7961
|
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
@@ -7702,14 +7975,14 @@ var HDWallet = class {
|
|
7702
7975
|
});
|
7703
7976
|
}
|
7704
7977
|
static fromExtendedKey(extendedKey) {
|
7705
|
-
const decoded = (0,
|
7978
|
+
const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
|
7706
7979
|
const bytes = (0, import_utils34.arrayify)(decoded);
|
7707
7980
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7708
7981
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7709
|
-
throw new
|
7982
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7710
7983
|
}
|
7711
7984
|
if (!validChecksum) {
|
7712
|
-
throw new
|
7985
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7713
7986
|
}
|
7714
7987
|
const depth = bytes[4];
|
7715
7988
|
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
@@ -7717,14 +7990,14 @@ var HDWallet = class {
|
|
7717
7990
|
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
7718
7991
|
const key = bytes.slice(45, 78);
|
7719
7992
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7720
|
-
throw new
|
7721
|
-
|
7993
|
+
throw new import_errors20.FuelError(
|
7994
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7722
7995
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7723
7996
|
);
|
7724
7997
|
}
|
7725
7998
|
if (isPublicExtendedKey(bytes)) {
|
7726
7999
|
if (key[0] !== 3) {
|
7727
|
-
throw new
|
8000
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
7728
8001
|
}
|
7729
8002
|
return new HDWallet({
|
7730
8003
|
publicKey: key,
|
@@ -7735,7 +8008,7 @@ var HDWallet = class {
|
|
7735
8008
|
});
|
7736
8009
|
}
|
7737
8010
|
if (key[0] !== 0) {
|
7738
|
-
throw new
|
8011
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
7739
8012
|
}
|
7740
8013
|
return new HDWallet({
|
7741
8014
|
privateKey: key.slice(1),
|
@@ -7907,14 +8180,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7907
8180
|
process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
|
7908
8181
|
wallet.provider
|
7909
8182
|
);
|
7910
|
-
const
|
7911
|
-
|
7912
|
-
|
7913
|
-
|
7914
|
-
gasPrice: minGasPrice
|
8183
|
+
const request = new ScriptTransactionRequest();
|
8184
|
+
quantities.forEach((quantity) => {
|
8185
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8186
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7915
8187
|
});
|
7916
|
-
|
7917
|
-
|
8188
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8189
|
+
request.gasLimit = txCost.gasUsed;
|
8190
|
+
request.maxFee = txCost.maxFee;
|
8191
|
+
await genesisWallet.fund(request, txCost);
|
7918
8192
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
7919
8193
|
};
|
7920
8194
|
|
@@ -7928,8 +8202,8 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7928
8202
|
};
|
7929
8203
|
|
7930
8204
|
// src/test-utils/launchNode.ts
|
7931
|
-
var
|
7932
|
-
var
|
8205
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8206
|
+
var import_math22 = require("@fuel-ts/math");
|
7933
8207
|
var import_utils35 = require("@fuel-ts/utils");
|
7934
8208
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7935
8209
|
var import_child_process = require("child_process");
|
@@ -8027,8 +8301,8 @@ var launchNode = async ({
|
|
8027
8301
|
...import_utils35.defaultChainConfig.initial_state.coins,
|
8028
8302
|
{
|
8029
8303
|
owner: signer.address.toHexString(),
|
8030
|
-
amount: (0,
|
8031
|
-
asset_id:
|
8304
|
+
amount: (0, import_math22.toHex)(1e9),
|
8305
|
+
asset_id: import_configs13.BaseAssetId
|
8032
8306
|
}
|
8033
8307
|
]
|
8034
8308
|
}
|
@@ -8044,7 +8318,7 @@ var launchNode = async ({
|
|
8044
8318
|
["--ip", ipToUse],
|
8045
8319
|
["--port", portToUse],
|
8046
8320
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8047
|
-
["--min-gas-price", "
|
8321
|
+
["--min-gas-price", "1"],
|
8048
8322
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8049
8323
|
["--consensus-key", consensusKey],
|
8050
8324
|
["--chain", chainConfigPathToUse],
|
@@ -8094,10 +8368,9 @@ var launchNode = async ({
|
|
8094
8368
|
})
|
8095
8369
|
);
|
8096
8370
|
var generateWallets = async (count, provider) => {
|
8097
|
-
const baseAssetId = provider.getBaseAssetId();
|
8098
8371
|
const wallets = [];
|
8099
8372
|
for (let i = 0; i < count; i += 1) {
|
8100
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8373
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
|
8101
8374
|
wallets.push(wallet);
|
8102
8375
|
}
|
8103
8376
|
return wallets;
|
@@ -8107,7 +8380,7 @@ var launchNodeAndGetWallets = async ({
|
|
8107
8380
|
walletCount = 10
|
8108
8381
|
} = {}) => {
|
8109
8382
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8110
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8383
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8111
8384
|
const wallets = await generateWallets(walletCount, provider);
|
8112
8385
|
const cleanup = () => {
|
8113
8386
|
closeNode();
|