aboutsummaryrefslogtreecommitdiff
path: root/utils/python-rpc/console.py
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-04-01 17:33:23 +0200
committerRiccardo Spagni <ric@spagni.net>2019-04-01 17:33:24 +0200
commite601028649466869d3ff4991441873ba753ca6a8 (patch)
tree8fbdd9771ee071eba5776b0b0a9a71a3d1fa524a /utils/python-rpc/console.py
parentMerge pull request #5329 (diff)
parentpython-rpc: add getblockheadersrange daemon RPC (diff)
downloadmonero-e601028649466869d3ff4991441873ba753ca6a8.tar.xz
Merge pull request #5331
32973434 python-rpc: add getblockheadersrange daemon RPC (moneromooo-monero) c7bfdc35 python-rpc: add console.py (moneromooo-monero) 22b644f4 functional_tests: move RPC API to utils, it is not test specific (moneromooo-monero) 30c865f0 functional_tests: add balance tests (moneromooo-monero) fdfa832f functional_tests: add missing parameters to get_balance (moneromooo-monero) cf6d7759 functional_tests: add proofs tests (tx key, in/out tx, reserve) (moneromooo-monero) a3144bd7 functional_tests: add more transfer tests (moneromooo-monero) 5d580bfa functional_tests: add get_bulk_transfer tests (moneromooo-monero) 0becbd16 functional_tests: add message signing/verification tests (moneromooo-monero) a5dbf7f5 functional_tests: add multisig and cold signing tests (moneromooo-monero) b2fc5719 functional_tests: support several daemons/wallets (moneromooo-monero) 9e979ffa functional_tests: add txpool RPC tests (moneromooo-monero) 3e93c157 functional_tests: add integrated address tests (moneromooo-monero) b384309e functional_tests: add basic transfer tests (moneromooo-monero) ef7681b6 functional_tests: plug RPC tests into the cmake machinery (moneromooo-monero) 18a2ed45 functional_tests: add basic mining tests (moneromooo-monero) 98e280fc functional_tests: add wallet address/subaddress RPC tests (moneromooo-monero) 8dcd4d3d functional_tests: improve RPC blockchain tests (moneromooo-monero)
Diffstat (limited to 'utils/python-rpc/console.py')
-rwxr-xr-xutils/python-rpc/console.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/utils/python-rpc/console.py b/utils/python-rpc/console.py
new file mode 100755
index 000000000..ab0d9f27f
--- /dev/null
+++ b/utils/python-rpc/console.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+import sys
+import subprocess
+import socket
+from framework import rpc
+from framework import wallet
+from framework import daemon
+
+USAGE = 'usage: python -i console.py <port>'
+try:
+ port = int(sys.argv[1])
+except:
+ print(USAGE)
+ sys.exit(1)
+
+# check for open port
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s.settimeout(1)
+if s.connect_ex(('127.0.0.1', port)) != 0:
+ print('No wallet or daemon RPC on port ' + str(port))
+ sys.exit(1)
+s.close()
+
+# both wallet and daemon have a get_version JSON RPC
+rpc = rpc.JSONRPC('{protocol}://{host}:{port}'.format(protocol='http', host='127.0.0.1', port=port))
+get_version = {
+ 'method': 'get_version',
+ 'jsonrpc': '2.0',
+ 'id': '0'
+}
+try:
+ res = rpc.send_json_rpc_request(get_version)
+except Exception, e:
+ print('Failed to call version RPC: ' + str(e))
+ sys.exit(1)
+
+if 'version' not in res:
+ print('Server is not a monero process')
+ sys.exit(1)
+
+if 'status' in res:
+ rpc = daemon.Daemon(port=port)
+else:
+ rpc = wallet.Wallet(port=port)
+
+print('Connected to %s RPC on port %u' % ('daemon' if 'status' in res else 'wallet', port))
+print('The \'rpc\' object may now be used to use the API')