Allow comments for LNURL-PAY invoices
Allows senders to add a short message to payments, which will be stored as invoice memo by LND/LndHub.
This commit is contained in:
parent
6790e8383d
commit
4c51b9c966
@ -3,6 +3,7 @@ class LnurlpayController < ApplicationController
|
|||||||
|
|
||||||
MIN_SATS = 100
|
MIN_SATS = 100
|
||||||
MAX_SATS = 1_000_000
|
MAX_SATS = 1_000_000
|
||||||
|
MAX_COMMENT_CHARS = 100
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render json: {
|
render json: {
|
||||||
@ -12,22 +13,29 @@ class LnurlpayController < ApplicationController
|
|||||||
maxSendable: MAX_SATS * 1000, # msat
|
maxSendable: MAX_SATS * 1000, # msat
|
||||||
minSendable: MIN_SATS * 1000, # msat
|
minSendable: MIN_SATS * 1000, # msat
|
||||||
metadata: metadata(@user.address),
|
metadata: metadata(@user.address),
|
||||||
commentAllowed: 0
|
commentAllowed: MAX_COMMENT_CHARS
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def invoice
|
def invoice
|
||||||
amount = params[:amount].to_i / 1000 # msats
|
amount = params[:amount].to_i / 1000 # msats
|
||||||
address = params[:address]
|
address = params[:address]
|
||||||
|
comment = params[:comment]
|
||||||
|
|
||||||
if !valid_amount?(amount)
|
if !valid_amount?(amount)
|
||||||
render json: { status: "ERROR", reason: "Invalid amount" }
|
render json: { status: "ERROR", reason: "Invalid amount" }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !valid_comment?(comment)
|
||||||
|
render json: { status: "ERROR", reason: "Comment too long" }
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
payment_request = @user.ln_create_invoice({
|
payment_request = @user.ln_create_invoice({
|
||||||
amount: amount, # we create invoices in sats
|
amount: amount, # we create invoices in sats
|
||||||
description_hash: Digest::SHA2.hexdigest(metadata(address))
|
description_hash: Digest::SHA2.hexdigest(metadata(address)),
|
||||||
|
memo: comment
|
||||||
})
|
})
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
@ -57,4 +65,8 @@ class LnurlpayController < ApplicationController
|
|||||||
amount_in_sats <= MAX_SATS && amount_in_sats >= MIN_SATS
|
amount_in_sats <= MAX_SATS && amount_in_sats >= MIN_SATS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def valid_comment?(comment)
|
||||||
|
comment.length <= MAX_COMMENT_CHARS
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -49,7 +49,8 @@ class Lndhub
|
|||||||
def addinvoice(payload)
|
def addinvoice(payload)
|
||||||
invoice = post "addinvoice", {
|
invoice = post "addinvoice", {
|
||||||
amt: payload[:amount],
|
amt: payload[:amount],
|
||||||
description_hash: payload[:description_hash]
|
description_hash: payload[:description_hash],
|
||||||
|
memo: payload[:memo]
|
||||||
}
|
}
|
||||||
|
|
||||||
invoice["payment_request"]
|
invoice["payment_request"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user