mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-04 10:21:40 +00:00
feature/migrate models (#16)
* feat: add new supported attestation formats to genesis * feat: refactor keyType to keytype enum * refactor: remove unused imports and code * refactor: update main.go to use src package * refactor: move web-related structs from to * refactor: move client middleware package to root * refactor: remove unused IndexedDB dependency * feat: update worker implementation to use * feat: add Caddyfile and Caddy configuration for vault service * refactor(config): move keyshare and address to Motr config * fix: validate service origin in AllocateVault * chore: remove IndexedDB configuration * feat: add support for IPNS-based vault access
This commit is contained in:
+60
-9
@@ -1,7 +1,9 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/ipfs/kubo/client/rpc"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/onsonr/sonr/x/did/types"
|
||||
@@ -14,18 +16,26 @@ type Context struct {
|
||||
Peer *peer.Peer
|
||||
}
|
||||
|
||||
func (k Keeper) CurrentCtx(goCtx context.Context) Context {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
peer, _ := peer.FromContext(goCtx)
|
||||
return Context{SDKCtx: ctx, Peer: peer, Keeper: k}
|
||||
// AverageBlockTime returns the average block time in seconds
|
||||
func (c Context) AverageBlockTime() float64 {
|
||||
return float64(c.SDK().BlockTime().Sub(c.SDK().BlockTime()).Seconds())
|
||||
}
|
||||
|
||||
func (c Context) Params() *types.Params {
|
||||
return c.Keeper.GetParams(c.SDK())
|
||||
// GetExpirationBlockHeight returns the block height at which the given duration will have passed
|
||||
func (c Context) CalculateExpiration(duration time.Duration) int64 {
|
||||
return c.SDKCtx.BlockHeight() + int64(duration.Seconds()/c.AverageBlockTime())
|
||||
}
|
||||
|
||||
func (c Context) SDK() sdk.Context {
|
||||
return c.SDKCtx
|
||||
// IPFSConnected returns true if the IPFS client is initialized
|
||||
func (c Context) IPFSConnected() bool {
|
||||
if c.Keeper.ipfsClient == nil {
|
||||
ipfsClient, err := rpc.NewLocalApi()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
c.Keeper.ipfsClient = ipfsClient
|
||||
}
|
||||
return c.Keeper.ipfsClient != nil
|
||||
}
|
||||
|
||||
func (c Context) IsAnonymous() bool {
|
||||
@@ -35,9 +45,50 @@ func (c Context) IsAnonymous() bool {
|
||||
return c.Peer.Addr == nil
|
||||
}
|
||||
|
||||
func (c Context) Params() *types.Params {
|
||||
p, err := c.Keeper.Params.Get(c.SDK())
|
||||
if err != nil {
|
||||
p = types.DefaultParams()
|
||||
}
|
||||
params := p.ActiveParams(c.IPFSConnected())
|
||||
return ¶ms
|
||||
}
|
||||
|
||||
func (c Context) PeerID() string {
|
||||
if c.Peer == nil {
|
||||
return ""
|
||||
}
|
||||
return c.Peer.Addr.String()
|
||||
}
|
||||
|
||||
func (c Context) SDK() sdk.Context {
|
||||
return c.SDKCtx
|
||||
}
|
||||
|
||||
// ValidateOrigin checks if a service origin is valid
|
||||
func (c Context) ValidateOrigin(origin string) error {
|
||||
if origin == "localhost" {
|
||||
return nil
|
||||
}
|
||||
return types.ErrInvalidServiceOrigin
|
||||
}
|
||||
|
||||
// VerifyMinimumStake checks if a validator has a minimum stake
|
||||
func (c Context) VerifyMinimumStake(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 := c.Keeper.StakingKeeper.GetDelegation(c.SDK(), address, addval)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if del.Shares.IsZero() {
|
||||
return false
|
||||
}
|
||||
return del.Shares.IsPositive()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user