Added ln_getconnectionstring

This commit is contained in:
kexkey
2019-01-16 22:21:07 -05:00
committed by kexkey
parent 6ee834d944
commit 1978932789
4 changed files with 28 additions and 10 deletions

View File

@@ -16,6 +16,8 @@ action_getblockinfo=watcher
action_gettransaction=watcher
action_ln_getinfo=watcher
action_ln_create_invoice=watcher
action_ln_getconnectionstring=watcher
action_ln_decodebolt11=watcher
# Spender can do what the watcher can do, plus:
action_getbalance=spender
@@ -32,7 +34,6 @@ action_ln_newaddr=spender
action_ots_stamp=spender
action_ots_getfile=spender
action_ln_getinvoice=spender
action_ln_decodebolt11=spender
# Admin can do what the spender can do, plus:

View File

@@ -39,6 +39,8 @@ action_getblockinfo=watcher
action_gettransaction=watcher
action_ln_getinfo=watcher
action_ln_create_invoice=watcher
action_ln_getconnectionstring=watcher
action_ln_decodebolt11=watcher
# Spender can do what the watcher can do, plus:
action_getbalance=spender

View File

@@ -46,15 +46,7 @@ ln_create_invoice()
trace "[ln_create_invoice] expires_at=${expires_at}"
# Let's get the connect string if provided in configuration
local connectstring
local getinfo=$(ln_getinfo)
trace "[ln_create_invoice] getinfo=${getinfo}"
echo ${getinfo} | jq -e '.address[0]' > /dev/null
if [ "$?" -eq 0 ]; then
# If there's an address
connectstring="$(echo ${getinfo} | jq '((.id + "@") + (.address[0] | ((.address + ":") + (.port | tostring))))' | tr -d '"')"
trace "[ln_create_invoice] connectstring=${connectstring}"
fi
local connectstring=$(ln_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\")"
trace_rc $?
@@ -81,6 +73,22 @@ ln_create_invoice()
return ${returncode}
}
ln_get_connection_string() {
trace "Entering ln_get_connection_string()..."
# Let's get the connect string if provided in configuration
local connectstring
local getinfo=$(ln_getinfo)
echo ${getinfo} | jq -e '.address[0]' > /dev/null
if [ "$?" -eq 0 ]; then
# If there's an address
connectstring="$(echo ${getinfo} | jq '((.id + "@") + (.address[0] | ((.address + ":") + (.port | tostring))))' | tr -d '"')"
trace "[ln_get_connection_string] connectstring=${connectstring}"
fi
echo "${connectstring}"
}
ln_getinfo()
{
trace "Entering ln_get_info()..."

View File

@@ -258,6 +258,13 @@ main()
response_to_client "${response}" ${?}
break
;;
ln_getconnectionstring)
# GET http://192.168.111.152:8080/ln_getconnectionstring
response=$(ln_get_connection_string)
response_to_client "${response}" ${?}
break
;;
ln_create_invoice)
# POST http://192.168.111.152:8080/ln_create_invoice
# BODY {"msatoshi":"10000","label":"koNCcrSvhX3dmyFhW","description":"Bylls order #10649","expiry":"900","callback_url":"http://192.168.122.159"}