From 2d7db18ddebbddf15469255ef6933e8d3030de28 Mon Sep 17 00:00:00 2001 From: stoffu Date: Mon, 5 Mar 2018 11:13:29 +0900 Subject: [PATCH] Support for stagenet --- main.cpp | 27 +++++++--- src/CmdLineOptions.cpp | 8 ++- src/CurrentBlockchainStatus.cpp | 2 +- src/CurrentBlockchainStatus.h | 2 +- src/MempoolStatus.cpp | 5 +- src/MempoolStatus.h | 4 +- src/MicroCore.cpp | 2 +- src/page.h | 94 +++++++++++++++++++++++---------- src/templates/address.html | 11 ++-- src/templates/index2.html | 6 +++ src/templates/js/cn_util.js | 7 +++ src/templates/js/config.js | 4 ++ src/tools.cpp | 20 +++---- src/tools.h | 8 +-- 14 files changed, 141 insertions(+), 59 deletions(-) diff --git a/main.cpp b/main.cpp index 5f6720c..04c45a3 100644 --- a/main.cpp +++ b/main.cpp @@ -50,10 +50,12 @@ main(int ac, const char* av[]) auto ssl_key_file_opt = opts.get_option("ssl-key-file"); auto no_blocks_on_index_opt = opts.get_option("no-blocks-on-index"); auto testnet_url = opts.get_option("testnet-url"); + auto stagenet_url = opts.get_option("stagenet-url"); auto mainnet_url = opts.get_option("mainnet-url"); auto mempool_info_timeout_opt = opts.get_option("mempool-info-timeout"); auto mempool_refresh_time_opt = opts.get_option("mempool-refresh-time"); auto testnet_opt = opts.get_option("testnet"); + auto stagenet_opt = opts.get_option("stagenet"); auto enable_key_image_checker_opt = opts.get_option("enable-key-image-checker"); auto enable_output_key_checker_opt = opts.get_option("enable-output-key-checker"); auto enable_autorefresh_option_opt = opts.get_option("enable-autorefresh-option"); @@ -69,6 +71,16 @@ main(int ac, const char* av[]) bool testnet {*testnet_opt}; + bool stagenet {*stagenet_opt}; + if (testnet && stagenet) + { + cerr << "testnet and stagenet cannot be specified at the same time!" << endl; + return EXIT_FAILURE; + } + const cryptonote::network_type nettype = testnet ? + cryptonote::network_type::TESTNET : stagenet ? + cryptonote::network_type::STAGENET : cryptonote::network_type::MAINNET; + bool enable_pusher {*enable_pusher_opt}; bool enable_js {*enable_js_opt}; bool enable_key_image_checker {*enable_key_image_checker_opt}; @@ -128,7 +140,7 @@ main(int ac, const char* av[]) // get blockchain path path blockchain_path; - if (!xmreg::get_blockchain_path(bc_path_opt, blockchain_path, testnet)) + if (!xmreg::get_blockchain_path(bc_path_opt, blockchain_path, nettype)) { cerr << "Error getting blockchain path." << endl; return EXIT_FAILURE; @@ -154,6 +166,8 @@ main(int ac, const char* av[]) if (testnet && deamon_url == "http:://127.0.0.1:18081") deamon_url = "http:://127.0.0.1:28081"; + if (stagenet && deamon_url == "http:://127.0.0.1:18081") + deamon_url = "http:://127.0.0.1:38081"; uint64_t mempool_info_timeout {5000}; @@ -187,8 +201,8 @@ main(int ac, const char* av[]) xmreg::CurrentBlockchainStatus::blockchain_path = blockchain_path; - xmreg::CurrentBlockchainStatus::testnet - = testnet; + xmreg::CurrentBlockchainStatus::nettype + = nettype; xmreg::CurrentBlockchainStatus::deamon_url = deamon_url; xmreg::CurrentBlockchainStatus::set_blockchain_variables( @@ -204,8 +218,8 @@ main(int ac, const char* av[]) xmreg::MempoolStatus::blockchain_path = blockchain_path; - xmreg::MempoolStatus::testnet - = testnet; + xmreg::MempoolStatus::nettype + = nettype; xmreg::MempoolStatus::deamon_url = deamon_url; xmreg::MempoolStatus::set_blockchain_variables( @@ -236,7 +250,7 @@ main(int ac, const char* av[]) xmreg::page xmrblocks(&mcore, core_storage, deamon_url, - testnet, + nettype, enable_pusher, enable_js, enable_key_image_checker, @@ -249,6 +263,7 @@ main(int ac, const char* av[]) no_blocks_on_index, mempool_info_timeout, *testnet_url, + *stagenet_url, *mainnet_url); // crow instance diff --git a/src/CmdLineOptions.cpp b/src/CmdLineOptions.cpp index d97bc7f..c8b922d 100644 --- a/src/CmdLineOptions.cpp +++ b/src/CmdLineOptions.cpp @@ -25,6 +25,8 @@ namespace xmreg "produce help message") ("testnet,t", value()->default_value(false)->implicit_value(true), "use testnet blockchain") + ("stagenet,s", value()->default_value(false)->implicit_value(true), + "use stagenet blockchain") ("enable-pusher", value()->default_value(false)->implicit_value(true), "enable signed transaction pusher") ("enable-mixin-details", value()->default_value(false)->implicit_value(true), @@ -50,9 +52,11 @@ namespace xmreg ("port,p", value()->default_value("8081"), "default explorer port") ("testnet-url", value()->default_value(""), - "you can specify testnet url, if you run it on mainnet. link will show on front page to testnet explorer") + "you can specify testnet url, if you run it on mainnet or stagenet. link will show on front page to testnet explorer") + ("stagenet-url", value()->default_value(""), + "you can specify stagenet url, if you run it on mainnet or testnet. link will show on front page to stagenet explorer") ("mainnet-url", value()->default_value(""), - "you can specify mainnet url, if you run it on testnet. link will show on front page to mainnet explorer") + "you can specify mainnet url, if you run it on testnet or stagenet. link will show on front page to mainnet explorer") ("no-blocks-on-index", value()->default_value("10"), "number of last blocks to be shown on index page") ("mempool-info-timeout", value()->default_value("5000"), diff --git a/src/CurrentBlockchainStatus.cpp b/src/CurrentBlockchainStatus.cpp index 8750700..1a4b1ab 100644 --- a/src/CurrentBlockchainStatus.cpp +++ b/src/CurrentBlockchainStatus.cpp @@ -299,7 +299,7 @@ CurrentBlockchainStatus::is_thread_running() bf::path CurrentBlockchainStatus::blockchain_path {"/home/mwo/.bitmonero/lmdb"}; -bool CurrentBlockchainStatus::testnet {false}; +cryptonote::network_type CurrentBlockchainStatus::nettype {cryptonote::network_type::MAINNET}; string CurrentBlockchainStatus::output_file {"emission_amount.txt"}; diff --git a/src/CurrentBlockchainStatus.h b/src/CurrentBlockchainStatus.h index d213894..54e0bc1 100644 --- a/src/CurrentBlockchainStatus.h +++ b/src/CurrentBlockchainStatus.h @@ -47,7 +47,7 @@ struct CurrentBlockchainStatus static bf::path blockchain_path; - static bool testnet; + static cryptonote::network_type nettype; static string output_file; diff --git a/src/MempoolStatus.cpp b/src/MempoolStatus.cpp index 956ccf7..46bea67 100644 --- a/src/MempoolStatus.cpp +++ b/src/MempoolStatus.cpp @@ -253,7 +253,8 @@ MempoolStatus::read_network_info() local_copy.outgoing_connections_count = rpc_network_info.outgoing_connections_count; local_copy.incoming_connections_count = rpc_network_info.incoming_connections_count; local_copy.white_peerlist_size = rpc_network_info.white_peerlist_size; - local_copy.testnet = rpc_network_info.testnet; + local_copy.nettype = rpc_network_info.testnet ? cryptonote::network_type::TESTNET : + rpc_network_info.stagenet ? cryptonote::network_type::STAGENET : cryptonote::network_type::MAINNET; local_copy.cumulative_difficulty = rpc_network_info.cumulative_difficulty; local_copy.block_size_limit = rpc_network_info.block_size_limit; local_copy.start_time = rpc_network_info.start_time; @@ -297,7 +298,7 @@ MempoolStatus::is_thread_running() bf::path MempoolStatus::blockchain_path {"/home/mwo/.bitmonero/lmdb"}; string MempoolStatus::deamon_url {"http:://127.0.0.1:18081"}; -bool MempoolStatus::testnet {false}; +cryptonote::network_type MempoolStatus::nettype {cryptonote::network_type::MAINNET}; atomic MempoolStatus::is_running {false}; boost::thread MempoolStatus::m_thread; Blockchain* MempoolStatus::core_storage {nullptr}; diff --git a/src/MempoolStatus.h b/src/MempoolStatus.h index 32418e1..e1cd49a 100644 --- a/src/MempoolStatus.h +++ b/src/MempoolStatus.h @@ -66,7 +66,7 @@ struct MempoolStatus uint64_t incoming_connections_count {0}; uint64_t white_peerlist_size {0}; uint64_t grey_peerlist_size {0}; - bool testnet {false}; + cryptonote::network_type nettype {cryptonote::network_type::MAINNET}; crypto::hash top_block_hash; uint64_t cumulative_difficulty {0}; uint64_t block_size_limit {0}; @@ -119,7 +119,7 @@ struct MempoolStatus static bf::path blockchain_path; static string deamon_url; - static bool testnet; + static cryptonote::network_type nettype; // make object for accessing the blockchain here static MicroCore* mcore; diff --git a/src/MicroCore.cpp b/src/MicroCore.cpp index 8205419..80a381a 100644 --- a/src/MicroCore.cpp +++ b/src/MicroCore.cpp @@ -88,7 +88,7 @@ MicroCore::init(const string& _blockchain_path) // initialize Blockchain object to manage // the database. - return m_blockchain_storage.init(db, m_hardfork, false); + return m_blockchain_storage.init(db, m_hardfork, network_type::MAINNET); } /** diff --git a/src/page.h b/src/page.h index f734021..44592b1 100644 --- a/src/page.h +++ b/src/page.h @@ -274,7 +274,10 @@ namespace xmreg atomic server_timestamp; + cryptonote::network_type nettype; + bool mainnet; bool testnet; + bool stagenet; bool enable_js; @@ -296,6 +299,7 @@ namespace xmreg uint64_t mempool_info_timeout; string testnet_url; + string stagenet_url; string mainnet_url; string js_html_files; @@ -331,7 +335,7 @@ namespace xmreg page(MicroCore* _mcore, Blockchain* _core_storage, string _deamon_url, - bool _testnet, + cryptonote::network_type _nettype, bool _enable_pusher, bool _enable_js, bool _enable_key_image_checker, @@ -344,12 +348,13 @@ namespace xmreg uint64_t _no_blocks_on_index, uint64_t _mempool_info_timeout, string _testnet_url, + string _stagenet_url, string _mainnet_url) : mcore {_mcore}, core_storage {_core_storage}, rpc {_deamon_url}, server_timestamp {std::time(nullptr)}, - testnet {_testnet}, + nettype {_nettype}, enable_pusher {_enable_pusher}, enable_js {_enable_js}, enable_key_image_checker {_enable_key_image_checker}, @@ -362,10 +367,15 @@ namespace xmreg no_blocks_on_index {_no_blocks_on_index}, mempool_info_timeout {_mempool_info_timeout}, testnet_url {_testnet_url}, + stagenet_url {_stagenet_url}, mainnet_url {_mainnet_url}, block_tx_cache(200), tx_context_cache(1000) { + mainnet = nettype == cryptonote::network_type::MAINNET; + testnet = nettype == cryptonote::network_type::TESTNET; + stagenet = nettype == cryptonote::network_type::STAGENET; + no_of_mempool_tx_of_frontpage = 25; @@ -419,6 +429,16 @@ namespace xmreg "testnet: true"); } + // the same idea as above for the stagenet + + if (stagenet) + { + template_file["config.js"] = std::regex_replace( + template_file["config.js"], + std::regex("stagenet: false"), + "stagenet: true"); + } + template_file["all_in_one.js"] = template_file["jquery.min.js"] + template_file["crc32.js"] + template_file["biginteger.js"] + @@ -491,7 +511,9 @@ namespace xmreg // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, {"testnet_url" , testnet_url}, + {"stagenet_url" , stagenet_url}, {"mainnet_url" , mainnet_url}, {"refresh" , refresh_page}, {"height" , height}, @@ -784,7 +806,7 @@ namespace xmreg // perapre network info mstch::map for the front page string hash_rate; - if (testnet) + if (testnet || stagenet) { hash_rate = std::to_string(current_network_info.hash_rate) + " H/s"; } @@ -1002,6 +1024,7 @@ namespace xmreg // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, {"blocks" , mstch::array()} }; @@ -1145,6 +1168,7 @@ namespace xmreg // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, {"blk_hash" , blk_hash_str}, {"blk_height" , _blk_height}, {"blk_timestamp" , blk_timestamp}, @@ -1471,6 +1495,7 @@ namespace xmreg mstch::map context { {"testnet" , this->testnet}, + {"stagenet" , this->stagenet}, {"show_cache_times" , show_cache_times}, {"txs" , mstch::array{}} }; @@ -1535,7 +1560,7 @@ namespace xmreg // parse string representing given monero address cryptonote::address_parse_info address_info; - if (!xmreg::parse_str_address(xmr_address_str, address_info, testnet)) + if (!xmreg::parse_str_address(xmr_address_str, address_info, nettype)) { cerr << "Cant parse string address: " << xmr_address_str << endl; return string("Cant parse xmr address: " + xmr_address_str); @@ -1706,6 +1731,7 @@ namespace xmreg // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, {"tx_hash" , tx_hash_str}, {"tx_prefix_hash" , pod_to_hex(txd.prefix_hash)}, {"xmr_address" , xmr_address_str}, @@ -2280,7 +2306,8 @@ namespace xmreg // initalise page tempate map with basic info about blockchain mstch::map context { - {"testnet" , testnet} + {"testnet" , testnet}, + {"stagenet" , stagenet} }; add_css_style(context); @@ -2312,6 +2339,7 @@ namespace xmreg // initalize page template context map mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, {"unsigned_tx_given" , unsigned_tx_given}, {"have_raw_tx" , true}, {"has_error" , false}, @@ -2389,7 +2417,7 @@ namespace xmreg { mstch::map dest_info { {"dest_address" , get_account_address_as_str( - testnet, a_dest.is_subaddress, a_dest.addr)}, + nettype, a_dest.is_subaddress, a_dest.addr)}, {"dest_amount" , xmreg::xmr_amount_to_str(a_dest.amount)} }; @@ -2733,7 +2761,7 @@ namespace xmreg destination_addresses.push_back( mstch::map { {"dest_address" , get_account_address_as_str( - testnet, a_dest.is_subaddress, a_dest.addr)}, + nettype, a_dest.is_subaddress, a_dest.addr)}, {"dest_amount" , xmreg::xmr_amount_to_str(a_dest.amount)}, {"is_this_change" , false} } @@ -2750,7 +2778,7 @@ namespace xmreg destination_addresses.push_back( mstch::map { {"dest_address" , get_account_address_as_str( - testnet, ptx.construction_data.change_dts.is_subaddress, ptx.construction_data.change_dts.addr)}, + nettype, ptx.construction_data.change_dts.is_subaddress, ptx.construction_data.change_dts.addr)}, {"dest_amount" , xmreg::xmr_amount_to_str(ptx.construction_data.change_dts.amount)}, {"is_this_change" , true} @@ -2934,6 +2962,7 @@ namespace xmreg // initalize page template context map mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, {"have_raw_tx" , true}, {"has_error" , false}, {"error_msg" , string {}}, @@ -3137,6 +3166,7 @@ namespace xmreg // initalize page template context map mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, }; add_css_style(context); @@ -3150,7 +3180,8 @@ namespace xmreg { // initalize page template context map mstch::map context { - {"testnet" , testnet} + {"testnet" , testnet}, + {"stagenet" , stagenet} }; add_css_style(context); @@ -3174,6 +3205,7 @@ namespace xmreg // initalize page template context map mstch::map context{ {"testnet" , testnet}, + {"stagenet" , stagenet}, {"has_error" , false}, {"error_msg" , string{}}, }; @@ -3262,7 +3294,7 @@ namespace xmreg context.insert({"address" , REMOVE_HASH_BRAKETS( - xmreg::print_address(address_info, testnet))}); + xmreg::print_address(address_info, nettype))}); context.insert({"viewkey" , REMOVE_HASH_BRAKETS( fmt::format("{:s}", prv_view_key))}); context.insert({"has_total_xmr" , false}); @@ -3291,7 +3323,7 @@ namespace xmreg {"key_image" , pod_to_hex(key_image)}, {"signature" , fmt::format("{:s}", signature)}, {"address" , xmreg::print_address( - address_info, testnet)}, + address_info, nettype)}, {"is_spent" , core_storage->have_tx_keyimg_as_spent(key_image)}, {"tx_hash" , string{}} }; @@ -3319,6 +3351,7 @@ namespace xmreg // initalize page template context map mstch::map context{ {"testnet" , testnet}, + {"stagenet" , stagenet}, {"has_error" , false}, {"error_msg" , string{}} }; @@ -3395,7 +3428,7 @@ namespace xmreg address_parse_info address_info {*xmr_address, false}; context.insert({"address" , REMOVE_HASH_BRAKETS( - xmreg::print_address(address_info, testnet))}); + xmreg::print_address(address_info, nettype))}); context.insert({"viewkey" , REMOVE_HASH_BRAKETS( fmt::format("{:s}", prv_view_key))}); context.insert({"has_total_xmr" , false}); @@ -3612,19 +3645,21 @@ namespace xmreg // parse string representing given monero address address_parse_info address_info; - bool testnet_addr {false}; + cryptonote::network_type nettype_addr {cryptonote::network_type::MAINNET}; if (search_text[0] == '9' || search_text[0] == 'A' || search_text[0] == 'B') - testnet_addr = true; + nettype_addr = cryptonote::network_type::TESTNET; + if (search_text[0] == '5' || search_text[0] == '7') + nettype_addr = cryptonote::network_type::STAGENET; - if (!xmreg::parse_str_address(search_text, address_info, testnet_addr)) + if (!xmreg::parse_str_address(search_text, address_info, nettype_addr)) { cerr << "Cant parse string address: " << search_text << endl; return string("Cant parse address (probably incorrect format): ") + search_text; } - return show_address_details(address_info, testnet_addr); + return show_address_details(address_info, nettype_addr); } // check if integrated monero address is given based on its length @@ -3636,7 +3671,7 @@ namespace xmreg address_parse_info address_info; - if (!get_account_address_from_str(address_info, testnet, search_text)) + if (!get_account_address_from_str(address_info, nettype, search_text)) { cerr << "Cant parse string integerated address: " << search_text << endl; return string("Cant parse address (probably incorrect format): ") @@ -3645,7 +3680,7 @@ namespace xmreg return show_integrated_address_details(address_info, address_info.payment_id, - testnet); + nettype); } // all_possible_tx_hashes was field using custom lmdb database @@ -3659,10 +3694,10 @@ namespace xmreg } string - show_address_details(const address_parse_info& address_info, bool testnet = false) + show_address_details(const address_parse_info& address_info, cryptonote::network_type nettype = cryptonote::network_type::MAINNET) { - string address_str = xmreg::print_address(address_info, testnet); + string address_str = xmreg::print_address(address_info, nettype); string pub_viewkey_str = fmt::format("{:s}", address_info.address.m_view_public_key); string pub_spendkey_str = fmt::format("{:s}", address_info.address.m_spend_public_key); @@ -3671,7 +3706,8 @@ namespace xmreg {"public_viewkey" , REMOVE_HASH_BRAKETS(pub_viewkey_str)}, {"public_spendkey" , REMOVE_HASH_BRAKETS(pub_spendkey_str)}, {"is_integrated_addr" , false}, - {"testnet" , testnet} + {"testnet" , testnet}, + {"stagenet" , stagenet}, }; add_css_style(context); @@ -3684,10 +3720,10 @@ namespace xmreg string show_integrated_address_details(const address_parse_info& address_info, const crypto::hash8& encrypted_payment_id, - bool testnet = false) + cryptonote::network_type nettype = cryptonote::network_type::MAINNET) { - string address_str = xmreg::print_address(address_info, testnet); + string address_str = xmreg::print_address(address_info, nettype); string pub_viewkey_str = fmt::format("{:s}", address_info.address.m_view_public_key); string pub_spendkey_str = fmt::format("{:s}", address_info.address.m_spend_public_key); string enc_payment_id_str = fmt::format("{:s}", encrypted_payment_id); @@ -3698,7 +3734,8 @@ namespace xmreg {"public_spendkey" , REMOVE_HASH_BRAKETS(pub_spendkey_str)}, {"encrypted_payment_id" , REMOVE_HASH_BRAKETS(enc_payment_id_str)}, {"is_integrated_addr" , true}, - {"testnet" , testnet} + {"testnet" , testnet}, + {"stagenet" , stagenet}, }; add_css_style(context); @@ -3789,6 +3826,7 @@ namespace xmreg // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, {"search_text" , search_text}, {"no_results" , true}, {"to_many_results" , false} @@ -4753,7 +4791,7 @@ namespace xmreg // parse string representing given monero address address_parse_info address_info; - if (!xmreg::parse_str_address(address_str, address_info, testnet)) + if (!xmreg::parse_str_address(address_str, address_info, nettype)) { j_response["status"] = "error"; j_response["message"] = "Cant parse monero address: " + address_str; @@ -4958,7 +4996,7 @@ namespace xmreg // parse string representing given monero address address_parse_info address_info; - if (!xmreg::parse_str_address(address_str, address_info, testnet)) + if (!xmreg::parse_str_address(address_str, address_info, nettype)) { j_response["status"] = "error"; j_response["message"] = "Cant parse monero address: " + address_str; @@ -5529,6 +5567,7 @@ namespace xmreg // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"stagenet" , stagenet}, {"tx_hash" , tx_hash_str}, {"tx_prefix_hash" , string{}}, {"tx_pub_key" , pod_to_hex(txd.pk)}, @@ -6176,7 +6215,8 @@ namespace xmreg {"incoming_connections_count", local_copy_network_info.incoming_connections_count}, {"white_peerlist_size" , local_copy_network_info.white_peerlist_size}, {"grey_peerlist_size" , local_copy_network_info.grey_peerlist_size}, - {"testnet" , local_copy_network_info.testnet}, + {"testnet" , local_copy_network_info.nettype == cryptonote::network_type::TESTNET}, + {"stagenet" , local_copy_network_info.nettype == cryptonote::network_type::STAGENET}, {"top_block_hash" , pod_to_hex(local_copy_network_info.top_block_hash)}, {"cumulative_difficulty" , local_copy_network_info.cumulative_difficulty}, {"block_size_limit" , local_copy_network_info.block_size_limit}, diff --git a/src/templates/address.html b/src/templates/address.html index 3c94b52..5e3f157 100644 --- a/src/templates/address.html +++ b/src/templates/address.html @@ -5,11 +5,14 @@
{{#testnet}} -

Testnet address: Yes

- {{/testnet}} - {{^testnet}} -

Testnet address: No

+

Network type: Testnet

{{/testnet}} + {{#stagenet}} +

Network type: Stagenet

+ {{/stagenet}} + {{^testnet}}{{^stagenet}} +

Network type: Mainnet

+ {{/stagenet}}{{/testnet}}

Associated public keys

diff --git a/src/templates/index2.html b/src/templates/index2.html index 32ab590..6b55652 100644 --- a/src/templates/index2.html +++ b/src/templates/index2.html @@ -24,12 +24,18 @@ {{#testnet_url}} | Go to testnet explorer {{/testnet_url}} + {{#stagenet_url}} + | Go to stagenet explorer + {{/stagenet_url}} {{#mainnet_url}} | Go to mainnet explorer {{/mainnet_url}} {{#testnet}} | This is testnet blockchian {{/testnet}} + {{#stagenet}} + | This is stagenet blockchian + {{/stagenet}} diff --git a/src/templates/js/cn_util.js b/src/templates/js/cn_util.js index 21dcb97..91f5c4c 100755 --- a/src/templates/js/cn_util.js +++ b/src/templates/js/cn_util.js @@ -56,6 +56,13 @@ var cnUtil = (function(initConfig) { CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX = config.subAddressPrefixTestnet; } + if (config.stagenet === true) + { + CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = config.addressPrefixStagenet; + CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX = config.integratedAddressPrefixStagenet; + CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX = config.subAddressPrefixStagenet; + } + var UINT64_MAX = new JSBigInt(2).pow(64); var CURRENT_TX_VERSION = 2; var OLD_TX_VERSION = 1; diff --git a/src/templates/js/config.js b/src/templates/js/config.js index 993b272..09aaf1c 100755 --- a/src/templates/js/config.js +++ b/src/templates/js/config.js @@ -1,5 +1,6 @@ var config = { testnet: false, // this is adjusted page.h if needed. dont need to change manually + stagenet: false, // this is adjusted page.h if needed. dont need to change manually coinUnitPlaces: 12, txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero @@ -13,6 +14,9 @@ var config = { addressPrefixTestnet: 53, integratedAddressPrefixTestnet: 54, subAddressPrefixTestnet: 63, + addressPrefixStagenet: 24, + integratedAddressPrefixStagenet: 25, + subAddressPrefixStagenet: 36, feePerKB: new JSBigInt('2000000000'),//20^10 - for testnet its not used, as fee is dynamic. dustThreshold: new JSBigInt('1000000000'),//10^10 used for choosing outputs/change - we decompose all the way down if the receiver wants now regardless of threshold txChargeRatio: 0.5, diff --git a/src/tools.cpp b/src/tools.cpp index fe680b4..2405992 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -78,10 +78,10 @@ get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, t bool parse_str_address(const string& address_str, address_parse_info& address_info, - bool testnet) + cryptonote::network_type nettype) { - if (!get_account_address_from_str(address_info, testnet, address_str)) + if (!get_account_address_from_str(address_info, nettype, address_str)) { cerr << "Error getting address: " << address_str << endl; return false; @@ -95,10 +95,10 @@ parse_str_address(const string& address_str, * Return string representation of monero address */ string -print_address(const address_parse_info& address_info, bool testnet) +print_address(const address_parse_info& address_info, cryptonote::network_type nettype) { return "<" + get_account_address_as_str( - testnet, address_info.is_subaddress, address_info.address) + nettype, address_info.is_subaddress, address_info.address) + ">"; } @@ -180,7 +180,7 @@ timestamp_to_str_gm(time_t timestamp, const char* format) ostream& operator<< (ostream& os, const address_parse_info& addr_info) { - os << get_account_address_as_str(false, addr_info.is_subaddress, addr_info.address); + os << get_account_address_as_str(network_type::MAINNET, addr_info.is_subaddress, addr_info.address); return os; } @@ -237,14 +237,16 @@ generate_key_image(const crypto::key_derivation& derivation, string -get_default_lmdb_folder(bool testnet) +get_default_lmdb_folder(cryptonote::network_type nettype) { // default path to monero folder // on linux this is /home//.bitmonero string default_monero_dir = tools::get_default_data_dir(); - if (testnet) + if (nettype == cryptonote::network_type::TESTNET) default_monero_dir += "/testnet"; + if (nettype == cryptonote::network_type::STAGENET) + default_monero_dir += "/stagenet"; // the default folder of the lmdb blockchain database @@ -261,10 +263,10 @@ get_default_lmdb_folder(bool testnet) bool get_blockchain_path(const boost::optional& bc_path, bf::path& blockchain_path, - bool testnet) + cryptonote::network_type nettype) { // the default folder of the lmdb blockchain database - string default_lmdb_dir = xmreg::get_default_lmdb_folder(testnet); + string default_lmdb_dir = xmreg::get_default_lmdb_folder(nettype); blockchain_path = bc_path ? bf::path(*bc_path) diff --git a/src/tools.h b/src/tools.h index 9dfe838..b212db0 100644 --- a/src/tools.h +++ b/src/tools.h @@ -101,14 +101,14 @@ get_tx_pub_key_from_str_hash(Blockchain& core_storage, bool parse_str_address(const string& address_str, address_parse_info& address_info, - bool testnet = false); + cryptonote::network_type nettype = cryptonote::network_type::MAINNET); inline bool is_separator(char c); string print_address(const address_parse_info& address, - bool testnet = false); + cryptonote::network_type nettype = cryptonote::network_type::MAINNET); string print_sig (const signature& sig); @@ -127,7 +127,7 @@ operator<< (ostream& os, const address_parse_info& addr_info); string -get_default_lmdb_folder(bool testnet = false); +get_default_lmdb_folder(cryptonote::network_type nettype = cryptonote::network_type::MAINNET); bool generate_key_image(const crypto::key_derivation& derivation, @@ -139,7 +139,7 @@ generate_key_image(const crypto::key_derivation& derivation, bool get_blockchain_path(const boost::optional& bc_path, bf::path& blockchain_path, - bool testnet = false); + cryptonote::network_type nettype = cryptonote::network_type::MAINNET); uint64_t sum_money_in_outputs(const transaction& tx);