Beispiel #1
0
    def create(sender,
               receiver,
               channel_name,
               asset_type,
               payment,
               nonce,
               comments=''):
        message = PaymentLinkAck.create_message_header(
            sender, receiver, PaymentLinkAck._message_name, channel_name,
            asset_type, nonce)

        hashcode, rcode = Payment.create_hr()
        Channel.add_payment(channel_name,
                            hashcode=hashcode,
                            rcode=rcode,
                            payment=payment)
        pycode = Payment.generate_payment_code(sender, asset_type, payment,
                                               hashcode, comments)

        message = message.message_header
        message_body = {'PaymentLink': pycode}
        message.update({'MessageBody': message_body})
        message.update({'Status': EnumResponseStatus.RESPONSE_OK.name})
        if comments:
            message.update({'Comments': comments})
        Message.send(message)
        pass
Beispiel #2
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
Beispiel #3
0
    def json_rpc_method_handler(self, method, params):

        # if method == "SendRawtransaction":
        #     return transaction.TrinityTransaction.sendrawtransaction(params[0])

        if method == "TransactionMessage":
            LOG.info("<-- {}".format(params))
            return MessageList.append(params)

        # elif method == "FunderTransaction":
        #     return transaction.funder_trans(params)

        # elif method == "FunderCreate":
        #     return transaction.funder_create(params)

        # elif method == "RSMCTransaction":
        #     return transaction.rsmc_trans(params)
        #
        # elif method == "HTLCTransaction":
        #     return transaction.hltc_trans(params)

        elif method == "SyncWallet":
            from wallet import prompt as PR
            wallet_info = PR.CurrentLiveWallet.wallet_info()
            return {"MessageType": "SyncWallet", "MessageBody": wallet_info}

        elif method == "GetChannelState":
            return {
                'MessageType': 'GetChannelState',
                'MessageBody': get_channel_via_name(params)
            }

        elif method == "GetChannelList":
            LOG.debug("GetChannelList")
            from wallet.utils import get_wallet_info
            if CurrentLiveWallet.Wallet:
                try:
                    channel_list = query_channel_list(
                        CurrentLiveWallet.Wallet.url)
                except Exception as e:
                    channel_list = None
                    LOG.error(e)
                wallet_info = get_wallet_info(CurrentLiveWallet.Wallet)

                return {
                    "MessageType": "GetChannelList",
                    "MessageBody": {
                        "Channel": channel_list,
                        "Wallet": wallet_info
                    }
                }
            else:
                return {
                    "MessageType": "GetChannelList",
                    "MessageBody": {
                        "Error": "Wallet No Open"
                    }
                }

        elif method == "GetPayment":
            asset_type = params[0]
            payment = params[1]

            try:
                hash_r, rcode = Payment.create_hr()
                pycode = Payment.generate_payment_code(
                    CurrentLiveWallet.Wallet.url, asset_type, payment, hash_r)
                Channel.add_payment(None, hash_r, rcode, payment)
            except Exception as e:
                LOG.error(e)
                pycode = None

            return {
                "MessageType": "GetPaymentAck",
                "MessageBody": {
                    "pycode": pycode
                }
            }

        elif method == "GetWalletStatistics":
            try:
                statistics_data = APIStatistics.query_statistics(params[0])[0]

            except Exception as e:
                LOG.error(e)

                return {
                    "MessageType": "GetWalletStatisticsAck",
                    "MessageBody": {
                        "Error": "data is null"
                    }
                }
            else:

                return {
                    "MessageType": "GetWalletStatisticsAck",
                    "MessageBody": json.loads(statistics_data.__str__())
                }