Skip to content

Commit

Permalink
refactor: add a Consent proto data type (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
inchori authored Jan 5, 2023
1 parent c1f8f76 commit 4f854a2
Show file tree
Hide file tree
Showing 26 changed files with 1,093 additions and 682 deletions.
6 changes: 4 additions & 2 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ option go_package = "github.com/medibloc/panacea-core/x/datadeal/types";
import "gogoproto/gogo.proto";
import "panacea/datadeal/v2/deal.proto";

// Consent defines a consent that includes a certificate
message Consent {
Certificate certificate = 1;
}

// Certificate defines a certificate with signature
message Certificate {
UnsignedCertificate unsigned_certificate = 1;
Expand Down
4 changes: 2 additions & 2 deletions proto/panacea/datadeal/v2/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ option go_package = "github.com/medibloc/panacea-core/x/datadeal/types";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "panacea/datadeal/v2/deal.proto";
import "panacea/datadeal/v2/certificate.proto";
import "panacea/datadeal/v2/consent.proto";

// GenesisState defines the datadeal module's genesis state.
message GenesisState {
uint64 next_deal_number = 1;
repeated Deal deals = 2 [(gogoproto.nullable) = false];
repeated Certificate certificates = 3 [(gogoproto.nullable) = false];
repeated Consent consents = 3 [(gogoproto.nullable) = false];
}
34 changes: 17 additions & 17 deletions proto/panacea/datadeal/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "gogoproto/gogo.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";
import "panacea/datadeal/v2/deal.proto";
import "panacea/datadeal/v2/certificate.proto";
import "panacea/datadeal/v2/consent.proto";

// Query defines the gRPC querier service.
service Query {
Expand All @@ -21,14 +21,14 @@ service Query {
option (google.api.http).get = "/panacea/datadeal/v2/deals/{deal_id}";
}

// Certificates returns a list of Certificate.
rpc Certificates(QueryCertificates) returns (QueryCertificatesResponse) {
option (google.api.http).get = "/panacea/datadeal/v2/deals/{deal_id}/certificates";
// Consents returns a list of Consent.
rpc Consents(QueryConsents) returns (QueryConsentsResponse) {
option (google.api.http).get = "/panacea/datadeal/v2/deals/{deal_id}/consents";
}

// Certificate returns a Certificate
rpc Certificate(QueryCertificate) returns (QueryCertificateResponse) {
option (google.api.http).get = "/panacea/datadeal/v2/deals/{deal_id}/certificates/{data_hash}";
// Consent returns a Consent
rpc Consent(QueryConsent) returns (QueryConsentResponse) {
option (google.api.http).get = "/panacea/datadeal/v2/deals/{deal_id}/consents/{data_hash}";
}

}
Expand All @@ -54,26 +54,26 @@ message QueryDealResponse {
Deal deal = 1;
}

// QueryDealsRequest defines the request type for the Query/Deals RPC method.
message QueryCertificates {
// QueryConsents defines the request type for the Query/Consents RPC method.
message QueryConsents {
uint64 deal_id = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryDealsResponse defines the response type for the Query/Deals RPC method.
message QueryCertificatesResponse {
repeated Certificate certificates = 1;
// QueryConsentsResponse defines the response type for the Query/Consents RPC method.
message QueryConsentsResponse {
repeated Consent consents = 1;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryCertificate defines the request type for the Query/Certificate RPC method.
message QueryCertificate {
// QueryConsent defines the request type for the Query/Consent RPC method.
message QueryConsent {
uint64 deal_id = 1;
string data_hash = 2;
}

// QueryCertificateResponse defines the response type for the Query/Certificate RPC method.
message QueryCertificateResponse {
Certificate certificate = 1;
// QueryConsentResponse defines the response type for the Query/Consent RPC method.
message QueryConsentResponse {
Consent consent = 1;
}

4 changes: 2 additions & 2 deletions proto/panacea/datadeal/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ option go_package = "github.com/medibloc/panacea-core/x/datadeal/types";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "panacea/datadeal/v2/deal.proto";
import "panacea/datadeal/v2/certificate.proto";
import "panacea/datadeal/v2/consent.proto";

// Msg defines the Msg service.
service Msg {
Expand Down Expand Up @@ -45,7 +45,7 @@ message MsgDeactivateDealResponse {

// MsgSubmitConsent defines the Msg/SubmitConsent request type.
message MsgSubmitConsent {
Certificate certificate = 1;
Consent consent = 1;
}

// MsgSubmitConsentResponse defines the Msg/SubmitConsent response type.
Expand Down
4 changes: 2 additions & 2 deletions x/datadeal/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command {

cmd.AddCommand(CmdGetDeals())
cmd.AddCommand(CmdGetDeal())
cmd.AddCommand(CmdGetCertificates())
cmd.AddCommand(CmdGetCertificate())
cmd.AddCommand(CmdGetConsents())
cmd.AddCommand(CmdGetConsent())

return cmd
}
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/medibloc/panacea-core/v2/x/datadeal/types"
"github.com/spf13/cobra"
)

func CmdGetCertificates() *cobra.Command {
cmd := &cobra.Command{
Use: "certificates [deal-id]",
Short: "Query certificates",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

dealID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

req := &types.QueryCertificates{
DealId: dealID,
Pagination: pageReq,
}
res, err := queryClient.Certificates(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdGetCertificate() *cobra.Command {
cmd := &cobra.Command{
Use: "certificate [deal-id] [data-hash]",
Short: "Query a certificate info",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

dealID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

req := &types.QueryCertificate{
DealId: dealID,
DataHash: args[1],
}
res, err := queryClient.Certificate(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/medibloc/panacea-core/v2/x/datadeal/types"
"github.com/spf13/cobra"
)

func CmdGetConsents() *cobra.Command {
cmd := &cobra.Command{
Use: "consents [deal-id]",
Short: "Query consents",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

dealID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

req := &types.QueryConsents{
DealId: dealID,
Pagination: pageReq,
}
res, err := queryClient.Consents(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdGetConsent() *cobra.Command {
cmd := &cobra.Command{
Use: "consent [deal-id] [data-hash]",
Short: "Query a consent info",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

dealID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

req := &types.QueryConsent{
DealId: dealID,
DataHash: args[1],
}
res, err := queryClient.Consent(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
6 changes: 3 additions & 3 deletions x/datadeal/client/cli/txSubmitConsent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func CmdSubmitConsent() *cobra.Command {
cmd := &cobra.Command{
Use: "submit-consent [certificate-file]",
Use: "submit-consent [consent-file]",
Short: "submit a consent to provide the data",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -42,8 +42,8 @@ func CmdSubmitConsent() *cobra.Command {
return cmd
}

func newDataCertificate(file string) (*types.Certificate, error) {
var cert *types.Certificate
func newDataCertificate(file string) (*types.Consent, error) {
var cert *types.Consent

contents, err := os.ReadFile(file)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions x/datadeal/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
panic(err)
}

for _, consent := range genState.Consents {
if err := k.SetConsent(ctx, &consent); err != nil {
panic(err)
}
}

}

// ExportGenesis returns the capability module's exported genesis.
Expand All @@ -37,5 +43,11 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
}
genesis.NextDealNumber = nextDealNum

consents, err := k.GetAllConsents(ctx)
if err != nil {
panic(err)
}
genesis.Consents = consents

return genesis
}
Loading

0 comments on commit 4f854a2

Please sign in to comment.