ln_connectfund finished

This commit is contained in:
kexkey
2019-03-27 15:54:54 -04:00
committed by kexkey
parent 5df00377f0
commit 25f377d94e
2 changed files with 31 additions and 5 deletions

View File

@@ -178,11 +178,16 @@ ln_decodebolt11() {
ln_connectfund() {
trace "Entering ln_connectfund()..."
# {"peer":"nodeId@ip:port","msatoshi":"100000","callbackUrl":"https://callbackUrl/?channelReady=f3y2c3cvm4uzg2gq"}
local result
local returncode
local tx
local txid
local nodeId
local data
local channel_id
local msg
local request=${1}
local peer=$(echo "${request}" | jq ".peer" | tr -d '"')
@@ -234,19 +239,39 @@ ln_connectfund() {
# { "code" : 301, "message" : "Cannot afford transaction" }
# Let's find what to watch
txid=$(echo "${result}" | jq ".txid" | tr -d '"')
tx=$(echo "${result}" | jq ".tx" | tr -d '"')
txid=$(echo "${result}" | jq ".txid")
tx=$(echo "${result}" | jq ".tx")
channel_id=$(echo "${result}" | jq ".channel_id")
data="{\"txid\":${txid},\"xconfCallbackURL\":\"${callback_url}\",\"nbxconf\":6}"
result=$(watchtxidrequest "${data}")
returncode=$?
trace_rc ${returncode}
trace "[ln_connectfund] result=${result}"
if [ "${returncode}" -eq "0" ]; then
result="{\"result\":\"success\",\"txid\":${txid},\"channel_id\":${channel_id}}"
else
trace "[ln_connectfund] Error watching txid, result=${result}"
result="{\"result\":\"failed\",\"message\":\"Failed at watching txid\"}"
fi
else
# Error funding
trace "[ln_connectfund] Error funding, result=${result}"
msg=$(echo "${result}" | jq ".message")
result="{\"result\":\"failed\",\"message\":${msg}}"
fi
else
# Error connecting
trace "[ln_connectfund] Error connecting, result=${result}"
msg=$(echo "${result}" | jq ".message")
result="{\"result\":\"failed\",\"message\":${msg}}"
fi
echo "${result}"
return ${returncode}
}
ln_pay() {

View File

@@ -307,6 +307,7 @@ main()
ln_connectfund)
# POST http://192.168.111.152:8080/ln_connectfund
# BODY {"peer":"nodeId@ip:port","msatoshi":"100000","callbackUrl":"https://callbackUrl/?channelReady=f3y2c3cvm4uzg2gq"}
# curl -H "Content-Type: application/json" -d '{"peer":"nodeId@ip:port","msatoshi":"100000","callbackUrl":"https://callbackUrl/?channelReady=f3y2c3cvm4uzg2gq"}' proxy:8888/ln_connectfund
response=$(ln_connectfund "${line}")
response_to_client "${response}" ${?}