diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index 369f474d7..b6e932d28 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -26,7 +26,7 @@ use util::Mutex; use v1::traits::EthFilter; use v1::types::{BlockNumber, Index, Filter, Log, H256 as RpcH256, U256 as RpcU256}; use v1::helpers::{PollFilter, PollManager, limit_logs}; -use v1::helpers::params::{expect_no_params}; +use v1::helpers::params::expect_no_params; use v1::impls::eth::pending_logs; /// Eth filter rpc implementation. diff --git a/rpc/src/v1/types/uint.rs b/rpc/src/v1/types/uint.rs index bcd874a18..9be7b1170 100644 --- a/rpc/src/v1/types/uint.rs +++ b/rpc/src/v1/types/uint.rs @@ -77,6 +77,10 @@ macro_rules! impl_uint { return Err(serde::Error::custom("Invalid length.")); } + if &value[0..2] != "0x" { + return Err(serde::Error::custom("Use hex encoded numbers with 0x prefix.")) + } + $other::from_str(&value[2..]).map($name).map_err(|_| serde::Error::custom("Invalid hex value.")) } @@ -100,6 +104,8 @@ mod tests { use super::U256; use serde_json; + type Res = Result; + #[test] fn should_serialize_u256() { let serialized1 = serde_json::to_string(&U256(0.into())).unwrap(); @@ -113,6 +119,21 @@ mod tests { assert_eq!(serialized4, r#""0x100""#); } + #[test] + fn should_fail_to_deserialize_decimals() { + let deserialized1: Res = serde_json::from_str(r#""""#); + let deserialized2: Res = serde_json::from_str(r#""0""#); + let deserialized3: Res = serde_json::from_str(r#""10""#); + let deserialized4: Res = serde_json::from_str(r#""1000000""#); + let deserialized5: Res = serde_json::from_str(r#""1000000000000000000""#); + + assert!(deserialized1.is_err()); + assert!(deserialized2.is_err()); + assert!(deserialized3.is_err()); + assert!(deserialized4.is_err()); + assert!(deserialized5.is_err()); + } + #[test] fn should_deserialize_u256() { let deserialized1: U256 = serde_json::from_str(r#""0x""#).unwrap();