Fixed sqlite3 replaceable bool and rawtx with LF in DB

This commit is contained in:
kexkey
2020-08-21 11:05:12 -04:00
parent b24c2bd36e
commit 86095a765d
5 changed files with 26 additions and 26 deletions

View File

@@ -441,7 +441,7 @@ batchspend() {
# 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})
tx_raw_details=$(get_rawtransaction ${txid} | tr -d '\n')
# Amounts and fees are negative when spending so we absolute those fields
local tx_hash=$(echo "${tx_raw_details}" | jq '.result.hash')
@@ -456,13 +456,13 @@ 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}" > batchspend-rawtx-${txid}.blob
echo "${tx_raw_details}" > batchspend-rawtx-${txid}-$$.blob
# Get the info on the batch before setting it to done
row=$(sql "SELECT COUNT(id), COALESCE(MIN(inserted_ts), 0), COALESCE(SUM(amount), 0.00000000) FROM recipient WHERE tx_id IS NULL AND batcher_id=${batcher_id}")
# Let's insert the txid in our little DB -- then we'll already have it when receiving confirmation
id_inserted=$(sql "INSERT OR IGNORE INTO tx (txid, hash, confirmations, timereceived, fee, size, vsize, is_replaceable, conf_target, raw_tx) VALUES (\"${txid}\", ${tx_hash}, 0, ${tx_ts_firstseen}, ${fees}, ${tx_size}, ${tx_vsize}, ${tx_replaceable}, ${conf_target}, readfile('batchspend-rawtx-${txid}.blob')); SELECT LAST_INSERT_ROWID();")
id_inserted=$(sql "INSERT OR IGNORE INTO tx (txid, hash, confirmations, timereceived, fee, size, vsize, is_replaceable, conf_target, raw_tx) VALUES (\"${txid}\", ${tx_hash}, 0, ${tx_ts_firstseen}, ${fees}, ${tx_size}, ${tx_vsize}, ${tx_replaceable}, ${conf_target}, readfile('batchspend-rawtx-${txid}-$$.blob')); SELECT LAST_INSERT_ROWID();")
returncode=$?
trace_rc ${returncode}
if [ "${returncode}" -eq 0 ]; then
@@ -487,7 +487,7 @@ batchspend() {
response="${response},\"error\":null}"
# Delete the temp file containing the raw tx (see above)
rm batchspend-rawtx-${txid}.blob
rm batchspend-rawtx-${txid}-$$.blob
batch_webhooks "[${webhooks_data}]" '"batcherId":'${batcher_id}',"confTarget":'${conf_target}',"nbOutputs":'${count}',"oldest":"'${oldest}'","total":'${total}',"status":"accepted","txid":"'${txid}'","hash":'${tx_hash}',"details":{"firstseen":'${tx_ts_firstseen}',"size":'${tx_size}',"vsize":'${tx_vsize}',"replaceable":'${tx_replaceable}',"fee":'${fees}'}'
@@ -826,7 +826,7 @@ getbatchdetails() {
# Using txid
outerclause="AND r.tx_id=${tx_id}"
tx=$(sql "SELECT '\"txid\":\"' || txid || '\",\"hash\":\"' || hash || '\",\"details\":{\"firstseen\":' || timereceived || ',\"size\":' || size || ',\"vsize\":' || vsize || ',\"replaceable\":' || (CASE WHEN is_replaceable>0 THEN \"\\\"true\\\"\") || ',\"fee\":' || fee || '}' FROM tx WHERE id=${tx_id}")
tx=$(sql "SELECT '\"txid\":\"' || txid || '\",\"hash\":\"' || hash || '\",\"details\":{\"firstseen\":' || timereceived || ',\"size\":' || size || ',\"vsize\":' || vsize || ',\"replaceable\":' || CASE is_replaceable WHEN 1 THEN 'true' ELSE 'false' END || ',\"fee\":' || fee || '}' FROM tx WHERE id=${tx_id}")
else
# null txid
outerclause="AND r.tx_id IS NULL"

View File

@@ -68,7 +68,7 @@ compute_vin_total_amount()
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}")
vin_raw_tx=$(get_rawtransaction "${vin_txid}" | tr -d '\n')
returncode=$?
if [ "${returncode}" -ne 0 ]; then
return ${returncode}

View File

@@ -66,7 +66,7 @@ confirmation() {
local tx=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"")
local id_inserted
local tx_raw_details=$(get_rawtransaction ${txid})
local tx_raw_details=$(get_rawtransaction ${txid} | tr -d '\n')
local tx_nb_conf=$(echo "${tx_details}" | jq -r '.result.confirmations // 0')
# Sometimes raw tx are too long to be passed as paramater, so let's write

View File

@@ -113,11 +113,11 @@ testbatching() {
id2=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${id2}"
if [ "${id2}" -ne "1" ]; then
exit 40
exit 47
fi
id2=$(echo "${response}" | jq -e ".result.outputId")
if [ "$?" -ne 0 ]; then
exit 42
exit 50
fi
echo "outputId=${id2}"
echo "Tested addtobatch."
@@ -128,7 +128,7 @@ testbatching() {
echo "response=${response}"
echo "${response}" | jq -e ".error"
if [ "$?" -ne 0 ]; then
exit 44
exit 55
fi
echo "Tested batchspend."
@@ -147,7 +147,7 @@ testbatching() {
id=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${id}"
if [ "${id}" -ne "1" ]; then
exit 50
exit 60
fi
response=$(curl -sd '{"outputId":'${id2}'}' localhost:8888/removefrombatch)
@@ -155,7 +155,7 @@ testbatching() {
id=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${id}"
if [ "${id}" -ne "1" ]; then
exit 54
exit 64
fi
echo "Tested removefrombatch."
@@ -166,7 +166,7 @@ testbatching() {
data2=$(echo "${response}" | jq ".result.nbOutputs")
echo "nbOutputs=${data2}"
if [ "${data2}" -ne "$((${data}-2))" ]; then
exit 58
exit 68
fi
echo "Tested getbatchdetails."
@@ -189,7 +189,7 @@ testbatching() {
echo "response=${response}"
id=$(echo "${response}" | jq -e ".result.batcherId")
if [ "$?" -ne "0" ]; then
exit 60
exit 70
fi
# List batchers (should show at least default and testbatcher batchers)
@@ -199,7 +199,7 @@ testbatching() {
id=$(echo "${response}" | jq '.result[] | select(.batcherLabel == "testbatcher") | .batcherId')
echo "batcherId=${id}"
if [ -z "${id}" ]; then
exit 70
exit 75
fi
echo "Tested listbatchers."
@@ -233,7 +233,7 @@ testbatching() {
fi
echo "${response}" | jq -e ".result.outputs"
if [ "$?" -ne 0 ]; then
exit 32
exit 110
fi
response=$(curl -sd '{"batcherId":'${id}'}' localhost:8888/getbatchdetails)
@@ -241,11 +241,11 @@ testbatching() {
data=$(echo "${response}" | jq -r ".result.batcherLabel")
echo "batcherLabel=${data}"
if [ "${data}" != "testbatcher" ]; then
exit 35
exit 120
fi
echo "${response}" | jq -e ".result.outputs"
if [ "$?" -ne 0 ]; then
exit 37
exit 130
fi
echo "Tested getbatchdetails."
@@ -258,11 +258,11 @@ testbatching() {
data=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${data}"
if [ "${data}" -ne "${id}" ]; then
exit 40
exit 140
fi
id2=$(echo "${response}" | jq -e ".result.outputId")
if [ "$?" -ne 0 ]; then
exit 42
exit 142
fi
echo "outputId=${id2}"
@@ -273,11 +273,11 @@ testbatching() {
data=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${data}"
if [ "${data}" -ne "${id}" ]; then
exit 40
exit 150
fi
id2=$(echo "${response}" | jq -e ".result.outputId")
if [ "$?" -ne 0 ]; then
exit 42
exit 152
fi
echo "outputId=${id2}"
echo "Tested addtobatch."
@@ -288,12 +288,12 @@ testbatching() {
echo "response=${response}"
data2=$(echo "${response}" | jq -e ".result.txid")
if [ "$?" -ne 0 ]; then
exit 44
exit 160
fi
echo "txid=${data2}"
data=$(echo "${response}" | jq ".result.outputs | length")
if [ "${data}" -ne "2" ]; then
exit 42
exit 162
fi
echo "Tested batchspend."
@@ -305,7 +305,7 @@ testbatching() {
data=$(echo "${response}" | jq ".result.nbOutputs")
echo "nbOutputs=${data}"
if [ "${data}" -ne "2" ]; then
exit 42
exit 170
fi
echo "Tested getbatchdetails."

View File

@@ -35,7 +35,7 @@ spend() {
# 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})
tx_raw_details=$(get_rawtransaction ${txid} | tr -d '\n')
# Amounts and fees are negative when spending so we absolute those fields
local tx_hash=$(echo "${tx_raw_details}" | jq '.result.hash')