Merge commit 'refs/merge-requests/3' of git://gitorious.org/electrum/server into...
authorAmir Taaki <genjix@riseup.net>
Fri, 17 Aug 2012 19:53:45 +0000 (20:53 +0100)
committerAmir Taaki <genjix@riseup.net>
Fri, 17 Aug 2012 19:53:45 +0000 (20:53 +0100)
backends/abe/__init__.py
backends/irc/__init__.py
server.py

index fac40b4..745493c 100644 (file)
@@ -10,7 +10,6 @@ from Queue import Queue
 import time, threading
 
 
-
 class AbeStore(Datastore_class):
 
     def __init__(self, config):
@@ -24,8 +23,22 @@ class AbeStore(Datastore_class):
         elif args.dbtype == 'psycopg2':
             args.connect_args = { 'database' : config.get('database','database') }
 
+        coin = config.get('server', 'coin')
+        self.addrtype = 0
+        if coin == 'litecoin':
+            print 'Litecoin settings:'
+            datadir = config.get('server','datadir')
+            print '  datadir = ' + datadir
+            args.datadir = [{"dirname":datadir,"chain":"Litecoin","code3":"LTC","address_version":"\u0030"}]
+            print '  addrtype = 48'
+            self.addrtype = 48
+
         Datastore_class.__init__(self,args)
 
+        # Use 1 (Bitcoin) if chain_id is not sent
+        self.chain_id = self.datadirs[0]["chain_id"] or 1
+        print 'Coin chain_id = %d' % self.chain_id
+
         self.sql_limit = int( config.get('database','limit') )
 
         self.tx_cache = {}
@@ -68,7 +81,7 @@ class AbeStore(Datastore_class):
                 #print "WARNING: missing tx_in for tx", txid
                 continue
 
-            address = hash_to_address(chr(0), _hash)
+            address = hash_to_address(chr(self.addrtype), _hash)
             if self.tx_cache.has_key(address):
                 print "cache: invalidating", address
                 self.tx_cache.pop(address)
@@ -81,7 +94,7 @@ class AbeStore(Datastore_class):
                 #print "WARNING: missing tx_out for tx", txid
                 continue
 
-            address = hash_to_address(chr(0), _hash)
+            address = hash_to_address(chr(self.addrtype), _hash)
             if self.tx_cache.has_key(address):
                 print "cache: invalidating", address
                 self.tx_cache.pop(address)
@@ -160,8 +173,9 @@ class AbeStore(Datastore_class):
               JOIN txout prevout ON (txin.txout_id = prevout.txout_id)
               JOIN pubkey ON (pubkey.pubkey_id = prevout.pubkey_id)
              WHERE pubkey.pubkey_hash = ?
+               AND cc.chain_id = ?
                AND cc.in_longest = 1
-             LIMIT ? """, (dbhash,self.sql_limit))
+             LIMIT ? """, (dbhash, self.chain_id, self.sql_limit))
 
         if len(out)==self.sql_limit: 
             raise BaseException('limit reached')
@@ -203,8 +217,9 @@ class AbeStore(Datastore_class):
               JOIN txout ON (txout.tx_id = tx.tx_id)
               JOIN pubkey ON (pubkey.pubkey_id = txout.pubkey_id)
              WHERE pubkey.pubkey_hash = ?
+               AND cc.chain_id = ?
                AND cc.in_longest = 1
-               LIMIT ? """, (dbhash,self.sql_limit))
+               LIMIT ? """, (dbhash, self.chain_id, self.sql_limit))
 
         if len(out)==self.sql_limit: 
             raise BaseException('limit reached')
@@ -314,7 +329,7 @@ class AbeStore(Datastore_class):
                 if not _hash:
                     #print "WARNING: missing tx_in for tx", tx_id, addr
                     continue
-                address = hash_to_address(chr(0), _hash)
+                address = hash_to_address(chr(self.addrtype), _hash)
                 txinputs.append(address)
             txpoint['inputs'] = txinputs
             txoutputs = []
@@ -324,7 +339,7 @@ class AbeStore(Datastore_class):
                 if not _hash:
                     #print "WARNING: missing tx_out for tx", tx_id, addr
                     continue
-                address = hash_to_address(chr(0), _hash)
+                address = hash_to_address(chr(self.addrtype), _hash)
                 txoutputs.append(address)
             txpoint['outputs'] = txoutputs
 
@@ -410,7 +425,7 @@ class AbeStore(Datastore_class):
         with store.dblock:
             store.catch_up()
             store.memorypool_update()
-            block_number = store.get_block_number(1)
+            block_number = store.get_block_number(store.chain_id)
             return block_number
 
 
@@ -512,7 +527,7 @@ class BlockchainProcessor(Processor):
         if self.block_number != block_number:
             self.block_number = block_number
             print "block number:", self.block_number
-            self.push_response({ 'method':'blockchain.numblocks.subscribe', 'params':[self.block_number] })
+            self.push_response({ 'id': None, 'method':'blockchain.numblocks.subscribe', 'params':[self.block_number] })
 
         while True:
             try:
@@ -521,7 +536,7 @@ class BlockchainProcessor(Processor):
                 break
             if addr in self.watched_addresses:
                 status = self.store.get_status( addr )
-                self.push_response({ 'method':'blockchain.address.subscribe', 'params':[addr, status] })
+                self.push_response({ 'id': None, 'method':'blockchain.address.subscribe', 'params':[addr, status] })
 
         threading.Timer(10, self.run_store_iteration).start()
 
index 8b35e2c..0372002 100644 (file)
@@ -19,6 +19,10 @@ class IrcThread(threading.Thread):
         self.host = config.get('server','host')
         self.nick = config.get('server', 'irc_nick')
         if not self.nick: self.nick = random_string(10)
+        self.prepend = 'E_'
+        if config.get('server', 'coin') == 'litecoin':
+            self.prepend = 'EL_'
+        self.nick = self.prepend + self.nick
 
     def get_peers(self):
         return self.peers.values()
@@ -41,7 +45,7 @@ class IrcThread(threading.Thread):
                 s = socket.socket()
                 s.connect(('irc.freenode.net', 6667))
                 s.send('USER electrum 0 * :' + self.host + ' ' + ircname + '\n')
-                s.send('NICK E_' + self.nick + '\n')
+                s.send('NICK ' + self.nick + '\n')
                 s.send('JOIN #electrum\n')
                 sf = s.makefile('r', 0)
                 t = 0
@@ -55,7 +59,7 @@ class IrcThread(threading.Thread):
                     elif '353' in line: # answer to /names
                         k = line.index('353')
                         for item in line[k+1:]:
-                            if item[0:2] == 'E_':
+                            if item.startswith(self.prepend):
                                 s.send('WHO %s\n'%item)
                     elif '352' in line: # answer to /who
                         # warning: this is a horrible hack which apparently works
index d2ef9d6..bfbeecd 100755 (executable)
--- a/server.py
+++ b/server.py
@@ -43,6 +43,8 @@ def create_config():
     config.set('server', 'password', '')
     config.set('server', 'irc', 'yes')
     config.set('server', 'irc_nick', '')
+    config.set('server', 'coin', '')
+    config.set('server', 'datadir', '')
     config.add_section('database')
     config.set('database', 'type', 'psycopg2')
     config.set('database', 'database', 'abe')