def subdispatch_targettask( node_state, state_change, token_network_identifier, token_address, channel_identifier, secrethash, ): block_number = node_state.block_number sub_task = node_state.payment_mapping.secrethashes_to_task.get(secrethash) if not sub_task: is_valid_subtask = True target_state = None elif sub_task and isinstance(sub_task, PaymentMappingState.TargetTask): is_valid_subtask = (token_network_identifier == sub_task.token_network_identifier and token_address == sub_task.token_address) target_state = sub_task.target_state else: is_valid_subtask = False events = list() channel_state = None if is_valid_subtask: channel_state = views.get_channelstate_by_token_network_identifier( node_state, token_network_identifier, channel_identifier, ) if channel_state: pseudo_random_generator = node_state.pseudo_random_generator iteration = target.state_transition( target_state, state_change, channel_state, pseudo_random_generator, block_number, ) events = iteration.events if iteration.new_state: sub_task = PaymentMappingState.TargetTask( token_network_identifier, channel_identifier, iteration.new_state, ) node_state.payment_mapping.secrethashes_to_task[ secrethash] = sub_task elif secrethash in node_state.payment_mapping.secrethashes_to_task: del node_state.payment_mapping.secrethashes_to_task[secrethash] return TransitionResult(node_state, events)
def subdispatch_targettask( chain_state: ChainState, state_change: StateChange, token_network_identifier: typing.TokenNetworkID, channel_identifier: typing.ChannelID, secrethash: typing.SecretHash, ) -> TransitionResult: block_number = chain_state.block_number sub_task = chain_state.payment_mapping.secrethashes_to_task.get(secrethash) if not sub_task: is_valid_subtask = True target_state = None elif sub_task and isinstance(sub_task, PaymentMappingState.TargetTask): is_valid_subtask = ( token_network_identifier == sub_task.token_network_identifier) target_state = sub_task.target_state else: is_valid_subtask = False events = list() channel_state = None if is_valid_subtask: channel_state = views.get_channelstate_by_token_network_identifier( chain_state, token_network_identifier, channel_identifier, ) if channel_state: pseudo_random_generator = chain_state.pseudo_random_generator iteration = target.state_transition( target_state, state_change, channel_state, pseudo_random_generator, block_number, ) events = iteration.events if iteration.new_state: sub_task = PaymentMappingState.TargetTask( token_network_identifier, channel_identifier, iteration.new_state, ) chain_state.payment_mapping.secrethashes_to_task[ secrethash] = sub_task elif secrethash in chain_state.payment_mapping.secrethashes_to_task: del chain_state.payment_mapping.secrethashes_to_task[secrethash] return TransitionResult(chain_state, events)
def subdispatch_targettask( node_state, state_change, payment_network_identifier, token_address, channel_identifier, hashlock): block_number = node_state.block_number sub_task = node_state.payment_mapping.hashlocks_to_task.get(hashlock) if not sub_task: is_valid_subtask = True target_state = None elif sub_task and isinstance(sub_task, PaymentMappingState.TargetTask): is_valid_subtask = ( payment_network_identifier == sub_task.payment_network_identifier and token_address == sub_task.token_address ) target_state = sub_task.target_state else: is_valid_subtask = False events = list() channel_state = None if is_valid_subtask: channel_state = views.get_channelstate_by_tokenaddress( node_state, payment_network_identifier, token_address, channel_identifier, ) if channel_state: iteration = target.state_transition( target_state, state_change, channel_state, block_number, ) events = iteration.events if iteration.new_state: sub_task = PaymentMappingState.TargetTask( payment_network_identifier, token_address, channel_identifier, iteration.new_state, ) node_state.payment_mapping.hashlocks_to_task[hashlock] = sub_task return TransitionResult(node_state, events)