Start of RPC book_offers.

This commit is contained in:
Arthur Britto
2013-02-28 20:31:51 -08:00
parent 5cb119c08f
commit b4c0469752
4 changed files with 83 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ Json::Value rpcError(int iError, Json::Value jvResult)
{ rpcDST_ACT_MALFORMED, "dstActMalformed", "Destination account is malformed." }, { rpcDST_ACT_MALFORMED, "dstActMalformed", "Destination account is malformed." },
{ rpcDST_ACT_MISSING, "dstActMissing", "Destination account does not exist." }, { rpcDST_ACT_MISSING, "dstActMissing", "Destination account does not exist." },
{ rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency/issuer is malformed." }, { rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency/issuer is malformed." },
{ rpcDST_ISR_MALFORMED, "dstIsrMalformed", "Destination issuer is malformed." },
{ rpcFORBIDDEN, "forbidden", "Bad credentials." }, { rpcFORBIDDEN, "forbidden", "Bad credentials." },
{ rpcFAIL_GEN_DECRPYT, "failGenDecrypt", "Failed to decrypt generator." }, { rpcFAIL_GEN_DECRPYT, "failGenDecrypt", "Failed to decrypt generator." },
{ rpcGETS_ACT_MALFORMED, "getsActMalformed", "Gets account malformed." }, { rpcGETS_ACT_MALFORMED, "getsActMalformed", "Gets account malformed." },

View File

@@ -50,6 +50,7 @@ enum {
rpcDST_ACT_MALFORMED, rpcDST_ACT_MALFORMED,
rpcDST_ACT_MISSING, rpcDST_ACT_MISSING,
rpcDST_AMT_MALFORMED, rpcDST_AMT_MALFORMED,
rpcDST_ISR_MALFORMED,
rpcGETS_ACT_MALFORMED, rpcGETS_ACT_MALFORMED,
rpcGETS_AMT_MALFORMED, rpcGETS_AMT_MALFORMED,
rpcHOST_IP_MALFORMED, rpcHOST_IP_MALFORMED,

View File

@@ -1021,6 +1021,85 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest)
return jvResult; return jvResult;
} }
// {
// "ledger_hash" : ledger, // Optional
// "ledger_index" : ledger_index, // Optional
// "taker_gets" : { "currency": currency, "issuer" : address },
// "taker_pays" : { "currency": currency, "issuer" : address },
// "marker" : element, // Optional.
// "limit" : integer, // Optional.
// "proof" : boolean // Defaults to false.
// }
Json::Value RPCHandler::doBookOffers(Json::Value jvRequest)
{
Ledger::pointer lpLedger;
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
if (!lpLedger)
return jvResult;
ScopedUnlock su(theApp->getMasterLock());
if (!jvRequest.isMember("taker_pays") || !jvRequest.isMember("taker_gets"))
return rpcError(rpcINVALID_PARAMS);
uint160 uTakerPaysCurrencyID;
uint160 uTakerPaysIssuerID;
Json::Value jvTakerPays = jvRequest["taker_pays"];
// Parse mandatory currency.
if (!jvTakerPays.isMember("currency")
|| !STAmount::currencyFromString(uTakerPaysCurrencyID, jvTakerPays["currency"].asString()))
{
cLog(lsINFO) << "Bad taker_pays currency.";
return rpcError(rpcSRC_CUR_MALFORMED);
}
// Parse optional issuer.
else if (((jvTakerPays.isMember("issuer"))
&& (!jvTakerPays["issuer"].isString()
|| !STAmount::issuerFromString(uTakerPaysIssuerID, jvTakerPays["issuer"].asString())))
// Don't allow illegal issuers.
|| !uTakerPaysCurrencyID
|| !uTakerPaysIssuerID
|| ACCOUNT_ONE == uTakerPaysIssuerID)
{
cLog(lsINFO) << "Bad taker_pays issuer.";
return rpcError(rpcSRC_ISR_MALFORMED);
}
uint160 uTakerGetsCurrencyID;
uint160 uTakerGetsIssuerID;
Json::Value jvTakerGets = jvRequest["taker_pays"];
// Parse mandatory currency.
if (!jvTakerGets.isMember("currency")
|| !STAmount::currencyFromString(uTakerGetsCurrencyID, jvTakerGets["currency"].asString()))
{
cLog(lsINFO) << "Bad taker_pays currency.";
return rpcError(rpcSRC_CUR_MALFORMED);
}
// Parse optional issuer.
else if (((jvTakerGets.isMember("issuer"))
&& (!jvTakerGets["issuer"].isString()
|| !STAmount::issuerFromString(uTakerGetsIssuerID, jvTakerGets["issuer"].asString())))
// Don't allow illegal issuers.
|| !uTakerGetsCurrencyID
|| !uTakerGetsIssuerID
|| ACCOUNT_ONE == uTakerGetsIssuerID)
{
cLog(lsINFO) << "Bad taker_gets issuer.";
return rpcError(rpcDST_ISR_MALFORMED);
}
jvResult["hello"] = "world";
return jvResult;
}
// Result: // Result:
// { // {
// random: <uint256> // random: <uint256>
@@ -2799,6 +2878,7 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole)
{ "account_lines", &RPCHandler::doAccountLines, false, optCurrent }, { "account_lines", &RPCHandler::doAccountLines, false, optCurrent },
{ "account_offers", &RPCHandler::doAccountOffers, false, optCurrent }, { "account_offers", &RPCHandler::doAccountOffers, false, optCurrent },
{ "account_tx", &RPCHandler::doAccountTransactions, false, optNetwork }, { "account_tx", &RPCHandler::doAccountTransactions, false, optNetwork },
{ "book_offers", &RPCHandler::doBookOffers, false, optCurrent },
{ "connect", &RPCHandler::doConnect, true, optNone }, { "connect", &RPCHandler::doConnect, true, optNone },
{ "consensus_info", &RPCHandler::doConsensusInfo, true, optNone }, { "consensus_info", &RPCHandler::doConsensusInfo, true, optNone },
{ "get_counts", &RPCHandler::doGetCounts, true, optNone }, { "get_counts", &RPCHandler::doGetCounts, true, optNone },

View File

@@ -47,6 +47,7 @@ class RPCHandler
Json::Value doAccountLines(Json::Value params); Json::Value doAccountLines(Json::Value params);
Json::Value doAccountOffers(Json::Value params); Json::Value doAccountOffers(Json::Value params);
Json::Value doAccountTransactions(Json::Value params); Json::Value doAccountTransactions(Json::Value params);
Json::Value doBookOffers(Json::Value params);
Json::Value doConnect(Json::Value params); Json::Value doConnect(Json::Value params);
Json::Value doConsensusInfo(Json::Value params); Json::Value doConsensusInfo(Json::Value params);
#if ENABLE_INSECURE #if ENABLE_INSECURE