2 #include <fc/filesystem.hpp>
3 #include <fc/optional.hpp>
4 #include <fc/variant_object.hpp>
16 #include <graphene/utilities/key_conversion.hpp>
23 namespace debug_node {
39 const std::string& account_name)
override;
42 std::map<scorum::chain::public_key_type, fc::ecc::private_key>
key_table;
50 uint32_t
debug_push_blocks(
const std::string& src_filename, uint32_t count,
bool skip_validate_invariants);
53 const fc::time_point_sec& head_block_time,
54 bool generate_sparsely);
70 std::shared_ptr<scorum::plugin::debug_node::debug_node_plugin>
get_plugin();
78 const std::string& account_name)
86 fc::ecc::private_key gen_priv = fc::ecc::private_key::regenerate(fc::sha256::hash(
dev_key_prefix + account_name));
102 #ifdef SCORUM_INIT_PRIVATE_KEY
103 fc::ecc::private_key init_key = SCORUM_INIT_PRIVATE_KEY;
116 fc::ecc::private_key priv
118 result.private_key = graphene::utilities::key_to_wif(priv);
119 result.public_key = priv.get_public_key();
130 fc::path src_path = fc::path(src_filename);
131 fc::path index_path = fc::path(src_filename +
".index");
132 if (fc::exists(src_path) && fc::exists(index_path) && !fc::is_directory(src_path) && !fc::is_directory(index_path))
134 ilog(
"Loading ${n} from block_log ${fn}", (
"n", count)(
"fn", src_filename));
135 idump((src_filename)(count)(skip_validate_invariants));
138 uint32_t first_block = db->head_block_num() + 1;
140 if (skip_validate_invariants)
142 for (uint32_t i = 0; i < count; i++)
149 wlog(
"Block database ${fn} only contained ${i} of ${n} requested blocks",
150 (
"i", i)(
"n", count)(
"fn", src_filename));
160 catch (
const fc::exception& e)
162 elog(
"Could not read block ${i} of ${n}", (
"i", i)(
"n", count));
168 db->push_block(result.first, skip_flags);
170 catch (
const fc::exception& e)
172 elog(
"Got exception pushing block ${bn} : ${bid} (${i} of ${n})",
173 (
"bn", result.first.block_num())(
"bid", result.first.id())(
"i", i)(
"n", count));
174 elog(
"Exception backtrace: ${bt}", (
"bt", e.to_detail_string()));
177 ilog(
"Completed loading block_database successfully");
190 const fc::time_point_sec& head_block_time,
191 bool generate_sparsely)
193 return get_plugin()->debug_generate_blocks_until(debug_key, head_block_time, generate_sparsely,
200 return db->fetch_block_by_number(db->head_block_num());
254 if (hardfork_id > SCORUM_NUM_HARDFORKS)
269 my = std::make_shared<detail::debug_node_api_impl>(ctx.
app);
278 return my->debug_push_blocks(source_filename, count, skip_validate_invariants);
283 return my->debug_generate_blocks(debug_key, count);
287 fc::time_point_sec head_block_time,
288 bool generate_sparsely)
290 return my->debug_generate_blocks_until(debug_key, head_block_time, generate_sparsely);
295 return my->debug_pop_block();
305 return my->debug_get_witness_schedule();
310 return my->debug_get_hardfork_property_object();
336 my->debug_set_dev_key_prefix(prefix);
342 my->debug_get_dev_key(
result, args);
360 my->debug_set_hardfork(hardfork_id);
365 return my->debug_has_hardfork(hardfork_id);
std::shared_ptr< chain::database > chain_database() const
std::shared_ptr< abstract_plugin > get_plugin(const std::string &name) const
static const uint64_t npos
void open(const fc::path &file)
uint64_t get_block_pos(uint32_t block_num) const
std::pair< signed_block, uint64_t > read_block(uint64_t file_pos) const
tracks the blockchain state in an extensible manner
@ skip_validate_invariants
used to skip database invariant check on block application
void set_hardfork(uint32_t hardfork, bool process_now=true)
debug_node_api(const scorum::app::api_context &ctx)
fc::variant_object debug_get_edits()
uint32_t debug_push_blocks(const std::string &src_filename, uint32_t count, bool skip_validate_invariants)
scorum::chain::hardfork_property_object debug_get_hardfork_property_object()
fc::optional< scorum::chain::signed_block > debug_pop_block()
void debug_get_dev_key(get_dev_key_result &result, const get_dev_key_args &args)
debug_node_api_impl(scorum::app::application &_app)
scorum::chain::witness_schedule_object debug_get_witness_schedule()
void debug_stream_json_objects_flush()
void debug_stream_json_objects(const std::string &filename)
uint32_t debug_generate_blocks_until(const std::string &debug_key, const fc::time_point_sec &head_block_time, bool generate_sparsely)
bool debug_has_hardfork(uint32_t hardfork_id)
void debug_set_dev_key_prefix(std::string prefix)
scorum::app::application & app
void debug_set_edits(const fc::variant_object &edits)
void debug_get_json_schema(std::string &schema)
void debug_set_hardfork(uint32_t hardfork_id)
std::shared_ptr< scorum::plugin::debug_node::debug_node_plugin > get_plugin()
uint32_t debug_generate_blocks(const std::string &debug_key, uint32_t count)
void debug_update_object(const fc::variant_object &update)
debug_private_key_storage key_storage
std::map< scorum::chain::public_key_type, fc::ecc::private_key > key_table
virtual void maybe_get_private_key(fc::optional< fc::ecc::private_key > &result, const scorum::chain::public_key_type &pubkey, const std::string &account_name) override
std::string dev_key_prefix
debug_private_key_storage()
virtual ~debug_private_key_storage()
scorum::chain::witness_schedule_object debug_get_witness_schedule()
fc::optional< scorum::chain::signed_block > debug_pop_block()
Pop a block from the blockchain, returning it.
get_dev_key_result debug_get_dev_key(get_dev_key_args args)
Get developer key. Use debug_set_key_prefix() to set a prefix if desired.
bool debug_has_hardfork(uint32_t hardfork_id)
void debug_set_dev_key_prefix(std::string prefix)
Set developer key prefix. This prefix only applies to the current API session. (Thus,...
uint32_t debug_generate_blocks(std::string debug_key, uint32_t count)
Generate blocks locally.
uint32_t debug_generate_blocks_until(std::string debug_key, fc::time_point_sec head_block_time, bool generate_sparsely=true)
Generate blocks locally until a specified head block time. Can generate them sparsely.
void debug_set_hardfork(uint32_t hardfork_id)
scorum::chain::hardfork_property_object debug_get_hardfork_property_object()
uint32_t debug_push_blocks(std::string src_filename, uint32_t count, bool skip_validate_invariants=false)
Push blocks from existing database.
void update(fc::flat_map< uuid_type, bet_resolved_operation > &results, const bet_data &bet, asset income, uuid_type game_uuid, bet_resolve_kind kind)