diff --git a/wallet/src/actors/app/handlers/generate_address.rs b/wallet/src/actors/app/handlers/generate_address.rs index 2c2d5d2f0..8fb266c99 100644 --- a/wallet/src/actors/app/handlers/generate_address.rs +++ b/wallet/src/actors/app/handlers/generate_address.rs @@ -8,6 +8,7 @@ use crate::{model, types}; pub struct GenerateAddressRequest { session_id: types::SessionId, wallet_id: String, + external: Option, label: Option, } @@ -26,7 +27,12 @@ impl Handler for app::App { fn handle(&mut self, msg: GenerateAddressRequest, _ctx: &mut Self::Context) -> Self::Result { let f = self - .generate_address(msg.session_id, msg.wallet_id, msg.label) + .generate_address( + msg.session_id, + msg.wallet_id, + msg.external.unwrap_or(true), + msg.label, + ) .map( |model::Address { address, path, .. }, _, _| GenerateAddressResponse { address, diff --git a/wallet/src/actors/app/methods.rs b/wallet/src/actors/app/methods.rs index 968e55fcb..c804b2503 100644 --- a/wallet/src/actors/app/methods.rs +++ b/wallet/src/actors/app/methods.rs @@ -93,6 +93,7 @@ impl App { &mut self, session_id: types::SessionId, wallet_id: String, + external: bool, label: Option, ) -> ResponseActFuture { let f = fut::result( @@ -102,7 +103,7 @@ impl App { .and_then(move |wallet, slf: &mut Self, _| { slf.params .worker - .send(worker::GenAddress(wallet, label)) + .send(worker::GenAddress(wallet, external, label)) .flatten() .map_err(From::from) .into_actor(slf) diff --git a/wallet/src/actors/worker/handlers/gen_address.rs b/wallet/src/actors/worker/handlers/gen_address.rs index 331e3becb..6c9380c65 100644 --- a/wallet/src/actors/worker/handlers/gen_address.rs +++ b/wallet/src/actors/worker/handlers/gen_address.rs @@ -3,7 +3,7 @@ use actix::prelude::*; use crate::actors::worker; use crate::{model, types}; -pub struct GenAddress(pub types::SessionWallet, pub Option); +pub struct GenAddress(pub types::SessionWallet, pub bool, pub Option); impl Message for GenAddress { type Result = worker::Result; @@ -14,10 +14,10 @@ impl Handler for worker::Worker { fn handle( &mut self, - GenAddress(wallet, label): GenAddress, + GenAddress(wallet, external, label): GenAddress, _ctx: &mut Self::Context, ) -> Self::Result { - self.gen_address(&wallet, label) + self.gen_address(&wallet, external, label) .map(|address| (*address).clone()) } } diff --git a/wallet/src/actors/worker/methods.rs b/wallet/src/actors/worker/methods.rs index 4857d45aa..43d6150f0 100644 --- a/wallet/src/actors/worker/methods.rs +++ b/wallet/src/actors/worker/methods.rs @@ -183,9 +183,14 @@ impl Worker { pub fn gen_address( &mut self, wallet: &types::Wallet, + external: bool, label: Option, ) -> Result> { - let address = wallet.gen_external_address(label)?; + let address = if external { + wallet.gen_external_address(label)? + } else { + wallet.gen_internal_address(label)? + }; Ok(address) } diff --git a/wallet/src/repository/wallet/mod.rs b/wallet/src/repository/wallet/mod.rs index 44b2c7109..9a493a445 100644 --- a/wallet/src/repository/wallet/mod.rs +++ b/wallet/src/repository/wallet/mod.rs @@ -287,7 +287,6 @@ where } /// Generate an address in the internal keychain (WIP-0001). - #[cfg(test)] pub fn gen_internal_address(&self, label: Option) -> Result> { let mut state = self.state.write()?;