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
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion applications/tari_indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub async fn run_indexer(config: ApplicationConfig, mut shutdown_signal: Shutdow
},

_ = shutdown_signal.wait() => {
dbg!("Shutting down run_substate_polling");
debug!(target: LOG_TARGET, "Shutting down run_substate_polling");
break;
},
}
Expand Down
9 changes: 7 additions & 2 deletions applications/tari_indexer/src/network_state_sync/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,17 @@ fn extend_bufs_from_substate_update(
value: create.substate.value().clone(),
});
},
Some(_) => {},
Some(_) => {
warn!(target: LOG_TARGET, "⚠️ NEVER HAPPEN: Received unexpected substate value for created substate: {}", create.substate.substate_id());
},
None => {
let id = create.substate.substate_id();
if id.is_template() || id.is_transaction_receipt() || id.is_utxo() {
if id.is_template() || id.is_transaction_receipt() {
warn!(target: LOG_TARGET, "⚠️ NEVER HAPPEN: Received substate {id} update with no value");
}
if let Some(addr) = id.as_utxo_address() {
debug!(target: LOG_TARGET, "🌍️ Received UTXO substate {addr} creation with no value. Ignoring as this means it is spent later.");
}
Comment thread
sdbondi marked this conversation as resolved.
},
},
SubstateUpdateProof::Destroy(destroy) => match &destroy.substate_id {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const SUBSTATE_TYPES = [
"TransactionReceipt",
"ValidatorFeePool",
"Template",
"Utxo",
] as const;

type ExtendedSubstateItem = ListSubstateItem & { id: string; show?: boolean };
Expand Down Expand Up @@ -90,7 +91,7 @@ function SubstatesLayout() {

const extendedSubstates = useMemo(
() => substates.map((substate) => ({ ...substate, id: substateIdToString(substate.substate_id) })),
[substates]
[substates],
);

const visibleSubstates = filteredSubstates.filter((substate) => substate.show !== false);
Expand Down
79 changes: 37 additions & 42 deletions applications/tari_walletd/src/handlers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::{array, collections::HashSet};

use anyhow::Context;
use axum_extra::headers::authorization::Bearer;
use indexmap::IndexMap;
use log::*;
Expand Down Expand Up @@ -36,7 +37,7 @@ use tari_template_lib::{
constants::{STEALTH_TARI_RESOURCE_ADDRESS, XTR, XTR_FAUCET_COMPONENT_ADDRESS, XTR_FAUCET_VAULT_ADDRESS},
types::{Amount, ResourceType},
};
use tari_transaction::args;
use tari_transaction::{args, TransactionSignature};
use tari_wallet_daemon_client::{
permissions::JrpcPermission,
types::{
Expand Down Expand Up @@ -284,7 +285,7 @@ pub async fn handle_get_balances(
let vaults = sdk.accounts_api().get_vaults_by_account(account.component_address())?;
let stealth_outputs = sdk
.stealth_outputs_api()
.get_unspent_outputs_by_account(account.component_address())?;
.get_unspent_outputs_by_account(account.component_address(), false)?;

let mut balances = Vec::with_capacity(vaults.len());
let mut vaulted_resources = HashSet::new();
Expand Down Expand Up @@ -683,6 +684,7 @@ pub async fn handle_create_free_test_coins(
account.is_confirmed_on_chain().then(|| NewAccountData {
address: *account.component_address(),
}),
None,
)
.await?;

Expand Down Expand Up @@ -987,13 +989,27 @@ pub async fn handle_stealth_transfer(
task::spawn(async move {
let transfer = sdk.stealth_transfer_api().transfer(owner_account, params).await?;

let transaction = transfer.transaction.authorized_sealed_signer().build();
let transaction = transfer.transaction.authorized_sealed_signer();
let main_pk = transfer.main_signer.public_key().to_byte_type();

// Add additional signature if needed
let additional_sig = transfer
.additional_signer
.as_ref()
.map(|s| {
sdk.local_signer_api()
.get_signature(s.branch, s.key_id, &main_pk, &transaction)
})
.transpose()?
.map(|sig| TransactionSignature::new(sig.public_key.to_byte_type(), sig.signature.to_byte_type()));

let transaction = transaction.build_with_signatures(additional_sig.into_iter().collect());

// Sign and seal the final transaction
let transaction =
sdk.local_signer_api()
.sign(transfer.signing_key_branch, transfer.signing_key_id, transaction)?;
.sign(transfer.main_signer.branch, transfer.main_signer.key_id, transaction)?;

Comment thread
sdbondi marked this conversation as resolved.
// TODO: if submitting fails we need to unlock the inputs again
if req.dry_run {
// Release the lock immediately as dry run does not submit the transaction
// TODO: maybe transfer() should not lock the outputs if it's a dry run
Expand All @@ -1009,46 +1025,25 @@ pub async fn handle_stealth_transfer(
Ok(res) => Ok(StealthTransferResponse {
transaction_id: res.finalize.transaction_hash.into(),
}),
Err(e) => {
if let Err(err) = sdk.stealth_outputs_api().release_lock(transfer.lock_id) {
error!(
target: LOG_TARGET,
"Failed to release locked outputs after dry run failure: {}",
err
);
}

Err(anyhow::anyhow!("Dry run transaction failed: {}", e))
},
Err(e) => Err(anyhow::anyhow!("Dry run transaction failed: {}", e)),
};
}

// Associate lock with transaction
sdk.stealth_outputs_api()
.locks_set_transaction_id(transfer.lock_id, transaction.calculate_id())?;

let result = transaction_service.submit_transaction(transaction).await;
match result {
Ok(tx_id) => {
notifier.notify(TransactionSubmittedEvent {
transaction_id: tx_id,
new_account: None,
});

Ok(StealthTransferResponse { transaction_id: tx_id })
},
Err(e) => {
if let Err(err) = sdk.stealth_outputs_api().release_lock(transfer.lock_id) {
error!(
target: LOG_TARGET,
"Failed to release locked outputs after submission failure: {}",
err
);
}

Err(anyhow::anyhow!("Transaction submission failed: {}", e))
},
}
let tx_id = sdk
.stealth_transfer_api()
.unlock_on_failure(
transfer.lock_id,
transaction_service
.submit_transaction_with_opts(transaction, None, Some(transfer.lock_id))
.await,
)
.context("Transaction failed to submit")?;
notifier.notify(TransactionSubmittedEvent {
transaction_id: tx_id,
new_account: None,
});

Ok(StealthTransferResponse { transaction_id: tx_id })
})
.await?
}
Expand Down
8 changes: 7 additions & 1 deletion applications/tari_walletd/src/handlers/auth/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ use axum_extra::headers::authorization::Bearer;
use jsonwebtoken::{errors, DecodingKey, EncodingKey, Header, Validation};
use serde::{Deserialize, Serialize};
use tari_crypto::tari_utilities::SafePassword;
use tari_ootle_wallet_sdk::storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter};
use tari_ootle_wallet_sdk::storage::{
CommitableStore,
WalletStorageError,
WalletStore,
WalletStoreReader,
WalletStoreWriter,
};
use tari_wallet_daemon_client::{
permissions::{Claims, JrpcPermission, JrpcPermissions},
types::EncodedJwtString,
Expand Down
8 changes: 7 additions & 1 deletion applications/tari_walletd/src/services/webauthn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

use std::time::{Duration, Instant};

use tari_ootle_wallet_sdk::storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter};
use tari_ootle_wallet_sdk::storage::{
CommitableStore,
WalletStorageError,
WalletStore,
WalletStoreReader,
WalletStoreWriter,
};
use thiserror::Error;
use webauthn_rs::prelude::{Passkey, PasskeyAuthentication, PasskeyRegistration};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ function StealthUtxoList({ account }: { account: Account }) {
);

const columnWidths = {
1: "10%",
2: "15%",
3: "20%",
4: "25%",
1: "15%",
2: "20%",
3: "15%",
4: "30%",
5: "10%",
6: "10%",
7: "10%",
};

return (
Expand All @@ -93,7 +92,6 @@ function StealthUtxoList({ account }: { account: Account }) {
<TableCell width={columnWidths[4]}>Memo</TableCell>
<TableCell width={columnWidths[5]}>Burnt</TableCell>
<TableCell width={columnWidths[6]}>Frozen</TableCell>
<TableCell width={columnWidths[7]}>On Chain</TableCell>
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -116,7 +114,6 @@ function StealthUtxoList({ account }: { account: Account }) {
</DataTableCell>
<DataTableCell>{utxo.is_burnt ? "Yes" : "No"}</DataTableCell>
<DataTableCell>{utxo.is_frozen ? "Yes" : "No"}</DataTableCell>
<DataTableCell>{utxo.is_on_chain ? "Yes" : "No"}</DataTableCell>
</TableRow>
))}
{emptyRows(page, rowsPerPage, data.utxos) > 0 && (
Expand Down
11 changes: 11 additions & 0 deletions crates/engine_types/src/commit_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ impl FinalizeResult {
self.result.any_reject()
}

pub fn reject(&self) -> Option<&RejectReason> {
self.result.reject()
}

pub fn fee_accept_transaction_reject(&self) -> Option<(&SubstateDiff, &RejectReason)> {
self.result.fee_accept_transaction_reject()
}
Expand Down Expand Up @@ -288,6 +292,13 @@ impl TransactionResult {
}
}

pub fn reject(&self) -> Option<&RejectReason> {
match self {
Self::Reject(reject_result) => Some(reject_result),
_ => None,
}
}

pub fn expect(self, msg: &str) -> SubstateDiff {
match self {
Self::Accept(substate_diff) => substate_diff,
Expand Down
4 changes: 2 additions & 2 deletions crates/engine_types/src/resource_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl ResourceContainer {
if withdraw_amt > *revealed_amount {
return Err(ResourceError::InsufficientBalance {
details: format!(
"Bucket contained insufficient revealed funds. Required: {}, Available: {}",
"Bucket or vault contained insufficient revealed funds. Required: {}, Available: {}",
withdraw_amt, revealed_amount
),
});
Expand All @@ -342,7 +342,7 @@ impl ResourceContainer {
if withdraw_amt > *revealed_amount {
return Err(ResourceError::InsufficientBalance {
details: format!(
"Bucket contained insufficient revealed funds. Required: {}, Available: {}",
"Bucket or vault contained insufficient revealed funds. Required: {}, Available: {}",
withdraw_amt, revealed_amount
),
});
Expand Down
7 changes: 0 additions & 7 deletions crates/wallet/crypto/src/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ impl Memo {
Some(Self::Bytes(b))
}

pub fn as_bytes(&self) -> &[u8] {
match self {
Memo::Message(s) => s.as_bytes(),
Memo::Bytes(b) => b.as_ref(),
}
}

pub fn len(&self) -> usize {
match self {
Memo::Message(s) => s.len(),
Expand Down
1 change: 1 addition & 0 deletions crates/wallet/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ webauthn-rs = { workspace = true }
keyring = { version = "3.6.3", features = ["apple-native", "windows-native", "sync-secret-service"] }
passwords = "3.1.16"
zeroize = { workspace = true, features = ["serde", "simd"] }
tokio = { workspace = true, default-features = false, features = ["sync"] }

[dev-dependencies]
tari_ootle_wallet_storage_sqlite = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/wallet/sdk/src/apis/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::{
WalletOotleAddressWithKeyIds,
},
network::WalletNetworkInterface,
storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter},
storage::{CommitableStore, WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter},
};

pub struct AccountsApi<'a, TStore, TNetworkInterface> {
Expand Down
2 changes: 1 addition & 1 deletion crates/wallet/sdk/src/apis/confidential_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
key_manager::{KeyManagerApi, KeyManagerApiError},
},
models::{Account, ConfidentialOutputModel, OutputStatus, WalletLockId, WalletSecretKey},
storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter},
storage::{CommitableStore, WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter},
};

const LOG_TARGET: &str = "tari::ootle::wallet_sdk::apis::confidential_outputs";
Expand Down
2 changes: 1 addition & 1 deletion crates/wallet/sdk/src/apis/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{str::FromStr, sync::OnceLock};
use serde::{de::DeserializeOwned, Serialize};
use tari_ootle_common_types::{optional::IsNotFoundError, Network};

use crate::storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter};
use crate::storage::{CommitableStore, WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter};

#[derive(Debug, Clone)]
pub struct ConfigApi<'a, TStore> {
Expand Down
7 changes: 6 additions & 1 deletion crates/wallet/sdk/src/apis/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::{
WalletPublicKey,
WalletSecretKey,
},
storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter},
storage::{CommitableStore, WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter},
};

pub type WalletKeyManager = TariKeyManager<Blake2b<U64>>;
Expand Down Expand Up @@ -76,6 +76,7 @@ impl<'a, TStore: WalletStore> KeyManagerApi<'a, TStore> {
key_id: KeyId::derived(index),
public_key: pk,
secret_key: key,
branch,
is_active: active,
});
}
Expand Down Expand Up @@ -137,13 +138,15 @@ impl<'a, TStore: WalletStore> KeyManagerApi<'a, TStore> {
let imported_key = self.get_imported_key(local_key_id)?;
Ok(WalletPublicKey {
public_key: imported_key.to_public_key(),
branch,
key_id,
})
},
KeyId::Derived { index } => {
let derived_key = self.derive_key(branch, index)?;
Ok(WalletPublicKey {
public_key: derived_key.to_public_key(),
branch,
key_id,
})
},
Expand All @@ -168,6 +171,7 @@ impl<'a, TStore: WalletStore> KeyManagerApi<'a, TStore> {
.map_err(|e| KeyManagerApiError::KeyStoreError { source: e.into() })?;
Ok(DerivedWalletKey {
key: secret,
branch,
key_index: index,
})
}
Expand Down Expand Up @@ -254,6 +258,7 @@ impl<'a, TStore: WalletStore> KeyManagerApi<'a, TStore> {
let key = self.derive_key(branch, next_key_id)?;
Ok(WalletPublicKey {
public_key: key.to_public_key(),
branch,
key_id: key.as_key_id(),
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wallet/sdk/src/apis/non_fungible_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use thiserror::Error;

use crate::{
models::NonFungibleToken,
storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter},
storage::{CommitableStore, WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter},
};

pub struct NonFungibleTokensApi<'a, TStore> {
Expand Down
Loading
Loading