#NEWLINE# def compose_tx_spec( self , op_tx_spec ) : #NEWLINE# #INDENT# targets_by_color = group_targets_by_color ( op_tx_spec . get_targets ( ) , self . __class__ ) #NEWLINE# uncolored_targets = targets_by_color . pop ( UNCOLORED_MARKER . color_id , [ ] ) #NEWLINE# composed_tx_spec = op_tx_spec . make_composed_tx_spec ( ) #NEWLINE# for ( color_id , targets ) in targets_by_color . items ( ) : #NEWLINE# #INDENT# color_def = targets [ 0 ] . get_colordef ( ) #NEWLINE# needed_sum = ColorTarget . sum ( targets ) #NEWLINE# ( inputs , total ) = op_tx_spec . select_coins ( needed_sum ) #NEWLINE# change = ( total - needed_sum ) #NEWLINE# if ( change > 0 ) : #NEWLINE# #INDENT# targets . append ( ColorTarget ( op_tx_spec . get_change_addr ( color_def ) , change ) ) #NEWLINE# #UNINDENT# composed_tx_spec . add_txins ( inputs ) #NEWLINE# for target in targets : #NEWLINE# #INDENT# composed_tx_spec . add_txout ( value = target . get_value ( ) , target = target ) #NEWLINE# #UNINDENT# #UNINDENT# uncolored_needed = ColorTarget . sum ( uncolored_targets ) #NEWLINE# ( uncolored_inputs , uncolored_total ) = op_tx_spec . select_coins ( uncolored_needed , composed_tx_spec ) #NEWLINE# composed_tx_spec . add_txins ( uncolored_inputs ) #NEWLINE# fee = composed_tx_spec . estimate_required_fee ( ) #NEWLINE# uncolored_change = ( ( uncolored_total - uncolored_needed ) - fee ) #NEWLINE# if ( uncolored_change > op_tx_spec . get_dust_threshold ( ) ) : #NEWLINE# #INDENT# composed_tx_spec . add_txout ( value = uncolored_change , target_addr = op_tx_spec . get_change_addr ( UNCOLORED_MARKER ) , is_fee_change = True ) #NEWLINE# #UNINDENT# return composed_tx_spec