mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-07-04 03:32:30 +00:00
Improve communication to liquid issuance service (#58)
* added OSC response listener with logging added Machine NFT issuance for each machine attestation process added CID and Planetmint Issuer extPublicKey to the issuance process removed type inconsistency * added machine NFT creation criteria * [toml] Parsing does not allow sub-structs * made OSC listener port configurable Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Signed-off-by: Julian Strobl <jmastr@mailbox.org> Co-authored-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
parent
70b61372d2
commit
01ef2dbfd0
@ -537,6 +537,7 @@ func New(
|
|||||||
app.GetSubspace(machinemoduletypes.ModuleName),
|
app.GetSubspace(machinemoduletypes.ModuleName),
|
||||||
)
|
)
|
||||||
machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper)
|
machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper)
|
||||||
|
go app.MachineKeeper.IssueResponseHandler(logger)
|
||||||
|
|
||||||
app.AssetKeeper = *assetmodulekeeper.NewKeeper(
|
app.AssetKeeper = *assetmodulekeeper.NewKeeper(
|
||||||
appCodec,
|
appCodec,
|
||||||
|
@ -238,7 +238,7 @@ func (a appCreator) newApp(
|
|||||||
|
|
||||||
// Get [planetmint] section from app.toml
|
// Get [planetmint] section from app.toml
|
||||||
plmntConfig := planetmintconfig.GetConfig()
|
plmntConfig := planetmintconfig.GetConfig()
|
||||||
plmntConfig.SetWatchmenConfig(appOpts.Get("planetmint"))
|
plmntConfig.SetPlanetmintConfig(appOpts.Get("planetmint"))
|
||||||
|
|
||||||
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
|
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
|
||||||
cache = store.NewCommitKVStoreCacheManager()
|
cache = store.NewCommitKVStoreCacheManager()
|
||||||
|
@ -2,7 +2,6 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,19 +11,16 @@ const DefaultConfigTemplate = `
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
[planetmint]
|
[planetmint]
|
||||||
watchmen-endpoint = "{{ .PlmntConfig.WatchmenConfig.Endpoint }}"
|
osc-service-port = {{ .PlmntConfig.OSCServicePort }}
|
||||||
watchmen-port = {{ .PlmntConfig.WatchmenConfig.Port }}
|
watchmen-endpoint = "{{ .PlmntConfig.WatchmenEndpoint }}"
|
||||||
|
watchmen-port = {{ .PlmntConfig.WatchmenPort }}
|
||||||
`
|
`
|
||||||
|
|
||||||
// Config defines Planetmint's top level configuration
|
// Config defines Planetmint's top level configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
WatchmenConfig WatchmenConfig `mapstructure:"watchmen-config" json:"watchmen-config"`
|
OSCServicePort int `mapstructure:"osc-service-port" json:"osc-service-port"`
|
||||||
}
|
WatchmenEndpoint string `mapstructure:"watchmen-endpoint" json:"watchmen-endpoint"`
|
||||||
|
WatchmenPort int `mapstructure:"watchmen-port" json:"watchmen-port"`
|
||||||
// WatchmenConfig defines Planetmint's watchmen configuration
|
|
||||||
type WatchmenConfig struct {
|
|
||||||
Endpoint string `mapstructure:"watchmen-endpoint" json:"watchmen-endpoint"`
|
|
||||||
Port int `mapstructure:"watchmen-port" json:"watchmen-port"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cosmos-sdk wide global singleton
|
// cosmos-sdk wide global singleton
|
||||||
@ -36,10 +32,9 @@ var (
|
|||||||
// DefaultConfig returns planetmint's default configuration.
|
// DefaultConfig returns planetmint's default configuration.
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
WatchmenConfig: WatchmenConfig{
|
OSCServicePort: 8766,
|
||||||
Endpoint: "localhost",
|
WatchmenEndpoint: "lab.r3c.network",
|
||||||
Port: 7401,
|
WatchmenPort: 7401,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,15 +46,14 @@ func GetConfig() *Config {
|
|||||||
return plmntConfig
|
return plmntConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWatchmenConfig sets Planetmint's watchmen configuration
|
// SetWatchmenConfig sets Planetmint's configuration
|
||||||
func (config *Config) SetWatchmenConfig(watchmenConfig interface{}) {
|
func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
|
||||||
jsonWatchmenConfig, err := json.Marshal(watchmenConfig)
|
jsonConfig, err := json.Marshal(planetmintconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonWatchmenConfig, &config.WatchmenConfig)
|
err = json.Unmarshal(jsonConfig, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Printf("%+v\n", config.WatchmenConfig.Port)
|
|
||||||
}
|
}
|
||||||
|
1
go.mod
1
go.mod
@ -19,6 +19,7 @@ require (
|
|||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2
|
||||||
|
github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5
|
||||||
github.com/spf13/cast v1.5.0
|
github.com/spf13/cast v1.5.0
|
||||||
github.com/spf13/cobra v1.6.1
|
github.com/spf13/cobra v1.6.1
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
|
2
go.sum
2
go.sum
@ -669,6 +669,8 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
|
|||||||
github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw=
|
github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw=
|
||||||
github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
|
github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
|
||||||
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
||||||
|
github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5 h1:fqwINudmUrvGCuw+e3tedZ2UJ0hklSw6t8UPomctKyQ=
|
||||||
|
github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5/go.mod h1:lqMjoCs0y0GoRRujSPZRBaGb4c5ER6TfkFKSClxkMbY=
|
||||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||||
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
|
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
|
||||||
|
29
x/machine/keeper/issue_response.go
Normal file
29
x/machine/keeper/issue_response.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package keeper
|
||||||
|
|
||||||
|
import (
|
||||||
|
config "planetmint-go/config"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
|
"github.com/hypebeast/go-osc/osc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (k Keeper) IssueResponseHandler(logger log.Logger) {
|
||||||
|
conf := config.GetConfig()
|
||||||
|
addr := "0.0.0.0:" + strconv.FormatInt(int64(conf.OSCServicePort), 10)
|
||||||
|
d := osc.NewStandardDispatcher()
|
||||||
|
err := d.AddMsgHandler("/rddl/resp", func(msg *osc.Message) {
|
||||||
|
logger.Info("Issue Response: " + msg.String())
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Unable to add handler to OSC service.")
|
||||||
|
}
|
||||||
|
server := &osc.Server{
|
||||||
|
Addr: addr,
|
||||||
|
Dispatcher: d,
|
||||||
|
}
|
||||||
|
err = server.ListenAndServe()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Unable to start the OSC service.")
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package keeper
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
config "planetmint-go/config"
|
config "planetmint-go/config"
|
||||||
"planetmint-go/x/machine/types"
|
"planetmint-go/x/machine/types"
|
||||||
@ -14,6 +15,12 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (k msgServer) isNFTCreationRequest(machine *types.Machine) bool {
|
||||||
|
if !machine.GetReissue() && machine.GetAmount() == 1 && machine.GetPrecision() == 8 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMachine) (*types.MsgAttestMachineResponse, error) {
|
func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMachine) (*types.MsgAttestMachineResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
@ -21,11 +28,10 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
|
|||||||
if !isValidIssuerLiquid {
|
if !isValidIssuerLiquid {
|
||||||
return nil, errors.New("invalid liquid key")
|
return nil, errors.New("invalid liquid key")
|
||||||
}
|
}
|
||||||
|
if k.isNFTCreationRequest(msg.Machine) {
|
||||||
if msg.Machine.Reissue {
|
err := k.issueMachineNFT(msg.Machine)
|
||||||
err := k.reissueMachine(msg.Machine)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("an error occured while reissuning the machine")
|
return nil, errors.New("an error occurred while issuing the machine NFT")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,16 +50,22 @@ func validateIssuerLiquid(issuerLiquid string) bool {
|
|||||||
return isValidLiquidKey
|
return isValidLiquidKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k msgServer) reissueMachine(machine *types.Machine) error {
|
func (k msgServer) issueMachineNFT(machine *types.Machine) error {
|
||||||
conf := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
client := osc.NewClient(conf.WatchmenConfig.Endpoint, conf.WatchmenConfig.Port)
|
client := osc.NewClient(conf.WatchmenEndpoint, conf.WatchmenPort)
|
||||||
msg := osc.NewMessage("/rddl/*")
|
machine_precision := strconv.FormatInt(int64(machine.Precision), 10)
|
||||||
|
machine_amount := strconv.FormatInt(int64(machine.Amount), 10)
|
||||||
|
|
||||||
|
msg := osc.NewMessage("/rddl/issue")
|
||||||
msg.Append(machine.Name)
|
msg.Append(machine.Name)
|
||||||
msg.Append(machine.Ticker)
|
msg.Append(machine.Ticker)
|
||||||
msg.Append(machine.Domain)
|
msg.Append(machine.Domain)
|
||||||
msg.Append(int32(machine.Amount))
|
msg.Append(machine_amount)
|
||||||
msg.Append("1")
|
msg.Append("1")
|
||||||
msg.Append(int32(machine.Precision))
|
msg.Append(machine_precision)
|
||||||
|
msg.Append(machine.Metadata.GetAdditionalDataCID())
|
||||||
|
msg.Append(machine.GetIssuerPlanetmint())
|
||||||
err := client.Send(msg)
|
err := client.Send(msg)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user