Skip to content

Commit

Permalink
implemented telepodstatus
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptozoidberg committed Oct 21, 2014
1 parent efa3e9f commit 28995ed
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 40 deletions.
11 changes: 11 additions & 0 deletions src/currency_core/blockchain_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,17 @@ bool blockchain_storage::get_transactions_daily_stat(uint64_t& daily_cnt, uint64
return true;
}
//------------------------------------------------------------------
bool blockchain_storage::check_keyimages(const std::list<crypto::key_image>& images, std::list<bool>& images_stat)
{
//true - unspent, false - spent
CRITICAL_REGION_LOCAL(m_blockchain_lock);
for (auto& ki : images)
{
images_stat.push_back(m_spent_keys.count(ki)?false:true);
}
return true;
}
//------------------------------------------------------------------
uint64_t blockchain_storage::get_current_hashrate(size_t aprox_count)
{
CRITICAL_REGION_LOCAL(m_blockchain_lock);
Expand Down
1 change: 1 addition & 0 deletions src/currency_core/blockchain_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ namespace currency
bool copy_scratchpad(std::string& dst);
bool prune_aged_alt_blocks();
bool get_transactions_daily_stat(uint64_t& daily_cnt, uint64_t& daily_volume);
bool check_keyimages(const std::list<crypto::key_image>& images, std::list<bool>& images_stat);//true - unspent, false - spent

template<class t_ids_container, class t_blocks_container, class t_missed_container>
bool get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ namespace tools
return m_rpc.on_get_transactions(req, rsp, m_cntxt_stub);
}
//------------------------------------------------------------------------------------------------------------------------------
bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp)
bool call_COMMAND_RPC_COMMAND_RPC_CHECK_KEYIMAGES(const currency::COMMAND_RPC_CHECK_KEYIMAGES::request& req, currency::COMMAND_RPC_CHECK_KEYIMAGES::response& rsp)
{
return m_rpc.on_get_indexes(req, rsp, m_http_client, m_cntxt_stub);
return m_rpc.on_check_keyimages(req, rsp, m_cntxt_stub);
}
//------------------------------------------------------------------------------------------------------------------------------

bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr)
{
return tools::get_transfer_address(adr_str, addr, this);
Expand Down
7 changes: 7 additions & 0 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ namespace currency
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_check_keyimages(const COMMAND_RPC_CHECK_KEYIMAGES::request& req, COMMAND_RPC_CHECK_KEYIMAGES::response& res, connection_context& cntx)
{
m_core.get_blockchain_storage().check_keyimages(req.images, res.images_stat);
res.status = CORE_RPC_STATUS_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
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();
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,8 @@ namespace currency
bool on_get_info(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, connection_context& cntx);
bool on_set_maintainers_info(const COMMAND_RPC_SET_MAINTAINERS_INFO::request& req, COMMAND_RPC_SET_MAINTAINERS_INFO::response& res, connection_context& cntx);
bool on_get_tx_pool(const COMMAND_RPC_GET_TX_POOL::request& req, COMMAND_RPC_GET_TX_POOL::response& res, connection_context& cntx);
bool on_check_keyimages(const COMMAND_RPC_CHECK_KEYIMAGES::request& req, COMMAND_RPC_CHECK_KEYIMAGES::response& res, connection_context& cntx);


//json_rpc
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx);
Expand Down Expand Up @@ -77,6 +79,7 @@ namespace currency
MAP_URI_AUTO_BIN2("/getrandom_outs.bin", on_get_random_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS)
MAP_URI_AUTO_BIN2("/set_maintainers_info.bin", on_set_maintainers_info, COMMAND_RPC_SET_MAINTAINERS_INFO)
MAP_URI_AUTO_BIN2("/get_tx_pool.bin", on_get_tx_pool, COMMAND_RPC_GET_TX_POOL)
MAP_URI_AUTO_BIN2("/check_keyimages.bin", on_check_keyimages, COMMAND_RPC_CHECK_KEYIMAGES)
MAP_URI_AUTO_JON2("/gettransactions", on_get_transactions, COMMAND_RPC_GET_TRANSACTIONS)
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)
Expand Down
22 changes: 22 additions & 0 deletions src/rpc/core_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ namespace currency
};
};
//-----------------------------------------------
struct COMMAND_RPC_CHECK_KEYIMAGES
{
struct request
{
std::list<crypto::key_image> images;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(images)
END_KV_SERIALIZE_MAP()
};

struct response
{
std::list<bool> images_stat; //true - unspent, false - spent
std::string status;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(images_stat)
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
};
//-----------------------------------------------
struct COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES
{
struct request
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/core_default_rpc_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ namespace tools
return epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/gettransactions", req, rsp, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
}
//------------------------------------------------------------------------------------------------------------------------------
bool default_http_core_proxy::call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp)
bool default_http_core_proxy::call_COMMAND_RPC_COMMAND_RPC_CHECK_KEYIMAGES(const currency::COMMAND_RPC_CHECK_KEYIMAGES::request& req, currency::COMMAND_RPC_CHECK_KEYIMAGES::response& rsp)
{
return epee::net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/get_o_indexes.bin", req, rsp, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
return epee::net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/check_keyimages.bin", req, rsp, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
}
//------------------------------------------------------------------------------------------------------------------------------
bool default_http_core_proxy::check_connection()
Expand Down
3 changes: 1 addition & 2 deletions src/wallet/core_default_rpc_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ namespace tools
bool call_COMMAND_RPC_GET_ALL_ALIASES(currency::COMMAND_RPC_GET_ALL_ALIASES::response& rsp);
bool call_COMMAND_RPC_GET_ALIAS_DETAILS(const currency::COMMAND_RPC_GET_ALIAS_DETAILS::request& req, currency::COMMAND_RPC_GET_ALIAS_DETAILS::response& rsp);
bool call_COMMAND_RPC_GET_TRANSACTIONS(const currency::COMMAND_RPC_GET_TRANSACTIONS::request& req, currency::COMMAND_RPC_GET_TRANSACTIONS::response& rsp);
bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp);

