Skip to content

Commit

Permalink
database: Remove log param from CreateNew.
Browse files Browse the repository at this point in the history
This logger did not write any useful information and all errors
generated by the func are already returned to the caller for logging.
  • Loading branch information
jholdstock committed May 23, 2024
1 parent 17f993a commit 64ad28e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
4 changes: 3 additions & 1 deletion cmd/vspd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,14 @@ func loadConfig() (*vspdConfig, error) {
}

// Create new database.
err = database.CreateNew(cfg.dbPath, cfg.FeeXPub, cfg.logger(" DB"))
fmt.Printf("Initializing new database at %s\n", cfg.dbPath)
err = database.CreateNew(cfg.dbPath, cfg.FeeXPub)
if err != nil {
return nil, fmt.Errorf("error creating db file %s: %w", cfg.dbPath, err)
}

// Exit with success
fmt.Printf("Database initialized\n")
os.Exit(0)
}

Expand Down
9 changes: 1 addition & 8 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ func (vdb *VspDatabase) WriteHotBackupFile() error {
// - the provided extended pubkey (to be used for deriving fee addresses).
// - an ed25519 keypair to sign API responses.
// - a secret key to use for initializing a HTTP cookie store.
func CreateNew(dbFile, feeXPub string, log slog.Logger) error {
log.Infof("Initializing new database at %s", dbFile)
func CreateNew(dbFile, feeXPub string) error {

db, err := bolt.Open(dbFile, 0600, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
Expand All @@ -115,8 +114,6 @@ func CreateNew(dbFile, feeXPub string, log slog.Logger) error {
return err
}

log.Info("Generating ed25519 signing key")

// Generate ed25519 key
_, signKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
Expand All @@ -128,7 +125,6 @@ func CreateNew(dbFile, feeXPub string, log slog.Logger) error {
}

// Generate a secret key for initializing the cookie store.
log.Info("Generating cookie secret")
secret := make([]byte, 32)
_, err = rand.Read(secret)
if err != nil {
Expand All @@ -139,7 +135,6 @@ func CreateNew(dbFile, feeXPub string, log slog.Logger) error {
return err
}

log.Info("Storing extended public key")
// Store fee xpub
err = vspBkt.Put(feeXPubK, []byte(feeXPub))
if err != nil {
Expand All @@ -165,8 +160,6 @@ func CreateNew(dbFile, feeXPub string, log slog.Logger) error {
return err
}

log.Info("Database initialized")

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestDatabase(t *testing.T) {
for testName, test := range tests {

// Create a new blank database for each sub-test.
err := CreateNew(testDb, feeXPub, log)
err := CreateNew(testDb, feeXPub)
if err != nil {
t.Fatalf("error creating test database: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/webapi/setaltsignaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestMain(m *testing.M) {
os.Remove(testDb)

// Create a new blank database for all tests.
err := database.CreateNew(testDb, feeXPub, log)
err := database.CreateNew(testDb, feeXPub)
if err != nil {
panic(fmt.Errorf("error creating test database: %w", err))
}
Expand Down

0 comments on commit 64ad28e

Please sign in to comment.