You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 } }
The text was updated successfully, but these errors were encountered:
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 } }
The text was updated successfully, but these errors were encountered: