<s> """<STR_LIT>""" <EOL> from . opcodes import * <EOL> from . utils import count_bytes <EOL> from . . constants import MAX_BYTES_AFTER_OP_RETURN <EOL> from . . b58check import b58check_decode , b58check_encode <EOL> from binascii import hexlify , unhexlify <EOL> from utilitybelt import is_hex <EOL> def script_to_hex ( script ) : <EOL> """<STR_LIT>""" <EOL> hex_script = '<STR_LIT>' <EOL> parts = script . split ( '<STR_LIT:U+0020>' ) <EOL> for part in parts : <EOL> if part [ <NUM_LIT:0> : <NUM_LIT:3> ] == '<STR_LIT>' : <EOL> try : <EOL> hex_script += '<STR_LIT>' % eval ( part ) <EOL> except : <EOL> raise Exception ( '<STR_LIT>' % part ) <EOL> elif isinstance ( part , ( int ) ) : <EOL> hex_script += '<STR_LIT>' % part <EOL> elif is_hex ( part ) : <EOL> hex_script += '<STR_LIT>' % count_bytes ( part ) + part <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> return hex_script <EOL> def make_pay_to_address_script ( address ) : <EOL> """<STR_LIT>""" <EOL> hash160 = hexlify ( b58check_decode ( address ) ) <EOL> script_string = '<STR_LIT>' % hash160 <EOL> return script_to_hex ( script_string ) <EOL> def make_op_return_script ( data , format = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if format == '<STR_LIT>' : <EOL> assert ( is_hex ( data ) ) <EOL> hex_data = data <EOL> elif format == '<STR_LIT>' : <EOL> hex_data = hexlify ( data ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> num_bytes = count_bytes ( hex_data ) <EOL> if num_bytes > MAX_BYTES_AFTER_OP_RETURN : <EOL> raise Exception ( '<STR_LIT>' % num_bytes ) <EOL> script_string = '<STR_LIT>' % hex_data <EOL> return script_to_hex ( script_string ) </s>
