@fuel-ts/account 0.0.0-rc-2037-20240423134048 → 0.0.0-rc-2021-20240423134551
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +829 -600
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +857 -637
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +680 -455
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +11 -18
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +822 -328
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +6 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -27
- 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/index.d.ts +0 -1
- package/dist/providers/transaction-request/index.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 +6 -7
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/index.d.ts +0 -1
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1545 -1076
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +837 -612
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +674 -446
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
- package/dist/providers/transaction-request/helpers.d.ts +0 -10
- package/dist/providers/transaction-request/helpers.d.ts.map +0 -1
- package/dist/test-utils/resources.d.ts +0 -4
- package/dist/test-utils/resources.d.ts.map +0 -1
- package/dist/test-utils/transactionRequest.d.ts +0 -5
- package/dist/test-utils/transactionRequest.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
@@ -32,8 +32,9 @@ import { Address as Address3 } from "@fuel-ts/address";
|
|
32
32
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
33
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
34
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
|
-
import { bn as
|
35
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
36
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
|
+
import { clone as clone4 } from "ramda";
|
37
38
|
|
38
39
|
// src/providers/coin-quantity.ts
|
39
40
|
import { BaseAssetId } from "@fuel-ts/address/configs";
|
@@ -42,24 +43,24 @@ import { hexlify } from "@fuel-ts/utils";
|
|
42
43
|
var coinQuantityfy = (coinQuantityLike) => {
|
43
44
|
let assetId;
|
44
45
|
let amount;
|
45
|
-
let
|
46
|
+
let max;
|
46
47
|
if (Array.isArray(coinQuantityLike)) {
|
47
48
|
amount = coinQuantityLike[0];
|
48
49
|
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
49
|
-
|
50
|
+
max = coinQuantityLike[2] ?? void 0;
|
50
51
|
} else {
|
51
52
|
amount = coinQuantityLike.amount;
|
52
53
|
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
53
|
-
|
54
|
+
max = coinQuantityLike.max ?? void 0;
|
54
55
|
}
|
55
56
|
const bnAmount = bn(amount);
|
56
57
|
return {
|
57
58
|
assetId: hexlify(assetId),
|
58
59
|
amount: bnAmount.lt(1) ? bn(1) : bnAmount,
|
59
|
-
max:
|
60
|
+
max: max ? bn(max) : void 0
|
60
61
|
};
|
61
62
|
};
|
62
|
-
var
|
63
|
+
var addAmountToCoinQuantities = (params) => {
|
63
64
|
const { amount, assetId } = params;
|
64
65
|
const coinQuantities = [...params.coinQuantities];
|
65
66
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -74,7 +75,7 @@ var addAmountToAsset = (params) => {
|
|
74
75
|
// src/providers/provider.ts
|
75
76
|
import { Address as Address2 } from "@fuel-ts/address";
|
76
77
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
77
|
-
import { BN, bn as
|
78
|
+
import { BN, bn as bn16 } from "@fuel-ts/math";
|
78
79
|
import {
|
79
80
|
InputType as InputType7,
|
80
81
|
TransactionType as TransactionType8,
|
@@ -90,16 +91,40 @@ import { clone as clone3 } from "ramda";
|
|
90
91
|
|
91
92
|
// src/providers/__generated__/operations.ts
|
92
93
|
import gql from "graphql-tag";
|
94
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
|
95
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
96
|
+
type: __typename
|
97
|
+
... on SubmittedStatus {
|
98
|
+
time
|
99
|
+
}
|
100
|
+
... on SuccessStatus {
|
101
|
+
block {
|
102
|
+
id
|
103
|
+
}
|
104
|
+
time
|
105
|
+
programState {
|
106
|
+
returnType
|
107
|
+
data
|
108
|
+
}
|
109
|
+
}
|
110
|
+
... on FailureStatus {
|
111
|
+
block {
|
112
|
+
id
|
113
|
+
}
|
114
|
+
time
|
115
|
+
reason
|
116
|
+
}
|
117
|
+
... on SqueezedOutStatus {
|
118
|
+
reason
|
119
|
+
}
|
120
|
+
}
|
121
|
+
`;
|
93
122
|
var ReceiptFragmentFragmentDoc = gql`
|
94
123
|
fragment receiptFragment on Receipt {
|
95
|
-
|
96
|
-
id
|
97
|
-
}
|
124
|
+
id
|
98
125
|
pc
|
99
126
|
is
|
100
|
-
to
|
101
|
-
id
|
102
|
-
}
|
127
|
+
to
|
103
128
|
toAddress
|
104
129
|
amount
|
105
130
|
assetId
|
@@ -137,10 +162,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
137
162
|
id
|
138
163
|
}
|
139
164
|
time
|
165
|
+
receipts {
|
166
|
+
...receiptFragment
|
167
|
+
}
|
140
168
|
programState {
|
141
169
|
returnType
|
142
170
|
data
|
143
171
|
}
|
172
|
+
receipts {
|
173
|
+
...receiptFragment
|
174
|
+
}
|
144
175
|
}
|
145
176
|
... on FailureStatus {
|
146
177
|
block {
|
@@ -148,26 +179,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
148
179
|
}
|
149
180
|
time
|
150
181
|
reason
|
182
|
+
receipts {
|
183
|
+
...receiptFragment
|
184
|
+
}
|
151
185
|
}
|
152
186
|
... on SqueezedOutStatus {
|
153
187
|
reason
|
154
188
|
}
|
155
189
|
}
|
156
|
-
`;
|
190
|
+
${ReceiptFragmentFragmentDoc}`;
|
157
191
|
var TransactionFragmentFragmentDoc = gql`
|
158
192
|
fragment transactionFragment on Transaction {
|
159
193
|
id
|
160
194
|
rawPayload
|
161
|
-
gasPrice
|
162
|
-
receipts {
|
163
|
-
...receiptFragment
|
164
|
-
}
|
165
195
|
status {
|
166
196
|
...transactionStatusFragment
|
167
197
|
}
|
168
198
|
}
|
169
|
-
${
|
170
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
199
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
171
200
|
var InputEstimatePredicatesFragmentFragmentDoc = gql`
|
172
201
|
fragment inputEstimatePredicatesFragment on Input {
|
173
202
|
... on InputCoin {
|
@@ -185,6 +214,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
|
|
185
214
|
}
|
186
215
|
}
|
187
216
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
217
|
+
var DryRunFailureStatusFragmentFragmentDoc = gql`
|
218
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
219
|
+
reason
|
220
|
+
programState {
|
221
|
+
returnType
|
222
|
+
data
|
223
|
+
}
|
224
|
+
}
|
225
|
+
`;
|
226
|
+
var DryRunSuccessStatusFragmentFragmentDoc = gql`
|
227
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
228
|
+
programState {
|
229
|
+
returnType
|
230
|
+
data
|
231
|
+
}
|
232
|
+
}
|
233
|
+
`;
|
234
|
+
var DryRunTransactionStatusFragmentFragmentDoc = gql`
|
235
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
236
|
+
... on DryRunFailureStatus {
|
237
|
+
...dryRunFailureStatusFragment
|
238
|
+
}
|
239
|
+
... on DryRunSuccessStatus {
|
240
|
+
...dryRunSuccessStatusFragment
|
241
|
+
}
|
242
|
+
}
|
243
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
244
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
245
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
|
246
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
247
|
+
id
|
248
|
+
status {
|
249
|
+
...dryRunTransactionStatusFragment
|
250
|
+
}
|
251
|
+
receipts {
|
252
|
+
...receiptFragment
|
253
|
+
}
|
254
|
+
}
|
255
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
256
|
+
${ReceiptFragmentFragmentDoc}`;
|
188
257
|
var CoinFragmentFragmentDoc = gql`
|
189
258
|
fragment coinFragment on Coin {
|
190
259
|
__typename
|
@@ -192,7 +261,6 @@ var CoinFragmentFragmentDoc = gql`
|
|
192
261
|
owner
|
193
262
|
amount
|
194
263
|
assetId
|
195
|
-
maturity
|
196
264
|
blockCreated
|
197
265
|
txCreatedIdx
|
198
266
|
}
|
@@ -231,26 +299,32 @@ var MessageProofFragmentFragmentDoc = gql`
|
|
231
299
|
messageBlockHeader {
|
232
300
|
id
|
233
301
|
daHeight
|
302
|
+
consensusParametersVersion
|
303
|
+
stateTransitionBytecodeVersion
|
234
304
|
transactionsCount
|
305
|
+
messageReceiptCount
|
235
306
|
transactionsRoot
|
307
|
+
messageOutboxRoot
|
308
|
+
eventInboxRoot
|
236
309
|
height
|
237
310
|
prevRoot
|
238
311
|
time
|
239
312
|
applicationHash
|
240
|
-
messageReceiptRoot
|
241
|
-
messageReceiptCount
|
242
313
|
}
|
243
314
|
commitBlockHeader {
|
244
315
|
id
|
245
316
|
daHeight
|
317
|
+
consensusParametersVersion
|
318
|
+
stateTransitionBytecodeVersion
|
246
319
|
transactionsCount
|
320
|
+
messageReceiptCount
|
247
321
|
transactionsRoot
|
322
|
+
messageOutboxRoot
|
323
|
+
eventInboxRoot
|
248
324
|
height
|
249
325
|
prevRoot
|
250
326
|
time
|
251
327
|
applicationHash
|
252
|
-
messageReceiptRoot
|
253
|
-
messageReceiptCount
|
254
328
|
}
|
255
329
|
sender
|
256
330
|
recipient
|
@@ -269,8 +343,8 @@ var BalanceFragmentFragmentDoc = gql`
|
|
269
343
|
var BlockFragmentFragmentDoc = gql`
|
270
344
|
fragment blockFragment on Block {
|
271
345
|
id
|
346
|
+
height
|
272
347
|
header {
|
273
|
-
height
|
274
348
|
time
|
275
349
|
}
|
276
350
|
transactions {
|
@@ -328,6 +402,11 @@ var DependentCostFragmentFragmentDoc = gql`
|
|
328
402
|
`;
|
329
403
|
var GasCostsFragmentFragmentDoc = gql`
|
330
404
|
fragment GasCostsFragment on GasCosts {
|
405
|
+
version {
|
406
|
+
... on Version {
|
407
|
+
value
|
408
|
+
}
|
409
|
+
}
|
331
410
|
add
|
332
411
|
addi
|
333
412
|
aloc
|
@@ -340,7 +419,6 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
340
419
|
cb
|
341
420
|
cfei
|
342
421
|
cfsi
|
343
|
-
croo
|
344
422
|
div
|
345
423
|
divi
|
346
424
|
ecr1
|
@@ -423,6 +501,9 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
423
501
|
ccp {
|
424
502
|
...DependentCostFragment
|
425
503
|
}
|
504
|
+
croo {
|
505
|
+
...DependentCostFragment
|
506
|
+
}
|
426
507
|
csiz {
|
427
508
|
...DependentCostFragment
|
428
509
|
}
|
@@ -482,6 +563,11 @@ var GasCostsFragmentFragmentDoc = gql`
|
|
482
563
|
${DependentCostFragmentFragmentDoc}`;
|
483
564
|
var ConsensusParametersFragmentFragmentDoc = gql`
|
484
565
|
fragment consensusParametersFragment on ConsensusParameters {
|
566
|
+
version {
|
567
|
+
... on Version {
|
568
|
+
value
|
569
|
+
}
|
570
|
+
}
|
485
571
|
txParams {
|
486
572
|
...TxParametersFragment
|
487
573
|
}
|
@@ -541,18 +627,9 @@ var NodeInfoFragmentFragmentDoc = gql`
|
|
541
627
|
fragment nodeInfoFragment on NodeInfo {
|
542
628
|
utxoValidation
|
543
629
|
vmBacktrace
|
544
|
-
minGasPrice
|
545
630
|
maxTx
|
546
631
|
maxDepth
|
547
632
|
nodeVersion
|
548
|
-
peers {
|
549
|
-
id
|
550
|
-
addresses
|
551
|
-
clientVersion
|
552
|
-
blockHeight
|
553
|
-
lastHeartbeatMs
|
554
|
-
appScore
|
555
|
-
}
|
556
633
|
}
|
557
634
|
`;
|
558
635
|
var GetVersionDocument = gql`
|
@@ -587,13 +664,9 @@ var GetTransactionWithReceiptsDocument = gql`
|
|
587
664
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
588
665
|
transaction(id: $transactionId) {
|
589
666
|
...transactionFragment
|
590
|
-
receipts {
|
591
|
-
...receiptFragment
|
592
|
-
}
|
593
667
|
}
|
594
668
|
}
|
595
|
-
${TransactionFragmentFragmentDoc}
|
596
|
-
${ReceiptFragmentFragmentDoc}`;
|
669
|
+
${TransactionFragmentFragmentDoc}`;
|
597
670
|
var GetTransactionsDocument = gql`
|
598
671
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
599
672
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -721,6 +794,20 @@ var GetBalanceDocument = gql`
|
|
721
794
|
}
|
722
795
|
}
|
723
796
|
${BalanceFragmentFragmentDoc}`;
|
797
|
+
var GetLatestGasPriceDocument = gql`
|
798
|
+
query getLatestGasPrice {
|
799
|
+
latestGasPrice {
|
800
|
+
gasPrice
|
801
|
+
}
|
802
|
+
}
|
803
|
+
`;
|
804
|
+
var EstimateGasPriceDocument = gql`
|
805
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
806
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
807
|
+
gasPrice
|
808
|
+
}
|
809
|
+
}
|
810
|
+
`;
|
724
811
|
var GetBalancesDocument = gql`
|
725
812
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
726
813
|
balances(
|
@@ -775,12 +862,12 @@ var GetMessageStatusDocument = gql`
|
|
775
862
|
}
|
776
863
|
`;
|
777
864
|
var DryRunDocument = gql`
|
778
|
-
mutation dryRun($
|
779
|
-
dryRun(
|
780
|
-
...
|
865
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
866
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
867
|
+
...dryRunTransactionExecutionStatusFragment
|
781
868
|
}
|
782
869
|
}
|
783
|
-
${
|
870
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
784
871
|
var SubmitDocument = gql`
|
785
872
|
mutation submit($encodedTransaction: HexString!) {
|
786
873
|
submit(tx: $encodedTransaction) {
|
@@ -799,17 +886,17 @@ var ProduceBlocksDocument = gql`
|
|
799
886
|
var SubmitAndAwaitDocument = gql`
|
800
887
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
801
888
|
submitAndAwait(tx: $encodedTransaction) {
|
802
|
-
...
|
889
|
+
...transactionStatusSubscriptionFragment
|
803
890
|
}
|
804
891
|
}
|
805
|
-
${
|
892
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
806
893
|
var StatusChangeDocument = gql`
|
807
894
|
subscription statusChange($transactionId: TransactionId!) {
|
808
895
|
statusChange(id: $transactionId) {
|
809
|
-
...
|
896
|
+
...transactionStatusSubscriptionFragment
|
810
897
|
}
|
811
898
|
}
|
812
|
-
${
|
899
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
813
900
|
function getSdk(requester) {
|
814
901
|
return {
|
815
902
|
getVersion(variables, options) {
|
@@ -863,6 +950,12 @@ function getSdk(requester) {
|
|
863
950
|
getBalance(variables, options) {
|
864
951
|
return requester(GetBalanceDocument, variables, options);
|
865
952
|
},
|
953
|
+
getLatestGasPrice(variables, options) {
|
954
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
955
|
+
},
|
956
|
+
estimateGasPrice(variables, options) {
|
957
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
958
|
+
},
|
866
959
|
getBalances(variables, options) {
|
867
960
|
return requester(GetBalancesDocument, variables, options);
|
868
961
|
},
|
@@ -1056,10 +1149,9 @@ var inputify = (value) => {
|
|
1056
1149
|
txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
|
1057
1150
|
},
|
1058
1151
|
witnessIndex: value.witnessIndex,
|
1059
|
-
maturity: value.maturity ?? 0,
|
1060
1152
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1061
|
-
predicateLength: predicate.length,
|
1062
|
-
predicateDataLength: predicateData.length,
|
1153
|
+
predicateLength: bn2(predicate.length),
|
1154
|
+
predicateDataLength: bn2(predicateData.length),
|
1063
1155
|
predicate: hexlify3(predicate),
|
1064
1156
|
predicateData: hexlify3(predicateData)
|
1065
1157
|
};
|
@@ -1090,8 +1182,8 @@ var inputify = (value) => {
|
|
1090
1182
|
nonce: hexlify3(value.nonce),
|
1091
1183
|
witnessIndex: value.witnessIndex,
|
1092
1184
|
predicateGasUsed: bn2(value.predicateGasUsed),
|
1093
|
-
predicateLength: predicate.length,
|
1094
|
-
predicateDataLength: predicateData.length,
|
1185
|
+
predicateLength: bn2(predicate.length),
|
1186
|
+
predicateDataLength: bn2(predicateData.length),
|
1095
1187
|
predicate: hexlify3(predicate),
|
1096
1188
|
predicateData: hexlify3(predicateData),
|
1097
1189
|
data: hexlify3(data),
|
@@ -1173,7 +1265,7 @@ import { bn as bn7 } from "@fuel-ts/math";
|
|
1173
1265
|
import {
|
1174
1266
|
PolicyType,
|
1175
1267
|
TransactionCoder,
|
1176
|
-
InputType as
|
1268
|
+
InputType as InputType2,
|
1177
1269
|
OutputType as OutputType2,
|
1178
1270
|
TransactionType
|
1179
1271
|
} from "@fuel-ts/transactions";
|
@@ -1221,8 +1313,8 @@ function assembleReceiptByType(receipt) {
|
|
1221
1313
|
case "CALL" /* Call */: {
|
1222
1314
|
const callReceipt = {
|
1223
1315
|
type: ReceiptType.Call,
|
1224
|
-
from: hexOrZero(receipt.
|
1225
|
-
to: hexOrZero(receipt?.to
|
1316
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1317
|
+
to: hexOrZero(receipt?.to),
|
1226
1318
|
amount: bn4(receipt.amount),
|
1227
1319
|
assetId: hexOrZero(receipt.assetId),
|
1228
1320
|
gas: bn4(receipt.gas),
|
@@ -1236,7 +1328,7 @@ function assembleReceiptByType(receipt) {
|
|
1236
1328
|
case "RETURN" /* Return */: {
|
1237
1329
|
const returnReceipt = {
|
1238
1330
|
type: ReceiptType.Return,
|
1239
|
-
id: hexOrZero(receipt.
|
1331
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1240
1332
|
val: bn4(receipt.val),
|
1241
1333
|
pc: bn4(receipt.pc),
|
1242
1334
|
is: bn4(receipt.is)
|
@@ -1246,7 +1338,7 @@ function assembleReceiptByType(receipt) {
|
|
1246
1338
|
case "RETURN_DATA" /* ReturnData */: {
|
1247
1339
|
const returnDataReceipt = {
|
1248
1340
|
type: ReceiptType.ReturnData,
|
1249
|
-
id: hexOrZero(receipt.
|
1341
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1250
1342
|
ptr: bn4(receipt.ptr),
|
1251
1343
|
len: bn4(receipt.len),
|
1252
1344
|
digest: hexOrZero(receipt.digest),
|
@@ -1258,7 +1350,7 @@ function assembleReceiptByType(receipt) {
|
|
1258
1350
|
case "PANIC" /* Panic */: {
|
1259
1351
|
const panicReceipt = {
|
1260
1352
|
type: ReceiptType.Panic,
|
1261
|
-
id: hexOrZero(receipt.
|
1353
|
+
id: hexOrZero(receipt.id),
|
1262
1354
|
reason: bn4(receipt.reason),
|
1263
1355
|
pc: bn4(receipt.pc),
|
1264
1356
|
is: bn4(receipt.is),
|
@@ -1269,7 +1361,7 @@ function assembleReceiptByType(receipt) {
|
|
1269
1361
|
case "REVERT" /* Revert */: {
|
1270
1362
|
const revertReceipt = {
|
1271
1363
|
type: ReceiptType.Revert,
|
1272
|
-
id: hexOrZero(receipt.
|
1364
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1273
1365
|
val: bn4(receipt.ra),
|
1274
1366
|
pc: bn4(receipt.pc),
|
1275
1367
|
is: bn4(receipt.is)
|
@@ -1279,7 +1371,7 @@ function assembleReceiptByType(receipt) {
|
|
1279
1371
|
case "LOG" /* Log */: {
|
1280
1372
|
const logReceipt = {
|
1281
1373
|
type: ReceiptType.Log,
|
1282
|
-
id: hexOrZero(receipt.
|
1374
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1283
1375
|
val0: bn4(receipt.ra),
|
1284
1376
|
val1: bn4(receipt.rb),
|
1285
1377
|
val2: bn4(receipt.rc),
|
@@ -1292,7 +1384,7 @@ function assembleReceiptByType(receipt) {
|
|
1292
1384
|
case "LOG_DATA" /* LogData */: {
|
1293
1385
|
const logDataReceipt = {
|
1294
1386
|
type: ReceiptType.LogData,
|
1295
|
-
id: hexOrZero(receipt.
|
1387
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1296
1388
|
val0: bn4(receipt.ra),
|
1297
1389
|
val1: bn4(receipt.rb),
|
1298
1390
|
ptr: bn4(receipt.ptr),
|
@@ -1306,8 +1398,8 @@ function assembleReceiptByType(receipt) {
|
|
1306
1398
|
case "TRANSFER" /* Transfer */: {
|
1307
1399
|
const transferReceipt = {
|
1308
1400
|
type: ReceiptType.Transfer,
|
1309
|
-
from: hexOrZero(receipt.
|
1310
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1401
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1402
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1311
1403
|
amount: bn4(receipt.amount),
|
1312
1404
|
assetId: hexOrZero(receipt.assetId),
|
1313
1405
|
pc: bn4(receipt.pc),
|
@@ -1318,8 +1410,8 @@ function assembleReceiptByType(receipt) {
|
|
1318
1410
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1319
1411
|
const transferOutReceipt = {
|
1320
1412
|
type: ReceiptType.TransferOut,
|
1321
|
-
from: hexOrZero(receipt.
|
1322
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1413
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1414
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1323
1415
|
amount: bn4(receipt.amount),
|
1324
1416
|
assetId: hexOrZero(receipt.assetId),
|
1325
1417
|
pc: bn4(receipt.pc),
|
@@ -1362,7 +1454,7 @@ function assembleReceiptByType(receipt) {
|
|
1362
1454
|
return receiptMessageOut;
|
1363
1455
|
}
|
1364
1456
|
case "MINT" /* Mint */: {
|
1365
|
-
const contractId = hexOrZero(receipt.
|
1457
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1366
1458
|
const subId = hexOrZero(receipt.subId);
|
1367
1459
|
const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
|
1368
1460
|
const mintReceipt = {
|
@@ -1377,7 +1469,7 @@ function assembleReceiptByType(receipt) {
|
|
1377
1469
|
return mintReceipt;
|
1378
1470
|
}
|
1379
1471
|
case "BURN" /* Burn */: {
|
1380
|
-
const contractId = hexOrZero(receipt.
|
1472
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1381
1473
|
const subId = hexOrZero(receipt.subId);
|
1382
1474
|
const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
|
1383
1475
|
const burnReceipt = {
|
@@ -1462,7 +1554,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1462
1554
|
import { bn as bn5 } from "@fuel-ts/math";
|
1463
1555
|
import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
|
1464
1556
|
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1465
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1466
1557
|
var getGasUsedFromReceipts = (receipts) => {
|
1467
1558
|
const scriptResult = receipts.filter(
|
1468
1559
|
(receipt) => receipt.type === ReceiptType2.ScriptResult
|
@@ -1483,18 +1574,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1483
1574
|
}
|
1484
1575
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1485
1576
|
const witnessCache = [];
|
1486
|
-
const
|
1577
|
+
const chargeableInputs = inputs.filter((input) => {
|
1578
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1579
|
+
if (isCoinOrMessage) {
|
1580
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1581
|
+
return true;
|
1582
|
+
}
|
1583
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1584
|
+
witnessCache.push(input.witnessIndex);
|
1585
|
+
return true;
|
1586
|
+
}
|
1587
|
+
}
|
1588
|
+
return false;
|
1589
|
+
});
|
1590
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1591
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1487
1592
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1488
1593
|
return total.add(
|
1489
|
-
|
1594
|
+
vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
|
1490
1595
|
);
|
1491
1596
|
}
|
1492
|
-
|
1493
|
-
|
1494
|
-
return total.add(gasCosts.ecr1);
|
1495
|
-
}
|
1496
|
-
return total;
|
1497
|
-
}, bn5());
|
1597
|
+
return total.add(gasCosts.ecr1);
|
1598
|
+
}, bn5(0));
|
1498
1599
|
return totalGas;
|
1499
1600
|
}
|
1500
1601
|
function getMinGas(params) {
|
@@ -1506,12 +1607,20 @@ function getMinGas(params) {
|
|
1506
1607
|
return minGas;
|
1507
1608
|
}
|
1508
1609
|
function getMaxGas(params) {
|
1509
|
-
const {
|
1610
|
+
const {
|
1611
|
+
gasPerByte,
|
1612
|
+
witnessesLength,
|
1613
|
+
witnessLimit,
|
1614
|
+
minGas,
|
1615
|
+
gasLimit = bn5(0),
|
1616
|
+
maxGasPerTx
|
1617
|
+
} = params;
|
1510
1618
|
let remainingAllowedWitnessGas = bn5(0);
|
1511
1619
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1512
1620
|
remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1513
1621
|
}
|
1514
|
-
|
1622
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1623
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1515
1624
|
}
|
1516
1625
|
function calculateMetadataGasForTxCreate({
|
1517
1626
|
gasCosts,
|
@@ -1533,6 +1642,10 @@ function calculateMetadataGasForTxScript({
|
|
1533
1642
|
}) {
|
1534
1643
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1535
1644
|
}
|
1645
|
+
var calculateGasFee = (params) => {
|
1646
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1647
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1648
|
+
};
|
1536
1649
|
|
1537
1650
|
// src/providers/utils/json.ts
|
1538
1651
|
import { hexlify as hexlify5 } from "@fuel-ts/utils";
|
@@ -1676,28 +1789,6 @@ var NoWitnessByOwnerError = class extends Error {
|
|
1676
1789
|
name = "NoWitnessByOwnerError";
|
1677
1790
|
};
|
1678
1791
|
|
1679
|
-
// src/providers/transaction-request/helpers.ts
|
1680
|
-
import { InputType as InputType2 } from "@fuel-ts/transactions";
|
1681
|
-
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
1682
|
-
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
1683
|
-
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1684
|
-
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
1685
|
-
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
1686
|
-
var cacheResources = (resources) => resources.reduce(
|
1687
|
-
(cache2, resource) => {
|
1688
|
-
if (isCoin(resource)) {
|
1689
|
-
cache2.utxos.push(resource.id);
|
1690
|
-
} else {
|
1691
|
-
cache2.messages.push(resource.nonce);
|
1692
|
-
}
|
1693
|
-
return cache2;
|
1694
|
-
},
|
1695
|
-
{
|
1696
|
-
utxos: [],
|
1697
|
-
messages: []
|
1698
|
-
}
|
1699
|
-
);
|
1700
|
-
|
1701
1792
|
// src/providers/transaction-request/witness.ts
|
1702
1793
|
import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
|
1703
1794
|
var witnessify = (value) => {
|
@@ -1711,7 +1802,7 @@ var witnessify = (value) => {
|
|
1711
1802
|
// src/providers/transaction-request/transaction-request.ts
|
1712
1803
|
var BaseTransactionRequest = class {
|
1713
1804
|
/** Gas price for transaction */
|
1714
|
-
|
1805
|
+
tip;
|
1715
1806
|
/** Block until which tx cannot be included */
|
1716
1807
|
maturity;
|
1717
1808
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1730,7 +1821,7 @@ var BaseTransactionRequest = class {
|
|
1730
1821
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1731
1822
|
*/
|
1732
1823
|
constructor({
|
1733
|
-
|
1824
|
+
tip,
|
1734
1825
|
maturity,
|
1735
1826
|
maxFee,
|
1736
1827
|
witnessLimit,
|
@@ -1738,7 +1829,7 @@ var BaseTransactionRequest = class {
|
|
1738
1829
|
outputs,
|
1739
1830
|
witnesses
|
1740
1831
|
} = {}) {
|
1741
|
-
this.
|
1832
|
+
this.tip = bn7(tip);
|
1742
1833
|
this.maturity = maturity ?? 0;
|
1743
1834
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1744
1835
|
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
@@ -1749,9 +1840,9 @@ var BaseTransactionRequest = class {
|
|
1749
1840
|
static getPolicyMeta(req) {
|
1750
1841
|
let policyTypes = 0;
|
1751
1842
|
const policies = [];
|
1752
|
-
if (req.
|
1753
|
-
policyTypes += PolicyType.
|
1754
|
-
policies.push({ data: req.
|
1843
|
+
if (req.tip) {
|
1844
|
+
policyTypes += PolicyType.Tip;
|
1845
|
+
policies.push({ data: req.tip, type: PolicyType.Tip });
|
1755
1846
|
}
|
1756
1847
|
if (req.witnessLimit) {
|
1757
1848
|
policyTypes += PolicyType.WitnessLimit;
|
@@ -1888,7 +1979,7 @@ var BaseTransactionRequest = class {
|
|
1888
1979
|
*/
|
1889
1980
|
getCoinInputs() {
|
1890
1981
|
return this.inputs.filter(
|
1891
|
-
(input) => input.type ===
|
1982
|
+
(input) => input.type === InputType2.Coin
|
1892
1983
|
);
|
1893
1984
|
}
|
1894
1985
|
/**
|
@@ -1920,9 +2011,9 @@ var BaseTransactionRequest = class {
|
|
1920
2011
|
const ownerAddress = addressify(owner);
|
1921
2012
|
const found = this.inputs.find((input) => {
|
1922
2013
|
switch (input.type) {
|
1923
|
-
case
|
2014
|
+
case InputType2.Coin:
|
1924
2015
|
return hexlify7(input.owner) === ownerAddress.toB256();
|
1925
|
-
case
|
2016
|
+
case InputType2.Message:
|
1926
2017
|
return hexlify7(input.recipient) === ownerAddress.toB256();
|
1927
2018
|
default:
|
1928
2019
|
return false;
|
@@ -1939,9 +2030,9 @@ var BaseTransactionRequest = class {
|
|
1939
2030
|
* @param predicateData - Predicate data bytes.
|
1940
2031
|
*/
|
1941
2032
|
addCoinInput(coin) {
|
1942
|
-
const { assetId, owner, amount
|
2033
|
+
const { assetId, owner, amount } = coin;
|
1943
2034
|
let witnessIndex;
|
1944
|
-
if (predicate) {
|
2035
|
+
if (coin.predicate) {
|
1945
2036
|
witnessIndex = 0;
|
1946
2037
|
} else {
|
1947
2038
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1950,14 +2041,13 @@ var BaseTransactionRequest = class {
|
|
1950
2041
|
}
|
1951
2042
|
}
|
1952
2043
|
const input = {
|
1953
|
-
|
1954
|
-
type:
|
2044
|
+
...coin,
|
2045
|
+
type: InputType2.Coin,
|
1955
2046
|
owner: owner.toB256(),
|
1956
2047
|
amount,
|
1957
2048
|
assetId,
|
1958
2049
|
txPointer: "0x00000000000000000000000000000000",
|
1959
|
-
witnessIndex
|
1960
|
-
predicate
|
2050
|
+
witnessIndex
|
1961
2051
|
};
|
1962
2052
|
this.pushInput(input);
|
1963
2053
|
this.addChangeOutput(owner, assetId);
|
@@ -1971,10 +2061,10 @@ var BaseTransactionRequest = class {
|
|
1971
2061
|
* @param predicateData - Predicate data bytes.
|
1972
2062
|
*/
|
1973
2063
|
addMessageInput(message) {
|
1974
|
-
const { recipient, sender, amount
|
2064
|
+
const { recipient, sender, amount } = message;
|
1975
2065
|
const assetId = BaseAssetId2;
|
1976
2066
|
let witnessIndex;
|
1977
|
-
if (predicate) {
|
2067
|
+
if (message.predicate) {
|
1978
2068
|
witnessIndex = 0;
|
1979
2069
|
} else {
|
1980
2070
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1983,13 +2073,12 @@ var BaseTransactionRequest = class {
|
|
1983
2073
|
}
|
1984
2074
|
}
|
1985
2075
|
const input = {
|
1986
|
-
|
1987
|
-
type:
|
2076
|
+
...message,
|
2077
|
+
type: InputType2.Message,
|
1988
2078
|
sender: sender.toB256(),
|
1989
2079
|
recipient: recipient.toB256(),
|
1990
2080
|
amount,
|
1991
|
-
witnessIndex
|
1992
|
-
predicate
|
2081
|
+
witnessIndex
|
1993
2082
|
};
|
1994
2083
|
this.pushInput(input);
|
1995
2084
|
this.addChangeOutput(recipient, assetId);
|
@@ -2099,7 +2188,7 @@ var BaseTransactionRequest = class {
|
|
2099
2188
|
}
|
2100
2189
|
calculateMaxGas(chainInfo, minGas) {
|
2101
2190
|
const { consensusParameters } = chainInfo;
|
2102
|
-
const { gasPerByte } = consensusParameters;
|
2191
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2103
2192
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2104
2193
|
(acc, wit) => acc + wit.dataLength,
|
2105
2194
|
0
|
@@ -2108,7 +2197,8 @@ var BaseTransactionRequest = class {
|
|
2108
2197
|
gasPerByte,
|
2109
2198
|
minGas,
|
2110
2199
|
witnessesLength,
|
2111
|
-
witnessLimit: this.witnessLimit
|
2200
|
+
witnessLimit: this.witnessLimit,
|
2201
|
+
maxGasPerTx
|
2112
2202
|
});
|
2113
2203
|
}
|
2114
2204
|
/**
|
@@ -2126,17 +2216,20 @@ var BaseTransactionRequest = class {
|
|
2126
2216
|
});
|
2127
2217
|
const updateAssetInput = (assetId, quantity) => {
|
2128
2218
|
const assetInput = findAssetInput(assetId);
|
2219
|
+
let usedQuantity = quantity;
|
2220
|
+
if (assetId === BaseAssetId2) {
|
2221
|
+
usedQuantity = bn7("1000000000000000000");
|
2222
|
+
}
|
2129
2223
|
if (assetInput && "assetId" in assetInput) {
|
2130
2224
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2131
|
-
assetInput.amount =
|
2225
|
+
assetInput.amount = usedQuantity;
|
2132
2226
|
} else {
|
2133
2227
|
this.addResources([
|
2134
2228
|
{
|
2135
2229
|
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2136
|
-
amount:
|
2230
|
+
amount: usedQuantity,
|
2137
2231
|
assetId,
|
2138
2232
|
owner: resourcesOwner || Address.fromRandom(),
|
2139
|
-
maturity: 0,
|
2140
2233
|
blockCreated: bn7(1),
|
2141
2234
|
txCreatedIdx: bn7(1)
|
2142
2235
|
}
|
@@ -2168,20 +2261,16 @@ var BaseTransactionRequest = class {
|
|
2168
2261
|
toJSON() {
|
2169
2262
|
return normalizeJSON(this);
|
2170
2263
|
}
|
2171
|
-
|
2172
|
-
this.witnesses.splice(index, 1);
|
2173
|
-
this.adjustWitnessIndexes(index);
|
2174
|
-
}
|
2175
|
-
updatePredicateInputs(inputs) {
|
2264
|
+
updatePredicateGasUsed(inputs) {
|
2176
2265
|
this.inputs.forEach((i) => {
|
2177
2266
|
let correspondingInput;
|
2178
2267
|
switch (i.type) {
|
2179
|
-
case
|
2180
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2268
|
+
case InputType2.Coin:
|
2269
|
+
correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
|
2181
2270
|
break;
|
2182
|
-
case
|
2271
|
+
case InputType2.Message:
|
2183
2272
|
correspondingInput = inputs.find(
|
2184
|
-
(x) => x.type ===
|
2273
|
+
(x) => x.type === InputType2.Message && x.sender === i.sender
|
2185
2274
|
);
|
2186
2275
|
break;
|
2187
2276
|
default:
|
@@ -2194,10 +2283,12 @@ var BaseTransactionRequest = class {
|
|
2194
2283
|
}
|
2195
2284
|
});
|
2196
2285
|
}
|
2197
|
-
|
2198
|
-
this.inputs.
|
2199
|
-
if (input.
|
2200
|
-
input.
|
2286
|
+
shiftPredicateData() {
|
2287
|
+
this.inputs.forEach((input) => {
|
2288
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2289
|
+
input.predicateData = input.paddPredicateData(
|
2290
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2291
|
+
);
|
2201
2292
|
}
|
2202
2293
|
});
|
2203
2294
|
}
|
@@ -2213,7 +2304,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2213
2304
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2214
2305
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2215
2306
|
import { bn as bn8 } from "@fuel-ts/math";
|
2216
|
-
import { TransactionType as TransactionType2, InputType as
|
2307
|
+
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2217
2308
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2218
2309
|
import { clone as clone2 } from "ramda";
|
2219
2310
|
function hashTransaction(transactionRequest, chainId) {
|
@@ -2224,7 +2315,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2224
2315
|
transaction.inputs = transaction.inputs.map((input) => {
|
2225
2316
|
const inputClone = clone2(input);
|
2226
2317
|
switch (inputClone.type) {
|
2227
|
-
case
|
2318
|
+
case InputType3.Coin: {
|
2228
2319
|
inputClone.txPointer = {
|
2229
2320
|
blockHeight: 0,
|
2230
2321
|
txIndex: 0
|
@@ -2232,11 +2323,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2232
2323
|
inputClone.predicateGasUsed = bn8(0);
|
2233
2324
|
return inputClone;
|
2234
2325
|
}
|
2235
|
-
case
|
2326
|
+
case InputType3.Message: {
|
2236
2327
|
inputClone.predicateGasUsed = bn8(0);
|
2237
2328
|
return inputClone;
|
2238
2329
|
}
|
2239
|
-
case
|
2330
|
+
case InputType3.Contract: {
|
2240
2331
|
inputClone.txPointer = {
|
2241
2332
|
blockHeight: 0,
|
2242
2333
|
txIndex: 0
|
@@ -2347,9 +2438,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2347
2438
|
return {
|
2348
2439
|
type: TransactionType3.Create,
|
2349
2440
|
...baseTransaction,
|
2350
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2351
2441
|
bytecodeWitnessIndex,
|
2352
|
-
storageSlotsCount: storageSlots.length,
|
2442
|
+
storageSlotsCount: bn9(storageSlots.length),
|
2353
2443
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2354
2444
|
storageSlots
|
2355
2445
|
};
|
@@ -2402,7 +2492,7 @@ import { Interface } from "@fuel-ts/abi-coder";
|
|
2402
2492
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2403
2493
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2404
2494
|
import { bn as bn10 } from "@fuel-ts/math";
|
2405
|
-
import { InputType as
|
2495
|
+
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2406
2496
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2407
2497
|
|
2408
2498
|
// src/providers/transaction-request/scripts.ts
|
@@ -2472,8 +2562,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2472
2562
|
type: TransactionType4.Script,
|
2473
2563
|
scriptGasLimit: this.gasLimit,
|
2474
2564
|
...super.getBaseTransaction(),
|
2475
|
-
scriptLength: script.length,
|
2476
|
-
scriptDataLength: scriptData.length,
|
2565
|
+
scriptLength: bn10(script.length),
|
2566
|
+
scriptDataLength: bn10(scriptData.length),
|
2477
2567
|
receiptsRoot: ZeroBytes327,
|
2478
2568
|
script: hexlify10(script),
|
2479
2569
|
scriptData: hexlify10(scriptData)
|
@@ -2486,7 +2576,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2486
2576
|
*/
|
2487
2577
|
getContractInputs() {
|
2488
2578
|
return this.inputs.filter(
|
2489
|
-
(input) => input.type ===
|
2579
|
+
(input) => input.type === InputType4.Contract
|
2490
2580
|
);
|
2491
2581
|
}
|
2492
2582
|
/**
|
@@ -2537,7 +2627,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2537
2627
|
}
|
2538
2628
|
calculateMaxGas(chainInfo, minGas) {
|
2539
2629
|
const { consensusParameters } = chainInfo;
|
2540
|
-
const { gasPerByte } = consensusParameters;
|
2630
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2541
2631
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2542
2632
|
(acc, wit) => acc + wit.dataLength,
|
2543
2633
|
0
|
@@ -2547,7 +2637,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2547
2637
|
minGas,
|
2548
2638
|
witnessesLength,
|
2549
2639
|
witnessLimit: this.witnessLimit,
|
2550
|
-
gasLimit: this.gasLimit
|
2640
|
+
gasLimit: this.gasLimit,
|
2641
|
+
maxGasPerTx
|
2551
2642
|
});
|
2552
2643
|
}
|
2553
2644
|
/**
|
@@ -2562,7 +2653,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2562
2653
|
return this;
|
2563
2654
|
}
|
2564
2655
|
const inputIndex = super.pushInput({
|
2565
|
-
type:
|
2656
|
+
type: InputType4.Contract,
|
2566
2657
|
contractId: contractAddress.toB256(),
|
2567
2658
|
txPointer: "0x00000000000000000000000000000000"
|
2568
2659
|
});
|
@@ -2604,7 +2695,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2604
2695
|
|
2605
2696
|
// src/providers/transaction-request/utils.ts
|
2606
2697
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2607
|
-
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2698
|
+
import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
|
2608
2699
|
var transactionRequestify = (obj) => {
|
2609
2700
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2610
2701
|
return obj;
|
@@ -2622,14 +2713,31 @@ var transactionRequestify = (obj) => {
|
|
2622
2713
|
}
|
2623
2714
|
}
|
2624
2715
|
};
|
2716
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2717
|
+
(acc, input) => {
|
2718
|
+
if (input.type === InputType5.Coin && input.owner === owner) {
|
2719
|
+
acc.utxos.push(input.id);
|
2720
|
+
}
|
2721
|
+
if (input.type === InputType5.Message && input.recipient === owner) {
|
2722
|
+
acc.messages.push(input.nonce);
|
2723
|
+
}
|
2724
|
+
return acc;
|
2725
|
+
},
|
2726
|
+
{
|
2727
|
+
utxos: [],
|
2728
|
+
messages: []
|
2729
|
+
}
|
2730
|
+
);
|
2625
2731
|
|
2626
2732
|
// src/providers/transaction-response/transaction-response.ts
|
2627
2733
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2628
|
-
import { bn as
|
2734
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2629
2735
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2630
2736
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2631
2737
|
|
2632
2738
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2739
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2740
|
+
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2633
2741
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2634
2742
|
|
2635
2743
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
@@ -2638,9 +2746,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
|
|
2638
2746
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2639
2747
|
var calculateTransactionFee = (params) => {
|
2640
2748
|
const {
|
2641
|
-
|
2749
|
+
gasPrice,
|
2642
2750
|
rawPayload,
|
2643
|
-
|
2751
|
+
tip,
|
2752
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2644
2753
|
} = params;
|
2645
2754
|
const gasPerByte = bn11(feeParams.gasPerByte);
|
2646
2755
|
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
@@ -2650,8 +2759,7 @@ var calculateTransactionFee = (params) => {
|
|
2650
2759
|
return {
|
2651
2760
|
fee: bn11(0),
|
2652
2761
|
minFee: bn11(0),
|
2653
|
-
maxFee: bn11(0)
|
2654
|
-
feeFromGasUsed: bn11(0)
|
2762
|
+
maxFee: bn11(0)
|
2655
2763
|
};
|
2656
2764
|
}
|
2657
2765
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2683,7 +2791,6 @@ var calculateTransactionFee = (params) => {
|
|
2683
2791
|
metadataGas,
|
2684
2792
|
txBytesSize: transactionBytes.length
|
2685
2793
|
});
|
2686
|
-
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2687
2794
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2688
2795
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2689
2796
|
const maxGas = getMaxGas({
|
@@ -2691,17 +2798,25 @@ var calculateTransactionFee = (params) => {
|
|
2691
2798
|
minGas,
|
2692
2799
|
witnessesLength,
|
2693
2800
|
gasLimit,
|
2694
|
-
witnessLimit
|
2801
|
+
witnessLimit,
|
2802
|
+
maxGasPerTx
|
2803
|
+
});
|
2804
|
+
const minFee = calculateGasFee({
|
2805
|
+
gasPrice,
|
2806
|
+
gas: minGas,
|
2807
|
+
priceFactor: gasPriceFactor,
|
2808
|
+
tip
|
2809
|
+
});
|
2810
|
+
const maxFee = calculateGasFee({
|
2811
|
+
gasPrice,
|
2812
|
+
gas: maxGas,
|
2813
|
+
priceFactor: gasPriceFactor,
|
2814
|
+
tip
|
2695
2815
|
});
|
2696
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2697
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2698
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2699
|
-
const fee = minFee.add(feeFromGasUsed);
|
2700
2816
|
return {
|
2701
|
-
fee,
|
2702
2817
|
minFee,
|
2703
2818
|
maxFee,
|
2704
|
-
|
2819
|
+
fee: maxFee
|
2705
2820
|
};
|
2706
2821
|
};
|
2707
2822
|
|
@@ -3315,7 +3430,9 @@ function assembleTransactionSummary(params) {
|
|
3315
3430
|
gqlTransactionStatus,
|
3316
3431
|
abiMap = {},
|
3317
3432
|
maxInputs,
|
3318
|
-
gasCosts
|
3433
|
+
gasCosts,
|
3434
|
+
maxGasPerTx,
|
3435
|
+
gasPrice
|
3319
3436
|
} = params;
|
3320
3437
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3321
3438
|
const rawPayload = hexlify11(transactionBytes);
|
@@ -3329,11 +3446,14 @@ function assembleTransactionSummary(params) {
|
|
3329
3446
|
maxInputs
|
3330
3447
|
});
|
3331
3448
|
const typeName = getTransactionTypeName(transaction.type);
|
3449
|
+
const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3332
3450
|
const { fee } = calculateTransactionFee({
|
3333
|
-
|
3451
|
+
gasPrice,
|
3334
3452
|
rawPayload,
|
3453
|
+
tip,
|
3335
3454
|
consensusParameters: {
|
3336
3455
|
gasCosts,
|
3456
|
+
maxGasPerTx,
|
3337
3457
|
feeParams: {
|
3338
3458
|
gasPerByte,
|
3339
3459
|
gasPriceFactor
|
@@ -3393,7 +3513,7 @@ var TransactionResponse = class {
|
|
3393
3513
|
/** Current provider */
|
3394
3514
|
provider;
|
3395
3515
|
/** Gas used on the transaction */
|
3396
|
-
gasUsed =
|
3516
|
+
gasUsed = bn15(0);
|
3397
3517
|
/** The graphql Transaction with receipts object. */
|
3398
3518
|
gqlTransaction;
|
3399
3519
|
abis;
|
@@ -3471,8 +3591,13 @@ var TransactionResponse = class {
|
|
3471
3591
|
const decodedTransaction = this.decodeTransaction(
|
3472
3592
|
transaction
|
3473
3593
|
);
|
3474
|
-
|
3475
|
-
|
3594
|
+
let txReceipts = [];
|
3595
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3596
|
+
txReceipts = transaction.status.receipts;
|
3597
|
+
}
|
3598
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3599
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3600
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3476
3601
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3477
3602
|
const transactionSummary = assembleTransactionSummary({
|
3478
3603
|
id: this.id,
|
@@ -3484,7 +3609,9 @@ var TransactionResponse = class {
|
|
3484
3609
|
gasPriceFactor,
|
3485
3610
|
abiMap: contractsAbiMap,
|
3486
3611
|
maxInputs,
|
3487
|
-
gasCosts
|
3612
|
+
gasCosts,
|
3613
|
+
maxGasPerTx,
|
3614
|
+
gasPrice
|
3488
3615
|
});
|
3489
3616
|
return transactionSummary;
|
3490
3617
|
}
|
@@ -3611,29 +3738,29 @@ var processGqlChain = (chain) => {
|
|
3611
3738
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3612
3739
|
return {
|
3613
3740
|
name,
|
3614
|
-
baseChainHeight:
|
3741
|
+
baseChainHeight: bn16(daHeight),
|
3615
3742
|
consensusParameters: {
|
3616
|
-
contractMaxSize:
|
3617
|
-
maxInputs:
|
3618
|
-
maxOutputs:
|
3619
|
-
maxWitnesses:
|
3620
|
-
maxGasPerTx:
|
3621
|
-
maxScriptLength:
|
3622
|
-
maxScriptDataLength:
|
3623
|
-
maxStorageSlots:
|
3624
|
-
maxPredicateLength:
|
3625
|
-
maxPredicateDataLength:
|
3626
|
-
maxGasPerPredicate:
|
3627
|
-
gasPriceFactor:
|
3628
|
-
gasPerByte:
|
3629
|
-
maxMessageDataLength:
|
3630
|
-
chainId:
|
3743
|
+
contractMaxSize: bn16(contractParams.contractMaxSize),
|
3744
|
+
maxInputs: bn16(txParams.maxInputs),
|
3745
|
+
maxOutputs: bn16(txParams.maxOutputs),
|
3746
|
+
maxWitnesses: bn16(txParams.maxWitnesses),
|
3747
|
+
maxGasPerTx: bn16(txParams.maxGasPerTx),
|
3748
|
+
maxScriptLength: bn16(scriptParams.maxScriptLength),
|
3749
|
+
maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
|
3750
|
+
maxStorageSlots: bn16(contractParams.maxStorageSlots),
|
3751
|
+
maxPredicateLength: bn16(predicateParams.maxPredicateLength),
|
3752
|
+
maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
|
3753
|
+
maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
|
3754
|
+
gasPriceFactor: bn16(feeParams.gasPriceFactor),
|
3755
|
+
gasPerByte: bn16(feeParams.gasPerByte),
|
3756
|
+
maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
|
3757
|
+
chainId: bn16(consensusParameters.chainId),
|
3631
3758
|
gasCosts
|
3632
3759
|
},
|
3633
3760
|
gasCosts,
|
3634
3761
|
latestBlock: {
|
3635
3762
|
id: latestBlock.id,
|
3636
|
-
height:
|
3763
|
+
height: bn16(latestBlock.height),
|
3637
3764
|
time: latestBlock.header.time,
|
3638
3765
|
transactions: latestBlock.transactions.map((i) => ({
|
3639
3766
|
id: i.id
|
@@ -3727,10 +3854,8 @@ var _Provider = class {
|
|
3727
3854
|
* Returns some helpful parameters related to gas fees.
|
3728
3855
|
*/
|
3729
3856
|
getGasConfig() {
|
3730
|
-
const { minGasPrice } = this.getNode();
|
3731
3857
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3732
3858
|
return {
|
3733
|
-
minGasPrice,
|
3734
3859
|
maxGasPerTx,
|
3735
3860
|
maxGasPerPredicate,
|
3736
3861
|
gasPriceFactor,
|
@@ -3828,7 +3953,7 @@ var _Provider = class {
|
|
3828
3953
|
*/
|
3829
3954
|
async getBlockNumber() {
|
3830
3955
|
const { chain } = await this.operations.getChain();
|
3831
|
-
return
|
3956
|
+
return bn16(chain.latestBlock.height, 10);
|
3832
3957
|
}
|
3833
3958
|
/**
|
3834
3959
|
* Returns the chain information.
|
@@ -3838,13 +3963,11 @@ var _Provider = class {
|
|
3838
3963
|
async fetchNode() {
|
3839
3964
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3840
3965
|
const processedNodeInfo = {
|
3841
|
-
maxDepth:
|
3842
|
-
maxTx:
|
3843
|
-
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3966
|
+
maxDepth: bn16(nodeInfo.maxDepth),
|
3967
|
+
maxTx: bn16(nodeInfo.maxTx),
|
3844
3968
|
nodeVersion: nodeInfo.nodeVersion,
|
3845
3969
|
utxoValidation: nodeInfo.utxoValidation,
|
3846
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3847
|
-
peers: nodeInfo.peers
|
3970
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3848
3971
|
};
|
3849
3972
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3850
3973
|
return processedNodeInfo;
|
@@ -3930,14 +4053,13 @@ var _Provider = class {
|
|
3930
4053
|
return this.estimateTxDependencies(transactionRequest);
|
3931
4054
|
}
|
3932
4055
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3933
|
-
const { dryRun:
|
3934
|
-
encodedTransaction,
|
4056
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4057
|
+
encodedTransactions: encodedTransaction,
|
3935
4058
|
utxoValidation: utxoValidation || false
|
3936
4059
|
});
|
3937
|
-
const receipts =
|
3938
|
-
|
3939
|
-
|
3940
|
-
};
|
4060
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4061
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4062
|
+
return { receipts, dryrunStatus: status };
|
3941
4063
|
}
|
3942
4064
|
/**
|
3943
4065
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3963,7 +4085,7 @@ var _Provider = class {
|
|
3963
4085
|
} = response;
|
3964
4086
|
if (inputs) {
|
3965
4087
|
inputs.forEach((input, index) => {
|
3966
|
-
if ("predicateGasUsed" in input &&
|
4088
|
+
if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
|
3967
4089
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3968
4090
|
}
|
3969
4091
|
});
|
@@ -3976,9 +4098,6 @@ var _Provider = class {
|
|
3976
4098
|
* If there are missing variable outputs,
|
3977
4099
|
* `addVariableOutputs` is called on the transaction.
|
3978
4100
|
*
|
3979
|
-
* @privateRemarks
|
3980
|
-
* TODO: Investigate support for missing contract IDs
|
3981
|
-
* TODO: Add support for missing output messages
|
3982
4101
|
*
|
3983
4102
|
* @param transactionRequest - The transaction request object.
|
3984
4103
|
* @returns A promise.
|
@@ -3991,16 +4110,19 @@ var _Provider = class {
|
|
3991
4110
|
missingContractIds: []
|
3992
4111
|
};
|
3993
4112
|
}
|
3994
|
-
await this.estimatePredicates(transactionRequest);
|
3995
4113
|
let receipts = [];
|
3996
4114
|
const missingContractIds = [];
|
3997
4115
|
let outputVariables = 0;
|
4116
|
+
let dryrunStatus;
|
3998
4117
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3999
|
-
const {
|
4000
|
-
|
4118
|
+
const {
|
4119
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4120
|
+
} = await this.operations.dryRun({
|
4121
|
+
encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
|
4001
4122
|
utxoValidation: false
|
4002
4123
|
});
|
4003
|
-
receipts =
|
4124
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4125
|
+
dryrunStatus = status;
|
4004
4126
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4005
4127
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4006
4128
|
if (hasMissingOutputs) {
|
@@ -4010,6 +4132,10 @@ var _Provider = class {
|
|
4010
4132
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
4011
4133
|
missingContractIds.push(contractId);
|
4012
4134
|
});
|
4135
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4136
|
+
transactionRequest
|
4137
|
+
});
|
4138
|
+
transactionRequest.maxFee = maxFee;
|
4013
4139
|
} else {
|
4014
4140
|
break;
|
4015
4141
|
}
|
@@ -4017,37 +4143,139 @@ var _Provider = class {
|
|
4017
4143
|
return {
|
4018
4144
|
receipts,
|
4019
4145
|
outputVariables,
|
4020
|
-
missingContractIds
|
4146
|
+
missingContractIds,
|
4147
|
+
dryrunStatus
|
4021
4148
|
};
|
4022
4149
|
}
|
4150
|
+
/**
|
4151
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4152
|
+
*
|
4153
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4154
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4155
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4156
|
+
*
|
4157
|
+
* @param transactionRequests - Array of transaction request objects.
|
4158
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4159
|
+
*/
|
4160
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4161
|
+
const results = transactionRequests.map(() => ({
|
4162
|
+
receipts: [],
|
4163
|
+
outputVariables: 0,
|
4164
|
+
missingContractIds: [],
|
4165
|
+
dryrunStatus: void 0
|
4166
|
+
}));
|
4167
|
+
const allRequests = clone3(transactionRequests);
|
4168
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4169
|
+
allRequests.forEach((req, index) => {
|
4170
|
+
if (req.type === TransactionType8.Script) {
|
4171
|
+
serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
|
4172
|
+
}
|
4173
|
+
});
|
4174
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4175
|
+
let attempt = 0;
|
4176
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4177
|
+
const encodedTransactions = transactionsToProcess.map(
|
4178
|
+
(index) => serializedTransactionsMap.get(index)
|
4179
|
+
);
|
4180
|
+
const dryRunResults = await this.operations.dryRun({
|
4181
|
+
encodedTransactions,
|
4182
|
+
utxoValidation: false
|
4183
|
+
});
|
4184
|
+
const nextRoundTransactions = [];
|
4185
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4186
|
+
const currentResultIndex = transactionsToProcess[i];
|
4187
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4188
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4189
|
+
results[currentResultIndex].dryrunStatus = status;
|
4190
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4191
|
+
results[currentResultIndex].receipts
|
4192
|
+
);
|
4193
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4194
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4195
|
+
if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
|
4196
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4197
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4198
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4199
|
+
requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
|
4200
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4201
|
+
});
|
4202
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4203
|
+
transactionRequest: requestToProcess
|
4204
|
+
});
|
4205
|
+
requestToProcess.maxFee = maxFee;
|
4206
|
+
serializedTransactionsMap.set(
|
4207
|
+
currentResultIndex,
|
4208
|
+
hexlify12(requestToProcess.toTransactionBytes())
|
4209
|
+
);
|
4210
|
+
nextRoundTransactions.push(currentResultIndex);
|
4211
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4212
|
+
}
|
4213
|
+
}
|
4214
|
+
transactionsToProcess = nextRoundTransactions;
|
4215
|
+
attempt += 1;
|
4216
|
+
}
|
4217
|
+
return results;
|
4218
|
+
}
|
4219
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4220
|
+
if (estimateTxDependencies) {
|
4221
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4222
|
+
}
|
4223
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
|
4224
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4225
|
+
encodedTransactions,
|
4226
|
+
utxoValidation: utxoValidation || false
|
4227
|
+
});
|
4228
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4229
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4230
|
+
return { receipts, dryrunStatus: status };
|
4231
|
+
});
|
4232
|
+
return results;
|
4233
|
+
}
|
4023
4234
|
/**
|
4024
4235
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4025
4236
|
* @param transactionRequest - The transaction request object.
|
4026
4237
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4027
4238
|
*/
|
4028
|
-
estimateTxGasAndFee(params) {
|
4239
|
+
async estimateTxGasAndFee(params) {
|
4029
4240
|
const { transactionRequest } = params;
|
4030
|
-
|
4241
|
+
let { gasPrice } = params;
|
4031
4242
|
const chainInfo = this.getChain();
|
4032
|
-
const
|
4033
|
-
transactionRequest.gasPrice = gasPrice;
|
4243
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4034
4244
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4035
|
-
|
4245
|
+
if (!gasPrice) {
|
4246
|
+
gasPrice = await this.estimateGasPrice(10);
|
4247
|
+
}
|
4248
|
+
const minFee = calculateGasFee({
|
4249
|
+
gasPrice: bn16(gasPrice),
|
4250
|
+
gas: minGas,
|
4251
|
+
priceFactor: gasPriceFactor,
|
4252
|
+
tip: transactionRequest.tip
|
4253
|
+
}).add(1);
|
4254
|
+
let gasLimit = bn16(0);
|
4036
4255
|
if (transactionRequest.type === TransactionType8.Script) {
|
4256
|
+
gasLimit = transactionRequest.gasLimit;
|
4037
4257
|
if (transactionRequest.gasLimit.eq(0)) {
|
4038
4258
|
transactionRequest.gasLimit = minGas;
|
4039
4259
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4040
4260
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4041
4261
|
);
|
4262
|
+
gasLimit = transactionRequest.gasLimit;
|
4042
4263
|
}
|
4043
4264
|
}
|
4044
4265
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4045
|
-
const maxFee =
|
4266
|
+
const maxFee = calculateGasFee({
|
4267
|
+
gasPrice: bn16(gasPrice),
|
4268
|
+
gas: maxGas,
|
4269
|
+
priceFactor: gasPriceFactor,
|
4270
|
+
tip: transactionRequest.tip
|
4271
|
+
}).add(1);
|
4046
4272
|
return {
|
4047
4273
|
minGas,
|
4048
4274
|
minFee,
|
4049
4275
|
maxGas,
|
4050
|
-
maxFee
|
4276
|
+
maxFee,
|
4277
|
+
gasPrice,
|
4278
|
+
gasLimit
|
4051
4279
|
};
|
4052
4280
|
}
|
4053
4281
|
/**
|
@@ -4065,15 +4293,17 @@ var _Provider = class {
|
|
4065
4293
|
if (estimateTxDependencies) {
|
4066
4294
|
return this.estimateTxDependencies(transactionRequest);
|
4067
4295
|
}
|
4068
|
-
const
|
4069
|
-
const { dryRun:
|
4070
|
-
|
4296
|
+
const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
|
4297
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4298
|
+
encodedTransactions,
|
4071
4299
|
utxoValidation: true
|
4072
4300
|
});
|
4073
|
-
const
|
4074
|
-
|
4075
|
-
receipts
|
4076
|
-
|
4301
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4302
|
+
const { id, receipts, status } = dryRunStatus;
|
4303
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4304
|
+
return { id, receipts: processedReceipts, status };
|
4305
|
+
});
|
4306
|
+
return { receipts: callResult[0].receipts };
|
4077
4307
|
}
|
4078
4308
|
/**
|
4079
4309
|
* Returns a transaction cost to enable user
|
@@ -4090,77 +4320,79 @@ var _Provider = class {
|
|
4090
4320
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4091
4321
|
* @returns A promise that resolves to the transaction cost object.
|
4092
4322
|
*/
|
4093
|
-
async getTransactionCost(transactionRequestLike,
|
4094
|
-
estimateTxDependencies = true,
|
4095
|
-
estimatePredicates = true,
|
4096
|
-
resourcesOwner,
|
4097
|
-
signatureCallback
|
4098
|
-
} = {}) {
|
4323
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4099
4324
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4100
|
-
const { minGasPrice } = this.getGasConfig();
|
4101
|
-
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4102
4325
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4103
4326
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4104
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4327
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4105
4328
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4329
|
+
txRequestClone.maxFee = bn16(0);
|
4106
4330
|
if (isScriptTransaction) {
|
4107
|
-
txRequestClone.gasLimit =
|
4331
|
+
txRequestClone.gasLimit = bn16(0);
|
4108
4332
|
}
|
4109
|
-
if (
|
4110
|
-
|
4111
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4112
|
-
}
|
4113
|
-
await this.estimatePredicates(txRequestClone);
|
4333
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4334
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4114
4335
|
}
|
4336
|
+
const signedRequest = clone3(txRequestClone);
|
4337
|
+
let addedSignatures = 0;
|
4115
4338
|
if (signatureCallback && isScriptTransaction) {
|
4116
|
-
|
4339
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4340
|
+
await signatureCallback(signedRequest);
|
4341
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4117
4342
|
}
|
4118
|
-
|
4119
|
-
|
4343
|
+
await this.estimatePredicates(signedRequest);
|
4344
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4345
|
+
transactionRequest: signedRequest
|
4120
4346
|
});
|
4121
4347
|
let receipts = [];
|
4122
4348
|
let missingContractIds = [];
|
4123
4349
|
let outputVariables = 0;
|
4124
|
-
let gasUsed =
|
4125
|
-
|
4126
|
-
|
4350
|
+
let gasUsed = bn16(0);
|
4351
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4352
|
+
txRequestClone.maxFee = maxFee;
|
4353
|
+
if (isScriptTransaction) {
|
4354
|
+
txRequestClone.gasLimit = gasLimit;
|
4355
|
+
if (signatureCallback) {
|
4356
|
+
await signatureCallback(txRequestClone);
|
4357
|
+
}
|
4127
4358
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4128
4359
|
receipts = result.receipts;
|
4129
4360
|
outputVariables = result.outputVariables;
|
4130
4361
|
missingContractIds = result.missingContractIds;
|
4131
4362
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4132
4363
|
txRequestClone.gasLimit = gasUsed;
|
4133
|
-
|
4134
|
-
|
4135
|
-
|
4364
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4365
|
+
transactionRequest: txRequestClone,
|
4366
|
+
gasPrice
|
4136
4367
|
}));
|
4137
4368
|
}
|
4138
4369
|
return {
|
4139
4370
|
requiredQuantities: allQuantities,
|
4140
4371
|
receipts,
|
4141
4372
|
gasUsed,
|
4142
|
-
|
4143
|
-
gasPrice: setGasPrice,
|
4373
|
+
gasPrice,
|
4144
4374
|
minGas,
|
4145
4375
|
maxGas,
|
4146
4376
|
minFee,
|
4147
4377
|
maxFee,
|
4148
|
-
estimatedInputs: txRequestClone.inputs,
|
4149
4378
|
outputVariables,
|
4150
|
-
missingContractIds
|
4379
|
+
missingContractIds,
|
4380
|
+
addedSignatures,
|
4381
|
+
estimatedPredicates: txRequestClone.inputs
|
4151
4382
|
};
|
4152
4383
|
}
|
4153
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4384
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4154
4385
|
const ownerAddress = Address2.fromAddressOrString(owner);
|
4155
4386
|
const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
|
4156
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4387
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4388
|
+
quantitiesToContract
|
4389
|
+
});
|
4157
4390
|
transactionRequest.addResources(
|
4158
4391
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4159
4392
|
);
|
4160
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4161
|
-
|
4162
|
-
|
4163
|
-
);
|
4393
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4394
|
+
quantitiesToContract
|
4395
|
+
});
|
4164
4396
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4165
4397
|
return {
|
4166
4398
|
resources,
|
@@ -4182,11 +4414,10 @@ var _Provider = class {
|
|
4182
4414
|
return coins.map((coin) => ({
|
4183
4415
|
id: coin.utxoId,
|
4184
4416
|
assetId: coin.assetId,
|
4185
|
-
amount:
|
4417
|
+
amount: bn16(coin.amount),
|
4186
4418
|
owner: Address2.fromAddressOrString(coin.owner),
|
4187
|
-
|
4188
|
-
|
4189
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4419
|
+
blockCreated: bn16(coin.blockCreated),
|
4420
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4190
4421
|
}));
|
4191
4422
|
}
|
4192
4423
|
/**
|
@@ -4223,9 +4454,9 @@ var _Provider = class {
|
|
4223
4454
|
switch (coin.__typename) {
|
4224
4455
|
case "MessageCoin":
|
4225
4456
|
return {
|
4226
|
-
amount:
|
4457
|
+
amount: bn16(coin.amount),
|
4227
4458
|
assetId: coin.assetId,
|
4228
|
-
daHeight:
|
4459
|
+
daHeight: bn16(coin.daHeight),
|
4229
4460
|
sender: Address2.fromAddressOrString(coin.sender),
|
4230
4461
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4231
4462
|
nonce: coin.nonce
|
@@ -4233,12 +4464,11 @@ var _Provider = class {
|
|
4233
4464
|
case "Coin":
|
4234
4465
|
return {
|
4235
4466
|
id: coin.utxoId,
|
4236
|
-
amount:
|
4467
|
+
amount: bn16(coin.amount),
|
4237
4468
|
assetId: coin.assetId,
|
4238
4469
|
owner: Address2.fromAddressOrString(coin.owner),
|
4239
|
-
|
4240
|
-
|
4241
|
-
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4470
|
+
blockCreated: bn16(coin.blockCreated),
|
4471
|
+
txCreatedIdx: bn16(coin.txCreatedIdx)
|
4242
4472
|
};
|
4243
4473
|
default:
|
4244
4474
|
return null;
|
@@ -4255,13 +4485,13 @@ var _Provider = class {
|
|
4255
4485
|
async getBlock(idOrHeight) {
|
4256
4486
|
let variables;
|
4257
4487
|
if (typeof idOrHeight === "number") {
|
4258
|
-
variables = { height:
|
4488
|
+
variables = { height: bn16(idOrHeight).toString(10) };
|
4259
4489
|
} else if (idOrHeight === "latest") {
|
4260
4490
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4261
4491
|
} else if (idOrHeight.length === 66) {
|
4262
4492
|
variables = { blockId: idOrHeight };
|
4263
4493
|
} else {
|
4264
|
-
variables = { blockId:
|
4494
|
+
variables = { blockId: bn16(idOrHeight).toString(10) };
|
4265
4495
|
}
|
4266
4496
|
const { block } = await this.operations.getBlock(variables);
|
4267
4497
|
if (!block) {
|
@@ -4269,7 +4499,7 @@ var _Provider = class {
|
|
4269
4499
|
}
|
4270
4500
|
return {
|
4271
4501
|
id: block.id,
|
4272
|
-
height:
|
4502
|
+
height: bn16(block.height),
|
4273
4503
|
time: block.header.time,
|
4274
4504
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4275
4505
|
};
|
@@ -4284,7 +4514,7 @@ var _Provider = class {
|
|
4284
4514
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4285
4515
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4286
4516
|
id: block.id,
|
4287
|
-
height:
|
4517
|
+
height: bn16(block.height),
|
4288
4518
|
time: block.header.time,
|
4289
4519
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4290
4520
|
}));
|
@@ -4299,7 +4529,7 @@ var _Provider = class {
|
|
4299
4529
|
async getBlockWithTransactions(idOrHeight) {
|
4300
4530
|
let variables;
|
4301
4531
|
if (typeof idOrHeight === "number") {
|
4302
|
-
variables = { blockHeight:
|
4532
|
+
variables = { blockHeight: bn16(idOrHeight).toString(10) };
|
4303
4533
|
} else if (idOrHeight === "latest") {
|
4304
4534
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4305
4535
|
} else {
|
@@ -4311,7 +4541,7 @@ var _Provider = class {
|
|
4311
4541
|
}
|
4312
4542
|
return {
|
4313
4543
|
id: block.id,
|
4314
|
-
height:
|
4544
|
+
height: bn16(block.height, 10),
|
4315
4545
|
time: block.header.time,
|
4316
4546
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4317
4547
|
transactions: block.transactions.map(
|
@@ -4360,7 +4590,7 @@ var _Provider = class {
|
|
4360
4590
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4361
4591
|
asset: hexlify12(assetId)
|
4362
4592
|
});
|
4363
|
-
return
|
4593
|
+
return bn16(contractBalance.amount, 10);
|
4364
4594
|
}
|
4365
4595
|
/**
|
4366
4596
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4374,7 +4604,7 @@ var _Provider = class {
|
|
4374
4604
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4375
4605
|
assetId: hexlify12(assetId)
|
4376
4606
|
});
|
4377
|
-
return
|
4607
|
+
return bn16(balance.amount, 10);
|
4378
4608
|
}
|
4379
4609
|
/**
|
4380
4610
|
* Returns balances for the given owner.
|
@@ -4392,7 +4622,7 @@ var _Provider = class {
|
|
4392
4622
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4393
4623
|
return balances.map((balance) => ({
|
4394
4624
|
assetId: balance.assetId,
|
4395
|
-
amount:
|
4625
|
+
amount: bn16(balance.amount)
|
4396
4626
|
}));
|
4397
4627
|
}
|
4398
4628
|
/**
|
@@ -4414,15 +4644,15 @@ var _Provider = class {
|
|
4414
4644
|
sender: message.sender,
|
4415
4645
|
recipient: message.recipient,
|
4416
4646
|
nonce: message.nonce,
|
4417
|
-
amount:
|
4647
|
+
amount: bn16(message.amount),
|
4418
4648
|
data: message.data
|
4419
4649
|
}),
|
4420
4650
|
sender: Address2.fromAddressOrString(message.sender),
|
4421
4651
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4422
4652
|
nonce: message.nonce,
|
4423
|
-
amount:
|
4653
|
+
amount: bn16(message.amount),
|
4424
4654
|
data: InputMessageCoder.decodeData(message.data),
|
4425
|
-
daHeight:
|
4655
|
+
daHeight: bn16(message.daHeight)
|
4426
4656
|
}));
|
4427
4657
|
}
|
4428
4658
|
/**
|
@@ -4475,44 +4705,60 @@ var _Provider = class {
|
|
4475
4705
|
} = result.messageProof;
|
4476
4706
|
return {
|
4477
4707
|
messageProof: {
|
4478
|
-
proofIndex:
|
4708
|
+
proofIndex: bn16(messageProof.proofIndex),
|
4479
4709
|
proofSet: messageProof.proofSet
|
4480
4710
|
},
|
4481
4711
|
blockProof: {
|
4482
|
-
proofIndex:
|
4712
|
+
proofIndex: bn16(blockProof.proofIndex),
|
4483
4713
|
proofSet: blockProof.proofSet
|
4484
4714
|
},
|
4485
4715
|
messageBlockHeader: {
|
4486
4716
|
id: messageBlockHeader.id,
|
4487
|
-
daHeight:
|
4488
|
-
transactionsCount:
|
4717
|
+
daHeight: bn16(messageBlockHeader.daHeight),
|
4718
|
+
transactionsCount: bn16(messageBlockHeader.transactionsCount),
|
4489
4719
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4490
|
-
height:
|
4720
|
+
height: bn16(messageBlockHeader.height),
|
4491
4721
|
prevRoot: messageBlockHeader.prevRoot,
|
4492
4722
|
time: messageBlockHeader.time,
|
4493
4723
|
applicationHash: messageBlockHeader.applicationHash,
|
4494
|
-
|
4495
|
-
|
4724
|
+
messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
|
4725
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4726
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4727
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4728
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4496
4729
|
},
|
4497
4730
|
commitBlockHeader: {
|
4498
4731
|
id: commitBlockHeader.id,
|
4499
|
-
daHeight:
|
4500
|
-
transactionsCount:
|
4732
|
+
daHeight: bn16(commitBlockHeader.daHeight),
|
4733
|
+
transactionsCount: bn16(commitBlockHeader.transactionsCount),
|
4501
4734
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4502
|
-
height:
|
4735
|
+
height: bn16(commitBlockHeader.height),
|
4503
4736
|
prevRoot: commitBlockHeader.prevRoot,
|
4504
4737
|
time: commitBlockHeader.time,
|
4505
4738
|
applicationHash: commitBlockHeader.applicationHash,
|
4506
|
-
|
4507
|
-
|
4739
|
+
messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
|
4740
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4741
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4742
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4743
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4508
4744
|
},
|
4509
4745
|
sender: Address2.fromAddressOrString(sender),
|
4510
4746
|
recipient: Address2.fromAddressOrString(recipient),
|
4511
4747
|
nonce,
|
4512
|
-
amount:
|
4748
|
+
amount: bn16(amount),
|
4513
4749
|
data
|
4514
4750
|
};
|
4515
4751
|
}
|
4752
|
+
async getLatestGasPrice() {
|
4753
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4754
|
+
return bn16(latestGasPrice.gasPrice);
|
4755
|
+
}
|
4756
|
+
async estimateGasPrice(blockHorizon) {
|
4757
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4758
|
+
blockHorizon: String(blockHorizon)
|
4759
|
+
});
|
4760
|
+
return bn16(estimateGasPrice.gasPrice);
|
4761
|
+
}
|
4516
4762
|
/**
|
4517
4763
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4518
4764
|
*
|
@@ -4532,10 +4778,10 @@ var _Provider = class {
|
|
4532
4778
|
*/
|
4533
4779
|
async produceBlocks(amount, startTime) {
|
4534
4780
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4535
|
-
blocksToProduce:
|
4781
|
+
blocksToProduce: bn16(amount).toString(10),
|
4536
4782
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4537
4783
|
});
|
4538
|
-
return
|
4784
|
+
return bn16(latestBlockHeight);
|
4539
4785
|
}
|
4540
4786
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4541
4787
|
async getTransactionResponse(transactionId) {
|
@@ -4559,7 +4805,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4559
4805
|
|
4560
4806
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4561
4807
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4562
|
-
import { bn as
|
4808
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
4563
4809
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4564
4810
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4565
4811
|
async function getTransactionSummary(params) {
|
@@ -4577,21 +4823,28 @@ async function getTransactionSummary(params) {
|
|
4577
4823
|
arrayify12(gqlTransaction.rawPayload),
|
4578
4824
|
0
|
4579
4825
|
);
|
4580
|
-
|
4826
|
+
let txReceipts = [];
|
4827
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4828
|
+
txReceipts = gqlTransaction.status.receipts;
|
4829
|
+
}
|
4830
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4581
4831
|
const {
|
4582
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4832
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4583
4833
|
} = provider.getChain();
|
4834
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4584
4835
|
const transactionInfo = assembleTransactionSummary({
|
4585
4836
|
id: gqlTransaction.id,
|
4586
4837
|
receipts,
|
4587
4838
|
transaction: decodedTransaction,
|
4588
4839
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4589
4840
|
gqlTransactionStatus: gqlTransaction.status,
|
4590
|
-
gasPerByte:
|
4591
|
-
gasPriceFactor:
|
4841
|
+
gasPerByte: bn17(gasPerByte),
|
4842
|
+
gasPriceFactor: bn17(gasPriceFactor),
|
4592
4843
|
abiMap,
|
4593
4844
|
maxInputs,
|
4594
|
-
gasCosts
|
4845
|
+
gasCosts,
|
4846
|
+
maxGasPerTx,
|
4847
|
+
gasPrice
|
4595
4848
|
});
|
4596
4849
|
return {
|
4597
4850
|
gqlTransaction,
|
@@ -4601,10 +4854,11 @@ async function getTransactionSummary(params) {
|
|
4601
4854
|
async function getTransactionSummaryFromRequest(params) {
|
4602
4855
|
const { provider, transactionRequest, abiMap } = params;
|
4603
4856
|
const { receipts } = await provider.call(transactionRequest);
|
4604
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4857
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4605
4858
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4606
4859
|
const transaction = transactionRequest.toTransaction();
|
4607
4860
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4861
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4608
4862
|
const transactionSummary = assembleTransactionSummary({
|
4609
4863
|
receipts,
|
4610
4864
|
transaction,
|
@@ -4613,7 +4867,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4613
4867
|
gasPerByte,
|
4614
4868
|
gasPriceFactor,
|
4615
4869
|
maxInputs,
|
4616
|
-
gasCosts
|
4870
|
+
gasCosts,
|
4871
|
+
maxGasPerTx,
|
4872
|
+
gasPrice
|
4617
4873
|
});
|
4618
4874
|
return transactionSummary;
|
4619
4875
|
}
|
@@ -4622,13 +4878,18 @@ async function getTransactionsSummaries(params) {
|
|
4622
4878
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4623
4879
|
const { edges, pageInfo } = transactionsByOwner;
|
4624
4880
|
const {
|
4625
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4881
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4626
4882
|
} = provider.getChain();
|
4883
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4627
4884
|
const transactions = edges.map((edge) => {
|
4628
4885
|
const { node: gqlTransaction } = edge;
|
4629
|
-
const { id, rawPayload,
|
4886
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4630
4887
|
const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
|
4631
|
-
|
4888
|
+
let txReceipts = [];
|
4889
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4890
|
+
txReceipts = gqlTransaction.status.receipts;
|
4891
|
+
}
|
4892
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4632
4893
|
const transactionSummary = assembleTransactionSummary({
|
4633
4894
|
id,
|
4634
4895
|
receipts,
|
@@ -4639,7 +4900,9 @@ async function getTransactionsSummaries(params) {
|
|
4639
4900
|
gasPerByte,
|
4640
4901
|
gasPriceFactor,
|
4641
4902
|
maxInputs,
|
4642
|
-
gasCosts
|
4903
|
+
gasCosts,
|
4904
|
+
maxGasPerTx,
|
4905
|
+
gasPrice
|
4643
4906
|
});
|
4644
4907
|
const output = {
|
4645
4908
|
gqlTransaction,
|
@@ -4971,36 +5234,33 @@ var Account = class extends AbstractAccount {
|
|
4971
5234
|
* @param fee - The estimated transaction fee.
|
4972
5235
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4973
5236
|
*/
|
4974
|
-
async fund(request,
|
4975
|
-
const
|
4976
|
-
|
5237
|
+
async fund(request, params) {
|
5238
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5239
|
+
const txRequest = request;
|
5240
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5241
|
+
amount: bn18(fee),
|
4977
5242
|
assetId: BaseAssetId3,
|
4978
|
-
coinQuantities
|
5243
|
+
coinQuantities: requiredQuantities
|
4979
5244
|
});
|
4980
5245
|
const quantitiesDict = {};
|
4981
|
-
|
5246
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4982
5247
|
quantitiesDict[assetId] = {
|
4983
5248
|
required: amount,
|
4984
|
-
owned:
|
5249
|
+
owned: bn18(0)
|
4985
5250
|
};
|
4986
5251
|
});
|
4987
|
-
|
4988
|
-
const cachedMessages = [];
|
4989
|
-
const owner = this.address.toB256();
|
4990
|
-
request.inputs.forEach((input) => {
|
5252
|
+
txRequest.inputs.forEach((input) => {
|
4991
5253
|
const isResource = "amount" in input;
|
4992
5254
|
if (isResource) {
|
4993
5255
|
const isCoin2 = "owner" in input;
|
4994
5256
|
if (isCoin2) {
|
4995
5257
|
const assetId = String(input.assetId);
|
4996
|
-
if (
|
4997
|
-
const amount =
|
5258
|
+
if (quantitiesDict[assetId]) {
|
5259
|
+
const amount = bn18(input.amount);
|
4998
5260
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4999
|
-
cachedUtxos.push(input.id);
|
5000
5261
|
}
|
5001
|
-
} else if (input.
|
5262
|
+
} else if (input.amount && quantitiesDict[BaseAssetId3]) {
|
5002
5263
|
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
5003
|
-
cachedMessages.push(input.nonce);
|
5004
5264
|
}
|
5005
5265
|
}
|
5006
5266
|
});
|
@@ -5015,12 +5275,23 @@ var Account = class extends AbstractAccount {
|
|
5015
5275
|
});
|
5016
5276
|
const needsToBeFunded = missingQuantities.length;
|
5017
5277
|
if (needsToBeFunded) {
|
5018
|
-
const
|
5019
|
-
|
5020
|
-
|
5021
|
-
|
5022
|
-
|
5278
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5279
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5280
|
+
txRequest.addResources(resources);
|
5281
|
+
}
|
5282
|
+
txRequest.shiftPredicateData();
|
5283
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5284
|
+
const requestToBeReEstimate = clone4(txRequest);
|
5285
|
+
if (addedSignatures) {
|
5286
|
+
Array.from({ length: addedSignatures }).forEach(
|
5287
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5288
|
+
);
|
5023
5289
|
}
|
5290
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5291
|
+
transactionRequest: requestToBeReEstimate
|
5292
|
+
});
|
5293
|
+
txRequest.maxFee = maxFee;
|
5294
|
+
return txRequest;
|
5024
5295
|
}
|
5025
5296
|
/**
|
5026
5297
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5028,28 +5299,25 @@ var Account = class extends AbstractAccount {
|
|
5028
5299
|
* @param destination - The address of the destination.
|
5029
5300
|
* @param amount - The amount of coins to transfer.
|
5030
5301
|
* @param assetId - The asset ID of the coins to transfer.
|
5031
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5302
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5032
5303
|
* @returns A promise that resolves to the prepared transaction request.
|
5033
5304
|
*/
|
5034
5305
|
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5035
|
-
const
|
5036
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5037
|
-
const request = new ScriptTransactionRequest(params);
|
5306
|
+
const request = new ScriptTransactionRequest(txParams);
|
5038
5307
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
5039
|
-
const
|
5308
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5040
5309
|
estimateTxDependencies: true,
|
5041
5310
|
resourcesOwner: this
|
5042
5311
|
});
|
5043
|
-
|
5044
|
-
|
5045
|
-
|
5046
|
-
|
5047
|
-
|
5048
|
-
|
5049
|
-
|
5050
|
-
|
5051
|
-
await this.fund(request,
|
5052
|
-
request.updatePredicateInputs(estimatedInputs);
|
5312
|
+
if ("gasLimit" in txParams) {
|
5313
|
+
this.validateGas({
|
5314
|
+
gasUsed: txCost.gasUsed,
|
5315
|
+
gasLimit: request.gasLimit
|
5316
|
+
});
|
5317
|
+
}
|
5318
|
+
request.gasLimit = txCost.gasUsed;
|
5319
|
+
request.maxFee = txCost.maxFee;
|
5320
|
+
await this.fund(request, txCost);
|
5053
5321
|
return request;
|
5054
5322
|
}
|
5055
5323
|
/**
|
@@ -5062,7 +5330,7 @@ var Account = class extends AbstractAccount {
|
|
5062
5330
|
* @returns A promise that resolves to the transaction response.
|
5063
5331
|
*/
|
5064
5332
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5065
|
-
if (
|
5333
|
+
if (bn18(amount).lte(0)) {
|
5066
5334
|
throw new FuelError15(
|
5067
5335
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5068
5336
|
"Transfer amount must be a positive number."
|
@@ -5081,38 +5349,37 @@ var Account = class extends AbstractAccount {
|
|
5081
5349
|
* @returns A promise that resolves to the transaction response.
|
5082
5350
|
*/
|
5083
5351
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5084
|
-
if (
|
5352
|
+
if (bn18(amount).lte(0)) {
|
5085
5353
|
throw new FuelError15(
|
5086
5354
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5087
5355
|
"Transfer amount must be a positive number."
|
5088
5356
|
);
|
5089
5357
|
}
|
5090
5358
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5091
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5092
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5093
5359
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5094
5360
|
hexlifiedContractId: contractAddress.toB256(),
|
5095
|
-
amountToTransfer:
|
5361
|
+
amountToTransfer: bn18(amount),
|
5096
5362
|
assetId
|
5097
5363
|
});
|
5098
5364
|
const request = new ScriptTransactionRequest({
|
5099
|
-
...
|
5365
|
+
...txParams,
|
5100
5366
|
script,
|
5101
5367
|
scriptData
|
5102
5368
|
});
|
5103
5369
|
request.addContractInputAndOutput(contractAddress);
|
5104
|
-
const
|
5105
|
-
|
5106
|
-
[{ amount:
|
5107
|
-
);
|
5108
|
-
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5109
|
-
this.validateGas({
|
5110
|
-
gasUsed,
|
5111
|
-
gasPrice: request.gasPrice,
|
5112
|
-
gasLimit: request.gasLimit,
|
5113
|
-
minGasPrice
|
5370
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5371
|
+
resourcesOwner: this,
|
5372
|
+
quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
|
5114
5373
|
});
|
5115
|
-
|
5374
|
+
if (txParams.gasLimit) {
|
5375
|
+
this.validateGas({
|
5376
|
+
gasUsed: txCost.gasUsed,
|
5377
|
+
gasLimit: request.gasLimit
|
5378
|
+
});
|
5379
|
+
}
|
5380
|
+
request.gasLimit = txCost.gasUsed;
|
5381
|
+
request.maxFee = txCost.maxFee;
|
5382
|
+
await this.fund(request, txCost);
|
5116
5383
|
return this.sendTransaction(request);
|
5117
5384
|
}
|
5118
5385
|
/**
|
@@ -5124,34 +5391,31 @@ var Account = class extends AbstractAccount {
|
|
5124
5391
|
* @returns A promise that resolves to the transaction response.
|
5125
5392
|
*/
|
5126
5393
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5127
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5128
5394
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5129
5395
|
const recipientDataArray = arrayify14(
|
5130
5396
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5131
5397
|
);
|
5132
5398
|
const amountDataArray = arrayify14(
|
5133
|
-
"0x".concat(
|
5399
|
+
"0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
|
5134
5400
|
);
|
5135
5401
|
const script = new Uint8Array([
|
5136
5402
|
...arrayify14(withdrawScript.bytes),
|
5137
5403
|
...recipientDataArray,
|
5138
5404
|
...amountDataArray
|
5139
5405
|
]);
|
5140
|
-
const params = { script,
|
5406
|
+
const params = { script, ...txParams };
|
5141
5407
|
const request = new ScriptTransactionRequest(params);
|
5142
|
-
const
|
5143
|
-
const
|
5144
|
-
|
5145
|
-
|
5146
|
-
|
5147
|
-
|
5148
|
-
|
5149
|
-
|
5150
|
-
|
5151
|
-
|
5152
|
-
|
5153
|
-
});
|
5154
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5408
|
+
const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
|
5409
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5410
|
+
if (txParams.gasLimit) {
|
5411
|
+
this.validateGas({
|
5412
|
+
gasUsed: txCost.gasUsed,
|
5413
|
+
gasLimit: request.gasLimit
|
5414
|
+
});
|
5415
|
+
}
|
5416
|
+
request.maxFee = txCost.maxFee;
|
5417
|
+
request.gasLimit = txCost.gasUsed;
|
5418
|
+
await this.fund(request, txCost);
|
5155
5419
|
return this.sendTransaction(request);
|
5156
5420
|
}
|
5157
5421
|
async signMessage(message) {
|
@@ -5209,18 +5473,7 @@ var Account = class extends AbstractAccount {
|
|
5209
5473
|
}
|
5210
5474
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5211
5475
|
}
|
5212
|
-
validateGas({
|
5213
|
-
gasUsed,
|
5214
|
-
gasPrice,
|
5215
|
-
gasLimit,
|
5216
|
-
minGasPrice
|
5217
|
-
}) {
|
5218
|
-
if (minGasPrice.gt(gasPrice)) {
|
5219
|
-
throw new FuelError15(
|
5220
|
-
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5221
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5222
|
-
);
|
5223
|
-
}
|
5476
|
+
validateGas({ gasUsed, gasLimit }) {
|
5224
5477
|
if (gasUsed.gt(gasLimit)) {
|
5225
5478
|
throw new FuelError15(
|
5226
5479
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
@@ -5516,7 +5769,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5516
5769
|
* @param transactionRequestLike - The transaction request to send.
|
5517
5770
|
* @returns A promise that resolves to the TransactionResponse object.
|
5518
5771
|
*/
|
5519
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5772
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5520
5773
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5521
5774
|
if (estimateTxDependencies) {
|
5522
5775
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5557,7 +5810,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5557
5810
|
// src/hdwallet/hdwallet.ts
|
5558
5811
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5559
5812
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5560
|
-
import { bn as
|
5813
|
+
import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5561
5814
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5562
5815
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5563
5816
|
|
@@ -8029,7 +8282,7 @@ var HDWallet = class {
|
|
8029
8282
|
const IR = bytes.slice(32);
|
8030
8283
|
if (privateKey) {
|
8031
8284
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8032
|
-
const ki =
|
8285
|
+
const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
|
8033
8286
|
return new HDWallet({
|
8034
8287
|
privateKey: ki,
|
8035
8288
|
chainCode: IR,
|
@@ -8718,7 +8971,7 @@ import {
|
|
8718
8971
|
import { Address as Address9 } from "@fuel-ts/address";
|
8719
8972
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8720
8973
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8721
|
-
import { ByteArrayCoder } from "@fuel-ts/transactions";
|
8974
|
+
import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
|
8722
8975
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8723
8976
|
|
8724
8977
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -8777,15 +9030,10 @@ var Predicate = class extends Account {
|
|
8777
9030
|
populateTransactionPredicateData(transactionRequestLike) {
|
8778
9031
|
const request = transactionRequestify(transactionRequestLike);
|
8779
9032
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8780
|
-
|
8781
|
-
|
8782
|
-
|
8783
|
-
|
8784
|
-
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
8785
|
-
if (isRequestInputResourceFromOwner(input, this.address)) {
|
8786
|
-
input.predicate = this.bytes;
|
8787
|
-
input.predicateData = this.getPredicateData(policies.length);
|
8788
|
-
input.witnessIndex = 0;
|
9033
|
+
request.inputs?.forEach((input) => {
|
9034
|
+
if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
9035
|
+
input.predicate = hexlify19(this.bytes);
|
9036
|
+
input.predicateData = hexlify19(this.getPredicateData(policies.length));
|
8789
9037
|
}
|
8790
9038
|
});
|
8791
9039
|
return request;
|
@@ -8800,8 +9048,7 @@ var Predicate = class extends Account {
|
|
8800
9048
|
* @returns A promise that resolves to the prepared transaction request.
|
8801
9049
|
*/
|
8802
9050
|
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
8803
|
-
|
8804
|
-
return this.populateTransactionPredicateData(request);
|
9051
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8805
9052
|
}
|
8806
9053
|
/**
|
8807
9054
|
* Sends a transaction with the populated predicate data.
|
@@ -8809,9 +9056,9 @@ var Predicate = class extends Account {
|
|
8809
9056
|
* @param transactionRequestLike - The transaction request-like object.
|
8810
9057
|
* @returns A promise that resolves to the transaction response.
|
8811
9058
|
*/
|
8812
|
-
sendTransaction(transactionRequestLike
|
8813
|
-
const transactionRequest =
|
8814
|
-
return super.sendTransaction(transactionRequest,
|
9059
|
+
sendTransaction(transactionRequestLike) {
|
9060
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9061
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8815
9062
|
}
|
8816
9063
|
/**
|
8817
9064
|
* Simulates a transaction with the populated predicate data.
|
@@ -8820,22 +9067,8 @@ var Predicate = class extends Account {
|
|
8820
9067
|
* @returns A promise that resolves to the call result.
|
8821
9068
|
*/
|
8822
9069
|
simulateTransaction(transactionRequestLike) {
|
8823
|
-
const transactionRequest =
|
8824
|
-
return super.simulateTransaction(transactionRequest);
|
8825
|
-
}
|
8826
|
-
/**
|
8827
|
-
* Retrieves resources satisfying the spend query for the account.
|
8828
|
-
*
|
8829
|
-
* @param quantities - Coins to retrieve.
|
8830
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
8831
|
-
* @returns A promise that resolves to an array of Resources.
|
8832
|
-
*/
|
8833
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
8834
|
-
const resources = await super.getResourcesToSpend(quantities, excludedIds);
|
8835
|
-
return resources.map((resource) => ({
|
8836
|
-
...resource,
|
8837
|
-
predicate: hexlify19(this.bytes)
|
8838
|
-
}));
|
9070
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9071
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8839
9072
|
}
|
8840
9073
|
getPredicateData(policiesLength) {
|
8841
9074
|
if (!this.predicateData.length) {
|
@@ -8881,6 +9114,25 @@ var Predicate = class extends Account {
|
|
8881
9114
|
predicateInterface: abiInterface
|
8882
9115
|
};
|
8883
9116
|
}
|
9117
|
+
/**
|
9118
|
+
* Retrieves resources satisfying the spend query for the account.
|
9119
|
+
*
|
9120
|
+
* @param quantities - IDs of coins to exclude.
|
9121
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9122
|
+
* @returns A promise that resolves to an array of Resources.
|
9123
|
+
*/
|
9124
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9125
|
+
const resources = await this.provider.getResourcesToSpend(
|
9126
|
+
this.address,
|
9127
|
+
quantities,
|
9128
|
+
excludedIds
|
9129
|
+
);
|
9130
|
+
return resources.map((resource) => ({
|
9131
|
+
...resource,
|
9132
|
+
predicate: hexlify19(this.bytes),
|
9133
|
+
paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
|
9134
|
+
}));
|
9135
|
+
}
|
8884
9136
|
/**
|
8885
9137
|
* Sets the configurable constants for the predicate.
|
8886
9138
|
*
|
@@ -8916,28 +9168,6 @@ var Predicate = class extends Account {
|
|
8916
9168
|
}
|
8917
9169
|
return mutatedBytes;
|
8918
9170
|
}
|
8919
|
-
/**
|
8920
|
-
* Returns the index of the witness placeholder that was added to this predicate.
|
8921
|
-
* If no witness placeholder was added, it returns -1.
|
8922
|
-
* @param request - The transaction request.
|
8923
|
-
* @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
|
8924
|
-
*/
|
8925
|
-
getIndexFromPlaceholderWitness(request) {
|
8926
|
-
const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
|
8927
|
-
let index = -1;
|
8928
|
-
const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
|
8929
|
-
if (hasEmptyPredicateInputs) {
|
8930
|
-
index = hasEmptyPredicateInputs.witnessIndex;
|
8931
|
-
const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
|
8932
|
-
if (!allInputsAreEmpty) {
|
8933
|
-
const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
|
8934
|
-
if (wasFilledInputAddedFirst) {
|
8935
|
-
index = -1;
|
8936
|
-
}
|
8937
|
-
}
|
8938
|
-
}
|
8939
|
-
return index;
|
8940
|
-
}
|
8941
9171
|
};
|
8942
9172
|
|
8943
9173
|
// src/connectors/fuel.ts
|
@@ -9651,7 +9881,7 @@ export {
|
|
9651
9881
|
WalletLocked,
|
9652
9882
|
WalletManager,
|
9653
9883
|
WalletUnlocked,
|
9654
|
-
|
9884
|
+
addAmountToCoinQuantities,
|
9655
9885
|
addOperation,
|
9656
9886
|
assemblePanicError,
|
9657
9887
|
assembleReceiptByType,
|
@@ -9660,10 +9890,10 @@ export {
|
|
9660
9890
|
assets,
|
9661
9891
|
buildBlockExplorerUrl,
|
9662
9892
|
cacheFor,
|
9663
|
-
|
9893
|
+
cacheTxInputsFromOwner,
|
9894
|
+
calculateGasFee,
|
9664
9895
|
calculateMetadataGasForTxCreate,
|
9665
9896
|
calculateMetadataGasForTxScript,
|
9666
|
-
calculatePriceWithFactor,
|
9667
9897
|
calculateTransactionFee,
|
9668
9898
|
coinQuantityfy,
|
9669
9899
|
deferPromise,
|
@@ -9707,7 +9937,6 @@ export {
|
|
9707
9937
|
getReceiptsMessageOut,
|
9708
9938
|
getReceiptsTransferOut,
|
9709
9939
|
getReceiptsWithMissingData,
|
9710
|
-
getRequestInputResourceOwner,
|
9711
9940
|
getTransactionStatusName,
|
9712
9941
|
getTransactionSummary,
|
9713
9942
|
getTransactionSummaryFromRequest,
|
@@ -9721,10 +9950,6 @@ export {
|
|
9721
9950
|
isMessage,
|
9722
9951
|
isRawCoin,
|
9723
9952
|
isRawMessage,
|
9724
|
-
isRequestInputCoin,
|
9725
|
-
isRequestInputMessage,
|
9726
|
-
isRequestInputResource,
|
9727
|
-
isRequestInputResourceFromOwner,
|
9728
9953
|
isType,
|
9729
9954
|
isTypeCreate,
|
9730
9955
|
isTypeMint,
|