@@ -28,7 +28,6 @@ pub use rusoto_core::{
2828 request:: HttpClient as AwsHttpClient , Client as AwsClient ,
2929} ;
3030pub use rusoto_kms:: KmsClient ;
31- use rustc_hex:: { FromHexIter , ToHex } ;
3231use std:: {
3332 path:: PathBuf ,
3433 str:: FromStr ,
@@ -915,8 +914,7 @@ impl SimpleCast {
915914 /// }
916915 /// ```
917916 pub fn from_utf8 ( s : & str ) -> String {
918- let s: String = s. as_bytes ( ) . to_hex ( ) ;
919- format ! ( "0x{s}" )
917+ hex:: encode_prefixed ( s)
920918 }
921919
922920 /// Converts hex data into text data
@@ -935,13 +933,11 @@ impl SimpleCast {
935933 /// }
936934 /// ```
937935 pub fn to_ascii ( hex : & str ) -> Result < String > {
938- let hex_trimmed = hex. trim_start_matches ( "0x" ) ;
939- let iter = FromHexIter :: new ( hex_trimmed) ;
940- let mut ascii = String :: new ( ) ;
941- for letter in iter. collect :: < Vec < _ > > ( ) {
942- ascii. push ( letter? as char ) ;
936+ let bytes = hex:: decode ( hex) ?;
937+ if !bytes. iter ( ) . all ( u8:: is_ascii) {
938+ return Err ( eyre:: eyre!( "Invalid ASCII bytes" ) )
943939 }
944- Ok ( ascii )
940+ Ok ( String :: from_utf8 ( bytes ) . unwrap ( ) )
945941 }
946942
947943 /// Converts fixed point number into specified number of decimals
@@ -1457,7 +1453,7 @@ impl SimpleCast {
14571453 }
14581454 } ;
14591455 let calldata = match encode_args ( & func, args) {
1460- Ok ( res) => res . to_hex :: < String > ( ) ,
1456+ Ok ( res) => hex :: encode ( res ) ,
14611457 Err ( e) => eyre:: bail!( "Could not ABI encode the function and arguments. Did you pass in the right types?\n Error\n {}" , e) ,
14621458 } ;
14631459 let encoded = & calldata[ 8 ..] ;
@@ -1482,7 +1478,7 @@ impl SimpleCast {
14821478 pub fn calldata_encode ( sig : impl AsRef < str > , args : & [ impl AsRef < str > ] ) -> Result < String > {
14831479 let func = HumanReadableParser :: parse_function ( sig. as_ref ( ) ) ?;
14841480 let calldata = encode_args ( & func, args) ?;
1485- Ok ( format ! ( "0x{}" , calldata . to_hex :: < String > ( ) ) )
1481+ Ok ( hex :: encode_prefixed ( calldata ) )
14861482 }
14871483
14881484 /// Generates an interface in solidity from either a local file ABI or a verified contract on
@@ -1609,8 +1605,7 @@ impl SimpleCast {
16091605 }
16101606 }
16111607
1612- let namehash: String = node. to_hex ( ) ;
1613- Ok ( format ! ( "0x{namehash}" ) )
1608+ Ok ( hex:: encode_prefixed ( node) )
16141609 }
16151610
16161611 /// Keccak-256 hashes arbitrary data
0 commit comments