mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-08 23:46:00 +01:00
Event published on spend
This commit is contained in:
@@ -257,7 +257,7 @@ main() {
|
||||
;;
|
||||
spend)
|
||||
# POST http://192.168.111.152:8080/spend
|
||||
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233}
|
||||
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233,"eventMessage":"eyJib3VuY2VfYWRkcmVzcyI6InRiMXE2czBwcHdrMm1zZGV3YWwzbXU5MGFoZmhweWVwYXdudzZ3ZGs4dCIsIm5iX2NvbmYiOjZ9Cg=="}
|
||||
|
||||
response=$(spend "${line}")
|
||||
response_to_client "${response}" ${?}
|
||||
|
||||
@@ -43,6 +43,24 @@ spend() {
|
||||
# it to a temp file for it to be read by sqlite3 and then delete the file
|
||||
echo "${tx_raw_details}" > rawtx-${txid}.blob
|
||||
|
||||
########################################################################################################
|
||||
# Let's publish the event if needed
|
||||
local event_message
|
||||
event_message=$(echo "${request}" | jq -er ".eventMessage")
|
||||
if [ "$?" -ne "0" ]; then
|
||||
# event_message tag null, so there's no event_message
|
||||
trace "[spend] event_message="
|
||||
event_message=
|
||||
else
|
||||
# There's an event message, let's publish it!
|
||||
|
||||
trace "[spend] mosquitto_pub -h broker -t spend -m \"{\"txid\":\"${txid}\",\"address\":\"${address}\",\"amount\":${tx_amount},\"event_message\":\"${event_message}\"}\""
|
||||
response=$(mosquitto_pub -h broker -t spend -m "{\"txid\":\"${txid}\",\"address\":\"${address}\",\"amount\":${tx_amount},\"event_message\":\"${event_message}\"}")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
fi
|
||||
########################################################################################################
|
||||
|
||||
# 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('rawtx-${txid}.blob'))"
|
||||
trace_rc $?
|
||||
|
||||
Reference in New Issue
Block a user