Ejemplo n.º 1
0
def update_deposit(address, channel_name, asset_type, value):
    """

    :param address: String , address
    :param channel_name: String, channel name
    :param asset_type: String, asset type
    :param value: String , the deposit number
    :return: {"channel_name": channel.channel_name,
            "trad_info": raw_tans}
    """

    sender, receiver = split_channel_name(channel_name)
    channel = Channel(sender, receiver)

    if channel.sender == address:
        if channel.state_in_database != State.OPEN:
            return {"channel_name": channel.channel_name,
                    "trad_info": "Channel exist but in state %s" % str(State(channel.state_in_database))}
        else:
            channel.update_channel_to_database(sender_deposit_cache=float(value))
            raw_tans ,state= blockchain.NewTransection(asset_type, address, Contract_addr, value)
            if state:
                channel.update_channel_state(state = State.UPDATING)
    elif channel.receiver == address:
        channel.update_channel_to_database(receiver_deposit_cache=float(value))
        raw_tans, state = blockchain.NewTransection(asset_type, address, Contract_addr, value)
        if state:
            channel.update_channel_state(state=State.UPDATING)
    else:
        return {"error":"channel name not match the address"}
    return {"channel_name": channel.channel_name,
            "trad_info": raw_tans}
Ejemplo n.º 2
0
def close_channel(sender_addr, receiver_addr,channel_name):
    """
    :param sender_addr: String, the sender address
    :param receiver_addr: String, receiver's address
    :param channel_name: String, channel name
    :return:
    """
    sender, receiver = split_channel_name(channel_name)
    ch = Channel(sender, receiver)
    ch.update_channel_state(State.SETTLING)
    return ch.settle_banlace_onblockchain()
Ejemplo n.º 3
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