Skip to content

Commit

Permalink
feat: add default world for easier access (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchon committed Jul 20, 2023
1 parent b050d94 commit aba3e34
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions x/indexer/data/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type Database struct {
ChainID string
UnconfirmedTransactions []UnconfirmedTransaction
txSentMutex *sync.Mutex

defaultWorld string
}

func NewDatabase() *Database {
Expand All @@ -93,6 +95,8 @@ func NewDatabase() *Database {
// TODO: use a list instead of array
UnconfirmedTransactions: []UnconfirmedTransaction{},
txSentMutex: &sync.Mutex{},
// Helper for games
defaultWorld: "",
}
}

Expand All @@ -118,6 +122,17 @@ func (db *Database) AddEvent(tableName string, key string, fields *[]Field) {
db.LastUpdate = time.Now()
}

func (db *Database) SetDefaultWorld(worldID string) {
db.defaultWorld = worldID
}

func (db *Database) GetDefaultWorld() *World {
if db.defaultWorld == "" {
return nil
}
return db.GetWorld(db.defaultWorld)
}

func (db *Database) GetWorld(worldID string) *World {
if world, ok := db.Worlds[worldID]; ok {
return world
Expand Down

0 comments on commit aba3e34

Please sign in to comment.