mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"planetmint-go/x/machine/types"
|
|
|
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
"github.com/crgimenes/go-osc"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMachine) (*types.MsgAttestMachineResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
isValidIssuerLiquid := validateIssuerLiquid(msg.Machine.IssuerLiquid)
|
|
if !isValidIssuerLiquid {
|
|
return nil, errors.New("invalid liquid key")
|
|
}
|
|
|
|
if msg.Machine.Reissue {
|
|
k.reissueMachineNFT(msg.Machine)
|
|
}
|
|
|
|
k.StoreMachine(ctx, *msg.Machine)
|
|
k.StoreMachineIndex(ctx, *msg.Machine)
|
|
|
|
return &types.MsgAttestMachineResponse{}, nil
|
|
}
|
|
|
|
func validateIssuerLiquid(issuerLiquid string) bool {
|
|
xpubKeyLiquid, err := hdkeychain.NewKeyFromString(issuerLiquid)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
isValidLiquidKey := xpubKeyLiquid.IsForNet(&chaincfg.MainNetParams)
|
|
return isValidLiquidKey
|
|
}
|
|
|
|
func (k msgServer) reissueMachineNFT(machine *types.Machine) {
|
|
client := osc.NewClient("localhost", 8765)
|
|
msg := osc.NewMessage("/rddl/*")
|
|
msg.Append(machine.Name)
|
|
msg.Append(machine.Ticker)
|
|
msg.Append(machine.Domain)
|
|
msg.Append(machine.Amount)
|
|
msg.Append("1")
|
|
msg.Append(machine.Precision)
|
|
client.Send(msg)
|
|
}
|