Do not fail if default wallet does not exist.
We must instead wait for the user to explicitly generate their own wallet for an account name. This is because all btcwallet wallets must be encrypted, and the passphrase must be known at time of wallet generation.
This commit is contained in:
parent
1c1ab52ef7
commit
1918bd3698
2 changed files with 17 additions and 8 deletions
21
cmd.go
21
cmd.go
|
@ -17,6 +17,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/conformal/btcwallet/tx"
|
||||
"github.com/conformal/btcwallet/wallet"
|
||||
|
@ -27,6 +28,10 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoWallet = errors.New("Wallet file does not exist.")
|
||||
)
|
||||
|
||||
var (
|
||||
log seelog.LoggerInterface = seelog.Default
|
||||
cfg *config
|
||||
|
@ -59,11 +64,14 @@ func main() {
|
|||
*/
|
||||
|
||||
// Open wallet
|
||||
btcw, err := OpenOrCreateWallet(cfg, "")
|
||||
btcw, err := OpenWallet(cfg, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Info(err.Error())
|
||||
} else {
|
||||
wallets.Lock()
|
||||
wallets.m[""] = btcw
|
||||
wallets.Unlock()
|
||||
}
|
||||
_ = btcw
|
||||
|
||||
// Start HTTP server to listen and send messages to frontend and btcd
|
||||
// backend. Try reconnection if connection failed.
|
||||
|
@ -98,7 +106,7 @@ func walletdir(cfg *config, account string) string {
|
|||
return filepath.Join(cfg.DataDir, wname)
|
||||
}
|
||||
|
||||
func OpenOrCreateWallet(cfg *config, account string) (*BtcWallet, error) {
|
||||
func OpenWallet(cfg *config, account string) (*BtcWallet, error) {
|
||||
wdir := walletdir(cfg, account)
|
||||
fi, err := os.Stat(wdir)
|
||||
if err != nil {
|
||||
|
@ -122,9 +130,8 @@ func OpenOrCreateWallet(cfg *config, account string) (*BtcWallet, error) {
|
|||
var wfile, txfile, utxofile *os.File
|
||||
if wfile, err = os.Open(wfilepath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if wfile, err = os.Create(wfilepath); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Must create and save wallet first.
|
||||
return nil, ErrNoWallet
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -255,7 +255,9 @@ func GetNewAddress(reply chan []byte, msg []byte) {
|
|||
addr := w.NextUnusedAddress()
|
||||
ReplySuccess(reply, v["id"], addr)
|
||||
} else {
|
||||
ReplyError(reply, v["id"], &WalletInvalidAccountName)
|
||||
e := WalletInvalidAccountName
|
||||
e.Message = fmt.Sprintf("Wallet for account '%s' does not exist.", wname)
|
||||
ReplyError(reply, v["id"], &e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue