def to_scriptPubKey(self, nested=False):
     """Convert an address to a scriptPubKey"""
     assert self.nVersion == ravencoin.params.BASE58_PREFIXES['PUBKEY_ADDR']
     return script.CScript([
         script.OP_DUP, script.OP_HASH160, self, script.OP_EQUALVERIFY,
         script.OP_CHECKSIG
     ])
 def to_redeemScript(self):
     return script.CScript([
         script.OP_DUP, script.OP_HASH160, self, script.OP_EQUALVERIFY,
         script.OP_CHECKSIG
     ])
 def to_scriptPubKey(self):
     """Convert an address to a scriptPubKey"""
     assert self.witver == 0
     return script.CScript([0, self])
    def from_scriptPubKey(cls,
                          scriptPubKey,
                          accept_non_canonical_pushdata=True,
                          accept_bare_checksig=True):
        """Convert a scriptPubKey to a P2PKH address

        Raises CRavencoinAddressError if the scriptPubKey isn't of the correct
        form.

        accept_non_canonical_pushdata - Allow non-canonical pushes (default True)

        accept_bare_checksig          - Treat bare-checksig as P2PKH scriptPubKeys (default True)
        """
        if accept_non_canonical_pushdata:
            # Canonicalize script pushes
            scriptPubKey = script.CScript(
                scriptPubKey)  # in case it's not a CScript instance yet

            try:
                scriptPubKey = script.CScript(
                    tuple(scriptPubKey))  # canonicalize
            except ravencoin.core.script.CScriptInvalidError:
                raise CRavencoinAddressError(
                    'not a P2PKH scriptPubKey: script is invalid')

        if scriptPubKey.is_witness_v0_keyhash():
            return cls.from_bytes(
                scriptPubKey[2:22],
                ravencoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])
        elif scriptPubKey.is_witness_v0_nested_keyhash():
            return cls.from_bytes(
                scriptPubKey[3:23],
                ravencoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])
        elif (len(scriptPubKey) == 25
              and _bord(scriptPubKey[0]) == script.OP_DUP
              and _bord(scriptPubKey[1]) == script.OP_HASH160
              and _bord(scriptPubKey[2]) == 0x14
              and _bord(scriptPubKey[23]) == script.OP_EQUALVERIFY
              and _bord(scriptPubKey[24]) == script.OP_CHECKSIG):
            return cls.from_bytes(
                scriptPubKey[3:23],
                ravencoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])

        elif accept_bare_checksig:
            pubkey = None

            # We can operate on the raw bytes directly because we've
            # canonicalized everything above.
            if (len(scriptPubKey) == 35  # compressed
                    and _bord(scriptPubKey[0]) == 0x21
                    and _bord(scriptPubKey[34]) == script.OP_CHECKSIG):

                pubkey = scriptPubKey[1:34]

            elif (len(scriptPubKey) == 67  # uncompressed
                  and _bord(scriptPubKey[0]) == 0x41
                  and _bord(scriptPubKey[66]) == script.OP_CHECKSIG):

                pubkey = scriptPubKey[1:65]

            if pubkey is not None:
                return cls.from_pubkey(pubkey, accept_invalid=True)

        raise CRavencoinAddressError('not a P2PKH scriptPubKey')
 def to_scriptPubKey(self):
     """Convert an address to a scriptPubKey"""
     assert self.nVersion == ravencoin.params.BASE58_PREFIXES['SCRIPT_ADDR']
     return script.CScript([script.OP_HASH160, self, script.OP_EQUAL])