mirror of
https://github.com/aljazceru/cyphernode.git
synced 2025-12-18 13:14:56 +01:00
OTS info first draft
This commit is contained in:
@@ -24,6 +24,8 @@ action_getbestblockhash=watcher
|
||||
action_getbestblockinfo=watcher
|
||||
action_getblockinfo=watcher
|
||||
action_gettransaction=watcher
|
||||
action_ots_verify=watcher
|
||||
action_ots_info=watcher
|
||||
action_ln_getinfo=watcher
|
||||
action_ln_create_invoice=watcher
|
||||
action_ln_getconnectionstring=watcher
|
||||
|
||||
@@ -197,3 +197,62 @@ verify() {
|
||||
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
info() {
|
||||
trace "Entering info()..."
|
||||
|
||||
local request=${1}
|
||||
local base64otsfile=$(echo "${request}" | jq ".base64otsfile" | tr -d '"')
|
||||
trace "[info] base64otsfile=${base64otsfile}"
|
||||
|
||||
local result
|
||||
local returncode
|
||||
local message
|
||||
local data
|
||||
|
||||
# Let's create the OTS file locally from the base64
|
||||
trace "[info] Creating /otsfiles/otsfile-$$.ots"
|
||||
echo "${base64otsfile}" | base64 -d > /otsfiles/otsfile-$$.ots
|
||||
|
||||
trace "[info] ots-cli.js info /otsfiles/otsfile-$$.ots"
|
||||
result=$(ots-cli.js info /otsfiles/otsfile-$$.ots 2>&1 | base64 | tr -d '\n')
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
trace "[info] result=${result}"
|
||||
|
||||
trace "[info] Removing temporary file /otsfiles/otsfile-$$.ots..."
|
||||
rm /otsfiles/otsfile-$$.ots
|
||||
|
||||
# /otsfiles # ots-cli.js info a2d4ff9c70b7b884e04e04c184a7bf8a07dca029a68efa4d0477cea0c6f8ac2b.ots
|
||||
# File sha256 hash: a2d4ff9c70b7b884e04e04c184a7bf8a07dca029a68efa4d0477cea0c6f8ac2b
|
||||
# Timestamp:
|
||||
# append 0736f76dfd242f5156321c561d11ef47
|
||||
# sha256
|
||||
# -> append 4820230d20f302a17a45f0de0e3e23a6
|
||||
# sha256
|
||||
# prepend 5d5da8e6
|
||||
# append 8b6d6af19f6ac839
|
||||
# verify PendingAttestation('https://alice.btc.calendar.opentimestamps.org')
|
||||
# -> append 9c5e80c7251b313b180acc6e2341d9de
|
||||
# sha256
|
||||
# prepend 5d5da8e6
|
||||
# append 59d56c4ad5d8d6e4
|
||||
# verify PendingAttestation('https://bob.btc.calendar.opentimestamps.org')
|
||||
# -> append a437fa964b029950dc8f507de448cd08
|
||||
# sha256
|
||||
# prepend 5d5da8e6
|
||||
# append d25542b20883d479
|
||||
# verify PendingAttestation('https://finney.calendar.eternitywall.com')
|
||||
# -> append a34c1ae4a38e776450a643d298abf428
|
||||
# sha256
|
||||
# prepend 5d5da8e7
|
||||
# append 60ed070138239971
|
||||
# verify PendingAttestation('https://btc.calendar.catallaxy.com')
|
||||
|
||||
data="{\"method\":\"info\",\"result\":\"${result}\"}"
|
||||
trace "[info] data=${data}"
|
||||
|
||||
echo "${data}"
|
||||
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,14 @@ main()
|
||||
response_to_client "${response}" ${?}
|
||||
break
|
||||
;;
|
||||
info)
|
||||
# POST http://192.168.111.152:8080/info
|
||||
# BODY {"base64otsfile":"AE9wZW5UaW1lc3RhbXBzAABQcm9vZ...gABYiWDXPXGQEDxNch"}
|
||||
|
||||
response=$(info "${line}")
|
||||
response_to_client "${response}" ${?}
|
||||
break
|
||||
;;
|
||||
esac
|
||||
break
|
||||
fi
|
||||
|
||||
@@ -9,8 +9,12 @@ serve_ots_stamp() {
|
||||
local request=${1}
|
||||
local hash=$(echo "${request}" | jq -r ".hash")
|
||||
trace "[serve_ots_stamp] hash=${hash}"
|
||||
local callbackUrl=$(echo "${request}" | jq -r ".callbackUrl")
|
||||
[ "${callbackUrl}" = "null" ] && callbackUrl=
|
||||
local callbackUrl
|
||||
callbackUrl=$(echo "${request}" | jq -er ".callbackUrl")
|
||||
if [ "$?" -ne "0" ]; then
|
||||
# callbackUrl tag null, so there's no callbackUrl provided
|
||||
callbackUrl=
|
||||
fi
|
||||
trace "[serve_ots_stamp] callbackUrl=${callbackUrl}"
|
||||
|
||||
local result
|
||||
@@ -204,7 +208,7 @@ serve_ots_backoffice() {
|
||||
trace "[serve_ots_backoffice] url=${url}"
|
||||
|
||||
# Call back newly upgraded stamps if url provided
|
||||
if [ ${#url} -gt 0 ]; then
|
||||
if [ -n ${url} ]; then
|
||||
trace "[serve_ots_backoffice] url is not empty, now trying to call it!"
|
||||
|
||||
notify_web "${url}"
|
||||
@@ -301,3 +305,88 @@ request_ots_verify() {
|
||||
echo "${result}"
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
serve_ots_info() {
|
||||
|
||||
trace "Entering serve_ots_info()..."
|
||||
|
||||
local request=${1}
|
||||
local hash
|
||||
hash=$(echo "${request}" | jq -e ".hash" | tr -d '"')
|
||||
if [ "$?" -ne "0" ]; then
|
||||
# Hash tag null, so there's no hash provided
|
||||
hash=
|
||||
fi
|
||||
trace "[serve_ots_info] hash=${hash}"
|
||||
local base64otsfile
|
||||
base64otsfile=$(echo "${request}" | jq -e ".base64otsfile" | tr -d '"')
|
||||
if [ "$?" -ne "0" ]; then
|
||||
# base64otsfile tag null, so there's no base64otsfile provided
|
||||
base64otsfile=
|
||||
fi
|
||||
trace "[serve_ots_info] base64otsfile=${base64otsfile}"
|
||||
|
||||
# If file is provided, we will execute info on it
|
||||
# If file not provided, we will check for hash.ots in our folder and execute info on it
|
||||
if [ -z "${base64otsfile}" ]; then
|
||||
if [ -f otsfiles/${hash}.ots ]; then
|
||||
trace "[serve_ots_info] Constructing base64otsfile from provided hash, file otsfiles/${hash}.ots"
|
||||
base64otsfile=$(cat otsfiles/${hash}.ots | base64 | tr -d '\n')
|
||||
else
|
||||
trace "[serve_ots_info] File otsfiles/${hash}.ots does not exists!"
|
||||
echo "{\"method\":\"ots_info\",\"result\":\"error\",\"message\":\"OTS File not found\"}"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
local result
|
||||
local message
|
||||
local returncode
|
||||
|
||||
trace "[serve_ots_info] request_ots_info \"${base64otsfile}\""
|
||||
result=$(request_ots_info "${base64otsfile}")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
|
||||
if [ "${returncode}" -eq "0" ]; then
|
||||
result=$(echo ${result} | jq ".result")
|
||||
result="{\"method\":\"ots_info\",\"result\":\"success\",\"message\":${result}}"
|
||||
else
|
||||
result="{\"method\":\"ots_info\",\"result\":\"error\",\"message\":${result}}"
|
||||
fi
|
||||
|
||||
trace "[serve_ots_info] result=${result}"
|
||||
|
||||
# Output response to stdout before exiting with return code
|
||||
echo "${result}"
|
||||
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
request_ots_info() {
|
||||
# Request the OTS server to verify
|
||||
|
||||
local base64otsfile=${1}
|
||||
trace "[request_ots_info] base64otsfile=${base64otsfile}"
|
||||
local returncode
|
||||
local result
|
||||
local data
|
||||
|
||||
# BODY {"base64otsfile":"AE9wZW5UaW1lc3RhbXBzAABQcm9vZ...gABYiWDXPXGQEDxNch"}
|
||||
data="{\"base64otsfile\":\"${base64otsfile}\"}"
|
||||
trace "[request_ots_info] data=${data}"
|
||||
|
||||
trace "[request_ots_info] Parsing..."
|
||||
trace "[request_ots_info] curl -s -d \"${data}\" ${OTSCLIENT_CONTAINER}/info"
|
||||
result=$(curl -s -d "${data}" ${OTSCLIENT_CONTAINER}/info)
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
trace "[request_ots_info] OTS info result=${result}"
|
||||
|
||||
if [ "${returncode}" -ne 0 ]; then
|
||||
trace "[request_ots_info] OTS info error"
|
||||
fi
|
||||
|
||||
echo "${result}"
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
@@ -407,6 +407,20 @@ main() {
|
||||
response_to_client "${response}" ${?}
|
||||
break
|
||||
;;
|
||||
ots_info)
|
||||
# POST http://192.168.111.152:8080/ots_info
|
||||
# BODY {"hash":"1ddfb769eb0b8876bc570e25580e6a53afcf973362ee1ee4b54a807da2e5eed7"}
|
||||
# BODY {"base64otsfile":"AE9wZW5UaW1lc3RhbXBzAABQcm9vZ...gABYiWDXPXGQEDxNch"}
|
||||
# BODY {"hash":"1ddfb769eb0b8876bc570e25580e6a53afcf973362ee1ee4b54a807da2e5eed7","base64otsfile":"AE9wZW5UaW1lc3RhbXBzAABQcm9vZ...gABYiWDXPXGQEDxNch"}
|
||||
|
||||
# curl -v -d "{\"hash\":\"a6ea81a46fec3d02d40815b8667b388351edecedc1cc9f97aab55b566db7aac8\"}" localhost:8888/ots_info
|
||||
# curl -v -d "{\"base64otsfile\":\"$(cat a6ea81a46fec3d02d40815b8667b388351edecedc1cc9f97aab55b566db7aac8.ots | base64 | tr -d '\n')\"}" localhost:8888/ots_info
|
||||
# curl -v -d "{\"hash\":\"a6ea81a46fec3d02d40815b8667b388351edecedc1cc9f97aab55b566db7aac8\",\"base64otsfile\":\"$(cat a6ea81a46fec3d02d40815b8667b388351edecedc1cc9f97aab55b566db7aac8.ots | base64 | tr -d '\n')\"}" localhost:8888/ots_info
|
||||
|
||||
response=$(serve_ots_info "${line}")
|
||||
response_to_client "${response}" ${?}
|
||||
break
|
||||
;;
|
||||
esac
|
||||
break
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user