From c18585687c9a52b888bfef74795309cdc770f0a7 Mon Sep 17 00:00:00 2001 From: Jowen Date: Wed, 30 Jan 2019 15:24:07 +0800 Subject: [PATCH 01/17] add rpc api methods filter config items for security --- include/metaverse/blockchain/settings.hpp | 1 + include/metaverse/mgbubble/HttpServ.hpp | 2 ++ include/metaverse/server/settings.hpp | 4 +++ src/lib/blockchain/block_chain_impl.cpp | 5 +++ src/lib/blockchain/settings.cpp | 1 + src/lib/explorer/dispatch.cpp | 43 +++++++++++++++++++++++ src/mvsd/mgbubble/HttpServ.cpp | 31 ++++++++++++++++ src/mvsd/server/parser.cpp | 22 +++++++++++- 8 files changed, 108 insertions(+), 1 deletion(-) diff --git a/include/metaverse/blockchain/settings.hpp b/include/metaverse/blockchain/settings.hpp index ea9e073a6..b94506cd4 100644 --- a/include/metaverse/blockchain/settings.hpp +++ b/include/metaverse/blockchain/settings.hpp @@ -42,6 +42,7 @@ class BCB_API settings bool transaction_pool_consistency; bool use_testnet_rules; bool collect_split_stake; + bool disable_account_operations; config::checkpoint::list checkpoints; config::checkpoint::list basic_checkpoints; }; diff --git a/include/metaverse/mgbubble/HttpServ.hpp b/include/metaverse/mgbubble/HttpServ.hpp index 2d2454d9e..8fde37944 100644 --- a/include/metaverse/mgbubble/HttpServ.hpp +++ b/include/metaverse/mgbubble/HttpServ.hpp @@ -55,6 +55,8 @@ class HttpServ : public MgServer void on_ws_handshake_done_handler(struct mg_connection& nc) override; void on_ws_frame_handler(struct mg_connection& nc, struct websocket_message& msg) override; + void check_rpc_client_addresses(struct mg_connection& nc); + private: enum : int { // Method values are represented as powers of two for simplicity. diff --git a/include/metaverse/server/settings.hpp b/include/metaverse/server/settings.hpp index 1fb94fc38..d3e2e2e96 100644 --- a/include/metaverse/server/settings.hpp +++ b/include/metaverse/server/settings.hpp @@ -71,6 +71,10 @@ class BCS_API settings config::sodium::list client_public_keys; config::authority::list client_addresses; + std::vector rpc_client_addresses; + std::vector allow_rpc_methods; + std::vector forbid_rpc_methods; + /// Helpers. asio::duration heartbeat_interval() const; asio::duration subscription_expiration() const; diff --git a/src/lib/blockchain/block_chain_impl.cpp b/src/lib/blockchain/block_chain_impl.cpp index d027b5a10..1f9ae2fd5 100644 --- a/src/lib/blockchain/block_chain_impl.cpp +++ b/src/lib/blockchain/block_chain_impl.cpp @@ -1340,6 +1340,11 @@ std::shared_ptr block_chain_impl::get_spends_output(const in std::shared_ptr block_chain_impl::is_account_passwd_valid (const std::string& name, const std::string& passwd) { + if (settings_.disable_account_operations) { + throw std::logic_error{"account related operations is forbidden " + "with config item server.disable_account_operations"}; + } + //added by chengzhiping to protect accounts from brute force password attacks. auto *ass = account_security_strategy::get_instance(); // ass->check_locked(name); diff --git a/src/lib/blockchain/settings.cpp b/src/lib/blockchain/settings.cpp index 5f10bc947..722d6c586 100644 --- a/src/lib/blockchain/settings.cpp +++ b/src/lib/blockchain/settings.cpp @@ -36,6 +36,7 @@ settings::settings() transaction_pool_consistency(false), use_testnet_rules(false), collect_split_stake(true), + disable_account_operations(false), checkpoints(), basic_checkpoints() { diff --git a/src/lib/explorer/dispatch.cpp b/src/lib/explorer/dispatch.cpp index 305f2e1b6..7aec5d781 100644 --- a/src/lib/explorer/dispatch.cpp +++ b/src/lib/explorer/dispatch.cpp @@ -34,6 +34,7 @@ #include #include #include +#include using namespace boost::filesystem; using namespace boost::program_options; @@ -181,6 +182,48 @@ console_result dispatch_command(int argc, const char* argv[], } } #endif + const std::string command_name = command->name(); + const auto& allowed_methods = node.server_settings().allow_rpc_methods; + const auto& forbidden_methods = node.server_settings().forbid_rpc_methods; + + if (!forbidden_methods.empty()) { + const std::sregex_iterator end; + for (const auto& item : forbidden_methods) { + auto patterns = bc::split(item, ", ", true); + for (const auto& pattern : patterns) { + const std::regex reg_pattern("^" + pattern + "$"); + std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); + if (it != end) { + throw invalid_command_exception{command_name + + " is forbidden with config item server.forbid_rpc_methods"}; + } + } + } + } + + if (!allowed_methods.empty()) { + bool allow = false; + const std::sregex_iterator end; + for (const auto& item : allowed_methods) { + auto patterns = bc::split(item, ", ", true); + for (const auto& pattern : patterns) { + const std::regex reg_pattern("^" + pattern + "$"); + std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); + if (it != end) { + allow = true; + break; + } + } + if (allow) { + break; + } + } + if (!allow) { + throw invalid_command_exception{command_name + + " is not allowed with config item server.allow_rpc_methods"}; + } + } + return static_cast(command.get())->invoke(jv_output, node); } else { diff --git a/src/mvsd/mgbubble/HttpServ.cpp b/src/mvsd/mgbubble/HttpServ.cpp index 4922d3f0c..3544c0ea7 100644 --- a/src/mvsd/mgbubble/HttpServ.cpp +++ b/src/mvsd/mgbubble/HttpServ.cpp @@ -32,6 +32,14 @@ thread_local OStream HttpServ::out_; thread_local Tokeniser<'/'> HttpServ::uri_; thread_local int HttpServ::state_ = 0; +std::string get_remote_address_from_nc(mg_connection& nc) +{ + char dst[60]; + constexpr int flags = MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_REMOTE; + mg_conn_addr_to_str(&nc, dst, sizeof(dst), flags); + return dst; +} + void HttpServ::reset(HttpMessage& data) noexcept { state_ = 0; @@ -63,6 +71,8 @@ void HttpServ::rpc_request(mg_connection& nc, HttpMessage data, uint8_t rpc_vers out_.reset(200, "OK"); try { + check_rpc_client_addresses(nc); + data.data_to_arg(rpc_version); Json::Value jv_output; @@ -131,6 +141,8 @@ void HttpServ::ws_request(mg_connection& nc, WebsocketMessage ws) Json::Value jv_output; try { + check_rpc_client_addresses(nc); + ws.data_to_arg(); console_result retcode = explorer::dispatch_command(ws.argc(), const_cast(ws.argv()), jv_output, node_); @@ -223,5 +235,24 @@ void HttpServ::on_ws_frame_handler(struct mg_connection& nc, websocket_message& ws_request(nc, WebsocketMessage(&msg)); } +void HttpServ::check_rpc_client_addresses(struct mg_connection& nc) +{ + const auto& allowed_clients = node_.server_settings().rpc_client_addresses; + if (allowed_clients.empty()) { + return; + } + + const auto remote_ip = get_remote_address_from_nc(nc); + + for (const auto& item : allowed_clients) { + auto clients = bc::split(item, ", ", true); + auto pos = std::find(clients.begin(), clients.end(), remote_ip); + if (pos == clients.end()) { + throw explorer::connection_exception{remote_ip + + " is not allowed with config item server.rpc_client_addresses"}; + } + } +} + }// mgbubble diff --git a/src/mvsd/server/parser.cpp b/src/mvsd/server/parser.cpp index 411e29cf1..dda151473 100644 --- a/src/mvsd/server/parser.cpp +++ b/src/mvsd/server/parser.cpp @@ -328,7 +328,7 @@ options_metadata parser::load_settings() ( "blockchain.collect_split_stake", value(&configured.chain.collect_split_stake), - "Use testnet rules for determination of work required, defaults to false." + "Automatically collect or split utxos for pos stake, defaults to true." ) /* [node] */ @@ -478,6 +478,26 @@ options_metadata parser::load_settings() "server.client_address", value(&configured.server.client_addresses), "Allowed client IP address, multiple entries allowed." + ) + ( + "server.rpc_client_addresses", + value>(&configured.server.rpc_client_addresses), + "Allowed RPC client IP address, multiple entries allowed." + ) + ( + "server.disable_account_operations", + value(&configured.chain.disable_account_operations), + "Disable account related operations for server security, defaults to false." + ) + ( + "server.allow_rpc_methods", + value>(&configured.server.allow_rpc_methods), + "Allowed rpc calling methods (regex), multiple entries allowed. Defaults to allow all." + ) + ( + "server.forbid_rpc_methods", + value>(&configured.server.forbid_rpc_methods), + "Forbidden rpc calling methods (regex), multiple entries allowed. Defaults to forbid none." ); return description; From 35698a934dc6f9ba7dcf0fa16985ccbf83bc8b5c Mon Sep 17 00:00:00 2001 From: Jowen Date: Thu, 31 Jan 2019 13:15:48 +0800 Subject: [PATCH 02/17] web socket support did as address parameter --- include/metaverse/mgbubble/WsPushServ.hpp | 4 +- src/mvsd/mgbubble/WsPushServ.cpp | 54 ++++++++++++++++------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/include/metaverse/mgbubble/WsPushServ.hpp b/include/metaverse/mgbubble/WsPushServ.hpp index 7c1ccc875..118a9026b 100644 --- a/include/metaverse/mgbubble/WsPushServ.hpp +++ b/include/metaverse/mgbubble/WsPushServ.hpp @@ -126,6 +126,8 @@ class WsPushServ : public MgServer { Json::Value& value, std::shared_ptr topic_map = nullptr); + std::string get_address(const std::string& did_or_address) const; + private: libbitcoin::server::server_node& node_; std::unordered_map> map_connections_; @@ -137,4 +139,4 @@ class WsPushServ : public MgServer { }; } -#endif \ No newline at end of file +#endif diff --git a/src/mvsd/mgbubble/WsPushServ.cpp b/src/mvsd/mgbubble/WsPushServ.cpp index f649cb051..c0dd26701 100644 --- a/src/mvsd/mgbubble/WsPushServ.cpp +++ b/src/mvsd/mgbubble/WsPushServ.cpp @@ -463,13 +463,16 @@ void WsPushServ::on_ws_frame_handler(struct mg_connection& nc, websocket_message std::vector addresses; if (root["address"].isString()) { auto short_addr = root["address"].asString(); - auto pay_addr = wallet::payment_address(short_addr); - if (!short_addr.empty() && !pay_addr) { - send_bad_response(nc, "invalid address."); - return; - } + if (!short_addr.empty()) { + auto pay_addr_str = get_address(short_addr); + auto pay_addr = wallet::payment_address(pay_addr_str); + if (!pay_addr) { + send_bad_response(nc, ("invalid did or address " + short_addr).c_str()); + return; + } - addresses.push_back(short_addr); + addresses.push_back(pay_addr_str); + } } else if (root["address"].isArray()) { auto array = root["address"]; @@ -477,24 +480,27 @@ void WsPushServ::on_ws_frame_handler(struct mg_connection& nc, websocket_message for (int i = 0; i < length; ++i) { auto item = array[i]; if (!item.isString()) { - send_bad_response(nc, "invalid address."); + send_bad_response(nc, "invalid did or address (not string)."); return; } auto short_addr = item.asString(); - auto pay_addr = wallet::payment_address(short_addr); - if (!short_addr.empty() && !pay_addr) { - send_bad_response(nc, "invalid address."); - return; - } + if (!short_addr.empty()) { + auto pay_addr_str = get_address(short_addr); + auto pay_addr = wallet::payment_address(pay_addr_str); + if (!pay_addr) { + send_bad_response(nc, ("invalid did or address " + short_addr).c_str()); + return; + } - if (addresses.end() == std::find(addresses.begin(), addresses.end(), short_addr)) { - addresses.push_back(short_addr); + if (addresses.end() == std::find(addresses.begin(), addresses.end(), pay_addr_str)) { + addresses.push_back(pay_addr_str); + } } } } else { - send_bad_response(nc, "invalid address."); + send_bad_response(nc, "invalid did or address (not string)."); return; } @@ -660,4 +666,22 @@ void WsPushServ::on_notify_handler(struct mg_connection& nc, struct mg_event& ev msg(++api_call_counter); } +std::string WsPushServ::get_address(const std::string& did_or_address) const +{ + auto& blockchain = node_.chain_impl(); + if (did_or_address.empty() || blockchain.is_valid_address(did_or_address)) { + return did_or_address; + } + + auto is_test = blockchain.chain_settings().use_testnet_rules; + if (bc::blockchain::block_chain_impl::is_valid_did_symbol(did_or_address, !is_test)) { + auto diddetail = blockchain.get_registered_did(did_or_address); + if (diddetail) { + return diddetail->get_address(); + } + } + + return ""; +} + } From 5d5af494c73775f580df121ca7de6ace512cce98 Mon Sep 17 00:00:00 2001 From: Jowen Date: Thu, 31 Jan 2019 14:14:04 +0800 Subject: [PATCH 03/17] get rid of depost completely --- builds/msvc-140/explorer/explorer.vcxproj | 4 +- .../explorer/explorer.vcxproj.filters | 8 +- .../explorer/extensions/base_helper.hpp | 44 ------ .../explorer/extensions/commands/deposit.hpp | 127 ------------------ src/lib/explorer/extensions/base_helper.cpp | 12 -- .../explorer/extensions/commands/deposit.cpp | 79 ----------- 6 files changed, 2 insertions(+), 272 deletions(-) delete mode 100644 include/metaverse/explorer/extensions/commands/deposit.hpp delete mode 100644 src/lib/explorer/extensions/commands/deposit.cpp diff --git a/builds/msvc-140/explorer/explorer.vcxproj b/builds/msvc-140/explorer/explorer.vcxproj index 7cf1e8a3b..ee75ef258 100644 --- a/builds/msvc-140/explorer/explorer.vcxproj +++ b/builds/msvc-140/explorer/explorer.vcxproj @@ -61,7 +61,6 @@ - @@ -193,7 +192,6 @@ - @@ -346,4 +344,4 @@ - \ No newline at end of file + diff --git a/builds/msvc-140/explorer/explorer.vcxproj.filters b/builds/msvc-140/explorer/explorer.vcxproj.filters index 0a2f7a1e8..99581baeb 100644 --- a/builds/msvc-140/explorer/explorer.vcxproj.filters +++ b/builds/msvc-140/explorer/explorer.vcxproj.filters @@ -185,9 +185,6 @@ Header Files\extensions\commands - - Header Files\extensions\commands - Header Files\extensions\commands @@ -543,9 +540,6 @@ Source Files\extensions\commands - - Source Files\extensions\commands - Source Files\extensions\commands @@ -816,4 +810,4 @@ Header Files\extensions\commands - \ No newline at end of file + diff --git a/include/metaverse/explorer/extensions/base_helper.hpp b/include/metaverse/explorer/extensions/base_helper.hpp index 36f8406e9..38568e648 100644 --- a/include/metaverse/explorer/extensions/base_helper.hpp +++ b/include/metaverse/explorer/extensions/base_helper.hpp @@ -489,50 +489,6 @@ class BCX_API base_transaction_constructor : public base_transfer_common std::vector from_vec_; // from address vector }; -class BCX_API depositing_etp : public base_transfer_helper -{ -public: - depositing_etp(command& cmd, bc::blockchain::block_chain_impl& blockchain, - std::string&& name, std::string&& passwd, - std::string&& to, receiver_record::list&& receiver_list, - uint16_t deposit_cycle = 7, uint64_t fee = 10000, uint32_t locktime = 0) - : base_transfer_helper(cmd, blockchain, std::move(name), std::move(passwd), - std::string(""), std::move(receiver_list), fee, "", "", locktime) - , to_{std::move(to)} - , deposit_cycle_{deposit_cycle} - {} - - ~depositing_etp(){} - - chain::operation::stack get_script_operations(const receiver_record& record) const override; - -private: - std::string to_; - uint16_t deposit_cycle_{7}; // 7 days -}; - -class BCX_API depositing_etp_transaction : public base_transaction_constructor -{ -public: - depositing_etp_transaction(bc::blockchain::block_chain_impl& blockchain, utxo_attach_type type, - std::vector&& from_vec, receiver_record::list&& receiver_list, - uint16_t deposit_cycle, std::string&& change, - std::string&& message, uint64_t fee, uint32_t locktime = 0) - : base_transaction_constructor( - blockchain, type, std::forward>(from_vec), - std::move(receiver_list), std::string(""), - std::move(change), std::move(message), fee, locktime) - , deposit_cycle_{deposit_cycle} - {} - - ~depositing_etp_transaction(){} - - chain::operation::stack get_script_operations(const receiver_record& record) const override; - -private: - uint16_t deposit_cycle_{7}; // 7 days -}; - class BCX_API sending_etp : public base_transfer_helper { public: diff --git a/include/metaverse/explorer/extensions/commands/deposit.hpp b/include/metaverse/explorer/extensions/commands/deposit.hpp deleted file mode 100644 index 0555fe0f2..000000000 --- a/include/metaverse/explorer/extensions/commands/deposit.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Copyright (c) 2016-2018 mvs developers - * - * This file is part of metaverse-explorer. - * - * metaverse-explorer 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 . - */ - - -#pragma once -#include -#include -#include -#include - -namespace libbitcoin { -namespace explorer { -namespace commands { - - -class deposit : public command_extension -{ -public: - static const char* symbol(){ return "deposit";} - const char* name() override { return symbol();} - bool category(int bs) override { return (ex_online & bs ) == bs; } - const char* description() override { return "Deposit some etp, then get reward for frozen some etp."; } - - arguments_metadata& load_arguments() override - { - return get_argument_metadata() - .add("ACCOUNTNAME", 1) - .add("ACCOUNTAUTH", 1) - .add("AMOUNT", 1); - } - - void load_fallbacks (std::istream& input, - po::variables_map& variables) override - { - const auto raw = requires_raw_input(); - load_input(auth_.name, "ACCOUNTNAME", variables, input, raw); - load_input(auth_.auth, "ACCOUNTAUTH", variables, input, raw); - load_input(argument_.amount, "AMOUNT", variables, input, raw); - } - - options_metadata& load_options() override - { - using namespace po; - options_description& options = get_option_metadata(); - options.add_options() - ( - BX_HELP_VARIABLE ",h", - value()->zero_tokens(), - "Get a description and instructions for this command." - ) - ( - "ACCOUNTNAME", - value(&auth_.name)->required(), - BX_ACCOUNT_NAME - ) - ( - "ACCOUNTAUTH", - value(&auth_.auth)->required(), - BX_ACCOUNT_AUTH - ) - ( - "AMOUNT", - value(&argument_.amount)->required(), - "ETP integer bits." - ) - ( - "address,a", - value(&argument_.address), - "The deposit target did/address." - ) - ( - "deposit,d", - value(&argument_.deposit)->default_value(7), - "Deposits support [7, 30, 90, 182, 365] days. defaluts to 7 days" - ) - ( - "fee,f", - value(&argument_.fee)->default_value(10000), - "Transaction fee. defaults to 10000 ETP bits" - ); - - return options; - } - - void set_defaults_from_config (po::variables_map& variables) override - { - } - - console_result invoke (Json::Value& jv_output, - libbitcoin::server::server_node& node) override; - - struct argument - { - uint64_t amount; - uint64_t fee; - uint16_t deposit; - std::string address; - } argument_; - - struct option - { - } option_; - -}; - - -} // namespace commands -} // namespace explorer -} // namespace libbitcoin - diff --git a/src/lib/explorer/extensions/base_helper.cpp b/src/lib/explorer/extensions/base_helper.cpp index 31a7ed6b2..b3d39cc25 100644 --- a/src/lib/explorer/extensions/base_helper.cpp +++ b/src/lib/explorer/extensions/base_helper.cpp @@ -1995,18 +1995,6 @@ void base_transaction_constructor::populate_unspent_list() populate_change(); } -chain::operation::stack -depositing_etp::get_script_operations(const receiver_record& record) const -{ - return get_pay_key_hash_with_lock_height_operations(deposit_cycle_, record); -} - -chain::operation::stack -depositing_etp_transaction::get_script_operations(const receiver_record& record) const -{ - return get_pay_key_hash_with_lock_height_operations(deposit_cycle_, record); -} - void sending_multisig_tx::populate_change() { // etp utxo diff --git a/src/lib/explorer/extensions/commands/deposit.cpp b/src/lib/explorer/extensions/commands/deposit.cpp deleted file mode 100644 index 82f26a288..000000000 --- a/src/lib/explorer/extensions/commands/deposit.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright (c) 2016-2018 mvs developers - * - * This file is part of metaverse-explorer. - * - * metaverse-explorer 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 . - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace libbitcoin { -namespace explorer { -namespace commands { - -console_result deposit::invoke(Json::Value& jv_output, - libbitcoin::server::server_node& node) -{ - auto& blockchain = node.chain_impl(); - blockchain.is_account_passwd_valid(auth_.name, auth_.auth); - - uint64_t last_height = 0; - blockchain.get_last_height(last_height); - if (last_height >= pos_enabled_height) { - throw fatal_exception{"deposit is not supported after block " + std::to_string(pos_enabled_height)}; - } - - chain::attachment attach; - std::string addr; - - if (argument_.address.empty()) { - auto pvaddr = blockchain.get_account_addresses(auth_.name); - if(!pvaddr || pvaddr->empty()) - throw address_list_nullptr_exception{"nullptr for address list"}; - - addr = get_random_payment_address(pvaddr, blockchain); - } - else { - addr = get_address(argument_.address, attach, false, blockchain); - } - - // receiver - std::vector receiver{ - {addr, "", argument_.amount, 0, utxo_attach_type::deposit, attach} - }; - auto deposit_helper = depositing_etp(*this, blockchain, std::move(auth_.name), std::move(auth_.auth), - std::move(addr), std::move(receiver), argument_.deposit, argument_.fee); - - deposit_helper.exec(); - - // json output - auto tx = deposit_helper.get_transaction(); - jv_output = config::json_helper(get_api_version()).prop_tree(tx, true); - - return console_result::okay; -} - -} // namespace commands -} // namespace explorer -} // namespace libbitcoin - From 309f892acb816ca85e9d35eb90ea458807d782bc Mon Sep 17 00:00:00 2001 From: Jowen Date: Thu, 31 Jan 2019 15:29:26 +0800 Subject: [PATCH 04/17] modify createrawtx, add --putscript option --- .../explorer/extensions/base_helper.hpp | 9 ++++++++- .../extensions/commands/createrawtx.hpp | 6 ++++++ src/lib/explorer/extensions/base_helper.cpp | 18 +++++++++++++----- .../extensions/commands/createrawtx.cpp | 3 ++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/metaverse/explorer/extensions/base_helper.hpp b/include/metaverse/explorer/extensions/base_helper.hpp index 38568e648..81d0d5bdd 100644 --- a/include/metaverse/explorer/extensions/base_helper.hpp +++ b/include/metaverse/explorer/extensions/base_helper.hpp @@ -373,6 +373,8 @@ class BCX_API base_transfer_common void set_did_verify_attachment(const receiver_record& record, chain::attachment& attach); + virtual bool include_input_script() const { return false; } + protected: bc::blockchain::block_chain_impl& blockchain_; tx_type tx_; // target transaction @@ -462,12 +464,14 @@ class BCX_API base_transaction_constructor : public base_transfer_common base_transaction_constructor(bc::blockchain::block_chain_impl& blockchain, utxo_attach_type type, std::vector&& from_vec, receiver_record::list&& receiver_list, std::string&& symbol, std::string&& change, - std::string&& message, uint64_t fee, uint32_t locktime = 0) + std::string&& message, uint64_t fee, uint32_t locktime = 0, + bool include_input_script = false) : base_transfer_common(blockchain, std::move(receiver_list), fee, std::move(symbol), "", std::move(change), locktime) , type_{type} , message_{std::move(message)} , from_vec_{std::move(from_vec)} + , include_input_script_(include_input_script) {} virtual ~base_transaction_constructor() @@ -483,10 +487,13 @@ class BCX_API base_transaction_constructor : public base_transfer_common void sign_tx_inputs() override {} void send_tx() override {} + bool include_input_script() const override { return include_input_script_; } + protected: utxo_attach_type type_{utxo_attach_type::invalid}; std::string message_; std::vector from_vec_; // from address vector + bool include_input_script_; // set input's script for offline sign }; class BCX_API sending_etp : public base_transfer_helper diff --git a/include/metaverse/explorer/extensions/commands/createrawtx.hpp b/include/metaverse/explorer/extensions/commands/createrawtx.hpp index 8eec07ae2..649ef9498 100644 --- a/include/metaverse/explorer/extensions/commands/createrawtx.hpp +++ b/include/metaverse/explorer/extensions/commands/createrawtx.hpp @@ -104,6 +104,11 @@ class createrawtx: public command_extension "Locktime. defaults to 0" ) #endif + ( + "putscript,p", + value(&option_.include_input_script)->default_value(false)->zero_tokens(), + "If specified, the input's script will be set. Defaults to not specified." + ) ( "fee,f", value(&option_.fee)->default_value(10000), @@ -138,6 +143,7 @@ class createrawtx: public command_extension std::string message; uint64_t fee; uint32_t locktime; + bool include_input_script; } option_; diff --git a/src/lib/explorer/extensions/base_helper.cpp b/src/lib/explorer/extensions/base_helper.cpp index b3d39cc25..f6f19021b 100644 --- a/src/lib/explorer/extensions/base_helper.cpp +++ b/src/lib/explorer/extensions/base_helper.cpp @@ -1047,17 +1047,18 @@ bool base_transfer_common::get_spendable_output( void base_transfer_common::sync_fetchutxo( const std::string& prikey, const std::string& addr, filter filter, const history::list& spec_rows) { - auto&& waddr = wallet::payment_address(addr); - uint64_t height = 0; blockchain_.get_last_height(height); - const auto &rows = spec_rows.empty() ? blockchain_.get_address_history(waddr, true) : spec_rows; + const auto use_specified_rows = !spec_rows.empty(); + const auto &rows = use_specified_rows + ? spec_rows + : blockchain_.get_address_history(addr, true); for (auto& row: rows) { chain::output output; - if (!spec_rows.empty()) { + if (use_specified_rows) { if (!get_spendable_output(output, row, height)) { throw std::logic_error("output spent error."); } @@ -1209,6 +1210,10 @@ void base_transfer_common::sync_fetchutxo( record.prikey = prikey; record.script = output.script; } + else if (include_input_script()) { + record.script = output.script; + } + record.addr = output.get_script_address(); record.amount = etp_amount; record.symbol = asset_symbol; @@ -1601,6 +1606,9 @@ void base_transfer_common::populate_tx_inputs() input.sequence = fromeach.sequence; input.previous_output.hash = fromeach.output.hash; input.previous_output.index = fromeach.output.index; + if (include_input_script()) { + input.script = fromeach.script; + } tx_.inputs.push_back(input); tx_item_idx_++; } @@ -1979,10 +1987,10 @@ void base_transaction_constructor::populate_unspent_list() { // get from address balances for (auto& each : from_vec_) { - sync_fetchutxo("", each); if (is_payment_satisfied()) { break; } + sync_fetchutxo("", each); } if (from_list_.empty()) { diff --git a/src/lib/explorer/extensions/commands/createrawtx.cpp b/src/lib/explorer/extensions/commands/createrawtx.cpp index a6d652013..6f560cd91 100644 --- a/src/lib/explorer/extensions/commands/createrawtx.cpp +++ b/src/lib/explorer/extensions/commands/createrawtx.cpp @@ -129,7 +129,8 @@ console_result createrawtx::invoke(Json::Value& jv_output, std::move(senders), std::move(receivers), std::move(option_.symbol), std::move(change_address), std::move(option_.message), - option_.fee, option_.locktime); + option_.fee, option_.locktime, + option_.include_input_script); break; } From ed2509d525ada14bcfef6fd88acb9331c1c6e4f6 Mon Sep 17 00:00:00 2001 From: Jowen Date: Thu, 31 Jan 2019 16:08:04 +0800 Subject: [PATCH 05/17] modify signrawtx, add --offline option --- .../extensions/commands/createrawtx.hpp | 2 +- .../extensions/commands/signrawtx.hpp | 7 +++ .../extensions/commands/signrawtx.cpp | 46 +++++++++++++------ 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/include/metaverse/explorer/extensions/commands/createrawtx.hpp b/include/metaverse/explorer/extensions/commands/createrawtx.hpp index 649ef9498..a01c29ee5 100644 --- a/include/metaverse/explorer/extensions/commands/createrawtx.hpp +++ b/include/metaverse/explorer/extensions/commands/createrawtx.hpp @@ -107,7 +107,7 @@ class createrawtx: public command_extension ( "putscript,p", value(&option_.include_input_script)->default_value(false)->zero_tokens(), - "If specified, the input's script will be set. Defaults to not specified." + "If specified, then set input's script. Default is not specified." ) ( "fee,f", diff --git a/include/metaverse/explorer/extensions/commands/signrawtx.hpp b/include/metaverse/explorer/extensions/commands/signrawtx.hpp index ea8d6b3da..5ac309034 100644 --- a/include/metaverse/explorer/extensions/commands/signrawtx.hpp +++ b/include/metaverse/explorer/extensions/commands/signrawtx.hpp @@ -86,6 +86,11 @@ class signrawtx: public command_extension "wif,w", value>(&option_.private_keys), "The wif(s) or private key(s) to sign." + ) + ( + "offline,o", + value(&option_.offline)->default_value(false)->zero_tokens(), + "If specified, then sign offline. Default is not specified." ); return options; @@ -106,11 +111,13 @@ class signrawtx: public command_extension struct option { std::vector private_keys; + bool offline; } option_; private: std::string get_private_key(blockchain::block_chain_impl& blockchain, const std::string& address); std::string get_private_key(const std::vector& keys, const std::string& address); + chain::script get_prev_output_script(blockchain::block_chain_impl& blockchain, const chain::input& input) const; bc::endorsement sign( const std::string& private_key, diff --git a/src/lib/explorer/extensions/commands/signrawtx.cpp b/src/lib/explorer/extensions/commands/signrawtx.cpp index 99e3391d0..2a002633d 100644 --- a/src/lib/explorer/extensions/commands/signrawtx.cpp +++ b/src/lib/explorer/extensions/commands/signrawtx.cpp @@ -85,20 +85,12 @@ console_result signrawtx::invoke(Json::Value& jv_output, // sign tx { uint32_t index = 0; - chain::transaction tx_temp; - uint64_t tx_height; - - for (auto& fromeach : tx_.inputs) { - if (!blockchain.get_transaction_consider_pool( - tx_temp, tx_height, fromeach.previous_output.hash)) { - throw argument_legality_exception{ - "invalid transaction hash " + encode_hash(fromeach.previous_output.hash)}; - } - auto output = tx_temp.outputs.at(fromeach.previous_output.index); + for (auto& input : tx_.inputs) { + auto prev_output_script = get_prev_output_script(blockchain, input); // get address private key - auto address = payment_address::extract(output.script); + auto address = payment_address::extract(prev_output_script); // script address : maybe multisig if (!address || (address.version() == payment_address::mainnet_p2sh)) { @@ -108,7 +100,7 @@ console_result signrawtx::invoke(Json::Value& jv_output, const auto script_vec = acc->get_script(address.encoded()); if (!script_vec || script_vec->empty()) { - throw argument_legality_exception{"invalid script: " + config::script(output.script).to_string()}; + throw argument_legality_exception{"invalid script: " + config::script(prev_output_script).to_string()}; } const auto& script = script_vec->begin(); @@ -116,7 +108,7 @@ console_result signrawtx::invoke(Json::Value& jv_output, // watch-only address const data_chunk& bin_script = script->get_script(); if (bin_script.empty()) { - throw argument_legality_exception{"watch-only script address: " + config::script(output.script).to_string()}; + throw argument_legality_exception{"watch-only script address: " + config::script(prev_output_script).to_string()}; } else { bc::explorer::config::script config_contract(bin_script); @@ -162,7 +154,7 @@ console_result signrawtx::invoke(Json::Value& jv_output, prv_key_str = get_private_key(private_keys, address.encoded()); } - bc::explorer::config::script config_contract(output.script); // previous output script + bc::explorer::config::script config_contract(prev_output_script); data_chunk public_key_data; bc::endorsement&& edsig = sign(prv_key_str, tx_, index, config_contract, public_key_data); @@ -172,7 +164,7 @@ console_result signrawtx::invoke(Json::Value& jv_output, ss.operations.push_back({bc::chain::opcode::special, edsig}); ss.operations.push_back({bc::chain::opcode::special, public_key_data}); const bc::chain::script& contract = config_contract; - // if pre-output script is deposit tx. + // if prev_output_script is deposit tx. if (contract.pattern() == bc::chain::script_pattern::pay_key_hash_with_lock_height) { uint64_t lock_height = chain::operation::get_lock_height_from_pay_key_hash_with_lock_height( contract.operations); @@ -217,6 +209,30 @@ std::string signrawtx::get_private_key(blockchain::block_chain_impl& blockchain, return acc_addr->get_prv_key(auth_.auth); } +chain::script signrawtx::get_prev_output_script( + blockchain::block_chain_impl& blockchain, const chain::input& input) const +{ + if (option_.offline) { + if (input.script.is_valid()) { + return input.script; + } + + throw argument_legality_exception{"Sign rawtx offline must specify the rawtx's input script!"}; + } + + chain::transaction tx_temp; + uint64_t tx_height; + + if (!blockchain.get_transaction_consider_pool( + tx_temp, tx_height, input.previous_output.hash)) { + throw argument_legality_exception{ + "invalid transaction hash " + encode_hash(input.previous_output.hash)}; + } + + auto output = tx_temp.outputs.at(input.previous_output.index); + return output.script; +} + bc::endorsement signrawtx::sign( const std::string& prv_key_str, tx_type tx_, From 6a29e0b535776d8d1d9d7e9751a87f7675e4c6c3 Mon Sep 17 00:00:00 2001 From: Jowen Date: Fri, 1 Feb 2019 13:02:05 +0800 Subject: [PATCH 06/17] fix gcc8 build error --- src/lib/consensus/common/libdevcore/Base64.cpp | 7 +++---- src/lib/consensus/common/libdevcore/CommonData.cpp | 5 ++--- src/lib/consensus/common/libdevcore/RLP.cpp | 3 +-- src/lib/explorer/utility.cpp | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/lib/consensus/common/libdevcore/Base64.cpp b/src/lib/consensus/common/libdevcore/Base64.cpp index df6598f24..5bde94010 100644 --- a/src/lib/consensus/common/libdevcore/Base64.cpp +++ b/src/lib/consensus/common/libdevcore/Base64.cpp @@ -29,7 +29,6 @@ //#include "Base64.h" #include -using namespace std; using namespace libbitcoin; static inline bool is_base64(byte c) @@ -47,14 +46,14 @@ static inline byte find_base64_char_index(byte c) else return 1 + find_base64_char_index('/'); } -string libbitcoin::toBase64(bytesConstRef _in) +std::string libbitcoin::toBase64(bytesConstRef _in) { static const char base64_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; - string ret; + std::string ret; int i = 0; int j = 0; byte char_array_3[3]; @@ -99,7 +98,7 @@ string libbitcoin::toBase64(bytesConstRef _in) return ret; } -bytes libbitcoin::fromBase64(string const& encoded_string) +bytes libbitcoin::fromBase64(std::string const& encoded_string) { auto in_len = encoded_string.size(); int i = 0; diff --git a/src/lib/consensus/common/libdevcore/CommonData.cpp b/src/lib/consensus/common/libdevcore/CommonData.cpp index 26b0c268c..615420e26 100644 --- a/src/lib/consensus/common/libdevcore/CommonData.cpp +++ b/src/lib/consensus/common/libdevcore/CommonData.cpp @@ -35,7 +35,6 @@ //#include "Log.h" #include #include -using namespace std; using namespace libbitcoin; namespace @@ -52,7 +51,7 @@ int fromHexChar(char _i) noexcept } } -bool libbitcoin::isHex(string const& _s) noexcept +bool libbitcoin::isHex(std::string const& _s) noexcept { auto it = _s.begin(); if (_s.compare(0, 2, "0x") == 0) @@ -62,7 +61,7 @@ bool libbitcoin::isHex(string const& _s) noexcept std::string libbitcoin::escaped(std::string const& _s, bool _all) { - static const map prettyEscapes{{'\r', 'r'}, {'\n', 'n'}, {'\t', 't'}, {'\v', 'v'}}; + static const std::map prettyEscapes{{'\r', 'r'}, {'\n', 'n'}, {'\t', 't'}, {'\v', 'v'}}; std::string ret; ret.reserve(_s.size() + 2); ret.push_back('"'); diff --git a/src/lib/consensus/common/libdevcore/RLP.cpp b/src/lib/consensus/common/libdevcore/RLP.cpp index e9434a2bc..82a7e32e1 100644 --- a/src/lib/consensus/common/libdevcore/RLP.cpp +++ b/src/lib/consensus/common/libdevcore/RLP.cpp @@ -20,7 +20,6 @@ */ #include -using namespace std; using namespace libbitcoin; bytes libbitcoin::RLPNull = rlp(""); @@ -355,7 +354,7 @@ static void streamOut(std::ostream& _out, libbitcoin::RLP const& _d, unsigned _d else if (_d.isNull()) _out << "null"; else if (_d.isInt()) - _out << std::showbase << std::hex << std::nouppercase << _d.toInt(RLP::LaissezFaire) << dec; + _out << std::showbase << std::hex << std::nouppercase << _d.toInt(RLP::LaissezFaire) << std::dec; else if (_d.isData()) _out << escaped(_d.toString(), false); else if (_d.isList()) diff --git a/src/lib/explorer/utility.cpp b/src/lib/explorer/utility.cpp index fb4638e8b..51ee50664 100644 --- a/src/lib/explorer/utility.cpp +++ b/src/lib/explorer/utility.cpp @@ -124,7 +124,7 @@ bool starts_with(const std::string& value, const std::string& prefix) { return boost::istarts_with(value, prefix); } - catch (boost::bad_lexical_cast) + catch (const boost::bad_lexical_cast&) { return false; } From 154a6d51bb0e7502faf1e8fd044872a8f9a7194a Mon Sep 17 00:00:00 2001 From: Jowen Date: Fri, 1 Feb 2019 13:59:17 +0800 Subject: [PATCH 07/17] fix gcc 8 compile error of format-truncation --- contrib/mongoose/mongoose.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/mongoose/mongoose.c b/contrib/mongoose/mongoose.c index 2585d6699..427423cc8 100644 --- a/contrib/mongoose/mongoose.c +++ b/contrib/mongoose/mongoose.c @@ -8161,7 +8161,7 @@ static void mg_send_file_data(struct mg_connection *nc, FILE *fp) { static void mg_do_ssi_include(struct mg_connection *nc, struct http_message *hm, const char *ssi, char *tag, int include_level, const struct mg_serve_http_opts *opts) { - char file_name[BUFSIZ], path[MAX_PATH_SIZE], *p; + char file_name[MAX_PATH_SIZE], path[MAX_PATH_SIZE * 2], *p; FILE *fp; /* @@ -10363,7 +10363,7 @@ int mg_dns_reply_record(struct mg_dns_reply *reply, static const char *mg_default_dns_server = "udp://" MG_DEFAULT_NAMESERVER ":53"; -MG_INTERNAL char mg_dns_server[256]; +MG_INTERNAL char mg_dns_server[256+16]; struct mg_resolve_async_request { char name[1024]; From 760dd0c9759916c8f08e270dee134a1eac65024f Mon Sep 17 00:00:00 2001 From: Jowen Date: Fri, 1 Feb 2019 18:03:02 +0800 Subject: [PATCH 08/17] fix clang6 compile error, no virtual DTOR --- include/metaverse/bitcoin/config/parameter.hpp | 2 ++ include/metaverse/bitcoin/message/get_blocks.hpp | 2 ++ include/metaverse/bitcoin/message/inventory.hpp | 2 ++ include/metaverse/database/memory/memory.hpp | 2 ++ include/metaverse/explorer/command.hpp | 1 + include/metaverse/mgbubble/Mongoose.hpp | 2 ++ include/metaverse/mgbubble/WsPushServ.hpp | 2 ++ include/metaverse/network/acceptor.hpp | 2 +- include/metaverse/network/connections.hpp | 2 +- include/metaverse/network/connector.hpp | 2 ++ include/metaverse/network/hosts.hpp | 2 ++ include/metaverse/network/protocols/protocol.hpp | 2 ++ include/metaverse/network/proxy.hpp | 2 +- include/metaverse/network/sessions/session.hpp | 2 +- include/metaverse/network/socket.hpp | 2 ++ include/metaverse/node/utility/reservation.hpp | 2 +- src/lib/bitcoin/utility/random.cpp | 1 - 17 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/metaverse/bitcoin/config/parameter.hpp b/include/metaverse/bitcoin/config/parameter.hpp index 05f238905..7007edb00 100644 --- a/include/metaverse/bitcoin/config/parameter.hpp +++ b/include/metaverse/bitcoin/config/parameter.hpp @@ -81,6 +81,8 @@ class BC_API parameter public: + virtual ~parameter() {} + /** * Sentinel - the option is not a positional argument. */ diff --git a/include/metaverse/bitcoin/message/get_blocks.hpp b/include/metaverse/bitcoin/message/get_blocks.hpp index c971d344a..ec783ce8b 100644 --- a/include/metaverse/bitcoin/message/get_blocks.hpp +++ b/include/metaverse/bitcoin/message/get_blocks.hpp @@ -49,6 +49,8 @@ class BC_API get_blocks get_blocks(const hash_list& start, const hash_digest& stop); get_blocks(hash_list&& start, hash_digest&& stop); + virtual ~get_blocks() {} + virtual bool from_data(uint32_t version, const data_chunk& data); virtual bool from_data(uint32_t version, std::istream& stream); virtual bool from_data(uint32_t version, reader& source); diff --git a/include/metaverse/bitcoin/message/inventory.hpp b/include/metaverse/bitcoin/message/inventory.hpp index 14b989799..141d9f2da 100644 --- a/include/metaverse/bitcoin/message/inventory.hpp +++ b/include/metaverse/bitcoin/message/inventory.hpp @@ -53,6 +53,8 @@ class BC_API inventory inventory(const hash_list& hashes, type_id type); inventory(const std::initializer_list& values); + virtual ~inventory() {} + virtual bool from_data(uint32_t version, const data_chunk& data); virtual bool from_data(uint32_t version, std::istream& stream); virtual bool from_data(uint32_t version, reader& source); diff --git a/include/metaverse/database/memory/memory.hpp b/include/metaverse/database/memory/memory.hpp index a4b537fc7..2075013ec 100644 --- a/include/metaverse/database/memory/memory.hpp +++ b/include/metaverse/database/memory/memory.hpp @@ -39,6 +39,8 @@ class BCD_API memory public: typedef std::shared_ptr ptr; + virtual ~memory() {} + /// Get the address indicated by the pointer. virtual uint8_t* buffer() = 0; diff --git a/include/metaverse/explorer/command.hpp b/include/metaverse/explorer/command.hpp index e6a6636bb..373b1ed96 100644 --- a/include/metaverse/explorer/command.hpp +++ b/include/metaverse/explorer/command.hpp @@ -81,6 +81,7 @@ enum : int { class BCX_API command { public: + virtual ~command() {} /** * The symbolic (not localizable) command name, lower case. diff --git a/include/metaverse/mgbubble/Mongoose.hpp b/include/metaverse/mgbubble/Mongoose.hpp index c853e531b..242cfff24 100644 --- a/include/metaverse/mgbubble/Mongoose.hpp +++ b/include/metaverse/mgbubble/Mongoose.hpp @@ -125,6 +125,8 @@ class MgEvent : public std::enable_shared_from_this { :callback_(std::move(handler)) {} + virtual ~MgEvent() {} + MgEvent* hook() { self_ = this->shared_from_this(); diff --git a/include/metaverse/mgbubble/WsPushServ.hpp b/include/metaverse/mgbubble/WsPushServ.hpp index 118a9026b..7e81a9c60 100644 --- a/include/metaverse/mgbubble/WsPushServ.hpp +++ b/include/metaverse/mgbubble/WsPushServ.hpp @@ -40,6 +40,8 @@ class WsEvent : public std::enable_shared_from_this { : callback_(std::move(handler)) {} + virtual ~WsEvent() {} + WsEvent* hook() { self_ = this->shared_from_this(); diff --git a/include/metaverse/network/acceptor.hpp b/include/metaverse/network/acceptor.hpp index af63f2561..67889d11f 100644 --- a/include/metaverse/network/acceptor.hpp +++ b/include/metaverse/network/acceptor.hpp @@ -47,7 +47,7 @@ class BCT_API acceptor acceptor(threadpool& pool, const settings& settings); /// Validate acceptor stopped. - ~acceptor(); + virtual ~acceptor(); /// This class is not copyable. acceptor(const acceptor&) = delete; diff --git a/include/metaverse/network/connections.hpp b/include/metaverse/network/connections.hpp index 2ddf6fad0..d06f7a78b 100644 --- a/include/metaverse/network/connections.hpp +++ b/include/metaverse/network/connections.hpp @@ -51,7 +51,7 @@ class BCT_API connections connections(); /// Validate connections stopped. - ~connections(); + virtual ~connections(); /// This class is not copyable. connections(const connections&) = delete; diff --git a/include/metaverse/network/connector.hpp b/include/metaverse/network/connector.hpp index 8c7571094..7bca67b8f 100644 --- a/include/metaverse/network/connector.hpp +++ b/include/metaverse/network/connector.hpp @@ -51,6 +51,8 @@ class BCT_API connector connector(const connector&) = delete; void operator=(const connector&) = delete; + virtual ~connector() {} + /// Try to connect to the endpoint. virtual void connect(const config::endpoint& endpoint, connect_handler handler, resolve_handler = nullptr); diff --git a/include/metaverse/network/hosts.hpp b/include/metaverse/network/hosts.hpp index 201eba2c6..a537fcde7 100644 --- a/include/metaverse/network/hosts.hpp +++ b/include/metaverse/network/hosts.hpp @@ -64,6 +64,8 @@ class BCT_API hosts hosts(const hosts&) = delete; void operator=(const hosts&) = delete; + virtual ~hosts() {} + /// Load hosts file if found. virtual code start(); diff --git a/include/metaverse/network/protocols/protocol.hpp b/include/metaverse/network/protocols/protocol.hpp index ae1ca8497..f5edba2f3 100644 --- a/include/metaverse/network/protocols/protocol.hpp +++ b/include/metaverse/network/protocols/protocol.hpp @@ -65,6 +65,8 @@ class BCT_API protocol protocol(const protocol&) = delete; void operator=(const protocol&) = delete; + virtual ~protocol() {} + /// Bind a method in the derived class. template auto bind(Handler&& handler, Args&&... args) -> diff --git a/include/metaverse/network/proxy.hpp b/include/metaverse/network/proxy.hpp index 49b14028d..16c689b66 100644 --- a/include/metaverse/network/proxy.hpp +++ b/include/metaverse/network/proxy.hpp @@ -58,7 +58,7 @@ class BCT_API proxy uint32_t protocol_version); /// Validate proxy stopped. - ~proxy(); + virtual ~proxy(); /// This class is not copyable. proxy(const proxy&) = delete; diff --git a/include/metaverse/network/sessions/session.hpp b/include/metaverse/network/sessions/session.hpp index 3f40ef6d1..2abb3252d 100644 --- a/include/metaverse/network/sessions/session.hpp +++ b/include/metaverse/network/sessions/session.hpp @@ -98,7 +98,7 @@ class BCT_API session session(p2p& network, bool outgoing, bool persistent); /// Validate session stopped. - ~session(); + virtual ~session(); /// This class is not copyable. session(const session&) = delete; diff --git a/include/metaverse/network/socket.hpp b/include/metaverse/network/socket.hpp index 3a4e89a63..1286e2a34 100644 --- a/include/metaverse/network/socket.hpp +++ b/include/metaverse/network/socket.hpp @@ -42,6 +42,8 @@ class BCT_API socket socket(const socket&) = delete; void operator=(const socket&) = delete; + virtual ~socket() {} + /// Obtain an exclusive reference to the socket. locked_socket::ptr get_socket(); diff --git a/include/metaverse/node/utility/reservation.hpp b/include/metaverse/node/utility/reservation.hpp index f50b2095e..693334472 100644 --- a/include/metaverse/node/utility/reservation.hpp +++ b/include/metaverse/node/utility/reservation.hpp @@ -50,7 +50,7 @@ class BCN_API reservation uint32_t block_timeout_seconds); /// Ensure there are no remaining reserved hashes. - ~reservation(); + virtual ~reservation(); /// The sequential identifier of this reservation. size_t slot() const; diff --git a/src/lib/bitcoin/utility/random.cpp b/src/lib/bitcoin/utility/random.cpp index a120f26f1..c3a04c486 100644 --- a/src/lib/bitcoin/utility/random.cpp +++ b/src/lib/bitcoin/utility/random.cpp @@ -20,7 +20,6 @@ */ #include -#include #include #include #include From e6133c58962e60d6903b3c2f5c82e88d6ae205fb Mon Sep 17 00:00:00 2001 From: Jowen Date: Fri, 1 Feb 2019 13:13:33 +0800 Subject: [PATCH 09/17] use boost::regex uniformly --- src/lib/bitcoin/config/authority.cpp | 17 +++++++---------- src/lib/bitcoin/config/checkpoint.cpp | 8 +++----- src/lib/bitcoin/config/endpoint.cpp | 8 +++----- src/lib/explorer/dispatch.cpp | 14 +++++++------- src/lib/explorer/extensions/base_helper.cpp | 16 ++++++++-------- .../explorer/extensions/commands/swaptoken.cpp | 1 - src/lib/network/connector.cpp | 1 - 7 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/lib/bitcoin/config/authority.cpp b/src/lib/bitcoin/config/authority.cpp index 9365cf8eb..dca3ea785 100644 --- a/src/lib/bitcoin/config/authority.cpp +++ b/src/lib/bitcoin/config/authority.cpp @@ -34,7 +34,6 @@ namespace libbitcoin { namespace config { -using namespace boost; using namespace boost::program_options; // host: [2001:db8::2] or 2001:db8::2 or 1.2.240.1 @@ -44,7 +43,7 @@ static std::string to_host_name(const std::string& host) if (host.find(":") == std::string::npos || host.find("[") == 0) return host; - const auto hostname = format("[%1%]") % host; + const auto hostname = boost::format("[%1%]") % host; return hostname.str(); } @@ -84,11 +83,10 @@ static asio::ipv6 to_ipv6(const asio::address& ip_address) static std::string to_ipv4_hostname(const asio::address& ip_address) { - // std::regex requires gcc 4.9, so we are using boost::regex for now. - static const regex regular("^::ffff:([0-9\\.]+)$"); + static const boost::regex regular("^::ffff:([0-9\\.]+)$"); const auto address = ip_address.to_string(); - sregex_iterator it(address.begin(), address.end(), regular), end; + boost::sregex_iterator it(address.begin(), address.end(), regular), end; if (it == end) return ""; @@ -99,7 +97,7 @@ static std::string to_ipv4_hostname(const asio::address& ip_address) static std::string to_ipv6_hostname(const asio::address& ip_address) { // IPv6 URLs use a bracketed IPv6 address, see rfc2732. - const auto hostname = format("[%1%]") % to_ipv6(ip_address); + const auto hostname = boost::format("[%1%]") % to_ipv6(ip_address); return hostname.str(); } @@ -219,11 +217,10 @@ std::istream& operator>>(std::istream& input, authority& argument) std::string value; input >> value; - // std::regex requires gcc 4.9, so we are using boost::regex for now. - static const regex regular( + static const boost::regex regular( "^(([0-9\\.]+)|\\[([0-9a-f:\\.]+)])(:([0-9]{1,5}))?$"); - sregex_iterator it(value.begin(), value.end(), regular), end; + boost::sregex_iterator it(value.begin(), value.end(), regular), end; if (it == end) { BOOST_THROW_EXCEPTION(invalid_option_value(value)); @@ -238,7 +235,7 @@ std::istream& operator>>(std::istream& input, authority& argument) try { argument.ip_ = asio::ipv6::from_string(ip_address); - argument.port_ = port.empty() ? 0 : lexical_cast(port); + argument.port_ = port.empty() ? 0 : boost::lexical_cast(port); } catch (const boost::exception&) { diff --git a/src/lib/bitcoin/config/checkpoint.cpp b/src/lib/bitcoin/config/checkpoint.cpp index 176071249..f8eafd33e 100644 --- a/src/lib/bitcoin/config/checkpoint.cpp +++ b/src/lib/bitcoin/config/checkpoint.cpp @@ -22,11 +22,10 @@ #include #include -#include +#include #include #include #include -#include #include #include #include @@ -120,10 +119,9 @@ std::istream& operator>>(std::istream& input, checkpoint& argument) std::string value; input >> value; - // std::regex requires gcc 4.9, so we are using boost::regex for now. - static const regex regular("^([0-9a-f]{64})(:([0-9]{1,20}))?$"); + static const boost::regex regular("^([0-9a-f]{64})(:([0-9]{1,20}))?$"); - sregex_iterator it(value.begin(), value.end(), regular), end; + boost::sregex_iterator it(value.begin(), value.end(), regular), end; if (it == end) { BOOST_THROW_EXCEPTION(invalid_option_value(value)); diff --git a/src/lib/bitcoin/config/endpoint.cpp b/src/lib/bitcoin/config/endpoint.cpp index 1880306c9..013544fe6 100644 --- a/src/lib/bitcoin/config/endpoint.cpp +++ b/src/lib/bitcoin/config/endpoint.cpp @@ -22,11 +22,10 @@ #include #include -#include +#include #include #include #include -#include #include #include #include @@ -113,11 +112,10 @@ std::istream& operator>>(std::istream& input, endpoint& argument) std::string value; input >> value; - // std::regex requires gcc 4.9, so we are using boost::regex for now. - static const regex regular("^((tcp|udp|http|https|inproc):\\/\\/)?" + static const boost::regex regular("^((tcp|udp|http|https|inproc):\\/\\/)?" "(\\[([0-9a-f:\\.]+)]|([^:]+))(:([0-9]{1,5}))?$"); - sregex_iterator it(value.begin(), value.end(), regular), end; + boost::sregex_iterator it(value.begin(), value.end(), regular), end; if (it == end) { BOOST_THROW_EXCEPTION(invalid_option_value(value)); diff --git a/src/lib/explorer/dispatch.cpp b/src/lib/explorer/dispatch.cpp index 7aec5d781..7ae5f05dc 100644 --- a/src/lib/explorer/dispatch.cpp +++ b/src/lib/explorer/dispatch.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include using namespace boost::filesystem; using namespace boost::program_options; @@ -187,12 +187,12 @@ console_result dispatch_command(int argc, const char* argv[], const auto& forbidden_methods = node.server_settings().forbid_rpc_methods; if (!forbidden_methods.empty()) { - const std::sregex_iterator end; + const boost::sregex_iterator end; for (const auto& item : forbidden_methods) { auto patterns = bc::split(item, ", ", true); for (const auto& pattern : patterns) { - const std::regex reg_pattern("^" + pattern + "$"); - std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); + const boost::regex reg_pattern("^" + pattern + "$"); + boost::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); if (it != end) { throw invalid_command_exception{command_name + " is forbidden with config item server.forbid_rpc_methods"}; @@ -203,12 +203,12 @@ console_result dispatch_command(int argc, const char* argv[], if (!allowed_methods.empty()) { bool allow = false; - const std::sregex_iterator end; + const boost::sregex_iterator end; for (const auto& item : allowed_methods) { auto patterns = bc::split(item, ", ", true); for (const auto& pattern : patterns) { - const std::regex reg_pattern("^" + pattern + "$"); - std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); + const boost::regex reg_pattern("^" + pattern + "$"); + boost::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); if (it != end) { allow = true; break; diff --git a/src/lib/explorer/extensions/base_helper.cpp b/src/lib/explorer/extensions/base_helper.cpp index f6f19021b..cf417a74c 100644 --- a/src/lib/explorer/extensions/base_helper.cpp +++ b/src/lib/explorer/extensions/base_helper.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace explorer { @@ -77,25 +77,25 @@ bool is_ETH_Address(const string& address) { // regex checking { - sregex_iterator end; + boost::sregex_iterator end; // check if it has the basic requirements of an address - static const regex reg_common("^0x[0-9a-fA-F]{40}$"); - sregex_iterator it(address.begin(), address.end(), reg_common); + static const boost::regex reg_common("^0x[0-9a-fA-F]{40}$"); + boost::sregex_iterator it(address.begin(), address.end(), reg_common); if (it == end) { return false; } // If it's all small caps, return true - static const regex reg_alllower("^0x[0-9a-f]{40}$"); - sregex_iterator it1(address.begin(), address.end(), reg_alllower); + static const boost::regex reg_alllower("^0x[0-9a-f]{40}$"); + boost::sregex_iterator it1(address.begin(), address.end(), reg_alllower); if (it1 != end) { return true; } // If it's all caps, return true - static const regex reg_allupper("^0x[0-9A-F]{40}$"); - sregex_iterator it2(address.begin(), address.end(), reg_allupper); + static const boost::regex reg_allupper("^0x[0-9A-F]{40}$"); + boost::sregex_iterator it2(address.begin(), address.end(), reg_allupper); if (it2 != end) { return true; } diff --git a/src/lib/explorer/extensions/commands/swaptoken.cpp b/src/lib/explorer/extensions/commands/swaptoken.cpp index 06c01e7c2..6d0d4b04a 100644 --- a/src/lib/explorer/extensions/commands/swaptoken.cpp +++ b/src/lib/explorer/extensions/commands/swaptoken.cpp @@ -27,7 +27,6 @@ #include #include #include -#include namespace libbitcoin { namespace explorer { diff --git a/src/lib/network/connector.cpp b/src/lib/network/connector.cpp index 88a942a39..99b2466d3 100644 --- a/src/lib/network/connector.cpp +++ b/src/lib/network/connector.cpp @@ -108,7 +108,6 @@ void connector::connect(const endpoint& endpoint, connect_handler handler static std::string to_ipv4_hostname(const asio::address& ip_address) { - // std::regex requires gcc 4.9, so we are using boost::regex for now. static const boost::regex regular("^::ffff:([0-9\\.]+)$"); const auto address = ip_address.to_string(); From 58151fd72e1ae9898d987133e5095f204e5cd8df Mon Sep 17 00:00:00 2001 From: Jowen Date: Fri, 1 Feb 2019 19:08:52 +0800 Subject: [PATCH 10/17] use std::regex to replace boost::regex to pass gcc8 building --- src/lib/bitcoin/config/authority.cpp | 10 +++++----- src/lib/bitcoin/config/checkpoint.cpp | 6 +++--- src/lib/bitcoin/config/endpoint.cpp | 6 +++--- src/lib/explorer/dispatch.cpp | 14 +++++++------- src/lib/explorer/extensions/base_helper.cpp | 16 ++++++++-------- src/lib/network/connector.cpp | 6 +++--- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/lib/bitcoin/config/authority.cpp b/src/lib/bitcoin/config/authority.cpp index dca3ea785..ccefca959 100644 --- a/src/lib/bitcoin/config/authority.cpp +++ b/src/lib/bitcoin/config/authority.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -83,10 +83,10 @@ static asio::ipv6 to_ipv6(const asio::address& ip_address) static std::string to_ipv4_hostname(const asio::address& ip_address) { - static const boost::regex regular("^::ffff:([0-9\\.]+)$"); + static const std::regex regular("^::ffff:([0-9\\.]+)$"); const auto address = ip_address.to_string(); - boost::sregex_iterator it(address.begin(), address.end(), regular), end; + std::sregex_iterator it(address.begin(), address.end(), regular), end; if (it == end) return ""; @@ -217,10 +217,10 @@ std::istream& operator>>(std::istream& input, authority& argument) std::string value; input >> value; - static const boost::regex regular( + static const std::regex regular( "^(([0-9\\.]+)|\\[([0-9a-f:\\.]+)])(:([0-9]{1,5}))?$"); - boost::sregex_iterator it(value.begin(), value.end(), regular), end; + std::sregex_iterator it(value.begin(), value.end(), regular), end; if (it == end) { BOOST_THROW_EXCEPTION(invalid_option_value(value)); diff --git a/src/lib/bitcoin/config/checkpoint.cpp b/src/lib/bitcoin/config/checkpoint.cpp index f8eafd33e..e8949c53e 100644 --- a/src/lib/bitcoin/config/checkpoint.cpp +++ b/src/lib/bitcoin/config/checkpoint.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -119,9 +119,9 @@ std::istream& operator>>(std::istream& input, checkpoint& argument) std::string value; input >> value; - static const boost::regex regular("^([0-9a-f]{64})(:([0-9]{1,20}))?$"); + static const std::regex regular("^([0-9a-f]{64})(:([0-9]{1,20}))?$"); - boost::sregex_iterator it(value.begin(), value.end(), regular), end; + std::sregex_iterator it(value.begin(), value.end(), regular), end; if (it == end) { BOOST_THROW_EXCEPTION(invalid_option_value(value)); diff --git a/src/lib/bitcoin/config/endpoint.cpp b/src/lib/bitcoin/config/endpoint.cpp index 013544fe6..9e26bdf32 100644 --- a/src/lib/bitcoin/config/endpoint.cpp +++ b/src/lib/bitcoin/config/endpoint.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -112,10 +112,10 @@ std::istream& operator>>(std::istream& input, endpoint& argument) std::string value; input >> value; - static const boost::regex regular("^((tcp|udp|http|https|inproc):\\/\\/)?" + static const std::regex regular("^((tcp|udp|http|https|inproc):\\/\\/)?" "(\\[([0-9a-f:\\.]+)]|([^:]+))(:([0-9]{1,5}))?$"); - boost::sregex_iterator it(value.begin(), value.end(), regular), end; + std::sregex_iterator it(value.begin(), value.end(), regular), end; if (it == end) { BOOST_THROW_EXCEPTION(invalid_option_value(value)); diff --git a/src/lib/explorer/dispatch.cpp b/src/lib/explorer/dispatch.cpp index 7ae5f05dc..7aec5d781 100644 --- a/src/lib/explorer/dispatch.cpp +++ b/src/lib/explorer/dispatch.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include using namespace boost::filesystem; using namespace boost::program_options; @@ -187,12 +187,12 @@ console_result dispatch_command(int argc, const char* argv[], const auto& forbidden_methods = node.server_settings().forbid_rpc_methods; if (!forbidden_methods.empty()) { - const boost::sregex_iterator end; + const std::sregex_iterator end; for (const auto& item : forbidden_methods) { auto patterns = bc::split(item, ", ", true); for (const auto& pattern : patterns) { - const boost::regex reg_pattern("^" + pattern + "$"); - boost::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); + const std::regex reg_pattern("^" + pattern + "$"); + std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); if (it != end) { throw invalid_command_exception{command_name + " is forbidden with config item server.forbid_rpc_methods"}; @@ -203,12 +203,12 @@ console_result dispatch_command(int argc, const char* argv[], if (!allowed_methods.empty()) { bool allow = false; - const boost::sregex_iterator end; + const std::sregex_iterator end; for (const auto& item : allowed_methods) { auto patterns = bc::split(item, ", ", true); for (const auto& pattern : patterns) { - const boost::regex reg_pattern("^" + pattern + "$"); - boost::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); + const std::regex reg_pattern("^" + pattern + "$"); + std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); if (it != end) { allow = true; break; diff --git a/src/lib/explorer/extensions/base_helper.cpp b/src/lib/explorer/extensions/base_helper.cpp index cf417a74c..5769ee632 100644 --- a/src/lib/explorer/extensions/base_helper.cpp +++ b/src/lib/explorer/extensions/base_helper.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace explorer { @@ -77,25 +77,25 @@ bool is_ETH_Address(const string& address) { // regex checking { - boost::sregex_iterator end; + std::sregex_iterator end; // check if it has the basic requirements of an address - static const boost::regex reg_common("^0x[0-9a-fA-F]{40}$"); - boost::sregex_iterator it(address.begin(), address.end(), reg_common); + static const std::regex reg_common("^0x[0-9a-fA-F]{40}$"); + std::sregex_iterator it(address.begin(), address.end(), reg_common); if (it == end) { return false; } // If it's all small caps, return true - static const boost::regex reg_alllower("^0x[0-9a-f]{40}$"); - boost::sregex_iterator it1(address.begin(), address.end(), reg_alllower); + static const std::regex reg_alllower("^0x[0-9a-f]{40}$"); + std::sregex_iterator it1(address.begin(), address.end(), reg_alllower); if (it1 != end) { return true; } // If it's all caps, return true - static const boost::regex reg_allupper("^0x[0-9A-F]{40}$"); - boost::sregex_iterator it2(address.begin(), address.end(), reg_allupper); + static const std::regex reg_allupper("^0x[0-9A-F]{40}$"); + std::sregex_iterator it2(address.begin(), address.end(), reg_allupper); if (it2 != end) { return true; } diff --git a/src/lib/network/connector.cpp b/src/lib/network/connector.cpp index 99b2466d3..ae3922750 100644 --- a/src/lib/network/connector.cpp +++ b/src/lib/network/connector.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace network { @@ -108,10 +108,10 @@ void connector::connect(const endpoint& endpoint, connect_handler handler static std::string to_ipv4_hostname(const asio::address& ip_address) { - static const boost::regex regular("^::ffff:([0-9\\.]+)$"); + static const std::regex regular("^::ffff:([0-9\\.]+)$"); const auto address = ip_address.to_string(); - boost::sregex_iterator it(address.begin(), address.end(), regular), end; + std::sregex_iterator it(address.begin(), address.end(), regular), end; if (it == end) return ""; From cc697043860467c9aad13cd8549bd3eb6207ce11 Mon Sep 17 00:00:00 2001 From: Jowen Date: Fri, 1 Feb 2019 19:14:29 +0800 Subject: [PATCH 11/17] now pass gcc8 and clang6 building with std=c++17 and boost 1.64 --- CMakeLists.txt | 19 ++++++++++--------- contrib/cryptojs/CMakeLists.txt | 2 -- contrib/jsoncpp/CMakeLists.txt | 2 -- contrib/mongoose/CMakeLists.txt | 4 ---- contrib/sodium/CMakeLists.txt | 2 -- src/lib/bitcoin/CMakeLists.txt | 1 - src/lib/bitcoin/math/external/CMakeLists.txt | 2 -- src/lib/client/CMakeLists.txt | 4 +--- src/lib/consensus/CMakeLists.txt | 8 ++------ src/lib/explorer/CMakeLists.txt | 2 -- src/lib/network/CMakeLists.txt | 1 - src/lib/protocol/CMakeLists.txt | 2 -- src/mvs-cli/CMakeLists.txt | 3 --- src/mvsd/CMakeLists.txt | 2 -- 14 files changed, 13 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 492ddfed0..d3d879df4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,11 +27,11 @@ IF(${CMAKE_CXX_COMPILER} MATCHES .*android.*) SET(ANDROID 1) ENDIF() -SET(COMMON_WARN "-Wall -Wextra -Wstrict-aliasing=2 -Wno-unused-parameter -Wno-unused-variable -Wno-type-limits") +SET(COMMON_WARN "-Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -Wno-type-limits -Wno-deprecated-declarations") if (NOT ANDROID) SET(COMMON_WARN "${COMMON_WARN} -Werror") endif() -SET(COMMON_FLAGS "-fstrict-aliasing -fvisibility=hidden") +SET(COMMON_FLAGS "-fvisibility=hidden") SET(COMMON_ARGS "${COMMON_FLAGS} ${COMMON_WARN}") IF (APPLE) @@ -43,13 +43,13 @@ ENDIF() # GXX/Clang settings IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 ${COMMON_ARGS}") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") #libbitcoin has too many ignored-qualifiers, and TODOs - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 ${COMMON_ARGS} -pthread -fno-enforce-eh-specs -fnothrow-opt -Wno-reorder -Wno-ignored-qualifiers -Wno-unused-function -Wno-unused-but-set-variable -Wno-sign-compare -Wno-unused-but-set-parameter -Wno-implicit-fallthrough") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 ${COMMON_ARGS} -pthread -fno-enforce-eh-specs -fnothrow-opt -Wno-reorder -Wno-ignored-qualifiers -Wno-unused-function -Wno-unused-but-set-variable -Wno-sign-compare -Wno-unused-but-set-parameter -Wno-implicit-fallthrough -Wno-parentheses") ELSEIF("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - SET(CMAKE_C_FLAGS "-std=c11 ${COMMON_ARGS}") - SET(CMAKE_CXX_FLAGS "-std=c++14 ${COMMON_ARGS} -Wno-reorder -Wno-ignored-qualifiers -Wno-missing-braces -Wno-mismatched-tags -Wno-sometimes-uninitialized -Wno-macro-redefined -Wno-uninitialized -Wno-unused-private-field -Wno-unused-function -Wno-implicit-fallthrough") + SET(CMAKE_C_FLAGS "-std=c11") + SET(CMAKE_CXX_FLAGS "-std=c++17 ${COMMON_ARGS} -Wno-reorder -Wno-ignored-qualifiers -Wno-missing-braces -Wno-mismatched-tags -Wno-sometimes-uninitialized -Wno-macro-redefined -Wno-uninitialized -Wno-unused-private-field -Wno-unused-function -Wno-implicit-fallthrough") ENDIF() SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fPIC") @@ -92,7 +92,7 @@ IF(USE_UPNP) ENDIF() ENDIF() -FIND_PACKAGE(Boost 1.56 REQUIRED COMPONENTS date_time filesystem system +FIND_PACKAGE(Boost 1.64 REQUIRED COMPONENTS date_time filesystem system program_options regex thread) #set(Boost_LIBRARIES ${Boost_LIBRARIES} icui18n icuuc icudata pthread dl) @@ -123,10 +123,11 @@ ENDIF() # ------------------ MVS Includes -------------------- INCLUDE_DIRECTORIES("${Boost_INCLUDE_DIRS}") -INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/contrib") -INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/include") INCLUDE_DIRECTORIES("${secp256k1_INCLUDE_DIRS}") INCLUDE_DIRECTORIES("${ZeroMQ_INCLUDE_DIRS}") +INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/contrib") +INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/include") +INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src/lib/consensus/clone") # ------------------ MVS Libraries -------------------- IF(ENABLE_SHARED_LIBS) diff --git a/contrib/cryptojs/CMakeLists.txt b/contrib/cryptojs/CMakeLists.txt index b4e5544c8..a83af684a 100644 --- a/contrib/cryptojs/CMakeLists.txt +++ b/contrib/cryptojs/CMakeLists.txt @@ -1,7 +1,5 @@ FILE(GLOB_RECURSE cryptojs_SOURCES "*.cpp") -INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/include") - ADD_LIBRARY(cryptojs_static STATIC ${cryptojs_SOURCES}) SET_TARGET_PROPERTIES(cryptojs_static PROPERTIES OUTPUT_NAME cryptojs) TARGET_LINK_LIBRARIES(cryptojs_static) diff --git a/contrib/jsoncpp/CMakeLists.txt b/contrib/jsoncpp/CMakeLists.txt index 3bda47e3e..7cbab1f73 100644 --- a/contrib/jsoncpp/CMakeLists.txt +++ b/contrib/jsoncpp/CMakeLists.txt @@ -1,7 +1,5 @@ FILE(GLOB_RECURSE jsoncpp_SOURCES "*.cpp") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") - ADD_LIBRARY(jsoncpp_static STATIC ${jsoncpp_SOURCES}) SET_TARGET_PROPERTIES(jsoncpp_static PROPERTIES OUTPUT_NAME jsoncpp) TARGET_LINK_LIBRARIES(jsoncpp_static) diff --git a/contrib/mongoose/CMakeLists.txt b/contrib/mongoose/CMakeLists.txt index be787a000..0e7aa88f6 100644 --- a/contrib/mongoose/CMakeLists.txt +++ b/contrib/mongoose/CMakeLists.txt @@ -1,9 +1,5 @@ FILE(GLOB_RECURSE mongoose_SOURCES "*.c") -#aux_source_directory(${CMAKE_CURRENT_LIST_DIR}) -#SET(mongoose_SOURCES ${CMAKE_CURRENT_LIST_DIR}) -# Mongoose does not compile with strict aliasing. -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing") IF(MG_ENABLE_DEBUG) ADD_DEFINITIONS(-DMG_ENABLE_DEBUG) ELSE() diff --git a/contrib/sodium/CMakeLists.txt b/contrib/sodium/CMakeLists.txt index 29a065e3c..fce5edf79 100644 --- a/contrib/sodium/CMakeLists.txt +++ b/contrib/sodium/CMakeLists.txt @@ -1,7 +1,5 @@ FILE(GLOB_RECURSE sodium_SOURCES "*.cpp") -INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/include") - ADD_LIBRARY(sodium_static STATIC ${sodium_SOURCES}) SET_TARGET_PROPERTIES(sodium_static PROPERTIES OUTPUT_NAME sodium) TARGET_LINK_LIBRARIES(sodium_static) diff --git a/src/lib/bitcoin/CMakeLists.txt b/src/lib/bitcoin/CMakeLists.txt index 691a3e293..f7c62035b 100644 --- a/src/lib/bitcoin/CMakeLists.txt +++ b/src/lib/bitcoin/CMakeLists.txt @@ -1,7 +1,6 @@ # for C library ADD_SUBDIRECTORY(math/external) -INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src/lib/consensus/clone") FILE(GLOB_RECURSE bitcoin_SOURCES "*.cpp") ADD_DEFINITIONS(-DBC_STATIC=1) diff --git a/src/lib/bitcoin/math/external/CMakeLists.txt b/src/lib/bitcoin/math/external/CMakeLists.txt index 2e84dcf91..242938295 100644 --- a/src/lib/bitcoin/math/external/CMakeLists.txt +++ b/src/lib/bitcoin/math/external/CMakeLists.txt @@ -1,7 +1,5 @@ FILE(GLOB bitcoinmath_SOURCES "*.c") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing") - ADD_LIBRARY(bitcoinmath_static STATIC ${bitcoinmath_SOURCES}) SET_TARGET_PROPERTIES(bitcoinmath_static PROPERTIES OUTPUT_NAME mvs_bitcoinmath) TARGET_LINK_LIBRARIES(bitcoinmath_static) diff --git a/src/lib/client/CMakeLists.txt b/src/lib/client/CMakeLists.txt index 0659b4429..d33bfd50b 100644 --- a/src/lib/client/CMakeLists.txt +++ b/src/lib/client/CMakeLists.txt @@ -2,15 +2,13 @@ FILE(GLOB_RECURSE client_SOURCES "*.cpp") ADD_DEFINITIONS(-DBCC_STATIC=1) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing") - ADD_LIBRARY(client_static STATIC ${client_SOURCES}) SET_TARGET_PROPERTIES(client_static PROPERTIES OUTPUT_NAME mvs_client) TARGET_LINK_LIBRARIES(client_static ${Boost_LIBRARIES} ${bitcoin_LIBRARY} ${protocol_LIBRARY}) INSTALL(TARGETS client_static DESTINATION lib) IF(ENABLE_SHARED_LIBS) - # ADD_DEFINITIONS(-DBCD_DLL=1) + #ADD_DEFINITIONS(-DBCD_DLL=1) ADD_LIBRARY(client_shared SHARED ${client_SOURCES}) SET_TARGET_PROPERTIES(client_shared PROPERTIES OUTPUT_NAME mvs_client) TARGET_LINK_LIBRARIES(client_shared ${Boost_LIBRARIES} ${bitcoin_LIBRARY} ${protocol_LIBRARY}) diff --git a/src/lib/consensus/CMakeLists.txt b/src/lib/consensus/CMakeLists.txt index 4d397af9f..56a8b52c2 100644 --- a/src/lib/consensus/CMakeLists.txt +++ b/src/lib/consensus/CMakeLists.txt @@ -1,8 +1,7 @@ -INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src/lib/consensus/clone") -INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src/lib/consensus/common") - FILE(GLOB_RECURSE consensus_SOURCES "*.cpp") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") + INCLUDE(CheckIncludeFile) CHECK_INCLUDE_FILE(byteswap.h HAVE_BYTESWAP_H) CHECK_INCLUDE_FILE(endian.h HAVE_ENDIAN_H) @@ -25,9 +24,6 @@ ELSE() -DHAVE_DECL_HTOBE16=0 -DHAVE_DECL_HTOBE32=0 -DHAVE_DECL_HTOBE64=0) ENDIF() -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing ") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -fpermissive") - ADD_DEFINITIONS(-DBCK_STATIC=1) ADD_LIBRARY(consensus_static STATIC ${consensus_SOURCES}) SET_TARGET_PROPERTIES(consensus_static PROPERTIES OUTPUT_NAME mvs_consensus) diff --git a/src/lib/explorer/CMakeLists.txt b/src/lib/explorer/CMakeLists.txt index 1e3761a2b..c8134a441 100644 --- a/src/lib/explorer/CMakeLists.txt +++ b/src/lib/explorer/CMakeLists.txt @@ -2,8 +2,6 @@ FILE(GLOB_RECURSE explorer_SOURCES "*.cpp") ADD_DEFINITIONS(-DBCX_STATIC=1) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") - ADD_LIBRARY(zmq_static STATIC IMPORTED) SET_TARGET_PROPERTIES(zmq_static PROPERTIES IMPORTED_LOCATION ${ZeroMQ_ROOT_DIR}/lib/libzmq.a) diff --git a/src/lib/network/CMakeLists.txt b/src/lib/network/CMakeLists.txt index 7d5ca9ffe..32a165afd 100644 --- a/src/lib/network/CMakeLists.txt +++ b/src/lib/network/CMakeLists.txt @@ -1,7 +1,6 @@ FILE(GLOB_RECURSE network_SOURCES "*.cpp") ADD_DEFINITIONS(-DBCT_STATIC=1) -# gcc-6 boost/multiprecision/cpp_int.hpp:181 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") IF(USE_UPNP) diff --git a/src/lib/protocol/CMakeLists.txt b/src/lib/protocol/CMakeLists.txt index 1eeab5562..903c9e9d5 100644 --- a/src/lib/protocol/CMakeLists.txt +++ b/src/lib/protocol/CMakeLists.txt @@ -1,7 +1,5 @@ FILE(GLOB_RECURSE protocol_SOURCES "*.cpp") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") - ADD_DEFINITIONS(-DBCP_STATIC=1) ADD_LIBRARY(zmq_static STATIC IMPORTED) diff --git a/src/mvs-cli/CMakeLists.txt b/src/mvs-cli/CMakeLists.txt index 99665e271..863a721e4 100644 --- a/src/mvs-cli/CMakeLists.txt +++ b/src/mvs-cli/CMakeLists.txt @@ -5,9 +5,6 @@ ADD_DEFINITIONS(-DBCX_STATIC=1) ADD_EXECUTABLE(mvs-cli ${mvs-cli_SOURCES}) -# for experimental/string_view -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") - IF(ENABLE_SHARED_LIBS) TARGET_LINK_LIBRARIES(mvs-cli ${mongoose_LIBRARY} ${jsoncpp_LIBRARY} ${bitcoin_LIBRARY} ${explorer_LIBRARY}) diff --git a/src/mvsd/CMakeLists.txt b/src/mvsd/CMakeLists.txt index 2fd853847..1553595c3 100644 --- a/src/mvsd/CMakeLists.txt +++ b/src/mvsd/CMakeLists.txt @@ -2,8 +2,6 @@ FILE(GLOB_RECURSE mvsd_SOURCES "*.cpp") ADD_EXECUTABLE(mvsd ${mvsd_SOURCES}) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") - IF(ENABLE_SHARED_LIBS) ADD_DEFINITIONS(-DBCS_DLL=1) TARGET_LINK_LIBRARIES(mvsd ${Boost_LIBRARIES} ${network_LIBRARY} ${database_LIBRARY} ${consensus_LIBRARY} From 383e1df9228fa1b3fbf4f2aaa0f767baddf1d3af Mon Sep 17 00:00:00 2001 From: Jowen Date: Fri, 1 Feb 2019 19:18:58 +0800 Subject: [PATCH 12/17] reset to std=c++14 and boost 1.56 as before --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3d879df4..a6f1580e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,11 +45,11 @@ ENDIF() IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") #libbitcoin has too many ignored-qualifiers, and TODOs - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 ${COMMON_ARGS} -pthread -fno-enforce-eh-specs -fnothrow-opt -Wno-reorder -Wno-ignored-qualifiers -Wno-unused-function -Wno-unused-but-set-variable -Wno-sign-compare -Wno-unused-but-set-parameter -Wno-implicit-fallthrough -Wno-parentheses") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 ${COMMON_ARGS} -pthread -fno-enforce-eh-specs -fnothrow-opt -Wno-reorder -Wno-ignored-qualifiers -Wno-unused-function -Wno-unused-but-set-variable -Wno-sign-compare -Wno-unused-but-set-parameter -Wno-implicit-fallthrough -Wno-parentheses") ELSEIF("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") SET(CMAKE_C_FLAGS "-std=c11") - SET(CMAKE_CXX_FLAGS "-std=c++17 ${COMMON_ARGS} -Wno-reorder -Wno-ignored-qualifiers -Wno-missing-braces -Wno-mismatched-tags -Wno-sometimes-uninitialized -Wno-macro-redefined -Wno-uninitialized -Wno-unused-private-field -Wno-unused-function -Wno-implicit-fallthrough") + SET(CMAKE_CXX_FLAGS "-std=c++14 ${COMMON_ARGS} -Wno-reorder -Wno-ignored-qualifiers -Wno-missing-braces -Wno-mismatched-tags -Wno-sometimes-uninitialized -Wno-macro-redefined -Wno-uninitialized -Wno-unused-private-field -Wno-unused-function -Wno-implicit-fallthrough") ENDIF() SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fPIC") @@ -92,7 +92,7 @@ IF(USE_UPNP) ENDIF() ENDIF() -FIND_PACKAGE(Boost 1.64 REQUIRED COMPONENTS date_time filesystem system +FIND_PACKAGE(Boost 1.56 REQUIRED COMPONENTS date_time filesystem system program_options regex thread) #set(Boost_LIBRARIES ${Boost_LIBRARIES} icui18n icuuc icudata pthread dl) From e566cc3852ff76418beb901255579c04702cf8d5 Mon Sep 17 00:00:00 2001 From: Jowen Date: Sat, 2 Feb 2019 10:47:53 +0800 Subject: [PATCH 13/17] fix wrong regex, brace mismatch --- src/lib/bitcoin/config/authority.cpp | 2 +- src/lib/bitcoin/config/endpoint.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/bitcoin/config/authority.cpp b/src/lib/bitcoin/config/authority.cpp index ccefca959..a0386efe0 100644 --- a/src/lib/bitcoin/config/authority.cpp +++ b/src/lib/bitcoin/config/authority.cpp @@ -218,7 +218,7 @@ std::istream& operator>>(std::istream& input, authority& argument) input >> value; static const std::regex regular( - "^(([0-9\\.]+)|\\[([0-9a-f:\\.]+)])(:([0-9]{1,5}))?$"); + "^(([0-9\\.]+)|\\[([0-9a-f:\\.]+)\\])(:([0-9]{1,5}))?$"); std::sregex_iterator it(value.begin(), value.end(), regular), end; if (it == end) diff --git a/src/lib/bitcoin/config/endpoint.cpp b/src/lib/bitcoin/config/endpoint.cpp index 9e26bdf32..e5f974031 100644 --- a/src/lib/bitcoin/config/endpoint.cpp +++ b/src/lib/bitcoin/config/endpoint.cpp @@ -113,7 +113,7 @@ std::istream& operator>>(std::istream& input, endpoint& argument) input >> value; static const std::regex regular("^((tcp|udp|http|https|inproc):\\/\\/)?" - "(\\[([0-9a-f:\\.]+)]|([^:]+))(:([0-9]{1,5}))?$"); + "(\\[([0-9a-f:\\.]+)\\]|([^:]+))(:([0-9]{1,5}))?$"); std::sregex_iterator it(value.begin(), value.end(), regular), end; if (it == end) From 643317cda0315e461d60c3d97691692d0ebb61ef Mon Sep 17 00:00:00 2001 From: Jowen Date: Sat, 2 Feb 2019 11:23:44 +0800 Subject: [PATCH 14/17] fix #346 testnet mvsd 0.9.0 not sync at block height 987948 --- src/lib/blockchain/validate_transaction.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/blockchain/validate_transaction.cpp b/src/lib/blockchain/validate_transaction.cpp index bc6ace08d..2fb0ef24a 100644 --- a/src/lib/blockchain/validate_transaction.cpp +++ b/src/lib/blockchain/validate_transaction.cpp @@ -1573,6 +1573,7 @@ code validate_transaction::check_transaction_basic() const { const chain::transaction& tx = *tx_; block_chain_impl& chain = blockchain_; + const auto is_testnet = chain.chain_settings().use_testnet_rules; if (tx.version >= transaction_version::check_output_script) { for (auto& i : tx.outputs) { @@ -1632,8 +1633,7 @@ code validate_transaction::check_transaction_basic() const } } else if (output.is_did_register()) { - auto is_test = chain.chain_settings().use_testnet_rules; - if (!block_chain_impl::is_valid_did_symbol(output.get_did_symbol(), !is_test)) { + if (!block_chain_impl::is_valid_did_symbol(output.get_did_symbol(), !is_testnet)) { return error::did_symbol_invalid; } } @@ -1699,7 +1699,7 @@ code validate_transaction::check_transaction_basic() const } } else if (chain::operation::is_pay_key_hash_with_sequence_lock_pattern(output.script.operations)) { - if (current_blockheight < pos_enabled_height) { + if (current_blockheight < pos_enabled_height && !is_testnet) { return error::pos_feature_not_activated; } } From 555765f29f114c88c63b335eff19c6855831d30b Mon Sep 17 00:00:00 2001 From: Jowen Date: Sat, 2 Feb 2019 14:27:44 +0800 Subject: [PATCH 15/17] catch exception when parsing regex --- src/lib/explorer/dispatch.cpp | 50 +++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/lib/explorer/dispatch.cpp b/src/lib/explorer/dispatch.cpp index 7aec5d781..7ba91b5d0 100644 --- a/src/lib/explorer/dispatch.cpp +++ b/src/lib/explorer/dispatch.cpp @@ -187,36 +187,46 @@ console_result dispatch_command(int argc, const char* argv[], const auto& forbidden_methods = node.server_settings().forbid_rpc_methods; if (!forbidden_methods.empty()) { - const std::sregex_iterator end; - for (const auto& item : forbidden_methods) { - auto patterns = bc::split(item, ", ", true); - for (const auto& pattern : patterns) { - const std::regex reg_pattern("^" + pattern + "$"); - std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); - if (it != end) { - throw invalid_command_exception{command_name - + " is forbidden with config item server.forbid_rpc_methods"}; + try { + const std::sregex_iterator end; + for (const auto& item : forbidden_methods) { + auto patterns = bc::split(item, ", ", true); + for (const auto& pattern : patterns) { + const std::regex reg_pattern("^" + pattern + "$"); + std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); + if (it != end) { + throw invalid_command_exception{command_name + + " is forbidden with config item server.forbid_rpc_methods"}; + } } } + } catch (const std::exception& e) { + throw std::runtime_error{command_name + + " is called. when parse config item server.forbid_rpc_methods caught exception. " + e.what()}; } } if (!allowed_methods.empty()) { bool allow = false; - const std::sregex_iterator end; - for (const auto& item : allowed_methods) { - auto patterns = bc::split(item, ", ", true); - for (const auto& pattern : patterns) { - const std::regex reg_pattern("^" + pattern + "$"); - std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); - if (it != end) { - allow = true; + try { + const std::sregex_iterator end; + for (const auto& item : allowed_methods) { + auto patterns = bc::split(item, ", ", true); + for (const auto& pattern : patterns) { + const std::regex reg_pattern("^" + pattern + "$"); + std::sregex_iterator it(command_name.begin(), command_name.end(), reg_pattern); + if (it != end) { + allow = true; + break; + } + } + if (allow) { break; } } - if (allow) { - break; - } + } catch (const std::exception& e) { + throw std::runtime_error{command_name + + " is called. when parse config item server.allow_rpc_methods caught exception. " + e.what()}; } if (!allow) { throw invalid_command_exception{command_name From 8eebbbaca0e80070de4ce3646ca3d49e8b48781b Mon Sep 17 00:00:00 2001 From: Jowen Date: Sat, 2 Feb 2019 16:56:42 +0800 Subject: [PATCH 16/17] add --type option for getasset command --- .../explorer/extensions/commands/getasset.hpp | 6 ++++++ src/lib/explorer/extensions/commands/getasset.cpp | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/metaverse/explorer/extensions/commands/getasset.hpp b/include/metaverse/explorer/extensions/commands/getasset.hpp index 3e95b6baf..5974e7d0e 100644 --- a/include/metaverse/explorer/extensions/commands/getasset.hpp +++ b/include/metaverse/explorer/extensions/commands/getasset.hpp @@ -73,6 +73,11 @@ class getasset: public command_extension value(&option_.is_cert)->default_value(false)->zero_tokens(), "If specified, then only get related cert. Default is not specified." ) + ( + "type,t", + value(&option_.cert_type)->default_value(""), + "If specified, then only get related type of cert. Default is not specified." + ) ( "issuer,i", value(&option_.issuer)->default_value(""), @@ -103,6 +108,7 @@ class getasset: public command_extension struct option { bool is_cert; + std::string cert_type; std::string issuer; } option_; diff --git a/src/lib/explorer/extensions/commands/getasset.cpp b/src/lib/explorer/extensions/commands/getasset.cpp index e7444ae0c..5da352a37 100644 --- a/src/lib/explorer/extensions/commands/getasset.cpp +++ b/src/lib/explorer/extensions/commands/getasset.cpp @@ -48,16 +48,24 @@ console_result getasset::invoke(Json::Value& jv_output, Json::Value json_value; auto json_helper = config::json_helper(get_api_version()); - if (option_.is_cert) { // only get asset certs + if (option_.is_cert || !option_.cert_type.empty()) { // only get asset certs json_key = "assetcerts"; + chain::asset_cert_type cert_type = asset_cert_ns::none; + if (!option_.cert_type.empty()) { + cert_type = check_cert_type_name(option_.cert_type, true); + } + // get asset cert in blockchain auto sh_vec = blockchain.get_issued_asset_certs(address); if (argument_.symbol.empty()) { std::set symbols; std::sort(sh_vec->begin(), sh_vec->end()); for (auto& elem : *sh_vec) { - // get rid of duplicate symbols + if (cert_type != asset_cert_ns::none && elem.get_type() != cert_type) { + continue; + } + // get rid of duplicate symbols if (!symbols.count(elem.get_symbol())) { symbols.insert(elem.get_symbol()); json_value.append(elem.get_symbol()); @@ -67,6 +75,9 @@ console_result getasset::invoke(Json::Value& jv_output, else { auto result_vec = std::make_shared(); for (auto& cert : *sh_vec) { + if (cert_type != asset_cert_ns::none && cert.get_type() != cert_type) { + continue; + } if (argument_.symbol != cert.get_symbol()) { continue; } From fa2648b07ccd1ad5c36ab3ffc26b3125400b3f9a Mon Sep 17 00:00:00 2001 From: jowenshaw Date: Sat, 2 Feb 2019 20:27:43 +0800 Subject: [PATCH 17/17] fix #348 Wrong recive height for pending transaciton, should be 0 as before. --- include/metaverse/blockchain/block_chain_impl.hpp | 2 +- src/lib/blockchain/block_chain_impl.cpp | 7 +++++-- src/lib/explorer/extensions/base_helper.cpp | 5 ++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/metaverse/blockchain/block_chain_impl.hpp b/include/metaverse/blockchain/block_chain_impl.hpp index b1629f19b..53921aa5b 100644 --- a/include/metaverse/blockchain/block_chain_impl.hpp +++ b/include/metaverse/blockchain/block_chain_impl.hpp @@ -402,7 +402,7 @@ class BCB_API block_chain_impl void fired() override; organizer& get_organizer() override; bool get_transaction_consider_pool( - chain::transaction& tx, uint64_t& tx_height, const hash_digest& hash); + chain::transaction& tx, uint64_t& tx_height, const hash_digest& hash, bool* is_in_pool=nullptr); bool get_history(const wallet::payment_address& address, uint64_t limit, uint64_t from_height, chain::history_compact::list& history); code validate_transaction(const chain::transaction& tx); diff --git a/src/lib/blockchain/block_chain_impl.cpp b/src/lib/blockchain/block_chain_impl.cpp index 1f9ae2fd5..51ac11909 100644 --- a/src/lib/blockchain/block_chain_impl.cpp +++ b/src/lib/blockchain/block_chain_impl.cpp @@ -2544,7 +2544,7 @@ organizer& block_chain_impl::get_organizer() } bool block_chain_impl::get_transaction_consider_pool( - chain::transaction& tx, uint64_t& tx_height, const hash_digest& hash) + chain::transaction& tx, uint64_t& tx_height, const hash_digest& hash, bool* is_in_pool) { bool ret = false; @@ -2573,7 +2573,10 @@ bool block_chain_impl::get_transaction_consider_pool( boost::unique_lock lock(mutex); if(tx_ptr) { tx = *tx_ptr; - tx_height = max_uint64; + tx_height = 0; + if (is_in_pool) { + *is_in_pool = true; + } ret = true; } } diff --git a/src/lib/explorer/extensions/base_helper.cpp b/src/lib/explorer/extensions/base_helper.cpp index 5769ee632..c30479723 100644 --- a/src/lib/explorer/extensions/base_helper.cpp +++ b/src/lib/explorer/extensions/base_helper.cpp @@ -1013,12 +1013,11 @@ bool base_transfer_common::get_spendable_output( chain::transaction tx_temp; uint64_t tx_height; - if (!blockchain_.get_transaction_consider_pool(tx_temp, tx_height, row.output.hash)) { + bool is_in_pool = false; + if (!blockchain_.get_transaction_consider_pool(tx_temp, tx_height, row.output.hash, &is_in_pool)) { return false; } - const auto is_in_pool = tx_height == max_uint64; - BITCOIN_ASSERT(row.output.index < tx_temp.outputs.size()); output = tx_temp.outputs.at(row.output.index);