Skip to content

Commit

Permalink
add helper script to connect to a remote node
Browse files Browse the repository at this point in the history
  • Loading branch information
openoms committed Dec 15, 2020
1 parent 440f289 commit e3da3ab
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 7 deletions.
45 changes: 45 additions & 0 deletions scripts/menu.bitcoinrpc.sh
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
2 changes: 1 addition & 1 deletion scripts/menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ OPTIONS+=(\
OFFERS "Watch the Order Book locally" \
"" ""
CONFIG "Edit the joinmarket.cfg" \
TOOLS "Use other tools and extras"
TOOLS "Extra helper functions and Boltzmann"
UPDATE "Update JoininBox or JoinMarket" \
"" ""
X "Exit to the Command Line" \
Expand Down
13 changes: 10 additions & 3 deletions scripts/menu.tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function getTXID {
}

# BASIC MENU INFO
HEIGHT=9
WIDTH=48
HEIGHT=8
WIDTH=49
CHOICE_HEIGHT=20
TITLE="Tools"
MENU=""
Expand All @@ -34,7 +34,8 @@ BACKTITLE="JoininBox GUI"

# Basic Options
OPTIONS+=(\
BOLTZMANN "Analyze a transaction"
CONNECT "Connect to a remote bitcoin node"\
BOLTZMANN "Analyze a transaction"\
)

CHOICE=$(dialog --clear \
Expand All @@ -46,6 +47,12 @@ CHOICE=$(dialog --clear \
2>&1 >/dev/tty)

case $CHOICE in
CONNECT)
/home/joinmarket/menu.bitcoinrpc.sh
echo ""
echo "Press ENTER to return to the menu..."
read key
;;
BOLTZMANN)
installBoltzmann
getTXID
Expand Down
44 changes: 44 additions & 0 deletions scripts/set.bitcoinrpc.py
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()
5 changes: 2 additions & 3 deletions scripts/start.boltzmann.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import configparser
import os
import signal
import sys
import getopt

def main(argv):

description = "\nBoltzmann - \n\
description = "\nBoltzmann - https://code.samourai.io/oxt/boltzmann/\n\
A python script computing the entropy of Bitcoin transactions and the linkability of their inputs and outputs.\n\
For a description of the metrics:\n\
Bitcoin Transactions & Privacy (part 1) : https://gist.github.com/LaurentMT/e758767ca4038ac40aaf\n\
Bitcoin Transactions & Privacy (part 2) : https://gist.github.com/LaurentMT/d361bca6dc52868573a2\n\
Bitcoin Transactions & Privacy (part 3) : https://gist.github.com/LaurentMT/e8644d5bc903f02613c6\n"

os.system('clear')
print(description)

txids = ''
Expand Down

0 comments on commit e3da3ab

Please sign in to comment.