mirror of
https://github.com/aljazceru/cyphernode.git
synced 2025-12-18 13:14:56 +01:00
Added addresstype when calling getnewaddress.
This commit is contained in:
@@ -554,10 +554,13 @@ Proxy response:
|
|||||||
|
|
||||||
### Get a new Bitcoin address from spending wallet (called by application)
|
### Get a new Bitcoin address from spending wallet (called by application)
|
||||||
|
|
||||||
Calls getnewaddress RPC on the spending wallet. Used to refill the spending wallet from cold wallet (ie Trezor).
|
Calls getnewaddress RPC on the spending wallet. Used to refill the spending wallet from cold wallet (ie Trezor). Will derive the default address type (set in your bitcoin.conf file, p2sh-segwit if not specified) or you can supply the address type like the following examples.
|
||||||
|
|
||||||
```http
|
```http
|
||||||
GET http://cyphernode:8888/getnewaddress
|
GET http://cyphernode:8888/getnewaddress
|
||||||
|
GET http://cyphernode:8888/getnewaddress/bech32
|
||||||
|
GET http://cyphernode:8888/getnewaddress/legacy
|
||||||
|
GET http://cyphernode:8888/getnewaddress/p2sh-segwit
|
||||||
```
|
```
|
||||||
|
|
||||||
Proxy response:
|
Proxy response:
|
||||||
@@ -568,6 +571,12 @@ Proxy response:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"address":"tb1ql7yvh3lmajxmaljsnsu3w8lhwczu963tvjfzpj"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Spend coins from spending wallet (called by application)
|
### Spend coins from spending wallet (called by application)
|
||||||
|
|
||||||
Calls sendtoaddress RPC on the spending wallet with supplied info.
|
Calls sendtoaddress RPC on the spending wallet with supplied info.
|
||||||
|
|||||||
@@ -227,8 +227,9 @@ main()
|
|||||||
;;
|
;;
|
||||||
getnewaddress)
|
getnewaddress)
|
||||||
# curl (GET) http://192.168.111.152:8080/getnewaddress
|
# curl (GET) http://192.168.111.152:8080/getnewaddress
|
||||||
|
# curl (GET) http://192.168.111.152:8080/getnewaddress/bech32
|
||||||
|
|
||||||
response=$(getnewaddress)
|
response=$(getnewaddress $(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3))
|
||||||
response_to_client "${response}" ${?}
|
response_to_client "${response}" ${?}
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -4,71 +4,71 @@
|
|||||||
. ./sendtobitcoinnode.sh
|
. ./sendtobitcoinnode.sh
|
||||||
|
|
||||||
spend() {
|
spend() {
|
||||||
trace "Entering spend()..."
|
trace "Entering spend()..."
|
||||||
|
|
||||||
local data
|
local data
|
||||||
local request=${1}
|
local request=${1}
|
||||||
local address=$(echo "${request}" | jq ".address" | tr -d '"')
|
local address=$(echo "${request}" | jq ".address" | tr -d '"')
|
||||||
trace "[spend] address=${address}"
|
trace "[spend] address=${address}"
|
||||||
local amount=$(echo "${request}" | jq ".amount" | awk '{ printf "%.8f", $0 }')
|
local amount=$(echo "${request}" | jq ".amount" | awk '{ printf "%.8f", $0 }')
|
||||||
trace "[spend] amount=${amount}"
|
trace "[spend] amount=${amount}"
|
||||||
local response
|
local response
|
||||||
local id_inserted
|
local id_inserted
|
||||||
|
|
||||||
response=$(send_to_spender_node "{\"method\":\"sendtoaddress\",\"params\":[\"${address}\",${amount}]}")
|
response=$(send_to_spender_node "{\"method\":\"sendtoaddress\",\"params\":[\"${address}\",${amount}]}")
|
||||||
local returncode=$?
|
local returncode=$?
|
||||||
trace_rc ${returncode}
|
trace_rc ${returncode}
|
||||||
trace "[spend] response=${response}"
|
trace "[spend] response=${response}"
|
||||||
|
|
||||||
if [ "${returncode}" -eq 0 ]; then
|
if [ "${returncode}" -eq 0 ]; then
|
||||||
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
|
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
|
||||||
trace "[spend] txid=${txid}"
|
trace "[spend] txid=${txid}"
|
||||||
|
|
||||||
# Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address
|
# Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address
|
||||||
sql "INSERT OR IGNORE INTO tx (txid) VALUES (\"${txid}\")"
|
sql "INSERT OR IGNORE INTO tx (txid) VALUES (\"${txid}\")"
|
||||||
trace_rc $?
|
trace_rc $?
|
||||||
id_inserted=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"")
|
id_inserted=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"")
|
||||||
trace_rc $?
|
trace_rc $?
|
||||||
sql "INSERT OR IGNORE INTO recipient (address, amount, tx_id) VALUES (\"${address}\", ${amount}, ${id_inserted})"
|
sql "INSERT OR IGNORE INTO recipient (address, amount, tx_id) VALUES (\"${address}\", ${amount}, ${id_inserted})"
|
||||||
trace_rc $?
|
trace_rc $?
|
||||||
|
|
||||||
data="{\"status\":\"accepted\""
|
data="{\"status\":\"accepted\""
|
||||||
data="${data},\"hash\":\"${txid}\"}"
|
data="${data},\"hash\":\"${txid}\"}"
|
||||||
else
|
else
|
||||||
local message=$(echo "${response}" | jq -e ".error.message")
|
local message=$(echo "${response}" | jq -e ".error.message")
|
||||||
data="{\"message\":${message}}"
|
data="{\"message\":${message}}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
trace "[spend] responding=${data}"
|
trace "[spend] responding=${data}"
|
||||||
echo "${data}"
|
echo "${data}"
|
||||||
|
|
||||||
return ${returncode}
|
return ${returncode}
|
||||||
}
|
}
|
||||||
|
|
||||||
getbalance() {
|
getbalance() {
|
||||||
trace "Entering getbalance()..."
|
trace "Entering getbalance()..."
|
||||||
|
|
||||||
local response
|
local response
|
||||||
local data='{"method":"getbalance"}'
|
local data='{"method":"getbalance"}'
|
||||||
response=$(send_to_spender_node "${data}")
|
response=$(send_to_spender_node "${data}")
|
||||||
local returncode=$?
|
local returncode=$?
|
||||||
trace_rc ${returncode}
|
trace_rc ${returncode}
|
||||||
trace "[getbalance] response=${response}"
|
trace "[getbalance] response=${response}"
|
||||||
|
|
||||||
if [ "${returncode}" -eq 0 ]; then
|
if [ "${returncode}" -eq 0 ]; then
|
||||||
local balance=$(echo ${response} | jq ".result")
|
local balance=$(echo ${response} | jq ".result")
|
||||||
trace "[getbalance] balance=${balance}"
|
trace "[getbalance] balance=${balance}"
|
||||||
|
|
||||||
data="{\"balance\":${balance}}"
|
data="{\"balance\":${balance}}"
|
||||||
else
|
else
|
||||||
trace "[getbalance] Coudn't get balance!"
|
trace "[getbalance] Coudn't get balance!"
|
||||||
data=""
|
data=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
trace "[getbalance] responding=${data}"
|
trace "[getbalance] responding=${data}"
|
||||||
echo "${data}"
|
echo "${data}"
|
||||||
|
|
||||||
return ${returncode}
|
return ${returncode}
|
||||||
}
|
}
|
||||||
|
|
||||||
getbalancebyxpublabel() {
|
getbalancebyxpublabel() {
|
||||||
@@ -100,8 +100,8 @@ getbalancebyxpub() {
|
|||||||
trace "[getbalancebyxpub] event=${event}"
|
trace "[getbalancebyxpub] event=${event}"
|
||||||
local addresses
|
local addresses
|
||||||
local balance
|
local balance
|
||||||
local data
|
local data
|
||||||
local returncode
|
local returncode
|
||||||
|
|
||||||
# addresses=$(./bitcoin-cli -rpcwallet=xpubwatching01.dat getaddressesbylabel upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb | jq "keys" | tr -d '\n ')
|
# addresses=$(./bitcoin-cli -rpcwallet=xpubwatching01.dat getaddressesbylabel upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb | jq "keys" | tr -d '\n ')
|
||||||
data="{\"method\":\"getaddressesbylabel\",\"params\":[${xpub}]}"
|
data="{\"method\":\"getaddressesbylabel\",\"params\":[${xpub}]}"
|
||||||
@@ -112,127 +112,135 @@ getbalancebyxpub() {
|
|||||||
|
|
||||||
data="{\"method\":\"listunspent\",\"params\":[0, 9999999, \"${addresses}\"]}"
|
data="{\"method\":\"listunspent\",\"params\":[0, 9999999, \"${addresses}\"]}"
|
||||||
trace "[getbalancebyxpub] data=${data}"
|
trace "[getbalancebyxpub] data=${data}"
|
||||||
balance=$(send_to_xpub_watcher_wallet ${data} | jq "[.[].amount] | add | . * 100000000 | trunc | . / 100000000")
|
balance=$(send_to_xpub_watcher_wallet ${data} | jq "[.[].amount] | add | . * 100000000 | trunc | . / 100000000")
|
||||||
returncode=$?
|
returncode=$?
|
||||||
trace_rc ${returncode}
|
trace_rc ${returncode}
|
||||||
trace "[getbalancebyxpub] balance=${balance}"
|
trace "[getbalancebyxpub] balance=${balance}"
|
||||||
|
|
||||||
data="{\"event\":\"${event}\",\"xpub\":\"${xpub}\",\"balance\":${balance}}"
|
data="{\"event\":\"${event}\",\"xpub\":\"${xpub}\",\"balance\":${balance}}"
|
||||||
|
|
||||||
echo "${data}"
|
echo "${data}"
|
||||||
|
|
||||||
return ${returncode}
|
return ${returncode}
|
||||||
}
|
}
|
||||||
|
|
||||||
getnewaddress() {
|
getnewaddress() {
|
||||||
trace "Entering getnewaddress()..."
|
trace "Entering getnewaddress()..."
|
||||||
|
|
||||||
local response
|
local address_type=${1}
|
||||||
local data='{"method":"getnewaddress"}'
|
trace "[getnewaddress] address_type=${address_type}"
|
||||||
response=$(send_to_spender_node "${data}")
|
|
||||||
local returncode=$?
|
|
||||||
trace_rc ${returncode}
|
|
||||||
trace "[getnewaddress] response=${response}"
|
|
||||||
|
|
||||||
if [ "${returncode}" -eq 0 ]; then
|
local response
|
||||||
local address=$(echo ${response} | jq ".result")
|
local data
|
||||||
trace "[getnewaddress] address=${address}"
|
if [ -z "${address_type}" ]; then
|
||||||
|
data='{"method":"getnewaddress"}'
|
||||||
|
else
|
||||||
|
data="{\"method\":\"getnewaddress\",\"params\":[\"\",\"${address_type}\"]}"
|
||||||
|
fi
|
||||||
|
response=$(send_to_spender_node "${data}")
|
||||||
|
local returncode=$?
|
||||||
|
trace_rc ${returncode}
|
||||||
|
trace "[getnewaddress] response=${response}"
|
||||||
|
|
||||||
data="{\"address\":${address}}"
|
if [ "${returncode}" -eq 0 ]; then
|
||||||
else
|
local address=$(echo ${response} | jq ".result")
|
||||||
trace "[getnewaddress] Coudn't get a new address!"
|
trace "[getnewaddress] address=${address}"
|
||||||
data=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
trace "[getnewaddress] responding=${data}"
|
data="{\"address\":${address}}"
|
||||||
echo "${data}"
|
else
|
||||||
|
trace "[getnewaddress] Coudn't get a new address!"
|
||||||
|
data=""
|
||||||
|
fi
|
||||||
|
|
||||||
return ${returncode}
|
trace "[getnewaddress] responding=${data}"
|
||||||
|
echo "${data}"
|
||||||
|
|
||||||
|
return ${returncode}
|
||||||
}
|
}
|
||||||
|
|
||||||
addtobatching() {
|
addtobatching() {
|
||||||
trace "Entering addtobatching()..."
|
trace "Entering addtobatching()..."
|
||||||
|
|
||||||
local address=${1}
|
local address=${1}
|
||||||
trace "[addtobatching] address=${address}"
|
trace "[addtobatching] address=${address}"
|
||||||
local amount=${2}
|
local amount=${2}
|
||||||
trace "[addtobatching] amount=${amount}"
|
trace "[addtobatching] amount=${amount}"
|
||||||
|
|
||||||
sql "INSERT OR IGNORE INTO recipient (address, amount) VALUES (\"${address}\", ${amount})"
|
sql "INSERT OR IGNORE INTO recipient (address, amount) VALUES (\"${address}\", ${amount})"
|
||||||
returncode=$?
|
returncode=$?
|
||||||
trace_rc ${returncode}
|
trace_rc ${returncode}
|
||||||
|
|
||||||
return ${returncode}
|
return ${returncode}
|
||||||
}
|
}
|
||||||
|
|
||||||
batchspend() {
|
batchspend() {
|
||||||
trace "Entering batchspend()..."
|
trace "Entering batchspend()..."
|
||||||
|
|
||||||
local data
|
local data
|
||||||
local response
|
local response
|
||||||
local recipientswhere
|
local recipientswhere
|
||||||
local recipientsjson
|
local recipientsjson
|
||||||
local id_inserted
|
local id_inserted
|
||||||
|
|
||||||
# We will batch all the addresses in DB without a TXID
|
# We will batch all the addresses in DB without a TXID
|
||||||
local batching=$(sql 'SELECT address, amount FROM recipient WHERE tx_id IS NULL')
|
local batching=$(sql 'SELECT address, amount FROM recipient WHERE tx_id IS NULL')
|
||||||
trace "[batchspend] batching=${batching}"
|
trace "[batchspend] batching=${batching}"
|
||||||
|
|
||||||
local returncode
|
local returncode
|
||||||
local address
|
local address
|
||||||
local amount
|
local amount
|
||||||
local notfirst=false
|
local notfirst=false
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
for row in ${batching}
|
for row in ${batching}
|
||||||
do
|
do
|
||||||
trace "[batchspend] row=${row}"
|
trace "[batchspend] row=${row}"
|
||||||
address=$(echo "${row}" | cut -d '|' -f1)
|
address=$(echo "${row}" | cut -d '|' -f1)
|
||||||
trace "[batchspend] address=${address}"
|
trace "[batchspend] address=${address}"
|
||||||
amount=$(echo "${row}" | cut -d '|' -f2)
|
amount=$(echo "${row}" | cut -d '|' -f2)
|
||||||
trace "[batchspend] amount=${amount}"
|
trace "[batchspend] amount=${amount}"
|
||||||
|
|
||||||
if ${notfirst}; then
|
if ${notfirst}; then
|
||||||
recipientswhere="${recipientswhere},"
|
recipientswhere="${recipientswhere},"
|
||||||
recipientsjson="${recipientsjson},"
|
recipientsjson="${recipientsjson},"
|
||||||
else
|
else
|
||||||
notfirst=true
|
notfirst=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
recipientswhere="${recipientswhere}\"${address}\""
|
recipientswhere="${recipientswhere}\"${address}\""
|
||||||
recipientsjson="${recipientsjson}\"${address}\":${amount}"
|
recipientsjson="${recipientsjson}\"${address}\":${amount}"
|
||||||
done
|
done
|
||||||
|
|
||||||
response=$(send_to_spender_node "{\"method\":\"sendmany\",\"params\":[\"\", {${recipientsjson}}]}")
|
response=$(send_to_spender_node "{\"method\":\"sendmany\",\"params\":[\"\", {${recipientsjson}}]}")
|
||||||
returncode=$?
|
returncode=$?
|
||||||
trace_rc ${returncode}
|
trace_rc ${returncode}
|
||||||
trace "[batchspend] response=${response}"
|
trace "[batchspend] response=${response}"
|
||||||
|
|
||||||
if [ "${returncode}" -eq 0 ]; then
|
if [ "${returncode}" -eq 0 ]; then
|
||||||
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
|
local txid=$(echo "${response}" | jq ".result" | tr -d '"')
|
||||||
trace "[batchspend] txid=${txid}"
|
trace "[batchspend] txid=${txid}"
|
||||||
|
|
||||||
# Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address
|
# Let's insert the txid in our little DB to manage the confirmation and tell it's not a watching address
|
||||||
sql "INSERT OR IGNORE INTO tx (txid) VALUES (\"${txid}\")"
|
sql "INSERT OR IGNORE INTO tx (txid) VALUES (\"${txid}\")"
|
||||||
returncode=$?
|
returncode=$?
|
||||||
trace_rc ${returncode}
|
trace_rc ${returncode}
|
||||||
if [ "${returncode}" -eq 0 ]; then
|
if [ "${returncode}" -eq 0 ]; then
|
||||||
id_inserted=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"")
|
id_inserted=$(sql "SELECT id FROM tx WHERE txid=\"${txid}\"")
|
||||||
trace "[batchspend] id_inserted: ${id_inserted}"
|
trace "[batchspend] id_inserted: ${id_inserted}"
|
||||||
sql "UPDATE recipient SET tx_id=${id_inserted} WHERE address IN (${recipientswhere})"
|
sql "UPDATE recipient SET tx_id=${id_inserted} WHERE address IN (${recipientswhere})"
|
||||||
trace_rc $?
|
trace_rc $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
data="{\"status\":\"accepted\""
|
data="{\"status\":\"accepted\""
|
||||||
data="${data},\"hash\":\"${txid}\"}"
|
data="${data},\"hash\":\"${txid}\"}"
|
||||||
else
|
else
|
||||||
local message=$(echo "${response}" | jq -e ".error.message")
|
local message=$(echo "${response}" | jq -e ".error.message")
|
||||||
data="{\"message\":${message}}"
|
data="{\"message\":${message}}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
trace "[batchspend] responding=${data}"
|
trace "[batchspend] responding=${data}"
|
||||||
echo "${data}"
|
echo "${data}"
|
||||||
|
|
||||||
return ${returncode}
|
return ${returncode}
|
||||||
}
|
}
|
||||||
|
|
||||||
create_wallet() {
|
create_wallet() {
|
||||||
|
|||||||
Reference in New Issue
Block a user