Skip to content

Commit

Permalink
Query panic fix (shentufoundation#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega authored Mar 18, 2021
1 parent 8db8822 commit ab4c9fe
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 69 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/google/go-cmp v0.5.2 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hyperledger/burrow v0.30.6-0.20210205235125-5ec0c8b2fee8
github.com/hyperledger/burrow v0.31.0
github.com/magiconair/properties v1.8.4
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
Expand All @@ -28,6 +28,7 @@ require (
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f
google.golang.org/grpc v1.35.0
google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/hyperledger/burrow v0.30.6-0.20210205235125-5ec0c8b2fee8 h1:sJQpNhZx9XIn97jWhWTAoz6civaV21opCGgWRFfOqQE=
github.com/hyperledger/burrow v0.30.6-0.20210205235125-5ec0c8b2fee8/go.mod h1:u2ioH/f/o3SwGXdN2/IlK/n2pInh0HHv1Q4GjahyMcY=
github.com/hyperledger/burrow v0.31.0 h1:eJrT+SgvTTePSektPiP5qo+oW3qQvI2TN6VuBAqazTo=
github.com/hyperledger/burrow v0.31.0/go.mod h1:FQQo/qSESfo/hh8NsbkqisNTzeo4H+KV0M+MG7dKTBA=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/iancoleman/strcase v0.1.3/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
Expand Down Expand Up @@ -460,6 +462,9 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pointlander/compress v1.1.0/go.mod h1:q5NXNGzqj5uPnVuhGkZfmgHqNUhf15VLi6L9kW0VEc0=
github.com/pointlander/jetset v1.0.0/go.mod h1:zY6+WHRPB10uzTajloHtybSicLW1bf6Rz0eSaU9Deng=
github.com/pointlander/peg v1.0.0/go.mod h1:WJTMcgeWYr6fZz4CwHnY1oWZCXew8GWCF93FaAxPrh4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
Expand Down
2 changes: 1 addition & 1 deletion proto/shentu/cert/v1alpha1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ service Query {
}

rpc Certificate(QueryCertificateRequest) returns (QueryCertificateResponse) {
option (google.api.http).get = "/shentu/cert/v1alpha1/certificates/{certificate_id}";
option (google.api.http).get = "/shentu/cert/v1alpha1/certificate/{certificate_id}";
}

rpc Certificates(QueryCertificatesRequest) returns (QueryCertificatesResponse) {
Expand Down
2 changes: 1 addition & 1 deletion x/cert/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func GetCmdCertificates() *cobra.Command {
}

res, err := queryClient.Certificates(
context.Background(),
cmd.Context(),
&types.QueryCertificatesRequest{
Certifier: viper.GetString(FlagCertifier),
Content: viper.GetString(FlagContent),
Expand Down
16 changes: 10 additions & 6 deletions x/cert/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (q Querier) Certifier(c context.Context, req *types.QueryCertifierRequest)
// query by address
certifierAddr, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
panic(err)
return nil, err
}

certifier, err = q.GetCertifier(ctx, certifierAddr)
Expand Down Expand Up @@ -71,7 +71,7 @@ func (q Querier) Validator(c context.Context, req *types.QueryValidatorRequest)

pk, ok := req.Pubkey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into cryto.PubKey %T", req.Pubkey))
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into cryto.PubKey %T", req.Pubkey)
}

certifier, err := q.GetValidatorCertifier(ctx, pk)
Expand Down Expand Up @@ -100,7 +100,7 @@ func (q Querier) Platform(c context.Context, req *types.QueryPlatformRequest) (*

pk, ok := req.Pubkey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into cryto.PubKey %T", req.Pubkey))
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into cryto.PubKey %T", req.Pubkey)
}

platform, ok := q.GetPlatform(ctx, pk)
Expand Down Expand Up @@ -141,9 +141,13 @@ func (q Querier) Certificates(c context.Context, req *types.QueryCertificatesReq
}
ctx := sdk.UnwrapSDKContext(c)

certifierAddr, err := sdk.AccAddressFromBech32(req.Certifier)
if err != nil {
panic(err)
var certifierAddr sdk.AccAddress
var err error
if req.Certifier != "" {
certifierAddr, err = sdk.AccAddressFromBech32(req.Certifier)
if err != nil {
return nil, err
}
}

page, limit, err := qtypes.ParsePagination(req.Pagination)
Expand Down
116 changes: 58 additions & 58 deletions x/cert/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/cert/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/cvm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (q Querier) Meta(c context.Context, request *types.QueryMetaRequest) (*type
state := q.NewState(ctx)
hash, err := hex.DecodeString(request.Hash)
if err != nil {
panic(err)
return nil, err
}
var metahash acmstate.MetadataHash
copy(metahash[:], hash)
Expand Down

0 comments on commit ab4c9fe

Please sign in to comment.