def test_bc_address_to_hash_160(self):
     self.assertEqual(bc_address_to_hash_160(None), None)
     self.assertEqual(bc_address_to_hash_160(''), None)
     self.assertEqual(
         bc_address_to_hash_160('13SrAVFPVW1txSj34B8Bd6hnDbyPsVGa92'), None)
     self.assertEqual(
         bc_address_to_hash_160(
             '13SrAVFPVW1txSj34B8Bd6hnDbyPsVGa92').encode('hex'),
         '1ad3b0b711f211655a01142fbb8fecabe8e30b93')
 def address_to_key(addr):
     return bc_address_to_hash_160(addr)
 def address_to_key(addr):
     return bc_address_to_hash_160(addr)
 def test_bc_address_to_hash_160(self):
     self.assertEqual(bc_address_to_hash_160(None), None)
     self.assertEqual(bc_address_to_hash_160(''), None)
     self.assertEqual(bc_address_to_hash_160('iXSa9ajrBhKcGZHUDKoJ7p7qsJGEMgXBh8'), None)
     self.assertEqual(bc_address_to_hash_160('iXSa9ajrBhKcGZHUDKoJ7p7qsJGEMgXBh8').encode('hex'),'32c4f4f7bb7ae8e5b1476cd04b5ce7c5ad52286d')
Exemple #5
0
    def raw_tx(self, inputs, outputs, for_sig=None):
        s = int_to_hex(1, 4)  # version
        s += var_int(len(inputs))  # number of inputs
        for i in range(len(inputs)):
            _, _, p_hash, p_index, p_script, pubkeysig = inputs[i]
            s += p_hash.decode('hex')[::-1].encode('hex')  # prev hash
            s += int_to_hex(p_index, 4)  # prev index

            if for_sig is None:
                if len(pubkeysig) == 1:
                    pubkey, sig = pubkeysig[0]
                    sig = sig + chr(1)  # hashtype
                    script = int_to_hex(len(sig))
                    script += sig.encode('hex')
                    script += int_to_hex(len(pubkey))
                    script += pubkey.encode('hex')
                else:
                    pubkey0, sig0 = pubkeysig[0]
                    pubkey1, sig1 = pubkeysig[1]
                    sig0 = sig0 + chr(1)
                    sig1 = sig1 + chr(1)
                    inner_script = self.multisig_script([pubkey0, pubkey1])
                    script = '00'  # op_0
                    script += int_to_hex(len(sig0))
                    script += sig0.encode('hex')
                    script += int_to_hex(len(sig1))
                    script += sig1.encode('hex')
                    script += var_int(len(inner_script) / 2)
                    script += inner_script

            elif for_sig == i:
                if len(pubkeysig) > 1:
                    script = self.multisig_script(pubkeysig)  # p2sh uses the
                    # inner script
                else:
                    script = p_script  # scriptsig
            else:
                script = ''
            s += var_int(len(self.tx_filter(script)) / 2)  # script length
            s += script
            s += "ffffffff"  # sequence

        s += var_int(len(outputs))  # number of outputs
        for output in outputs:
            addr, amount = output
            s += int_to_hex(amount, 8)  # amount
            addrtype, hash_160 = bc_address_to_hash_160(addr)
            if addrtype == 0:
                script = '76a9'  # op_dup, op_hash_160
                script += '14'  # push 0x14 bytes
                script += hash_160.encode('hex')
                script += '88ac'  # op_equalverify, op_checksig
            elif addrtype == 5:
                script = 'a9'  # op_hash_160
                script += '14'  # push 0x14 bytes
                script += hash_160.encode('hex')
                script += '87'  # op_equal
            else:
                raise

            s += var_int(len(self.tx_filter(script)) / 2)  # script length
            s += script  # script
        s += int_to_hex(0, 4)  # lock time
        if for_sig is not None:
            s += int_to_hex(1, 4)  # hash type
        return self.tx_filter(s)
 def test_bc_address_to_hash_160(self):
     self.assertEqual(bc_address_to_hash_160(None), None)
     self.assertEqual(bc_address_to_hash_160(''), None)
     self.assertEqual(bc_address_to_hash_160('13SrAVFPVW1txSj34B8Bd6hnDbyPsVGa921337'), None)
     self.assertEqual(bc_address_to_hash_160('13SrAVFPVW1txSj34B8Bd6hnDbyPsVGa92').encode('hex'),
                                             '1ad3b0b711f211655a01142fbb8fecabe8e30b93')
 def test_bc_address_to_hash_160(self):
     self.assertEqual(bc_address_to_hash_160(None), None)
     self.assertEqual(bc_address_to_hash_160(''), None)
     self.assertEqual(bc_address_to_hash_160('Sg677dvc44YEV8u5nTo1STR7P51ikfBDzm1337'), None)
     self.assertEqual(bc_address_to_hash_160('Sg677dvc44YEV8u5nTo1STR7P51ikfBDzm').encode('hex'),'ce2a79d5c9d8ba7096d218fb82aa16f01e6dff48')
