forked from cerc-io/plugeth
Rewrote mnemonic word loading to facilitate deployable builds.
This commit is contained in:
parent
5ec62a5153
commit
9a93169898
@ -6,30 +6,35 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitWords() []string {
|
func InitWords(wordsPath string) {
|
||||||
_, thisfile, _, _ := runtime.Caller(1)
|
filename := path.Join(wordsPath, "mnemonic.words.lst")
|
||||||
filename := path.Join(path.Dir(thisfile), "mnemonic.words.lst")
|
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||||
fmt.Printf("reading mnemonic word list file 'mnemonic.words.lst' from source folder failed, looking in current folder.")
|
fmt.Printf("reading mnemonic word list file from supplied path not found. Looked in %s. Trying next option.\n", filename)
|
||||||
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
|
||||||
if err != nil {
|
dir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "eth-go", "ethcrypto")
|
||||||
panic(fmt.Errorf("problem getting current folder: ", err))
|
|
||||||
}
|
|
||||||
filename = path.Join(dir, "mnemonic.words.lst")
|
filename = path.Join(dir, "mnemonic.words.lst")
|
||||||
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||||
|
fmt.Printf("reading mnemonic word list file 'mnemonic.words.lst' from source folder failed: %s.\n", filename)
|
||||||
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("problem getting current folder: ", err))
|
||||||
|
}
|
||||||
|
filename = path.Join(dir, "mnemonic.words.lst")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(filename)
|
content, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("reading mnemonic word list file 'mnemonic.words.lst' failed: ", err))
|
panic(fmt.Errorf("All options for finding the mnemonic word list file 'mnemonic.words.lst' failed: ", err))
|
||||||
}
|
}
|
||||||
return strings.Split(string(content), "\n")
|
words = strings.Split(string(content), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
var words = InitWords()
|
var words []string
|
||||||
|
|
||||||
// TODO: See if we can refactor this into a shared util lib if we need it multiple times
|
// TODO: See if we can refactor this into a shared util lib if we need it multiple times
|
||||||
func IndexOf(slice []string, value string) int64 {
|
func IndexOf(slice []string, value string) int64 {
|
||||||
|
Loading…
Reference in New Issue
Block a user