11pub mod dashboard;
2- use clap:: { Args , Parser , Subcommand } ;
2+ use clap:: { Args , Parser } ;
33
44use std:: path:: Path ;
55
6- use ethereum_types:: H256 ;
76use thiserror:: Error ;
87
98use dashboard:: grafana:: { GrafanaAPI , DASHBOARD_TEMPLATES } ;
10- use ethportal_api:: { BlockBodyKey , BlockHeaderKey , BlockReceiptsKey , HistoryContentKey } ;
11- use trin_utils:: bytes:: hex_encode;
129
1310#[ derive( Parser , Debug , PartialEq ) ]
1411#[ command(
@@ -18,36 +15,9 @@ use trin_utils::bytes::hex_encode;
1815 about = "Portal Network command line utilities"
1916) ]
2017enum Trin {
21- #[ command( subcommand) ]
22- EncodeKey ( EncodeKey ) ,
2318 CreateDashboard ( DashboardConfig ) ,
2419}
2520
26- // TODO: Remove clippy allow once a variant with non-"Block" prefix is added.
27- /// Encode a content key.
28- #[ derive( Subcommand , Debug , PartialEq ) ]
29- #[ allow( clippy:: enum_variant_names) ]
30- enum EncodeKey {
31- /// Encode the content key for a block header.
32- BlockHeader {
33- /// Hex-encoded block hash (omit '0x' prefix).
34- #[ arg( long) ]
35- block_hash : H256 ,
36- } ,
37- /// Encode the content key for a block body.
38- BlockBody {
39- /// Hex-encoded block hash (omit '0x' prefix).
40- #[ arg( long) ]
41- block_hash : H256 ,
42- } ,
43- /// Encode the content key for a block's transaction receipts.
44- BlockReceipts {
45- /// Hex-encoded block hash (omit '0x' prefix).
46- #[ arg( long) ]
47- block_hash : H256 ,
48- } ,
49- }
50-
5121#[ derive( Args , Debug , PartialEq ) ]
5222#[ command( name = "create-dashboard" ) ]
5323#[ allow( clippy:: enum_variant_names) ]
@@ -67,33 +37,10 @@ struct DashboardConfig {
6737
6838fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
6939 match Trin :: parse ( ) {
70- Trin :: EncodeKey ( content_key) => encode_content_key ( content_key) ,
7140 Trin :: CreateDashboard ( dashboard_config) => create_dashboard ( dashboard_config) ,
7241 }
7342}
7443
75- fn encode_content_key ( content_key : EncodeKey ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
76- let key = match content_key {
77- EncodeKey :: BlockHeader { block_hash } => {
78- HistoryContentKey :: BlockHeaderWithProof ( BlockHeaderKey {
79- block_hash : block_hash. into ( ) ,
80- } )
81- }
82- EncodeKey :: BlockBody { block_hash } => HistoryContentKey :: BlockBody ( BlockBodyKey {
83- block_hash : block_hash. into ( ) ,
84- } ) ,
85- EncodeKey :: BlockReceipts { block_hash } => {
86- HistoryContentKey :: BlockReceipts ( BlockReceiptsKey {
87- block_hash : block_hash. into ( ) ,
88- } )
89- }
90- } ;
91-
92- println ! ( "{}" , hex_encode( Into :: <Vec <u8 >>:: into( key) ) ) ;
93-
94- Ok ( ( ) )
95- }
96-
9744fn create_dashboard ( dashboard_config : DashboardConfig ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
9845 let grafana = GrafanaAPI :: new (
9946 dashboard_config. grafana_username ,
@@ -121,53 +68,6 @@ mod tests {
12168 use super :: * ;
12269 use std:: str:: FromStr ;
12370
124- #[ test]
125- fn test_trin_with_encode_key ( ) {
126- const BLOCK_HASH : & str =
127- "0x9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" ;
128- let trin = Trin :: parse_from ( [
129- "test" ,
130- "encode-key" ,
131- "block-header" ,
132- "--block-hash" ,
133- BLOCK_HASH ,
134- ] ) ;
135- assert_eq ! (
136- trin,
137- Trin :: EncodeKey ( EncodeKey :: BlockHeader {
138- block_hash: H256 :: from_str( BLOCK_HASH ) . unwrap( )
139- } )
140- ) ;
141-
142- let trin = Trin :: parse_from ( [
143- "test" ,
144- "encode-key" ,
145- "block-body" ,
146- "--block-hash" ,
147- BLOCK_HASH ,
148- ] ) ;
149- assert_eq ! (
150- trin,
151- Trin :: EncodeKey ( EncodeKey :: BlockBody {
152- block_hash: H256 :: from_str( BLOCK_HASH ) . unwrap( )
153- } )
154- ) ;
155-
156- let trin = Trin :: parse_from ( [
157- "test" ,
158- "encode-key" ,
159- "block-receipts" ,
160- "--block-hash" ,
161- BLOCK_HASH ,
162- ] ) ;
163- assert_eq ! (
164- trin,
165- Trin :: EncodeKey ( EncodeKey :: BlockReceipts {
166- block_hash: H256 :: from_str( BLOCK_HASH ) . unwrap( )
167- } )
168- ) ;
169- }
170-
17171 #[ test]
17272 fn test_trin_with_create_dashboard ( ) {
17373 let trin = Trin :: parse_from ( [
0 commit comments