Skip to content

Commit

Permalink
fix proto comments; cleanup address validation for FullDenom query
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 26, 2024
1 parent 5d8f15f commit 5fb656d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 29 deletions.
2 changes: 0 additions & 2 deletions proto/neutron/contractmanager/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ message MsgResubmitFailure {
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// failure_id is id of failure to resubmit
//
// NOTE: All parameters must be supplied.
uint64 failure_id = 2;
}

Expand Down
10 changes: 7 additions & 3 deletions proto/osmosis/tokenfactory/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,28 @@ message QueryDenomsFromCreatorResponse {
repeated string denoms = 1 [(gogoproto.moretags) = "yaml:\"denoms\""];
}

// QueryBeforeSendHookAddressRequest defines the request structure for the
// DenomsFromCreator gRPC query.
message QueryBeforeSendHookAddressRequest {
string creator = 1 [(gogoproto.moretags) = "yaml:\"creator\""];
string subdenom = 2 [(gogoproto.moretags) = "yaml:\"subdenom\""];
}

// QueryBeforeSendHookAddressResponse defines the response structure for the
// DenomBeforeSendHook gRPC query.
// BeforeSendHookAddress gRPC query.
message QueryBeforeSendHookAddressResponse {
string contract_addr = 1 [(gogoproto.moretags) = "yaml:\"contract_addr\""];
}

// QueryFullDenomRequest defines the request structure for the
// FullDenom gRPC query.
message QueryFullDenomRequest {
string creator = 1 [(gogoproto.moretags) = "yaml:\"creator\""];
string subdenom = 2 [(gogoproto.moretags) = "yaml:\"subdenom\""];
}

// QueryBeforeSendHookAddressResponse defines the response structure for the
// DenomBeforeSendHook gRPC query.
// QueryFullDenomResponse defines the response structure for the
// FullDenom gRPC query.
message QueryFullDenomResponse {
string full_denom = 1 [(gogoproto.moretags) = "yaml:\"full_denom\""];
}
2 changes: 0 additions & 2 deletions x/contractmanager/types/tx.pb.go

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

20 changes: 1 addition & 19 deletions x/tokenfactory/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"fmt"

"cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/neutron-org/neutron/v5/x/tokenfactory/types"
Expand Down Expand Up @@ -48,8 +46,7 @@ func (k Keeper) BeforeSendHookAddress(ctx context.Context, req *types.QueryBefor
}

func (k Keeper) FullDenom(_ context.Context, req *types.QueryFullDenomRequest) (*types.QueryFullDenomResponse, error) {
// Address validation
if _, err := parseAddress(req.Creator); err != nil {
if _, err := sdk.AccAddressFromBech32(req.Creator); err != nil {
return nil, err
}

Expand All @@ -60,18 +57,3 @@ func (k Keeper) FullDenom(_ context.Context, req *types.QueryFullDenomRequest) (

return &types.QueryFullDenomResponse{FullDenom: fullDenom}, nil
}

// parseAddress parses address from bech32 string and verifies its format.
func parseAddress(addr string) (sdk.AccAddress, error) {
parsed, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return nil, errors.Wrap(err, "address from bech32")
}

err = sdk.VerifyAddressFormat(parsed)
if err != nil {
return nil, errors.Wrap(err, "verify address format")
}

return parsed, nil
}
10 changes: 7 additions & 3 deletions x/tokenfactory/types/query.pb.go

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

0 comments on commit 5fb656d

Please sign in to comment.