2020-10-28 17:35:56 +00:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Secured-Finance/dione/node"
|
2020-10-31 03:48:15 +00:00
|
|
|
"github.com/jmoiron/sqlx"
|
2020-11-12 14:18:30 +00:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2020-10-28 17:35:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Store struct {
|
2020-10-31 03:48:15 +00:00
|
|
|
db *sqlx.DB
|
|
|
|
node *node.Node
|
|
|
|
genesisTs uint64
|
|
|
|
StakeStorage DioneStakeInfo
|
2020-10-28 17:35:56 +00:00
|
|
|
// genesisTask *types.DioneTask
|
|
|
|
}
|
|
|
|
|
2020-10-31 03:48:15 +00:00
|
|
|
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()
|
|
|
|
|
2020-10-28 17:35:56 +00:00
|
|
|
return &Store{
|
|
|
|
db: db,
|
|
|
|
node: node,
|
|
|
|
genesisTs: genesisTs,
|
2020-10-31 03:48:15 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDB(databaseURL string) (*sqlx.DB, error) {
|
2020-11-12 14:18:30 +00:00
|
|
|
db, err := sqlx.Connect("sqlite3", databaseURL)
|
2020-10-31 03:48:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := db.Ping(); err != nil {
|
|
|
|
return nil, err
|
2020-10-28 17:35:56 +00:00
|
|
|
}
|
2020-10-31 03:48:15 +00:00
|
|
|
|
|
|
|
return db, nil
|
2020-10-28 17:35:56 +00:00
|
|
|
}
|
2020-10-30 05:23:08 +00:00
|
|
|
|
2020-10-31 03:48:15 +00:00
|
|
|
// TODO: Discuss with ChronosX88 about using custom database to decrease I/O bound
|
|
|
|
// specify the migrations for stake storage;
|