Exemple #8
0
    def raw_tx(self, inputs, outputs, for_sig=None):
        s = int_to_hex(1, 4)                                 # version
        s += var_int(len(inputs))                            # number of inputs
        for i in range(len(inputs)):
            _, _, p_hash, p_index, p_script, pubkeysig = inputs[i]
            s += p_hash.decode('hex')[::-1].encode('hex')    # prev hash
            s += int_to_hex(p_index, 4)                    # prev index

            if for_sig is None:
                if len(pubkeysig) == 1:
                    pubkey, sig = pubkeysig[0]
                    sig = sig + chr(1)                               # hashtype
                    script = int_to_hex(len(sig))
                    script += sig.encode('hex')
                    script += int_to_hex(len(pubkey))
                    script += pubkey.encode('hex')
                else:
                    pubkey0, sig0 = pubkeysig[0]
                    pubkey1, sig1 = pubkeysig[1]
                    sig0 = sig0 + chr(1)
                    sig1 = sig1 + chr(1)
                    inner_script = self.multisig_script([pubkey0, pubkey1])
                    script = '00'                                    # op_0
                    script += int_to_hex(len(sig0))
                    script += sig0.encode('hex')
                    script += int_to_hex(len(sig1))
                    script += sig1.encode('hex')
                    script += var_int(len(inner_script) / 2)
                    script += inner_script

            elif for_sig == i:
                if len(pubkeysig) > 1:
                    script = self.multisig_script(pubkeysig)  # p2sh uses the
                                                              # inner script
                else:
                    script = p_script                         # scriptsig
            else:
                script = ''
            s += var_int(len(self.tx_filter(script)) / 2)    # script length
            s += script
            s += "ffffffff"                                   # sequence

        s += var_int(len(outputs))                      # number of outputs
        for output in outputs:
            addr, amount = output
            s += int_to_hex(amount, 8)                              # amount
            addrtype, hash_160 = bc_address_to_hash_160(addr)
            if addrtype == 0:
                script = '76a9'                         # op_dup, op_hash_160
                script += '14'                          # push 0x14 bytes
                script += hash_160.encode('hex')
                script += '88ac'                 # op_equalverify, op_checksig
            elif addrtype == 5:
                script = 'a9'                           # op_hash_160
                script += '14'                          # push 0x14 bytes
                script += hash_160.encode('hex')
                script += '87'                          # op_equal
            else:
                raise

            s += var_int(len(self.tx_filter(script)) / 2)  # script length
            s += script                                    # script
        s += int_to_hex(0, 4)                               # lock time
        if for_sig is not None:
            s += int_to_hex(1, 4)      # hash type
        return self.tx_filter(s)
Exemple #9
0
 def test_bc_address_to_hash_160(self):
     self.assertEqual(bc_address_to_hash_160(None), None)
     self.assertEqual(bc_address_to_hash_160(''), None)
     self.assertEqual(
         bc_address_to_hash_160('13SrAVFPVW1txSj34B8Bd6hnDbyPsVGa921337'),
         None)
Exemple #10
0
 def test_bc_address_to_hash_160(self):
     self.assertEqual(bc_address_to_hash_160(None), None)
     self.assertEqual(bc_address_to_hash_160(''), None)
Exemple #11
0
import deserialize
import utils
import sys

#script="534104c46d6462f67f990211d3a7077f005e67154f5f785b3edc06af3de62649a15bad35905fa7af9f272f80379a41525ad57a2245c2edc4807e3e49f43eb1c1b119794104cc71eb30d653c0c3163990c47b976f3fb3f37cccdcbedb169a1dfef58bbfbfaff7d8a473e7e2e6d317b87bafe8bde97e3cf8f065dec022b51d11fcdd0d348ac4410461cbdcc5409fb4b4d42b51d33381354d80e550078cb532a34bfa2fcfdeb7d76519aecc62770f5b0e4ef8551946d8a540911abe3e7854a26f39f58b25c15342af53ae"
script = "76a91469d28eb9a311256338d281025a7437096149472c88ac61"
#script="76a9145f8b65a4064ef5c071c382d594b55d94bd31ec3a88ac";
#script="76a914c6b72811560b8c6ba897580754ba60d99c2094ed88ac";

script = sys.argv[1]

addr = deserialize.get_address_from_output_script(script.decode('hex'))
#print addr.encode('hex');

if addr == None:
    print addr
else:
    print utils.bc_address_to_hash_160(addr).encode('hex')
Exemple #12
0
import deserialize
import utils
import sys

#script="534104c46d6462f67f990211d3a7077f005e67154f5f785b3edc06af3de62649a15bad35905fa7af9f272f80379a41525ad57a2245c2edc4807e3e49f43eb1c1b119794104cc71eb30d653c0c3163990c47b976f3fb3f37cccdcbedb169a1dfef58bbfbfaff7d8a473e7e2e6d317b87bafe8bde97e3cf8f065dec022b51d11fcdd0d348ac4410461cbdcc5409fb4b4d42b51d33381354d80e550078cb532a34bfa2fcfdeb7d76519aecc62770f5b0e4ef8551946d8a540911abe3e7854a26f39f58b25c15342af53ae"
script="76a91469d28eb9a311256338d281025a7437096149472c88ac61"
#script="76a9145f8b65a4064ef5c071c382d594b55d94bd31ec3a88ac";
#script="76a914c6b72811560b8c6ba897580754ba60d99c2094ed88ac";

script=sys.argv[1]

addr=deserialize.get_address_from_output_script(script.decode('hex'))
#print addr.encode('hex');

if addr == None:
  print addr
else:
  print utils.bc_address_to_hash_160(addr).encode('hex')


Exemple #13
0
 def test_bc_address_to_hash_160(self):
     self.assertEqual(bc_address_to_hash_160(None), None)
     self.assertEqual(bc_address_to_hash_160(''), None)
     self.assertEqual(bc_address_to_hash_160('LMfoRhZDaAFxDFRCEK7Uu7mYRpLg3BuCoQ1337'), None)
     self.assertEqual(bc_address_to_hash_160('LMfoRhZDaAFxDFRCEK7Uu7mYRpLg3BuCoQ').encode('hex'),
                                             '1ad3b0b711f211655a01142fbb8fecabe8e30b93')