-
Notifications
You must be signed in to change notification settings - Fork 126
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package ibctest | |
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
|
@@ -423,6 +424,7 @@ func (ic *Interchain) configureRelayerKeys(ctx context.Context, rep *testreporte | |
if err := r.RestoreKey(ctx, | ||
rep, | ||
c.Config().ChainID, chainName, | ||
c.Config().CoinType, | ||
ic.relayerWallets[relayerChain{R: r, C: c}].Mnemonic, | ||
); err != nil { | ||
return fmt.Errorf("failed to restore key to relayer %s for chain %s: %w", ic.relayers[r], chainName, err) | ||
|
@@ -442,9 +444,11 @@ type relayerChain struct { | |
// BuildWallet will generate a random key for the key name in the provided keyring. | ||
// Returns the mnemonic and address in the bech32 format of the provided ChainConfig. | ||
func BuildWallet(kr keyring.Keyring, keyName string, config ibc.ChainConfig) ibc.Wallet { | ||
// 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable is named Also the name could be shortened to just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Regardless, for readability, I like what you're saying here and can do the type cast directly in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well TIL! Disregard my comment then 😛 |
||
if err != nil { | ||
panic(fmt.Errorf("invalid coin type: %w", err)) | ||
} | ||
coinType := uint32(coinTypeU64) | ||
|
||
info, mnemonic, err := kr.NewMnemonic( | ||
keyName, | ||
|
@@ -463,9 +467,9 @@ func BuildWallet(kr keyring.Keyring, keyName string, config ibc.ChainConfig) ibc | |
} | ||
|
||
return ibc.Wallet{ | ||
Address: types.MustBech32ifyAddressBytes(config.Bech32Prefix, addr.Bytes()), | ||
|
||
Address: types.MustBech32ifyAddressBytes(config.Bech32Prefix, addr.Bytes()), | ||
Mnemonic: mnemonic, | ||
CoinType: coinType, | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!