mirror of
https://github.com/aljazceru/cyphernode.git
synced 2025-12-18 21:25:06 +01:00
Added -r to jq when tr -d double-quotes
This commit is contained in:
@@ -16,8 +16,7 @@
|
||||
|
||||
. ./trace.sh
|
||||
|
||||
verify_sign()
|
||||
{
|
||||
verify_sign() {
|
||||
local returncode
|
||||
|
||||
local header64=$(echo "${1}" | cut -sd '.' -f1)
|
||||
@@ -38,7 +37,7 @@ verify_sign()
|
||||
|
||||
if [ ${exp} -gt ${current} ]; then
|
||||
trace "[verify_sign] Not expired, let's validate signature"
|
||||
local id=$(echo "${payload}" | jq ".id" | tr -d '"')
|
||||
local id=$(echo "${payload}" | jq -r ".id")
|
||||
trace "[verify_sign] id=${id}"
|
||||
|
||||
# Check for code injection
|
||||
@@ -82,8 +81,7 @@ verify_sign()
|
||||
return 1
|
||||
}
|
||||
|
||||
verify_group()
|
||||
{
|
||||
verify_group() {
|
||||
trace "[verify_group] Verifying group..."
|
||||
|
||||
local id=${1}
|
||||
|
||||
@@ -103,7 +103,7 @@ checknotifier() {
|
||||
response=$(mosquitto_rr -h broker -W 15 -t notifier -e "response/$$" -m "{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"http://proxy:8888/helloworld\"}")
|
||||
returncode=$?
|
||||
[ "${returncode}" -ne "0" ] && return 115
|
||||
http_code=$(echo "${response}" | jq ".http_code" | tr -d '"')
|
||||
http_code=$(echo "${response}" | jq -r ".http_code")
|
||||
[ "${http_code}" -ge "400" ] && return 118
|
||||
|
||||
echo -e "\e[1;36mNotifier rocks!" > /dev/console
|
||||
|
||||
@@ -18,10 +18,10 @@ main() {
|
||||
trace "[main] New msg just arrived!"
|
||||
trace "[main] msg=${msg}"
|
||||
|
||||
cmd=$(echo ${msg} | jq ".cmd" | tr -d '"')
|
||||
cmd=$(echo ${msg} | jq -r ".cmd")
|
||||
trace "[main] cmd=${cmd}"
|
||||
|
||||
response_topic=$(echo ${msg} | jq '."response-topic"' | tr -d '"')
|
||||
response_topic=$(echo ${msg} | jq -r '."response-topic"')
|
||||
trace "[main] response_topic=${response_topic}"
|
||||
|
||||
case "${cmd}" in
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
. ./trace.sh
|
||||
. ./sendtobitcoinnode.sh
|
||||
|
||||
get_best_block_hash()
|
||||
{
|
||||
get_best_block_hash() {
|
||||
trace "Entering get_best_block_hash()..."
|
||||
|
||||
local data='{"method":"getbestblockhash"}'
|
||||
@@ -12,8 +11,7 @@ get_best_block_hash()
|
||||
return $?
|
||||
}
|
||||
|
||||
getestimatesmartfee()
|
||||
{
|
||||
getestimatesmartfee() {
|
||||
trace "Entering getestimatesmartfee()..."
|
||||
|
||||
local nb_blocks=${1}
|
||||
@@ -22,8 +20,7 @@ getestimatesmartfee()
|
||||
return $?
|
||||
}
|
||||
|
||||
get_block_info()
|
||||
{
|
||||
get_block_info() {
|
||||
trace "Entering get_block_info()..."
|
||||
|
||||
local block_hash=${1}
|
||||
@@ -34,18 +31,16 @@ get_block_info()
|
||||
return $?
|
||||
}
|
||||
|
||||
get_best_block_info()
|
||||
{
|
||||
get_best_block_info() {
|
||||
trace "Entering get_best_block_info()..."
|
||||
|
||||
local block_hash=$(echo "$(get_best_block_hash)" | jq ".result" | tr -d '"')
|
||||
local block_hash=$(echo "$(get_best_block_hash)" | jq -r ".result")
|
||||
trace "[get_best_block_info] block_hash=${block_hash}"
|
||||
get_block_info ${block_hash}
|
||||
return $?
|
||||
}
|
||||
|
||||
get_rawtransaction()
|
||||
{
|
||||
get_rawtransaction() {
|
||||
trace "Entering get_rawtransaction()..."
|
||||
|
||||
local txid=${1}
|
||||
@@ -74,8 +69,7 @@ get_transaction() {
|
||||
return $?
|
||||
}
|
||||
|
||||
get_blockchain_info()
|
||||
{
|
||||
get_blockchain_info() {
|
||||
trace "Entering get_blockchain_info()..."
|
||||
|
||||
local data='{"method":"getblockchaininfo"}'
|
||||
@@ -83,8 +77,7 @@ get_blockchain_info()
|
||||
return $?
|
||||
}
|
||||
|
||||
get_mempool_info()
|
||||
{
|
||||
get_mempool_info() {
|
||||
trace "Entering get_mempool_info()..."
|
||||
|
||||
local data='{"method":"getmempoolinfo"}'
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
. ./trace.sh
|
||||
|
||||
ln_create_invoice()
|
||||
{
|
||||
ln_create_invoice() {
|
||||
trace "Entering ln_create_invoice()..."
|
||||
|
||||
local result
|
||||
@@ -11,15 +10,15 @@ ln_create_invoice()
|
||||
local id
|
||||
|
||||
local request=${1}
|
||||
local msatoshi=$(echo "${request}" | jq ".msatoshi" | tr -d '"')
|
||||
local msatoshi=$(echo "${request}" | jq -r ".msatoshi")
|
||||
trace "[ln_create_invoice] msatoshi=${msatoshi}"
|
||||
local label=$(echo "${request}" | jq ".label" | tr -d '"')
|
||||
local label=$(echo "${request}" | jq -r ".label")
|
||||
trace "[ln_create_invoice] label=${label}"
|
||||
local description=$(echo "${request}" | jq ".description" | tr -d '"')
|
||||
local description=$(echo "${request}" | jq -r ".description")
|
||||
trace "[ln_create_invoice] description=${description}"
|
||||
local expiry=$(echo "${request}" | jq ".expiry" | tr -d '"')
|
||||
local expiry=$(echo "${request}" | jq -r ".expiry")
|
||||
trace "[ln_create_invoice] expiry=${expiry}"
|
||||
local callback_url=$(echo "${request}" | jq ".callbackUrl" | tr -d '"')
|
||||
local callback_url=$(echo "${request}" | jq -r ".callbackUrl")
|
||||
trace "[ln_create_invoice] callback_url=${callback_url}"
|
||||
|
||||
#/proxy $ ./lightning-cli invoice 10000 "t1" "t1d" 60
|
||||
@@ -38,11 +37,11 @@ ln_create_invoice()
|
||||
if [ "${returncode}" -ne "0" ]; then
|
||||
data=${result}
|
||||
else
|
||||
local bolt11=$(echo "${result}" | jq ".bolt11" | tr -d '"')
|
||||
local bolt11=$(echo "${result}" | jq -r ".bolt11")
|
||||
trace "[ln_create_invoice] bolt11=${bolt11}"
|
||||
local payment_hash=$(echo "${result}" | jq ".payment_hash" | tr -d '"')
|
||||
local payment_hash=$(echo "${result}" | jq -r ".payment_hash")
|
||||
trace "[ln_create_invoice] payment_hash=${payment_hash}"
|
||||
local expires_at=$(echo "${result}" | jq ".expires_at" | tr -d '"')
|
||||
local expires_at=$(echo "${result}" | jq -r ".expires_at")
|
||||
trace "[ln_create_invoice] expires_at=${expires_at}"
|
||||
|
||||
# Let's get the connect string if provided in configuration
|
||||
@@ -88,15 +87,14 @@ get_connection_string() {
|
||||
echo ${getinfo} | jq -e '.address[0]' > /dev/null
|
||||
if [ "$?" -eq 0 ]; then
|
||||
# If there's an address
|
||||
connectstring="$(echo ${getinfo} | jq '((.id + "@") + (.address[0] | ((.address + ":") + (.port | tostring))))' | tr -d '"')"
|
||||
connectstring="$(echo ${getinfo} | jq -r '((.id + "@") + (.address[0] | ((.address + ":") + (.port | tostring))))')"
|
||||
trace "[get_connection_string] connectstring=${connectstring}"
|
||||
fi
|
||||
|
||||
echo "${connectstring}"
|
||||
}
|
||||
|
||||
ln_getinfo()
|
||||
{
|
||||
ln_getinfo() {
|
||||
trace "Entering ln_get_info()..."
|
||||
|
||||
local result
|
||||
@@ -190,11 +188,11 @@ ln_connectfund() {
|
||||
local msg
|
||||
|
||||
local request=${1}
|
||||
local peer=$(echo "${request}" | jq ".peer" | tr -d '"')
|
||||
local peer=$(echo "${request}" | jq -r ".peer")
|
||||
trace "[ln_connectfund] peer=${peer}"
|
||||
local msatoshi=$(echo "${request}" | jq ".msatoshi")
|
||||
trace "[ln_connectfund] msatoshi=${msatoshi}"
|
||||
local callback_url=$(echo "${request}" | jq ".callbackUrl" | tr -d '"')
|
||||
local callback_url=$(echo "${request}" | jq -r ".callbackUrl")
|
||||
trace "[ln_connectfund] callback_url=${callback_url}"
|
||||
|
||||
# Let's first try to connect to peer
|
||||
@@ -215,7 +213,7 @@ ln_connectfund() {
|
||||
# ./lightning-cli connect 021a1b197aa79242532b23cb9a8d9cb78631f95f811457675fa1b362fe6d1c24b8@172.81.180.244:9735
|
||||
# { "code" : -1, "message" : "172.1.180.244:9735: Connection establishment: Operation timed out. " }
|
||||
|
||||
nodeId=$(echo "${result}" | jq ".id" | tr -d '"')
|
||||
nodeId=$(echo "${result}" | jq -r ".id")
|
||||
trace "[ln_connectfund] nodeId=${nodeId}"
|
||||
|
||||
# Now let's fund a channel with peer
|
||||
@@ -288,7 +286,7 @@ ln_pay() {
|
||||
local payment_hash
|
||||
|
||||
local request=${1}
|
||||
local bolt11=$(echo "${request}" | jq ".bolt11" | tr -d '"')
|
||||
local bolt11=$(echo "${request}" | jq -r ".bolt11")
|
||||
trace "[ln_pay] bolt11=${bolt11}"
|
||||
local expected_msatoshi=$(echo "${request}" | jq ".expected_msatoshi")
|
||||
trace "[ln_pay] expected_msatoshi=${expected_msatoshi}"
|
||||
@@ -344,7 +342,7 @@ ln_pay() {
|
||||
|
||||
if [ "${code}" -eq "200" ]; then
|
||||
trace "[ln_pay] Code 200, let's fetch status in data, should be pending..."
|
||||
status=$(echo "${result}" | jq ".data.status" | tr -d '"')
|
||||
status=$(echo "${result}" | jq -r ".data.status")
|
||||
trace "[ln_pay] status=${status}"
|
||||
else
|
||||
trace "[ln_pay] Failure code, response will be the cli result."
|
||||
@@ -352,14 +350,14 @@ ln_pay() {
|
||||
else
|
||||
# code tag not found
|
||||
trace "[ln_pay] No error code, getting the status..."
|
||||
status=$(echo "${result}" | jq ".status" | tr -d '"')
|
||||
status=$(echo "${result}" | jq -r ".status")
|
||||
trace "[ln_pay] status=${status}"
|
||||
fi
|
||||
|
||||
if [ "${status}" = "pending" ]; then
|
||||
trace "[ln_pay] Ok let's deal with pending status with waitsendpay."
|
||||
|
||||
payment_hash=$(echo "${result}" | jq ".data.payment_hash" | tr -d '"')
|
||||
payment_hash=$(echo "${result}" | jq -r ".data.payment_hash")
|
||||
trace "[ln_pay] ./lightning-cli waitsendpay ${payment_hash} 15"
|
||||
result=$(./lightning-cli waitsendpay ${payment_hash} 15)
|
||||
returncode=$?
|
||||
@@ -420,8 +418,7 @@ ln_pay() {
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
ln_newaddr()
|
||||
{
|
||||
ln_newaddr() {
|
||||
trace "Entering ln_newaddr()..."
|
||||
|
||||
local result
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
. ./importaddress.sh
|
||||
. ./confirmation.sh
|
||||
|
||||
manage_not_imported()
|
||||
{
|
||||
manage_not_imported() {
|
||||
# When we tried to import watched addresses in the watching node,
|
||||
# if it didn't succeed, we try again here.
|
||||
|
||||
@@ -31,15 +30,12 @@ manage_not_imported()
|
||||
return 0
|
||||
}
|
||||
|
||||
manage_missed_conf()
|
||||
{
|
||||
manage_missed_conf() {
|
||||
# Maybe we missed confirmations, because we were down or no network or
|
||||
# whatever, so we look at what might be missed and do confirmations.
|
||||
|
||||
trace "[Entering manage_missed_conf()]"
|
||||
|
||||
# local watches=$(sql 'SELECT address FROM watching WHERE txid IS NULL AND watching AND imported')
|
||||
#local watches=$(sql 'SELECT address FROM watching LEFT JOIN watching_tx ON id = watching_id WHERE watching AND imported AND tx_id IS NULL')
|
||||
local watches=$(sql 'SELECT address FROM watching w LEFT JOIN watching_tx ON w.id = watching_id LEFT JOIN tx t ON t.id = tx_id WHERE watching AND imported AND (tx_id IS NULL OR t.confirmations=0)')
|
||||
trace "[manage_missed_conf] watches=${watches}"
|
||||
if [ ${#watches} -eq 0 ]; then
|
||||
@@ -72,8 +68,7 @@ manage_missed_conf()
|
||||
return ${returncode}
|
||||
fi
|
||||
|
||||
# | tr -d '"'
|
||||
local txids=$(echo "${unspents}" | jq ".result[].txid" | tr -d '"')
|
||||
local txids=$(echo "${unspents}" | jq -r ".result[].txid")
|
||||
for txid in ${txids}
|
||||
do
|
||||
confirmation "${txid}"
|
||||
|
||||
@@ -24,9 +24,9 @@ notify_web() {
|
||||
# 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}"
|
||||
curl_code=$(echo "${response}" | jq ".curl_code" | tr -d '"')
|
||||
curl_code=$(echo "${response}" | jq -r ".curl_code")
|
||||
trace "[notify_web] curl_code=${curl_code}"
|
||||
http_code=$(echo "${response}" | jq ".http_code" | tr -d '"')
|
||||
http_code=$(echo "${response}" | jq -r ".http_code")
|
||||
trace "[notify_web] http_code=${http_code}"
|
||||
|
||||
if [ "${curl_code}" -eq "0" ] && [ "${returncode}" -eq "0" ]; then
|
||||
|
||||
@@ -7,9 +7,9 @@ serve_ots_stamp() {
|
||||
trace "Entering serve_ots_stamp()..."
|
||||
|
||||
local request=${1}
|
||||
local hash=$(echo "${request}" | jq ".hash" | tr -d '"')
|
||||
local hash=$(echo "${request}" | jq -r ".hash")
|
||||
trace "[serve_ots_stamp] hash=${hash}"
|
||||
local callbackUrl=$(echo "${request}" | jq ".callbackUrl" | tr -d '"')
|
||||
local callbackUrl=$(echo "${request}" | jq -r ".callbackUrl")
|
||||
trace "[serve_ots_stamp] callbackUrl=${callbackUrl}"
|
||||
|
||||
local result
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
. ./ots.sh
|
||||
. ./newblock.sh
|
||||
|
||||
main()
|
||||
{
|
||||
main() {
|
||||
trace "Entering main()..."
|
||||
|
||||
local step=0
|
||||
@@ -269,7 +268,7 @@ main()
|
||||
# POST http://192.168.111.152:8080/addtobatch
|
||||
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233}
|
||||
|
||||
response=$(addtobatching $(echo "${line}" | jq ".address" | tr -d '"') $(echo "${line}" | jq ".amount"))
|
||||
response=$(addtobatching $(echo "${line}" | jq -r ".address") $(echo "${line}" | jq ".amount"))
|
||||
response_to_client "${response}" ${?}
|
||||
break
|
||||
;;
|
||||
|
||||
@@ -36,11 +36,11 @@ ln_waitanyinvoice() {
|
||||
trace "[ln_waitanyinvoice] result=${result}"
|
||||
|
||||
if [ "${returncode}" -eq "0" ]; then
|
||||
bolt11=$(echo "${result}" | jq ".bolt11" | tr -d '"')
|
||||
pay_index=$(echo "${result}" | jq ".pay_index" | tr -d '"')
|
||||
msatoshi_received=$(echo "${result}" | jq ".msatoshi_received" | tr -d '"')
|
||||
status=$(echo "${result}" | jq ".status" | tr -d '"')
|
||||
paid_at=$(echo "${result}" | jq ".paid_at" | tr -d '"')
|
||||
bolt11=$(echo "${result}" | jq -r ".bolt11")
|
||||
pay_index=$(echo "${result}" | jq -r ".pay_index")
|
||||
msatoshi_received=$(echo "${result}" | jq -r ".msatoshi_received")
|
||||
status=$(echo "${result}" | jq -r ".status")
|
||||
paid_at=$(echo "${result}" | jq -r ".paid_at")
|
||||
|
||||
sql "UPDATE ln_invoice SET status=\"${status}\", pay_index=${pay_index}, msatoshi_received=${msatoshi_received}, paid_at=${paid_at} WHERE bolt11=\"${bolt11}\""
|
||||
row=$(sql "SELECT id, label, bolt11, callback_url, payment_hash, msatoshi, status, pay_index, msatoshi_received, paid_at, description, expires_at FROM ln_invoice WHERE NOT calledback AND bolt11=\"${bolt11}\"")
|
||||
|
||||
@@ -8,7 +8,7 @@ spend() {
|
||||
|
||||
local data
|
||||
local request=${1}
|
||||
local address=$(echo "${request}" | jq ".address" | tr -d '"')
|
||||
local address=$(echo "${request}" | jq -r ".address")
|
||||
trace "[spend] address=${address}"
|
||||
local amount=$(echo "${request}" | jq ".amount" | awk '{ printf "%.8f", $0 }')
|
||||
trace "[spend] amount=${amount}"
|
||||
@@ -23,7 +23,7 @@ spend() {
|
||||
trace "[spend] response=${response}"
|
||||
|
||||
if [ "${returncode}" -eq 0 ]; then
|
||||
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
|
||||
local txid=$(echo "${response}" | jq -r ".result")
|
||||
trace "[spend] txid=${txid}"
|
||||
|
||||
# Let's get transaction details on the spending wallet so that we have fee information
|
||||
@@ -66,7 +66,7 @@ bumpfee() {
|
||||
trace "Entering bumpfee()..."
|
||||
|
||||
local request=${1}
|
||||
local txid=$(echo "${request}" | jq ".txid" | tr -d '"')
|
||||
local txid=$(echo "${request}" | jq -r ".txid")
|
||||
trace "[bumpfee] txid=${txid}"
|
||||
|
||||
local confTarget
|
||||
@@ -273,7 +273,7 @@ batchspend() {
|
||||
trace "[batchspend] response=${response}"
|
||||
|
||||
if [ "${returncode}" -eq 0 ]; then
|
||||
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
|
||||
local txid=$(echo "${response}" | jq -r ".result")
|
||||
trace "[batchspend] txid=${txid}"
|
||||
|
||||
# Let's get transaction details on the spending wallet so that we have fee information
|
||||
|
||||
@@ -11,9 +11,9 @@ watchrequest() {
|
||||
|
||||
local returncode
|
||||
local request=${1}
|
||||
local address=$(echo "${request}" | jq ".address" | tr -d '"')
|
||||
local cb0conf_url=$(echo "${request}" | jq ".unconfirmedCallbackURL" | tr -d '"')
|
||||
local cb1conf_url=$(echo "${request}" | jq ".confirmedCallbackURL" | tr -d '"')
|
||||
local address=$(echo "${request}" | jq -r ".address")
|
||||
local cb0conf_url=$(echo "${request}" | jq -r ".unconfirmedCallbackURL")
|
||||
local cb1conf_url=$(echo "${request}" | jq -r ".confirmedCallbackURL")
|
||||
local imported
|
||||
local inserted
|
||||
local id_inserted
|
||||
@@ -76,17 +76,17 @@ watchpub32request() {
|
||||
|
||||
local returncode
|
||||
local request=${1}
|
||||
local label=$(echo "${request}" | jq ".label" | tr -d '"')
|
||||
local label=$(echo "${request}" | jq -r ".label")
|
||||
trace "[watchpub32request] label=${label}"
|
||||
local pub32=$(echo "${request}" | jq ".pub32" | tr -d '"')
|
||||
local pub32=$(echo "${request}" | jq -r ".pub32")
|
||||
trace "[watchpub32request] pub32=${pub32}"
|
||||
local path=$(echo "${request}" | jq ".path" | tr -d '"')
|
||||
local path=$(echo "${request}" | jq -r ".path")
|
||||
trace "[watchpub32request] path=${path}"
|
||||
local nstart=$(echo "${request}" | jq ".nstart")
|
||||
trace "[watchpub32request] nstart=${nstart}"
|
||||
local cb0conf_url=$(echo "${request}" | jq ".unconfirmedCallbackURL" | tr -d '"')
|
||||
local cb0conf_url=$(echo "${request}" | jq -r ".unconfirmedCallbackURL")
|
||||
trace "[watchpub32request] cb0conf_url=${cb0conf_url}"
|
||||
local cb1conf_url=$(echo "${request}" | jq ".confirmedCallbackURL" | tr -d '"')
|
||||
local cb1conf_url=$(echo "${request}" | jq -r ".confirmedCallbackURL")
|
||||
trace "[watchpub32request] cb1conf_url=${cb1conf_url}"
|
||||
|
||||
watchpub32 ${label} ${pub32} ${path} ${nstart} ${cb0conf_url} ${cb1conf_url}
|
||||
@@ -297,11 +297,11 @@ watchtxidrequest() {
|
||||
local returncode
|
||||
local request=${1}
|
||||
trace "[watchtxidrequest] request=${request}"
|
||||
local txid=$(echo "${request}" | jq ".txid" | tr -d '"')
|
||||
local txid=$(echo "${request}" | jq -r ".txid")
|
||||
trace "[watchtxidrequest] txid=${txid}"
|
||||
local cb1conf_url=$(echo "${request}" | jq ".confirmedCallbackURL" | tr -d '"')
|
||||
local cb1conf_url=$(echo "${request}" | jq -r ".confirmedCallbackURL")
|
||||
trace "[watchtxidrequest] cb1conf_url=${cb1conf_url}"
|
||||
local cbxconf_url=$(echo "${request}" | jq ".xconfCallbackURL" | tr -d '"')
|
||||
local cbxconf_url=$(echo "${request}" | jq -r ".xconfCallbackURL")
|
||||
trace "[watchtxidrequest] cbxconf_url=${cbxconf_url}"
|
||||
local nbxconf=$(echo "${request}" | jq ".nbxconf")
|
||||
trace "[watchtxidrequest] nbxconf=${nbxconf}"
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
. ./trace.sh
|
||||
|
||||
derive()
|
||||
{
|
||||
derive() {
|
||||
trace "Entering derive()..."
|
||||
|
||||
local request=${1}
|
||||
local pub32=$(echo "${request}" | jq ".pub32" | tr -d '"')
|
||||
local path=$(echo "${request}" | jq ".path" | tr -d '"')
|
||||
local pub32=$(echo "${request}" | jq -r ".pub32")
|
||||
local path=$(echo "${request}" | jq -r ".path")
|
||||
|
||||
local result
|
||||
local returncode
|
||||
|
||||
Reference in New Issue
Block a user