44mod utils;
55
66use config:: { get_testnet_rpc_url, get_mainnet_rpc_url, load_testnet_env} ;
7- use rpc:: fetch:: { fetch_latest_block, fetch_block_by_number, fetch_transaction_receipt } ;
8- use utils:: { print_block_info, print_transactions , find_max_gas_transaction , hex_to_u64, calculate_gas_percentage , consume_and_calculate_gas } ;
7+ use rpc:: fetch:: { fetch_latest_block, fetch_block_by_number, fetch_last_5_blocks_and_receipts } ;
8+ use utils:: { print_block_info, hex_to_u64, analyze_max_gas_transaction } ;
99use tokio;
1010
1111#[ tokio:: main]
@@ -28,35 +28,24 @@ async fn main() {
2828 print_block_info ( & block_mainnet) ;
2929
3030 let transactions = block_mainnet. transactions ;
31- print_transactions ( & transactions) ;
31+ // print_transactions(&transactions);
3232
33- println ! ( "----------------------" ) ;
34-
35- if let Some ( max_tx) = find_max_gas_transaction ( & transactions) {
36- println ! ( "Transakcija sa najvecim gas limitom: " ) ;
37- println ! ( "Hash {}" , max_tx. hash) ;
38- println ! ( "Gas limit: (hex): {}" , max_tx. gas) ;
39- println ! ( ) ;
40-
41- let receipt = fetch_transaction_receipt ( & mainnet_rpc_url, & max_tx. hash ) . await ;
42- //println!("{:?}", receipt); // OVO MOZE
43- let tx_gas_used = hex_to_u64 ( & receipt. gas_used ) ;
44- let block_gas_used = hex_to_u64 ( & block_mainnet. gas_used ) ;
45- let percent_of_block = calculate_gas_percentage ( tx_gas_used, block_gas_used) ;
33+ analyze_max_gas_transaction ( & mainnet_rpc_url, & transactions, & block_mainnet. gas_used ) . await ;
4634
47- println ! ( "Gas potrosen od ove transakcije: {}" , tx_gas_used ) ;
48- println ! ( "Gas potrosen u bloku: {}" , block_gas_used ) ;
49- println ! ( "Procenat potrosnje u bloku: {:.6}%" , percent_of_block ) ;
50- println ! ( ) ;
51-
52- println ! ( "Funkcija uzima ownership" ) ;
53- let percent_of_block1 = consume_and_calculate_gas ( receipt , block_mainnet . gas_used ) ;
54- println ! ( "Procenat potrosnje u bloku: {:.6}%" , percent_of_block1 ) ;
55- // println!("{:?}", receipt); //OVO NE MOZE jer je promenjen owner
56- //println!("{}",block_response.gas_used);
57- //let tx_gas_used1 = hex_to_u64(&receipt.gas_used);
58- //let block_gas_used1 = hex_to_u64(&block_response.gas_used);
59- } else {
60- println ! ( "Nema transakcija u ovom bloku" ) ;
35+ println ! ( ) ;
36+ println ! ( "=======================" ) ;
37+ println ! ( "Fetchujem 5 poslednjih blokova i njihove max gas transakcije..." ) ;
38+ println ! ( "======================= \n " ) ;
39+
40+ let latest_block_number = hex_to_u64 ( & block_mainnet . number ) ;
41+ let summaries = fetch_last_5_blocks_and_receipts ( mainnet_rpc_url , latest_block_number ) . await ;
42+
43+ println ! ( "\n ===== REZIME 5 BLOKOVA =====" ) ;
44+ for s in summaries {
45+ println ! (
46+ "Blok {} | TX {} | Gas {} | {:.3}%" ,
47+ s . block_number , s . tx_hash , s . gas_used , s . percent_in_block
48+ ) ;
6149 }
62- }
50+
51+ }
0 commit comments