Move some funcs for better file organization.
This commit is contained in:
parent
ce23523ed7
commit
ae4bf50f7a
2 changed files with 34 additions and 32 deletions
32
account.go
32
account.go
|
@ -26,7 +26,6 @@ import (
|
||||||
"github.com/conformal/btcwallet/wallet"
|
"github.com/conformal/btcwallet/wallet"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"github.com/conformal/btcws"
|
"github.com/conformal/btcws"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -722,34 +721,3 @@ func accountdir(name string, cfg *config) string {
|
||||||
|
|
||||||
return filepath.Join(cfg.DataDir, adir)
|
return filepath.Join(cfg.DataDir, adir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func networkDir(net btcwire.BitcoinNet) string {
|
|
||||||
var netname string
|
|
||||||
if net == btcwire.MainNet {
|
|
||||||
netname = "mainnet"
|
|
||||||
} else {
|
|
||||||
netname = "testnet"
|
|
||||||
}
|
|
||||||
return filepath.Join(cfg.DataDir, netname)
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkCreateDir checks that the path exists and is a directory.
|
|
||||||
// If path does not exist, it is created.
|
|
||||||
func checkCreateDir(path string) error {
|
|
||||||
if fi, err := os.Stat(path); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
// Attempt data directory creation
|
|
||||||
if err = os.MkdirAll(path, 0700); err != nil {
|
|
||||||
return fmt.Errorf("cannot create network directory: %s", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("error checking network directory: %s", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !fi.IsDir() {
|
|
||||||
return fmt.Errorf("path '%s' is not a directory", path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
34
disksync.go
34
disksync.go
|
@ -18,6 +18,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/conformal/btcwire"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -34,6 +35,39 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// networkDir returns the base directory name for the bitcoin network
|
||||||
|
// net.
|
||||||
|
func networkDir(net btcwire.BitcoinNet) string {
|
||||||
|
var netname string
|
||||||
|
if net == btcwire.MainNet {
|
||||||
|
netname = "mainnet"
|
||||||
|
} else {
|
||||||
|
netname = "testnet"
|
||||||
|
}
|
||||||
|
return filepath.Join(cfg.DataDir, netname)
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkCreateDir checks that the path exists and is a directory.
|
||||||
|
// If path does not exist, it is created.
|
||||||
|
func checkCreateDir(path string) error {
|
||||||
|
if fi, err := os.Stat(path); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
// Attempt data directory creation
|
||||||
|
if err = os.MkdirAll(path, 0700); err != nil {
|
||||||
|
return fmt.Errorf("cannot create directory: %s", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("error checking directory: %s", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !fi.IsDir() {
|
||||||
|
return fmt.Errorf("path '%s' is not a directory", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// accountFilename returns the filepath of an account file given the
|
// accountFilename returns the filepath of an account file given the
|
||||||
// filename suffix ("wallet.bin", "tx.bin", or "utxo.bin"), account
|
// filename suffix ("wallet.bin", "tx.bin", or "utxo.bin"), account
|
||||||
// name and the network directory holding the file.
|
// name and the network directory holding the file.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue