@@ -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 {
@@ -372,7 +380,12 @@ impl GenericApplicationId {
372380
373381impl < A > From < ApplicationId < A > > for AccountOwner {
374382 fn from ( app_id : ApplicationId < A > ) -> Self {
375- AccountOwner :: Address32 ( app_id. application_description_hash )
383+ if app_id. is_evm ( ) {
384+ let hash_bytes = app_id. application_description_hash . as_bytes ( ) ;
385+ AccountOwner :: Address20 ( hash_bytes[ ..20 ] . try_into ( ) . unwrap ( ) )
386+ } else {
387+ AccountOwner :: Address32 ( app_id. application_description_hash )
388+ }
376389 }
377390}
378391
@@ -916,6 +929,14 @@ impl<A> ApplicationId<A> {
916929 }
917930}
918931
932+ impl < A > ApplicationId < A > {
933+ /// Returns whether the `ApplicationId` is the one of an EVM application.
934+ pub fn is_evm ( & self ) -> bool {
935+ let bytes = self . application_description_hash . as_bytes ( ) ;
936+ bytes. 0 [ 20 ..] == [ 0 ; 12 ]
937+ }
938+ }
939+
919940#[ cfg( with_revm) ]
920941impl < A > ApplicationId < A > {
921942 /// Converts the `ApplicationId` into an Ethereum Address.
@@ -929,18 +950,6 @@ impl<A> ApplicationId<A> {
929950 pub fn bytes32 ( & self ) -> B256 {
930951 * self . application_description_hash . as_bytes ( )
931952 }
932-
933- /// Returns whether the `ApplicationId` is the one of an EVM application.
934- pub fn is_evm ( & self ) -> bool {
935- let bytes = self . application_description_hash . as_bytes ( ) ;
936- let bytes = bytes. 0 . as_ref ( ) ;
937- for byte in & bytes[ 20 ..] {
938- if byte != & 0 {
939- return false ;
940- }
941- }
942- true
943- }
944953}
945954
946955#[ derive( Serialize , Deserialize ) ]
0 commit comments