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) {
|
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.
|
// 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"
|
// 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])
|
querier := app.queryRouter.Route(path[1])
|
||||||
ctx := app.checkState.ctx
|
ctx := app.checkState.ctx
|
||||||
// Passes the rest of the path as an argument to the querier.
|
// 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 {
|
if err != nil {
|
||||||
return abci.ResponseQuery{
|
return abci.ResponseQuery{
|
||||||
Code: uint32(err.ABCICode()),
|
Code: uint32(err.ABCICode()),
|
||||||
|
Log: err.ABCILog(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return abci.ResponseQuery{
|
return abci.ResponseQuery{
|
||||||
|
|
|
@ -10,14 +10,8 @@ type QueryRouter interface {
|
||||||
Route(path string) (h sdk.Querier)
|
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 {
|
type queryrouter struct {
|
||||||
routes []queryroute
|
routes map[string]sdk.Querier
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint
|
// nolint
|
||||||
|
@ -25,27 +19,23 @@ type queryrouter struct {
|
||||||
// TODO either make Function unexported or make return type (router) Exported
|
// TODO either make Function unexported or make return type (router) Exported
|
||||||
func NewQueryRouter() *queryrouter {
|
func NewQueryRouter() *queryrouter {
|
||||||
return &queryrouter{
|
return &queryrouter{
|
||||||
routes: make([]queryroute, 0),
|
routes: map[string]sdk.Querier{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRoute - TODO add description
|
// AddRoute - Adds an sdk.Querier to the route provided. Panics on duplicate
|
||||||
func (rtr *queryrouter) AddRoute(r string, h sdk.Querier) QueryRouter {
|
func (rtr *queryrouter) AddRoute(r string, q sdk.Querier) QueryRouter {
|
||||||
if !isAlphaNumeric(r) {
|
if !isAlphaNumeric(r) {
|
||||||
panic("route expressions can only contain alphanumeric characters")
|
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
|
return rtr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route - TODO add description
|
// Returns the sdk.Querier for a certain route path
|
||||||
// TODO handle expressive matches.
|
|
||||||
func (rtr *queryrouter) Route(path string) (h sdk.Querier) {
|
func (rtr *queryrouter) Route(path string) (h sdk.Querier) {
|
||||||
for _, route := range rtr.routes {
|
return rtr.routes[path]
|
||||||
if route.r == path {
|
|
||||||
return route.h
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,13 +111,19 @@ func (bz AccAddress) Format(s fmt.State, verb rune) {
|
||||||
|
|
||||||
// Returns boolean for whether two AccAddresses are Equal
|
// Returns boolean for whether two AccAddresses are Equal
|
||||||
func (bz AccAddress) Equals(bz2 AccAddress) bool {
|
func (bz AccAddress) Equals(bz2 AccAddress) bool {
|
||||||
|
if bz.Empty() && bz2.Empty() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns boolean for whether an AccAddress is empty
|
// Returns boolean for whether an AccAddress is empty
|
||||||
func (bz AccAddress) Empty() bool {
|
func (bz AccAddress) Empty() bool {
|
||||||
|
if bz == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
bz2 := AccAddress{}
|
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
|
// Returns boolean for whether two ValAddresses are Equal
|
||||||
func (bz ValAddress) Equals(bz2 ValAddress) bool {
|
func (bz ValAddress) Equals(bz2 ValAddress) bool {
|
||||||
|
if bz.Empty() && bz2.Empty() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns boolean for whether an AccAddress is empty
|
// Returns boolean for whether an AccAddress is empty
|
||||||
func (bz ValAddress) Empty() bool {
|
func (bz ValAddress) Empty() bool {
|
||||||
|
if bz == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
bz2 := ValAddress{}
|
bz2 := ValAddress{}
|
||||||
return bz.Equals(bz2)
|
return (bytes.Compare(bz.Bytes(), bz2.Bytes()) == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bech32ifyAccPub takes AccountPubKey and returns the bech32 encoded string
|
// Bech32ifyAccPub takes AccountPubKey and returns the bech32 encoded string
|
||||||
|
|
Loading…
Reference in New Issue