From f810f5aa9bacd39b3e8c0bfc3d268341ab49e5c2 Mon Sep 17 00:00:00 2001 From: Oran Juice Date: Sat, 14 Feb 2015 18:44:00 +0530 Subject: [PATCH] Size prepend strings --- src/ipc/daemon_ipc_handlers.cpp | 2 +- src/wallet/wallet2.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ipc/daemon_ipc_handlers.cpp b/src/ipc/daemon_ipc_handlers.cpp index d12efde86..141ae234c 100644 --- a/src/ipc/daemon_ipc_handlers.cpp +++ b/src/ipc/daemon_ipc_handlers.cpp @@ -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); } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index e7c6d842f..9644384d1 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -339,11 +339,22 @@ void wallet2::pull_blocks(uint64_t start_height, size_t& blocks_added) blocks_added = 0; std::list block_ids; get_short_chain_history(block_ids); + std::list size_prepended_block_ids; zlist_t *list = zlist_new(); for (std::list::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::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::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);