Skip to content

Commit

Permalink
chore: update to remove memo and paymenthash
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Dec 11, 2023
1 parent 9b409ac commit 7945400
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
17 changes: 8 additions & 9 deletions alby.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (svc *AlbyOAuthService) SendPaymentSync(ctx context.Context, senderPubkey,
return "", errors.New(errorPayload.Message)
}

func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey string, amount int64, destination, memo, preimage string, custom_records []TLVRecord) (preImage, paymentHash string, err error) {
func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey string, amount int64, destination, preimage string, custom_records []TLVRecord) (preImage string, err error) {
app := App{}
err = svc.db.Preload("User").First(&app, &App{
NostrPubkey: senderPubkey,
Expand All @@ -418,7 +418,7 @@ func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey strin
"senderPubkey": senderPubkey,
"payeePubkey": destination,
}).Errorf("App not found: %v", err)
return "", "", err
return "", err
}
svc.Logger.WithFields(logrus.Fields{
"senderPubkey": senderPubkey,
Expand All @@ -428,7 +428,7 @@ func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey strin
}).Info("Processing payment request")
tok, err := svc.FetchUserToken(ctx, app)
if err != nil {
return "", "", err
return "", err
}
client := svc.oauthConf.Client(ctx, tok)

Expand All @@ -441,7 +441,6 @@ func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey strin
payload := &KeysendRequest{
Amount: amount,
Destination: destination,
Memo: memo,
CustomRecords: customRecordsMap,
}
err = json.NewEncoder(body).Encode(payload)
Expand All @@ -450,7 +449,7 @@ func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey strin
req, err := http.NewRequest("POST", fmt.Sprintf("%s/payments/keysend", svc.cfg.AlbyAPIURL), body)
if err != nil {
svc.Logger.WithError(err).Error("Error creating request /payments/keysend")
return "", "", err
return "", err
}

req.Header.Set("User-Agent", "NWC")
Expand All @@ -464,14 +463,14 @@ func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey strin
"appId": app.ID,
"userId": app.User.ID,
}).Errorf("Failed to pay keysend: %v", err)
return "", "", err
return "", err
}

if resp.StatusCode < 300 {
responsePayload := &PayResponse{}
err = json.NewDecoder(resp.Body).Decode(responsePayload)
if err != nil {
return "", "", err
return "", err
}
svc.Logger.WithFields(logrus.Fields{
"senderPubkey": senderPubkey,
Expand All @@ -480,7 +479,7 @@ func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey strin
"userId": app.User.ID,
"paymentHash": responsePayload.PaymentHash,
}).Info("Payment successful")
return responsePayload.Preimage, responsePayload.PaymentHash, nil
return responsePayload.Preimage, nil
}

errorPayload := &ErrorResponse{}
Expand All @@ -492,7 +491,7 @@ func (svc *AlbyOAuthService) SendKeysend(ctx context.Context, senderPubkey strin
"userId": app.User.ID,
"APIHttpStatus": resp.StatusCode,
}).Errorf("Payment failed %s", string(errorPayload.Message))
return "", "", errors.New(errorPayload.Message)
return "", errors.New(errorPayload.Message)
}

