Skip to content

Commit

Permalink
Merge pull request #55 from hmel/master
Browse files Browse the repository at this point in the history
Implement get/check tx_key in wallet; getblock json_rpc in daemon & misc. compilation fixes
  • Loading branch information
cryptozoidberg committed Oct 10, 2017
2 parents 09733a2 + bcd1b09 commit 8ecc5fc
Show file tree
Hide file tree
Showing 22 changed files with 391 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace epee
static bool serialize_stl_container_pod_val_as_blob(const stl_container& container, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
if(!container.size()) return true;
typename stl_container::const_iterator it = container.begin();
//typename stl_container::const_iterator it = container.begin();
std::string mb;
mb.resize(sizeof(typename stl_container::value_type)*container.size());
typename stl_container::value_type* p_elem = (typename stl_container::value_type*)mb.data();
Expand Down Expand Up @@ -365,4 +365,4 @@ namespace epee
return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_unserialize(d, stg, hparent_section, pname);
}
}
}
}
8 changes: 6 additions & 2 deletions contrib/epee/include/storages/portable_storage_from_bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ namespace epee
}
~recursuion_limitation_guard()
{
CHECK_AND_ASSERT_THROW_MES(m_counter_ref != 0, "Internal error: m_counter_ref == 0 while ~recursuion_limitation_guard()");
try {
CHECK_AND_ASSERT_THROW_MES(m_counter_ref != 0, "Internal error: m_counter_ref == 0 while ~recursuion_limitation_guard()");
} catch (...) {
std::terminate();
}
--m_counter_ref;
}
};
Expand Down Expand Up @@ -278,4 +282,4 @@ namespace epee
m_count -= len;
}
}
}
}
2 changes: 1 addition & 1 deletion contrib/miniupnpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endif (NO_GETADDRINFO)

