addressed Jae's comments
This commit is contained in:
parent
0134c3b7f1
commit
97f7b88a9f
|
@ -370,6 +370,9 @@ func handleQueryP2P(app *BaseApp, path []string, req abci.RequestQuery) (res abc
|
|||
func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res abci.ResponseQuery) {
|
||||
// path[0] should be "custom" because "/custom" prefix is required for keeper queries.
|
||||
// the queryRouter routes using path[1]. For example, in the path "custom/gov/proposal", queryRouter routes using "gov"
|
||||
if path[1] == "" {
|
||||
sdk.ErrUnknownRequest("No route for custom query specified").QueryResult()
|
||||
}
|
||||
querier := app.queryRouter.Route(path[1])
|
||||
ctx := app.checkState.ctx
|
||||
// Passes the rest of the path as an argument to the querier.
|
||||
|
@ -378,6 +381,7 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res
|
|||
if err != nil {
|
||||
return abci.ResponseQuery{
|
||||
Code: uint32(err.ABCICode()),
|
||||
Log: err.ABCILog(),
|
||||
}
|
||||
}
|
||||
return abci.ResponseQuery{
|
||||
|
|
|
@ -10,14 +10,8 @@ type QueryRouter interface {
|
|||
Route(path string) (h sdk.Querier)
|
||||
}
|
||||
|
||||
// map a transaction type to a handler and an initgenesis function
|
||||
type queryroute struct {
|
||||
r string
|
||||
h sdk.Querier
|
||||
}
|
||||
|
||||
type queryrouter struct {
|
||||
routes []queryroute
|
||||
routes map[string]sdk.Querier
|
||||
}
|
||||
|
||||
// nolint
|
||||
|
@ -25,27 +19,23 @@ type queryrouter struct {
|
|||
// TODO either make Function unexported or make return type (router) Exported
|
||||
func NewQueryRouter() *queryrouter {
|
||||
return &queryrouter{
|
||||
routes: make([]queryroute, 0),
|
||||
routes: map[string]sdk.Querier{},
|
||||
}
|
||||
}
|
||||
|
||||
// AddRoute - TODO add description
|
||||
func (rtr *queryrouter) AddRoute(r string, h sdk.Querier) QueryRouter {
|
||||
// AddRoute - Adds an sdk.Querier to the route provided. Panics on duplicate
|
||||
func (rtr *queryrouter) AddRoute(r string, q sdk.Querier) QueryRouter {
|
||||
if !isAlphaNumeric(r) {
|
||||
panic("route expressions can only contain alphanumeric characters")
|
||||
}
|
||||
rtr.routes = append(rtr.routes, queryroute{r, h})
|
||||
|
||||
if rtr.routes[r] != nil {
|
||||
panic("route has already been initialized")
|
||||
}
|
||||
rtr.routes[r] = q
|
||||
return rtr
|
||||
}
|
||||
|
||||
// Route - TODO add description
|
||||
// TODO handle expressive matches.
|
||||
// Returns the sdk.Querier for a certain route path
|
||||
func (rtr *queryrouter) Route(path string) (h sdk.Querier) {
|
||||
for _, route := range rtr.routes {
|
||||
if route.r == path {
|
||||
return route.h
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return rtr.routes[path]
|
||||
}
|
||||
|
|
|
@ -111,13 +111,19 @@ func (bz AccAddress) Format(s fmt.State, verb rune) {
|
|||
|
||||
// Returns boolean for whether two AccAddresses are Equal
|
||||
func (bz AccAddress) Equals(bz2 AccAddress) bool {
|
||||
if bz.Empty() && bz2.Empty() {
|
||||
return true
|
||||
}
|
||||
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
||||
}
|
||||
|
||||
// Returns boolean for whether an AccAddress is empty
|
||||
func (bz AccAddress) Empty() bool {
|
||||
if bz == nil {
|
||||
return true
|
||||
}
|
||||
bz2 := AccAddress{}
|
||||
return bz.Equals(bz2)
|
||||
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
||||
}
|
||||
|
||||
//__________________________________________________________
|
||||
|
@ -206,13 +212,19 @@ func (bz ValAddress) Format(s fmt.State, verb rune) {
|
|||
|
||||
// Returns boolean for whether two ValAddresses are Equal
|
||||
func (bz ValAddress) Equals(bz2 ValAddress) bool {
|
||||
if bz.Empty() && bz2.Empty() {
|
||||
return true
|
||||
}
|
||||
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
||||
}
|
||||
|
||||
// Returns boolean for whether an AccAddress is empty
|
||||
func (bz ValAddress) Empty() bool {
|
||||
if bz == nil {
|
||||
return true
|
||||
}
|
||||
bz2 := ValAddress{}
|
||||
return bz.Equals(bz2)
|
||||
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
||||
}
|
||||
|
||||
// Bech32ifyAccPub takes AccountPubKey and returns the bech32 encoded string
|
||||
|
|
Loading…
Reference in New Issue