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

LedgerCosmos.GetBip32bytes has pedantic variables and non-idiomatic usages, unnecessary if err != nil, yet could just plainly invoke early returns #52

Open
odeke-em opened this issue Oct 16, 2023 · 1 comment
Assignees

Comments

@odeke-em
Copy link
Contributor

This code has what looks like C-style coding styles and is quite pedantic to declare the byteslice and the error, then switch between the various callers whose return signatures are ([]byte, error) instead of an immediate return

func (ledger *LedgerCosmos) GetBip32bytes(bip32Path []uint32, hardenCount int) ([]byte, error) {
var pathBytes []byte
var err error
switch ledger.version.Major {
case 1:
pathBytes, err = GetBip32bytesv1(bip32Path, 3)
if err != nil {
return nil, err
}
case 2:
pathBytes, err = GetBip32bytesv2(bip32Path, 3)
if err != nil {
return nil, err
}
default:
return nil, errors.New("App version is not supported")
}
return pathBytes, nil
}

Suggested fix

func (ledger *LedgerCosmos) GetBip32bytes(bip32Path []uint32, hardenCount int) ([]byte, error) { 
 	switch major := ledger.version.Major; major { 
 	case 1: 
 		return GetBip32bytesv1(bip32Path, 3) 
 	case 2: 
 		return GetBip32bytesv2(bip32Path, 3) 
 	default: 
 		return nil, fmt.Errorf("Ledger version: %d is not supported", major) 
 	} 
 } 

/cc @elias-orijtech @julienrbrt

@jleni
Copy link
Member

jleni commented Sep 2, 2024

Cosmos app v1 support will be dropped, so most of this code can be completely removed

@jleni jleni self-assigned this Sep 2, 2024
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

No branches or pull requests

2 participants