@@ -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,14 @@ 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: [ u8 ; 32 ] = app_id. application_description_hash . into ( ) ;
385+ let mut address_20 = [ 0u8 ; 20 ] ;
386+ address_20. copy_from_slice ( & hash_bytes[ 0 ..20 ] ) ;
387+ AccountOwner :: Address20 ( address_20)
388+ } else {
389+ AccountOwner :: Address32 ( app_id. application_description_hash )
390+ }
376391 }
377392}
378393
@@ -916,6 +931,14 @@ impl<A> ApplicationId<A> {
916931 }
917932}
918933
934+ impl < A > ApplicationId < A > {
935+ /// Returns whether the `ApplicationId` is the one of an EVM application.
936+ pub fn is_evm ( & self ) -> bool {
937+ let bytes = self . application_description_hash . as_bytes ( ) ;
938+ bytes. 0 [ 20 ..] == [ 0 ; 12 ]
939+ }
940+ }
941+
919942#[ cfg( with_revm) ]
920943impl < A > ApplicationId < A > {
921944 /// Converts the `ApplicationId` into an Ethereum Address.
@@ -929,18 +952,6 @@ impl<A> ApplicationId<A> {
929952 pub fn bytes32 ( & self ) -> B256 {
930953 * self . application_description_hash . as_bytes ( )
931954 }
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- }
944955}
945956
946957#[ derive( Serialize , Deserialize ) ]
0 commit comments