Fix RpcClient MemCmp filter version mapping (#28499)
* Add VersionReq struct to handle multiple version checks * Use VersionReq to fix MemCmp filter breakage * Simplify if case
This commit is contained in:
parent
199398d5c4
commit
7be8af5f40
|
@ -1,5 +1,6 @@
|
|||
#![allow(deprecated)]
|
||||
use {
|
||||
crate::version_req::VersionReq,
|
||||
solana_sdk::account::{AccountSharedData, ReadableAccount},
|
||||
spl_token_2022::{generic_token_account::GenericTokenAccount, state::Account},
|
||||
std::borrow::Cow,
|
||||
|
@ -263,7 +264,11 @@ pub fn maybe_map_filters(
|
|||
node_version: Option<semver::Version>,
|
||||
filters: &mut [RpcFilterType],
|
||||
) -> Result<(), String> {
|
||||
if node_version.is_none() || node_version.unwrap() < semver::Version::new(1, 11, 2) {
|
||||
let version_reqs = VersionReq::from_strs(&["<1.11.2", "~1.13"])?;
|
||||
let needs_mapping = node_version
|
||||
.map(|version| version_reqs.matches_any(&version))
|
||||
.unwrap_or(true);
|
||||
if needs_mapping {
|
||||
for filter in filters.iter_mut() {
|
||||
if let RpcFilterType::Memcmp(memcmp) = filter {
|
||||
match &memcmp.bytes {
|
||||
|
|
|
@ -8,6 +8,7 @@ pub mod error_object;
|
|||
pub mod filter;
|
||||
pub mod request;
|
||||
pub mod response;
|
||||
pub mod version_req;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
pub(crate) struct VersionReq(Vec<semver::VersionReq>);
|
||||
|
||||
impl VersionReq {
|
||||
pub(crate) fn from_strs<T>(versions: &[T]) -> Result<Self, String>
|
||||
where
|
||||
T: AsRef<str> + std::fmt::Debug,
|
||||
{
|
||||
let mut version_reqs = vec![];
|
||||
for version in versions {
|
||||
let version_req = semver::VersionReq::parse(version.as_ref())
|
||||
.map_err(|err| format!("Could not parse version {:?}: {:?}", version, err))?;
|
||||
version_reqs.push(version_req);
|
||||
}
|
||||
Ok(Self(version_reqs))
|
||||
}
|
||||
|
||||
pub(crate) fn matches_any(&self, version: &semver::Version) -> bool {
|
||||
self.0.iter().any(|r| r.matches(version))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue