in service/http_server/crow_service.cpp [394:477]
std::string CrowService::GetAllBlocks(int batch_size, bool increment_txn_count,
bool make_sublists) {
int min_seq = 1;
bool full_batches = true;
std::string values = "[\n";
bool first_batch = true;
while (full_batches) {
std::string cur_batch_str = "";
if (!first_batch)
cur_batch_str.append(",\n");
if (batch_size > 1 && make_sublists)
cur_batch_str.append("[");
first_batch = false;
int max_seq = min_seq + batch_size - 1;
auto resp = txn_client_.GetTxn(min_seq, max_seq);
absl::StatusOr<std::vector<std::pair<uint64_t, std::string>>> GetTxn(
uint64_t min_seq, uint64_t max_seq);
if (!resp.ok()) {
LOG(ERROR) << "get replica txn fail";
return "";
};
int cur_size = 0;
bool first_batch_element = true;
for (auto &txn : *resp) {
BatchUserRequest request;
KVRequest kv_request;
cur_size++;
if (request.ParseFromString(txn.second)) {
if (!first_batch_element) cur_batch_str.append(",");
first_batch_element = false;
// id
uint64_t seq = txn.first;
cur_batch_str.append("{\"id\": " + std::to_string(seq));
// number
cur_batch_str.append(", \"number\": \"" + std::to_string(seq) + "\"");
// transactions
cur_batch_str.append(", \"transactions\": [");
bool first_transaction = true;
for (auto &sub_req : request.user_requests()) {
kv_request.ParseFromString(sub_req.request().data());
std::string kv_request_json = ParseKVRequest(kv_request);
if (!first_transaction)
cur_batch_str.append(",");
first_transaction = false;
cur_batch_str.append(kv_request_json);
cur_batch_str.append("\n");
if (increment_txn_count) num_transactions_++;
}
cur_batch_str.append("]"); // close transactions list
// size
cur_batch_str.append(", \"size\": " +
std::to_string(request.ByteSizeLong()));
// createdAt
uint64_t createtime = request.createtime();
cur_batch_str.append(", \"createdAt\": \"" +
ParseCreateTime(createtime) + "\"");
}
cur_batch_str.append("}\n");
}
full_batches = cur_size == batch_size;
if (batch_size > 1 && make_sublists)
cur_batch_str.append("]");
if (cur_size > 0)
values.append(cur_batch_str);
min_seq += batch_size;
}
values.append("\n]\n");
return values;
}