Files
explorer-monorepo/backend/api/track1/bridge_mode.go
defiQUG 763ca75c21
Some checks failed
Deploy Explorer Live / deploy (push) Failing after 13s
Validate Explorer / frontend (push) Failing after 18s
Validate Explorer / smoke-e2e (push) Has been skipped
Ship Tier A Week 1–2: posture glossary, delivery mode, freshness UI, canonical tokens.
Expose mission-control mode on home/bridge/analytics, quiet-chain freshness copy, and a canonical-first indexed token list with WETH9 metadata override and non-canonical warnings.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-23 03:48:22 -07:00

79 lines
2.0 KiB
Go

package track1
import (
"strings"
"github.com/explorer/backend/api/freshness"
)
type bridgeDeliveryMode struct {
Kind string
Reason any
Scope any
}
func resolveBridgeDeliveryMode(hasRelays bool, diagnostics *freshness.Diagnostics, txFeed freshness.Completeness) bridgeDeliveryMode {
if !hasRelays {
if diagnostics != nil && isStaleTransactionVisibility(diagnostics) {
return bridgeDeliveryMode{
Kind: "mixed",
Reason: "partial_observability_inputs",
Scope: "homepage_summary_only",
}
}
return bridgeDeliveryMode{
Kind: "live",
Reason: nil,
Scope: nil,
}
}
if diagnostics != nil && isStaleTransactionVisibility(diagnostics) {
return bridgeDeliveryMode{
Kind: "mixed",
Reason: "relay_snapshot_only_source",
Scope: "bridge_monitoring_and_homepage",
}
}
if txFeed == freshness.CompletenessPartial || txFeed == freshness.CompletenessStale {
return bridgeDeliveryMode{
Kind: "mixed",
Reason: "partial_observability_inputs",
Scope: "bridge_monitoring_and_homepage",
}
}
return bridgeDeliveryMode{
Kind: "snapshot",
Reason: "live_homepage_stream_not_attached",
Scope: "relay_monitoring_homepage_card_only",
}
}
func isStaleTransactionVisibility(diagnostics *freshness.Diagnostics) bool {
if diagnostics == nil {
return false
}
state := strings.ToLower(strings.TrimSpace(diagnostics.ActivityState))
switch state {
case "fresh_head_stale_transaction_visibility", "lagging", "stale_transaction_visibility":
return true
default:
return strings.Contains(state, "stale") && strings.Contains(state, "transaction")
}
}
func buildBridgeModePayload(now string, resolved bridgeDeliveryMode) map[string]interface{} {
return map[string]interface{}{
"kind": resolved.Kind,
"updated_at": now,
"age_seconds": int64(0),
"reason": resolved.Reason,
"scope": resolved.Scope,
"source": freshness.SourceReported,
"confidence": freshness.ConfidenceHigh,
"provenance": freshness.ProvenanceMissionFeed,
}
}