@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/index.mjs
CHANGED
@@ -29,38 +29,35 @@ var __privateMethod = (obj, member, method) => {
|
|
29
29
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
32
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
34
33
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
|
-
import { bn as
|
34
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
36
35
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
|
-
import { clone as clone4 } from "ramda";
|
38
36
|
|
39
37
|
// src/providers/coin-quantity.ts
|
40
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
41
38
|
import { bn } from "@fuel-ts/math";
|
42
39
|
import { hexlify } from "@fuel-ts/utils";
|
43
40
|
var coinQuantityfy = (coinQuantityLike) => {
|
44
41
|
let assetId;
|
45
42
|
let amount;
|
46
|
-
let
|
43
|
+
let max2;
|
47
44
|
if (Array.isArray(coinQuantityLike)) {
|
48
45
|
amount = coinQuantityLike[0];
|
49
|
-
assetId = coinQuantityLike[1]
|
50
|
-
|
46
|
+
assetId = coinQuantityLike[1];
|
47
|
+
max2 = coinQuantityLike[2];
|
51
48
|
} else {
|
52
49
|
amount = coinQuantityLike.amount;
|
53
|
-
assetId = coinQuantityLike.assetId
|
54
|
-
|
50
|
+
assetId = coinQuantityLike.assetId;
|
51
|
+
max2 = coinQuantityLike.max ?? void 0;
|
55
52
|
}
|
56
53
|
const bnAmount = bn(amount);
|
57
54
|
return {
|
58
55
|
assetId: hexlify(assetId),
|
59
56
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
60
|
-
max:
|
57
|
+
max: max2 ? bn(max2) : void 0
|
61
58
|
};
|
62
59
|
};
|
63
|
-
var
|
60
|
+
var addAmountToAsset = (params) => {
|
64
61
|
const { amount, assetId } = params;
|
65
62
|
const coinQuantities = [...params.coinQuantities];
|
66
63
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -75,9 +72,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
75
72
|
// src/providers/provider.ts
|
76
73
|
import { Address as Address2 } from "@fuel-ts/address";
|
77
74
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
78
|
-
import { BN, bn as
|
75
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
79
76
|
import {
|
80
|
-
InputType as
|
77
|
+
InputType as InputType6,
|
81
78
|
TransactionType as TransactionType8,
|
82
79
|
InputMessageCoder,
|
83
80
|
TransactionCoder as TransactionCoder5
|
@@ -93,10 +90,14 @@ import { clone as clone3 } from "ramda";
|
|
93
90
|
import gql from "graphql-tag";
|
94
91
|
var ReceiptFragmentFragmentDoc = gql`
|
95
92
|
fragment receiptFragment on Receipt {
|
96
|
-
|
93
|
+
contract {
|
94
|
+
id
|
95
|
+
}
|
97
96
|
pc
|
98
97
|
is
|
99
|
-
to
|
98
|
+
to {
|
99
|
+
id
|
100
|
+
}
|
100
101
|
toAddress
|
101
102
|
amount
|
102
103
|
assetId
|
@@ -134,16 +135,10 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
134
135
|
id
|
135
136
|
}
|
136
137
|
time
|
137
|
-
receipts {
|
138
|
-
...receiptFragment
|
139
|
-
}
|
140
138
|
programState {
|
141
139
|
returnType
|
142
140
|
data
|
143
141
|
}
|
144
|
-
receipts {
|
145
|
-
...receiptFragment
|
146
|
-
}
|
147
142
|
}
|
148
143
|
... on FailureStatus {
|
149
144
|
block {
|
@@ -151,24 +146,26 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
151
146
|
}
|
152
147
|
time
|
153
148
|
reason
|
154
|
-
receipts {
|
155
|
-
...receiptFragment
|
156
|
-
}
|
157
149
|
}
|
158
150
|
... on SqueezedOutStatus {
|
159
151
|
reason
|
160
152
|
}
|
161
153
|
}
|
162
|
-
|
154
|
+
`;
|
163
155
|
var TransactionFragmentFragmentDoc = gql`
|
164
156
|
fragment transactionFragment on Transaction {
|
165
157
|
id
|
166
158
|
rawPayload
|
159
|
+
gasPrice
|
160
|
+
receipts {
|
161
|
+
...receiptFragment
|
162
|
+
}
|
167
163
|
status {
|
168
164
|
...transactionStatusFragment
|
169
165
|
}
|
170
166
|
}
|
171
|
-
${
|
167
|
+
${ReceiptFragmentFragmentDoc}
|
168
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
172
169
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
173
170
|
fragment inputEstimatePredicatesFragment on Input {
|
174
171
|
... on InputCoin {
|
@@ -186,46 +183,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
186
183
|
}
|
187
184
|
}
|
188
185
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
189
|
-
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
190
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
191
|
-
reason
|
192
|
-
programState {
|
193
|
-
returnType
|
194
|
-
data
|
195
|
-
}
|
196
|
-
}
|
197
|
-
`;
|
198
|
-
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
199
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
200
|
-
programState {
|
201
|
-
returnType
|
202
|
-
data
|
203
|
-
}
|
204
|
-
}
|
205
|
-
`;
|
206
|
-
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
207
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
208
|
-
... on DryRunFailureStatus {
|
209
|
-
...dryRunFailureStatusFragment
|
210
|
-
}
|
211
|
-
... on DryRunSuccessStatus {
|
212
|
-
...dryRunSuccessStatusFragment
|
213
|
-
}
|
214
|
-
}
|
215
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
216
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
217
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
218
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
219
|
-
id
|
220
|
-
status {
|
221
|
-
...dryRunTransactionStatusFragment
|
222
|
-
}
|
223
|
-
receipts {
|
224
|
-
...receiptFragment
|
225
|
-
}
|
226
|
-
}
|
227
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
228
|
-
${ReceiptFragmentFragmentDoc}`;
|
229
186
|
var CoinFragmentFragmentDoc = gql`
|
230
187
|
fragment coinFragment on Coin {
|
231
188
|
__typename
|
@@ -233,6 +190,7 @@ var CoinFragmentFragmentDoc = gql`
|
|
233
190
|
owner
|
234
191
|
amount
|
235
192
|
assetId
|
193
|
+
maturity
|
236
194
|
blockCreated
|
237
195
|
txCreatedIdx
|
238
196
|
}
|
@@ -277,6 +235,7 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
277
235
|
prevRoot
|
278
236
|
time
|
279
237
|
applicationHash
|
238
|
+
messageReceiptRoot
|
280
239
|
messageReceiptCount
|
281
240
|
}
|
282
241
|
commitBlockHeader {
|
@@ -288,6 +247,7 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
288
247
|
prevRoot
|
289
248
|
time
|
290
249
|
applicationHash
|
250
|
+
messageReceiptRoot
|
291
251
|
messageReceiptCount
|
292
252
|
}
|
293
253
|
sender
|
@@ -307,8 +267,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
307
267
|
var BlockFragmentFragmentDoc = gql`
|
308
268
|
fragment blockFragment on Block {
|
309
269
|
id
|
310
|
-
height
|
311
270
|
header {
|
271
|
+
height
|
312
272
|
time
|
313
273
|
}
|
314
274
|
transactions {
|
@@ -366,11 +326,6 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
366
326
|
`;
|
367
327
|
var GasCostsFragmentFragmentDoc = gql`
|
368
328
|
fragment GasCostsFragment on GasCosts {
|
369
|
-
version {
|
370
|
-
... on Version {
|
371
|
-
value
|
372
|
-
}
|
373
|
-
}
|
374
329
|
add
|
375
330
|
addi
|
376
331
|
aloc
|
@@ -383,6 +338,7 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
383
338
|
cb
|
384
339
|
cfei
|
385
340
|
cfsi
|
341
|
+
croo
|
386
342
|
div
|
387
343
|
divi
|
388
344
|
ecr1
|
@@ -465,9 +421,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
465
421
|
ccp {
|
466
422
|
...DependentCostFragment
|
467
423
|
}
|
468
|
-
croo {
|
469
|
-
...DependentCostFragment
|
470
|
-
}
|
471
424
|
csiz {
|
472
425
|
...DependentCostFragment
|
473
426
|
}
|
@@ -527,11 +480,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
527
480
|
${DependentCostFragmentFragmentDoc}`;
|
528
481
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
529
482
|
fragment consensusParametersFragment on ConsensusParameters {
|
530
|
-
version {
|
531
|
-
... on Version {
|
532
|
-
value
|
533
|
-
}
|
534
|
-
}
|
535
483
|
txParams {
|
536
484
|
...TxParametersFragment
|
537
485
|
}
|
@@ -591,9 +539,18 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
591
539
|
fragment nodeInfoFragment on NodeInfo {
|
592
540
|
utxoValidation
|
593
541
|
vmBacktrace
|
542
|
+
minGasPrice
|
594
543
|
maxTx
|
595
544
|
maxDepth
|
596
545
|
nodeVersion
|
546
|
+
peers {
|
547
|
+
id
|
548
|
+
addresses
|
549
|
+
clientVersion
|
550
|
+
blockHeight
|
551
|
+
lastHeartbeatMs
|
552
|
+
appScore
|
553
|
+
}
|
597
554
|
}
|
598
555
|
`;
|
599
556
|
var GetVersionDocument = gql`
|
@@ -628,9 +585,13 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
628
585
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
629
586
|
transaction(id: $transactionId) {
|
630
587
|
...transactionFragment
|
588
|
+
receipts {
|
589
|
+
...receiptFragment
|
590
|
+
}
|
631
591
|
}
|
632
592
|
}
|
633
|
-
${TransactionFragmentFragmentDoc}
|
593
|
+
${TransactionFragmentFragmentDoc}
|
594
|
+
${ReceiptFragmentFragmentDoc}`;
|
634
595
|
var GetTransactionsDocument = gql`
|
635
596
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
636
597
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -758,20 +719,6 @@ var GetBalanceDocument = gql`
|
|
758
719
|
}
|
759
720
|
}
|
760
721
|
${BalanceFragmentFragmentDoc}`;
|
761
|
-
var GetLatestGasPriceDocument = gql`
|
762
|
-
query getLatestGasPrice {
|
763
|
-
latestGasPrice {
|
764
|
-
gasPrice
|
765
|
-
}
|
766
|
-
}
|
767
|
-
`;
|
768
|
-
var EstimateGasPriceDocument = gql`
|
769
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
770
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
771
|
-
gasPrice
|
772
|
-
}
|
773
|
-
}
|
774
|
-
`;
|
775
722
|
var GetBalancesDocument = gql`
|
776
723
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
777
724
|
balances(
|
@@ -826,12 +773,12 @@ var GetMessageStatusDocument = gql`
|
|
826
773
|
}
|
827
774
|
`;
|
828
775
|
var DryRunDocument = gql`
|
829
|
-
mutation dryRun($
|
830
|
-
dryRun(
|
831
|
-
...
|
776
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
777
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
778
|
+
...receiptFragment
|
832
779
|
}
|
833
780
|
}
|
834
|
-
${
|
781
|
+
${ReceiptFragmentFragmentDoc}`;
|
835
782
|
var SubmitDocument = gql`
|
836
783
|
mutation submit($encodedTransaction: HexString!) {
|
837
784
|
submit(tx: $encodedTransaction) {
|
@@ -914,12 +861,6 @@ function getSdk(requester) {
|
|
914
861
|
getBalance(variables, options) {
|
915
862
|
return requester(GetBalanceDocument, variables, options);
|
916
863
|
},
|
917
|
-
getLatestGasPrice(variables, options) {
|
918
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
919
|
-
},
|
920
|
-
estimateGasPrice(variables, options) {
|
921
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
922
|
-
},
|
923
864
|
getBalances(variables, options) {
|
924
865
|
return requester(GetBalancesDocument, variables, options);
|
925
866
|
},
|
@@ -989,14 +930,11 @@ var _FuelGraphqlSubscriber = class {
|
|
989
930
|
let data;
|
990
931
|
let errors;
|
991
932
|
try {
|
992
|
-
|
993
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
933
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
994
934
|
} catch (e) {
|
995
935
|
throw new FuelError(
|
996
936
|
ErrorCode.STREAM_PARSING_ERROR,
|
997
|
-
`Error while parsing stream data response: ${text}
|
998
|
-
|
999
|
-
Thrown error: ${e}`
|
937
|
+
`Error while parsing stream data response: ${text}`
|
1000
938
|
);
|
1001
939
|
}
|
1002
940
|
if (Array.isArray(errors)) {
|
@@ -1097,7 +1035,7 @@ var inputify = (value) => {
|
|
1097
1035
|
return {
|
1098
1036
|
type: InputType.Coin,
|
1099
1037
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1100
|
-
outputIndex:
|
1038
|
+
outputIndex: arrayify(value.id)[32],
|
1101
1039
|
owner: hexlify3(value.owner),
|
1102
1040
|
amount: bn2(value.amount),
|
1103
1041
|
assetId: hexlify3(value.assetId),
|
@@ -1106,9 +1044,10 @@ var inputify = (value) => {
|
|
1106
1044
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1107
1045
|
},
|
1108
1046
|
witnessIndex: value.witnessIndex,
|
1047
|
+
maturity: value.maturity ?? 0,
|
1109
1048
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1110
|
-
predicateLength:
|
1111
|
-
predicateDataLength:
|
1049
|
+
predicateLength: predicate.length,
|
1050
|
+
predicateDataLength: predicateData.length,
|
1112
1051
|
predicate: hexlify3(predicate),
|
1113
1052
|
predicateData: hexlify3(predicateData)
|
1114
1053
|
};
|
@@ -1139,8 +1078,8 @@ var inputify = (value) => {
|
|
1139
1078
|
nonce: hexlify3(value.nonce),
|
1140
1079
|
witnessIndex: value.witnessIndex,
|
1141
1080
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1142
|
-
predicateLength:
|
1143
|
-
predicateDataLength:
|
1081
|
+
predicateLength: predicate.length,
|
1082
|
+
predicateDataLength: predicateData.length,
|
1144
1083
|
predicate: hexlify3(predicate),
|
1145
1084
|
predicateData: hexlify3(predicateData),
|
1146
1085
|
data: hexlify3(data),
|
@@ -1215,7 +1154,7 @@ var outputify = (value) => {
|
|
1215
1154
|
|
1216
1155
|
// src/providers/transaction-request/transaction-request.ts
|
1217
1156
|
import { Address, addressify } from "@fuel-ts/address";
|
1218
|
-
import {
|
1157
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1219
1158
|
import { bn as bn7 } from "@fuel-ts/math";
|
1220
1159
|
import {
|
1221
1160
|
PolicyType,
|
@@ -1225,7 +1164,6 @@ import {
|
|
1225
1164
|
TransactionType
|
1226
1165
|
} from "@fuel-ts/transactions";
|
1227
1166
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1228
|
-
import { randomBytes } from "ethers";
|
1229
1167
|
|
1230
1168
|
// src/providers/resource.ts
|
1231
1169
|
var isRawCoin = (resource) => "utxoId" in resource;
|
@@ -1269,8 +1207,8 @@ function assembleReceiptByType(receipt) {
|
|
1269
1207
|
case "CALL" /* Call */: {
|
1270
1208
|
const callReceipt = {
|
1271
1209
|
type: ReceiptType.Call,
|
1272
|
-
from: hexOrZero(receipt.id
|
1273
|
-
to: hexOrZero(receipt?.to),
|
1210
|
+
from: hexOrZero(receipt.contract?.id),
|
1211
|
+
to: hexOrZero(receipt?.to?.id),
|
1274
1212
|
amount: bn4(receipt.amount),
|
1275
1213
|
assetId: hexOrZero(receipt.assetId),
|
1276
1214
|
gas: bn4(receipt.gas),
|
@@ -1284,7 +1222,7 @@ function assembleReceiptByType(receipt) {
|
|
1284
1222
|
case "RETURN" /* Return */: {
|
1285
1223
|
const returnReceipt = {
|
1286
1224
|
type: ReceiptType.Return,
|
1287
|
-
id: hexOrZero(receipt.id
|
1225
|
+
id: hexOrZero(receipt.contract?.id),
|
1288
1226
|
val: bn4(receipt.val),
|
1289
1227
|
pc: bn4(receipt.pc),
|
1290
1228
|
is: bn4(receipt.is)
|
@@ -1294,7 +1232,7 @@ function assembleReceiptByType(receipt) {
|
|
1294
1232
|
case "RETURN_DATA" /* ReturnData */: {
|
1295
1233
|
const returnDataReceipt = {
|
1296
1234
|
type: ReceiptType.ReturnData,
|
1297
|
-
id: hexOrZero(receipt.id
|
1235
|
+
id: hexOrZero(receipt.contract?.id),
|
1298
1236
|
ptr: bn4(receipt.ptr),
|
1299
1237
|
len: bn4(receipt.len),
|
1300
1238
|
digest: hexOrZero(receipt.digest),
|
@@ -1306,7 +1244,7 @@ function assembleReceiptByType(receipt) {
|
|
1306
1244
|
case "PANIC" /* Panic */: {
|
1307
1245
|
const panicReceipt = {
|
1308
1246
|
type: ReceiptType.Panic,
|
1309
|
-
id: hexOrZero(receipt.id),
|
1247
|
+
id: hexOrZero(receipt.contract?.id),
|
1310
1248
|
reason: bn4(receipt.reason),
|
1311
1249
|
pc: bn4(receipt.pc),
|
1312
1250
|
is: bn4(receipt.is),
|
@@ -1317,7 +1255,7 @@ function assembleReceiptByType(receipt) {
|
|
1317
1255
|
case "REVERT" /* Revert */: {
|
1318
1256
|
const revertReceipt = {
|
1319
1257
|
type: ReceiptType.Revert,
|
1320
|
-
id: hexOrZero(receipt.id
|
1258
|
+
id: hexOrZero(receipt.contract?.id),
|
1321
1259
|
val: bn4(receipt.ra),
|
1322
1260
|
pc: bn4(receipt.pc),
|
1323
1261
|
is: bn4(receipt.is)
|
@@ -1327,7 +1265,7 @@ function assembleReceiptByType(receipt) {
|
|
1327
1265
|
case "LOG" /* Log */: {
|
1328
1266
|
const logReceipt = {
|
1329
1267
|
type: ReceiptType.Log,
|
1330
|
-
id: hexOrZero(receipt.id
|
1268
|
+
id: hexOrZero(receipt.contract?.id),
|
1331
1269
|
val0: bn4(receipt.ra),
|
1332
1270
|
val1: bn4(receipt.rb),
|
1333
1271
|
val2: bn4(receipt.rc),
|
@@ -1340,7 +1278,7 @@ function assembleReceiptByType(receipt) {
|
|
1340
1278
|
case "LOG_DATA" /* LogData */: {
|
1341
1279
|
const logDataReceipt = {
|
1342
1280
|
type: ReceiptType.LogData,
|
1343
|
-
id: hexOrZero(receipt.id
|
1281
|
+
id: hexOrZero(receipt.contract?.id),
|
1344
1282
|
val0: bn4(receipt.ra),
|
1345
1283
|
val1: bn4(receipt.rb),
|
1346
1284
|
ptr: bn4(receipt.ptr),
|
@@ -1354,8 +1292,8 @@ function assembleReceiptByType(receipt) {
|
|
1354
1292
|
case "TRANSFER" /* Transfer */: {
|
1355
1293
|
const transferReceipt = {
|
1356
1294
|
type: ReceiptType.Transfer,
|
1357
|
-
from: hexOrZero(receipt.id
|
1358
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1295
|
+
from: hexOrZero(receipt.contract?.id),
|
1296
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1359
1297
|
amount: bn4(receipt.amount),
|
1360
1298
|
assetId: hexOrZero(receipt.assetId),
|
1361
1299
|
pc: bn4(receipt.pc),
|
@@ -1366,8 +1304,8 @@ function assembleReceiptByType(receipt) {
|
|
1366
1304
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1367
1305
|
const transferOutReceipt = {
|
1368
1306
|
type: ReceiptType.TransferOut,
|
1369
|
-
from: hexOrZero(receipt.id
|
1370
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1307
|
+
from: hexOrZero(receipt.contract?.id),
|
1308
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1371
1309
|
amount: bn4(receipt.amount),
|
1372
1310
|
assetId: hexOrZero(receipt.assetId),
|
1373
1311
|
pc: bn4(receipt.pc),
|
@@ -1410,7 +1348,7 @@ function assembleReceiptByType(receipt) {
|
|
1410
1348
|
return receiptMessageOut;
|
1411
1349
|
}
|
1412
1350
|
case "MINT" /* Mint */: {
|
1413
|
-
const contractId = hexOrZero(receipt.id
|
1351
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1414
1352
|
const subId = hexOrZero(receipt.subId);
|
1415
1353
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1416
1354
|
const mintReceipt = {
|
@@ -1425,7 +1363,7 @@ function assembleReceiptByType(receipt) {
|
|
1425
1363
|
return mintReceipt;
|
1426
1364
|
}
|
1427
1365
|
case "BURN" /* Burn */: {
|
1428
|
-
const contractId = hexOrZero(receipt.id
|
1366
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1429
1367
|
const subId = hexOrZero(receipt.subId);
|
1430
1368
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1431
1369
|
const burnReceipt = {
|
@@ -1510,6 +1448,7 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1510
1448
|
import { bn as bn5 } from "@fuel-ts/math";
|
1511
1449
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1512
1450
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1451
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1513
1452
|
var getGasUsedFromReceipts = (receipts) => {
|
1514
1453
|
const scriptResult = receipts.filter(
|
1515
1454
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1530,28 +1469,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1530
1469
|
}
|
1531
1470
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1532
1471
|
const witnessCache = [];
|
1533
|
-
const
|
1534
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1535
|
-
if (isCoinOrMessage) {
|
1536
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1537
|
-
return true;
|
1538
|
-
}
|
1539
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1540
|
-
witnessCache.push(input.witnessIndex);
|
1541
|
-
return true;
|
1542
|
-
}
|
1543
|
-
}
|
1544
|
-
return false;
|
1545
|
-
});
|
1546
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1547
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1472
|
+
const totalGas = inputs.reduce((total, input) => {
|
1548
1473
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1549
1474
|
return total.add(
|
1550
|
-
|
1475
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1551
1476
|
);
|
1552
1477
|
}
|
1553
|
-
|
1554
|
-
|
1478
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1479
|
+
witnessCache.push(input.witnessIndex);
|
1480
|
+
return total.add(gasCosts.ecr1);
|
1481
|
+
}
|
1482
|
+
return total;
|
1483
|
+
}, bn5());
|
1555
1484
|
return totalGas;
|
1556
1485
|
}
|
1557
1486
|
function getMinGas(params) {
|
@@ -1563,20 +1492,12 @@ function getMinGas(params) {
|
|
1563
1492
|
return minGas;
|
1564
1493
|
}
|
1565
1494
|
function getMaxGas(params) {
|
1566
|
-
const {
|
1567
|
-
gasPerByte,
|
1568
|
-
witnessesLength,
|
1569
|
-
witnessLimit,
|
1570
|
-
minGas,
|
1571
|
-
gasLimit = bn5(0),
|
1572
|
-
maxGasPerTx
|
1573
|
-
} = params;
|
1495
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
|
1574
1496
|
let remainingAllowedWitnessGas = bn5(0);
|
1575
1497
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1576
1498
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1577
1499
|
}
|
1578
|
-
|
1579
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1500
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1580
1501
|
}
|
1581
1502
|
function calculateMetadataGasForTxCreate({
|
1582
1503
|
gasCosts,
|
@@ -1598,10 +1519,6 @@ function calculateMetadataGasForTxScript({
|
|
1598
1519
|
}) {
|
1599
1520
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1600
1521
|
}
|
1601
|
-
var calculateGasFee = (params) => {
|
1602
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1603
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1604
|
-
};
|
1605
1522
|
|
1606
1523
|
// src/providers/utils/json.ts
|
1607
1524
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1758,7 +1675,7 @@ var witnessify = (value) => {
|
|
1758
1675
|
// src/providers/transaction-request/transaction-request.ts
|
1759
1676
|
var BaseTransactionRequest = class {
|
1760
1677
|
/** Gas price for transaction */
|
1761
|
-
|
1678
|
+
gasPrice;
|
1762
1679
|
/** Block until which tx cannot be included */
|
1763
1680
|
maturity;
|
1764
1681
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1771,34 +1688,38 @@ var BaseTransactionRequest = class {
|
|
1771
1688
|
outputs = [];
|
1772
1689
|
/** List of witnesses */
|
1773
1690
|
witnesses = [];
|
1691
|
+
/** Base asset ID - should be fetched from the chain */
|
1692
|
+
baseAssetId = ZeroBytes324;
|
1774
1693
|
/**
|
1775
1694
|
* Constructor for initializing a base transaction request.
|
1776
1695
|
*
|
1777
1696
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1778
1697
|
*/
|
1779
1698
|
constructor({
|
1780
|
-
|
1699
|
+
gasPrice,
|
1781
1700
|
maturity,
|
1782
1701
|
maxFee,
|
1783
1702
|
witnessLimit,
|
1784
1703
|
inputs,
|
1785
1704
|
outputs,
|
1786
|
-
witnesses
|
1705
|
+
witnesses,
|
1706
|
+
baseAssetId
|
1787
1707
|
} = {}) {
|
1788
|
-
this.
|
1708
|
+
this.gasPrice = bn7(gasPrice);
|
1789
1709
|
this.maturity = maturity ?? 0;
|
1790
1710
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1791
1711
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1792
1712
|
this.inputs = inputs ?? [];
|
1793
1713
|
this.outputs = outputs ?? [];
|
1794
1714
|
this.witnesses = witnesses ?? [];
|
1715
|
+
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1795
1716
|
}
|
1796
1717
|
static getPolicyMeta(req) {
|
1797
1718
|
let policyTypes = 0;
|
1798
1719
|
const policies = [];
|
1799
|
-
if (req.
|
1800
|
-
policyTypes += PolicyType.
|
1801
|
-
policies.push({ data: req.
|
1720
|
+
if (req.gasPrice) {
|
1721
|
+
policyTypes += PolicyType.GasPrice;
|
1722
|
+
policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
|
1802
1723
|
}
|
1803
1724
|
if (req.witnessLimit) {
|
1804
1725
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1985,10 +1906,10 @@ var BaseTransactionRequest = class {
|
|
1985
1906
|
* @param predicate - Predicate bytes.
|
1986
1907
|
* @param predicateData - Predicate data bytes.
|
1987
1908
|
*/
|
1988
|
-
addCoinInput(coin) {
|
1909
|
+
addCoinInput(coin, predicate) {
|
1989
1910
|
const { assetId, owner, amount } = coin;
|
1990
1911
|
let witnessIndex;
|
1991
|
-
if (
|
1912
|
+
if (predicate) {
|
1992
1913
|
witnessIndex = 0;
|
1993
1914
|
} else {
|
1994
1915
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2003,7 +1924,8 @@ var BaseTransactionRequest = class {
|
|
2003
1924
|
amount,
|
2004
1925
|
assetId,
|
2005
1926
|
txPointer: "0x00000000000000000000000000000000",
|
2006
|
-
witnessIndex
|
1927
|
+
witnessIndex,
|
1928
|
+
predicate: predicate?.bytes
|
2007
1929
|
};
|
2008
1930
|
this.pushInput(input);
|
2009
1931
|
this.addChangeOutput(owner, assetId);
|
@@ -2014,13 +1936,11 @@ var BaseTransactionRequest = class {
|
|
2014
1936
|
*
|
2015
1937
|
* @param message - Message resource.
|
2016
1938
|
* @param predicate - Predicate bytes.
|
2017
|
-
* @param predicateData - Predicate data bytes.
|
2018
1939
|
*/
|
2019
|
-
addMessageInput(message) {
|
1940
|
+
addMessageInput(message, predicate) {
|
2020
1941
|
const { recipient, sender, amount } = message;
|
2021
|
-
const assetId = BaseAssetId2;
|
2022
1942
|
let witnessIndex;
|
2023
|
-
if (
|
1943
|
+
if (predicate) {
|
2024
1944
|
witnessIndex = 0;
|
2025
1945
|
} else {
|
2026
1946
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2034,10 +1954,11 @@ var BaseTransactionRequest = class {
|
|
2034
1954
|
sender: sender.toB256(),
|
2035
1955
|
recipient: recipient.toB256(),
|
2036
1956
|
amount,
|
2037
|
-
witnessIndex
|
1957
|
+
witnessIndex,
|
1958
|
+
predicate: predicate?.bytes
|
2038
1959
|
};
|
2039
1960
|
this.pushInput(input);
|
2040
|
-
this.addChangeOutput(recipient,
|
1961
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
2041
1962
|
}
|
2042
1963
|
/**
|
2043
1964
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2065,6 +1986,32 @@ var BaseTransactionRequest = class {
|
|
2065
1986
|
resources.forEach((resource) => this.addResource(resource));
|
2066
1987
|
return this;
|
2067
1988
|
}
|
1989
|
+
/**
|
1990
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1991
|
+
* outputs from the related assetIds.
|
1992
|
+
*
|
1993
|
+
* @param resources - The resources to add.
|
1994
|
+
* @returns This transaction.
|
1995
|
+
*/
|
1996
|
+
addPredicateResource(resource, predicate) {
|
1997
|
+
if (isCoin(resource)) {
|
1998
|
+
this.addCoinInput(resource, predicate);
|
1999
|
+
} else {
|
2000
|
+
this.addMessageInput(resource, predicate);
|
2001
|
+
}
|
2002
|
+
return this;
|
2003
|
+
}
|
2004
|
+
/**
|
2005
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2006
|
+
* from the related assetIds.
|
2007
|
+
*
|
2008
|
+
* @param resources - The resources to add.
|
2009
|
+
* @returns This transaction.
|
2010
|
+
*/
|
2011
|
+
addPredicateResources(resources, predicate) {
|
2012
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2013
|
+
return this;
|
2014
|
+
}
|
2068
2015
|
/**
|
2069
2016
|
* Adds a coin output to the transaction.
|
2070
2017
|
*
|
@@ -2072,12 +2019,12 @@ var BaseTransactionRequest = class {
|
|
2072
2019
|
* @param amount - Amount of coin.
|
2073
2020
|
* @param assetId - Asset ID of coin.
|
2074
2021
|
*/
|
2075
|
-
addCoinOutput(to, amount, assetId
|
2022
|
+
addCoinOutput(to, amount, assetId) {
|
2076
2023
|
this.pushOutput({
|
2077
2024
|
type: OutputType2.Coin,
|
2078
2025
|
to: addressify(to).toB256(),
|
2079
2026
|
amount,
|
2080
|
-
assetId
|
2027
|
+
assetId: assetId ?? this.baseAssetId
|
2081
2028
|
});
|
2082
2029
|
return this;
|
2083
2030
|
}
|
@@ -2104,7 +2051,7 @@ var BaseTransactionRequest = class {
|
|
2104
2051
|
* @param to - Address of the owner.
|
2105
2052
|
* @param assetId - Asset ID of coin.
|
2106
2053
|
*/
|
2107
|
-
addChangeOutput(to, assetId
|
2054
|
+
addChangeOutput(to, assetId) {
|
2108
2055
|
const changeOutput = this.getChangeOutputs().find(
|
2109
2056
|
(output) => hexlify7(output.assetId) === assetId
|
2110
2057
|
);
|
@@ -2112,7 +2059,7 @@ var BaseTransactionRequest = class {
|
|
2112
2059
|
this.pushOutput({
|
2113
2060
|
type: OutputType2.Change,
|
2114
2061
|
to: addressify(to).toB256(),
|
2115
|
-
assetId
|
2062
|
+
assetId: assetId ?? this.baseAssetId
|
2116
2063
|
});
|
2117
2064
|
}
|
2118
2065
|
}
|
@@ -2144,7 +2091,7 @@ var BaseTransactionRequest = class {
|
|
2144
2091
|
}
|
2145
2092
|
calculateMaxGas(chainInfo, minGas) {
|
2146
2093
|
const { consensusParameters } = chainInfo;
|
2147
|
-
const { gasPerByte
|
2094
|
+
const { gasPerByte } = consensusParameters;
|
2148
2095
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2149
2096
|
(acc, wit) => acc + wit.dataLength,
|
2150
2097
|
0
|
@@ -2153,8 +2100,7 @@ var BaseTransactionRequest = class {
|
|
2153
2100
|
gasPerByte,
|
2154
2101
|
minGas,
|
2155
2102
|
witnessesLength,
|
2156
|
-
witnessLimit: this.witnessLimit
|
2157
|
-
maxGasPerTx
|
2103
|
+
witnessLimit: this.witnessLimit
|
2158
2104
|
});
|
2159
2105
|
}
|
2160
2106
|
/**
|
@@ -2164,6 +2110,12 @@ var BaseTransactionRequest = class {
|
|
2164
2110
|
* @param quantities - CoinQuantity Array.
|
2165
2111
|
*/
|
2166
2112
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2113
|
+
let idCounter = 0;
|
2114
|
+
const generateId = () => {
|
2115
|
+
const counterString = String(idCounter++);
|
2116
|
+
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2117
|
+
return id;
|
2118
|
+
};
|
2167
2119
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2168
2120
|
if ("assetId" in input) {
|
2169
2121
|
return input.assetId === assetId;
|
@@ -2172,27 +2124,24 @@ var BaseTransactionRequest = class {
|
|
2172
2124
|
});
|
2173
2125
|
const updateAssetInput = (assetId, quantity) => {
|
2174
2126
|
const assetInput = findAssetInput(assetId);
|
2175
|
-
let usedQuantity = quantity;
|
2176
|
-
if (assetId === BaseAssetId2) {
|
2177
|
-
usedQuantity = bn7("1000000000000000000");
|
2178
|
-
}
|
2179
2127
|
if (assetInput && "assetId" in assetInput) {
|
2180
|
-
assetInput.id =
|
2181
|
-
assetInput.amount =
|
2128
|
+
assetInput.id = generateId();
|
2129
|
+
assetInput.amount = quantity;
|
2182
2130
|
} else {
|
2183
2131
|
this.addResources([
|
2184
2132
|
{
|
2185
|
-
id:
|
2186
|
-
amount:
|
2133
|
+
id: generateId(),
|
2134
|
+
amount: quantity,
|
2187
2135
|
assetId,
|
2188
2136
|
owner: resourcesOwner || Address.fromRandom(),
|
2137
|
+
maturity: 0,
|
2189
2138
|
blockCreated: bn7(1),
|
2190
2139
|
txCreatedIdx: bn7(1)
|
2191
2140
|
}
|
2192
2141
|
]);
|
2193
2142
|
}
|
2194
2143
|
};
|
2195
|
-
updateAssetInput(
|
2144
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2196
2145
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2197
2146
|
}
|
2198
2147
|
/**
|
@@ -2217,7 +2166,7 @@ var BaseTransactionRequest = class {
|
|
2217
2166
|
toJSON() {
|
2218
2167
|
return normalizeJSON(this);
|
2219
2168
|
}
|
2220
|
-
|
2169
|
+
updatePredicateInputs(inputs) {
|
2221
2170
|
this.inputs.forEach((i) => {
|
2222
2171
|
let correspondingInput;
|
2223
2172
|
switch (i.type) {
|
@@ -2239,15 +2188,6 @@ var BaseTransactionRequest = class {
|
|
2239
2188
|
}
|
2240
2189
|
});
|
2241
2190
|
}
|
2242
|
-
shiftPredicateData() {
|
2243
|
-
this.inputs.forEach((input) => {
|
2244
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2245
|
-
input.predicateData = input.paddPredicateData(
|
2246
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2247
|
-
);
|
2248
|
-
}
|
2249
|
-
});
|
2250
|
-
}
|
2251
2191
|
};
|
2252
2192
|
|
2253
2193
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2394,8 +2334,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2394
2334
|
return {
|
2395
2335
|
type: TransactionType3.Create,
|
2396
2336
|
...baseTransaction,
|
2337
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2397
2338
|
bytecodeWitnessIndex,
|
2398
|
-
storageSlotsCount:
|
2339
|
+
storageSlotsCount: storageSlots.length,
|
2399
2340
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2400
2341
|
storageSlots
|
2401
2342
|
};
|
@@ -2518,8 +2459,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2518
2459
|
type: TransactionType4.Script,
|
2519
2460
|
scriptGasLimit: this.gasLimit,
|
2520
2461
|
...super.getBaseTransaction(),
|
2521
|
-
scriptLength:
|
2522
|
-
scriptDataLength:
|
2462
|
+
scriptLength: script.length,
|
2463
|
+
scriptDataLength: scriptData.length,
|
2523
2464
|
receiptsRoot: ZeroBytes327,
|
2524
2465
|
script: hexlify10(script),
|
2525
2466
|
scriptData: hexlify10(scriptData)
|
@@ -2583,7 +2524,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2583
2524
|
}
|
2584
2525
|
calculateMaxGas(chainInfo, minGas) {
|
2585
2526
|
const { consensusParameters } = chainInfo;
|
2586
|
-
const { gasPerByte
|
2527
|
+
const { gasPerByte } = consensusParameters;
|
2587
2528
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2588
2529
|
(acc, wit) => acc + wit.dataLength,
|
2589
2530
|
0
|
@@ -2593,8 +2534,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2593
2534
|
minGas,
|
2594
2535
|
witnessesLength,
|
2595
2536
|
witnessLimit: this.witnessLimit,
|
2596
|
-
gasLimit: this.gasLimit
|
2597
|
-
maxGasPerTx
|
2537
|
+
gasLimit: this.gasLimit
|
2598
2538
|
});
|
2599
2539
|
}
|
2600
2540
|
/**
|
@@ -2651,7 +2591,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2651
2591
|
|
2652
2592
|
// src/providers/transaction-request/utils.ts
|
2653
2593
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2654
|
-
import { TransactionType as TransactionType5
|
2594
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2655
2595
|
var transactionRequestify = (obj) => {
|
2656
2596
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2657
2597
|
return obj;
|
@@ -2669,31 +2609,14 @@ var transactionRequestify = (obj) => {
|
|
2669
2609
|
}
|
2670
2610
|
}
|
2671
2611
|
};
|
2672
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2673
|
-
(acc, input) => {
|
2674
|
-
if (input.type === InputType5.Coin && input.owner === owner) {
|
2675
|
-
acc.utxos.push(input.id);
|
2676
|
-
}
|
2677
|
-
if (input.type === InputType5.Message && input.recipient === owner) {
|
2678
|
-
acc.messages.push(input.nonce);
|
2679
|
-
}
|
2680
|
-
return acc;
|
2681
|
-
},
|
2682
|
-
{
|
2683
|
-
utxos: [],
|
2684
|
-
messages: []
|
2685
|
-
}
|
2686
|
-
);
|
2687
2612
|
|
2688
2613
|
// src/providers/transaction-response/transaction-response.ts
|
2689
2614
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2690
|
-
import { bn as
|
2615
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2691
2616
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2692
2617
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2693
2618
|
|
2694
2619
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2695
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
2696
|
-
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2697
2620
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2698
2621
|
|
2699
2622
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2702,10 +2625,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2702
2625
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2703
2626
|
var calculateTransactionFee = (params) => {
|
2704
2627
|
const {
|
2705
|
-
|
2628
|
+
gasUsed,
|
2706
2629
|
rawPayload,
|
2707
|
-
|
2708
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2630
|
+
consensusParameters: { gasCosts, feeParams }
|
2709
2631
|
} = params;
|
2710
2632
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2711
2633
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2715,7 +2637,8 @@ var calculateTransactionFee = (params) => {
|
|
2715
2637
|
return {
|
2716
2638
|
fee: bn11(0),
|
2717
2639
|
minFee: bn11(0),
|
2718
|
-
maxFee: bn11(0)
|
2640
|
+
maxFee: bn11(0),
|
2641
|
+
feeFromGasUsed: bn11(0)
|
2719
2642
|
};
|
2720
2643
|
}
|
2721
2644
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2747,6 +2670,7 @@ var calculateTransactionFee = (params) => {
|
|
2747
2670
|
metadataGas,
|
2748
2671
|
txBytesSize: transactionBytes.length
|
2749
2672
|
});
|
2673
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2750
2674
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2751
2675
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2752
2676
|
const maxGas = getMaxGas({
|
@@ -2754,25 +2678,17 @@ var calculateTransactionFee = (params) => {
|
|
2754
2678
|
minGas,
|
2755
2679
|
witnessesLength,
|
2756
2680
|
gasLimit,
|
2757
|
-
witnessLimit
|
2758
|
-
maxGasPerTx
|
2759
|
-
});
|
2760
|
-
const minFee = calculateGasFee({
|
2761
|
-
gasPrice,
|
2762
|
-
gas: minGas,
|
2763
|
-
priceFactor: gasPriceFactor,
|
2764
|
-
tip
|
2765
|
-
});
|
2766
|
-
const maxFee = calculateGasFee({
|
2767
|
-
gasPrice,
|
2768
|
-
gas: maxGas,
|
2769
|
-
priceFactor: gasPriceFactor,
|
2770
|
-
tip
|
2681
|
+
witnessLimit
|
2771
2682
|
});
|
2683
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2684
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2685
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2686
|
+
const fee = minFee.add(feeFromGasUsed);
|
2772
2687
|
return {
|
2688
|
+
fee,
|
2773
2689
|
minFee,
|
2774
2690
|
maxFee,
|
2775
|
-
|
2691
|
+
feeFromGasUsed
|
2776
2692
|
};
|
2777
2693
|
};
|
2778
2694
|
|
@@ -2828,7 +2744,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2828
2744
|
|
2829
2745
|
// src/providers/transaction-summary/input.ts
|
2830
2746
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2831
|
-
import { InputType as
|
2747
|
+
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2832
2748
|
function getInputsByTypes(inputs, types) {
|
2833
2749
|
return inputs.filter((i) => types.includes(i.type));
|
2834
2750
|
}
|
@@ -2836,16 +2752,16 @@ function getInputsByType(inputs, type) {
|
|
2836
2752
|
return inputs.filter((i) => i.type === type);
|
2837
2753
|
}
|
2838
2754
|
function getInputsCoin(inputs) {
|
2839
|
-
return getInputsByType(inputs,
|
2755
|
+
return getInputsByType(inputs, InputType5.Coin);
|
2840
2756
|
}
|
2841
2757
|
function getInputsMessage(inputs) {
|
2842
|
-
return getInputsByType(inputs,
|
2758
|
+
return getInputsByType(inputs, InputType5.Message);
|
2843
2759
|
}
|
2844
2760
|
function getInputsCoinAndMessage(inputs) {
|
2845
|
-
return getInputsByTypes(inputs, [
|
2761
|
+
return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
|
2846
2762
|
}
|
2847
2763
|
function getInputsContract(inputs) {
|
2848
|
-
return getInputsByType(inputs,
|
2764
|
+
return getInputsByType(inputs, InputType5.Contract);
|
2849
2765
|
}
|
2850
2766
|
function getInputFromAssetId(inputs, assetId) {
|
2851
2767
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2864,7 +2780,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2864
2780
|
if (!contractInput) {
|
2865
2781
|
return void 0;
|
2866
2782
|
}
|
2867
|
-
if (contractInput.type !==
|
2783
|
+
if (contractInput.type !== InputType5.Contract) {
|
2868
2784
|
throw new FuelError9(
|
2869
2785
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2870
2786
|
`Contract input should be of type 'contract'.`
|
@@ -2873,10 +2789,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2873
2789
|
return contractInput;
|
2874
2790
|
}
|
2875
2791
|
function getInputAccountAddress(input) {
|
2876
|
-
if (input.type ===
|
2792
|
+
if (input.type === InputType5.Coin) {
|
2877
2793
|
return input.owner.toString();
|
2878
2794
|
}
|
2879
|
-
if (input.type ===
|
2795
|
+
if (input.type === InputType5.Message) {
|
2880
2796
|
return input.recipient.toString();
|
2881
2797
|
}
|
2882
2798
|
return "";
|
@@ -3386,9 +3302,7 @@ function assembleTransactionSummary(params) {
|
|
3386
3302
|
gqlTransactionStatus,
|
3387
3303
|
abiMap = {},
|
3388
3304
|
maxInputs,
|
3389
|
-
gasCosts
|
3390
|
-
maxGasPerTx,
|
3391
|
-
gasPrice
|
3305
|
+
gasCosts
|
3392
3306
|
} = params;
|
3393
3307
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3394
3308
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3402,14 +3316,11 @@ function assembleTransactionSummary(params) {
|
|
3402
3316
|
maxInputs
|
3403
3317
|
});
|
3404
3318
|
const typeName = getTransactionTypeName(transaction.type);
|
3405
|
-
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3406
3319
|
const { fee } = calculateTransactionFee({
|
3407
|
-
|
3320
|
+
gasUsed,
|
3408
3321
|
rawPayload,
|
3409
|
-
tip,
|
3410
3322
|
consensusParameters: {
|
3411
3323
|
gasCosts,
|
3412
|
-
maxGasPerTx,
|
3413
3324
|
feeParams: {
|
3414
3325
|
gasPerByte,
|
3415
3326
|
gasPriceFactor
|
@@ -3469,7 +3380,7 @@ var TransactionResponse = class {
|
|
3469
3380
|
/** Current provider */
|
3470
3381
|
provider;
|
3471
3382
|
/** Gas used on the transaction */
|
3472
|
-
gasUsed =
|
3383
|
+
gasUsed = bn14(0);
|
3473
3384
|
/** The graphql Transaction with receipts object. */
|
3474
3385
|
gqlTransaction;
|
3475
3386
|
abis;
|
@@ -3547,13 +3458,8 @@ var TransactionResponse = class {
|
|
3547
3458
|
const decodedTransaction = this.decodeTransaction(
|
3548
3459
|
transaction
|
3549
3460
|
);
|
3550
|
-
|
3551
|
-
|
3552
|
-
txReceipts = transaction.status.receipts;
|
3553
|
-
}
|
3554
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3555
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3556
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3461
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3462
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3557
3463
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3558
3464
|
const transactionSummary = assembleTransactionSummary({
|
3559
3465
|
id: this.id,
|
@@ -3565,9 +3471,7 @@ var TransactionResponse = class {
|
|
3565
3471
|
gasPriceFactor,
|
3566
3472
|
abiMap: contractsAbiMap,
|
3567
3473
|
maxInputs,
|
3568
|
-
gasCosts
|
3569
|
-
maxGasPerTx,
|
3570
|
-
gasPrice
|
3474
|
+
gasCosts
|
3571
3475
|
});
|
3572
3476
|
return transactionSummary;
|
3573
3477
|
}
|
@@ -3694,29 +3598,30 @@ var processGqlChain = (chain) => {
|
|
3694
3598
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3695
3599
|
return {
|
3696
3600
|
name,
|
3697
|
-
baseChainHeight:
|
3601
|
+
baseChainHeight: bn15(daHeight),
|
3698
3602
|
consensusParameters: {
|
3699
|
-
contractMaxSize:
|
3700
|
-
maxInputs:
|
3701
|
-
maxOutputs:
|
3702
|
-
maxWitnesses:
|
3703
|
-
maxGasPerTx:
|
3704
|
-
maxScriptLength:
|
3705
|
-
maxScriptDataLength:
|
3706
|
-
maxStorageSlots:
|
3707
|
-
maxPredicateLength:
|
3708
|
-
maxPredicateDataLength:
|
3709
|
-
maxGasPerPredicate:
|
3710
|
-
gasPriceFactor:
|
3711
|
-
gasPerByte:
|
3712
|
-
maxMessageDataLength:
|
3713
|
-
chainId:
|
3603
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3604
|
+
maxInputs: bn15(txParams.maxInputs),
|
3605
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3606
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3607
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3608
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3609
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3610
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3611
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3612
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3613
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3614
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3615
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3616
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3617
|
+
chainId: bn15(consensusParameters.chainId),
|
3618
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3714
3619
|
gasCosts
|
3715
3620
|
},
|
3716
3621
|
gasCosts,
|
3717
3622
|
latestBlock: {
|
3718
3623
|
id: latestBlock.id,
|
3719
|
-
height:
|
3624
|
+
height: bn15(latestBlock.header.height),
|
3720
3625
|
time: latestBlock.header.time,
|
3721
3626
|
transactions: latestBlock.transactions.map((i) => ({
|
3722
3627
|
id: i.id
|
@@ -3810,8 +3715,10 @@ var _Provider = class {
|
|
3810
3715
|
* Returns some helpful parameters related to gas fees.
|
3811
3716
|
*/
|
3812
3717
|
getGasConfig() {
|
3718
|
+
const { minGasPrice } = this.getNode();
|
3813
3719
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3814
3720
|
return {
|
3721
|
+
minGasPrice,
|
3815
3722
|
maxGasPerTx,
|
3816
3723
|
maxGasPerPredicate,
|
3817
3724
|
gasPriceFactor,
|
@@ -3909,7 +3816,7 @@ var _Provider = class {
|
|
3909
3816
|
*/
|
3910
3817
|
async getBlockNumber() {
|
3911
3818
|
const { chain } = await this.operations.getChain();
|
3912
|
-
return
|
3819
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3913
3820
|
}
|
3914
3821
|
/**
|
3915
3822
|
* Returns the chain information.
|
@@ -3919,11 +3826,13 @@ var _Provider = class {
|
|
3919
3826
|
async fetchNode() {
|
3920
3827
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3921
3828
|
const processedNodeInfo = {
|
3922
|
-
maxDepth:
|
3923
|
-
maxTx:
|
3829
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3830
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3831
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3924
3832
|
nodeVersion: nodeInfo.nodeVersion,
|
3925
3833
|
utxoValidation: nodeInfo.utxoValidation,
|
3926
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3834
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3835
|
+
peers: nodeInfo.peers
|
3927
3836
|
};
|
3928
3837
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3929
3838
|
return processedNodeInfo;
|
@@ -3949,6 +3858,17 @@ var _Provider = class {
|
|
3949
3858
|
} = this.getChain();
|
3950
3859
|
return chainId.toNumber();
|
3951
3860
|
}
|
3861
|
+
/**
|
3862
|
+
* Returns the base asset ID
|
3863
|
+
*
|
3864
|
+
* @returns A promise that resolves to the base asset ID
|
3865
|
+
*/
|
3866
|
+
getBaseAssetId() {
|
3867
|
+
const {
|
3868
|
+
consensusParameters: { baseAssetId }
|
3869
|
+
} = this.getChain();
|
3870
|
+
return baseAssetId;
|
3871
|
+
}
|
3952
3872
|
/**
|
3953
3873
|
* Submits a transaction to the chain to be executed.
|
3954
3874
|
*
|
@@ -4009,13 +3929,14 @@ var _Provider = class {
|
|
4009
3929
|
return this.estimateTxDependencies(transactionRequest);
|
4010
3930
|
}
|
4011
3931
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
4012
|
-
const { dryRun:
|
4013
|
-
|
3932
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3933
|
+
encodedTransaction,
|
4014
3934
|
utxoValidation: utxoValidation || false
|
4015
3935
|
});
|
4016
|
-
const
|
4017
|
-
|
4018
|
-
|
3936
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3937
|
+
return {
|
3938
|
+
receipts
|
3939
|
+
};
|
4019
3940
|
}
|
4020
3941
|
/**
|
4021
3942
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4041,7 +3962,7 @@ var _Provider = class {
|
|
4041
3962
|
} = response;
|
4042
3963
|
if (inputs) {
|
4043
3964
|
inputs.forEach((input, index) => {
|
4044
|
-
if ("predicateGasUsed" in input &&
|
3965
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
4045
3966
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4046
3967
|
}
|
4047
3968
|
});
|
@@ -4054,6 +3975,9 @@ var _Provider = class {
|
|
4054
3975
|
* If there are missing variable outputs,
|
4055
3976
|
* `addVariableOutputs` is called on the transaction.
|
4056
3977
|
*
|
3978
|
+
* @privateRemarks
|
3979
|
+
* TODO: Investigate support for missing contract IDs
|
3980
|
+
* TODO: Add support for missing output messages
|
4057
3981
|
*
|
4058
3982
|
* @param transactionRequest - The transaction request object.
|
4059
3983
|
* @returns A promise.
|
@@ -4066,19 +3990,16 @@ var _Provider = class {
|
|
4066
3990
|
missingContractIds: []
|
4067
3991
|
};
|
4068
3992
|
}
|
3993
|
+
await this.estimatePredicates(transactionRequest);
|
4069
3994
|
let receipts = [];
|
4070
3995
|
const missingContractIds = [];
|
4071
3996
|
let outputVariables = 0;
|
4072
|
-
let dryrunStatus;
|
4073
3997
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4074
|
-
const {
|
4075
|
-
|
4076
|
-
} = await this.operations.dryRun({
|
4077
|
-
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
3998
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3999
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
4078
4000
|
utxoValidation: false
|
4079
4001
|
});
|
4080
|
-
receipts =
|
4081
|
-
dryrunStatus = status;
|
4002
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4082
4003
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4083
4004
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4084
4005
|
if (hasMissingOutputs) {
|
@@ -4088,11 +4009,6 @@ var _Provider = class {
|
|
4088
4009
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
4089
4010
|
missingContractIds.push(contractId);
|
4090
4011
|
});
|
4091
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4092
|
-
transactionRequest,
|
4093
|
-
optimizeGas: false
|
4094
|
-
});
|
4095
|
-
transactionRequest.maxFee = maxFee;
|
4096
4012
|
} else {
|
4097
4013
|
break;
|
4098
4014
|
}
|
@@ -4100,133 +4016,7 @@ var _Provider = class {
|
|
4100
4016
|
return {
|
4101
4017
|
receipts,
|
4102
4018
|
outputVariables,
|
4103
|
-
missingContractIds
|
4104
|
-
dryrunStatus
|
4105
|
-
};
|
4106
|
-
}
|
4107
|
-
/**
|
4108
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4109
|
-
*
|
4110
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4111
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4112
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4113
|
-
*
|
4114
|
-
* @param transactionRequests - Array of transaction request objects.
|
4115
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4116
|
-
*/
|
4117
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4118
|
-
const results = transactionRequests.map(() => ({
|
4119
|
-
receipts: [],
|
4120
|
-
outputVariables: 0,
|
4121
|
-
missingContractIds: [],
|
4122
|
-
dryrunStatus: void 0
|
4123
|
-
}));
|
4124
|
-
const allRequests = clone3(transactionRequests);
|
4125
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4126
|
-
allRequests.forEach((req, index) => {
|
4127
|
-
if (req.type === TransactionType8.Script) {
|
4128
|
-
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4129
|
-
}
|
4130
|
-
});
|
4131
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4132
|
-
let attempt = 0;
|
4133
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4134
|
-
const encodedTransactions = transactionsToProcess.map(
|
4135
|
-
(index) => serializedTransactionsMap.get(index)
|
4136
|
-
);
|
4137
|
-
const dryRunResults = await this.operations.dryRun({
|
4138
|
-
encodedTransactions,
|
4139
|
-
utxoValidation: false
|
4140
|
-
});
|
4141
|
-
const nextRoundTransactions = [];
|
4142
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4143
|
-
const currentResultIndex = transactionsToProcess[i];
|
4144
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4145
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4146
|
-
results[currentResultIndex].dryrunStatus = status;
|
4147
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4148
|
-
results[currentResultIndex].receipts
|
4149
|
-
);
|
4150
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4151
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4152
|
-
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4153
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4154
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4155
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4156
|
-
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4157
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4158
|
-
});
|
4159
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4160
|
-
transactionRequest: requestToProcess,
|
4161
|
-
optimizeGas: false
|
4162
|
-
});
|
4163
|
-
requestToProcess.maxFee = maxFee;
|
4164
|
-
serializedTransactionsMap.set(
|
4165
|
-
currentResultIndex,
|
4166
|
-
hexlify12(requestToProcess.toTransactionBytes())
|
4167
|
-
);
|
4168
|
-
nextRoundTransactions.push(currentResultIndex);
|
4169
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4170
|
-
}
|
4171
|
-
}
|
4172
|
-
transactionsToProcess = nextRoundTransactions;
|
4173
|
-
attempt += 1;
|
4174
|
-
}
|
4175
|
-
return results;
|
4176
|
-
}
|
4177
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4178
|
-
if (estimateTxDependencies) {
|
4179
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4180
|
-
}
|
4181
|
-
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4182
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4183
|
-
encodedTransactions,
|
4184
|
-
utxoValidation: utxoValidation || false
|
4185
|
-
});
|
4186
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4187
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4188
|
-
return { receipts, dryrunStatus: status };
|
4189
|
-
});
|
4190
|
-
return results;
|
4191
|
-
}
|
4192
|
-
async estimateTxGasAndFee(params) {
|
4193
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4194
|
-
let { gasPrice } = params;
|
4195
|
-
const chainInfo = this.getChain();
|
4196
|
-
const { gasPriceFactor } = this.getGasConfig();
|
4197
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4198
|
-
if (!gasPrice) {
|
4199
|
-
gasPrice = await this.estimateGasPrice(10);
|
4200
|
-
}
|
4201
|
-
const minFee = calculateGasFee({
|
4202
|
-
gasPrice: bn16(gasPrice),
|
4203
|
-
gas: minGas,
|
4204
|
-
priceFactor: gasPriceFactor,
|
4205
|
-
tip: transactionRequest.tip
|
4206
|
-
}).add(1);
|
4207
|
-
let gasLimit = bn16(0);
|
4208
|
-
if (transactionRequest.type === TransactionType8.Script) {
|
4209
|
-
gasLimit = transactionRequest.gasLimit;
|
4210
|
-
if (!optimizeGas) {
|
4211
|
-
transactionRequest.gasLimit = minGas;
|
4212
|
-
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4213
|
-
transactionRequest.gasLimit = gasLimit;
|
4214
|
-
}
|
4215
|
-
}
|
4216
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4217
|
-
const maxFee = calculateGasFee({
|
4218
|
-
gasPrice: bn16(gasPrice),
|
4219
|
-
gas: maxGas,
|
4220
|
-
priceFactor: gasPriceFactor,
|
4221
|
-
tip: transactionRequest.tip
|
4222
|
-
}).add(1);
|
4223
|
-
return {
|
4224
|
-
minGas,
|
4225
|
-
minFee,
|
4226
|
-
maxGas,
|
4227
|
-
maxFee,
|
4228
|
-
gasPrice,
|
4229
|
-
gasLimit
|
4019
|
+
missingContractIds
|
4230
4020
|
};
|
4231
4021
|
}
|
4232
4022
|
/**
|
@@ -4244,17 +4034,15 @@ var _Provider = class {
|
|
4244
4034
|
if (estimateTxDependencies) {
|
4245
4035
|
return this.estimateTxDependencies(transactionRequest);
|
4246
4036
|
}
|
4247
|
-
const
|
4248
|
-
const { dryRun:
|
4249
|
-
|
4037
|
+
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
4038
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4039
|
+
encodedTransaction,
|
4250
4040
|
utxoValidation: true
|
4251
4041
|
});
|
4252
|
-
const
|
4253
|
-
|
4254
|
-
|
4255
|
-
|
4256
|
-
});
|
4257
|
-
return { receipts: callResult[0].receipts };
|
4042
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4043
|
+
return {
|
4044
|
+
receipts
|
4045
|
+
};
|
4258
4046
|
}
|
4259
4047
|
/**
|
4260
4048
|
* Returns a transaction cost to enable user
|
@@ -4271,80 +4059,80 @@ var _Provider = class {
|
|
4271
4059
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4272
4060
|
* @returns A promise that resolves to the transaction cost object.
|
4273
4061
|
*/
|
4274
|
-
async getTransactionCost(transactionRequestLike,
|
4062
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4063
|
+
estimateTxDependencies = true,
|
4064
|
+
estimatePredicates = true,
|
4065
|
+
resourcesOwner,
|
4066
|
+
signatureCallback
|
4067
|
+
} = {}) {
|
4275
4068
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4069
|
+
const chainInfo = this.getChain();
|
4070
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4071
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4276
4072
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4277
4073
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4278
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4074
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4279
4075
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4280
|
-
|
4281
|
-
|
4282
|
-
|
4283
|
-
|
4284
|
-
|
4285
|
-
|
4076
|
+
if (estimatePredicates) {
|
4077
|
+
if (isScriptTransaction) {
|
4078
|
+
txRequestClone.gasLimit = bn15(0);
|
4079
|
+
}
|
4080
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4081
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4082
|
+
}
|
4083
|
+
await this.estimatePredicates(txRequestClone);
|
4286
4084
|
}
|
4287
|
-
const signedRequest = clone3(txRequestClone);
|
4288
|
-
let addedSignatures = 0;
|
4289
4085
|
if (signatureCallback && isScriptTransaction) {
|
4290
|
-
|
4291
|
-
|
4292
|
-
|
4293
|
-
|
4294
|
-
await this.estimatePredicates(signedRequest);
|
4295
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4296
|
-
transactionRequest: signedRequest,
|
4297
|
-
optimizeGas: false
|
4298
|
-
});
|
4299
|
-
txRequestClone.maxFee = maxFee;
|
4086
|
+
await signatureCallback(txRequestClone);
|
4087
|
+
}
|
4088
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4089
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4300
4090
|
let receipts = [];
|
4301
4091
|
let missingContractIds = [];
|
4302
4092
|
let outputVariables = 0;
|
4303
|
-
|
4304
|
-
|
4305
|
-
|
4306
|
-
if (signatureCallback) {
|
4307
|
-
await signatureCallback(txRequestClone);
|
4308
|
-
}
|
4309
|
-
txRequestClone.gasLimit = gasLimit;
|
4093
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4094
|
+
txRequestClone.gasPrice = bn15(0);
|
4095
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4310
4096
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4311
4097
|
receipts = result.receipts;
|
4312
4098
|
outputVariables = result.outputVariables;
|
4313
4099
|
missingContractIds = result.missingContractIds;
|
4314
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4315
|
-
txRequestClone.gasLimit = gasUsed;
|
4316
|
-
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4317
|
-
transactionRequest: txRequestClone,
|
4318
|
-
gasPrice
|
4319
|
-
}));
|
4320
4100
|
}
|
4101
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4102
|
+
const usedFee = calculatePriceWithFactor(
|
4103
|
+
gasUsed,
|
4104
|
+
gasPrice,
|
4105
|
+
gasPriceFactor
|
4106
|
+
).normalizeZeroToOne();
|
4107
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4108
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4321
4109
|
return {
|
4322
4110
|
requiredQuantities: allQuantities,
|
4323
4111
|
receipts,
|
4324
4112
|
gasUsed,
|
4113
|
+
minGasPrice,
|
4325
4114
|
gasPrice,
|
4326
4115
|
minGas,
|
4327
4116
|
maxGas,
|
4117
|
+
usedFee,
|
4328
4118
|
minFee,
|
4329
4119
|
maxFee,
|
4120
|
+
estimatedInputs: txRequestClone.inputs,
|
4330
4121
|
outputVariables,
|
4331
|
-
missingContractIds
|
4332
|
-
addedSignatures,
|
4333
|
-
estimatedPredicates: txRequestClone.inputs
|
4122
|
+
missingContractIds
|
4334
4123
|
};
|
4335
4124
|
}
|
4336
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4125
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4337
4126
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4338
4127
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4339
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4340
|
-
quantitiesToContract
|
4341
|
-
});
|
4128
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4342
4129
|
transactionRequest.addResources(
|
4343
4130
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4344
4131
|
);
|
4345
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4346
|
-
|
4347
|
-
|
4132
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4133
|
+
transactionRequest,
|
4134
|
+
forwardingQuantities
|
4135
|
+
);
|
4348
4136
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4349
4137
|
return {
|
4350
4138
|
resources,
|
@@ -4366,10 +4154,11 @@ var _Provider = class {
|
|
4366
4154
|
return coins.map((coin) => ({
|
4367
4155
|
id: coin.utxoId,
|
4368
4156
|
assetId: coin.assetId,
|
4369
|
-
amount:
|
4157
|
+
amount: bn15(coin.amount),
|
4370
4158
|
owner: Address2.fromAddressOrString(coin.owner),
|
4371
|
-
|
4372
|
-
|
4159
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4160
|
+
blockCreated: bn15(coin.blockCreated),
|
4161
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4373
4162
|
}));
|
4374
4163
|
}
|
4375
4164
|
/**
|
@@ -4406,9 +4195,9 @@ var _Provider = class {
|
|
4406
4195
|
switch (coin.__typename) {
|
4407
4196
|
case "MessageCoin":
|
4408
4197
|
return {
|
4409
|
-
amount:
|
4198
|
+
amount: bn15(coin.amount),
|
4410
4199
|
assetId: coin.assetId,
|
4411
|
-
daHeight:
|
4200
|
+
daHeight: bn15(coin.daHeight),
|
4412
4201
|
sender: Address2.fromAddressOrString(coin.sender),
|
4413
4202
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4414
4203
|
nonce: coin.nonce
|
@@ -4416,11 +4205,12 @@ var _Provider = class {
|
|
4416
4205
|
case "Coin":
|
4417
4206
|
return {
|
4418
4207
|
id: coin.utxoId,
|
4419
|
-
amount:
|
4208
|
+
amount: bn15(coin.amount),
|
4420
4209
|
assetId: coin.assetId,
|
4421
4210
|
owner: Address2.fromAddressOrString(coin.owner),
|
4422
|
-
|
4423
|
-
|
4211
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4212
|
+
blockCreated: bn15(coin.blockCreated),
|
4213
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4424
4214
|
};
|
4425
4215
|
default:
|
4426
4216
|
return null;
|
@@ -4437,13 +4227,13 @@ var _Provider = class {
|
|
4437
4227
|
async getBlock(idOrHeight) {
|
4438
4228
|
let variables;
|
4439
4229
|
if (typeof idOrHeight === "number") {
|
4440
|
-
variables = { height:
|
4230
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4441
4231
|
} else if (idOrHeight === "latest") {
|
4442
4232
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4443
4233
|
} else if (idOrHeight.length === 66) {
|
4444
4234
|
variables = { blockId: idOrHeight };
|
4445
4235
|
} else {
|
4446
|
-
variables = { blockId:
|
4236
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4447
4237
|
}
|
4448
4238
|
const { block } = await this.operations.getBlock(variables);
|
4449
4239
|
if (!block) {
|
@@ -4451,7 +4241,7 @@ var _Provider = class {
|
|
4451
4241
|
}
|
4452
4242
|
return {
|
4453
4243
|
id: block.id,
|
4454
|
-
height:
|
4244
|
+
height: bn15(block.header.height),
|
4455
4245
|
time: block.header.time,
|
4456
4246
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4457
4247
|
};
|
@@ -4466,7 +4256,7 @@ var _Provider = class {
|
|
4466
4256
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4467
4257
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4468
4258
|
id: block.id,
|
4469
|
-
height:
|
4259
|
+
height: bn15(block.header.height),
|
4470
4260
|
time: block.header.time,
|
4471
4261
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4472
4262
|
}));
|
@@ -4481,7 +4271,7 @@ var _Provider = class {
|
|
4481
4271
|
async getBlockWithTransactions(idOrHeight) {
|
4482
4272
|
let variables;
|
4483
4273
|
if (typeof idOrHeight === "number") {
|
4484
|
-
variables = { blockHeight:
|
4274
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4485
4275
|
} else if (idOrHeight === "latest") {
|
4486
4276
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4487
4277
|
} else {
|
@@ -4493,7 +4283,7 @@ var _Provider = class {
|
|
4493
4283
|
}
|
4494
4284
|
return {
|
4495
4285
|
id: block.id,
|
4496
|
-
height:
|
4286
|
+
height: bn15(block.header.height, 10),
|
4497
4287
|
time: block.header.time,
|
4498
4288
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4499
4289
|
transactions: block.transactions.map(
|
@@ -4542,7 +4332,7 @@ var _Provider = class {
|
|
4542
4332
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4543
4333
|
asset: hexlify12(assetId)
|
4544
4334
|
});
|
4545
|
-
return
|
4335
|
+
return bn15(contractBalance.amount, 10);
|
4546
4336
|
}
|
4547
4337
|
/**
|
4548
4338
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4556,7 +4346,7 @@ var _Provider = class {
|
|
4556
4346
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4557
4347
|
assetId: hexlify12(assetId)
|
4558
4348
|
});
|
4559
|
-
return
|
4349
|
+
return bn15(balance.amount, 10);
|
4560
4350
|
}
|
4561
4351
|
/**
|
4562
4352
|
* Returns balances for the given owner.
|
@@ -4574,7 +4364,7 @@ var _Provider = class {
|
|
4574
4364
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4575
4365
|
return balances.map((balance) => ({
|
4576
4366
|
assetId: balance.assetId,
|
4577
|
-
amount:
|
4367
|
+
amount: bn15(balance.amount)
|
4578
4368
|
}));
|
4579
4369
|
}
|
4580
4370
|
/**
|
@@ -4596,15 +4386,15 @@ var _Provider = class {
|
|
4596
4386
|
sender: message.sender,
|
4597
4387
|
recipient: message.recipient,
|
4598
4388
|
nonce: message.nonce,
|
4599
|
-
amount:
|
4389
|
+
amount: bn15(message.amount),
|
4600
4390
|
data: message.data
|
4601
4391
|
}),
|
4602
4392
|
sender: Address2.fromAddressOrString(message.sender),
|
4603
4393
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4604
4394
|
nonce: message.nonce,
|
4605
|
-
amount:
|
4395
|
+
amount: bn15(message.amount),
|
4606
4396
|
data: InputMessageCoder.decodeData(message.data),
|
4607
|
-
daHeight:
|
4397
|
+
daHeight: bn15(message.daHeight)
|
4608
4398
|
}));
|
4609
4399
|
}
|
4610
4400
|
/**
|
@@ -4657,52 +4447,44 @@ var _Provider = class {
|
|
4657
4447
|
} = result.messageProof;
|
4658
4448
|
return {
|
4659
4449
|
messageProof: {
|
4660
|
-
proofIndex:
|
4450
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4661
4451
|
proofSet: messageProof.proofSet
|
4662
4452
|
},
|
4663
4453
|
blockProof: {
|
4664
|
-
proofIndex:
|
4454
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4665
4455
|
proofSet: blockProof.proofSet
|
4666
4456
|
},
|
4667
4457
|
messageBlockHeader: {
|
4668
4458
|
id: messageBlockHeader.id,
|
4669
|
-
daHeight:
|
4670
|
-
transactionsCount:
|
4459
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4460
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4671
4461
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4672
|
-
height:
|
4462
|
+
height: bn15(messageBlockHeader.height),
|
4673
4463
|
prevRoot: messageBlockHeader.prevRoot,
|
4674
4464
|
time: messageBlockHeader.time,
|
4675
4465
|
applicationHash: messageBlockHeader.applicationHash,
|
4676
|
-
|
4466
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4467
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4677
4468
|
},
|
4678
4469
|
commitBlockHeader: {
|
4679
4470
|
id: commitBlockHeader.id,
|
4680
|
-
daHeight:
|
4681
|
-
transactionsCount:
|
4471
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4472
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4682
4473
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4683
|
-
height:
|
4474
|
+
height: bn15(commitBlockHeader.height),
|
4684
4475
|
prevRoot: commitBlockHeader.prevRoot,
|
4685
4476
|
time: commitBlockHeader.time,
|
4686
4477
|
applicationHash: commitBlockHeader.applicationHash,
|
4687
|
-
|
4478
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4479
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4688
4480
|
},
|
4689
4481
|
sender: Address2.fromAddressOrString(sender),
|
4690
4482
|
recipient: Address2.fromAddressOrString(recipient),
|
4691
4483
|
nonce,
|
4692
|
-
amount:
|
4484
|
+
amount: bn15(amount),
|
4693
4485
|
data
|
4694
4486
|
};
|
4695
4487
|
}
|
4696
|
-
async getLatestGasPrice() {
|
4697
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4698
|
-
return bn16(latestGasPrice.gasPrice);
|
4699
|
-
}
|
4700
|
-
async estimateGasPrice(blockHorizon) {
|
4701
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4702
|
-
blockHorizon: String(blockHorizon)
|
4703
|
-
});
|
4704
|
-
return bn16(estimateGasPrice.gasPrice);
|
4705
|
-
}
|
4706
4488
|
/**
|
4707
4489
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4708
4490
|
*
|
@@ -4722,10 +4504,10 @@ var _Provider = class {
|
|
4722
4504
|
*/
|
4723
4505
|
async produceBlocks(amount, startTime) {
|
4724
4506
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4725
|
-
blocksToProduce:
|
4507
|
+
blocksToProduce: bn15(amount).toString(10),
|
4726
4508
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4727
4509
|
});
|
4728
|
-
return
|
4510
|
+
return bn15(latestBlockHeight);
|
4729
4511
|
}
|
4730
4512
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4731
4513
|
async getTransactionResponse(transactionId) {
|
@@ -4739,7 +4521,7 @@ cacheInputs_fn = function(inputs) {
|
|
4739
4521
|
return;
|
4740
4522
|
}
|
4741
4523
|
inputs.forEach((input) => {
|
4742
|
-
if (input.type ===
|
4524
|
+
if (input.type === InputType6.Coin) {
|
4743
4525
|
this.cache?.set(input.id);
|
4744
4526
|
}
|
4745
4527
|
});
|
@@ -4749,7 +4531,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4749
4531
|
|
4750
4532
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4751
4533
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4752
|
-
import { bn as
|
4534
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4753
4535
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4754
4536
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4755
4537
|
async function getTransactionSummary(params) {
|
@@ -4767,28 +4549,21 @@ async function getTransactionSummary(params) {
|
|
4767
4549
|
arrayify12(gqlTransaction.rawPayload),
|
4768
4550
|
0
|
4769
4551
|
);
|
4770
|
-
|
4771
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4772
|
-
txReceipts = gqlTransaction.status.receipts;
|
4773
|
-
}
|
4774
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4552
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4775
4553
|
const {
|
4776
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4554
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4777
4555
|
} = provider.getChain();
|
4778
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4779
4556
|
const transactionInfo = assembleTransactionSummary({
|
4780
4557
|
id: gqlTransaction.id,
|
4781
4558
|
receipts,
|
4782
4559
|
transaction: decodedTransaction,
|
4783
4560
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4784
4561
|
gqlTransactionStatus: gqlTransaction.status,
|
4785
|
-
gasPerByte:
|
4786
|
-
gasPriceFactor:
|
4562
|
+
gasPerByte: bn16(gasPerByte),
|
4563
|
+
gasPriceFactor: bn16(gasPriceFactor),
|
4787
4564
|
abiMap,
|
4788
4565
|
maxInputs,
|
4789
|
-
gasCosts
|
4790
|
-
maxGasPerTx,
|
4791
|
-
gasPrice
|
4566
|
+
gasCosts
|
4792
4567
|
});
|
4793
4568
|
return {
|
4794
4569
|
gqlTransaction,
|
@@ -4798,11 +4573,10 @@ async function getTransactionSummary(params) {
|
|
4798
4573
|
async function getTransactionSummaryFromRequest(params) {
|
4799
4574
|
const { provider, transactionRequest, abiMap } = params;
|
4800
4575
|
const { receipts } = await provider.call(transactionRequest);
|
4801
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4576
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4802
4577
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4803
4578
|
const transaction = transactionRequest.toTransaction();
|
4804
4579
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4805
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4806
4580
|
const transactionSummary = assembleTransactionSummary({
|
4807
4581
|
receipts,
|
4808
4582
|
transaction,
|
@@ -4811,9 +4585,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4811
4585
|
gasPerByte,
|
4812
4586
|
gasPriceFactor,
|
4813
4587
|
maxInputs,
|
4814
|
-
gasCosts
|
4815
|
-
maxGasPerTx,
|
4816
|
-
gasPrice
|
4588
|
+
gasCosts
|
4817
4589
|
});
|
4818
4590
|
return transactionSummary;
|
4819
4591
|
}
|
@@ -4822,18 +4594,13 @@ async function getTransactionsSummaries(params) {
|
|
4822
4594
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4823
4595
|
const { edges, pageInfo } = transactionsByOwner;
|
4824
4596
|
const {
|
4825
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4597
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4826
4598
|
} = provider.getChain();
|
4827
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4828
4599
|
const transactions = edges.map((edge) => {
|
4829
4600
|
const { node: gqlTransaction } = edge;
|
4830
|
-
const { id, rawPayload, status } = gqlTransaction;
|
4601
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4831
4602
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4832
|
-
|
4833
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4834
|
-
txReceipts = gqlTransaction.status.receipts;
|
4835
|
-
}
|
4836
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4603
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4837
4604
|
const transactionSummary = assembleTransactionSummary({
|
4838
4605
|
id,
|
4839
4606
|
receipts,
|
@@ -4844,9 +4611,7 @@ async function getTransactionsSummaries(params) {
|
|
4844
4611
|
gasPerByte,
|
4845
4612
|
gasPriceFactor,
|
4846
4613
|
maxInputs,
|
4847
|
-
gasCosts
|
4848
|
-
maxGasPerTx,
|
4849
|
-
gasPrice
|
4614
|
+
gasCosts
|
4850
4615
|
});
|
4851
4616
|
const output = {
|
4852
4617
|
gqlTransaction,
|
@@ -5140,8 +4905,9 @@ var Account = class extends AbstractAccount {
|
|
5140
4905
|
* @param assetId - The asset ID to check the balance for.
|
5141
4906
|
* @returns A promise that resolves to the balance amount.
|
5142
4907
|
*/
|
5143
|
-
async getBalance(assetId
|
5144
|
-
const
|
4908
|
+
async getBalance(assetId) {
|
4909
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4910
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5145
4911
|
return amount;
|
5146
4912
|
}
|
5147
4913
|
/**
|
@@ -5178,33 +4944,37 @@ var Account = class extends AbstractAccount {
|
|
5178
4944
|
* @param fee - The estimated transaction fee.
|
5179
4945
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5180
4946
|
*/
|
5181
|
-
async fund(request,
|
5182
|
-
const
|
5183
|
-
const
|
5184
|
-
|
5185
|
-
|
5186
|
-
|
5187
|
-
coinQuantities: requiredQuantities
|
4947
|
+
async fund(request, coinQuantities, fee) {
|
4948
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4949
|
+
const updatedQuantities = addAmountToAsset({
|
4950
|
+
amount: bn17(fee),
|
4951
|
+
assetId: baseAssetId,
|
4952
|
+
coinQuantities
|
5188
4953
|
});
|
5189
4954
|
const quantitiesDict = {};
|
5190
|
-
|
4955
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5191
4956
|
quantitiesDict[assetId] = {
|
5192
4957
|
required: amount,
|
5193
|
-
owned:
|
4958
|
+
owned: bn17(0)
|
5194
4959
|
};
|
5195
4960
|
});
|
5196
|
-
|
4961
|
+
const cachedUtxos = [];
|
4962
|
+
const cachedMessages = [];
|
4963
|
+
const owner = this.address.toB256();
|
4964
|
+
request.inputs.forEach((input) => {
|
5197
4965
|
const isResource = "amount" in input;
|
5198
4966
|
if (isResource) {
|
5199
4967
|
const isCoin2 = "owner" in input;
|
5200
4968
|
if (isCoin2) {
|
5201
4969
|
const assetId = String(input.assetId);
|
5202
|
-
if (quantitiesDict[assetId]) {
|
5203
|
-
const amount =
|
4970
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4971
|
+
const amount = bn17(input.amount);
|
5204
4972
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4973
|
+
cachedUtxos.push(input.id);
|
5205
4974
|
}
|
5206
|
-
} else if (input.amount && quantitiesDict[
|
5207
|
-
quantitiesDict[
|
4975
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4976
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4977
|
+
cachedMessages.push(input.nonce);
|
5208
4978
|
}
|
5209
4979
|
}
|
5210
4980
|
});
|
@@ -5219,23 +4989,12 @@ var Account = class extends AbstractAccount {
|
|
5219
4989
|
});
|
5220
4990
|
const needsToBeFunded = missingQuantities.length;
|
5221
4991
|
if (needsToBeFunded) {
|
5222
|
-
const
|
5223
|
-
|
5224
|
-
|
5225
|
-
|
5226
|
-
|
5227
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5228
|
-
const requestToBeReEstimate = clone4(txRequest);
|
5229
|
-
if (addedSignatures) {
|
5230
|
-
Array.from({ length: addedSignatures }).forEach(
|
5231
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
5232
|
-
);
|
4992
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4993
|
+
messages: cachedMessages,
|
4994
|
+
utxos: cachedUtxos
|
4995
|
+
});
|
4996
|
+
request.addResources(resources);
|
5233
4997
|
}
|
5234
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5235
|
-
transactionRequest: requestToBeReEstimate
|
5236
|
-
});
|
5237
|
-
txRequest.maxFee = maxFee;
|
5238
|
-
return txRequest;
|
5239
4998
|
}
|
5240
4999
|
/**
|
5241
5000
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5243,25 +5002,29 @@ var Account = class extends AbstractAccount {
|
|
5243
5002
|
* @param destination - The address of the destination.
|
5244
5003
|
* @param amount - The amount of coins to transfer.
|
5245
5004
|
* @param assetId - The asset ID of the coins to transfer.
|
5246
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5005
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5247
5006
|
* @returns A promise that resolves to the prepared transaction request.
|
5248
5007
|
*/
|
5249
|
-
async createTransfer(destination, amount, assetId
|
5250
|
-
const
|
5251
|
-
|
5252
|
-
const
|
5008
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5009
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5010
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5011
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5012
|
+
const request = new ScriptTransactionRequest(params);
|
5013
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5014
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5253
5015
|
estimateTxDependencies: true,
|
5254
5016
|
resourcesOwner: this
|
5255
5017
|
});
|
5256
|
-
|
5257
|
-
|
5258
|
-
|
5259
|
-
|
5260
|
-
|
5261
|
-
|
5262
|
-
|
5263
|
-
|
5264
|
-
await this.fund(request,
|
5018
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
5019
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
5020
|
+
this.validateGas({
|
5021
|
+
gasUsed,
|
5022
|
+
gasPrice: request.gasPrice,
|
5023
|
+
gasLimit: request.gasLimit,
|
5024
|
+
minGasPrice
|
5025
|
+
});
|
5026
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5027
|
+
request.updatePredicateInputs(estimatedInputs);
|
5265
5028
|
return request;
|
5266
5029
|
}
|
5267
5030
|
/**
|
@@ -5273,14 +5036,15 @@ var Account = class extends AbstractAccount {
|
|
5273
5036
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5274
5037
|
* @returns A promise that resolves to the transaction response.
|
5275
5038
|
*/
|
5276
|
-
async transfer(destination, amount, assetId
|
5277
|
-
if (
|
5039
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5040
|
+
if (bn17(amount).lte(0)) {
|
5278
5041
|
throw new FuelError15(
|
5279
5042
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5280
5043
|
"Transfer amount must be a positive number."
|
5281
5044
|
);
|
5282
5045
|
}
|
5283
|
-
const
|
5046
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5047
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5284
5048
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5285
5049
|
}
|
5286
5050
|
/**
|
@@ -5292,38 +5056,40 @@ var Account = class extends AbstractAccount {
|
|
5292
5056
|
* @param txParams - The optional transaction parameters.
|
5293
5057
|
* @returns A promise that resolves to the transaction response.
|
5294
5058
|
*/
|
5295
|
-
async transferToContract(contractId, amount, assetId
|
5296
|
-
if (
|
5059
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5060
|
+
if (bn17(amount).lte(0)) {
|
5297
5061
|
throw new FuelError15(
|
5298
5062
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5299
5063
|
"Transfer amount must be a positive number."
|
5300
5064
|
);
|
5301
5065
|
}
|
5302
5066
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5067
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5068
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5069
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5303
5070
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5304
5071
|
hexlifiedContractId: contractAddress.toB256(),
|
5305
|
-
amountToTransfer:
|
5306
|
-
assetId
|
5072
|
+
amountToTransfer: bn17(amount),
|
5073
|
+
assetId: assetIdToTransfer
|
5307
5074
|
});
|
5308
5075
|
const request = new ScriptTransactionRequest({
|
5309
|
-
...
|
5076
|
+
...params,
|
5310
5077
|
script,
|
5311
5078
|
scriptData
|
5312
5079
|
});
|
5313
5080
|
request.addContractInputAndOutput(contractAddress);
|
5314
|
-
const
|
5315
|
-
|
5316
|
-
|
5081
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5082
|
+
request,
|
5083
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
5084
|
+
);
|
5085
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5086
|
+
this.validateGas({
|
5087
|
+
gasUsed,
|
5088
|
+
gasPrice: request.gasPrice,
|
5089
|
+
gasLimit: request.gasLimit,
|
5090
|
+
minGasPrice
|
5317
5091
|
});
|
5318
|
-
|
5319
|
-
this.validateGas({
|
5320
|
-
gasUsed: txCost.gasUsed,
|
5321
|
-
gasLimit: request.gasLimit
|
5322
|
-
});
|
5323
|
-
}
|
5324
|
-
request.gasLimit = txCost.gasUsed;
|
5325
|
-
request.maxFee = txCost.maxFee;
|
5326
|
-
await this.fund(request, txCost);
|
5092
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5327
5093
|
return this.sendTransaction(request);
|
5328
5094
|
}
|
5329
5095
|
/**
|
@@ -5335,31 +5101,35 @@ var Account = class extends AbstractAccount {
|
|
5335
5101
|
* @returns A promise that resolves to the transaction response.
|
5336
5102
|
*/
|
5337
5103
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5104
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5105
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5338
5106
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5339
5107
|
const recipientDataArray = arrayify14(
|
5340
5108
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5341
5109
|
);
|
5342
5110
|
const amountDataArray = arrayify14(
|
5343
|
-
"0x".concat(
|
5111
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5344
5112
|
);
|
5345
5113
|
const script = new Uint8Array([
|
5346
5114
|
...arrayify14(withdrawScript.bytes),
|
5347
5115
|
...recipientDataArray,
|
5348
5116
|
...amountDataArray
|
5349
5117
|
]);
|
5350
|
-
const params = { script, ...txParams };
|
5118
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5351
5119
|
const request = new ScriptTransactionRequest(params);
|
5352
|
-
const
|
5353
|
-
const
|
5354
|
-
|
5355
|
-
|
5356
|
-
|
5357
|
-
|
5358
|
-
|
5359
|
-
|
5360
|
-
|
5361
|
-
|
5362
|
-
|
5120
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
5121
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5122
|
+
request,
|
5123
|
+
forwardingQuantities
|
5124
|
+
);
|
5125
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5126
|
+
this.validateGas({
|
5127
|
+
gasUsed,
|
5128
|
+
gasPrice: request.gasPrice,
|
5129
|
+
gasLimit: request.gasLimit,
|
5130
|
+
minGasPrice
|
5131
|
+
});
|
5132
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5363
5133
|
return this.sendTransaction(request);
|
5364
5134
|
}
|
5365
5135
|
async signMessage(message) {
|
@@ -5417,7 +5187,18 @@ var Account = class extends AbstractAccount {
|
|
5417
5187
|
}
|
5418
5188
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5419
5189
|
}
|
5420
|
-
validateGas({
|
5190
|
+
validateGas({
|
5191
|
+
gasUsed,
|
5192
|
+
gasPrice,
|
5193
|
+
gasLimit,
|
5194
|
+
minGasPrice
|
5195
|
+
}) {
|
5196
|
+
if (minGasPrice.gt(gasPrice)) {
|
5197
|
+
throw new FuelError15(
|
5198
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5199
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5200
|
+
);
|
5201
|
+
}
|
5421
5202
|
if (gasUsed.gt(gasLimit)) {
|
5422
5203
|
throw new FuelError15(
|
5423
5204
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5433,7 +5214,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5433
5214
|
|
5434
5215
|
// src/signer/signer.ts
|
5435
5216
|
import { Address as Address4 } from "@fuel-ts/address";
|
5436
|
-
import { randomBytes
|
5217
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
5437
5218
|
import { hash } from "@fuel-ts/hasher";
|
5438
5219
|
import { toBytes } from "@fuel-ts/math";
|
5439
5220
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5526,7 +5307,7 @@ var Signer = class {
|
|
5526
5307
|
* @returns random 32-byte hashed
|
5527
5308
|
*/
|
5528
5309
|
static generatePrivateKey(entropy) {
|
5529
|
-
return entropy ? hash(concat3([
|
5310
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5530
5311
|
}
|
5531
5312
|
/**
|
5532
5313
|
* Extended publicKey from a compact publicKey
|
@@ -5545,7 +5326,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5545
5326
|
import {
|
5546
5327
|
bufferFromString,
|
5547
5328
|
keccak256,
|
5548
|
-
randomBytes as
|
5329
|
+
randomBytes as randomBytes2,
|
5549
5330
|
scrypt,
|
5550
5331
|
stringFromBuffer,
|
5551
5332
|
decryptJsonWalletData,
|
@@ -5568,7 +5349,7 @@ var removeHexPrefix = (hexString) => {
|
|
5568
5349
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5569
5350
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5570
5351
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5571
|
-
const salt =
|
5352
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5572
5353
|
const key = scrypt({
|
5573
5354
|
password: bufferFromString(password),
|
5574
5355
|
salt,
|
@@ -5577,7 +5358,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5577
5358
|
r: DEFAULT_KDF_PARAMS_R,
|
5578
5359
|
p: DEFAULT_KDF_PARAMS_P
|
5579
5360
|
});
|
5580
|
-
const iv =
|
5361
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5581
5362
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5582
5363
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5583
5364
|
const macHashUint8Array = keccak256(data);
|
@@ -5713,7 +5494,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5713
5494
|
* @param transactionRequestLike - The transaction request to send.
|
5714
5495
|
* @returns A promise that resolves to the TransactionResponse object.
|
5715
5496
|
*/
|
5716
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5497
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5717
5498
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5718
5499
|
if (estimateTxDependencies) {
|
5719
5500
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5754,12 +5535,12 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5754
5535
|
// src/hdwallet/hdwallet.ts
|
5755
5536
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5756
5537
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5757
|
-
import { bn as
|
5538
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5758
5539
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5759
5540
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5760
5541
|
|
5761
5542
|
// src/mnemonic/mnemonic.ts
|
5762
|
-
import { randomBytes as
|
5543
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5763
5544
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5764
5545
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5765
5546
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -8120,7 +7901,7 @@ var Mnemonic = class {
|
|
8120
7901
|
* @returns A randomly generated mnemonic
|
8121
7902
|
*/
|
8122
7903
|
static generate(size = 32, extraEntropy = "") {
|
8123
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7904
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
8124
7905
|
return Mnemonic.entropyToMnemonic(entropy);
|
8125
7906
|
}
|
8126
7907
|
};
|
@@ -8226,7 +8007,7 @@ var HDWallet = class {
|
|
8226
8007
|
const IR = bytes.slice(32);
|
8227
8008
|
if (privateKey) {
|
8228
8009
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8229
|
-
const ki =
|
8010
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
8230
8011
|
return new HDWallet({
|
8231
8012
|
privateKey: ki,
|
8232
8013
|
chainCode: IR,
|
@@ -8913,9 +8694,8 @@ import {
|
|
8913
8694
|
SCRIPT_FIXED_SIZE
|
8914
8695
|
} from "@fuel-ts/abi-coder";
|
8915
8696
|
import { Address as Address9 } from "@fuel-ts/address";
|
8916
|
-
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8917
8697
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8918
|
-
import { ByteArrayCoder, InputType as
|
8698
|
+
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8919
8699
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8920
8700
|
|
8921
8701
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -8934,7 +8714,6 @@ var getPredicateRoot = (bytecode) => {
|
|
8934
8714
|
// src/predicate/predicate.ts
|
8935
8715
|
var Predicate = class extends Account {
|
8936
8716
|
bytes;
|
8937
|
-
predicateDataBytes = Uint8Array.from([]);
|
8938
8717
|
predicateData = [];
|
8939
8718
|
interface;
|
8940
8719
|
/**
|
@@ -8964,7 +8743,6 @@ var Predicate = class extends Account {
|
|
8964
8743
|
this.interface = predicateInterface;
|
8965
8744
|
if (inputData !== void 0 && inputData.length > 0) {
|
8966
8745
|
this.predicateData = inputData;
|
8967
|
-
this.predicateDataBytes = this.getPredicateData(0);
|
8968
8746
|
}
|
8969
8747
|
}
|
8970
8748
|
/**
|
@@ -8977,9 +8755,9 @@ var Predicate = class extends Account {
|
|
8977
8755
|
const request = transactionRequestify(transactionRequestLike);
|
8978
8756
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8979
8757
|
request.inputs?.forEach((input) => {
|
8980
|
-
if (input.type ===
|
8981
|
-
input.predicate =
|
8982
|
-
input.predicateData =
|
8758
|
+
if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
8759
|
+
input.predicate = this.bytes;
|
8760
|
+
input.predicateData = this.getPredicateData(policies.length);
|
8983
8761
|
}
|
8984
8762
|
});
|
8985
8763
|
return request;
|
@@ -8993,8 +8771,10 @@ var Predicate = class extends Account {
|
|
8993
8771
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8994
8772
|
* @returns A promise that resolves to the prepared transaction request.
|
8995
8773
|
*/
|
8996
|
-
async createTransfer(destination, amount, assetId
|
8997
|
-
|
8774
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8775
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
8776
|
+
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8777
|
+
return this.populateTransactionPredicateData(request);
|
8998
8778
|
}
|
8999
8779
|
/**
|
9000
8780
|
* Sends a transaction with the populated predicate data.
|
@@ -9002,9 +8782,9 @@ var Predicate = class extends Account {
|
|
9002
8782
|
* @param transactionRequestLike - The transaction request-like object.
|
9003
8783
|
* @returns A promise that resolves to the transaction response.
|
9004
8784
|
*/
|
9005
|
-
sendTransaction(transactionRequestLike) {
|
9006
|
-
const transactionRequest =
|
9007
|
-
return super.sendTransaction(transactionRequest,
|
8785
|
+
sendTransaction(transactionRequestLike, options) {
|
8786
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8787
|
+
return super.sendTransaction(transactionRequest, options);
|
9008
8788
|
}
|
9009
8789
|
/**
|
9010
8790
|
* Simulates a transaction with the populated predicate data.
|
@@ -9013,8 +8793,8 @@ var Predicate = class extends Account {
|
|
9013
8793
|
* @returns A promise that resolves to the call result.
|
9014
8794
|
*/
|
9015
8795
|
simulateTransaction(transactionRequestLike) {
|
9016
|
-
const transactionRequest =
|
9017
|
-
return super.simulateTransaction(transactionRequest
|
8796
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8797
|
+
return super.simulateTransaction(transactionRequest);
|
9018
8798
|
}
|
9019
8799
|
getPredicateData(policiesLength) {
|
9020
8800
|
if (!this.predicateData.length) {
|
@@ -9060,26 +8840,6 @@ var Predicate = class extends Account {
|
|
9060
8840
|
predicateInterface: abiInterface
|
9061
8841
|
};
|
9062
8842
|
}
|
9063
|
-
/**
|
9064
|
-
* Retrieves resources satisfying the spend query for the account.
|
9065
|
-
*
|
9066
|
-
* @param quantities - IDs of coins to exclude.
|
9067
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
9068
|
-
* @returns A promise that resolves to an array of Resources.
|
9069
|
-
*/
|
9070
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
9071
|
-
const resources = await this.provider.getResourcesToSpend(
|
9072
|
-
this.address,
|
9073
|
-
quantities,
|
9074
|
-
excludedIds
|
9075
|
-
);
|
9076
|
-
return resources.map((resource) => ({
|
9077
|
-
...resource,
|
9078
|
-
predicate: hexlify19(this.bytes),
|
9079
|
-
predicateData: hexlify19(this.predicateDataBytes),
|
9080
|
-
paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9081
|
-
}));
|
9082
|
-
}
|
9083
8843
|
/**
|
9084
8844
|
* Sets the configurable constants for the predicate.
|
9085
8845
|
*
|
@@ -9828,7 +9588,7 @@ export {
|
|
9828
9588
|
WalletLocked,
|
9829
9589
|
WalletManager,
|
9830
9590
|
WalletUnlocked,
|
9831
|
-
|
9591
|
+
addAmountToAsset,
|
9832
9592
|
addOperation,
|
9833
9593
|
assemblePanicError,
|
9834
9594
|
assembleReceiptByType,
|
@@ -9837,10 +9597,9 @@ export {
|
|
9837
9597
|
assets,
|
9838
9598
|
buildBlockExplorerUrl,
|
9839
9599
|
cacheFor,
|
9840
|
-
cacheTxInputsFromOwner,
|
9841
|
-
calculateGasFee,
|
9842
9600
|
calculateMetadataGasForTxCreate,
|
9843
9601
|
calculateMetadataGasForTxScript,
|
9602
|
+
calculatePriceWithFactor,
|
9844
9603
|
calculateTransactionFee,
|
9845
9604
|
coinQuantityfy,
|
9846
9605
|
deferPromise,
|