diff --git a/handlers/bounty.go b/handlers/bounty.go index 24ba9efcc..3788b8f09 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -569,14 +569,16 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request // Get Bounty Assignee assignee := h.db.GetPersonByPubkey(bounty.Assignee) + memoText := fmt.Sprintf("Payment For: %ss", bounty.Title) + // If the v2contactkey is present if config.IsV2Payment { url := fmt.Sprintf("%s/pay", config.V2BotUrl) - fmt.Println("IS V@ PAYMENT ====") + fmt.Println("IS V2 PAYMENT ====") // Build v2 keysend payment data - bodyData := utils.BuildV2KeysendBodyData(amount, assignee.OwnerPubKey, assignee.OwnerRouteHint) + bodyData := utils.BuildV2KeysendBodyData(amount, assignee.OwnerPubKey, assignee.OwnerRouteHint, memoText) jsonBody := []byte(bodyData) req, _ := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonBody)) @@ -669,7 +671,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request } else { // Process v1 payment url := fmt.Sprintf("%s/payment", config.RelayUrl) - bodyData := utils.BuildKeysendBodyData(amount, assignee.OwnerPubKey, assignee.OwnerRouteHint) + bodyData := utils.BuildKeysendBodyData(amount, assignee.OwnerPubKey, assignee.OwnerRouteHint, memoText) jsonBody := []byte(bodyData) req, _ := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonBody)) @@ -1209,7 +1211,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) { url := fmt.Sprintf("%s/pay", config.V2BotUrl) // Build v2 keysend payment data - bodyData := utils.BuildV2KeysendBodyData(amount, invData.UserPubkey, invData.RouteHint) + bodyData := utils.BuildV2KeysendBodyData(amount, invData.UserPubkey, invData.RouteHint, "") jsonBody := []byte(bodyData) req, _ := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonBody)) @@ -1267,7 +1269,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) { } else { url := fmt.Sprintf("%s/payment", config.RelayUrl) - bodyData := utils.BuildKeysendBodyData(amount, invData.UserPubkey, invData.RouteHint) + bodyData := utils.BuildKeysendBodyData(amount, invData.UserPubkey, invData.RouteHint, "") jsonBody := []byte(bodyData) diff --git a/handlers/bounty_test.go b/handlers/bounty_test.go index 3818e7282..264176e84 100644 --- a/handlers/bounty_test.go +++ b/handlers/bounty_test.go @@ -1418,12 +1418,14 @@ func TestMakeBountyPayment(t *testing.T) { bHandler2.getSocketConnections = mockGetSocketConnections bHandler2.userHasAccess = mockUserHasAccessTrue + memoText := fmt.Sprintf("Payment For: %ss", bounty.Title) + expectedUrl := fmt.Sprintf("%s/payment", config.RelayUrl) - expectedBody := fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "memotext added for notification"}`, bountyAmount, person.OwnerPubKey) + expectedBody := fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "memotext added for notification", "data": "%s"}`, bountyAmount, person.OwnerPubKey, memoText) expectedV2Url := fmt.Sprintf("%s/pay", botURL) expectedV2Body := - fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "%s", "wait": true}`, bountyAmount*1000, person.OwnerPubKey, person.OwnerRouteHint) + fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "%s", "data": "%s", "wait": true}`, bountyAmount*1000, person.OwnerPubKey, person.OwnerRouteHint, memoText) r := io.NopCloser(bytes.NewReader([]byte(`"internal server error"`))) if botURL != "" && botToken != "" { @@ -1464,12 +1466,14 @@ func TestMakeBountyPayment(t *testing.T) { bHandler.getSocketConnections = mockGetSocketConnections bHandler.userHasAccess = mockUserHasAccessTrue + memoText := fmt.Sprintf("Payment For: %ss", bounty.Title) + expectedUrl := fmt.Sprintf("%s/payment", config.RelayUrl) - expectedBody := fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "memotext added for notification"}`, bountyAmount, person.OwnerPubKey) + expectedBody := fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "memotext added for notification", "data": "%s"}`, bountyAmount, person.OwnerPubKey, memoText) expectedV2Url := fmt.Sprintf("%s/pay", botURL) expectedV2Body := - fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "%s", "wait": true}`, bountyAmount*1000, person.OwnerPubKey, person.OwnerRouteHint) + fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "%s", "data": "%s", "wait": true}`, bountyAmount*1000, person.OwnerPubKey, person.OwnerRouteHint, memoText) if botURL != "" && botToken != "" { rv2 := io.NopCloser(bytes.NewReader([]byte(`{"status": "COMPLETE", "tag": "", "preimage": "", "payment_hash": "" }`))) @@ -1951,10 +1955,10 @@ func TestPollInvoice(t *testing.T) { expectedPaymentUrl := fmt.Sprintf("%s/payment", config.RelayUrl) expectedV2PaymentUrl := fmt.Sprintf("%s/pay", botURL) - expectedPaymentBody := fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "memotext added for notification"}`, bountyAmount, invoice.OwnerPubkey) + expectedPaymentBody := fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "memotext added for notification", "data": ""}`, bountyAmount, invoice.OwnerPubkey) expectedV2PaymentBody := - fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "%s", "wait": true}`, bountyAmount*1000, invoice.OwnerPubkey, invoiceData.RouteHint) + fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "%s", "data": "", "wait": true}`, bountyAmount*1000, invoice.OwnerPubkey, invoiceData.RouteHint) r2 := io.NopCloser(bytes.NewReader([]byte(`{"success": true, "response": { "sumAmount": "1"}}`))) r3 := io.NopCloser(bytes.NewReader([]byte(`{"status": "COMPLETE", "amt_msat": "", "timestamp": "" }`))) diff --git a/handlers/invoiceCron.go b/handlers/invoiceCron.go index b1914150a..4d079d1a3 100644 --- a/handlers/invoiceCron.go +++ b/handlers/invoiceCron.go @@ -75,7 +75,7 @@ func InitInvoiceCron() { amount, _ := utils.ConvertStringToUint(inv.Amount) - bodyData := utils.BuildKeysendBodyData(amount, inv.User_pubkey, inv.Route_hint) + bodyData := utils.BuildKeysendBodyData(amount, inv.User_pubkey, inv.Route_hint, "") jsonBody := []byte(bodyData) diff --git a/utils/utils.go b/utils/utils.go index 8404aee56..7edd46c4b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -53,25 +53,24 @@ func BuildSearchQuery(key string, term string) (string, string) { return arg1, arg2 } -func BuildKeysendBodyData(amount uint, receiver_pubkey string, route_hint string) string { +func BuildKeysendBodyData(amount uint, receiver_pubkey string, route_hint string, memo string) string { var bodyData string - memoText := "memotext added for notification" if route_hint != "" { - bodyData = fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "route_hint": "%s", "text": "%s"}`, amount, receiver_pubkey, route_hint, memoText) + bodyData = fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "route_hint": "%s", "text": "%s", "data": "%s"}`, amount, receiver_pubkey, route_hint, memo, memo) } else { - bodyData = fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "%s"}`, amount, receiver_pubkey, memoText) + bodyData = fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "%s", "data": "%s"}`, amount, receiver_pubkey, memo, memo) } return bodyData } -func BuildV2KeysendBodyData(amount uint, receiver_pubkey string, route_hint string) string { +func BuildV2KeysendBodyData(amount uint, receiver_pubkey string, route_hint string, memo string) string { amountMsat := amount * 1000 var bodyData string if route_hint != "" { - bodyData = fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "%s", "wait": true}`, amountMsat, receiver_pubkey, route_hint) + bodyData = fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "%s", "data": "%s", "wait": true}`, amountMsat, receiver_pubkey, route_hint, memo) } else { - bodyData = fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "", "wait": true}`, amountMsat, receiver_pubkey) + bodyData = fmt.Sprintf(`{"amt_msat": %d, "dest": "%s", "route_hint": "", , "data": "%s", "wait": true}`, amountMsat, receiver_pubkey, memo) } return bodyData