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
3 changes: 1 addition & 2 deletions applications/tari_walletd/src/handlers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ use tari_ootle_wallet_sdk::{
stealth_transfer::{StealthTransferParams, TransferOutput},
substate::ValidatorScanResult,
},
models::{BranchAndKeyId, KeyBranch, KeyId, NewAccountData},
models::{BranchAndKeyId, KeyBranch, KeyId, NewAccountData, TransactionSubmittedEvent},
};
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
2 changes: 1 addition & 1 deletion applications/tari_walletd/src/handlers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: BSD-3-Clause

use axum_extra::headers::authorization::Bearer;
use tari_ootle_wallet_sdk::models::WalletEvent;
use tari_ootle_wallet_sdk_services::{
account_monitor::AccountMonitorHandle,
events::WalletEvent,
notify::Notify,
transaction_service::TransactionServiceHandle,
};
Expand Down
3 changes: 1 addition & 2 deletions applications/tari_walletd/src/handlers/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ use tari_ootle_common_types::{
};
use tari_ootle_wallet_sdk::{
apis::accounts::{AccountsApi, AccountsApiError},
models::{AccountWithAddress, DerivedKeyIndex},
models::{AccountWithAddress, DerivedKeyIndex, TransactionFinalizedEvent, WalletEvent},
network::{StatusResponseError, WalletNetworkInterface},
storage::WalletStore,
WalletSdk,
};
use tari_ootle_wallet_sdk_services::events::{TransactionFinalizedEvent, WalletEvent};
use tari_template_builtin::ACCOUNT_TEMPLATE_ADDRESS;
use tari_template_lib::models::ComponentAddress;
use tari_transaction::TransactionId;
Expand Down
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,7 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause

