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

eth.getAccounts() function returns an empty address Array #24

Closed
chaomaf opened this issue Sep 7, 2018 · 2 comments
Closed

eth.getAccounts() function returns an empty address Array #24

chaomaf opened this issue Sep 7, 2018 · 2 comments
Labels
bug Something isn't working

Comments

@chaomaf
Copy link

chaomaf commented Sep 7, 2018

I involved this function on my private chain environment which is installed on mac that geth client. the json rpc interface about "eth_accounts" actually returns an address data. So I read the source found that a bug code, here it is:

guard let string = self.result as? [String] else {return nil} let values = string.compactMap { (str) -> EthereumAddress? in return EthereumAddress(str, ignoreChecksum: true) }
the ignoreChecksum parmas value if is ture, then the init function body will return nil, so that leads the values empty
public init?(_ addressString:String, type: AddressType = .normal, ignoreChecksum: Bool = false) { switch type { case .normal: guard let data = Data.fromHex(addressString) else {return nil} guard data.count == 20 else {return nil} if !addressString.hasHexPrefix() { return nil } if (!ignoreChecksum) { // check for checksum if data.toHexString() == addressString.stripHexPrefix() { self._address = data.toHexString().addHexPrefix() self.type = .normal return } else if data.toHexString().uppercased() == addressString.stripHexPrefix() { self._address = data.toHexString().addHexPrefix() self.type = .normal return } else { let checksummedAddress = EthereumAddress.toChecksumAddress(data.toHexString().addHexPrefix()) guard checksummedAddress == addressString else {return nil} self._address = data.toHexString().addHexPrefix() self.type = .normal return } } return nil case .contractDeployment: self._address = "0x" self.type = .contractDeployment } }

@shamatar
Copy link
Contributor

shamatar commented Sep 8, 2018

Hello @chaomaf

Thank you for spotting a bug :) will fix immediately

Sincerely, Alexander

@shamatar
Copy link
Contributor

Should be fixed in #34

@shamatar shamatar added the bug Something isn't working label Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants