def channel_htlc_unlock(self, arguments): """ :param arguments: :return: """ channel_name = get_arg(arguments, 1) hashcode = get_arg(arguments, 2) rcode = get_arg(arguments, 3) payment = get_arg(arguments, 4) payment = TrinityNumber(payment).number console_log.console( "Force to unlock htlc payment for channel {}".format(channel_name)) if channel_name: channel_event = ChannelHtlcUnlockEvent(channel_name, True) channel_event.register_args( EnumEventAction.EVENT_EXECUTE, invoker_uri=self.Wallet.url, channel_name=channel_name, hashcode=hashcode, rcode=rcode, invoker_key=self.Wallet._key.private_key_string, is_debug=True) ws_instance.register_event(channel_event) else: console_log.warn("No Channel Create") return
def channel_force_close(self, arguments): """ :param arguments: :return: """ channel_name = get_arg(arguments, 1) nonce = get_arg(arguments, 2, True) is_debug = False if 'debug' in arguments: is_debug = True console_log.console("Force to close channel {}".format(channel_name)) if channel_name: channel_event = ChannelForceSettleEvent(channel_name, True) channel_event.register_args( EnumEventAction.EVENT_EXECUTE, invoker_uri=self.Wallet.url, channel_name=channel_name, nonce=nonce, invoker_key=self.Wallet._key.private_key_string, is_debug=is_debug) ws_instance.register_event(channel_event) else: console_log.warn("No Channel Create") return
def configure_gas(self, arguments): """ :param arguments: :return: """ subcommand = get_arg(arguments) if not subcommand: self.help() return False if subcommand == 'configure': coef = get_arg(arguments, 1, True) if coef is None or 0 >= coef: console_log.warn( 'Please use number. Attention: much larger, much more expensive charge.' ) return False Client.set_gas_price(coef) elif subcommand == 'query': console_log.info('Current use {} GWEI'.format( Client.get_gas_price())) else: self.help() return
def channel_close(self, arguments): """ :param arguments: :return: """ channel_name = get_arg(arguments, 1) console_log.console("Closing channel {}".format(channel_name)) if channel_name: Channel.quick_close(channel_name, wallet=self.Wallet, cli=True, trigger=SettleMessage.create) else: console_log.warn("No Channel Create")
def sys_exit(f): console_log.warn( "Setup jsonRpc server error, please check if the port {} already opened" .format(port)) os.kill(os.getpgid(os.getpid()), signal.SIGKILL)
def _channel_noopen(self): console_log.warn( "Channel Function Can Not be Opened at Present, You can try again via channel enable" ) return False
def channel_trans(self, arguments): """ :param arguments: :return: """ if len(arguments) == 2: # payment code pay_code = get_arg(arguments, 1) result, info = Payment.decode_payment_code(pay_code) if result: receiver = info.get("uri") net_magic = info.get('net_magic') if not net_magic or net_magic != str(get_magic()): console_log.error("No correct net magic") return None hashcode = info.get("hashcode") asset_type = info.get("asset_type") # asset_type = get_asset_type_name(asset_type) count = info.get("payment") comments = info.get("comments") console_log.info("will pay {} {} to {} comments {}".format( TrinityNumber.convert_to_number(count), asset_type, receiver, comments)) else: console_log.error("The payment code is not correct") return else: receiver = get_arg(arguments, 1) asset_type = get_arg(arguments, 2) count = TrinityNumber(get_arg(arguments, 3).strip()).number hashcode = get_arg(arguments, 4) if not receiver or not asset_type or not count: self.help() return None asset_type = asset_type.upper() if check_support_asset_type( asset_type) else None if not asset_type: console_log.error( "No support asset, current just support {}".format( str(SupportAssetType.SupportAssetType))) return None if 0 >= count: console_log.warn('Not support negative number or zero.') return None # query channels by address channel_set = Channel.get_channel(self.Wallet.url, receiver, EnumChannelState.OPENED) if channel_set and channel_set[0]: Channel.transfer(channel_set[0].channel, self.Wallet, receiver, asset_type, count, cli=True, comments=hashcode, trigger=RsmcMessage.create) else: if not hashcode: console_log.error("No hashcode") return None try: message = { "MessageType": "GetRouterInfo", "Sender": self.Wallet.url, "Receiver": receiver, "AssetType": asset_type, "NetMagic": get_magic(), "MessageBody": { "AssetType": asset_type, "Value": count } } result = gate_way.get_router_info(message) routerinfo = json.loads(result.get("result")) except Exception as error: LOG.error( 'Exception occurred during get route info. Exception: {}'. format(error)) console_log.warning('No router was found.') return else: router = routerinfo.get("RouterInfo") if not router: LOG.error('Router between {} and {} was not found.'.format( self.Wallet.url, receiver)) console_log.error('Router not found for HTLC transfer.') return full_path = router.get("FullPath") LOG.info("Get Router {}".format(str(full_path))) next_jump = router.get("Next") LOG.info("Get Next {}".format(str(next_jump))) fee_router = [ i for i in full_path if i[0] not in (self.Wallet.url, receiver) ] if fee_router: # fee = reduce(lambda x, y:x+y,[TrinityNumber(str(i[1]).strip()).number for i in fee_router]) fee = reduce(lambda x, y: x + y, [float(i[1]) for i in fee_router]) else: fee = 0 fee = TrinityNumber(str(fee)).number count = int(count) + fee fee = fee / pow(10, 8) receiver = full_path[1][0] channel_set = Channel.get_channel(self.Wallet.url, receiver, EnumChannelState.OPENED) if not (channel_set and channel_set[0]): print('No OPENED channel was found for HTLC trade.') return LOG.info("Get Fee {}".format(fee)) answer = prompt( "You will pay extra fee {}. Do you wish continue this transaction? [Yes/No]>" .format(fee)) if answer.upper() in ["YES", "Y"]: channel_name = channel_set[0].channel Channel.transfer(channel_name, self.Wallet, receiver, asset_type, count, hashcode, router=full_path, next_jump=full_path[2][0], cli=True, trigger=HtlcMessage.create) else: return