예제 #1
0
    def _show_cashaddr_warning(self, address_text):
        '''
        cash addresses are not in the future for BSV. Anyone who uses one should be warned that
        they are being phased out, in order to encourage them to pre-emptively move on.
        '''
        address_text = self._parse_address_text(address_text)
        # We only care if it is decoded, as this will be a cash address.
        try:
            cashaddr.decode(address_text)
        except:
            return

        last_check_time = PayToEdit.last_cashaddr_warning
        ignore_watermark_time = time.time() - 24 * 60 * 60
        if last_check_time is None or last_check_time < ignore_watermark_time:
            PayToEdit.last_cashaddr_warning = time.time()

            message = ("<p>" + _(
                "One or more of the addresses you have provided has been recognized "
                +
                "as a 'cash address'. For now, this is acceptable but is recommended that you get "
                +
                "in the habit of requesting that anyone who provides you with payment addresses "
                + "do so in the form of normal Bitcoin SV addresses."
            ) + "</p>" + "<p>" + _(
                "Within the very near future, various services and applications in the Bitcoin "
                +
                "SV ecosystem will stop accepting 'cash addresses'. It is in your best interest "
                +
                "to make sure you transition over to normal Bitcoin SV addresses as soon as "
                +
                "possible, in order to ensure that you can both be paid, and also get paid."
            ) + "</p>")
            util.MessageBox.show_warning(message,
                                         title=_("Cash address warning"))
예제 #2
0
 def test_prefix(self):
     with pytest.raises(ValueError):
         cashaddr.decode(":ppm2qsznhks23z7629mms6s4cwef74vcwvn0h82")
     with pytest.raises(ValueError):
         cashaddr.decode("ppm2qsznhks23z7629mms6s4cwef74vcwvn0h82")
     with pytest.raises(ValueError):
         cashaddr.decode("bitcoin cash:ppm2qsznhks23z7629mms6s4cwef74vcwvn0h82")
     with pytest.raises(ValueError):
         cashaddr.decode("bitcoin cash:ab")
     # b is invalid
     with pytest.raises(ValueError):
         cashaddr.decode("bitcoincash:ppm2qsznbks23z7629mms6s4cwef74vcwvn0h82")
예제 #3
0
 def test_valid_pubkeys(self):
     """Test whether valid P2SH addresses decode to the correct output."""
     for (address, hashbytes) in zip(VALID_PUBKEY_ADDRESSES, VALID_HASHES):
         rprefix, kind, addr_hash = cashaddr.decode(address)
         assert rprefix == BSV_PREFIX
         assert kind == cashaddr.PUBKEY_TYPE
         assert addr_hash == hashbytes
예제 #4
0
 def test_valid_scripthash(self):
     """Test whether valid P2PK addresses decode to the correct output."""
     for (address, hashbytes) in zip(VALID_SCRIPT_ADDRESSES, VALID_HASHES):
         rprefix, kind, addr_hash = cashaddr.decode(address)
         assert rprefix == BSV_PREFIX
         assert kind == cashaddr.SCRIPT_TYPE
         assert addr_hash == hashbytes
예제 #5
0
 def test_bad_decode_size(self):
     """Test that addresses with invalid sizes fail to decode."""
     for bits_size in self.valid_sizes:
         size = bits_size // 8
         # Convert to a valid number of bytes for a hash
         hashbytes = bytes(random.randint(0, 255) for i in range(size))
         payload = cashaddr._pack_addr_data(cashaddr.PUBKEY_TYPE, hashbytes)
         # Add some more 5-bit data after size has been encoded
         payload += bytes(random.randint(0, 15) for i in range(3))
         # Add checksum
         payload += cashaddr._create_checksum(BSV_PREFIX, payload)
         addr = BSV_PREFIX + ':' + ''.join(cashaddr._CHARSET[d] for d in payload)
         # Check decode fails.  This can trigger the length mismatch,
         # excess padding, or non-zero padding errors
         with pytest.raises(ValueError):
             cashaddr.decode(addr)
예제 #6
0
    def _from_cashaddr_string(cls, text, network):
        '''Construct from a cashaddress string.'''
        network = network or Bitcoin
        prefix = network.cashaddr_prefix
        if text.upper() == text:
            prefix = prefix.upper()
        if not text.startswith(prefix + ':'):
            text = ':'.join((prefix, text))
        addr_prefix, kind, hash160 = cashaddr.decode(text)
        assert prefix == addr_prefix

        if kind == cashaddr.PUBKEY_TYPE:
            return P2PKH_Address(hash160, network)
        return P2SH_Address(hash160, network)
예제 #7
0
 def test_encode_decode(self):
     """Test whether valid addresses encode and decode properly, for all
     valid hash sizes.
     """
     for prefix in (BSV_PREFIX, BSV_TESTNET_PREFIX):
         for bits_size in self.valid_sizes:
             size = bits_size // 8
             # Convert to a valid number of bytes for a hash
             hashbytes = bytes(random.randint(0, 255) for i in range(size))
             addr = _encode_full(prefix, cashaddr.PUBKEY_TYPE, hashbytes)
             rprefix, kind, addr_hash = cashaddr.decode(addr)
             assert rprefix == prefix
             assert kind == cashaddr.PUBKEY_TYPE
             assert addr_hash == hashbytes
예제 #8
0
 def test_address_case(self):
     prefix, _kind, _hash160 = cashaddr.decode("bitcoincash:ppm2qsznhks23z7629mms6s4cwef74vcwvn0h829pq")
     assert prefix == "bitcoincash"
     prefix, _kind, _hash160 = cashaddr.decode("BITCOINCASH:PPM2QSZNHKS23Z7629MMS6S4CWEF74VCWVN0H829PQ")
     assert prefix == "BITCOINCASH"
     with pytest.raises(ValueError):
         cashaddr.decode("bitcoincash:PPM2QSZNHKS23Z7629MMS6S4CWEF74VCWVN0H829PQ")
     with pytest.raises(ValueError):
         cashaddr.decode("bitcoincash:ppm2qsznhks23z7629mmS6s4cwef74vcwvn0h829pq")
예제 #9
0
 def test_decode_bad_inputs(self):
     with pytest.raises(TypeError):
         cashaddr.decode(b'foobar')
예제 #10
0
 def test_bad_decode_checksum(self, mangled_addr):
     """Test whether addresses with invalid checksums fail to decode."""
     with pytest.raises(ValueError) as e:
         cashaddr.decode('bitcoincash:' + mangled_addr)
     assert 'invalid checksum' in str(e.value)
예제 #11
0
 def test_decode_bad_kind(self):
     addr = _encode_full(BSV_PREFIX, 2, bytes(20))
     with pytest.raises(ValueError) as e:
         cashaddr.decode(addr)