Пример #1
0
async def chain_info(request):
    best_height = builder.best_block.height
    best_block = builder.best_block
    old_block_height = builder.best_chain[0].height - 1
    old_block_hash = hexlify(builder.get_block_hash(old_block_height)).decode()
    data = {'best': best_block.getinfo()}
    difficulty = dict()
    for consensus, ratio in V.BLOCK_CONSENSUSES.items():
        name = C.consensus2name[consensus]
        target = get_bits_by_hash(previous_hash=best_block.hash, consensus=consensus)[1]
        block_time = round(V.BLOCK_TIME_SPAN / ratio * 100)
        diff = (MAX_256_INT // target) / 100000000
        bias = get_bias_by_hash(previous_hash=best_block.previous_hash, consensus=consensus)
        difficulty[name] = {
            'number': consensus,
            'diff': round(diff / 100000000, 8),
            'bias': round(bias, 8),
            'fixed_diff': round(diff / bias, 8),
            'hashrate(kh/s)': round((MAX_256_INT//target)/block_time/1000, 3),
            'is_base': V.BLOCK_BASE_CONSENSUS == consensus,
        }
    data['mining'] = difficulty
    data['size'] = best_block.getsize()
    data['checkpoint'] = {'height': old_block_height, 'blockhash': old_block_hash}
    data['money_supply'] = GompertzCurve.calc_total_supply(best_height)
    data['total_supply'] = GompertzCurve.k
    return web_base.json_res(data)
Пример #2
0
async def chain_info(request):
    try:
        best_height = chain_builder.best_block.height
        best_block = chain_builder.best_block
        old_block_height = chain_builder.best_chain[0].height - 1
        old_block_hash = chain_builder.get_block_hash(old_block_height).hex()
        data = {'best': best_block.getinfo()}
        difficulty = dict()
        for consensus, ratio in V.BLOCK_CONSENSUSES.items():
            name = C.consensus2name[consensus]
            bits, target = get_bits_by_hash(previous_hash=best_block.hash,
                                            consensus=consensus)
            target = float(target)
            block_time = round(V.BLOCK_TIME_SPAN / ratio * 100)
            diff = round(DEFAULT_TARGET / target, 8)
            bias = get_bias_by_hash(previous_hash=best_block.previous_hash,
                                    consensus=consensus)
            difficulty[name] = {
                'number':
                consensus,
                'bits':
                bits.to_bytes(4, 'big').hex(),
                'diff':
                round(diff, 8),
                'bias':
                round(bias, 8),
                'fixed_diff':
                round(diff / bias, 8),
                'hashrate(kh/s)':
                round((MAX_256_FLOAT / target) / block_time / 1000, 3)
            }
        data['mining'] = difficulty
        data['size'] = best_block.size
        data['checkpoint'] = {
            'height': old_block_height,
            'blockhash': old_block_hash
        }
        data['money_supply'] = GompertzCurve.calc_total_supply(best_height)
        data['total_supply'] = GompertzCurve.k
        if F_ADD_CASHE_INFO:
            data['cashe'] = {
                'get_bits_by_hash': str(get_bits_by_hash.cache_info()),
                'get_bias_by_hash': str(get_bias_by_hash.cache_info())
            }
        return utils.json_res(data)
    except Exception:
        return utils.error_res()
Пример #3
0
 def bias(self):
     if not self._bias:
         from bc4py.chain.difficulty import get_bias_by_hash  # not good?
         self._bias = get_bias_by_hash(self.previous_hash, self.flag)
     return self._bias