def test_from_nonstd_scriptPubKey(self):
        """CRavencoinAddress.from_scriptPubKey() with non-standard scriptPubKeys"""

        # Bad P2SH scriptPubKeys

        # non-canonical pushdata
        scriptPubKey = CScript(x('a94c14000000000000000000000000000000000000000087'))
        with self.assertRaises(CRavencoinAddressError):
            CRavencoinAddress.from_scriptPubKey(scriptPubKey)

        # Bad P2PKH scriptPubKeys

        # Missing a byte
        scriptPubKey = CScript(x('76a914000000000000000000000000000000000000000088'))
        with self.assertRaises(CRavencoinAddressError):
            CRavencoinAddress.from_scriptPubKey(scriptPubKey)

        # One extra byte
        scriptPubKey = CScript(x('76a914000000000000000000000000000000000000000088acac'))
        with self.assertRaises(CRavencoinAddressError):
            CRavencoinAddress.from_scriptPubKey(scriptPubKey)

        # One byte changed
        scriptPubKey = CScript(x('76a914000000000000000000000000000000000000000088ad'))
        with self.assertRaises(CRavencoinAddressError):
            CRavencoinAddress.from_scriptPubKey(scriptPubKey)
    def test_from_redeemScript(self):
        def T(script, expected_str_address):
            addr = P2SHRavencoinAddress.from_redeemScript(script)
            self.assertEqual(str(addr), expected_str_address)

        T(CScript(), 'rNgi5iPXJfKYt65YnocubTpm9swCcJwLTY')
        T(CScript(x('76a914751e76e8199196d454941c45d1b3a323f1433bd688ac')),
          'rQy5KSWuzWQwK6ZGJ8wkwLGDb5oCh5FXog')
    def test_from_invalid_scriptPubKey(self):
        """CRavencoinAddress.from_scriptPubKey() with invalid scriptPubKeys"""

        # We should raise a CRavencoinAddressError, not any other type of error

        # Truncated P2SH
        scriptPubKey = CScript(x('a91400000000000000000000000000000000000000'))
        with self.assertRaises(CRavencoinAddressError):
            CRavencoinAddress.from_scriptPubKey(scriptPubKey)

        # Truncated P2PKH
        scriptPubKey = CScript(x('76a91400000000000000000000000000000000000000'))
        with self.assertRaises(CRavencoinAddressError):
            CRavencoinAddress.from_scriptPubKey(scriptPubKey)
示例#4
0
    def listunspent(self, minconf=0, maxconf=9999999, addrs=None):
        """Return unspent transaction outputs in wallet

        Outputs will have between minconf and maxconf (inclusive)
        confirmations, optionally filtered to only include txouts paid to
        addresses in addrs.
        """
        r = None
        if addrs is None:
            r = self._call('listunspent', minconf, maxconf)
        else:
            addrs = [str(addr) for addr in addrs]
            r = self._call('listunspent', minconf, maxconf, addrs)

        r2 = []
        for unspent in r:
            unspent['outpoint'] = COutPoint(lx(unspent['txid']), unspent['vout'])
            del unspent['txid']
            del unspent['vout']

            # address isn't always available as Ravencoin Core allows scripts w/o
            # an address type to be imported into the wallet, e.g. non-p2sh
            # segwit
            try:
                unspent['address'] = CRavencoinAddress(unspent['address'])
            except KeyError:
                pass
            unspent['scriptPubKey'] = CScript(unhexlify(unspent['scriptPubKey']))
            unspent['amount'] = int(unspent['amount'] * COIN)
            r2.append(unspent)
        return r2
        def T(hex_scriptpubkey, expected_str_address):
            scriptPubKey = CScript(x(hex_scriptpubkey))
            addr = P2PKHRavencoinAddress.from_scriptPubKey(scriptPubKey)
            self.assertEqual(str(addr), expected_str_address)

            # now test that CRavencoinAddressError is raised with accept_non_canonical_pushdata=False
            with self.assertRaises(CRavencoinAddressError):
                P2PKHRavencoinAddress.from_scriptPubKey(scriptPubKey, accept_bare_checksig=False)
示例#6
0
    def gettxout(self, outpoint, includemempool=True):
        """Return details about an unspent transaction output.

        Raises IndexError if outpoint is not found or was spent.

        includemempool - Include mempool txouts
        """
        r = self._call('gettxout', b2lx(outpoint.hash), outpoint.n, includemempool)

        if r is None:
            raise IndexError('%s.gettxout(): unspent txout %r not found' % (self.__class__.__name__, outpoint))

        r['txout'] = CTxOut(int(r['value'] * COIN),
                            CScript(unhexlify(r['scriptPubKey']['hex'])))
        del r['value']
        del r['scriptPubKey']
        r['bestblock'] = lx(r['bestblock'])
        return r
def to_scriptPubKey(witver, witprog):
    """Decoded bech32 address to script"""
    return CScript([witver]) + CScript(_tobytes(witprog))
 def T(hex_scriptpubkey, expected_str_address, expected_class):
     scriptPubKey = CScript(x(hex_scriptpubkey))
     addr = CRavencoinAddress.from_scriptPubKey(scriptPubKey)
     self.assertEqual(str(addr), expected_str_address)
     self.assertEqual(addr.__class__, expected_class)