use axum_extra::headers::authorization::Bearer;
use tari_ootle_wallet_sdk_services::events::AuthLoginRequestEvent;
use tari_ootle_wallet_sdk::models::AuthLoginRequestEvent;
use tari_wallet_daemon_client::{
permissions::JrpcPermission,
types::{
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_walletd/src/handlers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use tari_engine_types::ToByteType;
use tari_ootle_common_types::{optional::Optional, Epoch, Network};
use tari_ootle_wallet_sdk::{
apis::{config::ConfigKey, transaction::TransactionApiError},
models::{BranchAndKeyId, KeyBranch},
models::{BranchAndKeyId, KeyBranch, WalletEvent},
network::WalletQueryErrorStatus,
};
use tari_ootle_wallet_sdk_services::{events::WalletEvent, transaction_service::TransactionServiceError};
use tari_ootle_wallet_sdk_services::transaction_service::TransactionServiceError;
use tari_transaction::{args, Transaction};
use tari_transaction_manifest::parse_manifest;
use tari_wallet_daemon_client::{
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_walletd/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use futures::{future, future::BoxFuture, FutureExt};
pub use session_store::*;
use tari_ootle_common_types::optional::IsNotFoundError;
use tari_ootle_wallet_sdk::{
models::WalletEvent,
network::{StatusResponseError, WalletNetworkInterface},
storage::WalletStore,
WalletSdk,
};
use tari_ootle_wallet_sdk_services::{
account_monitor::{AccountMonitor, AccountMonitorHandle},
events::WalletEvent,
notify::Notify,
transaction_service::{TransactionService, TransactionServiceHandle},
utxo_scanner::{StealthUtxoScannerWorker, UtxoRecovery},
Expand Down Expand Up @@ -54,7 +54,7 @@ where
let utxo_recovery_join_handle = {
let sdk = wallet_sdk.clone();
let notify_sub = utxo_scanner_handle.subscribe_notifications();
tokio::spawn(UtxoRecovery::new(sdk).run(notify_sub))
tokio::spawn(UtxoRecovery::new(sdk).with_notify(notify.clone()).run(notify_sub))
};

let (account_monitor, account_monitor_handle) =
Expand Down
3 changes: 2 additions & 1 deletion applications/tari_walletd/src/services/template_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use tari_ootle_common_types::{
substate_type::SubstateType,
};
use tari_ootle_wallet_sdk::{
models::WalletEvent,
network::{StatusResponseError, WalletNetworkInterface},
storage::WalletStore,
WalletSdk,
};
use tari_ootle_wallet_sdk_services::{events::WalletEvent, notify::Notify};
use tari_ootle_wallet_sdk_services::notify::Notify;
use tari_shutdown::ShutdownSignal;
use tari_template_abi::TemplateDef;
use tari_template_lib::types::TemplateAddress;
Expand Down
1 change: 1 addition & 0 deletions crates/template_lib_types/src/encrypted_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};

use crate::max_bytes::MaxBytes;

/// The maximum size of EncryptedData including the maximum memo size (335 bytes)
const MAX_SIZE: usize = EncryptedData::ENCRYPTED_DATA_SIZE_WITHOUT_MEMO + EncryptedData::MAX_MEMO_SIZE;

/// Used by the receiver to determine the value and mask of the commitment. Used in stealth and confidential transfers,
Expand Down
12 changes: 11 additions & 1 deletion crates/template_lib_types/src/max_string.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright 2025 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use std::ops::{Deref, DerefMut};
use std::{
fmt,
fmt::Display,
ops::{Deref, DerefMut},
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MaxString<const N: usize> {
Expand Down Expand Up @@ -61,6 +65,12 @@ impl<'de, const N: usize> serde::Deserialize<'de> for MaxString<N> {
}
}

impl<const N: usize> Display for MaxString<N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.s.as_ref().fmt(f)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
48 changes: 46 additions & 2 deletions crates/wallet/crypto/src/memo.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2025 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use std::{cmp, io};
use std::{cmp, fmt::Display, io};

use tari_template_lib::types::{MaxBytes, MaxString};
use tari_template_lib::types::{hex::write_hex_fmt, MaxBytes, MaxString};

/// These are selected to be out of range of the Minotari memo field tags
/// See:
Expand Down Expand Up @@ -118,6 +118,20 @@ impl Memo {
self.len() == 0
}

/// Attempt to interpret the memo as a UTF-8 string, regardless of its variant.
/// Returns `None` if the memo cannot be represented as a UTF-8 string.
pub fn as_utf8_str(&self) -> Option<&str> {
match self {
Self::Message(s) => Some(s),
Self::Bytes(b) => str::from_utf8(b.as_ref()).ok(),
Self::PayRefAndBytes(body) => {
let (_, msg_bytes) = split_len_prefixed(body)?;
str::from_utf8(msg_bytes).ok()
},
Self::U256(_) => None,
}
}

pub fn as_memo_message(&self) -> Option<&str> {
match self {
Self::Message(s) => Some(s),
Expand Down Expand Up @@ -241,6 +255,36 @@ impl Memo {
}
}

impl Display for Memo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::U256(b) => {
write!(f, "U256(")?;
write_hex_fmt(f, b)?;
write!(f, ")")
},
Self::Message(s) => write!(f, "Message({})", s),
Self::Bytes(b) => {
write!(f, "Bytes(")?;
write_hex_fmt(f, b)?;
write!(f, ")")
},
Self::PayRefAndBytes(b) => {
let Some((pay_ref, msg_bytes)) = split_len_prefixed(b) else {
return write!(f, "PayRefAndBytes(<invalid encoding>)");
};
write!(
f,
"PayRefAndBytes(pay_ref: {}, bytes: ",
std::str::from_utf8(pay_ref).unwrap_or("<not utf-8>"),
)?;
write_hex_fmt(f, msg_bytes)?;
write!(f, ")")
},
}
}
}

fn read_until_len_or_eof<R: io::Read>(mut buf: &mut [u8], reader: &mut R, max_len: usize) -> io::Result<usize> {
let mut bytes_read = 0;
while !buf.is_empty() {
Expand Down
51 changes: 51 additions & 0 deletions crates/wallet/sdk/src/apis/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2025 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tari_ootle_common_types::optional::IsNotFoundError;

use crate::{
models::WalletEvent,
storage::{WalletEventStoreWriter, WalletStorageError, WriteableWalletStore},
};

#[derive(Clone)]
pub struct EventsApi<'a, TStore> {
store: &'a TStore,
}

impl<'a, TStore> EventsApi<'a, TStore> {
pub(crate) fn new(store: &'a TStore) -> Self {
Self { store }
}
}

impl<'a, TStore: WriteableWalletStore> EventsApi<'a, TStore> {
pub fn log_event(&self, event: &WalletEvent) -> Result<(), EventApiError> {
self.store.with_write_tx(|tx| tx.append_wallet_event(event))?;
Ok(())
}

// pub fn search_events(
// &self,
// event_type: Option<WalletEvent>,
// limit: usize,
// offset: usize,
// ) -> Result<Vec<WalletEvent>, EventApiError> {
// let events = self
// .store
// .with_read_tx(|tx| tx.search_wallet_events(event_type, limit, offset))?;
// Ok(events)
// }
}

#[derive(thiserror::Error, Debug)]
pub enum EventApiError {
#[error("Store error: {0}")]
StoreError(#[from] WalletStorageError),
}

impl IsNotFoundError for EventApiError {
fn is_not_found_error(&self) -> bool {
matches!(self, EventApiError::StoreError(e) if e.is_not_found_error())
}
}
1 change: 1 addition & 0 deletions crates/wallet/sdk/src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod confidential_crypto;
pub mod confidential_outputs;
pub mod confidential_transfer;
pub mod config;
pub mod events;
pub mod key_manager;
pub mod locks;
pub mod non_fungible_tokens;
Expand Down
Loading
Loading