forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to query enabled modules
See PR forbole#35
- Loading branch information
1 parent
ae638d6
commit e583515
Showing
24 changed files
with
686 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package types | ||
|
||
// ModuleRow represents a single row inside the modules table | ||
type ModuleRow struct { | ||
Module string `db:"module_name"` | ||
} | ||
|
||
//NewModuleRow return a new instance of ModuleRow | ||
func NewModuleRow(name string) ModuleRow { | ||
return ModuleRow{Module: name} | ||
} | ||
|
||
// Equal return true if two moduleRow is equal | ||
func (v ModuleRow) Equal(w ModuleRow) bool { | ||
return v.Module == w.Module | ||
} | ||
|
||
// ModuleRows represent an array of ModulerRow | ||
type ModuleRows []*ModuleRow | ||
|
||
//NewModuleRows return a new instance of ModuleRows | ||
func NewModuleRows(names []string) ModuleRows { | ||
rows := make([]*ModuleRow, 0) | ||
for _, name := range names { | ||
rows = append(rows, &ModuleRow{Module: name}) | ||
} | ||
return rows | ||
} | ||
|
||
// Equal return true if two ModulesRow is equal | ||
func (v ModuleRows) Equal(w *ModuleRows) bool { | ||
if w == nil { | ||
return false | ||
} | ||
|
||
if len(v) != len(*w) { | ||
return false | ||
} | ||
|
||
for index, val := range v { | ||
if !val.Equal(*(*w)[index]) { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
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,29 @@ | ||
package database | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// UpdateEnableModules allows to save enabled module into the database | ||
func (db BigDipperDb) InsertEnableModules(modules []string) error { | ||
//clear table first | ||
stmt := "DELETE FROM modules" | ||
_, err := db.Sql.Exec(stmt) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var values []interface{} | ||
stmt = `INSERT INTO modules (module_name) VALUES` | ||
for key, value := range modules { | ||
stmt += fmt.Sprintf("($%d),", key+1) | ||
values = append(values, value) | ||
} | ||
stmt = stmt[:len(stmt)-1] //remove tailing "," | ||
stmt += " ON CONFLICT DO NOTHING" | ||
_, err = db.Sql.Exec(stmt, values...) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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,19 @@ | ||
package database_test | ||
|
||
import ( | ||
"github.com/forbole/bdjuno/database/types" | ||
) | ||
|
||
func (suite *DbTestSuite) TestBigDipperDb_InsertEnableModules() { | ||
modules := []string{"auth", "bank", "consensus", "distribution", "gov", "mint", "pricefeed", "staking", "supply"} | ||
err := suite.database.InsertEnableModules(modules) | ||
suite.Require().NoError(err) | ||
|
||
var results types.ModuleRows | ||
err = suite.database.Sqlx.Select(&results, "SELECT * FROM modules") | ||
suite.Require().NoError(err) | ||
|
||
expected := types.NewModuleRows(modules) | ||
suite.Require().True(results.Equal(&expected)) | ||
|
||
} |
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,3 @@ | ||
CREATE TABLE modules( | ||
module_name TEXT | ||
); |
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,45 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/desmos-labs/juno/parse" | ||
juno "github.com/desmos-labs/juno/parse/worker" | ||
x "github.com/forbole/bdjuno/x/types" | ||
) | ||
|
||
// Module represent /x/Auth module | ||
type Module struct{} | ||
|
||
// Name return the name of the module | ||
func (m Module) Name() string { | ||
return "auth" | ||
} | ||
|
||
// BlockHandlers return a list of block handler of the module | ||
func (m Module) BlockHandlers() []juno.BlockHandler { | ||
return []juno.BlockHandler{} | ||
} | ||
|
||
// TxHandlers return a list of TxHandlers of the module | ||
func (m Module) TxHandlers() []juno.TxHandler { | ||
return []juno.TxHandler{} | ||
} | ||
|
||
// MsgHandlers return a list of MsgHandlers of the module | ||
func (m Module) MsgHandlers() []juno.MsgHandler { | ||
return []juno.MsgHandler{} | ||
} | ||
|
||
// AdditionalOperations return a list of AdditionalOperations of the module | ||
func (m Module) AdditionalOperations() []parse.AdditionalOperation { | ||
return []parse.AdditionalOperation{} | ||
} | ||
|
||
// PeriodicOperations return a list of PeriodicOperations of the module | ||
func (m Module) PeriodicOperations() []x.PerodicOperation { | ||
return []x.PerodicOperation{PeriodicAuthOperations} | ||
} | ||
|
||
// GenesisHandlers return a list of GenesisHandlers of the module | ||
func (m Module) GenesisHandlers() []juno.GenesisHandler { | ||
return []juno.GenesisHandler{GenesisHandler} | ||
} |
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,45 @@ | ||
package bank | ||
|
||
import ( | ||
"github.com/desmos-labs/juno/parse" | ||
juno "github.com/desmos-labs/juno/parse/worker" | ||
x "github.com/forbole/bdjuno/x/types" | ||
) | ||
|
||
// Module represent /x/Bank module | ||
type Module struct{} | ||
|
||
// Name return the name of the module | ||
func (m Module) Name() string { | ||
return "bank" | ||
} | ||
|
||
// BlockHandlers return a list of block handler of the module | ||
func (m Module) BlockHandlers() []juno.BlockHandler { | ||
return []juno.BlockHandler{} | ||
} | ||
|
||
// TxHandlers return a list of TxHandlers of the module | ||
func (m Module) TxHandlers() []juno.TxHandler { | ||
return []juno.TxHandler{} | ||
} | ||
|
||
// MsgHandlers return a list of MsgHandlers of the module | ||
func (m Module) MsgHandlers() []juno.MsgHandler { | ||
return []juno.MsgHandler{MsgHandler} | ||
} | ||
|
||
// AdditionalOperations return a list of AdditionalOperations of the module | ||
func (m Module) AdditionalOperations() []parse.AdditionalOperation { | ||
return []parse.AdditionalOperation{} | ||
} | ||
|
||
// PeriodicOperations return a list of PeriodicOperations of the module | ||
func (m Module) PeriodicOperations() []x.PerodicOperation { | ||
return []x.PerodicOperation{} | ||
} | ||
|
||
// GenesisHandlers return a list of GenesisHandlers of the module | ||
func (m Module) GenesisHandlers() []juno.GenesisHandler { | ||
return []juno.GenesisHandler{} | ||
} |
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,45 @@ | ||
package consensus | ||
|
||
import ( | ||
"github.com/desmos-labs/juno/parse" | ||
juno "github.com/desmos-labs/juno/parse/worker" | ||
x "github.com/forbole/bdjuno/x/types" | ||
) | ||
|
||
// Module represent /x/Consensus module | ||
type Module struct{} | ||
|
||
// Name return the name of the module | ||
func (m Module) Name() string { | ||
return "consensus" | ||
} | ||
|
||
// BlockHandlers return a list of block handler of the module | ||
func (m Module) BlockHandlers() []juno.BlockHandler { | ||
return []juno.BlockHandler{} | ||
} | ||
|
||
// TxHandlers return a list of TxHandlers of the module | ||
func (m Module) TxHandlers() []juno.TxHandler { | ||
return []juno.TxHandler{} | ||
} | ||
|
||
// MsgHandlers return a list of MsgHandlers of the module | ||
func (m Module) MsgHandlers() []juno.MsgHandler { | ||
return []juno.MsgHandler{} | ||
} | ||
|
||
// AdditionalOperations return a list of AdditionalOperations of the module | ||
func (m Module) AdditionalOperations() []parse.AdditionalOperation { | ||
return []parse.AdditionalOperation{ListenOperation} | ||
} | ||
|
||
// PeriodicOperations return a list of PeriodicOperations of the module | ||
func (m Module) PeriodicOperations() []x.PerodicOperation { | ||
return []x.PerodicOperation{} | ||
} | ||
|
||
// GenesisHandlers return a list of GenesisHandlers of the module | ||
func (m Module) GenesisHandlers() []juno.GenesisHandler { | ||
return []juno.GenesisHandler{} | ||
} |
Oops, something went wrong.