Skip to content

Commit

Permalink
implemented maketelepode
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptozoidberg committed Oct 20, 2014
1 parent 8fe1aa0 commit d99dc80
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/wallet/wallet_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,38 @@ namespace tools
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_maketelepod(const wallet_rpc::COMMAND_RPC_MAKETELEPOD::request& req, wallet_rpc::COMMAND_RPC_MAKETELEPOD::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
//check available balance
if (m_wallet.unlocked_balance() <= req.amount)
{
res.status = "INSUFFICIENT_COINS";
return true;
}

currency::account_base acc;
acc.generate();
std::vector<currency::tx_destination_entry> dsts(1);
dsts.back().amount = req.amount;
dsts.back().addr = acc.get_keys().m_account_address;
currency::transaction tx = AUTO_VAL_INIT(tx);
try
{
std::vector<uint8_t> extra;
m_wallet.transfer(dsts, 0, 0, DEFAULT_FEE, extra, tx);
}
catch (const std::runtime_error& er)
{
LOG_ERROR("Failed to send transaction: " << er.what());
res.status = "INTERNAL_ERROR";
return true;
}

res.tpd.basement_tx_id_hex = string_tools::pod_to_hex(currency::get_transaction_hash(tx));
std::string buff = epee::serialization::store_t_to_binary(acc);
res.tpd.account_keys_hex = string_tools::buff_to_hex_nodelimer(buff);

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

return true;
}
//------------------------------------------------------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/wallet/wallet_rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace tools
MAP_JON_RPC_WE("clonetelepod", on_clonetelepod, wallet_rpc::COMMAND_RPC_CLONETELEPOD)
MAP_JON_RPC_WE("telepodstatus", on_telepodstatus, wallet_rpc::COMMAND_RPC_TELEPODSTATUS)
MAP_JON_RPC_WE("withdrawtelepod", on_withdrawtelepod, wallet_rpc::COMMAND_RPC_WITHDRAWTELEPOD)

END_JSON_RPC_MAP()
END_URI_MAP2()

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 @@ -214,7 +214,7 @@ namespace wallet_rpc

struct response
{
std::string status;
std::string status; //"OK", "INSUFFICIENT_COINS", "INTERNAL_ERROR"
telepod tpd;

BEGIN_KV_SERIALIZE_MAP()
Expand Down

0 comments on commit d99dc80

Please sign in to comment.