aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2014-07-15 18:52:44 +0800
committerMaran <maran.hidskes@gmail.com>2014-07-15 18:52:44 +0800
commit9a931698989fb8db2059a3dee1a431ef94beb59e (patch)
tree23c56d30fe32401dcb659cd23a3f78156de3cfe2
parent5ec62a51537dec6cd299dfc0ff1fbd0847338ff8 (diff)
downloadgo-tangerine-9a931698989fb8db2059a3dee1a431ef94beb59e.tar
go-tangerine-9a931698989fb8db2059a3dee1a431ef94beb59e.tar.gz
go-tangerine-9a931698989fb8db2059a3dee1a431ef94beb59e.tar.bz2
go-tangerine-9a931698989fb8db2059a3dee1a431ef94beb59e.tar.lz
go-tangerine-9a931698989fb8db2059a3dee1a431ef94beb59e.tar.xz
go-tangerine-9a931698989fb8db2059a3dee1a431ef94beb59e.tar.zst
go-tangerine-9a931698989fb8db2059a3dee1a431ef94beb59e.zip
Rewrote mnemonic word loading to facilitate deployable builds.
-rw-r--r--ethcrypto/mnemonic.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/ethcrypto/mnemonic.go b/ethcrypto/mnemonic.go
index 725846792..b8df2ad6f 100644
--- a/ethcrypto/mnemonic.go
+++ b/ethcrypto/mnemonic.go
@@ -6,30 +6,35 @@ import (
"os"
"path"
"path/filepath"
- "runtime"
"strconv"
"strings"
)
-func InitWords() []string {
- _, thisfile, _, _ := runtime.Caller(1)
- filename := path.Join(path.Dir(thisfile), "mnemonic.words.lst")
+func InitWords(wordsPath string) {
+ filename := path.Join(wordsPath, "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, looking in current folder.")
- dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
- if err != nil {
- panic(fmt.Errorf("problem getting current folder: ", err))
- }
+ fmt.Printf("reading mnemonic word list file from supplied path not found. Looked in %s. Trying next option.\n", filename)
+
+ dir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "eth-go", "ethcrypto")
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)
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
func IndexOf(slice []string, value string) int64 {