forked from cerc-io/laconicd-deprecated
Transaction signing and encoding (#95)
* WIP setting up evm tx command and updating emint keys output * Fix linting issue * Wip restructuring to allow for ethereum signing and encoding * WIP setting up keybase and context to use Ethermint keys * Fixed encoding and decoding of emint keys * Adds command for generating explicit ethereum tx * Fixed evm route for handling tx * Fixed tx and msg encoding which allows transactions to be sent * Added relevant documentation for changes and cleaned up code * Added documentation and indicators why code was overriden
This commit is contained in:
+1
-1
@@ -90,7 +90,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
|
||||
interactive := viper.GetBool(flagInteractive)
|
||||
showMnemonic := !viper.GetBool(flagNoBackup)
|
||||
|
||||
kb, err = clientkeys.NewKeyBaseFromHomeFlag()
|
||||
kb, err = NewKeyBaseFromHomeFlag()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+1
-2
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
)
|
||||
|
||||
@@ -32,7 +31,7 @@ func TestRunShowCmd(t *testing.T) {
|
||||
|
||||
fakeKeyName1 := "runShowCmd_Key1"
|
||||
fakeKeyName2 := "runShowCmd_Key2"
|
||||
kb, err := clientkeys.NewKeyBaseFromHomeFlag()
|
||||
kb, err := NewKeyBaseFromHomeFlag()
|
||||
assert.NoError(t, err)
|
||||
_, err = kb.CreateAccount(fakeKeyName1, tests.TestMnemonic, "", "", 0, 0)
|
||||
assert.NoError(t, err)
|
||||
|
||||
+51
-5
@@ -2,28 +2,33 @@ package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
cosmosKeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
emintKeys "github.com/cosmos/ethermint/crypto/keys"
|
||||
)
|
||||
|
||||
// available output formats.
|
||||
const (
|
||||
OutputFormatText = "text"
|
||||
OutputFormatJSON = "json"
|
||||
|
||||
defaultKeyDBName = "emintkeys"
|
||||
)
|
||||
|
||||
type bechKeyOutFn func(keyInfo cosmosKeys.Info) (cosmosKeys.KeyOutput, error)
|
||||
type bechKeyOutFn func(keyInfo cosmosKeys.Info) (emintKeys.KeyOutput, error)
|
||||
|
||||
// GetKeyInfo returns key info for a given name. An error is returned if the
|
||||
// keybase cannot be retrieved or getting the info fails.
|
||||
func GetKeyInfo(name string) (cosmosKeys.Info, error) {
|
||||
keybase, err := clientkeys.NewKeyBaseFromHomeFlag()
|
||||
keybase, err := NewKeyBaseFromHomeFlag()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -31,6 +36,47 @@ func GetKeyInfo(name string) (cosmosKeys.Info, error) {
|
||||
return keybase.Get(name)
|
||||
}
|
||||
|
||||
// NewKeyBaseFromHomeFlag initializes a Keybase based on the configuration.
|
||||
func NewKeyBaseFromHomeFlag() (cosmosKeys.Keybase, error) {
|
||||
rootDir := viper.GetString(flags.FlagHome)
|
||||
return NewKeyBaseFromDir(rootDir)
|
||||
}
|
||||
|
||||
// NewKeyBaseFromDir initializes a keybase at a particular dir.
|
||||
func NewKeyBaseFromDir(rootDir string) (cosmosKeys.Keybase, error) {
|
||||
return getLazyKeyBaseFromDir(rootDir)
|
||||
}
|
||||
|
||||
// NewInMemoryKeyBase returns a storage-less keybase.
|
||||
func NewInMemoryKeyBase() cosmosKeys.Keybase { return emintKeys.NewInMemory() }
|
||||
|
||||
func getLazyKeyBaseFromDir(rootDir string) (cosmosKeys.Keybase, error) {
|
||||
return emintKeys.New(defaultKeyDBName, filepath.Join(rootDir, defaultKeyDBName)), nil
|
||||
}
|
||||
|
||||
// GetPassphrase returns a passphrase for a given name. It will first retrieve
|
||||
// the key info for that name if the type is local, it'll fetch input from
|
||||
// STDIN. Otherwise, an empty passphrase is returned. An error is returned if
|
||||
// the key info cannot be fetched or reading from STDIN fails.
|
||||
func GetPassphrase(name string) (string, error) {
|
||||
var passphrase string
|
||||
|
||||
keyInfo, err := GetKeyInfo(name)
|
||||
if err != nil {
|
||||
return passphrase, err
|
||||
}
|
||||
|
||||
// we only need a passphrase for locally stored keys
|
||||
if keyInfo.GetType().String() == emintKeys.TypeLocal.String() {
|
||||
passphrase, err = clientkeys.ReadPassphraseFromStdin(name)
|
||||
if err != nil {
|
||||
return passphrase, err
|
||||
}
|
||||
}
|
||||
|
||||
return passphrase, nil
|
||||
}
|
||||
|
||||
func printKeyInfo(keyInfo cosmosKeys.Info, bechKeyOut bechKeyOutFn) {
|
||||
ko, err := bechKeyOut(keyInfo)
|
||||
if err != nil {
|
||||
@@ -39,7 +85,7 @@ func printKeyInfo(keyInfo cosmosKeys.Info, bechKeyOut bechKeyOutFn) {
|
||||
|
||||
switch viper.Get(cli.OutputFlag) {
|
||||
case OutputFormatText:
|
||||
printTextInfos([]cosmosKeys.KeyOutput{ko})
|
||||
printTextInfos([]emintKeys.KeyOutput{ko})
|
||||
|
||||
case OutputFormatJSON:
|
||||
var out []byte
|
||||
@@ -84,7 +130,7 @@ func printKeyInfo(keyInfo cosmosKeys.Info, bechKeyOut bechKeyOutFn) {
|
||||
// }
|
||||
// }
|
||||
|
||||
func printTextInfos(kos []cosmosKeys.KeyOutput) {
|
||||
func printTextInfos(kos []emintKeys.KeyOutput) {
|
||||
out, err := yaml.Marshal(&kos)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user