mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
fix: pin added did documents to local ipfs node
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
package keeper
|
||||
|
||||
// deriveAccount is used to derive a wallet account using bip32
|
||||
func (k Keeper) deriveAccount() {
|
||||
}
|
||||
|
||||
// insertAccount places an Account into the did module orm as a Delegation
|
||||
func (k Keeper) insertAccount() {
|
||||
}
|
||||
@@ -1 +1,56 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ipfs/boxo/files"
|
||||
"github.com/ipfs/boxo/path"
|
||||
"github.com/ipfs/kubo/core/coreiface/options"
|
||||
)
|
||||
|
||||
// AddToLocalIPFS adds a file to the local IPFS node
|
||||
func (k Keeper) AddToLocalIPFS(ctx sdk.Context, data files.Node) (string, error) {
|
||||
cid, err := k.ipfsClient.Unixfs().Add(ctx, data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cid.String(), nil
|
||||
}
|
||||
|
||||
// GetFromLocalIPFS gets a file from the local IPFS node
|
||||
func (k Keeper) GetFromLocalIPFS(ctx sdk.Context, cid string) (files.Node, error) {
|
||||
path, err := path.NewPath(cid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return k.ipfsClient.Unixfs().Get(ctx, path)
|
||||
}
|
||||
|
||||
// HasPathInLocalIPFS checks if a file is in the local IPFS node
|
||||
func (k Keeper) HasPathInLocalIPFS(ctx sdk.Context, cid string) (bool, error) {
|
||||
path, err := path.NewPath(cid)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
v, err := k.ipfsClient.Unixfs().Get(ctx, path)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if v == nil {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// PinToLocalIPFS pins a file to the local IPFS node
|
||||
func (k Keeper) PinToLocalIPFS(ctx sdk.Context, cid string, name string) error {
|
||||
path, err := path.NewPath(cid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = k.ipfsClient.Pin().Add(ctx, path, options.Pin.Name(name))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+12
-1
@@ -10,6 +10,7 @@ import (
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/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"
|
||||
@@ -29,7 +30,8 @@ type Keeper struct {
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
StakingKeeper *stakkeeper.Keeper
|
||||
|
||||
authority string
|
||||
authority string
|
||||
ipfsClient *rpc.HttpApi
|
||||
}
|
||||
|
||||
// NewKeeper creates a new poa Keeper instance
|
||||
@@ -47,7 +49,11 @@ func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, ac
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Initialize IPFS client
|
||||
ipfsClient, _ := rpc.NewLocalApi()
|
||||
k := Keeper{
|
||||
ipfsClient: ipfsClient,
|
||||
cdc: cdc,
|
||||
logger: logger,
|
||||
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
|
||||
@@ -64,3 +70,8 @@ func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, ac
|
||||
k.Schema = schema
|
||||
return k
|
||||
}
|
||||
|
||||
// HasIPFSConnection returns true if the IPFS client is initialized
|
||||
func (k *Keeper) HasIPFSConnection() bool {
|
||||
return k.ipfsClient != nil
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
// "github.com/onsonr/sonr/internal/local"
|
||||
"github.com/onsonr/sonr/x/did/types"
|
||||
)
|
||||
|
||||
@@ -28,7 +27,7 @@ func (k Querier) Params(c context.Context, req *types.QueryRequest) (*types.Quer
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.QueryParamsResponse{Params: &p}, nil
|
||||
return &types.QueryParamsResponse{Params: &p, IpfsActive: k.HasIPFSConnection()}, nil
|
||||
}
|
||||
|
||||
// Accounts implements types.QueryServer.
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
didv1 "github.com/onsonr/sonr/api/did/v1"
|
||||
"github.com/onsonr/sonr/x/did/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func (k Keeper) convertProfileToVerification() {
|
||||
}
|
||||
|
||||
func (k Keeper) insertAuthenticationFromCredential() {
|
||||
}
|
||||
|
||||
func (k Keeper) insertControllerFromMotrVault() {
|
||||
}
|
||||
|
||||
func (k Keeper) insertDelegationFromAccount(ctx sdk.Context, address string, label string) (*didv1.Delegation, error) {
|
||||
del, err := k.OrmDB.DelegationTable().GetByControllerAccountLabel(ctx, address, label)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return del, nil
|
||||
}
|
||||
|
||||
func (k Keeper) insertServiceRecord(ctx sdk.Context, msg *types.MsgRegisterService) error {
|
||||
record, err := msg.ExtractServiceRecord()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = k.OrmDB.ServiceRecordTable().Insert(ctx, record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user