Skip to content

Commit

Permalink
refactor(derived-leaves.ts): remove unused empty() and toJSON() metho…
Browse files Browse the repository at this point in the history
…ds 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.
  • Loading branch information
MartinMinkov committed Jul 10, 2024
1 parent f9cd5d9 commit 7263ff6
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions mina-transaction/derived-leaves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,13 @@ function createMayUseToken<
>(base: Base, Bool: GenericSignableBool<Field, Bool>) {
return {
...(base as Omit<Base, 'toJSON' | 'fromJSON'>),
empty(): MayUseToken<Bool> {
return {
parentsOwnToken: Bool(false),
inheritFromParent: Bool(false),
};
},
toJSON(x: MayUseToken<Bool>): Json.MayUseToken {
return {
parentsOwnToken: Bool.toJSON(x.parentsOwnToken),
inheritFromParent: Bool.toJSON(x.inheritFromParent),
};
check(mayUseToken: MayUseToken<Bool>) {
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<Bool> {
return {
Expand Down

0 comments on commit 7263ff6

Please sign in to comment.