Simplify block parsing
authorCryptoManiac <balthazar@yandex.ru>
Tue, 22 Jul 2014 19:24:20 +0000 (23:24 +0400)
committerCryptoManiac <balthazar@yandex.ru>
Tue, 22 Jul 2014 19:24:20 +0000 (23:24 +0400)
backends/bitcoind/blockchain_processor.py
backends/bitcoind/deserialize.py

index fb68f25..3d93fd8 100644 (file)
@@ -235,7 +235,7 @@ class BlockchainProcessor(Processor):
         vds = deserialize.BCDataStream()
         vds.write(raw_tx.decode('hex'))
         try:
-            return deserialize.parse_Transaction(vds, is_coinbase=False, is_coinstake=False)
+            return deserialize.parse_Transaction(vds, is_coinbase=False)
         except:
             print_log("ERROR: cannot parse", txid)
             return None
@@ -356,23 +356,18 @@ class BlockchainProcessor(Processor):
 
 
     def deserialize_block(self, block):
-        is_stake_block = False
         txlist = block.get('tx')
-        if "proof-of-stake" in block.get('flags'): # scan block flags list for
-            is_stake_block = True                  #    "proof-of-stake" substring
 
         tx_hashes = []  # ordered txids
         txdict = {}     # deserialized tx
 
-        for i in xrange(len(txlist)):
-            if is_stake_block and i == 0: # skip coinbase for
-                continue                  #     stake block
-            tx_hash = hash_encode(Hash(txlist[i].decode('hex')))
+        for i, raw_tx in enumerate(txlist):
+            tx_hash = hash_encode(Hash(raw_tx.decode('hex')))
             vds = deserialize.BCDataStream()
-            vds.write(txlist[i].decode('hex'))
+            vds.write(raw_tx.decode('hex'))
             try:
-                tx = deserialize.parse_Transaction(vds, i == 0, is_stake_block and i == 1) # first transaction is always coinbase
-            except:                                                                        # second transaction is coinstake if we have a stake block
+                tx = deserialize.parse_Transaction(vds, i == 0) # first transaction is always coinbase
+            except:
                 print_log("ERROR: cannot parse", tx_hash)
                 continue
             tx_hashes.append(tx_hash)
index 7effb18..816db77 100644 (file)
@@ -239,7 +239,7 @@ def parse_TxOut(vds, i):
     return d
 
 
-def parse_Transaction(vds, is_coinbase, is_coinstake):
+def parse_Transaction(vds, is_coinbase):
     d = {}
     start = vds.read_cursor
     d['version'] = vds.read_int32()
@@ -255,12 +255,10 @@ def parse_Transaction(vds, is_coinbase, is_coinstake):
     for i in xrange(n_vout):
             o = parse_TxOut(vds, i)
 
-            #if o['address'] == "None" and o['value']==0:
-            #        print("skipping strange tx output with zero value")
-            #        continue
-            # if o['address'] != "None":
-            if not is_coinstake or i > 0:  # first coinstake output
-                d['outputs'].append(o)     #    transaction doesn't make any sense
+            if o['address'] == None or o['value']==0:
+                    #print("skipping strange tx output with zero value")
+                    continue
+            d['outputs'].append(o)
 
     d['lockTime'] = vds.read_uint32()
     return d