virtual bool call_COMMAND_RPC_COMMAND_RPC_CHECK_KEYIMAGES(const currency::COMMAND_RPC_CHECK_KEYIMAGES::request& req, currency::COMMAND_RPC_CHECK_KEYIMAGES::response& rsp);

bool check_connection();
bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr);
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/core_rpc_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ namespace tools
virtual bool call_COMMAND_RPC_GET_ALL_ALIASES(currency::COMMAND_RPC_GET_ALL_ALIASES::response& rsp) = 0;
virtual bool call_COMMAND_RPC_GET_ALIAS_DETAILS(const currency::COMMAND_RPC_GET_ALIAS_DETAILS::request& req, currency::COMMAND_RPC_GET_ALIAS_DETAILS::response& rsp) = 0;
virtual bool call_COMMAND_RPC_GET_TRANSACTIONS(const currency::COMMAND_RPC_GET_TRANSACTIONS::request& req, currency::COMMAND_RPC_GET_TRANSACTIONS::response& rsp) = 0;
virtual bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp) = 0;
virtual bool call_COMMAND_RPC_COMMAND_RPC_CHECK_KEYIMAGES(const currency::COMMAND_RPC_CHECK_KEYIMAGES::request& req, currency::COMMAND_RPC_CHECK_KEYIMAGES::response& rsp) = 0;




