#NEWLINE# def handle_task( self , task ) : #NEWLINE# #INDENT# message = cjson . decode ( task [ 'json_data' ] ) #NEWLINE# txid = message [ 'txid' ] #NEWLINE# n = message [ 'n' ] #NEWLINE# redeemScript = self . kv . get_by_section_key ( 'safe_timelock_redeem' , message [ 'address' ] ) [ 'redeem' ] #NEWLINE# tx = self . btc . get_raw_transaction ( txid ) #NEWLINE# transaction = self . btc . decode_raw_transaction ( tx ) #NEWLINE# vout = None #NEWLINE# for v in transaction [ 'vout' ] : #NEWLINE# #INDENT# if ( v [ 'n' ] == n ) : #NEWLINE# #INDENT# vout = v #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not vout ) : #NEWLINE# #INDENT# logging . info ( 'missing vout for txid {} n {}' . format ( txid , n ) ) #NEWLINE# return #NEWLINE# #UNINDENT# sum_satoshi = int ( round ( ( vout [ 'value' ] * 100000000 ) ) ) #NEWLINE# message [ 'sum_satoshi' ] = sum_satoshi #NEWLINE# scriptPubKey = vout [ 'scriptPubKey' ] [ 'hex' ] #NEWLINE# prevtx = { #NEWLINE# #INDENT# 'txid' : txid , #NEWLINE# 'vout' : n , #NEWLINE# 'redeemScript' : redeemScript , #NEWLINE# 'scriptPubKey' : scriptPubKey , #NEWLINE# #UNINDENT# } #NEWLINE# prevtxs = [ prevtx ] #NEWLINE# message [ 'prevtxs' ] = prevtxs #NEWLINE# message [ 'outputs' ] = message [ 'oracle_fees' ] #NEWLINE# logging . debug ( ( 'outputs: %r' % message [ 'outputs' ] ) ) #NEWLINE# try : #NEWLINE# #INDENT# future_transaction = self . try_prepare_raw_transaction ( message ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# msg_id = ( '%s-%s' % ( 'timelock_signature' , str ( randrange ( 1000000000 , 9000000000 ) ) ) ) #NEWLINE# contract_id = '{}#{}' . format ( message [ 'address' ] , message [ 'mark' ] ) #NEWLINE# info_msg = { #NEWLINE# #INDENT# 'operation' : 'timelock_signing_fail' , #NEWLINE# 'in_reply_to' : '' , #NEWLINE# 'message_id' : msg_id , #NEWLINE# 'contract_id' : contract_id , #NEWLINE# #UNINDENT# } #NEWLINE# self . oracle . broadcast_with_fastcast ( json . dumps ( info_msg ) ) #NEWLINE# logging . exception ( ( 'problem signing tx: %r ; %r' % ( contract_id , msg_id ) ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( not future_transaction ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# logging . info ( future_transaction ) #NEWLINE# try : #NEWLINE# #INDENT# pwtxid = self . get_tx_hash ( future_transaction ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logging . error ( 'Failed to create tx hash' ) #NEWLINE# return #NEWLINE# #UNINDENT# assert ( future_transaction is not None ) #NEWLINE# self . oracle . signer . sign ( future_transaction , pwtxid , prevtxs , message [ 'req_sigs' ] ) #NEWLINE# info_msg = { #NEWLINE# #INDENT# 'operation' : 'safe_timelock_signed' , #NEWLINE# 'in_reply_to' : '' , #NEWLINE# 'message_id' : ( '%s-%s' % ( 'timelock_signature' , str ( randrange ( 1000000000 , 9000000000 ) ) ) ) , #NEWLINE# 'contract_id' : '{}#{}' . format ( message [ 'address' ] , message [ 'mark' ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# self . oracle . broadcast_with_fastcast ( json . dumps ( info_msg ) )