Fix wallet file name

This commit is contained in:
Ivan Kuznetsov 2017-10-01 10:53:26 +07:00
parent 4acc3ae271
commit 130cf66a90
2 changed files with 6 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import "fmt"
func (cli *CLI) createWallet(nodeID string) { func (cli *CLI) createWallet(nodeID string) {
wallets, _ := NewWallets(nodeID) wallets, _ := NewWallets(nodeID)
address := wallets.CreateWallet() address := wallets.CreateWallet()
wallets.SaveToFile() wallets.SaveToFile(nodeID)
fmt.Printf("Your new address: %s\n", address) fmt.Printf("Your new address: %s\n", address)
} }

View File

@ -22,7 +22,7 @@ func NewWallets(nodeID string) (*Wallets, error) {
wallets := Wallets{} wallets := Wallets{}
wallets.Wallets = make(map[string]*Wallet) wallets.Wallets = make(map[string]*Wallet)
err := wallets.LoadFromFile() err := wallets.LoadFromFile(nodeID)
return &wallets, err return &wallets, err
} }
@ -54,7 +54,8 @@ func (ws Wallets) GetWallet(address string) Wallet {
} }
// LoadFromFile loads wallets from the file // LoadFromFile loads wallets from the file
func (ws *Wallets) LoadFromFile() error { func (ws *Wallets) LoadFromFile(nodeID string) error {
walletFile := fmt.Sprintf(walletFile, nodeID)
if _, err := os.Stat(walletFile); os.IsNotExist(err) { if _, err := os.Stat(walletFile); os.IsNotExist(err) {
return err return err
} }
@ -78,8 +79,9 @@ func (ws *Wallets) LoadFromFile() error {
} }
// SaveToFile saves wallets to a file // SaveToFile saves wallets to a file
func (ws Wallets) SaveToFile() { func (ws Wallets) SaveToFile(nodeID string) {
var content bytes.Buffer var content bytes.Buffer
walletFile := fmt.Sprintf(walletFile, nodeID)
gob.Register(elliptic.P256()) gob.Register(elliptic.P256())