mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
feature/1118 formatter interface creation (#1147)
- **refactor: improve query service code structure** - **chore(deps): update protoc-gen-go-grpc to v1.5.1** - **refactor: replace package with** - **chore(deps): update dependencies** - **fix(deps): update webauthn to v0.11.2** - **refactor: remove onsonr.sonr from package names** - **refactor: improve code readability in vault querier** - **refactor: simplify controller initialization** - **fix: remove unnecessary function for counter data** - **refactor: update button component file paths** - **refactor(authentication): simplify register page** - **fix: update error filenames in marketing section templates**
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"cosmossdk.io/log"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ipfs/boxo/path"
|
||||
"github.com/ipfs/kubo/client/rpc"
|
||||
|
||||
"github.com/onsonr/sonr/x/vault/types"
|
||||
)
|
||||
@@ -41,14 +40,7 @@ func (k *Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
|
||||
|
||||
// IPFSConnected returns true if the IPFS client is initialized
|
||||
func (c Keeper) IPFSConnected() bool {
|
||||
if c.ipfsClient == nil {
|
||||
ipfsClient, err := rpc.NewLocalApi()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
c.ipfsClient = ipfsClient
|
||||
}
|
||||
return c.ipfsClient != nil
|
||||
return c.hasIpfsConn
|
||||
}
|
||||
|
||||
// HasPathInIPFS checks if a file is in the local IPFS node
|
||||
|
||||
@@ -33,7 +33,8 @@ type Keeper struct {
|
||||
|
||||
authority string
|
||||
|
||||
ipfsClient *rpc.HttpApi
|
||||
ipfsClient *rpc.HttpApi
|
||||
hasIpfsConn bool
|
||||
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
DIDKeeper didkeeper.Keeper
|
||||
@@ -50,6 +51,7 @@ func NewKeeper(
|
||||
didKeeper didkeeper.Keeper,
|
||||
macaroonKeeper macaroonkeeper.Keeper,
|
||||
) Keeper {
|
||||
var hasIpfs bool
|
||||
logger = logger.With(log.ModuleKey, "x/"+types.ModuleName)
|
||||
|
||||
sb := collections.NewSchemaBuilder(storeService)
|
||||
@@ -70,7 +72,11 @@ func NewKeeper(
|
||||
|
||||
ipfsClient, err := rpc.NewLocalApi()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
hasIpfs = false
|
||||
}
|
||||
|
||||
if ipfsClient != nil {
|
||||
hasIpfs = true
|
||||
}
|
||||
|
||||
k := Keeper{
|
||||
@@ -82,8 +88,9 @@ func NewKeeper(
|
||||
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
|
||||
OrmDB: store,
|
||||
|
||||
ipfsClient: ipfsClient,
|
||||
authority: authority,
|
||||
ipfsClient: ipfsClient,
|
||||
hasIpfsConn: hasIpfs,
|
||||
authority: authority,
|
||||
}
|
||||
|
||||
schema, err := sb.Build()
|
||||
|
||||
+12
-16
@@ -2,6 +2,7 @@ package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -59,33 +60,28 @@ func (k Querier) Allocate(goCtx context.Context, req *types.QueryAllocateRequest
|
||||
// 1. Get current schema
|
||||
sch, err := k.currentSchema(ctx)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
ctx.Logger().Error(fmt.Sprintf("Error getting current schema: %s", err.Error()))
|
||||
return nil, types.ErrInvalidSchema.Wrap(err.Error())
|
||||
}
|
||||
shares, err := mpc.GenerateKeyshares()
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
con, err := didtypes.NewController(ctx, shares)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
usrKs, err := con.ExportUserKs()
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
ctx.Logger().Error(fmt.Sprintf("Error generating keyshares: %s", err.Error()))
|
||||
return nil, types.ErrInvalidSchema.Wrap(err.Error())
|
||||
}
|
||||
v, err := types.NewVault(usrKs, con.SonrAddress(), con.ChainID(), sch)
|
||||
|
||||
con, err := didtypes.NewController(shares)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
ctx.Logger().Error(fmt.Sprintf("Error creating controller: %s", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
v, err := types.NewVault("", con.SonrAddress(), con.ChainID(), sch)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(fmt.Sprintf("Error creating vault: %s", err.Error()))
|
||||
return nil, types.ErrInvalidSchema.Wrap(err.Error())
|
||||
}
|
||||
cid, err := k.ipfsClient.Unixfs().Add(context.Background(), v.FS)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
ctx.Logger().Error(fmt.Sprintf("Error adding to IPFS: %s", err.Error()))
|
||||
return nil, types.ErrVaultAssembly.Wrap(err.Error())
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,9 @@ import (
|
||||
func DefaultParams() Params {
|
||||
// TODO:
|
||||
return Params{
|
||||
IpfsActive: true,
|
||||
Schema: DefaultSchema(),
|
||||
IpfsActive: true,
|
||||
LocalRegistrationEnabled: true,
|
||||
Schema: DefaultSchema(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -652,6 +652,7 @@ func _Query_Sync_Handler(srv interface{}, ctx context.Context, dec func(interfac
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Query_serviceDesc = _Query_serviceDesc
|
||||
var _Query_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "vault.v1.Query",
|
||||
HandlerType: (*QueryServer)(nil),
|
||||
|
||||
@@ -236,6 +236,7 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Msg_serviceDesc = _Msg_serviceDesc
|
||||
var _Msg_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "vault.v1.Msg",
|
||||
HandlerType: (*MsgServer)(nil),
|
||||
|
||||
Reference in New Issue
Block a user