Skip to content

Commit

Permalink
WIP on sw_tari_address
Browse files Browse the repository at this point in the history
working code
  • Loading branch information
SWvheerden committed May 23, 2024
1 parent 64c130e commit 97c0841
Show file tree
Hide file tree
Showing 41 changed files with 1,127 additions and 348 deletions.
8 changes: 4 additions & 4 deletions applications/minotari_console_wallet/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
TransactionWrapper::Completed(completed) => TransactionEvent {
event,
tx_id: completed.tx_id.to_string(),
source_address: completed.source_address.to_bytes().to_vec(),
dest_address: completed.destination_address.to_bytes().to_vec(),
source_address: completed.source_address.to_vec(),
dest_address: completed.destination_address.to_vec(),
status: completed.status.to_string(),
direction: completed.direction.to_string(),
amount: completed.amount.as_u64(),
Expand All @@ -34,7 +34,7 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
event,
tx_id: outbound.tx_id.to_string(),
source_address: vec![],
dest_address: outbound.destination_address.to_bytes().to_vec(),
dest_address: outbound.destination_address.to_vec(),
status: outbound.status.to_string(),
direction: "outbound".to_string(),
amount: outbound.amount.as_u64(),
Expand All @@ -43,7 +43,7 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
TransactionWrapper::Inbound(inbound) => TransactionEvent {
event,
tx_id: inbound.tx_id.to_string(),
source_address: inbound.source_address.to_bytes().to_vec(),
source_address: inbound.source_address.to_vec(),
dest_address: vec![],
status: inbound.status.to_string(),
direction: "inbound".to_string(),
Expand Down
35 changes: 19 additions & 16 deletions applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ impl wallet_server::Wallet for WalletGrpcServer {
}

async fn get_address(&self, _: Request<tari_rpc::Empty>) -> Result<Response<GetAddressResponse>, Status> {
let network = self.wallet.network.as_network();
let pk = self.wallet.comms.node_identity().public_key().clone();
let address = TariAddress::new(pk, network);
let address = self
.wallet
.get_wallet_address()
.await
.map_err(|e| Status::internal(format!("{:?}", e)))?;
Ok(Response::new(GetAddressResponse {
address: address.to_bytes().to_vec(),
address: address.to_vec(),
}))
}

Expand Down Expand Up @@ -650,10 +652,11 @@ impl wallet_server::Wallet for WalletGrpcServer {
.await
.map(|tx| tx.into_iter())
.map_err(|err| Status::unknown(err.to_string()))?;

let wallet_pk = self.wallet.comms.node_identity_ref().public_key();
let wallet_network = self.wallet.network.as_network();
let wallet_address = TariAddress::new(wallet_pk.clone(), wallet_network);
let wallet_address = self
.wallet
.get_wallet_address()
.await
.map_err(|e| Status::internal(format!("{:?}", e)))?;
let transactions = transactions
.map(|(tx_id, tx)| match tx {
Some(tx) => convert_wallet_transaction_into_transaction_info(tx, &wallet_address),
Expand Down Expand Up @@ -755,8 +758,8 @@ impl wallet_server::Wallet for WalletGrpcServer {
let response = GetCompletedTransactionsResponse {
transaction: Some(TransactionInfo {
tx_id: txn.tx_id.into(),
source_address: txn.source_address.to_bytes().to_vec(),
dest_address: txn.destination_address.to_bytes().to_vec(),
source_address: txn.source_address.to_vec(),
dest_address: txn.destination_address.to_vec(),
status: TransactionStatus::from(txn.status.clone()) as i32,
amount: txn.amount.into(),
is_cancelled: txn.cancelled.is_some(),
Expand Down Expand Up @@ -1097,8 +1100,8 @@ fn convert_wallet_transaction_into_transaction_info(
match tx {
PendingInbound(tx) => TransactionInfo {
tx_id: tx.tx_id.into(),
source_address: tx.source_address.to_bytes().to_vec(),
dest_address: wallet_address.to_bytes().to_vec(),
source_address: tx.source_address.to_vec(),
dest_address: wallet_address.to_vec(),
status: TransactionStatus::from(tx.status) as i32,
amount: tx.amount.into(),
is_cancelled: tx.cancelled,
Expand All @@ -1110,8 +1113,8 @@ fn convert_wallet_transaction_into_transaction_info(
},
PendingOutbound(tx) => TransactionInfo {
tx_id: tx.tx_id.into(),
source_address: wallet_address.to_bytes().to_vec(),
dest_address: tx.destination_address.to_bytes().to_vec(),
source_address: wallet_address.to_vec(),
dest_address: tx.destination_address.to_vec(),
status: TransactionStatus::from(tx.status) as i32,
amount: tx.amount.into(),
is_cancelled: tx.cancelled,
Expand All @@ -1123,8 +1126,8 @@ fn convert_wallet_transaction_into_transaction_info(
},
Completed(tx) => TransactionInfo {
tx_id: tx.tx_id.into(),
source_address: tx.source_address.to_bytes().to_vec(),
dest_address: tx.destination_address.to_bytes().to_vec(),
source_address: tx.source_address.to_vec(),
dest_address: tx.destination_address.to_vec(),
status: TransactionStatus::from(tx.status) as i32,
amount: tx.amount.into(),
is_cancelled: tx.cancelled.is_some(),
Expand Down
25 changes: 18 additions & 7 deletions applications/minotari_console_wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,32 @@ pub fn run_wallet_with_cli(
let handle = runtime.handle().clone();

let result = match wallet_mode {
WalletMode::Tui => tui_mode(handle, &config.wallet, &base_node_config, wallet.clone()),
WalletMode::Tui => runtime.block_on(tui_mode(handle, &config.wallet, &base_node_config, wallet.clone())),
WalletMode::Grpc => grpc_mode(handle, &config.wallet, wallet.clone()),
WalletMode::Script(path) => script_mode(handle, &cli, &config.wallet, &base_node_config, wallet.clone(), path),
WalletMode::Command(command) => command_mode(
WalletMode::Script(path) => runtime.block_on(script_mode(
handle,
&cli,
&config.wallet,
&base_node_config,
wallet.clone(),
path,
)),
WalletMode::Command(command) => runtime.block_on(command_mode(
handle,
&cli,
&config.wallet,
&base_node_config,
wallet.clone(),
*command,
),
)),

WalletMode::RecoveryDaemon | WalletMode::RecoveryTui => {
recovery_mode(handle, &base_node_config, &config.wallet, wallet_mode, wallet.clone())
},
WalletMode::RecoveryDaemon | WalletMode::RecoveryTui => runtime.block_on(recovery_mode(
handle,
&base_node_config,
&config.wallet,
wallet_mode,
wallet.clone(),
)),
WalletMode::Invalid => Err(ExitError::new(
ExitCode::InputError,
"Invalid wallet mode - are you trying too many command options at once?",
Expand Down
7 changes: 5 additions & 2 deletions applications/minotari_console_wallet/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@

#![allow(dead_code, unused)]

use std::ptr;

use chrono::offset::Local;
use futures::FutureExt;
use log::*;
use minotari_wallet::{
connectivity_service::WalletConnectivityHandle,
error::WalletError,
storage::sqlite_db::wallet::WalletSqliteDatabase,
utxo_scanner_service::{handle::UtxoScannerEvent, service::UtxoScannerService},
WalletSqlite,
Expand All @@ -37,7 +40,7 @@ use tari_crypto::tari_utilities::Hidden;
use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::Mnemonic, SeedWords};
use tari_shutdown::Shutdown;
use tari_utilities::hex::Hex;
use tokio::sync::broadcast;
use tokio::{runtime::Runtime, sync::broadcast};
use zeroize::{Zeroize, Zeroizing};

use crate::wallet_modes::PeerConfig;
Expand Down Expand Up @@ -122,7 +125,7 @@ pub async fn wallet_recovery(
.with_peers(peer_public_keys)
// Do not make this a small number as wallet recovery needs to be resilient
.with_retry_limit(retry_limit)
.build_with_wallet(wallet, shutdown_signal);
.build_with_wallet(wallet, shutdown_signal).await.map_err(|e| ExitError::new(ExitCode::RecoveryError, e))?;

let mut event_stream = recovery_task.get_event_receiver();

Expand Down
12 changes: 7 additions & 5 deletions applications/minotari_console_wallet/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use minotari_wallet::{util::wallet_identity::WalletIdentity, WalletConfig, WalletSqlite};
use tari_common::exit_codes::ExitError;
use tari_comms::peer_manager::Peer;
use tokio::runtime::Handle;
use tui::{
Expand Down Expand Up @@ -69,15 +70,16 @@ pub struct App<B: Backend> {
}

impl<B: Backend> App<B> {
pub fn new(
pub async fn new(
title: String,
wallet: WalletSqlite,
wallet_config: WalletConfig,
base_node_selected: Peer,
base_node_config: PeerConfig,
notifier: Notifier,
) -> Self {
let wallet_id = WalletIdentity::new(wallet.comms.node_identity(), wallet.network.as_network());
) -> Result<Self, ExitError> {
let wallet_address = wallet.get_wallet_address().await?;
let wallet_id = WalletIdentity::new(wallet.comms.node_identity(), wallet_address);
let app_state = AppState::new(
&wallet_id,
wallet,
Expand All @@ -101,15 +103,15 @@ impl<B: Backend> App<B> {
let base_node_status = BaseNode::new();
let menu = Menu::new();

Self {
Ok(Self {
title,
should_quit: false,
app_state,
tabs,
base_node_status,
menu,
notifier,
}
})
}

pub fn on_control_key(&mut self, c: char) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,11 +939,11 @@ impl AppStateInner {
}

pub async fn refresh_network_id(&mut self) -> Result<(), UiError> {
let wallet_id = WalletIdentity::new(self.wallet.comms.node_identity(), self.wallet.network.as_network());
let wallet_id = self.wallet.get_wallet_id().await?;
let eid = wallet_id.address.to_emoji_string();
let qr_link = format!(
"tari://{}/transactions/send?tariAddress={}",
wallet_id.network,
wallet_id.network(),
wallet_id.address.to_hex()
);
let code = QrCode::new(qr_link).unwrap();
Expand Down Expand Up @@ -1278,7 +1278,7 @@ impl AppStateData {
let eid = wallet_identity.address.to_emoji_string();
let qr_link = format!(
"tari://{}/transactions/send?tariAddress={}",
wallet_identity.network,
wallet_identity.network(),
wallet_identity.address.to_hex()
);
let code = QrCode::new(qr_link).unwrap();
Expand Down
21 changes: 11 additions & 10 deletions applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl PeerConfig {
}
}

pub(crate) fn command_mode(
pub(crate) async fn command_mode(
handle: Handle,
cli: &Cli,
config: &WalletConfig,
Expand All @@ -159,7 +159,7 @@ pub(crate) fn command_mode(

info!(target: LOG_TARGET, "Completed wallet command mode");

wallet_or_exit(handle, cli, config, base_node_config, wallet)
wallet_or_exit(handle, cli, config, base_node_config, wallet).await
}

pub(crate) fn parse_command_file(script: String) -> Result<Vec<CliCommands>, ExitError> {
Expand Down Expand Up @@ -188,7 +188,7 @@ pub(crate) fn parse_command_file(script: String) -> Result<Vec<CliCommands>, Exi
Ok(commands)
}

pub(crate) fn script_mode(
pub(crate) async fn script_mode(
handle: Handle,
cli: &Cli,
config: &WalletConfig,
Expand Down Expand Up @@ -221,11 +221,11 @@ pub(crate) fn script_mode(

info!(target: LOG_TARGET, "Completed wallet script mode");

wallet_or_exit(handle, cli, config, base_node_config, wallet)
wallet_or_exit(handle, cli, config, base_node_config, wallet).await
}

/// Prompts the user to continue to the wallet, or exit.
fn wallet_or_exit(
async fn wallet_or_exit(
handle: Handle,
cli: &Cli,
config: &WalletConfig,
Expand Down Expand Up @@ -255,13 +255,13 @@ fn wallet_or_exit(
},
_ => {
info!(target: LOG_TARGET, "Starting TUI.");
tui_mode(handle, config, base_node_config, wallet)
tui_mode(handle, config, base_node_config, wallet).await
},
}
}
}

pub fn tui_mode(
pub async fn tui_mode(
handle: Handle,
config: &WalletConfig,
base_node_config: &PeerConfig,
Expand Down Expand Up @@ -329,7 +329,8 @@ pub fn tui_mode(
base_node_selected,
base_node_config.clone(),
notifier,
);
)
.await?;

info!(target: LOG_TARGET, "Starting app");

Expand All @@ -350,7 +351,7 @@ pub fn tui_mode(
Ok(())
}

pub fn recovery_mode(
pub async fn recovery_mode(
handle: Handle,
base_node_config: &PeerConfig,
wallet_config: &WalletConfig,
Expand Down Expand Up @@ -387,7 +388,7 @@ pub fn recovery_mode(

match wallet_mode {
WalletMode::RecoveryDaemon => grpc_mode(handle, wallet_config, wallet),
WalletMode::RecoveryTui => tui_mode(handle, wallet_config, base_node_config, wallet),
WalletMode::RecoveryTui => tui_mode(handle, wallet_config, base_node_config, wallet).await,
_ => Err(ExitError::new(
ExitCode::RecoveryError,
"Unsupported post recovery mode",
Expand Down
2 changes: 1 addition & 1 deletion base_layer/chat_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ use libc::c_int;
use log::info;
use minotari_app_utilities::identity_management::setup_node_identity;
use tari_chat_client::{config::ApplicationConfig, networking::PeerFeatures, ChatClient as ChatClientTrait, Client};
use tari_common_types::tari_address::TariAddress;
use tari_contacts::contacts_service::handle::ContactsServiceHandle;
use tokio::runtime::Runtime;
use tari_common_types::tari_address::TariAddress;

use crate::{
callback_handler::{
Expand Down
Loading

0 comments on commit 97c0841

Please sign in to comment.