Make RPC submit more robust.

This commit is contained in:
Arthur Britto
2012-12-22 16:25:42 -08:00
parent c05d4fb559
commit a201a91ab0

View File

@@ -868,6 +868,10 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
RippleAddress naSeed; RippleAddress naSeed;
RippleAddress raSrcAddressID; RippleAddress raSrcAddressID;
cLog(lsDEBUG)
<< boost::str(boost::format("doSubmit: %s")
% jvRequest);
if (!jvRequest.isMember("secret") || !jvRequest.isMember("tx_json")) if (!jvRequest.isMember("secret") || !jvRequest.isMember("tx_json"))
{ {
return rpcError(rpcINVALID_PARAMS); return rpcError(rpcINVALID_PARAMS);
@@ -875,6 +879,10 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
Json::Value txJSON = jvRequest["tx_json"]; Json::Value txJSON = jvRequest["tx_json"];
if (!txJSON.isObject())
{
return rpcError(rpcINVALID_PARAMS);
}
if (!naSeed.setSeedGeneric(jvRequest["secret"].asString())) if (!naSeed.setSeedGeneric(jvRequest["secret"].asString()))
{ {
return rpcError(rpcBAD_SEED); return rpcError(rpcBAD_SEED);
@@ -887,18 +895,14 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
{ {
return rpcError(rpcSRC_ACT_MALFORMED); return rpcError(rpcSRC_ACT_MALFORMED);
} }
if (!txJSON.isMember("TransactionType"))
{
return rpcError(rpcINVALID_PARAMS);
}
AccountState::pointer asSrc = mNetOps->getAccountState(mNetOps->getCurrentLedger(), raSrcAddressID); AccountState::pointer asSrc = mNetOps->getAccountState(mNetOps->getCurrentLedger(), raSrcAddressID);
if (!asSrc) return rpcError(rpcSRC_ACT_MALFORMED); if (!asSrc) return rpcError(rpcSRC_ACT_MALFORMED);
if (!txJSON.isMember("Fee")
&& ("OfferCreate" == txJSON["TransactionType"].asString()
|| "OfferCancel" == txJSON["TransactionType"].asString()
|| "TrustSet" == txJSON["TransactionType"].asString()))
{
txJSON["Fee"] = (int) theConfig.FEE_DEFAULT;
}
if ("Payment" == txJSON["TransactionType"].asString()) if ("Payment" == txJSON["TransactionType"].asString())
{ {
@@ -976,6 +980,14 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
} }
} }
if (!txJSON.isMember("Fee")
&& ("OfferCreate" == txJSON["TransactionType"].asString()
|| "OfferCancel" == txJSON["TransactionType"].asString()
|| "TrustSet" == txJSON["TransactionType"].asString()))
{
txJSON["Fee"] = (int) theConfig.FEE_DEFAULT;
}
if (!txJSON.isMember("Sequence")) txJSON["Sequence"] = asSrc->getSeq(); if (!txJSON.isMember("Sequence")) txJSON["Sequence"] = asSrc->getSeq();
if (!txJSON.isMember("Flags")) txJSON["Flags"] = 0; if (!txJSON.isMember("Flags")) txJSON["Flags"] = 0;
@@ -991,7 +1003,6 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest)
bool bHaveAuthKey = false; bool bHaveAuthKey = false;
RippleAddress naAuthorizedPublic; RippleAddress naAuthorizedPublic;
RippleAddress naSecret = RippleAddress::createSeedGeneric(jvRequest["secret"].asString()); RippleAddress naSecret = RippleAddress::createSeedGeneric(jvRequest["secret"].asString());
RippleAddress naMasterGenerator = RippleAddress::createGeneratorPublic(naSecret); RippleAddress naMasterGenerator = RippleAddress::createGeneratorPublic(naSecret);