-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): centralize
blockchain_rpc
methods into a single enum
Reduce boilerplate for metrics
- Loading branch information
1 parent
28c8444
commit 12c7958
Showing
3 changed files
with
118 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::proto::blockchain::*; | ||
use crate::proto::overlay; | ||
|
||
macro_rules! constructor_to_string { | ||
($($ty:path as $name:ident),* $(,)?) => { | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum Constructor { | ||
$($name),* | ||
} | ||
|
||
impl Constructor { | ||
pub fn from_tl_id(id: u32) -> Option<Self> { | ||
match id { | ||
$(<$ty>::TL_ID => Some(Self::$name)),*, | ||
_ => None | ||
} | ||
} | ||
|
||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
$(Self::$name => stringify!($name)),* | ||
} | ||
} | ||
|
||
} | ||
}; | ||
} | ||
|
||
// update list in `def core_blockchain_rpc_per_method_stats() -> RowPanel:` after changing this | ||
constructor_to_string! { | ||
overlay::Ping as Ping, | ||
rpc::GetNextKeyBlockIds as GetNextKeyBlockIds, | ||
rpc::GetBlockFull as GetBlockFull, | ||
rpc::GetNextBlockFull as GetNextBlockFull, | ||
rpc::GetBlockDataChunk as GetBlockDataChunk, | ||
rpc::GetKeyBlockProof as GetKeyBlockProof, | ||
rpc::GetPersistentShardStateInfo as GetPersistentShardStateInfo, | ||
rpc::GetPersistentQueueStateInfo as GetPersistentQueueStateInfo, | ||
rpc::GetPersistentShardStateChunk as GetPersistentShardStateChunk, | ||
rpc::GetPersistentQueueStateChunk as GetPersistentQueueStateChunk, | ||
rpc::GetArchiveInfo as GetArchiveInfo, | ||
rpc::GetArchiveChunk as GetArchiveChunk | ||
} |
Oops, something went wrong.