@fuel-ts/account 0.0.0-rc-1936-20240326112905 → 0.0.0-rc-1895-20240327220629
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/dist/index.global.js +167 -22
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +581 -479
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +359 -252
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +3 -0
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/types.d.ts +5 -0
- package/dist/providers/transaction-request/types.d.ts.map +1 -1
- package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +5 -2
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +14 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +167 -9
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +541 -434
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +329 -214
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.global.js
CHANGED
@@ -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 of 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 of an "assert" statement failed to evaluate to true.`;
|
39427
|
+
break;
|
39428
|
+
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
39429
|
+
errorMessage = `The transaction reverted because missing "OutputChange"(s).`;
|
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 wasPanic = receipts.some(({ type: type3 }) => type3 === ReceiptType.Panic);
|
39440
|
+
let err = status?.type === "FailureStatus" && wasPanic ? 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";
|
@@ -40107,6 +40218,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
40107
40218
|
script;
|
40108
40219
|
/** Script input data (parameters) */
|
40109
40220
|
scriptData;
|
40221
|
+
abis;
|
40110
40222
|
/**
|
40111
40223
|
* Constructor for `ScriptTransactionRequest`.
|
40112
40224
|
*
|
@@ -40117,6 +40229,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
40117
40229
|
this.gasLimit = bn(gasLimit);
|
40118
40230
|
this.script = arrayify(script ?? returnZeroScript.bytes);
|
40119
40231
|
this.scriptData = arrayify(scriptData ?? returnZeroScript.encodeScriptData());
|
40232
|
+
this.abis = rest.abis;
|
40120
40233
|
}
|
40121
40234
|
/**
|
40122
40235
|
* Converts the transaction request to a `TransactionScript`.
|
@@ -41002,6 +41115,19 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41002
41115
|
return transactionSummary;
|
41003
41116
|
}
|
41004
41117
|
|
41118
|
+
// src/providers/transaction-response/getDecodedLogs.ts
|
41119
|
+
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
41120
|
+
return receipts.reduce((logs, receipt) => {
|
41121
|
+
if (receipt.type === ReceiptType.LogData || receipt.type === ReceiptType.Log) {
|
41122
|
+
const interfaceToUse = new Interface(externalAbis[receipt.id] || mainAbi);
|
41123
|
+
const data = receipt.type === ReceiptType.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
41124
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
41125
|
+
logs.push(decodedLog);
|
41126
|
+
}
|
41127
|
+
return logs;
|
41128
|
+
}, []);
|
41129
|
+
}
|
41130
|
+
|
41005
41131
|
// src/providers/transaction-response/transaction-response.ts
|
41006
41132
|
var TransactionResponse2 = class {
|
41007
41133
|
/** Transaction ID */
|
@@ -41012,15 +41138,17 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41012
41138
|
gasUsed = bn(0);
|
41013
41139
|
/** The graphql Transaction with receipts object. */
|
41014
41140
|
gqlTransaction;
|
41141
|
+
abis;
|
41015
41142
|
/**
|
41016
41143
|
* Constructor for `TransactionResponse`.
|
41017
41144
|
*
|
41018
41145
|
* @param id - The transaction ID.
|
41019
41146
|
* @param provider - The provider.
|
41020
41147
|
*/
|
41021
|
-
constructor(id, provider) {
|
41148
|
+
constructor(id, provider, abis) {
|
41022
41149
|
this.id = id;
|
41023
41150
|
this.provider = provider;
|
41151
|
+
this.abis = abis;
|
41024
41152
|
}
|
41025
41153
|
/**
|
41026
41154
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
@@ -41030,8 +41158,8 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41030
41158
|
* @param id - The transaction ID.
|
41031
41159
|
* @param provider - The provider.
|
41032
41160
|
*/
|
41033
|
-
static async create(id, provider) {
|
41034
|
-
const response = new TransactionResponse2(id, provider);
|
41161
|
+
static async create(id, provider, abis) {
|
41162
|
+
const response = new TransactionResponse2(id, provider, abis);
|
41035
41163
|
await response.fetch();
|
41036
41164
|
return response;
|
41037
41165
|
}
|
@@ -41135,6 +41263,26 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41135
41263
|
gqlTransaction: this.gqlTransaction,
|
41136
41264
|
...transactionSummary
|
41137
41265
|
};
|
41266
|
+
let logs = [];
|
41267
|
+
if (this.abis) {
|
41268
|
+
logs = getDecodedLogs(
|
41269
|
+
transactionSummary.receipts,
|
41270
|
+
this.abis.main,
|
41271
|
+
this.abis.otherContractsAbis
|
41272
|
+
);
|
41273
|
+
transactionResult.logs = logs;
|
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
|
+
}
|
41138
41286
|
return transactionResult;
|
41139
41287
|
}
|
41140
41288
|
/**
|
@@ -41145,28 +41293,21 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41145
41293
|
async wait(contractsAbiMap) {
|
41146
41294
|
const result = await this.waitForResult(contractsAbiMap);
|
41147
41295
|
if (result.isStatusFailure) {
|
41148
|
-
|
41149
|
-
|
41150
|
-
|
41151
|
-
|
41296
|
+
const {
|
41297
|
+
receipts,
|
41298
|
+
logs = [],
|
41299
|
+
gqlTransaction: { status }
|
41300
|
+
} = result;
|
41301
|
+
throw extractTxError({
|
41302
|
+
receipts,
|
41303
|
+
logs,
|
41304
|
+
status
|
41305
|
+
});
|
41152
41306
|
}
|
41153
41307
|
return result;
|
41154
41308
|
}
|
41155
41309
|
};
|
41156
41310
|
|
41157
|
-
// src/providers/transaction-response/getDecodedLogs.ts
|
41158
|
-
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
41159
|
-
return receipts.reduce((logs, receipt) => {
|
41160
|
-
if (receipt.type === ReceiptType.LogData || receipt.type === ReceiptType.Log) {
|
41161
|
-
const interfaceToUse = externalAbis[receipt.id] ? new Interface(externalAbis[receipt.id]) : new Interface(mainAbi);
|
41162
|
-
const data = receipt.type === ReceiptType.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
41163
|
-
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
41164
|
-
logs.push(decodedLog);
|
41165
|
-
}
|
41166
|
-
return logs;
|
41167
|
-
}, []);
|
41168
|
-
}
|
41169
|
-
|
41170
41311
|
// src/providers/utils/auto-retry-fetch.ts
|
41171
41312
|
function getWaitDelay(options, retryAttemptNum) {
|
41172
41313
|
const duration = options.baseDelay ?? 150;
|
@@ -41501,6 +41642,10 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41501
41642
|
await this.estimateTxDependencies(transactionRequest);
|
41502
41643
|
}
|
41503
41644
|
const encodedTransaction = hexlify(transactionRequest.toTransactionBytes());
|
41645
|
+
let abis;
|
41646
|
+
if (transactionRequest.type === TransactionType.Script) {
|
41647
|
+
abis = transactionRequest.abis;
|
41648
|
+
}
|
41504
41649
|
if (awaitExecution) {
|
41505
41650
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
41506
41651
|
for await (const { submitAndAwait } of subscription) {
|
@@ -41515,14 +41660,14 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41515
41660
|
}
|
41516
41661
|
}
|
41517
41662
|
const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
|
41518
|
-
const response = new TransactionResponse2(transactionId2, this);
|
41663
|
+
const response = new TransactionResponse2(transactionId2, this, abis);
|
41519
41664
|
await response.fetch();
|
41520
41665
|
return response;
|
41521
41666
|
}
|
41522
41667
|
const {
|
41523
41668
|
submit: { id: transactionId }
|
41524
41669
|
} = await this.operations.submit({ encodedTransaction });
|
41525
|
-
return new TransactionResponse2(transactionId, this);
|
41670
|
+
return new TransactionResponse2(transactionId, this, abis);
|
41526
41671
|
}
|
41527
41672
|
/**
|
41528
41673
|
* Executes a transaction without actually submitting it to the chain.
|