-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
497 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package database | ||
|
||
import ( | ||
"github.com/KiraCore/interx/config" | ||
"github.com/sonyarouje/simdb/db" | ||
) | ||
|
||
// Layer2Data is a struct for layer2 details. | ||
type Layer2Data struct { | ||
Id string `json:"id"` | ||
Data string `json:"data"` | ||
} | ||
|
||
// ID is a field for facuet claim struct. | ||
func (c Layer2Data) ID() (jsonField string, value interface{}) { | ||
value = c.Id | ||
jsonField = "id" | ||
return | ||
} | ||
|
||
func LoadLayer2DbDriver() { | ||
DisableStdout() | ||
driver, _ := db.New(config.GetDbCacheDir() + "/layer2") | ||
EnableStdout() | ||
|
||
layer2Db = driver | ||
} | ||
|
||
// GetLayer2State is a function to get layer2 app state stored | ||
func GetLayer2State(id string) (string, error) { | ||
if layer2Db == nil { | ||
panic("cache dir not set") | ||
} | ||
|
||
data := Layer2Data{} | ||
|
||
DisableStdout() | ||
err := layer2Db.Open(Layer2Data{}).Where("id", "=", id).First().AsEntity(&data) | ||
EnableStdout() | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return data.Data, nil | ||
} | ||
|
||
// GetAllLayer2s is a function to get all layer2Times | ||
func GetAllLayer2s() []interface{} { | ||
if layer2Db == nil { | ||
panic("cache dir not set") | ||
} | ||
|
||
DisableStdout() | ||
rawData := layer2Db.Open(Layer2Data{}).RawArray() | ||
EnableStdout() | ||
|
||
return rawData | ||
} | ||
|
||
// SetLayer2State is a function to set layer2 app status | ||
func SetLayer2State(id string, data string) { | ||
if layer2Db == nil { | ||
panic("cache dir not set") | ||
} | ||
|
||
DisableStdout() | ||
err := layer2Db.Open(Layer2Data{}).Insert(Layer2Data{ | ||
Id: id, | ||
Data: data, | ||
}) | ||
EnableStdout() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
var ( | ||
layer2Db *db.Driver | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package layer2 | ||
|
||
import ( | ||
"github.com/gorilla/mux" | ||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime" | ||
) | ||
|
||
// RegisterRequest is a function to register requests. | ||
func RegisterRequest(router *mux.Router, gwCosmosmux *runtime.ServeMux, rpcAddr string) { | ||
RegisterStatusRoutes(router, gwCosmosmux, rpcAddr) | ||
} |
Oops, something went wrong.