From 7263ff6f75e395c06ed1b67efff582ad95e663cc Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Wed, 10 Jul 2024 12:04:53 -0700 Subject: [PATCH] refactor(derived-leaves.ts): remove unused empty() and toJSON() methods from createMayUseToken feat(derived-leaves.ts): add check() method to createMayUseToken to validate that parentsOwnToken and inheritFromParent are not both true, improving data integrity and catching potential errors early The empty() and toJSON() methods were removed because they were not being used in the codebase. The new check() method was added to validate the integrity of the MayUseToken data structure by ensuring that parentsOwnToken and inheritFromParent are not both true at the same time, which would be an invalid state. This check helps catch potential errors early and improves the overall reliability and maintainability of the code. --- mina-transaction/derived-leaves.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/mina-transaction/derived-leaves.ts b/mina-transaction/derived-leaves.ts index e39e4e27..f29d1700 100644 --- a/mina-transaction/derived-leaves.ts +++ b/mina-transaction/derived-leaves.ts @@ -261,17 +261,13 @@ function createMayUseToken< >(base: Base, Bool: GenericSignableBool) { return { ...(base as Omit), - empty(): MayUseToken { - return { - parentsOwnToken: Bool(false), - inheritFromParent: Bool(false), - }; - }, - toJSON(x: MayUseToken): Json.MayUseToken { - return { - parentsOwnToken: Bool.toJSON(x.parentsOwnToken), - inheritFromParent: Bool.toJSON(x.inheritFromParent), - }; + check(mayUseToken: MayUseToken) { + let parentsOwnToken = Bool.toJSON(mayUseToken.parentsOwnToken); + let inheritFromParent = Bool.toJSON(mayUseToken.inheritFromParent); + if (parentsOwnToken && inheritFromParent) + throw Error( + 'MayUseToken: parentsOwnToken and inheritFromParent cannot both be true' + ); }, fromJSON(json: Json.MayUseToken): MayUseToken { return {