mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-04 21:45:33 +01:00
More comments, cleaned code
This commit is contained in:
@@ -150,6 +150,8 @@ confirmation() {
|
||||
do
|
||||
watching_id=$(echo "${row}" | cut -d '|' -f1)
|
||||
address=$(echo "${row}" | cut -d '|' -f2)
|
||||
# In the case of us spending to a watched address, the address appears twice in the details,
|
||||
# once on the spend side (negative amount) and once on the receiving side (positive amount)
|
||||
tx_vout_n=$(echo "${tx_details}" | jq ".result.details | map(select(.address==\"${address}\"))[0] | .vout")
|
||||
tx_vout_amount=$(echo "${tx_details}" | jq ".result.details | map(select(.address==\"${address}\"))[0] | .amount | fabs" | awk '{ printf "%.8f", $0 }')
|
||||
sql "INSERT OR IGNORE INTO watching_tx (watching_id, tx_id, vout, amount) VALUES (${watching_id}, ${id_inserted}, ${tx_vout_n}, ${tx_vout_amount})"
|
||||
@@ -177,6 +179,7 @@ confirmation() {
|
||||
|
||||
) 201>./.confirmation.lock
|
||||
|
||||
# There's a lock in callbacks, let's get out of the confirmation lock before entering another one
|
||||
do_callbacks
|
||||
echo '{"result":"confirmed"}'
|
||||
|
||||
|
||||
@@ -14,11 +14,14 @@ notify_web() {
|
||||
local response
|
||||
local http_code
|
||||
|
||||
# We use the pid as the response-topic, so there's no conflict in responses.
|
||||
trace "[notify_web] mosquitto_rr -h broker -W 5 -t notifier -e \"response/$$\" -m \"{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"${url}\",\"body\":\"${body}\"}\""
|
||||
response=$(mosquitto_rr -h broker -W 5 -t notifier -e "response/$$" -m "{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"${url}\",\"body\":\"${body}\"}")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
|
||||
# The response looks like this: {"curl_code":0,"http_code":200,"body":"..."} where the body
|
||||
# is the base64(response body) but we don't need the response content here.
|
||||
trace "[notify_web] response=${response}"
|
||||
http_code=$(echo "${response}" | jq ".http_code" | tr -d '"')
|
||||
trace "[notify_web] http_code=${http_code}"
|
||||
|
||||
@@ -26,13 +26,14 @@ spend() {
|
||||
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
|
||||
trace "[spend] txid=${txid}"
|
||||
|
||||
# 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})
|
||||
|
||||
# Amounts and fees are negative when spending so we absolute those fields
|
||||
local tx_hash=$(echo "${tx_raw_details}" | jq '.result.hash')
|
||||
local tx_ts_firstseen=$(echo "${tx_details}" | jq '.result.timereceived')
|
||||
local tx_amount=$(echo "${tx_details}" | jq '.result.amount | fabs' | awk '{ printf "%.8f", $0 }')
|
||||
|
||||
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"')
|
||||
@@ -40,8 +41,7 @@ spend() {
|
||||
local fees=$(echo "${tx_details}" | jq '.result.fee | fabs' | awk '{ printf "%.8f", $0 }')
|
||||
local rawtx=$(echo "${tx_details}" | jq '.result.hex')
|
||||
|
||||
# Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address
|
||||
#sql "INSERT OR IGNORE INTO tx (txid) VALUES (\"${txid}\")"
|
||||
# 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}, ${rawtx})"
|
||||
trace_rc $?
|
||||
id_inserted=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"")
|
||||
@@ -230,13 +230,14 @@ batchspend() {
|
||||
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
|
||||
trace "[batchspend] txid=${txid}"
|
||||
|
||||
# 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})
|
||||
|
||||
# Amounts and fees are negative when spending so we absolute those fields
|
||||
local tx_hash=$(echo "${tx_raw_details}" | jq '.result.hash')
|
||||
local tx_ts_firstseen=$(echo "${tx_details}" | jq '.result.timereceived')
|
||||
local tx_amount=$(echo "${tx_details}" | jq '.result.amount | fabs' | awk '{ printf "%.8f", $0 }')
|
||||
|
||||
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"')
|
||||
@@ -244,8 +245,7 @@ batchspend() {
|
||||
local fees=$(echo "${tx_details}" | jq '.result.fee | fabs' | awk '{ printf "%.8f", $0 }')
|
||||
local rawtx=$(echo "${tx_details}" | jq '.result.hex')
|
||||
|
||||
# Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address
|
||||
#sql "INSERT OR IGNORE INTO tx (txid) VALUES (\"${txid}\")"
|
||||
# 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}, ${rawtx})"
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
|
||||
Reference in New Issue
Block a user