Skip to content

Feat/to checksum address #228

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

Merged
merged 6 commits into from
Jun 14, 2022

Conversation

dhruv500
Copy link
Contributor

@dhruv500 dhruv500 commented Jun 8, 2022

to checksum address func added in string extension

Comment on lines 38 to 51
func toChecksumAddress() -> String {
let lowerCaseAddress = self.stripHexPrefix().lowercased()
let arr = Array(lowerCaseAddress)
let keccaf = Array(lowerCaseAddress.web3.keccak256.web3.hexString.stripHexPrefix())
var result = "0x"
for i in 0 ... lowerCaseAddress.count - 1 {
if let val = Int(String(keccaf[i]), radix: 16), val >= 8 {
result.append(arr[i].uppercased())
} else {
result.append(arr[i])
}
}
return result
}
Copy link
Member

Choose a reason for hiding this comment

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

This should be an method in EthereumAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 99 to 107
public extension String {
func stripHexPrefix() -> String {
if hasPrefix("0x") {
let indexStart = index(startIndex, offsetBy: 2)
return String(self[indexStart...])
}
return self
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We already have an extension on string noHexPrefix, why did you add this one here?

Choose a reason for hiding this comment

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

my bad,removed.

Copy link
Member

@DarthMike DarthMike left a comment

Choose a reason for hiding this comment

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

Thanks @dhruv500

@DarthMike DarthMike merged commit 05bd9d4 into argentlabs:develop Jun 14, 2022
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.

3 participants