Skip to content

Commit

Permalink
feat(wallet): add generate internal address to API
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocao committed Oct 5, 2020
1 parent 81ae268 commit 2de44f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
8 changes: 7 additions & 1 deletion wallet/src/actors/app/handlers/generate_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{model, types};
pub struct GenerateAddressRequest {
session_id: types::SessionId,
wallet_id: String,
external: Option<bool>,
label: Option<String>,
}

Expand All @@ -26,7 +27,12 @@ impl Handler<GenerateAddressRequest> 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,
Expand Down
3 changes: 2 additions & 1 deletion wallet/src/actors/app/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl App {
&mut self,
session_id: types::SessionId,
wallet_id: String,
external: bool,
label: Option<String>,
) -> ResponseActFuture<model::Address> {
let f = fut::result(
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions wallet/src/actors/worker/handlers/gen_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use actix::prelude::*;
use crate::actors::worker;
use crate::{model, types};

pub struct GenAddress(pub types::SessionWallet, pub Option<String>);
pub struct GenAddress(pub types::SessionWallet, pub bool, pub Option<String>);

impl Message for GenAddress {
type Result = worker::Result<model::Address>;
Expand All @@ -14,10 +14,10 @@ impl Handler<GenAddress> 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())
}
}
7 changes: 6 additions & 1 deletion wallet/src/actors/worker/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,14 @@ impl Worker {
pub fn gen_address(
&mut self,
wallet: &types::Wallet,
external: bool,
label: Option<String>,
) -> Result<Arc<model::Address>> {
let address = wallet.gen_external_address(label)?;
let address = if external {
wallet.gen_external_address(label)?
} else {
wallet.gen_internal_address(label)?
};

Ok(address)
}
Expand Down
1 change: 0 additions & 1 deletion wallet/src/repository/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ where
}

/// Generate an address in the internal keychain (WIP-0001).
#[cfg(test)]
pub fn gen_internal_address(&self, label: Option<String>) -> Result<Arc<model::Address>> {
let mut state = self.state.write()?;

Expand Down

0 comments on commit 2de44f8

Please sign in to comment.