Merge pull request 'Allow comments for LNURL-PAY invoices' (#65) from feature/lnurlp_memos into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #65
This commit is contained in:
commit
83e4dfa18f
@ -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,32 @@ 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
|
||||||
|
|
||||||
|
memo = "Sats for #{address}"
|
||||||
|
memo = "#{memo}: \"#{comment}\"" if comment.present?
|
||||||
|
|
||||||
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))
|
memo: memo,
|
||||||
|
description_hash: Digest::SHA2.hexdigest(metadata(address)),
|
||||||
})
|
})
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
@ -57,4 +68,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,6 +49,7 @@ class Lndhub
|
|||||||
def addinvoice(payload)
|
def addinvoice(payload)
|
||||||
invoice = post "addinvoice", {
|
invoice = post "addinvoice", {
|
||||||
amt: payload[:amount],
|
amt: payload[:amount],
|
||||||
|
memo: payload[:memo],
|
||||||
description_hash: payload[:description_hash]
|
description_hash: payload[:description_hash]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user