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

Addresses generator (#1) #825

Merged
merged 20 commits into from
Jul 19, 2023
Merged

Conversation

6od9i
Copy link
Contributor

@6od9i 6od9i commented Jun 29, 2023

  • Generation amount of addresses added
  • Generation wallet with index > 9 FIXED
  • Test generation addresses added

I had added method for faster generation addresses by derivation path index in seed, and found bug with generation.

There was bug with generation wallets from seed when index has more than 1 symbol, for example:
address of wallet "m/44'/60'/0'/1" same with wallet "m/44'/60'/0'/10" or "m/44'/60'/0'/121"

- Generation amount of addresses added
- Generation wallet with index > 9 fixed
- Test generation addresses added
@6od9i
Copy link
Contributor Author

6od9i commented Jun 29, 2023

I pulled from develop and there had failed tests too

@yaroslavyaroslav
Copy link
Collaborator

@6od9i Hey, thanks for this PR. Could you please fix typos within added code, to make the ci pipeline green.

Sources/Web3Core/KeystoreManager/BIP32Keystore.swift:220: wich ==> which
Sources/Web3Core/KeystoreManager/BIP32Keystore.swift:220: wiil ==> will
Sources/Web3Core/KeystoreManager/BIP32Keystore.swift:223: preffix ==> prefix
Sources/Web3Core/KeystoreManager/BIP32Keystore.swift:224: adresses ==> addresses

- Removed prefix path from address generation
var pathAppendix: String?

return [Int](0..<number).compactMap({ number in
pathAppendix = nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

your variable should be declared here and not line 233

let prefixPath = self.rootPrefix
var pathAppendix: String?

return [Int](0..<number).compactMap({ number in
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use trailing closure syntax

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done.

pathAppendix = nil
let path = prefixPath + "/\(number)"
if path.hasPrefix(prefixPath) {
let upperIndex = (path.range(of: prefixPath)?.upperBound)!
Copy link
Collaborator

Choose a reason for hiding this comment

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

please no force unwrap

Copy link
Contributor Author

@6od9i 6od9i Jun 29, 2023

Choose a reason for hiding this comment

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

copyed from createNewCustomChildAccount

guard pathAppendix != nil else {
return nil
}
if pathAppendix!.hasPrefix("/") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

no force unwrap

Copy link
Contributor Author

@6od9i 6od9i Jun 29, 2023

Choose a reason for hiding this comment

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

copyed from createNewCustomChildAccount

return nil
}
if pathAppendix!.hasPrefix("/") {
pathAppendix = pathAppendix?.trimmingCharacters(in: CharacterSet.init(charactersIn: "/"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use proper swift init syntax

Copy link
Contributor Author

@6od9i 6od9i Jun 29, 2023

Choose a reason for hiding this comment

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

copyed from createNewCustomChildAccount

Copy link
Collaborator

Choose a reason for hiding this comment

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

All CharacterSet.init were replaced with .init to reduce the length of lines where it occurs.

}
} else {
if path.hasPrefix("/") {
pathAppendix = path.trimmingCharacters(in: CharacterSet.init(charactersIn: "/"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use proper swift init syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copyed from createNewCustomChildAccount

}
guard pathAppendix != nil,
rootNode.depth == prefixPath.components(separatedBy: "/").count - 1,
let newNode = rootNode.derive(path: pathAppendix!, derivePrivateKey: true),
Copy link
Collaborator

Choose a reason for hiding this comment

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

please no force unwrap

Copy link
Contributor Author

@6od9i 6od9i Jun 29, 2023

Choose a reason for hiding this comment

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

Hi, thank you for your comments, but this code in style of all this file
I copied createNewCustomChildAccount method and changed it here, force unwraps had been written here everywhere, that why i used it. And i do not want to change all this file, i used this style

Copy link
Collaborator

Choose a reason for hiding this comment

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

In addition to all of the folks said, I'd like to add that there's a fair point in your arguing about relatively bad code style within all the least file. The thing is that this is how we decided to maintain this lib some time ago: we're leaving all the code that works yet unsound for as long as we're not required to change it. But if we are we're making it as sounded as we can.

Certainly it's not necessary to rewrite the whole file at the time, actually it's just fine to write in a good way just the required part, but it would be so much better if meanwhile you're applying your effort to the main problem to improve as much relative code as your effort big enough, this would really help to all successor folks who will use this lib afterwards, and you'll get a significant part of that appreciation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is very dangerous to change all this code, because i do not have enough time to understand all logic, i will change this method

Copy link
Collaborator

@pharms-eth pharms-eth left a comment

Choose a reason for hiding this comment

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

please use proper Swift syntax, ie no force unwraps, init syntax and trailing clusures

- pathAppendix declaration place changed
- small refactoring
@pharms-eth pharms-eth self-requested a review June 30, 2023 18:33
JeneaVranceanu
JeneaVranceanu previously approved these changes Jul 1, 2023
Copy link
Collaborator

@JeneaVranceanu JeneaVranceanu left a comment

Choose a reason for hiding this comment

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

LGTM! 👍🏻

@yaroslavyaroslav yaroslavyaroslav merged commit 4833b1c into web3swift-team:develop Jul 19, 2023
2 checks passed
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.

4 participants