Added double-quotes on echo commands and LN node connect string

This commit is contained in:
kexkey
2019-01-15 09:49:22 -05:00
committed by kexkey
parent 6bbe5ac69b
commit 0c86522fdf
20 changed files with 119 additions and 85 deletions

View File

@@ -10,7 +10,7 @@ deriveindex()
trace "[deriveindex] index=${index}"
local pub32=$DERIVATION_PUB32
local path=$(echo -e $DERIVATION_PATH | sed -En "s/n/${index}/p")
local path=$(echo -e "$DERIVATION_PATH" | sed -En "s/n/${index}/p")
# pub32=$(grep "derivation.pub32" config.properties | cut -d'=' -f2)
# path=$(grep "derivation.path" config.properties | cut -d'=' -f2 | sed -En "s/n/${index}/p")

View File

@@ -29,34 +29,52 @@ ln_create_invoice()
# "bolt11": "lnbc100n1pwzllqgpp55a8xen9sdcntehwr93pkwnuu8nmtqx9yew0flalcxhx9nvy34crqdq9wsckgxqzpucqp2rzjqt04ll5ft3mcuy8hws4xcku2pnhma9r9mavtjtadawyrw5kgzp7g7zr745qq3mcqqyqqqqlgqqqqqzsqpcr85k33shzaxscpj29fadmjmfej6y2p380x9w4kxydqpxq87l6lshy69fry9q2yrtu037nt44x77uhzkdyn8043n5yj8tqgluvmcl69cquaxr68"
#}
trace "[ln_create_invoice] ./lightning-cli invoice ${msatoshi} \"${label}\" \${description}\" ${expiry}"
trace "[ln_create_invoice] ./lightning-cli invoice ${msatoshi} \"${label}\" \"${description}\" ${expiry}"
result=$(./lightning-cli invoice ${msatoshi} "${label}" "${description}" ${expiry})
returncode=$?
trace_rc ${returncode}
trace "[ln_create_invoice] result=${result}"
local bolt11=$(echo ${result} | jq ".bolt11" | tr -d '"')
trace "[ln_create_invoice] bolt11=${bolt11}"
local payment_hash=$(echo ${result} | jq ".payment_hash" | tr -d '"')
trace "[ln_create_invoice] payment_hash=${payment_hash}"
local expires_at=$(echo ${result} | jq ".expires_at" | tr -d '"')
trace "[ln_create_invoice] expires_at=${expires_at}"
if [ "${returncode}" -ne "0" ]; then
data=${result}
else
local bolt11=$(echo "${result}" | jq ".bolt11" | tr -d '"')
trace "[ln_create_invoice] bolt11=${bolt11}"
local payment_hash=$(echo "${result}" | jq ".payment_hash" | tr -d '"')
trace "[ln_create_invoice] payment_hash=${payment_hash}"
local expires_at=$(echo "${result}" | jq ".expires_at" | tr -d '"')
trace "[ln_create_invoice] expires_at=${expires_at}"
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 $?
id=$(sql "SELECT id FROM ln_invoice WHERE bolt11=\"${bolt11}\"")
trace_rc $?
# 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
data="{\"id\":\"${id}\","
data="${data}\"label\":\"${label}\","
data="${data}\"bolt11\":\"${bolt11}\","
data="${data}\"callback_url\":\"${callback_url}\","
data="${data}\"payment_hash\":\"${payment_hash}\","
data="${data}\"msatoshi\":${msatoshi},"
data="${data}\"status\":\"unpaid\","
data="${data}\"description\":\"${description}\","
data="${data}\"expires_at\":${expires_at}}"
trace "[ln_create_invoice] data=${data}"
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 $?
id=$(sql "SELECT id FROM ln_invoice WHERE bolt11=\"${bolt11}\"")
trace_rc $?
data="{\"id\":\"${id}\","
data="${data}\"label\":\"${label}\","
data="${data}\"bolt11\":\"${bolt11}\","
if [ -n "${connectstring}" ]; then
data="${data}\"connectstring\":\"${connectstring}\","
fi
data="${data}\"callback_url\":\"${callback_url}\","
data="${data}\"payment_hash\":\"${payment_hash}\","
data="${data}\"msatoshi\":${msatoshi},"
data="${data}\"status\":\"unpaid\","
data="${data}\"description\":\"${description}\","
data="${data}\"expires_at\":${expires_at}}"
trace "[ln_create_invoice] data=${data}"
fi
echo "${data}"
@@ -103,6 +121,7 @@ ln_delinvoice() {
local returncode
local rc
trace "[ln_delinvoice] ./lightning-cli delinvoice ${label} \"unpaid\""
result=$(./lightning-cli delinvoice ${label} "unpaid")
returncode=$?
trace_rc ${returncode}

View File

@@ -35,7 +35,7 @@ compute_fees()
local fees=$(awk "BEGIN { printf(\"%.8f\", ${vin_total_amount}-${vout_total_amount}); exit }")
trace "[compute_fees] fees=${fees}"
echo ${fees}
echo "${fees}"
}
compute_vin_total_amount()
@@ -43,8 +43,7 @@ compute_vin_total_amount()
trace "Entering compute_vin_total_amount()..."
local main_tx=${1}
# local vin_txids=$(echo ${main_tx} | jq '.result.vin[].txid')
local vin_txids_vout=$(echo ${main_tx} | jq '.result.vin[] | ((.txid + "-") + (.vout | tostring))')
local vin_txids_vout=$(echo "${main_tx}" | jq '.result.vin[] | ((.txid + "-") + (.vout | tostring))')
trace "[compute_vin_total_amount] vin_txids_vout=${vin_txids_vout}"
local returncode
local vin_txid_vout
@@ -64,8 +63,7 @@ compute_vin_total_amount()
for vin_txid_vout in ${vin_txids_vout}
do
# vin_txid=$(echo ${vin_txid} | tr -d '"')
vin_txid=$(echo ${vin_txid_vout} | tr -d '"' | cut -d '-' -f1)
vin_txid=$(echo "${vin_txid_vout}" | tr -d '"' | cut -d '-' -f1)
# Check if we already have the tx in our DB
vin_raw_tx=$(sql "SELECT raw_tx FROM tx WHERE txid=\"${vin_txid}\"")
if [ -z "${vin_raw_tx}" ]; then
@@ -76,21 +74,20 @@ compute_vin_total_amount()
return ${returncode}
fi
fi
# vout=$(echo ${main_tx} | jq ".result.vin[] | select(.txid == \"${vin_txid}\") | .vout")
vout=$(echo ${vin_txid_vout} | tr -d '"' | cut -d '-' -f2)
vout=$(echo "${vin_txid_vout}" | tr -d '"' | cut -d '-' -f2)
trace "[compute_vin_total_amount] vout=${vout}"
vin_vout_amount=$(echo ${vin_raw_tx} | jq ".result.vout[] | select(.n == ${vout}) | .value" | awk '{ printf "%.8f", $0 }')
vin_vout_amount=$(echo "${vin_raw_tx}" | jq ".result.vout[] | select(.n == ${vout}) | .value" | awk '{ printf "%.8f", $0 }')
trace "[compute_vin_total_amount] vin_vout_amount=${vin_vout_amount}"
vin_total_amount=$(awk "BEGIN { printf(\"%.8f\", ${vin_total_amount}+${vin_vout_amount}); exit}")
trace "[compute_vin_total_amount] vin_total_amount=${vin_total_amount}"
vin_hash=$(echo ${vin_raw_tx} | jq ".result.hash")
vin_confirmations=$(echo ${vin_raw_tx} | jq ".result.confirmations")
vin_timereceived=$(echo ${vin_raw_tx} | jq ".result.time")
vin_size=$(echo ${vin_raw_tx} | jq ".result.size")
vin_vsize=$(echo ${vin_raw_tx} | jq ".result.vsize")
vin_blockhash=$(echo ${vin_raw_tx} | jq ".result.blockhash")
vin_blockheight=$(echo ${vin_raw_tx} | jq ".result.blockheight")
vin_blocktime=$(echo ${vin_raw_tx} | jq ".result.blocktime")
vin_hash=$(echo "${vin_raw_tx}" | jq ".result.hash")
vin_confirmations=$(echo "${vin_raw_tx}" | jq ".result.confirmations")
vin_timereceived=$(echo "${vin_raw_tx}" | jq ".result.time")
vin_size=$(echo "${vin_raw_tx}" | jq ".result.size")
vin_vsize=$(echo "${vin_raw_tx}" | jq ".result.vsize")
vin_blockhash=$(echo "${vin_raw_tx}" | jq ".result.blockhash")
vin_blockheight=$(echo "${vin_raw_tx}" | jq ".result.blockheight")
vin_blocktime=$(echo "${vin_raw_tx}" | jq ".result.blocktime")
# Let's insert the vin tx in the DB just in case it would be useful
if ! ${txid_already_inserted}; then
@@ -104,7 +101,7 @@ compute_vin_total_amount()
fi
done
echo ${vin_total_amount}
echo "${vin_total_amount}"
return 0
}

