Skip to content

Commit

Permalink
refactor: cleanup store
Browse files Browse the repository at this point in the history
  • Loading branch information
stinkymonkeyph committed Jul 29, 2024
1 parent d60df65 commit db13d70
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions blockchain/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ import (
"github.com/stinkymonkeyph/gopher-blocks/constants"
)

func PutIntoDb(bc *Blockchain) error {
func openDb() (*badger.DB, error) {
db, err := badger.Open(badger.DefaultOptions(constants.DB_PATH))

if err != nil {
return nil, err
}

return db, nil
}

func PutIntoDb(bc *Blockchain) error {

db, err := openDb()

if err != nil {
return err
}
Expand All @@ -27,17 +38,13 @@ func PutIntoDb(bc *Blockchain) error {
return err
})

if err != nil {
return err
}

return nil
return err
}

func ReadFromDb() (Blockchain, error) {
var bc Blockchain

db, err := badger.Open(badger.DefaultOptions(constants.DB_PATH))
db, err := openDb()

if err != nil {
return bc, err
Expand All @@ -63,9 +70,5 @@ func ReadFromDb() (Blockchain, error) {
return nil
})

if err != nil {
return bc, err
}

return bc, nil
return bc, err
}

0 comments on commit db13d70

Please sign in to comment.