Fixes for RPC wallet_add and work toward more commands.

This commit is contained in:
Arthur Britto
2012-06-02 11:53:38 -07:00
parent f0e3383856
commit 583b0b9052
8 changed files with 57 additions and 9 deletions

View File

@@ -36,9 +36,9 @@ public:
return mLedgerEntry->getIFieldPresent(sfAuthorizedKey);
}
uint160 getAuthorizedKey()
NewcoinAddress getAuthorizedKey()
{
return mLedgerEntry->getIFieldH160(sfAuthorizedKey);
return mLedgerEntry->getIValueFieldAccount(sfAuthorizedKey);
}
const NewcoinAddress& getAccountID() const { return mAccountID; }

View File

@@ -5,6 +5,9 @@
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <openssl/md5.h>
#include "../json/reader.h"
#include "../json/writer.h"
@@ -254,10 +257,10 @@ Json::Value RPCServer::authorize(const uint256& uLedger,
naAccountPublic.setAccountPublic(naGenerator, iIndex);
naAccountPrivate.setAccountPrivate(naGenerator, naSeed, iIndex);
if (asSrc->getAuthorizedKey() != naAccountPublic.getAccountID())
if (asSrc->getAuthorizedKey().getAccountID() != naAccountPublic.getAccountID())
{
std::cerr << "iIndex: " << iIndex << std::endl;
std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey()) << std::endl;
std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()) << std::endl;
std::cerr << "naAccountPublic: " << strHex(naAccountPublic.getAccountID()) << std::endl;
return JSONRPCError(500, "wrong password (changed)");
@@ -322,6 +325,40 @@ Json::Value RPCServer::accountFromString(const uint256& uLedger, NewcoinAddress&
return Json::Value(Json::objectValue);
}
// account_email_set <seed> <paying_account> [<email_address>]
Json::Value RPCServer::doAccountEmailSet(Json::Value &params)
{
if (params.size() < 2 || params.size() > 3)
{
return "invalid params";
}
else if (!mNetOps->available())
{
return JSONRPCError(503, "network not available");
}
// Hash as per: http://en.gravatar.com/site/implement/hash/
std::string strEmail = 3 == params.size() ? params[2u].asString() : "";
std::vector<unsigned char> vucMD5(128/8, 0);
std::string strMD5Lower;
boost::trim(strEmail);
boost::to_lower(strEmail);
MD5(reinterpret_cast<const unsigned char*>(strEmail.c_str()), strEmail.size(), &vucMD5.front());
strMD5Lower = strHex(vucMD5);
boost::to_lower(strMD5Lower);
Json::Value ret(Json::objectValue);
ret["email"] = strEmail;
ret["hash"] = strHex(vucMD5);
ret["url_gravatar"] = str(boost::format("http://www.gravatar.com/avatar/%s") % strMD5Lower);
return ret;
}
// account_info <account>|<nickname>|<account_public_key>
// account_info <seed>|<pass_phrase>|<key> [<index>]
Json::Value RPCServer::doAccountInfo(Json::Value &params)
@@ -1458,6 +1495,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
{
std::cerr << "RPC:" << command << std::endl;
if (command == "account_email_set") return doAccountEmailSet(params);
if (command == "account_info") return doAccountInfo(params);
if (command == "account_lines") return doAccountLines(params);
if (command == "connect") return doConnect(params);

View File

@@ -48,6 +48,7 @@ private:
Json::Value accountFromString(const uint256& uLedger, NewcoinAddress& naAccount, bool& bIndex, const std::string& strIdent, const int iIndex);
Json::Value doAccountEmailSet(Json::Value &params);
Json::Value doAccountInfo(Json::Value& params);
Json::Value doAccountLines(Json::Value &params);
Json::Value doConnect(Json::Value& params);

View File

@@ -49,6 +49,7 @@ enum SOE_Field
sfFlags,
sfGenerator,
sfGeneratorID,
sfHash,
sfHighID,
sfHighLimit,
sfIdentifier,

View File

@@ -583,7 +583,7 @@ TransactionEngineResult TransactionEngine::doClaim(const SerializedTransaction&
//
// Set the public key needed to use the account.
sleDst->setIFieldH160(sfAuthorizedKey, hGeneratorID);
sleDst->setIFieldAccount(sfAuthorizedKey, hGeneratorID);
// Construct a generator map entry.
sleGen = boost::make_shared<SerializedLedgerEntry>(ltGENERATOR_MAP);
@@ -930,8 +930,6 @@ TransactionEngineResult TransactionEngine::doWalletAdd(const SerializedTransacti
LedgerStateParms qry = lepNONE;
SLE::pointer sleDst = mLedger->getAccountRoot(qry, uDstAccountID);
std::cerr << str(boost::format("WalletAdd: %s") % sleDst->getFullText()) << std::endl;
if (sleDst)
{
std::cerr << "WalletAdd: account already created" << std::endl;

View File

@@ -5,6 +5,14 @@
TransactionFormat InnerTxnFormats[]=
{
{ "AccountSet", ttACCOUNT_SET, {
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
{ S_FIELD(EmailHash), STI_HASH128, SOE_IFFLAG, 1 },
{ S_FIELD(WalletLocator), STI_HASH256, SOE_IFFLAG, 2 },
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 4 },
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
{ "Claim", ttCLAIM, {
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
{ S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 },

View File

@@ -9,8 +9,9 @@ enum TransactionType
ttPAYMENT = 0,
ttCLAIM = 1,
ttWALLET_ADD = 2,
ttINVOICE = 3,
ttOFFER = 4,
ttACCOUNT_SET = 3,
ttINVOICE = 4,
ttOFFER = 5,
ttCREDIT_SET = 20,
ttTRANSIT_SET = 21,
};

View File

@@ -37,6 +37,7 @@ void printHelp(const po::options_description& desc)
cout << desc << endl;
cout << "Commands: " << endl;
cout << " account_email_set <seed> <paying_account> [<email_address>]" << endl;
cout << " account_info <account>|<nickname>" << endl;
cout << " account_info <seed>|<pass_phrase>|<key> [<index>]" << endl;
cout << " account_lines <account>|<nickname>" << endl;