Skip to content

Commit

Permalink
Allow ImplicitAccountCreationAddress unlocking (#1597)
Browse files Browse the repository at this point in the history
* Allow ImplicitAccountCreationAddress unlocking

* Forward the inner unlock

* Nit

* Update sdk/src/types/block/address/mod.rs

Co-authored-by: /alex/ <[email protected]>

* Add getter

* Remove clone

---------

Co-authored-by: /alex/ <[email protected]>
Co-authored-by: DaughterOfMars <[email protected]>
  • Loading branch information
3 people authored Nov 9, 2023
1 parent edefa1d commit 640328b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions sdk/src/types/block/address/implicit_account_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion sdk/src/types/block/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
}

Expand Down

0 comments on commit 640328b

Please sign in to comment.