diff --git a/notifier_docker/script/requesthandler.sh b/notifier_docker/script/requesthandler.sh index e150dfa..916d110 100644 --- a/notifier_docker/script/requesthandler.sh +++ b/notifier_docker/script/requesthandler.sh @@ -12,6 +12,8 @@ main() { local response local response_topic + # Messages should have this form: + # {"response-topic":"response/5541","cmd":"web","url":"2557df870b9a:1111/callback1conf","body":"eyJpZCI6IjUxIiwiYWRkc...dCI6MTUxNzYwMH0K"} while read msg; do trace "[main] New msg just arrived!" trace "[main] msg=${msg}" diff --git a/notifier_docker/script/response.sh b/notifier_docker/script/response.sh index e11f587..288687d 100644 --- a/notifier_docker/script/response.sh +++ b/notifier_docker/script/response.sh @@ -13,7 +13,6 @@ publish_response() { trace "[publish_response] response_topic=${response_topic}" trace "[publish_response] returncode=${returncode}" -# response=$(echo "${response}" | base64 | tr -d '\n') trace "[publish_response] mosquitto_pub -h broker -t \"${response_topic}\" -m \"${response}\"" mosquitto_pub -h broker -t "${response_topic}" -m "${response}" returncode=$? diff --git a/notifier_docker/script/web.sh b/notifier_docker/script/web.sh index 5ec6d02..00277d1 100644 --- a/notifier_docker/script/web.sh +++ b/notifier_docker/script/web.sh @@ -20,6 +20,7 @@ web() { # jq -e will have a return code of 1 if the supplied tag is null. if [ "$?" -eq "0" ]; then # body tag not null, so it's a POST + # The body field has been based-64 to avoid dealing with escaping special chars body=$(echo "${body}" | base64 -d) trace "[web] body=${body}" else @@ -31,16 +32,7 @@ web() { returncode=$? trace_rc ${returncode} - if [ "${returncode}" -eq "0" ]; then - # {"result":"success", "response":""} - result="success" - else - # {"result":"error", "response":""} - result="error" - fi - echo "${response}" -# echo "{\"result\":\"${result}\",\"http_code\":\"${http_code}\"}" return ${returncode} } @@ -55,8 +47,8 @@ curl_it() { local rnd=$(dd if=/dev/urandom bs=5 count=1 | xxd -pc 5) if [ -n "${data}" ]; then - trace "[curl_it] curl -o webresponse-${rnd} -w \"%{http_code}\" -H \"Content-Type: application/json\" -H \"X-Forwarded-Proto: https\" -d ${data} ${url}" - rc=$(curl -o webresponse-${rnd} -w "%{http_code}" -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d ${data} ${url}) + trace "[curl_it] curl -o webresponse-${rnd} -w \"%{http_code}\" -H \"Content-Type: application/json\" -H \"X-Forwarded-Proto: https\" -d \"${data}\" ${url}" + rc=$(curl -o webresponse-${rnd} -w "%{http_code}" -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d "${data}" ${url}) returncode=$? else trace "[curl_it] curl -o webresponse-$$ -w \"%{http_code}\" ${url}" diff --git a/proxy_docker/Dockerfile b/proxy_docker/Dockerfile index 7a89aa1..e46f981 100644 --- a/proxy_docker/Dockerfile +++ b/proxy_docker/Dockerfile @@ -13,8 +13,8 @@ WORKDIR ${HOME} COPY app/data/* ./ COPY app/script/* ./ COPY --from=cyphernode/clightning:v0.7.0-test /usr/local/bin/lightning-cli ./ -COPY --from=eclipse-mosquitto /usr/bin/mosquitto_rr /usr/bin/mosquitto_sub /usr/bin/mosquitto_pub /usr/bin/ -COPY --from=eclipse-mosquitto /usr/lib/libmosquitto* /usr/lib/ +COPY --from=eclipse-mosquitto:1.6 /usr/bin/mosquitto_rr /usr/bin/mosquitto_sub /usr/bin/mosquitto_pub /usr/bin/ +COPY --from=eclipse-mosquitto:1.6 /usr/lib/libmosquitto* /usr/lib/ RUN chmod +x startproxy.sh requesthandler.sh lightning-cli sqlmigrate*.sh waitanyinvoice.sh tests* \ && chmod o+w . \ diff --git a/proxy_docker/app/script/confirmation.sh b/proxy_docker/app/script/confirmation.sh index 1b80951..48bbfa1 100644 --- a/proxy_docker/app/script/confirmation.sh +++ b/proxy_docker/app/script/confirmation.sh @@ -150,6 +150,8 @@ confirmation() { do watching_id=$(echo "${row}" | cut -d '|' -f1) address=$(echo "${row}" | cut -d '|' -f2) + # In the case of us spending to a watched address, the address appears twice in the details, + # once on the spend side (negative amount) and once on the receiving side (positive amount) tx_vout_n=$(echo "${tx_details}" | jq ".result.details | map(select(.address==\"${address}\"))[0] | .vout") tx_vout_amount=$(echo "${tx_details}" | jq ".result.details | map(select(.address==\"${address}\"))[0] | .amount | fabs" | awk '{ printf "%.8f", $0 }') sql "INSERT OR IGNORE INTO watching_tx (watching_id, tx_id, vout, amount) VALUES (${watching_id}, ${id_inserted}, ${tx_vout_n}, ${tx_vout_amount})" @@ -177,6 +179,7 @@ confirmation() { ) 201>./.confirmation.lock + # There's a lock in callbacks, let's get out of the confirmation lock before entering another one do_callbacks echo '{"result":"confirmed"}' diff --git a/proxy_docker/app/script/notify.sh b/proxy_docker/app/script/notify.sh index 4fd23d7..4715aee 100644 --- a/proxy_docker/app/script/notify.sh +++ b/proxy_docker/app/script/notify.sh @@ -14,11 +14,14 @@ notify_web() { local response local http_code + # We use the pid as the response-topic, so there's no conflict in responses. trace "[notify_web] mosquitto_rr -h broker -W 5 -t notifier -e \"response/$$\" -m \"{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"${url}\",\"body\":\"${body}\"}\"" response=$(mosquitto_rr -h broker -W 5 -t notifier -e "response/$$" -m "{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"${url}\",\"body\":\"${body}\"}") returncode=$? trace_rc ${returncode} + # The response looks like this: {"curl_code":0,"http_code":200,"body":"..."} where the body + # is the base64(response body) but we don't need the response content here. trace "[notify_web] response=${response}" http_code=$(echo "${response}" | jq ".http_code" | tr -d '"') trace "[notify_web] http_code=${http_code}" diff --git a/proxy_docker/app/script/walletoperations.sh b/proxy_docker/app/script/walletoperations.sh index 7c1b134..56302b7 100644 --- a/proxy_docker/app/script/walletoperations.sh +++ b/proxy_docker/app/script/walletoperations.sh @@ -26,13 +26,14 @@ spend() { local txid=$(echo "${response}" | jq ".result" | tr -d '"') trace "[spend] txid=${txid}" + # Let's get transaction details on the spending wallet so that we have fee information tx_details=$(get_transaction ${txid} "spender") tx_raw_details=$(get_rawtransaction ${txid}) + # Amounts and fees are negative when spending so we absolute those fields 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 | fabs' | awk '{ printf "%.8f", $0 }') - 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"') @@ -40,8 +41,7 @@ spend() { local fees=$(echo "${tx_details}" | jq '.result.fee | fabs' | awk '{ printf "%.8f", $0 }') local rawtx=$(echo "${tx_details}" | jq '.result.hex') - # Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address - #sql "INSERT OR IGNORE INTO tx (txid) VALUES (\"${txid}\")" + # Let's insert the txid in our little DB -- then we'll already have it when receiving confirmation sql "INSERT OR IGNORE INTO tx (txid, hash, confirmations, timereceived, fee, size, vsize, is_replaceable, raw_tx) VALUES (\"${txid}\", ${tx_hash}, 0, ${tx_ts_firstseen}, ${fees}, ${tx_size}, ${tx_vsize}, ${tx_replaceable}, ${rawtx})" trace_rc $? id_inserted=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"") @@ -230,13 +230,14 @@ batchspend() { local txid=$(echo "${response}" | jq ".result" | tr -d '"') trace "[batchspend] txid=${txid}" + # Let's get transaction details on the spending wallet so that we have fee information tx_details=$(get_transaction ${txid} "spender") tx_raw_details=$(get_rawtransaction ${txid}) + # Amounts and fees are negative when spending so we absolute those fields 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 | fabs' | awk '{ printf "%.8f", $0 }') - 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"') @@ -244,8 +245,7 @@ batchspend() { local fees=$(echo "${tx_details}" | jq '.result.fee | fabs' | awk '{ printf "%.8f", $0 }') local rawtx=$(echo "${tx_details}" | jq '.result.hex') - # Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address - #sql "INSERT OR IGNORE INTO tx (txid) VALUES (\"${txid}\")" + # Let's insert the txid in our little DB -- then we'll already have it when receiving confirmation sql "INSERT OR IGNORE INTO tx (txid, hash, confirmations, timereceived, fee, size, vsize, is_replaceable, raw_tx) VALUES (\"${txid}\", ${tx_hash}, 0, ${tx_ts_firstseen}, ${fees}, ${tx_size}, ${tx_vsize}, ${tx_replaceable}, ${rawtx})" returncode=$? trace_rc ${returncode}