def handle_channel_new(raiden: RaidenService, event: Event): data = event.event_data block_number = data['block_number'] args = data['args'] token_network_identifier = event.originating_contract transaction_hash = event.event_data['transaction_hash'] channel_identifier = args['channel_identifier'] participant1 = args['participant1'] participant2 = args['participant2'] is_participant = raiden.address in (participant1, participant2) # Raiden node is participant if is_participant: channel_proxy = raiden.chain.payment_channel( token_network_identifier, channel_identifier, ) token_address = channel_proxy.token_address() channel_state = get_channel_state( token_address, raiden.default_registry.address, token_network_identifier, raiden.config['reveal_timeout'], channel_proxy, block_number, ) new_channel = ContractReceiveChannelNew( transaction_hash=transaction_hash, token_network_identifier=token_network_identifier, channel_state=channel_state, block_number=block_number, ) raiden.handle_state_change(new_channel) partner_address = channel_state.partner_state.address if ConnectionManager.BOOTSTRAP_ADDR != partner_address: raiden.start_health_check_for(partner_address) # Raiden node is not participant of channel else: new_route = ContractReceiveRouteNew( transaction_hash=transaction_hash, token_network_identifier=token_network_identifier, channel_identifier=channel_identifier, participant1=participant1, participant2=participant2, block_number=block_number, ) raiden.handle_state_change(new_route) # A new channel is available, run the connection manager in case more # connections are needed connection_manager = raiden.connection_manager_for_token_network( token_network_identifier) retry_connect = gevent.spawn(connection_manager.retry_connect) raiden.add_pending_greenlet(retry_connect)
def handle_channel_new(raiden, event: Event): data = event.event_data token_network_identifier = event.originating_contract transaction_hash = event.event_data['transactionHash'] assert transaction_hash, 'A mined transaction must have the hash field' channel_identifier = data['channel_identifier'] participant1 = data['participant1'] participant2 = data['participant2'] is_participant = raiden.address in (participant1, participant2) # Raiden node is participant if is_participant: channel_proxy = raiden.chain.payment_channel( token_network_identifier, channel_identifier, ) token_address = channel_proxy.token_address() channel_state = get_channel_state( token_address, raiden.default_registry.address, token_network_identifier, raiden.config['reveal_timeout'], channel_proxy, event.event_data['block_number'], ) new_channel = ContractReceiveChannelNew( transaction_hash=transaction_hash, token_network_identifier=token_network_identifier, channel_state=channel_state, block_number=data['block_number'], ) raiden.handle_state_change(new_channel) partner_address = channel_state.partner_state.address if ConnectionManager.BOOTSTRAP_ADDR != partner_address: raiden.start_health_check_for(partner_address) # Raiden node is not participant of channel else: new_route = ContractReceiveRouteNew( transaction_hash=transaction_hash, token_network_identifier=token_network_identifier, channel_identifier=channel_identifier, participant1=participant1, participant2=participant2, block_number=data['block_number'], ) raiden.handle_state_change(new_route) # A new channel is available, run the connection manager in case more # connections are needed connection_manager = raiden.connection_manager_for_token_network(token_network_identifier) retry_connect = gevent.spawn(connection_manager.retry_connect) raiden.add_pending_greenlet(retry_connect)
def handle_channel_new(raiden, event): payment_network_identifier = raiden.default_registry.address data = event.event_data participant1 = data['participant1'] participant2 = data['participant2'] is_participant = raiden.address in (participant1, participant2) if is_participant: channel_proxy = raiden.chain.netting_channel(data['netting_channel']) token_address = channel_proxy.token_address() channel_state = get_channel_state( token_address, raiden.config['reveal_timeout'], channel_proxy, ) new_channel = ContractReceiveChannelNew(channel_state) state_change = ActionForTokenNetwork( payment_network_identifier, token_address, new_channel, ) raiden.handle_state_change(state_change) partner_address = channel_state.partner_state.address connection_manager = raiden.connection_manager_for_token(token_address) if ConnectionManager.BOOTSTRAP_ADDR != partner_address: raiden.start_health_check_for(partner_address) if connection_manager.wants_more_channels: gevent.spawn(connection_manager.retry_connect) # Start the listener *after* the channel is registered, to avoid None # exceptions (and not applying the event state change). # # TODO: install the filter on the same block or previous block in which # the channel state was queried raiden.blockchain_events.add_netting_channel_listener(channel_proxy) else: manager = raiden.chain.channel_manager(event.originating_contract) token_address = manager.token_address() new_route = ContractReceiveRouteNew( participant1, participant2, ) state_change = ActionForTokenNetwork( payment_network_identifier, token_address, new_route, ) raiden.handle_state_change(state_change)
def handle_channel_new(raiden, event, current_block_number): data = event.event_data token_network_identifier = event.originating_contract transaction_hash = event.event_data['transactionHash'] assert transaction_hash, 'A mined transaction must have the hash field' channel_identifier = data['channel_identifier'] participant1 = data['participant1'] participant2 = data['participant2'] is_participant = raiden.address in (participant1, participant2) # Raiden node is participant if is_participant: channel_proxy = raiden.chain.payment_channel( token_network_identifier, channel_identifier, ) token_address = channel_proxy.token_address() channel_state = get_channel_state( token_address, raiden.default_registry.address, token_network_identifier, raiden.config['reveal_timeout'], channel_proxy, event.event_data['block_number'], ) new_channel = ContractReceiveChannelNew( transaction_hash, token_network_identifier, channel_state, ) raiden.handle_state_change(new_channel, current_block_number) partner_address = channel_state.partner_state.address if ConnectionManager.BOOTSTRAP_ADDR != partner_address: raiden.start_health_check_for(partner_address) # Raiden node is not participant of channel else: new_route = ContractReceiveRouteNew( transaction_hash, token_network_identifier, channel_identifier, participant1, participant2, ) raiden.handle_state_change(new_route, current_block_number) # A new channel is available, run the connection manager in case more # connections are needed connection_manager = raiden.connection_manager_for_token_network( token_network_identifier) gevent.spawn(connection_manager.retry_connect)
def handle_channel_new(raiden, event, current_block_number): data = event.event_data token_network_identifier = event.originating_contract participant1 = data['participant1'] participant2 = data['participant2'] is_participant = raiden.address in (participant1, participant2) if is_participant: channel_proxy = raiden.chain.payment_channel( token_network_identifier, data['channel_identifier'], ) token_address = channel_proxy.token_address() channel_state = get_channel_state( token_address, token_network_identifier, raiden.config['reveal_timeout'], channel_proxy, event.event_data['block_number'], ) new_channel = ContractReceiveChannelNew( token_network_identifier, channel_state, ) raiden.handle_state_change(new_channel, current_block_number) partner_address = channel_state.partner_state.address connection_manager = raiden.connection_manager_for_token_network( token_network_identifier) if ConnectionManager.BOOTSTRAP_ADDR != partner_address: raiden.start_health_check_for(partner_address) gevent.spawn(connection_manager.retry_connect) # Start the listener *after* the channel is registered, to avoid None # exceptions (and not applying the event state change). # # TODO: install the filter on the same block or previous block in which # the channel state was queried raiden.blockchain_events.add_payment_channel_listener( channel_proxy, from_block=data['blockNumber'] + 1, ) else: new_route = ContractReceiveRouteNew( token_network_identifier, participant1, participant2, ) raiden.handle_state_change(new_route, current_block_number)
def handle_channel_new(raiden, event, current_block_number): data = event.event_data token_network_identifier = event.originating_contract transaction_hash = event.event_data['transactionHash'] assert transaction_hash, 'A mined transaction must have the hash field' channel_identifier = data['channel_identifier'] participant1 = data['participant1'] participant2 = data['participant2'] is_participant = raiden.address in (participant1, participant2) # Raiden node is participant if is_participant: channel_proxy = raiden.chain.payment_channel( token_network_identifier, channel_identifier, ) token_address = channel_proxy.token_address() channel_state = get_channel_state( token_address, raiden.default_registry.address, token_network_identifier, raiden.config['reveal_timeout'], channel_proxy, event.event_data['block_number'], ) new_channel = ContractReceiveChannelNew( transaction_hash, token_network_identifier, channel_state, ) raiden.handle_state_change(new_channel, current_block_number) partner_address = channel_state.partner_state.address if ConnectionManager.BOOTSTRAP_ADDR != partner_address: raiden.start_health_check_for(partner_address) # Start the listener *after* the channel is registered, to avoid None # exceptions (and not applying the event state change). # # TODO: install the filter on the same block or previous block in which # the channel state was queried raiden.blockchain_events.add_payment_channel_listener( channel_proxy, from_block=data['blockNumber'] + 1, ) # Raiden node is not participant of channel else: new_route = ContractReceiveRouteNew( transaction_hash, token_network_identifier, channel_identifier, participant1, participant2, ) raiden.handle_state_change(new_route, current_block_number) # A new channel is available, run the connection manager in case more # connections are needed connection_manager = raiden.connection_manager_for_token_network( token_network_identifier) gevent.spawn(connection_manager.retry_connect)
def handle_channel_new(raiden: "RaidenService", event: Event): data = event.event_data block_number = data["block_number"] block_hash = data["block_hash"] args = data["args"] token_network_identifier = event.originating_contract transaction_hash = event.event_data["transaction_hash"] channel_identifier = args["channel_identifier"] participant1 = args["participant1"] participant2 = args["participant2"] is_participant = raiden.address in (participant1, participant2) # Check if at least one of the implied participants is a LC handled by the node is_participant1_handled_lc = LightClientService.is_handled_lc( to_checksum_address(encode_hex(participant1)), raiden.wal) is_participant2_handled_lc = LightClientService.is_handled_lc( to_checksum_address(encode_hex(participant2)), raiden.wal) if is_participant or is_participant1_handled_lc or is_participant2_handled_lc: channel_proxy = raiden.chain.payment_channel( canonical_identifier=CanonicalIdentifier( chain_identifier=views.state_from_raiden(raiden).chain_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, )) token_address = channel_proxy.token_address() channel_state = get_channel_state( token_address=typing.TokenAddress(token_address), payment_network_identifier=raiden.default_registry.address, token_network_address=token_network_identifier, reveal_timeout=raiden.config["reveal_timeout"], payment_channel_proxy=channel_proxy, opened_block_number=block_number, ) # Swap our_state and partner_state in order to have the LC from our_side of the channel if is_participant1_handled_lc or is_participant2_handled_lc: if is_participant1_handled_lc: if participant1 != channel_state.our_state.address: channel_state.our_state, channel_state.partner_state = channel_state.partner_state, channel_state.our_state else: if participant2 != channel_state.our_state.address: channel_state.our_state, channel_state.partner_state = channel_state.partner_state, channel_state.our_state new_channel = ContractReceiveChannelNew( transaction_hash=transaction_hash, channel_state=channel_state, block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(new_channel) partner_address = channel_state.partner_state.address light_client_address = None if is_participant1_handled_lc: light_client_address = participant1 elif is_participant2_handled_lc: light_client_address = participant2 if ConnectionManager.BOOTSTRAP_ADDR != partner_address: raiden.start_health_check_for(partner_address, light_client_address) # Raiden node is not participant of channel. Lc are not participants else: new_route = ContractReceiveRouteNew( transaction_hash=transaction_hash, canonical_identifier=CanonicalIdentifier( chain_identifier=raiden.chain.network_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ), participant1=participant1, participant2=participant2, block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(new_route) # A new channel is available, run the connection manager in case more # connections are needed connection_manager = raiden.connection_manager_for_token_network( token_network_identifier) retry_connect = gevent.spawn(connection_manager.retry_connect) raiden.add_pending_greenlet(retry_connect)
def handle_channel_new(raiden: "RaidenService", event: Event): data = event.event_data block_number = data["block_number"] block_hash = data["block_hash"] args = data["args"] token_network_identifier = event.originating_contract transaction_hash = event.event_data["transaction_hash"] channel_identifier = args["channel_identifier"] participant1 = args["participant1"] participant2 = args["participant2"] is_participant = raiden.address in (participant1, participant2) # Raiden node is participant if is_participant: channel_proxy = raiden.chain.payment_channel( canonical_identifier=CanonicalIdentifier( chain_identifier=views.state_from_raiden(raiden).chain_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ) ) token_address = channel_proxy.token_address() channel_state = get_channel_state( token_address=typing.TokenAddress(token_address), payment_network_identifier=raiden.default_registry.address, token_network_address=token_network_identifier, reveal_timeout=raiden.config["reveal_timeout"], payment_channel_proxy=channel_proxy, opened_block_number=block_number, ) new_channel = ContractReceiveChannelNew( transaction_hash=transaction_hash, channel_state=channel_state, block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(new_channel) partner_address = channel_state.partner_state.address if ConnectionManager.BOOTSTRAP_ADDR != partner_address: raiden.start_health_check_for(partner_address) # Raiden node is not participant of channel else: new_route = ContractReceiveRouteNew( transaction_hash=transaction_hash, canonical_identifier=CanonicalIdentifier( chain_identifier=raiden.chain.network_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ), participant1=participant1, participant2=participant2, block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(new_route) # A new channel is available, run the connection manager in case more # connections are needed connection_manager = raiden.connection_manager_for_token_network(token_network_identifier) retry_connect = gevent.spawn(connection_manager.retry_connect) raiden.add_pending_greenlet(retry_connect)