-
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
Added Error messages on Gateway_Balance and Channel_Authorize #4577
Changes from 16 commits
f7c5c65
2b78768
2eb175e
e493534
690ce23
0cd5145
c843248
614cea4
29971ca
311e66c
3adae5b
dad2e8e
7344b30
b1bae4d
da46159
41fcf31
682a1a4
920cd81
21c5ebd
38e7f8e
ce680b5
092f6c3
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 |
---|---|---|
|
@@ -78,6 +78,12 @@ doGatewayBalances(RPC::JsonContext& context) | |
|
||
result[jss::account] = toBase58(accountID); | ||
|
||
if (!ledger->exists(keylet::account(accountID)) && context.apiVersion > 1u) | ||
{ | ||
RPC::inject_error(rpcACT_NOT_FOUND, result); | ||
return result; | ||
} | ||
|
||
// Parse the specified hotwallet(s), if any | ||
std::set<AccountID> hotWallets; | ||
|
||
|
@@ -116,7 +122,18 @@ doGatewayBalances(RPC::JsonContext& context) | |
|
||
if (!valid) | ||
{ | ||
result[jss::error] = "invalidHotWallet"; | ||
// The documentation states that invalidParams is used when | ||
// One or more fields are specified incorrectly. | ||
// invalidHotwallet should be used when the account exists, but does | ||
// not have currency issued by the account from the request. | ||
if (context.apiVersion < 2u) | ||
{ | ||
result[jss::error] = "invalidHotWallet"; | ||
} | ||
else | ||
{ | ||
result[jss::error] = "invalidParams"; | ||
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. Please inject |
||
} | ||
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. brackets here as well |
||
return result; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ doChannelAuthorize(RPC::JsonContext& context) | |
return RPC::missing_field_error(jss::secret); | ||
|
||
Json::Value result; | ||
auto const [pk, sk] = RPC::keypairForSignature(params, result); | ||
auto const [pk, sk] = RPC::keypairForSignature(params, result, context); | ||
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. consider passing |
||
if (RPC::contains_error(result)) | ||
return result; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -846,7 +846,10 @@ getSeedFromRPC(Json::Value const& params, Json::Value& error) | |
} | ||
|
||
std::pair<PublicKey, SecretKey> | ||
keypairForSignature(Json::Value const& params, Json::Value& error) | ||
keypairForSignature( | ||
Json::Value const& params, | ||
Json::Value& error, | ||
std::optional<std::reference_wrapper<JsonContext>> context) | ||
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. consider |
||
{ | ||
bool const has_key_type = params.isMember(jss::key_type); | ||
|
||
|
@@ -900,7 +903,14 @@ keypairForSignature(Json::Value const& params, Json::Value& error) | |
|
||
if (!keyType) | ||
{ | ||
error = RPC::invalid_field_error(jss::key_type); | ||
if (context.has_value() && context.value().get().apiVersion > 1) | ||
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. nit: keep it consistent - use |
||
{ | ||
error = RPC::make_error(rpcBAD_KEY_TYPE); | ||
} | ||
else | ||
{ | ||
error = RPC::invalid_field_error(jss::key_type); | ||
} | ||
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. are the brackets needed here? |
||
return {}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,7 +207,10 @@ std::optional<Seed> | |
parseRippleLibSeed(Json::Value const& params); | ||
|
||
std::pair<PublicKey, SecretKey> | ||
keypairForSignature(Json::Value const& params, Json::Value& error); | ||
keypairForSignature( | ||
Json::Value const& params, | ||
Json::Value& error, | ||
std::optional<std::reference_wrapper<JsonContext>> context = std::nullopt); | ||
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. Consider changing to |
||
|
||
/** | ||
* API version numbers used in API version 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,9 @@ | |
#include <ripple/protocol/PayChan.h> | ||
#include <ripple/protocol/TxFlags.h> | ||
#include <ripple/protocol/jss.h> | ||
#include <test/jtx.h> | ||
|
||
#include <ripple/rpc/impl/RPCHelpers.h> | ||
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. Why did you change the headers order? The original order and the new line looks right to me. |
||
#include <chrono> | ||
#include <test/jtx.h> | ||
|
||
namespace ripple { | ||
namespace test { | ||
|
@@ -1160,6 +1160,50 @@ struct PayChan_test : public beast::unit_test::suite | |
bob.human()); | ||
} | ||
|
||
void | ||
testAccountChannelAuthorize(FeatureBitset features, unsigned int apiVersion) | ||
{ | ||
testcase("PayChan Channel_Auth RPC Api " + std::to_string(apiVersion)); | ||
using namespace jtx; | ||
using namespace std::literals::chrono_literals; | ||
|
||
Env env{*this, features}; | ||
auto const alice = Account("alice"); | ||
auto const bob = Account("bob"); | ||
auto const charlie = Account("charlie", KeyType::ed25519); | ||
env.fund(XRP(10000), alice, bob, charlie); | ||
auto const pk = alice.pk(); | ||
auto const settleDelay = 3600s; | ||
auto const channelFunds = XRP(1000); | ||
auto const chan1Str = to_string(channel(alice, bob, env.seq(alice))); | ||
env(create(alice, bob, channelFunds, settleDelay, pk)); | ||
env.close(); | ||
|
||
// test for api_version 2 | ||
Json::Value args{Json::objectValue}; | ||
args[jss::api_version] = apiVersion; | ||
args[jss::channel_id] = chan1Str; | ||
args[jss::key_type] = "ed255191"; | ||
args[jss::seed] = "snHq1rzQoN2qiUkC3XF5RyxBzUtN"; | ||
args[jss::amount] = 51110000; | ||
if (apiVersion < 2u) | ||
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. Consider moving the testVersion loop inside this function. The channel above doesn't need to be created twice. Then this is going to be:
|
||
{ | ||
auto const rs = env.rpc( | ||
"json", | ||
"channel_authorize", | ||
args.toStyledString())[jss::result]; | ||
BEAST_EXPECT(rs[jss::error] == "invalidParams"); | ||
} | ||
else | ||
{ | ||
auto const rs = env.rpc( | ||
"json", | ||
"channel_authorize", | ||
args.toStyledString())[jss::result]; | ||
BEAST_EXPECT(rs[jss::error] == "badKeyType"); | ||
} | ||
} | ||
|
||
void | ||
testAuthVerifyRPC(FeatureBitset features) | ||
{ | ||
|
@@ -2139,6 +2183,12 @@ struct PayChan_test : public beast::unit_test::suite | |
testAccountChannelsRPC(features); | ||
testAccountChannelsRPCMarkers(features); | ||
testAccountChannelsRPCSenderOnly(features); | ||
for (auto testVersion = RPC::apiMinimumSupportedVersion; | ||
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. Consider moving the loop inside the function. |
||
testVersion <= RPC::apiBetaVersion; | ||
++testVersion) | ||
{ | ||
testAccountChannelAuthorize(features, testVersion); | ||
} | ||
testAuthVerifyRPC(features); | ||
testOptionalFields(features); | ||
testMalformedPK(features); | ||
|
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.
Please add
rpcINALID_HOT_WALLET
error and inject it into the result.