planetmint-go/x/asset/keeper/msg_server_notarize_asset.go
Jürgen Eckel cb9f762675
Eckelj/fix store resolve issues ()
* added upper and lower case TA resolution testing

* added more detailed error reporting to the ValidateSignature method.
* extended test cases to test and verify these errs and their differences

* fixed CID attestation issue. CIDs are send in web compatible encoding that is not hex encoded and can be utilized without any further decoding on the server side.

* added checks and error handling for the Ta store object storage/loading

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
2023-09-15 10:10:04 +02:00

40 lines
885 B
Go

package keeper
import (
"context"
"errors"
"planetmint-go/util"
"planetmint-go/x/asset/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAsset) (*types.MsgNotarizeAssetResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
_, found := k.machineKeeper.GetMachineIndex(ctx, msg.PubKey)
if !found {
return nil, errors.New("machine not found")
}
hex_pub_key, err := util.GetHexPubKey(msg.PubKey)
if err != nil {
return nil, errors.New("could not convert xpub key to hex pub key")
}
valid, err := util.ValidateSignatureByteMsg([]byte(msg.Hash), msg.Signature, hex_pub_key)
if !valid {
return nil, err
}
var asset = types.Asset{
Hash: msg.Hash,
Signature: msg.Signature,
Pubkey: msg.PubKey,
}
k.StoreAsset(ctx, asset)
return &types.MsgNotarizeAssetResponse{}, nil
}