From cc5334be07799d34c2d52edd789104eee85d3211 Mon Sep 17 00:00:00 2001 From: ksrichard Date: Fri, 17 Jan 2025 15:04:33 +0100 Subject: [PATCH 1/4] using the correct network --- .../tari_dan_wallet_daemon/src/config.rs | 10 +- .../src/handlers/accounts.rs | 12 +- .../src/handlers/helpers.rs | 8 +- .../src/handlers/nfts.rs | 6 +- .../src/handlers/transaction.rs | 13 ++- .../src/handlers/validator.rs | 4 +- .../tari_dan_wallet_daemon/src/main.rs | 6 +- .../tari_validator_node/src/bootstrap.rs | 14 ++- .../src/transaction_validators/error.rs | 5 + .../src/transaction_validators/mod.rs | 2 + .../src/transaction_validators/network.rs | 105 ++++++++++++++++++ dan_layer/engine_types/src/substate.rs | 27 +++-- 12 files changed, 180 insertions(+), 32 deletions(-) create mode 100644 applications/tari_validator_node/src/transaction_validators/network.rs diff --git a/applications/tari_dan_wallet_daemon/src/config.rs b/applications/tari_dan_wallet_daemon/src/config.rs index 3f6e160c7c..65e650ad43 100644 --- a/applications/tari_dan_wallet_daemon/src/config.rs +++ b/applications/tari_dan_wallet_daemon/src/config.rs @@ -24,7 +24,12 @@ use std::{net::SocketAddr, path::PathBuf, time::Duration}; use config::Config; use serde::{Deserialize, Serialize}; -use tari_common::{configuration::CommonConfig, ConfigurationError, DefaultConfigLoader, SubConfigPath}; +use tari_common::{ + configuration::{CommonConfig, Network}, + ConfigurationError, + DefaultConfigLoader, + SubConfigPath, +}; use tari_dan_common_types::crypto::create_secret; #[derive(Debug, Clone)] @@ -48,6 +53,8 @@ impl ApplicationConfig { #[allow(clippy::struct_excessive_bools)] pub struct WalletDaemonConfig { override_from: Option, + /// Network that is used to send transactions. + pub network: Network, /// The wallet daemon listening address pub json_rpc_address: Option, /// The jrpc address where the UI should connect (it can be the same as the json_rpc_addr, but doesn't have to be), @@ -76,6 +83,7 @@ impl Default for WalletDaemonConfig { fn default() -> Self { Self { override_from: None, + network: Default::default(), json_rpc_address: Some(SocketAddr::from(([127u8, 0, 0, 1], 9000))), ui_connect_address: None, signaling_server_address: Some(SocketAddr::from(([127u8, 0, 0, 1], 9100))), diff --git a/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs b/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs index f05500feee..d6192c7fa9 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs @@ -76,6 +76,7 @@ use crate::{ get_account_or_default, get_account_with_inputs, invalid_params, + transaction_builder, wait_for_result, wait_for_result_and_account, }, @@ -122,7 +123,7 @@ pub async fn handle_create( ); let max_fee = req.max_fee.unwrap_or(DEFAULT_FEE); - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .fee_transaction_pay_from_component(default_account.address.as_component_address().unwrap(), max_fee) .create_account(owner_pk.clone()) .with_inputs(inputs) @@ -222,7 +223,7 @@ pub async fn handle_invoke( .map(|s| SubstateRequirement::new(s.substate_id.clone(), Some(s.version))); let account_address = account.address.as_component_address().unwrap(); - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .fee_transaction_pay_from_component(account_address, req.max_fee.unwrap_or(DEFAULT_FEE)) .call_method(account_address, &req.method, req.args) .with_inputs(inputs) @@ -323,6 +324,7 @@ pub async fn handle_reveal_funds( // If the caller aborts the request early, this async block would be aborted at any await point. To avoid this, we // spawn a task that will continue running. + let ctx = context.clone(); task::spawn(async move { let account = get_account_or_default(req.account, &sdk.accounts_api())?; @@ -387,7 +389,7 @@ pub async fn handle_reveal_funds( let account_address = account.address.as_component_address().unwrap(); - let mut builder = Transaction::builder(); + let mut builder = transaction_builder(&ctx); if req.pay_fee_from_reveal { builder = builder.with_fee_instructions(vec![ Instruction::CallMethod { @@ -693,7 +695,7 @@ async fn finish_claiming( method: "pay_fee".to_string(), args: args![max_fee], }); - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .with_fee_instructions(instructions) .with_inputs(inputs) .build_and_seal(&account_secret_key.key); @@ -941,7 +943,7 @@ pub async fn handle_transfer( .key_manager_api() .derive_key(key_manager::TRANSACTION_BRANCH, account.key_index)?; - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .with_fee_instructions(fee_instructions) .with_instructions(instructions) .with_inputs(vec![resource_substate_address]) diff --git a/applications/tari_dan_wallet_daemon/src/handlers/helpers.rs b/applications/tari_dan_wallet_daemon/src/handlers/helpers.rs index 87542a7bcc..5ecce58466 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/helpers.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/helpers.rs @@ -11,11 +11,12 @@ use tari_dan_wallet_sdk::{ }; use tari_dan_wallet_storage_sqlite::SqliteWalletStore; use tari_engine_types::substate::SubstateId; -use tari_transaction::TransactionId; +use tari_transaction::{Transaction, TransactionBuilder, TransactionId}; use tari_wallet_daemon_client::ComponentAddressOrName; use tokio::sync::broadcast; use crate::{ + handlers::HandlerContext, indexer_jrpc_impl::IndexerJsonRpcNetworkInterface, services::{TransactionFinalizedEvent, WalletEvent}, }; @@ -150,3 +151,8 @@ pub(super) fn invalid_params(field: &str, details: Option) -> any ) .into() } + +/// Returns a TransactionBuilder with the current network configured. +pub fn transaction_builder(context: &HandlerContext) -> TransactionBuilder { + Transaction::builder().for_network(context.config().network.as_byte()) +} diff --git a/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs b/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs index 64bc087713..3953e8ae1d 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs @@ -32,7 +32,7 @@ use tokio::sync::broadcast; use super::{context::HandlerContext, helpers::get_account_or_default}; use crate::{ - handlers::helpers::get_account, + handlers::helpers::{get_account, transaction_builder}, services::{TransactionFinalizedEvent, WalletEvent}, DEFAULT_FEE, }; @@ -207,7 +207,7 @@ async fn mint_account_nft( }, ]; - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .fee_transaction_pay_from_component(account.address.as_component_address().unwrap(), fee) .with_instructions(instructions) .build_and_seal(owner_sk); @@ -249,7 +249,7 @@ async fn create_account_nft( .locate_dependent_substates(&[account.address.clone()]) .await?; - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .fee_transaction_pay_from_component(account.address.as_component_address().unwrap(), fee) .call_function(ACCOUNT_NFT_TEMPLATE_ADDRESS, "create", args![owner_token,]) .with_inputs(inputs) diff --git a/applications/tari_dan_wallet_daemon/src/handlers/transaction.rs b/applications/tari_dan_wallet_daemon/src/handlers/transaction.rs index 881eef52ca..c3ae14459e 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/transaction.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/transaction.rs @@ -34,7 +34,10 @@ use tokio::time; use super::{accounts, context::HandlerContext}; use crate::{ - handlers::{helpers::get_account_or_default, HandlerError}, + handlers::{ + helpers::{get_account_or_default, transaction_builder}, + HandlerError, + }, services::WalletEvent, }; @@ -45,7 +48,7 @@ pub async fn handle_submit_instruction( token: Option, req: CallInstructionRequest, ) -> Result { - let mut builder = Transaction::builder().with_instructions(req.instructions); + let mut builder = transaction_builder(context).with_instructions(req.instructions); if let Some(dump_account) = req.dump_outputs_into { let AccountGetResponse { @@ -130,7 +133,7 @@ pub async fn handle_submit( req.detect_inputs_use_unversioned, ); - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .with_unsigned_transaction(req.transaction) .with_inputs(detected_inputs) .build_and_seal(&key.key); @@ -183,7 +186,7 @@ pub async fn handle_submit_dry_run( vec![] }; - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .with_unsigned_transaction(req.transaction) .with_inputs(detected_inputs) .build_and_seal(&key.key); @@ -381,7 +384,7 @@ pub async fn handle_publish_template( let fee_account = get_account_or_default(req.fee_account, &sdk.accounts_api())?; - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .fee_transaction_pay_from_component( fee_account.address.as_component_address().unwrap(), req.max_fee.try_into()?, diff --git a/applications/tari_dan_wallet_daemon/src/handlers/validator.rs b/applications/tari_dan_wallet_daemon/src/handlers/validator.rs index 31e62c2eaa..ddb1938326 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/validator.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/validator.rs @@ -16,7 +16,7 @@ use tari_wallet_daemon_client::types::{ use crate::{ handlers::{ - helpers::{get_account_with_inputs, wait_for_result}, + helpers::{get_account_with_inputs, transaction_builder, wait_for_result}, HandlerContext, }, DEFAULT_FEE, @@ -74,7 +74,7 @@ pub async fn handle_claim_validator_fees( .key_manager_api() .derive_key(key_manager::TRANSACTION_BRANCH, account.key_index)?; - let transaction = Transaction::builder() + let transaction = transaction_builder(context) .with_fee_instructions(fee_instructions) .build_and_seal(&account_secret_key.key); diff --git a/applications/tari_dan_wallet_daemon/src/main.rs b/applications/tari_dan_wallet_daemon/src/main.rs index 25c7f3eafc..812ec030aa 100644 --- a/applications/tari_dan_wallet_daemon/src/main.rs +++ b/applications/tari_dan_wallet_daemon/src/main.rs @@ -43,7 +43,7 @@ async fn main() -> Result<(), anyhow::Error> { let config_path = cli.common.config_path(); let cfg = load_configuration(config_path, true, &cli, cli.common.network)?; - let config = ApplicationConfig::load_from(&cfg)?; + let mut config = ApplicationConfig::load_from(&cfg)?; if let Some(index) = cli.derive_secret { let sdk = initialize_wallet_sdk(&config)?; @@ -55,6 +55,10 @@ async fn main() -> Result<(), anyhow::Error> { return Ok(()); } + if let Some(network) = cli.common.network { + config.dan_wallet_daemon.network = network; + } + // Remove the file if it was left behind by a previous run let _file = fs::remove_file(config.common.base_path.join("pid")); diff --git a/applications/tari_validator_node/src/bootstrap.rs b/applications/tari_validator_node/src/bootstrap.rs index a9637b1748..d491b5e8a1 100644 --- a/applications/tari_validator_node/src/bootstrap.rs +++ b/applications/tari_validator_node/src/bootstrap.rs @@ -121,7 +121,13 @@ use crate::{ NopLogger, }, substate_resolver::TariSubstateResolver, - transaction_validators::{FeeTransactionValidator, HasInputs, TemplateExistsValidator, TransactionValidationError}, + transaction_validators::{ + FeeTransactionValidator, + HasInputs, + TemplateExistsValidator, + TransactionNetworkValidator, + TransactionValidationError, + }, validator::Validator, validator_registration_file::ValidatorRegistrationFile, virtual_substate::VirtualSubstateManager, @@ -337,7 +343,7 @@ pub async fn spawn_services( let (mempool, join_handle) = mempool::spawn( epoch_manager.clone(), - create_mempool_transaction_validator(template_manager.clone()), + create_mempool_transaction_validator(config.network, template_manager.clone()), state_store.clone(), consensus_handle.clone(), networking.clone(), @@ -658,9 +664,11 @@ where } fn create_mempool_transaction_validator( + network: Network, template_manager: TemplateManager, ) -> impl Validator { - HasInputs::new() + TransactionNetworkValidator::new(network) + .and_then(HasInputs::new()) .and_then(TemplateExistsValidator::new(template_manager)) .and_then(FeeTransactionValidator) } diff --git a/applications/tari_validator_node/src/transaction_validators/error.rs b/applications/tari_validator_node/src/transaction_validators/error.rs index 067d9eb66d..2b14bad8b0 100644 --- a/applications/tari_validator_node/src/transaction_validators/error.rs +++ b/applications/tari_validator_node/src/transaction_validators/error.rs @@ -1,6 +1,7 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause +use tari_common::{configuration::Network, ConfigurationError}; use tari_dan_app_utilities::template_manager::interface::TemplateManagerError; use tari_dan_common_types::Epoch; use tari_dan_storage::{consensus_models::TransactionPoolError, StorageError}; @@ -44,4 +45,8 @@ pub enum TransactionValidationError { TransactionNotSigned { transaction_id: TransactionId }, #[error("Network error: {0}")] NetworkingError(#[from] NetworkingError), + #[error("Unknown network byte \"{0:?}\": {1}")] + UnknownNetwork(u8, ConfigurationError), + #[error("Network mismatch! Current network: {0}, Transaction network: {1}")] + NetworkMismatch(Network, Network), } diff --git a/applications/tari_validator_node/src/transaction_validators/mod.rs b/applications/tari_validator_node/src/transaction_validators/mod.rs index ff6a9140ed..e1f535516d 100644 --- a/applications/tari_validator_node/src/transaction_validators/mod.rs +++ b/applications/tari_validator_node/src/transaction_validators/mod.rs @@ -5,6 +5,7 @@ mod claim_fee_instructions; mod epoch_range; mod fee; mod has_inputs; +mod network; mod signature; mod template_exists; @@ -12,6 +13,7 @@ pub use claim_fee_instructions::*; pub use epoch_range::*; pub use fee::*; pub use has_inputs::*; +pub use network::*; pub use signature::*; pub use template_exists::*; diff --git a/applications/tari_validator_node/src/transaction_validators/network.rs b/applications/tari_validator_node/src/transaction_validators/network.rs new file mode 100644 index 0000000000..6ae1d64dcc --- /dev/null +++ b/applications/tari_validator_node/src/transaction_validators/network.rs @@ -0,0 +1,105 @@ +// Copyright 2025 The Tari Project +// SPDX-License-Identifier: BSD-3-Clause + +use log::warn; +use tari_common::configuration::Network; +use tari_transaction::Transaction; + +use crate::{transaction_validators::TransactionValidationError, validator::Validator}; + +const LOG_TARGET: &str = "tari::dan::mempool::validators::network"; + +#[derive(Debug)] +pub struct TransactionNetworkValidator { + network: Network, +} + +impl TransactionNetworkValidator { + pub fn new(network: Network) -> Self { + Self { network } + } +} + +impl Validator for TransactionNetworkValidator { + type Context = (); + type Error = TransactionValidationError; + + fn validate(&self, _context: &Self::Context, input: &Transaction) -> Result<(), Self::Error> { + match input { + Transaction::V1(tx) => { + let tx_network = Network::try_from(tx.network()) + .map_err(|error| Self::Error::UnknownNetwork(tx.network(), error))?; + if tx_network == self.network { + Ok(()) + } else { + warn!(target: LOG_TARGET, "TransactionNetworkValidator - FAIL: mismatching networks: TX: {} != Current: {}", tx_network, self.network); + Err(Self::Error::NetworkMismatch(self.network, tx_network)) + } + }, + } + } +} + +#[cfg(test)] +mod tests { + use indexmap::IndexSet; + use tari_common::configuration::Network; + use tari_common_types::types::{PublicKey, Signature}; + use tari_transaction::{ + Transaction, + TransactionSealSignature, + TransactionSignature, + UnsealedTransactionV1, + UnsignedTransactionV1, + }; + + use crate::{ + transaction_validators::{TransactionNetworkValidator, TransactionValidationError}, + validator::Validator, + }; + + fn tx(network_byte: u8) -> Transaction { + Transaction::new( + UnsealedTransactionV1::new( + UnsignedTransactionV1::new(network_byte, vec![], vec![], IndexSet::new(), None, None), + vec![TransactionSignature::new(PublicKey::default(), Signature::default())], + ), + TransactionSealSignature::new(PublicKey::default(), Signature::default()), + ) + } + + #[test] + fn unknown_network() { + let network_byte = 9u8; + let validator = TransactionNetworkValidator::new(Network::LocalNet); + let tx = tx(network_byte); + let result = validator.validate(&(), &tx); + assert!(result.is_err()); + assert!(matches!( + result.err().unwrap(), + TransactionValidationError::UnknownNetwork(_, _) + )); + } + + #[test] + fn network_mismatch() { + let network_byte = Network::MainNet.as_byte(); + let validator = TransactionNetworkValidator::new(Network::LocalNet); + let tx = tx(network_byte); + let result = validator.validate(&(), &tx); + assert!(result.is_err()); + assert!(matches!( + result.err().unwrap(), + TransactionValidationError::NetworkMismatch(_, _) + )); + } + + #[test] + fn network_ok() { + let network_byte = Network::LocalNet.as_byte(); + let validator = TransactionNetworkValidator::new(Network::LocalNet); + let tx = tx(network_byte); + let result = validator.validate(&(), &tx); + assert!(result.is_ok()); + } +} diff --git a/dan_layer/engine_types/src/substate.rs b/dan_layer/engine_types/src/substate.rs index c5b7599220..6e0f0e7e1d 100644 --- a/dan_layer/engine_types/src/substate.rs +++ b/dan_layer/engine_types/src/substate.rs @@ -32,8 +32,13 @@ use tari_bor::{decode, decode_exact, encode, BorError}; use tari_common_types::types::FixedHash; use tari_template_lib::{ models::{ - ComponentAddress, NonFungibleAddress, NonFungibleIndexAddress, ObjectKey, ResourceAddress, - UnclaimedConfidentialOutputAddress, VaultId, + ComponentAddress, + NonFungibleAddress, + NonFungibleIndexAddress, + ObjectKey, + ResourceAddress, + UnclaimedConfidentialOutputAddress, + VaultId, }, prelude::PUBLIC_IDENTITY_RESOURCE_ADDRESS, Hash, @@ -163,15 +168,15 @@ impl SubstateId { /// Returns true for any substate that has is "versionable" i.e. can have a version > 0, otherwise false. pub fn is_versioned(&self) -> bool { match self { - SubstateId::Component(_) - | SubstateId::Resource(_) - | SubstateId::Vault(_) - | SubstateId::NonFungibleIndex(_) - | SubstateId::Template(_) - | SubstateId::NonFungible(_) => true, - SubstateId::UnclaimedConfidentialOutput(_) - | SubstateId::TransactionReceipt(_) - | SubstateId::FeeClaim(_) => false, + SubstateId::Component(_) | + SubstateId::Resource(_) | + SubstateId::Vault(_) | + SubstateId::NonFungibleIndex(_) | + SubstateId::Template(_) | + SubstateId::NonFungible(_) => true, + SubstateId::UnclaimedConfidentialOutput(_) | + SubstateId::TransactionReceipt(_) | + SubstateId::FeeClaim(_) => false, } } From ae6d15ec5420e1bdb38a9029c7b5ad25d5febab4 Mon Sep 17 00:00:00 2001 From: ksrichard Date: Mon, 20 Jan 2025 08:41:47 +0100 Subject: [PATCH 2/4] small update --- integration_tests/src/wallet_daemon.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration_tests/src/wallet_daemon.rs b/integration_tests/src/wallet_daemon.rs index 6b0b672967..4e213215f4 100644 --- a/integration_tests/src/wallet_daemon.rs +++ b/integration_tests/src/wallet_daemon.rs @@ -26,7 +26,7 @@ use std::{ }; use reqwest::Url; -use tari_common::configuration::CommonConfig; +use tari_common::configuration::{CommonConfig, Network}; use tari_dan_wallet_daemon::{ config::{ApplicationConfig, WalletDaemonConfig}, run_tari_dan_wallet_daemon, @@ -78,6 +78,7 @@ pub async fn spawn_wallet_daemon(world: &mut TariWorld, wallet_daemon_name: Stri config.dan_wallet_daemon.json_rpc_address = Some(json_rpc_address); config.dan_wallet_daemon.signaling_server_address = Some(signaling_server_addr); config.dan_wallet_daemon.indexer_node_json_rpc_url = indexer_url; + config.dan_wallet_daemon.network = Network::LocalNet; let handle = task::spawn(run_tari_dan_wallet_daemon(config, shutdown_signal)); From 51e95f4fed3207671487219d1ecdc29baba53457 Mon Sep 17 00:00:00 2001 From: ksrichard Date: Mon, 20 Jan 2025 08:49:06 +0100 Subject: [PATCH 3/4] clippy --- applications/tari_dan_wallet_daemon/src/handlers/accounts.rs | 1 - applications/tari_dan_wallet_daemon/src/handlers/nfts.rs | 2 +- applications/tari_dan_wallet_daemon/src/handlers/transaction.rs | 1 - applications/tari_dan_wallet_daemon/src/handlers/validator.rs | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs b/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs index d6192c7fa9..2f01018e3f 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs @@ -36,7 +36,6 @@ use tari_template_lib::{ models::{Amount, UnclaimedConfidentialOutputAddress}, prelude::CONFIDENTIAL_TARI_RESOURCE_ADDRESS, }; -use tari_transaction::Transaction; use tari_wallet_daemon_client::{ types::{ AccountGetDefaultRequest, diff --git a/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs b/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs index 3953e8ae1d..11b3b914e6 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs @@ -19,7 +19,7 @@ use tari_template_lib::{ crypto::RistrettoPublicKeyBytes, prelude::{Amount, ComponentAddress, Metadata, NonFungibleAddress, NonFungibleId, ResourceAddress}, }; -use tari_transaction::{Transaction, TransactionId}; +use tari_transaction::TransactionId; use tari_wallet_daemon_client::types::{ GetAccountNftRequest, GetAccountNftResponse, diff --git a/applications/tari_dan_wallet_daemon/src/handlers/transaction.rs b/applications/tari_dan_wallet_daemon/src/handlers/transaction.rs index c3ae14459e..dfdb8d5984 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/transaction.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/transaction.rs @@ -10,7 +10,6 @@ use tari_dan_app_utilities::json_encoding; use tari_dan_common_types::{optional::Optional, Epoch, SubstateRequirement}; use tari_dan_wallet_sdk::apis::{jwt::JrpcPermission, key_manager}; use tari_template_lib::{args, models::Amount}; -use tari_transaction::Transaction; use tari_wallet_daemon_client::types::{ AccountGetRequest, AccountGetResponse, diff --git a/applications/tari_dan_wallet_daemon/src/handlers/validator.rs b/applications/tari_dan_wallet_daemon/src/handlers/validator.rs index ddb1938326..fd36165122 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/validator.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/validator.rs @@ -6,7 +6,6 @@ use log::*; use tari_dan_wallet_sdk::apis::{jwt::JrpcPermission, key_manager}; use tari_engine_types::instruction::Instruction; use tari_template_lib::args; -use tari_transaction::Transaction; use tari_wallet_daemon_client::types::{ ClaimValidatorFeesRequest, ClaimValidatorFeesResponse, From d88fcb6ea3480bd927bb47ed99069a65fb91c334 Mon Sep 17 00:00:00 2001 From: ksrichard Date: Thu, 23 Jan 2025 12:05:06 +0100 Subject: [PATCH 4/4] changed network mismatch error --- .../tari_dan_wallet_daemon/src/handlers/accounts.rs | 2 +- applications/tari_dan_wallet_daemon/src/handlers/nfts.rs | 3 +-- .../src/transaction_validators/error.rs | 4 ++-- .../src/transaction_validators/network.rs | 7 +++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs b/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs index 098d07f0ff..c7e2e884bd 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/accounts.rs @@ -75,8 +75,8 @@ use crate::{ get_account_or_default, get_account_with_inputs, invalid_params, - transaction_builder, not_found, + transaction_builder, wait_for_result, wait_for_result_and_account, }, diff --git a/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs b/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs index 628627bcdf..e6e044ae51 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/nfts.rs @@ -30,9 +30,8 @@ use tokio::sync::broadcast; use super::{context::HandlerContext, helpers::get_account_or_default}; use crate::{ - handlers::helpers::{application, get_account}, + handlers::helpers::{application, get_account, transaction_builder}, jrpc_server::ApplicationErrorCode, - handlers::helpers::{get_account, transaction_builder}, services::{TransactionFinalizedEvent, WalletEvent}, DEFAULT_FEE, }; diff --git a/applications/tari_validator_node/src/transaction_validators/error.rs b/applications/tari_validator_node/src/transaction_validators/error.rs index 2b14bad8b0..4edfbf236b 100644 --- a/applications/tari_validator_node/src/transaction_validators/error.rs +++ b/applications/tari_validator_node/src/transaction_validators/error.rs @@ -47,6 +47,6 @@ pub enum TransactionValidationError { NetworkingError(#[from] NetworkingError), #[error("Unknown network byte \"{0:?}\": {1}")] UnknownNetwork(u8, ConfigurationError), - #[error("Network mismatch! Current network: {0}, Transaction network: {1}")] - NetworkMismatch(Network, Network), + #[error("Network mismatch! Current network: {actual}, Transaction network: {expected}")] + NetworkMismatch { actual: Network, expected: Network }, } diff --git a/applications/tari_validator_node/src/transaction_validators/network.rs b/applications/tari_validator_node/src/transaction_validators/network.rs index 6ae1d64dcc..35874219d7 100644 --- a/applications/tari_validator_node/src/transaction_validators/network.rs +++ b/applications/tari_validator_node/src/transaction_validators/network.rs @@ -33,7 +33,10 @@ impl Validator for TransactionNetworkValidator { Ok(()) } else { warn!(target: LOG_TARGET, "TransactionNetworkValidator - FAIL: mismatching networks: TX: {} != Current: {}", tx_network, self.network); - Err(Self::Error::NetworkMismatch(self.network, tx_network)) + Err(Self::Error::NetworkMismatch { + actual: self.network, + expected: tx_network, + }) } }, } @@ -90,7 +93,7 @@ mod tests { assert!(result.is_err()); assert!(matches!( result.err().unwrap(), - TransactionValidationError::NetworkMismatch(_, _) + TransactionValidationError::NetworkMismatch { actual: _, expected: _ }, )); }