Skip to content

Commit

Permalink
Simplewallet fee for remote node
Browse files Browse the repository at this point in the history
Simplewallet includes fee 0.25% when sending transaction through remote
"masternode"
  • Loading branch information
aivve committed Nov 14, 2016
1 parent 1674ffb commit 82e7489
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
54 changes: 54 additions & 0 deletions src/SimpleWallet/SimpleWallet.cpp
@@ -1,4 +1,5 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers, The Karbovanets developers
// Copyright (c) 2014-2016 XDN developers
//
// This file is part of Bytecoin.
//
Expand Down Expand Up @@ -223,6 +224,13 @@ struct TransferCommand {
destination.amount = de.amount;

dsts.push_back(destination);

if (!remote_fee_address.empty()) {
destination.address = remote_fee_address;
destination.amount = de.amount * 0.25 / 100;
dsts.push_back(destination);
}

}
}

Expand Down Expand Up @@ -441,6 +449,26 @@ bool writeAddressFile(const std::string& addressFilename, const std::string& add
return true;
}

bool processServerFeeAddressResponse(const std::string& response, std::string& fee_address) {
try {
std::stringstream stream(response);
JsonValue json;
stream >> json;

auto rootIt = json.getObject().find("fee_address");
if (rootIt == json.getObject().end()) {
return false;
}

fee_address = rootIt->second.getString();
}
catch (std::exception&) {
return false;
}

return true;
}

}

std::string simple_wallet::get_commands_str() {
Expand Down Expand Up @@ -580,7 +608,11 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) {
fail_msg_writer() << "failed to parse daemon address: " << m_daemon_address;
return false;
}
remote_fee_address = getFeeAddress();
} else {
if (!m_daemon_host.empty()) {
remote_fee_address = getFeeAddress();
}
m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port);
}

Expand Down Expand Up @@ -990,6 +1022,28 @@ bool simple_wallet::show_blockchain_height(const std::vector<std::string>& args)
return true;
}
//----------------------------------------------------------------------------------------------------
std::string simple_wallet::getFeeAddress() {

HttpClient httpClient(m_dispatcher, m_daemon_host, m_daemon_port);

HttpRequest req;
HttpResponse res;

req.setUrl("/feeaddress");
httpClient.request(req, res);

if (res.getStatus() != HttpResponse::STATUS_200) {
throw std::runtime_error("Remote server returned code " + std::to_string(res.getStatus()));
}

std::string address;
if (!processServerFeeAddressResponse(res.getBody(), address)) {
throw std::runtime_error("Failed to parse server response");
}

return address;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::transfer(const std::vector<std::string> &args) {
try {
TransferCommand cmd(m_currency);
Expand Down
5 changes: 4 additions & 1 deletion src/SimpleWallet/SimpleWallet.h
@@ -1,4 +1,4 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers, The Karbovanets developers
//
// This file is part of Bytecoin.
//
Expand Down Expand Up @@ -39,6 +39,8 @@
#include <System/Dispatcher.h>
#include <System/Ipv4Address.h>

std::string remote_fee_address;

namespace CryptoNote
{
/************************************************************************/
Expand All @@ -55,6 +57,7 @@ namespace CryptoNote

bool process_command(const std::vector<std::string> &args);
std::string get_commands_str();
std::string getFeeAddress();

const CryptoNote::Currency& currency() const { return m_currency; }

Expand Down

0 comments on commit 82e7489

Please sign in to comment.