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