-
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.
Merge pull request #5 from xpladev/my/refactor-x
refactor: change to modular design for tx/query routing
- Loading branch information
Showing
38 changed files
with
1,751 additions
and
242 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,82 @@ | ||
package controller | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/xpladev/xpla.go/core" | ||
"github.com/xpladev/xpla.go/core/auth" | ||
"github.com/xpladev/xpla.go/core/authz" | ||
"github.com/xpladev/xpla.go/core/bank" | ||
"github.com/xpladev/xpla.go/core/base" | ||
"github.com/xpladev/xpla.go/core/crisis" | ||
"github.com/xpladev/xpla.go/core/distribution" | ||
"github.com/xpladev/xpla.go/core/evidence" | ||
"github.com/xpladev/xpla.go/core/evm" | ||
"github.com/xpladev/xpla.go/core/feegrant" | ||
"github.com/xpladev/xpla.go/core/gov" | ||
"github.com/xpladev/xpla.go/core/ibc" | ||
"github.com/xpladev/xpla.go/core/mint" | ||
"github.com/xpladev/xpla.go/core/params" | ||
"github.com/xpladev/xpla.go/core/reward" | ||
"github.com/xpladev/xpla.go/core/slashing" | ||
"github.com/xpladev/xpla.go/core/staking" | ||
"github.com/xpladev/xpla.go/core/upgrade" | ||
"github.com/xpladev/xpla.go/core/wasm" | ||
) | ||
|
||
var once sync.Once | ||
var cc *coreController | ||
|
||
// Controller is able to contol modules in the core package. | ||
// Route Tx & Query logic by message type. | ||
// If need to add new modules of XPLA, insert NewCoreModule in the core controller. | ||
type coreController struct { | ||
cores map[string]core.CoreModule | ||
} | ||
|
||
func init() { | ||
Controller() | ||
} | ||
|
||
// Set core controller only once as singleton, and get core controller. | ||
func Controller() *coreController { | ||
once.Do( | ||
func() { | ||
cc = NewCoreController( | ||
auth.NewCoreModule(), | ||
authz.NewCoreModule(), | ||
bank.NewCoreModule(), | ||
base.NewCoreModule(), | ||
crisis.NewCoreModule(), | ||
distribution.NewCoreModule(), | ||
evidence.NewCoreModule(), | ||
evm.NewCoreModule(), | ||
feegrant.NewCoreModule(), | ||
gov.NewCoreModule(), | ||
ibc.NewCoreModule(), | ||
mint.NewCoreModule(), | ||
params.NewCoreModule(), | ||
reward.NewCoreModule(), | ||
slashing.NewCoreModule(), | ||
staking.NewCoreModule(), | ||
upgrade.NewCoreModule(), | ||
wasm.NewCoreModule(), | ||
) | ||
}) | ||
return cc | ||
} | ||
|
||
func NewCoreController(coreModules ...core.CoreModule) *coreController { | ||
m := make(map[string]core.CoreModule) | ||
for _, coreModule := range coreModules { | ||
m[coreModule.Name()] = coreModule | ||
} | ||
|
||
return &coreController{ | ||
cores: m, | ||
} | ||
} | ||
|
||
func (c coreController) Get(moduleName string) core.CoreModule { | ||
return c.cores[moduleName] | ||
} |
Oops, something went wrong.