Skip to content

Commit

Permalink
Add address conversion (#777)
Browse files Browse the repository at this point in the history
* Add address conversion
  • Loading branch information
skyargos authored Sep 21, 2023
1 parent df3da02 commit 9e47c55
Show file tree
Hide file tree
Showing 4 changed files with 555 additions and 49 deletions.
12 changes: 12 additions & 0 deletions proto/shentu/cert/v1alpha1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ service Query {
rpc Certificates(QueryCertificatesRequest) returns (QueryCertificatesResponse) {
option (google.api.http).get = "/shentu/cert/v1alpha1/certificates";
}

rpc AddrConversion(ConversionToShentuAddrRequest) returns (ConversionToShentuAddrResponse) {
option (google.api.http).get = "/shentu/conversion/to-shentu/{address}";
}
}

message QueryCertifierRequest {
Expand Down Expand Up @@ -81,3 +85,11 @@ message QueryCertificatesResponse {
// pagination defines the pagination in the response.
//cosmos.base.query.v1beta1.PageResponse pagination = 3;
}

message ConversionToShentuAddrRequest {
string address = 1;
}

message ConversionToShentuAddrResponse {
string address = 1;
}
12 changes: 12 additions & 0 deletions x/cert/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
qtypes "github.com/cosmos/cosmos-sdk/types/query"

"github.com/shentufoundation/shentu/v2/common"
"github.com/shentufoundation/shentu/v2/x/cert/types"
)

Expand Down Expand Up @@ -137,3 +138,14 @@ func (q Querier) Certificates(c context.Context, req *types.QueryCertificatesReq

return &types.QueryCertificatesResponse{Total: total, Certificates: results}, nil
}

func (q Querier) AddrConversion(c context.Context, req *types.ConversionToShentuAddrRequest) (*types.ConversionToShentuAddrResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
shentuAddr, err := common.PrefixToShentu(req.Address)
if err != nil {
return nil, err
}
return &types.ConversionToShentuAddrResponse{Address: shentuAddr}, nil
}
Loading

0 comments on commit 9e47c55

Please sign in to comment.