mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-02-14 16:54:27 +01:00
OTS on the client samples and a fix in comments
This commit is contained in:
@@ -30,48 +30,56 @@ CyphernodeClient.prototype._generateToken = function() {
|
||||
return token
|
||||
}
|
||||
|
||||
CyphernodeClient.prototype._post = function(url, postdata, cb) {
|
||||
CyphernodeClient.prototype._post = function(url, postdata, cb, addedOptions) {
|
||||
let urlr = this.baseURL + url;
|
||||
|
||||
HTTP.post(urlr,
|
||||
{
|
||||
data: postdata,
|
||||
npmRequestOptions: {
|
||||
strictSSL: false,
|
||||
agentOptions: {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + this._generateToken()
|
||||
let httpOptions = {
|
||||
data: postdata,
|
||||
npmRequestOptions: {
|
||||
strictSSL: false,
|
||||
agentOptions: {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
}, function (err, resp) {
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + this._generateToken()
|
||||
}
|
||||
}
|
||||
if (addedOptions) {
|
||||
Object.assign(httpOptions.npmRequestOptions, addedOptions)
|
||||
}
|
||||
|
||||
HTTP.post(urlr, httpOptions,
|
||||
function (err, resp) {
|
||||
// console.log(err)
|
||||
// console.log(resp)
|
||||
cb(err, resp.data)
|
||||
cb(err, resp.data || resp.content)
|
||||
}
|
||||
)
|
||||
};
|
||||
|
||||
CyphernodeClient.prototype._get = function(url, cb) {
|
||||
CyphernodeClient.prototype._get = function(url, cb, addedOptions) {
|
||||
let urlr = this.baseURL + url;
|
||||
|
||||
HTTP.get(urlr,
|
||||
{
|
||||
npmRequestOptions: {
|
||||
strictSSL: false,
|
||||
agentOptions: {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + this._generateToken()
|
||||
let httpOptions = {
|
||||
npmRequestOptions: {
|
||||
strictSSL: false,
|
||||
agentOptions: {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
}, function (err, resp) {
|
||||
},
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + this._generateToken()
|
||||
}
|
||||
}
|
||||
if (addedOptions) {
|
||||
Object.assign(httpOptions.npmRequestOptions, addedOptions)
|
||||
}
|
||||
|
||||
HTTP.get(urlr, httpOptions,
|
||||
function (err, resp) {
|
||||
// console.log(err)
|
||||
// console.log(resp)
|
||||
cb(err, resp.data)
|
||||
cb(err, resp.data || resp.content)
|
||||
}
|
||||
)
|
||||
};
|
||||
@@ -112,3 +120,17 @@ CyphernodeClient.prototype.getNewAddress = function(cbreply) {
|
||||
// http://192.168.122.152:8080/getnewaddress
|
||||
this._get('/getnewaddress', cbreply);
|
||||
};
|
||||
|
||||
CyphernodeClient.prototype.ots_stamp = function(hash, callbackUrl, cbreply) {
|
||||
// POST https://cyphernode/ots_stamp
|
||||
// BODY {"hash":"1ddfb769eb0b8876bc570e25580e6a53afcf973362ee1ee4b54a807da2e5eed7","callbackUrl":"192.168.111.233:1111/callbackUrl"}
|
||||
let data = { hash: hash, callbackUrl: callbackUrl }
|
||||
this._post('/ots_stamp', data, cbreply);
|
||||
};
|
||||
|
||||
CyphernodeClient.prototype.ots_getfile = function(hash, cbreply) {
|
||||
// http://192.168.122.152:8080/ots_getfile/1ddfb769eb0b8876bc570e25580e6a53afcf973362ee1ee4b54a807da2e5eed7
|
||||
|
||||
// encoding: null is for HTTP get to not convert the binary data to the default encoding
|
||||
this._get('/ots_getfile/' + hash, cbreply, { encoding: null });
|
||||
};
|
||||
|
||||
@@ -4,73 +4,92 @@
|
||||
|
||||
invoke_cyphernode()
|
||||
{
|
||||
local action=${1}
|
||||
local post=${2}
|
||||
local action=${1}
|
||||
local post=${2}
|
||||
|
||||
local p64=$(echo -n "{\"id\":\"${id}\",\"exp\":$((`date +"%s"`+10))}" | base64)
|
||||
local s=$(echo -n "$h64.$p64" | openssl dgst -hmac "$key" -sha256 -r | cut -sd ' ' -f1)
|
||||
local token="$h64.$p64.$s"
|
||||
local p64=$(echo -n "{\"id\":\"${id}\",\"exp\":$((`date +"%s"`+10))}" | base64)
|
||||
local s=$(echo -n "$h64.$p64" | openssl dgst -hmac "$key" -sha256 -r | cut -sd ' ' -f1)
|
||||
local token="$h64.$p64.$s"
|
||||
|
||||
if [ -n "${post}" ]; then
|
||||
echo $(curl -v -H "Authorization: Bearer $token" -d "${post}" -k "https://cyphernode/${action}")
|
||||
return $?
|
||||
else
|
||||
echo $(curl -v -H "Authorization: Bearer $token" -k "https://cyphernode/${action}")
|
||||
return $?
|
||||
fi
|
||||
if [ -n "${post}" ]; then
|
||||
echo $(curl -v -H "Authorization: Bearer $token" -d "${post}" -k "https://cyphernode/${action}")
|
||||
return $?
|
||||
else
|
||||
echo $(curl -v -H "Authorization: Bearer $token" -k "https://cyphernode/${action}")
|
||||
return $?
|
||||
fi
|
||||
}
|
||||
|
||||
watch()
|
||||
{
|
||||
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","unconfirmedCallbackURL":"192.168.122.233:1111/callback0conf","confirmedCallbackURL":"192.168.122.233:1111/callback1conf"}
|
||||
local btcaddr=${1}
|
||||
local cb0conf=${2}
|
||||
local cb1conf=${3}
|
||||
local post="{\"address\":\"${btcaddr}\",\"unconfirmedCallbackURL\":\"${cb0conf}\",\"confirmedCallbackURL\":\"${cb1conf}\"}"
|
||||
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","unconfirmedCallbackURL":"192.168.122.233:1111/callback0conf","confirmedCallbackURL":"192.168.122.233:1111/callback1conf"}
|
||||
local btcaddr=${1}
|
||||
local cb0conf=${2}
|
||||
local cb1conf=${3}
|
||||
local post="{\"address\":\"${btcaddr}\",\"unconfirmedCallbackURL\":\"${cb0conf}\",\"confirmedCallbackURL\":\"${cb1conf}\"}"
|
||||
|
||||
echo $(invoke_cyphernode "watch" ${post})
|
||||
echo $(invoke_cyphernode "watch" ${post})
|
||||
}
|
||||
|
||||
unwatch()
|
||||
{
|
||||
# 192.168.122.152:8080/unwatch/2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp
|
||||
local btcaddr=${1}
|
||||
# 192.168.122.152:8080/unwatch/2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp
|
||||
local btcaddr=${1}
|
||||
|
||||
echo $(invoke_cyphernode "unwatch/${btcaddr}")
|
||||
echo $(invoke_cyphernode "unwatch/${btcaddr}")
|
||||
}
|
||||
|
||||
getactivewatches()
|
||||
{
|
||||
# 192.168.122.152:8080/getactivewatches
|
||||
echo $(invoke_cyphernode "getactivewatches")
|
||||
# 192.168.122.152:8080/getactivewatches
|
||||
echo $(invoke_cyphernode "getactivewatches")
|
||||
}
|
||||
|
||||
gettransaction()
|
||||
{
|
||||
# http://192.168.122.152:8080/gettransaction/af867c86000da76df7ddb1054b273ca9e034e8c89d049b5b2795f9f590f67648
|
||||
local txid=${1}
|
||||
# http://192.168.122.152:8080/gettransaction/af867c86000da76df7ddb1054b273ca9e034e8c89d049b5b2795f9f590f67648
|
||||
local txid=${1}
|
||||
|
||||
echo $(invoke_cyphernode "gettransaction/${txid}")
|
||||
echo $(invoke_cyphernode "gettransaction/${txid}")
|
||||
}
|
||||
|
||||
spend()
|
||||
{
|
||||
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233}
|
||||
local btcaddr=${1}
|
||||
local amount=${2}
|
||||
local post="{\"address\":\"${btcaddr}\",\"amount\":\"${amount}\"}"
|
||||
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233}
|
||||
local btcaddr=${1}
|
||||
local amount=${2}
|
||||
local post="{\"address\":\"${btcaddr}\",\"amount\":\"${amount}\"}"
|
||||
|
||||
echo $(invoke_cyphernode "spend" ${post})
|
||||
echo $(invoke_cyphernode "spend" ${post})
|
||||
}
|
||||
|
||||
getbalance()
|
||||
{
|
||||
# http://192.168.122.152:8080/getbalance
|
||||
echo $(invoke_cyphernode "getbalance")
|
||||
# http://192.168.122.152:8080/getbalance
|
||||
echo $(invoke_cyphernode "getbalance")
|
||||
}
|
||||
|
||||
getnewaddress()
|
||||
{
|
||||
# http://192.168.122.152:8080/getnewaddress
|
||||
echo $(invoke_cyphernode "getnewaddress")
|
||||
# http://192.168.122.152:8080/getnewaddress
|
||||
echo $(invoke_cyphernode "getnewaddress")
|
||||
}
|
||||
|
||||
ots_stamp()
|
||||
{
|
||||
# POST https://cyphernode/ots_stamp
|
||||
# BODY {"hash":"1ddfb769eb0b8876bc570e25580e6a53afcf973362ee1ee4b54a807da2e5eed7","callbackUrl":"192.168.111.233:1111/callbackUrl"}
|
||||
local hash=${1}
|
||||
local callbackUrl=${2}
|
||||
local post="{\"hash\":\"${hash}\",\"callbackUrl\":\"${callbackUrl}\"}"
|
||||
|
||||
echo $(invoke_cyphernode "ots_stamp" ${post})
|
||||
}
|
||||
|
||||
ots_getfile()
|
||||
{
|
||||
# http://192.168.122.152:8080/ots_getfile/1ddfb769eb0b8876bc570e25580e6a53afcf973362ee1ee4b54a807da2e5eed7
|
||||
local hash=${1}
|
||||
|
||||
echo $(invoke_cyphernode "ots_getfile/${hash}")
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ serve_ots_backoffice()
|
||||
fi
|
||||
fi
|
||||
if [ "${upgraded}" -eq "1" ]; then
|
||||
trace "[serve_ots_backoffice] upgraded! Let's send the OTS file to callback..."
|
||||
trace "[serve_ots_backoffice] upgraded! Let's call the callback..."
|
||||
url=$(echo "${row}" | cut -d '|' -f2)
|
||||
trace "[serve_ots_backoffice] url=${url}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user