Skip to content

Commit

Permalink
fixed conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
paybee committed Jun 2, 2014
2 parents 295c284 + 24b4f47 commit 133019c
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 43 deletions.
19 changes: 15 additions & 4 deletions src/cryptonote_core/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,19 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::is_mining()
bool miner::is_mining() const
{
return !m_stop;
}
//-----------------------------------------------------------------------------------------------------
const account_public_address& miner::get_mining_address() const
{
return m_mine_address;
}
//-----------------------------------------------------------------------------------------------------
uint32_t miner::get_threads_count() const {
return m_threads_total;
}
//-----------------------------------------------------------------------------------------------------
bool miner::start(const account_public_address& adr, size_t threads_count, const boost::thread::attributes& attrs)
{
Expand Down Expand Up @@ -226,12 +235,14 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------------
uint64_t miner::get_speed()
uint64_t miner::get_speed() const
{
if(is_mining())
if(is_mining()) {
return m_current_hash_rate;
else
}
else {
return 0;
}
}
//-----------------------------------------------------------------------------------------------------
void miner::send_stop_signal()
Expand Down
6 changes: 4 additions & 2 deletions src/cryptonote_core/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ namespace cryptonote
bool set_block_template(const block& bl, const difficulty_type& diffic, uint64_t height);
bool on_block_chain_update();
bool start(const account_public_address& adr, size_t threads_count, const boost::thread::attributes& attrs);
uint64_t get_speed();
uint64_t get_speed() const;
uint32_t get_threads_count() const;
void send_stop_signal();
bool stop();
bool is_mining();
bool is_mining() const;
const account_public_address& get_mining_address() const;
bool on_idle();
void on_synchronized();
//synchronous analog (for fast calls)
Expand Down
58 changes: 40 additions & 18 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,38 @@ namespace cryptonote
return epee::http_server_impl_base<core_rpc_server, connection_context>::init(m_port, m_bind_ip);
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::check_core_ready()
bool core_rpc_server::check_core_busy()
{
if(!m_p2p.get_payload_object().is_synchronized())
if(m_p2p.get_payload_object().get_core().get_blockchain_storage().is_storing_blockchain())
{
return false;
}
if(m_p2p.get_payload_object().get_core().get_blockchain_storage().is_storing_blockchain())
return true;
}
#define CHECK_CORE_BUSY() if(!check_core_busy()){res.status = CORE_RPC_STATUS_BUSY;return true;}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::check_core_ready()
{
if(!m_p2p.get_payload_object().is_synchronized())
{
return false;
}
return true;
return check_core_busy();
}
#define CHECK_CORE_READY() if(!check_core_ready()){res.status = CORE_RPC_STATUS_BUSY;return true;}

//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_height(const COMMAND_RPC_GET_HEIGHT::request& req, COMMAND_RPC_GET_HEIGHT::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
CHECK_CORE_BUSY();
res.height = m_core.get_current_blockchain_height();
res.status = CORE_RPC_STATUS_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_info(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
CHECK_CORE_BUSY();
res.height = m_core.get_current_blockchain_height();
res.difficulty = m_core.get_blockchain_storage().get_difficulty_for_next_block();
res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase
Expand All @@ -90,7 +96,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
CHECK_CORE_BUSY();
std::list<std::pair<block, std::list<transaction> > > bs;
if(!m_core.find_blockchain_supplement(req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
{
Expand All @@ -114,7 +120,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_random_outs(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
CHECK_CORE_BUSY();
res.status = "Failed";
if(!m_core.get_random_outs_for_amounts(req, res))
{
Expand Down Expand Up @@ -143,7 +149,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_indexes(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
CHECK_CORE_BUSY();
bool r = m_core.get_tx_outputs_gindexs(req.txid, res.o_indexes);
if(!r)
{
Expand All @@ -157,7 +163,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request& req, COMMAND_RPC_GET_TRANSACTIONS::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
CHECK_CORE_BUSY();
std::vector<crypto::hash> vh;
BOOST_FOREACH(const auto& tx_hex_str, req.txs_hashes)
{
Expand Down Expand Up @@ -232,7 +238,6 @@ namespace cryptonote
return true;
}


NOTIFY_NEW_TRANSACTIONS::request r;
r.txs.push_back(tx_blob);
m_core.get_protocol()->relay_transactions(r, fake_context);
Expand Down Expand Up @@ -265,7 +270,6 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_stop_mining(const COMMAND_RPC_STOP_MINING::request& req, COMMAND_RPC_STOP_MINING::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
if(!m_core.get_miner().stop())
{
res.status = "Failed, mining not stopped";
Expand All @@ -275,9 +279,27 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res, connection_context& cntx)
bool core_rpc_server::on_mining_status(const COMMAND_RPC_MINING_STATUS::request& req, COMMAND_RPC_MINING_STATUS::response& res, connection_context& cntx)
{
CHECK_CORE_READY();

const miner& lMiner = m_core.get_miner();
res.active = lMiner.is_mining();

if ( lMiner.is_mining() ) {
res.speed = lMiner.get_speed();
res.threads_count = lMiner.get_threads_count();
const account_public_address& lMiningAdr = lMiner.get_mining_address();
res.address = get_account_address_as_str(lMiningAdr);
}

res.status = CORE_RPC_STATUS_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res, connection_context& cntx)
{
CHECK_CORE_BUSY();
if( !m_core.get_blockchain_storage().store_blockchain() )
{
res.status = "Error while storing blockhain";
Expand All @@ -289,15 +311,15 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
CHECK_CORE_BUSY();
res.count = m_core.get_current_blockchain_height();
res.status = CORE_RPC_STATUS_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request& req, COMMAND_RPC_GETBLOCKHASH::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
{
if(!check_core_ready())
if(!check_core_busy())
{
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
error_resp.message = "Core is busy";
Expand Down Expand Up @@ -455,7 +477,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request& req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
{
if(!check_core_ready())
if(!check_core_busy())
{
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
error_resp.message = "Core is busy.";
Expand Down Expand Up @@ -490,7 +512,7 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_block_header_by_hash(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response& res, epee::json_rpc::error& error_resp, connection_context& cntx){
if(!check_core_ready())
if(!check_core_busy())
{
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
error_resp.message = "Core is busy.";
Expand Down Expand Up @@ -531,7 +553,7 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response& res, epee::json_rpc::error& error_resp, connection_context& cntx){
if(!check_core_ready())
if(!check_core_busy())
{
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
error_resp.message = "Core is busy.";
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/core_rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace cryptonote
MAP_URI_AUTO_JON2("/sendrawtransaction", on_send_raw_tx, COMMAND_RPC_SEND_RAW_TX)
MAP_URI_AUTO_JON2("/start_mining", on_start_mining, COMMAND_RPC_START_MINING)
MAP_URI_AUTO_JON2("/stop_mining", on_stop_mining, COMMAND_RPC_STOP_MINING)
MAP_URI_AUTO_JON2("/mining_status", on_mining_status, COMMAND_RPC_MINING_STATUS)
MAP_URI_AUTO_JON2("/save_bc", on_save_bc, COMMAND_RPC_SAVE_BC)
MAP_URI_AUTO_JON2("/getinfo", on_get_info, COMMAND_RPC_GET_INFO)
BEGIN_JSON_RPC_MAP("/json_rpc")
Expand All @@ -60,6 +61,7 @@ namespace cryptonote
bool on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request& req, COMMAND_RPC_SEND_RAW_TX::response& res, connection_context& cntx);
bool on_start_mining(const COMMAND_RPC_START_MINING::request& req, COMMAND_RPC_START_MINING::response& res, connection_context& cntx);
bool on_stop_mining(const COMMAND_RPC_STOP_MINING::request& req, COMMAND_RPC_STOP_MINING::response& res, connection_context& cntx);
bool on_mining_status(const COMMAND_RPC_MINING_STATUS::request& req, COMMAND_RPC_MINING_STATUS::response& res, connection_context& cntx);
bool on_get_random_outs(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res, connection_context& cntx);
bool on_get_info(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, connection_context& cntx);
bool on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res, connection_context& cntx);
Expand All @@ -74,6 +76,7 @@ namespace cryptonote
bool on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
//-----------------------
bool handle_command_line(const boost::program_options::variables_map& vm);
bool check_core_busy();
bool check_core_ready();

//utils
Expand Down
29 changes: 29 additions & 0 deletions src/rpc/core_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,35 @@ namespace cryptonote
};
};

//-----------------------------------------------
struct COMMAND_RPC_MINING_STATUS
{
struct request
{

BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};


struct response
{
std::string status;
bool active;
uint64_t speed;
uint32_t threads_count;
std::string address;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
KV_SERIALIZE(active)
KV_SERIALIZE(speed)
KV_SERIALIZE(threads_count)
KV_SERIALIZE(address)
END_KV_SERIALIZE_MAP()
};
};

//-----------------------------------------------
struct COMMAND_RPC_SAVE_BC
{
Expand Down
23 changes: 5 additions & 18 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,6 @@ namespace
return err;
}

bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id)
{
blobdata payment_id_data;
if(!string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_data))
return false;

if(sizeof(crypto::hash) != payment_id_data.size())
return false;

payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_data.data());
return true;
}

class message_writer
{
public:
Expand Down Expand Up @@ -680,7 +667,7 @@ bool simple_wallet::show_payments(const std::vector<std::string> &args)
for(std::string arg : args)
{
crypto::hash payment_id;
if(parse_payment_id(arg, payment_id))
if(tools::wallet2::parse_payment_id(arg, payment_id))
{
std::list<tools::wallet2::payment_details> payments;
m_wallet->get_payments(payment_id, payments);
Expand Down Expand Up @@ -763,7 +750,7 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_)
local_args.pop_back();

crypto::hash payment_id;
bool r = parse_payment_id(payment_id_str, payment_id);
bool r = tools::wallet2::parse_payment_id(payment_id_str, payment_id);
if(r)
{
std::string extra_nonce;
Expand Down Expand Up @@ -944,7 +931,7 @@ int main(int argc, char* argv[])

if (command_line::get_arg(vm, command_line::arg_help))
{
success_msg_writer() << "bytecoin wallet v" << PROJECT_VERSION_LONG;
success_msg_writer() << CRYPTONOTE_NAME << " wallet v" << PROJECT_VERSION_LONG;
success_msg_writer() << "Usage: simplewallet [--wallet-file=<file>|--generate-new-wallet=<file>] [--daemon-address=<host>:<port>] [<COMMAND>]";
success_msg_writer() << desc_all << '\n' << w.get_commands_str();
return false;
Expand All @@ -961,7 +948,7 @@ int main(int argc, char* argv[])
return true;
});
if (!r)
return 1;
return 0;

//set up logging options
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2);
Expand Down Expand Up @@ -1069,6 +1056,6 @@ int main(int argc, char* argv[])
w.deinit();
}
}
return 1;
return 0;
//CATCH_ENTRY_L0("main", 1);
}
14 changes: 14 additions & 0 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using namespace epee;
#include "profile_tools.h"
#include "crypto/crypto.h"
#include "serialization/binary_utils.h"
#include "cryptonote_protocol/blobdatatype.h"

using namespace cryptonote;

Expand Down Expand Up @@ -465,6 +466,19 @@ void wallet2::wallet_exists(const std::string& file_path, bool& keys_file_exists
wallet_file_exists = boost::filesystem::exists(wallet_file, ignore);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id)
{
cryptonote::blobdata payment_id_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_data))
return false;

if(sizeof(crypto::hash) != payment_id_data.size())
return false;

payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_data.data());
return true;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::prepare_file_names(const std::string& file_path)
{
do_prepare_file_names(file_path, m_keys_file, m_wallet_file);
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ namespace tools

static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists);

static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);

private:
bool store_keys(const std::string& keys_file_name, const std::string& password);
void load_keys(const std::string& keys_file_name, const std::string& password);
Expand Down
Loading

0 comments on commit 133019c

Please sign in to comment.