diff --git a/proxy_docker/app/script/computefees.sh b/proxy_docker/app/script/computefees.sh index c8dfa2d..c0f1341 100644 --- a/proxy_docker/app/script/computefees.sh +++ b/proxy_docker/app/script/computefees.sh @@ -5,105 +5,105 @@ . ./sql.sh . ./blockchainrpc.sh -compute_fees() -{ - local pruned=${WATCHER_BTC_NODE_PRUNED} - if [ "${pruned}" = "true" ]; then - trace "[compute_fees] pruned=${pruned}" - # We want null instead of 0.00000000 in this case. - echo "null" - exit 0 - fi +compute_fees() { + local pruned=${WATCHER_BTC_NODE_PRUNED} + if [ "${pruned}" = "true" ]; then + trace "[compute_fees] pruned=${pruned}" + # We want null instead of 0.00000000 in this case. + echo "null" + exit 0 + fi - local txid=${1} + local txid=${1} - local tx_raw_details=$(cat rawtx-${txid}.blob) - trace "[compute_fees] tx_raw_details=${tx_raw_details}" - local vin_total_amount=$(compute_vin_total_amount "${tx_raw_details}") + # Let's reuse the file created in confirmation... + local tx_raw_details=$(cat conf-rawtx-${txid}.blob) + trace "[compute_fees] tx_raw_details=${tx_raw_details}" + local vin_total_amount=$(compute_vin_total_amount "${tx_raw_details}") - local vout_total_amount=0 - local vout_value - local vout_values=$(echo "${tx_raw_details}" | jq ".result.vout[].value") - for vout_value in ${vout_values} - do - vout_total_amount=$(awk "BEGIN { printf(\"%.8f\", ${vout_total_amount}+${vout_value}); exit }") - done + local vout_total_amount=0 + local vout_value + local vout_values=$(echo "${tx_raw_details}" | jq ".result.vout[].value") + for vout_value in ${vout_values} + do + vout_total_amount=$(awk "BEGIN { printf(\"%.8f\", ${vout_total_amount}+${vout_value}); exit }") + done - trace "[compute_fees] vin total amount=${vin_total_amount}" - trace "[compute_fees] vout total amount=${vout_total_amount}" + trace "[compute_fees] vin total amount=${vin_total_amount}" + trace "[compute_fees] vout total amount=${vout_total_amount}" - local fees=$(awk "BEGIN { printf(\"%.8f\", ${vin_total_amount}-${vout_total_amount}); exit }") - trace "[compute_fees] fees=${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() { - trace "Entering compute_vin_total_amount()..." + trace "Entering compute_vin_total_amount()..." - local main_tx=${1} - 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 - local vin_txid - local vin_raw_tx - local vin_vout_amount=0 - local vout - local vin_total_amount=0 - local vin_hash - local vin_confirmations - local vin_timereceived - local vin_vsize - local vin_blockhash - local vin_blockheight - local vin_blocktime - local txid_already_inserted=true + local main_tx=${1} + 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 + local vin_txid + local vin_raw_tx + local vin_vout_amount=0 + local vout + local vin_total_amount=0 + local vin_hash + local vin_confirmations + local vin_timereceived + local vin_vsize + local vin_blockhash + local vin_blockheight + local vin_blocktime + local txid_already_inserted=true - for vin_txid_vout in ${vin_txids_vout} - do - 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 - txid_already_inserted=false - vin_raw_tx=$(get_rawtransaction "${vin_txid}") - returncode=$? - if [ "${returncode}" -ne 0 ]; then - return ${returncode} - fi - fi - 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 }') - 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") + for vin_txid_vout in ${vin_txids_vout} + do + 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 + txid_already_inserted=false + vin_raw_tx=$(get_rawtransaction "${vin_txid}") + returncode=$? + if [ "${returncode}" -ne 0 ]; then + return ${returncode} + fi + fi + 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 }') + 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") - # Let's insert the vin tx in the DB just in case it would be useful - if ! ${txid_already_inserted}; then - # 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 - echo "${vin_raw_tx}" > rawtx-${vin_txid}.blob - sql "INSERT OR IGNORE INTO tx (txid, hash, confirmations, timereceived, size, vsize, blockhash, blockheight, blocktime, raw_tx) VALUES (\"${vin_txid}\", ${vin_hash}, ${vin_confirmations}, ${vin_timereceived}, ${vin_size}, ${vin_vsize}, ${vin_blockhash}, ${vin_blockheight}, ${vin_blocktime}, readfile('rawtx-${vin_txid}.blob'))" - trace_rc $? - rm rawtx-${vin_txid}.blob - txid_already_inserted=true - fi - done + # Let's insert the vin tx in the DB just in case it would be useful + if ! ${txid_already_inserted}; then + # 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 + echo "${vin_raw_tx}" > vin-rawtx-${vin_txid}.blob + sql "INSERT OR IGNORE INTO tx (txid, hash, confirmations, timereceived, size, vsize, blockhash, blockheight, blocktime, raw_tx) VALUES (\"${vin_txid}\", ${vin_hash}, ${vin_confirmations}, ${vin_timereceived}, ${vin_size}, ${vin_vsize}, ${vin_blockhash}, ${vin_blockheight}, ${vin_blocktime}, readfile('vin-rawtx-${vin_txid}.blob'))" + trace_rc $? + rm vin-rawtx-${vin_txid}.blob + txid_already_inserted=true + fi + done - echo "${vin_total_amount}" + echo "${vin_total_amount}" - return 0 + return 0 } case "${0}" in *computefees.sh) compute_vin_total_amount $@;; esac diff --git a/proxy_docker/app/script/confirmation.sh b/proxy_docker/app/script/confirmation.sh index 499f030..1862f3e 100644 --- a/proxy_docker/app/script/confirmation.sh +++ b/proxy_docker/app/script/confirmation.sh @@ -71,7 +71,7 @@ confirmation() { # 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 - echo "${tx_raw_details}" > rawtx-${txid}.blob + echo "${tx_raw_details}" > conf-rawtx-${txid}.blob if [ -z ${tx} ]; then # TX not found in our DB. @@ -103,7 +103,7 @@ confirmation() { 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'))" + 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('conf-rawtx-${txid}.blob'))" trace_rc $? id_inserted=$(sql "SELECT id FROM tx WHERE txid='${txid}'") @@ -126,14 +126,14 @@ confirmation() { blockhash=${tx_blockhash}, blockheight=${tx_blockheight}, blocktime=${tx_blocktime}, - raw_tx=readfile('rawtx-${txid}.blob') + raw_tx=readfile('conf-rawtx-${txid}.blob') WHERE txid=\"${txid}\"" trace_rc $? fi id_inserted=${tx} fi # Delete the temp file containing the raw tx (see above) - rm rawtx-${txid}.blob + rm conf-rawtx-${txid}.blob ######################################################################################################## diff --git a/proxy_docker/app/script/walletoperations.sh b/proxy_docker/app/script/walletoperations.sh index b067bf4..ce8a871 100644 --- a/proxy_docker/app/script/walletoperations.sh +++ b/proxy_docker/app/script/walletoperations.sh @@ -41,7 +41,7 @@ spend() { local fees=$(echo "${tx_details}" | jq '.result.fee | fabs' | awk '{ printf "%.8f", $0 }') # 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 - echo "${tx_raw_details}" > rawtx-${txid}.blob + echo "${tx_raw_details}" > spend-rawtx-${txid}.blob ######################################################################################################## # Let's publish the event if needed @@ -62,7 +62,7 @@ spend() { ######################################################################################################## # 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}, readfile('rawtx-${txid}.blob'))" + 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}, readfile('spend-rawtx-${txid}.blob'))" trace_rc $? id_inserted=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"") trace_rc $? @@ -73,7 +73,7 @@ spend() { data="${data},\"hash\":\"${txid}\"}" # Delete the temp file containing the raw tx (see above) - rm rawtx-${txid}.blob + rm spendrawtx-${txid}.blob else local message=$(echo "${response}" | jq -e ".error.message") data="{\"message\":${message}}" @@ -364,10 +364,10 @@ batchspend() { local fees=$(echo "${tx_details}" | jq '.result.fee | fabs' | awk '{ printf "%.8f", $0 }') # 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 - echo "${tx_raw_details}" > rawtx-${txid}.blob + echo "${tx_raw_details}" > batchspend-rawtx-${txid}.blob # 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}, readfile('rawtx-${txid}.blob'))" + 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}, readfile('batchspend-rawtx-${txid}.blob'))" returncode=$? trace_rc ${returncode} if [ "${returncode}" -eq 0 ]; then @@ -381,7 +381,7 @@ batchspend() { data="${data},\"hash\":\"${txid}\"}" # Delete the temp file containing the raw tx (see above) - rm rawtx-${txid}.blob + rm batchspend-rawtx-${txid}.blob else local message=$(echo "${response}" | jq -e ".error.message") data="{\"message\":${message}}"