mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 06:25:47 +00:00
added get/store asset keeper methods
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
28cdbb7719
commit
2514f20649
29
x/asset/keeper/asset.go
Normal file
29
x/asset/keeper/asset.go
Normal file
@ -0,0 +1,29 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"planetmint-go/x/asset/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func (k Keeper) StoreAsset(ctx sdk.Context, asset types.Asset) {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
|
||||
appendValue := k.cdc.MustMarshal(&asset)
|
||||
store.Set(GetAssetHashBytes(asset.Hash), appendValue)
|
||||
}
|
||||
|
||||
func (k Keeper) GetAsset(ctx sdk.Context, hash string) (val types.Asset, found bool) {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
|
||||
asset := store.Get(GetAssetHashBytes(hash))
|
||||
if asset == nil {
|
||||
return val, false
|
||||
}
|
||||
k.cdc.MustUnmarshal(asset, &val)
|
||||
return val, true
|
||||
}
|
||||
|
||||
func GetAssetHashBytes(hash string) []byte {
|
||||
bz := []byte(hash)
|
||||
return bz
|
||||
}
|
||||
@ -11,14 +11,17 @@ import (
|
||||
func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAsset) (*types.MsgNotarizeAssetResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
// TODO: Handling the message
|
||||
_ = ctx
|
||||
|
||||
// CHECK IF MSG CREATOR (pub_key) IS ATTESTED MACHINE
|
||||
var asset = types.Asset{
|
||||
Hash: msg.CidHash,
|
||||
Signature: msg.Sign,
|
||||
Pubkey: msg.Creator,
|
||||
}
|
||||
|
||||
// CHECK SHORTENED URL FOR NODE
|
||||
// CHECK LOCATION FOR NODE
|
||||
|
||||
// STORE CID_HASH SIGNATURE PUBLIC KEY
|
||||
k.StoreAsset(ctx, asset)
|
||||
|
||||
return &types.MsgNotarizeAssetResponse{}, nil
|
||||
}
|
||||
|
||||
@ -12,6 +12,8 @@ const (
|
||||
|
||||
// MemStoreKey defines the in-memory store key
|
||||
MemStoreKey = "mem_asset"
|
||||
|
||||
AssetKey = "Asset/value/"
|
||||
)
|
||||
|
||||
func KeyPrefix(p string) []byte {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user