Skip to content

Commit

Permalink
feat: update msg and query server
Browse files Browse the repository at this point in the history
  • Loading branch information
MikkySnow committed Mar 19, 2024
1 parent 606b193 commit 568e7a7
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 273 deletions.
4 changes: 2 additions & 2 deletions proto/swisstronik/compliance/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ service Query {
}

rpc VerificationDetails(QueryVerificationDetailsRequest) returns (QueryVerificationDetailsResponse) {
option (google.api.http).get = "/swisstronik/compliance/details/{userAddress}";
option (google.api.http).get = "/swisstronik/compliance/details/{verificationID}";
}
}

Expand Down Expand Up @@ -58,7 +58,7 @@ message QueryIssuerDetailsResponse {
}

message QueryVerificationDetailsRequest {
string userAddress = 1;
string verificationID = 1;
}

message QueryVerificationDetailsResponse {
Expand Down
12 changes: 7 additions & 5 deletions proto/swisstronik/compliance/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ option go_package = "swisstronik/x/compliance/types";

// Msg defines the Msg service.
service Msg {
rpc SetIssuerDetails(MsgSetIssuerDetails) returns (MsgSetIssuerDetailsResponse);
rpc UpdateIssuerDetails(MsgUpdateIssuerDetails) returns (MsgUpdateIssuerDetailsResponse);
rpc RemoveIssuer(MsgRemoveIssuer) returns (MsgRemoveIssuer);
rpc HandleSetIssuerDetails(MsgSetIssuerDetails) returns (MsgSetIssuerDetailsResponse);
rpc HandleUpdateIssuerDetails(MsgUpdateIssuerDetails) returns (MsgUpdateIssuerDetailsResponse);
rpc HandleRemoveIssuer(MsgRemoveIssuer) returns (MsgRemoveIssuerResponse);
}

message MsgSetIssuerDetails {
string operator = 1;
IssuerDetails details = 2;
string issuerAddress = 2;
IssuerDetails details = 3;
}
message MsgSetIssuerDetailsResponse {}

message MsgUpdateIssuerDetails {
string operator = 1;
IssuerDetails details = 2;
string issuerAddress = 2;
IssuerDetails details = 3;
}
message MsgUpdateIssuerDetailsResponse {}

Expand Down
39 changes: 36 additions & 3 deletions x/compliance/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
Expand All @@ -23,6 +23,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
CmdQueryParams(),
CmdGetAddressInfo(),
CmdGetIssuerDetails(),
CmdGetVerificationDetails(),
)

return cmd
Expand All @@ -42,11 +43,11 @@ func CmdGetAddressInfo() *cobra.Command {
return err
}

