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

feat: add function to mask address #12

Merged
merged 2 commits into from
Jul 4, 2024
Merged

feat: add function to mask address #12

merged 2 commits into from
Jul 4, 2024

Conversation

piavgh
Copy link
Member

@piavgh piavgh commented Jul 4, 2024

Why did we need it?

Related Issue

Release Note

How Has This Been Tested?

Screenshots (if appropriate):

return "", ErrInvalidNumVisibleChars
}

prefixLength := len("0x") + numVisibleChars/2 // The number of characters to keep at the start (0x + first some hex digits)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, numVisibleChars/2 vs numVisibleChars / 2 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, sometimes go formating is weird https://go.screenpal.com/watch/cZifeCV8zdQ

// @param numVisibleChars: The number of visible characters to keep at the start and end of the address
// @param maskedCharacter: The character to use for masking the middle part of the address
// @return The masked address and error if any
func MaskAddress(address string, numVisibleChars int, maskedCharacter rune) (string, error) {
Copy link
Member

@hieuvo hieuvo Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with negative numVisibleChars, this method will throw panic

panic: runtime error: slice bounds out of range [44:42] [recovered]
panic: runtime error: slice bounds out of range [44:42]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, good catch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit to fix this

@piavgh piavgh merged commit 771fd26 into main Jul 4, 2024
2 checks passed
@piavgh piavgh deleted the feature/masked-address branch July 4, 2024 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants