-
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 5 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 const accountID = | ||
parseBase58<AccountID>(params[jss::account].asString()); | ||
if (!accountID) | ||
{ | ||
rpcError(rpcACT_MALFORMED); | ||
} | ||
|
||
if (!ledger->exists(keylet::account(accountID))) | ||
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; | ||
|
@@ -151,7 +149,7 @@ doAccountChannels(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); | ||
} | ||
|
||
|
@@ -160,7 +158,7 @@ doAccountChannels(RPC::JsonContext& context) | |
std::uint64_t nextHint = 0; | ||
if (!forEachItemAfter( | ||
*ledger, | ||
accountID, | ||
*accountID, | ||
startAfter, | ||
startHint, | ||
limit + 1, | ||
|
@@ -179,9 +177,9 @@ doAccountChannels(RPC::JsonContext& context) | |
} | ||
|
||
if (count <= limit && sleCur->getType() == ltPAYCHAN && | ||
(*sleCur)[sfAccount] == accountID && | ||
(!visitData.hasDst || | ||
visitData.raDstAccount == (*sleCur)[sfDestination])) | ||
(*sleCur)[sfAccount] == *accountID && | ||
(!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); | ||
} | ||
|
@@ -202,7 +200,7 @@ doAccountChannels(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) | ||
addChannel(jsonChannels, *item); | ||
|
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(); | ||
|
||
|
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.