mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-31 10:14:35 +01:00
Added info on watchtxid webhook and improved stuff
This commit is contained in:
@@ -83,25 +83,53 @@ build_callback_txid() {
|
||||
|
||||
if [ "${returncode}" -eq "0" ]; then
|
||||
confirmations=$(echo "${tx_raw_details}" | jq '.result.confirmations')
|
||||
if [ "${confirmations}" == "null" ]; then
|
||||
confirmations=0
|
||||
fi
|
||||
trace "[build_callback_txid] confirmations=${confirmations}"
|
||||
|
||||
if [ "${confirmations}" -ge "${nbxconf}" ]; then
|
||||
trace "[build_callback_txid] Number of confirmations for tx is at least what we're looking for, callback time!"
|
||||
|
||||
# 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
|
||||
|
||||
# Number of confirmations for transaction is at least what we want
|
||||
# Let's prepare the callback!
|
||||
|
||||
# blockhash=$(echo "${tx_raw_details}" | jq '.result.blockhash')
|
||||
# trace "[build_callback_txid] blockhash=${blockhash}"
|
||||
# blockheight=$(get_block_info $(echo "${blockhash}" | tr -d '"') | jq '.result.height')
|
||||
# trace "[build_callback_txid] blockheight=${blockheight}"
|
||||
local tx_hash=$(echo "${tx_raw_details}" | jq '.result.hash')
|
||||
trace "[build_callback_txid] tx_hash=${tx_hash}"
|
||||
local tx_size=$(echo "${tx_raw_details}" | jq '.result.size')
|
||||
trace "[build_callback_txid] tx_size=${tx_size}"
|
||||
local tx_vsize=$(echo "${tx_raw_details}" | jq '.result.vsize')
|
||||
trace "[build_callback_txid] tx_vsize=${tx_vsize}"
|
||||
local fees=$(compute_fees "${txid}")
|
||||
trace "[build_callback_txid] fees=${fees}"
|
||||
local tx_blockhash=$(echo "${tx_raw_details}" | jq '.result.blockhash')
|
||||
trace "[build_callback_txid] tx_blockhash=${tx_blockhash}"
|
||||
local tx_blockheight=$(get_block_info $(echo ${tx_blockhash} | tr -d '"') | jq '.result.height')
|
||||
trace "[build_callback_txid] tx_blockheight=${tx_blockheight}"
|
||||
local tx_blocktime=$(echo "${tx_raw_details}" | jq '.result.blocktime')
|
||||
trace "[build_callback_txid] tx_blocktime=${tx_blocktime}"
|
||||
|
||||
data="{\"id\":\"${id}\","
|
||||
data="${data}\"txid\":\"${txid}\","
|
||||
data="${data}\"confirmations\":${confirmations}"
|
||||
data="${data}}"
|
||||
data="${data}\"hash\":${tx_hash},"
|
||||
data="${data}\"confirmations\":${confirmations},"
|
||||
data="${data}\"size\":${tx_size},"
|
||||
data="${data}\"vsize\":${tx_vsize},"
|
||||
data="${data}\"fees\":${fees},"
|
||||
data="${data}\"blockhash\":${tx_blockhash},"
|
||||
data="${data}\"blocktime\":\"$(date -Is -d @${tx_blocktime})\","
|
||||
data="${data}\"blockheight\":${tx_blockheight}}"
|
||||
trace "[build_callback_txid] data=${data}"
|
||||
|
||||
curl_callback_txid "${url}" "${data}"
|
||||
|
||||
# Delete the temp file containing the raw tx (see above)
|
||||
rm rawtx-${txid}-$$.blob
|
||||
|
||||
return $?
|
||||
else
|
||||
trace "[build_callback_txid] Number of confirmations for tx is not enough to call back."
|
||||
|
||||
@@ -17,7 +17,7 @@ compute_fees() {
|
||||
local txid=${1}
|
||||
|
||||
# Let's reuse the file created in confirmation...
|
||||
local tx_raw_details=$(cat conf-rawtx-${txid}.blob)
|
||||
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}")
|
||||
|
||||
@@ -93,10 +93,10 @@ compute_vin_total_amount()
|
||||
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'))"
|
||||
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
|
||||
rm vin-rawtx-${vin_txid}-$$.blob
|
||||
txid_already_inserted=true
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -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}" > conf-rawtx-${txid}.blob
|
||||
echo "${tx_raw_details}" > rawtx-${txid}-$$.blob
|
||||
|
||||
if [ -z ${tx} ]; then
|
||||
# TX not found in our DB.
|
||||
@@ -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('conf-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('rawtx-${txid}-$$.blob'))"
|
||||
trace_rc $?
|
||||
|
||||
id_inserted=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"")
|
||||
@@ -126,14 +126,14 @@ confirmation() {
|
||||
blockhash=${tx_blockhash},
|
||||
blockheight=${tx_blockheight},
|
||||
blocktime=${tx_blocktime},
|
||||
raw_tx=readfile('conf-rawtx-${txid}.blob')
|
||||
raw_tx=readfile('rawtx-${txid}-$$.blob')
|
||||
WHERE txid=\"${txid}\""
|
||||
trace_rc $?
|
||||
fi
|
||||
id_inserted=${tx}
|
||||
fi
|
||||
# Delete the temp file containing the raw tx (see above)
|
||||
rm conf-rawtx-${txid}.blob
|
||||
rm rawtx-${txid}-$$.blob
|
||||
|
||||
########################################################################################################
|
||||
|
||||
|
||||
@@ -48,7 +48,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}" > spend-rawtx-${txid}.blob
|
||||
echo "${tx_raw_details}" > spend-rawtx-${txid}-$$.blob
|
||||
|
||||
########################################################################################################
|
||||
# Let's publish the event if needed
|
||||
@@ -69,7 +69,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('spend-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 $?
|
||||
@@ -80,7 +80,7 @@ spend() {
|
||||
data="${data},\"hash\":\"${txid}\",\"details\":{\"address\":\"${address}\",\"amount\":${amount},\"firstseen\":${tx_ts_firstseen},\"size\":${tx_size},\"vsize\":${tx_vsize},\"replaceable\":${replaceable},\"fee\":${fees},\"subtractfeefromamount\":${subtractfeefromamount}}}"
|
||||
|
||||
# Delete the temp file containing the raw tx (see above)
|
||||
rm spend-rawtx-${txid}.blob
|
||||
rm spend-rawtx-${txid}-$$.blob
|
||||
else
|
||||
local message=$(echo "${response}" | jq -e ".error.message")
|
||||
data="{\"message\":${message}}"
|
||||
@@ -371,10 +371,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}" > batchspend-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('batchspend-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
|
||||
@@ -388,7 +388,7 @@ batchspend() {
|
||||
data="${data},\"hash\":\"${txid}\"}"
|
||||
|
||||
# Delete the temp file containing the raw tx (see above)
|
||||
rm batchspend-rawtx-${txid}.blob
|
||||
rm batchspend-rawtx-${txid}-$$.blob
|
||||
else
|
||||
local message=$(echo "${response}" | jq -e ".error.message")
|
||||
data="{\"message\":${message}}"
|
||||
|
||||
Reference in New Issue
Block a user