func (svc *AlbyOAuthService) AuthHandler(c echo.Context) error {
Expand Down
3 changes: 1 addition & 2 deletions handle_pay_keysend_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ func (svc *Service) HandlePayKeysendEvent(ctx context.Context, request *Nip47Req
svc.db.Save(&payment)
return svc.createResponse(event, Nip47Response{
ResultType: request.Method,
Result: Nip47KeysendResponse{
Result: Nip47PayResponse{
Preimage: preimage,
PaymentHash: paymentHash,
},
}, ss)
}
12 changes: 6 additions & 6 deletions lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

type LNClient interface {
SendPaymentSync(ctx context.Context, senderPubkey string, payReq string) (preimage string, err error)
SendKeysend(ctx context.Context, senderPubkey string, amount int64, destination, memo, preimage string, custom_records []TLVRecord) (preImage, paymentHash string, err error)
SendKeysend(ctx context.Context, senderPubkey string, amount int64, destination, preimage string, custom_records []TLVRecord) (preImage string, err error)
GetBalance(ctx context.Context, senderPubkey string) (balance int64, err error)
MakeInvoice(ctx context.Context, senderPubkey string, amount int64, description string, descriptionHash string, expiry int64) (invoice string, paymentHash string, err error)
LookupInvoice(ctx context.Context, senderPubkey string, paymentHash string) (invoice string, paid bool, err error)
Expand Down Expand Up @@ -104,14 +104,14 @@ func (svc *LNDService) SendPaymentSync(ctx context.Context, senderPubkey, payReq
return hex.EncodeToString(resp.PaymentPreimage), nil
}

func (svc *LNDService) SendKeysend(ctx context.Context, senderPubkey string, amount int64, destination, memo, preimage string, custom_records []TLVRecord) (preImage, paymentHash string, err error) {
func (svc *LNDService) SendKeysend(ctx context.Context, senderPubkey string, amount int64, destination, preimage string, custom_records []TLVRecord) (preImage string, err error) {
destBytes, err := hex.DecodeString(destination)
if err != nil {
return "", "", err
return "", err
}
preimageBytes, err := hex.DecodeString(preimage)
if err != nil {
return "", "", err
return "", err
}
resultMap := make(map[uint64][]byte)
for _, record := range custom_records {
Expand All @@ -128,9 +128,9 @@ func (svc *LNDService) SendKeysend(ctx context.Context, senderPubkey string, amo

resp, err := svc.client.SendPaymentSync(ctx, sendPaymentRequest)
if err != nil {
return "", "", err
return "", err
}
return hex.EncodeToString(resp.PaymentPreimage), hex.EncodeToString(resp.PaymentHash), nil
return hex.EncodeToString(resp.PaymentPreimage), nil
}

func NewLNDService(ctx context.Context, svc *Service, e *echo.Echo) (result *LNDService, err error) {
Expand Down
7 changes: 0 additions & 7 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ type PayRequest struct {
type KeysendRequest struct {
Amount int64 `json:"amount"`
Destination string `json:"destination"`
Memo string `json:"memo,omitempty"`
CustomRecords map[string]string `json:"custom_records,omitempty"`
}

Expand Down Expand Up @@ -193,7 +192,6 @@ type Nip47PayResponse struct {
type Nip47KeysendParams struct {
Amount int64 `json:"amount"`
Pubkey string `json:"pubkey"`
Message string `json:"message"`
Preimage string `json:"preimage"`
TLVRecords []TLVRecord `json:"tlv_records"`
}
Expand All @@ -203,11 +201,6 @@ type TLVRecord struct {
Value string `json:"value"`
}

type Nip47KeysendResponse struct {
Preimage string `json:"preimage"`
PaymentHash string `json:"payment_hash"`
}

type Nip47BalanceResponse struct {
Balance int64 `json:"balance"`
MaxAmount int `json:"max_amount"`
Expand Down
4 changes: 2 additions & 2 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ func (mln *MockLn) SendPaymentSync(ctx context.Context, senderPubkey string, pay
return "123preimage", nil
}

func (mln *MockLn) SendKeysend(ctx context.Context, senderPubkey string, amount int64, destination, memo, preimage string, custom_records []TLVRecord) (preImage, paymentHash string, err error) {
func (mln *MockLn) SendKeysend(ctx context.Context, senderPubkey string, amount int64, destination, preimage string, custom_records []TLVRecord) (preImage string, err error) {
//todo more advanced behaviour
return "123preimage", "123paymenthash", nil
return "123preimage", nil
}

func (mln *MockLn) GetBalance(ctx context.Context, senderPubkey string) (balance int64, err error) {
Expand Down

0 comments on commit 7945400

Please sign in to comment.