Beispiel #1
0
 def test_address_from_base58addr(self):
     #TESTNET
     addr1 = BitcoinAddress.from_base58addr(
         "n4MsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo")
     self.assertEquals(hexstr(addr1.get_hash160()),
                       'fa92e151722c0ebca07059a505252218b4c50e7a')
     self.assertEquals(addr1.get_addr_version(),
                       AddressVersion(PUBKEY_ADDRESS_TEST))
     #TESTNET script address
     addr2 = BitcoinAddress.from_base58addr(
         "2NG68seqhTqLnniguW6efUDKyCHm4LYEFRa")
     self.assertEquals(hexstr(addr2.get_hash160()),
                       'fa92e151722c0ebca07059a505252218b4c50e7a')
     self.assertEquals(addr2.get_addr_version(),
                       AddressVersion(SCRIPT_ADDRESS_TEST))
     #MAIN
     addr2 = BitcoinAddress.from_base58addr(
         "1PqutNREJUX4VmMvhsNCRdymqRGAzifdsx")
     self.assertEquals(hexstr(addr2.get_hash160()),
                       'fa92e151722c0ebca07059a505252218b4c50e7a')
     self.assertEquals(addr2.get_addr_version(),
                       AddressVersion(PUBKEY_ADDRESS_MAIN))
     #MAIN Script address
     addr2 = BitcoinAddress.from_base58addr(
         "3QXvouufrNqSaw4Mpy2nrGLhywYtXx6wsi")
     self.assertEquals(hexstr(addr2.get_hash160()),
                       'fa92e151722c0ebca07059a505252218b4c50e7a')
     self.assertEquals(addr2.get_addr_version(),
                       AddressVersion(SCRIPT_ADDRESS_MAIN))
Beispiel #2
0
 def from_bytestring(bytestr):
     if (len(bytestr) != 21):
         raise InvalidBitcoinAddress(
             "BitcoinAddress.from_base58addr(): incorrect length")
     return BitcoinAddress(hash160=bytestr[1:],
                           address_version=AddressVersion.from_byte(
                               ord(bytestr[0])))
Beispiel #3
0
 def test_address_get_addr_version(self):
     self.assertEquals(
         BitcoinAddress(
             decodehexstr("b0600c55b16851c4f9d0e2c82fa161ac8190e04c"),
             AddressVersion(PUBKEY_ADDRESS_TEST)).get_addr_version(),
         AddressVersion(PUBKEY_ADDRESS_TEST))
Beispiel #4
0
 def test_address_to_hexstring(self):
     self.assertEquals(
         BitcoinAddress(
             decodehexstr("b0600c55b16851c4f9d0e2c82fa161ac8190e04c"),
             AddressVersion(PUBKEY_ADDRESS_MAIN)).to_hexstring(),
         "00b0600c55b16851c4f9d0e2c82fa161ac8190e04c")
Beispiel #5
0
 def test_address_to_base58addr(self):
     self.assertEquals(
         BitcoinAddress(
             decodehexstr("b0600c55b16851c4f9d0e2c82fa161ac8190e04c"),
             AddressVersion(PUBKEY_ADDRESS_MAIN)).to_base58addr(),
         "1H5azJoKoYd92DxjXX7k7gejpbLVMAczAi")
Beispiel #6
0
 def from_publickey(public_key, runmode):
     return BitcoinAddress(hash160(public_key),
                           AddressVersion.from_runmode(runmode))
Beispiel #7
0
    if script_type == TX_PUBKEY:
        return hash160(tx_pubkey_get_pubkey(txout.script))
    raise Exception("Unexpected script type")


if __name__ == '__main__':
    from coinpy.model.protocol.runmode import TESTNET, MAIN
    from coinpy.tools.hex import decodehexstr
    assert BitcoinAddress.is_valid("n4MsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo",
                                   TESTNET)
    assert not BitcoinAddress.is_valid("n4NsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo",
                                       TESTNET)
    print BitcoinAddress.is_valid("1H5azJoKoYd92DxjXX7k7gejpbLVMAczAi", MAIN)
    print BitcoinAddress.is_valid("1H1hQVMZ6bpyGNWboJQT4aouDSksBnZWL3", MAIN)
    print BitcoinAddress.from_base58addr("n4MsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo")
    print BitcoinAddress.from_base58addr("1H5azJoKoYd92DxjXX7k7gejpbLVMAczAi")
    print BitcoinAddress.from_base58addr(
        "1H5azJoKoYd92DxjXX7k7gejpbLVMAczAi").to_base58addr()
    print BitcoinAddress.from_base58addr(
        "1H5azJoKoYd92DxjXX7k7gejpbLVMAczAi").to_hexstring()
    print BitcoinAddress.from_base58addr(
        "n4MsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo").to_base58addr()
    print BitcoinAddress(
        decodehexstr("00600c55b16851c4f9d0e2c82fa161ac8190e04c"),
        AddressVersion(PUBKEY_ADDRESS_MAIN))
    print BitcoinAddress(
        decodehexstr("00602005b16851c4f9d0e2c82fa161ac8190e04c"),
        AddressVersion(PUBKEY_ADDRESS_MAIN))
    print BitcoinAddress.is_valid("112z9tWej11X94khKKzofFgWbdhiXLeHPD", MAIN)
    print BitcoinAddress.is_valid("1111MJe7b4ZnktoPZabb6DLAKfac8tvx", MAIN)
Beispiel #8
0
 def from_bytestring(bytestr):
     if (len(bytestr) != 21):
         raise InvalidBitcoinAddress("BitcoinAddress.from_base58addr(): incorrect length")
     return BitcoinAddress(hash160=bytestr[1:], address_version=AddressVersion.from_byte(ord(bytestr[0])))
Beispiel #9
0
 def from_publickey(public_key, runmode):
     return BitcoinAddress(hash160(public_key), AddressVersion.from_runmode(runmode))