@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/index.mjs
CHANGED
@@ -29,35 +29,38 @@ var __privateMethod = (obj, member, method) => {
|
|
29
29
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
|
-
import {
|
32
|
+
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
33
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
34
|
-
import { bn as
|
35
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
35
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
|
+
import { clone as clone4 } from "ramda";
|
36
38
|
|
37
39
|
// src/providers/coin-quantity.ts
|
40
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
38
41
|
import { bn } from "@fuel-ts/math";
|
39
42
|
import { hexlify } from "@fuel-ts/utils";
|
40
43
|
var coinQuantityfy = (coinQuantityLike) => {
|
41
44
|
let assetId;
|
42
45
|
let amount;
|
43
|
-
let
|
46
|
+
let max;
|
44
47
|
if (Array.isArray(coinQuantityLike)) {
|
45
48
|
amount = coinQuantityLike[0];
|
46
|
-
assetId = coinQuantityLike[1];
|
47
|
-
|
49
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
50
|
+
max = coinQuantityLike[2] ?? void 0;
|
48
51
|
} else {
|
49
52
|
amount = coinQuantityLike.amount;
|
50
|
-
assetId = coinQuantityLike.assetId;
|
51
|
-
|
53
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
54
|
+
max = coinQuantityLike.max ?? void 0;
|
52
55
|
}
|
53
56
|
const bnAmount = bn(amount);
|
54
57
|
return {
|
55
58
|
assetId: hexlify(assetId),
|
56
59
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
57
|
-
max:
|
60
|
+
max: max ? bn(max) : void 0
|
58
61
|
};
|
59
62
|
};
|
60
|
-
var
|
63
|
+
var addAmountToCoinQuantities = (params) => {
|
61
64
|
const { amount, assetId } = params;
|
62
65
|
const coinQuantities = [...params.coinQuantities];
|
63
66
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -71,10 +74,10 @@ var addAmountToAsset = (params) => {
|
|
71
74
|
|
72
75
|
// src/providers/provider.ts
|
73
76
|
import { Address as Address2 } from "@fuel-ts/address";
|
74
|
-
import { ErrorCode as
|
75
|
-
import { BN, bn as
|
77
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
78
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
76
79
|
import {
|
77
|
-
InputType as
|
80
|
+
InputType as InputType7,
|
78
81
|
TransactionType as TransactionType8,
|
79
82
|
InputMessageCoder,
|
80
83
|
TransactionCoder as TransactionCoder5
|
@@ -90,14 +93,10 @@ import { clone as clone3 } from "ramda";
|
|
90
93
|
import gql from "graphql-tag";
|
91
94
|
var ReceiptFragmentFragmentDoc = gql`
|
92
95
|
fragment receiptFragment on Receipt {
|
93
|
-
|
94
|
-
id
|
95
|
-
}
|
96
|
+
id
|
96
97
|
pc
|
97
98
|
is
|
98
|
-
to
|
99
|
-
id
|
100
|
-
}
|
99
|
+
to
|
101
100
|
toAddress
|
102
101
|
amount
|
103
102
|
assetId
|
@@ -135,10 +134,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
135
134
|
id
|
136
135
|
}
|
137
136
|
time
|
137
|
+
receipts {
|
138
|
+
...receiptFragment
|
139
|
+
}
|
138
140
|
programState {
|
139
141
|
returnType
|
140
142
|
data
|
141
143
|
}
|
144
|
+
receipts {
|
145
|
+
...receiptFragment
|
146
|
+
}
|
142
147
|
}
|
143
148
|
... on FailureStatus {
|
144
149
|
block {
|
@@ -146,26 +151,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
146
151
|
}
|
147
152
|
time
|
148
153
|
reason
|
154
|
+
receipts {
|
155
|
+
...receiptFragment
|
156
|
+
}
|
149
157
|
}
|
150
158
|
... on SqueezedOutStatus {
|
151
159
|
reason
|
152
160
|
}
|
153
161
|
}
|
154
|
-
`;
|
162
|
+
${ReceiptFragmentFragmentDoc}`;
|
155
163
|
var TransactionFragmentFragmentDoc = gql`
|
156
164
|
fragment transactionFragment on Transaction {
|
157
165
|
id
|
158
166
|
rawPayload
|
159
|
-
gasPrice
|
160
|
-
receipts {
|
161
|
-
...receiptFragment
|
162
|
-
}
|
163
167
|
status {
|
164
168
|
...transactionStatusFragment
|
165
169
|
}
|
166
170
|
}
|
167
|
-
${
|
168
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
171
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
169
172
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
170
173
|
fragment inputEstimatePredicatesFragment on Input {
|
171
174
|
... on InputCoin {
|
@@ -183,6 +186,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
183
186
|
}
|
184
187
|
}
|
185
188
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
189
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
190
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
191
|
+
reason
|
192
|
+
programState {
|
193
|
+
returnType
|
194
|
+
data
|
195
|
+
}
|
196
|
+
}
|
197
|
+
`;
|
198
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
199
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
200
|
+
programState {
|
201
|
+
returnType
|
202
|
+
data
|
203
|
+
}
|
204
|
+
}
|
205
|
+
`;
|
206
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
207
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
208
|
+
... on DryRunFailureStatus {
|
209
|
+
...dryRunFailureStatusFragment
|
210
|
+
}
|
211
|
+
... on DryRunSuccessStatus {
|
212
|
+
...dryRunSuccessStatusFragment
|
213
|
+
}
|
214
|
+
}
|
215
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
216
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
217
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
218
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
219
|
+
id
|
220
|
+
status {
|
221
|
+
...dryRunTransactionStatusFragment
|
222
|
+
}
|
223
|
+
receipts {
|
224
|
+
...receiptFragment
|
225
|
+
}
|
226
|
+
}
|
227
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
228
|
+
${ReceiptFragmentFragmentDoc}`;
|
186
229
|
var CoinFragmentFragmentDoc = gql`
|
187
230
|
fragment coinFragment on Coin {
|
188
231
|
__typename
|
@@ -190,7 +233,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
190
233
|
owner
|
191
234
|
amount
|
192
235
|
assetId
|
193
|
-
maturity
|
194
236
|
blockCreated
|
195
237
|
txCreatedIdx
|
196
238
|
}
|
@@ -267,8 +309,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
267
309
|
var BlockFragmentFragmentDoc = gql`
|
268
310
|
fragment blockFragment on Block {
|
269
311
|
id
|
312
|
+
height
|
270
313
|
header {
|
271
|
-
height
|
272
314
|
time
|
273
315
|
}
|
274
316
|
transactions {
|
@@ -338,7 +380,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
338
380
|
cb
|
339
381
|
cfei
|
340
382
|
cfsi
|
341
|
-
croo
|
342
383
|
div
|
343
384
|
divi
|
344
385
|
ecr1
|
@@ -421,6 +462,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
421
462
|
ccp {
|
422
463
|
...DependentCostFragment
|
423
464
|
}
|
465
|
+
croo {
|
466
|
+
...DependentCostFragment
|
467
|
+
}
|
424
468
|
csiz {
|
425
469
|
...DependentCostFragment
|
426
470
|
}
|
@@ -543,14 +587,6 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
543
587
|
maxTx
|
544
588
|
maxDepth
|
545
589
|
nodeVersion
|
546
|
-
peers {
|
547
|
-
id
|
548
|
-
addresses
|
549
|
-
clientVersion
|
550
|
-
blockHeight
|
551
|
-
lastHeartbeatMs
|
552
|
-
appScore
|
553
|
-
}
|
554
590
|
}
|
555
591
|
`;
|
556
592
|
var GetVersionDocument = gql`
|
@@ -585,13 +621,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
585
621
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
586
622
|
transaction(id: $transactionId) {
|
587
623
|
...transactionFragment
|
588
|
-
receipts {
|
589
|
-
...receiptFragment
|
590
|
-
}
|
591
624
|
}
|
592
625
|
}
|
593
|
-
${TransactionFragmentFragmentDoc}
|
594
|
-
${ReceiptFragmentFragmentDoc}`;
|
626
|
+
${TransactionFragmentFragmentDoc}`;
|
595
627
|
var GetTransactionsDocument = gql`
|
596
628
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
597
629
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -719,6 +751,20 @@ var GetBalanceDocument = gql`
|
|
719
751
|
}
|
720
752
|
}
|
721
753
|
${BalanceFragmentFragmentDoc}`;
|
754
|
+
var GetLatestGasPriceDocument = gql`
|
755
|
+
query getLatestGasPrice {
|
756
|
+
latestGasPrice {
|
757
|
+
gasPrice
|
758
|
+
}
|
759
|
+
}
|
760
|
+
`;
|
761
|
+
var EstimateGasPriceDocument = gql`
|
762
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
763
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
764
|
+
gasPrice
|
765
|
+
}
|
766
|
+
}
|
767
|
+
`;
|
722
768
|
var GetBalancesDocument = gql`
|
723
769
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
724
770
|
balances(
|
@@ -773,12 +819,12 @@ var GetMessageStatusDocument = gql`
|
|
773
819
|
}
|
774
820
|
`;
|
775
821
|
var DryRunDocument = gql`
|
776
|
-
mutation dryRun($
|
777
|
-
dryRun(
|
778
|
-
...
|
822
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
823
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
824
|
+
...dryRunTransactionExecutionStatusFragment
|
779
825
|
}
|
780
826
|
}
|
781
|
-
${
|
827
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
782
828
|
var SubmitDocument = gql`
|
783
829
|
mutation submit($encodedTransaction: HexString!) {
|
784
830
|
submit(tx: $encodedTransaction) {
|
@@ -861,6 +907,12 @@ function getSdk(requester) {
|
|
861
907
|
getBalance(variables, options) {
|
862
908
|
return requester(GetBalanceDocument, variables, options);
|
863
909
|
},
|
910
|
+
getLatestGasPrice(variables, options) {
|
911
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
912
|
+
},
|
913
|
+
estimateGasPrice(variables, options) {
|
914
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
915
|
+
},
|
864
916
|
getBalances(variables, options) {
|
865
917
|
return requester(GetBalancesDocument, variables, options);
|
866
918
|
},
|
@@ -1044,7 +1096,6 @@ var inputify = (value) => {
|
|
1044
1096
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1045
1097
|
},
|
1046
1098
|
witnessIndex: value.witnessIndex,
|
1047
|
-
maturity: value.maturity ?? 0,
|
1048
1099
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1049
1100
|
predicateLength: predicate.length,
|
1050
1101
|
predicateDataLength: predicateData.length,
|
@@ -1154,8 +1205,8 @@ var outputify = (value) => {
|
|
1154
1205
|
|
1155
1206
|
// src/providers/transaction-request/transaction-request.ts
|
1156
1207
|
import { Address, addressify } from "@fuel-ts/address";
|
1157
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1158
|
-
import { bn as
|
1208
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1209
|
+
import { bn as bn7 } from "@fuel-ts/math";
|
1159
1210
|
import {
|
1160
1211
|
PolicyType,
|
1161
1212
|
TransactionCoder,
|
@@ -1164,6 +1215,7 @@ import {
|
|
1164
1215
|
TransactionType
|
1165
1216
|
} from "@fuel-ts/transactions";
|
1166
1217
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1218
|
+
import { randomBytes } from "ethers";
|
1167
1219
|
|
1168
1220
|
// src/providers/resource.ts
|
1169
1221
|
var isRawCoin = (resource) => "utxoId" in resource;
|
@@ -1207,8 +1259,8 @@ function assembleReceiptByType(receipt) {
|
|
1207
1259
|
case "CALL" /* Call */: {
|
1208
1260
|
const callReceipt = {
|
1209
1261
|
type: ReceiptType.Call,
|
1210
|
-
from: hexOrZero(receipt.
|
1211
|
-
to: hexOrZero(receipt?.to
|
1262
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1263
|
+
to: hexOrZero(receipt?.to),
|
1212
1264
|
amount: bn4(receipt.amount),
|
1213
1265
|
assetId: hexOrZero(receipt.assetId),
|
1214
1266
|
gas: bn4(receipt.gas),
|
@@ -1222,7 +1274,7 @@ function assembleReceiptByType(receipt) {
|
|
1222
1274
|
case "RETURN" /* Return */: {
|
1223
1275
|
const returnReceipt = {
|
1224
1276
|
type: ReceiptType.Return,
|
1225
|
-
id: hexOrZero(receipt.
|
1277
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1226
1278
|
val: bn4(receipt.val),
|
1227
1279
|
pc: bn4(receipt.pc),
|
1228
1280
|
is: bn4(receipt.is)
|
@@ -1232,7 +1284,7 @@ function assembleReceiptByType(receipt) {
|
|
1232
1284
|
case "RETURN_DATA" /* ReturnData */: {
|
1233
1285
|
const returnDataReceipt = {
|
1234
1286
|
type: ReceiptType.ReturnData,
|
1235
|
-
id: hexOrZero(receipt.
|
1287
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1236
1288
|
ptr: bn4(receipt.ptr),
|
1237
1289
|
len: bn4(receipt.len),
|
1238
1290
|
digest: hexOrZero(receipt.digest),
|
@@ -1244,7 +1296,7 @@ function assembleReceiptByType(receipt) {
|
|
1244
1296
|
case "PANIC" /* Panic */: {
|
1245
1297
|
const panicReceipt = {
|
1246
1298
|
type: ReceiptType.Panic,
|
1247
|
-
id: hexOrZero(receipt.
|
1299
|
+
id: hexOrZero(receipt.id),
|
1248
1300
|
reason: bn4(receipt.reason),
|
1249
1301
|
pc: bn4(receipt.pc),
|
1250
1302
|
is: bn4(receipt.is),
|
@@ -1255,7 +1307,7 @@ function assembleReceiptByType(receipt) {
|
|
1255
1307
|
case "REVERT" /* Revert */: {
|
1256
1308
|
const revertReceipt = {
|
1257
1309
|
type: ReceiptType.Revert,
|
1258
|
-
id: hexOrZero(receipt.
|
1310
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1259
1311
|
val: bn4(receipt.ra),
|
1260
1312
|
pc: bn4(receipt.pc),
|
1261
1313
|
is: bn4(receipt.is)
|
@@ -1265,7 +1317,7 @@ function assembleReceiptByType(receipt) {
|
|
1265
1317
|
case "LOG" /* Log */: {
|
1266
1318
|
const logReceipt = {
|
1267
1319
|
type: ReceiptType.Log,
|
1268
|
-
id: hexOrZero(receipt.
|
1320
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1269
1321
|
val0: bn4(receipt.ra),
|
1270
1322
|
val1: bn4(receipt.rb),
|
1271
1323
|
val2: bn4(receipt.rc),
|
@@ -1278,7 +1330,7 @@ function assembleReceiptByType(receipt) {
|
|
1278
1330
|
case "LOG_DATA" /* LogData */: {
|
1279
1331
|
const logDataReceipt = {
|
1280
1332
|
type: ReceiptType.LogData,
|
1281
|
-
id: hexOrZero(receipt.
|
1333
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1282
1334
|
val0: bn4(receipt.ra),
|
1283
1335
|
val1: bn4(receipt.rb),
|
1284
1336
|
ptr: bn4(receipt.ptr),
|
@@ -1292,8 +1344,8 @@ function assembleReceiptByType(receipt) {
|
|
1292
1344
|
case "TRANSFER" /* Transfer */: {
|
1293
1345
|
const transferReceipt = {
|
1294
1346
|
type: ReceiptType.Transfer,
|
1295
|
-
from: hexOrZero(receipt.
|
1296
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1347
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1348
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1297
1349
|
amount: bn4(receipt.amount),
|
1298
1350
|
assetId: hexOrZero(receipt.assetId),
|
1299
1351
|
pc: bn4(receipt.pc),
|
@@ -1304,8 +1356,8 @@ function assembleReceiptByType(receipt) {
|
|
1304
1356
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1305
1357
|
const transferOutReceipt = {
|
1306
1358
|
type: ReceiptType.TransferOut,
|
1307
|
-
from: hexOrZero(receipt.
|
1308
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1359
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1360
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1309
1361
|
amount: bn4(receipt.amount),
|
1310
1362
|
assetId: hexOrZero(receipt.assetId),
|
1311
1363
|
pc: bn4(receipt.pc),
|
@@ -1348,7 +1400,7 @@ function assembleReceiptByType(receipt) {
|
|
1348
1400
|
return receiptMessageOut;
|
1349
1401
|
}
|
1350
1402
|
case "MINT" /* Mint */: {
|
1351
|
-
const contractId = hexOrZero(receipt.
|
1403
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1352
1404
|
const subId = hexOrZero(receipt.subId);
|
1353
1405
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1354
1406
|
const mintReceipt = {
|
@@ -1363,7 +1415,7 @@ function assembleReceiptByType(receipt) {
|
|
1363
1415
|
return mintReceipt;
|
1364
1416
|
}
|
1365
1417
|
case "BURN" /* Burn */: {
|
1366
|
-
const contractId = hexOrZero(receipt.
|
1418
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1367
1419
|
const subId = hexOrZero(receipt.subId);
|
1368
1420
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1369
1421
|
const burnReceipt = {
|
@@ -1448,7 +1500,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1448
1500
|
import { bn as bn5 } from "@fuel-ts/math";
|
1449
1501
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1450
1502
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1451
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1452
1503
|
var getGasUsedFromReceipts = (receipts) => {
|
1453
1504
|
const scriptResult = receipts.filter(
|
1454
1505
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1469,18 +1520,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1469
1520
|
}
|
1470
1521
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1471
1522
|
const witnessCache = [];
|
1472
|
-
const
|
1523
|
+
const chargeableInputs = inputs.filter((input) => {
|
1524
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1525
|
+
if (isCoinOrMessage) {
|
1526
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1527
|
+
return true;
|
1528
|
+
}
|
1529
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1530
|
+
witnessCache.push(input.witnessIndex);
|
1531
|
+
return true;
|
1532
|
+
}
|
1533
|
+
}
|
1534
|
+
return false;
|
1535
|
+
});
|
1536
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1537
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1473
1538
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1474
1539
|
return total.add(
|
1475
|
-
|
1540
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1476
1541
|
);
|
1477
1542
|
}
|
1478
|
-
|
1479
|
-
|
1480
|
-
return total.add(gasCosts.ecr1);
|
1481
|
-
}
|
1482
|
-
return total;
|
1483
|
-
}, bn5());
|
1543
|
+
return total.add(gasCosts.ecr1);
|
1544
|
+
}, bn5(0));
|
1484
1545
|
return totalGas;
|
1485
1546
|
}
|
1486
1547
|
function getMinGas(params) {
|
@@ -1492,12 +1553,20 @@ function getMinGas(params) {
|
|
1492
1553
|
return minGas;
|
1493
1554
|
}
|
1494
1555
|
function getMaxGas(params) {
|
1495
|
-
const {
|
1556
|
+
const {
|
1557
|
+
gasPerByte,
|
1558
|
+
witnessesLength,
|
1559
|
+
witnessLimit,
|
1560
|
+
minGas,
|
1561
|
+
gasLimit = bn5(0),
|
1562
|
+
maxGasPerTx
|
1563
|
+
} = params;
|
1496
1564
|
let remainingAllowedWitnessGas = bn5(0);
|
1497
1565
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1498
1566
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1499
1567
|
}
|
1500
|
-
|
1568
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1569
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1501
1570
|
}
|
1502
1571
|
function calculateMetadataGasForTxCreate({
|
1503
1572
|
gasCosts,
|
@@ -1519,6 +1588,10 @@ function calculateMetadataGasForTxScript({
|
|
1519
1588
|
}) {
|
1520
1589
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1521
1590
|
}
|
1591
|
+
var calculateGasFee = (params) => {
|
1592
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1593
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1594
|
+
};
|
1522
1595
|
|
1523
1596
|
// src/providers/utils/json.ts
|
1524
1597
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1560,6 +1633,86 @@ function sleep(time) {
|
|
1560
1633
|
});
|
1561
1634
|
}
|
1562
1635
|
|
1636
|
+
// src/providers/utils/extract-tx-error.ts
|
1637
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1638
|
+
import { bn as bn6 } from "@fuel-ts/math";
|
1639
|
+
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
1640
|
+
import {
|
1641
|
+
FAILED_REQUIRE_SIGNAL,
|
1642
|
+
FAILED_ASSERT_EQ_SIGNAL,
|
1643
|
+
FAILED_ASSERT_NE_SIGNAL,
|
1644
|
+
FAILED_ASSERT_SIGNAL,
|
1645
|
+
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
1646
|
+
PANIC_REASONS,
|
1647
|
+
PANIC_DOC_URL
|
1648
|
+
} from "@fuel-ts/transactions/configs";
|
1649
|
+
var assemblePanicError = (status) => {
|
1650
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1651
|
+
const reason = status.reason;
|
1652
|
+
if (PANIC_REASONS.includes(status.reason)) {
|
1653
|
+
errorMessage = `${errorMessage}
|
1654
|
+
|
1655
|
+
You can read more about this error at:
|
1656
|
+
|
1657
|
+
${PANIC_DOC_URL}#variant.${status.reason}`;
|
1658
|
+
}
|
1659
|
+
return { errorMessage, reason };
|
1660
|
+
};
|
1661
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1662
|
+
var assembleRevertError = (receipts, logs) => {
|
1663
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1664
|
+
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1665
|
+
let reason = "";
|
1666
|
+
if (revertReceipt) {
|
1667
|
+
const reasonHex = bn6(revertReceipt.val).toHex();
|
1668
|
+
switch (reasonHex) {
|
1669
|
+
case FAILED_REQUIRE_SIGNAL: {
|
1670
|
+
reason = "require";
|
1671
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1672
|
+
break;
|
1673
|
+
}
|
1674
|
+
case FAILED_ASSERT_EQ_SIGNAL: {
|
1675
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1676
|
+
reason = "assert_eq";
|
1677
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1678
|
+
break;
|
1679
|
+
}
|
1680
|
+
case FAILED_ASSERT_NE_SIGNAL: {
|
1681
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1682
|
+
reason = "assert_ne";
|
1683
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1684
|
+
break;
|
1685
|
+
}
|
1686
|
+
case FAILED_ASSERT_SIGNAL:
|
1687
|
+
reason = "assert";
|
1688
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1689
|
+
break;
|
1690
|
+
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
1691
|
+
reason = "MissingOutputChange";
|
1692
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1693
|
+
break;
|
1694
|
+
default:
|
1695
|
+
reason = "unknown";
|
1696
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1697
|
+
}
|
1698
|
+
}
|
1699
|
+
return { errorMessage, reason };
|
1700
|
+
};
|
1701
|
+
var extractTxError = (params) => {
|
1702
|
+
const { receipts, status, logs } = params;
|
1703
|
+
const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1704
|
+
const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
|
1705
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1706
|
+
const metadata = {
|
1707
|
+
logs,
|
1708
|
+
receipts,
|
1709
|
+
panic: isPanic,
|
1710
|
+
revert: isRevert,
|
1711
|
+
reason
|
1712
|
+
};
|
1713
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
|
1714
|
+
};
|
1715
|
+
|
1563
1716
|
// src/providers/transaction-request/errors.ts
|
1564
1717
|
var ChangeOutputCollisionError = class extends Error {
|
1565
1718
|
name = "ChangeOutputCollisionError";
|
@@ -1595,7 +1748,7 @@ var witnessify = (value) => {
|
|
1595
1748
|
// src/providers/transaction-request/transaction-request.ts
|
1596
1749
|
var BaseTransactionRequest = class {
|
1597
1750
|
/** Gas price for transaction */
|
1598
|
-
|
1751
|
+
tip;
|
1599
1752
|
/** Block until which tx cannot be included */
|
1600
1753
|
maturity;
|
1601
1754
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1608,38 +1761,34 @@ var BaseTransactionRequest = class {
|
|
1608
1761
|
outputs = [];
|
1609
1762
|
/** List of witnesses */
|
1610
1763
|
witnesses = [];
|
1611
|
-
/** Base asset ID - should be fetched from the chain */
|
1612
|
-
baseAssetId = ZeroBytes324;
|
1613
1764
|
/**
|
1614
1765
|
* Constructor for initializing a base transaction request.
|
1615
1766
|
*
|
1616
1767
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1617
1768
|
*/
|
1618
1769
|
constructor({
|
1619
|
-
|
1770
|
+
tip,
|
1620
1771
|
maturity,
|
1621
1772
|
maxFee,
|
1622
1773
|
witnessLimit,
|
1623
1774
|
inputs,
|
1624
1775
|
outputs,
|
1625
|
-
witnesses
|
1626
|
-
baseAssetId
|
1776
|
+
witnesses
|
1627
1777
|
} = {}) {
|
1628
|
-
this.
|
1778
|
+
this.tip = bn7(tip);
|
1629
1779
|
this.maturity = maturity ?? 0;
|
1630
|
-
this.witnessLimit = witnessLimit ?
|
1631
|
-
this.maxFee = maxFee ?
|
1780
|
+
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1781
|
+
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1632
1782
|
this.inputs = inputs ?? [];
|
1633
1783
|
this.outputs = outputs ?? [];
|
1634
1784
|
this.witnesses = witnesses ?? [];
|
1635
|
-
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1636
1785
|
}
|
1637
1786
|
static getPolicyMeta(req) {
|
1638
1787
|
let policyTypes = 0;
|
1639
1788
|
const policies = [];
|
1640
|
-
if (req.
|
1641
|
-
policyTypes += PolicyType.
|
1642
|
-
policies.push({ data: req.
|
1789
|
+
if (req.tip) {
|
1790
|
+
policyTypes += PolicyType.Tip;
|
1791
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1643
1792
|
}
|
1644
1793
|
if (req.witnessLimit) {
|
1645
1794
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1826,10 +1975,10 @@ var BaseTransactionRequest = class {
|
|
1826
1975
|
* @param predicate - Predicate bytes.
|
1827
1976
|
* @param predicateData - Predicate data bytes.
|
1828
1977
|
*/
|
1829
|
-
addCoinInput(coin
|
1978
|
+
addCoinInput(coin) {
|
1830
1979
|
const { assetId, owner, amount } = coin;
|
1831
1980
|
let witnessIndex;
|
1832
|
-
if (predicate) {
|
1981
|
+
if (coin.predicate) {
|
1833
1982
|
witnessIndex = 0;
|
1834
1983
|
} else {
|
1835
1984
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1844,9 +1993,7 @@ var BaseTransactionRequest = class {
|
|
1844
1993
|
amount,
|
1845
1994
|
assetId,
|
1846
1995
|
txPointer: "0x00000000000000000000000000000000",
|
1847
|
-
witnessIndex
|
1848
|
-
predicate: predicate?.bytes,
|
1849
|
-
predicateData: predicate?.predicateDataBytes
|
1996
|
+
witnessIndex
|
1850
1997
|
};
|
1851
1998
|
this.pushInput(input);
|
1852
1999
|
this.addChangeOutput(owner, assetId);
|
@@ -1857,11 +2004,13 @@ var BaseTransactionRequest = class {
|
|
1857
2004
|
*
|
1858
2005
|
* @param message - Message resource.
|
1859
2006
|
* @param predicate - Predicate bytes.
|
2007
|
+
* @param predicateData - Predicate data bytes.
|
1860
2008
|
*/
|
1861
|
-
addMessageInput(message
|
2009
|
+
addMessageInput(message) {
|
1862
2010
|
const { recipient, sender, amount } = message;
|
2011
|
+
const assetId = BaseAssetId2;
|
1863
2012
|
let witnessIndex;
|
1864
|
-
if (predicate) {
|
2013
|
+
if (message.predicate) {
|
1865
2014
|
witnessIndex = 0;
|
1866
2015
|
} else {
|
1867
2016
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1875,12 +2024,10 @@ var BaseTransactionRequest = class {
|
|
1875
2024
|
sender: sender.toB256(),
|
1876
2025
|
recipient: recipient.toB256(),
|
1877
2026
|
amount,
|
1878
|
-
witnessIndex
|
1879
|
-
predicate: predicate?.bytes,
|
1880
|
-
predicateData: predicate?.predicateDataBytes
|
2027
|
+
witnessIndex
|
1881
2028
|
};
|
1882
2029
|
this.pushInput(input);
|
1883
|
-
this.addChangeOutput(recipient,
|
2030
|
+
this.addChangeOutput(recipient, assetId);
|
1884
2031
|
}
|
1885
2032
|
/**
|
1886
2033
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1908,32 +2055,6 @@ var BaseTransactionRequest = class {
|
|
1908
2055
|
resources.forEach((resource) => this.addResource(resource));
|
1909
2056
|
return this;
|
1910
2057
|
}
|
1911
|
-
/**
|
1912
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1913
|
-
* outputs from the related assetIds.
|
1914
|
-
*
|
1915
|
-
* @param resources - The resources to add.
|
1916
|
-
* @returns This transaction.
|
1917
|
-
*/
|
1918
|
-
addPredicateResource(resource, predicate) {
|
1919
|
-
if (isCoin(resource)) {
|
1920
|
-
this.addCoinInput(resource, predicate);
|
1921
|
-
} else {
|
1922
|
-
this.addMessageInput(resource, predicate);
|
1923
|
-
}
|
1924
|
-
return this;
|
1925
|
-
}
|
1926
|
-
/**
|
1927
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1928
|
-
* from the related assetIds.
|
1929
|
-
*
|
1930
|
-
* @param resources - The resources to add.
|
1931
|
-
* @returns This transaction.
|
1932
|
-
*/
|
1933
|
-
addPredicateResources(resources, predicate) {
|
1934
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1935
|
-
return this;
|
1936
|
-
}
|
1937
2058
|
/**
|
1938
2059
|
* Adds a coin output to the transaction.
|
1939
2060
|
*
|
@@ -1941,12 +2062,12 @@ var BaseTransactionRequest = class {
|
|
1941
2062
|
* @param amount - Amount of coin.
|
1942
2063
|
* @param assetId - Asset ID of coin.
|
1943
2064
|
*/
|
1944
|
-
addCoinOutput(to, amount, assetId) {
|
2065
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
1945
2066
|
this.pushOutput({
|
1946
2067
|
type: OutputType2.Coin,
|
1947
2068
|
to: addressify(to).toB256(),
|
1948
2069
|
amount,
|
1949
|
-
assetId
|
2070
|
+
assetId
|
1950
2071
|
});
|
1951
2072
|
return this;
|
1952
2073
|
}
|
@@ -1973,7 +2094,7 @@ var BaseTransactionRequest = class {
|
|
1973
2094
|
* @param to - Address of the owner.
|
1974
2095
|
* @param assetId - Asset ID of coin.
|
1975
2096
|
*/
|
1976
|
-
addChangeOutput(to, assetId) {
|
2097
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
1977
2098
|
const changeOutput = this.getChangeOutputs().find(
|
1978
2099
|
(output) => hexlify7(output.assetId) === assetId
|
1979
2100
|
);
|
@@ -1981,7 +2102,7 @@ var BaseTransactionRequest = class {
|
|
1981
2102
|
this.pushOutput({
|
1982
2103
|
type: OutputType2.Change,
|
1983
2104
|
to: addressify(to).toB256(),
|
1984
|
-
assetId
|
2105
|
+
assetId
|
1985
2106
|
});
|
1986
2107
|
}
|
1987
2108
|
}
|
@@ -2013,7 +2134,7 @@ var BaseTransactionRequest = class {
|
|
2013
2134
|
}
|
2014
2135
|
calculateMaxGas(chainInfo, minGas) {
|
2015
2136
|
const { consensusParameters } = chainInfo;
|
2016
|
-
const { gasPerByte } = consensusParameters;
|
2137
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2017
2138
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2018
2139
|
(acc, wit) => acc + wit.dataLength,
|
2019
2140
|
0
|
@@ -2022,7 +2143,8 @@ var BaseTransactionRequest = class {
|
|
2022
2143
|
gasPerByte,
|
2023
2144
|
minGas,
|
2024
2145
|
witnessesLength,
|
2025
|
-
witnessLimit: this.witnessLimit
|
2146
|
+
witnessLimit: this.witnessLimit,
|
2147
|
+
maxGasPerTx
|
2026
2148
|
});
|
2027
2149
|
}
|
2028
2150
|
/**
|
@@ -2032,12 +2154,6 @@ var BaseTransactionRequest = class {
|
|
2032
2154
|
* @param quantities - CoinQuantity Array.
|
2033
2155
|
*/
|
2034
2156
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2035
|
-
let idCounter = 0;
|
2036
|
-
const generateId = () => {
|
2037
|
-
const counterString = String(idCounter++);
|
2038
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2039
|
-
return id;
|
2040
|
-
};
|
2041
2157
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2042
2158
|
if ("assetId" in input) {
|
2043
2159
|
return input.assetId === assetId;
|
@@ -2046,24 +2162,27 @@ var BaseTransactionRequest = class {
|
|
2046
2162
|
});
|
2047
2163
|
const updateAssetInput = (assetId, quantity) => {
|
2048
2164
|
const assetInput = findAssetInput(assetId);
|
2165
|
+
let usedQuantity = quantity;
|
2166
|
+
if (assetId === BaseAssetId2) {
|
2167
|
+
usedQuantity = bn7("1000000000000000000");
|
2168
|
+
}
|
2049
2169
|
if (assetInput && "assetId" in assetInput) {
|
2050
|
-
assetInput.id =
|
2051
|
-
assetInput.amount =
|
2170
|
+
assetInput.id = hexlify7(randomBytes(33));
|
2171
|
+
assetInput.amount = usedQuantity;
|
2052
2172
|
} else {
|
2053
2173
|
this.addResources([
|
2054
2174
|
{
|
2055
|
-
id:
|
2056
|
-
amount:
|
2175
|
+
id: hexlify7(randomBytes(33)),
|
2176
|
+
amount: usedQuantity,
|
2057
2177
|
assetId,
|
2058
2178
|
owner: resourcesOwner || Address.fromRandom(),
|
2059
|
-
|
2060
|
-
|
2061
|
-
txCreatedIdx: bn6(1)
|
2179
|
+
blockCreated: bn7(1),
|
2180
|
+
txCreatedIdx: bn7(1)
|
2062
2181
|
}
|
2063
2182
|
]);
|
2064
2183
|
}
|
2065
2184
|
};
|
2066
|
-
updateAssetInput(
|
2185
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2067
2186
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2068
2187
|
}
|
2069
2188
|
/**
|
@@ -2074,7 +2193,7 @@ var BaseTransactionRequest = class {
|
|
2074
2193
|
*/
|
2075
2194
|
getCoinOutputsQuantities() {
|
2076
2195
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2077
|
-
amount:
|
2196
|
+
amount: bn7(amount),
|
2078
2197
|
assetId: assetId.toString()
|
2079
2198
|
}));
|
2080
2199
|
return coinsQuantities;
|
@@ -2088,7 +2207,7 @@ var BaseTransactionRequest = class {
|
|
2088
2207
|
toJSON() {
|
2089
2208
|
return normalizeJSON(this);
|
2090
2209
|
}
|
2091
|
-
|
2210
|
+
updatePredicateGasUsed(inputs) {
|
2092
2211
|
this.inputs.forEach((i) => {
|
2093
2212
|
let correspondingInput;
|
2094
2213
|
switch (i.type) {
|
@@ -2103,25 +2222,34 @@ var BaseTransactionRequest = class {
|
|
2103
2222
|
default:
|
2104
2223
|
return;
|
2105
2224
|
}
|
2106
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2225
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
|
2107
2226
|
i.predicate = correspondingInput.predicate;
|
2108
2227
|
i.predicateData = correspondingInput.predicateData;
|
2109
2228
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
2110
2229
|
}
|
2111
2230
|
});
|
2112
2231
|
}
|
2232
|
+
shiftPredicateData() {
|
2233
|
+
this.inputs.forEach((input) => {
|
2234
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2235
|
+
input.predicateData = input.paddPredicateData(
|
2236
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2237
|
+
);
|
2238
|
+
}
|
2239
|
+
});
|
2240
|
+
}
|
2113
2241
|
};
|
2114
2242
|
|
2115
2243
|
// src/providers/transaction-request/create-transaction-request.ts
|
2116
2244
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2117
|
-
import { bn as
|
2245
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2118
2246
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2119
2247
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2120
2248
|
|
2121
2249
|
// src/providers/transaction-request/hash-transaction.ts
|
2122
2250
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2123
2251
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2124
|
-
import { bn as
|
2252
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2125
2253
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2126
2254
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2127
2255
|
import { clone as clone2 } from "ramda";
|
@@ -2138,11 +2266,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2138
2266
|
blockHeight: 0,
|
2139
2267
|
txIndex: 0
|
2140
2268
|
};
|
2141
|
-
inputClone.predicateGasUsed =
|
2269
|
+
inputClone.predicateGasUsed = bn8(0);
|
2142
2270
|
return inputClone;
|
2143
2271
|
}
|
2144
2272
|
case InputType3.Message: {
|
2145
|
-
inputClone.predicateGasUsed =
|
2273
|
+
inputClone.predicateGasUsed = bn8(0);
|
2146
2274
|
return inputClone;
|
2147
2275
|
}
|
2148
2276
|
case InputType3.Contract: {
|
@@ -2169,12 +2297,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2169
2297
|
return outputClone;
|
2170
2298
|
}
|
2171
2299
|
case OutputType3.Change: {
|
2172
|
-
outputClone.amount =
|
2300
|
+
outputClone.amount = bn8(0);
|
2173
2301
|
return outputClone;
|
2174
2302
|
}
|
2175
2303
|
case OutputType3.Variable: {
|
2176
2304
|
outputClone.to = ZeroBytes325;
|
2177
|
-
outputClone.amount =
|
2305
|
+
outputClone.amount = bn8(0);
|
2178
2306
|
outputClone.assetId = ZeroBytes325;
|
2179
2307
|
return outputClone;
|
2180
2308
|
}
|
@@ -2298,7 +2426,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2298
2426
|
}
|
2299
2427
|
metadataGas(gasCosts) {
|
2300
2428
|
return calculateMetadataGasForTxCreate({
|
2301
|
-
contractBytesSize:
|
2429
|
+
contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2302
2430
|
gasCosts,
|
2303
2431
|
stateRootSize: this.storageSlots.length,
|
2304
2432
|
txBytesSize: this.byteSize()
|
@@ -2310,7 +2438,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2310
2438
|
import { Interface } from "@fuel-ts/abi-coder";
|
2311
2439
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2312
2440
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2313
|
-
import { bn as
|
2441
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2314
2442
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2315
2443
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2316
2444
|
|
@@ -2364,7 +2492,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2364
2492
|
*/
|
2365
2493
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2366
2494
|
super(rest);
|
2367
|
-
this.gasLimit =
|
2495
|
+
this.gasLimit = bn10(gasLimit);
|
2368
2496
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2369
2497
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2370
2498
|
this.abis = rest.abis;
|
@@ -2446,7 +2574,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2446
2574
|
}
|
2447
2575
|
calculateMaxGas(chainInfo, minGas) {
|
2448
2576
|
const { consensusParameters } = chainInfo;
|
2449
|
-
const { gasPerByte } = consensusParameters;
|
2577
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2450
2578
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2451
2579
|
(acc, wit) => acc + wit.dataLength,
|
2452
2580
|
0
|
@@ -2456,7 +2584,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2456
2584
|
minGas,
|
2457
2585
|
witnessesLength,
|
2458
2586
|
witnessLimit: this.witnessLimit,
|
2459
|
-
gasLimit: this.gasLimit
|
2587
|
+
gasLimit: this.gasLimit,
|
2588
|
+
maxGasPerTx
|
2460
2589
|
});
|
2461
2590
|
}
|
2462
2591
|
/**
|
@@ -2512,8 +2641,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2512
2641
|
};
|
2513
2642
|
|
2514
2643
|
// src/providers/transaction-request/utils.ts
|
2515
|
-
import { ErrorCode as
|
2516
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2644
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2645
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2517
2646
|
var transactionRequestify = (obj) => {
|
2518
2647
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2519
2648
|
return obj;
|
@@ -2527,48 +2656,65 @@ var transactionRequestify = (obj) => {
|
|
2527
2656
|
return CreateTransactionRequest.from(obj);
|
2528
2657
|
}
|
2529
2658
|
default: {
|
2530
|
-
throw new
|
2659
|
+
throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2531
2660
|
}
|
2532
2661
|
}
|
2533
2662
|
};
|
2663
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2664
|
+
(acc, input) => {
|
2665
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2666
|
+
acc.utxos.push(input.id);
|
2667
|
+
}
|
2668
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2669
|
+
acc.messages.push(input.nonce);
|
2670
|
+
}
|
2671
|
+
return acc;
|
2672
|
+
},
|
2673
|
+
{
|
2674
|
+
utxos: [],
|
2675
|
+
messages: []
|
2676
|
+
}
|
2677
|
+
);
|
2534
2678
|
|
2535
2679
|
// src/providers/transaction-response/transaction-response.ts
|
2536
|
-
import { ErrorCode as
|
2537
|
-
import { bn as
|
2680
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2681
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2538
2682
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2539
2683
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2540
2684
|
|
2541
2685
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2686
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2687
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2542
2688
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2543
2689
|
|
2544
2690
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2545
|
-
import { bn as
|
2691
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2546
2692
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2547
2693
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2548
2694
|
var calculateTransactionFee = (params) => {
|
2549
2695
|
const {
|
2550
|
-
|
2696
|
+
gasPrice,
|
2551
2697
|
rawPayload,
|
2552
|
-
|
2698
|
+
tip,
|
2699
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2553
2700
|
} = params;
|
2554
|
-
const gasPerByte =
|
2555
|
-
const gasPriceFactor =
|
2701
|
+
const gasPerByte = bn11(feeParams.gasPerByte);
|
2702
|
+
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
2556
2703
|
const transactionBytes = arrayify9(rawPayload);
|
2557
2704
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2558
2705
|
if (transaction.type === TransactionType6.Mint) {
|
2559
2706
|
return {
|
2560
|
-
fee:
|
2561
|
-
minFee:
|
2562
|
-
maxFee:
|
2563
|
-
feeFromGasUsed: bn10(0)
|
2707
|
+
fee: bn11(0),
|
2708
|
+
minFee: bn11(0),
|
2709
|
+
maxFee: bn11(0)
|
2564
2710
|
};
|
2565
2711
|
}
|
2566
2712
|
const { type, witnesses, inputs, policies } = transaction;
|
2567
|
-
let metadataGas =
|
2568
|
-
let gasLimit =
|
2713
|
+
let metadataGas = bn11(0);
|
2714
|
+
let gasLimit = bn11(0);
|
2569
2715
|
if (type === TransactionType6.Create) {
|
2570
2716
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2571
|
-
const contractBytesSize =
|
2717
|
+
const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2572
2718
|
metadataGas = calculateMetadataGasForTxCreate({
|
2573
2719
|
contractBytesSize,
|
2574
2720
|
gasCosts,
|
@@ -2587,12 +2733,11 @@ var calculateTransactionFee = (params) => {
|
|
2587
2733
|
}
|
2588
2734
|
const minGas = getMinGas({
|
2589
2735
|
gasCosts,
|
2590
|
-
gasPerByte:
|
2736
|
+
gasPerByte: bn11(gasPerByte),
|
2591
2737
|
inputs,
|
2592
2738
|
metadataGas,
|
2593
2739
|
txBytesSize: transactionBytes.length
|
2594
2740
|
});
|
2595
|
-
const gasPrice = bn10(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2596
2741
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2597
2742
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2598
2743
|
const maxGas = getMaxGas({
|
@@ -2600,29 +2745,37 @@ var calculateTransactionFee = (params) => {
|
|
2600
2745
|
minGas,
|
2601
2746
|
witnessesLength,
|
2602
2747
|
gasLimit,
|
2603
|
-
witnessLimit
|
2748
|
+
witnessLimit,
|
2749
|
+
maxGasPerTx
|
2750
|
+
});
|
2751
|
+
const minFee = calculateGasFee({
|
2752
|
+
gasPrice,
|
2753
|
+
gas: minGas,
|
2754
|
+
priceFactor: gasPriceFactor,
|
2755
|
+
tip
|
2756
|
+
});
|
2757
|
+
const maxFee = calculateGasFee({
|
2758
|
+
gasPrice,
|
2759
|
+
gas: maxGas,
|
2760
|
+
priceFactor: gasPriceFactor,
|
2761
|
+
tip
|
2604
2762
|
});
|
2605
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2606
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2607
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2608
|
-
const fee = minFee.add(feeFromGasUsed);
|
2609
2763
|
return {
|
2610
|
-
fee,
|
2611
2764
|
minFee,
|
2612
2765
|
maxFee,
|
2613
|
-
|
2766
|
+
fee: maxFee
|
2614
2767
|
};
|
2615
2768
|
};
|
2616
2769
|
|
2617
2770
|
// src/providers/transaction-summary/operations.ts
|
2618
2771
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2619
|
-
import { ErrorCode as
|
2620
|
-
import { bn as
|
2621
|
-
import { ReceiptType as
|
2772
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2773
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2774
|
+
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2622
2775
|
|
2623
2776
|
// src/providers/transaction-summary/call.ts
|
2624
2777
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2625
|
-
import { bn as
|
2778
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2626
2779
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2627
2780
|
const abiInterface = new Interface2(abi);
|
2628
2781
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2631,7 +2784,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2631
2784
|
let encodedArgs;
|
2632
2785
|
if (functionFragment.isInputDataPointer) {
|
2633
2786
|
if (rawPayload) {
|
2634
|
-
const argsOffset =
|
2787
|
+
const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2635
2788
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2636
2789
|
}
|
2637
2790
|
} else {
|
@@ -2665,8 +2818,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2665
2818
|
};
|
2666
2819
|
|
2667
2820
|
// src/providers/transaction-summary/input.ts
|
2668
|
-
import { ErrorCode as
|
2669
|
-
import { InputType as
|
2821
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2822
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2670
2823
|
function getInputsByTypes(inputs, types) {
|
2671
2824
|
return inputs.filter((i) => types.includes(i.type));
|
2672
2825
|
}
|
@@ -2674,16 +2827,16 @@ function getInputsByType(inputs, type) {
|
|
2674
2827
|
return inputs.filter((i) => i.type === type);
|
2675
2828
|
}
|
2676
2829
|
function getInputsCoin(inputs) {
|
2677
|
-
return getInputsByType(inputs,
|
2830
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2678
2831
|
}
|
2679
2832
|
function getInputsMessage(inputs) {
|
2680
|
-
return getInputsByType(inputs,
|
2833
|
+
return getInputsByType(inputs, InputType6.Message);
|
2681
2834
|
}
|
2682
2835
|
function getInputsCoinAndMessage(inputs) {
|
2683
|
-
return getInputsByTypes(inputs, [
|
2836
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2684
2837
|
}
|
2685
2838
|
function getInputsContract(inputs) {
|
2686
|
-
return getInputsByType(inputs,
|
2839
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2687
2840
|
}
|
2688
2841
|
function getInputFromAssetId(inputs, assetId) {
|
2689
2842
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2702,19 +2855,19 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2702
2855
|
if (!contractInput) {
|
2703
2856
|
return void 0;
|
2704
2857
|
}
|
2705
|
-
if (contractInput.type !==
|
2706
|
-
throw new
|
2707
|
-
|
2858
|
+
if (contractInput.type !== InputType6.Contract) {
|
2859
|
+
throw new FuelError9(
|
2860
|
+
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2708
2861
|
`Contract input should be of type 'contract'.`
|
2709
2862
|
);
|
2710
2863
|
}
|
2711
2864
|
return contractInput;
|
2712
2865
|
}
|
2713
2866
|
function getInputAccountAddress(input) {
|
2714
|
-
if (input.type ===
|
2867
|
+
if (input.type === InputType6.Coin) {
|
2715
2868
|
return input.owner.toString();
|
2716
2869
|
}
|
2717
|
-
if (input.type ===
|
2870
|
+
if (input.type === InputType6.Message) {
|
2718
2871
|
return input.recipient.toString();
|
2719
2872
|
}
|
2720
2873
|
return "";
|
@@ -2792,8 +2945,8 @@ function getTransactionTypeName(transactionType) {
|
|
2792
2945
|
case TransactionType7.Script:
|
2793
2946
|
return "Script" /* Script */;
|
2794
2947
|
default:
|
2795
|
-
throw new
|
2796
|
-
|
2948
|
+
throw new FuelError10(
|
2949
|
+
ErrorCode10.INVALID_TRANSACTION_TYPE,
|
2797
2950
|
`Invalid transaction type: ${transactionType}.`
|
2798
2951
|
);
|
2799
2952
|
}
|
@@ -2815,10 +2968,10 @@ function hasSameAssetId(a) {
|
|
2815
2968
|
return (b) => a.assetId === b.assetId;
|
2816
2969
|
}
|
2817
2970
|
function getReceiptsCall(receipts) {
|
2818
|
-
return getReceiptsByType(receipts,
|
2971
|
+
return getReceiptsByType(receipts, ReceiptType4.Call);
|
2819
2972
|
}
|
2820
2973
|
function getReceiptsMessageOut(receipts) {
|
2821
|
-
return getReceiptsByType(receipts,
|
2974
|
+
return getReceiptsByType(receipts, ReceiptType4.MessageOut);
|
2822
2975
|
}
|
2823
2976
|
var mergeAssets = (op1, op2) => {
|
2824
2977
|
const assets1 = op1.assetsSent || [];
|
@@ -2831,7 +2984,7 @@ var mergeAssets = (op1, op2) => {
|
|
2831
2984
|
if (!matchingAsset) {
|
2832
2985
|
return asset1;
|
2833
2986
|
}
|
2834
|
-
const mergedAmount =
|
2987
|
+
const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
|
2835
2988
|
return { ...asset1, amount: mergedAmount };
|
2836
2989
|
});
|
2837
2990
|
return mergedAssets.concat(filteredAssets);
|
@@ -2857,7 +3010,7 @@ function addOperation(operations, toAdd) {
|
|
2857
3010
|
return allOperations;
|
2858
3011
|
}
|
2859
3012
|
function getReceiptsTransferOut(receipts) {
|
2860
|
-
return getReceiptsByType(receipts,
|
3013
|
+
return getReceiptsByType(receipts, ReceiptType4.TransferOut);
|
2861
3014
|
}
|
2862
3015
|
function getWithdrawFromFuelOperations({
|
2863
3016
|
inputs,
|
@@ -3017,11 +3170,11 @@ function getTransferOperations({
|
|
3017
3170
|
});
|
3018
3171
|
const transferReceipts = getReceiptsByType(
|
3019
3172
|
receipts,
|
3020
|
-
|
3173
|
+
ReceiptType4.Transfer
|
3021
3174
|
);
|
3022
3175
|
const transferOutReceipts = getReceiptsByType(
|
3023
3176
|
receipts,
|
3024
|
-
|
3177
|
+
ReceiptType4.TransferOut
|
3025
3178
|
);
|
3026
3179
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3027
3180
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3106,17 +3259,17 @@ function getOperations({
|
|
3106
3259
|
}
|
3107
3260
|
|
3108
3261
|
// src/providers/transaction-summary/receipt.ts
|
3109
|
-
import { ReceiptType as
|
3262
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3110
3263
|
var processGqlReceipt = (gqlReceipt) => {
|
3111
3264
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3112
3265
|
switch (receipt.type) {
|
3113
|
-
case
|
3266
|
+
case ReceiptType5.ReturnData: {
|
3114
3267
|
return {
|
3115
3268
|
...receipt,
|
3116
3269
|
data: gqlReceipt.data || "0x"
|
3117
3270
|
};
|
3118
3271
|
}
|
3119
|
-
case
|
3272
|
+
case ReceiptType5.LogData: {
|
3120
3273
|
return {
|
3121
3274
|
...receipt,
|
3122
3275
|
data: gqlReceipt.data || "0x"
|
@@ -3129,7 +3282,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3129
3282
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3130
3283
|
const mintedAssets = [];
|
3131
3284
|
receipts.forEach((receipt) => {
|
3132
|
-
if (receipt.type ===
|
3285
|
+
if (receipt.type === ReceiptType5.Mint) {
|
3133
3286
|
mintedAssets.push({
|
3134
3287
|
subId: receipt.subId,
|
3135
3288
|
contractId: receipt.contractId,
|
@@ -3143,7 +3296,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3143
3296
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3144
3297
|
const burnedAssets = [];
|
3145
3298
|
receipts.forEach((receipt) => {
|
3146
|
-
if (receipt.type ===
|
3299
|
+
if (receipt.type === ReceiptType5.Burn) {
|
3147
3300
|
burnedAssets.push({
|
3148
3301
|
subId: receipt.subId,
|
3149
3302
|
contractId: receipt.contractId,
|
@@ -3156,7 +3309,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3156
3309
|
};
|
3157
3310
|
|
3158
3311
|
// src/providers/transaction-summary/status.ts
|
3159
|
-
import { ErrorCode as
|
3312
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3160
3313
|
var getTransactionStatusName = (gqlStatus) => {
|
3161
3314
|
switch (gqlStatus) {
|
3162
3315
|
case "FailureStatus":
|
@@ -3168,8 +3321,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3168
3321
|
case "SqueezedOutStatus":
|
3169
3322
|
return "squeezedout" /* squeezedout */;
|
3170
3323
|
default:
|
3171
|
-
throw new
|
3172
|
-
|
3324
|
+
throw new FuelError11(
|
3325
|
+
ErrorCode11.INVALID_TRANSACTION_STATUS,
|
3173
3326
|
`Invalid transaction status: ${gqlStatus}.`
|
3174
3327
|
);
|
3175
3328
|
}
|
@@ -3224,7 +3377,9 @@ function assembleTransactionSummary(params) {
|
|
3224
3377
|
gqlTransactionStatus,
|
3225
3378
|
abiMap = {},
|
3226
3379
|
maxInputs,
|
3227
|
-
gasCosts
|
3380
|
+
gasCosts,
|
3381
|
+
maxGasPerTx,
|
3382
|
+
gasPrice
|
3228
3383
|
} = params;
|
3229
3384
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3230
3385
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3238,11 +3393,14 @@ function assembleTransactionSummary(params) {
|
|
3238
3393
|
maxInputs
|
3239
3394
|
});
|
3240
3395
|
const typeName = getTransactionTypeName(transaction.type);
|
3396
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3241
3397
|
const { fee } = calculateTransactionFee({
|
3242
|
-
|
3398
|
+
gasPrice,
|
3243
3399
|
rawPayload,
|
3400
|
+
tip,
|
3244
3401
|
consensusParameters: {
|
3245
3402
|
gasCosts,
|
3403
|
+
maxGasPerTx,
|
3246
3404
|
feeParams: {
|
3247
3405
|
gasPerByte,
|
3248
3406
|
gasPriceFactor
|
@@ -3282,12 +3440,12 @@ function assembleTransactionSummary(params) {
|
|
3282
3440
|
|
3283
3441
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3284
3442
|
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3285
|
-
import { ReceiptType as
|
3443
|
+
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
3286
3444
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3287
3445
|
return receipts.reduce((logs, receipt) => {
|
3288
|
-
if (receipt.type ===
|
3446
|
+
if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
|
3289
3447
|
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3290
|
-
const data = receipt.type ===
|
3448
|
+
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3291
3449
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3292
3450
|
logs.push(decodedLog);
|
3293
3451
|
}
|
@@ -3302,7 +3460,7 @@ var TransactionResponse = class {
|
|
3302
3460
|
/** Current provider */
|
3303
3461
|
provider;
|
3304
3462
|
/** Gas used on the transaction */
|
3305
|
-
gasUsed =
|
3463
|
+
gasUsed = bn15(0);
|
3306
3464
|
/** The graphql Transaction with receipts object. */
|
3307
3465
|
gqlTransaction;
|
3308
3466
|
abis;
|
@@ -3380,8 +3538,13 @@ var TransactionResponse = class {
|
|
3380
3538
|
const decodedTransaction = this.decodeTransaction(
|
3381
3539
|
transaction
|
3382
3540
|
);
|
3383
|
-
|
3384
|
-
|
3541
|
+
let txReceipts = [];
|
3542
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3543
|
+
txReceipts = transaction.status.receipts;
|
3544
|
+
}
|
3545
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3546
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3547
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3385
3548
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3386
3549
|
const transactionSummary = assembleTransactionSummary({
|
3387
3550
|
id: this.id,
|
@@ -3393,7 +3556,9 @@ var TransactionResponse = class {
|
|
3393
3556
|
gasPriceFactor,
|
3394
3557
|
abiMap: contractsAbiMap,
|
3395
3558
|
maxInputs,
|
3396
|
-
gasCosts
|
3559
|
+
gasCosts,
|
3560
|
+
maxGasPerTx,
|
3561
|
+
gasPrice
|
3397
3562
|
});
|
3398
3563
|
return transactionSummary;
|
3399
3564
|
}
|
@@ -3407,8 +3572,8 @@ var TransactionResponse = class {
|
|
3407
3572
|
});
|
3408
3573
|
for await (const { statusChange } of subscription) {
|
3409
3574
|
if (statusChange.type === "SqueezedOutStatus") {
|
3410
|
-
throw new
|
3411
|
-
|
3575
|
+
throw new FuelError12(
|
3576
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3412
3577
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3413
3578
|
);
|
3414
3579
|
}
|
@@ -3430,14 +3595,26 @@ var TransactionResponse = class {
|
|
3430
3595
|
gqlTransaction: this.gqlTransaction,
|
3431
3596
|
...transactionSummary
|
3432
3597
|
};
|
3598
|
+
let logs = [];
|
3433
3599
|
if (this.abis) {
|
3434
|
-
|
3600
|
+
logs = getDecodedLogs(
|
3435
3601
|
transactionSummary.receipts,
|
3436
3602
|
this.abis.main,
|
3437
3603
|
this.abis.otherContractsAbis
|
3438
3604
|
);
|
3439
3605
|
transactionResult.logs = logs;
|
3440
3606
|
}
|
3607
|
+
if (transactionResult.isStatusFailure) {
|
3608
|
+
const {
|
3609
|
+
receipts,
|
3610
|
+
gqlTransaction: { status }
|
3611
|
+
} = transactionResult;
|
3612
|
+
throw extractTxError({
|
3613
|
+
receipts,
|
3614
|
+
status,
|
3615
|
+
logs
|
3616
|
+
});
|
3617
|
+
}
|
3441
3618
|
return transactionResult;
|
3442
3619
|
}
|
3443
3620
|
/**
|
@@ -3446,14 +3623,7 @@ var TransactionResponse = class {
|
|
3446
3623
|
* @param contractsAbiMap - The contracts ABI map.
|
3447
3624
|
*/
|
3448
3625
|
async wait(contractsAbiMap) {
|
3449
|
-
|
3450
|
-
if (result.isStatusFailure) {
|
3451
|
-
throw new FuelError11(
|
3452
|
-
ErrorCode11.TRANSACTION_FAILED,
|
3453
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3454
|
-
);
|
3455
|
-
}
|
3456
|
-
return result;
|
3626
|
+
return this.waitForResult(contractsAbiMap);
|
3457
3627
|
}
|
3458
3628
|
};
|
3459
3629
|
|
@@ -3515,30 +3685,29 @@ var processGqlChain = (chain) => {
|
|
3515
3685
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3516
3686
|
return {
|
3517
3687
|
name,
|
3518
|
-
baseChainHeight:
|
3688
|
+
baseChainHeight: bn16(daHeight),
|
3519
3689
|
consensusParameters: {
|
3520
|
-
contractMaxSize:
|
3521
|
-
maxInputs:
|
3522
|
-
maxOutputs:
|
3523
|
-
maxWitnesses:
|
3524
|
-
maxGasPerTx:
|
3525
|
-
maxScriptLength:
|
3526
|
-
maxScriptDataLength:
|
3527
|
-
maxStorageSlots:
|
3528
|
-
maxPredicateLength:
|
3529
|
-
maxPredicateDataLength:
|
3530
|
-
maxGasPerPredicate:
|
3531
|
-
gasPriceFactor:
|
3532
|
-
gasPerByte:
|
3533
|
-
maxMessageDataLength:
|
3534
|
-
chainId:
|
3535
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3690
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3691
|
+
maxInputs: bn16(txParams.maxInputs),
|
3692
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3693
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3694
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3695
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3696
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3697
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3698
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3699
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3700
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3701
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3702
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3703
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3704
|
+
chainId: bn16(consensusParameters.chainId),
|
3536
3705
|
gasCosts
|
3537
3706
|
},
|
3538
3707
|
gasCosts,
|
3539
3708
|
latestBlock: {
|
3540
3709
|
id: latestBlock.id,
|
3541
|
-
height:
|
3710
|
+
height: bn16(latestBlock.height),
|
3542
3711
|
time: latestBlock.header.time,
|
3543
3712
|
transactions: latestBlock.transactions.map((i) => ({
|
3544
3713
|
id: i.id
|
@@ -3608,8 +3777,8 @@ var _Provider = class {
|
|
3608
3777
|
getChain() {
|
3609
3778
|
const chain = _Provider.chainInfoCache[this.url];
|
3610
3779
|
if (!chain) {
|
3611
|
-
throw new
|
3612
|
-
|
3780
|
+
throw new FuelError13(
|
3781
|
+
ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
|
3613
3782
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3614
3783
|
);
|
3615
3784
|
}
|
@@ -3621,8 +3790,8 @@ var _Provider = class {
|
|
3621
3790
|
getNode() {
|
3622
3791
|
const node = _Provider.nodeInfoCache[this.url];
|
3623
3792
|
if (!node) {
|
3624
|
-
throw new
|
3625
|
-
|
3793
|
+
throw new FuelError13(
|
3794
|
+
ErrorCode13.NODE_INFO_CACHE_EMPTY,
|
3626
3795
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3627
3796
|
);
|
3628
3797
|
}
|
@@ -3669,8 +3838,8 @@ var _Provider = class {
|
|
3669
3838
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3670
3839
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3671
3840
|
if (!isMajorSupported || !isMinorSupported) {
|
3672
|
-
throw new
|
3673
|
-
|
3841
|
+
throw new FuelError13(
|
3842
|
+
FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3674
3843
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3675
3844
|
);
|
3676
3845
|
}
|
@@ -3733,7 +3902,7 @@ var _Provider = class {
|
|
3733
3902
|
*/
|
3734
3903
|
async getBlockNumber() {
|
3735
3904
|
const { chain } = await this.operations.getChain();
|
3736
|
-
return
|
3905
|
+
return bn16(chain.latestBlock.height, 10);
|
3737
3906
|
}
|
3738
3907
|
/**
|
3739
3908
|
* Returns the chain information.
|
@@ -3743,13 +3912,12 @@ var _Provider = class {
|
|
3743
3912
|
async fetchNode() {
|
3744
3913
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3745
3914
|
const processedNodeInfo = {
|
3746
|
-
maxDepth:
|
3747
|
-
maxTx:
|
3748
|
-
minGasPrice:
|
3915
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3916
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3917
|
+
minGasPrice: bn16(nodeInfo.minGasPrice),
|
3749
3918
|
nodeVersion: nodeInfo.nodeVersion,
|
3750
3919
|
utxoValidation: nodeInfo.utxoValidation,
|
3751
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3752
|
-
peers: nodeInfo.peers
|
3920
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3753
3921
|
};
|
3754
3922
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3755
3923
|
return processedNodeInfo;
|
@@ -3775,17 +3943,6 @@ var _Provider = class {
|
|
3775
3943
|
} = this.getChain();
|
3776
3944
|
return chainId.toNumber();
|
3777
3945
|
}
|
3778
|
-
/**
|
3779
|
-
* Returns the base asset ID
|
3780
|
-
*
|
3781
|
-
* @returns A promise that resolves to the base asset ID
|
3782
|
-
*/
|
3783
|
-
getBaseAssetId() {
|
3784
|
-
const {
|
3785
|
-
consensusParameters: { baseAssetId }
|
3786
|
-
} = this.getChain();
|
3787
|
-
return baseAssetId;
|
3788
|
-
}
|
3789
3946
|
/**
|
3790
3947
|
* Submits a transaction to the chain to be executed.
|
3791
3948
|
*
|
@@ -3811,8 +3968,8 @@ var _Provider = class {
|
|
3811
3968
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3812
3969
|
for await (const { submitAndAwait } of subscription) {
|
3813
3970
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3814
|
-
throw new
|
3815
|
-
|
3971
|
+
throw new FuelError13(
|
3972
|
+
ErrorCode13.TRANSACTION_SQUEEZED_OUT,
|
3816
3973
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3817
3974
|
);
|
3818
3975
|
}
|
@@ -3846,14 +4003,13 @@ var _Provider = class {
|
|
3846
4003
|
return this.estimateTxDependencies(transactionRequest);
|
3847
4004
|
}
|
3848
4005
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3849
|
-
const { dryRun:
|
3850
|
-
encodedTransaction,
|
4006
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4007
|
+
encodedTransactions: encodedTransaction,
|
3851
4008
|
utxoValidation: utxoValidation || false
|
3852
4009
|
});
|
3853
|
-
const receipts =
|
3854
|
-
|
3855
|
-
|
3856
|
-
};
|
4010
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4011
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4012
|
+
return { receipts, dryrunStatus: status };
|
3857
4013
|
}
|
3858
4014
|
/**
|
3859
4015
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3879,7 +4035,7 @@ var _Provider = class {
|
|
3879
4035
|
} = response;
|
3880
4036
|
if (inputs) {
|
3881
4037
|
inputs.forEach((input, index) => {
|
3882
|
-
if ("predicateGasUsed" in input &&
|
4038
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3883
4039
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3884
4040
|
}
|
3885
4041
|
});
|
@@ -3892,9 +4048,6 @@ var _Provider = class {
|
|
3892
4048
|
* If there are missing variable outputs,
|
3893
4049
|
* `addVariableOutputs` is called on the transaction.
|
3894
4050
|
*
|
3895
|
-
* @privateRemarks
|
3896
|
-
* TODO: Investigate support for missing contract IDs
|
3897
|
-
* TODO: Add support for missing output messages
|
3898
4051
|
*
|
3899
4052
|
* @param transactionRequest - The transaction request object.
|
3900
4053
|
* @returns A promise.
|
@@ -3907,16 +4060,19 @@ var _Provider = class {
|
|
3907
4060
|
missingContractIds: []
|
3908
4061
|
};
|
3909
4062
|
}
|
3910
|
-
await this.estimatePredicates(transactionRequest);
|
3911
4063
|
let receipts = [];
|
3912
4064
|
const missingContractIds = [];
|
3913
4065
|
let outputVariables = 0;
|
4066
|
+
let dryrunStatus;
|
3914
4067
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3915
|
-
const {
|
3916
|
-
|
4068
|
+
const {
|
4069
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4070
|
+
} = await this.operations.dryRun({
|
4071
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3917
4072
|
utxoValidation: false
|
3918
4073
|
});
|
3919
|
-
receipts =
|
4074
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4075
|
+
dryrunStatus = status;
|
3920
4076
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3921
4077
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3922
4078
|
if (hasMissingOutputs) {
|
@@ -3926,6 +4082,11 @@ var _Provider = class {
|
|
3926
4082
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3927
4083
|
missingContractIds.push(contractId);
|
3928
4084
|
});
|
4085
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4086
|
+
transactionRequest,
|
4087
|
+
optimizeGas: false
|
4088
|
+
});
|
4089
|
+
transactionRequest.maxFee = maxFee;
|
3929
4090
|
} else {
|
3930
4091
|
break;
|
3931
4092
|
}
|
@@ -3933,7 +4094,133 @@ var _Provider = class {
|
|
3933
4094
|
return {
|
3934
4095
|
receipts,
|
3935
4096
|
outputVariables,
|
3936
|
-
missingContractIds
|
4097
|
+
missingContractIds,
|
4098
|
+
dryrunStatus
|
4099
|
+
};
|
4100
|
+
}
|
4101
|
+
/**
|
4102
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4103
|
+
*
|
4104
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4105
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4106
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4107
|
+
*
|
4108
|
+
* @param transactionRequests - Array of transaction request objects.
|
4109
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4110
|
+
*/
|
4111
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4112
|
+
const results = transactionRequests.map(() => ({
|
4113
|
+
receipts: [],
|
4114
|
+
outputVariables: 0,
|
4115
|
+
missingContractIds: [],
|
4116
|
+
dryrunStatus: void 0
|
4117
|
+
}));
|
4118
|
+
const allRequests = clone3(transactionRequests);
|
4119
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4120
|
+
allRequests.forEach((req, index) => {
|
4121
|
+
if (req.type === TransactionType8.Script) {
|
4122
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4123
|
+
}
|
4124
|
+
});
|
4125
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4126
|
+
let attempt = 0;
|
4127
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4128
|
+
const encodedTransactions = transactionsToProcess.map(
|
4129
|
+
(index) => serializedTransactionsMap.get(index)
|
4130
|
+
);
|
4131
|
+
const dryRunResults = await this.operations.dryRun({
|
4132
|
+
encodedTransactions,
|
4133
|
+
utxoValidation: false
|
4134
|
+
});
|
4135
|
+
const nextRoundTransactions = [];
|
4136
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4137
|
+
const currentResultIndex = transactionsToProcess[i];
|
4138
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4139
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4140
|
+
results[currentResultIndex].dryrunStatus = status;
|
4141
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4142
|
+
results[currentResultIndex].receipts
|
4143
|
+
);
|
4144
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4145
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4146
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4147
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4148
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4149
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4150
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4151
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4152
|
+
});
|
4153
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4154
|
+
transactionRequest: requestToProcess,
|
4155
|
+
optimizeGas: false
|
4156
|
+
});
|
4157
|
+
requestToProcess.maxFee = maxFee;
|
4158
|
+
serializedTransactionsMap.set(
|
4159
|
+
currentResultIndex,
|
4160
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4161
|
+
);
|
4162
|
+
nextRoundTransactions.push(currentResultIndex);
|
4163
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4164
|
+
}
|
4165
|
+
}
|
4166
|
+
transactionsToProcess = nextRoundTransactions;
|
4167
|
+
attempt += 1;
|
4168
|
+
}
|
4169
|
+
return results;
|
4170
|
+
}
|
4171
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4172
|
+
if (estimateTxDependencies) {
|
4173
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4174
|
+
}
|
4175
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4176
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4177
|
+
encodedTransactions,
|
4178
|
+
utxoValidation: utxoValidation || false
|
4179
|
+
});
|
4180
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4181
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4182
|
+
return { receipts, dryrunStatus: status };
|
4183
|
+
});
|
4184
|
+
return results;
|
4185
|
+
}
|
4186
|
+
async estimateTxGasAndFee(params) {
|
4187
|
+
const { transactionRequest, totalGasUsedByPredicates = bn16(0), optimizeGas = true } = params;
|
4188
|
+
let { gasPrice } = params;
|
4189
|
+
const chainInfo = this.getChain();
|
4190
|
+
const { gasPriceFactor } = this.getGasConfig();
|
4191
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4192
|
+
if (!gasPrice) {
|
4193
|
+
gasPrice = await this.estimateGasPrice(10);
|
4194
|
+
}
|
4195
|
+
const shouldSetGaslimit = transactionRequest.type === TransactionType8.Script && !optimizeGas;
|
4196
|
+
const minFee = calculateGasFee({
|
4197
|
+
gasPrice: bn16(gasPrice),
|
4198
|
+
gas: minGas,
|
4199
|
+
priceFactor: gasPriceFactor,
|
4200
|
+
tip: transactionRequest.tip
|
4201
|
+
}).add(1);
|
4202
|
+
if (shouldSetGaslimit) {
|
4203
|
+
transactionRequest.gasLimit = chainInfo.consensusParameters.maxGasPerTx.sub(
|
4204
|
+
minGas.add(totalGasUsedByPredicates)
|
4205
|
+
);
|
4206
|
+
}
|
4207
|
+
let maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4208
|
+
const maxFee = calculateGasFee({
|
4209
|
+
gasPrice: bn16(gasPrice),
|
4210
|
+
gas: maxGas,
|
4211
|
+
priceFactor: gasPriceFactor,
|
4212
|
+
tip: transactionRequest.tip
|
4213
|
+
}).add(1);
|
4214
|
+
if (shouldSetGaslimit) {
|
4215
|
+
maxGas = chainInfo.consensusParameters.maxGasPerTx.sub(maxFee);
|
4216
|
+
transactionRequest.gasLimit = maxGas;
|
4217
|
+
}
|
4218
|
+
return {
|
4219
|
+
minGas,
|
4220
|
+
minFee,
|
4221
|
+
maxGas,
|
4222
|
+
maxFee,
|
4223
|
+
gasPrice
|
3937
4224
|
};
|
3938
4225
|
}
|
3939
4226
|
/**
|
@@ -3951,15 +4238,17 @@ var _Provider = class {
|
|
3951
4238
|
if (estimateTxDependencies) {
|
3952
4239
|
return this.estimateTxDependencies(transactionRequest);
|
3953
4240
|
}
|
3954
|
-
const
|
3955
|
-
const { dryRun:
|
3956
|
-
|
4241
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4242
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4243
|
+
encodedTransactions,
|
3957
4244
|
utxoValidation: true
|
3958
4245
|
});
|
3959
|
-
const
|
3960
|
-
|
3961
|
-
receipts
|
3962
|
-
|
4246
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4247
|
+
const { id, receipts, status } = dryRunStatus;
|
4248
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4249
|
+
return { id, receipts: processedReceipts, status };
|
4250
|
+
});
|
4251
|
+
return { receipts: callResult[0].receipts };
|
3963
4252
|
}
|
3964
4253
|
/**
|
3965
4254
|
* Returns a transaction cost to enable user
|
@@ -3976,80 +4265,80 @@ var _Provider = class {
|
|
3976
4265
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3977
4266
|
* @returns A promise that resolves to the transaction cost object.
|
3978
4267
|
*/
|
3979
|
-
async getTransactionCost(transactionRequestLike,
|
3980
|
-
estimateTxDependencies = true,
|
3981
|
-
estimatePredicates = true,
|
3982
|
-
resourcesOwner,
|
3983
|
-
signatureCallback
|
3984
|
-
} = {}) {
|
4268
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3985
4269
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3986
|
-
const chainInfo = this.getChain();
|
3987
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3988
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3989
4270
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3990
4271
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3991
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4272
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3992
4273
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3993
|
-
|
3994
|
-
|
3995
|
-
|
3996
|
-
}
|
3997
|
-
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3998
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3999
|
-
}
|
4000
|
-
await this.estimatePredicates(txRequestClone);
|
4274
|
+
txRequestClone.maxFee = bn16(0);
|
4275
|
+
if (isScriptTransaction) {
|
4276
|
+
txRequestClone.gasLimit = bn16(0);
|
4001
4277
|
}
|
4002
|
-
if (
|
4003
|
-
|
4278
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4279
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4004
4280
|
}
|
4005
|
-
const
|
4006
|
-
|
4281
|
+
const signedRequest = clone3(txRequestClone);
|
4282
|
+
let addedSignatures = 0;
|
4283
|
+
if (signatureCallback && isScriptTransaction) {
|
4284
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4285
|
+
await signatureCallback(signedRequest);
|
4286
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4287
|
+
}
|
4288
|
+
await this.estimatePredicates(signedRequest);
|
4289
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4290
|
+
transactionRequest: signedRequest,
|
4291
|
+
optimizeGas: false
|
4292
|
+
});
|
4293
|
+
txRequestClone.maxFee = maxFee;
|
4007
4294
|
let receipts = [];
|
4008
4295
|
let missingContractIds = [];
|
4009
4296
|
let outputVariables = 0;
|
4010
|
-
|
4011
|
-
|
4012
|
-
|
4297
|
+
let gasUsed = bn16(0);
|
4298
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4299
|
+
if (isScriptTransaction) {
|
4300
|
+
if (signatureCallback) {
|
4301
|
+
await signatureCallback(txRequestClone);
|
4302
|
+
}
|
4303
|
+
txRequestClone.gasLimit = maxGas;
|
4013
4304
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4014
4305
|
receipts = result.receipts;
|
4015
4306
|
outputVariables = result.outputVariables;
|
4016
4307
|
missingContractIds = result.missingContractIds;
|
4308
|
+
gasUsed = getGasUsedFromReceipts(receipts);
|
4309
|
+
txRequestClone.gasLimit = gasUsed;
|
4310
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4311
|
+
transactionRequest: txRequestClone,
|
4312
|
+
gasPrice
|
4313
|
+
}));
|
4017
4314
|
}
|
4018
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4019
|
-
const usedFee = calculatePriceWithFactor(
|
4020
|
-
gasUsed,
|
4021
|
-
gasPrice,
|
4022
|
-
gasPriceFactor
|
4023
|
-
).normalizeZeroToOne();
|
4024
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4025
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4026
4315
|
return {
|
4027
4316
|
requiredQuantities: allQuantities,
|
4028
4317
|
receipts,
|
4029
4318
|
gasUsed,
|
4030
|
-
minGasPrice,
|
4031
4319
|
gasPrice,
|
4032
4320
|
minGas,
|
4033
4321
|
maxGas,
|
4034
|
-
usedFee,
|
4035
4322
|
minFee,
|
4036
4323
|
maxFee,
|
4037
|
-
estimatedInputs: txRequestClone.inputs,
|
4038
4324
|
outputVariables,
|
4039
|
-
missingContractIds
|
4325
|
+
missingContractIds,
|
4326
|
+
addedSignatures,
|
4327
|
+
estimatedPredicates: txRequestClone.inputs
|
4040
4328
|
};
|
4041
4329
|
}
|
4042
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4330
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4043
4331
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4044
4332
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4045
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4333
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4334
|
+
quantitiesToContract
|
4335
|
+
});
|
4046
4336
|
transactionRequest.addResources(
|
4047
4337
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4048
4338
|
);
|
4049
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4050
|
-
|
4051
|
-
|
4052
|
-
);
|
4339
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4340
|
+
quantitiesToContract
|
4341
|
+
});
|
4053
4342
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4054
4343
|
return {
|
4055
4344
|
resources,
|
@@ -4071,11 +4360,10 @@ var _Provider = class {
|
|
4071
4360
|
return coins.map((coin) => ({
|
4072
4361
|
id: coin.utxoId,
|
4073
4362
|
assetId: coin.assetId,
|
4074
|
-
amount:
|
4363
|
+
amount: bn16(coin.amount),
|
4075
4364
|
owner: Address2.fromAddressOrString(coin.owner),
|
4076
|
-
|
4077
|
-
|
4078
|
-
txCreatedIdx: bn14(coin.txCreatedIdx)
|
4365
|
+
blockCreated: bn16(coin.blockCreated),
|
4366
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4079
4367
|
}));
|
4080
4368
|
}
|
4081
4369
|
/**
|
@@ -4112,9 +4400,9 @@ var _Provider = class {
|
|
4112
4400
|
switch (coin.__typename) {
|
4113
4401
|
case "MessageCoin":
|
4114
4402
|
return {
|
4115
|
-
amount:
|
4403
|
+
amount: bn16(coin.amount),
|
4116
4404
|
assetId: coin.assetId,
|
4117
|
-
daHeight:
|
4405
|
+
daHeight: bn16(coin.daHeight),
|
4118
4406
|
sender: Address2.fromAddressOrString(coin.sender),
|
4119
4407
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4120
4408
|
nonce: coin.nonce
|
@@ -4122,12 +4410,11 @@ var _Provider = class {
|
|
4122
4410
|
case "Coin":
|
4123
4411
|
return {
|
4124
4412
|
id: coin.utxoId,
|
4125
|
-
amount:
|
4413
|
+
amount: bn16(coin.amount),
|
4126
4414
|
assetId: coin.assetId,
|
4127
4415
|
owner: Address2.fromAddressOrString(coin.owner),
|
4128
|
-
|
4129
|
-
|
4130
|
-
txCreatedIdx: bn14(coin.txCreatedIdx)
|
4416
|
+
blockCreated: bn16(coin.blockCreated),
|
4417
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4131
4418
|
};
|
4132
4419
|
default:
|
4133
4420
|
return null;
|
@@ -4144,13 +4431,13 @@ var _Provider = class {
|
|
4144
4431
|
async getBlock(idOrHeight) {
|
4145
4432
|
let variables;
|
4146
4433
|
if (typeof idOrHeight === "number") {
|
4147
|
-
variables = { height:
|
4434
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4148
4435
|
} else if (idOrHeight === "latest") {
|
4149
4436
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4150
4437
|
} else if (idOrHeight.length === 66) {
|
4151
4438
|
variables = { blockId: idOrHeight };
|
4152
4439
|
} else {
|
4153
|
-
variables = { blockId:
|
4440
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4154
4441
|
}
|
4155
4442
|
const { block } = await this.operations.getBlock(variables);
|
4156
4443
|
if (!block) {
|
@@ -4158,7 +4445,7 @@ var _Provider = class {
|
|
4158
4445
|
}
|
4159
4446
|
return {
|
4160
4447
|
id: block.id,
|
4161
|
-
height:
|
4448
|
+
height: bn16(block.height),
|
4162
4449
|
time: block.header.time,
|
4163
4450
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4164
4451
|
};
|
@@ -4173,7 +4460,7 @@ var _Provider = class {
|
|
4173
4460
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4174
4461
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4175
4462
|
id: block.id,
|
4176
|
-
height:
|
4463
|
+
height: bn16(block.height),
|
4177
4464
|
time: block.header.time,
|
4178
4465
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4179
4466
|
}));
|
@@ -4188,7 +4475,7 @@ var _Provider = class {
|
|
4188
4475
|
async getBlockWithTransactions(idOrHeight) {
|
4189
4476
|
let variables;
|
4190
4477
|
if (typeof idOrHeight === "number") {
|
4191
|
-
variables = { blockHeight:
|
4478
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4192
4479
|
} else if (idOrHeight === "latest") {
|
4193
4480
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4194
4481
|
} else {
|
@@ -4200,7 +4487,7 @@ var _Provider = class {
|
|
4200
4487
|
}
|
4201
4488
|
return {
|
4202
4489
|
id: block.id,
|
4203
|
-
height:
|
4490
|
+
height: bn16(block.height, 10),
|
4204
4491
|
time: block.header.time,
|
4205
4492
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4206
4493
|
transactions: block.transactions.map(
|
@@ -4249,7 +4536,7 @@ var _Provider = class {
|
|
4249
4536
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4250
4537
|
asset: hexlify12(assetId)
|
4251
4538
|
});
|
4252
|
-
return
|
4539
|
+
return bn16(contractBalance.amount, 10);
|
4253
4540
|
}
|
4254
4541
|
/**
|
4255
4542
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4263,7 +4550,7 @@ var _Provider = class {
|
|
4263
4550
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4264
4551
|
assetId: hexlify12(assetId)
|
4265
4552
|
});
|
4266
|
-
return
|
4553
|
+
return bn16(balance.amount, 10);
|
4267
4554
|
}
|
4268
4555
|
/**
|
4269
4556
|
* Returns balances for the given owner.
|
@@ -4281,7 +4568,7 @@ var _Provider = class {
|
|
4281
4568
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4282
4569
|
return balances.map((balance) => ({
|
4283
4570
|
assetId: balance.assetId,
|
4284
|
-
amount:
|
4571
|
+
amount: bn16(balance.amount)
|
4285
4572
|
}));
|
4286
4573
|
}
|
4287
4574
|
/**
|
@@ -4303,15 +4590,15 @@ var _Provider = class {
|
|
4303
4590
|
sender: message.sender,
|
4304
4591
|
recipient: message.recipient,
|
4305
4592
|
nonce: message.nonce,
|
4306
|
-
amount:
|
4593
|
+
amount: bn16(message.amount),
|
4307
4594
|
data: message.data
|
4308
4595
|
}),
|
4309
4596
|
sender: Address2.fromAddressOrString(message.sender),
|
4310
4597
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4311
4598
|
nonce: message.nonce,
|
4312
|
-
amount:
|
4599
|
+
amount: bn16(message.amount),
|
4313
4600
|
data: InputMessageCoder.decodeData(message.data),
|
4314
|
-
daHeight:
|
4601
|
+
daHeight: bn16(message.daHeight)
|
4315
4602
|
}));
|
4316
4603
|
}
|
4317
4604
|
/**
|
@@ -4329,8 +4616,8 @@ var _Provider = class {
|
|
4329
4616
|
nonce
|
4330
4617
|
};
|
4331
4618
|
if (commitBlockId && commitBlockHeight) {
|
4332
|
-
throw new
|
4333
|
-
|
4619
|
+
throw new FuelError13(
|
4620
|
+
ErrorCode13.INVALID_INPUT_PARAMETERS,
|
4334
4621
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4335
4622
|
);
|
4336
4623
|
}
|
@@ -4364,44 +4651,54 @@ var _Provider = class {
|
|
4364
4651
|
} = result.messageProof;
|
4365
4652
|
return {
|
4366
4653
|
messageProof: {
|
4367
|
-
proofIndex:
|
4654
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4368
4655
|
proofSet: messageProof.proofSet
|
4369
4656
|
},
|
4370
4657
|
blockProof: {
|
4371
|
-
proofIndex:
|
4658
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4372
4659
|
proofSet: blockProof.proofSet
|
4373
4660
|
},
|
4374
4661
|
messageBlockHeader: {
|
4375
4662
|
id: messageBlockHeader.id,
|
4376
|
-
daHeight:
|
4377
|
-
transactionsCount:
|
4663
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4664
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4378
4665
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4379
|
-
height:
|
4666
|
+
height: bn16(messageBlockHeader.height),
|
4380
4667
|
prevRoot: messageBlockHeader.prevRoot,
|
4381
4668
|
time: messageBlockHeader.time,
|
4382
4669
|
applicationHash: messageBlockHeader.applicationHash,
|
4383
4670
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4384
|
-
messageReceiptCount:
|
4671
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount)
|
4385
4672
|
},
|
4386
4673
|
commitBlockHeader: {
|
4387
4674
|
id: commitBlockHeader.id,
|
4388
|
-
daHeight:
|
4389
|
-
transactionsCount:
|
4675
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4676
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4390
4677
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4391
|
-
height:
|
4678
|
+
height: bn16(commitBlockHeader.height),
|
4392
4679
|
prevRoot: commitBlockHeader.prevRoot,
|
4393
4680
|
time: commitBlockHeader.time,
|
4394
4681
|
applicationHash: commitBlockHeader.applicationHash,
|
4395
4682
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4396
|
-
messageReceiptCount:
|
4683
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount)
|
4397
4684
|
},
|
4398
4685
|
sender: Address2.fromAddressOrString(sender),
|
4399
4686
|
recipient: Address2.fromAddressOrString(recipient),
|
4400
4687
|
nonce,
|
4401
|
-
amount:
|
4688
|
+
amount: bn16(amount),
|
4402
4689
|
data
|
4403
4690
|
};
|
4404
4691
|
}
|
4692
|
+
async getLatestGasPrice() {
|
4693
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4694
|
+
return bn16(latestGasPrice.gasPrice);
|
4695
|
+
}
|
4696
|
+
async estimateGasPrice(blockHorizon) {
|
4697
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4698
|
+
blockHorizon: String(blockHorizon)
|
4699
|
+
});
|
4700
|
+
return bn16(estimateGasPrice.gasPrice);
|
4701
|
+
}
|
4405
4702
|
/**
|
4406
4703
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4407
4704
|
*
|
@@ -4421,10 +4718,10 @@ var _Provider = class {
|
|
4421
4718
|
*/
|
4422
4719
|
async produceBlocks(amount, startTime) {
|
4423
4720
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4424
|
-
blocksToProduce:
|
4721
|
+
blocksToProduce: bn16(amount).toString(10),
|
4425
4722
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4426
4723
|
});
|
4427
|
-
return
|
4724
|
+
return bn16(latestBlockHeight);
|
4428
4725
|
}
|
4429
4726
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4430
4727
|
async getTransactionResponse(transactionId) {
|
@@ -4438,7 +4735,7 @@ cacheInputs_fn = function(inputs) {
|
|
4438
4735
|
return;
|
4439
4736
|
}
|
4440
4737
|
inputs.forEach((input) => {
|
4441
|
-
if (input.type ===
|
4738
|
+
if (input.type === InputType7.Coin) {
|
4442
4739
|
this.cache?.set(input.id);
|
4443
4740
|
}
|
4444
4741
|
});
|
@@ -4447,8 +4744,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4447
4744
|
__publicField(Provider, "nodeInfoCache", {});
|
4448
4745
|
|
4449
4746
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4450
|
-
import { ErrorCode as
|
4451
|
-
import { bn as
|
4747
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4748
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4452
4749
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4453
4750
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4454
4751
|
async function getTransactionSummary(params) {
|
@@ -4457,8 +4754,8 @@ async function getTransactionSummary(params) {
|
|
4457
4754
|
transactionId: id
|
4458
4755
|
});
|
4459
4756
|
if (!gqlTransaction) {
|
4460
|
-
throw new
|
4461
|
-
|
4757
|
+
throw new FuelError14(
|
4758
|
+
ErrorCode14.TRANSACTION_NOT_FOUND,
|
4462
4759
|
`Transaction not found for given id: ${id}.`
|
4463
4760
|
);
|
4464
4761
|
}
|
@@ -4466,21 +4763,28 @@ async function getTransactionSummary(params) {
|
|
4466
4763
|
arrayify12(gqlTransaction.rawPayload),
|
4467
4764
|
0
|
4468
4765
|
);
|
4469
|
-
|
4766
|
+
let txReceipts = [];
|
4767
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4768
|
+
txReceipts = gqlTransaction.status.receipts;
|
4769
|
+
}
|
4770
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4470
4771
|
const {
|
4471
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4772
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4472
4773
|
} = provider.getChain();
|
4774
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4473
4775
|
const transactionInfo = assembleTransactionSummary({
|
4474
4776
|
id: gqlTransaction.id,
|
4475
4777
|
receipts,
|
4476
4778
|
transaction: decodedTransaction,
|
4477
4779
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4478
4780
|
gqlTransactionStatus: gqlTransaction.status,
|
4479
|
-
gasPerByte:
|
4480
|
-
gasPriceFactor:
|
4781
|
+
gasPerByte: bn17(gasPerByte),
|
4782
|
+
gasPriceFactor: bn17(gasPriceFactor),
|
4481
4783
|
abiMap,
|
4482
4784
|
maxInputs,
|
4483
|
-
gasCosts
|
4785
|
+
gasCosts,
|
4786
|
+
maxGasPerTx,
|
4787
|
+
gasPrice
|
4484
4788
|
});
|
4485
4789
|
return {
|
4486
4790
|
gqlTransaction,
|
@@ -4490,10 +4794,11 @@ async function getTransactionSummary(params) {
|
|
4490
4794
|
async function getTransactionSummaryFromRequest(params) {
|
4491
4795
|
const { provider, transactionRequest, abiMap } = params;
|
4492
4796
|
const { receipts } = await provider.call(transactionRequest);
|
4493
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4797
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4494
4798
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4495
4799
|
const transaction = transactionRequest.toTransaction();
|
4496
4800
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4801
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4497
4802
|
const transactionSummary = assembleTransactionSummary({
|
4498
4803
|
receipts,
|
4499
4804
|
transaction,
|
@@ -4502,7 +4807,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4502
4807
|
gasPerByte,
|
4503
4808
|
gasPriceFactor,
|
4504
4809
|
maxInputs,
|
4505
|
-
gasCosts
|
4810
|
+
gasCosts,
|
4811
|
+
maxGasPerTx,
|
4812
|
+
gasPrice
|
4506
4813
|
});
|
4507
4814
|
return transactionSummary;
|
4508
4815
|
}
|
@@ -4511,13 +4818,18 @@ async function getTransactionsSummaries(params) {
|
|
4511
4818
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4512
4819
|
const { edges, pageInfo } = transactionsByOwner;
|
4513
4820
|
const {
|
4514
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4821
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4515
4822
|
} = provider.getChain();
|
4823
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4516
4824
|
const transactions = edges.map((edge) => {
|
4517
4825
|
const { node: gqlTransaction } = edge;
|
4518
|
-
const { id, rawPayload,
|
4826
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4519
4827
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4520
|
-
|
4828
|
+
let txReceipts = [];
|
4829
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4830
|
+
txReceipts = gqlTransaction.status.receipts;
|
4831
|
+
}
|
4832
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4521
4833
|
const transactionSummary = assembleTransactionSummary({
|
4522
4834
|
id,
|
4523
4835
|
receipts,
|
@@ -4528,7 +4840,9 @@ async function getTransactionsSummaries(params) {
|
|
4528
4840
|
gasPerByte,
|
4529
4841
|
gasPriceFactor,
|
4530
4842
|
maxInputs,
|
4531
|
-
gasCosts
|
4843
|
+
gasCosts,
|
4844
|
+
maxGasPerTx,
|
4845
|
+
gasPrice
|
4532
4846
|
});
|
4533
4847
|
const output = {
|
4534
4848
|
gqlTransaction,
|
@@ -4731,7 +5045,7 @@ var Account = class extends AbstractAccount {
|
|
4731
5045
|
*/
|
4732
5046
|
get provider() {
|
4733
5047
|
if (!this._provider) {
|
4734
|
-
throw new
|
5048
|
+
throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
|
4735
5049
|
}
|
4736
5050
|
return this._provider;
|
4737
5051
|
}
|
@@ -4783,8 +5097,8 @@ var Account = class extends AbstractAccount {
|
|
4783
5097
|
if (!hasNextPage) {
|
4784
5098
|
break;
|
4785
5099
|
}
|
4786
|
-
throw new
|
4787
|
-
|
5100
|
+
throw new FuelError15(
|
5101
|
+
ErrorCode15.NOT_SUPPORTED,
|
4788
5102
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4789
5103
|
);
|
4790
5104
|
}
|
@@ -4809,8 +5123,8 @@ var Account = class extends AbstractAccount {
|
|
4809
5123
|
if (!hasNextPage) {
|
4810
5124
|
break;
|
4811
5125
|
}
|
4812
|
-
throw new
|
4813
|
-
|
5126
|
+
throw new FuelError15(
|
5127
|
+
ErrorCode15.NOT_SUPPORTED,
|
4814
5128
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4815
5129
|
);
|
4816
5130
|
}
|
@@ -4822,9 +5136,8 @@ var Account = class extends AbstractAccount {
|
|
4822
5136
|
* @param assetId - The asset ID to check the balance for.
|
4823
5137
|
* @returns A promise that resolves to the balance amount.
|
4824
5138
|
*/
|
4825
|
-
async getBalance(assetId) {
|
4826
|
-
const
|
4827
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5139
|
+
async getBalance(assetId = BaseAssetId3) {
|
5140
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4828
5141
|
return amount;
|
4829
5142
|
}
|
4830
5143
|
/**
|
@@ -4846,8 +5159,8 @@ var Account = class extends AbstractAccount {
|
|
4846
5159
|
if (!hasNextPage) {
|
4847
5160
|
break;
|
4848
5161
|
}
|
4849
|
-
throw new
|
4850
|
-
|
5162
|
+
throw new FuelError15(
|
5163
|
+
ErrorCode15.NOT_SUPPORTED,
|
4851
5164
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4852
5165
|
);
|
4853
5166
|
}
|
@@ -4861,37 +5174,33 @@ var Account = class extends AbstractAccount {
|
|
4861
5174
|
* @param fee - The estimated transaction fee.
|
4862
5175
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4863
5176
|
*/
|
4864
|
-
async fund(request,
|
4865
|
-
const
|
4866
|
-
const
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
5177
|
+
async fund(request, params) {
|
5178
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5179
|
+
const txRequest = request;
|
5180
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5181
|
+
amount: bn18(fee),
|
5182
|
+
assetId: BaseAssetId3,
|
5183
|
+
coinQuantities: requiredQuantities
|
4870
5184
|
});
|
4871
5185
|
const quantitiesDict = {};
|
4872
|
-
|
5186
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4873
5187
|
quantitiesDict[assetId] = {
|
4874
5188
|
required: amount,
|
4875
|
-
owned:
|
5189
|
+
owned: bn18(0)
|
4876
5190
|
};
|
4877
5191
|
});
|
4878
|
-
|
4879
|
-
const cachedMessages = [];
|
4880
|
-
const owner = this.address.toB256();
|
4881
|
-
request.inputs.forEach((input) => {
|
5192
|
+
txRequest.inputs.forEach((input) => {
|
4882
5193
|
const isResource = "amount" in input;
|
4883
5194
|
if (isResource) {
|
4884
5195
|
const isCoin2 = "owner" in input;
|
4885
5196
|
if (isCoin2) {
|
4886
5197
|
const assetId = String(input.assetId);
|
4887
|
-
if (
|
4888
|
-
const amount =
|
5198
|
+
if (quantitiesDict[assetId]) {
|
5199
|
+
const amount = bn18(input.amount);
|
4889
5200
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4890
|
-
cachedUtxos.push(input.id);
|
4891
5201
|
}
|
4892
|
-
} else if (input.
|
4893
|
-
quantitiesDict[
|
4894
|
-
cachedMessages.push(input.nonce);
|
5202
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
5203
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4895
5204
|
}
|
4896
5205
|
}
|
4897
5206
|
});
|
@@ -4906,12 +5215,23 @@ var Account = class extends AbstractAccount {
|
|
4906
5215
|
});
|
4907
5216
|
const needsToBeFunded = missingQuantities.length;
|
4908
5217
|
if (needsToBeFunded) {
|
4909
|
-
const
|
4910
|
-
|
4911
|
-
|
4912
|
-
|
4913
|
-
|
5218
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toString());
|
5219
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5220
|
+
txRequest.addResources(resources);
|
5221
|
+
}
|
5222
|
+
txRequest.shiftPredicateData();
|
5223
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5224
|
+
const requestToBeReEstimate = clone4(txRequest);
|
5225
|
+
if (addedSignatures) {
|
5226
|
+
Array.from({ length: addedSignatures }).forEach(
|
5227
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5228
|
+
);
|
4914
5229
|
}
|
5230
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5231
|
+
transactionRequest: requestToBeReEstimate
|
5232
|
+
});
|
5233
|
+
txRequest.maxFee = maxFee;
|
5234
|
+
return txRequest;
|
4915
5235
|
}
|
4916
5236
|
/**
|
4917
5237
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4919,29 +5239,25 @@ var Account = class extends AbstractAccount {
|
|
4919
5239
|
* @param destination - The address of the destination.
|
4920
5240
|
* @param amount - The amount of coins to transfer.
|
4921
5241
|
* @param assetId - The asset ID of the coins to transfer.
|
4922
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5242
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4923
5243
|
* @returns A promise that resolves to the prepared transaction request.
|
4924
5244
|
*/
|
4925
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4926
|
-
const
|
4927
|
-
|
4928
|
-
const
|
4929
|
-
const request = new ScriptTransactionRequest(params);
|
4930
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4931
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5245
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5246
|
+
const request = new ScriptTransactionRequest(txParams);
|
5247
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
5248
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4932
5249
|
estimateTxDependencies: true,
|
4933
5250
|
resourcesOwner: this
|
4934
5251
|
});
|
4935
|
-
|
4936
|
-
|
4937
|
-
|
4938
|
-
|
4939
|
-
|
4940
|
-
|
4941
|
-
|
4942
|
-
|
4943
|
-
await this.fund(request,
|
4944
|
-
request.updatePredicateInputs(estimatedInputs);
|
5252
|
+
if ("gasLimit" in txParams) {
|
5253
|
+
this.validateGas({
|
5254
|
+
gasUsed: txCost.gasUsed,
|
5255
|
+
gasLimit: request.gasLimit
|
5256
|
+
});
|
5257
|
+
}
|
5258
|
+
request.gasLimit = txCost.gasUsed;
|
5259
|
+
request.maxFee = txCost.maxFee;
|
5260
|
+
await this.fund(request, txCost);
|
4945
5261
|
return request;
|
4946
5262
|
}
|
4947
5263
|
/**
|
@@ -4953,15 +5269,14 @@ var Account = class extends AbstractAccount {
|
|
4953
5269
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4954
5270
|
* @returns A promise that resolves to the transaction response.
|
4955
5271
|
*/
|
4956
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4957
|
-
if (
|
4958
|
-
throw new
|
4959
|
-
|
5272
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5273
|
+
if (bn18(amount).lte(0)) {
|
5274
|
+
throw new FuelError15(
|
5275
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4960
5276
|
"Transfer amount must be a positive number."
|
4961
5277
|
);
|
4962
5278
|
}
|
4963
|
-
const
|
4964
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5279
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4965
5280
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4966
5281
|
}
|
4967
5282
|
/**
|
@@ -4973,40 +5288,38 @@ var Account = class extends AbstractAccount {
|
|
4973
5288
|
* @param txParams - The optional transaction parameters.
|
4974
5289
|
* @returns A promise that resolves to the transaction response.
|
4975
5290
|
*/
|
4976
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4977
|
-
if (
|
4978
|
-
throw new
|
4979
|
-
|
5291
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5292
|
+
if (bn18(amount).lte(0)) {
|
5293
|
+
throw new FuelError15(
|
5294
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4980
5295
|
"Transfer amount must be a positive number."
|
4981
5296
|
);
|
4982
5297
|
}
|
4983
5298
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4984
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4985
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4986
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4987
5299
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4988
5300
|
hexlifiedContractId: contractAddress.toB256(),
|
4989
|
-
amountToTransfer:
|
4990
|
-
assetId
|
5301
|
+
amountToTransfer: bn18(amount),
|
5302
|
+
assetId
|
4991
5303
|
});
|
4992
5304
|
const request = new ScriptTransactionRequest({
|
4993
|
-
...
|
5305
|
+
...txParams,
|
4994
5306
|
script,
|
4995
5307
|
scriptData
|
4996
5308
|
});
|
4997
5309
|
request.addContractInputAndOutput(contractAddress);
|
4998
|
-
const
|
4999
|
-
|
5000
|
-
[{ amount:
|
5001
|
-
);
|
5002
|
-
request.gasLimit = bn16(params.gasLimit ?? gasUsed);
|
5003
|
-
this.validateGas({
|
5004
|
-
gasUsed,
|
5005
|
-
gasPrice: request.gasPrice,
|
5006
|
-
gasLimit: request.gasLimit,
|
5007
|
-
minGasPrice
|
5310
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5311
|
+
resourcesOwner: this,
|
5312
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
5008
5313
|
});
|
5009
|
-
|
5314
|
+
if (txParams.gasLimit) {
|
5315
|
+
this.validateGas({
|
5316
|
+
gasUsed: txCost.gasUsed,
|
5317
|
+
gasLimit: request.gasLimit
|
5318
|
+
});
|
5319
|
+
}
|
5320
|
+
request.gasLimit = txCost.gasUsed;
|
5321
|
+
request.maxFee = txCost.maxFee;
|
5322
|
+
await this.fund(request, txCost);
|
5010
5323
|
return this.sendTransaction(request);
|
5011
5324
|
}
|
5012
5325
|
/**
|
@@ -5018,40 +5331,36 @@ var Account = class extends AbstractAccount {
|
|
5018
5331
|
* @returns A promise that resolves to the transaction response.
|
5019
5332
|
*/
|
5020
5333
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5021
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5022
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5023
5334
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5024
5335
|
const recipientDataArray = arrayify14(
|
5025
5336
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5026
5337
|
);
|
5027
5338
|
const amountDataArray = arrayify14(
|
5028
|
-
"0x".concat(
|
5339
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
5029
5340
|
);
|
5030
5341
|
const script = new Uint8Array([
|
5031
5342
|
...arrayify14(withdrawScript.bytes),
|
5032
5343
|
...recipientDataArray,
|
5033
5344
|
...amountDataArray
|
5034
5345
|
]);
|
5035
|
-
const params = { script,
|
5346
|
+
const params = { script, ...txParams };
|
5036
5347
|
const request = new ScriptTransactionRequest(params);
|
5037
|
-
const
|
5038
|
-
const
|
5039
|
-
|
5040
|
-
|
5041
|
-
|
5042
|
-
|
5043
|
-
|
5044
|
-
|
5045
|
-
|
5046
|
-
|
5047
|
-
|
5048
|
-
});
|
5049
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5348
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5349
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5350
|
+
if (txParams.gasLimit) {
|
5351
|
+
this.validateGas({
|
5352
|
+
gasUsed: txCost.gasUsed,
|
5353
|
+
gasLimit: request.gasLimit
|
5354
|
+
});
|
5355
|
+
}
|
5356
|
+
request.maxFee = txCost.maxFee;
|
5357
|
+
request.gasLimit = txCost.gasUsed;
|
5358
|
+
await this.fund(request, txCost);
|
5050
5359
|
return this.sendTransaction(request);
|
5051
5360
|
}
|
5052
5361
|
async signMessage(message) {
|
5053
5362
|
if (!this._connector) {
|
5054
|
-
throw new
|
5363
|
+
throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5055
5364
|
}
|
5056
5365
|
return this._connector.signMessage(this.address.toString(), message);
|
5057
5366
|
}
|
@@ -5063,8 +5372,8 @@ var Account = class extends AbstractAccount {
|
|
5063
5372
|
*/
|
5064
5373
|
async signTransaction(transactionRequestLike) {
|
5065
5374
|
if (!this._connector) {
|
5066
|
-
throw new
|
5067
|
-
|
5375
|
+
throw new FuelError15(
|
5376
|
+
ErrorCode15.MISSING_CONNECTOR,
|
5068
5377
|
"A connector is required to sign transactions."
|
5069
5378
|
);
|
5070
5379
|
}
|
@@ -5104,21 +5413,10 @@ var Account = class extends AbstractAccount {
|
|
5104
5413
|
}
|
5105
5414
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5106
5415
|
}
|
5107
|
-
validateGas({
|
5108
|
-
gasUsed,
|
5109
|
-
gasPrice,
|
5110
|
-
gasLimit,
|
5111
|
-
minGasPrice
|
5112
|
-
}) {
|
5113
|
-
if (minGasPrice.gt(gasPrice)) {
|
5114
|
-
throw new FuelError14(
|
5115
|
-
ErrorCode14.GAS_PRICE_TOO_LOW,
|
5116
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5117
|
-
);
|
5118
|
-
}
|
5416
|
+
validateGas({ gasUsed, gasLimit }) {
|
5119
5417
|
if (gasUsed.gt(gasLimit)) {
|
5120
|
-
throw new
|
5121
|
-
|
5418
|
+
throw new FuelError15(
|
5419
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
5122
5420
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5123
5421
|
);
|
5124
5422
|
}
|
@@ -5131,7 +5429,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5131
5429
|
|
5132
5430
|
// src/signer/signer.ts
|
5133
5431
|
import { Address as Address4 } from "@fuel-ts/address";
|
5134
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5432
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
5135
5433
|
import { hash } from "@fuel-ts/hasher";
|
5136
5434
|
import { toBytes } from "@fuel-ts/math";
|
5137
5435
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5224,7 +5522,7 @@ var Signer = class {
|
|
5224
5522
|
* @returns random 32-byte hashed
|
5225
5523
|
*/
|
5226
5524
|
static generatePrivateKey(entropy) {
|
5227
|
-
return entropy ? hash(concat3([
|
5525
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
5228
5526
|
}
|
5229
5527
|
/**
|
5230
5528
|
* Extended publicKey from a compact publicKey
|
@@ -5243,13 +5541,13 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5243
5541
|
import {
|
5244
5542
|
bufferFromString,
|
5245
5543
|
keccak256,
|
5246
|
-
randomBytes as
|
5544
|
+
randomBytes as randomBytes3,
|
5247
5545
|
scrypt,
|
5248
5546
|
stringFromBuffer,
|
5249
5547
|
decryptJsonWalletData,
|
5250
5548
|
encryptJsonWalletData
|
5251
5549
|
} from "@fuel-ts/crypto";
|
5252
|
-
import { ErrorCode as
|
5550
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
5253
5551
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5254
5552
|
import { v4 as uuidv4 } from "uuid";
|
5255
5553
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5266,7 +5564,7 @@ var removeHexPrefix = (hexString) => {
|
|
5266
5564
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5267
5565
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5268
5566
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5269
|
-
const salt =
|
5567
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5270
5568
|
const key = scrypt({
|
5271
5569
|
password: bufferFromString(password),
|
5272
5570
|
salt,
|
@@ -5275,7 +5573,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5275
5573
|
r: DEFAULT_KDF_PARAMS_R,
|
5276
5574
|
p: DEFAULT_KDF_PARAMS_P
|
5277
5575
|
});
|
5278
|
-
const iv =
|
5576
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5279
5577
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5280
5578
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5281
5579
|
const macHashUint8Array = keccak256(data);
|
@@ -5327,8 +5625,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5327
5625
|
const macHashUint8Array = keccak256(data);
|
5328
5626
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5329
5627
|
if (mac !== macHash) {
|
5330
|
-
throw new
|
5331
|
-
|
5628
|
+
throw new FuelError16(
|
5629
|
+
ErrorCode16.INVALID_PASSWORD,
|
5332
5630
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5333
5631
|
);
|
5334
5632
|
}
|
@@ -5411,7 +5709,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5411
5709
|
* @param transactionRequestLike - The transaction request to send.
|
5412
5710
|
* @returns A promise that resolves to the TransactionResponse object.
|
5413
5711
|
*/
|
5414
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5712
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5415
5713
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5416
5714
|
if (estimateTxDependencies) {
|
5417
5715
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5450,15 +5748,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5450
5748
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5451
5749
|
|
5452
5750
|
// src/hdwallet/hdwallet.ts
|
5453
|
-
import { ErrorCode as
|
5751
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5454
5752
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5455
|
-
import { bn as
|
5753
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5456
5754
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5457
5755
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5458
5756
|
|
5459
5757
|
// src/mnemonic/mnemonic.ts
|
5460
|
-
import { randomBytes as
|
5461
|
-
import { ErrorCode as
|
5758
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5759
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5462
5760
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5463
5761
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5464
5762
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7522,7 +7820,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7522
7820
|
})(Language || {});
|
7523
7821
|
|
7524
7822
|
// src/mnemonic/utils.ts
|
7525
|
-
import { ErrorCode as
|
7823
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
7526
7824
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7527
7825
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7528
7826
|
function toUtf8Bytes(stri) {
|
@@ -7539,8 +7837,8 @@ function toUtf8Bytes(stri) {
|
|
7539
7837
|
i += 1;
|
7540
7838
|
const c2 = str.charCodeAt(i);
|
7541
7839
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7542
|
-
throw new
|
7543
|
-
|
7840
|
+
throw new FuelError17(
|
7841
|
+
ErrorCode17.INVALID_INPUT_PARAMETERS,
|
7544
7842
|
"Invalid UTF-8 in the input string."
|
7545
7843
|
);
|
7546
7844
|
}
|
@@ -7603,8 +7901,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7603
7901
|
for (let i = 0; i < words.length; i += 1) {
|
7604
7902
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7605
7903
|
if (index === -1) {
|
7606
|
-
throw new
|
7607
|
-
|
7904
|
+
throw new FuelError17(
|
7905
|
+
ErrorCode17.INVALID_MNEMONIC,
|
7608
7906
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7609
7907
|
);
|
7610
7908
|
}
|
@@ -7620,8 +7918,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7620
7918
|
const checksumMask = getUpperMask(checksumBits);
|
7621
7919
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7622
7920
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7623
|
-
throw new
|
7624
|
-
|
7921
|
+
throw new FuelError17(
|
7922
|
+
ErrorCode17.INVALID_CHECKSUM,
|
7625
7923
|
"Checksum validation failed for the provided mnemonic."
|
7626
7924
|
);
|
7627
7925
|
}
|
@@ -7635,16 +7933,16 @@ var TestnetPRV = "0x04358394";
|
|
7635
7933
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7636
7934
|
function assertWordList(wordlist) {
|
7637
7935
|
if (wordlist.length !== 2048) {
|
7638
|
-
throw new
|
7639
|
-
|
7936
|
+
throw new FuelError18(
|
7937
|
+
ErrorCode18.INVALID_WORD_LIST,
|
7640
7938
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7641
7939
|
);
|
7642
7940
|
}
|
7643
7941
|
}
|
7644
7942
|
function assertEntropy(entropy) {
|
7645
7943
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7646
|
-
throw new
|
7647
|
-
|
7944
|
+
throw new FuelError18(
|
7945
|
+
ErrorCode18.INVALID_ENTROPY,
|
7648
7946
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7649
7947
|
);
|
7650
7948
|
}
|
@@ -7654,7 +7952,7 @@ function assertMnemonic(words) {
|
|
7654
7952
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7655
7953
|
", "
|
7656
7954
|
)}] words, but got ${words.length}.`;
|
7657
|
-
throw new
|
7955
|
+
throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
|
7658
7956
|
}
|
7659
7957
|
}
|
7660
7958
|
var Mnemonic = class {
|
@@ -7772,8 +8070,8 @@ var Mnemonic = class {
|
|
7772
8070
|
static masterKeysFromSeed(seed) {
|
7773
8071
|
const seedArray = arrayify17(seed);
|
7774
8072
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7775
|
-
throw new
|
7776
|
-
|
8073
|
+
throw new FuelError18(
|
8074
|
+
ErrorCode18.INVALID_SEED,
|
7777
8075
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7778
8076
|
);
|
7779
8077
|
}
|
@@ -7818,7 +8116,7 @@ var Mnemonic = class {
|
|
7818
8116
|
* @returns A randomly generated mnemonic
|
7819
8117
|
*/
|
7820
8118
|
static generate(size = 32, extraEntropy = "") {
|
7821
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
8119
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7822
8120
|
return Mnemonic.entropyToMnemonic(entropy);
|
7823
8121
|
}
|
7824
8122
|
};
|
@@ -7850,7 +8148,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7850
8148
|
function parsePath(path, depth = 0) {
|
7851
8149
|
const components = path.split("/");
|
7852
8150
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7853
|
-
throw new
|
8151
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path}`);
|
7854
8152
|
}
|
7855
8153
|
if (components[0] === "m") {
|
7856
8154
|
components.shift();
|
@@ -7879,8 +8177,8 @@ var HDWallet = class {
|
|
7879
8177
|
this.privateKey = hexlify17(config.privateKey);
|
7880
8178
|
} else {
|
7881
8179
|
if (!config.publicKey) {
|
7882
|
-
throw new
|
7883
|
-
|
8180
|
+
throw new FuelError19(
|
8181
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7884
8182
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7885
8183
|
);
|
7886
8184
|
}
|
@@ -7909,8 +8207,8 @@ var HDWallet = class {
|
|
7909
8207
|
const data = new Uint8Array(37);
|
7910
8208
|
if (index & HARDENED_INDEX) {
|
7911
8209
|
if (!privateKey) {
|
7912
|
-
throw new
|
7913
|
-
|
8210
|
+
throw new FuelError19(
|
8211
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7914
8212
|
"Cannot derive a hardened index without a private Key."
|
7915
8213
|
);
|
7916
8214
|
}
|
@@ -7924,7 +8222,7 @@ var HDWallet = class {
|
|
7924
8222
|
const IR = bytes.slice(32);
|
7925
8223
|
if (privateKey) {
|
7926
8224
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7927
|
-
const ki =
|
8225
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
7928
8226
|
return new HDWallet({
|
7929
8227
|
privateKey: ki,
|
7930
8228
|
chainCode: IR,
|
@@ -7962,8 +8260,8 @@ var HDWallet = class {
|
|
7962
8260
|
*/
|
7963
8261
|
toExtendedKey(isPublic = false, testnet = false) {
|
7964
8262
|
if (this.depth >= 256) {
|
7965
|
-
throw new
|
7966
|
-
|
8263
|
+
throw new FuelError19(
|
8264
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7967
8265
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7968
8266
|
);
|
7969
8267
|
}
|
@@ -7994,10 +8292,10 @@ var HDWallet = class {
|
|
7994
8292
|
const bytes = arrayify18(decoded);
|
7995
8293
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7996
8294
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7997
|
-
throw new
|
8295
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7998
8296
|
}
|
7999
8297
|
if (!validChecksum) {
|
8000
|
-
throw new
|
8298
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8001
8299
|
}
|
8002
8300
|
const depth = bytes[4];
|
8003
8301
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -8005,14 +8303,14 @@ var HDWallet = class {
|
|
8005
8303
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
8006
8304
|
const key = bytes.slice(45, 78);
|
8007
8305
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8008
|
-
throw new
|
8009
|
-
|
8306
|
+
throw new FuelError19(
|
8307
|
+
ErrorCode19.HD_WALLET_ERROR,
|
8010
8308
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
8011
8309
|
);
|
8012
8310
|
}
|
8013
8311
|
if (isPublicExtendedKey(bytes)) {
|
8014
8312
|
if (key[0] !== 3) {
|
8015
|
-
throw new
|
8313
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
|
8016
8314
|
}
|
8017
8315
|
return new HDWallet({
|
8018
8316
|
publicKey: key,
|
@@ -8023,7 +8321,7 @@ var HDWallet = class {
|
|
8023
8321
|
});
|
8024
8322
|
}
|
8025
8323
|
if (key[0] !== 0) {
|
8026
|
-
throw new
|
8324
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
|
8027
8325
|
}
|
8028
8326
|
return new HDWallet({
|
8029
8327
|
privateKey: key.slice(1),
|
@@ -8191,7 +8489,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8191
8489
|
// src/wallet-manager/wallet-manager.ts
|
8192
8490
|
import { Address as Address8 } from "@fuel-ts/address";
|
8193
8491
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
8194
|
-
import { ErrorCode as
|
8492
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError22 } from "@fuel-ts/errors";
|
8195
8493
|
import { EventEmitter } from "events";
|
8196
8494
|
|
8197
8495
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8214,7 +8512,7 @@ var MemoryStorage = class {
|
|
8214
8512
|
|
8215
8513
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8216
8514
|
import { Address as Address6 } from "@fuel-ts/address";
|
8217
|
-
import { ErrorCode as
|
8515
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8218
8516
|
var _secret;
|
8219
8517
|
var MnemonicVault = class {
|
8220
8518
|
constructor(options) {
|
@@ -8270,8 +8568,8 @@ var MnemonicVault = class {
|
|
8270
8568
|
}
|
8271
8569
|
numberOfAccounts += 1;
|
8272
8570
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8273
|
-
throw new
|
8274
|
-
|
8571
|
+
throw new FuelError20(
|
8572
|
+
ErrorCode20.WALLET_MANAGER_ERROR,
|
8275
8573
|
`Account with address '${address}' not found in derived wallets.`
|
8276
8574
|
);
|
8277
8575
|
}
|
@@ -8285,7 +8583,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8285
8583
|
|
8286
8584
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8287
8585
|
import { Address as Address7 } from "@fuel-ts/address";
|
8288
|
-
import { ErrorCode as
|
8586
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8289
8587
|
var _privateKeys;
|
8290
8588
|
var PrivateKeyVault = class {
|
8291
8589
|
/**
|
@@ -8326,8 +8624,8 @@ var PrivateKeyVault = class {
|
|
8326
8624
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
8327
8625
|
);
|
8328
8626
|
if (!privateKey) {
|
8329
|
-
throw new
|
8330
|
-
|
8627
|
+
throw new FuelError21(
|
8628
|
+
ErrorCode21.WALLET_MANAGER_ERROR,
|
8331
8629
|
`No private key found for address '${address}'.`
|
8332
8630
|
);
|
8333
8631
|
}
|
@@ -8351,7 +8649,7 @@ var ERROR_MESSAGES = {
|
|
8351
8649
|
};
|
8352
8650
|
function assert(condition, message) {
|
8353
8651
|
if (!condition) {
|
8354
|
-
throw new
|
8652
|
+
throw new FuelError22(ErrorCode22.WALLET_MANAGER_ERROR, message);
|
8355
8653
|
}
|
8356
8654
|
}
|
8357
8655
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8577,25 +8875,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8577
8875
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8578
8876
|
|
8579
8877
|
// src/wallet-manager/types.ts
|
8580
|
-
import { ErrorCode as
|
8878
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8581
8879
|
var Vault = class {
|
8582
8880
|
constructor(_options) {
|
8583
|
-
throw new
|
8881
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8584
8882
|
}
|
8585
8883
|
serialize() {
|
8586
|
-
throw new
|
8884
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8587
8885
|
}
|
8588
8886
|
getAccounts() {
|
8589
|
-
throw new
|
8887
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8590
8888
|
}
|
8591
8889
|
addAccount() {
|
8592
|
-
throw new
|
8890
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8593
8891
|
}
|
8594
8892
|
exportAccount(_address) {
|
8595
|
-
throw new
|
8893
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8596
8894
|
}
|
8597
8895
|
getWallet(_address) {
|
8598
|
-
throw new
|
8896
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8599
8897
|
}
|
8600
8898
|
};
|
8601
8899
|
__publicField(Vault, "type");
|
@@ -8611,8 +8909,9 @@ import {
|
|
8611
8909
|
SCRIPT_FIXED_SIZE
|
8612
8910
|
} from "@fuel-ts/abi-coder";
|
8613
8911
|
import { Address as Address9 } from "@fuel-ts/address";
|
8614
|
-
import {
|
8615
|
-
import {
|
8912
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8913
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8914
|
+
import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
|
8616
8915
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8617
8916
|
|
8618
8917
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -8661,6 +8960,7 @@ var Predicate = class extends Account {
|
|
8661
8960
|
this.interface = predicateInterface;
|
8662
8961
|
if (inputData !== void 0 && inputData.length > 0) {
|
8663
8962
|
this.predicateData = inputData;
|
8963
|
+
this.predicateDataBytes = this.getPredicateData(0);
|
8664
8964
|
}
|
8665
8965
|
}
|
8666
8966
|
/**
|
@@ -8673,9 +8973,9 @@ var Predicate = class extends Account {
|
|
8673
8973
|
const request = transactionRequestify(transactionRequestLike);
|
8674
8974
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8675
8975
|
request.inputs?.forEach((input) => {
|
8676
|
-
if (input.type ===
|
8677
|
-
input.predicate = this.bytes;
|
8678
|
-
input.predicateData = this.getPredicateData(policies.length);
|
8976
|
+
if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
8977
|
+
input.predicate = hexlify19(this.bytes);
|
8978
|
+
input.predicateData = hexlify19(this.getPredicateData(policies.length));
|
8679
8979
|
}
|
8680
8980
|
});
|
8681
8981
|
return request;
|
@@ -8689,10 +8989,8 @@ var Predicate = class extends Account {
|
|
8689
8989
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8690
8990
|
* @returns A promise that resolves to the prepared transaction request.
|
8691
8991
|
*/
|
8692
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8693
|
-
|
8694
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8695
|
-
return this.populateTransactionPredicateData(request);
|
8992
|
+
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
8993
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8696
8994
|
}
|
8697
8995
|
/**
|
8698
8996
|
* Sends a transaction with the populated predicate data.
|
@@ -8700,9 +8998,9 @@ var Predicate = class extends Account {
|
|
8700
8998
|
* @param transactionRequestLike - The transaction request-like object.
|
8701
8999
|
* @returns A promise that resolves to the transaction response.
|
8702
9000
|
*/
|
8703
|
-
sendTransaction(transactionRequestLike
|
8704
|
-
const transactionRequest =
|
8705
|
-
return super.sendTransaction(transactionRequest,
|
9001
|
+
sendTransaction(transactionRequestLike) {
|
9002
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9003
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8706
9004
|
}
|
8707
9005
|
/**
|
8708
9006
|
* Simulates a transaction with the populated predicate data.
|
@@ -8711,8 +9009,8 @@ var Predicate = class extends Account {
|
|
8711
9009
|
* @returns A promise that resolves to the call result.
|
8712
9010
|
*/
|
8713
9011
|
simulateTransaction(transactionRequestLike) {
|
8714
|
-
const transactionRequest =
|
8715
|
-
return super.simulateTransaction(transactionRequest);
|
9012
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9013
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8716
9014
|
}
|
8717
9015
|
getPredicateData(policiesLength) {
|
8718
9016
|
if (!this.predicateData.length) {
|
@@ -8740,8 +9038,8 @@ var Predicate = class extends Account {
|
|
8740
9038
|
if (jsonAbi) {
|
8741
9039
|
abiInterface = new Interface4(jsonAbi);
|
8742
9040
|
if (abiInterface.functions.main === void 0) {
|
8743
|
-
throw new
|
8744
|
-
|
9041
|
+
throw new FuelError24(
|
9042
|
+
ErrorCode24.ABI_MAIN_METHOD_MISSING,
|
8745
9043
|
'Cannot use ABI without "main" function.'
|
8746
9044
|
);
|
8747
9045
|
}
|
@@ -8758,6 +9056,26 @@ var Predicate = class extends Account {
|
|
8758
9056
|
predicateInterface: abiInterface
|
8759
9057
|
};
|
8760
9058
|
}
|
9059
|
+
/**
|
9060
|
+
* Retrieves resources satisfying the spend query for the account.
|
9061
|
+
*
|
9062
|
+
* @param quantities - IDs of coins to exclude.
|
9063
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9064
|
+
* @returns A promise that resolves to an array of Resources.
|
9065
|
+
*/
|
9066
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9067
|
+
const resources = await this.provider.getResourcesToSpend(
|
9068
|
+
this.address,
|
9069
|
+
quantities,
|
9070
|
+
excludedIds
|
9071
|
+
);
|
9072
|
+
return resources.map((resource) => ({
|
9073
|
+
...resource,
|
9074
|
+
predicate: hexlify19(this.bytes),
|
9075
|
+
predicateData: hexlify19(this.predicateDataBytes),
|
9076
|
+
paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9077
|
+
}));
|
9078
|
+
}
|
8761
9079
|
/**
|
8762
9080
|
* Sets the configurable constants for the predicate.
|
8763
9081
|
*
|
@@ -8786,8 +9104,8 @@ var Predicate = class extends Account {
|
|
8786
9104
|
mutatedBytes.set(encoded, offset);
|
8787
9105
|
});
|
8788
9106
|
} catch (err) {
|
8789
|
-
throw new
|
8790
|
-
|
9107
|
+
throw new FuelError24(
|
9108
|
+
ErrorCode24.INVALID_CONFIGURABLE_CONSTANTS,
|
8791
9109
|
`Error setting configurable constants: ${err.message}.`
|
8792
9110
|
);
|
8793
9111
|
}
|
@@ -8796,7 +9114,7 @@ var Predicate = class extends Account {
|
|
8796
9114
|
};
|
8797
9115
|
|
8798
9116
|
// src/connectors/fuel.ts
|
8799
|
-
import { ErrorCode as
|
9117
|
+
import { ErrorCode as ErrorCode25, FuelError as FuelError25 } from "@fuel-ts/errors";
|
8800
9118
|
|
8801
9119
|
// src/connectors/fuel-connector.ts
|
8802
9120
|
import { EventEmitter as EventEmitter2 } from "events";
|
@@ -9429,7 +9747,7 @@ var _Fuel = class extends FuelConnector {
|
|
9429
9747
|
const currentNetwork = await this.currentNetwork();
|
9430
9748
|
provider = await Provider.create(currentNetwork.url);
|
9431
9749
|
} else {
|
9432
|
-
throw new
|
9750
|
+
throw new FuelError25(ErrorCode25.INVALID_PROVIDER, "Provider is not valid.");
|
9433
9751
|
}
|
9434
9752
|
return provider;
|
9435
9753
|
}
|
@@ -9506,16 +9824,19 @@ export {
|
|
9506
9824
|
WalletLocked,
|
9507
9825
|
WalletManager,
|
9508
9826
|
WalletUnlocked,
|
9509
|
-
|
9827
|
+
addAmountToCoinQuantities,
|
9510
9828
|
addOperation,
|
9829
|
+
assemblePanicError,
|
9511
9830
|
assembleReceiptByType,
|
9831
|
+
assembleRevertError,
|
9512
9832
|
assembleTransactionSummary,
|
9513
9833
|
assets,
|
9514
9834
|
buildBlockExplorerUrl,
|
9515
9835
|
cacheFor,
|
9836
|
+
cacheTxInputsFromOwner,
|
9837
|
+
calculateGasFee,
|
9516
9838
|
calculateMetadataGasForTxCreate,
|
9517
9839
|
calculateMetadataGasForTxScript,
|
9518
|
-
calculatePriceWithFactor,
|
9519
9840
|
calculateTransactionFee,
|
9520
9841
|
coinQuantityfy,
|
9521
9842
|
deferPromise,
|
@@ -9523,6 +9844,7 @@ export {
|
|
9523
9844
|
english,
|
9524
9845
|
extractBurnedAssetsFromReceipts,
|
9525
9846
|
extractMintedAssetsFromReceipts,
|
9847
|
+
extractTxError,
|
9526
9848
|
gasUsedByInputs,
|
9527
9849
|
getAssetEth,
|
9528
9850
|
getAssetFuel,
|