cmd/check_senders.cpp
// Prints out info of block's transactions with senders
Prints out info of block's transactions with senders
Prints out info of block ' s transactions with senders
int do_verify(app_options_t& options) {
    if (options.block_to == UINT32_MAX) options.block_to = options.block_from;
    try {
        lmdb::DatabaseConfig db_config{options.datadir};
        db_config.map_size = options.mapsize;
        std::shared_ptr<lmdb::Environment> lmdb_env{lmdb::get_env(db_config)};
        std::unique_ptr<lmdb::Transaction> lmdb_txn{lmdb_env->begin_ro_transaction()};
        std::unique_ptr<lmdb::Table> lmdb_headers{lmdb_txn->open(db::table::kBlockHeaders)};
        std::unique_ptr<lmdb::Table> lmdb_bodies{lmdb_txn->open(db::table::kBlockBodies)};
        std::unique_ptr<lmdb::Table> lmdb_senders{lmdb_txn->open(db::table::kSenders)};
        size_t count{0};
        lmdb::err_handler(lmdb_senders->get_rcount(&count));
        if (!count) throw std::logic_error("Senders table is empty. Is the sync completed ?");
        lmdb::err_handler(lmdb_bodies->get_rcount(&count));
        if (!count) throw std::logic_error("Block bodies table is empty. Is the sync completed ?");
        lmdb::err_handler(lmdb_headers->get_rcount(&count));
        if (!count) throw std::logic_error("Headers table is empty. Is the sync completed ?");
        MDB_val key, data;
        lmdb::err_handler(lmdb_senders->get_last(&key, &data));
        ByteView v{static_cast<uint8_t*>(key.mv_data), key.mv_size};
        uint64_t most_recent_sender{boost::endian::load_big_u64(&v[0])};
        if (options.block_from > most_recent_sender) {
            throw std::logic_error("Selected block beyond collected senders");
        }
        for (uint32_t block_num = options.block_from; block_num <= options.block_to; block_num++) {
            std::cout << "Reading block #" << block_num << std::endl;
            std::optional<BlockWithHash> bh{db::read_block(*lmdb_txn, block_num, true)};
            if (!bh) {
                throw std::logic_error("Could not locate block #" + std::to_string(block_num));
            }
            if (!bh->block.transactions.size()) {
                std::cout << "Block has 0 transactions" << std::endl;
                continue;
            }
            std::cout << std::right << std::setw(4) << std::setfill(' ') << "Tx"
                      << " " << std::left << std::setw(66) << std::setfill(' ') << "Hash"
                      << " " << std::left << std::setw(42) << std::setfill(' ') << "From"
                      << " " << std::left << std::setw(42) << std::setfill(' ') << "To" << std::endl;
            std::cout << std::right << std::setw(4) << std::setfill('-') << ""
                      << " " << std::left << std::setw(66) << std::setfill('-') << ""
                      << " " << std::left << std::setw(42) << std::setfill('-') << ""
                      << " " << std::left << std::setw(42) << std::setfill('-') << "" << std::endl;
            for (size_t i = 0; i < bh->block.transactions.size(); i++) {
                Bytes rlp{};
                rlp::encode(rlp, bh->block.transactions.at(i),  false, {});
                ethash::hash256 hash{ethash::keccak256(rlp.data(), rlp.length())};
                ByteView bv{hash.bytes, 32};
                std::cout << std::right << std::setw(4) << std::setfill(' ') << i << " 0x" << to_hex(bv) << " 0x"
                          << to_hex(*(bh->block.transactions.at(i).from)) << " 0x"
                          << to_hex(*(bh->block.transactions.at(i).to)) << std::endl;
            }
            std::cout << std::endl;
        }
    } catch (const std::logic_error& ex) {
        std::cout << ex.what() << std::endl;
        return -1;
    } catch (const std::exception& ex) {
        std::cout << "Unexpected error : " << ex.what() << std::endl;
        return -1;
    }
    return 0;
}
int do_verify ( app_options_t & options ) { if ( options . block_to == UINT32_MAX ) options . block_to = options . block_from ; try { lmdb :: DatabaseConfig db_config { options . datadir } ; db_config . map_size = options . mapsize ; std :: shared_ptr < lmdb :: Environment > lmdb_env { lmdb :: get_env ( db_config ) } ; std :: unique_ptr < lmdb :: Transaction > lmdb_txn { lmdb_env -> begin_ro_transaction ( ) } ; std :: unique_ptr < lmdb :: Table > lmdb_headers { lmdb_txn -> open ( db :: table :: kBlockHeaders ) } ; std :: unique_ptr < lmdb :: Table > lmdb_bodies { lmdb_txn -> open ( db :: table :: kBlockBodies ) } ; std :: unique_ptr < lmdb :: Table > lmdb_senders { lmdb_txn -> open ( db :: table :: kSenders ) } ; size_t count { 0 } ; lmdb :: err_handler ( lmdb_senders -> get_rcount ( & count ) ) ; if ( ! count ) throw std :: logic_error ( " " ) ; lmdb :: err_handler ( lmdb_bodies -> get_rcount ( & count ) ) ; if ( ! count ) throw std :: logic_error ( " " ) ; lmdb :: err_handler ( lmdb_headers -> get_rcount ( & count ) ) ; if ( ! count ) throw std :: logic_error ( " " ) ; MDB_val key , data ; lmdb :: err_handler ( lmdb_senders -> get_last ( & key , & data ) ) ; ByteView v { static_cast < uint8_t * > ( key . mv_data ) , key . mv_size } ; uint64_t most_recent_sender { boost :: endian :: load_big_u64 ( & v [ 0 ] ) } ; if ( options . block_from > most_recent_sender ) { throw std :: logic_error ( " " ) ; } for ( uint32_t block_num = options . block_from ; block_num <= options . block_to ; block_num ++ ) { std :: cout << " " << block_num << std :: endl ; std :: optional < BlockWithHash > bh { db :: read_block ( * lmdb_txn , block_num , true ) } ; if ( ! bh ) { throw std :: logic_error ( " " + std :: to_string ( block_num ) ) ; } if ( ! bh -> block . transactions . size ( ) ) { std :: cout << " " << std :: endl ; continue ; } std :: cout << std :: right << std :: setw ( 4 ) << std :: setfill ( ' ' ) << " " << " " << std :: left << std :: setw ( 66 ) << std :: setfill ( ' ' ) << " " << " " << std :: left << std :: setw ( 42 ) << std :: setfill ( ' ' ) << " " << " " << std :: left << std :: setw ( 42 ) << std :: setfill ( ' ' ) << " " << std :: endl ; std :: cout << std :: right << std :: setw ( 4 ) << std :: setfill ( ' ' ) << " " << " " << std :: left << std :: setw ( 66 ) << std :: setfill ( ' ' ) << " " << " " << std :: left << std :: setw ( 42 ) << std :: setfill ( ' ' ) << " " << " " << std :: left << std :: setw ( 42 ) << std :: setfill ( ' ' ) << " " << std :: endl ; for ( size_t i = 0 ; i < bh -> block . transactions . size ( ) ; i ++ ) { Bytes rlp { } ; rlp :: encode ( rlp , bh -> block . transactions . at ( i ) , false , { } ) ; ethash :: hash256 hash { ethash :: keccak256 ( rlp . data ( ) , rlp . length ( ) ) } ; ByteView bv { hash . bytes , 32 } ; std :: cout << std :: right << std :: setw ( 4 ) << std :: setfill ( ' ' ) << i << " " << to_hex ( bv ) << " " << to_hex ( * ( bh -> block . transactions . at ( i ) . from ) ) << " " << to_hex ( * ( bh -> block . transactions . at ( i ) . to ) ) << std :: endl ; } std :: cout << std :: endl ; } } catch ( const std :: logic_error & ex ) { std :: cout << ex . what ( ) << std :: endl ; return -1 ; } catch ( const std :: exception & ex ) { std :: cout << " " << ex . what ( ) << std :: endl ; return -1 ; } return 0 ; }
Prints out info of block's transactions with senders
Prints out info of block ' s transactions with senders
// Adjust params // Open db and start transaction // Verify requested block is not beyond what we already have in chaindb /*read_senders=*/ /*forsigning*/