Exemplo n.º 1
0
    def execute(self, block_height, channel_name='', hashcode=''):
        """

        :param block_height:
        :param channel_name:
        :param kwargs:
        :return:
        """
        super(ChannelHtlcUnlockedEvent, self).execute(block_height)

        # if monitor this event, update the htlc trade state to confirmed
        if channel_name and hashcode:
            try:
                htlc_trade = Channel.batch_query_trade(
                    channel_name,
                    filters={
                        'type': EnumTradeType.TRADE_TYPE_HTLC.name,
                        'hashcode': hashcode
                    })[0]
            except Exception as error:
                LOG.error('Htlc trade with HashR<{}> not found for channel<{}>. Exception: {}'\
                          .format(hashcode, channel_name, error))
            else:
                Channel.update_trade(
                    channel_name,
                    htlc_trade.nonce,
                    state=EnumTradeState.confirmed_onchain.name)
        else:
            LOG.error(
                'Error input parameters: channel <{}>, hashcode<{}>.'.format(
                    channel_name, hashcode))
Exemplo n.º 2
0
 def check_hashcode_used(cls, channel_name, hashcode):
     try:
         trade_record = Channel.batch_query_trade(
             channel_name, filters={'hashcode': hashcode})[0]
     except Exception as error:
         return True
     else:
         raise GoTo(
             EnumResponseStatus.RESPONSE_TRADE_HASHR_ALREADY_EXISTED,
             'HashR<{}> already used by trade with nonce<{}>'.format(
                 hashcode, trade_record.nonce))
Exemplo n.º 3
0
    def get_htlc_trade_by_hashr(cls, channel_name, hashcode):
        """

        :param channel_name:
        :param hashcode:
        :return:
        """
        try:
            return Channel.batch_query_trade(
                channel_name,
                filters={
                    'type': EnumTradeType.TRADE_TYPE_HTLC.name,
                    'hashcode': hashcode
                })[0]
        except Exception as error:
            raise GoTo(
                EnumResponseStatus.RESPONSE_TRADE_HASHR_NOT_FOUND,
                'Htlc trade not found by the HashR<{}> in channel<{}>'.format(
                    hashcode, channel_name))
Exemplo n.º 4
0
    def get_rcode(cls, channel_name, hashcode):
        """

        :param hashcode:
        :return:
        """
        if cls.is_hlock_to_rsmc(hashcode):
            htlc_trade = Channel.batch_query_trade(
                channel_name,
                filters={
                    'type': EnumTradeType.TRADE_TYPE_HTLC.name,
                    'hashcode': hashcode
                })
            if not htlc_trade:
                raise GoTo(
                    EnumResponseStatus.RESPONSE_TRADE_HASHR_NOT_FOUND,
                    'Htlc trade with HashR<{}> NOT found'.format(hashcode))
            htlc_trade = htlc_trade[0]
            return hashcode, htlc_trade.rcode
        else:
            return cls.get_default_rcode()
Exemplo n.º 5
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