diff --git a/core/api/service/child_state/requests/get_keys.cpp b/core/api/service/child_state/requests/get_keys.cpp index a78a26d3c4..90c7d8e6c0 100644 --- a/core/api/service/child_state/requests/get_keys.cpp +++ b/core/api/service/child_state/requests/get_keys.cpp @@ -19,7 +19,7 @@ namespace kagome::api::child_state::request { // childKey auto ¶m0 = params[0]; - if (not param0.IsString() or param0.IsNil()) { + if (not param0.IsString()) { throw jsonrpc::InvalidParametersFault( "Parameter '[child_storage_key]' must be a hex string"); } @@ -29,7 +29,7 @@ namespace kagome::api::child_state::request { auto ¶m1 = params[1]; - if (not param1.IsString() and not param1.IsNil()) { + if (not param1.IsString()) { throw jsonrpc::InvalidParametersFault( "Parameter '[prefix]' must be a hex string"); } @@ -48,16 +48,17 @@ namespace kagome::api::child_state::request { return outcome::success(); } - // process at param - if (not params[2].IsString()) { - throw jsonrpc::InvalidParametersFault( - "Parameter '[at]' must be a hex string representation of an encoded " - "optional byte sequence"); + if (not params[2].IsNil()) { + // process at param + if (not params[2].IsString()) { + throw jsonrpc::InvalidParametersFault( + "Parameter '[at]' must be a hex string representation of an " + "encoded optional byte sequence"); + } + OUTCOME_TRY(at_span, common::unhexWith0x(params[2].AsString())); + OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span)); + at_ = at; } - OUTCOME_TRY(at_span, common::unhexWith0x(params[2].AsString())); - OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span)); - at_ = at; - return outcome::success(); } diff --git a/core/api/service/child_state/requests/get_keys_paged.cpp b/core/api/service/child_state/requests/get_keys_paged.cpp index f63aa65c21..fbe4deef75 100644 --- a/core/api/service/child_state/requests/get_keys_paged.cpp +++ b/core/api/service/child_state/requests/get_keys_paged.cpp @@ -19,7 +19,7 @@ namespace kagome::api::child_state::request { // childKey auto ¶m0 = params[0]; - if (not param0.IsString() or param0.IsNil()) { + if (not param0.IsString()) { throw jsonrpc::InvalidParametersFault( "Parameter '[child_storage_key]' must be a hex string"); } @@ -29,7 +29,7 @@ namespace kagome::api::child_state::request { auto ¶m1 = params[1]; - if (not param1.IsString() and not param1.IsNil()) { + if (not param1.IsString()) { throw jsonrpc::InvalidParametersFault( "Parameter '[prefix]' must be a hex string"); } @@ -69,15 +69,17 @@ namespace kagome::api::child_state::request { return outcome::success(); } - // process at param - if (not params[4].IsString()) { - throw jsonrpc::InvalidParametersFault( - "Parameter '[at]' must be a hex string representation of an encoded " - "optional byte sequence"); + if (not params[4].IsNil()) { + // process at param + if (not params[4].IsString()) { + throw jsonrpc::InvalidParametersFault( + "Parameter '[at]' must be a hex string representation of an encoded " + "optional byte sequence"); + } + OUTCOME_TRY(at_span, common::unhexWith0x(params[4].AsString())); + OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span)); + at_ = at; } - OUTCOME_TRY(at_span, common::unhexWith0x(params[4].AsString())); - OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span)); - at_ = at; return outcome::success(); } diff --git a/core/api/service/child_state/requests/get_storage.cpp b/core/api/service/child_state/requests/get_storage.cpp index 87f9b981f5..d147852a6c 100644 --- a/core/api/service/child_state/requests/get_storage.cpp +++ b/core/api/service/child_state/requests/get_storage.cpp @@ -14,7 +14,7 @@ namespace kagome::api::child_state::request { } auto ¶m0 = params[0]; - if (not param0.IsString() or param0.IsNil()) { + if (not param0.IsString()) { throw jsonrpc::InvalidParametersFault( "Parameter '[child_storage_key]' must be a hex string"); } diff --git a/core/api/service/child_state/requests/get_storage_size.cpp b/core/api/service/child_state/requests/get_storage_size.cpp index a278b2af47..5f62ed1b9c 100644 --- a/core/api/service/child_state/requests/get_storage_size.cpp +++ b/core/api/service/child_state/requests/get_storage_size.cpp @@ -14,7 +14,7 @@ namespace kagome::api::child_state::request { } auto ¶m0 = params[0]; - if (not param0.IsString() or param0.IsNil()) { + if (not param0.IsString()) { throw jsonrpc::InvalidParametersFault( "Parameter '[child_storage_key]' must be a hex string"); } diff --git a/core/api/service/state/requests/call.cpp b/core/api/service/state/requests/call.cpp index 52aafc0e91..677a990196 100644 --- a/core/api/service/state/requests/call.cpp +++ b/core/api/service/state/requests/call.cpp @@ -14,12 +14,12 @@ namespace kagome::api::state::request { }; outcome::result Call::init(const jsonrpc::Request::Parameters ¶ms) { - if (params.size() > 3 or params.size() < 2) { + if (params.size() < 2 or params.size() > 3) { throw jsonrpc::InvalidParametersFault("Incorrect number of params"); } auto ¶m0 = params[0]; - if (param0.IsString() and not param0.IsNil()) { + if (param0.IsString()) { method_ = param0.AsString(); } else { throw jsonrpc::InvalidParametersFault( @@ -27,7 +27,7 @@ namespace kagome::api::state::request { } auto ¶m1 = params[1]; - if (param1.IsString() and not param1.IsNil()) { + if (param1.IsString()) { auto encoded_args = common::unhexWith0x(param1.AsString()); if (encoded_args.has_value()) { data_ = common::Buffer(encoded_args.value()); @@ -45,15 +45,17 @@ namespace kagome::api::state::request { } auto ¶m2 = params[2]; - // process at param - if (not param2.IsString()) { - throw jsonrpc::InvalidParametersFault( - "Parameter '[at]' must be a hex string representation of an encoded " - "optional byte sequence"); + if (!param2.IsNil()) { + // process at param + if (not param2.IsString()) { + throw jsonrpc::InvalidParametersFault( + "Parameter '[at]' must be a hex string representation of an " + "encoded optional byte sequence"); + } + OUTCOME_TRY(at_span, common::unhexWith0x(param2.AsString())); + OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span)); + at_ = at; } - OUTCOME_TRY(at_span, common::unhexWith0x(param2.AsString())); - OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span)); - at_ = at; return outcome::success(); } diff --git a/core/api/service/state/requests/get_keys_paged.cpp b/core/api/service/state/requests/get_keys_paged.cpp index 8c1b4d8cf2..557a09f71d 100644 --- a/core/api/service/state/requests/get_keys_paged.cpp +++ b/core/api/service/state/requests/get_keys_paged.cpp @@ -11,12 +11,12 @@ namespace kagome::api::state::request { outcome::result GetKeysPaged::init( const jsonrpc::Request::Parameters ¶ms) { - if (params.size() > 4 or params.size() <= 1) { + if (params.size() > 4 or params.size() < 2) { throw jsonrpc::InvalidParametersFault("Incorrect number of params"); } auto ¶m0 = params[0]; - if (not param0.IsString() and not param0.IsNil()) { + if (not param0.IsString()) { throw jsonrpc::InvalidParametersFault( "Parameter '[prefix]' must be a hex string"); } @@ -42,7 +42,6 @@ namespace kagome::api::state::request { return outcome::success(); } - // process prev_key param if (not params[2].IsNil()) { if (not params[2].IsString()) { throw jsonrpc::InvalidParametersFault( @@ -57,15 +56,17 @@ namespace kagome::api::state::request { return outcome::success(); } - // process at param - if (not params[3].IsString()) { - throw jsonrpc::InvalidParametersFault( - "Parameter '[at]' must be a hex string representation of an encoded " - "optional byte sequence"); + if (not params[3].IsNil()) { + // process at param + if (not params[3].IsString()) { + throw jsonrpc::InvalidParametersFault( + "Parameter '[at]' must be a hex string representation of an encoded " + "optional byte sequence"); + } + OUTCOME_TRY(at_span, common::unhexWith0x(params[3].AsString())); + OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span)); + at_ = at; } - OUTCOME_TRY(at_span, common::unhexWith0x(params[3].AsString())); - OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span)); - at_ = at; return outcome::success(); } diff --git a/core/api/service/state/requests/subscribe_storage.cpp b/core/api/service/state/requests/subscribe_storage.cpp index 26bd20bb04..af59698e79 100644 --- a/core/api/service/state/requests/subscribe_storage.cpp +++ b/core/api/service/state/requests/subscribe_storage.cpp @@ -9,8 +9,8 @@ namespace kagome::api::state::request { outcome::result SubscribeStorage::init( const jsonrpc::Request::Parameters ¶ms) { - if (params.size() > 1 or params.empty()) { - throw jsonrpc::InvalidParametersFault("Incorrect number of params"); + if (params.size() != 1) { + throw jsonrpc::InvalidParametersFault("subscribeStorage takes one parameter"); } auto &keys = params[0]; if (!keys.IsArray()) { diff --git a/core/api/service/state/requests/unsubscribe_storage.cpp b/core/api/service/state/requests/unsubscribe_storage.cpp index 5a09531bed..9f6e0d45f1 100644 --- a/core/api/service/state/requests/unsubscribe_storage.cpp +++ b/core/api/service/state/requests/unsubscribe_storage.cpp @@ -9,8 +9,8 @@ namespace kagome::api::state::request { outcome::result UnsubscribeStorage::init( const jsonrpc::Request::Parameters ¶ms) { - if (params.size() > 1 or params.empty()) { - throw jsonrpc::InvalidParametersFault("Incorrect number of params"); + if (params.size() != 1) { + throw jsonrpc::InvalidParametersFault("unsubscribeStorage takes one parameter"); } auto &id = params[0];