Skip to content

Commit

Permalink
implemented clonetelepod
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptozoidberg committed Oct 20, 2014
1 parent d99dc80 commit efa3e9f
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/currency_core/currency_format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace currency

std::vector<output_entry> outputs; //index + key
uint64_t real_output; //index in outputs vector of real output_entry
crypto::public_key real_out_tx_key; //incoming real tx public key
crypto::public_key real_out_tx_key; //real output's transaction's public key
size_t real_output_in_tx_index; //index in transaction outputs vector
uint64_t amount; //money
};
Expand Down
35 changes: 8 additions & 27 deletions src/gui/qt-daemon/html5applicationviewer/core_fast_rpc_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,20 @@ namespace tools
return m_rpc.on_get_alias_details(req, res, m_err_stub, 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);
}


/* bool get_info(const currency::COMMAND_RPC_GET_INFO::response& info)
bool call_COMMAND_RPC_GET_TRANSACTIONS(const currency::COMMAND_RPC_GET_TRANSACTIONS::request& req, currency::COMMAND_RPC_GET_TRANSACTIONS::response& rsp)
{
currency::core_rpc_server::connection_context stub_cntxt = AUTO_VAL_INIT(stub_cntxt);
currency::COMMAND_RPC_GET_INFO::request res = AUTO_VAL_INIT(res);
return m_rpc.on_get_info(res, info, stub_cntxt);
return m_rpc.on_get_transactions(req, rsp, m_cntxt_stub);
}
bool get_aliases(const currency::COMMAND_RPC_GET_ALL_ALIASES::response& aliases)
//------------------------------------------------------------------------------------------------------------------------------
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)
{
currency::core_rpc_server::connection_context stub_cntxt = AUTO_VAL_INIT(stub_cntxt);
currency::COMMAND_RPC_GET_ALL_ALIASES::request res = AUTO_VAL_INIT(res);
epee::json_rpc::error error_resp;
return m_rpc.on_get_all_aliases(res, aliases, error_resp, stub_cntxt);
return m_rpc.on_get_indexes(req, rsp, m_http_client, m_cntxt_stub);
}
bool get_alias_info(const std::string& alias, currency::COMMAND_RPC_GET_ALIAS_DETAILS::response& alias_info)
//------------------------------------------------------------------------------------------------------------------------------
bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr)
{
currency::core_rpc_server::connection_context stub_cntxt = AUTO_VAL_INIT(stub_cntxt);
currency::COMMAND_RPC_GET_ALIAS_DETAILS::request req = AUTO_VAL_INIT(req);
req.alias = alias;
epee::json_rpc::error error_resp;
return m_rpc.on_get_alias_details(req, alias_info, error_resp, stub_cntxt);
return tools::get_transfer_address(adr_str, addr, this);
}
*/

private:
currency::core_rpc_server& m_rpc;
Expand Down
10 changes: 10 additions & 0 deletions src/wallet/core_default_rpc_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ namespace tools
return epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
}
//------------------------------------------------------------------------------------------------------------------------------
bool default_http_core_proxy::call_COMMAND_RPC_GET_TRANSACTIONS(const currency::COMMAND_RPC_GET_TRANSACTIONS::request& req, currency::COMMAND_RPC_GET_TRANSACTIONS::response& rsp)
{
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)
{
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);
}
//------------------------------------------------------------------------------------------------------------------------------
bool default_http_core_proxy::check_connection()
{
if (m_http_client.is_connected())
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/core_default_rpc_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace tools
bool call_COMMAND_RPC_SEND_RAW_TX(const currency::COMMAND_RPC_SEND_RAW_TX::request& rqt, currency::COMMAND_RPC_SEND_RAW_TX::response& rsp);
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);


bool check_connection();
bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr);
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/core_rpc_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ namespace tools
virtual bool call_COMMAND_RPC_SEND_RAW_TX(const currency::COMMAND_RPC_SEND_RAW_TX::request& rqt, currency::COMMAND_RPC_SEND_RAW_TX::response& rsp) = 0;
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 check_connection() = 0;
virtual bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr)=0;
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ bool wallet2::set_core_proxy(std::shared_ptr<i_core_proxy>& proxy)
return true;
}
//----------------------------------------------------------------------------------------------------
std::shared_ptr<i_core_proxy> wallet2::get_core_proxy()
{
return m_core_proxy;
}
//----------------------------------------------------------------------------------------------------
void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t height, const currency::block& b)
{
std::string recipient, recipient_alias;
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace tools
bool refresh(size_t & blocks_fetched, bool& received_money, bool& ok);

bool set_core_proxy(std::shared_ptr<i_core_proxy>& proxy);
std::shared_ptr<i_core_proxy> get_core_proxy();
uint64_t balance();
uint64_t unlocked_balance();
template<typename T>
Expand Down
134 changes: 134 additions & 0 deletions src/wallet/wallet_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,140 @@ namespace tools
//------------------------------------------------------------------------------------------------------------------------------
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)
{
//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);
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;
}

//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))
{
LOG_ERROR("Failed to parse_hexstr_to_binbuff(req.tpd.account_keys_hex, acc_buff)");
res.status = "BAD";
return true;
}
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;
}

//extract transaction
currency::transaction tx = AUTO_VAL_INIT(tx);
std::string buff;
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;
}
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;
}

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;

}

//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);
get_ind_req.txid = currency::get_transaction_hash(tx);
if (!m_wallet.get_core_proxy()->call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(get_ind_req, get_ind_rsp)
|| get_ind_rsp.status != CORE_RPC_STATUS_OK
|| 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;
}

//prepare inputs
std::vector<currency::tx_source_entry> sources;
size_t i = 0;
uint64_t amount = 0;
for (auto& o : get_ind_rsp.o_indexes)
{
//check if input is for telepod's address
if (currency::is_out_to_acc(acc.get_keys(), boost::get<currency::txout_to_key>(tx.vout[i].target), tx_pub_key, i))
{
//income output
amount += tx.vout[i].amount;
sources.resize(sources.size() + 1);
currency::tx_source_entry& tse = sources.back();
tse.amount = tx.vout[i].amount;
tse.outputs.push_back(currency::tx_source_entry::output_entry(o, boost::get<currency::txout_to_key>(tx.vout[i].target).key));
tse.real_out_tx_key = tx_pub_key;
tse.real_output = 0;
tse.real_output_in_tx_index = i;
}
++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;
}
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";
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);
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));
res.status = "INTERNAL_ERROR";
return true;
}

res.tpd.basement_tx_id_hex = string_tools::pod_to_hex(currency::get_transaction_hash(tx2));
std::string acc2_buff = epee::serialization::store_t_to_binary(acc2);
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);

return true;
}
//------------------------------------------------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/wallet_rpc_server_commans_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace wallet_rpc

struct response
{
std::string status; //"OK", "UNCONFIRMED", "BAD", "SPENT"
std::string status; //"OK", "UNCONFIRMED", "BAD", "SPENT", "INTERNAL_ERROR"

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
Expand All @@ -257,7 +257,7 @@ namespace wallet_rpc

struct response
{
std::string status;
std::string status;//"OK", "UNCONFIRMED", "BAD", "SPENT", "INTERNAL_ERROR:"
telepod tpd;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
Expand All @@ -278,7 +278,7 @@ namespace wallet_rpc

struct response
{
std::string status; ////"OK", "UNCONFIRMED", "BAD", "SPENT"
std::string status; //"OK", "UNCONFIRMED", "BAD", "SPENT", "INTERNAL_ERROR"
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
Expand Down

0 comments on commit efa3e9f

Please sign in to comment.