예제 #1
0
파일: data.py 프로젝트: nformant1/p2pool
def pubkey_hash_to_address(pubkey_hash, addr_ver, bech32_ver, net):
    if addr_ver == -1:
        if hasattr(net, 'padding_bugfix') and net.padding_bugfix:
            thash = '{:040x}'.format(pubkey_hash)
        else:
            thash = '{:x}'.format(pubkey_hash)
            if len(thash) % 2 == 1:
                thash = '0%s' % thash
        data = [int(x) for x in bytearray.fromhex(thash)]
        if net.SYMBOL.lower() in ['bch', 'tbch', 'bsv', 'tbsv']:
            return cash_addr.encode(net.HUMAN_READABLE_PART, bech32_ver, data)
        else:
            return segwit_addr.encode(net.HUMAN_READABLE_PART, bech32_ver, data)
    return base58_encode(human_address_type.pack(dict(version=addr_ver, pubkey_hash=pubkey_hash)))
예제 #2
0
 def test_encode(self, md, mba, mcb):
     mcb.return_value = ['foo']
     mba.return_value = 'bar'
     md.return_value = (None, None)
     # Test for invalid data lengths.
     valid_lengths = [20, 24, 28, 32, 40, 48, 56, 64]
     data = []
     self.assertEqual(None, cash_addr.encode('bchtest', 0, data))
     for i in range(1, 129):
         data.append(i)
         if i in valid_lengths:
             continue
         self.assertEqual(None, cash_addr.encode('bchtest', 0, data))
     # Test unsupported versions.
     data = [x for x in range(20)]
     for i in range(2, 15):
         self.assertEqual(None, cash_addr.encode('bchtest', i, [0]))
     self.assertEqual(None, cash_addr.encode('bitcoincash', 0, data))
     mcb.assert_called_once_with([0] + data, 8, 5)
     mba.assert_called_once_with('bitcoincash', ['foo'])
     md.assert_called_once_with('bitcoincash', 'bar')
     mcb.reset_mock()
     mba.reset_mock()
     md.reset_mock()
     md.return_value = (3, [6, 7, 8])
     self.assertEqual('bar', cash_addr.encode('bchtest', 1, data))
     mcb.assert_called_once_with([8] + data, 8, 5)
     mba.assert_called_once_with('bchtest', ['foo'])
     md.assert_called_once_with('bchtest', 'bar')
     mcb.reset_mock()
     self.assertEqual('bar', cash_addr.encode('bchtest', 15, data))
     mcb.assert_called_once_with([120] + data, 8, 5)
     for i in range(8):
         mcb.reset_mock()
         data = [x for x in range(valid_lengths[i])]
         self.assertEqual('bar', cash_addr.encode('bchtest', 0, data))
         mcb.assert_called_once_with([i] + data, 8, 5)
예제 #3
0
 def test_valid_addresses(self):
     for addr, script in self.VALID_ADDRESS:
         prefix = self.get_prefix(addr)
         ver, data = cash_addr.decode(prefix, addr)
         self.assertEqual(addr.lower(), cash_addr.encode(prefix, ver, data),
                          "Address %s failed." % addr)