Skip to content

Commit b130b09

Browse files
Add truncate param to indexesToString (#26)
* add truncate arg * fix lint
1 parent f001efc commit b130b09

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

internal/adapters/notifier/notifier.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex,
127127
status = Resolved
128128
isBanner = false
129129
} else {
130-
title = fmt.Sprintf("Validator(s) Offline: %s", indexesToString(validators))
131-
body = fmt.Sprintf("❌ Validator(s) %s are not attesting on %s.", indexesToString(validators), n.Network)
130+
title = fmt.Sprintf("Validator(s) Offline: %s", indexesToString(validators, true))
131+
body = fmt.Sprintf("❌ Validator(s) %s are not attesting on %s.", indexesToString(validators, true), n.Network)
132132
priority = High
133133
status = Triggered
134134
isBanner = true
@@ -149,8 +149,8 @@ func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex,
149149

150150
// SendValidatorsSlashedNot sends a notification when one or more validators are slashed.
151151
func (n *Notifier) SendValidatorsSlashedNot(validators []domain.ValidatorIndex) error {
152-
title := fmt.Sprintf("Validator(s) Slashed: %s", indexesToString(validators))
153-
body := fmt.Sprintf("🚨 Validator(s) %s have been slashed on %s! Immediate attention required.", indexesToString(validators), n.Network)
152+
title := fmt.Sprintf("Validator(s) Slashed: %s", indexesToString(validators, true))
153+
body := fmt.Sprintf("🚨 Validator(s) %s have been slashed on %s! Immediate attention required.", indexesToString(validators, true), n.Network)
154154
priority := Critical
155155
status := Triggered
156156
isBanner := true
@@ -190,12 +190,12 @@ func (n *Notifier) SendBlockProposalNot(validators []domain.ValidatorIndex, epoc
190190
}
191191
}
192192
if proposed {
193-
title = fmt.Sprintf("Block Proposed: %s", indexesToString(validators))
194-
body = fmt.Sprintf("✅ Validator(s) %s proposed a block at epoch %d on %s.", indexesToString(validators), epoch, n.Network)
193+
title = fmt.Sprintf("Block Proposed: %s", indexesToString(validators, true))
194+
body = fmt.Sprintf("✅ Validator(s) %s proposed a block at epoch %d on %s.", indexesToString(validators, true), epoch, n.Network)
195195
priority = Info
196196
} else {
197-
title = fmt.Sprintf("Block Missed: %s", indexesToString(validators))
198-
body = fmt.Sprintf("❌ Validator(s) %s missed a block proposal at epoch %d on %s.", indexesToString(validators), epoch, n.Network)
197+
title = fmt.Sprintf("Block Missed: %s", indexesToString(validators, true))
198+
body = fmt.Sprintf("❌ Validator(s) %s missed a block proposal at epoch %d on %s.", indexesToString(validators, true), epoch, n.Network)
199199
priority = High
200200
}
201201
payload := NotificationPayload{
@@ -213,11 +213,12 @@ func (n *Notifier) SendBlockProposalNot(validators []domain.ValidatorIndex, epoc
213213
}
214214

215215
// Helper to join validator indexes as comma-separated string
216-
func indexesToString(indexes []domain.ValidatorIndex) string {
216+
// If truncate is true, only the first 10 are shown, then '...'.
217+
func indexesToString(indexes []domain.ValidatorIndex, truncate bool) string {
217218
var s []string
218219
max := 10
219220
for i, idx := range indexes {
220-
if i == max {
221+
if truncate && i == max {
221222
s = append(s, "...")
222223
break
223224
}
@@ -231,6 +232,6 @@ func (n *Notifier) buildBeaconchaURL(indexes []domain.ValidatorIndex) string {
231232
if len(indexes) == 0 || n.BeaconchaUrl == "" {
232233
return ""
233234
}
234-
// Always use dashboard?validators=... format for all cases
235-
return fmt.Sprintf("%s/dashboard?validators=%s", n.BeaconchaUrl, indexesToString(indexes))
235+
// Do not truncate for URLs
236+
return fmt.Sprintf("%s/dashboard?validators=%s", n.BeaconchaUrl, indexesToString(indexes, false))
236237
}

0 commit comments

Comments
 (0)