2024-07-05 22:20:13 -04:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-09-07 18:12:58 -04:00
|
|
|
"fmt"
|
2024-07-05 22:20:13 -04:00
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2024-09-07 18:12:58 -04:00
|
|
|
"google.golang.org/genproto/googleapis/api/httpbody"
|
|
|
|
|
"google.golang.org/grpc/peer"
|
2024-07-05 22:20:13 -04:00
|
|
|
|
2024-09-05 01:24:57 -04:00
|
|
|
"github.com/onsonr/sonr/x/did/types"
|
2024-07-05 22:20:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ types.QueryServer = Querier{}
|
|
|
|
|
|
|
|
|
|
type Querier struct {
|
|
|
|
|
Keeper
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewQuerier(keeper Keeper) Querier {
|
|
|
|
|
return Querier{Keeper: keeper}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Params returns the total set of did parameters.
|
2024-09-07 18:12:58 -04:00
|
|
|
func (k Querier) Params(
|
|
|
|
|
c context.Context,
|
|
|
|
|
req *types.QueryRequest,
|
|
|
|
|
) (*types.QueryParamsResponse, error) {
|
2024-07-05 22:20:13 -04:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
|
|
p, err := k.Keeper.Params.Get(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2024-09-07 18:12:58 -04:00
|
|
|
params := p.ActiveParams(k.HasIPFSConnection())
|
|
|
|
|
return &types.QueryParamsResponse{Params: ¶ms}, nil
|
2024-08-10 17:01:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resolve implements types.QueryServer.
|
2024-09-07 18:12:58 -04:00
|
|
|
func (k Querier) Resolve(
|
|
|
|
|
goCtx context.Context,
|
|
|
|
|
req *types.QueryRequest,
|
|
|
|
|
) (*types.QueryResolveResponse, error) {
|
2024-07-05 22:20:13 -04:00
|
|
|
// ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
|
return &types.QueryResolveResponse{}, nil
|
|
|
|
|
}
|
2024-07-23 14:18:15 -04:00
|
|
|
|
2024-08-10 17:01:14 -04:00
|
|
|
// Service implements types.QueryServer.
|
2024-09-07 18:12:58 -04:00
|
|
|
func (k Querier) Service(
|
|
|
|
|
goCtx context.Context,
|
|
|
|
|
req *types.QueryRequest,
|
|
|
|
|
) (*types.QueryServiceResponse, error) {
|
|
|
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
|
|
|
|
|
|
_, ok := peer.FromContext(goCtx)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, fmt.Errorf("failed to get peer from context")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rec, err := k.OrmDB.ServiceRecordTable().GetByOriginUri(ctx, req.Origin)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &types.QueryServiceResponse{Service: convertServiceRecord(rec)}, nil
|
2024-07-23 14:18:15 -04:00
|
|
|
}
|
2024-09-05 01:24:57 -04:00
|
|
|
|
2024-09-07 18:12:58 -04:00
|
|
|
// HTMX implements types.QueryServer.
|
|
|
|
|
func (k Querier) HTMX(goCtx context.Context, req *types.QueryRequest) (*httpbody.HttpBody, error) {
|
2024-09-05 01:24:57 -04:00
|
|
|
// ctx := sdk.UnwrapSDKContext(goCtx)
|
2024-09-07 18:12:58 -04:00
|
|
|
return &httpbody.HttpBody{
|
|
|
|
|
ContentType: "text/html",
|
|
|
|
|
Data: []byte("<html><body>HTMX</body></html>"),
|
|
|
|
|
}, nil
|
2024-09-05 01:24:57 -04:00
|
|
|
}
|