Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions applications/tari_walletd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ license.workspace = true

[dependencies]
minotari_app_utilities = { workspace = true }
tari_bor = { workspace = true }
tari_common = { workspace = true }
tari_common_types = { workspace = true }
tari_crypto = { workspace = true }
tari_ootle_app_utilities = { workspace = true }
tari_shutdown = { workspace = true }
tari_ootle_wallet_crypto = { workspace = true }
tari_ootle_wallet_sdk = { workspace = true }
tari_ootle_wallet_sdk_services = { workspace = true }
tari_ootle_wallet_sdk_services = { workspace = true, features = ["indexer_jrpc"] }
tari_ootle_wallet_storage_sqlite = { workspace = true }
tari_transaction = { workspace = true }
tari_ootle_common_types = { workspace = true }
Expand All @@ -27,7 +26,6 @@ tari_template_builtin = { workspace = true }
# TODO: Ideally we should not have to include the WASM template lib, we should perhaps extract the address types into a separate crate (e.g. template_types)
tari_template_lib = { workspace = true }
tari_template_abi = { workspace = true }
tari_transaction_components = { workspace = true }
tari_transaction_manifest = { workspace = true }

async-trait = { workspace = true }
Expand Down Expand Up @@ -71,7 +69,6 @@ webauthn-rs = { workspace = true }
uuid = { workspace = true }
wasm-opt = "0.116.1"
tempfile.workspace = true
futures-bounded = { workspace = true }

[dev-dependencies]
tari_utilities = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_walletd/src/handlers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use tari_ootle_wallet_sdk::{
},
models::NewAccountData,
};
use tari_ootle_wallet_sdk_services::events::TransactionSubmittedEvent;
use tari_template_builtin::ACCOUNT_TEMPLATE_ADDRESS;
use tari_template_lib::{
constants::{STEALTH_TARI_RESOURCE_ADDRESS, XTR, XTR_FAUCET_COMPONENT_ADDRESS, XTR_FAUCET_VAULT_ADDRESS},
Expand Down Expand Up @@ -93,7 +94,6 @@ use crate::{
wait_for_result_and_account,
},
jrpc_server::ApplicationErrorCode,
services::TransactionSubmittedEvent,
DEFAULT_FEE,
};

Expand Down
11 changes: 8 additions & 3 deletions applications/tari_walletd/src/handlers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

use axum_extra::headers::authorization::Bearer;
use tari_ootle_wallet_sdk::WalletSdk;
use tari_ootle_wallet_sdk_services::indexer_jrpc_impl::IndexerJsonRpcNetworkInterface;
use tari_ootle_wallet_sdk_services::{
account_monitor::AccountMonitorHandle,
events::WalletEvent,
indexer_jrpc::IndexerJsonRpcNetworkInterface,
notify::Notify,
transaction_service::TransactionServiceHandle,
};
use tari_ootle_wallet_storage_sqlite::SqliteWalletStore;
use tari_shutdown::ShutdownSignal;
use tari_transaction::{Transaction, TransactionBuilder};
Expand All @@ -16,8 +22,7 @@ use crate::{
jwt::{JwtApi, JwtApiError},
WalletAuthenticator,
},
notify::Notify,
services::{AccountMonitorHandle, TransactionServiceHandle, WalletEvent, WebauthnService},
services::WebauthnService,
};

#[derive(Debug, Clone)]
Expand Down
10 changes: 5 additions & 5 deletions applications/tari_walletd/src/handlers/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ use tari_ootle_wallet_sdk::{
storage::WalletStore,
WalletSdk,
};
use tari_ootle_wallet_sdk_services::indexer_jrpc_impl::IndexerJsonRpcNetworkInterface;
use tari_ootle_wallet_sdk_services::{
events::{TransactionFinalizedEvent, WalletEvent},
indexer_jrpc::IndexerJsonRpcNetworkInterface,
};
use tari_ootle_wallet_storage_sqlite::SqliteWalletStore;
use tari_template_builtin::ACCOUNT_TEMPLATE_ADDRESS;
use tari_template_lib::models::ComponentAddress;
use tari_transaction::TransactionId;
use tari_wallet_daemon_client::ComponentAddressOrName;
use tokio::sync::broadcast;

use crate::{
jrpc_server::ApplicationErrorCode,
services::{TransactionFinalizedEvent, WalletEvent},
};
use crate::jrpc_server::ApplicationErrorCode;

