1- use std :: collections :: HashMap ;
1+ use blockless_sdk :: * ;
22use serde:: Serialize ;
33use serde_json:: json;
4- use blockless_sdk :: * ;
4+ use std :: collections :: HashMap ;
55
66#[ derive( Debug , Serialize ) ]
77struct CoinPrice {
@@ -14,20 +14,28 @@ fn main() {
1414 // read coin id from stdin
1515 let mut buf = [ 0 ; 1024 ] ;
1616 let len = read_stdin ( & mut buf) . unwrap ( ) ;
17- let coin_id = std:: str:: from_utf8 ( & buf[ ..len as usize ] ) . unwrap_or_default ( ) . trim ( ) ;
17+ let coin_id = std:: str:: from_utf8 ( & buf[ ..len as usize ] )
18+ . unwrap_or_default ( )
19+ . trim ( ) ;
1820
1921 // perform http request
2022 let http_opts = HttpOptions :: new ( "GET" , 30 , 10 ) ;
2123 let http_res = BlocklessHttp :: open (
22- format ! ( "https://api.coingecko.com/api/v3/simple/price?ids={}&vs_currencies=usd" , coin_id) . as_str ( ) ,
23- & http_opts
24- ) . unwrap ( ) ;
24+ format ! (
25+ "https://api.coingecko.com/api/v3/simple/price?ids={}&vs_currencies=usd" ,
26+ coin_id
27+ )
28+ . as_str ( ) ,
29+ & http_opts,
30+ )
31+ . unwrap ( ) ;
2532 let body = http_res. get_all_body ( ) . unwrap ( ) ; // e.g. {"bitcoin":{"usd":67675}}
2633
2734 // println!("{}", String::from_utf8(body.clone()).unwrap());
2835
2936 // parse the json response; extrac usd price
30- let json: serde_json:: Result < HashMap < String , HashMap < String , f64 > > > = serde_json:: from_slice ( & body) ;
37+ let json: serde_json:: Result < HashMap < String , HashMap < String , f64 > > > =
38+ serde_json:: from_slice ( & body) ;
3139 let Ok ( data) = json else {
3240 eprintln ! ( "Failed to parse JSON" ) ;
3341 return ;
0 commit comments