From 62f0731c6bac0eade00469eed335150beaf18735 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 8 Nov 2023 11:27:13 +0100 Subject: [PATCH 1/6] Allow ImplicitAccountCreationAddress unlocking --- sdk/src/types/block/address/implicit_account_creation.rs | 2 +- sdk/src/types/block/address/mod.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sdk/src/types/block/address/implicit_account_creation.rs b/sdk/src/types/block/address/implicit_account_creation.rs index ecb900e7ab..c5364bfc74 100644 --- a/sdk/src/types/block/address/implicit_account_creation.rs +++ b/sdk/src/types/block/address/implicit_account_creation.rs @@ -11,7 +11,7 @@ use crate::types::block::address::Ed25519Address; /// [`AccountOutput`](crate::types::block::output::AccountOutput). #[derive(Copy, Clone, Display, Eq, PartialEq, Ord, PartialOrd, Hash, FromStr, AsRef, Deref, From, Packable)] #[as_ref(forward)] -pub struct ImplicitAccountCreationAddress(Ed25519Address); +pub struct ImplicitAccountCreationAddress(pub(crate) Ed25519Address); impl ImplicitAccountCreationAddress { /// The [`Address`](crate::types::block::address::Address) kind of an [`ImplicitAccountCreationAddress`]. diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index 626eeb43ca..33bd710984 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -118,7 +118,11 @@ impl Address { context: &mut SemanticValidationContext<'_>, ) -> Result<(), TransactionFailureReason> { match (self, unlock) { - (Self::Ed25519(ed25519_address), Unlock::Signature(unlock)) => { + ( + Self::Ed25519(ed25519_address) + | Self::ImplicitAccountCreation(ImplicitAccountCreationAddress(ed25519_address)), + Unlock::Signature(unlock), + ) => { if context.unlocked_addresses.contains(self) { return Err(TransactionFailureReason::InvalidInputUnlock); } @@ -134,7 +138,7 @@ impl Address { context.unlocked_addresses.insert(self.clone()); } - (Self::Ed25519(_ed25519_address), Unlock::Reference(_unlock)) => { + (Self::Ed25519(_) | Self::ImplicitAccountCreation(_), Unlock::Reference(_)) => { // TODO actually check that it was unlocked by the same signature. if !context.unlocked_addresses.contains(self) { return Err(TransactionFailureReason::InvalidInputUnlock); From ee6b26f3ca36a7a645dc74fcf6f955b8af161d51 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 8 Nov 2023 11:47:46 +0100 Subject: [PATCH 2/6] Forward the inner unlock --- sdk/src/types/block/address/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index 33bd710984..6864acb3ac 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -118,11 +118,7 @@ impl Address { context: &mut SemanticValidationContext<'_>, ) -> Result<(), TransactionFailureReason> { match (self, unlock) { - ( - Self::Ed25519(ed25519_address) - | Self::ImplicitAccountCreation(ImplicitAccountCreationAddress(ed25519_address)), - Unlock::Signature(unlock), - ) => { + (Self::Ed25519(ed25519_address), Unlock::Signature(unlock)) => { if context.unlocked_addresses.contains(self) { return Err(TransactionFailureReason::InvalidInputUnlock); } @@ -138,7 +134,7 @@ impl Address { context.unlocked_addresses.insert(self.clone()); } - (Self::Ed25519(_) | Self::ImplicitAccountCreation(_), Unlock::Reference(_)) => { + (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); @@ -172,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(ImplicitAccountCreationAddress(ed25519_address)), _) => { + Address::from(ed25519_address.clone()).unlock(unlock, context)? + } _ => return Err(TransactionFailureReason::InvalidInputUnlock), } From f4a6429f6924b7f747fd425d979a358869850a7c Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 8 Nov 2023 11:48:38 +0100 Subject: [PATCH 3/6] Nit --- sdk/src/types/block/address/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index 6864acb3ac..93d0e6673d 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -169,7 +169,7 @@ 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(ImplicitAccountCreationAddress(ed25519_address)), _) => { - Address::from(ed25519_address.clone()).unlock(unlock, context)? + Address::from(ed25519_address.clone()).unlock(unlock, context)?; } _ => return Err(TransactionFailureReason::InvalidInputUnlock), } From 64903c24f358cceff34fb05c4438b1f9dd2018df Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 8 Nov 2023 13:52:39 +0100 Subject: [PATCH 4/6] Update sdk/src/types/block/address/mod.rs Co-authored-by: /alex/ --- sdk/src/types/block/address/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index 93d0e6673d..e076c937fd 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -169,7 +169,7 @@ 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(ImplicitAccountCreationAddress(ed25519_address)), _) => { - Address::from(ed25519_address.clone()).unlock(unlock, context)?; + return Self::from(ed25519_address.clone()).unlock(unlock, context); } _ => return Err(TransactionFailureReason::InvalidInputUnlock), } From 49a2656b5717bf5b62105739292b0dba8d5ef3bf Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 8 Nov 2023 21:46:21 +0100 Subject: [PATCH 5/6] Add getter --- sdk/src/types/block/address/implicit_account_creation.rs | 7 ++++++- sdk/src/types/block/address/mod.rs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sdk/src/types/block/address/implicit_account_creation.rs b/sdk/src/types/block/address/implicit_account_creation.rs index c5364bfc74..2d27681af5 100644 --- a/sdk/src/types/block/address/implicit_account_creation.rs +++ b/sdk/src/types/block/address/implicit_account_creation.rs @@ -11,7 +11,7 @@ use crate::types::block::address::Ed25519Address; /// [`AccountOutput`](crate::types::block::output::AccountOutput). #[derive(Copy, Clone, Display, Eq, PartialEq, Ord, PartialOrd, Hash, FromStr, AsRef, Deref, From, Packable)] #[as_ref(forward)] -pub struct ImplicitAccountCreationAddress(pub(crate) Ed25519Address); +pub struct ImplicitAccountCreationAddress(Ed25519Address); impl ImplicitAccountCreationAddress { /// The [`Address`](crate::types::block::address::Address) kind of an [`ImplicitAccountCreationAddress`]. @@ -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 e076c937fd..99d3fdbe5b 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -168,8 +168,8 @@ 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(ImplicitAccountCreationAddress(ed25519_address)), _) => { - return Self::from(ed25519_address.clone()).unlock(unlock, context); + (Self::ImplicitAccountCreation(address), _) => { + return Self::from(address.ed25519_address().clone()).unlock(unlock, context); } _ => return Err(TransactionFailureReason::InvalidInputUnlock), } From ba0a534e58391bd10fed0aee8b2bad818d2bdbe0 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 9 Nov 2023 09:00:31 +0100 Subject: [PATCH 6/6] Remove clone --- sdk/src/types/block/address/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index 99d3fdbe5b..96f2bda0ca 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -169,7 +169,7 @@ 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().clone()).unlock(unlock, context); + return Self::from(*address.ed25519_address()).unlock(unlock, context); } _ => return Err(TransactionFailureReason::InvalidInputUnlock), }