Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it compilable #331

Merged
merged 2 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,24 @@ require (
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/goccy/go-json v0.9.4 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand Down Expand Up @@ -374,6 +375,8 @@ github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2V
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188/go.mod h1:vXjM/+wXQnTPR4KqTKDgJukSZ6amVRtWMPEjE6sQoK8=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -458,6 +461,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0=
Expand Down Expand Up @@ -491,6 +496,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 h1:BGNSrTRW4rwfhJiFwvwF4XQ0Y72Jj9YEgxVrtovbD5o=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3/go.mod h1:VHn7KgNsRriXa4mcgtkpR00OXyQY6g67JWMvn+R27A4=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down
2 changes: 1 addition & 1 deletion x/cheqd/types/query.pb.gw.go

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

36 changes: 16 additions & 20 deletions x/resource/genesis.go
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
package recource
package resource

import (
"fmt"

"github.com/cheqd/cheqd-node/x/cheqd/keeper"
"github.com/cheqd/cheqd-node/x/cheqd/types"
"github.com/cheqd/cheqd-node/x/resource/keeper"
"github.com/cheqd/cheqd-node/x/resource/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// InitGenesis initializes the cheqd module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
for _, elem := range genState.DidList {
did, err := elem.UnpackDataAsDid()
if err != nil {
panic(fmt.Sprintf("Cannot import geneses case: %s", err.Error()))
}
for _, resource := range genState.ResourceList {

if err = k.SetDid(&ctx, did, elem.Metadata); err != nil {
panic(fmt.Sprintf("Cannot set did case: %s", err.Error()))
if err := k.SetResource(&ctx, resource); err != nil {
panic(fmt.Sprintf("Cannot set resource case: %s", err.Error()))
}
}

// Set nym count
k.SetDidCount(&ctx, uint64(len(genState.DidList)))
k.SetResourceCount(&ctx, uint64(len(genState.ResourceList)))

k.SetDidNamespace(ctx, genState.DidNamespace)
//k.SetResourceNamespace(ctx, genState.ResourceNamespace)
}

// ExportGenesis returns the cheqd module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()

// this line is used by starport scaffolding # genesis/module/export
// Get all did
didList := k.GetAllDid(&ctx)
for _, elem := range didList {
elem := elem
genesis.DidList = append(genesis.DidList, &elem)
}

genesis.DidNamespace = k.GetDidNamespace(ctx)
// Get all resource
//resourceList := k.GetAllResource(&ctx)
//for _, elem := range resourceList {
// elem := elem
// genesis.ResourceList = append(genesis.ResourceList, &elem)
//}
//
//genesis.ResourceNamespace = k.GetResourceNamespace(ctx)

return genesis
}
18 changes: 9 additions & 9 deletions x/resource/handler.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package recource
package resource

import (
"fmt"

"github.com/cheqd/cheqd-node/x/cheqd/keeper"
"github.com/cheqd/cheqd-node/x/cheqd/types"
"github.com/cheqd/cheqd-node/x/resource/keeper"
"github.com/cheqd/cheqd-node/x/resource/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand All @@ -16,13 +16,13 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
ctx = ctx.WithEventManager(sdk.NewEventManager())

switch msg := msg.(type) {
case *types.MsgCreateDid:
res, err := msgServer.CreateDid(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

case *types.MsgUpdateDid:
res, err := msgServer.UpdateDid(sdk.WrapSDKContext(ctx), msg)
case *types.MsgCreateResource:
res, err := msgServer.CreateResource(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
//
//case *types.Msg:
// res, err := msgServer.UpdateDid(sdk.WrapSDKContext(ctx), msg)
// return sdk.WrapServiceResult(ctx, res, err)

default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
Expand Down
2 changes: 1 addition & 1 deletion x/resource/keeper/keeper_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (k Keeper) AppendResource(ctx *sdk.Context, resource *types.Resource) error
// SetResource set a specific resource in the store
func (k Keeper) SetResource(ctx *sdk.Context, resource *types.Resource) error {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ResourceKey))
b := k.cdc.MustMarshal(&resource)
b := k.cdc.MustMarshal(resource)
store.Set(GetResourceKeyBytes(resource.CollectionId, resource.Id), b)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion x/resource/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package keeper

import (
cheqd_types "github.com/cheqd/cheqd-node/x/cheqd/types"
"github.com/cheqd/cheqd-node/x/resource/types"
cheqd_types "github.com/cheqd/cheqd-node/x/resource/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down
2 changes: 1 addition & 1 deletion x/resource/module.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package recource
package resource

import (
"context"
Expand Down
6 changes: 1 addition & 5 deletions x/resource/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ func DefaultGenesis() *GenesisState {
func (gs GenesisState) Validate() error {
resourceIdMap := make(map[string]bool)

for _, elem := range gs.ResourceList {
resource, err := elem.UnpackDataAsResource()
if err != nil {
return err
}
for _, resource := range gs.ResourceList {

if _, ok := resourceIdMap[resource.Id]; ok {
return fmt.Errorf("duplicated id for resource")
Expand Down
6 changes: 3 additions & 3 deletions x/resource/types/query.pb.gw.go

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

6 changes: 4 additions & 2 deletions x/resource/types/tx_msg_create_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
cheqd_types "github.com/cheqd/cheqd-node/x/cheqd/types"
sdk "github.com/cosmos/cosmos-sdk/types"
validation "github.com/go-ozzo/ozzo-validation/v4"
)

var _ sdk.Msg = &MsgCreateResource{}
Expand Down Expand Up @@ -43,6 +44,7 @@ func (msg *MsgCreateResource) ValidateBasic() error {
// Validate

func (msg MsgCreateResource) Validate() error {
//TODO: implement
return nil
return validation.ValidateStruct(&msg,
validation.Field(&msg.Payload, validation.Required, ValidMsgCreateResourcePayload()),
)
}
24 changes: 22 additions & 2 deletions x/resource/types/tx_msg_create_resource_payload.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package types

import (
validation "github.com/go-ozzo/ozzo-validation/v4"
)

func (msg *MsgCreateResourcePayload) GetSignBytes() []byte {
return ModuleCdc.MustMarshal(msg)
}
Expand All @@ -22,6 +26,22 @@ func (msg *MsgCreateResourcePayload) ToResource() Resource {
// Validation

func (msg MsgCreateResourcePayload) Validate() error {
//TODO: implementation
return nil
//return validation.ValidateStruct(&msg,
// validation.Field(&msg.Payload, validation.Required, ValidMsgCreateDidPayloadRule(allowedNamespaces)),
// validation.Field(&msg.Signatures, IsUniqueSignInfoListByIdRule(), validation.Each(ValidSignInfoRule(allowedNamespaces))),
//)
return validation.ValidateStruct(&msg,
validation.Field(&msg.CollectionId, validation.Required, IsUUID()),
)
}

func ValidMsgCreateResourcePayload() *CustomErrorRule {
return NewCustomErrorRule(func(value interface{}) error {
casted, ok := value.(*MsgCreateResourcePayload)
if !ok {
panic("ValidMsgCreateResourcePayload must be only applied on MsgCreateDidPayload properties")
}

return casted.Validate()
})
}
42 changes: 42 additions & 0 deletions x/resource/types/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package types

import (
utils "github.com/cheqd/cheqd-node/x/resource/utils"
)

// Helper enums

type ValidationType int

const (
Optional ValidationType = iota
Required ValidationType = iota
Empty ValidationType = iota
)

// Custom error rule

type CustomErrorRule struct {
fn func(value interface{}) error
}

func NewCustomErrorRule(fn func(value interface{}) error) *CustomErrorRule {
return &CustomErrorRule{fn: fn}
}

func (c CustomErrorRule) Validate(value interface{}) error {
return c.fn(value)
}

// Validate URL

func IsUUID() *CustomErrorRule {
return NewCustomErrorRule(func(value interface{}) error {
casted, ok := value.(string)
if !ok {
panic("IsDID must be only applied on string properties")
}

return utils.ValidateUUID(casted)
})
}
7 changes: 6 additions & 1 deletion x/resource/utils/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ package utils

import (
"fmt"

"github.com/google/uuid"
"github.com/tendermint/tendermint/types"
)

func GetTxHash(txBytes []byte) string {
// return base64.StdEncoding.EncodeToString(tmhash.Sum(txBytes))
return fmt.Sprintf("%X", types.Tx(txBytes).Hash())
}

func ValidateUUID(u string) error {
_, err := uuid.Parse(u)
return err
}