11use crate :: {
2+ get_endpoint,
23 rpc_wrapper:: {
34 block_store:: { BlockInformation , BlockStore } ,
45 configs:: { IsBlockHashValidConfig , SendTransactionConfig } ,
@@ -8,13 +9,18 @@ use crate::{
89 workers:: { BlockListener , Cleaner , TxSender , WireTransaction } ,
910 } ,
1011 sampler:: { get_serialized, pull_and_verify_shreds, SHRED_CF } ,
12+ tinydancer:: Cluster ,
13+ ConfigSchema ,
1114} ;
15+ use colored:: Colorize ;
1216use hyper:: Method ;
1317use reqwest:: header;
1418use serde:: { self , Deserialize , Serialize } ;
1519use solana_client:: rpc_response:: RpcApiVersion ;
1620use std:: {
21+ fs,
1722 ops:: { Deref , Sub } ,
23+ path:: Path ,
1824 str:: FromStr ,
1925 sync:: Arc ,
2026 time:: Duration ,
@@ -260,13 +266,24 @@ impl LiteRpcServer for LiteBridge {
260266 ) = self . block_store . get_latest_block ( commitment_config) . await ;
261267
262268 info ! ( "glb {blockhash} {slot} {block_height}" ) ;
263-
264- let sampled = pull_and_verify_shreds (
265- slot as usize ,
266- String :: from ( "http://0.0.0.0:8899" ) ,
267- 10 as usize ,
268- )
269- . await ;
269+ let mut rpc_url = String :: from ( "http://0.0.0.0:8899" ) ;
270+ let home_path = std:: env:: var ( "HOME" ) . unwrap ( ) ;
271+ let is_existing = home_path. clone ( ) + "/.config/tinydancer/config.json" ;
272+ let path = Path :: new ( & is_existing) ;
273+ if path. exists ( ) {
274+ let file = fs:: File :: open ( home_path. clone ( ) + "/.config/tinydancer/config.json" )
275+ . expect ( "Error reading config in bridge" ) ;
276+ let config: ConfigSchema = serde_json:: from_reader ( file) . unwrap ( ) ;
277+ rpc_url = get_endpoint ( config. cluster ) ;
278+ } else {
279+ println ! (
280+ "{} {}" ,
281+ "Initialise a config first using:" . to_string( ) . yellow( ) ,
282+ "tinydancer set config" . to_string( ) . green( )
283+ ) ;
284+ }
285+ let sampled =
286+ pull_and_verify_shreds ( slot as usize , String :: from ( rpc_url) , 10 as usize ) . await ;
270287
271288 Ok ( LiteResponse {
272289 context : LiteRpcResponseContext {
@@ -345,12 +362,24 @@ impl LiteRpcServer for LiteBridge {
345362 . get_latest_block_info ( CommitmentConfig :: finalized ( ) )
346363 . await
347364 . slot ;
348- let sampled = pull_and_verify_shreds (
349- slot as usize ,
350- String :: from ( "http://0.0.0.0:8899" ) ,
351- 10 as usize ,
352- )
353- . await ;
365+ let mut rpc_url = String :: from ( "http://0.0.0.0:8899" ) ;
366+ let home_path = std:: env:: var ( "HOME" ) . unwrap ( ) ;
367+ let is_existing = home_path. clone ( ) + "/.config/tinydancer/config.json" ;
368+ let path = Path :: new ( & is_existing) ;
369+ if path. exists ( ) {
370+ let file = fs:: File :: open ( home_path. clone ( ) + "/.config/tinydancer/config.json" )
371+ . expect ( "Error reading config in bridge" ) ;
372+ let config: ConfigSchema = serde_json:: from_reader ( file) . unwrap ( ) ;
373+ rpc_url = get_endpoint ( config. cluster ) ;
374+ } else {
375+ println ! (
376+ "{} {}" ,
377+ "Initialise a config first using:" . to_string( ) . yellow( ) ,
378+ "tinydancer set config" . to_string( ) . green( )
379+ ) ;
380+ }
381+ let sampled =
382+ pull_and_verify_shreds ( slot as usize , String :: from ( rpc_url) , 10 as usize ) . await ;
354383 Ok ( LiteResponse {
355384 context : LiteRpcResponseContext {
356385 slot,
0 commit comments