Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: add node id to the precheck error #2414

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ export default class Executable {
* @internal
* @param {RequestT} request
* @param {ResponseT} response
* @param {AccountId} nodeId
* @returns {Error}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapStatusError(request, response) {
_mapStatusError(request, response, nodeId) {
throw new Error("not implemented");
}

Expand Down Expand Up @@ -722,7 +723,11 @@ export default class Executable {
case ExecutionState.Finished:
return this._mapResponse(response, nodeAccountId, request);
case ExecutionState.Error:
throw this._mapStatusError(request, response);
throw this._mapStatusError(
request,
response,
nodeAccountId,
);
default:
throw new Error(
"(BUG) non-exhaustive switch statement for `ExecutionState`",
Expand Down
12 changes: 11 additions & 1 deletion src/PrecheckStatusError.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import StatusError from "./StatusError.js";
* @typedef {import("./Status.js").default} Status
* @typedef {import("./transaction/TransactionId.js").default} TransactionId
* @typedef {import("./contract/ContractFunctionResult.js").default} ContractFunctionResult
* @typedef {import("./account/AccountId.js").default} AccountId
*/

/**
* @typedef {object} PrecheckStatusErrorJSON
* @property {string} name
* @property {string} status
* @property {string} transactionId
* @property {?string | null} nodeId
* @property {string} message
* @property {?ContractFunctionResult} contractFunctionResult
*/
Expand All @@ -40,19 +42,26 @@ export default class PrecheckStatusError extends StatusError {
* @param {object} props
* @param {Status} props.status
* @param {TransactionId} props.transactionId
* @param {AccountId} props.nodeId
* @param {?ContractFunctionResult} props.contractFunctionResult
*/
constructor(props) {
super(
props,
`transaction ${props.transactionId.toString()} failed precheck with status ${props.status.toString()}`,
`transaction ${props.transactionId.toString()} failed precheck with status ${props.status.toString()} against node account id ${props.nodeId.toString()}`,
);

/**
* @type {?ContractFunctionResult}
* @readonly
*/
this.contractFunctionResult = props.contractFunctionResult;

/**
* @type {AccountId}
* @readonly
*/
this.nodeId = props.nodeId;
}

/**
Expand All @@ -63,6 +72,7 @@ export default class PrecheckStatusError extends StatusError {
name: this.name,
status: this.status.toString(),
transactionId: this.transactionId.toString(),
nodeId: this.nodeId.toString(),
message: this.message,
contractFunctionResult: this.contractFunctionResult,
};
Expand Down
9 changes: 9 additions & 0 deletions src/Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ export default class Status {
return "EMPTY_TOKEN_REFERENCE_LIST";
case Status.UpdateNodeAccountNotAllowed:
return "UPDATE_NODE_ACCOUNT_NOT_ALLOWED";
case Status.TokenHasNoMetadataOrSupplyKey:
return "TOKEN_HAS_NO_METADATA_OR_SUPPLY_KEY";
default:
return `UNKNOWN (${this._code})`;
}
Expand Down Expand Up @@ -1325,6 +1327,8 @@ export default class Status {
return Status.EmptyTokenReferenceList;
case 359:
return Status.UpdateNodeAccountNotAllowed;
case 360:
return Status.TokenHasNoMetadataOrSupplyKey;
default:
throw new Error(
`(BUG) Status.fromCode() does not handle code: ${code}`,
Expand Down Expand Up @@ -2973,3 +2977,8 @@ Status.EmptyTokenReferenceList = new Status(358);
* The node account is not allowed to be updated
*/
Status.UpdateNodeAccountNotAllowed = new Status(359);

/*
* The token has no metadata or supply key
*/
Status.TokenHasNoMetadataOrSupplyKey = new Status(360);
5 changes: 4 additions & 1 deletion src/contract/ContractCallQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ export default class ContractCallQuery extends Query {
* @internal
* @param {HashgraphProto.proto.IQuery} request
* @param {HashgraphProto.proto.IResponse} response
* @param {AccountId} nodeId
* @returns {Error}
*/
_mapStatusError(request, response) {
_mapStatusError(request, response, nodeId) {
const { nodeTransactionPrecheckCode } =
this._mapResponseHeader(response);

Expand All @@ -262,6 +263,7 @@ export default class ContractCallQuery extends Query {
(response.contractCallLocal);
if (!call.functionResult) {
return new PrecheckStatusError({
nodeId,
status,
transactionId: this._getTransactionId(),
contractFunctionResult: null,
Expand All @@ -271,6 +273,7 @@ export default class ContractCallQuery extends Query {
const contractFunctionResult = this._mapResponseSync(response);

return new PrecheckStatusError({
nodeId,
status,
transactionId: this._getTransactionId(),
contractFunctionResult,
Expand Down
5 changes: 3 additions & 2 deletions src/query/CostQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ export default class CostQuery extends Executable {
* @internal
* @param {HashgraphProto.proto.IQuery} request
* @param {HashgraphProto.proto.IResponse} response
* @param {AccountId} nodeId
* @returns {Error}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapStatusError(request, response) {
return this._query._mapStatusError(request, response);
_mapStatusError(request, response, nodeId) {
return this._query._mapStatusError(request, response, nodeId);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/query/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,11 @@ export default class Query extends Executable {
* @internal
* @param {HashgraphProto.proto.IQuery} request
* @param {HashgraphProto.proto.IResponse} response
* @param {AccountId} nodeId
* @returns {Error}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapStatusError(request, response) {
_mapStatusError(request, response, nodeId) {
const { nodeTransactionPrecheckCode } =
this._mapResponseHeader(response);

Expand All @@ -520,6 +521,7 @@ export default class Query extends Executable {
);

return new PrecheckStatusError({
nodeId,
status,
transactionId: this._getTransactionId(),
contractFunctionResult: null,
Expand Down
6 changes: 4 additions & 2 deletions src/transaction/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ export default class Transaction extends Executable {
}

/**
* Before we proceed exeuction, we need to do a couple checks
* Before we proceed execution, we need to do a couple checks
*
* @override
* @protected
Expand Down Expand Up @@ -1513,10 +1513,11 @@ export default class Transaction extends Executable {
* @internal
* @param {HashgraphProto.proto.ITransaction} request
* @param {HashgraphProto.proto.ITransactionResponse} response
* @param {AccountId} nodeId
* @returns {Error}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapStatusError(request, response) {
_mapStatusError(request, response, nodeId) {
const { nodeTransactionPrecheckCode } = response;

const status = Status._fromCode(
Expand All @@ -1532,6 +1533,7 @@ export default class Transaction extends Executable {
}

return new PrecheckStatusError({
nodeId,
status,
transactionId: this._getTransactionId(),
contractFunctionResult: null,
Expand Down
4 changes: 3 additions & 1 deletion src/transaction/TransactionReceiptQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,11 @@ export default class TransactionReceiptQuery extends Query {
* @internal
* @param {HashgraphProto.proto.IQuery} request
* @param {HashgraphProto.proto.IResponse} response
* @param {AccountId} nodeId
* @returns {Error}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapStatusError(request, response) {
_mapStatusError(request, response, nodeId) {
const { nodeTransactionPrecheckCode } =
this._mapResponseHeader(response);

Expand All @@ -303,6 +304,7 @@ export default class TransactionReceiptQuery extends Query {

default:
return new PrecheckStatusError({
nodeId,
status,
transactionId: this._getTransactionId(),
contractFunctionResult: null,
Expand Down
4 changes: 3 additions & 1 deletion src/transaction/TransactionRecordQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,11 @@ export default class TransactionRecordQuery extends Query {
* @internal
* @param {HashgraphProto.proto.IQuery} request
* @param {HashgraphProto.proto.IResponse} response
* @param {AccountId} nodeId
* @returns {Error}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapStatusError(request, response) {
_mapStatusError(request, response, nodeId) {
const { nodeTransactionPrecheckCode } =
this._mapResponseHeader(response);

Expand All @@ -312,6 +313,7 @@ export default class TransactionRecordQuery extends Query {

default:
return new PrecheckStatusError({
nodeId,
status,
transactionId: this._getTransactionId(),
contractFunctionResult: null,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/AccountInfoMocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ describe("AccountInfoMocking", function () {
} catch (error) {
if (
error.message !==
"transaction [email protected] failed precheck with status TRANSACTION_EXPIRED"
"transaction [email protected] failed precheck with status TRANSACTION_EXPIRED against node account id 0.0.3"
) {
throw error;
}
Expand Down