Update getLeaderSchedule options (#16749)
This commit is contained in:
parent
556997666c
commit
636b5987af
|
@ -49,6 +49,22 @@ pub struct RpcLeaderScheduleConfig {
|
|||
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)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum RpcLargestAccountsFilter {
|
||||
|
|
|
@ -2109,7 +2109,7 @@ pub mod rpc_minimal {
|
|||
fn get_leader_schedule(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
slot: Option<Slot>,
|
||||
options: Option<RpcLeaderScheduleConfigWrapper>,
|
||||
config: Option<RpcLeaderScheduleConfig>,
|
||||
) -> Result<Option<RpcLeaderSchedule>>;
|
||||
}
|
||||
|
@ -2214,10 +2214,11 @@ pub mod rpc_minimal {
|
|||
fn get_leader_schedule(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
slot: Option<Slot>,
|
||||
options: Option<RpcLeaderScheduleConfigWrapper>,
|
||||
config: Option<RpcLeaderScheduleConfig>,
|
||||
) -> 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 {
|
||||
let _ = verify_pubkey(identity)?;
|
||||
|
@ -4250,6 +4251,10 @@ pub mod tests {
|
|||
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [null, {{ "identity": "{}" }}]}}"#,
|
||||
bank.collector_id().to_string()
|
||||
),
|
||||
&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [{{ "identity": "{}" }}]}}"#,
|
||||
bank.collector_id().to_string()
|
||||
),
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
|
@ -4299,7 +4304,7 @@ pub mod tests {
|
|||
|
||||
// `bob` is not in the leader schedule, look for an empty response
|
||||
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
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue