-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API does not accept seed or public key for account #4404
Changes from 7 commits
d183bf6
f028527
b3cf64a
aa420cf
958a3e6
0263106
4f970ef
8997cb7
7d93021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ addChannel(Json::Value& jsonLines, SLE const& line) | |
} | ||
|
||
// { | ||
// account: <account>|<account_public_key> | ||
// account: <account> | ||
// ledger_hash : <ledger> | ||
// ledger_index : <ledger_index> | ||
// limit: integer // optional | ||
|
@@ -76,26 +76,25 @@ doAccountChannels(RPC::JsonContext& context) | |
if (!ledger) | ||
return result; | ||
|
||
std::string strIdent(params[jss::account].asString()); | ||
AccountID accountID; | ||
|
||
if (auto const err = RPC::accountFromString(accountID, strIdent)) | ||
return err; | ||
auto id = parseBase58<AccountID>(params[jss::account].asString()); | ||
if (!id) | ||
{ | ||
return rpcError(rpcACT_MALFORMED); | ||
} | ||
AccountID const accountID{std::move(id.value())}; | ||
|
||
if (!ledger->exists(keylet::account(accountID))) | ||
return rpcError(rpcACT_NOT_FOUND); | ||
|
||
std::string strDst; | ||
if (params.isMember(jss::destination_account)) | ||
strDst = params[jss::destination_account].asString(); | ||
auto hasDst = !strDst.empty(); | ||
|
||
AccountID raDstAccount; | ||
if (hasDst) | ||
{ | ||
if (auto const err = RPC::accountFromString(raDstAccount, strDst)) | ||
return err; | ||
} | ||
auto const raDstAccount = [&]() -> std::optional<AccountID> { | ||
return strDst.empty() ? std::nullopt : parseBase58<AccountID>(strDst); | ||
}(); | ||
if (!strDst.empty() && !raDstAccount) | ||
return rpcError(rpcACT_MALFORMED); | ||
|
||
unsigned int limit; | ||
if (auto err = readLimitField(limit, RPC::Tuning::accountChannels, context)) | ||
|
@@ -109,10 +108,9 @@ doAccountChannels(RPC::JsonContext& context) | |
{ | ||
std::vector<std::shared_ptr<SLE const>> items; | ||
AccountID const& accountID; | ||
bool hasDst; | ||
AccountID const& raDstAccount; | ||
std::optional<AccountID> const& raDstAccount; | ||
}; | ||
VisitData visitData = {{}, accountID, hasDst, raDstAccount}; | ||
VisitData visitData = {{}, accountID, raDstAccount}; | ||
visitData.items.reserve(limit); | ||
uint256 startAfter = beast::zero; | ||
std::uint64_t startHint = 0; | ||
|
@@ -180,8 +178,8 @@ doAccountChannels(RPC::JsonContext& context) | |
|
||
if (count <= limit && sleCur->getType() == ltPAYCHAN && | ||
(*sleCur)[sfAccount] == accountID && | ||
(!visitData.hasDst || | ||
visitData.raDstAccount == (*sleCur)[sfDestination])) | ||
(!visitData.raDstAccount || | ||
*visitData.raDstAccount == (*sleCur)[sfDestination])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can simplify:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently we check if DstAccount is provided or Your suggestion seems to change the intention of this check. Would it work as expected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. I'm taking back this suggestion. |
||
{ | ||
visitData.items.emplace_back(sleCur); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,19 +46,19 @@ doAccountCurrencies(RPC::JsonContext& context) | |
params.isMember(jss::account) ? params[jss::account].asString() | ||
: params[jss::ident].asString()); | ||
|
||
bool const bStrict = | ||
params.isMember(jss::strict) && params[jss::strict].asBool(); | ||
|
||
// Get info on account. | ||
AccountID accountID; // out param | ||
if (auto jvAccepted = RPC::accountFromString(accountID, strIdent, bStrict)) | ||
return jvAccepted; | ||
auto const accountID = parseBase58<AccountID>(strIdent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have applied your suggested changes across the board. Let me know if you find any further issues. |
||
if (!accountID) | ||
{ | ||
RPC::inject_error(rpcACT_MALFORMED, result); | ||
return result; | ||
} | ||
|
||
if (!ledger->exists(keylet::account(accountID))) | ||
if (!ledger->exists(keylet::account(*accountID))) | ||
return rpcError(rpcACT_NOT_FOUND); | ||
|
||
std::set<Currency> send, receive; | ||
for (auto const& rspEntry : RPCTrustLine::getItems(accountID, *ledger)) | ||
for (auto const& rspEntry : RPCTrustLine::getItems(*accountID, *ledger)) | ||
{ | ||
STAmount const& saBalance = rspEntry.getBalance(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,17 +30,6 @@ | |
|
||
namespace ripple { | ||
|
||
struct VisitData | ||
{ | ||
std::vector<RPCTrustLine> items; | ||
AccountID const& accountID; | ||
bool hasPeer; | ||
AccountID const& raPeerAccount; | ||
|
||
bool ignoreDefault; | ||
uint32_t foundCount; | ||
}; | ||
|
||
void | ||
addLine(Json::Value& jsonLines, RPCTrustLine const& line) | ||
{ | ||
|
@@ -76,7 +65,7 @@ addLine(Json::Value& jsonLines, RPCTrustLine const& line) | |
} | ||
|
||
// { | ||
// account: <account>|<account_public_key> | ||
// account: <account> | ||
// ledger_hash : <ledger> | ||
// ledger_index : <ledger_index> | ||
// limit: integer // optional | ||
|
@@ -96,33 +85,28 @@ doAccountLines(RPC::JsonContext& context) | |
if (!ledger) | ||
return result; | ||
|
||
std::string strIdent(params[jss::account].asString()); | ||
AccountID accountID; | ||
|
||
if (auto jv = RPC::accountFromString(accountID, strIdent)) | ||
auto const accountID = | ||
parseBase58<AccountID>(params[jss::account].asString()); | ||
if (!accountID) | ||
{ | ||
for (auto it = jv.begin(); it != jv.end(); ++it) | ||
justinr1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
result[it.memberName()] = *it; | ||
RPC::inject_error(rpcACT_MALFORMED, result); | ||
return result; | ||
} | ||
|
||
if (!ledger->exists(keylet::account(accountID))) | ||
if (!ledger->exists(keylet::account(*accountID))) | ||
return rpcError(rpcACT_NOT_FOUND); | ||
|
||
std::string strPeer; | ||
if (params.isMember(jss::peer)) | ||
strPeer = params[jss::peer].asString(); | ||
auto hasPeer = !strPeer.empty(); | ||
|
||
AccountID raPeerAccount; | ||
if (hasPeer) | ||
auto const raPeerAccount = [&]() -> std::optional<AccountID> { | ||
return strPeer.empty() ? std::nullopt : parseBase58<AccountID>(strPeer); | ||
}(); | ||
if (!strPeer.empty() && !raPeerAccount) | ||
{ | ||
if (auto jv = RPC::accountFromString(raPeerAccount, strPeer)) | ||
{ | ||
for (auto it = jv.begin(); it != jv.end(); ++it) | ||
result[it.memberName()] = *it; | ||
return result; | ||
} | ||
RPC::inject_error(rpcACT_MALFORMED, result); | ||
return result; | ||
} | ||
|
||
unsigned int limit; | ||
|
@@ -138,8 +122,15 @@ doAccountLines(RPC::JsonContext& context) | |
params[jss::ignore_default].asBool(); | ||
|
||
Json::Value& jsonLines(result[jss::lines] = Json::arrayValue); | ||
VisitData visitData = { | ||
{}, accountID, hasPeer, raPeerAccount, ignoreDefault, 0}; | ||
struct VisitData | ||
{ | ||
std::vector<RPCTrustLine> items; | ||
AccountID const& accountID; | ||
std::optional<AccountID> const& raPeerAccount; | ||
bool ignoreDefault; | ||
uint32_t foundCount; | ||
}; | ||
VisitData visitData = {{}, *accountID, raPeerAccount, ignoreDefault, 0}; | ||
uint256 startAfter = beast::zero; | ||
std::uint64_t startHint = 0; | ||
|
||
|
@@ -177,7 +168,7 @@ doAccountLines(RPC::JsonContext& context) | |
if (!sle) | ||
return rpcError(rpcINVALID_PARAMS); | ||
|
||
if (!RPC::isRelatedToAccount(*ledger, sle, accountID)) | ||
if (!RPC::isRelatedToAccount(*ledger, sle, *accountID)) | ||
return rpcError(rpcINVALID_PARAMS); | ||
} | ||
|
||
|
@@ -187,7 +178,7 @@ doAccountLines(RPC::JsonContext& context) | |
{ | ||
if (!forEachItemAfter( | ||
*ledger, | ||
accountID, | ||
*accountID, | ||
startAfter, | ||
startHint, | ||
limit + 1, | ||
|
@@ -227,8 +218,8 @@ doAccountLines(RPC::JsonContext& context) | |
RPCTrustLine::makeItem(visitData.accountID, sleCur); | ||
|
||
if (line && | ||
(!visitData.hasPeer || | ||
visitData.raPeerAccount == | ||
(!visitData.raPeerAccount || | ||
*visitData.raPeerAccount == | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can simplify: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, we check if peerAccount is not provided or Your suggestion seems to change the intention of this check. Would it work as expected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. I'm taking back this suggestion. |
||
line->getAccountIDPeer())) | ||
{ | ||
visitData.items.emplace_back(*line); | ||
|
@@ -252,7 +243,7 @@ doAccountLines(RPC::JsonContext& context) | |
to_string(*marker) + "," + std::to_string(nextHint); | ||
} | ||
|
||
result[jss::account] = toBase58(accountID); | ||
result[jss::account] = toBase58(*accountID); | ||
|
||
for (auto const& item : visitData.items) | ||
addLine(jsonLines, item); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accountID
is not really an optional. It's always seated if valid. Consider something like this:It also results in fewer code changes. Other handlers have a similar code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed.