Event published on spend

This commit is contained in:
kexkey
2019-12-02 13:19:41 -05:00
committed by kexkey
parent 08d221274b
commit 8021864f93
2 changed files with 19 additions and 1 deletions

View File

@@ -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}" ${?}

View File

@@ -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 $?