Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
display contact names (#104)
Browse files Browse the repository at this point in the history
* display contact name with '@' in txs log
* removed all references to std::sync::Arc in favour of common::Arc
  • Loading branch information
ravidio authored Jan 26, 2019
1 parent 3ac1c4b commit e199d64
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 44 deletions.
32 changes: 16 additions & 16 deletions src/broker/grinbox.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::sync::{Arc, Mutex};
use std::thread;
use ws::{connect, Sender, Handler, Handshake, Message, CloseCode, Result as WsResult, ErrorKind as WsErrorKind, Error as WsError};
use ws::util::Token;

use grin_core::libtx::slate::Slate;

use crate::wallet::types::{TxProofErrorKind, TxProof};
use common::{ErrorKind, Result};
use common::{ErrorKind, Result, Arc, Mutex};
use common::crypto::{SecretKey, sign_challenge, Hex, EncryptedMessage};
use contacts::{Address, GrinboxAddress, DEFAULT_GRINBOX_PORT};

Expand Down Expand Up @@ -164,9 +163,10 @@ impl GrinboxBroker {
let cloned_cloned_inner = cloned_inner.clone();
let cloned_connection_meta_data = connection_meta_data.clone();
let result = connect(url.clone(), move |sender| {
if let Ok(mut guard) = cloned_cloned_inner.lock() {
{
let mut guard = cloned_cloned_inner.lock();
*guard = Some(sender.clone());
};
}

let client = GrinboxClient {
sender,
Expand All @@ -179,41 +179,41 @@ impl GrinboxBroker {
client
});

let is_stopped = cloned_inner.lock().unwrap().is_none();
let is_stopped = cloned_inner.lock().is_none();

if is_stopped {
match result {
Err(_) => handler.lock().unwrap().on_close(CloseReason::Abnormal(ErrorKind::GrinboxWebsocketAbnormalTermination.into())),
_ => handler.lock().unwrap().on_close(CloseReason::Normal),
Err(_) => handler.lock().on_close(CloseReason::Abnormal(ErrorKind::GrinboxWebsocketAbnormalTermination.into())),
_ => handler.lock().on_close(CloseReason::Normal),
}
break;
} else {
let mut guard = connection_meta_data.lock().unwrap();
let mut guard = connection_meta_data.lock();
if guard.retries == 0 && guard.connected_at_least_once {
handler.lock().unwrap().on_dropped();
handler.lock().on_dropped();
}
let secs = std::cmp::min(32, 2u64.pow(guard.retries));
let duration = std::time::Duration::from_secs(secs);
std::thread::sleep(duration);
guard.retries += 1;
}
}
let mut guard = cloned_inner.lock().unwrap();
let mut guard = cloned_inner.lock();
*guard = None;
});
Ok(())
}

fn stop(&self) {
let mut guard = self.inner.lock().unwrap();
let mut guard = self.inner.lock();
if let Some(ref sender) = *guard {
sender.close(CloseCode::Normal).is_ok();
}
*guard = None;
}

