# -*- coding: utf-8 -*-
import logging
import random
import time
from collections import namedtuple, defaultdict

import gevent
from gevent.queue import Empty
from ethereum import slogging

from raiden.network.channelgraph import (
    get_best_routes,
)
from raiden.tasks import Task
from raiden.messages import (
    MediatedTransfer,
    RefundTransfer,
    RevealSecret,
    Secret,
    SecretRequest,
)
from raiden.settings import (
    DEFAULT_EVENTS_POLL_TIMEOUT,
)
from raiden.utils import lpex, pex, sha3

log = slogging.get_logger(__name__)  # pylint: disable=invalid-name
TIMEOUT = object()

TokenSwap = namedtuple('TokenSwap', (
    'identifier',
    'from_token',
    'from_amount',
    'from_nodeaddress',  # the node address of the owner of the `from_token`
    'to_token',
    'to_amount',
    'to_nodeaddress',  # the node address of the owner of the `to_token`
))
SwapKey = namedtuple('SwapKey', (
    'identifier',
    'from_token',
    'from_amount',