Cleanup ledger godocs and reduce complexity

This commit is contained in:
Aleksandr Bezobchuk 2018-08-28 08:16:50 -04:00
parent de061fa8e1
commit 1a6c4785e9
2 changed files with 10 additions and 14 deletions

View File

@ -6,9 +6,9 @@ import (
ledger "github.com/zondax/ledger-goclient"
)
// If ledger support (build tag) has been enabled, set the discoverLedger
// function which is responsible for loading the Ledger device at runtime or
// returning an error.
// If ledger support (build tag) has been enabled, which implies a CGO dependency,
// set the discoverLedger function which is responsible for loading the Ledger
// device at runtime or returning an error.
func init() {
discoverLedger = func() (LedgerSECP256K1, error) {
device, err := ledger.FindLedger()

View File

@ -49,20 +49,16 @@ type (
// CONTRACT: The ledger device, ledgerDevice, must be loaded and set prior to
// any creation of a PrivKeyLedgerSecp256k1.
func NewPrivKeyLedgerSecp256k1(path DerivationPath) (tmcrypto.PrivKey, error) {
var ledgerDevice LedgerSECP256K1
if discoverLedger != nil {
device, err := discoverLedger()
if err != nil {
return nil, errors.Wrap(err, "failed to create PrivKeyLedgerSecp256k1")
}
ledgerDevice = device
} else {
if discoverLedger == nil {
return nil, errors.New("no Ledger discovery function defined")
}
pkl := &PrivKeyLedgerSecp256k1{Path: path, ledger: ledgerDevice}
device, err := discoverLedger()
if err != nil {
return nil, errors.Wrap(err, "failed to create PrivKeyLedgerSecp256k1")
}
pkl := &PrivKeyLedgerSecp256k1{Path: path, ledger: device}
pubKey, err := pkl.getPubKey()
if err != nil {