fn is_running(&self) -> bool {
let guard = self.inner.lock().unwrap();
let guard = self.inner.lock();
guard.is_some()
}
}
Expand Down Expand Up @@ -249,12 +249,12 @@ impl GrinboxClient {

impl Handler for GrinboxClient {
fn on_open(&mut self, _shake: Handshake) -> WsResult<()> {
let mut guard = self.connection_meta_data.lock().unwrap();
let mut guard = self.connection_meta_data.lock();

if guard.connected_at_least_once {
self.handler.lock().unwrap().on_reestablished();
self.handler.lock().on_reestablished();
} else {
self.handler.lock().unwrap().on_open();
self.handler.lock().on_open();
guard.connected_at_least_once = true;
}

Expand Down Expand Up @@ -328,7 +328,7 @@ impl Handler for GrinboxClient {
};

let address = tx_proof.address.clone();
self.handler.lock().unwrap().on_slate(&address, &mut slate, Some(&mut tx_proof));
self.handler.lock().on_slate(&address, &mut slate, Some(&mut tx_proof));
},
ProtocolResponse::Error { kind: _, description: _ } => {
cli_message!("{}", response);
Expand Down
13 changes: 7 additions & 6 deletions src/broker/keybase.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::process::{Command, Stdio};
use std::collections::HashSet;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::borrow::Borrow;
use std::iter::FromIterator;
Expand All @@ -9,7 +8,7 @@ use serde::Serialize;
use serde_json::{json, Value};
use grin_core::libtx::slate::Slate;

use common::{ErrorKind, Result};
use common::{ErrorKind, Result, Arc, Mutex};
use contacts::{Address, KeybaseAddress};
use super::types::{Publisher, Subscriber, SubscriptionHandler, CloseReason};

Expand Down Expand Up @@ -66,13 +65,15 @@ impl Publisher for KeybasePublisher {

impl Subscriber for KeybaseSubscriber {
fn start(&mut self, handler: Box<SubscriptionHandler + Send>) -> Result<()> {
if let Ok(mut guard) = self.stop_signal.lock() {
{
let mut guard = self.stop_signal.lock();
*guard = false;
}

let mut subscribed = false;
let mut dropped = false;
let result: Result<()> = loop {
if *self.stop_signal.lock().unwrap() {
if *self.stop_signal.lock() {
break Ok(())
};
let result = KeybaseBroker::get_unread(HashSet::from_iter(vec![
Expand Down Expand Up @@ -121,12 +122,12 @@ impl Subscriber for KeybaseSubscriber {
}

fn stop(&self) {
let mut guard = self.stop_signal.lock().unwrap();
let mut guard = self.stop_signal.lock();
*guard = true;
}

fn is_running(&self) -> bool {
let guard = self.stop_signal.lock().unwrap();
let guard = self.stop_signal.lock();
!*guard
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ mod error_kind;
pub use self::error_kind::ErrorKind;
pub use self::macros::*;
pub use failure::Error;
pub use std::sync::Arc;
pub use grin_util::Mutex;
pub type Result<T> = std::result::Result<T, Error>;

#[derive(Clone, PartialEq)]
Expand Down
3 changes: 1 addition & 2 deletions src/contacts/backend.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::sync::Arc;
use std::cell::RefCell;
use std::path::Path;
use std::fs::{create_dir_all};
Expand All @@ -8,7 +7,7 @@ use grin_core::ser::{Readable, Writeable, Reader, Writer};
use grin_core::ser::Error as CoreError;

use super::types::{Address, Contact, AddressBookBackend, AddressBookBatch};
use common::Error;
use common::{Error, Arc};

const DB_DIR: &'static str = "contacts";
const CONTACT_PREFIX: u8 = 'X' as u8;
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ extern crate grin_util;
extern crate grin_wallet;
extern crate grin_store;

use std::sync::Arc;
use std::io::{Read, Write};
use std::fs::File;
use std::path::Path;
Expand Down Expand Up @@ -62,7 +61,7 @@ use common::config::Wallet713Config;
use wallet::Wallet;
use cli::Parser;

use crate::wallet::types::{TxProof, Mutex};
use crate::wallet::types::{TxProof, Arc, Mutex};

use contacts::{Address, AddressType, GrinboxAddress, Contact, AddressBook, Backend};

Expand Down
5 changes: 1 addition & 4 deletions src/wallet/api/api.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use std::collections::HashSet;
use std::marker::PhantomData;
use std::sync::Arc;
use uuid::Uuid;

use grin_core::ser;
use grin_util::Mutex;
use grin_util::secp::{ContextFlag, Secp256k1};
use grin_util::secp::key::PublicKey;
use grin_util::secp::pedersen;

use crate::wallet::types::TxProof;
use crate::contacts::GrinboxAddress;

use super::types::{Transaction, Slate, Keychain, Identifier, NodeClient, TxWrapper, WalletBackend, AcctPathMapping, OutputData, TxLogEntry, TxLogEntryType, WalletInfo, ContextType, Error, ErrorKind};
use super::types::{TxProof, Arc, Mutex, Transaction, Slate, Keychain, Identifier, NodeClient, TxWrapper, WalletBackend, AcctPathMapping, OutputData, TxLogEntry, TxLogEntryType, WalletInfo, ContextType, Error, ErrorKind};
use super::tx;
use super::keys;
use super::updater;
Expand Down
4 changes: 1 addition & 3 deletions src/wallet/api/controller.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::sync::Arc;

use super::types::{WalletBackend, NodeClient, Error, Keychain, Mutex};
use super::types::{WalletBackend, NodeClient, Error, Keychain, Arc, Mutex};
use super::api::{Wallet713ForeignAPI, Wallet713OwnerAPI};

pub fn owner_single_use<F, T: ?Sized, C, K>(wallet: Arc<Mutex<T>>, f: F) -> Result<(), Error>
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/api/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub fn txs(
let mut address_book = address_book.lock();
let contact = address_book.get_contact_by_address(a);
if let Ok(contact) = contact {
contact.get_name().to_string()
format!("@{}", contact.get_name())
} else {
a.clone()
}
Expand Down
5 changes: 1 addition & 4 deletions src/wallet/backend/lmdb_backend.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::cell::RefCell;
use std::sync::Arc;
use std::{fs, path};
use std::fs::File;
use std::io::{Read, Write};
Expand All @@ -14,9 +13,7 @@ use grin_core::{global, ser};
use grin_store::{self, option_to_not_found, to_key, to_key_u64};
use grin_wallet::WalletConfig;

use crate::wallet::types::TxProof;

use super::types::{ErrorKind, Result, WalletSeed, WalletBackend, WalletBackendBatch, ChildNumber, Transaction, OutputData, TxLogEntry, AcctPathMapping, Context, ExtKeychain, Identifier, Keychain, NodeClient};
use super::types::{TxProof, Arc, ErrorKind, Result, WalletSeed, WalletBackend, WalletBackendBatch, ChildNumber, Transaction, OutputData, TxLogEntry, AcctPathMapping, Context, ExtKeychain, Identifier, Keychain, NodeClient};
use super::api::restore;

pub const DB_DIR: &'static str = "db";
Expand Down
5 changes: 1 addition & 4 deletions src/wallet/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ mod wallet_backend_batch;
mod wallet_inst;
mod context_type;

pub use std::sync::Arc;
pub use failure::Error;
pub use grin_util::Mutex;
pub use grin_util::secp::key::{PublicKey, SecretKey};
pub use grin_core::core::hash::Hash;
pub use grin_core::core::{Output, TxKernel, Transaction};
Expand All @@ -25,7 +22,7 @@ pub use grin_keychain::{Identifier, Keychain, ChildNumber, ExtKeychain};
pub use grin_wallet::{WalletSeed, EncryptedWalletSeed};
pub use grin_wallet::libwallet::types::{NodeClient, TxWrapper};

pub use common::{ErrorKind, Result};
pub use common::{Error, ErrorKind, Result, Arc, Mutex};

pub use self::output_data::OutputData;
pub use self::output_status::OutputStatus;
Expand Down
3 changes: 1 addition & 2 deletions src/wallet/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::sync::Arc;
use grin_wallet::{HTTPNodeClient, NodeClient, WalletConfig};

use common::{ErrorKind, Result};
use common::config::Wallet713Config;

use super::types::{SecretKey, Slate, ExtKeychain, Mutex, WalletBackend, WalletInst, WalletSeed};
use super::types::{Arc, SecretKey, Slate, ExtKeychain, Mutex, WalletBackend, WalletInst, WalletSeed};
use super::backend::Backend;
use super::api::{controller, display};

Expand Down

0 comments on commit e199d64

Please sign in to comment.