@fuel-ts/account 0.97.1 → 0.98.0
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.
- package/dist/account.d.ts +19 -16
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +4 -4
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/fuel.d.ts +3 -3
- package/dist/connectors/fuel.d.ts.map +1 -1
- package/dist/connectors/types/data-type.d.ts +8 -0
- package/dist/connectors/types/data-type.d.ts.map +1 -1
- package/dist/hdwallet/hdwallet.d.ts +1 -1
- package/dist/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +2923 -1250
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +333 -279
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +358 -309
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts +1 -1
- package/dist/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic/utils.d.ts +1 -1
- package/dist/mnemonic/utils.d.ts.map +1 -1
- package/dist/predicate/predicate.d.ts +9 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/predicate/utils/getPredicateRoot.d.ts +1 -1
- package/dist/predicate/utils/getPredicateRoot.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +0 -169
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +3 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +8 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +27 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource.d.ts +1 -1
- package/dist/providers/resource.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/errors.d.ts +3 -3
- package/dist/providers/transaction-request/errors.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +26 -4
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +1 -1
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/output.d.ts +1 -1
- package/dist/providers/transaction-request/output.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +13 -3
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/scripts.d.ts +1 -1
- package/dist/providers/transaction-request/scripts.d.ts.map +1 -1
- package/dist/providers/transaction-request/storage-slot.d.ts +1 -1
- package/dist/providers/transaction-request/storage-slot.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +5 -3
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/types.d.ts +7 -0
- package/dist/providers/transaction-request/types.d.ts.map +1 -1
- package/dist/providers/transaction-request/upgrade-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/upgrade-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/upload-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/upload-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/witness.d.ts +1 -1
- package/dist/providers/transaction-request/witness.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts +0 -1
- package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/input.d.ts +1 -1
- package/dist/providers/transaction-summary/status.d.ts +9 -2
- package/dist/providers/transaction-summary/status.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +1 -21
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/providers/utils/receipts.d.ts.map +1 -1
- package/dist/signer/signer.d.ts +1 -1
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +4 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -1
- package/dist/test-utils/test-coin.d.ts +1 -0
- package/dist/test-utils/test-coin.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +6 -6
- package/dist/test-utils/test-message.d.ts.map +1 -1
- package/dist/test-utils.global.js +3033 -1799
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +294 -223
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +323 -252
- package/dist/test-utils.mjs.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/formatTransferToContractScriptData.d.ts +1 -1
- package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/dist/wallet/keystore-wallet.d.ts +2 -2
- package/dist/wallet/keystore-wallet.d.ts.map +1 -1
- package/dist/wallet/wallet.d.ts +3 -2
- package/dist/wallet/wallet.d.ts.map +1 -1
- package/dist/wallet/wallets.d.ts +1 -1
- package/dist/wallet/wallets.d.ts.map +1 -1
- package/dist/wallet-manager/types.d.ts +4 -4
- package/dist/wallet-manager/types.d.ts.map +1 -1
- package/dist/wallet-manager/vaults/mnemonic-vault.d.ts +5 -5
- package/dist/wallet-manager/vaults/mnemonic-vault.d.ts.map +1 -1
- package/dist/wallet-manager/vaults/privatekey-vault.d.ts +5 -5
- package/dist/wallet-manager/vaults/privatekey-vault.d.ts.map +1 -1
- package/dist/wallet-manager/wallet-manager.d.ts +3 -3
- package/dist/wallet-manager/wallet-manager.d.ts.map +1 -1
- package/package.json +27 -28
package/dist/test-utils.mjs
CHANGED
@@ -154,7 +154,11 @@ var extractRemainingArgs = (args, flagsToRemove) => {
|
|
154
154
|
});
|
155
155
|
return newArgs;
|
156
156
|
};
|
157
|
-
function getFinalStateConfigJSON({
|
157
|
+
function getFinalStateConfigJSON({
|
158
|
+
stateConfig,
|
159
|
+
chainConfig,
|
160
|
+
includeInitialState = false
|
161
|
+
}) {
|
158
162
|
const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
159
163
|
...coin,
|
160
164
|
amount: "18446744073709551615"
|
@@ -165,6 +169,26 @@ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
|
165
169
|
}));
|
166
170
|
const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
|
167
171
|
const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
|
172
|
+
if (includeInitialState) {
|
173
|
+
coins.push({
|
174
|
+
tx_id: "0x0000000000000000000000000000000000000000000000000000000000000001",
|
175
|
+
output_index: 0,
|
176
|
+
tx_pointer_block_height: 0,
|
177
|
+
tx_pointer_tx_idx: 0,
|
178
|
+
owner: "0x94ffcc53b892684acefaebc8a3d4a595e528a8cf664eeb3ef36f1020b0809d0d",
|
179
|
+
amount: "18446744073709551615",
|
180
|
+
asset_id: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
181
|
+
});
|
182
|
+
coins.push({
|
183
|
+
tx_id: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
184
|
+
output_index: 0,
|
185
|
+
tx_pointer_block_height: 0,
|
186
|
+
tx_pointer_tx_idx: 0,
|
187
|
+
owner: "0x09c0b2d1a486c439a87bcba6b46a7a1a23f3897cc83a94521a96da5c23bc58db",
|
188
|
+
amount: "18446744073709551615",
|
189
|
+
asset_id: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
190
|
+
});
|
191
|
+
}
|
168
192
|
if (!process.env.GENESIS_SECRET) {
|
169
193
|
const pk = Signer.generatePrivateKey();
|
170
194
|
const signer = new Signer(pk);
|
@@ -174,7 +198,7 @@ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
|
174
198
|
owner: signer.address.toHexString(),
|
175
199
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
176
200
|
amount: "18446744073709551615",
|
177
|
-
asset_id: chainConfig.consensus_parameters.
|
201
|
+
asset_id: chainConfig.consensus_parameters.V2.base_asset_id,
|
178
202
|
output_index: 0,
|
179
203
|
tx_pointer_block_height: 0,
|
180
204
|
tx_pointer_tx_idx: 0
|
@@ -195,7 +219,9 @@ var launchNode = async ({
|
|
195
219
|
fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
|
196
220
|
loggingEnabled = true,
|
197
221
|
basePath,
|
198
|
-
snapshotConfig = defaultSnapshotConfigs
|
222
|
+
snapshotConfig = defaultSnapshotConfigs,
|
223
|
+
includeInitialState = false,
|
224
|
+
killProcessOnExit = false
|
199
225
|
} = {}) => (
|
200
226
|
// eslint-disable-next-line no-async-promise-executor
|
201
227
|
new Promise(async (resolve, reject) => {
|
@@ -235,7 +261,14 @@ var launchNode = async ({
|
|
235
261
|
const stateConfigPath = path.join(tempDir, metadata.table_encoding.Json.filepath);
|
236
262
|
const stateTransitionPath = path.join(tempDir, "state_transition_bytecode.wasm");
|
237
263
|
writeFileSync(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
|
238
|
-
writeFileSync(
|
264
|
+
writeFileSync(
|
265
|
+
stateConfigPath,
|
266
|
+
getFinalStateConfigJSON({
|
267
|
+
...snapshotConfig,
|
268
|
+
includeInitialState
|
269
|
+
}),
|
270
|
+
"utf8"
|
271
|
+
);
|
239
272
|
writeFileSync(metadataPath, JSON.stringify(metadata), "utf8");
|
240
273
|
writeFileSync(stateTransitionPath, JSON.stringify(""));
|
241
274
|
snapshotDirToUse = tempDir;
|
@@ -265,14 +298,14 @@ var launchNode = async ({
|
|
265
298
|
console.log(chunk.toString());
|
266
299
|
});
|
267
300
|
}
|
268
|
-
const
|
301
|
+
const removeChildListeners = () => {
|
269
302
|
child.stderr.removeAllListeners();
|
303
|
+
};
|
304
|
+
const removeTempDir = () => {
|
270
305
|
if (existsSync(tempDir)) {
|
271
306
|
rmSync(tempDir, { recursive: true });
|
272
307
|
}
|
273
308
|
};
|
274
|
-
child.on("error", removeSideffects);
|
275
|
-
child.on("exit", removeSideffects);
|
276
309
|
const childState = {
|
277
310
|
isDead: false
|
278
311
|
};
|
@@ -281,7 +314,7 @@ var launchNode = async ({
|
|
281
314
|
return;
|
282
315
|
}
|
283
316
|
childState.isDead = true;
|
284
|
-
|
317
|
+
removeChildListeners();
|
285
318
|
if (child.pid !== void 0) {
|
286
319
|
try {
|
287
320
|
process.kill(-child.pid);
|
@@ -300,6 +333,7 @@ var launchNode = async ({
|
|
300
333
|
} else {
|
301
334
|
console.error("No PID available for the child process, unable to kill launched node");
|
302
335
|
}
|
336
|
+
removeTempDir();
|
303
337
|
};
|
304
338
|
child.stderr.on("data", (chunk) => {
|
305
339
|
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
@@ -328,7 +362,18 @@ var launchNode = async ({
|
|
328
362
|
process.on("SIGUSR2", cleanup);
|
329
363
|
process.on("beforeExit", cleanup);
|
330
364
|
process.on("uncaughtException", cleanup);
|
331
|
-
child.on("
|
365
|
+
child.on("exit", (code, _signal) => {
|
366
|
+
removeChildListeners();
|
367
|
+
removeTempDir();
|
368
|
+
if (killProcessOnExit) {
|
369
|
+
process.exit(code);
|
370
|
+
}
|
371
|
+
});
|
372
|
+
child.on("error", (err) => {
|
373
|
+
removeChildListeners();
|
374
|
+
removeTempDir();
|
375
|
+
reject(err);
|
376
|
+
});
|
332
377
|
})
|
333
378
|
);
|
334
379
|
|
@@ -373,7 +418,7 @@ var addAmountToCoinQuantities = (params) => {
|
|
373
418
|
|
374
419
|
// src/providers/provider.ts
|
375
420
|
import { Address as Address3 } from "@fuel-ts/address";
|
376
|
-
import { ErrorCode as
|
421
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError19 } from "@fuel-ts/errors";
|
377
422
|
import { BN as BN2, bn as bn17 } from "@fuel-ts/math";
|
378
423
|
import { InputType as InputType7, InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
|
379
424
|
import { arrayify as arrayify13, hexlify as hexlify17, DateTime as DateTime2, isDefined as isDefined2 } from "@fuel-ts/utils";
|
@@ -1244,13 +1289,6 @@ var GetConsensusParametersVersionDocument = gql`
|
|
1244
1289
|
}
|
1245
1290
|
}
|
1246
1291
|
`;
|
1247
|
-
var SubmitAndAwaitDocument = gql`
|
1248
|
-
subscription submitAndAwait($encodedTransaction: HexString!) {
|
1249
|
-
submitAndAwait(tx: $encodedTransaction) {
|
1250
|
-
...transactionStatusSubscriptionFragment
|
1251
|
-
}
|
1252
|
-
}
|
1253
|
-
${TransactionStatusSubscriptionFragmentDoc}`;
|
1254
1292
|
var SubmitAndAwaitStatusDocument = gql`
|
1255
1293
|
subscription submitAndAwaitStatus($encodedTransaction: HexString!) {
|
1256
1294
|
submitAndAwaitStatus(tx: $encodedTransaction) {
|
@@ -1366,9 +1404,6 @@ function getSdk(requester) {
|
|
1366
1404
|
getConsensusParametersVersion(variables, options) {
|
1367
1405
|
return requester(GetConsensusParametersVersionDocument, variables, options);
|
1368
1406
|
},
|
1369
|
-
submitAndAwait(variables, options) {
|
1370
|
-
return requester(SubmitAndAwaitDocument, variables, options);
|
1371
|
-
},
|
1372
1407
|
submitAndAwaitStatus(variables, options) {
|
1373
1408
|
return requester(SubmitAndAwaitStatusDocument, variables, options);
|
1374
1409
|
},
|
@@ -1652,13 +1687,13 @@ import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
|
1652
1687
|
import { Address as Address2, addressify } from "@fuel-ts/address";
|
1653
1688
|
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1654
1689
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
1655
|
-
import { FuelError as
|
1690
|
+
import { FuelError as FuelError10 } from "@fuel-ts/errors";
|
1656
1691
|
import { bn as bn8 } from "@fuel-ts/math";
|
1657
1692
|
import {
|
1658
1693
|
PolicyType,
|
1659
1694
|
TransactionCoder,
|
1660
1695
|
InputType as InputType3,
|
1661
|
-
OutputType as
|
1696
|
+
OutputType as OutputType3,
|
1662
1697
|
TransactionType
|
1663
1698
|
} from "@fuel-ts/transactions";
|
1664
1699
|
import { concat as concat2, hexlify as hexlify10, isDefined } from "@fuel-ts/utils";
|
@@ -1702,7 +1737,6 @@ function assembleReceiptByType(receipt) {
|
|
1702
1737
|
const callReceipt = {
|
1703
1738
|
type: ReceiptType.Call,
|
1704
1739
|
id,
|
1705
|
-
from: id,
|
1706
1740
|
to: hexOrZero(receipt?.to),
|
1707
1741
|
amount: bn4(receipt.amount),
|
1708
1742
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1770,10 +1804,6 @@ function assembleReceiptByType(receipt) {
|
|
1770
1804
|
rb,
|
1771
1805
|
rc,
|
1772
1806
|
rd,
|
1773
|
-
val0: ra,
|
1774
|
-
val1: rb,
|
1775
|
-
val2: rc,
|
1776
|
-
val3: rd,
|
1777
1807
|
pc: bn4(receipt.pc),
|
1778
1808
|
is: bn4(receipt.is)
|
1779
1809
|
};
|
@@ -1787,8 +1817,6 @@ function assembleReceiptByType(receipt) {
|
|
1787
1817
|
id: hexOrZero(receipt.id || receipt.contractId),
|
1788
1818
|
ra,
|
1789
1819
|
rb,
|
1790
|
-
val0: ra,
|
1791
|
-
val1: rb,
|
1792
1820
|
ptr: bn4(receipt.ptr),
|
1793
1821
|
len: bn4(receipt.len),
|
1794
1822
|
digest: hexOrZero(receipt.digest),
|
@@ -1803,7 +1831,6 @@ function assembleReceiptByType(receipt) {
|
|
1803
1831
|
const transferReceipt = {
|
1804
1832
|
type: ReceiptType.Transfer,
|
1805
1833
|
id,
|
1806
|
-
from: id,
|
1807
1834
|
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1808
1835
|
amount: bn4(receipt.amount),
|
1809
1836
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1817,7 +1844,6 @@ function assembleReceiptByType(receipt) {
|
|
1817
1844
|
const transferOutReceipt = {
|
1818
1845
|
type: ReceiptType.TransferOut,
|
1819
1846
|
id,
|
1820
|
-
from: id,
|
1821
1847
|
to: hexOrZero(receipt.toAddress || receipt.to),
|
1822
1848
|
amount: bn4(receipt.amount),
|
1823
1849
|
assetId: hexOrZero(receipt.assetId),
|
@@ -2175,8 +2201,9 @@ var NoWitnessAtIndexError = class extends Error {
|
|
2175
2201
|
};
|
2176
2202
|
|
2177
2203
|
// src/providers/transaction-request/helpers.ts
|
2204
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2178
2205
|
import { bn as bn7 } from "@fuel-ts/math";
|
2179
|
-
import { InputType as InputType2 } from "@fuel-ts/transactions";
|
2206
|
+
import { InputType as InputType2, OutputType as OutputType2 } from "@fuel-ts/transactions";
|
2180
2207
|
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
2181
2208
|
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
2182
2209
|
var isRequestInputMessageWithoutData = (input) => input.type === InputType2.Message && bn7(input.data).isZero();
|
@@ -2207,6 +2234,32 @@ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
|
2207
2234
|
messages: []
|
2208
2235
|
}
|
2209
2236
|
);
|
2237
|
+
var getBurnableAssetCount = (baseAssetId, transactionRequest) => {
|
2238
|
+
const { inputs, outputs } = transactionRequest;
|
2239
|
+
const coinInputs = new Set(inputs.filter(isRequestInputCoin).map((input) => input.assetId));
|
2240
|
+
if (inputs.some((i) => isRequestInputMessage(i) && bn7(i.amount).gt(0))) {
|
2241
|
+
coinInputs.add(baseAssetId);
|
2242
|
+
}
|
2243
|
+
const changeOutputs = new Set(
|
2244
|
+
outputs.filter((output) => output.type === OutputType2.Change).map((output) => output.assetId)
|
2245
|
+
);
|
2246
|
+
const difference = new Set([...coinInputs].filter((x) => !changeOutputs.has(x)));
|
2247
|
+
return difference.size;
|
2248
|
+
};
|
2249
|
+
var validateTransactionForAssetBurn = (baseAssetId, transactionRequest, enableAssetBurn = false) => {
|
2250
|
+
if (enableAssetBurn === true) {
|
2251
|
+
return;
|
2252
|
+
}
|
2253
|
+
if (getBurnableAssetCount(baseAssetId, transactionRequest) <= 0) {
|
2254
|
+
return;
|
2255
|
+
}
|
2256
|
+
const message = [
|
2257
|
+
"Asset burn detected.",
|
2258
|
+
"Add the relevant change outputs to the transaction to avoid burning assets.",
|
2259
|
+
"Or enable asset burn, upon sending the transaction."
|
2260
|
+
].join("\n");
|
2261
|
+
throw new FuelError9(ErrorCode8.ASSET_BURN_DETECTED, message);
|
2262
|
+
};
|
2210
2263
|
|
2211
2264
|
// src/providers/transaction-request/witness.ts
|
2212
2265
|
import { arrayify as arrayify5, hexlify as hexlify9 } from "@fuel-ts/utils";
|
@@ -2407,7 +2460,7 @@ var BaseTransactionRequest = class {
|
|
2407
2460
|
*/
|
2408
2461
|
getCoinOutputs() {
|
2409
2462
|
return this.outputs.filter(
|
2410
|
-
(output) => output.type ===
|
2463
|
+
(output) => output.type === OutputType3.Coin
|
2411
2464
|
);
|
2412
2465
|
}
|
2413
2466
|
/**
|
@@ -2417,7 +2470,7 @@ var BaseTransactionRequest = class {
|
|
2417
2470
|
*/
|
2418
2471
|
getChangeOutputs() {
|
2419
2472
|
return this.outputs.filter(
|
2420
|
-
(output) => output.type ===
|
2473
|
+
(output) => output.type === OutputType3.Change
|
2421
2474
|
);
|
2422
2475
|
}
|
2423
2476
|
/**
|
@@ -2538,7 +2591,7 @@ var BaseTransactionRequest = class {
|
|
2538
2591
|
*/
|
2539
2592
|
addCoinOutput(to, amount, assetId) {
|
2540
2593
|
this.pushOutput({
|
2541
|
-
type:
|
2594
|
+
type: OutputType3.Coin,
|
2542
2595
|
to: addressify(to).toB256(),
|
2543
2596
|
amount,
|
2544
2597
|
assetId
|
@@ -2554,7 +2607,7 @@ var BaseTransactionRequest = class {
|
|
2554
2607
|
addCoinOutputs(to, quantities) {
|
2555
2608
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
2556
2609
|
this.pushOutput({
|
2557
|
-
type:
|
2610
|
+
type: OutputType3.Coin,
|
2558
2611
|
to: addressify(to).toB256(),
|
2559
2612
|
amount: quantity.amount,
|
2560
2613
|
assetId: quantity.assetId
|
@@ -2574,7 +2627,7 @@ var BaseTransactionRequest = class {
|
|
2574
2627
|
);
|
2575
2628
|
if (!changeOutput) {
|
2576
2629
|
this.pushOutput({
|
2577
|
-
type:
|
2630
|
+
type: OutputType3.Change,
|
2578
2631
|
to: addressify(to).toB256(),
|
2579
2632
|
assetId
|
2580
2633
|
});
|
@@ -2590,7 +2643,7 @@ var BaseTransactionRequest = class {
|
|
2590
2643
|
* @hidden
|
2591
2644
|
*/
|
2592
2645
|
metadataGas(_gasCosts) {
|
2593
|
-
throw new
|
2646
|
+
throw new FuelError10(FuelError10.CODES.NOT_IMPLEMENTED, "Not implemented");
|
2594
2647
|
}
|
2595
2648
|
/**
|
2596
2649
|
* @hidden
|
@@ -2726,7 +2779,7 @@ import { clone as clone3 } from "ramda";
|
|
2726
2779
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2727
2780
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2728
2781
|
import { bn as bn9 } from "@fuel-ts/math";
|
2729
|
-
import { TransactionType as TransactionType2, InputType as InputType4, OutputType as
|
2782
|
+
import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType4, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2730
2783
|
import { concat as concat3 } from "@fuel-ts/utils";
|
2731
2784
|
import { clone as clone2 } from "ramda";
|
2732
2785
|
function hashTransaction(transactionRequest, chainId) {
|
@@ -2767,16 +2820,16 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2767
2820
|
transaction.outputs = transaction.outputs.map((output) => {
|
2768
2821
|
const outputClone = clone2(output);
|
2769
2822
|
switch (outputClone.type) {
|
2770
|
-
case
|
2823
|
+
case OutputType4.Contract: {
|
2771
2824
|
outputClone.balanceRoot = ZeroBytes325;
|
2772
2825
|
outputClone.stateRoot = ZeroBytes325;
|
2773
2826
|
return outputClone;
|
2774
2827
|
}
|
2775
|
-
case
|
2828
|
+
case OutputType4.Change: {
|
2776
2829
|
outputClone.amount = bn9(0);
|
2777
2830
|
return outputClone;
|
2778
2831
|
}
|
2779
|
-
case
|
2832
|
+
case OutputType4.Variable: {
|
2780
2833
|
outputClone.to = ZeroBytes325;
|
2781
2834
|
outputClone.amount = bn9(0);
|
2782
2835
|
outputClone.assetId = ZeroBytes325;
|
@@ -2857,7 +2910,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
2857
2910
|
// src/providers/transaction-request/create-transaction-request.ts
|
2858
2911
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2859
2912
|
import { bn as bn10 } from "@fuel-ts/math";
|
2860
|
-
import { TransactionType as TransactionType3, OutputType as
|
2913
|
+
import { TransactionType as TransactionType3, OutputType as OutputType5 } from "@fuel-ts/transactions";
|
2861
2914
|
import { arrayify as arrayify7, hexlify as hexlify12 } from "@fuel-ts/utils";
|
2862
2915
|
import { clone as clone4 } from "ramda";
|
2863
2916
|
|
@@ -2933,7 +2986,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2933
2986
|
*/
|
2934
2987
|
getContractCreatedOutputs() {
|
2935
2988
|
return this.outputs.filter(
|
2936
|
-
(output) => output.type ===
|
2989
|
+
(output) => output.type === OutputType5.ContractCreated
|
2937
2990
|
);
|
2938
2991
|
}
|
2939
2992
|
/**
|
@@ -2954,7 +3007,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2954
3007
|
*/
|
2955
3008
|
addContractCreatedOutput(contractId, stateRoot) {
|
2956
3009
|
this.pushOutput({
|
2957
|
-
type:
|
3010
|
+
type: OutputType5.ContractCreated,
|
2958
3011
|
contractId,
|
2959
3012
|
stateRoot
|
2960
3013
|
});
|
@@ -2974,7 +3027,7 @@ import { Interface } from "@fuel-ts/abi-coder";
|
|
2974
3027
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2975
3028
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2976
3029
|
import { bn as bn11 } from "@fuel-ts/math";
|
2977
|
-
import { InputType as InputType5, OutputType as
|
3030
|
+
import { InputType as InputType5, OutputType as OutputType6, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2978
3031
|
import { arrayify as arrayify9, hexlify as hexlify13 } from "@fuel-ts/utils";
|
2979
3032
|
import { clone as clone5 } from "ramda";
|
2980
3033
|
|
@@ -3030,6 +3083,20 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3030
3083
|
this.scriptData = arrayify9(scriptData ?? returnZeroScript.encodeScriptData());
|
3031
3084
|
this.abis = rest.abis;
|
3032
3085
|
}
|
3086
|
+
/**
|
3087
|
+
* Helper function to estimate and fund the transaction request with a specified account.
|
3088
|
+
*
|
3089
|
+
* @param account - The account to fund the transaction.
|
3090
|
+
* @param params - The parameters for the transaction cost.
|
3091
|
+
* @returns The current instance of the `ScriptTransactionRequest` funded.
|
3092
|
+
*/
|
3093
|
+
async estimateAndFund(account, { signatureCallback, quantities = [] } = {}) {
|
3094
|
+
const txCost = await account.getTransactionCost(this, { signatureCallback, quantities });
|
3095
|
+
this.maxFee = txCost.maxFee;
|
3096
|
+
this.gasLimit = txCost.gasUsed;
|
3097
|
+
await account.fund(this, txCost);
|
3098
|
+
return this;
|
3099
|
+
}
|
3033
3100
|
/**
|
3034
3101
|
* Converts the transaction request to a `TransactionScript`.
|
3035
3102
|
*
|
@@ -3066,7 +3133,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3066
3133
|
*/
|
3067
3134
|
getContractOutputs() {
|
3068
3135
|
return this.outputs.filter(
|
3069
|
-
(output) => output.type ===
|
3136
|
+
(output) => output.type === OutputType6.Contract
|
3070
3137
|
);
|
3071
3138
|
}
|
3072
3139
|
/**
|
@@ -3076,7 +3143,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3076
3143
|
*/
|
3077
3144
|
getVariableOutputs() {
|
3078
3145
|
return this.outputs.filter(
|
3079
|
-
(output) => output.type ===
|
3146
|
+
(output) => output.type === OutputType6.Variable
|
3080
3147
|
);
|
3081
3148
|
}
|
3082
3149
|
/**
|
@@ -3099,7 +3166,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3099
3166
|
let outputsNumber = numberOfVariables;
|
3100
3167
|
while (outputsNumber) {
|
3101
3168
|
this.pushOutput({
|
3102
|
-
type:
|
3169
|
+
type: OutputType6.Variable
|
3103
3170
|
});
|
3104
3171
|
outputsNumber -= 1;
|
3105
3172
|
}
|
@@ -3148,7 +3215,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3148
3215
|
txPointer: "0x00000000000000000000000000000000"
|
3149
3216
|
});
|
3150
3217
|
this.pushOutput({
|
3151
|
-
type:
|
3218
|
+
type: OutputType6.Contract,
|
3152
3219
|
inputIndex
|
3153
3220
|
});
|
3154
3221
|
return this;
|
@@ -3184,7 +3251,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3184
3251
|
};
|
3185
3252
|
|
3186
3253
|
// src/providers/transaction-request/upgrade-transaction-request.ts
|
3187
|
-
import { FuelError as
|
3254
|
+
import { FuelError as FuelError11 } from "@fuel-ts/errors";
|
3188
3255
|
import { hash as hash2 } from "@fuel-ts/hasher";
|
3189
3256
|
import {
|
3190
3257
|
TransactionType as TransactionType5,
|
@@ -3291,7 +3358,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3291
3358
|
}
|
3292
3359
|
};
|
3293
3360
|
} else {
|
3294
|
-
throw new
|
3361
|
+
throw new FuelError11(FuelError11.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3295
3362
|
}
|
3296
3363
|
return {
|
3297
3364
|
type: TransactionType5.Upgrade,
|
@@ -3333,7 +3400,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3333
3400
|
txBytesSize
|
3334
3401
|
});
|
3335
3402
|
}
|
3336
|
-
throw new
|
3403
|
+
throw new FuelError11(FuelError11.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3337
3404
|
}
|
3338
3405
|
};
|
3339
3406
|
|
@@ -3444,7 +3511,7 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
3444
3511
|
};
|
3445
3512
|
|
3446
3513
|
// src/providers/transaction-request/utils.ts
|
3447
|
-
import { ErrorCode as
|
3514
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError12 } from "@fuel-ts/errors";
|
3448
3515
|
import { TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
3449
3516
|
var transactionRequestify = (obj) => {
|
3450
3517
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest || obj instanceof UpgradeTransactionRequest || obj instanceof UploadTransactionRequest) {
|
@@ -3468,8 +3535,8 @@ var transactionRequestify = (obj) => {
|
|
3468
3535
|
return UploadTransactionRequest.from(obj);
|
3469
3536
|
}
|
3470
3537
|
default: {
|
3471
|
-
throw new
|
3472
|
-
|
3538
|
+
throw new FuelError12(
|
3539
|
+
ErrorCode9.UNSUPPORTED_TRANSACTION_TYPE,
|
3473
3540
|
`Unsupported transaction type: ${type}.`
|
3474
3541
|
);
|
3475
3542
|
}
|
@@ -3479,9 +3546,9 @@ var isTransactionTypeScript = (request) => request.type === TransactionType7.Scr
|
|
3479
3546
|
var isTransactionTypeCreate = (request) => request.type === TransactionType7.Create;
|
3480
3547
|
|
3481
3548
|
// src/providers/transaction-response/transaction-response.ts
|
3482
|
-
import { ErrorCode as
|
3549
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError16 } from "@fuel-ts/errors";
|
3483
3550
|
import { bn as bn16 } from "@fuel-ts/math";
|
3484
|
-
import { OutputType as
|
3551
|
+
import { OutputType as OutputType8, TransactionCoder as TransactionCoder4, TxPointerCoder } from "@fuel-ts/transactions";
|
3485
3552
|
import { arrayify as arrayify12, assertUnreachable } from "@fuel-ts/utils";
|
3486
3553
|
|
3487
3554
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
@@ -3498,12 +3565,8 @@ var calculateTXFeeForSummary = (params) => {
|
|
3498
3565
|
gasPrice,
|
3499
3566
|
rawPayload,
|
3500
3567
|
tip,
|
3501
|
-
totalFee,
|
3502
3568
|
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
3503
3569
|
} = params;
|
3504
|
-
if (totalFee) {
|
3505
|
-
return totalFee;
|
3506
|
-
}
|
3507
3570
|
const gasPerByte = bn12(feeParams.gasPerByte);
|
3508
3571
|
const gasPriceFactor = bn12(feeParams.gasPriceFactor);
|
3509
3572
|
const transactionBytes = arrayify11(rawPayload);
|
@@ -3561,7 +3624,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3561
3624
|
|
3562
3625
|
// src/providers/transaction-summary/operations.ts
|
3563
3626
|
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
3564
|
-
import { ErrorCode as
|
3627
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError14 } from "@fuel-ts/errors";
|
3565
3628
|
import { bn as bn13 } from "@fuel-ts/math";
|
3566
3629
|
import { ReceiptType as ReceiptType4, TransactionType as TransactionType9 } from "@fuel-ts/transactions";
|
3567
3630
|
|
@@ -3599,7 +3662,7 @@ var getFunctionCall = ({ abi, receipt }) => {
|
|
3599
3662
|
};
|
3600
3663
|
|
3601
3664
|
// src/providers/transaction-summary/input.ts
|
3602
|
-
import { ErrorCode as
|
3665
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError13 } from "@fuel-ts/errors";
|
3603
3666
|
import { BN } from "@fuel-ts/math";
|
3604
3667
|
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
3605
3668
|
function getInputsByTypes(inputs, types) {
|
@@ -3627,10 +3690,10 @@ function findCoinInput(inputs, assetId) {
|
|
3627
3690
|
const coinInputs = getInputsCoin(inputs);
|
3628
3691
|
return coinInputs.find((i) => i.assetId === assetId);
|
3629
3692
|
}
|
3630
|
-
function aggregateInputsAmountsByAssetAndOwner(inputs,
|
3693
|
+
function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId) {
|
3631
3694
|
const aggregated = /* @__PURE__ */ new Map();
|
3632
3695
|
getInputsCoinAndMessage(inputs).forEach((input) => {
|
3633
|
-
const assetId = isInputCoin(input) ? input.assetId :
|
3696
|
+
const assetId = isInputCoin(input) ? input.assetId : baseAssetId;
|
3634
3697
|
const owner = isInputCoin(input) ? input.owner : input.recipient;
|
3635
3698
|
let ownersMap = aggregated.get(assetId);
|
3636
3699
|
if (!ownersMap) {
|
@@ -3668,8 +3731,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
3668
3731
|
return void 0;
|
3669
3732
|
}
|
3670
3733
|
if (contractInput.type !== InputType6.Contract) {
|
3671
|
-
throw new
|
3672
|
-
|
3734
|
+
throw new FuelError13(
|
3735
|
+
ErrorCode10.INVALID_TRANSACTION_INPUT,
|
3673
3736
|
`Contract input should be of type 'contract'.`
|
3674
3737
|
);
|
3675
3738
|
}
|
@@ -3686,21 +3749,21 @@ function getInputAccountAddress(input) {
|
|
3686
3749
|
}
|
3687
3750
|
|
3688
3751
|
// src/providers/transaction-summary/output.ts
|
3689
|
-
import { OutputType as
|
3752
|
+
import { OutputType as OutputType7 } from "@fuel-ts/transactions";
|
3690
3753
|
function getOutputsByType(outputs, type) {
|
3691
3754
|
return outputs.filter((o) => o.type === type);
|
3692
3755
|
}
|
3693
3756
|
function getOutputsContractCreated(outputs) {
|
3694
|
-
return getOutputsByType(outputs,
|
3757
|
+
return getOutputsByType(outputs, OutputType7.ContractCreated);
|
3695
3758
|
}
|
3696
3759
|
function getOutputsCoin(outputs) {
|
3697
|
-
return getOutputsByType(outputs,
|
3760
|
+
return getOutputsByType(outputs, OutputType7.Coin);
|
3698
3761
|
}
|
3699
3762
|
function getOutputsChange(outputs) {
|
3700
|
-
return getOutputsByType(outputs,
|
3763
|
+
return getOutputsByType(outputs, OutputType7.Change);
|
3701
3764
|
}
|
3702
3765
|
function getOutputsContract(outputs) {
|
3703
|
-
return getOutputsByType(outputs,
|
3766
|
+
return getOutputsByType(outputs, OutputType7.Contract);
|
3704
3767
|
}
|
3705
3768
|
|
3706
3769
|
// src/providers/transaction-summary/operations.ts
|
@@ -3722,8 +3785,8 @@ function getTransactionTypeName(transactionType) {
|
|
3722
3785
|
case TransactionType9.Upload:
|
3723
3786
|
return "Upload" /* Upload */;
|
3724
3787
|
default:
|
3725
|
-
throw new
|
3726
|
-
|
3788
|
+
throw new FuelError14(
|
3789
|
+
ErrorCode11.UNSUPPORTED_TRANSACTION_TYPE,
|
3727
3790
|
`Unsupported transaction type: ${transactionType}.`
|
3728
3791
|
);
|
3729
3792
|
}
|
@@ -3916,7 +3979,7 @@ function getContractCallOperations({
|
|
3916
3979
|
}
|
3917
3980
|
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
3918
3981
|
const { to: toAddress, assetId, amount } = receipt;
|
3919
|
-
let {
|
3982
|
+
let { id: fromAddress } = receipt;
|
3920
3983
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3921
3984
|
if (ZeroBytes329 === fromAddress) {
|
3922
3985
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
@@ -4103,7 +4166,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
4103
4166
|
};
|
4104
4167
|
|
4105
4168
|
// src/providers/transaction-summary/status.ts
|
4106
|
-
import { ErrorCode as
|
4169
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError15 } from "@fuel-ts/errors";
|
4107
4170
|
import { bn as bn14 } from "@fuel-ts/math";
|
4108
4171
|
var getTransactionStatusName = (gqlStatus) => {
|
4109
4172
|
switch (gqlStatus) {
|
@@ -4116,8 +4179,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
4116
4179
|
case "SqueezedOutStatus":
|
4117
4180
|
return "squeezedout" /* squeezedout */;
|
4118
4181
|
default:
|
4119
|
-
throw new
|
4120
|
-
|
4182
|
+
throw new FuelError15(
|
4183
|
+
ErrorCode12.INVALID_TRANSACTION_STATUS,
|
4121
4184
|
`Invalid transaction status: ${gqlStatus}.`
|
4122
4185
|
);
|
4123
4186
|
}
|
@@ -4167,6 +4230,7 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
4167
4230
|
};
|
4168
4231
|
return processedGraphqlStatus;
|
4169
4232
|
};
|
4233
|
+
var getTotalFeeFromStatus = (status) => status && "totalFee" in status ? bn14(status.totalFee) : void 0;
|
4170
4234
|
|
4171
4235
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
4172
4236
|
function assembleTransactionSummary(params) {
|
@@ -4200,8 +4264,7 @@ function assembleTransactionSummary(params) {
|
|
4200
4264
|
const typeName = getTransactionTypeName(transaction.type);
|
4201
4265
|
const tip = bn15(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
4202
4266
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
4203
|
-
const fee = calculateTXFeeForSummary({
|
4204
|
-
totalFee,
|
4267
|
+
const fee = totalFee ?? calculateTXFeeForSummary({
|
4205
4268
|
gasPrice,
|
4206
4269
|
rawPayload,
|
4207
4270
|
tip,
|
@@ -4255,8 +4318,8 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
4255
4318
|
return receipts.reduce((logs, receipt) => {
|
4256
4319
|
if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
|
4257
4320
|
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
4258
|
-
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.
|
4259
|
-
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.
|
4321
|
+
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
4322
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
4260
4323
|
logs.push(decodedLog);
|
4261
4324
|
}
|
4262
4325
|
return logs;
|
@@ -4269,24 +4332,24 @@ function mapGqlOutputsToTxOutputs(outputs) {
|
|
4269
4332
|
const obj = "amount" in o ? { ...o, amount: bn16(o.amount) } : o;
|
4270
4333
|
switch (obj.type) {
|
4271
4334
|
case "CoinOutput":
|
4272
|
-
return { ...obj, type:
|
4335
|
+
return { ...obj, type: OutputType8.Coin };
|
4273
4336
|
case "ContractOutput":
|
4274
4337
|
return {
|
4275
4338
|
...obj,
|
4276
|
-
type:
|
4339
|
+
type: OutputType8.Contract,
|
4277
4340
|
inputIndex: parseInt(obj.inputIndex, 10)
|
4278
4341
|
};
|
4279
4342
|
case "ChangeOutput":
|
4280
4343
|
return {
|
4281
4344
|
...obj,
|
4282
|
-
type:
|
4345
|
+
type: OutputType8.Change
|
4283
4346
|
};
|
4284
4347
|
case "VariableOutput":
|
4285
|
-
return { ...obj, type:
|
4348
|
+
return { ...obj, type: OutputType8.Variable };
|
4286
4349
|
case "ContractCreated":
|
4287
4350
|
return {
|
4288
4351
|
...obj,
|
4289
|
-
type:
|
4352
|
+
type: OutputType8.ContractCreated,
|
4290
4353
|
contractId: obj.contract
|
4291
4354
|
};
|
4292
4355
|
default:
|
@@ -4301,9 +4364,9 @@ var TransactionResponse = class {
|
|
4301
4364
|
* @param tx - The transaction ID or TransactionRequest.
|
4302
4365
|
* @param provider - The provider.
|
4303
4366
|
*/
|
4304
|
-
constructor(tx, provider, abis, submitTxSubscription) {
|
4367
|
+
constructor(tx, provider, chainId, abis, submitTxSubscription) {
|
4305
4368
|
this.submitTxSubscription = submitTxSubscription;
|
4306
|
-
this.id = typeof tx === "string" ? tx : tx.getTransactionId(
|
4369
|
+
this.id = typeof tx === "string" ? tx : tx.getTransactionId(chainId);
|
4307
4370
|
this.provider = provider;
|
4308
4371
|
this.abis = abis;
|
4309
4372
|
this.request = typeof tx === "string" ? void 0 : tx;
|
@@ -4328,7 +4391,8 @@ var TransactionResponse = class {
|
|
4328
4391
|
* @param provider - The provider.
|
4329
4392
|
*/
|
4330
4393
|
static async create(id, provider, abis) {
|
4331
|
-
const
|
4394
|
+
const chainId = await provider.getChainId();
|
4395
|
+
const response = new TransactionResponse(id, provider, chainId, abis);
|
4332
4396
|
await response.fetch();
|
4333
4397
|
return response;
|
4334
4398
|
}
|
@@ -4425,10 +4489,11 @@ var TransactionResponse = class {
|
|
4425
4489
|
*/
|
4426
4490
|
async getTransactionSummary(contractsAbiMap) {
|
4427
4491
|
const { tx: transaction, bytes: transactionBytes } = await this.getTransaction();
|
4428
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
4429
|
-
const
|
4430
|
-
const
|
4431
|
-
const
|
4492
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = await this.provider.getGasConfig();
|
4493
|
+
const totalFee = getTotalFeeFromStatus(this.status ?? this.gqlTransaction?.status);
|
4494
|
+
const gasPrice = totalFee ? bn16(0) : await this.provider.getLatestGasPrice();
|
4495
|
+
const maxInputs = (await this.provider.getChain()).consensusParameters.txParameters.maxInputs;
|
4496
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
4432
4497
|
const transactionSummary = assembleTransactionSummary({
|
4433
4498
|
id: this.id,
|
4434
4499
|
receipts: this.getReceipts(),
|
@@ -4459,8 +4524,8 @@ var TransactionResponse = class {
|
|
4459
4524
|
this.status = statusChange;
|
4460
4525
|
if (statusChange.type === "SqueezedOutStatus") {
|
4461
4526
|
this.unsetResourceCache();
|
4462
|
-
throw new
|
4463
|
-
|
4527
|
+
throw new FuelError16(
|
4528
|
+
ErrorCode13.TRANSACTION_SQUEEZED_OUT,
|
4464
4529
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
4465
4530
|
);
|
4466
4531
|
}
|
@@ -4568,54 +4633,54 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4568
4633
|
}
|
4569
4634
|
|
4570
4635
|
// src/providers/utils/handle-gql-error-message.ts
|
4571
|
-
import { ErrorCode as
|
4636
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError17 } from "@fuel-ts/errors";
|
4572
4637
|
var handleGqlErrorMessage = (errorMessage, rawError) => {
|
4573
4638
|
switch (errorMessage) {
|
4574
4639
|
case "not enough coins to fit the target" /* NOT_ENOUGH_COINS */:
|
4575
|
-
throw new
|
4576
|
-
|
4640
|
+
throw new FuelError17(
|
4641
|
+
ErrorCode14.NOT_ENOUGH_FUNDS,
|
4577
4642
|
`The account(s) sending the transaction don't have enough funds to cover the transaction.`,
|
4578
4643
|
{},
|
4579
4644
|
rawError
|
4580
4645
|
);
|
4581
4646
|
case "max number of coins is reached while trying to fit the target" /* MAX_COINS_REACHED */:
|
4582
|
-
throw new
|
4583
|
-
|
4647
|
+
throw new FuelError17(
|
4648
|
+
ErrorCode14.MAX_COINS_REACHED,
|
4584
4649
|
"The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.",
|
4585
4650
|
{},
|
4586
4651
|
rawError
|
4587
4652
|
);
|
4588
4653
|
default:
|
4589
|
-
throw new
|
4654
|
+
throw new FuelError17(ErrorCode14.INVALID_REQUEST, errorMessage);
|
4590
4655
|
}
|
4591
4656
|
};
|
4592
4657
|
|
4593
4658
|
// src/providers/utils/validate-pagination-args.ts
|
4594
|
-
import { FuelError as
|
4659
|
+
import { FuelError as FuelError18, ErrorCode as ErrorCode15 } from "@fuel-ts/errors";
|
4595
4660
|
var validatePaginationArgs = (params) => {
|
4596
4661
|
const { paginationLimit, inputArgs = {} } = params;
|
4597
4662
|
const { first, last, after, before } = inputArgs;
|
4598
4663
|
if (after && before) {
|
4599
|
-
throw new
|
4600
|
-
|
4664
|
+
throw new FuelError18(
|
4665
|
+
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
4601
4666
|
'Pagination arguments "after" and "before" cannot be used together'
|
4602
4667
|
);
|
4603
4668
|
}
|
4604
4669
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
4605
|
-
throw new
|
4606
|
-
|
4670
|
+
throw new FuelError18(
|
4671
|
+
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
4607
4672
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
4608
4673
|
);
|
4609
4674
|
}
|
4610
4675
|
if (first && before) {
|
4611
|
-
throw new
|
4612
|
-
|
4676
|
+
throw new FuelError18(
|
4677
|
+
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
4613
4678
|
'The use of pagination argument "first" with "before" is not supported'
|
4614
4679
|
);
|
4615
4680
|
}
|
4616
4681
|
if (last && after) {
|
4617
|
-
throw new
|
4618
|
-
|
4682
|
+
throw new FuelError18(
|
4683
|
+
ErrorCode15.INVALID_INPUT_PARAMETERS,
|
4619
4684
|
'The use of pagination argument "last" with "after" is not supported'
|
4620
4685
|
);
|
4621
4686
|
}
|
@@ -4769,7 +4834,7 @@ var _Provider = class {
|
|
4769
4834
|
try {
|
4770
4835
|
parsedUrl = new URL(url);
|
4771
4836
|
} catch (error) {
|
4772
|
-
throw new
|
4837
|
+
throw new FuelError19(FuelError19.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
|
4773
4838
|
}
|
4774
4839
|
const username = parsedUrl.username;
|
4775
4840
|
const password = parsedUrl.password;
|
@@ -4784,58 +4849,40 @@ var _Provider = class {
|
|
4784
4849
|
};
|
4785
4850
|
}
|
4786
4851
|
/**
|
4787
|
-
*
|
4788
|
-
*
|
4789
|
-
* @param url - GraphQL endpoint of the Fuel node
|
4790
|
-
* @param options - Additional options for the provider
|
4791
|
-
*
|
4792
|
-
* @returns A promise that resolves to a Provider instance.
|
4852
|
+
* Initialize Provider async stuff
|
4793
4853
|
*/
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4797
|
-
return provider;
|
4854
|
+
async init() {
|
4855
|
+
await this.fetchChainAndNodeInfo();
|
4856
|
+
return this;
|
4798
4857
|
}
|
4799
4858
|
/**
|
4800
|
-
* Returns the
|
4859
|
+
* Returns the `chainInfo` for the current network.
|
4801
4860
|
*
|
4802
4861
|
* @returns the chain information configuration.
|
4803
4862
|
*/
|
4804
|
-
getChain() {
|
4805
|
-
|
4806
|
-
|
4807
|
-
throw new FuelError18(
|
4808
|
-
ErrorCode15.CHAIN_INFO_CACHE_EMPTY,
|
4809
|
-
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4810
|
-
);
|
4811
|
-
}
|
4812
|
-
return chain;
|
4863
|
+
async getChain() {
|
4864
|
+
await this.init();
|
4865
|
+
return _Provider.chainInfoCache[this.urlWithoutAuth];
|
4813
4866
|
}
|
4814
4867
|
/**
|
4815
|
-
* Returns the
|
4868
|
+
* Returns the `nodeInfo` for the current network.
|
4816
4869
|
*
|
4817
4870
|
* @returns the node information configuration.
|
4818
4871
|
*/
|
4819
|
-
getNode() {
|
4820
|
-
|
4821
|
-
|
4822
|
-
throw new FuelError18(
|
4823
|
-
ErrorCode15.NODE_INFO_CACHE_EMPTY,
|
4824
|
-
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4825
|
-
);
|
4826
|
-
}
|
4827
|
-
return node;
|
4872
|
+
async getNode() {
|
4873
|
+
await this.init();
|
4874
|
+
return _Provider.nodeInfoCache[this.urlWithoutAuth];
|
4828
4875
|
}
|
4829
4876
|
/**
|
4830
4877
|
* Returns some helpful parameters related to gas fees.
|
4831
4878
|
*/
|
4832
|
-
getGasConfig() {
|
4879
|
+
async getGasConfig() {
|
4833
4880
|
const {
|
4834
4881
|
txParameters: { maxGasPerTx },
|
4835
4882
|
predicateParameters: { maxGasPerPredicate },
|
4836
4883
|
feeParameters: { gasPriceFactor, gasPerByte },
|
4837
4884
|
gasCosts
|
4838
|
-
} = this.getChain().consensusParameters;
|
4885
|
+
} = (await this.getChain()).consensusParameters;
|
4839
4886
|
return {
|
4840
4887
|
maxGasPerTx,
|
4841
4888
|
maxGasPerPredicate,
|
@@ -4857,7 +4904,7 @@ var _Provider = class {
|
|
4857
4904
|
this.options = options ?? this.options;
|
4858
4905
|
this.options = { ...this.options, headers: { ...this.options.headers, ...headers } };
|
4859
4906
|
this.operations = this.createOperations();
|
4860
|
-
await this.
|
4907
|
+
await this.init();
|
4861
4908
|
}
|
4862
4909
|
/**
|
4863
4910
|
* Return the chain and node information.
|
@@ -4868,11 +4915,12 @@ var _Provider = class {
|
|
4868
4915
|
let nodeInfo;
|
4869
4916
|
let chain;
|
4870
4917
|
try {
|
4871
|
-
|
4872
|
-
|
4918
|
+
nodeInfo = _Provider.nodeInfoCache[this.urlWithoutAuth];
|
4919
|
+
chain = _Provider.chainInfoCache[this.urlWithoutAuth];
|
4920
|
+
const noCache = !nodeInfo || !chain;
|
4921
|
+
if (ignoreCache || noCache) {
|
4922
|
+
throw new Error(`Jumps to the catch block and re-fetch`);
|
4873
4923
|
}
|
4874
|
-
nodeInfo = this.getNode();
|
4875
|
-
chain = this.getChain();
|
4876
4924
|
} catch (_err) {
|
4877
4925
|
const data = await this.operations.getChainAndNodeInfo();
|
4878
4926
|
nodeInfo = {
|
@@ -5019,10 +5067,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5019
5067
|
*
|
5020
5068
|
* @returns A promise that resolves to the chain ID number.
|
5021
5069
|
*/
|
5022
|
-
getChainId() {
|
5070
|
+
async getChainId() {
|
5023
5071
|
const {
|
5024
5072
|
consensusParameters: { chainId }
|
5025
|
-
} = this.getChain();
|
5073
|
+
} = await this.getChain();
|
5026
5074
|
return chainId.toNumber();
|
5027
5075
|
}
|
5028
5076
|
/**
|
@@ -5030,30 +5078,31 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5030
5078
|
*
|
5031
5079
|
* @returns the base asset ID.
|
5032
5080
|
*/
|
5033
|
-
getBaseAssetId() {
|
5081
|
+
async getBaseAssetId() {
|
5082
|
+
const all = await this.getChain();
|
5034
5083
|
const {
|
5035
5084
|
consensusParameters: { baseAssetId }
|
5036
|
-
} =
|
5085
|
+
} = all;
|
5037
5086
|
return baseAssetId;
|
5038
5087
|
}
|
5039
5088
|
/**
|
5040
5089
|
* @hidden
|
5041
5090
|
*/
|
5042
|
-
validateTransaction(tx) {
|
5091
|
+
async validateTransaction(tx) {
|
5043
5092
|
const {
|
5044
5093
|
consensusParameters: {
|
5045
5094
|
txParameters: { maxInputs, maxOutputs }
|
5046
5095
|
}
|
5047
|
-
} = this.getChain();
|
5096
|
+
} = await this.getChain();
|
5048
5097
|
if (bn17(tx.inputs.length).gt(maxInputs)) {
|
5049
|
-
throw new
|
5050
|
-
|
5098
|
+
throw new FuelError19(
|
5099
|
+
ErrorCode16.MAX_INPUTS_EXCEEDED,
|
5051
5100
|
`The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
|
5052
5101
|
);
|
5053
5102
|
}
|
5054
5103
|
if (bn17(tx.outputs.length).gt(maxOutputs)) {
|
5055
|
-
throw new
|
5056
|
-
|
5104
|
+
throw new FuelError19(
|
5105
|
+
ErrorCode16.MAX_OUTPUTS_EXCEEDED,
|
5057
5106
|
`The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
|
5058
5107
|
);
|
5059
5108
|
}
|
@@ -5068,20 +5117,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5068
5117
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
5069
5118
|
* @returns A promise that resolves to the transaction response object.
|
5070
5119
|
*/
|
5071
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
5120
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, enableAssetBurn } = {}) {
|
5072
5121
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5122
|
+
validateTransactionForAssetBurn(
|
5123
|
+
await this.getBaseAssetId(),
|
5124
|
+
transactionRequest,
|
5125
|
+
enableAssetBurn
|
5126
|
+
);
|
5073
5127
|
if (estimateTxDependencies) {
|
5074
5128
|
await this.estimateTxDependencies(transactionRequest);
|
5075
5129
|
}
|
5076
|
-
this.validateTransaction(transactionRequest);
|
5130
|
+
await this.validateTransaction(transactionRequest);
|
5077
5131
|
const encodedTransaction = hexlify17(transactionRequest.toTransactionBytes());
|
5078
5132
|
let abis;
|
5079
5133
|
if (isTransactionTypeScript(transactionRequest)) {
|
5080
5134
|
abis = transactionRequest.abis;
|
5081
5135
|
}
|
5082
5136
|
const subscription = await this.operations.submitAndAwaitStatus({ encodedTransaction });
|
5083
|
-
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionRequest.getTransactionId(this.getChainId()));
|
5084
|
-
|
5137
|
+
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionRequest.getTransactionId(await this.getChainId()));
|
5138
|
+
const chainId = await this.getChainId();
|
5139
|
+
return new TransactionResponse(transactionRequest, this, chainId, abis, subscription);
|
5085
5140
|
}
|
5086
5141
|
/**
|
5087
5142
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -5161,7 +5216,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5161
5216
|
const missingContractIds = [];
|
5162
5217
|
let outputVariables = 0;
|
5163
5218
|
let dryRunStatus;
|
5164
|
-
this.validateTransaction(transactionRequest);
|
5219
|
+
await this.validateTransaction(transactionRequest);
|
5165
5220
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
5166
5221
|
const {
|
5167
5222
|
dryRun: [{ receipts: rawReceipts, status }]
|
@@ -5292,7 +5347,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5292
5347
|
if (diff < 6e4) {
|
5293
5348
|
return;
|
5294
5349
|
}
|
5295
|
-
|
5350
|
+
if (!_Provider.chainInfoCache?.[this.urlWithoutAuth]) {
|
5351
|
+
await this.fetchChainAndNodeInfo(true);
|
5352
|
+
return;
|
5353
|
+
}
|
5354
|
+
const chainInfo = _Provider.chainInfoCache[this.urlWithoutAuth];
|
5296
5355
|
const {
|
5297
5356
|
consensusParameters: { version: previous }
|
5298
5357
|
} = chainInfo;
|
@@ -5316,8 +5375,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5316
5375
|
const { transactionRequest } = params;
|
5317
5376
|
let { gasPrice } = params;
|
5318
5377
|
await this.autoRefetchConfigs();
|
5319
|
-
const chainInfo = this.getChain();
|
5320
|
-
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
5378
|
+
const chainInfo = await this.getChain();
|
5379
|
+
const { gasPriceFactor, maxGasPerTx } = await this.getGasConfig();
|
5321
5380
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
5322
5381
|
if (!isDefined2(gasPrice)) {
|
5323
5382
|
gasPrice = await this.estimateGasPrice(10);
|
@@ -5429,7 +5488,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5429
5488
|
if (dryRunStatus && "reason" in dryRunStatus) {
|
5430
5489
|
throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
|
5431
5490
|
}
|
5432
|
-
const { maxGasPerTx } = this.getGasConfig();
|
5491
|
+
const { maxGasPerTx } = await this.getGasConfig();
|
5433
5492
|
const pristineGasUsed = getGasUsedFromReceipts(receipts);
|
5434
5493
|
gasUsed = bn17(pristineGasUsed.muln(GAS_USED_MODIFIER)).max(maxGasPerTx.sub(minGas));
|
5435
5494
|
txRequestClone.gasLimit = gasUsed;
|
@@ -5686,7 +5745,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5686
5745
|
0
|
5687
5746
|
)?.[0];
|
5688
5747
|
} catch (error) {
|
5689
|
-
if (error instanceof
|
5748
|
+
if (error instanceof FuelError19 && error.code === ErrorCode16.UNSUPPORTED_TRANSACTION_TYPE) {
|
5690
5749
|
console.warn("Unsupported transaction type encountered");
|
5691
5750
|
return null;
|
5692
5751
|
}
|
@@ -5712,7 +5771,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5712
5771
|
try {
|
5713
5772
|
return coder.decode(arrayify13(rawPayload), 0)[0];
|
5714
5773
|
} catch (error) {
|
5715
|
-
if (error instanceof
|
5774
|
+
if (error instanceof FuelError19 && error.code === ErrorCode16.UNSUPPORTED_TRANSACTION_TYPE) {
|
5716
5775
|
console.warn("Unsupported transaction type encountered");
|
5717
5776
|
return null;
|
5718
5777
|
}
|
@@ -5838,8 +5897,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5838
5897
|
nonce
|
5839
5898
|
};
|
5840
5899
|
if (commitBlockId && commitBlockHeight) {
|
5841
|
-
throw new
|
5842
|
-
|
5900
|
+
throw new FuelError19(
|
5901
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
5843
5902
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5844
5903
|
);
|
5845
5904
|
}
|
@@ -6002,9 +6061,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
6002
6061
|
* @param transactionId - The transaction ID to get the response for.
|
6003
6062
|
* @returns A promise that resolves to the transaction response.
|
6004
6063
|
*/
|
6005
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
6006
6064
|
async getTransactionResponse(transactionId) {
|
6007
|
-
|
6065
|
+
const chainId = await this.getChainId();
|
6066
|
+
return new TransactionResponse(transactionId, this, chainId);
|
6008
6067
|
}
|
6009
6068
|
/**
|
6010
6069
|
* Returns Message for given nonce.
|
@@ -6094,7 +6153,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
6094
6153
|
__publicField(Provider, "nodeInfoCache", {});
|
6095
6154
|
|
6096
6155
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
6097
|
-
import { ErrorCode as
|
6156
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError20 } from "@fuel-ts/errors";
|
6098
6157
|
import { bn as bn18 } from "@fuel-ts/math";
|
6099
6158
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
6100
6159
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
@@ -6728,7 +6787,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
6728
6787
|
|
6729
6788
|
// src/test-utils/wallet-config.ts
|
6730
6789
|
import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
|
6731
|
-
import { FuelError as
|
6790
|
+
import { FuelError as FuelError26 } from "@fuel-ts/errors";
|
6732
6791
|
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify24 } from "@fuel-ts/utils";
|
6733
6792
|
|
6734
6793
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -6739,8 +6798,7 @@ import { hexlify as hexlify21 } from "@fuel-ts/utils";
|
|
6739
6798
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
6740
6799
|
import { Address as Address5 } from "@fuel-ts/address";
|
6741
6800
|
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
6742
|
-
import { ErrorCode as
|
6743
|
-
import { AbstractAccount } from "@fuel-ts/interfaces";
|
6801
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError21 } from "@fuel-ts/errors";
|
6744
6802
|
import { bn as bn19 } from "@fuel-ts/math";
|
6745
6803
|
import { InputType as InputType8 } from "@fuel-ts/transactions";
|
6746
6804
|
import { arrayify as arrayify16, hexlify as hexlify19, isDefined as isDefined3 } from "@fuel-ts/utils";
|
@@ -6760,6 +6818,10 @@ var mergeQuantities = (...coinQuantities) => {
|
|
6760
6818
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
6761
6819
|
};
|
6762
6820
|
|
6821
|
+
// src/types.ts
|
6822
|
+
var AbstractAccount = class {
|
6823
|
+
};
|
6824
|
+
|
6763
6825
|
// src/utils/formatTransferToContractScriptData.ts
|
6764
6826
|
import { ASSET_ID_LEN, BigNumberCoder as BigNumberCoder2, CONTRACT_ID_LEN, WORD_SIZE } from "@fuel-ts/abi-coder";
|
6765
6827
|
import { Address as Address4 } from "@fuel-ts/address";
|
@@ -6841,7 +6903,7 @@ var Account = class extends AbstractAccount {
|
|
6841
6903
|
*/
|
6842
6904
|
get provider() {
|
6843
6905
|
if (!this._provider) {
|
6844
|
-
throw new
|
6906
|
+
throw new FuelError21(ErrorCode18.MISSING_PROVIDER, "Provider not set");
|
6845
6907
|
}
|
6846
6908
|
return this._provider;
|
6847
6909
|
}
|
@@ -6897,7 +6959,7 @@ var Account = class extends AbstractAccount {
|
|
6897
6959
|
* @returns A promise that resolves to the balance amount.
|
6898
6960
|
*/
|
6899
6961
|
async getBalance(assetId) {
|
6900
|
-
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
6962
|
+
const assetIdToFetch = assetId ?? await this.provider.getBaseAssetId();
|
6901
6963
|
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
6902
6964
|
return amount;
|
6903
6965
|
}
|
@@ -6920,7 +6982,7 @@ var Account = class extends AbstractAccount {
|
|
6920
6982
|
async fund(request, params) {
|
6921
6983
|
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee, gasPrice } = params;
|
6922
6984
|
const fee = request.maxFee;
|
6923
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
6985
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
6924
6986
|
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn19(0);
|
6925
6987
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
6926
6988
|
amount: bn19(fee),
|
@@ -6992,12 +7054,12 @@ var Account = class extends AbstractAccount {
|
|
6992
7054
|
fundingAttempts += 1;
|
6993
7055
|
}
|
6994
7056
|
if (needsToBeFunded) {
|
6995
|
-
throw new
|
6996
|
-
|
7057
|
+
throw new FuelError21(
|
7058
|
+
ErrorCode18.NOT_ENOUGH_FUNDS,
|
6997
7059
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
6998
7060
|
);
|
6999
7061
|
}
|
7000
|
-
this.provider.validateTransaction(request);
|
7062
|
+
await this.provider.validateTransaction(request);
|
7001
7063
|
request.updatePredicateGasUsed(estimatedPredicates);
|
7002
7064
|
const requestToReestimate = clone9(request);
|
7003
7065
|
if (addedSignatures) {
|
@@ -7024,7 +7086,11 @@ var Account = class extends AbstractAccount {
|
|
7024
7086
|
*/
|
7025
7087
|
async createTransfer(destination, amount, assetId, txParams = {}) {
|
7026
7088
|
let request = new ScriptTransactionRequest(txParams);
|
7027
|
-
request = this.addTransfer(request, {
|
7089
|
+
request = this.addTransfer(request, {
|
7090
|
+
destination,
|
7091
|
+
amount,
|
7092
|
+
assetId: assetId || await this.provider.getBaseAssetId()
|
7093
|
+
});
|
7028
7094
|
request = await this.estimateAndFundTransaction(request, txParams);
|
7029
7095
|
return request;
|
7030
7096
|
}
|
@@ -7064,11 +7130,7 @@ var Account = class extends AbstractAccount {
|
|
7064
7130
|
addTransfer(request, transferParams) {
|
7065
7131
|
const { destination, amount, assetId } = transferParams;
|
7066
7132
|
this.validateTransferAmount(amount);
|
7067
|
-
request.addCoinOutput(
|
7068
|
-
Address5.fromAddressOrString(destination),
|
7069
|
-
amount,
|
7070
|
-
assetId ?? this.provider.getBaseAssetId()
|
7071
|
-
);
|
7133
|
+
request.addCoinOutput(Address5.fromAddressOrString(destination), amount, assetId);
|
7072
7134
|
return request;
|
7073
7135
|
}
|
7074
7136
|
/**
|
@@ -7079,12 +7141,11 @@ var Account = class extends AbstractAccount {
|
|
7079
7141
|
* @returns The updated script transaction request.
|
7080
7142
|
*/
|
7081
7143
|
addBatchTransfer(request, transferParams) {
|
7082
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7083
7144
|
transferParams.forEach(({ destination, amount, assetId }) => {
|
7084
7145
|
this.addTransfer(request, {
|
7085
7146
|
destination,
|
7086
7147
|
amount,
|
7087
|
-
assetId
|
7148
|
+
assetId
|
7088
7149
|
});
|
7089
7150
|
});
|
7090
7151
|
return request;
|
@@ -7106,13 +7167,14 @@ var Account = class extends AbstractAccount {
|
|
7106
7167
|
...txParams
|
7107
7168
|
});
|
7108
7169
|
const quantities = [];
|
7170
|
+
const defaultAssetId = await this.provider.getBaseAssetId();
|
7109
7171
|
const transferParams = contractTransferParams.map((transferParam) => {
|
7110
7172
|
const amount = bn19(transferParam.amount);
|
7111
7173
|
const contractAddress = Address5.fromAddressOrString(transferParam.contractId);
|
7112
|
-
const assetId = transferParam.assetId ? hexlify19(transferParam.assetId) :
|
7174
|
+
const assetId = transferParam.assetId ? hexlify19(transferParam.assetId) : defaultAssetId;
|
7113
7175
|
if (amount.lte(0)) {
|
7114
|
-
throw new
|
7115
|
-
|
7176
|
+
throw new FuelError21(
|
7177
|
+
ErrorCode18.INVALID_TRANSFER_AMOUNT,
|
7116
7178
|
"Transfer amount must be a positive number."
|
7117
7179
|
);
|
7118
7180
|
}
|
@@ -7152,7 +7214,7 @@ var Account = class extends AbstractAccount {
|
|
7152
7214
|
...amountDataArray
|
7153
7215
|
]);
|
7154
7216
|
const params = { script, ...txParams };
|
7155
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7217
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
7156
7218
|
let request = new ScriptTransactionRequest(params);
|
7157
7219
|
const quantities = [{ amount: bn19(amount), assetId: baseAssetId }];
|
7158
7220
|
const txCost = await this.getTransactionCost(request, { quantities });
|
@@ -7177,7 +7239,7 @@ var Account = class extends AbstractAccount {
|
|
7177
7239
|
*/
|
7178
7240
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
|
7179
7241
|
const txRequestClone = clone9(transactionRequestify(transactionRequestLike));
|
7180
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7242
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
7181
7243
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
7182
7244
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
7183
7245
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: bn19("100000000000000000") }];
|
@@ -7227,7 +7289,7 @@ var Account = class extends AbstractAccount {
|
|
7227
7289
|
*/
|
7228
7290
|
async signMessage(message) {
|
7229
7291
|
if (!this._connector) {
|
7230
|
-
throw new
|
7292
|
+
throw new FuelError21(ErrorCode18.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
7231
7293
|
}
|
7232
7294
|
return this._connector.signMessage(this.address.toString(), message);
|
7233
7295
|
}
|
@@ -7239,8 +7301,8 @@ var Account = class extends AbstractAccount {
|
|
7239
7301
|
*/
|
7240
7302
|
async signTransaction(transactionRequestLike) {
|
7241
7303
|
if (!this._connector) {
|
7242
|
-
throw new
|
7243
|
-
|
7304
|
+
throw new FuelError21(
|
7305
|
+
ErrorCode18.MISSING_CONNECTOR,
|
7244
7306
|
"A connector is required to sign transactions."
|
7245
7307
|
);
|
7246
7308
|
}
|
@@ -7253,10 +7315,13 @@ var Account = class extends AbstractAccount {
|
|
7253
7315
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
7254
7316
|
* @returns A promise that resolves to the transaction response.
|
7255
7317
|
*/
|
7256
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
7318
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, onBeforeSend, skipCustomFee = false } = {}) {
|
7257
7319
|
if (this._connector) {
|
7258
7320
|
return this.provider.getTransactionResponse(
|
7259
|
-
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike
|
7321
|
+
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike, {
|
7322
|
+
onBeforeSend,
|
7323
|
+
skipCustomFee
|
7324
|
+
})
|
7260
7325
|
);
|
7261
7326
|
}
|
7262
7327
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
@@ -7299,8 +7364,8 @@ var Account = class extends AbstractAccount {
|
|
7299
7364
|
/** @hidden * */
|
7300
7365
|
validateTransferAmount(amount) {
|
7301
7366
|
if (bn19(amount).lte(0)) {
|
7302
|
-
throw new
|
7303
|
-
|
7367
|
+
throw new FuelError21(
|
7368
|
+
ErrorCode18.INVALID_TRANSFER_AMOUNT,
|
7304
7369
|
"Transfer amount must be a positive number."
|
7305
7370
|
);
|
7306
7371
|
}
|
@@ -7329,16 +7394,16 @@ var Account = class extends AbstractAccount {
|
|
7329
7394
|
if (!isDefined3(setGasLimit)) {
|
7330
7395
|
request.gasLimit = gasUsed;
|
7331
7396
|
} else if (gasUsed.gt(setGasLimit)) {
|
7332
|
-
throw new
|
7333
|
-
|
7397
|
+
throw new FuelError21(
|
7398
|
+
ErrorCode18.GAS_LIMIT_TOO_LOW,
|
7334
7399
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
7335
7400
|
);
|
7336
7401
|
}
|
7337
7402
|
if (!isDefined3(setMaxFee)) {
|
7338
7403
|
request.maxFee = maxFee;
|
7339
7404
|
} else if (maxFee.gt(setMaxFee)) {
|
7340
|
-
throw new
|
7341
|
-
|
7405
|
+
throw new FuelError21(
|
7406
|
+
ErrorCode18.MAX_FEE_TOO_LOW,
|
7342
7407
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
7343
7408
|
);
|
7344
7409
|
}
|
@@ -7358,7 +7423,7 @@ import {
|
|
7358
7423
|
encryptJsonWalletData,
|
7359
7424
|
randomUUID as randomUUID2
|
7360
7425
|
} from "@fuel-ts/crypto";
|
7361
|
-
import { ErrorCode as
|
7426
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError22 } from "@fuel-ts/errors";
|
7362
7427
|
import { hexlify as hexlify20 } from "@fuel-ts/utils";
|
7363
7428
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
7364
7429
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -7435,8 +7500,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7435
7500
|
const macHashUint8Array = keccak256(data);
|
7436
7501
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
7437
7502
|
if (mac !== macHash) {
|
7438
|
-
throw new
|
7439
|
-
|
7503
|
+
throw new FuelError22(
|
7504
|
+
ErrorCode19.INVALID_PASSWORD,
|
7440
7505
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
7441
7506
|
);
|
7442
7507
|
}
|
@@ -7496,7 +7561,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
7496
7561
|
*/
|
7497
7562
|
async signTransaction(transactionRequestLike) {
|
7498
7563
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
7499
|
-
const chainId = this.provider.getChainId();
|
7564
|
+
const chainId = await this.provider.getChainId();
|
7500
7565
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
7501
7566
|
const signature = await this.signer().sign(hashedTransaction);
|
7502
7567
|
return hexlify21(signature);
|
@@ -7520,14 +7585,19 @@ var BaseWalletUnlocked = class extends Account {
|
|
7520
7585
|
* @param estimateTxDependencies - Whether to estimate the transaction dependencies.
|
7521
7586
|
* @returns A promise that resolves to the TransactionResponse object.
|
7522
7587
|
*/
|
7523
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false } = {}) {
|
7588
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, enableAssetBurn } = {}) {
|
7524
7589
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
7590
|
+
validateTransactionForAssetBurn(
|
7591
|
+
await this.provider.getBaseAssetId(),
|
7592
|
+
transactionRequest,
|
7593
|
+
enableAssetBurn
|
7594
|
+
);
|
7525
7595
|
if (estimateTxDependencies) {
|
7526
7596
|
await this.provider.estimateTxDependencies(transactionRequest);
|
7527
7597
|
}
|
7528
7598
|
return this.provider.sendTransaction(
|
7529
7599
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
7530
|
-
{ estimateTxDependencies: false }
|
7600
|
+
{ estimateTxDependencies: false, enableAssetBurn }
|
7531
7601
|
);
|
7532
7602
|
}
|
7533
7603
|
/**
|
@@ -7566,14 +7636,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
7566
7636
|
|
7567
7637
|
// src/hdwallet/hdwallet.ts
|
7568
7638
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
7569
|
-
import { ErrorCode as
|
7639
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError25 } from "@fuel-ts/errors";
|
7570
7640
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
7571
7641
|
import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
7572
7642
|
import { arrayify as arrayify19, hexlify as hexlify23, concat as concat6, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
7573
7643
|
|
7574
7644
|
// src/mnemonic/mnemonic.ts
|
7575
7645
|
import { randomBytes as randomBytes7, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
7576
|
-
import { ErrorCode as
|
7646
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError24 } from "@fuel-ts/errors";
|
7577
7647
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
7578
7648
|
import { arrayify as arrayify18, hexlify as hexlify22, concat as concat5, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
7579
7649
|
|
@@ -9630,7 +9700,7 @@ var english = [
|
|
9630
9700
|
];
|
9631
9701
|
|
9632
9702
|
// src/mnemonic/utils.ts
|
9633
|
-
import { ErrorCode as
|
9703
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError23 } from "@fuel-ts/errors";
|
9634
9704
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
9635
9705
|
import { arrayify as arrayify17 } from "@fuel-ts/utils";
|
9636
9706
|
function getLowerMask(bits) {
|
@@ -9679,8 +9749,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9679
9749
|
for (let i = 0; i < words.length; i += 1) {
|
9680
9750
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
9681
9751
|
if (index === -1) {
|
9682
|
-
throw new
|
9683
|
-
|
9752
|
+
throw new FuelError23(
|
9753
|
+
ErrorCode20.INVALID_MNEMONIC,
|
9684
9754
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
9685
9755
|
);
|
9686
9756
|
}
|
@@ -9696,8 +9766,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9696
9766
|
const checksumMask = getUpperMask(checksumBits);
|
9697
9767
|
const checksum = arrayify17(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
9698
9768
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
9699
|
-
throw new
|
9700
|
-
|
9769
|
+
throw new FuelError23(
|
9770
|
+
ErrorCode20.INVALID_CHECKSUM,
|
9701
9771
|
"Checksum validation failed for the provided mnemonic."
|
9702
9772
|
);
|
9703
9773
|
}
|
@@ -9711,16 +9781,16 @@ var TestnetPRV = "0x04358394";
|
|
9711
9781
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
9712
9782
|
function assertWordList(wordlist) {
|
9713
9783
|
if (wordlist.length !== 2048) {
|
9714
|
-
throw new
|
9715
|
-
|
9784
|
+
throw new FuelError24(
|
9785
|
+
ErrorCode21.INVALID_WORD_LIST,
|
9716
9786
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
9717
9787
|
);
|
9718
9788
|
}
|
9719
9789
|
}
|
9720
9790
|
function assertEntropy(entropy) {
|
9721
9791
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
9722
|
-
throw new
|
9723
|
-
|
9792
|
+
throw new FuelError24(
|
9793
|
+
ErrorCode21.INVALID_ENTROPY,
|
9724
9794
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
9725
9795
|
);
|
9726
9796
|
}
|
@@ -9730,7 +9800,7 @@ function assertMnemonic(words) {
|
|
9730
9800
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
9731
9801
|
", "
|
9732
9802
|
)}] words, but got ${words.length}.`;
|
9733
|
-
throw new
|
9803
|
+
throw new FuelError24(ErrorCode21.INVALID_MNEMONIC, errorMsg);
|
9734
9804
|
}
|
9735
9805
|
}
|
9736
9806
|
var Mnemonic = class {
|
@@ -9848,8 +9918,8 @@ var Mnemonic = class {
|
|
9848
9918
|
static masterKeysFromSeed(seed) {
|
9849
9919
|
const seedArray = arrayify18(seed);
|
9850
9920
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
9851
|
-
throw new
|
9852
|
-
|
9921
|
+
throw new FuelError24(
|
9922
|
+
ErrorCode21.INVALID_SEED,
|
9853
9923
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
9854
9924
|
);
|
9855
9925
|
}
|
@@ -9926,7 +9996,7 @@ function isValidExtendedKey(extendedKey) {
|
|
9926
9996
|
function parsePath(path2, depth = 0) {
|
9927
9997
|
const components = path2.split("/");
|
9928
9998
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
9929
|
-
throw new
|
9999
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
9930
10000
|
}
|
9931
10001
|
if (components[0] === "m") {
|
9932
10002
|
components.shift();
|
@@ -9955,8 +10025,8 @@ var HDWallet = class {
|
|
9955
10025
|
this.privateKey = hexlify23(config.privateKey);
|
9956
10026
|
} else {
|
9957
10027
|
if (!config.publicKey) {
|
9958
|
-
throw new
|
9959
|
-
|
10028
|
+
throw new FuelError25(
|
10029
|
+
ErrorCode22.HD_WALLET_ERROR,
|
9960
10030
|
"Both public and private Key cannot be missing. At least one should be provided."
|
9961
10031
|
);
|
9962
10032
|
}
|
@@ -9985,8 +10055,8 @@ var HDWallet = class {
|
|
9985
10055
|
const data = new Uint8Array(37);
|
9986
10056
|
if (index & HARDENED_INDEX) {
|
9987
10057
|
if (!privateKey) {
|
9988
|
-
throw new
|
9989
|
-
|
10058
|
+
throw new FuelError25(
|
10059
|
+
ErrorCode22.HD_WALLET_ERROR,
|
9990
10060
|
"Cannot derive a hardened index without a private Key."
|
9991
10061
|
);
|
9992
10062
|
}
|
@@ -10038,8 +10108,8 @@ var HDWallet = class {
|
|
10038
10108
|
*/
|
10039
10109
|
toExtendedKey(isPublic = false, testnet = false) {
|
10040
10110
|
if (this.depth >= 256) {
|
10041
|
-
throw new
|
10042
|
-
|
10111
|
+
throw new FuelError25(
|
10112
|
+
ErrorCode22.HD_WALLET_ERROR,
|
10043
10113
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
10044
10114
|
);
|
10045
10115
|
}
|
@@ -10070,10 +10140,10 @@ var HDWallet = class {
|
|
10070
10140
|
const bytes = arrayify19(decoded);
|
10071
10141
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
10072
10142
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
10073
|
-
throw new
|
10143
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
10074
10144
|
}
|
10075
10145
|
if (!validChecksum) {
|
10076
|
-
throw new
|
10146
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
10077
10147
|
}
|
10078
10148
|
const depth = bytes[4];
|
10079
10149
|
const parentFingerprint = hexlify23(bytes.slice(5, 9));
|
@@ -10081,14 +10151,14 @@ var HDWallet = class {
|
|
10081
10151
|
const chainCode = hexlify23(bytes.slice(13, 45));
|
10082
10152
|
const key = bytes.slice(45, 78);
|
10083
10153
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
10084
|
-
throw new
|
10085
|
-
|
10154
|
+
throw new FuelError25(
|
10155
|
+
ErrorCode22.HD_WALLET_ERROR,
|
10086
10156
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
10087
10157
|
);
|
10088
10158
|
}
|
10089
10159
|
if (isPublicExtendedKey(bytes)) {
|
10090
10160
|
if (key[0] !== 3) {
|
10091
|
-
throw new
|
10161
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, "Invalid public extended key.");
|
10092
10162
|
}
|
10093
10163
|
return new HDWallet({
|
10094
10164
|
publicKey: key,
|
@@ -10099,7 +10169,7 @@ var HDWallet = class {
|
|
10099
10169
|
});
|
10100
10170
|
}
|
10101
10171
|
if (key[0] !== 0) {
|
10102
|
-
throw new
|
10172
|
+
throw new FuelError25(ErrorCode22.HD_WALLET_ERROR, "Invalid private extended key.");
|
10103
10173
|
}
|
10104
10174
|
return new HDWallet({
|
10105
10175
|
privateKey: key.slice(1),
|
@@ -10343,26 +10413,26 @@ var WalletsConfig = class {
|
|
10343
10413
|
amountPerCoin
|
10344
10414
|
}) {
|
10345
10415
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
10346
|
-
throw new
|
10347
|
-
|
10416
|
+
throw new FuelError26(
|
10417
|
+
FuelError26.CODES.INVALID_INPUT_PARAMETERS,
|
10348
10418
|
"Number of wallets must be greater than zero."
|
10349
10419
|
);
|
10350
10420
|
}
|
10351
10421
|
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
10352
|
-
throw new
|
10353
|
-
|
10422
|
+
throw new FuelError26(
|
10423
|
+
FuelError26.CODES.INVALID_INPUT_PARAMETERS,
|
10354
10424
|
"Number of assets per wallet must be greater than zero."
|
10355
10425
|
);
|
10356
10426
|
}
|
10357
10427
|
if (coinsPerAsset <= 0) {
|
10358
|
-
throw new
|
10359
|
-
|
10428
|
+
throw new FuelError26(
|
10429
|
+
FuelError26.CODES.INVALID_INPUT_PARAMETERS,
|
10360
10430
|
"Number of coins per asset must be greater than zero."
|
10361
10431
|
);
|
10362
10432
|
}
|
10363
10433
|
if (amountPerCoin < 0) {
|
10364
|
-
throw new
|
10365
|
-
|
10434
|
+
throw new FuelError26(
|
10435
|
+
FuelError26.CODES.INVALID_INPUT_PARAMETERS,
|
10366
10436
|
"Amount per coin must be greater than or equal to zero."
|
10367
10437
|
);
|
10368
10438
|
}
|
@@ -10385,7 +10455,7 @@ async function setupTestProviderAndWallets({
|
|
10385
10455
|
} = {}) {
|
10386
10456
|
Symbol.dispose ??= Symbol("Symbol.dispose");
|
10387
10457
|
const walletsConfig = new WalletsConfig(
|
10388
|
-
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.
|
10458
|
+
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V2?.base_asset_id ?? defaultSnapshotConfigs3.chainConfig.consensus_parameters.V2.base_asset_id,
|
10389
10459
|
{
|
10390
10460
|
...defaultWalletConfigOptions,
|
10391
10461
|
...walletsConfigOptions
|
@@ -10415,7 +10485,8 @@ async function setupTestProviderAndWallets({
|
|
10415
10485
|
}
|
10416
10486
|
let provider;
|
10417
10487
|
try {
|
10418
|
-
provider =
|
10488
|
+
provider = new Provider(url, providerOptions);
|
10489
|
+
await provider.init();
|
10419
10490
|
} catch (err) {
|
10420
10491
|
cleanup();
|
10421
10492
|
throw err;
|