From 4b862a779387901c57abd5f5f7141dd9a12fa7b3 Mon Sep 17 00:00:00 2001 From: 1bananagirl <168954040+1bananagirl@users.noreply.github.com> Date: Fri, 20 Dec 2024 23:09:02 +0100 Subject: [PATCH] Added new address kind. --- wallet/core/src/account/mod.rs | 13 +++++++++++++ wallet/core/src/api/message.rs | 1 + wallet/core/src/derivation.rs | 5 +++++ wallet/core/src/wallet/api.rs | 1 + 4 files changed, 20 insertions(+) diff --git a/wallet/core/src/account/mod.rs b/wallet/core/src/account/mod.rs index 2b022beb1..88f320eec 100644 --- a/wallet/core/src/account/mod.rs +++ b/wallet/core/src/account/mod.rs @@ -728,6 +728,19 @@ pub trait DerivationCapableAccount: Account { Ok(address) } + async fn commit_reveal_address(self: Arc) -> Result
{ + let address = self.derivation().receive_address_manager().commit_reveal_address()?; + self.utxo_context().register_addresses(&[address.clone()]).await?; + + let metadata = self.metadata()?.expect("derivation accounts must provide metadata"); + let store = self.wallet().store().as_account_store()?; + store.update_metadata(vec![metadata]).await?; + + self.wallet().notify(Events::AccountUpdate { account_descriptor: self.descriptor()? }).await?; + + Ok(address) + } + fn cosigner_index(&self) -> u32 { 0 } diff --git a/wallet/core/src/api/message.rs b/wallet/core/src/api/message.rs index 0fe5ce951..ab971db7b 100644 --- a/wallet/core/src/api/message.rs +++ b/wallet/core/src/api/message.rs @@ -464,6 +464,7 @@ pub struct AccountsGetResponse { pub enum NewAddressKind { Receive, Change, + CommitReveal, } impl FromStr for NewAddressKind { diff --git a/wallet/core/src/derivation.rs b/wallet/core/src/derivation.rs index 2e598334e..9e4fa377b 100644 --- a/wallet/core/src/derivation.rs +++ b/wallet/core/src/derivation.rs @@ -89,6 +89,11 @@ impl AddressManager { self.current_address() } + pub fn commit_reveal_address(&self) -> Result
{ + self.set_index(0)?; + self.current_address() + } + pub fn current_address(&self) -> Result
{ let list = self.pubkey_managers.iter().map(|m| m.current_pubkey()); diff --git a/wallet/core/src/wallet/api.rs b/wallet/core/src/wallet/api.rs index acb5869e0..1a02028a6 100644 --- a/wallet/core/src/wallet/api.rs +++ b/wallet/core/src/wallet/api.rs @@ -383,6 +383,7 @@ impl WalletApi for super::Wallet { let address = match kind { NewAddressKind::Receive => account.as_derivation_capable()?.new_receive_address().await?, NewAddressKind::Change => account.as_derivation_capable()?.new_change_address().await?, + NewAddressKind::CommitReveal => account.as_derivation_capable()?.commit_reveal_address().await?, }; Ok(AccountsCreateNewAddressResponse { address })