diff --git a/app/app.go b/app/app.go index eab152e..8277f61 100644 --- a/app/app.go +++ b/app/app.go @@ -109,6 +109,7 @@ import ( machinemodule "planetmint-go/x/machine" machinemodulekeeper "planetmint-go/x/machine/keeper" machinemoduletypes "planetmint-go/x/machine/types" + // this line is used by starport scaffolding # stargate/app/moduleImport appparams "planetmint-go/app/params" @@ -507,6 +508,7 @@ func New( keys[assetmoduletypes.StoreKey], keys[assetmoduletypes.MemStoreKey], app.GetSubspace(assetmoduletypes.ModuleName), + app.MachineKeeper, ) assetModule := assetmodule.NewAppModule(appCodec, app.AssetKeeper, app.AccountKeeper, app.BankKeeper) diff --git a/x/asset/keeper/keeper.go b/x/asset/keeper/keeper.go index 43e3154..e41c537 100644 --- a/x/asset/keeper/keeper.go +++ b/x/asset/keeper/keeper.go @@ -14,10 +14,11 @@ import ( type ( Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey - paramstore paramtypes.Subspace + machineKeeper types.MachineKeeper + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramstore paramtypes.Subspace } ) @@ -26,6 +27,7 @@ func NewKeeper( storeKey, memKey storetypes.StoreKey, ps paramtypes.Subspace, + machineKeeper types.MachineKeeper, ) *Keeper { // set KeyTable if it has not already been set @@ -34,10 +36,11 @@ func NewKeeper( } return &Keeper{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, - paramstore: ps, + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramstore: ps, + machineKeeper: machineKeeper, } } diff --git a/x/asset/keeper/msg_server_notarize_asset.go b/x/asset/keeper/msg_server_notarize_asset.go index e46a940..aefa71b 100644 --- a/x/asset/keeper/msg_server_notarize_asset.go +++ b/x/asset/keeper/msg_server_notarize_asset.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "errors" "planetmint-go/x/asset/types" @@ -11,16 +12,18 @@ import ( func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAsset) (*types.MsgNotarizeAssetResponse, error) { 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{ Hash: msg.CidHash, Signature: msg.Sign, - Pubkey: msg.Creator, + Pubkey: machine.IssuerPlanetmint, } - // CHECK LOCATION FOR NODE - - // STORE CID_HASH SIGNATURE PUBLIC KEY k.StoreAsset(ctx, asset) return &types.MsgNotarizeAssetResponse{}, nil diff --git a/x/asset/types/expected_keepers.go b/x/asset/types/expected_keepers.go index 6aa6e97..4a38db1 100644 --- a/x/asset/types/expected_keepers.go +++ b/x/asset/types/expected_keepers.go @@ -1,6 +1,8 @@ package types import ( + machineTypes "planetmint-go/x/machine/types" + sdk "github.com/cosmos/cosmos-sdk/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 // Methods imported from bank should be defined here } + +type MachineKeeper interface { + GetMachine(ctx sdk.Context, pubKey string) (val machineTypes.Machine, found bool) +} diff --git a/x/machine/keeper/machine.go b/x/machine/keeper/machine.go new file mode 100644 index 0000000..ae6d8b6 --- /dev/null +++ b/x/machine/keeper/machine.go @@ -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) +} diff --git a/x/machine/types/keys.go b/x/machine/types/keys.go index 115fa81..1d13b47 100644 --- a/x/machine/types/keys.go +++ b/x/machine/types/keys.go @@ -12,6 +12,8 @@ const ( // MemStoreKey defines the in-memory store key MemStoreKey = "mem_machine" + + MachineKey = "Machine/value/" ) func KeyPrefix(p string) []byte {