Example #1
0
    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
Example #2
0
    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
Example #3
0
    def channel_qrcode(self, arguments):
        """

        :param arguments:
        :return:
        """
        enable = get_arg(arguments, 1)
        if enable.upper() not in ["ON", "OFF"]:
            console_log.error("should be on or off")
        self.qrcode = True if enable.upper() == "ON" else False
        console_log.console(
            "Qrcode opened") if self.qrcode else console_log.info(
                "Qrcode closed")
        return None
Example #4
0
    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")
Example #5
0
 def do_faucet(self):
     console_log.console(self.Wallet.address)
     request = {
         "jsonrpc": "2.0",
         "method": "transferTnc",
         "params":
         ["AGgZna4kbTXPm16yYZyG6RyrQz2Sqotno6", self.Wallet.address],
         "id": 1
     }
     result = requests.post(url=Configure['BlockChain']['NeoUrlEnhance'],
                            json=request)
     txid = result.json().get("result")
     if txid:
         print(txid)
     else:
         print(result.json())
     return
Example #6
0
    def channel_payment(self, arguments):
        """

        :param arguments:
        :return:
        """
        asset_type = get_arg(arguments, 1)
        if not check_support_asset_type(asset_type):
            console_log.error(
                "No support asset, current just support {}".format(
                    SupportAssetType.SupportAssetType))
            return None
        value = TrinityNumber(get_arg(arguments, 2).strip()).number
        if not value:
            console_log.error("command not give the count")
            return None
        try:
            if 0 >= value or not check_float_decimals(value, asset_type):
                console_log.error("value should not be less than 0")
                return None
        except ValueError:
            console_log.error("value format error")
            return None
        comments = " ".join(arguments[3:])
        comments = comments if comments else "None"
        if len(comments) > 128:
            console_log.error("comments length should be less than 128")
            return None
        try:
            hash_r, rcode = Payment.create_hr()
            Channel.add_payment(None, hash_r, rcode, value)
            paycode = Payment.generate_payment_code(self.Wallet.url,
                                                    asset_type, value, hash_r,
                                                    comments, True)
        except Exception as e:
            LOG.error(e)
            console_log.error("Get payment link error, please check the log")
            return None
        if self.qrcode:
            qrcode_terminal.draw(paycode, version=4)
        console_log.console(paycode)
        return None
Example #7
0
    def get_channel_list(address, **kwargs):
        """

        :param address:
        :param kwargs:
        :return:
        """
        filter_src = {'src_addr': address, 'magic': get_magic()}
        filter_dest = {'dest_addr': address, 'magic': get_magic()}

        output_text = ''
        for key, value in kwargs.items():
            if value:
                filter_dest.update({key: value})
                filter_src.update({key: value})

                output_text += ' {} {}'.format(key, value)

        console_log.info('Get Channels with Address {}{}'.format(
            address, output_text))

        if filter_src.get('peer'):
            filter_src.update({'dest_addr': filter_src.get('peer')})
            filter_src.pop('peer')

        channels = APIChannel.batch_query_channel(filters=filter_src)
        for ch in channels:
            balance = Channel.convert_balance(ch.balance)
            console_log.console('==' * 10, '\nChannelName:', ch.channel,
                                '\nState:', ch.state, '\nPeer:', ch.dest_addr,
                                '\nBalance:', json.dumps(balance, indent=1))

        channels = APIChannel.batch_query_channel(filters=filter_dest)
        for ch in channels:
            balance = Channel.convert_balance(ch.balance)
            console_log.console('==' * 10, '\nChannelName:', ch.channel,
                                '\nState:', ch.state, '\nPeer:', ch.src_addr,
                                '\nBalance:', json.dumps(balance, indent=1))
Example #8
0
    def channel_show(self, arguments):
        """

        :param arguments:
        :return:
        """
        subcommand = get_arg(arguments, 1)
        if not subcommand:
            self.help()
            return None
        if subcommand.upper() == "URI":
            console_log.console(self.Wallet.url)
        elif subcommand.upper() == "TRANS_HISTORY":
            channel_name = get_arg(arguments, 2)
            if channel_name is None:
                console_log.error("No provide channel")
                return None
            tx_his = Channel.batch_query_trade(channel_name)
            for tx in tx_his:
                console_log.console(tx)
            return None
        else:
            self.help()
        return None