11pub mod dashboard;
2- use clap:: { Args , Parser , Subcommand } ;
3-
4- use ethereum_types:: H256 ;
2+ use clap:: { Args , Parser } ;
53
64use dashboard:: grafana:: { GrafanaAPI , DASHBOARD_TEMPLATES } ;
7- use ethportal_api:: { BlockBodyKey , BlockHeaderKey , BlockReceiptsKey , HistoryContentKey } ;
8- use trin_utils:: bytes:: hex_encode;
95
106#[ derive( Parser , Debug , PartialEq ) ]
117#[ command(
@@ -15,36 +11,9 @@ use trin_utils::bytes::hex_encode;
1511 about = "Portal Network command line utilities"
1612) ]
1713enum Trin {
18- #[ command( subcommand) ]
19- EncodeKey ( EncodeKey ) ,
2014 CreateDashboard ( DashboardConfig ) ,
2115}
2216
23- // TODO: Remove clippy allow once a variant with non-"Block" prefix is added.
24- /// Encode a content key.
25- #[ derive( Subcommand , Debug , PartialEq ) ]
26- #[ allow( clippy:: enum_variant_names) ]
27- enum EncodeKey {
28- /// Encode the content key for a block header.
29- BlockHeader {
30- /// Hex-encoded block hash (omit '0x' prefix).
31- #[ arg( long) ]
32- block_hash : H256 ,
33- } ,
34- /// Encode the content key for a block body.
35- BlockBody {
36- /// Hex-encoded block hash (omit '0x' prefix).
37- #[ arg( long) ]
38- block_hash : H256 ,
39- } ,
40- /// Encode the content key for a block's transaction receipts.
41- BlockReceipts {
42- /// Hex-encoded block hash (omit '0x' prefix).
43- #[ arg( long) ]
44- block_hash : H256 ,
45- } ,
46- }
47-
4817#[ derive( Args , Debug , PartialEq ) ]
4918#[ command( name = "create-dashboard" ) ]
5019#[ allow( clippy:: enum_variant_names) ]
@@ -64,33 +33,10 @@ struct DashboardConfig {
6433
6534fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
6635 match Trin :: parse ( ) {
67- Trin :: EncodeKey ( content_key) => encode_content_key ( content_key) ,
6836 Trin :: CreateDashboard ( dashboard_config) => create_dashboard ( dashboard_config) ,
6937 }
7038}
7139
72- fn encode_content_key ( content_key : EncodeKey ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
73- let key = match content_key {
74- EncodeKey :: BlockHeader { block_hash } => {
75- HistoryContentKey :: BlockHeaderWithProof ( BlockHeaderKey {
76- block_hash : block_hash. into ( ) ,
77- } )
78- }
79- EncodeKey :: BlockBody { block_hash } => HistoryContentKey :: BlockBody ( BlockBodyKey {
80- block_hash : block_hash. into ( ) ,
81- } ) ,
82- EncodeKey :: BlockReceipts { block_hash } => {
83- HistoryContentKey :: BlockReceipts ( BlockReceiptsKey {
84- block_hash : block_hash. into ( ) ,
85- } )
86- }
87- } ;
88-
89- println ! ( "{}" , hex_encode( Into :: <Vec <u8 >>:: into( key) ) ) ;
90-
91- Ok ( ( ) )
92- }
93-
9440fn create_dashboard ( dashboard_config : DashboardConfig ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
9541 let grafana = GrafanaAPI :: new (
9642 dashboard_config. grafana_username ,
@@ -116,54 +62,6 @@ fn create_dashboard(dashboard_config: DashboardConfig) -> Result<(), Box<dyn std
11662#[ cfg( test) ]
11763mod tests {
11864 use super :: * ;
119- use std:: str:: FromStr ;
120-
121- #[ test]
122- fn test_trin_with_encode_key ( ) {
123- const BLOCK_HASH : & str =
124- "0x9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" ;
125- let trin = Trin :: parse_from ( [
126- "test" ,
127- "encode-key" ,
128- "block-header" ,
129- "--block-hash" ,
130- BLOCK_HASH ,
131- ] ) ;
132- assert_eq ! (
133- trin,
134- Trin :: EncodeKey ( EncodeKey :: BlockHeader {
135- block_hash: H256 :: from_str( BLOCK_HASH ) . unwrap( )
136- } )
137- ) ;
138-
139- let trin = Trin :: parse_from ( [
140- "test" ,
141- "encode-key" ,
142- "block-body" ,
143- "--block-hash" ,
144- BLOCK_HASH ,
145- ] ) ;
146- assert_eq ! (
147- trin,
148- Trin :: EncodeKey ( EncodeKey :: BlockBody {
149- block_hash: H256 :: from_str( BLOCK_HASH ) . unwrap( )
150- } )
151- ) ;
152-
153- let trin = Trin :: parse_from ( [
154- "test" ,
155- "encode-key" ,
156- "block-receipts" ,
157- "--block-hash" ,
158- BLOCK_HASH ,
159- ] ) ;
160- assert_eq ! (
161- trin,
162- Trin :: EncodeKey ( EncodeKey :: BlockReceipts {
163- block_hash: H256 :: from_str( BLOCK_HASH ) . unwrap( )
164- } )
165- ) ;
166- }
16765
16866 #[ test]
16967 fn test_trin_with_create_dashboard ( ) {
0 commit comments