if (NOT WIN32)
add_definitions (-DMINIUPNPC_SET_SOCKET_TIMEOUT)
add_definitions (-D_BSD_SOURCE -D_POSIX_C_SOURCE=1)
add_definitions (-D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=1)
else (NOT WIN32)
add_definitions (-D_WIN32_WINNT=0x0501) # XP or higher for getnameinfo and friends
endif (NOT WIN32)
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ PUSH_WARNINGS
DISABLE_VS_WARNINGS(4200)
struct rs_comm {
hash h;
struct {
struct point {
ec_point a, b;
} ab[];
};
POP_WARNINGS

static inline size_t rs_comm_size(size_t pubs_count) {
return sizeof(rs_comm) + pubs_count * sizeof(rs_comm().ab[0]);
return sizeof(rs_comm) + pubs_count * sizeof(rs_comm::point);
}

void crypto_ops::generate_ring_signature(const hash &prefix_hash, const key_image &image,
Expand Down
10 changes: 6 additions & 4 deletions src/currency_core/currency_format_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,16 +504,18 @@ namespace currency
//---------------------------------------------------------------
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources,
const std::vector<tx_destination_entry>& destinations,
transaction& tx,
transaction& tx,
keypair& txkey,
uint64_t unlock_time,
uint8_t tx_outs_attr)
{
return construct_tx(sender_account_keys, sources, destinations, std::vector<uint8_t>(), tx, unlock_time, tx_outs_attr);
return construct_tx(sender_account_keys, sources, destinations, std::vector<uint8_t>(), tx, txkey, unlock_time, tx_outs_attr);
}
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources,
const std::vector<tx_destination_entry>& destinations,
const std::vector<uint8_t>& extra,
transaction& tx,
transaction& tx,
keypair& txkey,
uint64_t unlock_time,
uint8_t tx_outs_attr)
{
Expand All @@ -525,7 +527,7 @@ namespace currency
tx.version = CURRENT_TRANSACTION_VERSION;
tx.unlock_time = unlock_time;

keypair txkey = keypair::generate();
txkey = keypair::generate();
add_tx_pub_key_to_extra(tx, txkey.pub);

struct input_generation_context_data
Expand Down
4 changes: 2 additions & 2 deletions src/currency_core/currency_format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ namespace currency
//---------------------------------------------------------------
bool construct_tx_out(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t output_index, uint64_t amount, transaction& tx, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED);
bool validate_alias_name(const std::string& al);
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, transaction& tx, uint64_t unlock_time, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED);
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, const std::vector<uint8_t>& extra, transaction& tx, uint64_t unlock_time, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED);
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, transaction& tx, keypair& txkey, uint64_t unlock_time, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED);
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, const std::vector<uint8_t>& extra, transaction& tx, keypair& txkey, uint64_t unlock_time, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED);
bool sign_update_alias(alias_info& ai, const crypto::public_key& pkey, const crypto::secret_key& skey);
bool make_tx_extra_alias_entry(std::string& buff, const alias_info& alinfo, bool make_buff_to_sign = false);
bool add_tx_extra_alias(transaction& tx, const alias_info& alinfo);
Expand Down
3 changes: 2 additions & 1 deletion src/p2p/net_node.inl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ namespace nodetool
}
}
if(command_line::has_arg(vm, arg_p2p_hide_my_port))
m_hide_my_port = true; return true;
m_hide_my_port = true;
return true;
}
//-----------------------------------------------------------------------------------
namespace
Expand Down
59 changes: 59 additions & 0 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,65 @@ namespace currency
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_getblock(const COMMAND_RPC_GETBLOCK::request& req, COMMAND_RPC_GETBLOCK::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
{
if(!check_core_ready())
{
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
error_resp.message = "Core is busy";
return false;
}

currency::block b;
if (!m_core.get_blockchain_storage().get_block_by_height(req.height, b)) {
error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT;
error_resp.message = "Invalid block height";
return false;
}
res.block_hash = string_tools::pod_to_hex(get_block_hash(b));
res.block_time = b.timestamp;

std::vector<crypto::hash> txs_ids;
txs_ids.reserve(b.tx_hashes.size());
for(const auto& tx: b.tx_hashes) {
txs_ids.push_back(tx);
}

std::list<crypto::hash> missed_ids;
std::list<transaction> txs;
m_core.get_transactions(txs_ids, txs, missed_ids);
if (missed_ids.size()) {
//can't find transaction from block. Major boo-boo
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Can't find transaction in block";
return false;
}

size_t idx = 0;
for(const auto& tx: txs) {
std::string payment_id;
get_payment_id_from_tx_extra(tx, payment_id);
crypto::hash hash;
get_transaction_hash(tx, hash);

transfer_rpc_details transfer;
transfer.tx_hash = string_tools::pod_to_hex(hash);
transfer.payment_id = string_tools::pod_to_hex(payment_id);

for (const auto& vout: tx.vout) {
const txout_to_key* key_out = boost::get<txout_to_key>(&vout.target);
if (!key_out) {
LOG_PRINT_L0("Found tx_out with target != txout_to_key... skipping");
continue;
}
transfer.amount = vout.amount;
transfer.recipient = string_tools::pod_to_hex(key_out->key);
res.transfers.push_back(transfer);
}
}
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::get_addendum_for_hi(const mining::height_info& hi, std::list<mining::addendum>& res)
{
if(!hi.height || hi.height + 1 == m_core.get_current_blockchain_height())
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/core_rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace currency
//json_rpc
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx);
bool on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request& req, COMMAND_RPC_GETBLOCKHASH::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
bool on_getblock(const COMMAND_RPC_GETBLOCK::request& req, COMMAND_RPC_GETBLOCK::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
bool on_getblocktemplate(const COMMAND_RPC_GETBLOCKTEMPLATE::request& req, COMMAND_RPC_GETBLOCKTEMPLATE::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
bool on_submitblock(const COMMAND_RPC_SUBMITBLOCK::request& req, COMMAND_RPC_SUBMITBLOCK::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
bool 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);
Expand Down Expand Up @@ -98,6 +99,7 @@ namespace currency
MAP_JON_RPC_WE("get_all_alias_details", on_get_all_aliases, COMMAND_RPC_GET_ALL_ALIASES)
MAP_JON_RPC_WE("get_alias_by_address", on_alias_by_address, COMMAND_RPC_GET_ALIASES_BY_ADDRESS)
MAP_JON_RPC_WE("get_addendums", on_get_addendums, COMMAND_RPC_GET_ADDENDUMS)
MAP_JON_RPC_WE("getblock", on_getblock, COMMAND_RPC_GETBLOCK)
MAP_JON_RPC("reset_transaction_pool", on_reset_transaction_pool, COMMAND_RPC_RESET_TX_POOL)
//remote miner rpc
MAP_JON_RPC_N(on_login, mining::COMMAND_RPC_LOGIN)
Expand Down
39 changes: 39 additions & 0 deletions src/rpc/core_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,46 @@ namespace currency
typedef std::string response;
};

struct transfer_rpc_details {
std::string tx_hash;
std::string recipient;
uint64_t amount;
std::string payment_id;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_hash)
KV_SERIALIZE(recipient)
KV_SERIALIZE(amount)
KV_SERIALIZE(payment_id)
END_KV_SERIALIZE_MAP()
};

struct COMMAND_RPC_GETBLOCK
{
struct request {

uint64_t height;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(height)
END_KV_SERIALIZE_MAP()
};

struct response
{
std::string block_hash;
uint64_t block_time;
std::list<transfer_rpc_details> transfers;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(block_hash)
KV_SERIALIZE(block_time)
KV_SERIALIZE(transfers)
END_KV_SERIALIZE_MAP()
};

};

struct COMMAND_RPC_GETBLOCKTEMPLATE
{
struct request
Expand Down
Loading

0 comments on commit 8ecc5fc

Please sign in to comment.