From 640328bffb5a2fe90fa9e433bf252ecb13743160 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 9 Nov 2023 14:28:29 +0100 Subject: [PATCH] Allow ImplicitAccountCreationAddress unlocking (#1597) * Allow ImplicitAccountCreationAddress unlocking * Forward the inner unlock * Nit * Update sdk/src/types/block/address/mod.rs Co-authored-by: /alex/ * Add getter * Remove clone --------- Co-authored-by: /alex/ Co-authored-by: DaughterOfMars --- sdk/src/types/block/address/implicit_account_creation.rs | 5 +++++ sdk/src/types/block/address/mod.rs | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sdk/src/types/block/address/implicit_account_creation.rs b/sdk/src/types/block/address/implicit_account_creation.rs index ecb900e7ab..2d27681af5 100644 --- a/sdk/src/types/block/address/implicit_account_creation.rs +++ b/sdk/src/types/block/address/implicit_account_creation.rs @@ -24,6 +24,11 @@ impl ImplicitAccountCreationAddress { pub fn new(address: [u8; Self::LENGTH]) -> Self { Self(Ed25519Address::new(address)) } + + /// Returns the inner [`Ed25519Address`] of the [`ImplicitAccountCreationAddress`]. + pub fn ed25519_address(&self) -> &Ed25519Address { + &self.0 + } } impl core::fmt::Debug for ImplicitAccountCreationAddress { diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index 626eeb43ca..96f2bda0ca 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -134,7 +134,7 @@ impl Address { context.unlocked_addresses.insert(self.clone()); } - (Self::Ed25519(_ed25519_address), Unlock::Reference(_unlock)) => { + (Self::Ed25519(_), Unlock::Reference(_)) => { // TODO actually check that it was unlocked by the same signature. if !context.unlocked_addresses.contains(self) { return Err(TransactionFailureReason::InvalidInputUnlock); @@ -168,6 +168,9 @@ impl Address { } // TODO maybe shouldn't be a semantic error but this function currently returns a TransactionFailureReason. (Self::Anchor(_), _) => return Err(TransactionFailureReason::SemanticValidationFailed), + (Self::ImplicitAccountCreation(address), _) => { + return Self::from(*address.ed25519_address()).unlock(unlock, context); + } _ => return Err(TransactionFailureReason::InvalidInputUnlock), }