Skip to content

Commit

Permalink
Api for mobile client
Browse files Browse the repository at this point in the history
  • Loading branch information
BixBite-project committed Nov 28, 2018
1 parent 5479cf3 commit 9c3f4f1
Show file tree
Hide file tree
Showing 18 changed files with 1,032 additions and 707 deletions.
8 changes: 8 additions & 0 deletions contrib/epee/include/storages/portable_storage_from_bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace epee
storage_entry load_storage_entry();
void read(section& sec);
void read(std::string& str);
void read(array_entry &ae);
private:
struct recursuion_limitation_guard
{
Expand Down Expand Up @@ -114,6 +115,7 @@ namespace epee
void throwable_buffer_reader::read(t_pod_type& pod_val)
{
RECURSION_LIMITATION();
static_assert(std::is_pod<t_pod_type>::value, "POD type expected");
read(&pod_val, sizeof(pod_val));
}

Expand Down Expand Up @@ -277,5 +279,11 @@ namespace epee
m_ptr+=len;
m_count -= len;
}
inline
void throwable_buffer_reader::read(array_entry &ae)
{
RECURSION_LIMITATION();
CHECK_AND_ASSERT_THROW_MES(false, "Reading array entry is not supported");
}
}
}
21 changes: 8 additions & 13 deletions src/blockchain_utilities/blockchain_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <vector>

#include <boost/filesystem.hpp>
#include "bootstrap_file.h"
Expand Down Expand Up @@ -290,7 +291,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,

std::string str1;
char buffer1[1024];
char buffer_block[BUFFER_SIZE];
std::vector<char> buffer_block;
block b;
transaction tx;
int quit = 0;
Expand Down Expand Up @@ -352,20 +353,14 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
}
LOG_PRINT_L3("chunk_size: " << chunk_size);

if (chunk_size > BUFFER_SIZE)
{
LOG_PRINT_L0("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
throw std::runtime_error("Aborting: chunk size exceeds buffer size");
}
if (chunk_size > 100000)
{
LOG_PRINT_L0("NOTE: chunk_size " << chunk_size << " > 100000");
}
else if (chunk_size == 0) {
if (chunk_size == 0) {
LOG_PRINT_L0("ERROR: chunk_size == 0");
return 2;
}
import_file.read(buffer_block, chunk_size);
if(buffer_block.size() < chunk_size){
buffer_block.resize(chunk_size);
}
import_file.read(buffer_block.data(), chunk_size);
if (! import_file) {
LOG_PRINT_L0("ERROR: unexpected end of file: bytes read before error: "
<< import_file.gcount() << " of chunk_size " << chunk_size);
Expand All @@ -392,7 +387,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,

try
{
str1.assign(buffer_block, chunk_size);
str1.assign(buffer_block.begin(), buffer_block.begin() + chunk_size);
bootstrap::block_package bp;
if (! ::serialization::parse_binary(str1, bp))
throw std::runtime_error("Error in deserialization of chunk");
Expand Down
1 change: 0 additions & 1 deletion src/blockchain_utilities/blockchain_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

// bounds checking is done before writing to buffer, but buffer size
// should be a sensible maximum
#define BUFFER_SIZE 1000000
#define NUM_BLOCKS_PER_CHUNK 1
#define BLOCKCHAIN_RAW "blockchain.raw"

21 changes: 2 additions & 19 deletions src/blockchain_utilities/bootstrap_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ void BootstrapFile::flush_chunk()
m_output_stream->flush();

uint32_t chunk_size = m_buffer.size();
// LOG_PRINT_L0("chunk_size " << chunk_size);
if (chunk_size > BUFFER_SIZE)
{
LOG_PRINT_L0("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
}


std::string blob;
if (! ::serialization::dump_binary(chunk_size, blob))
Expand Down Expand Up @@ -428,20 +424,7 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
throw std::runtime_error("Error in deserialization of chunk_size");
LOG_PRINT_L3("chunk_size: " << chunk_size);

if (chunk_size > BUFFER_SIZE)
{
std::cout << refresh_string;
LOG_PRINT_L0("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE
<< " height: " << h-1);
throw std::runtime_error("Aborting: chunk size exceeds buffer size");
}
if (chunk_size > 100000)
{
std::cout << refresh_string;
LOG_PRINT_L0("NOTE: chunk_size " << chunk_size << " > 100000" << " height: "
<< h-1);
}
else if (chunk_size <= 0) {
if (chunk_size <= 0) {
std::cout << refresh_string;
LOG_PRINT_L0("ERROR: chunk_size " << chunk_size << " <= 0" << " height: " << h-1);
throw std::runtime_error("Aborting");
Expand Down
Loading

0 comments on commit 9c3f4f1

Please sign in to comment.