From 0c86522fdf85e6e2a9ea016ec2a6a78a0c28ef6c Mon Sep 17 00:00:00 2001 From: kexkey Date: Tue, 15 Jan 2019 09:49:22 -0500 Subject: [PATCH] Added double-quotes on echo commands and LN node connect string --- api_auth_docker/auth.sh | 12 ++-- dist/config.json.sample | 1 + .../generators/app/help.json | 1 + .../generators/app/prompters/100_lightning.js | 9 +++ .../templates/lightning/c-lightning/config | 2 + otsclient_docker/script/requesthandler.sh | 2 +- otsclient_docker/script/responsetoclient.sh | 3 +- proxy_docker/app/script/bitcoin.sh | 2 +- proxy_docker/app/script/call_lightningd.sh | 61 ++++++++++++------- proxy_docker/app/script/computefees.sh | 31 +++++----- proxy_docker/app/script/confirmation.sh | 30 ++++----- proxy_docker/app/script/manage_missed_conf.sh | 2 +- proxy_docker/app/script/requesthandler.sh | 2 +- proxy_docker/app/script/responsetoclient.sh | 9 +-- proxy_docker/app/script/startproxy.sh | 2 +- proxy_docker/app/script/tests-cb.sh | 2 +- proxy_docker/app/script/waitanyinvoice.sh | 24 ++++---- proxy_docker/app/script/walletoperations.sh | 4 +- pycoin_docker/script/requesthandler.sh | 2 +- pycoin_docker/script/responsetoclient.sh | 3 +- 20 files changed, 119 insertions(+), 85 deletions(-) diff --git a/api_auth_docker/auth.sh b/api_auth_docker/auth.sh index 8604f3a..57eae04 100644 --- a/api_auth_docker/auth.sh +++ b/api_auth_docker/auth.sh @@ -20,16 +20,16 @@ verify_sign() { local returncode - local header64=$(echo ${1} | cut -sd '.' -f1) - local payload64=$(echo ${1} | cut -sd '.' -f2) - local signature=$(echo ${1} | cut -sd '.' -f3) + local header64=$(echo "${1}" | cut -sd '.' -f1) + local payload64=$(echo "${1}" | cut -sd '.' -f2) + local signature=$(echo "${1}" | cut -sd '.' -f3) trace "[verify_sign] header64=${header64}" trace "[verify_sign] payload64=${payload64}" trace "[verify_sign] signature=${signature}" - local payload=$(echo -n ${payload64} | base64 -d) - local exp=$(echo ${payload} | jq ".exp") + local payload=$(echo -n "${payload64}" | base64 -d) + local exp=$(echo "${payload}" | jq ".exp") local current=$(date +"%s") trace "[verify_sign] payload=${payload}" @@ -38,7 +38,7 @@ verify_sign() if [ ${exp} -gt ${current} ]; then trace "[verify_sign] Not expired, let's validate signature" - local id=$(echo ${payload} | jq ".id" | tr -d '"') + local id=$(echo "${payload}" | jq ".id" | tr -d '"') trace "[verify_sign] id=${id}" # Check for code injection diff --git a/dist/config.json.sample b/dist/config.json.sample index c0abc27..7158652 100644 --- a/dist/config.json.sample +++ b/dist/config.json.sample @@ -14,6 +14,7 @@ "bitcoin_prune": false, "bitcoin_uacomment": "", "lightning_implementation": "c-lightning", + "lightning_external_ip": "clightning.nodes.com", "lightning_nodename": "SatoshiPortal", "lightning_nodecolor": "ff00ff", "electrum_implementation": "eps", diff --git a/install/generator-cyphernode/generators/app/help.json b/install/generator-cyphernode/generators/app/help.json index 90deeb1..0084243 100644 --- a/install/generator-cyphernode/generators/app/help.json +++ b/install/generator-cyphernode/generators/app/help.json @@ -28,6 +28,7 @@ "bitcoin_datapath_custom": " ", "bitcoin_expose": "By default, Bitcoin node ports (RPC and protocol) won't be published outside of Docker. Do you want to expose them so that your node can be accessed from outside of the Docker network?", "lightning_implementation": "Multiple LN implementations exist. Please choose the one you want to use with Cyphernode.", + "lightning_external_ip": "If you want you LN node to be accessible from the Internet, provide the IP address that other LN nodes will use to connect to it. This is usually your router's public IP. NOTE: In case you are running Cyphernode at home. This option won't make your router forward needed LN ports; you still need to configure and manage that part yourself in your router configuration.", "lightning_nodename": "LN nodes have names. Choose the name you want for yours.", "lightning_nodecolor": "LN nodes have colors. Choose the color you want for yours in RGB format (RRGGBB). For example, pure red would be ff0000.", "lightning_datapath": "Path name to where LN's data files are stored. This directory will be mounted into the LN node's container. If running on OSX, check mountable directories in Docker's File Sharing configs.", diff --git a/install/generator-cyphernode/generators/app/prompters/100_lightning.js b/install/generator-cyphernode/generators/app/prompters/100_lightning.js index 5da99a9..fb7becb 100644 --- a/install/generator-cyphernode/generators/app/prompters/100_lightning.js +++ b/install/generator-cyphernode/generators/app/prompters/100_lightning.js @@ -46,6 +46,15 @@ module.exports = { ] }, */ + { + when: featureCondition, + type: 'input', + name: 'lightning_external_ip', + default: utils._getDefault( 'lightning_external_ip' ), + filter: utils._trimFilter, + validate: utils._ipOrFQDNValidator, + message: prefix()+'What external ip does your lightning node have?'+utils._getHelp('lightning_external_ip'), + }, { when: featureCondition, type: 'input', diff --git a/install/generator-cyphernode/generators/app/templates/lightning/c-lightning/config b/install/generator-cyphernode/generators/app/templates/lightning/c-lightning/config index 2ced26c..8ccaacf 100644 --- a/install/generator-cyphernode/generators/app/templates/lightning/c-lightning/config +++ b/install/generator-cyphernode/generators/app/templates/lightning/c-lightning/config @@ -13,3 +13,5 @@ rgb=<%= lightning_nodecolor %> bitcoin-rpcconnect=<%= (bitcoin_mode === 'internal')?'bitcoin':bitcoin_node_ip %> bitcoin-rpcuser=<%= bitcoin_rpcuser %> bitcoin-rpcpassword=<%= bitcoin_rpcpassword %> + +announce-addr=<%= lightning_external_ip %> diff --git a/otsclient_docker/script/requesthandler.sh b/otsclient_docker/script/requesthandler.sh index 7ad8d08..23c1614 100644 --- a/otsclient_docker/script/requesthandler.sh +++ b/otsclient_docker/script/requesthandler.sh @@ -49,7 +49,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 diff --git a/otsclient_docker/script/responsetoclient.sh b/otsclient_docker/script/responsetoclient.sh index c907e76..6203950 100644 --- a/otsclient_docker/script/responsetoclient.sh +++ b/otsclient_docker/script/responsetoclient.sh @@ -8,11 +8,12 @@ response_to_client() local response=${1} local returncode=${2} + local length=$(echo -n "${response}" | wc -c) ([ -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 -e "Content-Type: application/json\r\nContent-Length: ${#response}\r\n\r\n${response}" + echo -e "Content-Type: application/json\r\nContent-Length: ${length}\r\n\r\n${response}" # Small delay needed for the data to be processed correctly by peer sleep 0.2s diff --git a/proxy_docker/app/script/bitcoin.sh b/proxy_docker/app/script/bitcoin.sh index 6364022..4c7e596 100644 --- a/proxy_docker/app/script/bitcoin.sh +++ b/proxy_docker/app/script/bitcoin.sh @@ -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") diff --git a/proxy_docker/app/script/call_lightningd.sh b/proxy_docker/app/script/call_lightningd.sh index 7f67060..471a412 100644 --- a/proxy_docker/app/script/call_lightningd.sh +++ b/proxy_docker/app/script/call_lightningd.sh @@ -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} diff --git a/proxy_docker/app/script/computefees.sh b/proxy_docker/app/script/computefees.sh index 640e24d..c8dfa2d 100644 --- a/proxy_docker/app/script/computefees.sh +++ b/proxy_docker/app/script/computefees.sh @@ -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 } diff --git a/proxy_docker/app/script/confirmation.sh b/proxy_docker/app/script/confirmation.sh index 51cc6cd..c9f769b 100644 --- a/proxy_docker/app/script/confirmation.sh +++ b/proxy_docker/app/script/confirmation.sh @@ -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 diff --git a/proxy_docker/app/script/manage_missed_conf.sh b/proxy_docker/app/script/manage_missed_conf.sh index 610e776..8d07de3 100644 --- a/proxy_docker/app/script/manage_missed_conf.sh +++ b/proxy_docker/app/script/manage_missed_conf.sh @@ -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}" diff --git a/proxy_docker/app/script/requesthandler.sh b/proxy_docker/app/script/requesthandler.sh index 8c643f3..74d30b7 100644 --- a/proxy_docker/app/script/requesthandler.sh +++ b/proxy_docker/app/script/requesthandler.sh @@ -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 diff --git a/proxy_docker/app/script/responsetoclient.sh b/proxy_docker/app/script/responsetoclient.sh index ad4467d..40f2277 100644 --- a/proxy_docker/app/script/responsetoclient.sh +++ b/proxy_docker/app/script/responsetoclient.sh @@ -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 diff --git a/proxy_docker/app/script/startproxy.sh b/proxy_docker/app/script/startproxy.sh index 4df34b0..4ec85dc 100644 --- a/proxy_docker/app/script/startproxy.sh +++ b/proxy_docker/app/script/startproxy.sh @@ -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() { diff --git a/proxy_docker/app/script/tests-cb.sh b/proxy_docker/app/script/tests-cb.sh index bccbed8..ed659f3 100644 --- a/proxy_docker/app/script/tests-cb.sh +++ b/proxy_docker/app/script/tests-cb.sh @@ -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" diff --git a/proxy_docker/app/script/waitanyinvoice.sh b/proxy_docker/app/script/waitanyinvoice.sh index bfd8d75..7125790 100644 --- a/proxy_docker/app/script/waitanyinvoice.sh +++ b/proxy_docker/app/script/waitanyinvoice.sh @@ -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 : diff --git a/proxy_docker/app/script/walletoperations.sh b/proxy_docker/app/script/walletoperations.sh index c48d996..fd2b57f 100644 --- a/proxy_docker/app/script/walletoperations.sh +++ b/proxy_docker/app/script/walletoperations.sh @@ -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 diff --git a/pycoin_docker/script/requesthandler.sh b/pycoin_docker/script/requesthandler.sh index b5e12dc..5be6d0c 100644 --- a/pycoin_docker/script/requesthandler.sh +++ b/pycoin_docker/script/requesthandler.sh @@ -49,7 +49,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 diff --git a/pycoin_docker/script/responsetoclient.sh b/pycoin_docker/script/responsetoclient.sh index 8204395..6d8e9f2 100644 --- a/pycoin_docker/script/responsetoclient.sh +++ b/pycoin_docker/script/responsetoclient.sh @@ -8,11 +8,12 @@ response_to_client() local response=${1} local returncode=${2} + local length=$(echo -n "${response}" | wc -c) ([ -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: application/json\r\nContent-Length: ${#response}\r\n\r\n${response}" + echo -en "Content-Type: application/json\r\nContent-Length: ${length}\r\n\r\n${response}" # Small delay needed for the data to be processed correctly by peer sleep 0.2s