@@ -228,10 +228,10 @@ async fn eth_get_block_by_number(state: &RpcState, params: Option<Value>) -> Res
228228 . collect ( ) ;
229229 json ! ( tx_hashes)
230230 } ;
231-
231+
232232 // Calculate actual block size
233233 let block_size = bincode:: serialized_size ( & block) . unwrap_or ( 0 ) ;
234-
234+
235235 Ok ( json ! ( {
236236 "number" : format!( "0x{:x}" , block. header. height) ,
237237 "hash" : format!( "0x{}" , hex:: encode( block. hash( ) . as_bytes( ) ) ) ,
@@ -305,7 +305,7 @@ async fn eth_get_transaction_by_hash(state: &RpcState, params: Option<Value>) ->
305305 let mut hash = [ 0u8 ; 32 ] ;
306306 hash. copy_from_slice ( & tx_hash_bytes) ;
307307 let target_hash = bitcell_crypto:: Hash256 :: from ( hash) ;
308-
308+
309309 // Use efficient O(1) lookup via transaction hash index
310310 if let Some ( ( tx, location) ) = state. blockchain . get_transaction_by_hash ( & target_hash) {
311311 // Get the block to include block hash in response
@@ -325,7 +325,7 @@ async fn eth_get_transaction_by_hash(state: &RpcState, params: Option<Value>) ->
325325 } ) ) ;
326326 }
327327 }
328-
328+
329329 Ok ( Value :: Null )
330330}
331331
@@ -387,7 +387,8 @@ async fn eth_get_balance(state: &RpcState, params: Option<Value>) -> Result<Valu
387387 . map ( |account| account. balance )
388388 . unwrap_or ( 0 )
389389 } ;
390-
390+
391+
391392 // Return balance as hex string
392393 Ok ( json ! ( format!( "0x{:x}" , balance) ) )
393394}
@@ -405,7 +406,7 @@ async fn eth_get_transaction_count(state: &RpcState, params: Option<Value>) -> R
405406 message : "Params must be an array" . to_string ( ) ,
406407 data : None ,
407408 } ) ?;
408-
409+
409410 if args. is_empty ( ) {
410411 return Err ( JsonRpcError {
411412 code : -32602 ,
@@ -427,18 +428,18 @@ async fn eth_get_transaction_count(state: &RpcState, params: Option<Value>) -> R
427428 message : "Invalid address format" . to_string ( ) ,
428429 data : None ,
429430 } ) ?;
430-
431+
431432 if address_bytes. len ( ) != 33 {
432433 return Err ( JsonRpcError {
433434 code : -32602 ,
434435 message : "Address must be 33 bytes (compressed public key)" . to_string ( ) ,
435436 data : None ,
436437 } ) ;
437438 }
438-
439+
439440 let mut address = [ 0u8 ; 33 ] ;
440441 address. copy_from_slice ( & address_bytes) ;
441-
442+
442443 // Fetch nonce from blockchain state
443444 let nonce = {
444445 let state_lock = state. blockchain . state ( ) ;
@@ -451,7 +452,7 @@ async fn eth_get_transaction_count(state: &RpcState, params: Option<Value>) -> R
451452 . map ( |account| account. nonce )
452453 . unwrap_or ( 0 )
453454 } ;
454-
455+
455456 // Return nonce as hex string
456457 Ok ( json ! ( format!( "0x{:x}" , nonce) ) )
457458}
@@ -460,7 +461,7 @@ async fn eth_get_transaction_count(state: &RpcState, params: Option<Value>) -> R
460461const DEFAULT_GAS_PRICE : u64 = 1_000_000_000 ;
461462
462463/// Get current gas price
463- ///
464+ ///
464465/// Returns the current gas price. In production, this should be
465466/// dynamically calculated based on network congestion and mempool state.
466467async fn eth_gas_price ( _state : & RpcState ) -> Result < Value , JsonRpcError > {
@@ -565,36 +566,36 @@ async fn eth_send_raw_transaction(state: &RpcState, params: Option<Value>) -> Re
565566 data : None ,
566567 } ) ;
567568 }
568-
569+
569570 // Validate gas parameters to prevent spam and overflow attacks
570571 // Gas price and limit must be non-zero and within reasonable bounds
571572 const MAX_GAS_PRICE : u64 = 10_000_000_000_000 ; // 10,000 Gwei max
572573 const MAX_GAS_LIMIT : u64 = 30_000_000 ; // 30M gas max (similar to Ethereum block limit)
573-
574+
574575 if tx. gas_price == 0 || tx. gas_limit == 0 {
575576 return Err ( JsonRpcError {
576577 code : -32602 ,
577578 message : "Transactions from new accounts require non-zero gas price and limit to prevent DoS attacks" . to_string ( ) ,
578579 data : None ,
579580 } ) ;
580581 }
581-
582+
582583 if tx. gas_price > MAX_GAS_PRICE {
583584 return Err ( JsonRpcError {
584585 code : -32602 ,
585586 message : format ! ( "Gas price {} exceeds maximum allowed {}" , tx. gas_price, MAX_GAS_PRICE ) ,
586587 data : None ,
587588 } ) ;
588589 }
589-
590+
590591 if tx. gas_limit > MAX_GAS_LIMIT {
591592 return Err ( JsonRpcError {
592593 code : -32602 ,
593594 message : format ! ( "Gas limit {} exceeds maximum allowed {}" , tx. gas_limit, MAX_GAS_LIMIT ) ,
594595 data : None ,
595596 } ) ;
596597 }
597-
598+
598599 tracing:: debug!(
599600 from = %hex:: encode( tx. from. as_bytes( ) ) ,
600601 "Allowing transaction from new account with nonce 0"
0 commit comments