virtual bool check_connection() = 0;
virtual bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr)=0;
Expand Down
110 changes: 78 additions & 32 deletions src/wallet/wallet_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,34 +224,34 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_clonetelepod(const wallet_rpc::COMMAND_RPC_CLONETELEPOD::request& req, wallet_rpc::COMMAND_RPC_CLONETELEPOD::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::build_transaction_from_telepod(const wallet_rpc::telepod& tlp, const currency::account_base& acc2, currency::transaction& tx2, std::string& status)
{
//check if base transaction confirmed
currency::COMMAND_RPC_GET_TRANSACTIONS::request get_tx_req = AUTO_VAL_INIT(get_tx_req);
currency::COMMAND_RPC_GET_TRANSACTIONS::response get_tx_rsp = AUTO_VAL_INIT(get_tx_rsp);
get_tx_req.txs_hashes.push_back(req.tpd.basement_tx_id_hex);
get_tx_req.txs_hashes.push_back(tlp.basement_tx_id_hex);
if (!m_wallet.get_core_proxy()->call_COMMAND_RPC_GET_TRANSACTIONS(get_tx_req, get_tx_rsp)
|| get_tx_rsp.status != CORE_RPC_STATUS_OK
|| !get_tx_rsp.txs_as_hex.size())
{
res.status = "UNCONFIRMED";
return true;
status = "UNCONFIRMED";
return false;
}

//extract account keys
std::string acc_buff;
currency::account_base acc = AUTO_VAL_INIT(acc);
if (!string_tools::parse_hexstr_to_binbuff(req.tpd.account_keys_hex, acc_buff))
if (!string_tools::parse_hexstr_to_binbuff(tlp.account_keys_hex, acc_buff))
{
LOG_ERROR("Failed to parse_hexstr_to_binbuff(req.tpd.account_keys_hex, acc_buff)");
res.status = "BAD";
return true;
LOG_ERROR("Failed to parse_hexstr_to_binbuff(tlp.account_keys_hex, acc_buff)");
status = "BAD";
return false;
}
if (!epee::serialization::load_t_from_binary(acc, acc_buff))
{
LOG_ERROR("Failed to load_t_from_binary(acc, acc_buff)");
res.status = "BAD";
return true;
status = "BAD";
return false;
}

//extract transaction
Expand All @@ -260,25 +260,25 @@ namespace tools
if (!string_tools::parse_hexstr_to_binbuff(get_tx_rsp.txs_as_hex.back(), buff))
{
LOG_ERROR("Failed to parse_hexstr_to_binbuff(get_tx_rsp.txs_as_hex.back(), buff)");
res.status = "INTERNAL_ERROR";
return true;
status = "INTERNAL_ERROR";
return false;
}
if (!currency::parse_and_validate_tx_from_blob(buff, tx))
{
LOG_ERROR("Failed to currency::parse_and_validate_tx_from_blob(buff, tx)");
res.status = "INTERNAL_ERROR";
return true;
status = "INTERNAL_ERROR";
return false;
}

crypto::public_key tx_pub_key = currency::get_tx_pub_key_from_extra(tx);
if (tx_pub_key == currency::null_pkey)
{
LOG_ERROR("Failed to currency::get_tx_pub_key_from_extra(tx)");
res.status = "BAD";
return true;
status = "BAD";
return false;

}

//get transaction global output indices
currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request get_ind_req = AUTO_VAL_INIT(get_ind_req);
currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response get_ind_rsp = AUTO_VAL_INIT(get_ind_rsp);
Expand All @@ -288,8 +288,8 @@ namespace tools
|| get_ind_rsp.o_indexes.size() != tx.vout.size())
{
LOG_ERROR("Problem with call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(....) ");
res.status = "INTERNAL_ERROR";
return true;
status = "INTERNAL_ERROR";
return false;
}

//prepare inputs
Expand All @@ -313,42 +313,54 @@ namespace tools
}
++i;
}

//new destination account
currency::account_base acc2 = AUTO_VAL_INIT(acc2);
acc2.generate();


//prepare outputs
std::vector<currency::tx_destination_entry> dsts(1);
currency::tx_destination_entry& dst = dsts.back();
dst.addr = acc2.get_keys().m_account_address;
dst.amount = amount - DEFAULT_FEE;

//generate transaction
const std::vector<uint8_t> extra;
currency::transaction tx2 = AUTO_VAL_INIT(tx2);
bool r = currency::construct_tx(acc.get_keys(), sources, dsts, extra, tx2, 0);
if (!r)
{
LOG_ERROR("Problem with construct_tx(....) ");
res.status = "INTERNAL_ERROR";
return true;
status = "INTERNAL_ERROR";
return false;
}
if (CURRENCY_MAX_TRANSACTION_BLOB_SIZE <= get_object_blobsize(tx))
{
LOG_ERROR("Problem with construct_tx(....), blobl size os too big: " << get_object_blobsize(tx));
res.status = "INTERNAL_ERROR";
status = "INTERNAL_ERROR";
return false;
}

