check that rpc interface connects to the right bitcoin/namecoin mainnet/testnet insta...
authorForrest Voight <forrest@forre.st>
Sun, 14 Aug 2011 08:18:14 +0000 (04:18 -0400)
committerForrest Voight <forrest@forre.st>
Sun, 14 Aug 2011 08:18:14 +0000 (04:18 -0400)
p2pool/bitcoin/data.py
p2pool/main.py
p2pool/namecoin.py

index a6981e4..b103cda 100644 (file)
@@ -4,6 +4,8 @@ import hashlib
 import itertools
 import struct
 
+from twisted.internet import defer
+
 from . import base58, skiplists
 from p2pool.util import bases, math, variable
 import p2pool
@@ -798,8 +800,10 @@ class Mainnet(object):
     BITCOIN_P2P_PREFIX = 'f9beb4d9'.decode('hex')
     BITCOIN_P2P_PORT = 8333
     BITCOIN_ADDRESS_VERSION = 0
+    BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue('name_firstupdate' not in (yield bitcoind.rpc_help()) and not (yield bitcoind.rpc_getinfo())['testnet'])))
 
 class Testnet(object):
     BITCOIN_P2P_PREFIX = 'fabfb5da'.decode('hex')
     BITCOIN_P2P_PORT = 18333
     BITCOIN_ADDRESS_VERSION = 111
+    BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue('name_firstupdate' not in (yield bitcoind.rpc_help()) and (yield bitcoind.rpc_getinfo())['testnet'])))
index cc49172..40c95f5 100644 (file)
@@ -68,6 +68,10 @@ def main(args):
         url = 'http://%s:%i/' % (args.bitcoind_address, args.bitcoind_rpc_port)
         print '''Testing bitcoind RPC connection to '%s' with username '%s'...''' % (url, args.bitcoind_rpc_username)
         bitcoind = jsonrpc.Proxy(url, (args.bitcoind_rpc_username, args.bitcoind_rpc_password))
+        good = yield args.net.BITCOIN_RPC_CHECK(bitcoind)
+        if not good:
+            print "    Check failed! Make sure that you're connected to the right bitcoind with --bitcoind-rpc-port!"
+            return
         temp_work, temp_height = yield getwork(bitcoind)
         print '    ...success!'
         print '    Current block hash: %x height: %i' % (temp_work.previous_block, temp_height)
@@ -589,6 +593,7 @@ def main(args):
                 log.err()
     except:
         log.err(None, 'Fatal error:')
+    finally:
         reactor.stop()
 
 def run():
index e7ba7ab..213f584 100644 (file)
@@ -4,8 +4,10 @@ class NamecoinMainnet(object):
     BITCOIN_P2P_PREFIX = 'f9beb4fe'.decode('hex')
     BITCOIN_P2P_PORT = 8334
     BITCOIN_ADDRESS_VERSION = 52
+    BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue('name_firstupdate' in (yield bitcoind.rpc_help()) and not (yield bitcoind.rpc_getinfo())['testnet'])))
 
 class NamecoinTestnet(object):
     BITCOIN_P2P_PREFIX = 'fabfb5fe'.decode('hex')
     BITCOIN_P2P_PORT = 18334
     BITCOIN_ADDRESS_VERSION = 111
+    BITCOIN_RPC_CHECK = staticmethod(defer.inlineCallbacks(lambda bitcoind: defer.returnValue('name_firstupdate' in (yield bitcoind.rpc_help()) and (yield bitcoind.rpc_getinfo())['testnet'])))