added block explorer urls to block hash displays and changed names of irc bots to...
authorForrest Voight <forrest@forre.st>
Sun, 12 Feb 2012 23:15:10 +0000 (18:15 -0500)
committerForrest Voight <forrest@forre.st>
Sun, 12 Feb 2012 23:19:39 +0000 (18:19 -0500)
p2pool/bitcoin/networks.py
p2pool/main.py
p2pool/networks.py

index 1b123da..7775c31 100644 (file)
@@ -20,6 +20,7 @@ nets = dict(
         BLOCK_PERIOD=600, # s
         SYMBOL='BTC',
         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Bitcoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Bitcoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.bitcoin'), 'bitcoin.conf'),
+        BLOCK_EXPLORER_URL_PREFIX='http://blockexplorer.com/block/',
     ),
     bitcoin_testnet=math.Object(
         P2P_PREFIX='fabfb5da'.decode('hex'),
@@ -34,6 +35,7 @@ nets = dict(
         BLOCK_PERIOD=600, # s
         SYMBOL='tBTC',
         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Bitcoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Bitcoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.bitcoin'), 'bitcoin.conf'),
+        BLOCK_EXPLORER_URL_PREFIX='http://blockexplorer.com/testnet/block/',
     ),
     
     nameecoin=math.Object(
@@ -49,6 +51,7 @@ nets = dict(
         BLOCK_PERIOD=600, # s
         SYMBOL='NMC',
         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Namecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Namecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.namecoin'), 'bitcoin.conf'),
+        BLOCK_EXPLORER_URL_PREFIX='http://explorer.dot-bit.org/b/',
     ),
     namecoin_testnet=math.Object(
         P2P_PREFIX='fabfb5fe'.decode('hex'),
@@ -63,6 +66,7 @@ nets = dict(
         BLOCK_PERIOD=600, # s
         SYMBOL='tNMC',
         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Namecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Namecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.namecoin'), 'bitcoin.conf'),
+        BLOCK_EXPLORER_URL_PREFIX='http://testnet.explorer.dot-bit.org/b/',
     ),
     
     litecoin=math.Object(
@@ -78,6 +82,7 @@ nets = dict(
         BLOCK_PERIOD=150, # s
         SYMBOL='LTC',
         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Litecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Litecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.litecoin'), 'litecoin.conf'),
+        BLOCK_EXPLORER_URL_PREFIX='http://litecoin.kicks-ass.org/block/',
     ),
     litecoin_testnet=math.Object(
         P2P_PREFIX='fcc1b7dc'.decode('hex'),
@@ -92,5 +97,8 @@ nets = dict(
         BLOCK_PERIOD=150, # s
         SYMBOL='tLTC',
         CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Litecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Litecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.litecoin'), 'litecoin.conf'),
+        BLOCK_EXPLORER_URL_PREFIX='http://nonexistent-litecoin-testnet-explorer/block/',
     ),
 )
+for net_name, net in nets.iteritems():
+    net.NAME = net_name
index c271759..8702afd 100644 (file)
@@ -312,9 +312,9 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
                 else:
                     print >>sys.stderr, 'No bitcoind connection when block submittal attempted! Erp!'
                 print
-                print 'GOT BLOCK FROM PEER! Passing to bitcoind! %s bitcoin: %x' % (p2pool_data.format_hash(share.hash), share.header_hash)
+                print 'GOT BLOCK FROM PEER! Passing to bitcoind! %s bitcoin: %s%064x' % (p2pool_data.format_hash(share.hash), net.PARENT.BLOCK_EXPLORER_URL_PREFIX, share.header_hash)
                 print
-                recent_blocks.append({ 'ts': share.timestamp, 'hash': '%x' % (share.header_hash) })
+                recent_blocks.append(dict(ts=share.timestamp, hash='%064x' % (share.header_hash,)))
         
         print 'Joining p2pool network using port %i...' % (args.p2pool_port,)
         
@@ -561,15 +561,15 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
                             @deferral.retry('Error submitting primary block: (will retry)', 10, 10)
                             def submit_block():
                                 if factory.conn.value is None:
-                                    print >>sys.stderr, 'No bitcoind connection when block submittal attempted! Hash: %x' % (header_hash,)
+                                    print >>sys.stderr, 'No bitcoind connection when block submittal attempted! %s%32x' % (net.PARENT.BLOCK_EXPLORER_URL_PREFIX, header_hash)
                                     raise deferral.RetrySilentlyException()
                                 factory.conn.value.send_block(block=dict(header=header, txs=transactions))
                             submit_block()
                             if pow_hash <= header['bits'].target:
                                 print
-                                print 'GOT BLOCK FROM MINER! Passing to bitcoind! bitcoin: %x' % (header_hash,)
+                                print 'GOT BLOCK FROM MINER! Passing to bitcoind! %s%064x' % (net.PARENT.BLOCK_EXPLORER_URL_PREFIX, header_hash)
                                 print
-                                recent_blocks.append(dict(ts=time.time(), hash='%x' % (header_hash,)))
+                                recent_blocks.append(dict(ts=time.time(), hash='%064x' % (header_hash,)))
                     except:
                         log.err(None, 'Error while processing potential block:')
                     
@@ -904,7 +904,7 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
         if args.irc_announce:
             from twisted.words.protocols import irc
             class IRCClient(irc.IRCClient):
-                nickname = 'p2pool'
+                nickname = 'p2pool_%s%i' % (net.NAME, random.randrange(100))
                 def lineReceived(self, line):
                     print repr(line)
                     irc.IRCClient.lineReceived(self, line)
@@ -917,7 +917,7 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
                 def _new_share(self, share):
                     if share.pow_hash <= share.header['bits'].target and share.header_hash not in self.announced_hashes and abs(share.timestamp - time.time()) < 10*60:
                         self.announced_hashes.add(share.header_hash)
-                        self.say('#p2pool', '\x02BLOCK FOUND by %s! http://blockexplorer.com/block/%064x' % (bitcoin_data.script2_to_address(share.share_data['new_script'], net.PARENT), share.header_hash))
+                        self.say('#p2pool', '\x02BLOCK FOUND by %s! %s%064x' % (bitcoin_data.script2_to_address(share.share_data['new_script'], net.PARENT), net.PARENT.BLOCK_EXPLORER_URL_PREFIX, share.header_hash))
                 def connectionLost(self, reason):
                     tracker.verified.added.unwatch(self.watch_id)
                     print 'IRC connection lost:', reason.getErrorMessage()
index 96b6fbd..71a3b6a 100644 (file)
@@ -70,3 +70,5 @@ nets = dict(
         BOOTSTRAP_ADDRS='72.14.191.28'.split(' '),
     ),
 )
+for net_name, net in nets.iteritems():
+    net.NAME = net_name