Skip to content

Commit

Permalink
Refactor events
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Oct 22, 2018
1 parent a995749 commit ad78da8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
8 changes: 1 addition & 7 deletions api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package api
import (
"encoding/json"
"fmt"
"github.com/MinterTeam/minter-go-node/cmd/utils"
"github.com/MinterTeam/minter-go-node/core/rewards"
"github.com/MinterTeam/minter-go-node/core/transaction"
"github.com/MinterTeam/minter-go-node/core/types"
"github.com/MinterTeam/minter-go-node/eventsdb"
"github.com/gorilla/mux"
"github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/db"
"math/big"
"net/http"
"strconv"
Expand All @@ -20,11 +18,7 @@ import (
var edb *eventsdb.EventsDB

func init() {
eventsDB, err := db.NewGoLevelDB("events", utils.GetMinterHome()+"/data")
if err != nil {
panic(err)
}
edb = eventsdb.NewEventsDB(eventsDB)
edb = eventsdb.NewEventsDB(eventsdb.GetCurrentDB())
}

type BlockResponse struct {
Expand Down
25 changes: 18 additions & 7 deletions eventsdb/eventsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,31 @@ var cdc = amino.NewCodec()
var eventsEnabled = !config.GetConfig().ValidatorMode

var edb *EventsDB
var godb *db.GoLevelDB

func init() {
RegisterAminoEvents(cdc)
}

func GetCurrent() *EventsDB {
if edb == nil {
eventsDB, err := db.NewGoLevelDB("events", utils.GetMinterHome()+"/data")
func GetCurrentDB() *db.GoLevelDB {
if godb != nil {
return godb
}

gdb, err := db.NewGoLevelDB("events", utils.GetMinterHome()+"/data")

if err != nil {
panic(err)
}

godb = gdb

if err != nil {
panic(err)
}
return gdb
}

edb = NewEventsDB(eventsDB)
func GetCurrent() *EventsDB {
if edb == nil {
edb = NewEventsDB(GetCurrentDB())
}

return edb
Expand Down

0 comments on commit ad78da8

Please sign in to comment.