Merge pull request #23 from blockchain/master
authorThomasV <thomasv1@gmx.de>
Tue, 12 Feb 2013 18:57:58 +0000 (10:57 -0800)
committerThomasV <thomasv1@gmx.de>
Tue, 12 Feb 2013 18:57:58 +0000 (10:57 -0800)
Added Common Headers to Access-Control-Allow-Headers

backends/bitcoind/deserialize.py
utils/__init__.py

index a1e873c..75cbc3e 100644 (file)
@@ -225,8 +225,7 @@ def parse_TxOut(vds, i):
     d = {}
     d['value'] = vds.read_int64()
     scriptPubKey = vds.read_bytes(vds.read_compact_size())
-    d['address'] = extract_public_key(scriptPubKey)
-    #d['script'] = decode_script(scriptPubKey)
+    d['address'] = get_address_from_output_script(scriptPubKey)
     d['raw_output_script'] = scriptPubKey.encode('hex')
     d['index'] = i
     return d
@@ -336,15 +335,10 @@ def match_decoded(decoded, to_match):
     return True
 
 
-def extract_public_key(bytes):
-    decoded = list(script_GetOp(bytes))
 
-    # non-generated TxIn transactions push a signature
-    # (seventy-something bytes) and then their public key
-    # (65 bytes) onto the stack:
-    match = [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4]
-    if match_decoded(decoded, match):
-        return public_key_to_bc_address(decoded[1][1])
+
+def get_address_from_output_script(bytes):
+    decoded = [ x for x in script_GetOp(bytes) ]
 
     # The Genesis Block, self-payments, and pay-by-IP-address payments look like:
     # 65 BYTES:... CHECKSIG
@@ -369,5 +363,10 @@ def extract_public_key(bytes):
     if match_decoded(decoded, match):
         return hash_160_to_bc_address(decoded[2][1])
 
-    #raise BaseException("address not found in script") see ce35795fb64c268a52324b884793b3165233b1e6d678ccaadf760628ec34d76b
+    # p2sh
+    match = [ opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUAL ]
+    if match_decoded(decoded, match):
+        addr = hash_160_to_bc_address(decoded[1][1],5)
+        return addr
+
     return "None"
index a01d0e1..f6e64f2 100644 (file)
@@ -90,7 +90,6 @@ def header_from_string(s):
 
 ############ functions from pywallet #####################
 
-addrtype = 0
 
 
 def hash_160(public_key):
@@ -108,7 +107,7 @@ def public_key_to_bc_address(public_key):
     return hash_160_to_bc_address(hash_160(public_key))
 
 
-def hash_160_to_bc_address(h160):
+def hash_160_to_bc_address(h160, addrtype = 0):
     if h160 == 'None':
         return 'None'
     vh160 = chr(addrtype) + h160
@@ -194,21 +193,6 @@ def DecodeBase58Check(psz):
         return key
 
 
-def PrivKeyToSecret(privkey):
-    return privkey[9:9+32]
-
-
-def SecretToASecret(secret):
-    vchIn = chr(addrtype+128) + secret
-    return EncodeBase58Check(vchIn)
-
-
-def ASecretToSecret(key):
-    vch = DecodeBase58Check(key)
-    if vch and vch[0] == chr(addrtype+128):
-        return vch[1:]
-    else:
-        return False
 
 
 ########### end pywallet functions #######################