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