Skip to content

Commit

Permalink
refactor(account-update.ts): simplify isParentsOwnToken and remove ch…
Browse files Browse the repository at this point in the history
…eck for inheritFromParent flag

The isParentsOwnToken method was checking that inheritFromParent is not true when validating if an account update is for a parent's own token. However, this check is unnecessary as the two flags are mutually exclusive and should not both be true at the same time. The check method was ensuring this invariant.

By removing the inheritFromParent check from isParentsOwnToken and the entire check method, we simplify the code while still maintaining the intended behavior. The isParentsOwnToken method now only returns the value of the parentsOwnToken flag, and the isInheritFromParent method continues to return the value of the inheritFromParent flag.

This refactoring improves code readability and maintainability by removing redundant checks and simplifying the logic.
  • Loading branch information
MartinMinkov committed Jul 10, 2024
1 parent b3c972b commit df603bc
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/lib/mina/account-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,22 +1193,11 @@ class AccountUpdate implements Types.AccountUpdate {
return parentsOwnToken.or(inheritFromParent).not();
},
isParentsOwnToken(a: AccountUpdate) {
// Check that inheritFromParent is not true when validating if an account update is for a parent's own token
return a.body.mayUseToken.parentsOwnToken.and(
a.body.mayUseToken.inheritFromParent.not()
);
return a.body.mayUseToken.parentsOwnToken;
},
isInheritFromParent(a: AccountUpdate) {
return a.body.mayUseToken.inheritFromParent;
},
check(mayUseToken: { parentsOwnToken: Bool; inheritFromParent: Bool }) {
// Ensure the flags are not both set to true
mayUseToken.parentsOwnToken
.and(mayUseToken.inheritFromParent)
.assertFalse(
'MayUseToken: parentsOwnToken and inheritFromParent cannot both be true'
);
},
};
}

Expand Down

0 comments on commit df603bc

Please sign in to comment.