@fuel-ts/account 0.0.0-rc-1962-20240328175938 → 0.0.0-rc-1895-20240329092733

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.

@@ -38962,7 +38962,60 @@ ${MessageCoinFragmentFragmentDoc}`;
38962
38962
  var MAX_SCRIPT_DATA_LENGTH = 1024 * 1024 * 1024;
38963
38963
  var MAX_PREDICATE_LENGTH = 1024 * 1024;
38964
38964
  var MAX_PREDICATE_DATA_LENGTH = 1024 * 1024;
38965
+ var FAILED_REQUIRE_SIGNAL = "0xffffffffffff0000";
38965
38966
  var FAILED_TRANSFER_TO_ADDRESS_SIGNAL = "0xffffffffffff0001";
38967
+ var FAILED_ASSERT_EQ_SIGNAL = "0xffffffffffff0003";
38968
+ var FAILED_ASSERT_SIGNAL = "0xffffffffffff0004";
38969
+ var FAILED_ASSERT_NE_SIGNAL = "0xffffffffffff0005";
38970
+ var PANIC_REASONS = [
38971
+ "UnknownPanicReason",
38972
+ "Revert",
38973
+ "OutOfGas",
38974
+ "TransactionValidity",
38975
+ "MemoryOverflow",
38976
+ "ArithmeticOverflow",
38977
+ "ContractNotFound",
38978
+ "MemoryOwnership",
38979
+ "NotEnoughBalance",
38980
+ "ExpectedInternalContext",
38981
+ "AssetIdNotFound",
38982
+ "InputNotFound",
38983
+ "OutputNotFound",
38984
+ "WitnessNotFound",
38985
+ "TransactionMaturity",
38986
+ "InvalidMetadataIdentifier",
38987
+ "MalformedCallStructure",
38988
+ "ReservedRegisterNotWritable",
38989
+ "InvalidFlags",
38990
+ "InvalidImmediateValue",
38991
+ "ExpectedCoinInput",
38992
+ "EcalError",
38993
+ "MemoryWriteOverlap",
38994
+ "ContractNotInInputs",
38995
+ "InternalBalanceOverflow",
38996
+ "ContractMaxSize",
38997
+ "ExpectedUnallocatedStack",
38998
+ "MaxStaticContractsReached",
38999
+ "TransferAmountCannotBeZero",
39000
+ "ExpectedOutputVariable",
39001
+ "ExpectedParentInternalContext",
39002
+ "PredicateReturnedNonOne",
39003
+ "ContractIdAlreadyDeployed",
39004
+ "ContractMismatch",
39005
+ "MessageDataTooLong",
39006
+ "ArithmeticError",
39007
+ "ContractInstructionNotAllowed",
39008
+ "TransferZeroCoins",
39009
+ "InvalidInstruction",
39010
+ "MemoryNotExecutable",
39011
+ "PolicyIsNotSet",
39012
+ "PolicyNotFound",
39013
+ "TooManyReceipts",
39014
+ "BalanceOverflow",
39015
+ "InvalidBlockHeight",
39016
+ "TooManySlots"
39017
+ ];
39018
+ var PANIC_DOC_URL = "https://docs.rs/fuel-asm/latest/fuel_asm/enum.PanicReason.html";
38966
39019
 
38967
39020
  // src/providers/utils/receipts.ts
38968
39021
  var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
@@ -39336,6 +39389,64 @@ ${MessageCoinFragmentFragmentDoc}`;
39336
39389
  });
39337
39390
  }
39338
39391
 
39392
+ // src/providers/utils/extract-tx-error.ts
39393
+ var assemblePanicError = (status) => {
39394
+ let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
39395
+ if (PANIC_REASONS.includes(status.reason)) {
39396
+ errorMessage = `${errorMessage}
39397
+
39398
+ You can read more about this error at:
39399
+
39400
+ ${PANIC_DOC_URL}#variant.${status.reason}`;
39401
+ }
39402
+ return errorMessage;
39403
+ };
39404
+ var stringify2 = (obj) => JSON.stringify(obj, null, 2);
39405
+ var assembleRevertError = (receipts, logs) => {
39406
+ let errorMessage = "The transaction reverted with an unknown reason.";
39407
+ const revertReceipt = receipts.find(({ type: type3 }) => type3 === ReceiptType.Revert);
39408
+ if (revertReceipt) {
39409
+ const reasonHex = bn(revertReceipt.val).toHex();
39410
+ switch (reasonHex) {
39411
+ case FAILED_REQUIRE_SIGNAL: {
39412
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify2(logs[0]) : "an error."}.`;
39413
+ break;
39414
+ }
39415
+ case FAILED_ASSERT_EQ_SIGNAL: {
39416
+ const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39417
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
39418
+ break;
39419
+ }
39420
+ case FAILED_ASSERT_NE_SIGNAL: {
39421
+ const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39422
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
39423
+ break;
39424
+ }
39425
+ case FAILED_ASSERT_SIGNAL:
39426
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
39427
+ break;
39428
+ case FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
39429
+ errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
39430
+ break;
39431
+ default:
39432
+ errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
39433
+ }
39434
+ }
39435
+ return errorMessage;
39436
+ };
39437
+ var extractTxError = (params) => {
39438
+ const { receipts, status, logs } = params;
39439
+ const isPanic = receipts.some(({ type: type3 }) => type3 === ReceiptType.Panic);
39440
+ let err = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
39441
+ err += `
39442
+
39443
+ logs: ${JSON.stringify(logs, null, 2)}`;
39444
+ err += `
39445
+
39446
+ receipts: ${JSON.stringify(receipts, null, 2)}`;
39447
+ return new FuelError(ErrorCode.SCRIPT_REVERTED, err);
39448
+ };
39449
+
39339
39450
  // src/providers/transaction-request/errors.ts
39340
39451
  var ChangeOutputCollisionError = class extends Error {
39341
39452
  name = "ChangeOutputCollisionError";
@@ -41152,14 +41263,26 @@ ${MessageCoinFragmentFragmentDoc}`;
41152
41263
  gqlTransaction: this.gqlTransaction,
41153
41264
  ...transactionSummary
41154
41265
  };
41266
+ let logs = [];
41155
41267
  if (this.abis) {
41156
- const logs = getDecodedLogs(
41268
+ logs = getDecodedLogs(
41157
41269
  transactionSummary.receipts,
41158
41270
  this.abis.main,
41159
41271
  this.abis.otherContractsAbis
41160
41272
  );
41161
41273
  transactionResult.logs = logs;
41162
41274
  }
41275
+ if (transactionResult.isStatusFailure) {
41276
+ const {
41277
+ receipts,
41278
+ gqlTransaction: { status }
41279
+ } = transactionResult;
41280
+ throw extractTxError({
41281
+ receipts,
41282
+ status,
41283
+ logs
41284
+ });
41285
+ }
41163
41286
  return transactionResult;
41164
41287
  }
41165
41288
  /**
@@ -41168,14 +41291,7 @@ ${MessageCoinFragmentFragmentDoc}`;
41168
41291
  * @param contractsAbiMap - The contracts ABI map.
41169
41292
  */
41170
41293
  async wait(contractsAbiMap) {
41171
- const result = await this.waitForResult(contractsAbiMap);
41172
- if (result.isStatusFailure) {
41173
- throw new FuelError(
41174
- ErrorCode.TRANSACTION_FAILED,
41175
- `Transaction failed: ${result.gqlTransaction.status.reason}`
41176
- );
41177
- }
41178
- return result;
41294
+ return this.waitForResult(contractsAbiMap);
41179
41295
  }
41180
41296
  };
41181
41297