summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgenjix <genjix@gmail.com>2014-04-16 02:18:13 (GMT)
committer genjix <genjix@gmail.com>2014-04-16 02:18:13 (GMT)
commit4c8f51db78b63d7c9c3d5e283701274b62493220 (patch)
tree9d754c5db7b1aad13bdde22b90c08d03ef10beb1
parent82f2b7d9a8e89505b58ce54a6411bfc63bd10636 (diff)
parent2e8fb1161393969ae13a200096d6ae2269fcea51 (diff)
Merge pull request #45 from lclc/lclc2
Updated initchain example to latest (stealth) version
-rw-r--r--examples/initchain.cpp65
1 files changed, 44 insertions, 21 deletions
diff --git a/examples/initchain.cpp b/examples/initchain.cpp
index e723465..3a7b453 100644
--- a/examples/initchain.cpp
+++ b/examples/initchain.cpp
@@ -1,34 +1,56 @@
/*
- * Copyright (c) 2011-2013 libbitcoin developers (see AUTHORS)
- *
- * This file is part of libbitcoin.
- *
- * libbitcoin is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License with
- * additional permissions to the one published by the Free Software
- * Foundation, either version 3 of the License, or (at your option)
- * any later version. For more information see LICENSE.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-/*
- Create a new leveldb blockchain database.
+Create a new leveldb blockchain database.
*/
+#include <iostream>
+
+#ifndef LEVELDB_ENABLED
+
+int main()
+{
+ std::cerr << "initchain: The feature is not supported in this build." << std::endl;
+ return 1;
+}
+
+#else
+
#include <future>
#include <bitcoin/bitcoin.hpp>
+
using namespace bc;
+void create_file(const std::string& filename, size_t filesize)
+{
+ std::ofstream file(filename, std::ios::binary | std::ios::trunc);
+ constexpr size_t chunk_size = 100000;
+ std::vector<char> random_buffer(chunk_size);
+ for (size_t i = 0; i < filesize; i += chunk_size)
+ file.write(random_buffer.data(), chunk_size);
+}
+
+void initialize_new_stealth_database(const std::string& filename)
+{
+ create_file(filename, 100000000);
+ mmfile file(filename);
+ auto serial = make_serializer(file.data());
+ serial.write_4_bytes(1);
+ // should last us a decade
+ size_t max_header_rows = 10000;
+ serial.write_4_bytes(max_header_rows);
+ serial.write_4_bytes(0);
+ for (size_t i = 0; i < max_header_rows; ++i)
+ serial.write_4_bytes(0);
+}
+
int main(int argc, char** argv)
{
if (argc != 2)
+ {
+ std::cerr << "initchain: No directory specified." << std::endl;
return 1;
+ }
const std::string dbpath = argv[1];
+ // Create custom databases first.
+ initialize_new_stealth_database(dbpath + "/stealth.db");
// Threadpool context containing 1 thread.
threadpool pool(1);
// leveldb_blockchain operations execute in pool's thread.
@@ -42,7 +64,7 @@ int main(int argc, char** argv)
block_type first_block = genesis_block();
std::promise<std::error_code> ec_promise;
// Completion handler for import method.
- auto import_finished =
+ auto import_finished =
[&ec_promise](const std::error_code& ec)
{
ec_promise.set_value(ec);
@@ -69,3 +91,4 @@ int main(int argc, char** argv)
return 0;
}
+#endif