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

Integrate coin-type configuration #338

Merged
merged 5 commits into from
Nov 8, 2022
Merged

Integrate coin-type configuration #338

merged 5 commits into from
Nov 8, 2022

Conversation

boojamya
Copy link
Contributor

@boojamya boojamya commented Nov 3, 2022

The PR adds the ability to specify Coin Types when creating or restoring keys for chains.

The coinType is invoked in the chainConfig but defaults to "118" (Cosmos SDK default) if the key:value pair is left blank.

@boojamya boojamya marked this pull request as ready for review November 4, 2022 18:01
@boojamya boojamya requested a review from a team as a code owner November 4, 2022 18:01
@boojamya boojamya requested a review from jtieri November 4, 2022 18:01
@boojamya boojamya self-assigned this Nov 4, 2022
relayer/rly/cosmos_relayer.go Show resolved Hide resolved
interchain.go Outdated
// NOTE: this is hardcoded to the cosmos coin type.
// In the future, we may need to get the coin type from the chain config.
const coinType = types.CoinType
coinTypeU64, err := strconv.ParseUint(config.CoinType, 10, 32)
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable is named coinTypeU64 but you are telling ParseUInt to use 32bits, and then on L451 there's a typecast to uint32. It looks like the coin type is a uint32 so I'd say this parse call is fine but the type cast could be eliminated.

Also the name could be shortened to just coinType for brevity

Copy link
Contributor Author

@boojamya boojamya Nov 4, 2022

Choose a reason for hiding this comment

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

ParseUInt outputs a typed uint64 integer whether you specify 32bits or 64bits.
That hd.CreateHdPath function takes a uint32. This is the reason for the type cast.

Regardless, for readability, I like what you're saying here and can do the type cast directly in the hd.CreateHdPath function (L456) with the renaming suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well TIL! Disregard my comment then 😛

Comment on lines +58 to +60
typ := reflect.TypeOf(c)
f, _ := typ.FieldByName("CoinType")
coinType := f.Tag.Get("default")
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels odd in the sense that I would expect the struct's field to take on the default value if the empty string is passed in. Idk that I've personally used the default tag before so maybe this is the idiomatic way to go about this?

Thoughts? cc @DavidNix @agouin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I thought so too! After testing, if the value is empty, it takes on "0" which is Bitcoin's coin-type.
If there is a better way to go about this, I'm happy to learn.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems very counterintuitive. I'll go ahead and approve, if there is a better way to do this we can always circle back up on it. Good job!

@boojamya boojamya merged commit 097da3a into main Nov 8, 2022
@boojamya boojamya deleted the dan/key-type branch November 8, 2022 00:24
boojamya added a commit that referenced this pull request Nov 8, 2022
* integrate coin-type configuration

* account for cointype 0

* fix types

* add comment

* handle feedback
boojamya added a commit that referenced this pull request Dec 2, 2022
* Integrate coin-type configuration (#338)

* integrate coin-type configuration

* account for cointype 0

* fix types

* add comment

* handle feedback

* remove extra fmt.Sprint
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