Size prepend strings

This commit is contained in:
Oran Juice 2015-02-14 18:44:00 +05:30
parent d75b5dd60b
commit f810f5aa9b
No known key found for this signature in database
GPG Key ID: 71C5AF46CCB28124
2 changed files with 13 additions and 2 deletions

View File

@ -104,7 +104,7 @@ namespace IPC
char *block_id = (char*)zlist_first(z_block_ids);
while (block_id) {
crypto::hash hash;
memcpy(hash.data, block_id, crypto::HASH_SIZE);
memcpy(hash.data, block_id + 1, crypto::HASH_SIZE);
block_ids.push_back(hash);
block_id = (char*)zlist_next(z_block_ids);
}

View File

@ -339,11 +339,22 @@ void wallet2::pull_blocks(uint64_t start_height, size_t& blocks_added)
blocks_added = 0;
std::list<crypto::hash> block_ids;
get_short_chain_history(block_ids);
std::list<char*> size_prepended_block_ids;
zlist_t *list = zlist_new();
for (std::list<crypto::hash>::iterator it = block_ids.begin(); it != block_ids.end(); it++) {
zlist_append(list, it->data);
char *block_id = new char[crypto::HASH_SIZE + 1];
block_id[0] = crypto::HASH_SIZE;
memcpy(block_id + 1, it->data, crypto::HASH_SIZE);
size_prepended_block_ids.push_back(block_id);
}
for (std::list<char*>::iterator it = size_prepended_block_ids.begin(); it != size_prepended_block_ids.end(); it++) {
zlist_append(list, *it);
}
int rc = wap_client_blocks(client, &list, start_height);
for (std::list<char*>::iterator it = size_prepended_block_ids.begin(); it != size_prepended_block_ids.end(); it++) {
delete *it;
}
zlist_destroy(&list);
THROW_WALLET_EXCEPTION_IF(rc != 0, error::no_connection_to_daemon, "getblocks");
uint64_t status = wap_client_status(client);