Documentation
¶
Index ¶
- Constants
- func AllNotifyPrefs() []string
- func ConfigDir() string
- func ExpandTildePath(path string) (string, error)
- func LogDir() string
- func RegisterService(cfg ServiceConfig) error
- func StartService() error
- func StopService() error
- func SummarizeFilter(f FilterConfig) string
- func UnregisterService() error
- func ValidateAssetFingerprint(p string) error
- func ValidateDRepID(p string) error
- func ValidatePolicyID(p string) error
- func ValidatePoolID(p string) error
- func ValidateWalletAddr(p string) error
- type APIConfig
- type AdvancedMatchMode
- type AppBinaryFinder
- type AppConfig
- type ApplyResult
- type BinaryFinder
- type ConfigStore
- type Connector
- type FilterConfig
- type LocalStore
- type NetworkConfig
- type NotificationConfig
- type NotificationMonitorConfig
- type NotificationNetworkConfig
- type NotificationPrefs
- type NotificationRateConfig
- type OSManager
- type OutputConfig
- type ServiceConfig
- type ServiceManager
- type ServiceStatus
- type SetupPlan
- type SetupRunner
- type TrayConfig
- type ValidationIssue
- type ValidationIssuesError
Constants ¶
const ( NotificationConfigSchemaVersion = 1 DefaultConnectionStaleSeconds = 90 AlertIncomingTransactions = "incomingTransactions" AlertOutgoingTransactions = "outgoingTransactions" AlertTokenTransfers = "tokenTransfers" AlertBlocksMinted = "blocksMinted" AlertChainRollbacks = "chainRollbacks" AlertPoolParameterChanges = "poolParameterChanges" AlertGovernanceProposals = "governanceProposals" AlertVotesCast = "votesCast" AlertRegistrationChanges = "registrationChanges" AlertAssetActivity = "assetActivity" AlertPolicyActivity = "policyActivity" AlertConnectionIssues = "connectionIssues" )
const ( // NotifyPrefBlocksMinted is the preference key for block minting alerts. NotifyPrefBlocksMinted = "Blocks minted" // NotifyPrefChainRollbacks is the preference key for chain rollback alerts. NotifyPrefChainRollbacks = "Chain rollbacks" // NotifyPrefIncomingTx is the preference key for incoming transaction alerts. NotifyPrefIncomingTx = "Incoming transactions" // NotifyPrefOutgoingTx is the preference key for outgoing transaction alerts. NotifyPrefOutgoingTx = "Outgoing transactions" // NotifyPrefTokenTransfers is the preference key for token transfer alerts. NotifyPrefTokenTransfers = "Token transfers" // NotifyPrefGovProposals is the preference key for new governance proposals. NotifyPrefGovProposals = "New governance proposals" // NotifyPrefVotesCast is the preference key for votes cast alerts. NotifyPrefVotesCast = "Votes cast" // NotifyPrefRegChanges is the preference key for registration change alerts. NotifyPrefRegChanges = "Registration changes" // NotifyPrefPoolParams is the preference key for pool parameter change alerts. NotifyPrefPoolParams = "Pool parameter changes" // NotifyPrefAssetActivity is the preference key for events touching // any followed asset fingerprint (mint, burn, transfer). NotifyPrefAssetActivity = "Asset activity" // NotifyPrefPolicyActivity is the preference key for events touching // any followed minting policy ID. NotifyPrefPolicyActivity = "Policy activity" // NotifyPrefConnectionIssues is the preference key for connection status // alerts. NotifyPrefConnectionIssues = "Connection issues" )
const ( DefaultNotifyRateLimit = 1 DefaultNotifyRateWindow = 5 * time.Second )
Default values for the notification rate limiter. Used when the YAML config omits the fields or leaves them at zero.
Variables ¶
This section is empty.
Functions ¶
func AllNotifyPrefs ¶ added in v0.43.0
func AllNotifyPrefs() []string
AllNotifyPrefs returns the canonical ordering of every NotifyPref* as a fresh slice; the backing array is private so callers cannot corrupt the order. New prefs must be added to allNotifyPrefs so every surface enumerates the same set; TestAllNotifyPrefsExhaustive guards against drift between this list and the NotifyPref* consts.
func ConfigDir ¶
func ConfigDir() string
ConfigDir returns the platform-specific directory for storing configuration files. It can be overridden by the ADDER_TRAY_CONFIG_DIR environment variable.
func ExpandTildePath ¶
ExpandTildePath expands the '~' prefix in a file path to the user's home directory. Returns the original path if no expansion is needed.
func LogDir ¶
func LogDir() string
LogDir returns the platform-specific directory for storing log files. It can be overridden by the ADDER_TRAY_LOG_DIR environment variable.
func RegisterService ¶
func RegisterService(cfg ServiceConfig) error
RegisterService installs adder as a system service using the platform-specific mechanism (systemd user unit, launchd plist, or Windows HKCU Run).
func StartService ¶
func StartService() error
StartService starts the adder system service using the platform-specific mechanism.
func StopService ¶
func StopService() error
StopService stops the adder system service using the platform-specific mechanism.
func SummarizeFilter ¶ added in v0.42.0
func SummarizeFilter(f FilterConfig) string
SummarizeFilter returns a human-readable description of the active matching expression for use in dialogs, notifications, and the wizard's current configuration line. Examples:
"Monitor everything" "Standard: 2 wallets OR 1 DRep OR 1 pool" "No monitoring targets configured"
func UnregisterService ¶
func UnregisterService() error
UnregisterService removes the adder system service.
func ValidateAssetFingerprint ¶ added in v0.42.0
ValidateAssetFingerprint checks that p is a CIP-14 asset fingerprint (asset1-prefixed bech32). Hex is NOT accepted here because the natural hex form of an asset is `<policy>.<assetName>`, not a flat hex string — accepting flat hex would silently let policy IDs pass.
func ValidateDRepID ¶ added in v0.42.0
ValidateDRepID checks that p is a DRep ID (drep1-prefixed bech32 or hex bytes). Surfaces a cross-template hint when the input's HRP matches a different template.
func ValidatePolicyID ¶ added in v0.42.0
ValidatePolicyID checks that p is a 56-character hex string (28-byte minting policy script hash). Length matters: a shorter or longer value is almost certainly the wrong field, so we reject it visibly rather than letting it flow into a never-matching rule.
func ValidatePoolID ¶ added in v0.42.0
ValidatePoolID checks that p is a stake-pool ID (pool1-prefixed bech32 or hex bytes). Surfaces a cross-template hint when the input's HRP matches a different template.
func ValidateWalletAddr ¶ added in v0.42.0
ValidateWalletAddr checks that p is a Cardano payment or stake address (Phase 1: prefix check only — bech32 checksum validation is a follow-up). Surfaces a cross-template hint when the input's HRP matches a different template.
Types ¶
type AdvancedMatchMode ¶ added in v0.43.0
type AdvancedMatchMode string
AdvancedMatchMode selects how a populated target group joins the preceding populated group when the filter expression is built: AND ("all") or OR ("any"). The name is historical — it drives the standard per-group connectors, not a separate "advanced" mode.
const ( AdvancedMatchAll AdvancedMatchMode = "all" AdvancedMatchAny AdvancedMatchMode = "any" )
type AppBinaryFinder ¶
type AppBinaryFinder struct {
// DevLookup, when true, lets Find() fall back to the current working
// directory (development/debug mode). It defaults to false and is never
// set by production code, so shipped builds never resolve a binary from an
// attacker-influenceable CWD.
//
// A build tag (//go:build dev) would compile the fallback out of release
// binaries entirely — a stronger guarantee — but a struct field is used
// here so the dev path stays exercisable under the standard `go test`
// run. The guarantee therefore rests on no production caller ever setting
// this true; keep it that way.
DevLookup bool
}
AppBinaryFinder locates a trusted `adder` binary to register and run as a system service. The resolved path is embedded into the OS service definition (systemd ExecStart, launchd ProgramArguments, Windows command) and executed, so resolution must never trust an attacker-influenceable location.
func (*AppBinaryFinder) Find ¶
func (f *AppBinaryFinder) Find() (string, error)
type AppConfig ¶
type AppConfig struct {
AutoStart bool
CheckUpdatesWeekly bool
// NotifyRateLimit / NotifyRateWindow override the engine's
// notification rate limiter. Zero values resolve to
// DefaultNotifyRateLimit / DefaultNotifyRateWindow at engine
// construction time via TrayConfig.ResolvedNotifyRate.
NotifyRateLimit int
NotifyRateWindow time.Duration
}
AppConfig defines tray-specific application settings.
type ApplyResult ¶ added in v0.42.0
type ApplyResult struct {
// TrayConfig is the snapshot just persisted by Apply, returned to
// callers so they can refresh in-memory caches without re-reading
// from disk. Populated as soon as SaveTrayAtomic succeeds, before
// any service / reconnect step runs. NotifyPrefs map and Filter
// slices alias the persisted snapshot — treat as read-only.
TrayConfig TrayConfig
// BinaryFindErr is non-nil when Finder.Find failed; the service
// was NOT (re)started.
BinaryFindErr error
// ServiceRestartErr is non-nil when the service manager failed
// to (re)start adder; the running process may not reflect the
// new config.
ServiceRestartErr error
// ReconnectErr is non-nil when the post-restart Reconnect to the
// running adder API failed. The config IS persisted and the
// service WAS asked to (re)start; the API just is not reachable
// yet (slow startup, port collision, firewall). Soft so the
// caller can surface it without rolling back the apply.
ReconnectErr error
}
ApplyResult carries the soft (non-fatal) errors from Apply so callers can surface them to the user. Apply still succeeds (config is saved) but the running service may not reflect the change.
func (ApplyResult) HasSoftErrors ¶ added in v0.42.0
func (r ApplyResult) HasSoftErrors() bool
HasSoftErrors reports whether the result carries any non-fatal error worth surfacing to the user.
type BinaryFinder ¶
BinaryFinder defines the interface for locating the adder binary.
type ConfigStore ¶
type ConfigStore interface {
LoadEngine(path string) (config.Config, error)
SaveEngineAtomic(path string, cfg config.Config) error
LoadTray() (TrayConfig, error)
SaveTrayAtomic(cfg TrayConfig) error
}
ConfigStore defines the interface for persisting engine and tray configurations.
type Connector ¶
type Connector interface {
Connect() error
Disconnect()
Reconnect() error
SetAddress(addr string)
SetPort(port uint)
}
Connector defines the interface for managing the API connection.
type FilterConfig ¶
type FilterConfig struct {
MonitorEverything bool `yaml:"monitor_everything"`
DRepMatch AdvancedMatchMode `yaml:"drep_match,omitempty"`
PoolMatch AdvancedMatchMode `yaml:"pool_match,omitempty"`
AssetMatch AdvancedMatchMode `yaml:"asset_match,omitempty"`
PolicyMatch AdvancedMatchMode `yaml:"policy_match,omitempty"`
Wallets []string `yaml:"wallets,omitempty"`
DReps []string `yaml:"dreps,omitempty"`
Pools []string `yaml:"pools,omitempty"`
Assets []string `yaml:"assets,omitempty"`
Policies []string `yaml:"policies,omitempty"`
}
FilterConfig defines the user's monitoring targets. Values within a target group OR together; the per-group *Match connectors join adjacent populated groups with AND or OR. MonitorEverything ignores all target lists and emits one coarse rule per event type. Persisted on TrayConfig so the tray notification engine owns the matching semantics instead of leaking UI state into the sidecar config.
func CloneFilter ¶ added in v0.42.0
func CloneFilter(f FilterConfig) FilterConfig
CloneFilter returns a deep copy of f with fresh slice backing arrays so mutations on one side don't leak to the other.
func (FilterConfig) MatchesNothing ¶ added in v0.43.0
func (f FilterConfig) MatchesNothing() bool
MatchesNothing reports whether f's standard target expression can never match any event because every AND-term joins target groups from incompatible event families. Wallets/Assets/Policies match transaction events, Pools match block events, and DReps match governance events, so an AND across two families (e.g. Pool AND Wallet) is a term no single event can satisfy. The expression is a disjunction (OR) of such AND- terms — see standardFilterMatcher — so it is dead only when EVERY term is dead. MonitorEverything and single-group filters are never dead.
func (FilterConfig) ResolvedAssetMatch ¶ added in v0.43.0
func (f FilterConfig) ResolvedAssetMatch() AdvancedMatchMode
func (FilterConfig) ResolvedDRepMatch ¶ added in v0.43.0
func (f FilterConfig) ResolvedDRepMatch() AdvancedMatchMode
func (FilterConfig) ResolvedPolicyMatch ¶ added in v0.43.0
func (f FilterConfig) ResolvedPolicyMatch() AdvancedMatchMode
func (FilterConfig) ResolvedPoolMatch ¶ added in v0.43.0
func (f FilterConfig) ResolvedPoolMatch() AdvancedMatchMode
type LocalStore ¶
type LocalStore struct {
TrayConfigPath string
}
LocalStore implements ConfigStore using the local filesystem.
func (*LocalStore) LoadEngine ¶
func (s *LocalStore) LoadEngine(path string) (config.Config, error)
func (*LocalStore) LoadTray ¶
func (s *LocalStore) LoadTray() (TrayConfig, error)
func (*LocalStore) SaveEngineAtomic ¶
func (s *LocalStore) SaveEngineAtomic(path string, cfg config.Config) error
func (*LocalStore) SaveTrayAtomic ¶
func (s *LocalStore) SaveTrayAtomic(cfg TrayConfig) error
type NetworkConfig ¶
type NetworkConfig struct {
Name string // mainnet, preprod, preview, dijkstra
CustomAddress string // For custom node connections
CustomPort uint
}
NetworkConfig defines the Cardano network settings.
type NotificationConfig ¶ added in v0.44.0
type NotificationConfig struct {
SchemaVersion int `json:"schemaVersion"`
Network NotificationNetworkConfig `json:"network"`
Monitor NotificationMonitorConfig `json:"monitor"`
Alerts map[string]bool `json:"alerts"`
RateLimit NotificationRateConfig `json:"rateLimit"`
ConnectionStaleSeconds int `json:"connectionStaleSeconds"`
}
NotificationConfig is the UI-neutral configuration consumed by headless notification outputs. It deliberately uses stable machine keys rather than the tray's user-facing labels so non-Go clients can safely persist it.
func DecodeNotificationConfig ¶ added in v0.44.0
func DecodeNotificationConfig(r io.Reader) (NotificationConfig, error)
func DefaultNotificationConfig ¶ added in v0.44.0
func DefaultNotificationConfig() NotificationConfig
func ReadNotificationConfig ¶ added in v0.44.0
func ReadNotificationConfig(path string) (NotificationConfig, error)
func (NotificationConfig) NetworkLabel ¶ added in v0.44.0
func (c NotificationConfig) NetworkLabel() string
func (NotificationConfig) SetupPlan ¶ added in v0.44.0
func (c NotificationConfig) SetupPlan() SetupPlan
func (NotificationConfig) ValidationIssues ¶ added in v0.44.0
func (c NotificationConfig) ValidationIssues() []ValidationIssue
type NotificationMonitorConfig ¶ added in v0.44.0
type NotificationMonitorConfig struct {
Everything bool `json:"everything"`
Wallets []string `json:"wallets,omitempty"`
DReps []string `json:"dreps,omitempty"`
Pools []string `json:"pools,omitempty"`
Assets []string `json:"assets,omitempty"`
Policies []string `json:"policies,omitempty"`
DRepMatch AdvancedMatchMode `json:"drepMatch,omitempty"`
PoolMatch AdvancedMatchMode `json:"poolMatch,omitempty"`
AssetMatch AdvancedMatchMode `json:"assetMatch,omitempty"`
PolicyMatch AdvancedMatchMode `json:"policyMatch,omitempty"`
}
type NotificationNetworkConfig ¶ added in v0.44.0
type NotificationPrefs ¶
NotificationPrefs defines the user's desktop alert preferences.
type NotificationRateConfig ¶ added in v0.44.0
type OSManager ¶
type OSManager struct {
// AutoStart overrides the autostart setting when non-nil.
// When nil, EnsureRegistered attempts to read AutoStart from the persisted
// TrayConfig, defaulting to false if unavailable.
AutoStart *bool
// contains filtered or unexported fields
}
OSManager implements ServiceManager by delegating to platform-specific logic, ensuring operations are idempotent.
func (*OSManager) EnsureRegistered ¶
func (*OSManager) EnsureRunning ¶
func (*OSManager) RestartIfConfigChanged ¶
func (*OSManager) Status ¶
func (m *OSManager) Status() (ServiceStatus, error)
type OutputConfig ¶
type OutputConfig struct {
Type string // log, webhook, telegram
Config map[string]string // Key-value pairs for plugin options
}
OutputConfig defines the external event destination.
type ServiceConfig ¶
type ServiceConfig struct {
// BinaryPath is the absolute path to the adder binary.
BinaryPath string
// ConfigPath is the optional path to the adder configuration file.
ConfigPath string
// LogDir is the directory for log output (used by platforms that
// do not support journal-style logging).
LogDir string
// AutoStart indicates whether the service should start automatically
// on system reboot / login.
AutoStart bool
}
ServiceConfig holds the configuration needed for service registration.
func (ServiceConfig) Validate ¶
func (c ServiceConfig) Validate() error
Validate checks that the ServiceConfig contains the minimum required fields.
type ServiceManager ¶
type ServiceManager interface {
EnsureRegistered(binPath, cfgPath string) error
EnsureRunning() error
RestartIfConfigChanged(binPath, cfgPath string) error
Stop() error
Status() (ServiceStatus, error)
}
ServiceManager defines the interface for idempotent service lifecycle management.
type ServiceStatus ¶
type ServiceStatus int
ServiceStatus represents the state of the system service.
const ( // ServiceNotRegistered indicates no service is installed. ServiceNotRegistered ServiceStatus = iota // ServiceRegistered indicates the service is installed but not running. ServiceRegistered // ServiceRunning indicates the service is installed and currently running. ServiceRunning )
func ServiceStatusCheck ¶
func ServiceStatusCheck() (ServiceStatus, error)
ServiceStatusCheck returns the current status of the adder system service.
func (ServiceStatus) String ¶
func (s ServiceStatus) String() string
String returns a human-readable representation of the ServiceStatus.
type SetupPlan ¶
type SetupPlan struct {
Network NetworkConfig
Filter FilterConfig
Output OutputConfig
API APIConfig
Notify NotificationPrefs
App AppConfig
}
SetupPlan represents the desired configuration state of the Adder ecosystem, decoupled from UI display strings and engine-specific map structures.
func ClonePlan ¶ added in v0.43.0
ClonePlan returns a deep copy of p whose reference-typed fields (Filter slices, Notify map, Output.Config map) are independent, so a caller can mutate its copy without touching the source. Centralised here next to CloneFilter so adding a new reference-typed field to SetupPlan updates exactly one place.
func SetupPlanFromEngineConfig ¶
func SetupPlanFromEngineConfig(c config.Config, tray TrayConfig) SetupPlan
SetupPlanFromEngineConfig reconstructs a SetupPlan from an existing engine configuration and tray settings.
type SetupRunner ¶
type SetupRunner struct {
Store ConfigStore
Service ServiceManager
Conn Connector
Finder BinaryFinder
}
SetupRunner orchestrates the application of a SetupPlan.
func (*SetupRunner) Apply ¶
func (r *SetupRunner) Apply( ctx context.Context, plan SetupPlan, ) (ApplyResult, error)
type TrayConfig ¶
type TrayConfig struct {
APIAddress string `yaml:"api_address"`
APIPort uint `yaml:"api_port"`
AdderConfig string `yaml:"adder_config"`
AutoStart bool `yaml:"auto_start"`
NotifyPrefs map[string]bool `yaml:"notify_prefs"`
Filter FilterConfig `yaml:"filter,omitempty"`
// NotifyRateLimit caps emitted notifications per
// NotifyRateWindow. Matches beyond the cap are coalesced into a
// single "Multiple events occurred" batch fired at the window
// boundary. A non-positive value disables the limiter (every
// match fires immediately). Zero (the YAML default for omitted
// fields) is resolved to DefaultNotifyRateLimit at load time.
NotifyRateLimit int `yaml:"notify_rate_limit,omitempty"`
// NotifyRateWindow is the limiter window. Zero is resolved to
// DefaultNotifyRateWindow at load time.
NotifyRateWindow time.Duration `yaml:"notify_rate_window,omitempty"`
// SkippedVersion records a release tag the user chose to skip in the
// update checker.
SkippedVersion string `yaml:"skipped_version,omitempty"`
// CheckUpdatesWeekly controls whether adder-tray checks for updates
// automatically once a week.
CheckUpdatesWeekly bool `yaml:"check_updates_weekly"`
// LastUpdateCheck records the timestamp of the last update check.
LastUpdateCheck time.Time `yaml:"last_update_check,omitempty"`
}
TrayConfig holds the configuration for the adder-tray application. Filter is the authoritative source of monitoring targets — the sidecar engine config carries no per-target lists because the tray notification engine owns target matching semantics.
func (TrayConfig) ResolvedNotifyRate ¶ added in v0.42.0
func (c TrayConfig) ResolvedNotifyRate() (int, time.Duration)
ResolvedNotifyRate returns the rate-limit + window the engine should use, substituting defaults for zero values. A negative NotifyRateLimit is passed through (disables the limiter) so power users can opt out of coalescing entirely.
type ValidationIssue ¶ added in v0.44.0
ValidationIssue is stable JSON output for configuration frontends.
type ValidationIssuesError ¶ added in v0.44.0
type ValidationIssuesError struct {
Issues []ValidationIssue
}
func (ValidationIssuesError) Error ¶ added in v0.44.0
func (e ValidationIssuesError) Error() string