mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 06:25:47 +00:00
added machine keeper method to notarize asset
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
169ea30bf8
commit
b80c50fb5e
@ -109,6 +109,7 @@ import (
|
|||||||
machinemodule "planetmint-go/x/machine"
|
machinemodule "planetmint-go/x/machine"
|
||||||
machinemodulekeeper "planetmint-go/x/machine/keeper"
|
machinemodulekeeper "planetmint-go/x/machine/keeper"
|
||||||
machinemoduletypes "planetmint-go/x/machine/types"
|
machinemoduletypes "planetmint-go/x/machine/types"
|
||||||
|
|
||||||
// this line is used by starport scaffolding # stargate/app/moduleImport
|
// this line is used by starport scaffolding # stargate/app/moduleImport
|
||||||
|
|
||||||
appparams "planetmint-go/app/params"
|
appparams "planetmint-go/app/params"
|
||||||
@ -507,6 +508,7 @@ func New(
|
|||||||
keys[assetmoduletypes.StoreKey],
|
keys[assetmoduletypes.StoreKey],
|
||||||
keys[assetmoduletypes.MemStoreKey],
|
keys[assetmoduletypes.MemStoreKey],
|
||||||
app.GetSubspace(assetmoduletypes.ModuleName),
|
app.GetSubspace(assetmoduletypes.ModuleName),
|
||||||
|
app.MachineKeeper,
|
||||||
)
|
)
|
||||||
assetModule := assetmodule.NewAppModule(appCodec, app.AssetKeeper, app.AccountKeeper, app.BankKeeper)
|
assetModule := assetmodule.NewAppModule(appCodec, app.AssetKeeper, app.AccountKeeper, app.BankKeeper)
|
||||||
|
|
||||||
|
|||||||
@ -14,10 +14,11 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Keeper struct {
|
Keeper struct {
|
||||||
cdc codec.BinaryCodec
|
machineKeeper types.MachineKeeper
|
||||||
storeKey storetypes.StoreKey
|
cdc codec.BinaryCodec
|
||||||
memKey storetypes.StoreKey
|
storeKey storetypes.StoreKey
|
||||||
paramstore paramtypes.Subspace
|
memKey storetypes.StoreKey
|
||||||
|
paramstore paramtypes.Subspace
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ func NewKeeper(
|
|||||||
storeKey,
|
storeKey,
|
||||||
memKey storetypes.StoreKey,
|
memKey storetypes.StoreKey,
|
||||||
ps paramtypes.Subspace,
|
ps paramtypes.Subspace,
|
||||||
|
machineKeeper types.MachineKeeper,
|
||||||
|
|
||||||
) *Keeper {
|
) *Keeper {
|
||||||
// set KeyTable if it has not already been set
|
// set KeyTable if it has not already been set
|
||||||
@ -34,10 +36,11 @@ func NewKeeper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Keeper{
|
return &Keeper{
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
storeKey: storeKey,
|
storeKey: storeKey,
|
||||||
memKey: memKey,
|
memKey: memKey,
|
||||||
paramstore: ps,
|
paramstore: ps,
|
||||||
|
machineKeeper: machineKeeper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package keeper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"planetmint-go/x/asset/types"
|
"planetmint-go/x/asset/types"
|
||||||
|
|
||||||
@ -11,16 +12,18 @@ import (
|
|||||||
func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAsset) (*types.MsgNotarizeAssetResponse, error) {
|
func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAsset) (*types.MsgNotarizeAssetResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
// CHECK IF MSG CREATOR (pub_key) IS ATTESTED MACHINE
|
machine, found := k.machineKeeper.GetMachine(ctx, msg.Creator)
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
return &types.MsgNotarizeAssetResponse{}, errors.New("machine not found")
|
||||||
|
}
|
||||||
|
|
||||||
var asset = types.Asset{
|
var asset = types.Asset{
|
||||||
Hash: msg.CidHash,
|
Hash: msg.CidHash,
|
||||||
Signature: msg.Sign,
|
Signature: msg.Sign,
|
||||||
Pubkey: msg.Creator,
|
Pubkey: machine.IssuerPlanetmint,
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK LOCATION FOR NODE
|
|
||||||
|
|
||||||
// STORE CID_HASH SIGNATURE PUBLIC KEY
|
|
||||||
k.StoreAsset(ctx, asset)
|
k.StoreAsset(ctx, asset)
|
||||||
|
|
||||||
return &types.MsgNotarizeAssetResponse{}, nil
|
return &types.MsgNotarizeAssetResponse{}, nil
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
machineTypes "planetmint-go/x/machine/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
)
|
)
|
||||||
@ -16,3 +18,7 @@ type BankKeeper interface {
|
|||||||
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
||||||
// Methods imported from bank should be defined here
|
// Methods imported from bank should be defined here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MachineKeeper interface {
|
||||||
|
GetMachine(ctx sdk.Context, pubKey string) (val machineTypes.Machine, found bool)
|
||||||
|
}
|
||||||
|
|||||||
28
x/machine/keeper/machine.go
Normal file
28
x/machine/keeper/machine.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package keeper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"planetmint-go/x/machine/types"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (k Keeper) StoreMachine(ctx sdk.Context, machine types.Machine) {
|
||||||
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MachineKey))
|
||||||
|
appendValue := k.cdc.MustMarshal(&machine)
|
||||||
|
store.Set(GetMachineBytes(machine.IssuerPlanetmint), appendValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k Keeper) GetMachine(ctx sdk.Context, pubKey string) (val types.Machine, found bool) {
|
||||||
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MachineKey))
|
||||||
|
machine := store.Get(GetMachineBytes(pubKey))
|
||||||
|
if machine == nil {
|
||||||
|
return val, false
|
||||||
|
}
|
||||||
|
k.cdc.Unmarshal(machine, &val)
|
||||||
|
return val, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMachineBytes(pubKey string) []byte {
|
||||||
|
return []byte(pubKey)
|
||||||
|
}
|
||||||
@ -12,6 +12,8 @@ const (
|
|||||||
|
|
||||||
// MemStoreKey defines the in-memory store key
|
// MemStoreKey defines the in-memory store key
|
||||||
MemStoreKey = "mem_machine"
|
MemStoreKey = "mem_machine"
|
||||||
|
|
||||||
|
MachineKey = "Machine/value/"
|
||||||
)
|
)
|
||||||
|
|
||||||
func KeyPrefix(p string) []byte {
|
func KeyPrefix(p string) []byte {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user