From f80fd8d5e93a74dc32bb0478cb6cef61750b83e3 Mon Sep 17 00:00:00 2001 From: kexkey Date: Fri, 6 Dec 2019 16:37:59 -0500 Subject: [PATCH] callbackUrl now optional on ln_create_invoice --- doc/API.v0.md | 4 ++-- doc/openapi/v0/cyphernode-api.yaml | 3 +++ proxy_docker/app/script/call_lightningd.sh | 13 ++++++++++--- proxy_docker/app/script/waitanyinvoice.sh | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/doc/API.v0.md b/doc/API.v0.md index 611bab1..809b916 100644 --- a/doc/API.v0.md +++ b/doc/API.v0.md @@ -786,12 +786,12 @@ Proxy response: ### Create a Lightning Network invoice (called by application) -Returns a LN invoice. Label must be unique. Description will be used by your user for payment. Expiry is in seconds. If msatoshi is not supplied, will use "any" (ie donation invoice). +Returns a LN invoice. Label must be unique. Description will be used by your user for payment. Expiry is in seconds. If msatoshi is not supplied, will use "any" (ie donation invoice). callbackUrl is optional. ```http POST http://cyphernode:8888/ln_create_invoice with body... -{"msatoshi":10000,"label":"koNCcrSvhX3dmyFhW","description":"Bylls order #10649","expiry":900} +{"msatoshi":10000,"label":"koNCcrSvhX3dmyFhW","description":"Bylls order #10649","expiry":900,"callbackUrl":"https://thesite/lnwebhook/9d8sa98yd"} or {"label":"koNCcrSvhX3dmyFhW","description":"Bylls order #10649","expiry":900} ``` diff --git a/doc/openapi/v0/cyphernode-api.yaml b/doc/openapi/v0/cyphernode-api.yaml index 768b205..8418a2d 100644 --- a/doc/openapi/v0/cyphernode-api.yaml +++ b/doc/openapi/v0/cyphernode-api.yaml @@ -1399,6 +1399,9 @@ paths: type: "string" expiry: type: "integer" + callbackUrl: + type: "string" + format: "url" responses: '200': description: "successful operation" diff --git a/proxy_docker/app/script/call_lightningd.sh b/proxy_docker/app/script/call_lightningd.sh index 205b02c..c65b59a 100644 --- a/proxy_docker/app/script/call_lightningd.sh +++ b/proxy_docker/app/script/call_lightningd.sh @@ -20,6 +20,11 @@ ln_create_invoice() { trace "[ln_create_invoice] expiry=${expiry}" local callback_url=$(echo "${request}" | jq -r ".callbackUrl") trace "[ln_create_invoice] callback_url=${callback_url}" + if [ "${callback_url}" != "null" ]; then + # If not null, let's add double-quotes so we don't need to add the double-quotes in the sql insert, + # so if it's null, it will insert the actual sql NULL value. + callback_url="\"${callback_url}\"" + fi #/proxy $ ./lightning-cli invoice 10000 "t1" "t1d" 60 #{ @@ -53,9 +58,9 @@ ln_create_invoice() { local connectstring=$(get_connection_string) 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\")" + 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\")" + 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}\"") @@ -67,7 +72,9 @@ ln_create_invoice() { if [ -n "${connectstring}" ]; then data="${data}\"connectstring\":\"${connectstring}\"," fi - data="${data}\"callback_url\":\"${callback_url}\"," + if [ "${callback_url}" != "null" ]; then + data="${data}\"callback_url\":${callback_url}," + fi data="${data}\"payment_hash\":\"${payment_hash}\"," if [ "${msatoshi}" != "null" ]; then data="${data}\"msatoshi\":${msatoshi}," diff --git a/proxy_docker/app/script/waitanyinvoice.sh b/proxy_docker/app/script/waitanyinvoice.sh index 9930f55..9c3e269 100644 --- a/proxy_docker/app/script/waitanyinvoice.sh +++ b/proxy_docker/app/script/waitanyinvoice.sh @@ -43,7 +43,7 @@ ln_waitanyinvoice() { paid_at=$(echo "${result}" | jq -r ".paid_at") sql "UPDATE ln_invoice SET status=\"${status}\", pay_index=${pay_index}, msatoshi_received=${msatoshi_received}, paid_at=${paid_at} WHERE bolt11=\"${bolt11}\"" - row=$(sql "SELECT id, label, bolt11, callback_url, payment_hash, msatoshi, status, pay_index, msatoshi_received, paid_at, description, expires_at FROM ln_invoice WHERE NOT calledback AND bolt11=\"${bolt11}\"") + row=$(sql "SELECT id, label, bolt11, callback_url, payment_hash, msatoshi, status, pay_index, msatoshi_received, paid_at, description, expires_at FROM ln_invoice WHERE callback_url<>\"\" AND NOT calledback AND bolt11=\"${bolt11}\"") if [ -n "${row}" ]; then ln_manage_callback ${row}