mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-02-23 13:04:22 +01:00
Support for "any" amount for LN invoice and LN pay
This commit is contained in:
@@ -28,8 +28,13 @@ ln_create_invoice() {
|
||||
# "bolt11": "lnbc100n1pwzllqgpp55a8xen9sdcntehwr93pkwnuu8nmtqx9yew0flalcxhx9nvy34crqdq9wsckgxqzpucqp2rzjqt04ll5ft3mcuy8hws4xcku2pnhma9r9mavtjtadawyrw5kgzp7g7zr745qq3mcqqyqqqqlgqqqqqzsqpcr85k33shzaxscpj29fadmjmfej6y2p380x9w4kxydqpxq87l6lshy69fry9q2yrtu037nt44x77uhzkdyn8043n5yj8tqgluvmcl69cquaxr68"
|
||||
#}
|
||||
|
||||
trace "[ln_create_invoice] ./lightning-cli invoice ${msatoshi} \"${label}\" \"${description}\" ${expiry}"
|
||||
result=$(./lightning-cli invoice ${msatoshi} "${label}" "${description}" ${expiry})
|
||||
if [ "${msatoshi}" = "null" ]; then
|
||||
trace "[ln_create_invoice] ./lightning-cli invoice \"any\" \"${label}\" \"${description}\" ${expiry}"
|
||||
result=$(./lightning-cli invoice "any" "${label}" "${description}" ${expiry})
|
||||
else
|
||||
trace "[ln_create_invoice] ./lightning-cli invoice ${msatoshi} \"${label}\" \"${description}\" ${expiry}"
|
||||
result=$(./lightning-cli invoice ${msatoshi} "${label}" "${description}" ${expiry})
|
||||
fi
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
trace "[ln_create_invoice] result=${result}"
|
||||
@@ -47,7 +52,11 @@ ln_create_invoice() {
|
||||
# Let's get the connect string if provided in configuration
|
||||
local connectstring=$(get_connection_string)
|
||||
|
||||
sql "INSERT OR IGNORE INTO ln_invoice (label, bolt11, callback_url, payment_hash, expires_at, msatoshi, description, status) VALUES (\"${label}\", \"${bolt11}\", \"${callback_url}\", \"${payment_hash}\", ${expires_at}, ${msatoshi}, \"${description}\", \"unpaid\")"
|
||||
if [ "${msatoshi}" = "null" ]; then
|
||||
sql "INSERT OR IGNORE INTO ln_invoice (label, bolt11, callback_url, payment_hash, expires_at, description, status) VALUES (\"${label}\", \"${bolt11}\", \"${callback_url}\", \"${payment_hash}\", ${expires_at}, \"${description}\", \"unpaid\")"
|
||||
else
|
||||
sql "INSERT OR IGNORE INTO ln_invoice (label, bolt11, callback_url, payment_hash, expires_at, msatoshi, description, status) VALUES (\"${label}\", \"${bolt11}\", \"${callback_url}\", \"${payment_hash}\", ${expires_at}, ${msatoshi}, \"${description}\", \"unpaid\")"
|
||||
fi
|
||||
trace_rc $?
|
||||
id=$(sql "SELECT id FROM ln_invoice WHERE bolt11=\"${bolt11}\"")
|
||||
trace_rc $?
|
||||
@@ -60,7 +69,9 @@ ln_create_invoice() {
|
||||
fi
|
||||
data="${data}\"callback_url\":\"${callback_url}\","
|
||||
data="${data}\"payment_hash\":\"${payment_hash}\","
|
||||
data="${data}\"msatoshi\":${msatoshi},"
|
||||
if [ "${msatoshi}" != "null" ]; then
|
||||
data="${data}\"msatoshi\":${msatoshi},"
|
||||
fi
|
||||
data="${data}\"status\":\"unpaid\","
|
||||
data="${data}\"description\":\"${description}\","
|
||||
data="${data}\"expires_at\":${expires_at}}"
|
||||
@@ -306,12 +317,15 @@ ln_pay() {
|
||||
local invoice_description=$(echo "${result}" | jq ".description")
|
||||
trace "[ln_pay] invoice_description=${invoice_description}"
|
||||
|
||||
# The amount must match
|
||||
if [ "${expected_msatoshi}" != "${invoice_msatoshi}" ]; then
|
||||
# The amount must match if not "any"
|
||||
# If the amount is not in the invoice and not supplied as expected_msatoshi, then both will be null, that's ok!
|
||||
# Same thing goes for the description.
|
||||
if [ "${expected_msatoshi}" != "${invoice_msatoshi}" ] && [ "${invoice_msatoshi}" != "null" ]; then
|
||||
# If invoice_msatoshi is null, that means "any" was supplied, so the amounts don't have to match!
|
||||
result="{\"result\":\"error\",\"expected_msatoshi\":${expected_msatoshi},\"invoice_msatoshi\":${invoice_msatoshi}}"
|
||||
returncode=1
|
||||
elif [ "${expected_description}" != '""' ] && [ "${expected_description}" != "${invoice_description}" ]; then
|
||||
# If expected description is empty, we accept any description on the invoice. Amount is the important thing.
|
||||
elif [ -n "${expected_description}" ] && [ "${expected_description}" != "null" ] && [ "${expected_description}" != "${invoice_description}" ]; then
|
||||
# If expected description is empty, we accept any description on the invoice. Amount is the most important thing.
|
||||
|
||||
result="{\"result\":\"error\",\"expected_description\":${expected_description},\"invoice_description\":${invoice_description}}"
|
||||
returncode=1
|
||||
@@ -319,8 +333,14 @@ ln_pay() {
|
||||
# Amount and description is as expected, let's pay!
|
||||
trace "[ln_pay] Amount and description are as expected, let's try to pay!"
|
||||
|
||||
trace "[ln_pay] ./lightning-cli pay -k bolt11=${bolt11} retry_for=15"
|
||||
result=$(./lightning-cli pay -k bolt11=${bolt11} retry_for=15)
|
||||
if [ "${invoice_msatoshi}" = "null" ]; then
|
||||
# "any" amount on the invoice, we force paying the expected_msatoshi provided to ln_pay by the user
|
||||
trace "[ln_pay] ./lightning-cli pay -k bolt11=${bolt11} msatoshi=${expected_msatoshi} retry_for=15"
|
||||
result=$(./lightning-cli pay -k bolt11=${bolt11} msatoshi=${expected_msatoshi} retry_for=15)
|
||||
else
|
||||
trace "[ln_pay] ./lightning-cli pay -k bolt11=${bolt11} retry_for=15"
|
||||
result=$(./lightning-cli pay -k bolt11=${bolt11} retry_for=15)
|
||||
fi
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
trace "[ln_pay] result=${result}"
|
||||
|
||||
Reference in New Issue
Block a user