<s> from ... import ecdsa <EOL> from ... import encoding <EOL> from ... networks import DEFAULT_NETCODES , pay_to_script_prefix_for_netcode <EOL> from ... key . validate import netcode_and_type_for_data <EOL> from . ScriptPayToAddress import ScriptPayToAddress <EOL> from . ScriptPayToPublicKey import ScriptPayToPublicKey <EOL> from . ScriptPayToScript import ScriptPayToScript <EOL> from . ScriptMultisig import ScriptMultisig <EOL> from . ScriptUnknown import ScriptUnknown <EOL> from . ScriptNulldata import ScriptNulldata <EOL> SUBCLASSES = [ <EOL> ScriptPayToAddress , ScriptPayToPublicKey , ScriptPayToScript , <EOL> ScriptMultisig , ScriptNulldata , ScriptUnknown <EOL> ] <EOL> def script_obj_from_address ( text , netcodes = DEFAULT_NETCODES ) : <EOL> data = encoding . a2b_hashed_base58 ( text ) <EOL> netcode , key_type = netcode_and_type_for_data ( data , netcodes = netcodes ) <EOL> if key_type == '<STR_LIT>' : <EOL> return ScriptPayToScript ( hash160 = data [ <NUM_LIT:1> : ] ) <EOL> if key_type == '<STR_LIT:address>' : <EOL> return ScriptPayToAddress ( hash160 = data [ <NUM_LIT:1> : ] ) <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def script_obj_from_script ( script ) : <EOL> for sc in SUBCLASSES : <EOL> try : <EOL> st = sc . from_script ( script ) <EOL> return st <EOL> except ValueError : <EOL> pass <EOL> return None <EOL> def address_for_pay_to_script ( script , netcode = "<STR_LIT>" ) : <EOL> address_prefix = pay_to_script_prefix_for_netcode ( netcode ) <EOL> return encoding . hash160_sec_to_bitcoin_address ( encoding . hash160 ( script ) , address_prefix = address_prefix ) <EOL> def build_hash160_lookup ( secret_exponents ) : <EOL> d = { } <EOL> for secret_exponent in secret_exponents : <EOL> public_pair = ecdsa . public_pair_for_secret_exponent ( ecdsa . generator_secp256k1 , secret_exponent ) <EOL> for compressed in ( True , False ) : <EOL> hash160 = encoding . public_pair_to_hash160_sec ( public_pair , compressed = compressed ) <EOL> d [ hash160 ] = ( secret_exponent , public_pair , compressed ) <EOL> return d <EOL> def build_p2sh_lookup ( scripts ) : <EOL> return dict ( ( encoding . hash160 ( s ) , s ) for s in scripts ) </s>
