mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-31 10:14:35 +01:00
Fixed replaceable json, batching tests and several small glitches
This commit is contained in:
@@ -554,6 +554,7 @@ 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}"
|
||||
@@ -812,7 +813,7 @@ getbatchdetails() {
|
||||
fi
|
||||
|
||||
# First get the batch summary
|
||||
batch=$(sql "SELECT b.id, COALESCE(t.id, NULL), '{\"batcherId\":' || b.id || ',\"batcherLabel\":\"' || b.label || '\",\"confTarget\":' || conf_target || ',\"nbOutputs\":' || COUNT(r.id) || ',\"oldest\":\"' ||COALESCE(MIN(r.inserted_ts), 0) || '\",\"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")
|
||||
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), 0) || '\",\"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")
|
||||
trace "[getbatchdetails] batch=${batch}"
|
||||
|
||||
if [ -n "${batch}" ]; then
|
||||
@@ -825,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\":' || is_replaceable || ',\"fee\":' || fee || '}' FROM tx WHERE 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}")
|
||||
else
|
||||
# null txid
|
||||
outerclause="AND r.tx_id IS NULL"
|
||||
|
||||
@@ -11,7 +11,7 @@ do_callbacks() {
|
||||
trace "Entering do_callbacks()..."
|
||||
|
||||
# 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, label, derivation_path, event_message 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 watching_by_pub32_id = w32.id WHERE NOT calledback0conf AND watching_id NOT NULL AND w.callback0conf NOT NULL AND w.watching')
|
||||
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, 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 watching_by_pub32_id = w32.id WHERE NOT calledback0conf AND watching_id NOT NULL AND w.callback0conf NOT NULL AND w.watching')
|
||||
trace "[do_callbacks] callbacks0conf=${callbacks}"
|
||||
|
||||
local returncode
|
||||
@@ -30,7 +30,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, label, derivation_path, event_message FROM watching w, watching_tx wt, tx t LEFT JOIN watching_by_pub32 w32 ON watching_by_pub32_id = w32.id WHERE w.id = watching_id AND tx_id = t.id AND NOT calledback1conf AND confirmations>0 AND w.callback1conf NOT NULL AND w.watching')
|
||||
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, label, derivation_path, event_message, hash FROM watching w, watching_tx wt, tx t LEFT JOIN watching_by_pub32 w32 ON watching_by_pub32_id = w32.id WHERE w.id = watching_id AND tx_id = t.id AND NOT calledback1conf AND confirmations>0 AND w.callback1conf NOT NULL AND w.watching')
|
||||
trace "[do_callbacks] callbacks1conf=${callbacks}"
|
||||
|
||||
for row in ${callbacks}
|
||||
@@ -152,6 +152,7 @@ build_callback() {
|
||||
local derivation_path
|
||||
|
||||
local event_message
|
||||
local hash
|
||||
|
||||
# w.callback0conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime,
|
||||
# w.id, is_replaceable, pub32_index, pub32, label, derivation_path, event_message
|
||||
@@ -171,6 +172,8 @@ build_callback() {
|
||||
trace "[build_callback] address=${address}"
|
||||
txid=$(echo "${row}" | cut -d '|' -f3)
|
||||
trace "[build_callback] txid=${txid}"
|
||||
hash=$(echo "${row}" | cut -d '|' -f21)
|
||||
trace "[build_callback] hash=${hash}"
|
||||
vout_n=$(echo "${row}" | cut -d '|' -f4)
|
||||
trace "[build_callback] vout_n=${vout_n}"
|
||||
sent_amount=$(echo "${row}" | cut -d '|' -f5 | awk '{ printf "%.8f", $0 }')
|
||||
@@ -192,6 +195,7 @@ build_callback() {
|
||||
vsize=$(echo "${row}" | cut -d '|' -f10)
|
||||
trace "[build_callback] vsize=${vsize}"
|
||||
is_replaceable=$(echo "${row}" | cut -d '|' -f15)
|
||||
is_replaceable=$([ "${is_replaceable}" -eq "1" ] && echo "true" || echo "false")
|
||||
trace "[build_callback] is_replaceable=${is_replaceable}"
|
||||
blockhash=$(echo "${row}" | cut -d '|' -f11)
|
||||
trace "[build_callback] blockhash=${blockhash}"
|
||||
@@ -215,7 +219,8 @@ build_callback() {
|
||||
|
||||
data="{\"id\":\"${id}\","
|
||||
data="${data}\"address\":\"${address}\","
|
||||
data="${data}\"hash\":\"${txid}\","
|
||||
data="${data}\"txid\":\"${txid}\","
|
||||
data="${data}\"hash\":\"${hash}\","
|
||||
data="${data}\"vout_n\":${vout_n},"
|
||||
data="${data}\"sent_amount\":${sent_amount},"
|
||||
data="${data}\"confirmations\":${confirmations},"
|
||||
|
||||
@@ -86,8 +86,8 @@ confirmation() {
|
||||
|
||||
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"')
|
||||
tx_replaceable=$([ ${tx_replaceable} = "yes" ] && echo 1 || echo 0)
|
||||
local tx_replaceable=$(echo "${tx_details}" | jq -r '.result."bip125-replaceable"')
|
||||
tx_replaceable=$([ ${tx_replaceable} = "yes" ] && echo "true" || echo "false")
|
||||
|
||||
local fees=$(compute_fees "${txid}")
|
||||
trace "[confirmation] fees=${fees}"
|
||||
@@ -184,8 +184,8 @@ confirmation() {
|
||||
if [ -n "${event_message}" ]; then
|
||||
# There's an event message, let's publish it!
|
||||
|
||||
trace "[confirmation] mosquitto_pub -h broker -t tx_confirmation -m \"{\"txid\":\"${txid}\",\"address\":\"${address}\",\"vout_n\":${tx_vout_n},\"amount\":${tx_vout_amount},\"confirmations\":${tx_nb_conf},\"eventMessage\":\"${event_message}\"}\""
|
||||
response=$(mosquitto_pub -h broker -t tx_confirmation -m "{\"txid\":\"${txid}\",\"address\":\"${address}\",\"vout_n\":${tx_vout_n},\"amount\":${tx_vout_amount},\"confirmations\":${tx_nb_conf},\"eventMessage\":\"${event_message}\"}")
|
||||
trace "[confirmation] mosquitto_pub -h broker -t tx_confirmation -m \"{\"txid\":\"${txid}\",\"hash\":\"${tx_hash}\",\"address\":\"${address}\",\"vout_n\":${tx_vout_n},\"amount\":${tx_vout_amount},\"confirmations\":${tx_nb_conf},\"eventMessage\":\"${event_message}\"}\""
|
||||
response=$(mosquitto_pub -h broker -t tx_confirmation -m "{\"txid\":\"${txid}\",\"hash\":\"${tx_hash}\",\"address\":\"${address}\",\"vout_n\":${tx_vout_n},\"amount\":${tx_vout_amount},\"confirmations\":${tx_nb_conf},\"eventMessage\":\"${event_message}\"}")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
fi
|
||||
|
||||
@@ -91,7 +91,9 @@ testbatching() {
|
||||
|
||||
# addtobatch to default batcher
|
||||
echo "Testing addtobatch..."
|
||||
response=$(curl -sd '{"outputLabel":"test001","address":"test001","amount":0.001}' localhost:8888/addtobatch)
|
||||
address1=$(curl -s localhost:8888/getnewaddress | jq -r ".address")
|
||||
echo "address1=${address1}"
|
||||
response=$(curl -sd '{"outputLabel":"test001","address":"'${address1}'","amount":0.001}' localhost:8888/addtobatch)
|
||||
echo "response=${response}"
|
||||
id=$(echo "${response}" | jq ".result.batcherId")
|
||||
echo "batcherId=${id}"
|
||||
@@ -104,7 +106,9 @@ testbatching() {
|
||||
fi
|
||||
echo "outputId=${id}"
|
||||
|
||||
response=$(curl -sd '{"batcherId":1,"outputLabel":"test002","address":"test002","amount":0.002}' localhost:8888/addtobatch)
|
||||
address2=$(curl -s localhost:8888/getnewaddress | jq -r ".address")
|
||||
echo "address2=${address2}"
|
||||
response=$(curl -sd '{"batcherId":1,"outputLabel":"test002","address":"'${address2}'","amount":22000000}' localhost:8888/addtobatch)
|
||||
echo "response=${response}"
|
||||
id2=$(echo "${response}" | jq ".result.batcherId")
|
||||
echo "batcherId=${id2}"
|
||||
|
||||
Reference in New Issue
Block a user