@fuel-ts/account 0.0.0-rc-2021-20240410132122 → 0.0.0-rc-1976-20240410141707
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 +615 -871
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +609 -851
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +452 -693
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -11
- 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 +1116 -1585
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +606 -826
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +464 -684
- 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
|
},
|
@@ -984,14 +925,11 @@ var _FuelGraphqlSubscriber = class {
|
|
984
925
|
let data;
|
985
926
|
let errors;
|
986
927
|
try {
|
987
|
-
|
988
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
928
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
989
929
|
} catch (e) {
|
990
930
|
throw new FuelError(
|
991
931
|
ErrorCode.STREAM_PARSING_ERROR,
|
992
|
-
`Error while parsing stream data response: ${text}
|
993
|
-
|
994
|
-
Thrown error: ${e}`
|
932
|
+
`Error while parsing stream data response: ${text}`
|
995
933
|
);
|
996
934
|
}
|
997
935
|
if (Array.isArray(errors)) {
|
@@ -1092,7 +1030,7 @@ var inputify = (value) => {
|
|
1092
1030
|
return {
|
1093
1031
|
type: InputType.Coin,
|
1094
1032
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1095
|
-
outputIndex:
|
1033
|
+
outputIndex: arrayify(value.id)[32],
|
1096
1034
|
owner: hexlify3(value.owner),
|
1097
1035
|
amount: bn2(value.amount),
|
1098
1036
|
assetId: hexlify3(value.assetId),
|
@@ -1101,9 +1039,10 @@ var inputify = (value) => {
|
|
1101
1039
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1102
1040
|
},
|
1103
1041
|
witnessIndex: value.witnessIndex,
|
1042
|
+
maturity: value.maturity ?? 0,
|
1104
1043
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1105
|
-
predicateLength:
|
1106
|
-
predicateDataLength:
|
1044
|
+
predicateLength: predicate.length,
|
1045
|
+
predicateDataLength: predicateData.length,
|
1107
1046
|
predicate: hexlify3(predicate),
|
1108
1047
|
predicateData: hexlify3(predicateData)
|
1109
1048
|
};
|
@@ -1134,8 +1073,8 @@ var inputify = (value) => {
|
|
1134
1073
|
nonce: hexlify3(value.nonce),
|
1135
1074
|
witnessIndex: value.witnessIndex,
|
1136
1075
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1137
|
-
predicateLength:
|
1138
|
-
predicateDataLength:
|
1076
|
+
predicateLength: predicate.length,
|
1077
|
+
predicateDataLength: predicateData.length,
|
1139
1078
|
predicate: hexlify3(predicate),
|
1140
1079
|
predicateData: hexlify3(predicateData),
|
1141
1080
|
data: hexlify3(data),
|
@@ -1210,7 +1149,7 @@ var outputify = (value) => {
|
|
1210
1149
|
|
1211
1150
|
// src/providers/transaction-request/transaction-request.ts
|
1212
1151
|
import { Address, addressify } from "@fuel-ts/address";
|
1213
|
-
import {
|
1152
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1214
1153
|
import { bn as bn7 } from "@fuel-ts/math";
|
1215
1154
|
import {
|
1216
1155
|
PolicyType,
|
@@ -1220,7 +1159,6 @@ import {
|
|
1220
1159
|
TransactionType
|
1221
1160
|
} from "@fuel-ts/transactions";
|
1222
1161
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1223
|
-
import { randomBytes } from "ethers";
|
1224
1162
|
|
1225
1163
|
// src/providers/resource.ts
|
1226
1164
|
var isCoin = (resource) => "id" in resource;
|
@@ -1261,8 +1199,8 @@ function assembleReceiptByType(receipt) {
|
|
1261
1199
|
case "CALL" /* Call */: {
|
1262
1200
|
const callReceipt = {
|
1263
1201
|
type: ReceiptType.Call,
|
1264
|
-
from: hexOrZero(receipt.id
|
1265
|
-
to: hexOrZero(receipt?.to),
|
1202
|
+
from: hexOrZero(receipt.contract?.id),
|
1203
|
+
to: hexOrZero(receipt?.to?.id),
|
1266
1204
|
amount: bn4(receipt.amount),
|
1267
1205
|
assetId: hexOrZero(receipt.assetId),
|
1268
1206
|
gas: bn4(receipt.gas),
|
@@ -1276,7 +1214,7 @@ function assembleReceiptByType(receipt) {
|
|
1276
1214
|
case "RETURN" /* Return */: {
|
1277
1215
|
const returnReceipt = {
|
1278
1216
|
type: ReceiptType.Return,
|
1279
|
-
id: hexOrZero(receipt.id
|
1217
|
+
id: hexOrZero(receipt.contract?.id),
|
1280
1218
|
val: bn4(receipt.val),
|
1281
1219
|
pc: bn4(receipt.pc),
|
1282
1220
|
is: bn4(receipt.is)
|
@@ -1286,7 +1224,7 @@ function assembleReceiptByType(receipt) {
|
|
1286
1224
|
case "RETURN_DATA" /* ReturnData */: {
|
1287
1225
|
const returnDataReceipt = {
|
1288
1226
|
type: ReceiptType.ReturnData,
|
1289
|
-
id: hexOrZero(receipt.id
|
1227
|
+
id: hexOrZero(receipt.contract?.id),
|
1290
1228
|
ptr: bn4(receipt.ptr),
|
1291
1229
|
len: bn4(receipt.len),
|
1292
1230
|
digest: hexOrZero(receipt.digest),
|
@@ -1298,7 +1236,7 @@ function assembleReceiptByType(receipt) {
|
|
1298
1236
|
case "PANIC" /* Panic */: {
|
1299
1237
|
const panicReceipt = {
|
1300
1238
|
type: ReceiptType.Panic,
|
1301
|
-
id: hexOrZero(receipt.id),
|
1239
|
+
id: hexOrZero(receipt.contract?.id),
|
1302
1240
|
reason: bn4(receipt.reason),
|
1303
1241
|
pc: bn4(receipt.pc),
|
1304
1242
|
is: bn4(receipt.is),
|
@@ -1309,7 +1247,7 @@ function assembleReceiptByType(receipt) {
|
|
1309
1247
|
case "REVERT" /* Revert */: {
|
1310
1248
|
const revertReceipt = {
|
1311
1249
|
type: ReceiptType.Revert,
|
1312
|
-
id: hexOrZero(receipt.id
|
1250
|
+
id: hexOrZero(receipt.contract?.id),
|
1313
1251
|
val: bn4(receipt.ra),
|
1314
1252
|
pc: bn4(receipt.pc),
|
1315
1253
|
is: bn4(receipt.is)
|
@@ -1319,7 +1257,7 @@ function assembleReceiptByType(receipt) {
|
|
1319
1257
|
case "LOG" /* Log */: {
|
1320
1258
|
const logReceipt = {
|
1321
1259
|
type: ReceiptType.Log,
|
1322
|
-
id: hexOrZero(receipt.id
|
1260
|
+
id: hexOrZero(receipt.contract?.id),
|
1323
1261
|
val0: bn4(receipt.ra),
|
1324
1262
|
val1: bn4(receipt.rb),
|
1325
1263
|
val2: bn4(receipt.rc),
|
@@ -1332,7 +1270,7 @@ function assembleReceiptByType(receipt) {
|
|
1332
1270
|
case "LOG_DATA" /* LogData */: {
|
1333
1271
|
const logDataReceipt = {
|
1334
1272
|
type: ReceiptType.LogData,
|
1335
|
-
id: hexOrZero(receipt.id
|
1273
|
+
id: hexOrZero(receipt.contract?.id),
|
1336
1274
|
val0: bn4(receipt.ra),
|
1337
1275
|
val1: bn4(receipt.rb),
|
1338
1276
|
ptr: bn4(receipt.ptr),
|
@@ -1346,8 +1284,8 @@ function assembleReceiptByType(receipt) {
|
|
1346
1284
|
case "TRANSFER" /* Transfer */: {
|
1347
1285
|
const transferReceipt = {
|
1348
1286
|
type: ReceiptType.Transfer,
|
1349
|
-
from: hexOrZero(receipt.id
|
1350
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1287
|
+
from: hexOrZero(receipt.contract?.id),
|
1288
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1351
1289
|
amount: bn4(receipt.amount),
|
1352
1290
|
assetId: hexOrZero(receipt.assetId),
|
1353
1291
|
pc: bn4(receipt.pc),
|
@@ -1358,8 +1296,8 @@ function assembleReceiptByType(receipt) {
|
|
1358
1296
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1359
1297
|
const transferOutReceipt = {
|
1360
1298
|
type: ReceiptType.TransferOut,
|
1361
|
-
from: hexOrZero(receipt.id
|
1362
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1299
|
+
from: hexOrZero(receipt.contract?.id),
|
1300
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1363
1301
|
amount: bn4(receipt.amount),
|
1364
1302
|
assetId: hexOrZero(receipt.assetId),
|
1365
1303
|
pc: bn4(receipt.pc),
|
@@ -1402,7 +1340,7 @@ function assembleReceiptByType(receipt) {
|
|
1402
1340
|
return receiptMessageOut;
|
1403
1341
|
}
|
1404
1342
|
case "MINT" /* Mint */: {
|
1405
|
-
const contractId = hexOrZero(receipt.id
|
1343
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1406
1344
|
const subId = hexOrZero(receipt.subId);
|
1407
1345
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1408
1346
|
const mintReceipt = {
|
@@ -1417,7 +1355,7 @@ function assembleReceiptByType(receipt) {
|
|
1417
1355
|
return mintReceipt;
|
1418
1356
|
}
|
1419
1357
|
case "BURN" /* Burn */: {
|
1420
|
-
const contractId = hexOrZero(receipt.id
|
1358
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1421
1359
|
const subId = hexOrZero(receipt.subId);
|
1422
1360
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1423
1361
|
const burnReceipt = {
|
@@ -1443,6 +1381,7 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
|
|
1443
1381
|
import { bn as bn5 } from "@fuel-ts/math";
|
1444
1382
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1445
1383
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1384
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1446
1385
|
var getGasUsedFromReceipts = (receipts) => {
|
1447
1386
|
const scriptResult = receipts.filter(
|
1448
1387
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1463,28 +1402,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1463
1402
|
}
|
1464
1403
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1465
1404
|
const witnessCache = [];
|
1466
|
-
const
|
1467
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1468
|
-
if (isCoinOrMessage) {
|
1469
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1470
|
-
return true;
|
1471
|
-
}
|
1472
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1473
|
-
witnessCache.push(input.witnessIndex);
|
1474
|
-
return true;
|
1475
|
-
}
|
1476
|
-
}
|
1477
|
-
return false;
|
1478
|
-
});
|
1479
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1480
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1405
|
+
const totalGas = inputs.reduce((total, input) => {
|
1481
1406
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1482
1407
|
return total.add(
|
1483
|
-
|
1408
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1484
1409
|
);
|
1485
1410
|
}
|
1486
|
-
|
1487
|
-
|
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());
|
1488
1417
|
return totalGas;
|
1489
1418
|
}
|
1490
1419
|
function getMinGas(params) {
|
@@ -1496,20 +1425,12 @@ function getMinGas(params) {
|
|
1496
1425
|
return minGas;
|
1497
1426
|
}
|
1498
1427
|
function getMaxGas(params) {
|
1499
|
-
const {
|
1500
|
-
gasPerByte,
|
1501
|
-
witnessesLength,
|
1502
|
-
witnessLimit,
|
1503
|
-
minGas,
|
1504
|
-
gasLimit = bn5(0),
|
1505
|
-
maxGasPerTx
|
1506
|
-
} = params;
|
1428
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1507
1429
|
let remainingAllowedWitnessGas = bn5(0);
|
1508
1430
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1509
1431
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1510
1432
|
}
|
1511
|
-
|
1512
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1433
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1513
1434
|
}
|
1514
1435
|
function calculateMetadataGasForTxCreate({
|
1515
1436
|
gasCosts,
|
@@ -1531,10 +1452,6 @@ function calculateMetadataGasForTxScript({
|
|
1531
1452
|
}) {
|
1532
1453
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1533
1454
|
}
|
1534
|
-
var calculateGasFee = (params) => {
|
1535
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1536
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1537
|
-
};
|
1538
1455
|
|
1539
1456
|
// src/providers/utils/json.ts
|
1540
1457
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1679,7 +1596,7 @@ var witnessify = (value) => {
|
|
1679
1596
|
// src/providers/transaction-request/transaction-request.ts
|
1680
1597
|
var BaseTransactionRequest = class {
|
1681
1598
|
/** Gas price for transaction */
|
1682
|
-
|
1599
|
+
gasPrice;
|
1683
1600
|
/** Block until which tx cannot be included */
|
1684
1601
|
maturity;
|
1685
1602
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1692,34 +1609,38 @@ var BaseTransactionRequest = class {
|
|
1692
1609
|
outputs = [];
|
1693
1610
|
/** List of witnesses */
|
1694
1611
|
witnesses = [];
|
1612
|
+
/** Base asset ID - should be fetched from the chain */
|
1613
|
+
baseAssetId = ZeroBytes324;
|
1695
1614
|
/**
|
1696
1615
|
* Constructor for initializing a base transaction request.
|
1697
1616
|
*
|
1698
1617
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1699
1618
|
*/
|
1700
1619
|
constructor({
|
1701
|
-
|
1620
|
+
gasPrice,
|
1702
1621
|
maturity,
|
1703
1622
|
maxFee,
|
1704
1623
|
witnessLimit,
|
1705
1624
|
inputs,
|
1706
1625
|
outputs,
|
1707
|
-
witnesses
|
1626
|
+
witnesses,
|
1627
|
+
baseAssetId
|
1708
1628
|
} = {}) {
|
1709
|
-
this.
|
1629
|
+
this.gasPrice = bn7(gasPrice);
|
1710
1630
|
this.maturity = maturity ?? 0;
|
1711
1631
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1712
1632
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1713
1633
|
this.inputs = inputs ?? [];
|
1714
1634
|
this.outputs = outputs ?? [];
|
1715
1635
|
this.witnesses = witnesses ?? [];
|
1636
|
+
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1716
1637
|
}
|
1717
1638
|
static getPolicyMeta(req) {
|
1718
1639
|
let policyTypes = 0;
|
1719
1640
|
const policies = [];
|
1720
|
-
if (req.
|
1721
|
-
policyTypes += PolicyType.
|
1722
|
-
policies.push({ data: req.
|
1641
|
+
if (req.gasPrice) {
|
1642
|
+
policyTypes += PolicyType.GasPrice;
|
1643
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1723
1644
|
}
|
1724
1645
|
if (req.witnessLimit) {
|
1725
1646
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1906,10 +1827,10 @@ var BaseTransactionRequest = class {
|
|
1906
1827
|
* @param predicate - Predicate bytes.
|
1907
1828
|
* @param predicateData - Predicate data bytes.
|
1908
1829
|
*/
|
1909
|
-
addCoinInput(coin) {
|
1830
|
+
addCoinInput(coin, predicate) {
|
1910
1831
|
const { assetId, owner, amount } = coin;
|
1911
1832
|
let witnessIndex;
|
1912
|
-
if (
|
1833
|
+
if (predicate) {
|
1913
1834
|
witnessIndex = 0;
|
1914
1835
|
} else {
|
1915
1836
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1924,7 +1845,8 @@ var BaseTransactionRequest = class {
|
|
1924
1845
|
amount,
|
1925
1846
|
assetId,
|
1926
1847
|
txPointer: "0x00000000000000000000000000000000",
|
1927
|
-
witnessIndex
|
1848
|
+
witnessIndex,
|
1849
|
+
predicate: predicate?.bytes
|
1928
1850
|
};
|
1929
1851
|
this.pushInput(input);
|
1930
1852
|
this.addChangeOutput(owner, assetId);
|
@@ -1935,13 +1857,11 @@ var BaseTransactionRequest = class {
|
|
1935
1857
|
*
|
1936
1858
|
* @param message - Message resource.
|
1937
1859
|
* @param predicate - Predicate bytes.
|
1938
|
-
* @param predicateData - Predicate data bytes.
|
1939
1860
|
*/
|
1940
|
-
addMessageInput(message) {
|
1861
|
+
addMessageInput(message, predicate) {
|
1941
1862
|
const { recipient, sender, amount } = message;
|
1942
|
-
const assetId = BaseAssetId2;
|
1943
1863
|
let witnessIndex;
|
1944
|
-
if (
|
1864
|
+
if (predicate) {
|
1945
1865
|
witnessIndex = 0;
|
1946
1866
|
} else {
|
1947
1867
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1955,10 +1875,11 @@ var BaseTransactionRequest = class {
|
|
1955
1875
|
sender: sender.toB256(),
|
1956
1876
|
recipient: recipient.toB256(),
|
1957
1877
|
amount,
|
1958
|
-
witnessIndex
|
1878
|
+
witnessIndex,
|
1879
|
+
predicate: predicate?.bytes
|
1959
1880
|
};
|
1960
1881
|
this.pushInput(input);
|
1961
|
-
this.addChangeOutput(recipient,
|
1882
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1962
1883
|
}
|
1963
1884
|
/**
|
1964
1885
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1986,6 +1907,32 @@ var BaseTransactionRequest = class {
|
|
1986
1907
|
resources.forEach((resource) => this.addResource(resource));
|
1987
1908
|
return this;
|
1988
1909
|
}
|
1910
|
+
/**
|
1911
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1912
|
+
* outputs from the related assetIds.
|
1913
|
+
*
|
1914
|
+
* @param resources - The resources to add.
|
1915
|
+
* @returns This transaction.
|
1916
|
+
*/
|
1917
|
+
addPredicateResource(resource, predicate) {
|
1918
|
+
if (isCoin(resource)) {
|
1919
|
+
this.addCoinInput(resource, predicate);
|
1920
|
+
} else {
|
1921
|
+
this.addMessageInput(resource, predicate);
|
1922
|
+
}
|
1923
|
+
return this;
|
1924
|
+
}
|
1925
|
+
/**
|
1926
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1927
|
+
* from the related assetIds.
|
1928
|
+
*
|
1929
|
+
* @param resources - The resources to add.
|
1930
|
+
* @returns This transaction.
|
1931
|
+
*/
|
1932
|
+
addPredicateResources(resources, predicate) {
|
1933
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1934
|
+
return this;
|
1935
|
+
}
|
1989
1936
|
/**
|
1990
1937
|
* Adds a coin output to the transaction.
|
1991
1938
|
*
|
@@ -1993,12 +1940,12 @@ var BaseTransactionRequest = class {
|
|
1993
1940
|
* @param amount - Amount of coin.
|
1994
1941
|
* @param assetId - Asset ID of coin.
|
1995
1942
|
*/
|
1996
|
-
addCoinOutput(to, amount, assetId
|
1943
|
+
addCoinOutput(to, amount, assetId) {
|
1997
1944
|
this.pushOutput({
|
1998
1945
|
type: OutputType2.Coin,
|
1999
1946
|
to: addressify(to).toB256(),
|
2000
1947
|
amount,
|
2001
|
-
assetId
|
1948
|
+
assetId: assetId ?? this.baseAssetId
|
2002
1949
|
});
|
2003
1950
|
return this;
|
2004
1951
|
}
|
@@ -2025,7 +1972,7 @@ var BaseTransactionRequest = class {
|
|
2025
1972
|
* @param to - Address of the owner.
|
2026
1973
|
* @param assetId - Asset ID of coin.
|
2027
1974
|
*/
|
2028
|
-
addChangeOutput(to, assetId
|
1975
|
+
addChangeOutput(to, assetId) {
|
2029
1976
|
const changeOutput = this.getChangeOutputs().find(
|
2030
1977
|
(output) => hexlify7(output.assetId) === assetId
|
2031
1978
|
);
|
@@ -2033,7 +1980,7 @@ var BaseTransactionRequest = class {
|
|
2033
1980
|
this.pushOutput({
|
2034
1981
|
type: OutputType2.Change,
|
2035
1982
|
to: addressify(to).toB256(),
|
2036
|
-
assetId
|
1983
|
+
assetId: assetId ?? this.baseAssetId
|
2037
1984
|
});
|
2038
1985
|
}
|
2039
1986
|
}
|
@@ -2065,7 +2012,7 @@ var BaseTransactionRequest = class {
|
|
2065
2012
|
}
|
2066
2013
|
calculateMaxGas(chainInfo, minGas) {
|
2067
2014
|
const { consensusParameters } = chainInfo;
|
2068
|
-
const { gasPerByte
|
2015
|
+
const { gasPerByte } = consensusParameters;
|
2069
2016
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2070
2017
|
(acc, wit) => acc + wit.dataLength,
|
2071
2018
|
0
|
@@ -2074,8 +2021,7 @@ var BaseTransactionRequest = class {
|
|
2074
2021
|
gasPerByte,
|
2075
2022
|
minGas,
|
2076
2023
|
witnessesLength,
|
2077
|
-
witnessLimit: this.witnessLimit
|
2078
|
-
maxGasPerTx
|
2024
|
+
witnessLimit: this.witnessLimit
|
2079
2025
|
});
|
2080
2026
|
}
|
2081
2027
|
/**
|
@@ -2085,6 +2031,12 @@ var BaseTransactionRequest = class {
|
|
2085
2031
|
* @param quantities - CoinQuantity Array.
|
2086
2032
|
*/
|
2087
2033
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2034
|
+
let idCounter = 0;
|
2035
|
+
const generateId = () => {
|
2036
|
+
const counterString = String(idCounter++);
|
2037
|
+
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2038
|
+
return id;
|
2039
|
+
};
|
2088
2040
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2089
2041
|
if ("assetId" in input) {
|
2090
2042
|
return input.assetId === assetId;
|
@@ -2093,27 +2045,24 @@ var BaseTransactionRequest = class {
|
|
2093
2045
|
});
|
2094
2046
|
const updateAssetInput = (assetId, quantity) => {
|
2095
2047
|
const assetInput = findAssetInput(assetId);
|
2096
|
-
let usedQuantity = quantity;
|
2097
|
-
if (assetId === BaseAssetId2) {
|
2098
|
-
usedQuantity = bn7("1000000000000000000");
|
2099
|
-
}
|
2100
2048
|
if (assetInput && "assetId" in assetInput) {
|
2101
|
-
assetInput.id =
|
2102
|
-
assetInput.amount =
|
2049
|
+
assetInput.id = generateId();
|
2050
|
+
assetInput.amount = quantity;
|
2103
2051
|
} else {
|
2104
2052
|
this.addResources([
|
2105
2053
|
{
|
2106
|
-
id:
|
2107
|
-
amount:
|
2054
|
+
id: generateId(),
|
2055
|
+
amount: quantity,
|
2108
2056
|
assetId,
|
2109
2057
|
owner: resourcesOwner || Address.fromRandom(),
|
2058
|
+
maturity: 0,
|
2110
2059
|
blockCreated: bn7(1),
|
2111
2060
|
txCreatedIdx: bn7(1)
|
2112
2061
|
}
|
2113
2062
|
]);
|
2114
2063
|
}
|
2115
2064
|
};
|
2116
|
-
updateAssetInput(
|
2065
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2117
2066
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2118
2067
|
}
|
2119
2068
|
/**
|
@@ -2138,7 +2087,7 @@ var BaseTransactionRequest = class {
|
|
2138
2087
|
toJSON() {
|
2139
2088
|
return normalizeJSON(this);
|
2140
2089
|
}
|
2141
|
-
|
2090
|
+
updatePredicateInputs(inputs) {
|
2142
2091
|
this.inputs.forEach((i) => {
|
2143
2092
|
let correspondingInput;
|
2144
2093
|
switch (i.type) {
|
@@ -2160,15 +2109,6 @@ var BaseTransactionRequest = class {
|
|
2160
2109
|
}
|
2161
2110
|
});
|
2162
2111
|
}
|
2163
|
-
shiftPredicateData() {
|
2164
|
-
this.inputs.forEach((input) => {
|
2165
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2166
|
-
input.predicateData = input.paddPredicateData(
|
2167
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2168
|
-
);
|
2169
|
-
}
|
2170
|
-
});
|
2171
|
-
}
|
2172
2112
|
};
|
2173
2113
|
|
2174
2114
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2315,8 +2255,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2315
2255
|
return {
|
2316
2256
|
type: TransactionType3.Create,
|
2317
2257
|
...baseTransaction,
|
2258
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2318
2259
|
bytecodeWitnessIndex,
|
2319
|
-
storageSlotsCount:
|
2260
|
+
storageSlotsCount: storageSlots.length,
|
2320
2261
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2321
2262
|
storageSlots
|
2322
2263
|
};
|
@@ -2439,8 +2380,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2439
2380
|
type: TransactionType4.Script,
|
2440
2381
|
scriptGasLimit: this.gasLimit,
|
2441
2382
|
...super.getBaseTransaction(),
|
2442
|
-
scriptLength:
|
2443
|
-
scriptDataLength:
|
2383
|
+
scriptLength: script.length,
|
2384
|
+
scriptDataLength: scriptData.length,
|
2444
2385
|
receiptsRoot: ZeroBytes327,
|
2445
2386
|
script: hexlify10(script),
|
2446
2387
|
scriptData: hexlify10(scriptData)
|
@@ -2504,7 +2445,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2504
2445
|
}
|
2505
2446
|
calculateMaxGas(chainInfo, minGas) {
|
2506
2447
|
const { consensusParameters } = chainInfo;
|
2507
|
-
const { gasPerByte
|
2448
|
+
const { gasPerByte } = consensusParameters;
|
2508
2449
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2509
2450
|
(acc, wit) => acc + wit.dataLength,
|
2510
2451
|
0
|
@@ -2514,8 +2455,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2514
2455
|
minGas,
|
2515
2456
|
witnessesLength,
|
2516
2457
|
witnessLimit: this.witnessLimit,
|
2517
|
-
gasLimit: this.gasLimit
|
2518
|
-
maxGasPerTx
|
2458
|
+
gasLimit: this.gasLimit
|
2519
2459
|
});
|
2520
2460
|
}
|
2521
2461
|
/**
|
@@ -2572,7 +2512,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2572
2512
|
|
2573
2513
|
// src/providers/transaction-request/utils.ts
|
2574
2514
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2575
|
-
import { TransactionType as TransactionType5
|
2515
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2576
2516
|
var transactionRequestify = (obj) => {
|
2577
2517
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2578
2518
|
return obj;
|
@@ -2590,31 +2530,14 @@ var transactionRequestify = (obj) => {
|
|
2590
2530
|
}
|
2591
2531
|
}
|
2592
2532
|
};
|
2593
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2594
|
-
(acc, input) => {
|
2595
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2596
|
-
acc.utxos.push(input.id);
|
2597
|
-
}
|
2598
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2599
|
-
acc.messages.push(input.nonce);
|
2600
|
-
}
|
2601
|
-
return acc;
|
2602
|
-
},
|
2603
|
-
{
|
2604
|
-
utxos: [],
|
2605
|
-
messages: []
|
2606
|
-
}
|
2607
|
-
);
|
2608
2533
|
|
2609
2534
|
// src/providers/transaction-response/transaction-response.ts
|
2610
2535
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2611
|
-
import { bn as
|
2536
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2612
2537
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2613
2538
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2614
2539
|
|
2615
2540
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2616
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2617
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2618
2541
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2619
2542
|
|
2620
2543
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2623,10 +2546,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2623
2546
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2624
2547
|
var calculateTransactionFee = (params) => {
|
2625
2548
|
const {
|
2626
|
-
|
2549
|
+
gasUsed,
|
2627
2550
|
rawPayload,
|
2628
|
-
|
2629
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2551
|
+
consensusParameters: { gasCosts, feeParams }
|
2630
2552
|
} = params;
|
2631
2553
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2632
2554
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2636,7 +2558,8 @@ var calculateTransactionFee = (params) => {
|
|
2636
2558
|
return {
|
2637
2559
|
fee: bn11(0),
|
2638
2560
|
minFee: bn11(0),
|
2639
|
-
maxFee: bn11(0)
|
2561
|
+
maxFee: bn11(0),
|
2562
|
+
feeFromGasUsed: bn11(0)
|
2640
2563
|
};
|
2641
2564
|
}
|
2642
2565
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2668,6 +2591,7 @@ var calculateTransactionFee = (params) => {
|
|
2668
2591
|
metadataGas,
|
2669
2592
|
txBytesSize: transactionBytes.length
|
2670
2593
|
});
|
2594
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2671
2595
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2672
2596
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2673
2597
|
const maxGas = getMaxGas({
|
@@ -2675,25 +2599,17 @@ var calculateTransactionFee = (params) => {
|
|
2675
2599
|
minGas,
|
2676
2600
|
witnessesLength,
|
2677
2601
|
gasLimit,
|
2678
|
-
witnessLimit
|
2679
|
-
maxGasPerTx
|
2680
|
-
});
|
2681
|
-
const minFee = calculateGasFee({
|
2682
|
-
gasPrice,
|
2683
|
-
gas: minGas,
|
2684
|
-
priceFactor: gasPriceFactor,
|
2685
|
-
tip
|
2686
|
-
});
|
2687
|
-
const maxFee = calculateGasFee({
|
2688
|
-
gasPrice,
|
2689
|
-
gas: maxGas,
|
2690
|
-
priceFactor: gasPriceFactor,
|
2691
|
-
tip
|
2602
|
+
witnessLimit
|
2692
2603
|
});
|
2604
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2605
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2606
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2607
|
+
const fee = minFee.add(feeFromGasUsed);
|
2693
2608
|
return {
|
2609
|
+
fee,
|
2694
2610
|
minFee,
|
2695
2611
|
maxFee,
|
2696
|
-
|
2612
|
+
feeFromGasUsed
|
2697
2613
|
};
|
2698
2614
|
};
|
2699
2615
|
|
@@ -2749,7 +2665,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2749
2665
|
|
2750
2666
|
// src/providers/transaction-summary/input.ts
|
2751
2667
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2752
|
-
import { InputType as
|
2668
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2753
2669
|
function getInputsByTypes(inputs, types) {
|
2754
2670
|
return inputs.filter((i) => types.includes(i.type));
|
2755
2671
|
}
|
@@ -2757,16 +2673,16 @@ function getInputsByType(inputs, type) {
|
|
2757
2673
|
return inputs.filter((i) => i.type === type);
|
2758
2674
|
}
|
2759
2675
|
function getInputsCoin(inputs) {
|
2760
|
-
return getInputsByType(inputs,
|
2676
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2761
2677
|
}
|
2762
2678
|
function getInputsMessage(inputs) {
|
2763
|
-
return getInputsByType(inputs,
|
2679
|
+
return getInputsByType(inputs, InputType5.Message);
|
2764
2680
|
}
|
2765
2681
|
function getInputsCoinAndMessage(inputs) {
|
2766
|
-
return getInputsByTypes(inputs, [
|
2682
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2767
2683
|
}
|
2768
2684
|
function getInputsContract(inputs) {
|
2769
|
-
return getInputsByType(inputs,
|
2685
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2770
2686
|
}
|
2771
2687
|
function getInputFromAssetId(inputs, assetId) {
|
2772
2688
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2785,7 +2701,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2785
2701
|
if (!contractInput) {
|
2786
2702
|
return void 0;
|
2787
2703
|
}
|
2788
|
-
if (contractInput.type !==
|
2704
|
+
if (contractInput.type !== InputType5.Contract) {
|
2789
2705
|
throw new FuelError9(
|
2790
2706
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2791
2707
|
`Contract input should be of type 'contract'.`
|
@@ -2794,10 +2710,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2794
2710
|
return contractInput;
|
2795
2711
|
}
|
2796
2712
|
function getInputAccountAddress(input) {
|
2797
|
-
if (input.type ===
|
2713
|
+
if (input.type === InputType5.Coin) {
|
2798
2714
|
return input.owner.toString();
|
2799
2715
|
}
|
2800
|
-
if (input.type ===
|
2716
|
+
if (input.type === InputType5.Message) {
|
2801
2717
|
return input.recipient.toString();
|
2802
2718
|
}
|
2803
2719
|
return "";
|
@@ -3260,9 +3176,7 @@ function assembleTransactionSummary(params) {
|
|
3260
3176
|
gqlTransactionStatus,
|
3261
3177
|
abiMap = {},
|
3262
3178
|
maxInputs,
|
3263
|
-
gasCosts
|
3264
|
-
maxGasPerTx,
|
3265
|
-
gasPrice
|
3179
|
+
gasCosts
|
3266
3180
|
} = params;
|
3267
3181
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3268
3182
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3276,14 +3190,11 @@ function assembleTransactionSummary(params) {
|
|
3276
3190
|
maxInputs
|
3277
3191
|
});
|
3278
3192
|
const typeName = getTransactionTypeName(transaction.type);
|
3279
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3280
3193
|
const { fee } = calculateTransactionFee({
|
3281
|
-
|
3194
|
+
gasUsed,
|
3282
3195
|
rawPayload,
|
3283
|
-
tip,
|
3284
3196
|
consensusParameters: {
|
3285
3197
|
gasCosts,
|
3286
|
-
maxGasPerTx,
|
3287
3198
|
feeParams: {
|
3288
3199
|
gasPerByte,
|
3289
3200
|
gasPriceFactor
|
@@ -3343,7 +3254,7 @@ var TransactionResponse = class {
|
|
3343
3254
|
/** Current provider */
|
3344
3255
|
provider;
|
3345
3256
|
/** Gas used on the transaction */
|
3346
|
-
gasUsed =
|
3257
|
+
gasUsed = bn14(0);
|
3347
3258
|
/** The graphql Transaction with receipts object. */
|
3348
3259
|
gqlTransaction;
|
3349
3260
|
abis;
|
@@ -3421,13 +3332,8 @@ var TransactionResponse = class {
|
|
3421
3332
|
const decodedTransaction = this.decodeTransaction(
|
3422
3333
|
transaction
|
3423
3334
|
);
|
3424
|
-
|
3425
|
-
|
3426
|
-
txReceipts = transaction.status.receipts;
|
3427
|
-
}
|
3428
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3429
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3430
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3335
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3336
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3431
3337
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3432
3338
|
const transactionSummary = assembleTransactionSummary({
|
3433
3339
|
id: this.id,
|
@@ -3439,9 +3345,7 @@ var TransactionResponse = class {
|
|
3439
3345
|
gasPriceFactor,
|
3440
3346
|
abiMap: contractsAbiMap,
|
3441
3347
|
maxInputs,
|
3442
|
-
gasCosts
|
3443
|
-
maxGasPerTx,
|
3444
|
-
gasPrice
|
3348
|
+
gasCosts
|
3445
3349
|
});
|
3446
3350
|
return transactionSummary;
|
3447
3351
|
}
|
@@ -3568,29 +3472,30 @@ var processGqlChain = (chain) => {
|
|
3568
3472
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3569
3473
|
return {
|
3570
3474
|
name,
|
3571
|
-
baseChainHeight:
|
3475
|
+
baseChainHeight: bn15(daHeight),
|
3572
3476
|
consensusParameters: {
|
3573
|
-
contractMaxSize:
|
3574
|
-
maxInputs:
|
3575
|
-
maxOutputs:
|
3576
|
-
maxWitnesses:
|
3577
|
-
maxGasPerTx:
|
3578
|
-
maxScriptLength:
|
3579
|
-
maxScriptDataLength:
|
3580
|
-
maxStorageSlots:
|
3581
|
-
maxPredicateLength:
|
3582
|
-
maxPredicateDataLength:
|
3583
|
-
maxGasPerPredicate:
|
3584
|
-
gasPriceFactor:
|
3585
|
-
gasPerByte:
|
3586
|
-
maxMessageDataLength:
|
3587
|
-
chainId:
|
3477
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3478
|
+
maxInputs: bn15(txParams.maxInputs),
|
3479
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3480
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3481
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3482
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3483
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3484
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3485
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3486
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3487
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3488
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3489
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3490
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3491
|
+
chainId: bn15(consensusParameters.chainId),
|
3492
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3588
3493
|
gasCosts
|
3589
3494
|
},
|
3590
3495
|
gasCosts,
|
3591
3496
|
latestBlock: {
|
3592
3497
|
id: latestBlock.id,
|
3593
|
-
height:
|
3498
|
+
height: bn15(latestBlock.header.height),
|
3594
3499
|
time: latestBlock.header.time,
|
3595
3500
|
transactions: latestBlock.transactions.map((i) => ({
|
3596
3501
|
id: i.id
|
@@ -3684,8 +3589,10 @@ var _Provider = class {
|
|
3684
3589
|
* Returns some helpful parameters related to gas fees.
|
3685
3590
|
*/
|
3686
3591
|
getGasConfig() {
|
3592
|
+
const { minGasPrice } = this.getNode();
|
3687
3593
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3688
3594
|
return {
|
3595
|
+
minGasPrice,
|
3689
3596
|
maxGasPerTx,
|
3690
3597
|
maxGasPerPredicate,
|
3691
3598
|
gasPriceFactor,
|
@@ -3783,7 +3690,7 @@ var _Provider = class {
|
|
3783
3690
|
*/
|
3784
3691
|
async getBlockNumber() {
|
3785
3692
|
const { chain } = await this.operations.getChain();
|
3786
|
-
return
|
3693
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3787
3694
|
}
|
3788
3695
|
/**
|
3789
3696
|
* Returns the chain information.
|
@@ -3793,11 +3700,13 @@ var _Provider = class {
|
|
3793
3700
|
async fetchNode() {
|
3794
3701
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3795
3702
|
const processedNodeInfo = {
|
3796
|
-
maxDepth:
|
3797
|
-
maxTx:
|
3703
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3704
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3705
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3798
3706
|
nodeVersion: nodeInfo.nodeVersion,
|
3799
3707
|
utxoValidation: nodeInfo.utxoValidation,
|
3800
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3708
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3709
|
+
peers: nodeInfo.peers
|
3801
3710
|
};
|
3802
3711
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3803
3712
|
return processedNodeInfo;
|
@@ -3823,6 +3732,17 @@ var _Provider = class {
|
|
3823
3732
|
} = this.getChain();
|
3824
3733
|
return chainId.toNumber();
|
3825
3734
|
}
|
3735
|
+
/**
|
3736
|
+
* Returns the base asset ID
|
3737
|
+
*
|
3738
|
+
* @returns A promise that resolves to the base asset ID
|
3739
|
+
*/
|
3740
|
+
getBaseAssetId() {
|
3741
|
+
const {
|
3742
|
+
consensusParameters: { baseAssetId }
|
3743
|
+
} = this.getChain();
|
3744
|
+
return baseAssetId;
|
3745
|
+
}
|
3826
3746
|
/**
|
3827
3747
|
* Submits a transaction to the chain to be executed.
|
3828
3748
|
*
|
@@ -3883,13 +3803,14 @@ var _Provider = class {
|
|
3883
3803
|
return this.estimateTxDependencies(transactionRequest);
|
3884
3804
|
}
|
3885
3805
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3886
|
-
const { dryRun:
|
3887
|
-
|
3806
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3807
|
+
encodedTransaction,
|
3888
3808
|
utxoValidation: utxoValidation || false
|
3889
3809
|
});
|
3890
|
-
const
|
3891
|
-
|
3892
|
-
|
3810
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3811
|
+
return {
|
3812
|
+
receipts
|
3813
|
+
};
|
3893
3814
|
}
|
3894
3815
|
/**
|
3895
3816
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3915,7 +3836,7 @@ var _Provider = class {
|
|
3915
3836
|
} = response;
|
3916
3837
|
if (inputs) {
|
3917
3838
|
inputs.forEach((input, index) => {
|
3918
|
-
if ("predicateGasUsed" in input &&
|
3839
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3919
3840
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3920
3841
|
}
|
3921
3842
|
});
|
@@ -3928,6 +3849,9 @@ var _Provider = class {
|
|
3928
3849
|
* If there are missing variable outputs,
|
3929
3850
|
* `addVariableOutputs` is called on the transaction.
|
3930
3851
|
*
|
3852
|
+
* @privateRemarks
|
3853
|
+
* TODO: Investigate support for missing contract IDs
|
3854
|
+
* TODO: Add support for missing output messages
|
3931
3855
|
*
|
3932
3856
|
* @param transactionRequest - The transaction request object.
|
3933
3857
|
* @returns A promise.
|
@@ -3940,19 +3864,16 @@ var _Provider = class {
|
|
3940
3864
|
missingContractIds: []
|
3941
3865
|
};
|
3942
3866
|
}
|
3867
|
+
await this.estimatePredicates(transactionRequest);
|
3943
3868
|
let receipts = [];
|
3944
3869
|
const missingContractIds = [];
|
3945
3870
|
let outputVariables = 0;
|
3946
|
-
let dryrunStatus;
|
3947
3871
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3948
|
-
const {
|
3949
|
-
|
3950
|
-
} = await this.operations.dryRun({
|
3951
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3872
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3873
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3952
3874
|
utxoValidation: false
|
3953
3875
|
});
|
3954
|
-
receipts =
|
3955
|
-
dryrunStatus = status;
|
3876
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3956
3877
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3957
3878
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3958
3879
|
if (hasMissingOutputs) {
|
@@ -3962,11 +3883,6 @@ var _Provider = class {
|
|
3962
3883
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3963
3884
|
missingContractIds.push(contractId);
|
3964
3885
|
});
|
3965
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3966
|
-
transactionRequest,
|
3967
|
-
optimizeGas: false
|
3968
|
-
});
|
3969
|
-
transactionRequest.maxFee = maxFee;
|
3970
3886
|
} else {
|
3971
3887
|
break;
|
3972
3888
|
}
|
@@ -3974,133 +3890,7 @@ var _Provider = class {
|
|
3974
3890
|
return {
|
3975
3891
|
receipts,
|
3976
3892
|
outputVariables,
|
3977
|
-
missingContractIds
|
3978
|
-
dryrunStatus
|
3979
|
-
};
|
3980
|
-
}
|
3981
|
-
/**
|
3982
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3983
|
-
*
|
3984
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3985
|
-
* further modifications are identified. The method iteratively updates these transactions
|
3986
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
3987
|
-
*
|
3988
|
-
* @param transactionRequests - Array of transaction request objects.
|
3989
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
3990
|
-
*/
|
3991
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
3992
|
-
const results = transactionRequests.map(() => ({
|
3993
|
-
receipts: [],
|
3994
|
-
outputVariables: 0,
|
3995
|
-
missingContractIds: [],
|
3996
|
-
dryrunStatus: void 0
|
3997
|
-
}));
|
3998
|
-
const allRequests = clone3(transactionRequests);
|
3999
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4000
|
-
allRequests.forEach((req, index) => {
|
4001
|
-
if (req.type === TransactionType8.Script) {
|
4002
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4003
|
-
}
|
4004
|
-
});
|
4005
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4006
|
-
let attempt = 0;
|
4007
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4008
|
-
const encodedTransactions = transactionsToProcess.map(
|
4009
|
-
(index) => serializedTransactionsMap.get(index)
|
4010
|
-
);
|
4011
|
-
const dryRunResults = await this.operations.dryRun({
|
4012
|
-
encodedTransactions,
|
4013
|
-
utxoValidation: false
|
4014
|
-
});
|
4015
|
-
const nextRoundTransactions = [];
|
4016
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4017
|
-
const currentResultIndex = transactionsToProcess[i];
|
4018
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4019
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4020
|
-
results[currentResultIndex].dryrunStatus = status;
|
4021
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4022
|
-
results[currentResultIndex].receipts
|
4023
|
-
);
|
4024
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4025
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4026
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4027
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4028
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4029
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4030
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4031
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4032
|
-
});
|
4033
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4034
|
-
transactionRequest: requestToProcess,
|
4035
|
-
optimizeGas: false
|
4036
|
-
});
|
4037
|
-
requestToProcess.maxFee = maxFee;
|
4038
|
-
serializedTransactionsMap.set(
|
4039
|
-
currentResultIndex,
|
4040
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4041
|
-
);
|
4042
|
-
nextRoundTransactions.push(currentResultIndex);
|
4043
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4044
|
-
}
|
4045
|
-
}
|
4046
|
-
transactionsToProcess = nextRoundTransactions;
|
4047
|
-
attempt += 1;
|
4048
|
-
}
|
4049
|
-
return results;
|
4050
|
-
}
|
4051
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4052
|
-
if (estimateTxDependencies) {
|
4053
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4054
|
-
}
|
4055
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4056
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4057
|
-
encodedTransactions,
|
4058
|
-
utxoValidation: utxoValidation || false
|
4059
|
-
});
|
4060
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4061
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4062
|
-
return { receipts, dryrunStatus: status };
|
4063
|
-
});
|
4064
|
-
return results;
|
4065
|
-
}
|
4066
|
-
async estimateTxGasAndFee(params) {
|
4067
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4068
|
-
let { gasPrice } = params;
|
4069
|
-
const chainInfo = this.getChain();
|
4070
|
-
const { gasPriceFactor } = this.getGasConfig();
|
4071
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4072
|
-
if (!gasPrice) {
|
4073
|
-
gasPrice = await this.estimateGasPrice(10);
|
4074
|
-
}
|
4075
|
-
const minFee = calculateGasFee({
|
4076
|
-
gasPrice: bn16(gasPrice),
|
4077
|
-
gas: minGas,
|
4078
|
-
priceFactor: gasPriceFactor,
|
4079
|
-
tip: transactionRequest.tip
|
4080
|
-
}).add(1);
|
4081
|
-
let gasLimit = bn16(0);
|
4082
|
-
if (transactionRequest.type === TransactionType8.Script) {
|
4083
|
-
gasLimit = transactionRequest.gasLimit;
|
4084
|
-
if (!optimizeGas) {
|
4085
|
-
transactionRequest.gasLimit = minGas;
|
4086
|
-
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4087
|
-
transactionRequest.gasLimit = gasLimit;
|
4088
|
-
}
|
4089
|
-
}
|
4090
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4091
|
-
const maxFee = calculateGasFee({
|
4092
|
-
gasPrice: bn16(gasPrice),
|
4093
|
-
gas: maxGas,
|
4094
|
-
priceFactor: gasPriceFactor,
|
4095
|
-
tip: transactionRequest.tip
|
4096
|
-
}).add(1);
|
4097
|
-
return {
|
4098
|
-
minGas,
|
4099
|
-
minFee,
|
4100
|
-
maxGas,
|
4101
|
-
maxFee,
|
4102
|
-
gasPrice,
|
4103
|
-
gasLimit
|
3893
|
+
missingContractIds
|
4104
3894
|
};
|
4105
3895
|
}
|
4106
3896
|
/**
|
@@ -4118,17 +3908,15 @@ var _Provider = class {
|
|
4118
3908
|
if (estimateTxDependencies) {
|
4119
3909
|
return this.estimateTxDependencies(transactionRequest);
|
4120
3910
|
}
|
4121
|
-
const
|
4122
|
-
const { dryRun:
|
4123
|
-
|
3911
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3912
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3913
|
+
encodedTransaction,
|
4124
3914
|
utxoValidation: true
|
4125
3915
|
});
|
4126
|
-
const
|
4127
|
-
|
4128
|
-
|
4129
|
-
|
4130
|
-
});
|
4131
|
-
return { receipts: callResult[0].receipts };
|
3916
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3917
|
+
return {
|
3918
|
+
receipts
|
3919
|
+
};
|
4132
3920
|
}
|
4133
3921
|
/**
|
4134
3922
|
* Returns a transaction cost to enable user
|
@@ -4145,80 +3933,80 @@ var _Provider = class {
|
|
4145
3933
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4146
3934
|
* @returns A promise that resolves to the transaction cost object.
|
4147
3935
|
*/
|
4148
|
-
async getTransactionCost(transactionRequestLike,
|
3936
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3937
|
+
estimateTxDependencies = true,
|
3938
|
+
estimatePredicates = true,
|
3939
|
+
resourcesOwner,
|
3940
|
+
signatureCallback
|
3941
|
+
} = {}) {
|
4149
3942
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3943
|
+
const chainInfo = this.getChain();
|
3944
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3945
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4150
3946
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4151
3947
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4152
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3948
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4153
3949
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
3950
|
+
if (estimatePredicates) {
|
3951
|
+
if (isScriptTransaction) {
|
3952
|
+
txRequestClone.gasLimit = bn15(0);
|
3953
|
+
}
|
3954
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3955
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3956
|
+
}
|
3957
|
+
await this.estimatePredicates(txRequestClone);
|
4160
3958
|
}
|
4161
|
-
const signedRequest = clone3(txRequestClone);
|
4162
|
-
let addedSignatures = 0;
|
4163
3959
|
if (signatureCallback && isScriptTransaction) {
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
await this.estimatePredicates(signedRequest);
|
4169
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4170
|
-
transactionRequest: signedRequest,
|
4171
|
-
optimizeGas: false
|
4172
|
-
});
|
4173
|
-
txRequestClone.maxFee = maxFee;
|
3960
|
+
await signatureCallback(txRequestClone);
|
3961
|
+
}
|
3962
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3963
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4174
3964
|
let receipts = [];
|
4175
3965
|
let missingContractIds = [];
|
4176
3966
|
let outputVariables = 0;
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4180
|
-
if (signatureCallback) {
|
4181
|
-
await signatureCallback(txRequestClone);
|
4182
|
-
}
|
4183
|
-
txRequestClone.gasLimit = gasLimit;
|
3967
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3968
|
+
txRequestClone.gasPrice = bn15(0);
|
3969
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4184
3970
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4185
3971
|
receipts = result.receipts;
|
4186
3972
|
outputVariables = result.outputVariables;
|
4187
3973
|
missingContractIds = result.missingContractIds;
|
4188
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4189
|
-
txRequestClone.gasLimit = gasUsed;
|
4190
|
-
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4191
|
-
transactionRequest: txRequestClone,
|
4192
|
-
gasPrice
|
4193
|
-
}));
|
4194
3974
|
}
|
3975
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3976
|
+
const usedFee = calculatePriceWithFactor(
|
3977
|
+
gasUsed,
|
3978
|
+
gasPrice,
|
3979
|
+
gasPriceFactor
|
3980
|
+
).normalizeZeroToOne();
|
3981
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3982
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4195
3983
|
return {
|
4196
3984
|
requiredQuantities: allQuantities,
|
4197
3985
|
receipts,
|
4198
3986
|
gasUsed,
|
3987
|
+
minGasPrice,
|
4199
3988
|
gasPrice,
|
4200
3989
|
minGas,
|
4201
3990
|
maxGas,
|
3991
|
+
usedFee,
|
4202
3992
|
minFee,
|
4203
3993
|
maxFee,
|
3994
|
+
estimatedInputs: txRequestClone.inputs,
|
4204
3995
|
outputVariables,
|
4205
|
-
missingContractIds
|
4206
|
-
addedSignatures,
|
4207
|
-
estimatedPredicates: txRequestClone.inputs
|
3996
|
+
missingContractIds
|
4208
3997
|
};
|
4209
3998
|
}
|
4210
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
3999
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4211
4000
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4212
4001
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4213
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4214
|
-
quantitiesToContract
|
4215
|
-
});
|
4002
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4216
4003
|
transactionRequest.addResources(
|
4217
4004
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4218
4005
|
);
|
4219
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4220
|
-
|
4221
|
-
|
4006
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4007
|
+
transactionRequest,
|
4008
|
+
forwardingQuantities
|
4009
|
+
);
|
4222
4010
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4223
4011
|
return {
|
4224
4012
|
resources,
|
@@ -4240,10 +4028,11 @@ var _Provider = class {
|
|
4240
4028
|
return coins.map((coin) => ({
|
4241
4029
|
id: coin.utxoId,
|
4242
4030
|
assetId: coin.assetId,
|
4243
|
-
amount:
|
4031
|
+
amount: bn15(coin.amount),
|
4244
4032
|
owner: Address2.fromAddressOrString(coin.owner),
|
4245
|
-
|
4246
|
-
|
4033
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4034
|
+
blockCreated: bn15(coin.blockCreated),
|
4035
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4247
4036
|
}));
|
4248
4037
|
}
|
4249
4038
|
/**
|
@@ -4280,9 +4069,9 @@ var _Provider = class {
|
|
4280
4069
|
switch (coin.__typename) {
|
4281
4070
|
case "MessageCoin":
|
4282
4071
|
return {
|
4283
|
-
amount:
|
4072
|
+
amount: bn15(coin.amount),
|
4284
4073
|
assetId: coin.assetId,
|
4285
|
-
daHeight:
|
4074
|
+
daHeight: bn15(coin.daHeight),
|
4286
4075
|
sender: Address2.fromAddressOrString(coin.sender),
|
4287
4076
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4288
4077
|
nonce: coin.nonce
|
@@ -4290,11 +4079,12 @@ var _Provider = class {
|
|
4290
4079
|
case "Coin":
|
4291
4080
|
return {
|
4292
4081
|
id: coin.utxoId,
|
4293
|
-
amount:
|
4082
|
+
amount: bn15(coin.amount),
|
4294
4083
|
assetId: coin.assetId,
|
4295
4084
|
owner: Address2.fromAddressOrString(coin.owner),
|
4296
|
-
|
4297
|
-
|
4085
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4086
|
+
blockCreated: bn15(coin.blockCreated),
|
4087
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4298
4088
|
};
|
4299
4089
|
default:
|
4300
4090
|
return null;
|
@@ -4311,13 +4101,13 @@ var _Provider = class {
|
|
4311
4101
|
async getBlock(idOrHeight) {
|
4312
4102
|
let variables;
|
4313
4103
|
if (typeof idOrHeight === "number") {
|
4314
|
-
variables = { height:
|
4104
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4315
4105
|
} else if (idOrHeight === "latest") {
|
4316
4106
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4317
4107
|
} else if (idOrHeight.length === 66) {
|
4318
4108
|
variables = { blockId: idOrHeight };
|
4319
4109
|
} else {
|
4320
|
-
variables = { blockId:
|
4110
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4321
4111
|
}
|
4322
4112
|
const { block } = await this.operations.getBlock(variables);
|
4323
4113
|
if (!block) {
|
@@ -4325,7 +4115,7 @@ var _Provider = class {
|
|
4325
4115
|
}
|
4326
4116
|
return {
|
4327
4117
|
id: block.id,
|
4328
|
-
height:
|
4118
|
+
height: bn15(block.header.height),
|
4329
4119
|
time: block.header.time,
|
4330
4120
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4331
4121
|
};
|
@@ -4340,7 +4130,7 @@ var _Provider = class {
|
|
4340
4130
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4341
4131
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4342
4132
|
id: block.id,
|
4343
|
-
height:
|
4133
|
+
height: bn15(block.header.height),
|
4344
4134
|
time: block.header.time,
|
4345
4135
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4346
4136
|
}));
|
@@ -4355,7 +4145,7 @@ var _Provider = class {
|
|
4355
4145
|
async getBlockWithTransactions(idOrHeight) {
|
4356
4146
|
let variables;
|
4357
4147
|
if (typeof idOrHeight === "number") {
|
4358
|
-
variables = { blockHeight:
|
4148
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4359
4149
|
} else if (idOrHeight === "latest") {
|
4360
4150
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4361
4151
|
} else {
|
@@ -4367,7 +4157,7 @@ var _Provider = class {
|
|
4367
4157
|
}
|
4368
4158
|
return {
|
4369
4159
|
id: block.id,
|
4370
|
-
height:
|
4160
|
+
height: bn15(block.header.height, 10),
|
4371
4161
|
time: block.header.time,
|
4372
4162
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4373
4163
|
transactions: block.transactions.map(
|
@@ -4416,7 +4206,7 @@ var _Provider = class {
|
|
4416
4206
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4417
4207
|
asset: hexlify12(assetId)
|
4418
4208
|
});
|
4419
|
-
return
|
4209
|
+
return bn15(contractBalance.amount, 10);
|
4420
4210
|
}
|
4421
4211
|
/**
|
4422
4212
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4430,7 +4220,7 @@ var _Provider = class {
|
|
4430
4220
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4431
4221
|
assetId: hexlify12(assetId)
|
4432
4222
|
});
|
4433
|
-
return
|
4223
|
+
return bn15(balance.amount, 10);
|
4434
4224
|
}
|
4435
4225
|
/**
|
4436
4226
|
* Returns balances for the given owner.
|
@@ -4448,7 +4238,7 @@ var _Provider = class {
|
|
4448
4238
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4449
4239
|
return balances.map((balance) => ({
|
4450
4240
|
assetId: balance.assetId,
|
4451
|
-
amount:
|
4241
|
+
amount: bn15(balance.amount)
|
4452
4242
|
}));
|
4453
4243
|
}
|
4454
4244
|
/**
|
@@ -4470,15 +4260,15 @@ var _Provider = class {
|
|
4470
4260
|
sender: message.sender,
|
4471
4261
|
recipient: message.recipient,
|
4472
4262
|
nonce: message.nonce,
|
4473
|
-
amount:
|
4263
|
+
amount: bn15(message.amount),
|
4474
4264
|
data: message.data
|
4475
4265
|
}),
|
4476
4266
|
sender: Address2.fromAddressOrString(message.sender),
|
4477
4267
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4478
4268
|
nonce: message.nonce,
|
4479
|
-
amount:
|
4269
|
+
amount: bn15(message.amount),
|
4480
4270
|
data: InputMessageCoder.decodeData(message.data),
|
4481
|
-
daHeight:
|
4271
|
+
daHeight: bn15(message.daHeight)
|
4482
4272
|
}));
|
4483
4273
|
}
|
4484
4274
|
/**
|
@@ -4531,52 +4321,44 @@ var _Provider = class {
|
|
4531
4321
|
} = result.messageProof;
|
4532
4322
|
return {
|
4533
4323
|
messageProof: {
|
4534
|
-
proofIndex:
|
4324
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4535
4325
|
proofSet: messageProof.proofSet
|
4536
4326
|
},
|
4537
4327
|
blockProof: {
|
4538
|
-
proofIndex:
|
4328
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4539
4329
|
proofSet: blockProof.proofSet
|
4540
4330
|
},
|
4541
4331
|
messageBlockHeader: {
|
4542
4332
|
id: messageBlockHeader.id,
|
4543
|
-
daHeight:
|
4544
|
-
transactionsCount:
|
4333
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4334
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4545
4335
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4546
|
-
height:
|
4336
|
+
height: bn15(messageBlockHeader.height),
|
4547
4337
|
prevRoot: messageBlockHeader.prevRoot,
|
4548
4338
|
time: messageBlockHeader.time,
|
4549
4339
|
applicationHash: messageBlockHeader.applicationHash,
|
4550
|
-
|
4340
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4341
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4551
4342
|
},
|
4552
4343
|
commitBlockHeader: {
|
4553
4344
|
id: commitBlockHeader.id,
|
4554
|
-
daHeight:
|
4555
|
-
transactionsCount:
|
4345
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4346
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4556
4347
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4557
|
-
height:
|
4348
|
+
height: bn15(commitBlockHeader.height),
|
4558
4349
|
prevRoot: commitBlockHeader.prevRoot,
|
4559
4350
|
time: commitBlockHeader.time,
|
4560
4351
|
applicationHash: commitBlockHeader.applicationHash,
|
4561
|
-
|
4352
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4353
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4562
4354
|
},
|
4563
4355
|
sender: Address2.fromAddressOrString(sender),
|
4564
4356
|
recipient: Address2.fromAddressOrString(recipient),
|
4565
4357
|
nonce,
|
4566
|
-
amount:
|
4358
|
+
amount: bn15(amount),
|
4567
4359
|
data
|
4568
4360
|
};
|
4569
4361
|
}
|
4570
|
-
async getLatestGasPrice() {
|
4571
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4572
|
-
return bn16(latestGasPrice.gasPrice);
|
4573
|
-
}
|
4574
|
-
async estimateGasPrice(blockHorizon) {
|
4575
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4576
|
-
blockHorizon: String(blockHorizon)
|
4577
|
-
});
|
4578
|
-
return bn16(estimateGasPrice.gasPrice);
|
4579
|
-
}
|
4580
4362
|
/**
|
4581
4363
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4582
4364
|
*
|
@@ -4596,10 +4378,10 @@ var _Provider = class {
|
|
4596
4378
|
*/
|
4597
4379
|
async produceBlocks(amount, startTime) {
|
4598
4380
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4599
|
-
blocksToProduce:
|
4381
|
+
blocksToProduce: bn15(amount).toString(10),
|
4600
4382
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4601
4383
|
});
|
4602
|
-
return
|
4384
|
+
return bn15(latestBlockHeight);
|
4603
4385
|
}
|
4604
4386
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4605
4387
|
async getTransactionResponse(transactionId) {
|
@@ -4613,7 +4395,7 @@ cacheInputs_fn = function(inputs) {
|
|
4613
4395
|
return;
|
4614
4396
|
}
|
4615
4397
|
inputs.forEach((input) => {
|
4616
|
-
if (input.type ===
|
4398
|
+
if (input.type === InputType6.Coin) {
|
4617
4399
|
this.cache?.set(input.id);
|
4618
4400
|
}
|
4619
4401
|
});
|
@@ -4623,7 +4405,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4623
4405
|
|
4624
4406
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4625
4407
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4626
|
-
import { bn as
|
4408
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4627
4409
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4628
4410
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4629
4411
|
|
@@ -4831,8 +4613,9 @@ var Account = class extends AbstractAccount {
|
|
4831
4613
|
* @param assetId - The asset ID to check the balance for.
|
4832
4614
|
* @returns A promise that resolves to the balance amount.
|
4833
4615
|
*/
|
4834
|
-
async getBalance(assetId
|
4835
|
-
const
|
4616
|
+
async getBalance(assetId) {
|
4617
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4618
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4836
4619
|
return amount;
|
4837
4620
|
}
|
4838
4621
|
/**
|
@@ -4869,33 +4652,37 @@ var Account = class extends AbstractAccount {
|
|
4869
4652
|
* @param fee - The estimated transaction fee.
|
4870
4653
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4871
4654
|
*/
|
4872
|
-
async fund(request,
|
4873
|
-
const
|
4874
|
-
const
|
4875
|
-
|
4876
|
-
|
4877
|
-
|
4878
|
-
coinQuantities: requiredQuantities
|
4655
|
+
async fund(request, coinQuantities, fee) {
|
4656
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4657
|
+
const updatedQuantities = addAmountToAsset({
|
4658
|
+
amount: bn17(fee),
|
4659
|
+
assetId: baseAssetId,
|
4660
|
+
coinQuantities
|
4879
4661
|
});
|
4880
4662
|
const quantitiesDict = {};
|
4881
|
-
|
4663
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4882
4664
|
quantitiesDict[assetId] = {
|
4883
4665
|
required: amount,
|
4884
|
-
owned:
|
4666
|
+
owned: bn17(0)
|
4885
4667
|
};
|
4886
4668
|
});
|
4887
|
-
|
4669
|
+
const cachedUtxos = [];
|
4670
|
+
const cachedMessages = [];
|
4671
|
+
const owner = this.address.toB256();
|
4672
|
+
request.inputs.forEach((input) => {
|
4888
4673
|
const isResource = "amount" in input;
|
4889
4674
|
if (isResource) {
|
4890
4675
|
const isCoin2 = "owner" in input;
|
4891
4676
|
if (isCoin2) {
|
4892
4677
|
const assetId = String(input.assetId);
|
4893
|
-
if (quantitiesDict[assetId]) {
|
4894
|
-
const amount =
|
4678
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4679
|
+
const amount = bn17(input.amount);
|
4895
4680
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4681
|
+
cachedUtxos.push(input.id);
|
4896
4682
|
}
|
4897
|
-
} else if (input.amount && quantitiesDict[
|
4898
|
-
quantitiesDict[
|
4683
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4684
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4685
|
+
cachedMessages.push(input.nonce);
|
4899
4686
|
}
|
4900
4687
|
}
|
4901
4688
|
});
|
@@ -4910,23 +4697,12 @@ var Account = class extends AbstractAccount {
|
|
4910
4697
|
});
|
4911
4698
|
const needsToBeFunded = missingQuantities.length;
|
4912
4699
|
if (needsToBeFunded) {
|
4913
|
-
const
|
4914
|
-
|
4915
|
-
|
4916
|
-
|
4917
|
-
|
4918
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4919
|
-
const requestToBeReEstimate = clone4(txRequest);
|
4920
|
-
if (addedSignatures) {
|
4921
|
-
Array.from({ length: addedSignatures }).forEach(
|
4922
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4923
|
-
);
|
4700
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4701
|
+
messages: cachedMessages,
|
4702
|
+
utxos: cachedUtxos
|
4703
|
+
});
|
4704
|
+
request.addResources(resources);
|
4924
4705
|
}
|
4925
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4926
|
-
transactionRequest: requestToBeReEstimate
|
4927
|
-
});
|
4928
|
-
txRequest.maxFee = maxFee;
|
4929
|
-
return txRequest;
|
4930
4706
|
}
|
4931
4707
|
/**
|
4932
4708
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4934,25 +4710,29 @@ var Account = class extends AbstractAccount {
|
|
4934
4710
|
* @param destination - The address of the destination.
|
4935
4711
|
* @param amount - The amount of coins to transfer.
|
4936
4712
|
* @param assetId - The asset ID of the coins to transfer.
|
4937
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4713
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4938
4714
|
* @returns A promise that resolves to the prepared transaction request.
|
4939
4715
|
*/
|
4940
|
-
async createTransfer(destination, amount, assetId
|
4941
|
-
const
|
4942
|
-
|
4943
|
-
const
|
4716
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4717
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4718
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4719
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4720
|
+
const request = new ScriptTransactionRequest(params);
|
4721
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4722
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4944
4723
|
estimateTxDependencies: true,
|
4945
4724
|
resourcesOwner: this
|
4946
4725
|
});
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
4955
|
-
await this.fund(request,
|
4726
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4727
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4728
|
+
this.validateGas({
|
4729
|
+
gasUsed,
|
4730
|
+
gasPrice: request.gasPrice,
|
4731
|
+
gasLimit: request.gasLimit,
|
4732
|
+
minGasPrice
|
4733
|
+
});
|
4734
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4735
|
+
request.updatePredicateInputs(estimatedInputs);
|
4956
4736
|
return request;
|
4957
4737
|
}
|
4958
4738
|
/**
|
@@ -4964,14 +4744,15 @@ var Account = class extends AbstractAccount {
|
|
4964
4744
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4965
4745
|
* @returns A promise that resolves to the transaction response.
|
4966
4746
|
*/
|
4967
|
-
async transfer(destination, amount, assetId
|
4968
|
-
if (
|
4747
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4748
|
+
if (bn17(amount).lte(0)) {
|
4969
4749
|
throw new FuelError15(
|
4970
4750
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4971
4751
|
"Transfer amount must be a positive number."
|
4972
4752
|
);
|
4973
4753
|
}
|
4974
|
-
const
|
4754
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4755
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4975
4756
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4976
4757
|
}
|
4977
4758
|
/**
|
@@ -4983,38 +4764,40 @@ var Account = class extends AbstractAccount {
|
|
4983
4764
|
* @param txParams - The optional transaction parameters.
|
4984
4765
|
* @returns A promise that resolves to the transaction response.
|
4985
4766
|
*/
|
4986
|
-
async transferToContract(contractId, amount, assetId
|
4987
|
-
if (
|
4767
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4768
|
+
if (bn17(amount).lte(0)) {
|
4988
4769
|
throw new FuelError15(
|
4989
4770
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4990
4771
|
"Transfer amount must be a positive number."
|
4991
4772
|
);
|
4992
4773
|
}
|
4993
4774
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4775
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4776
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4777
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4994
4778
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4995
4779
|
hexlifiedContractId: contractAddress.toB256(),
|
4996
|
-
amountToTransfer:
|
4997
|
-
assetId
|
4780
|
+
amountToTransfer: bn17(amount),
|
4781
|
+
assetId: assetIdToTransfer
|
4998
4782
|
});
|
4999
4783
|
const request = new ScriptTransactionRequest({
|
5000
|
-
...
|
4784
|
+
...params,
|
5001
4785
|
script,
|
5002
4786
|
scriptData
|
5003
4787
|
});
|
5004
4788
|
request.addContractInputAndOutput(contractAddress);
|
5005
|
-
const
|
5006
|
-
|
5007
|
-
|
4789
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4790
|
+
request,
|
4791
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4792
|
+
);
|
4793
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4794
|
+
this.validateGas({
|
4795
|
+
gasUsed,
|
4796
|
+
gasPrice: request.gasPrice,
|
4797
|
+
gasLimit: request.gasLimit,
|
4798
|
+
minGasPrice
|
5008
4799
|
});
|
5009
|
-
|
5010
|
-
this.validateGas({
|
5011
|
-
gasUsed: txCost.gasUsed,
|
5012
|
-
gasLimit: request.gasLimit
|
5013
|
-
});
|
5014
|
-
}
|
5015
|
-
request.gasLimit = txCost.gasUsed;
|
5016
|
-
request.maxFee = txCost.maxFee;
|
5017
|
-
await this.fund(request, txCost);
|
4800
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5018
4801
|
return this.sendTransaction(request);
|
5019
4802
|
}
|
5020
4803
|
/**
|
@@ -5026,31 +4809,35 @@ var Account = class extends AbstractAccount {
|
|
5026
4809
|
* @returns A promise that resolves to the transaction response.
|
5027
4810
|
*/
|
5028
4811
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4812
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4813
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5029
4814
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5030
4815
|
const recipientDataArray = arrayify14(
|
5031
4816
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5032
4817
|
);
|
5033
4818
|
const amountDataArray = arrayify14(
|
5034
|
-
"0x".concat(
|
4819
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5035
4820
|
);
|
5036
4821
|
const script = new Uint8Array([
|
5037
4822
|
...arrayify14(withdrawScript.bytes),
|
5038
4823
|
...recipientDataArray,
|
5039
4824
|
...amountDataArray
|
5040
4825
|
]);
|
5041
|
-
const params = { script, ...txParams };
|
4826
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5042
4827
|
const request = new ScriptTransactionRequest(params);
|
5043
|
-
const
|
5044
|
-
const
|
5045
|
-
|
5046
|
-
|
5047
|
-
|
5048
|
-
|
5049
|
-
|
5050
|
-
|
5051
|
-
|
5052
|
-
|
5053
|
-
|
4828
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4829
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4830
|
+
request,
|
4831
|
+
forwardingQuantities
|
4832
|
+
);
|
4833
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4834
|
+
this.validateGas({
|
4835
|
+
gasUsed,
|
4836
|
+
gasPrice: request.gasPrice,
|
4837
|
+
gasLimit: request.gasLimit,
|
4838
|
+
minGasPrice
|
4839
|
+
});
|
4840
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5054
4841
|
return this.sendTransaction(request);
|
5055
4842
|
}
|
5056
4843
|
async signMessage(message) {
|
@@ -5108,7 +4895,18 @@ var Account = class extends AbstractAccount {
|
|
5108
4895
|
}
|
5109
4896
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5110
4897
|
}
|
5111
|
-
validateGas({
|
4898
|
+
validateGas({
|
4899
|
+
gasUsed,
|
4900
|
+
gasPrice,
|
4901
|
+
gasLimit,
|
4902
|
+
minGasPrice
|
4903
|
+
}) {
|
4904
|
+
if (minGasPrice.gt(gasPrice)) {
|
4905
|
+
throw new FuelError15(
|
4906
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4907
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4908
|
+
);
|
4909
|
+
}
|
5112
4910
|
if (gasUsed.gt(gasLimit)) {
|
5113
4911
|
throw new FuelError15(
|
5114
4912
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5120,7 +4918,7 @@ var Account = class extends AbstractAccount {
|
|
5120
4918
|
|
5121
4919
|
// src/signer/signer.ts
|
5122
4920
|
import { Address as Address4 } from "@fuel-ts/address";
|
5123
|
-
import { randomBytes
|
4921
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
5124
4922
|
import { hash } from "@fuel-ts/hasher";
|
5125
4923
|
import { toBytes } from "@fuel-ts/math";
|
5126
4924
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5213,7 +5011,7 @@ var Signer = class {
|
|
5213
5011
|
* @returns random 32-byte hashed
|
5214
5012
|
*/
|
5215
5013
|
static generatePrivateKey(entropy) {
|
5216
|
-
return entropy ? hash(concat3([
|
5014
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5217
5015
|
}
|
5218
5016
|
/**
|
5219
5017
|
* Extended publicKey from a compact publicKey
|
@@ -5232,7 +5030,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5232
5030
|
import {
|
5233
5031
|
bufferFromString,
|
5234
5032
|
keccak256,
|
5235
|
-
randomBytes as
|
5033
|
+
randomBytes as randomBytes2,
|
5236
5034
|
scrypt,
|
5237
5035
|
stringFromBuffer,
|
5238
5036
|
decryptJsonWalletData,
|
@@ -5255,7 +5053,7 @@ var removeHexPrefix = (hexString) => {
|
|
5255
5053
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5256
5054
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5257
5055
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5258
|
-
const salt =
|
5056
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5259
5057
|
const key = scrypt({
|
5260
5058
|
password: bufferFromString(password),
|
5261
5059
|
salt,
|
@@ -5264,7 +5062,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5264
5062
|
r: DEFAULT_KDF_PARAMS_R,
|
5265
5063
|
p: DEFAULT_KDF_PARAMS_P
|
5266
5064
|
});
|
5267
|
-
const iv =
|
5065
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5268
5066
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5269
5067
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5270
5068
|
const macHashUint8Array = keccak256(data);
|
@@ -5400,7 +5198,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5400
5198
|
* @param transactionRequestLike - The transaction request to send.
|
5401
5199
|
* @returns A promise that resolves to the TransactionResponse object.
|
5402
5200
|
*/
|
5403
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5201
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5404
5202
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5405
5203
|
if (estimateTxDependencies) {
|
5406
5204
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5441,12 +5239,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5441
5239
|
// src/hdwallet/hdwallet.ts
|
5442
5240
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5443
5241
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5444
|
-
import { bn as
|
5242
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5445
5243
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5446
5244
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5447
5245
|
|
5448
5246
|
// src/mnemonic/mnemonic.ts
|
5449
|
-
import { randomBytes as
|
5247
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5450
5248
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5451
5249
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5452
5250
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7801,7 +7599,7 @@ var Mnemonic = class {
|
|
7801
7599
|
* @returns A randomly generated mnemonic
|
7802
7600
|
*/
|
7803
7601
|
static generate(size = 32, extraEntropy = "") {
|
7804
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7602
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7805
7603
|
return Mnemonic.entropyToMnemonic(entropy);
|
7806
7604
|
}
|
7807
7605
|
};
|
@@ -7907,7 +7705,7 @@ var HDWallet = class {
|
|
7907
7705
|
const IR = bytes.slice(32);
|
7908
7706
|
if (privateKey) {
|
7909
7707
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7910
|
-
const ki =
|
7708
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7911
7709
|
return new HDWallet({
|
7912
7710
|
privateKey: ki,
|
7913
7711
|
chainCode: IR,
|
@@ -8172,21 +7970,20 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
8172
7970
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
8173
7971
|
|
8174
7972
|
// src/test-utils/seedTestWallet.ts
|
8175
|
-
import { randomBytes as
|
7973
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
8176
7974
|
var seedTestWallet = async (wallet, quantities) => {
|
8177
7975
|
const genesisWallet = new WalletUnlocked(
|
8178
|
-
process.env.GENESIS_SECRET ||
|
7976
|
+
process.env.GENESIS_SECRET || randomBytes4(32),
|
8179
7977
|
wallet.provider
|
8180
7978
|
);
|
8181
|
-
const
|
8182
|
-
|
8183
|
-
|
8184
|
-
|
7979
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7980
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7981
|
+
const request = new ScriptTransactionRequest({
|
7982
|
+
gasLimit: 1e4,
|
7983
|
+
gasPrice: minGasPrice
|
8185
7984
|
});
|
8186
|
-
|
8187
|
-
request.
|
8188
|
-
request.maxFee = txCost.maxFee;
|
8189
|
-
await genesisWallet.fund(request, txCost);
|
7985
|
+
request.addResources(resources);
|
7986
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8190
7987
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8191
7988
|
};
|
8192
7989
|
|
@@ -8200,12 +7997,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8200
7997
|
};
|
8201
7998
|
|
8202
7999
|
// src/test-utils/launchNode.ts
|
8203
|
-
import {
|
8204
|
-
import {
|
8000
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8001
|
+
import { toHex as toHex2 } from "@fuel-ts/math";
|
8002
|
+
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8205
8003
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8206
8004
|
import { spawn } from "child_process";
|
8207
8005
|
import { randomUUID } from "crypto";
|
8208
|
-
import { randomBytes as randomBytes6 } from "ethers";
|
8209
8006
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8210
8007
|
import os from "os";
|
8211
8008
|
import path from "path";
|
@@ -8254,12 +8051,12 @@ var launchNode = async ({
|
|
8254
8051
|
// eslint-disable-next-line no-async-promise-executor
|
8255
8052
|
new Promise(async (resolve, reject) => {
|
8256
8053
|
const remainingArgs = extractRemainingArgs(args, [
|
8257
|
-
"--
|
8054
|
+
"--chain",
|
8258
8055
|
"--consensus-key",
|
8259
8056
|
"--db-type",
|
8260
8057
|
"--poa-instant"
|
8261
8058
|
]);
|
8262
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8059
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8263
8060
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
|
8264
8061
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8265
8062
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
@@ -8278,54 +8075,36 @@ var launchNode = async ({
|
|
8278
8075
|
let chainConfigPathToUse;
|
8279
8076
|
const prefix = basePath || os.tmpdir();
|
8280
8077
|
const suffix = basePath ? "" : randomUUID();
|
8281
|
-
const tempDirPath = path.join(prefix, ".fuels", suffix
|
8078
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix);
|
8282
8079
|
if (chainConfigPath) {
|
8283
8080
|
chainConfigPathToUse = chainConfigPath;
|
8284
8081
|
} else {
|
8285
8082
|
if (!existsSync(tempDirPath)) {
|
8286
8083
|
mkdirSync(tempDirPath, { recursive: true });
|
8287
8084
|
}
|
8288
|
-
|
8289
|
-
|
8290
|
-
stateConfigJson = {
|
8291
|
-
...stateConfigJson,
|
8292
|
-
coins: [
|
8293
|
-
...stateConfigJson.coins.map((coin) => ({
|
8294
|
-
...coin,
|
8295
|
-
amount: "18446744073709551615"
|
8296
|
-
}))
|
8297
|
-
],
|
8298
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8299
|
-
...message,
|
8300
|
-
amount: "18446744073709551615"
|
8301
|
-
}))
|
8302
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8303
|
-
};
|
8085
|
+
const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
|
8086
|
+
let chainConfig = defaultChainConfig;
|
8304
8087
|
if (!process.env.GENESIS_SECRET) {
|
8305
8088
|
const pk = Signer.generatePrivateKey();
|
8306
8089
|
const signer = new Signer(pk);
|
8307
8090
|
process.env.GENESIS_SECRET = hexlify18(pk);
|
8308
|
-
|
8309
|
-
|
8310
|
-
|
8311
|
-
|
8312
|
-
|
8313
|
-
|
8314
|
-
|
8315
|
-
|
8316
|
-
|
8317
|
-
|
8091
|
+
chainConfig = {
|
8092
|
+
...defaultChainConfig,
|
8093
|
+
initial_state: {
|
8094
|
+
...defaultChainConfig.initial_state,
|
8095
|
+
coins: [
|
8096
|
+
...defaultChainConfig.initial_state.coins,
|
8097
|
+
{
|
8098
|
+
owner: signer.address.toHexString(),
|
8099
|
+
amount: toHex2(1e9),
|
8100
|
+
asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
|
8101
|
+
}
|
8102
|
+
]
|
8103
|
+
}
|
8104
|
+
};
|
8318
8105
|
}
|
8319
|
-
|
8320
|
-
|
8321
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8322
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8323
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8324
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8325
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8326
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8327
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8328
|
-
chainConfigPathToUse = tempDirPath;
|
8106
|
+
writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8107
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8329
8108
|
}
|
8330
8109
|
const child = spawn(
|
8331
8110
|
command,
|
@@ -8334,10 +8113,10 @@ var launchNode = async ({
|
|
8334
8113
|
["--ip", ipToUse],
|
8335
8114
|
["--port", portToUse],
|
8336
8115
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8337
|
-
["--min-gas-price", "
|
8116
|
+
["--min-gas-price", "0"],
|
8338
8117
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8339
8118
|
["--consensus-key", consensusKey],
|
8340
|
-
["--
|
8119
|
+
["--chain", chainConfigPathToUse],
|
8341
8120
|
"--vm-backtrace",
|
8342
8121
|
"--utxo-validation",
|
8343
8122
|
"--debug",
|
@@ -8384,9 +8163,10 @@ var launchNode = async ({
|
|
8384
8163
|
})
|
8385
8164
|
);
|
8386
8165
|
var generateWallets = async (count, provider) => {
|
8166
|
+
const baseAssetId = provider.getBaseAssetId();
|
8387
8167
|
const wallets = [];
|
8388
8168
|
for (let i = 0; i < count; i += 1) {
|
8389
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8169
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8390
8170
|
wallets.push(wallet);
|
8391
8171
|
}
|
8392
8172
|
return wallets;
|
@@ -8396,7 +8176,7 @@ var launchNodeAndGetWallets = async ({
|
|
8396
8176
|
walletCount = 10
|
8397
8177
|
} = {}) => {
|
8398
8178
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8399
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8179
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8400
8180
|
const wallets = await generateWallets(walletCount, provider);
|
8401
8181
|
const cleanup = () => {
|
8402
8182
|
closeNode();
|