<s> """<STR_LIT>""" <EOL> from . . encoding import bitcoin_address_to_hash160_sec <EOL> from . . serialize import b2h , b2h_rev <EOL> from . Tx import Tx , SIGHASH_ALL <EOL> from . TxIn import TxIn <EOL> from . TxOut import TxOut <EOL> from . script import tools <EOL> from . script . vm import verify_script <EOL> class UnsignedTxOut ( object ) : <EOL> def __init__ ( self , previous_hash , previous_index , coin_value , script , sequence = <NUM_LIT> ) : <EOL> self . previous_hash = previous_hash <EOL> self . previous_index = previous_index <EOL> self . coin_value = coin_value <EOL> self . script = script <EOL> self . sequence = sequence <EOL> class UnsignedTx ( object ) : <EOL> def __init__ ( self , version , unsigned_txs_out , new_txs_out , lock_time = <NUM_LIT:0> ) : <EOL> self . version = version <EOL> self . unsigned_txs_out = unsigned_txs_out <EOL> self . new_txs_out = new_txs_out <EOL> self . lock_time = lock_time <EOL> @ classmethod <EOL> def standard_tx ( class_ , previous_hash_index_txout_tuple_list , coin_value__bitcoin_address__tuple_list , version = <NUM_LIT:1> , lock_time = <NUM_LIT:0> , is_test = False ) : <EOL> """<STR_LIT>""" <EOL> new_txs_out = [ ] <EOL> STANDARD_SCRIPT_OUT = "<STR_LIT>" <EOL> for coin_value , bitcoin_address in coin_value__bitcoin_address__tuple_list : <EOL> hash160 = bitcoin_address_to_hash160_sec ( bitcoin_address , is_test ) <EOL> script_text = STANDARD_SCRIPT_OUT % b2h ( hash160 ) <EOL> script_bin = tools . compile ( script_text ) <EOL> new_txs_out . append ( TxOut ( coin_value , script_bin ) ) <EOL> unsigned_txs_out = [ UnsignedTxOut ( h , idx , tx_out . coin_value , tx_out . script ) for h , idx , tx_out in previous_hash_index_txout_tuple_list ] <EOL> return class_ ( version , unsigned_txs_out , new_txs_out , lock_time ) <EOL> def sign ( self , solver , hash_type = SIGHASH_ALL ) : <EOL> """<STR_LIT>""" <EOL> blank_txs_in = [ TxIn ( unsigned_tx_out . previous_hash , unsigned_tx_out . previous_index ) for unsigned_tx_out_idx , unsigned_tx_out in enumerate ( self . unsigned_txs_out ) ] <EOL> tx = Tx ( self . version , blank_txs_in , self . new_txs_out , self . lock_time ) <EOL> new_txs_in = [ ] <EOL> for unsigned_tx_out_idx , unsigned_tx_out in enumerate ( self . unsigned_txs_out ) : <EOL> signature_hash = tx . signature_hash ( unsigned_tx_out . script , unsigned_tx_out_idx , hash_type = hash_type ) <EOL> new_script = solver ( unsigned_tx_out . script , signature_hash , hash_type ) <EOL> new_txs_in . append ( TxIn ( unsigned_tx_out . previous_hash , unsigned_tx_out . previous_index , new_script ) ) <EOL> if not verify_script ( new_script , unsigned_tx_out . script , signature_hash , hash_type = <NUM_LIT:0> ) : <EOL> raise ValidationFailureError ( "<STR_LIT>" % ( b2h_rev ( tx_in . previous_hash ) , unsigned_tx_out_idx ) ) <EOL> tx . txs_in = new_txs_in <EOL> return tx </s>
