Skip to content

Commit

Permalink
WIP monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
icellan committed Apr 20, 2022
1 parent 1642b24 commit 42f1162
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type (
GDPRCompliance bool `json:"gdpr_compliance" mapstructure:"gdpr_compliance"`
GraphQL *GraphqlConfig `json:"graphql" mapstructure:"graphql"`
Mongo *datastore.MongoDBConfig `json:"mongodb" mapstructure:"mongodb"`
Monitor *MonitorOptions `json:"monitor" mapstructure:"monitor"`
NewRelic *NewRelicConfig `json:"new_relic" mapstructure:"new_relic"`
Notifications *NotificationsConfig `json:"notifications" mapstructure:"notifications"`
Paymail *PaymailConfig `json:"paymail" mapstructure:"paymail"`
Expand Down Expand Up @@ -95,6 +96,15 @@ type (
ServerPath string `json:"server_path" mapstructure:"server_path"` // server path i.e. "/graphql"
}

// MonitorOptions is the configuration for blockchain monitoring
MonitorOptions struct {
Enabled bool `json:"enabled" mapstructure:"enabled"` // true/false
CentrifugeServer string `json:"centrifuge_server" mapstructure:"centrifuge_server"` // how many days in the past should we monitor an address (default: 7)
MonitorDays int `json:"monitor_days" mapstructure:"monitor_days"` // how many days in the past should we monitor an address (default: 7)
FalsePositiveRate float64 `json:"false_positive_rate" mapstructure:"false_positive_rate"` // how many false positives do we except (default: 0.01)
MaxNumberOfDestinations int `json:"max_number_of_destinations" mapstructure:"max_number_of_destinations"` // how many destinations can the filter hold (default: 100,000)
}

// NewRelicConfig is the configuration for New Relic
NewRelicConfig struct {
DomainName string `json:"domain_name" mapstructure:"domain_name"` // used for hostname display
Expand Down
15 changes: 15 additions & 0 deletions config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
"time"

"github.com/BuxOrg/bux/chainstate"

"github.com/BuxOrg/bux"
"github.com/BuxOrg/bux/cachestore"
"github.com/BuxOrg/bux/datastore"
Expand Down Expand Up @@ -203,6 +205,19 @@ func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig) (err er
options = append(options, bux.WithNotifications(appConfig.Notifications.WebhookEndpoint))
}

if appConfig.Monitor != nil && appConfig.Monitor.Enabled {
if appConfig.Monitor.CentrifugeServer == "" {
err = errors.New("CentrifugeServer is required for monitoring to work")
return
}
options = append(options, bux.WithMonitoring(ctx, &chainstate.MonitorOptions{
CentrifugeServer: appConfig.Monitor.CentrifugeServer,
MonitorDays: appConfig.Monitor.MonitorDays,
FalsePositiveRate: appConfig.Monitor.FalsePositiveRate,
MaxNumberOfDestinations: appConfig.Monitor.MaxNumberOfDestinations,
}))
}

// Create the new client
s.Bux, err = bux.NewClient(ctx, options...)

Expand Down
1 change: 1 addition & 0 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 42f1162

Please sign in to comment.