planetmint-go/x/machine/keeper/msg_server_attest_machine.go
Lorenz Herzberger 017014317c
adjust msg_attest_machine validation
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
2023-07-25 13:51:38 +02:00

36 lines
884 B
Go

package keeper
import (
"context"
"errors"
"planetmint-go/x/machine/types"
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/btcsuite/btcd/chaincfg"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMachine) (*types.MsgAttestMachineResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
xpubKeyLiquid, err := hdkeychain.NewKeyFromString(msg.Machine.IssuerLiquid)
if err != nil {
return nil, errors.New("invalid liquid key")
}
isValidLiquidKey := xpubKeyLiquid.IsForNet(&chaincfg.MainNetParams)
if !isValidLiquidKey {
return nil, errors.New("invalid liquid key")
}
if msg.Machine.Reissue {
k.Logger(ctx).Info("TODO Implement handle on reissue == true")
}
k.StoreMachine(ctx, *msg.Machine)
k.StoreMachineIndex(ctx, *msg.Machine)
return &types.MsgAttestMachineResponse{}, nil
}