@@ -70,6 +70,14 @@ impl AccountOwner {
7070 }
7171}
7272
73+ #[ cfg( with_revm) ]
74+ impl From < Address > for AccountOwner {
75+ fn from ( address : Address ) -> Self {
76+ let address = address. into_array ( ) ;
77+ AccountOwner :: Address20 ( address)
78+ }
79+ }
80+
7381#[ cfg( with_testing) ]
7482impl From < CryptoHash > for AccountOwner {
7583 fn from ( address : CryptoHash ) -> Self {
@@ -407,7 +415,12 @@ impl GenericApplicationId {
407415
408416impl < A > From < ApplicationId < A > > for AccountOwner {
409417 fn from ( app_id : ApplicationId < A > ) -> Self {
410- AccountOwner :: Address32 ( app_id. application_description_hash )
418+ if app_id. is_evm ( ) {
419+ let hash_bytes = app_id. application_description_hash . as_bytes ( ) ;
420+ AccountOwner :: Address20 ( hash_bytes[ ..20 ] . try_into ( ) . unwrap ( ) )
421+ } else {
422+ AccountOwner :: Address32 ( app_id. application_description_hash )
423+ }
411424 }
412425}
413426
@@ -951,6 +964,14 @@ impl<A> ApplicationId<A> {
951964 }
952965}
953966
967+ impl < A > ApplicationId < A > {
968+ /// Returns whether the `ApplicationId` is the one of an EVM application.
969+ pub fn is_evm ( & self ) -> bool {
970+ let bytes = self . application_description_hash . as_bytes ( ) ;
971+ bytes. 0 [ 20 ..] == [ 0 ; 12 ]
972+ }
973+ }
974+
954975#[ cfg( with_revm) ]
955976impl < A > ApplicationId < A > {
956977 /// Converts the `ApplicationId` into an Ethereum Address.
@@ -964,18 +985,6 @@ impl<A> ApplicationId<A> {
964985 pub fn bytes32 ( & self ) -> B256 {
965986 * self . application_description_hash . as_bytes ( )
966987 }
967-
968- /// Returns whether the `ApplicationId` is the one of an EVM application.
969- pub fn is_evm ( & self ) -> bool {
970- let bytes = self . application_description_hash . as_bytes ( ) ;
971- let bytes = bytes. 0 . as_ref ( ) ;
972- for byte in & bytes[ 20 ..] {
973- if byte != & 0 {
974- return false ;
975- }
976- }
977- true
978- }
979988}
980989
981990#[ derive( Serialize , Deserialize ) ]
0 commit comments