forked from lthn/blockchain
rpc: removed old deprecated mining API (get_addenum, getjob, submitshare, etc.)
This commit is contained in:
parent
452047cb88
commit
185ccae95f
4 changed files with 6 additions and 339 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2022 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
|
|
@ -35,8 +35,11 @@ namespace currency
|
|||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
core_rpc_server::core_rpc_server(core& cr, nodetool::node_server<currency::t_currency_protocol_handler<currency::core> >& p2p,
|
||||
bc_services::bc_offers_service& of
|
||||
) :m_core(cr), m_p2p(p2p), m_of(of), m_session_counter(0), m_ignore_status(false)
|
||||
bc_services::bc_offers_service& of)
|
||||
: m_core(cr)
|
||||
, m_p2p(p2p)
|
||||
, m_of(of)
|
||||
, m_ignore_status(false)
|
||||
{}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::handle_command_line(const boost::program_options::variables_map& vm)
|
||||
|
|
@ -1156,109 +1159,6 @@ namespace currency
|
|||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::get_current_hi(mining::height_info& hi)
|
||||
{
|
||||
block prev_block = AUTO_VAL_INIT(prev_block);
|
||||
m_core.get_blockchain_storage().get_top_block(prev_block);
|
||||
hi.block_id = string_tools::pod_to_hex(currency::get_block_hash(prev_block));
|
||||
hi.height = get_block_height(prev_block);
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
void core_rpc_server::set_session_blob(const std::string& session_id, const currency::block& blob)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_session_jobs_lock);
|
||||
m_session_jobs[session_id] = blob;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::get_session_blob(const std::string& session_id, currency::block& blob)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_session_jobs_lock);
|
||||
auto it = m_session_jobs.find(session_id);
|
||||
if(it == m_session_jobs.end())
|
||||
return false;
|
||||
|
||||
blob = it->second;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::get_job(const std::string& job_id, mining::job_details& job, epee::json_rpc::error& err, connection_context& cntx)
|
||||
{
|
||||
COMMAND_RPC_GETBLOCKTEMPLATE::request bt_req = AUTO_VAL_INIT(bt_req);
|
||||
COMMAND_RPC_GETBLOCKTEMPLATE::response bt_res = AUTO_VAL_INIT(bt_res);
|
||||
|
||||
// !!!!!!!! SET YOUR WALLET ADDRESS HERE !!!!!!!!
|
||||
bt_req.wallet_address = "1HNJjUsofq5LYLoXem119dd491yFAb5g4bCHkecV4sPqigmuxw57Ci9am71fEN4CRmA9jgnvo5PDNfaq8QnprWmS5uLqnbq";
|
||||
|
||||
if(!on_getblocktemplate(bt_req, bt_res, err, cntx))
|
||||
return false;
|
||||
|
||||
//patch block blob if you need(bt_res.blocktemplate_blob), and than load block from blob template
|
||||
//important: you can't change block size, since it could touch reward and block became invalid
|
||||
|
||||
block b = AUTO_VAL_INIT(b);
|
||||
std::string bin_buff;
|
||||
bool r = string_tools::parse_hexstr_to_binbuff(bt_res.blocktemplate_blob, bin_buff);
|
||||
CHECK_AND_ASSERT_MES(r, false, "internal error, failed to parse hex block");
|
||||
r = currency::parse_and_validate_block_from_blob(bin_buff, b);
|
||||
CHECK_AND_ASSERT_MES(r, false, "internal error, failed to parse block");
|
||||
|
||||
set_session_blob(job_id, b);
|
||||
job.blob = string_tools::buff_to_hex_nodelimer(currency::get_block_hashing_blob(b));
|
||||
//TODO: set up share difficulty here!
|
||||
job.difficulty = bt_res.difficulty; //difficulty leaved as string field since it will be refactored into 128 bit format
|
||||
job.job_id = "SOME_JOB_ID";
|
||||
get_current_hi(job.prev_hi);
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_login(const mining::COMMAND_RPC_LOGIN::request& req, mining::COMMAND_RPC_LOGIN::response& res, connection_context& cntx)
|
||||
{
|
||||
if(!check_core_ready())
|
||||
{
|
||||
res.status = API_RETURN_CODE_BUSY;
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO: add login information here
|
||||
|
||||
|
||||
res.id = std::to_string(m_session_counter++); //session id
|
||||
|
||||
if(req.hi.height)
|
||||
{
|
||||
epee::json_rpc::error err = AUTO_VAL_INIT(err);
|
||||
if(!get_job(res.id, res.job, err, cntx))
|
||||
{
|
||||
res.status = err.message;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
res.status = API_RETURN_CODE_OK;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_getjob(const mining::COMMAND_RPC_GETJOB::request& req, mining::COMMAND_RPC_GETJOB::response& res, connection_context& cntx)
|
||||
{
|
||||
if(!check_core_ready())
|
||||
{
|
||||
res.status = API_RETURN_CODE_BUSY;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*epee::json_rpc::error err = AUTO_VAL_INIT(err);
|
||||
if(!get_job(req.id, res.jd, err, cntx))
|
||||
{
|
||||
res.status = err.message;
|
||||
return true;
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_alias_reward(const COMMAND_RPC_GET_ALIAS_REWARD::request& req, COMMAND_RPC_GET_ALIAS_REWARD::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
|
||||
{
|
||||
|
|
@ -1324,45 +1224,6 @@ namespace currency
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_submit(const mining::COMMAND_RPC_SUBMITSHARE::request& req, mining::COMMAND_RPC_SUBMITSHARE::response& res, connection_context& cntx)
|
||||
{
|
||||
if(!check_core_ready())
|
||||
{
|
||||
res.status = API_RETURN_CODE_BUSY;
|
||||
return true;
|
||||
}
|
||||
block b = AUTO_VAL_INIT(b);
|
||||
if(!get_session_blob(req.id, b))
|
||||
{
|
||||
res.status = "Wrong session id";
|
||||
return true;
|
||||
}
|
||||
|
||||
b.nonce = req.nonce;
|
||||
|
||||
if(!m_core.handle_block_found(b))
|
||||
{
|
||||
res.status = "Block not accepted";
|
||||
LOG_ERROR("Submited block not accepted");
|
||||
return true;
|
||||
}
|
||||
res.status = API_RETURN_CODE_OK;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_addendums(const COMMAND_RPC_GET_ADDENDUMS::request& req, COMMAND_RPC_GET_ADDENDUMS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
|
||||
{
|
||||
if (!check_core_ready())
|
||||
{
|
||||
res.status = API_RETURN_CODE_BUSY;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
res.status = API_RETURN_CODE_OK;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_reset_transaction_pool(const COMMAND_RPC_RESET_TX_POOL::request& req, COMMAND_RPC_RESET_TX_POOL::response& res, connection_context& cntx)
|
||||
{
|
||||
m_core.get_tx_pool().purge_transactions();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
#include "currency_core/currency_core.h"
|
||||
#include "p2p/net_node.h"
|
||||
#include "currency_protocol/currency_protocol_handler.h"
|
||||
#include "mining_protocol_defs.h"
|
||||
#include "currency_core/bc_offers_service.h"
|
||||
|
||||
|
||||
|
|
@ -72,7 +71,6 @@ namespace currency
|
|||
bool on_get_aliases(const COMMAND_RPC_GET_ALIASES::request& req, COMMAND_RPC_GET_ALIASES::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||
bool on_aliases_by_address(const COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& req, COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||
bool on_get_alias_reward(const COMMAND_RPC_GET_ALIAS_REWARD::request& req, COMMAND_RPC_GET_ALIAS_REWARD::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||
bool on_get_addendums(const COMMAND_RPC_GET_ADDENDUMS::request& req, COMMAND_RPC_GET_ADDENDUMS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||
bool on_reset_transaction_pool(const COMMAND_RPC_RESET_TX_POOL::request& req, COMMAND_RPC_RESET_TX_POOL::response& res, connection_context& cntx);
|
||||
bool on_get_pos_mining_details(const COMMAND_RPC_GET_POS_MINING_DETAILS::request& req, COMMAND_RPC_GET_POS_MINING_DETAILS::response& res, connection_context& cntx);
|
||||
bool on_get_current_core_tx_expiration_median(const COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::request& req, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::response& res, connection_context& cntx);
|
||||
|
|
@ -93,15 +91,6 @@ namespace currency
|
|||
|
||||
|
||||
|
||||
//mining rpc
|
||||
bool on_login(const mining::COMMAND_RPC_LOGIN::request& req, mining::COMMAND_RPC_LOGIN::response& res, connection_context& cntx);
|
||||
bool on_getjob(const mining::COMMAND_RPC_GETJOB::request& req, mining::COMMAND_RPC_GETJOB::response& res, connection_context& cntx);
|
||||
bool on_submit(const mining::COMMAND_RPC_SUBMITSHARE::request& req, mining::COMMAND_RPC_SUBMITSHARE::response& res, connection_context& cntx);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CHAIN_HTTP_TO_MAP2(connection_context); //forward http requests to uri map
|
||||
|
||||
BEGIN_URI_MAP2()
|
||||
|
|
@ -157,10 +146,6 @@ namespace currency
|
|||
MAP_JON_RPC ("get_current_core_tx_expiration_median", on_get_current_core_tx_expiration_median, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN)
|
||||
//
|
||||
MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX)
|
||||
//remote miner rpc
|
||||
MAP_JON_RPC_N(on_login, mining::COMMAND_RPC_LOGIN)
|
||||
MAP_JON_RPC_N(on_getjob, mining::COMMAND_RPC_GETJOB)
|
||||
MAP_JON_RPC_N(on_submit, mining::COMMAND_RPC_SUBMITSHARE)
|
||||
END_JSON_RPC_MAP()
|
||||
END_URI_MAP2()
|
||||
|
||||
|
|
@ -169,8 +154,6 @@ namespace currency
|
|||
//-----------------------
|
||||
bool handle_command_line(const boost::program_options::variables_map& vm);
|
||||
bool check_core_ready_(const std::string& calling_method);
|
||||
bool get_job(const std::string& job_id, mining::job_details& job, epee::json_rpc::error& err, connection_context& cntx);
|
||||
bool get_current_hi(mining::height_info& hi);
|
||||
|
||||
//utils
|
||||
uint64_t get_block_reward(const block& blk);
|
||||
|
|
@ -184,10 +167,6 @@ namespace currency
|
|||
std::string m_port;
|
||||
std::string m_bind_ip;
|
||||
bool m_ignore_status;
|
||||
//mining stuff
|
||||
epee::critical_section m_session_jobs_lock;
|
||||
std::map<std::string, currency::block> m_session_jobs; //session id -> blob
|
||||
std::atomic<size_t> m_session_counter;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include "currency_core/difficulty.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "p2p/p2p_protocol_defs.h"
|
||||
#include "rpc/mining_protocol_defs.h"
|
||||
#include "storages/portable_storage_base.h"
|
||||
#include "currency_core/offers_service_basics.h"
|
||||
#include "currency_core/basic_api_response_codes.h"
|
||||
|
|
@ -1084,25 +1083,6 @@ namespace currency
|
|||
};
|
||||
|
||||
|
||||
struct COMMAND_RPC_GET_ADDENDUMS
|
||||
{
|
||||
|
||||
typedef mining::height_info request;
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string status;
|
||||
std::list<mining::addendum> addms;
|
||||
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
KV_SERIALIZE(addms)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct COMMAND_RPC_RESET_TX_POOL
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -1,153 +0,0 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#pragma once
|
||||
#include "currency_protocol/currency_protocol_defs.h"
|
||||
#include "currency_core/currency_basic.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "net/rpc_method_name.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Seems to be obsolete. Consider removing due to stratum support.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace mining
|
||||
{
|
||||
struct height_info
|
||||
{
|
||||
uint64_t height;
|
||||
std::string block_id;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(height)
|
||||
KV_SERIALIZE(block_id)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
struct addendum
|
||||
{
|
||||
height_info hi;
|
||||
std::string prev_id;
|
||||
std::string addm;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(hi)
|
||||
KV_SERIALIZE(prev_id)
|
||||
KV_SERIALIZE(addm)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct job_details
|
||||
{
|
||||
std::string blob;
|
||||
std::string difficulty;
|
||||
std::string job_id;
|
||||
height_info prev_hi;
|
||||
std::list<addendum> addms;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(blob)
|
||||
KV_SERIALIZE(difficulty)
|
||||
KV_SERIALIZE(job_id)
|
||||
KV_SERIALIZE(prev_hi)
|
||||
KV_SERIALIZE(addms)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct COMMAND_RPC_LOGIN
|
||||
{
|
||||
RPC_METHOD_NAME("login");
|
||||
|
||||
struct request
|
||||
{
|
||||
std::string login;
|
||||
std::string pass;
|
||||
std::string agent;
|
||||
height_info hi;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(login)
|
||||
KV_SERIALIZE(pass)
|
||||
KV_SERIALIZE(agent)
|
||||
KV_SERIALIZE(hi)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string status;
|
||||
std::string id;
|
||||
job_details job;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(job)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
struct COMMAND_RPC_GETJOB
|
||||
{
|
||||
RPC_METHOD_NAME("getjob");
|
||||
|
||||
struct request
|
||||
{
|
||||
std::string id;
|
||||
height_info hi;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(hi)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string status;
|
||||
job_details jd;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
KV_CHAIN_MAP(jd)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
struct COMMAND_RPC_SUBMITSHARE
|
||||
{
|
||||
RPC_METHOD_NAME("submit");
|
||||
|
||||
struct request
|
||||
{
|
||||
std::string id;
|
||||
uint64_t nonce;
|
||||
std::string job_id;
|
||||
std::string result;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(nonce)
|
||||
KV_SERIALIZE(job_id)
|
||||
KV_SERIALIZE(result)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string status;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Reference in a new issue