mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Implement RPC commands nickname_info and nickname_set.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "Conversion.h"
|
||||
#include "NewcoinAddress.h"
|
||||
#include "AccountState.h"
|
||||
#include "NicknameState.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define VALIDATORS_FETCH_SECONDS 30
|
||||
@@ -826,6 +827,78 @@ Json::Value RPCServer::doCreditSet(Json::Value& params)
|
||||
}
|
||||
}
|
||||
|
||||
// nickname_info <nickname>
|
||||
Json::Value RPCServer::doNicknameInfo(Json::Value& params)
|
||||
{
|
||||
uint256 uLedger;
|
||||
|
||||
if (params.size() != 1)
|
||||
{
|
||||
return JSONRPCError(400, "invalid params");
|
||||
}
|
||||
|
||||
std::string strNickname = params[0u].asString();
|
||||
boost::trim(strNickname);
|
||||
|
||||
if (strNickname.empty())
|
||||
{
|
||||
return JSONRPCError(400, "invalid nickname (zero length)");
|
||||
}
|
||||
else if (!mNetOps->available())
|
||||
{
|
||||
return JSONRPCError(503, "network not available");
|
||||
}
|
||||
else if ((uLedger = mNetOps->getCurrentLedger()).isZero())
|
||||
{
|
||||
return JSONRPCError(503, "no current ledger");
|
||||
}
|
||||
|
||||
NicknameState::pointer nsSrc = mNetOps->getNicknameState(uLedger, strNickname);
|
||||
if (!nsSrc)
|
||||
{
|
||||
return JSONRPCError(500, "nickname does not exist");
|
||||
}
|
||||
|
||||
Json::Value ret(Json::objectValue);
|
||||
|
||||
ret["nickname"] = strNickname;
|
||||
|
||||
nsSrc->addJson(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// nickname_set <seed> <paying_account> <nickname> [<offer_minimum>] [<authorization>]
|
||||
Json::Value RPCServer::doNicknameSet(Json::Value& params)
|
||||
{
|
||||
uint256 uLedger;
|
||||
|
||||
if (params.size() < 2 || params.size() > 3)
|
||||
{
|
||||
return JSONRPCError(400, "invalid params");
|
||||
}
|
||||
|
||||
std::string strNickname = params[2u].asString();
|
||||
boost::trim(strNickname);
|
||||
|
||||
if (strNickname.empty())
|
||||
{
|
||||
return JSONRPCError(400, "invalid nickname (zero length)");
|
||||
}
|
||||
else if (!mNetOps->available())
|
||||
{
|
||||
return JSONRPCError(503, "network not available");
|
||||
}
|
||||
else if ((uLedger = mNetOps->getCurrentLedger()).isZero())
|
||||
{
|
||||
return JSONRPCError(503, "no current ledger");
|
||||
}
|
||||
|
||||
NicknameState::pointer nsSrc = mNetOps->getNicknameState(uLedger, strNickname);
|
||||
|
||||
return "not implemented";
|
||||
}
|
||||
|
||||
// password_fund <seed> <paying_account> [<account>]
|
||||
// YYY Make making account default to first account for seed.
|
||||
Json::Value RPCServer::doPasswordFund(Json::Value ¶ms)
|
||||
@@ -1867,6 +1940,8 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
|
||||
if (command == "account_wallet_set") return doAccountWalletSet(params);
|
||||
if (command == "connect") return doConnect(params);
|
||||
if (command == "credit_set") return doCreditSet(params);
|
||||
if (command == "nickname_info") return doNicknameInfo(params);
|
||||
if (command == "nickname_set") return doNicknameSet(params);
|
||||
if (command == "password_fund") return doPasswordFund(params);
|
||||
if (command == "password_set") return doPasswordSet(params);
|
||||
if (command == "peers") return doPeers(params);
|
||||
|
||||
@@ -56,6 +56,8 @@ private:
|
||||
Json::Value doConnect(Json::Value& params);
|
||||
Json::Value doCreditSet(Json::Value& params);
|
||||
Json::Value doLedger(Json::Value& params);
|
||||
Json::Value doNicknameInfo(Json::Value& params);
|
||||
Json::Value doNicknameSet(Json::Value& params);
|
||||
Json::Value doPasswordFund(Json::Value& params);
|
||||
Json::Value doPasswordSet(Json::Value& params);
|
||||
Json::Value doPeers(Json::Value& params);
|
||||
|
||||
@@ -46,6 +46,8 @@ void printHelp(const po::options_description& desc)
|
||||
cout << " connect <ip> [<port>]" << endl;
|
||||
cout << " credit_set <seed> <paying_account> <destination_account> <limit_amount> <currency> [<account_rate>]" << endl;
|
||||
cout << " ledger" << endl;
|
||||
cout << " nickname_info <nickname>" << endl;
|
||||
cout << " nickname_set <seed> <paying_account> <nickname> [<offer_minimum>] [<authorization>]" << endl;
|
||||
cout << " password_fund <seed> <paying_account> [<account>]" << endl;
|
||||
cout << " password_set <master_seed> <regular_seed> [<account>]" << endl;
|
||||
cout << " peers" << endl;
|
||||
|
||||
Reference in New Issue
Block a user