diff --git a/internal/plugin/cln4go_plugin.go b/internal/plugin/cln4go_plugin.go index 386be52..9ccc673 100644 --- a/internal/plugin/cln4go_plugin.go +++ b/internal/plugin/cln4go_plugin.go @@ -23,7 +23,7 @@ func ConfigureCLNPlugin[T MetricsPluginState](state T) (*cln4go.Plugin[T], error "Disable the usage of proxy in case only for the go-lnmmetrics.reporter", false) plugin.RegisterNotification("shutdown", &OnShoutdown[T]{}) - plugin.RegisterRPCMethod("metric_one", "", "return the metrics calculated by the plugin", NewMetricPlugin[T]()) + plugin.RegisterRPCMethod("raw-local-score", "", "return the local reputation raw data collected by the plugin", NewRawLocalScoreRPC[T]()) // FIXME: register the force rpc command only in developer mode plugin.RegisterRPCMethod("lnmetrics-force-update", "", "trigget the update to the server (caution)", &ForceUpdateRPC[T]{}) plugin.RegisterRPCMethod("lnmetrics-info", "", "return the information regarding the lnmetrics plugin", &LNMetricsInfoRPC[T]{}) @@ -69,7 +69,7 @@ func (self *LNMetricsInfoRPC[T]) Call(plugin *cln4go.Plugin[T], payload map[stri goInfo := sysinfo.Go() resp := info{ Name: "go-lnmetrics.reporter", - Version: "v0.0.5-rc1", + Version: "v0.0.5-rc2", LangVersion: goInfo.Version, Architecture: goInfo.Arch, MaxProcs: goInfo.MaxProcs, diff --git a/internal/plugin/diagnostic.go b/internal/plugin/diagnostic.go index 3e0394d..7af410a 100644 --- a/internal/plugin/diagnostic.go +++ b/internal/plugin/diagnostic.go @@ -7,54 +7,30 @@ import ( cln4go "github.com/vincenzopalazzo/cln4go/plugin" ) -type MetricOneRpcMethod[T MetricsPluginState] struct{} +type RawLocalScoreRPC[T MetricsPluginState] struct{} -func NewMetricPlugin[T MetricsPluginState]() *MetricOneRpcMethod[T] { - return &MetricOneRpcMethod[T]{} +func NewRawLocalScoreRPC[T MetricsPluginState]() *RawLocalScoreRPC[T] { + return &RawLocalScoreRPC[T]{} } -func (instance *MetricOneRpcMethod[T]) Call(plugin *cln4go.Plugin[T], payload map[string]any) (map[string]any, error) { - // FIXME: take variable from the payload. +func (instance *RawLocalScoreRPC[T]) Call(plugin *cln4go.Plugin[T], payload map[string]any) (map[string]any, error) { metricOne, found := plugin.GetState().GetMetrics()[MetricOneID] var result map[string]any if !found { return nil, fmt.Errorf("Metric with id %d not found", 1) } - startPeriod, startFound := payload["start"] - //endPeriod, endFound := payload["end"] - - if !startFound { - return nil, fmt.Errorf("method argument missing: need to specify the start period") - } - - if startPeriod.(string) == "now" { - // FIXME: improve the metric API to include the ToMap call - resultStr, err := json.Marshal(metricOne) - if err != nil { - return nil, err - } - - if err != json.Unmarshal(resultStr, &result) { - return nil, err - } - return result, nil + // FIXME: improve the metric API to include the ToMap call + resultStr, err := json.Marshal(metricOne) + if err != nil { + return nil, err } - if startPeriod.(string) == "last" { - jsonValue, err := plugin.GetState().GetStorage().LoadLastMetricOne() - if err != nil { - return nil, err - } - - if err := json.Unmarshal([]byte(*jsonValue), &result); err != nil { - return nil, err - } - - return result, nil + if err != json.Unmarshal(resultStr, &result) { + return nil, err } - return nil, fmt.Errorf("We don't support the filter operation right now") + return result, nil } // ForceUpdateRPC enable the force update command