mirror of
https://github.com/aljazceru/cyphernode.git
synced 2025-12-18 13:14:56 +01:00
Have true/false in selects instead of t/f, fixed dir creation
This commit is contained in:
4
dist/setup.sh
vendored
4
dist/setup.sh
vendored
@@ -394,8 +394,8 @@ install_docker() {
|
||||
|
||||
|
||||
if [ ! -d $LOGS_DATAPATH ]; then
|
||||
step " [32mcreate[0m $POSTGRES_DATAPATH"
|
||||
sudo_if_required mkdir -p $POSTGRES_DATAPATH
|
||||
step " [32mcreate[0m $LOGS_DATAPATH"
|
||||
sudo_if_required mkdir -p $LOGS_DATAPATH
|
||||
next
|
||||
fi
|
||||
|
||||
|
||||
@@ -536,7 +536,7 @@ batch_check_webhooks() {
|
||||
local total
|
||||
local tx_id
|
||||
|
||||
local batching=$(sql "SELECT address, amount, r.id, webhook_url, b.id, t.txid, t.hash, t.timereceived, t.fee, t.size, t.vsize, t.is_replaceable, t.conf_target, t.id FROM recipient r, batcher b, tx t WHERE r.batcher_id=b.id AND r.tx_id=t.id AND NOT calledback AND tx_id IS NOT NULL AND webhook_url IS NOT NULL")
|
||||
local batching=$(sql "SELECT address, amount, r.id, webhook_url, b.id, t.txid, t.hash, t.timereceived, t.fee, t.size, t.vsize, t.is_replaceable::text, t.conf_target, t.id FROM recipient r, batcher b, tx t WHERE r.batcher_id=b.id AND r.tx_id=t.id AND NOT calledback AND tx_id IS NOT NULL AND webhook_url IS NOT NULL")
|
||||
trace "[batch_check_webhooks] batching=${batching}"
|
||||
|
||||
local IFS=$'\n'
|
||||
@@ -566,7 +566,6 @@ batch_check_webhooks() {
|
||||
tx_vsize=$(echo "${row}" | cut -d '|' -f11)
|
||||
trace "[batch_check_webhooks] tx_vsize=${tx_vsize}"
|
||||
tx_replaceable=$(echo "${row}" | cut -d '|' -f12)
|
||||
tx_replaceable=$([ "${tx_replaceable}" -eq "1" ] && echo "true" || echo "false")
|
||||
trace "[batch_check_webhooks] tx_replaceable=${tx_replaceable}"
|
||||
conf_target=$(echo "${row}" | cut -d '|' -f13)
|
||||
trace "[batch_check_webhooks] conf_target=${conf_target}"
|
||||
@@ -826,7 +825,7 @@ getbatchdetails() {
|
||||
fi
|
||||
|
||||
# First get the batch summary
|
||||
batch=$(sql "SELECT b.id, COALESCE(t.id, NULL), '{\"batcherId\":' || b.id || ',\"batcherLabel\":\"' || b.label || '\",\"confTarget\":' || b.conf_target || ',\"nbOutputs\":' || COUNT(r.id) || ',\"oldest\":\"' ||COALESCE(MIN(r.inserted_ts), DATE '0001-01-01') || '\",\"total\":' ||COALESCE(SUM(amount), 0.00000000) FROM batcher b LEFT JOIN recipient r ON r.batcher_id=b.id ${outerclause} LEFT JOIN tx t ON t.id=r.tx_id WHERE ${whereclause} GROUP BY b.id, t.id")
|
||||
batch=$(sql "SELECT b.id, COALESCE(t.id, NULL), '{\"batcherId\":' || b.id || ',\"batcherLabel\":\"' || b.label || '\",\"confTarget\":' || b.conf_target || ',\"nbOutputs\":' || COUNT(r.id) || ',\"oldest\":\"' || COALESCE(MIN(r.inserted_ts), DATE '0001-01-01') || '\",\"total\":' || COALESCE(SUM(amount), 0.00000000) FROM batcher b LEFT JOIN recipient r ON r.batcher_id=b.id ${outerclause} LEFT JOIN tx t ON t.id=r.tx_id WHERE ${whereclause} GROUP BY b.id, t.id")
|
||||
trace "[getbatchdetails] batch=${batch}"
|
||||
|
||||
if [ -n "${batch}" ]; then
|
||||
@@ -839,7 +838,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 is_replaceable WHEN true THEN 'true' ELSE 'false' END || ',\"fee\":' || fee || '}' FROM tx WHERE id=${tx_id}")
|
||||
tx=$(sql "SELECT '\"txid\":\"' || txid || '\",\"hash\":\"' || hash || '\",\"details\":{\"firstseen\":' || timereceived || ',\"size\":' || size || ',\"vsize\":' || vsize || ',\"replaceable\":' || is_replaceable || ',\"fee\":' || fee || '}' FROM tx WHERE id=${tx_id}")
|
||||
else
|
||||
# null txid
|
||||
outerclause="AND r.tx_id IS NULL"
|
||||
|
||||
@@ -20,7 +20,7 @@ do_callbacks() {
|
||||
fi
|
||||
|
||||
# Let's fetch all the watching addresses still being watched but not called back
|
||||
local callbacks=$(sql "SELECT DISTINCT w.callback0conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime, w.id, is_replaceable, pub32_index, pub32, w32.label, derivation_path, event_message, hash FROM watching w LEFT JOIN watching_tx ON w.id = watching_id LEFT JOIN tx ON tx.id = tx_id LEFT JOIN watching_by_pub32 w32 ON w.watching_by_pub32_id = w32.id WHERE NOT calledback0conf AND watching_id IS NOT NULL AND w.callback0conf IS NOT NULL AND w.watching${txid_where}")
|
||||
local callbacks=$(sql "SELECT DISTINCT w.callback0conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime, w.id, is_replaceable::text, pub32_index, pub32, w32.label, derivation_path, event_message, hash FROM watching w LEFT JOIN watching_tx ON w.id = watching_id LEFT JOIN tx ON tx.id = tx_id LEFT JOIN watching_by_pub32 w32 ON w.watching_by_pub32_id = w32.id WHERE NOT calledback0conf AND watching_id IS NOT NULL AND w.callback0conf IS NOT NULL AND w.watching${txid_where}")
|
||||
trace "[do_callbacks] callbacks0conf=${callbacks}"
|
||||
|
||||
local returncode
|
||||
@@ -39,7 +39,7 @@ do_callbacks() {
|
||||
fi
|
||||
done
|
||||
|
||||
callbacks=$(sql "SELECT DISTINCT w.callback1conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime, w.id, is_replaceable, pub32_index, pub32, w32.label, derivation_path, event_message, hash FROM watching w JOIN watching_tx wt ON w.id = wt.watching_id JOIN tx t ON wt.tx_id = t.id LEFT JOIN watching_by_pub32 w32 ON watching_by_pub32_id = w32.id WHERE NOT calledback1conf AND confirmations>0 AND w.callback1conf IS NOT NULL AND w.watching${txid_where}")
|
||||
callbacks=$(sql "SELECT DISTINCT w.callback1conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime, w.id, is_replaceable::text, pub32_index, pub32, w32.label, derivation_path, event_message, hash FROM watching w JOIN watching_tx wt ON w.id = wt.watching_id JOIN tx t ON wt.tx_id = t.id LEFT JOIN watching_by_pub32 w32 ON watching_by_pub32_id = w32.id WHERE NOT calledback1conf AND confirmations>0 AND w.callback1conf IS NOT NULL AND w.watching${txid_where}")
|
||||
trace "[do_callbacks] callbacks1conf=${callbacks}"
|
||||
|
||||
for row in ${callbacks}
|
||||
@@ -227,7 +227,6 @@ build_callback() {
|
||||
vsize=$(echo "${row}" | cut -d '|' -f10)
|
||||
trace "[build_callback] vsize=${vsize}"
|
||||
is_replaceable=$(echo "${row}" | cut -d '|' -f15)
|
||||
is_replaceable=$([ "${is_replaceable}" = "t" ] && echo "true" || echo "false")
|
||||
trace "[build_callback] is_replaceable=${is_replaceable}"
|
||||
blockhash=$(echo "${row}" | cut -d '|' -f11)
|
||||
trace "[build_callback] blockhash=${blockhash}"
|
||||
|
||||
@@ -65,7 +65,7 @@ getactivewatches() {
|
||||
trace "Entering getactivewatches()..."
|
||||
|
||||
local watches
|
||||
# Let's build the string directly with sqlite instead of manipulating multiple strings afterwards, it's faster.
|
||||
# Let's build the string directly with dbms instead of manipulating multiple strings afterwards, it's faster.
|
||||
# {"id":"${id}","address":"${address}","imported":"${imported}","unconfirmedCallbackURL":"${cb0conf_url}","confirmedCallbackURL":"${cb1conf_url}","watching_since":"${timestamp}"}
|
||||
watches=$(sql "SELECT '{\"id\":' || id || ',\"address\":\"' || address || '\",\"imported\":' || imported || ',\"unconfirmedCallbackURL\":' || CASE WHEN callback0conf IS NULL THEN 'null' ELSE ('\"' || callback0conf || '\"') END || ',\"confirmedCallbackURL\":' || CASE WHEN callback1conf IS NULL THEN 'null' ELSE ('\"' || callback1conf || '\"') END || ',\"label\":\"' || COALESCE(label, '') || '\",\"watching_since\":\"' || inserted_ts || '\"}' FROM watching WHERE watching AND NOT calledback1conf ORDER BY id")
|
||||
returncode=$?
|
||||
@@ -128,7 +128,7 @@ getactivewatchesxpub() {
|
||||
trace "[getactivewatchesxpub] value=${value}"
|
||||
local watches
|
||||
|
||||
# Let's build the string directly with sqlite instead of manipulating multiple strings afterwards, it's faster.
|
||||
# Let's build the string directly with dbms instead of manipulating multiple strings afterwards, it's faster.
|
||||
# {"id":"${id}","address":"${address}","imported":"${imported}","unconfirmedCallbackURL":"${cb0conf_url}","confirmedCallbackURL":"${cb1conf_url}","watching_since":"${timestamp}","derivation_path":"${derivation_path}","pub32_index":"${pub32_index}"}
|
||||
watches=$(sql "SELECT '{\"id\":' || w.id || ',\"address\":\"' || address || '\",\"imported\":' || imported || ',\"unconfirmedCallbackURL\":' || CASE WHEN w.callback0conf IS NULL THEN 'null' ELSE ('\"' || w.callback0conf || '\"') END || ',\"confirmedCallbackURL\":' || CASE WHEN w.callback1conf IS NULL THEN 'null' ELSE ('\"' || w.callback1conf || '\"') END || ',\"watching_since\":\"' || w.inserted_ts || '\",\"derivation_path\":\"' || derivation_path || '\",\"pub32_index\":' || pub32_index || '}' FROM watching w, watching_by_pub32 w32 WHERE watching_by_pub32_id = w32.id AND w32.${where} = '${value}' AND w.watching AND NOT calledback1conf ORDER BY w.id")
|
||||
returncode=$?
|
||||
@@ -160,7 +160,7 @@ getactivexpubwatches() {
|
||||
trace "Entering getactivexpubwatches()..."
|
||||
|
||||
local watches
|
||||
# Let's build the string directly with sqlite instead of manipulating multiple strings afterwards, it's faster.
|
||||
# Let's build the string directly with dbms instead of manipulating multiple strings afterwards, it's faster.
|
||||
# {"id":"${id}","pub32":"${pub32}","label":"${label}","derivation_path":"${derivation_path}","last_imported_n":${last_imported_n},"unconfirmedCallbackURL":"${cb0conf_url}","confirmedCallbackURL":"${cb1conf_url}","watching_since":"${timestamp}"}
|
||||
watches=$(sql "SELECT '{\"id\":' || id || ',\"pub32\":\"' || pub32 || '\",\"label\":\"' || label || '\",\"derivation_path\":\"' || derivation_path || '\",\"last_imported_n\":' || last_imported_n || ',\"unconfirmedCallbackURL\":' || CASE WHEN callback0conf IS NULL THEN 'null' ELSE ('\"' || callback0conf || '\"') END || ',\"confirmedCallbackURL\":' || CASE WHEN callback1conf IS NULL THEN 'null' ELSE ('\"' || callback1conf || '\"') END || ',\"watching_since\":\"' || inserted_ts || '\"}' FROM watching_by_pub32 WHERE watching ORDER BY id")
|
||||
returncode=$?
|
||||
|
||||
@@ -39,7 +39,7 @@ serve_ots_stamp() {
|
||||
id_inserted=$(echo "${row}" | cut -d '|' -f1)
|
||||
trace "[serve_ots_stamp] id_inserted=${id_inserted}"
|
||||
|
||||
if [ "${requested}" -eq "1" ]; then
|
||||
if [ "${requested}" = "t" ]; then
|
||||
# Stamp already requested
|
||||
trace "[serve_ots_stamp] Stamp already requested"
|
||||
errorstring="Duplicate stamping request, hash already exists in DB and been OTS requested"
|
||||
@@ -176,12 +176,12 @@ serve_ots_backoffice() {
|
||||
id=$(echo "${row}" | cut -d '|' -f5)
|
||||
trace "[serve_ots_backoffice] id=${id}"
|
||||
|
||||
if [ "${requested}" -ne "1" ]; then
|
||||
if [ "${requested}" != "t" ]; then
|
||||
# Re-request the unrequested calls to ots_stamp
|
||||
request_ots_stamp "${hash}" ${id}
|
||||
returncode=$?
|
||||
else
|
||||
if [ "${upgraded}" -ne "1" ]; then
|
||||
if [ "${upgraded}" != "t" ]; then
|
||||
# Upgrade requested calls to ots_stamp that have not been called back yet
|
||||
trace "[serve_ots_backoffice] curl -s ${OTSCLIENT_CONTAINER}/upgrade/${hash}"
|
||||
result=$(curl -s ${OTSCLIENT_CONTAINER}/upgrade/${hash})
|
||||
@@ -196,18 +196,18 @@ serve_ots_backoffice() {
|
||||
# Error tag not null, so there's an error
|
||||
trace "[serve_ots_backoffice] not upgraded!"
|
||||
|
||||
upgraded=0
|
||||
upgraded="f"
|
||||
else
|
||||
# No failure, upgraded
|
||||
trace "[serve_ots_backoffice] just upgraded!"
|
||||
sql "UPDATE stamp SET upgraded=true WHERE id=${id}"
|
||||
trace_rc $?
|
||||
|
||||
upgraded=1
|
||||
upgraded="t"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ "${upgraded}" -eq "1" ]; then
|
||||
if [ "${upgraded}" = "t" ]; then
|
||||
trace "[serve_ots_backoffice] upgraded! Let's call the callback..."
|
||||
url=$(echo "${row}" | cut -d '|' -f2)
|
||||
trace "[serve_ots_backoffice] url=${url}"
|
||||
|
||||
@@ -454,7 +454,6 @@ extend_watchers() {
|
||||
|
||||
local last_imported_n
|
||||
local row
|
||||
# row=$(sql "SELECT COALESCE('\"'||pub32||'\"', 'null'), COALESCE('\"'||label||'\"', 'null'), COALESCE('\"'||derivation_path||'\"', 'null'), COALESCE('\"'||callback0conf||'\"', 'null'), COALESCE('\"'||callback1conf||'\"', 'null'), last_imported_n FROM watching_by_pub32 WHERE id=${watching_by_pub32_id} AND watching")
|
||||
row=$(sql "SELECT pub32, label, derivation_path, callback0conf, callback1conf, last_imported_n FROM watching_by_pub32 WHERE id=${watching_by_pub32_id} AND watching")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
|
||||
Reference in New Issue
Block a user