<s> from . . script import tools <EOL> from ... import encoding <EOL> from ... networks import address_prefix_for_netcode <EOL> from ... serialize import b2h <EOL> from . . exceptions import SolvingError <EOL> from . ScriptType import ScriptType <EOL> class ScriptPayToPublicKey ( ScriptType ) : <EOL> """<STR_LIT>""" <EOL> TEMPLATE = tools . compile ( "<STR_LIT>" ) <EOL> def __init__ ( self , sec ) : <EOL> self . sec = sec <EOL> self . _address = None <EOL> self . _script = None <EOL> @ classmethod <EOL> def from_key ( cls , key , use_uncompressed = False ) : <EOL> return cls . from_sec ( key . sec ( use_uncompressed = use_uncompressed ) ) <EOL> @ classmethod <EOL> def from_sec ( cls , sec ) : <EOL> return cls ( sec ) <EOL> @ classmethod <EOL> def from_script ( cls , script ) : <EOL> r = cls . match ( script ) <EOL> if r : <EOL> sec = r [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> s = cls ( sec ) <EOL> return s <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def script ( self ) : <EOL> if self . _script is None : <EOL> STANDARD_SCRIPT_OUT = "<STR_LIT>" <EOL> script_text = STANDARD_SCRIPT_OUT % b2h ( self . sec ) <EOL> self . _script = tools . compile ( script_text ) <EOL> return self . _script <EOL> def solve ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> db = kwargs . get ( "<STR_LIT>" ) <EOL> if db is None : <EOL> raise SolvingError ( "<STR_LIT>" ) <EOL> self . address ( ) <EOL> result = db . get ( encoding . hash160 ( self . sec ) ) <EOL> if result is None : <EOL> raise SolvingError ( "<STR_LIT>" % self . address ( ) ) <EOL> sign_value = kwargs . get ( "<STR_LIT>" ) <EOL> signature_type = kwargs . get ( "<STR_LIT>" ) <EOL> secret_exponent , public_pair , compressed = result <EOL> solution = tools . bin_script ( [ self . _create_script_signature ( <EOL> secret_exponent , sign_value , signature_type ) ] ) <EOL> return solution <EOL> def info ( self , netcode = "<STR_LIT>" ) : <EOL> address_prefix = address_prefix_for_netcode ( netcode ) <EOL> hash160 = encoding . hash160 ( self . sec ) <EOL> address = encoding . hash160_sec_to_bitcoin_address ( hash160 , address_prefix = address_prefix ) <EOL> return dict ( type = "<STR_LIT>" , address = address , hash160 = hash160 , <EOL> script = self . _script , address_prefix = address_prefix , summary = address ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . address ( ) </s>
