Ejemplo n.º 1
0
def handle_recache_utxo(args):
    store = Storage(args.root)
    print('Removing all cached utxo')
    remove_prefix(store.db, b'ut/t/')
    print('Iterating blocks')
    count = 0
    for block in store.blocks():
        batch = rocksdb.WriteBatch()
        store.utxo_apply_block(block, batch)
        store.db.write(batch)
        count += 1
        print('%d' % count, end='\r')
Ejemplo n.º 2
0
def handle_stat_utxo(args):
    store = Storage(args.root)
    total_coin = 0
    balances = defaultdict(int)
    print('Start iterating utxos')
    for txin, txout in store.iter_utxo():
        total_coin += txout.c
        balances[txout.addr] += txout.c
    top_balances = itertools.islice(
        sorted(balances.items(), key=lambda t: t[1], reverse=True), 10)
    print('total_coin', total_coin / (10**6))
    print('top addresses:')
    for addr, c in top_balances:
        print(' ', base58.b58encode(addr).decode(), c / (10**6))
Ejemplo n.º 3
0
def handle_wallet_balance(args):
    cfg = load_wallet_config(args)
    root_key = binascii.unhexlify(cfg['root_key'])
    hdpass = derive_hdpassphase(xpriv_to_xpub(root_key))

    # iterate utxo.
    print('Searching for utxo...')
    store = Storage(args.root)
    txouts = []
    for txin, txout in store.iter_utxo():
        if Address.decode(txout.addr).get_derive_path(hdpass):
            txouts.append(txout)

    balance = sum(out.c for out in txouts)
    print('balance:', balance)
    print('details:')
    for out in txouts:
        print(base58.b58encode(out.addr), out.c)
Ejemplo n.º 4
0
def handle_sync(args):
    store = Storage(args.root)
    node = default_node(Transport().endpoint())
    try:
        sync(store, node, args.addr.encode(), args.genesis, args.genesis_prev)
    finally:
        # close database properly.
        store = None
        import gc
        gc.collect()
Ejemplo n.º 5
0
def handle_run(args):
    store = Storage(args.root)
    transport = Transport(args.listen)
    node = LogicNode(transport.endpoint(), store)
    if args.backdoor:
        from gevent.backdoor import BackdoorServer
        BackdoorServer(('127.0.0.1', args.backdoor),
                       banner="Hello from gevent backdoor!",
                       locals={
                           'node': node
                       }).start()
    gevent.wait()
Ejemplo n.º 6
0
        config.GENESIS['protocolConsts']['k'] * 10,
        config.GENESIS['ftsSeed'].encode(),
        sum(n for _, n in stakes),
        stakes,
    )
    return DecodedBlock([
        0,
        [[
            config.PROTOCOL_MAGIC,
            config.GENESIS_HASH,
            hash_data(leaders),
            [0, 0],
            {}
        ], leaders],
        {}
    ])


if __name__ == '__main__':
    config.use('mainnet')
    blk = genesis_block0()
    leaders = blk.leaders()

    from cardano.storage import Storage
    store = Storage('test_db')
    db_leaders = store.genesis_block(0).leaders()

    # compare with official result.
    for i in range(10):
        print(leaders[i], db_leaders[i])