From be8c1292932b4b652639b87e5ac43e7c85463c1c Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Wed, 28 Dec 2022 11:35:00 +0100 Subject: [PATCH 1/5] feature: return custom records --- controllers_v2/keysend.ctrl.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/controllers_v2/keysend.ctrl.go b/controllers_v2/keysend.ctrl.go index 8558640..6cef341 100644 --- a/controllers_v2/keysend.ctrl.go +++ b/controllers_v2/keysend.ctrl.go @@ -41,13 +41,14 @@ type KeySendResult struct { } type KeySendResponseBody struct { - Amount int64 `json:"amount"` - Fee int64 `json:"fee"` - Description string `json:"description,omitempty"` - DescriptionHash string `json:"description_hash,omitempty"` - Destination string `json:"destination,omitempty"` - PaymentPreimage string `json:"payment_preimage,omitempty"` - PaymentHash string `json:"payment_hash,omitempty"` + Amount int64 `json:"amount"` + Fee int64 `json:"fee"` + Description string `json:"description,omitempty"` + DescriptionHash string `json:"description_hash,omitempty"` + Destination string `json:"destination,omitempty"` + CustomRecords map[string]string `json:"customRecords" validate:"omitempty"` + PaymentPreimage string `json:"payment_preimage,omitempty"` + PaymentHash string `json:"payment_hash,omitempty"` } // // KeySend godoc @@ -117,7 +118,8 @@ func (controller *KeySendController) MultiKeySend(c echo.Context) error { controller.svc.Logger.Errorf("Error making keysend split payment %v %s", keysend, err.Message) result.Keysends = append(result.Keysends, KeySendResult{ Keysend: &KeySendResponseBody{ - Destination: keysend.Destination, + Destination: keysend.Destination, + CustomRecords: keysend.CustomRecords, }, Error: err, }) @@ -186,6 +188,7 @@ func (controller *KeySendController) SingleKeySend(c echo.Context, reqBody *KeyS responseBody := &KeySendResponseBody{ Amount: sendPaymentResponse.PaymentRoute.TotalAmt, Fee: sendPaymentResponse.PaymentRoute.TotalFees, + CustomRecords: reqBody.CustomRecords, Description: reqBody.Memo, Destination: reqBody.Destination, PaymentPreimage: sendPaymentResponse.PaymentPreimageStr, From ed2eb2eeaeb2ae07dbb8b577f462b9fe202b3562 Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Thu, 29 Dec 2022 14:26:46 +0100 Subject: [PATCH 2/5] keysend response: use snake case to be consistent --- controllers_v2/keysend.ctrl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers_v2/keysend.ctrl.go b/controllers_v2/keysend.ctrl.go index 6cef341..ee51691 100644 --- a/controllers_v2/keysend.ctrl.go +++ b/controllers_v2/keysend.ctrl.go @@ -46,7 +46,7 @@ type KeySendResponseBody struct { Description string `json:"description,omitempty"` DescriptionHash string `json:"description_hash,omitempty"` Destination string `json:"destination,omitempty"` - CustomRecords map[string]string `json:"customRecords" validate:"omitempty"` + CustomRecords map[string]string `json:"custom_ecords" validate:"omitempty"` PaymentPreimage string `json:"payment_preimage,omitempty"` PaymentHash string `json:"payment_hash,omitempty"` } From 786bba76438e50a500686923e5aa6ecf3e6a4e22 Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Thu, 29 Dec 2022 14:27:05 +0100 Subject: [PATCH 3/5] keysend response: use snake case to be consistent --- controllers_v2/keysend.ctrl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers_v2/keysend.ctrl.go b/controllers_v2/keysend.ctrl.go index ee51691..b4ec29b 100644 --- a/controllers_v2/keysend.ctrl.go +++ b/controllers_v2/keysend.ctrl.go @@ -46,7 +46,7 @@ type KeySendResponseBody struct { Description string `json:"description,omitempty"` DescriptionHash string `json:"description_hash,omitempty"` Destination string `json:"destination,omitempty"` - CustomRecords map[string]string `json:"custom_ecords" validate:"omitempty"` + CustomRecords map[string]string `json:"custom_records" validate:"omitempty"` PaymentPreimage string `json:"payment_preimage,omitempty"` PaymentHash string `json:"payment_hash,omitempty"` } From d02a5f9510181aa134018fab0833f494eac81ee0 Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Thu, 29 Dec 2022 15:07:33 +0100 Subject: [PATCH 4/5] keysend: use camel case for request body --- controllers_v2/keysend.ctrl.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/controllers_v2/keysend.ctrl.go b/controllers_v2/keysend.ctrl.go index b4ec29b..6f6a65a 100644 --- a/controllers_v2/keysend.ctrl.go +++ b/controllers_v2/keysend.ctrl.go @@ -22,10 +22,11 @@ func NewKeySendController(svc *service.LndhubService) *KeySendController { } type KeySendRequestBody struct { - Amount int64 `json:"amount" validate:"required,gt=0"` - Destination string `json:"destination" validate:"required"` - Memo string `json:"memo" validate:"omitempty"` - CustomRecords map[string]string `json:"customRecords" validate:"omitempty"` + Amount int64 `json:"amount" validate:"required,gt=0"` + Destination string `json:"destination" validate:"required"` + Memo string `json:"memo" validate:"omitempty"` + DeprecatedCustomRecords map[string]string `json:"customRecords" validate:"omitempty"` + NewCustomRecords map[string]string `json:"custom_records" validate:"omitempty"` } type MultiKeySendRequestBody struct { @@ -119,7 +120,7 @@ func (controller *KeySendController) MultiKeySend(c echo.Context) error { result.Keysends = append(result.Keysends, KeySendResult{ Keysend: &KeySendResponseBody{ Destination: keysend.Destination, - CustomRecords: keysend.CustomRecords, + CustomRecords: keysend.NewCustomRecords, }, Error: err, }) @@ -167,7 +168,13 @@ func (controller *KeySendController) SingleKeySend(c echo.Context, reqBody *KeyS } invoice.DestinationCustomRecords = map[uint64][]byte{} - for key, value := range reqBody.CustomRecords { + //temporary workaround due to an inconsistency in json snake case vs camel case + //DeprecatedCustomRecords to be removed later + customRecords := reqBody.DeprecatedCustomRecords + if reqBody.NewCustomRecords != nil { + customRecords = reqBody.NewCustomRecords + } + for key, value := range customRecords { intKey, err := strconv.Atoi(key) if err != nil { return nil, &responses.BadArgumentsError @@ -188,7 +195,7 @@ func (controller *KeySendController) SingleKeySend(c echo.Context, reqBody *KeyS responseBody := &KeySendResponseBody{ Amount: sendPaymentResponse.PaymentRoute.TotalAmt, Fee: sendPaymentResponse.PaymentRoute.TotalFees, - CustomRecords: reqBody.CustomRecords, + CustomRecords: customRecords, Description: reqBody.Memo, Destination: reqBody.Destination, PaymentPreimage: sendPaymentResponse.PaymentPreimageStr, From 373f236a0dd9f57f831fff4c6eff5ee5d67a3c75 Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Thu, 29 Dec 2022 15:19:01 +0100 Subject: [PATCH 5/5] keysend: custom records --- controllers_v2/keysend.ctrl.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers_v2/keysend.ctrl.go b/controllers_v2/keysend.ctrl.go index 6f6a65a..fb8f108 100644 --- a/controllers_v2/keysend.ctrl.go +++ b/controllers_v2/keysend.ctrl.go @@ -26,7 +26,7 @@ type KeySendRequestBody struct { Destination string `json:"destination" validate:"required"` Memo string `json:"memo" validate:"omitempty"` DeprecatedCustomRecords map[string]string `json:"customRecords" validate:"omitempty"` - NewCustomRecords map[string]string `json:"custom_records" validate:"omitempty"` + CustomRecords map[string]string `json:"custom_records" validate:"omitempty"` } type MultiKeySendRequestBody struct { @@ -120,7 +120,7 @@ func (controller *KeySendController) MultiKeySend(c echo.Context) error { result.Keysends = append(result.Keysends, KeySendResult{ Keysend: &KeySendResponseBody{ Destination: keysend.Destination, - CustomRecords: keysend.NewCustomRecords, + CustomRecords: keysend.CustomRecords, }, Error: err, }) @@ -171,8 +171,8 @@ func (controller *KeySendController) SingleKeySend(c echo.Context, reqBody *KeyS //temporary workaround due to an inconsistency in json snake case vs camel case //DeprecatedCustomRecords to be removed later customRecords := reqBody.DeprecatedCustomRecords - if reqBody.NewCustomRecords != nil { - customRecords = reqBody.NewCustomRecords + if reqBody.CustomRecords != nil { + customRecords = reqBody.CustomRecords } for key, value := range customRecords { intKey, err := strconv.Atoi(key)