-
Notifications
You must be signed in to change notification settings - Fork 1
feat: integrate DCA bot with configuration and deposit notification #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||||||||||||||||||||
| package dca | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| "github.com/LightningTipBot/LightningTipBot/internal" | ||||||||||||||||||||||||
| log "github.com/sirupsen/logrus" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // NotifyDeposit checks whether the given recipient username matches the configured | ||||||||||||||||||||||||
| // DCA wallet username and, if so, asks the DCA backend to reset its retry counts. | ||||||||||||||||||||||||
| func NotifyDeposit(toUsername string) { | ||||||||||||||||||||||||
| wallet := strings.TrimPrefix(internal.Configuration.DCA.WalletUsername, "@") | ||||||||||||||||||||||||
| if wallet == "" || strings.TrimPrefix(toUsername, "@") != wallet { | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| apiUrl := strings.TrimSuffix(internal.Configuration.DCA.ApiUrl, "/") | ||||||||||||||||||||||||
| if apiUrl == "" { | ||||||||||||||||||||||||
| log.Errorln("[DCA] dca.api_url is not configured, skipping reset-retry-counts call") | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| url := apiUrl + "/transaction/reset-retry-counts" | ||||||||||||||||||||||||
| req, err := http.NewRequest(http.MethodPost, url, nil) | ||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||
| log.Errorf("[DCA] Error creating reset-retry-counts request: %s", err.Error()) | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| req.Header.Set("Content-Type", "application/json") | ||||||||||||||||||||||||
|
Comment on lines
+27
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove The request sets 🧹 Proposed fix req, err := http.NewRequest(http.MethodPost, url, nil)
if err != nil {
log.Errorf("[DCA] Error creating reset-retry-counts request: %s", err.Error())
return
}
- req.Header.Set("Content-Type", "application/json")📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| client := &http.Client{Timeout: 10 * time.Second} | ||||||||||||||||||||||||
| resp, err := client.Do(req) | ||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||
| log.Errorf("[DCA] Error calling reset-retry-counts: %s", err.Error()) | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| defer resp.Body.Close() | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check error return from The deferred 🔧 Proposed fix- defer resp.Body.Close()
+ defer func() {
+ if err := resp.Body.Close(); err != nil {
+ log.Errorf("[DCA] Error closing response body: %s", err.Error())
+ }
+ }()Based on learnings from static analysis tool errcheck. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 golangci-lint (2.12.2)[error] 32-32: Error return value of (errcheck) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||||||||||||||||||||
| log.Infof("[DCA] reset-retry-counts called for %s, status: %s", toUsername, resp.Status) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.