joininbox/scripts/menu.bitcoinrpc.sh

77 lines
2.3 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
source /home/joinmarket/_functions.sh
# check connectedRemoteNode var in joinin.conf
if ! grep -Eq "^connectedRemoteNode=" $joininConfPath; then
echo "connectedRemoteNode=off" >> $joininConfPath
fi
clear
generateJMconfig
2021-01-05 02:00:23 +00:00
function displayHelp {
echo "# See how to prepare a remote node to accept the JoinMarket connection:"
echo "# https://github.com/openoms/joininbox/blob/master/prepare_remote_node.md"
2021-01-05 02:00:23 +00:00
}
2021-01-03 23:23:16 +00:00
function inputRPC {
echo
echo "Input the RPC username of the remote bitcoin node:"
read rpc_user
echo "Input the RPC password of the remote node:"
read rpc_pass
echo "Type or paste the LAN IP or .onion address of the remote node:"
read rpc_host
echo "Input the RPC port (8332 by default):"
read rpc_port
}
function checkRPC {
tor=""
if [ $(echo $rpc_host | grep -c .onion) -gt 0 ]; then
2021-10-03 00:37:34 +01:00
tor="torsocks"
echo "# Connecting over Tor..."
echo
fi
$tor curl -sS --data-binary \
'{"jsonrpc": "1.0", "id":"# Connected to bitcoinRPC successfully", "method": "getblockcount", "params": [] }' \
http://$rpc_user:$rpc_pass@$rpc_host:$rpc_port
}
2021-01-05 02:00:23 +00:00
displayHelp
inputRPC
2021-01-03 19:19:16 +00:00
echo "# Checking the remote RPC connection with curl..."
echo
trap 'rm -f "$connectionOutput"' EXIT
connectionOutput=$(mktemp -p /dev/shm/)
2021-01-05 02:00:23 +00:00
connectionSuccess=$(checkRPC 2>$connectionOutput | grep -c "bitcoinRPC")
2021-01-03 23:23:16 +00:00
while [ $connectionSuccess -eq 0 ]; do
2021-01-03 19:19:16 +00:00
echo
echo "# Could not connect to bitcoinRPC with the error:"
2021-01-05 02:00:23 +00:00
cat $connectionOutput
echo
2021-01-05 02:00:23 +00:00
displayHelp
echo
echo "Press ENTER to retry or CTLR+C to abort"
read key
2021-01-04 01:48:42 +00:00
echo "---------------------------------------"
2021-01-03 23:23:16 +00:00
inputRPC
2021-01-05 02:00:23 +00:00
connectionSuccess=$(checkRPC 2>$connectionOutput | grep -c "bitcoinRPC")
2021-01-03 19:39:57 +00:00
done
echo
echo "# Connected to bitcoinRPC successfully"
echo
echo "# Blockheight on the connected node: $(checkRPC 2>/dev/null|grep "result"|cut -d":" -f2|cut -d"," -f1)"
echo
rpc_wallet=joininbox
python /home/joinmarket/set.bitcoinrpc.py --network=mainnet --rpc_user=$rpc_user\
--rpc_pass=$rpc_pass --rpc_host=$rpc_host --rpc_port=$rpc_port --rpc_wallet=$rpc_wallet
2021-01-03 19:39:57 +00:00
echo
echo "# The wallet used in the connected bitcoind is called: $rpc_wallet"
echo
2021-01-03 19:39:57 +00:00
echo "# The bitcoinRPC connection settings are set in the joinmarket.cfg"
sed -i "s#^connectedRemoteNode=.*#connectedRemoteNode=on#g" $joininConfPath
echo
checkRPCwallet $rpc_wallet