req := &types.QueryVerificationDataRequest{
req := &types.QueryAddressInfoRequest{
Address: address.String(),
}

resp, err := queryClient.VerificationData(context.Background(), req)
resp, err := queryClient.AddressInfo(context.Background(), req)
if err != nil {
return err
}
Expand Down Expand Up @@ -91,3 +92,35 @@ func CmdGetIssuerDetails() *cobra.Command {

return cmd
}

func CmdGetVerificationDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "get-verification-details [verification-id]",
Short: "Returns details of provided address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

id, err := types.ParseAddress(args[0])
if err != nil {
return err
}

req := &types.QueryVerificationDetailsRequest{
VerificationID: id.String(),
}

resp, err := queryClient.VerificationDetails(context.Background(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(resp)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
77 changes: 14 additions & 63 deletions x/compliance/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package cli

import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/ethereum/go-ethereum/common"
"swisstronik/x/compliance/types"
"time"

"github.com/spf13/cobra"
"swisstronik/x/compliance/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand All @@ -24,70 +20,16 @@ func GetTxCmd() *cobra.Command {
}

cmd.AddCommand(
CmdSetAddressInfo(),
CmdSetIssuerDetails(),
)

return cmd
}

// CmdSetAddressInfo command sets sample verification data for specific address.
// This function is used only for debug purposes and will be removed before chain update.
func CmdSetAddressInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "set-address-info [user-address] [issuer-address] [issuer-alias] [origin-chain]",
Short: "Sets sample verification data for provided address",
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

userAddress := args[0]
if !common.IsHexAddress(userAddress) {
return fmt.Errorf("provided non-eth user address")
}

issuerAddress := args[1]
if !common.IsHexAddress(issuerAddress) {
return fmt.Errorf("provided non-eth user address")
}

issuerAlias := args[2]
if len(issuerAlias) == 0 {
issuerAlias = "sample_issuer"
}

originChain := args[3]
if len(originChain) == 0 {
originChain = "swisstronik"
}

timestamp := uint32(time.Now().Unix())

msg := types.NewMsgSetAddressInfo(
clientCtx.GetFromAddress().String(),
userAddress,
issuerAddress,
issuerAlias,
originChain,
timestamp,
types.VerificationType_VT_KYC,
)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

// CmdSetIssuerDetails command sets provided issuer details.
func CmdSetIssuerDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "set-issuer-details [issuer-address] [issuer-alias]",
Use: "set-issuer-details [issuer-address] [name] [description] [url] [logo-url] [legalEntity]",
Short: "Sets issuer details",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -101,11 +43,20 @@ func CmdSetIssuerDetails() *cobra.Command {
return err
}

issuerAlias := args[1]
issuerName := args[1]
issuerDescription := args[2]
issuerURL := args[3]
issuerLogo := args[4]
issuerLegalEntity := args[5]

msg := types.NewSetIssuerDetailsMsg(
clientCtx.GetFromAddress().String(),
clientCtx.GetFromAddress(),
issuerAddress.String(),
issuerAlias,
issuerName,
issuerDescription,
issuerURL,
issuerLogo,
issuerLegalEntity,
)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
Expand Down
19 changes: 2 additions & 17 deletions x/compliance/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,10 @@ func (k Keeper) GetAddressInfo(ctx sdk.Context, address sdk.Address) (*types.Add
return &addrInfo, nil
}

// SetIssuerDetailsInner sets description about provided issuer address
func (k Keeper) SetIssuerDetailsInner(ctx sdk.Context, issuerAddress sdk.Address, alias string) error {
// SetIssuerDetails sets details for provided issuer address
func (k Keeper) SetIssuerDetails(ctx sdk.Context, issuerAddress sdk.Address, details *types.IssuerDetails) error {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixIssuerDetails)

if len(alias) == 0 {
return errors.Wrap(types.ErrInvalidParam, "invalid issuer alias")
}

details := &types.IssuerDetails{IssuerAlias: alias}
detailsBytes, err := details.Marshal()
if err != nil {
return err
Expand All @@ -149,16 +144,6 @@ func (k Keeper) GetIssuerDetails(ctx sdk.Context, issuerAddress sdk.Address) (*t
return &issuerDetails, nil
}

// GetIssuerAlias returns human-readable alias of provided issuer address
func (k Keeper) GetIssuerAlias(ctx sdk.Context, issuerAddress sdk.Address) (string, error) {
issuerDetails, err := k.GetIssuerDetails(ctx, issuerAddress)
if err != nil {
return "", err
}

return issuerDetails.IssuerAlias, nil
}

// GetAddressDetails returns address details
func (k Keeper) GetAddressDetails(ctx sdk.Context, address sdk.Address) (*types.AddressDetails, error) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAddressDetails)
Expand Down
27 changes: 11 additions & 16 deletions x/compliance/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,27 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {

var _ types.MsgServer = msgServer{}

func (k msgServer) SetAddressInfo(goCtx context.Context, msg *types.MsgSetAddressInfo) (*types.MsgSetAddressInfoResponse, error) {
func (k msgServer) HandleSetIssuerDetails(goCtx context.Context, msg *types.MsgSetIssuerDetails) (*types.MsgSetIssuerDetailsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

address, err := sdk.AccAddressFromBech32(msg.UserAddress)
issuerAddress, err := sdk.AccAddressFromBech32(msg.IssuerAddress)
if err != nil {
return nil, err
}

if err := k.SetAddressInfoRaw(ctx, address, msg.Data); err != nil {
if err := k.SetIssuerDetails(ctx, issuerAddress, msg.Details); err != nil {
return nil, err
}

return &types.MsgSetAddressInfoResponse{}, nil
return &types.MsgSetIssuerDetailsResponse{}, nil
}

func (k msgServer) SetIssuerDetails(goCtx context.Context, msg *types.MsgSetIssuerDetails) (*types.MsgSetIssuerDetailsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

issuerAddress, err := sdk.AccAddressFromBech32(msg.IssuerAddress)
if err != nil {
return nil, err
}

if err := k.SetIssuerDetailsInner(ctx, issuerAddress, msg.Details.IssuerAlias); err != nil {
return nil, err
}
func (k msgServer) HandleUpdateIssuerDetails(goCtx context.Context, msg *types.MsgUpdateIssuerDetails) (*types.MsgUpdateIssuerDetailsResponse, error) {
// TODO: Implement
return &types.MsgUpdateIssuerDetailsResponse{}, nil
}

return &types.MsgSetIssuerDetailsResponse{}, nil
func (k msgServer) HandleRemoveIssuer(goCtx context.Context, msg *types.MsgRemoveIssuer) (*types.MsgRemoveIssuerResponse, error) {
// TODO: Implement
return &types.MsgRemoveIssuerResponse{}, nil
}
22 changes: 20 additions & 2 deletions x/compliance/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var _ types.QueryServer = Keeper{}

func (k Keeper) VerificationData(goCtx context.Context, req *types.QueryVerificationDataRequest) (*types.QueryVerificationDataResponse, error) {
func (k Keeper) AddressInfo(goCtx context.Context, req *types.QueryAddressInfoRequest) (*types.QueryAddressInfoResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand All @@ -26,7 +26,7 @@ func (k Keeper) VerificationData(goCtx context.Context, req *types.QueryVerifica
return nil, err
}

return &types.QueryVerificationDataResponse{Data: verificationData}, nil
return &types.QueryAddressInfoResponse{Data: verificationData}, nil
}

func (k Keeper) IssuerDetails(goCtx context.Context, req *types.QueryIssuerDetailsRequest) (*types.QueryIssuerDetailsResponse, error) {
Expand All @@ -47,3 +47,21 @@ func (k Keeper) IssuerDetails(goCtx context.Context, req *types.QueryIssuerDetai

return &types.QueryIssuerDetailsResponse{Details: issuerDetails}, nil
}

func (k Keeper) VerificationDetails(goCtx context.Context, req *types.QueryVerificationDetailsRequest) (*types.QueryVerificationDetailsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

details, err := k.GetVerificationDetails(ctx, []byte(req.VerificationID))
if err != nil {
return nil, err
}

if details == nil {
return &types.QueryVerificationDetailsResponse{}, nil
}

return &types.QueryVerificationDetailsResponse{Details: details}, nil
}
4 changes: 2 additions & 2 deletions x/compliance/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command {

// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd(types.StoreKey)
return cli.GetQueryCmd()
}

// ----------------------------------------------------------------------------
Expand All @@ -88,7 +88,7 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
type AppModule struct {
AppModuleBasic

keeper keeper.Keeper
keeper keeper.Keeper
}

func NewAppModule(
Expand Down
Loading

0 comments on commit 568e7a7

Please sign in to comment.