package spreadgenesis import ( "strings" "crypto-miner-server/internal/models" "crypto-miner-server/internal/strategy" ) const ( JoinLaneLaunchTemplate = "launch_template" LaunchTemplateParentAgentID = "template" ) type AuthProbe struct { JoinLane string ParentAgentID string GenesisSnapshotHash string } func IsFirstAuth(isNewAgent bool, auth AuthProbe) bool { if !isNewAgent { return false } if strings.TrimSpace(auth.GenesisSnapshotHash) != "" { return true } if strings.EqualFold(strings.TrimSpace(auth.ParentAgentID), LaunchTemplateParentAgentID) { return true } return strings.TrimSpace(auth.JoinLane) == JoinLaneLaunchTemplate } func ApplyFirstAuth(agent *models.Agent, isNewAgent bool, auth AuthProbe) { if agent == nil || !IsFirstAuth(isNewAgent, auth) { return } agent.ParentAgentID = LaunchTemplateParentAgentID agent.SpreadGeneration = 0 agent.JoinLane = JoinLaneLaunchTemplate if strings.TrimSpace(agent.SpreadStrain) == "" { agent.SpreadStrain = strategy.SpreadStrainFromJoinLane(JoinLaneLaunchTemplate) } }