- 
                Notifications
    You must be signed in to change notification settings 
- Fork 44
feat(platform): get current quorum info #2168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
86ab246
              676c115
              ff0eded
              5b5833b
              19994b2
              f7fffd7
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| pub mod validator; | ||
| pub mod validator_set; | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| use crate::bls_signatures::PublicKey as BlsPublicKey; | ||
| use crate::core_types::validator::v0::{ValidatorV0, ValidatorV0Getters, ValidatorV0Setters}; | ||
| use dashcore::{ProTxHash, PubkeyHash}; | ||
| #[cfg(feature = "core-types-serde-conversion")] | ||
| use serde::{Deserialize, Serialize}; | ||
|  | ||
| /// Version 0 | ||
| pub mod v0; | ||
|  | ||
| /// A validator in the context of a quorum | ||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| #[cfg_attr( | ||
| feature = "core-types-serde-conversion", | ||
| derive(Serialize, Deserialize) | ||
| )] | ||
| pub enum Validator { | ||
| /// Version 0 | ||
| V0(ValidatorV0), | ||
| } | ||
|  | ||
| impl ValidatorV0Getters for Validator { | ||
| fn pro_tx_hash(&self) -> &ProTxHash { | ||
| match self { | ||
| Validator::V0(v0) => v0.pro_tx_hash(), | ||
| } | ||
| } | ||
|  | ||
| fn public_key(&self) -> &Option<BlsPublicKey> { | ||
| match self { | ||
| Validator::V0(v0) => v0.public_key(), | ||
| } | ||
| } | ||
|  | ||
| fn node_ip(&self) -> &String { | ||
| match self { | ||
| Validator::V0(v0) => v0.node_ip(), | ||
| } | ||
| } | ||
|  | ||
| fn node_id(&self) -> &PubkeyHash { | ||
| match self { | ||
| Validator::V0(v0) => v0.node_id(), | ||
| } | ||
| } | ||
|  | ||
| fn core_port(&self) -> u16 { | ||
| match self { | ||
| Validator::V0(v0) => v0.core_port(), | ||
| } | ||
| } | ||
|  | ||
| fn platform_http_port(&self) -> u16 { | ||
| match self { | ||
| Validator::V0(v0) => v0.platform_http_port(), | ||
| } | ||
| } | ||
|  | ||
| fn platform_p2p_port(&self) -> u16 { | ||
| match self { | ||
| Validator::V0(v0) => v0.platform_p2p_port(), | ||
| } | ||
| } | ||
|  | ||
| fn is_banned(&self) -> bool { | ||
| match self { | ||
| Validator::V0(v0) => v0.is_banned(), | ||
| } | ||
| } | ||
| } | ||
| 
      Comment on lines
    
      +21
     to 
      +69
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor repetitive match statements in  The implementation of  Consider implementing the trait methods using a macro or delegating directly to the inner  impl ValidatorV0Getters for Validator {
    fn pro_tx_hash(&self) -> &ProTxHash {
        &self.as_v0().pro_tx_hash
    }
    fn public_key(&self) -> &Option<BlsPublicKey> {
        &self.as_v0().public_key
    }
    // Implement other methods similarly...
}
impl Validator {
    fn as_v0(&self) -> &ValidatorV0 {
        match self {
            Validator::V0(v0) => v0,
        }
    }
}This approach reduces the repetitive pattern matching in each method. | ||
|  | ||
| impl ValidatorV0Setters for Validator { | ||
| fn set_pro_tx_hash(&mut self, pro_tx_hash: ProTxHash) { | ||
| match self { | ||
| Validator::V0(v0) => v0.set_pro_tx_hash(pro_tx_hash), | ||
| } | ||
| } | ||
|  | ||
| fn set_public_key(&mut self, public_key: Option<BlsPublicKey>) { | ||
| match self { | ||
| Validator::V0(v0) => v0.set_public_key(public_key), | ||
| } | ||
| } | ||
|  | ||
| fn set_node_ip(&mut self, node_ip: String) { | ||
| match self { | ||
| Validator::V0(v0) => v0.set_node_ip(node_ip), | ||
| } | ||
| } | ||
|  | ||
| fn set_node_id(&mut self, node_id: PubkeyHash) { | ||
| match self { | ||
| Validator::V0(v0) => v0.set_node_id(node_id), | ||
| } | ||
| } | ||
|  | ||
| fn set_core_port(&mut self, core_port: u16) { | ||
| match self { | ||
| Validator::V0(v0) => v0.set_core_port(core_port), | ||
| } | ||
| } | ||
|  | ||
| fn set_platform_http_port(&mut self, platform_http_port: u16) { | ||
| match self { | ||
| Validator::V0(v0) => v0.set_platform_http_port(platform_http_port), | ||
| } | ||
| } | ||
|  | ||
| fn set_platform_p2p_port(&mut self, platform_p2p_port: u16) { | ||
| match self { | ||
| Validator::V0(v0) => v0.set_platform_p2p_port(platform_p2p_port), | ||
| } | ||
| } | ||
|  | ||
| fn set_is_banned(&mut self, is_banned: bool) { | ||
| match self { | ||
| Validator::V0(v0) => v0.set_is_banned(is_banned), | ||
| } | ||
| } | ||
| } | ||
| 
      Comment on lines
    
      +71
     to 
      +119
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor repetitive match statements in  Similarly, the  You can apply the same strategy as with the getters by adding a mutable accessor for  impl ValidatorV0Setters for Validator {
    fn set_pro_tx_hash(&mut self, pro_tx_hash: ProTxHash) {
        self.as_mut_v0().pro_tx_hash = pro_tx_hash;
    }
    fn set_public_key(&mut self, public_key: Option<BlsPublicKey>) {
        self.as_mut_v0().public_key = public_key;
    }
    // Implement other methods similarly...
}
impl Validator {
    fn as_mut_v0(&mut self) -> &mut ValidatorV0 {
        match self {
            Validator::V0(v0) => v0,
        }
    }
}This refactoring reduces redundancy and makes the code cleaner. | ||
Uh oh!
There was an error while loading. Please reload this page.