code: def leave(self, registry_address):
          
          with self.lock:
              self.initial_channel_target = 0
  
              channels_to_close = views.get_channelstate_open(
                  chain_state=views.state_from_raiden(self.raiden),
                  payment_network_id=registry_address,
                  token_address=self.token_address,
              )
  
              partner_addresses = [
                  channel_state.partner_state.address
                  for channel_state in channels_to_close
              ]
              self.api.channel_batch_close(
                  registry_address,
                  self.token_address,
                  partner_addresses,
              )
  
              channel_ids = [
                  channel_state.identifier
                  for channel_state in channels_to_close
              ]
  
              waiting.wait_for_settle(
                  self.raiden,
                  registry_address,
                  self.token_address,
                  channel_ids,
                  self.raiden.alarm.sleep_time,
              )
  
          return channels_to_close
docs: Leave the token network.
  
          This implies closing all channels and waiting for all channels to be
          settled.