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}
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}
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) return ch.settle_balance_onchain()
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
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
def close_channel(sender_addr, receiver_addr, channel_name): """ :param sender_addr: :param receiver_addr: :param channel_name: :return: """ sender, receiver = split_channel_name(channel_name) ch = Channel(sender, receiver) return ch.close()
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()
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
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
def sender_to_receiver(sender_addr, receiver_addr, channel_name, asset_type, count): """ :param sender_addr: String, the sender address :param receiver_addr: String, receiver's address :param channel_name: String, channel name :param asset_type: String, asset type should be symbol name , asset id should be configured in the configure.json :param count: String, depoist number in block chain :return: """ sender,receiver = split_channel_name(channel_name) ch = Channel(sender,receiver) if sender_addr == ch.sender and receiver_addr == ch.receiver: return ch.sender_to_receiver(float(count)) elif receiver_addr == ch.sender and sender_addr == ch.receiver: return ch.receiver_to_sender(float(count)) else: return {"error":"Address and Channelname not match"}
def sender_to_receiver(sender_addr, receiver_addr, channel_name, asset_type, count): """ :param sender_addr: :param receiver_addr: :param channel_name: :param asset_type: :param count: :return: """ sender, receiver = split_channel_name(channel_name) ch = Channel(sender, receiver) if sender_addr == ch.sender and receiver_addr == ch.receiver: return ch.sender_to_receiver(int(count)) elif receiver_addr == ch.sender and sender_addr == ch.receiver: return ch.receiver_to_sender(int(count)) else: return {"error": "Address and Channelname not match"}
def send_raw_transaction(sender_address, channel_name, hex): """ :param sender_address: :param channel_name: :param hex: :return: """ blockchain.send_raw_transection(hex) sender, receiver = split_channel_name(channel_name) ch = Channel(sender, receiver) sender_deposit = ch.sender_deposit receiver_deposit = ch.receiver_deposit sender_cache = ch.sender_deposit_cache receiver_cache = ch.receiver_deposit_cache ch.update_channel_deposit(sender_deposit=sender_deposit + sender_cache, receiver_deposit=receiver_deposit + receiver_cache) return ch.set_channel_open()
def get_history(channel_name, index, count): sender, receiver = split_channel_name(channel_name) ch = Channel(sender, receiver) result = ch.read_channel() return result[int(index):int(index) + int(count)]