Update getLeaderSchedule options (#16749)

This commit is contained in:
Tyera Eulberg 2021-04-22 13:27:30 -06:00 committed by GitHub
parent 556997666c
commit 636b5987af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -49,6 +49,22 @@ pub struct RpcLeaderScheduleConfig {
pub commitment: Option<CommitmentConfig>, pub commitment: Option<CommitmentConfig>,
} }
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RpcLeaderScheduleConfigWrapper {
SlotOnly(Option<Slot>),
ConfigOnly(Option<RpcLeaderScheduleConfig>),
}
impl RpcLeaderScheduleConfigWrapper {
pub fn unzip(&self) -> (Option<Slot>, Option<RpcLeaderScheduleConfig>) {
match &self {
RpcLeaderScheduleConfigWrapper::SlotOnly(slot) => (*slot, None),
RpcLeaderScheduleConfigWrapper::ConfigOnly(config) => (None, config.clone()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum RpcLargestAccountsFilter { pub enum RpcLargestAccountsFilter {

View File

@ -2109,7 +2109,7 @@ pub mod rpc_minimal {
fn get_leader_schedule( fn get_leader_schedule(
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
slot: Option<Slot>, options: Option<RpcLeaderScheduleConfigWrapper>,
config: Option<RpcLeaderScheduleConfig>, config: Option<RpcLeaderScheduleConfig>,
) -> Result<Option<RpcLeaderSchedule>>; ) -> Result<Option<RpcLeaderSchedule>>;
} }
@ -2214,10 +2214,11 @@ pub mod rpc_minimal {
fn get_leader_schedule( fn get_leader_schedule(
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
slot: Option<Slot>, options: Option<RpcLeaderScheduleConfigWrapper>,
config: Option<RpcLeaderScheduleConfig>, config: Option<RpcLeaderScheduleConfig>,
) -> Result<Option<RpcLeaderSchedule>> { ) -> Result<Option<RpcLeaderSchedule>> {
let config = config.unwrap_or_default(); let (slot, maybe_config) = options.map(|options| options.unzip()).unwrap_or_default();
let config = maybe_config.or(config).unwrap_or_default();
if let Some(ref identity) = config.identity { if let Some(ref identity) = config.identity {
let _ = verify_pubkey(identity)?; let _ = verify_pubkey(identity)?;
@ -4250,6 +4251,10 @@ pub mod tests {
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [null, {{ "identity": "{}" }}]}}"#, r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [null, {{ "identity": "{}" }}]}}"#,
bank.collector_id().to_string() bank.collector_id().to_string()
), ),
&format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [{{ "identity": "{}" }}]}}"#,
bank.collector_id().to_string()
),
] ]
.iter() .iter()
{ {
@ -4299,7 +4304,7 @@ pub mod tests {
// `bob` is not in the leader schedule, look for an empty response // `bob` is not in the leader schedule, look for an empty response
let req = format!( let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [null, {{ "identity": "{}"}}]}}"#, r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [{{ "identity": "{}"}}]}}"#,
bob_pubkey bob_pubkey
); );