diff --git a/discord/referral.go b/discord/referral.go index 946e3729..bfef9ba9 100644 --- a/discord/referral.go +++ b/discord/referral.go @@ -95,31 +95,27 @@ func (rs *ReferralStore) GetAllReferrals() []*Referral { // AddPoint add one point for a referral. func (rs *ReferralStore) AddPoint(code string) bool { - entry, found := rs.syncMap.Load(code) - if !found { - return false - } - - if found { - referral := entry.(*Referral) - referral.Points++ - rs.syncMap.Store(referral.ReferralCode, referral) - return true - } - - // save record - data, err := marshaReferralJSON(rs.syncMap) - if err != nil { - log.Printf("error marshalling validator data file: %v", err) - return false - } - - if err := os.WriteFile(rs.cfg.ReferralDataPath, data, 0o600); err != nil { - log.Printf("failed to write to %s: %v", rs.cfg.ReferralDataPath, err) - return false - } - - return false + entry, found := rs.syncMap.Load(code) + if !found { + return false + } + referral := entry.(*Referral) + referral.Points++ + rs.syncMap.Store(referral.ReferralCode, referral) + + // save record + data, err := marshaReferralJSON(rs.syncMap) + if err != nil { + log.Printf("error marshalling validator data file: %v", err) + return false + } + + if err := os.WriteFile(rs.cfg.ReferralDataPath, data, 0o600); err != nil { + log.Printf("failed to write to %s: %v", rs.cfg.ReferralDataPath, err) + return false + } + + return true } func marshaReferralJSON(m *sync.Map) ([]byte, error) {