View File

@@ -43,7 +43,7 @@ confirmation() {
# First of all, let's make sure we're working on watched addresses...
local address
local addresseswhere
local addresses=$(echo ${tx_details} | jq ".result.details[].address")
local addresses=$(echo "${tx_details}" | jq ".result.details[].address")
local notfirst=false
local IFS=$'\n'
@@ -68,7 +68,7 @@ confirmation() {
local tx=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"")
local id_inserted
local tx_raw_details=$(get_rawtransaction ${txid})
local tx_nb_conf=$(echo ${tx_details} | jq '.result.confirmations')
local tx_nb_conf=$(echo "${tx_details}" | jq '.result.confirmations')
# Sometimes raw tx are too long to be passed as paramater, so let's write
# it to a temp file for it to be read by sqlite3 and then delete the file
@@ -81,13 +81,13 @@ confirmation() {
# Let's first insert the tx in our DB
local tx_hash=$(echo ${tx_raw_details} | jq '.result.hash')
local tx_ts_firstseen=$(echo ${tx_details} | jq '.result.timereceived')
local tx_amount=$(echo ${tx_details} | jq '.result.amount')
local tx_hash=$(echo "${tx_raw_details}" | jq '.result.hash')
local tx_ts_firstseen=$(echo "${tx_details}" | jq '.result.timereceived')
local tx_amount=$(echo "${tx_details}" | jq '.result.amount')
local tx_size=$(echo ${tx_raw_details} | jq '.result.size')
local tx_vsize=$(echo ${tx_raw_details} | jq '.result.vsize')
local tx_replaceable=$(echo ${tx_details} | jq '.result."bip125-replaceable"')
local tx_size=$(echo "${tx_raw_details}" | jq '.result.size')
local tx_vsize=$(echo "${tx_raw_details}" | jq '.result.vsize')
local tx_replaceable=$(echo "${tx_details}" | jq '.result."bip125-replaceable"')
tx_replaceable=$([ ${tx_replaceable} = "yes" ] && echo 1 || echo 0)
local fees=$(compute_fees "${txid}")
@@ -99,9 +99,9 @@ confirmation() {
local tx_blocktime=null
if [ "${tx_nb_conf}" -gt "0" ]; then
trace "[confirmation] tx_nb_conf=${tx_nb_conf}"
tx_blockhash=$(echo ${tx_details} | jq '.result.blockhash')
tx_blockhash=$(echo "${tx_details}" | jq '.result.blockhash')
tx_blockheight=$(get_block_info $(echo ${tx_blockhash} | tr -d '"') | jq '.result.height')
tx_blocktime=$(echo ${tx_details} | jq '.result.blocktime')
tx_blocktime=$(echo "${tx_details}" | jq '.result.blocktime')
fi
sql "INSERT OR IGNORE INTO tx (txid, hash, confirmations, timereceived, fee, size, vsize, is_replaceable, blockhash, blockheight, blocktime, raw_tx) VALUES (\"${txid}\", ${tx_hash}, ${tx_nb_conf}, ${tx_ts_firstseen}, ${fees}, ${tx_size}, ${tx_vsize}, ${tx_replaceable}, ${tx_blockhash}, ${tx_blockheight}, ${tx_blocktime}, readfile('rawtx-${txid}.blob'))"
@@ -114,13 +114,13 @@ confirmation() {
# TX found in our DB.
# 1-conf or executecallbacks on an unconfirmed tx or spending watched address (in this case, we probably missed conf)
local tx_blockhash=$(echo ${tx_details} | jq '.result.blockhash')
local tx_blockhash=$(echo "${tx_details}" | jq '.result.blockhash')
trace "[confirmation] tx_blockhash=${tx_blockhash}"
if [ "${tx_blockhash}" = "null" ]; then
trace "[confirmation] probably being called by executecallbacks without any confirmations since the last time we checked"
else
local tx_blockheight=$(get_block_info $(echo ${tx_blockhash} | tr -d '"') | jq '.result.height')
local tx_blocktime=$(echo ${tx_details} | jq '.result.blocktime')
local tx_blockheight=$(get_block_info $(echo "${tx_blockhash}" | tr -d '"') | jq '.result.height')
local tx_blocktime=$(echo "${tx_details}" | jq '.result.blocktime')
sql "UPDATE tx SET
confirmations=${tx_nb_conf},
@@ -151,8 +151,8 @@ confirmation() {
do
watching_id=$(echo "${row}" | cut -d '|' -f1)
address=$(echo "${row}" | cut -d '|' -f2)
tx_vout_n=$(echo ${tx_details} | jq ".result.details[] | select(.address==\"${address}\") | .vout")
tx_vout_amount=$(echo ${tx_details} | jq ".result.details[] | select(.address==\"${address}\") | .amount")
tx_vout_n=$(echo "${tx_details}" | jq ".result.details[] | select(.address==\"${address}\") | .vout")
tx_vout_amount=$(echo "${tx_details}" | jq ".result.details[] | select(.address==\"${address}\") | .amount")
sql "INSERT OR IGNORE INTO watching_tx (watching_id, tx_id, vout, amount) VALUES (${watching_id}, ${id_inserted}, ${tx_vout_n}, ${tx_vout_amount})"
trace_rc $?
done

View File

@@ -73,7 +73,7 @@ manage_missed_conf()
fi
# | tr -d '"'
local txids=$(echo ${unspents} | jq ".result[].txid" | tr -d '"')
local txids=$(echo "${unspents}" | jq ".result[].txid" | tr -d '"')
for txid in ${txids}
do
confirmation "${txid}"

View File

@@ -60,7 +60,7 @@ main()
fi
# line=content-length: 406
case "${line}" in *[cC][oO][nN][tT][eE][nN][tT]-[lL][eE][nN][gG][tT][hH]*)
content_length=$(echo ${line} | cut -d ':' -f2)
content_length=$(echo "${line}" | cut -d ':' -f2)
trace "[main] content_length=${content_length}";
;;
esac

View File

@@ -9,16 +9,17 @@ response_to_client()
local response=${1}
local returncode=${2}
local contenttype=${3}
local length=$(echo -en "${response}" | wc -c)
[ -z "${contenttype}" ] && contenttype="application/json"
([ -z "${returncode}" ] || [ "${returncode}" -eq "0" ]) && echo -ne "HTTP/1.1 200 OK\r\n"
[ -n "${returncode}" ] && [ "${returncode}" -ne "0" ] && echo -ne "HTTP/1.1 400 Bad Request\r\n"
echo -en "Content-Type: ${contenttype}\r\nContent-Length: ${#response}\r\n\r\n${response}"
echo -en "Content-Type: ${contenttype}\r\nContent-Length: ${length}\r\n\r\n${response}"
# Small delay needed for the data to be processed correctly by peer
sleep 0.5s
sleep 1
}
htmlfile_response_to_client()
@@ -43,7 +44,7 @@ htmlfile_response_to_client()
[ ! -r "${pathfile}" ] && echo -ne "HTTP/1.1 404 Not Found\r\n"
# Small delay needed for the data to be processed correctly by peer
sleep 0.5s
sleep 1
}
binfile_response_to_client()
@@ -68,7 +69,7 @@ binfile_response_to_client()
[ ! -r "${pathfile}" ] && echo -ne "HTTP/1.1 404 Not Found\r\n"
# Small delay needed for the data to be processed correctly by peer
sleep 0.5s
sleep 1
}
case "${0}" in *responsetoclient.sh) response_to_client $@;; esac

