Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use full path to seed file #240

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions internal/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package wallet
import (
"errors"
"os"
"path"

"github.com/blinklabs-io/bluefin/internal/config"
"github.com/blinklabs-io/bluefin/internal/logging"
Expand All @@ -34,9 +35,17 @@ func Setup() {
// TODO: check storage for mnemonic
mnemonic := cfg.Wallet.Mnemonic
if mnemonic == "" {
pwd, err := os.Getwd()
if err != nil {
panic(err.Error())
}
seedPath := path.Join(
pwd,
"seed.txt",
)
// Read seed.txt if it exists
if data, err := os.ReadFile("seed.txt"); err == nil {
logger.Infof("read mnemonic from seed.txt")
if data, err := os.ReadFile(seedPath); err == nil {
logger.Infof("read mnemonic from %s", seedPath)
mnemonic = string(data)
} else if errors.Is(err, os.ErrNotExist) {
mnemonic, err = bursa.NewMnemonic()
Expand All @@ -45,7 +54,7 @@ func Setup() {
}
// Write seed.txt
// WARNING: this will clobber existing files
f, err := os.Create("seed.txt")
f, err := os.Create(seedPath)
if err != nil {
panic(err)
}
Expand All @@ -59,7 +68,7 @@ func Setup() {
if err != nil {
panic(err)
}
logger.Infof("wrote generated mnemonic to seed.txt")
logger.Infof("wrote generated mnemonic to %s", seedPath)
// TODO: write mnemonic to storage
} else {
panic(err)
Expand Down