Use the new visitor code to reimplement account_offers.

This commit is contained in:
JoelKatz
2013-05-30 13:20:34 -07:00
parent fdea361dd7
commit ce3a8d9d76

View File

@@ -1101,6 +1101,17 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL
return jvResult;
}
static void offerAdder(Json::Value& jvLines, SLE::ref offer)
{
if (offer->getType() == ltOFFER)
{
Json::Value& obj = jvLines.append(Json::objectValue);
offer->getFieldAmount(sfTakerPays).setJson(obj["taker_pays"]);
offer->getFieldAmount(sfTakerGets).setJson(obj["taker_gets"]);
obj["seq"] = offer->getFieldU32(sfSequence);
}
}
// {
// account: <account>|<nickname>|<account_public_key>
// account_index: <number> // optional, defaults to 0.
@@ -1139,26 +1150,10 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest, int& cost, Scoped
jvResult["account_index"] = iIndex;
if (lpLedger->hasAccount(raAccount))
{
Json::Value& jsonLines = (jvResult["offers"] = Json::arrayValue);
AccountItems offers(raAccount.getAccountID(), lpLedger, AccountItem::pointer(new Offer()));
BOOST_FOREACH(AccountItem::ref item, offers.getItems())
{
Offer* offer=(Offer*)item.get();
Json::Value& obj = jsonLines.append(Json::objectValue);
offer->getTakerPays().setJson(obj["taker_pays"]);
offer->getTakerGets().setJson(obj["taker_gets"]);
obj["seq"] = offer->getSeq();
}
}
lpLedger->visitAccountItems(raAccount.getAccountID(),
BIND_TYPE(&offerAdder, boost::ref(jvResult["offers"] = Json::arrayValue), P_1));
else
{
jvResult = rpcError(rpcACT_NOT_FOUND);
}
return jvResult;
}