Skip to content

Commit

Permalink
Merge branch 'development' into transaction-unsigned-transaction
Browse files Browse the repository at this point in the history
* development:
  feat(walletd/js/client): use abstract transport to allow for WebRTC transport (tari-project#943)
  fix(engine): prevent creation of mismatched resource type bucket (tari-project#940)
  chore: update to latest feature-dan2 (tari-project#937)
  feat!: optional versions in transaction inputs (tari-project#922)
  feat: add tari-generate (tari-project#941)
  • Loading branch information
sdbondi committed Feb 27, 2024
2 parents 16da161 + 10afb16 commit b5b5b2d
Show file tree
Hide file tree
Showing 111 changed files with 3,406 additions and 1,446 deletions.
1,174 changes: 539 additions & 635 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"applications/tari_dan_app_utilities",
"applications/tari_dan_wallet_cli",
"applications/tari_dan_wallet_daemon",
"applications/tari_generate",
"applications/tari_indexer",
"applications/tari_scaffolder",
"applications/tari_signaling_server",
Expand Down Expand Up @@ -184,9 +185,10 @@ libp2p = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "49ca2
#libp2p-identity = "0.2.8"
libsqlite3-sys = "0.25"
liquid = "0.26.4"
liquid-core = "0.26.4"
lmdb-zero = "0.4.4"
log = "0.4.20"
log4rs = "1.1.1"
log4rs = "1.3"
mime_guess = "2.0.4"
mini-moka = "0.10.0"
multiaddr = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "49ca2a88961f7131d3e496b579b522a823ae0418" }
Expand Down Expand Up @@ -267,4 +269,3 @@ overflow-checks = true
#minotari_app_utilities = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_node = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_metrics = { git = "https://github.com/account/tari.git", branch = "my-branch" }

1 change: 0 additions & 1 deletion applications/tari_dan_app_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ tari_common_types = { workspace = true }
tari_core = { workspace = true, default-features = false, features = ["transactions"] }
tari_crypto = { workspace = true }
tari_shutdown = { workspace = true }

tari_dan_common_types = { workspace = true }
tari_state_store_sqlite = { workspace = true }
tari_dan_engine = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ use tari_crypto::tari_utilities::ByteArray;
use tari_dan_common_types::{services::template_provider::TemplateProvider, SubstateAddress};
use tari_dan_engine::{
fees::{FeeModule, FeeTable},
runtime::{AuthParams, RuntimeModule, VirtualSubstates},
runtime::{AuthParams, RuntimeModule},
state_store::{memory::MemoryStateStore, StateStoreError},
template::LoadedTemplate,
transaction::{TransactionError, TransactionProcessor},
};
use tari_dan_storage::consensus_models::ExecutedTransaction;
use tari_engine_types::commit_result::{ExecuteResult, FinalizeResult, RejectReason};
use tari_engine_types::{
commit_result::{ExecuteResult, FinalizeResult, RejectReason},
virtual_substate::VirtualSubstates,
};
use tari_template_lib::{crypto::RistrettoPublicKeyBytes, prelude::NonFungibleAddress};
use tari_transaction::Transaction;

const _LOG_TARGET: &str = "tari::dan::transaction_executor";

pub trait TransactionExecutor {
type Error: Send + Sync + 'static;
type Error: std::error::Error + Send + Sync + 'static;

fn execute(
&self,
Expand Down
40 changes: 24 additions & 16 deletions applications/tari_dan_wallet_daemon/src/handlers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tari_crypto::{
ristretto::{RistrettoComSig, RistrettoPublicKey},
tari_utilities::ByteArray,
};
use tari_dan_common_types::{optional::Optional, SubstateAddress};
use tari_dan_common_types::optional::Optional;
use tari_dan_wallet_sdk::{
apis::{jwt::JrpcPermission, key_manager, substate::ValidatorScanResult},
confidential::{get_commitment_factory, ConfidentialProofStatement},
Expand All @@ -37,7 +37,7 @@ use tari_template_lib::{
prelude::{ComponentAddress, ResourceType, CONFIDENTIAL_TARI_RESOURCE_ADDRESS},
Hash,
};
use tari_transaction::Transaction;
use tari_transaction::{SubstateRequirement, Transaction};
use tari_wallet_daemon_client::{
types::{
AccountGetDefaultRequest,
Expand Down Expand Up @@ -77,6 +77,7 @@ use crate::{
get_account_or_default,
get_account_with_inputs,
invalid_params,
wait_for_account_create_or_update,
wait_for_result,
},
indexer_jrpc_impl::IndexerJsonRpcNetworkInterface,
Expand Down Expand Up @@ -135,12 +136,12 @@ pub async fn handle_create(
.with_input_refs(
input_refs
.iter()
.map(|s| SubstateAddress::from_address(&s.substate_id, s.version)),
.map(|s| SubstateRequirement::new(s.substate_id.clone(), Some(s.version))),
)
.with_inputs(
inputs
.iter()
.map(|addr| SubstateAddress::from_address(&addr.substate_id, addr.version)),
.map(|addr| SubstateRequirement::new(addr.substate_id.clone(), Some(addr.version))),
)
.sign(&signing_key.key)
.build();
Expand Down Expand Up @@ -238,7 +239,7 @@ pub async fn handle_invoke(

let inputs = inputs
.into_iter()
.map(|s| SubstateAddress::from_address(&s.substate_id, s.version));
.map(|s| SubstateRequirement::new(s.substate_id.clone(), Some(s.version)));

let account_address = account.address.as_component_address().unwrap();
let transaction = Transaction::builder()
Expand Down Expand Up @@ -452,7 +453,7 @@ pub async fn handle_reveal_funds(

let inputs = inputs
.into_iter()
.map(|addr| SubstateAddress::from_address(&addr.substate_id, addr.version));
.map(|addr| SubstateRequirement::new(addr.substate_id.clone(), Some(addr.version)));

let transaction = builder.with_inputs(inputs).sign(&account_key.key).build();

Expand Down Expand Up @@ -655,7 +656,7 @@ pub async fn handle_claim_burn(
&account_public_key,
max_fee,
account_secret_key,
accounts_api,
&accounts_api,
context,
)
.await?;
Expand All @@ -676,7 +677,7 @@ async fn finish_claiming<T: WalletStore>(
account_public_key: &RistrettoPublicKey,
max_fee: Amount,
account_secret_key: DerivedKey<RistrettoPublicKey>,
accounts_api: tari_dan_wallet_sdk::apis::accounts::AccountsApi<'_, T>,
accounts_api: &tari_dan_wallet_sdk::apis::accounts::AccountsApi<'_, T>,
context: &HandlerContext,
) -> Result<
(
Expand Down Expand Up @@ -717,7 +718,7 @@ async fn finish_claiming<T: WalletStore>(
});
let inputs = inputs
.into_iter()
.map(|s| SubstateAddress::from_address(&s.substate_id, s.version));
.map(|s| SubstateRequirement::new(s.substate_id.clone(), Some(s.version)));
let transaction = Transaction::builder()
.with_fee_instructions(instructions)
.with_inputs(inputs)
Expand All @@ -735,15 +736,19 @@ async fn finish_claiming<T: WalletStore>(
}),
});
let finalized = wait_for_result(&mut events, tx_id).await?;
if let Some(reject) = finalized.finalize.result.reject() {
if let Some(reject) = finalized.finalize.reject() {
return Err(anyhow::anyhow!("Fee transaction rejected: {}", reject));
}
if let Some(reason) = finalized.finalize.reject() {
if let Some(reason) = finalized.finalize.full_reject() {
return Err(anyhow::anyhow!(
"Fee transaction succeeded (fees charged) however the transaction failed: {}",
reason
));
}

// Wait for the monitor to pick up the new or updated account
wait_for_account_create_or_update(&mut events, &account_address).await?;

Ok((tx_id, finalized))
}

Expand Down Expand Up @@ -791,19 +796,22 @@ pub async fn handle_create_free_test_coins(
// ------------------------------
let (tx_id, finalized) = finish_claiming(
instructions,
account_address,
account_address.clone(),
new_account_name,
sdk,
inputs,
&account_public_key,
max_fee,
account_secret_key,
accounts_api,
&accounts_api,
context,
)
.await?;

let account = accounts_api.get_account_by_address(&account_address)?;

Ok(AccountsCreateFreeTestCoinsResponse {
account,
transaction_id: tx_id,
amount,
fee: max_fee,
Expand Down Expand Up @@ -891,9 +899,9 @@ pub async fn handle_transfer(
.substate_api()
.scan_for_substate(&SubstateId::Resource(req.resource_address), None)
.await?;
let resource_substate_address = SubstateAddress::from_address(
&resource_substate.address.substate_id,
resource_substate.address.version,
let resource_substate_address = SubstateRequirement::new(
resource_substate.address.substate_id.clone(),
Some(resource_substate.address.version),
);
inputs.push(resource_substate.address);

Expand Down
19 changes: 19 additions & 0 deletions applications/tari_dan_wallet_daemon/src/handlers/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tari_dan_wallet_sdk::{
DanWalletSdk,
};
use tari_dan_wallet_storage_sqlite::SqliteWalletStore;
use tari_engine_types::substate::SubstateId;
use tari_transaction::TransactionId;
use tari_wallet_daemon_client::ComponentAddressOrName;
use tokio::sync::broadcast;
Expand Down Expand Up @@ -43,6 +44,24 @@ pub async fn wait_for_result(
}
}

pub async fn wait_for_account_create_or_update(
events: &mut broadcast::Receiver<WalletEvent>,
account_address: &SubstateId,
) -> Result<SubstateId, anyhow::Error> {
loop {
let wallet_event = events.recv().await?;
match wallet_event {
WalletEvent::AccountCreated(event) if event.account.address == *account_address => {
return Ok(event.account.address);
},
WalletEvent::AccountChanged(event) if event.account_address == *account_address => {
return Ok(event.account_address);
},
_ => {},
}
}
}

pub fn get_account_with_inputs(
account: Option<ComponentAddressOrName>,
sdk: &DanWalletSdk<SqliteWalletStore, IndexerJsonRpcNetworkInterface>,
Expand Down
3 changes: 1 addition & 2 deletions applications/tari_dan_wallet_daemon/src/handlers/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use anyhow::anyhow;
use log::info;
use tari_common_types::types::PublicKey;
use tari_crypto::{keys::PublicKey as PK, ristretto::RistrettoSecretKey, tari_utilities::ByteArray};
use tari_dan_common_types::SubstateAddress;
use tari_dan_wallet_sdk::{
apis::{jwt::JrpcPermission, key_manager},
models::Account,
Expand Down Expand Up @@ -260,7 +259,7 @@ async fn create_account_nft(
.await?;
let inputs = inputs
.iter()
.map(|addr| SubstateAddress::from_address(&addr.substate_id, addr.version))
.map(|addr| SubstateRequirement::new(addr.substate_id.clone(), Some(addr.version)))
.collect::<Vec<_>>();

let transaction = Transaction::builder()
Expand Down
50 changes: 33 additions & 17 deletions applications/tari_dan_wallet_daemon/src/services/account_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use tokio::{

use crate::{
notify::Notify,
services::{AccountChangedEvent, NewAccountInfo, Reply, WalletEvent},
services::{AccountChangedEvent, AccountCreatedEvent, NewAccountInfo, Reply, WalletEvent},
};

const LOG_TARGET: &str = "tari::dan::wallet_daemon::account_monitor";
Expand Down Expand Up @@ -134,7 +134,7 @@ where

if is_updated {
self.notify.notify(AccountChangedEvent {
account_address: account.address.clone(),
account_address: account.address,
});
} else {
info!(
Expand Down Expand Up @@ -185,14 +185,14 @@ where
.await
.optional()?;
let Some(ValidatorScanResult {
address: versioned_addr,
substate,
created_by_tx,
}) = scan_result
else {
warn!(target: LOG_TARGET, "Vault {} for account {} does not exist according to validator node", vault_addr, versioned_account_address);
continue;
};
address: versioned_addr,
substate,
created_by_tx,
}) = scan_result
else {
warn!(target: LOG_TARGET, "Vault {} for account {} does not exist according to validator node", vault_addr, versioned_account_address);
continue;
};

if let Some(vault_version) = maybe_vault_version {
// The first time a vault is found, know about the vault substate from the tx result but never added
Expand Down Expand Up @@ -324,20 +324,23 @@ where
let substate_api = self.wallet_sdk.substate_api();
let accounts_api = self.wallet_sdk.accounts_api();

if let Some(new_account) = self.pending_accounts.remove(&tx_id) {
let mut new_account = None;
if let Some(account) = self.pending_accounts.remove(&tx_id) {
// Filter for a _new_ account created in this transaction
let new_account_address =
find_new_account_address(diff).ok_or_else(|| AccountMonitorError::ExpectedNewAccount {
tx_id,
account_name: new_account.name.clone().unwrap_or_else(|| "<no-name>".to_string()),
account_name: account.name.clone().unwrap_or_else(|| "<no-name>".to_string()),
})?;

accounts_api.add_account(
new_account.name.as_deref(),
account.name.as_deref(),
new_account_address,
new_account.key_index,
new_account.is_default,
account.key_index,
account.is_default,
)?;

new_account = Some(accounts_api.get_account_by_address(new_account_address)?);
}

let mut vaults = diff
Expand Down Expand Up @@ -379,6 +382,7 @@ where
}
}

let mut updated_accounts = vec![];
// Process all existing vaults that belong to an account
for (vault_addr, substate) in vaults {
let vault_addr = SubstateId::Vault(vault_addr);
Expand Down Expand Up @@ -414,7 +418,20 @@ where

// Update the vault balance / confidential outputs
self.refresh_vault(&account_addr, vault, &nfts).await?;
updated_accounts.push(account_addr);
}

if let Some(account) = new_account {
self.notify.notify(AccountCreatedEvent {
account,
created_by_tx: tx_id,
});
} else {
for account_address in updated_accounts {
self.notify.notify(AccountChangedEvent { account_address });
}
}

Ok(())
}

Expand Down Expand Up @@ -494,8 +511,7 @@ where
WalletEvent::TransactionInvalid(event) => {
self.pending_accounts.remove(&event.transaction_id);
},
WalletEvent::AccountChanged(_) => {},
WalletEvent::AuthLoginRequest(_) => {},
WalletEvent::AccountCreated(_) | WalletEvent::AccountChanged(_) | WalletEvent::AuthLoginRequest(_) => {},
}
Ok(())
}
Expand Down
Loading

0 comments on commit b5b5b2d

Please sign in to comment.