pub async fn wait_for_result(
events: &mut broadcast::Receiver<WalletEvent>,
Expand Down
21 changes: 3 additions & 18 deletions applications/tari_walletd/src/handlers/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tari_template_lib::{
constants::{NFT_FAUCET_COMPONENT_ADDRESS, NFT_FAUCET_RESOURCE_ADDRESS},
models::{ComponentAddress, ResourceAddress},
};
use tari_transaction::{args, TransactionId};
use tari_transaction::args;
use tari_wallet_daemon_client::{
permissions::JrpcPermission,
types::{
Expand All @@ -33,13 +33,11 @@ use tari_wallet_daemon_client::{
TransferNftResponse,
},
};
use tokio::sync::broadcast;

use super::{context::HandlerContext, helpers::get_account_or_default};
use crate::{
handlers::helpers::{application_error, get_account, get_account_with_inputs, invalid_params},
handlers::helpers::{application_error, get_account, get_account_with_inputs, invalid_params, wait_for_result},
jrpc_server::ApplicationErrorCode,
services::{TransactionFinalizedEvent, WalletEvent},
DEFAULT_FEE,
};

Expand Down Expand Up @@ -287,7 +285,7 @@ pub async fn handle_transfer(
let transaction = builder
.with_dry_run(req.dry_run)
.fee_transaction_pay_from_component(fee_payer_account_address, req.max_fee)
.with_inputs(inputs)
.with_inputs(inputs.into_iter().map(|input| input.into_unversioned()))
// Seal signer is the fee payer account
.with_authorized_seal_signer()
.add_signer(
Expand Down Expand Up @@ -342,16 +340,3 @@ pub async fn handle_transfer(
result: finalized.finalize,
})
}

async fn wait_for_result(
events: &mut broadcast::Receiver<WalletEvent>,
transaction_id: TransactionId,
) -> Result<TransactionFinalizedEvent, anyhow::Error> {
loop {
let wallet_event = events.recv().await?;
match wallet_event {
WalletEvent::TransactionFinalized(event) if event.transaction_id == transaction_id => return Ok(event),
_ => {},
}
}
}
2 changes: 1 addition & 1 deletion applications/tari_walletd/src/handlers/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause

use axum_extra::headers::authorization::Bearer;
use tari_ootle_wallet_sdk_services::events::AuthLoginRequestEvent;
use tari_wallet_daemon_client::{
permissions::JrpcPermission,
types::{
Expand All @@ -24,7 +25,6 @@ use tari_wallet_daemon_client::{
use crate::{
config::WalletDaemonAuth,
handlers::{auth::Authenticator, HandlerContext},
services::AuthLoginRequestEvent,
};

// NOTE: most of these do not require a bearer token, either because they are not sensitive or because they validate a
Expand Down
12 changes: 5 additions & 7 deletions applications/tari_walletd/src/handlers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tari_ootle_wallet_sdk::{
apis::{config::ConfigKey, key_manager::KeyBranch, transaction::TransactionApiError},
network::WalletQueryErrorStatus,
};
use tari_ootle_wallet_sdk_services::{events::WalletEvent, transaction_service::TransactionServiceError};
use tari_transaction::{args, Transaction};
use tari_transaction_manifest::parse_manifest;
use tari_wallet_daemon_client::{
Expand Down Expand Up @@ -41,13 +42,10 @@ use tari_wallet_daemon_client::{
use tokio::time;

use super::context::HandlerContext;
use crate::{
handlers::{
helpers::{get_account, get_account_or_default, invalid_params, not_found, transaction_rejected},
wasm_optimizer::optimize_wasm_template,
HandlerError,
},
services::{transaction_service::TransactionServiceError, WalletEvent},
use crate::handlers::{
helpers::{get_account, get_account_or_default, invalid_params, not_found, transaction_rejected},
wasm_optimizer::optimize_wasm_template,
HandlerError,
};

const LOG_TARGET: &str = "tari::ootle::wallet_daemon::handlers::transaction";
Expand Down
12 changes: 7 additions & 5 deletions applications/tari_walletd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ mod handlers;
#[cfg(feature = "web_ui")]
mod http_ui;
mod jrpc_server;
mod notify;
mod services;
mod webrtc;

Expand All @@ -43,16 +42,19 @@ use tari_ootle_wallet_sdk::{
WalletSdk,
WalletSdkConfig,
};
use tari_ootle_wallet_sdk_services::indexer_jrpc_impl::IndexerJsonRpcNetworkInterface;
use tari_ootle_wallet_sdk_services::{
account_recovery::AccountRecoveryService,
indexer_jrpc::IndexerJsonRpcNetworkInterface,
notify::Notify,
};
use tari_ootle_wallet_storage_sqlite::SqliteWalletStore;
use tari_shutdown::ShutdownSignal;
use tari_template_lib::constants::XTR;

use crate::{
config::ApplicationConfig,
handlers::{auth::create_authenticator, HandlerContext},
notify::Notify,
services::{recovery_service, spawn_services},
services::spawn_services,
};

const LOG_TARGET: &str = "tari::ootle::wallet_daemon";
Expand Down Expand Up @@ -91,7 +93,7 @@ pub async fn run_tari_ootle_walletd(

// trigger account scanning if needed
if needs_seed_recovery {
let scanner = recovery_service::AccountRecoveryService::new(
let scanner = AccountRecoveryService::new(
wallet_sdk.clone(),
services.account_monitor_handle.clone(),
config.ootle_wallet_daemon.recovery_abandon_count,
Expand Down
36 changes: 9 additions & 27 deletions applications/tari_walletd/src/services/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
// Copyright 2023 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

mod events;
pub use events::*;

mod account_monitor;
pub use account_monitor::AccountMonitorHandle;

pub mod transaction_service;
mod webauthn;
pub use webauthn::*;

mod session_store;
mod template_monitor;

pub mod recovery_service;
mod stealth_utxo_scanner;

// -------------------------------- Spawn -------------------------------- //
use anyhow::anyhow;
use futures::{future, future::BoxFuture, FutureExt};
Expand All @@ -27,22 +17,17 @@ use tari_ootle_wallet_sdk::{
storage::WalletStore,
WalletSdk,
};
use tari_ootle_wallet_sdk_services::utxo_scanner::UtxoRecovery;
use tari_shutdown::ShutdownSignal;
use tokio::{sync::oneshot, task::JoinHandle};
use transaction_service::TransactionService;
pub use transaction_service::TransactionServiceHandle;

use crate::{
use tari_ootle_wallet_sdk_services::{
account_monitor::{AccountMonitor, AccountMonitorHandle},
events::WalletEvent,
notify::Notify,
services::{
account_monitor::AccountMonitor,
stealth_utxo_scanner::StealthUtxoScannerWorker,
template_monitor::TemplateMonitor,
},
transaction_service::{TransactionService, TransactionServiceHandle},
utxo_scanner::{StealthUtxoScannerWorker, UtxoRecovery},
};
use tari_shutdown::ShutdownSignal;
use tokio::task::JoinHandle;

type Reply<T> = oneshot::Sender<T>;
use crate::services::template_monitor::TemplateMonitor;

pub fn spawn_services<TStore, TNetworkInterface>(
shutdown_signal: ShutdownSignal,
Expand Down Expand Up @@ -97,8 +82,5 @@ pub struct Services {
async fn try_select_any<I>(handles: I) -> Result<(), anyhow::Error>
where I: IntoIterator<Item = JoinHandle<Result<(), anyhow::Error>>> {
let (res, _, _) = future::select_all(handles).await;
match res {
Ok(res) => res,
Err(e) => Err(anyhow!("Task panicked: {}", e)),
}
res.unwrap_or_else(|e| Err(anyhow!("Task panicked: {}", e)))
}
3 changes: 1 addition & 2 deletions applications/tari_walletd/src/services/template_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ use tari_ootle_wallet_sdk::{
storage::WalletStore,
WalletSdk,
};
use tari_ootle_wallet_sdk_services::{events::WalletEvent, notify::Notify};
use tari_shutdown::ShutdownSignal;
use tari_template_abi::TemplateDef;
use tari_template_lib::types::TemplateAddress;

use crate::{notify::Notify, services::WalletEvent};

const LOG_TARGET: &str = "tari::ootle_wallet_daemon::services::template_monitor";

pub struct TemplateMonitor<TStore, TNetworkInterface> {
Expand Down
15 changes: 12 additions & 3 deletions crates/wallet/sdk_services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@ repository.workspace = true
license.workspace = true

[dependencies]
tari_bor = { workspace = true }
tari_template_abi = { workspace = true }
tari_ootle_common_types = { workspace = true }
tari_ootle_wallet_sdk = { workspace = true }
tari_engine_types = { workspace = true }
tari_template_lib = { workspace = true }
tari_indexer_client = { workspace = true, features = ["client"] }
tari_indexer_client = { workspace = true, features = ["client"], optional = true }
tari_transaction = { workspace = true }
tari_transaction_components = { workspace = true }
tari_template_builtin = { workspace = true }

tari_crypto = { workspace = true }
tari_shutdown = { workspace = true }

anyhow = { workspace = true }
reqwest = { workspace = true }
reqwest = { workspace = true, optional = true }
futures-bounded = { workspace = true }
thiserror = { workspace = true }
url = { workspace = true }
log = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
tokio = { workspace = true, features = ["sync", "macros", "time"] }

[features]
default = []
indexer_jrpc = ["tari_indexer_client", "reqwest"]
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ use tokio::{
};

use crate::{
events::{AccountChangedEvent, AccountCreatedEvent, WalletEvent},
notify::Notify,
services::{stealth_utxo_scanner::UtxoScannerHandle, AccountChangedEvent, AccountCreatedEvent, Reply, WalletEvent},
utxo_scanner::UtxoScannerHandle,
Reply,
};

const LOG_TARGET: &str = "tari::ootle::wallet_daemon::account_monitor";
const LOG_TARGET: &str = "tari::ootle::wallet_services::account_monitor";

pub struct AccountMonitor<TStore, TNetworkInterface> {
notify: Notify<WalletEvent>,
Expand Down
Loading
Loading