예제 #1
0
def api_stats():
    max_target = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    blocks = BU.get_blocks()
    total_nonce = 0
    periods = []
    last_time = None
    for block in blocks:
        difficulty = max_target / int(block.get('target'), 16)
        if block.get('index') == 0:
            start_timestamp = block.get('time')
        if last_time:
            if int(block.get('time')) > last_time:
                periods.append({
                    'hashrate': (difficulty * 2**32) /
                    (int(block.get('time')) - last_time),
                    'index':
                    block.get('index'),
                    'elapsed_time': (int(block.get('time')) - last_time)
                })
        last_time = int(block.get('time'))
        total_nonce += block.get('nonce')
    sorted(periods, key=lambda x: x['index'])
    total_time_elapsed = int(block.get('time')) - int(start_timestamp)
    network_hash_rate = total_nonce / int(total_time_elapsed)
    return json.dumps(
        {
            'stats': {
                'network_hash_rate': network_hash_rate,
                'total_time_elapsed': total_time_elapsed,
                'total_nonce': total_nonce,
                'periods': periods
            }
        },
        indent=4)
예제 #2
0
파일: rpc.py 프로젝트: BadPirateX/yadacoin
def api_stats():
    max_target = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    config = current_app.config['yada_config']
    mongo = current_app.config['yada_mongo']
    blocks = BU.get_blocks(config, mongo)
    total_nonce = 0
    periods = []
    last_time = None
    for block in blocks:
        difficulty = max_target / int(block.get('target'), 16)
        if block.get('index') == 0:
            start_timestamp = block.get('time')
        if last_time:
            if int(block.get('time')) > last_time:
                periods.append({
                    'hashrate':
                    (((int(block.get('index')) / 144) * difficulty) * 2**32) /
                    600 / 100,
                    'index':
                    block.get('index'),
                    'elapsed_time': (int(block.get('time')) - last_time)
                })
        last_time = int(block.get('time'))
        total_nonce += block.get('nonce')
    sorted(periods, key=lambda x: x['index'])
    total_time_elapsed = int(block.get('time')) - int(start_timestamp)
    network_hash_rate = total_nonce / int(total_time_elapsed)
    return json.dumps(
        {
            'stats': {
                'network_hash_rate': network_hash_rate,
                'total_time_elapsed': total_time_elapsed,
                'total_nonce': total_nonce,
                'periods': periods
            }
        },
        indent=4)
예제 #3
0
def output(percent):
    sys.stdout.write(str(percent))  # write the next character
    sys.stdout.flush()  # flush stdout buffer (actual character display)
    sys.stdout.write(''.join(['\b' for i in range(len(percent))
                              ]))  # erase the last written char
    if float(percent) >= 100:
        print "\n\n\nDone!"


with open('config/config.json') as f:
    config = json.loads(f.read())
    config = Config.from_dict(config)

mongo = Mongo(config)
blocks = BU.get_blocks(config, mongo)
blockchain = Blockchain(blocks)
blockchain.verify(output)

res = mongo.db.blocks.aggregate([{
    "$unwind": "$transactions"
}, {
    "$project": {
        "_id": 0,
        "txn": "$transactions"
    }
}, {
    "$unwind": "$txn.inputs"
}, {
    "$project": {
        "_id": 0,
예제 #4
0
 def app_getblocks():
     return json.dumps([x for x in BU.get_blocks()])
예제 #5
0
def output(percent):
    sys.stdout.write(str(percent))  # write the next character
    sys.stdout.flush()  # flush stdout buffer (actual character display)
    sys.stdout.write(''.join(['\b' for i in range(len(percent))
                              ]))  # erase the last written char
    if float(percent) >= 100:
        print "\n\n\nDone!"


with open('config/config.json') as f:
    config = json.loads(f.read())
    Config.from_dict(config)

Mongo.init()
blocks = BU.get_blocks()
blockchain = Blockchain(blocks)
blockchain.verify(output)

res = Mongo.db.blocks.aggregate([{
    "$unwind": "$transactions"
}, {
    "$project": {
        "_id": 0,
        "txn": "$transactions"
    }
}, {
    "$unwind": "$txn.inputs"
}, {
    "$project": {
        "_id": 0,