-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper script to connect to a remote node
- Loading branch information
Showing
5 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
clear | ||
|
||
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#prepare-a-remote-node-to-accept-the-joinmarket-connection" | ||
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 | ||
|
||
echo "# Checking the remote RPC connection with curl..." | ||
echo | ||
|
||
function checkRPC { | ||
tor="" | ||
if [ $(echo $rpc_addr | grep -c .onion) -gt 0 ]; then | ||
tor="torify" | ||
echo "# Connecting over Tor..." | ||
echo | ||
fi | ||
$tor curl --data-binary \ | ||
'{"jsonrpc": "1.0", "id":"# Connected to bitcoinRPC successfully", "method": "getblockcount", "params": [] }' \ | ||
http://$rpc_user:$rpc_pass@$rpc_addr:$rpc_port | ||
} | ||
|
||
if [ $(checkRPC 2>/dev/null | grep -c "bitcoinRPC") -gt 0 ]; then | ||
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 | ||
python /home/joinmarket/set.bitcoinrpc.py --rpc_user=$rpc_user --rpc_pass=$rpc_pass --rpc_host=$rpc_host --rpc_port=$rpc_port | ||
else | ||
echo "# Could not connect to bitcoinRPC with the error:" | ||
echo | ||
checkRPC | ||
echo | ||
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#prepare-a-remote-node-to-accept-the-joinmarket-connection" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import configparser | ||
import os | ||
import sys | ||
import getopt | ||
|
||
def main(): | ||
|
||
description = "# Setting bitcoinRPC in the joinmarket.cfg" | ||
print(description) | ||
|
||
try: | ||
opts, args = getopt.getopt(sys.argv[1:], "rphc", ["rpc_user=","rpc_pass=","rpc_host=","rpc_port="]) | ||
except getopt.GetoptError: | ||
print('# Usage:') | ||
print('python /home/joinmarket/set.bitcoinrpc.py --rpc_user=$rpc_user --rpc_pass=$rpc_pass --rpc_host=$rpc_host --rpc_port=$rpc_port') | ||
sys.exit(2) | ||
|
||
for opt, arg in opts: | ||
if opt in ('-r','--rpc_user'): | ||
rpc_user = arg | ||
elif opt in ('-p','--rpc_pass'): | ||
rpc_password = arg | ||
elif opt in ('-h','--rpc_host'): | ||
rpc_host = arg | ||
elif opt in ('-c','--rpc_port'): | ||
rpc_port = arg | ||
else: | ||
assert False, "unhandled option" | ||
|
||
config = configparser.ConfigParser(strict=False, comment_prefixes='/', allow_no_value=True) | ||
config.read('/home/joinmarket/.joinmarket/joinmarket.cfg') | ||
|
||
config.set('BLOCKCHAIN','rpc_user',rpc_user) | ||
config.set('BLOCKCHAIN','rpc_password',rpc_password) | ||
config.set('BLOCKCHAIN','rpc_host',rpc_host) | ||
config.set('BLOCKCHAIN','rpc_port',rpc_port) | ||
|
||
with open('/home/joinmarket/.joinmarket/joinmarket.cfg', 'w') as configfile: | ||
config.write(configfile) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters