Ledger_entry return invalid parameter error for v1 (#873)

Fixes #875
This commit is contained in:
cyan317
2023-09-28 09:14:01 +01:00
committed by GitHub
parent e36545058d
commit 963685dd31
8 changed files with 153 additions and 48 deletions

View File

@@ -31,7 +31,7 @@ namespace rpc {
/**
* @brief Default API version to use if no version is specified by clients
*/
static constexpr uint32_t API_VERSION_DEFAULT = 2u;
static constexpr uint32_t API_VERSION_DEFAULT = 1u;
/**
* @brief Minimum API version supported by this build

View File

@@ -56,10 +56,6 @@ public:
if (ctx.method == "subscribe" || ctx.method == "unsubscribe")
return false;
// TODO: if needed, make configurable with json config option
if (ctx.apiVersion == 1)
return true;
if (handlerProvider_->isClioOnly(ctx.method))
return false;

View File

@@ -80,10 +80,17 @@ AccountInfoHandler::process(AccountInfoHandler::Input input, Context const& ctx)
}
return Output(
lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle, isDisallowIncomingEnabled, isClawbackEnabled, signerList);
lgrInfo.seq,
ripple::strHex(lgrInfo.hash),
sle,
isDisallowIncomingEnabled,
isClawbackEnabled,
ctx.apiVersion,
signerList);
}
return Output(lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle, isDisallowIncomingEnabled, isClawbackEnabled);
return Output(
lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle, isDisallowIncomingEnabled, isClawbackEnabled, ctx.apiVersion);
}
void
@@ -138,12 +145,10 @@ tag_invoke(boost::json::value_from_tag, boost::json::value& jv, AccountInfoHandl
std::cend(output.signerLists.value()),
std::back_inserter(signers),
[](auto const& signerList) { return toJson(signerList); });
// version 2 puts the signer_lists out of the account_data
jv.as_object()[JS(signer_lists)] = signers;
// this is a temporary fix to support the clients that still expect v1 api(the signer_lists under
// account_data)
// TODO: we need to deprecate the duplicate later
jv.as_object()[JS(account_data)].as_object()[JS(signer_lists)] = std::move(signers);
if (output.apiVersion == 1)
jv.as_object()[JS(account_data)].as_object()[JS(signer_lists)] = std::move(signers);
else
jv.as_object()[JS(signer_lists)] = signers;
}
}

View File

@@ -44,6 +44,7 @@ public:
ripple::STLedgerEntry accountData;
bool isDisallowIncomingEnabled = false;
bool isClawbackEnabled = false;
uint32_t apiVersion;
std::optional<std::vector<ripple::STLedgerEntry>> signerLists;
// validated should be sent via framework
bool validated = true;
@@ -54,12 +55,14 @@ public:
ripple::STLedgerEntry sle,
bool isDisallowIncomingEnabled,
bool isClawbackEnabled,
uint32_t version,
std::optional<std::vector<ripple::STLedgerEntry>> signerLists = std::nullopt)
: ledgerIndex(ledgerId)
, ledgerHash(std::move(ledgerHash))
, accountData(std::move(sle))
, isDisallowIncomingEnabled(isDisallowIncomingEnabled)
, isClawbackEnabled(isClawbackEnabled)
, apiVersion(version)
, signerLists(std::move(signerLists))
{
}

View File

@@ -82,6 +82,8 @@ LedgerEntryHandler::process(LedgerEntryHandler::Input input, Context const& ctx)
else
{
// Must specify 1 of the following fields to indicate what type
if (ctx.apiVersion == 1)
return Error{Status{RippledError::rpcINVALID_PARAMS}};
return Error{Status{ClioError::rpcUNKNOWN_OPTION}};
}