Esempio n. 1
0
def get_channel_state(address):
    """

    :param sender_addr:
    :param receiver_addr:
    :return:
    """
    channel_infos = []
    channels = get_channelnames_via_address(address)
    for channel in channels:
        ch = Channel(channel.sender, channel.receiver)
        channel_detail = [{
            "address": ch.sender,
            "deposit": ch.sender_deposit,
            "balance": ch.get_address_balance(ch.sender)
        }, {
            "address": ch.receiver,
            "deposit": ch.receiver_deposit,
            "balance": ch.get_address_balance(ch.receiver)
        }]
        channel_info = {
            "channel_name": ch.channel_name,
            "channel_state": str(State(ch.stateinDB)),
            "open_block": ch.open_block_number,
            "tx_info": channel_detail
        }
        channel_infos.append(channel_info)
    return channel_infos
Esempio n. 2
0
def get_channel_state(address):
    """
    :param sender_addr: String, the sender address
    :param receiver_addr: String, receiver's address
    :return: Dictionary, the chnnnel information
    """
    channel_infos =[]
    channels = get_channelnames_via_address(address)
    for channel in channels:
        channel_detail =[]
        ch = Channel(channel.sender, channel.receiver)
        sender_info = {"address": ch.sender,
                           "deposit": ch.sender_deposit,
                           "balance": ch.get_address_balance(ch.sender) if ch.get_address_balance(ch.sender) else 0}
        recevier_info = {"address": ch.receiver,
                           "deposit": ch.receiver_deposit,
                           "balance": ch.get_address_balance(ch.receiver) if ch.get_address_balance(ch.receiver) else 0}
        if ch.sender == address:
            channel_detail.append(sender_info)
            channel_detail.append(recevier_info)
        else:
            channel_detail.append(recevier_info)
            channel_detail.append(sender_info)
        channel_info  = {
            "channel_name": ch.channel_name,
            "channel_state": str(State(ch.stateinDB)),
            "open_block":ch.open_block_number,
             "tx_info": channel_detail
        }
        channel_infos.append(channel_info)
    return channel_infos
Esempio n. 3
0
def depoist_out(address, value):
    channel_name = get_channelnames_via_address(address)
    if channel_name:
        sender, receiver = split_channel_name(channel_name)
        ch = Channel(sender, receiver)
        ch.delete_channle_in_database()
        ch.delete_channel()
    else:
        return None
    return address
Esempio n. 4
0
def depoistout(address, value):
    channels = get_channelnames_via_address(address)
    success_channel = []
    for channel in channels:
        if channel.state == State.SETTLING.value:
            sender, receiver = split_channel_name(channel.channel_name)
            ch = Channel(sender, receiver)
            ch.close()
            success_channel.append(channel.channel_name)
        else:
            continue
Esempio n. 5
0
def depoist_in(address, value):
    channel_name = get_channelnames_via_address(address)
    if channel_name:
        sender, receiver = split_channel_name(channel_name)
        ch = Channel(sender, receiver)
        if address == sender and ch.stateinDB == State.OPENING and value == ch.sender_deposit_cache:
            ch.update_channel_state(State.OPEN)
        elif address == receiver and ch.stateinDB == State.OPENING and value == ch.receiver_deposit_cache:
            ch.update_channel_state(State.OPEN)
        else:
            return None
    else:
        return None
    return address
Esempio n. 6
0
def depositin(address, value):
    channels = get_channelnames_via_address(address)
    success_channel = []
    for channel in channels:
        print(channel.channel_name)
        sender, receiver = split_channel_name(channel.channel_name)
        ch = Channel(sender, receiver)
        # if address == sender and value == ch.sender_deposit_cache:
        if address == sender:
            ch.set_channel_open()
            success_channel.append(channel.channel_name)
        # elif address == receiver and value == ch.receiver_deposit_cache:
        elif address == receiver:
            ch.set_channel_open()
            success_channel.append(channel.channel_name)
        else:
            continue
Esempio n. 7
0
def _get_channel_states_info(address):
    channel_infos = []
    channels = get_channelnames_via_address(address)
    for channel in channels:
        channel_detail = []
        ch = Channel(channel.sender, channel.receiver)
        sender_info = {
            "address":
            ch.sender,
            "deposit":
            ch.sender_deposit,
            "balance":
            ch.get_address_balance(ch.sender)
            if ch.get_address_balance(ch.sender) else 0
        }
        recevier_info = {
            "address":
            ch.receiver,
            "deposit":
            ch.receiver_deposit,
            "balance":
            ch.get_address_balance(ch.receiver)
            if ch.get_address_balance(ch.receiver) else 0
        }
        if ch.sender == address:
            channel_detail.append(sender_info)
            channel_detail.append(recevier_info)
        else:
            channel_detail.append(recevier_info)
            channel_detail.append(sender_info)
        channel_info = {
            "channel_name": ch.channel_name,
            "channel_state": str(State(ch.stateinDB)),
            "open_block": ch.open_block_number,
            "contract_address": ch.contract_address,
            "tx_info": channel_detail
        }
        channel_infos.append(channel_info)
    return channel_infos