Allow qualities to be specified as a float for RPC.

This commit is contained in:
Arthur Britto
2012-08-20 13:19:43 -07:00
parent 2522c4625f
commit a99f814c20
5 changed files with 35 additions and 4 deletions

View File

@@ -44,8 +44,8 @@ Json::Value RPCServer::RPCError(int iError)
{ rpcACT_NOT_FOUND, "actNotFound", "Account not found." },
{ rpcBAD_SEED, "badSeed", "Disallowed seed." },
{ rpcDST_ACT_MALFORMED, "dstActMalformed", "Destination account is malformed." },
{ rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency is malformed." },
{ rpcDST_ACT_MISSING, "dstActMissing", "Destination account does not exists." },
{ rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency is malformed." },
{ rpcFAIL_GEN_DECRPYT, "failGenDecrypt", "Failed to decrypt generator." },
{ rpcGETS_ACT_MALFORMED, "getsActMalformed", "Gets account malformed." },
{ rpcGETS_AMT_MALFORMED, "getsAmtMalformed", "Gets ammount malformed." },
@@ -71,6 +71,7 @@ Json::Value RPCServer::RPCError(int iError)
{ rpcPAYS_AMT_MALFORMED, "paysAmtMalformed", "Pays amount malformed." },
{ rpcPORT_MALFORMED, "portMalformed", "Port is malformed." },
{ rpcPUBLIC_MALFORMED, "publicMalformed", "Public key is malformed." },
{ rpcQUALITY_MALFORMED, "qualityMalformed", "Quality malformed." },
{ rpcSRC_ACT_MALFORMED, "srcActMalformed", "Source account is malformed." },
{ rpcSRC_ACT_MISSING, "srcActMissing", "Source account does not exist." },
{ rpcSRC_AMT_MALFORMED, "srcAmtMalformed", "Source amount/currency is malformed." },
@@ -1573,8 +1574,8 @@ Json::Value RPCServer::doRippleLineSet(const Json::Value& params)
bool bLimitAmount = true;
bool bQualityIn = params.size() >= 6;
bool bQualityOut = params.size() >= 7;
uint32 uQualityIn = bQualityIn ? lexical_cast_s<uint32>(params[5u].asString()) : 0;
uint32 uQualityOut = bQualityOut ? lexical_cast_s<uint32>(params[6u].asString()) : 0;
uint32 uQualityIn = 0;
uint32 uQualityOut = 0;
if (!naSeed.setSeedGeneric(params[0u].asString()))
{
@@ -1592,6 +1593,14 @@ Json::Value RPCServer::doRippleLineSet(const Json::Value& params)
{
return RPCError(rpcSRC_AMT_MALFORMED);
}
else if (bQualityIn && !parseQuality(params[5u].asString(), uQualityIn))
{
return RPCError(rpcQUALITY_MALFORMED);
}
else if (bQualityOut && !parseQuality(params[6u].asString(), uQualityOut))
{
return RPCError(rpcQUALITY_MALFORMED);
}
else
{
NewcoinAddress naMasterGenerator;

View File

@@ -48,6 +48,7 @@ public:
// Bad parameter
rpcACT_MALFORMED,
rpcQUALITY_MALFORMED,
rpcBAD_SEED,
rpcDST_ACT_MALFORMED,
rpcDST_ACT_MISSING,

View File

@@ -50,7 +50,6 @@ enum PathFlags
PF_ISSUE = 0x80,
};
#define QUALITY_ONE 1000000000 // 10e9
#define CURRENCY_XNS uint160(0)
#define CURRENCY_ONE uint160(1) // Used as a place holder
#define ACCOUNT_XNS uint160(0)

View File

@@ -156,6 +156,25 @@ bool parseIpPort(const std::string& strSource, std::string& strIP, int& iPort)
return bValid;
}
//
// Quality parsing
// - integers as is.
// - floats multiplied by a billion
bool parseQuality(const std::string& strSource, uint32& uQuality)
{
uQuality = lexical_cast_s<uint32>(strSource);
if (!uQuality)
{
float fQuality = lexical_cast_s<float>(strSource);
if (fQuality)
uQuality = QUALITY_ONE*fQuality;
}
return !!uQuality;
}
/*
void intIPtoStr(int ip,std::string& retStr)
{

View File

@@ -8,6 +8,8 @@
#include "types.h"
#define QUALITY_ONE 1000000000 // 10e9
#define nothing() do {} while (0)
#define fallthru() do {} while (0)
#define NUMBER(x) (sizeof(x)/sizeof((x)[0]))
@@ -153,6 +155,7 @@ std::vector<unsigned char> strCopy(const std::string& strSrc);
std::string strCopy(const std::vector<unsigned char>& vucSrc);
bool parseIpPort(const std::string& strSource, std::string& strIP, int& iPort);
bool parseQuality(const std::string& strSource, uint32& uQuality);
DH* DH_der_load(const std::string& strDer);
std::string DH_der_gen(int iKeyLength);