Ledger integration (#931)

Merges the keybase and Ledger code from go-crypto (which is no more) into the SDK
Adds support for Ledger into gaiacli
Cherry-picks updated error handling from #1158
This commit is contained in:
Christopher Goes
2018-06-29 02:54:47 +02:00
committed by GitHub
parent ac3adff1e8
commit 59aadf42aa
143 changed files with 2699 additions and 424 deletions
+17 -3
View File
@@ -126,7 +126,7 @@ func (ctx CoreContext) GetFromAddress() (from sdk.Address, err error) {
return nil, errors.Errorf("no key for: %s", name)
}
return info.PubKey.Address(), nil
return info.GetPubKey().Address(), nil
}
// sign and build the transaction from the msg
@@ -187,15 +187,29 @@ func (ctx CoreContext) ensureSignBuild(name string, msgs []sdk.Msg, cdc *wire.Co
return nil, err
}
passphrase, err := ctx.GetPassphraseFromStdin(name)
var txBytes []byte
keybase, err := keys.GetKeyBase()
if err != nil {
return nil, err
}
txBytes, err := ctx.SignAndBuild(name, passphrase, msgs, cdc)
info, err := keybase.Get(name)
if err != nil {
return nil, err
}
var passphrase string
// Only need a passphrase for locally-stored keys
if info.GetType() == "local" {
passphrase, err = ctx.GetPassphraseFromStdin(name)
if err != nil {
return nil, fmt.Errorf("Error fetching passphrase: %v", err)
}
}
txBytes, err = ctx.SignAndBuild(name, passphrase, msgs, cdc)
if err != nil {
return nil, fmt.Errorf("Error signing transaction: %v", err)
}
return txBytes, err
}
+7
View File
@@ -20,6 +20,7 @@ type CoreContext struct {
Client rpcclient.Client
Decoder auth.AccountDecoder
AccountStore string
UseLedger bool
}
// WithChainID - return a copy of the context with an updated chainID
@@ -94,3 +95,9 @@ func (c CoreContext) WithAccountStore(accountStore string) CoreContext {
c.AccountStore = accountStore
return c
}
// WithUseLedger - return a copy of the context with an updated UseLedger
func (c CoreContext) WithUseLedger(useLedger bool) CoreContext {
c.UseLedger = useLedger
return c
}
+1
View File
@@ -40,6 +40,7 @@ func NewCoreContextFromViper() CoreContext {
Client: rpc,
Decoder: nil,
AccountStore: "acc",
UseLedger: viper.GetBool(client.FlagUseLedger),
}
}