Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed temp rawtx file conflicts #170

Merged
merged 1 commit into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 84 additions & 84 deletions proxy_docker/app/script/computefees.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions proxy_docker/app/script/confirmation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}'")
Expand All @@ -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

########################################################################################################

Expand Down
12 changes: 6 additions & 6 deletions proxy_docker/app/script/walletoperations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 $?
Expand All @@ -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}}"
Expand Down Expand Up @@ -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
Expand All @@ -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}}"
Expand Down