Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet): using correct network #1249

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion applications/tari_dan_wallet_daemon/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -48,6 +53,8 @@ impl ApplicationConfig {
#[allow(clippy::struct_excessive_bools)]
pub struct WalletDaemonConfig {
override_from: Option<String>,
/// Network that is used to send transactions.
pub network: Network,
/// The wallet daemon listening address
pub json_rpc_address: Option<SocketAddr>,
/// The jrpc address where the UI should connect (it can be the same as the json_rpc_addr, but doesn't have to be),
Expand Down Expand Up @@ -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))),
Expand Down
12 changes: 7 additions & 5 deletions applications/tari_dan_wallet_daemon/src/handlers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())?;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -693,7 +695,7 @@ async fn finish_claiming<T: WalletStore>(
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);
Expand Down Expand Up @@ -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])
Expand Down
8 changes: 7 additions & 1 deletion applications/tari_dan_wallet_daemon/src/handlers/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -150,3 +151,8 @@ pub(super) fn invalid_params<T: Display>(field: &str, details: Option<T>) -> 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())
}
6 changes: 3 additions & 3 deletions applications/tari_dan_wallet_daemon/src/handlers/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions applications/tari_dan_wallet_daemon/src/handlers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -45,7 +48,7 @@ pub async fn handle_submit_instruction(
token: Option<String>,
req: CallInstructionRequest,
) -> Result<TransactionSubmitResponse, anyhow::Error> {
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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()?,
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_dan_wallet_daemon/src/handlers/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion applications/tari_dan_wallet_daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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"));

Expand Down
14 changes: 11 additions & 3 deletions applications/tari_validator_node/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -658,9 +664,11 @@ where
}

fn create_mempool_transaction_validator(
network: Network,
template_manager: TemplateManager<PeerAddress>,
) -> impl Validator<Transaction, Context = (), Error = TransactionValidationError> {
HasInputs::new()
TransactionNetworkValidator::new(network)
.and_then(HasInputs::new())
.and_then(TemplateExistsValidator::new(template_manager))
.and_then(FeeTransactionValidator)
}
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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),
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ mod claim_fee_instructions;
mod epoch_range;
mod fee;
mod has_inputs;
mod network;
mod signature;
mod template_exists;

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::*;

Expand Down
Loading
Loading