Skip to content

Instantly share code, notes, and snippets.

@AlexShkor
Created October 16, 2017 11:53
Show Gist options
  • Save AlexShkor/b8e377200ccc0873683463a0f92cf385 to your computer and use it in GitHub Desktop.
Save AlexShkor/b8e377200ccc0873683463a0f92cf385 to your computer and use it in GitHub Desktop.
s.cpp
#ifndef IS_TEST_NET
+ auto snapshot_path = string("./snapshot5392323.json");
+ auto snapshot_file = fc::path(snapshot_path);
+ FC_ASSERT( fc::exists( snapshot_file ), "Snapshot file '${file}' was not found.", ("file", snapshot_file) );
+
+ std::cout << "Initializing state from snapshot file: "<< snapshot_file.generic_string() << "\n";
+
+ unsigned char digest[MD5_DIGEST_LENGTH];
+ char snapshot_checksum [] = "081b0149f0b2a570ae76b663090cfb0c";
+ char md5hash[33];
+ boost::iostreams::mapped_file_source src(snapshot_path);
+ MD5((unsigned char*) src.data(), src.size(), (unsigned char*) &digest);
+ for(int i = 0; i < 16; i++) {
+ sprintf(&md5hash[i*2], "%02x", (unsigned int)digest[i]);
+ }
+ FC_ASSERT( memcmp(md5hash, snapshot_checksum, 32) == 0 , "Checksum of snapshot [${h}] is not equal [${s}]", ("h", md5hash)("s", snapshot_checksum) );
+
+ snapshot_state snapshot = fc::json::from_file(snapshot_file).as<snapshot_state>();
+ for (account_summary& account : snapshot.accounts)
+ {
+ create<account_object>([&](account_object& a)
+ {
+ a.name = account.name;
+ a.owner.weight_threshold = 1;
+ a.owner = account.keys.owner_key;
+ a.active = account.keys.active_key;
+ a.posting = account.keys.posting_key;
+ a.memo_key = account.keys.memo_key;
+ a.json_metadata = "{created_at: 'GENESIS'}";
+ a.recovery_account = STEEMIT_INIT_MINER_NAME;
+ } );
+ }
+ std::cout << "Imported " << snapshot.accounts.size() << " accounts from " << snapshot_file.generic_string() << ".\n";
+ #endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment