Skip to content

Commit

Permalink
Added new address kind.
Browse files Browse the repository at this point in the history
  • Loading branch information
1bananagirl committed Dec 20, 2024
1 parent 03100ae commit 4b862a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions wallet/core/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,19 @@ pub trait DerivationCapableAccount: Account {
Ok(address)
}

async fn commit_reveal_address(self: Arc<Self>) -> Result<Address> {
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
}
Expand Down
1 change: 1 addition & 0 deletions wallet/core/src/api/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ pub struct AccountsGetResponse {
pub enum NewAddressKind {
Receive,
Change,
CommitReveal,
}

impl FromStr for NewAddressKind {
Expand Down
5 changes: 5 additions & 0 deletions wallet/core/src/derivation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ impl AddressManager {
self.current_address()
}

pub fn commit_reveal_address(&self) -> Result<Address> {
self.set_index(0)?;
self.current_address()
}

pub fn current_address(&self) -> Result<Address> {
let list = self.pubkey_managers.iter().map(|m| m.current_pubkey());

Expand Down
1 change: 1 addition & 0 deletions wallet/core/src/wallet/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 4b862a7

Please sign in to comment.