Skip to content

Commit

Permalink
Merge pull request #1884 from stakwork/feat/add_logs_to_payment
Browse files Browse the repository at this point in the history
PR: added logs for MakeBountyPayment
  • Loading branch information
elraphty authored Oct 12, 2024
2 parents 20daa2b + a39e4ed commit 1dde90f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,19 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
return
}

log.Printf("[bounty] After Making Bounty V2 Payment: amount: %d, pubkey: %s, route_hint: %s", amount, assignee.OwnerPubKey, assignee.OwnerRouteHint)

defer res.Body.Close()
body, err = io.ReadAll(res.Body)
if err != nil {
fmt.Println("[read body]", err)
log.Println("[read body failed]", err)
w.WriteHeader(http.StatusNotAcceptable)
h.m.Unlock()
return
}

log.Println("[bounty] After Reading Keysend V2 Payment Body ===")

msg := make(map[string]interface{})
// payment is successful add to payment history
// and reduce workspaces budget
Expand All @@ -614,7 +618,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
err = json.Unmarshal(body, &v2KeysendRes)

if err != nil {
fmt.Println("[Unmarshal]", err)
fmt.Println("[Unmarshal failed]", err)
w.WriteHeader(http.StatusNotAcceptable)
h.m.Unlock()
return
Expand Down Expand Up @@ -653,22 +657,29 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
socket.Conn.WriteJSON(msg)
}
} else { // Send payment status
log.Println("Keysend payment not completed ===")
msg["msg"] = v2KeysendRes.Status
msg["invoice"] = ""

socket, err := h.getSocketConnections(request.Websocket_token)
if err == nil {
socket.Conn.WriteJSON(msg)
}
h.m.Unlock()
return
}
} else { // Send Payment error
log.Println("Keysend payment error ===")
msg["msg"] = "keysend_error"
msg["invoice"] = ""

socket, err := h.getSocketConnections(request.Websocket_token)
if err == nil {
socket.Conn.WriteJSON(msg)
}

h.m.Unlock()
return
}
} else { // Process v1 payment
url := fmt.Sprintf("%s/payment", config.RelayUrl)
Expand Down Expand Up @@ -741,6 +752,8 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
if err == nil {
socket.Conn.WriteJSON(msg)
}
h.m.Unlock()
return
} else {
msg["msg"] = "keysend_error"
msg["invoice"] = ""
Expand All @@ -749,6 +762,9 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
if err == nil {
socket.Conn.WriteJSON(msg)
}

h.m.Unlock()
return
}
}

Expand Down

0 comments on commit 1dde90f

Please sign in to comment.