Skip to content

Commit

Permalink
Added GetTransferFee method
Browse files Browse the repository at this point in the history
  • Loading branch information
EDDragonWolf committed Feb 5, 2018
1 parent d1f1872 commit 133ab00
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 4 deletions.
79 changes: 79 additions & 0 deletions src/supernode/baseclientproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void supernode::BaseClientProxy::Init()
m_DAPIServer->ADD_DAPI_HANDLER(GetSeed, rpc_command::GET_SEED, BaseClientProxy);
m_DAPIServer->ADD_DAPI_HANDLER(RestoreAccount, rpc_command::RESTORE_ACCOUNT, BaseClientProxy);
m_DAPIServer->ADD_DAPI_HANDLER(Transfer, rpc_command::TRANSFER, BaseClientProxy);
m_DAPIServer->ADD_DAPI_HANDLER(GetTransferFee, rpc_command::GET_TRANSFER_FEE, BaseClientProxy);
}

bool supernode::BaseClientProxy::GetWalletBalance(const supernode::rpc_command::GET_WALLET_BALANCE::request &in, supernode::rpc_command::GET_WALLET_BALANCE::response &out)
Expand Down Expand Up @@ -174,6 +175,84 @@ bool supernode::BaseClientProxy::RestoreAccount(const supernode::rpc_command::RE
return true;
}

bool supernode::BaseClientProxy::GetTransferFee(const supernode::rpc_command::GET_TRANSFER_FEE::request &in, supernode::rpc_command::GET_TRANSFER_FEE::response &out)
{
std::unique_ptr<tools::GraftWallet> wal = initWallet(base64_decode(in.Account), in.Password);
if (!wal)
{
out.Result = ERROR_OPEN_WALLET_FAILED;
return false;
}

if (wal->restricted())
{
// er.code = WALLET_RPC_ERROR_CODE_DENIED;
// er.message = "Command unavailable in restricted mode.";
out.Result = ERROR_OPEN_WALLET_FAILED;
return false;
}

std::vector<cryptonote::tx_destination_entry> dsts;
std::vector<uint8_t> extra;

std::string payment_id = "";

uint64_t amount;
std::istringstream iss(in.Amount);
iss >> amount;

// validate the transfer requested and populate dsts & extra
if (!validate_transfer(in.Account, in.Password, in.Address, amount, payment_id, dsts, extra))
{
out.Result = ERROR_OPEN_WALLET_FAILED;
return false;
}

try
{
uint64_t mixin = 4;
uint64_t unlock_time = 0;
uint64_t priority = 0;
std::vector<tools::GraftWallet::pending_tx> ptx_vector =
wal->create_transactions_2(dsts, mixin, unlock_time, priority, extra, false);

// reject proposed transactions if there are more than one. see on_transfer_split below.
if (ptx_vector.size() != 1)
{
// er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR;
// er.message = "Transaction would be too large. try /transfer_split.";
out.Result = ERROR_OPEN_WALLET_FAILED;
return false;
}

out.Fee = ptx_vector.back().fee;
}
catch (const tools::error::daemon_busy& e)
{
// er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY;
// er.message = e.what();
out.Result = ERROR_OPEN_WALLET_FAILED;
return false;
}
catch (const std::exception& e)
{
// er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR;
// er.message = e.what();
out.Result = ERROR_OPEN_WALLET_FAILED;
return false;
}
catch (...)
{
// er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
// er.message = "WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR";
out.Result = ERROR_OPEN_WALLET_FAILED;
return false;
}

out.Result = STATUS_OK;
return true;
}

bool supernode::BaseClientProxy::Transfer(const supernode::rpc_command::TRANSFER::request &in, supernode::rpc_command::TRANSFER::response &out)
{
std::unique_ptr<tools::GraftWallet> wal = initWallet(base64_decode(in.Account), in.Password);
Expand Down
1 change: 1 addition & 0 deletions src/supernode/baseclientproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class BaseClientProxy : public BaseRTAProcessor
bool GetSeed(const rpc_command::GET_SEED::request &in, rpc_command::GET_SEED::response &out);
bool RestoreAccount(const rpc_command::RESTORE_ACCOUNT::request &in, rpc_command::RESTORE_ACCOUNT::response &out);

bool GetTransferFee(const rpc_command::GET_TRANSFER_FEE::request &in, rpc_command::GET_TRANSFER_FEE::response &out);
bool Transfer(const rpc_command::TRANSFER::request &in, rpc_command::TRANSFER::response &out);

private:
Expand Down
1 change: 1 addition & 0 deletions src/supernode/supernode_rpc_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ DCALL(CreateAccount)
DCALL(GetSeed)
DCALL(RestoreAccount)
DCALL(Transfer)
DCALL(GetTransferFee)
DCALL(WalletRejectPay)
DCALL(WalletProxyRejectPay)
DCALL(AuthWalletRejectPay)
Expand Down
31 changes: 27 additions & 4 deletions src/supernode/supernode_rpc_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace supernode {
extern const string GetSeed;
extern const string RestoreAccount;
extern const string Transfer;
extern const string GetTransferFee;

extern const string WalletRejectPay;
extern const string WalletProxyRejectPay;
Expand Down Expand Up @@ -484,6 +485,32 @@ namespace supernode {
};
};


struct GET_TRANSFER_FEE {
struct request {
std::string Account;
std::string Password;
std::string Address;
std::string Amount;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(Account)
KV_SERIALIZE(Password)
KV_SERIALIZE(Address)
KV_SERIALIZE(Amount)
END_KV_SERIALIZE_MAP()
};
struct response {
int64_t Result;
uint64_t Fee;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(Result)
KV_SERIALIZE(Fee)
END_KV_SERIALIZE_MAP()
};
};

void ConvertFromTR(RTA_TransactionRecordRequest& dst, const RTA_TransactionRecord& src);

void ConvertToTR(RTA_TransactionRecord& dst, const RTA_TransactionRecordRequest& src, const FSN_ServantBase* servant);
Expand Down Expand Up @@ -589,10 +616,6 @@ namespace supernode {
vector<P2P_ADD_NODE_TO_LIST> List;
};
};




}
}

Expand Down

0 comments on commit 133ab00

Please sign in to comment.