return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_clonetelepod(const wallet_rpc::COMMAND_RPC_CLONETELEPOD::request& req, wallet_rpc::COMMAND_RPC_CLONETELEPOD::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
currency::transaction tx2 = AUTO_VAL_INIT(tx2);
//new destination account
currency::account_base acc2 = AUTO_VAL_INIT(acc2);
acc2.generate();

if (!build_transaction_from_telepod(req.tpd, acc2, tx2, res.status))
{
LOG_ERROR("Failed to build_transaction_from_telepod(...)");
return true;
}

//send transaction to daemon
currency::COMMAND_RPC_SEND_RAW_TX::request req_send_raw;
req_send_raw.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx2));
currency::COMMAND_RPC_SEND_RAW_TX::response rsp_send_raw;
r = m_wallet.get_core_proxy()->call_COMMAND_RPC_SEND_RAW_TX(req_send_raw, rsp_send_raw);
bool r = m_wallet.get_core_proxy()->call_COMMAND_RPC_SEND_RAW_TX(req_send_raw, rsp_send_raw);
if (!r || rsp_send_raw.status != CORE_RPC_STATUS_OK)
{
LOG_ERROR("Problem with construct_tx(....), blobl size os too big: " << get_object_blobsize(tx));
LOG_ERROR("Problem with construct_tx(....), blobl size os too big: " << get_object_blobsize(tx2));
res.status = "INTERNAL_ERROR";
return true;
}
Expand All @@ -358,13 +370,47 @@ namespace tools
res.tpd.account_keys_hex = string_tools::buff_to_hex_nodelimer(acc2_buff);

res.status = "OK";
LOG_PRINT_GREEN("TELEPOD ISSUED [" << currency::print_money(dst.amount) << "BBR, base_tx_id: ]" << currency::get_transaction_hash(tx2), LOG_LEVEL_0);
LOG_PRINT_GREEN("TELEPOD ISSUED [" << currency::print_money(currency::get_outs_money_amount(tx2)) << "BBR, base_tx_id: ]" << currency::get_transaction_hash(tx2), LOG_LEVEL_0);

return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_telepodstatus(const wallet_rpc::COMMAND_RPC_TELEPODSTATUS::request& req, wallet_rpc::COMMAND_RPC_TELEPODSTATUS::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
currency::transaction tx2 = AUTO_VAL_INIT(tx2);
//new destination account
currency::account_base acc2 = AUTO_VAL_INIT(acc2);
acc2.generate();

if (!build_transaction_from_telepod(req.tpd, acc2, tx2, res.status))
{
return true;
}
//check if transaction is spent
currency::COMMAND_RPC_CHECK_KEYIMAGES::request req_ki = AUTO_VAL_INIT(req_ki);
currency::COMMAND_RPC_CHECK_KEYIMAGES::response rsp_ki = AUTO_VAL_INIT(rsp_ki);
for (auto& i : tx2.vin)
req_ki.images.push_back(boost::get<currency::txin_to_key>(i).k_image);

if (!m_wallet.get_core_proxy()->call_COMMAND_RPC_COMMAND_RPC_CHECK_KEYIMAGES(req_ki, rsp_ki)
|| rsp_ki.status != CORE_RPC_STATUS_OK
|| rsp_ki.images_stat.size() != req_ki.images.size())
{
LOG_ERROR("Problem with call_COMMAND_RPC_COMMAND_RPC_CHECK_KEYIMAGES(....)");
res.status = "INTERNAL_ERROR";
return true;
}

for (auto s : rsp_ki.images_stat)
{
if (!s)
{
res.status = "SPENT";
return true;
}
}

res.status = "OK";
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet_rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace tools
bool on_withdrawtelepod(const wallet_rpc::COMMAND_RPC_WITHDRAWTELEPOD::request& req, wallet_rpc::COMMAND_RPC_WITHDRAWTELEPOD::response& res, epee::json_rpc::error& er, connection_context& cntx);

bool handle_command_line(const boost::program_options::variables_map& vm);
bool build_transaction_from_telepod(const wallet_rpc::telepod& tlp, const currency::account_base& acc2, currency::transaction& tx2, std::string& status );

wallet2& m_wallet;
std::string m_port;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet_rpc_server_commans_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace wallet_rpc
};
};


/*stay-alone instance*/
struct telepod
{
std::string account_keys_hex;
Expand Down

0 comments on commit 28995ed

Please sign in to comment.