bool fetch_block_header_impl(txn_guard_ptr txn, const Index& index, bdb_common_ptr common, message::block& serial_block) { protobuf::Block proto_block = common->fetch_proto_block(txn, index); if (!proto_block.IsInitialized()) return false; serial_block = protobuf_to_block_header(proto_block); return true; }
int get_block_hash(Db*, const Dbt*, const Dbt* data, Dbt* second_key) { std::stringstream ss(std::string( reinterpret_cast<const char*>(data->get_data()), data->get_size())); protobuf::Block proto_block; proto_block.ParseFromIstream(&ss); message::block serial_block = protobuf_to_block_header(proto_block); second_hash = hash_block_header(serial_block); second_key->set_data(second_hash.data()); second_key->set_size(second_hash.size()); return 0; }
bool bdb_common::reconstruct_block(txn_guard_ptr txn, const protobuf::Block& proto_block_header, message::block& result_block) { result_block = protobuf_to_block_header(proto_block_header); for (const std::string& raw_tx_hash: proto_block_header.transactions()) { protobuf::Transaction proto_tx; if (!proto_read(db_txs_, txn, raw_tx_hash, proto_tx)) return false; result_block.transactions.push_back(protobuf_to_transaction(proto_tx)); } return true; }
bool reconstruct_block(leveldb_common_ptr common, const protobuf::Block& proto_block_header, block_type& result_block) { result_block = protobuf_to_block_header(proto_block_header); for (const std::string& raw_tx_hash: proto_block_header.transactions()) { // Convert protobuf hash string into internal hash format. hash_digest tx_hash; BITCOIN_ASSERT(raw_tx_hash.size() == tx_hash.max_size()); std::copy(raw_tx_hash.begin(), raw_tx_hash.end(), tx_hash.begin()); // Fetch the actual transaction. protobuf::Transaction proto_tx = common->fetch_proto_transaction(tx_hash); if (!proto_tx.IsInitialized()) return false; result_block.transactions.push_back(protobuf_to_transaction(proto_tx)); } return true; }