Squash merge develop into master

This commit is contained in:
Prad Nukala
2024-09-14 14:27:45 -04:00
parent a929e61d01
commit 05bda3d1b2
227 changed files with 56902 additions and 10178 deletions
+87 -9
View File
@@ -5,13 +5,18 @@ import (
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/orm/model/ormdb"
nftkeeper "cosmossdk.io/x/nft/keeper"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
apiv1 "github.com/onsonr/hway/api/did/v1"
"github.com/onsonr/hway/x/did/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/ipfs/kubo/client/rpc"
apiv1 "github.com/onsonr/sonr/api/did/v1"
"github.com/onsonr/sonr/x/did/types"
)
// Keeper defines the middleware keeper.
@@ -26,18 +31,32 @@ type Keeper struct {
Schema collections.Schema
AccountKeeper authkeeper.AccountKeeper
NftKeeper nftkeeper.Keeper
StakingKeeper *stakkeeper.Keeper
authority string
authority string
ipfsClient *rpc.HttpApi
}
// NewKeeper creates a new poa Keeper instance
func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, accKeeper authkeeper.AccountKeeper, logger log.Logger, authority string) Keeper {
func NewKeeper(
cdc codec.BinaryCodec,
storeService storetypes.KVStoreService,
accKeeper authkeeper.AccountKeeper,
nftKeeper nftkeeper.Keeper,
stkKeeper *stakkeeper.Keeper,
logger log.Logger,
authority string,
) Keeper {
logger = logger.With(log.ModuleKey, "x/"+types.ModuleName)
sb := collections.NewSchemaBuilder(storeService)
if authority == "" {
authority = authtypes.NewModuleAddress(govtypes.ModuleName).String()
}
db, err := ormdb.NewModuleDB(&types.ORMModuleSchema, ormdb.ModuleDBOptions{KVStoreService: storeService})
db, err := ormdb.NewModuleDB(
&types.ORMModuleSchema,
ormdb.ModuleDBOptions{KVStoreService: storeService},
)
if err != nil {
panic(err)
}
@@ -45,13 +64,24 @@ func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, ac
if err != nil {
panic(err)
}
// Initialize IPFS client
ipfsClient, _ := rpc.NewLocalApi()
k := Keeper{
cdc: cdc,
logger: logger,
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
ipfsClient: ipfsClient,
cdc: cdc,
logger: logger,
Params: collections.NewItem(
sb,
types.ParamsKey,
"params",
codec.CollValue[types.Params](cdc),
),
authority: authority,
OrmDB: store,
AccountKeeper: accKeeper,
NftKeeper: nftKeeper,
StakingKeeper: stkKeeper,
}
schema, err := sb.Build()
if err != nil {
@@ -61,3 +91,51 @@ func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, ac
k.Schema = schema
return k
}
// IsClaimedServiceOrigin checks if a service origin is unclaimed
func (k Keeper) IsUnclaimedServiceOrigin(ctx sdk.Context, origin string) bool {
rec, _ := k.OrmDB.ServiceRecordTable().GetByOrigin(ctx, origin)
return rec == nil
}
// IsValidServiceOrigin checks if a service origin is valid
func (k Keeper) IsValidServiceOrigin(ctx sdk.Context, origin string) bool {
rec, err := k.OrmDB.ServiceRecordTable().GetByOrigin(ctx, origin)
if err != nil {
return false
}
if rec == nil {
return false
}
return true
}
// VerifyMinimumStake checks if a validator has a minimum stake
func (k Keeper) VerifyMinimumStake(ctx sdk.Context, addr string) bool {
address, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return false
}
addval, err := sdk.ValAddressFromBech32(addr)
if err != nil {
return false
}
del, err := k.StakingKeeper.GetDelegation(ctx, address, addval)
if err != nil {
return false
}
if del.Shares.IsZero() {
return false
}
return del.Shares.IsPositive()
}
// VerifyServicePermissions checks if a service has permission
func (k Keeper) VerifyServicePermissions(
ctx sdk.Context,
addr string,
service string,
permissions string,
) bool {
return false
}