@@ -41,9 +41,9 @@ use crate::{
4141 AccountId ,
4242 BoxGrpcFuture ,
4343 Error ,
44+ EvmAddress ,
4445 Hbar ,
4546 Key ,
46- PublicKey ,
4747 Transaction ,
4848 ValidateChecksums ,
4949} ;
@@ -84,11 +84,9 @@ pub struct AccountCreateTransactionData {
8484 /// Defaults to `0`. Allows up to a maximum value of `1000`.
8585 max_automatic_token_associations : u16 ,
8686
87- /// A key to be used as the account's alias.
88- alias : Option < PublicKey > ,
89-
90- /// A 20-byte EVM address to be used as the account's evm address.
91- evm_address : Option < [ u8 ; 20 ] > ,
87+ // notably *not* a PublicKey.
88+ /// A 20-byte EVM address to be used as the account's alias.
89+ alias : Option < EvmAddress > ,
9290
9391 /// ID of the account or node to which this account is staking, if any.
9492 staked_id : Option < StakedId > ,
@@ -108,7 +106,6 @@ impl Default for AccountCreateTransactionData {
108106 account_memo : String :: new ( ) ,
109107 max_automatic_token_associations : 0 ,
110108 alias : None ,
111- evm_address : None ,
112109 staked_id : None ,
113110 decline_staking_reward : false ,
114111 }
@@ -214,45 +211,23 @@ impl AccountCreateTransaction {
214211 self
215212 }
216213
217- /// Returns the public key to be used as the account's alias.
214+ /// Returns the evm address the account will be created with as an alias.
218215 ///
219216 /// # Network Support
220217 /// Please note that this not currently supported on mainnet.
221218 #[ must_use]
222- pub fn get_alias ( & self ) -> Option < & PublicKey > {
223- self . data ( ) . alias . as_ref ( )
219+ pub fn get_alias ( & self ) -> Option < EvmAddress > {
220+ self . data ( ) . alias
224221 }
225222
226- /// The bytes to be used as the account's alias.
227- ///
228- /// A given alias can map to at most one account on the network at a time. This uniqueness will be enforced
229- /// relative to aliases currently on the network at alias assignment.
223+ /// Sets the evm address the account will be created with as an alias.
230224 ///
231- /// If a transaction creates an account using an alias, any further crypto transfers to that alias will
232- /// simply be deposited in that account, without creating anything, and with no creation fee being charged.
233- ///
234- /// # Network Support
235- /// Please note that this not currently supported on mainnet.
236- pub fn alias ( & mut self , key : PublicKey ) -> & mut Self {
237- self . data_mut ( ) . alias = Some ( key) ;
238- self
239- }
240-
241- /// Returns the evm address the account will be created with.
242- ///
243- /// # Network Support
244- /// Please note that this not currently supported on mainnet.
245- #[ must_use]
246- pub fn get_evm_address ( & self ) -> Option < [ u8 ; 20 ] > {
247- self . data ( ) . evm_address
248- }
249-
250225 /// The last 20 bytes of the keccak-256 hash of a `ECDSA_SECP256K1` primitive key.
251226 ///
252227 /// # Network Support
253228 /// Please note that this not currently supported on mainnet.
254- pub fn evm_address ( & mut self , evm_address : [ u8 ; 20 ] ) -> & mut Self {
255- self . data_mut ( ) . evm_address = Some ( evm_address ) ;
229+ pub fn alias ( & mut self , alias : EvmAddress ) -> & mut Self {
230+ self . data_mut ( ) . alias = Some ( alias ) ;
256231 self
257232 }
258233
@@ -342,12 +317,7 @@ impl From<AccountCreateTransactionData> for AnyTransactionData {
342317
343318impl FromProtobuf < services:: CryptoCreateTransactionBody > for AccountCreateTransactionData {
344319 fn from_protobuf ( pb : services:: CryptoCreateTransactionBody ) -> crate :: Result < Self > {
345- let evm_address = pb. alias . as_slice ( ) . try_into ( ) . ok ( ) ;
346-
347- let alias = ( pb. alias . len ( ) != 20 )
348- . then ( || PublicKey :: from_alias_bytes ( & pb. alias ) . transpose ( ) )
349- . flatten ( )
350- . transpose ( ) ?;
320+ let alias = ( !pb. alias . is_empty ( ) ) . then ( || EvmAddress :: try_from ( pb. alias ) ) . transpose ( ) ?;
351321
352322 Ok ( Self {
353323 key : Option :: from_protobuf ( pb. key ) ?,
@@ -358,7 +328,6 @@ impl FromProtobuf<services::CryptoCreateTransactionBody> for AccountCreateTransa
358328 account_memo : pb. memo ,
359329 max_automatic_token_associations : pb. max_automatic_token_associations as u16 ,
360330 alias,
361- evm_address,
362331 staked_id : Option :: from_protobuf ( pb. staked_id ) ?,
363332 decline_staking_reward : pb. decline_reward ,
364333 } )
@@ -396,7 +365,7 @@ impl ToProtobuf for AccountCreateTransactionData {
396365 new_realm_admin_key : None ,
397366 memo : self . account_memo . clone ( ) ,
398367 max_automatic_token_associations : i32:: from ( self . max_automatic_token_associations ) ,
399- alias : self . alias . map_or ( vec ! [ ] , |key| key . to_bytes_raw ( ) ) ,
368+ alias : self . alias . map_or ( vec ! [ ] , |it| it . to_bytes ( ) . to_vec ( ) ) ,
400369 decline_reward : self . decline_staking_reward ,
401370 staked_id,
402371 }
0 commit comments