Example #1
0
 def get_mian_block_num(self):
     """获取公链上的最新区块数"""
     try:
         ret = session_pool.get(self.IPCHAIN_BLOCK_API, timeout=30).json()
         block_num = int(ret.get('result'), 16)  # 16进制转int
     except Exception as e:
         logging.error('Get eth main chain block number error:{}'.format(e))
         return
     return block_num  # int
Example #2
0
    def eth_transaction_record(
        cls,
        address,
        last_timestamp,
        start_block=None,
        end_block=99999999,
        sort='asc',
    ):
        """查询账户交易记录"""
        if start_block is None:
            start_block = 0

        url = cls.IPCHAIN_TX_API.format(
            address=address,  # eth账户地址
            start_block=start_block,  # 开始区块
            end_block=end_block,  # 结束区块
            sort=sort,  # 排序 desc降序 asc 升序
            api_key=cls.IPCHAIN_API_KEY)  # eth api KEY
        try:
            ret = session_pool.get(url, timeout=10).json()
        except Exception as e:
            logging.error('Request IPCHAIN_TX_API error:{}'.format(str(e)))
            return

        status = ret.get('status')
        message = ret.get('message')
        records = ret.get('result')  # list
        if status == '1' and message == 'OK':
            for record in records:
                to_address = record['to']  # 是否为收款记录
                if to_address.lower() != address.lower():
                    continue
                current_timestamp = int(record['timeStamp'])  # 当前记录时间戳
                if last_timestamp > current_timestamp:
                    continue
                confirmations = int(record['confirmations'])  # 交易记录确认数
                if confirmations < 12:
                    continue
                contract_address = record['contractAddress']
                if contract_address != cls.IPCHAIN_CONTRACT_ADDRESS.lower():
                    continue
                amount = round(Decimal(record['value']) / (10**18), 7)
                if amount < 0.0000001:
                    continue
                else:
                    yield record
        else:
            if records is None:
                logging.error('Request IPCHAIN_TX_API error:{}'.format(
                    str(ret)))
                return
Example #3
0
 def get_mian_block_num(self):
     """获取公链上的最新区块数"""
     try:
         header = {
             'User-Agent':
             'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36',
         }
         ret = session_pool.get(self.USDT_BLOCK_NUM,
                                headers=header,
                                timeout=30).json()
         if ret is None:
             logging.error('Get usdt main chain block number error')
             return
         block_num = ret.get('data')
     except Exception as e:
         logging.error(
             'Get usdt main chain block number error:{}'.format(e))
         return
     return block_num  # int
Example #4
0
    def eth_transaction_record(
        cls,
        address,
        last_timestamp,
        start_block=None,
        end_block=99999999,
        sort='asc',
    ):
        """查询账户交易记录"""
        if start_block is None:
            start_block = 0

        url = cls.ETH_TX_API.format(
            address=address,  # eth账户地址
            start_block=start_block,  # 开始区块
            end_block=end_block,  # 结束区块
            sort=sort,  # 排序 desc降序 asc 升序
            api_key=cls.ETH_API_KEY)  # eth api KEY
        try:
            ret = session_pool.get(url, timeout=50).json()
        except Exception as e:
            logging.error(
                'Request ETH_TX_API error address:{},error:{},url:{}'.format(
                    address, str(e), url))
            # raise Exception('Request ETH_TX_API error')
            ret = None

        new_records = []
        if ret is None:
            return new_records

        status = ret.get('status')
        message = ret.get('message')
        records = ret.get('result')  # list
        if status == '1' and message == 'OK':
            for record in records:
                is_error = record['isError']  # 为0表示交易正常
                to_address = record['to']  # 是否为收款记录
                current_timestamp = int(record['timeStamp'])  # 当前记录时间戳
                confirmations = int(record['confirmations'])  # 交易记录确认数
                record_hash = record['hash']
                amount = round(Decimal(record['value']) / (10**18), 7)
                if is_error != '0':
                    continue
                if to_address.lower() != address.lower():
                    continue
                if last_timestamp > current_timestamp:
                    continue
                if Order.hash_is_exist(record_hash):
                    continue
                if amount < Decimal('0.0000001'):
                    continue
                if confirmations < 12:
                    break
                else:
                    new_records.append(record)
                    # yield record
        else:
            if records is None:
                logging.error(
                    'Request ETH_TX_API fail address:{} ret:{}, url:{}'.format(
                        address, str(ret), url))
                # raise Exception('Request ETH_TX_API error:{}'.format(str(ret)))
        return new_records