コード例 #1
0
def update_deposit(address, channel_name, asset_type, value):
    """

    :param address:
    :param channel_name:
    :param asset_type:
    :param value:
    :return:
    """

    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:
            raw_tans = blockchain.NewTransection(asset_type, address,
                                                 Contract_addr, int(value))
            channel.update_channel_to_database(sender_deposit_cache=int(value))
    elif channel.receiver == address:
        raw_tans = blockchain.NewTransection(asset_type, address,
                                             Contract_addr, int(value))
        channel.update_channel_to_database(receiver_deposit_cache=int(value))
    else:
        return {"error": "channel name not match the address"}
    return {"channel_name": channel.channel_name, "trad_info": raw_tans}
コード例 #2
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}
コード例 #3
0
ファイル: manager.py プロジェクト: trinity-project/trinity
def regist_channel(sender_addr, receiver_addr, asset_type, deposit,
                   open_blockchain):
    """
    This func is to register channel
    :param sender_addr: String, the sender address
    :param receiver_addr: String, receiver's address
    :param asset_type: String, asset type should be symbol name , asset id should be configured in the configure.json
    :param deposit:  String, depoist number in block chain
    :param open_blockchain:  Open block chain number
    :return: Dictionary, {"channel_name":channel_name,
                "trad_info":raw_tans}
    """
    channel = Channel(sender_addr, receiver_addr)
    logger.info('start to register channel')
    if channel.qeury_channel():
        return {"error": "channel already exist"}
    else:
        channel_name = channel.create(sender_deposit=int(deposit),
                                      open_block_number=int(open_blockchain),
                                      settle_timeout=10)
        if not channel_name:
            return {
                "channel_name": None,
                "contract_address": None,
                "trad_info": "on pub key or not register pub key"
            }
        channel.qeury_channel()
        raw_tans, tx_id, state = blockchain.deposit_transaction(
            asset_type, sender_addr, channel.contract_address, int(deposit))
        if state:
            channel.update_channel_to_database(tx_id=tx_id,
                                               state=State.OPENING)
            return {
                "channel_name": channel_name,
                "contract_address": channel.contract_address,
                "trad_info": raw_tans
            }
        else:
            channel.delete_channel()
            channel.delete_channel_in_database()
            return {
                "channel_name": None,
                "contract_address": None,
                "trad_info": raw_tans
            }