View File

@@ -10,7 +10,7 @@ export DB_PATH
export DB_FILE
trim() {
echo -e $1 | sed -e 's/^[[:space:]]*//' | sed -e 's/[[:space:]]*$//'
echo -e "$1" | sed -e 's/^[[:space:]]*//' | sed -e 's/[[:space:]]*$//'
}
createCurlConfig() {

View File

@@ -1,7 +1,7 @@
#!/bin/sh
read line
echo ${line} 1>&2
echo "${line}" 1>&2
echo -ne "HTTP/1.1 200 OK\r\n"
echo -e "Content-Type: application/json\r\nContent-Length: 0\r\n\r\n"

View File

@@ -35,20 +35,22 @@ ln_waitanyinvoice() {
trace_rc ${returncode}
trace "[ln_waitanyinvoice] result=${result}"
bolt11=$(echo ${result} | jq ".bolt11" | tr -d '"')
pay_index=$(echo ${result} | jq ".pay_index" | tr -d '"')
msatoshi_received=$(echo ${result} | jq ".msatoshi_received" | tr -d '"')
status=$(echo ${result} | jq ".status" | tr -d '"')
paid_at=$(echo ${result} | jq ".paid_at" | tr -d '"')
if [ "${returncode}" -eq "0" ]; then
bolt11=$(echo "${result}" | jq ".bolt11" | tr -d '"')
pay_index=$(echo "${result}" | jq ".pay_index" | tr -d '"')
msatoshi_received=$(echo "${result}" | jq ".msatoshi_received" | tr -d '"')
status=$(echo "${result}" | jq ".status" | tr -d '"')
paid_at=$(echo "${result}" | jq ".paid_at" | tr -d '"')
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}\"")
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}\"")
if [ -n "${row}" ]; then
ln_manage_callback ${row}
if [ -n "${row}" ]; then
ln_manage_callback ${row}
fi
sql "UPDATE cyphernode_props SET value="${pay_index}" WHERE property=\"pay_index\""
fi
sql "UPDATE cyphernode_props SET value="${pay_index}" WHERE property=\"pay_index\""
}
while :

View File

@@ -21,7 +21,7 @@ spend() {
trace "[spend] response=${response}"
if [ "${returncode}" -eq 0 ]; then
local txid=$(echo ${response} | jq ".result" | tr -d '"')
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
trace "[spend] txid=${txid}"
# Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address
@@ -208,7 +208,7 @@ batchspend() {
trace "[batchspend] response=${response}"
if [ "${returncode}" -eq 0 ]; then
local txid=$(echo ${response} | jq ".result" | tr -d '"')
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
trace "[batchspend] txid=${txid}"
# Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address