dione/store/store.go

46 lines
855 B
Go
Raw Normal View History

package store
import (
"github.com/Secured-Finance/dione/node"
"github.com/jmoiron/sqlx"
)
type Store struct {
db *sqlx.DB
node *node.Node
genesisTs uint64
StakeStorage DioneStakeInfo
// genesisTask *types.DioneTask
}
func NewStore(node *node.Node, genesisTs uint64) (*Store, error) {
db, err := newDB(node.Config.Store.DatabaseURL)
if err != nil {
return nil, err
}
defer db.Close()
return &Store{
db: db,
node: node,
genesisTs: genesisTs,
}, nil
}
func newDB(databaseURL string) (*sqlx.DB, error) {
db, err := sqlx.Connect("postgres", databaseURL)
if err != nil {
return nil, err
}
if err := db.Ping(); err != nil {
return nil, err
}
return db, nil
}
// TODO: Discuss with ChronosX88 about using custom database to decrease I/O bound
// specify the migrations for stake storage;