Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Jul 31, 2024
1 parent e9bd7cc commit 8fdb9fd
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 69 deletions.
36 changes: 22 additions & 14 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,22 +1268,28 @@ pub async fn command_runner(
println!();
},
PreMineSpendBackupUtxo(args) => {
let commitment = if let Ok(val) = Commitment::from_hex(&args.commitment) {
val
} else {
eprintln!("\nError: Invalid 'commitment' provided!\n");
continue;
};
let hash = if let Ok(val) = FixedHash::from_hex(&args.output_hash) {
val
} else {
eprintln!("\nError: Invalid 'output_hash' provided!\n");
continue;
match key_manager_service.get_wallet_type().await {
WalletType::Ledger(_) => {},
_ => {
eprintln!("\nError: Wallet type must be 'Ledger' to spend pre-mine outputs!\n");
break;
},
}

let embedded_output = match get_embedded_pre_mine_outputs(vec![args.output_index]) {
Ok(outputs) => outputs[0].clone(),
Err(e) => {
eprintln!("\nError: {}\n", e);
break;
},
};
let commitment = embedded_output.commitment.clone();
let output_hash = embedded_output.hash();

match spend_backup_pre_mine_utxo(
transaction_service.clone(),
args.fee_per_gram,
hash,
output_hash,
commitment.clone(),
args.recipient_address,
)
Expand All @@ -1294,10 +1300,12 @@ pub async fn command_runner(
println!("Spend utxo: {} with tx_id: {}", commitment.to_hex(), tx_id);
println!();
},
Err(e) => eprintln!("\nError:Spent pre-mine transaction error! {}\n", e),
Err(e) => {
eprintln!("\nError: Spent pre-mine transaction error! {}\n", e);
break;
},
}
},
PreMineCreatePartyDetails(args) => {
PreMineSpendPartyDetails(args) => {
match key_manager_service.get_wallet_type().await {
WalletType::Ledger(_) => {},
Expand Down
4 changes: 1 addition & 3 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ pub struct PreMineSpendBackupUtxoArgs {
#[clap(long)]
pub fee_per_gram: MicroMinotari,
#[clap(long)]
pub commitment: String,
#[clap(long)]
pub output_hash: String,
pub output_index: usize,
#[clap(long)]
pub recipient_address: TariAddress,
}
Expand Down
8 changes: 3 additions & 5 deletions applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use tari_comms::{
use tari_core::{
consensus::ConsensusManager,
transactions::{
key_manager::{TariKeyId, TransactionKeyManagerInterface},
key_manager::{TariKeyId, TransactionKeyManagerInterface, LEDGER_NOT_SUPPORTED},
transaction_components::TransactionError,
CryptoFactories,
},
Expand Down Expand Up @@ -576,9 +576,7 @@ pub async fn start_wallet(
{
return Err(ExitError::new(
ExitCode::WalletError,
"Ledger is not supported in this build, please enable the \"ledger\" feature for console wallet and \
core"
.to_string(),
format!("{}", LEDGER_NOT_SUPPORTED),
));
}

Expand All @@ -591,7 +589,7 @@ pub async fn start_wallet(
match wallet.key_manager_service.get_public_key_at_key_id(&key_id).await {
Ok(public_key) => {},
Err(e) => {
if e.to_string().contains("Ledger is not supported in this build") {
if e.to_string().contains(LEDGER_NOT_SUPPORTED) {
return Err(ExitError::new(ExitCode::WalletError, format!(" {}", e)));
}
},
Expand Down
3 changes: 2 additions & 1 deletion applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ fn force_exit_for_pre_mine_commands(command: &CliCommands) -> bool {
CliCommands::PreMineSpendEncumberAggregateUtxo(_) |
CliCommands::PreMineSpendAggregateTransaction(_) |
CliCommands::PreMineSpendPartyDetails(_) |
CliCommands::PreMineSpendInputOutputSigs(_)
CliCommands::PreMineSpendInputOutputSigs(_) |
CliCommands::PreMineSpendBackupUtxo(_)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn main() {
let index = OsRng.next_u64();

for branch in &[
TransactionKeyManagerBranch::SenderOffsetLedger,
TransactionKeyManagerBranch::OneSidedSenderOffset,
TransactionKeyManagerBranch::Spend,
TransactionKeyManagerBranch::RandomKey,
TransactionKeyManagerBranch::PreMine,
Expand Down
12 changes: 6 additions & 6 deletions base_layer/common_types/src/key_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl TransactionKeyManagerBranch {
Some(Branch::Nonce) => Some(TransactionKeyManagerBranch::Nonce),
Some(Branch::KernelNonce) => Some(TransactionKeyManagerBranch::KernelNonce),
Some(Branch::SenderOffset) => Some(TransactionKeyManagerBranch::SenderOffset),
Some(Branch::SenderOffsetLedger) => Some(TransactionKeyManagerBranch::SenderOffsetLedger),
Some(Branch::OneSidedSenderOffset) => Some(TransactionKeyManagerBranch::OneSidedSenderOffset),
Some(Branch::Spend) => Some(TransactionKeyManagerBranch::Spend),
Some(Branch::RandomKey) => Some(TransactionKeyManagerBranch::RandomKey),
Some(Branch::PreMine) => Some(TransactionKeyManagerBranch::PreMine),
Expand All @@ -119,10 +119,10 @@ mod test {
KERNEL_NONCE,
METADATA_EPHEMERAL_NONCE,
NONCE,
ONE_SIDED_SENDER_OFFSET,
PRE_MINE,
RANDOM_KEY,
SENDER_OFFSET,
SENDER_OFFSET_LEDGER,
},
WALLET_COMMS_AND_SPEND_KEY_BRANCH,
};
Expand Down Expand Up @@ -158,9 +158,9 @@ mod test {
SENDER_OFFSET,
),
(
Branch::SenderOffsetLedger as u8,
TransactionKeyManagerBranch::SenderOffsetLedger,
SENDER_OFFSET_LEDGER,
Branch::OneSidedSenderOffset as u8,
TransactionKeyManagerBranch::OneSidedSenderOffset,
ONE_SIDED_SENDER_OFFSET,
),
(
Branch::Spend as u8,
Expand Down Expand Up @@ -213,7 +213,7 @@ mod test {
assert_eq!(&branch.get_branch_key(), *key);
assert_eq!(TransactionKeyManagerBranch::from_key(key), *branch);
},
TransactionKeyManagerBranch::SenderOffsetLedger => {
TransactionKeyManagerBranch::OneSidedSenderOffset => {
assert_eq!(branch.as_byte(), *expected_byte);
assert_eq!(TransactionKeyManagerBranch::from_byte(*expected_byte), Some(*branch));
assert_eq!(&branch.get_branch_key(), *key);
Expand Down
65 changes: 33 additions & 32 deletions base_layer/core/src/transactions/key_manager/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const LOG_TARGET: &str = "c::bn::key_manager::key_manager_service";
const TRANSACTION_KEY_MANAGER_MAX_SEARCH_DEPTH: u64 = 1_000_000;
const HASHER_LABEL_STEALTH_KEY: &str = "script key";

pub const LEDGER_NOT_SUPPORTED: &str = "Ledger is not supported in this build, please enable the \"ledger\" feature.";

use crate::{
common::ConfidentialOutputHasher,
one_sided::diffie_hellman_stealth_domain_hasher,
Expand Down Expand Up @@ -188,12 +190,12 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
pub async fn get_random_key(&self) -> Result<KeyAndId<PublicKey>, KeyManagerServiceError> {
match &self.wallet_type {
WalletType::Ledger(ledger) => {
debug!(target: LOG_TARGET, "get_random_key: wallet type {}", self.wallet_type);
debug!(target: LOG_TARGET, "get_random_key: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
Err(KeyManagerServiceError::LedgerError(format!(
"Ledger {} is not supported in this build, please enable the \"ledger\" feature for core",
ledger
"{} 'get_random_key' was called. ({})",
LEDGER_NOT_SUPPORTED, ledger
)))
}
#[cfg(feature = "ledger")]
Expand Down Expand Up @@ -240,13 +242,13 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
if let WalletType::Ledger(ledger) = &self.wallet_type {
match TransactionKeyManagerBranch::from_key(branch) {
TransactionKeyManagerBranch::OneSidedSenderOffset | TransactionKeyManagerBranch::RandomKey => {
debug!(target: LOG_TARGET, "get_public_key_at_key_id: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
Err(KeyManagerServiceError::LedgerError(
"Ledger is not supported in this build, please enable the \"ledger\" feature for \
core"
.to_string(),
))
Err(KeyManagerServiceError::LedgerError(format!(
"{} 'get_public_key_at_key_id' was called.",
LEDGER_NOT_SUPPORTED
)))
}

#[cfg(feature = "ledger")]
Expand Down Expand Up @@ -667,13 +669,12 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
if let KeyId::Managed { branch, index } = secret_key_id {
match TransactionKeyManagerBranch::from_key(branch) {
TransactionKeyManagerBranch::OneSidedSenderOffset | TransactionKeyManagerBranch::RandomKey => {
debug!(target: LOG_TARGET, "get_diffie_hellman_shared_secret: wallet type {}", self.wallet_type);
debug!(target: LOG_TARGET, "get_diffie_hellman_shared_secret: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
return Err(TransactionError::LedgerNotSupported(format!(
"Ledger {} (has index {}) is not supported in this build, please enable the \
\"ledger\" feature for core",
ledger, index
"{} 'get_diffie_hellman_shared_secret' was called. ({} (has index {}))",
LEDGER_NOT_SUPPORTED, ledger, index
)));
}

Expand Down Expand Up @@ -707,13 +708,12 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
WalletType::Ledger(ledger) => match secret_key_id {
KeyId::Managed { branch, index } => match TransactionKeyManagerBranch::from_key(branch) {
TransactionKeyManagerBranch::OneSidedSenderOffset => {
debug!(target: LOG_TARGET, "get_diffie_hellman_stealth_domain_hasher: allet type {}", self.wallet_type);
debug!(target: LOG_TARGET, "get_diffie_hellman_stealth_domain_hasher: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
Err(TransactionError::LedgerNotSupported(format!(
"Ledger {} (has index {}) is not supported in this build, please enable the \
\"ledger\" feature for core",
ledger, index
"{} 'get_diffie_hellman_stealth_domain_hasher' was called. ({} (has index {}))",
LEDGER_NOT_SUPPORTED, ledger, index
)))
}

Expand Down Expand Up @@ -792,13 +792,12 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static

match (&self.wallet_type, script_key_id) {
(WalletType::Ledger(ledger), KeyId::Derived { key }) => {
debug!(target: LOG_TARGET, "get_script_signature: wallet type {}", self.wallet_type);
debug!(target: LOG_TARGET, "get_script_signature: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
Err(TransactionError::LedgerNotSupported(format!(
"Ledger {} (has script_key_id {}, branch {}, index {}) is not supported in this build, please \
enable the \"ledger\" feature for core",
ledger, script_key_id, branch, index
"{} 'get_script_signature' was called. ({} (has key {}))",
LEDGER_NOT_SUPPORTED, ledger, key
)))
}

Expand Down Expand Up @@ -993,12 +992,12 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
Ok(script_offset)
},
WalletType::Ledger(ledger) => {
debug!(target: LOG_TARGET, "get_script_offset: wallet type {}", self.wallet_type);
debug!(target: LOG_TARGET, "get_script_offset: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
Err(TransactionError::LedgerNotSupported(format!(
"Ledger {} is not supported in this build, please enable the \"ledger\" feature for core",
ledger
"{} 'get_script_offset' was called. ({})",
LEDGER_NOT_SUPPORTED, ledger
)))
}

Expand Down Expand Up @@ -1082,12 +1081,12 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
) -> Result<CheckSigSchnorrSignature, TransactionError> {
match &self.wallet_type {
WalletType::Ledger(ledger) => {
debug!(target: LOG_TARGET, "sign_script_message: wallet type {}", self.wallet_type);
debug!(target: LOG_TARGET, "sign_script_message: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
Err(TransactionError::LedgerNotSupported(format!(
"Ledger {} is not supported in this build, please enable the \"ledger\" feature for core",
ledger
"{} 'sign_script_message' was called. ({})",
LEDGER_NOT_SUPPORTED, ledger
)))
}

Expand Down Expand Up @@ -1127,12 +1126,12 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
) -> Result<Signature, TransactionError> {
match &self.wallet_type {
WalletType::Ledger(ledger) => {
debug!(target: LOG_TARGET, "sign_with_nonce_and_challenge: wallet type {}", self.wallet_type);
debug!(target: LOG_TARGET, "sign_with_nonce_and_challenge: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
Err(TransactionError::LedgerNotSupported(format!(
"Ledger {} is not supported in this build, please enable the \"ledger\" feature for core",
ledger
"{} 'sign_with_nonce_and_challenge' was called. ({})",
LEDGER_NOT_SUPPORTED, ledger
)))
}

Expand Down Expand Up @@ -1245,11 +1244,13 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
.await
},
WalletType::Ledger(ledger) => {
debug!(target: LOG_TARGET, "get_one_sided_metadata_signature: {}", self.wallet_type);
#[cfg(not(feature = "ledger"))]
{
Err(TransactionError::LedgerNotSupported(
"One sided metadata signature was called for ledger, but ledger is not supported.".to_string(),
))
Err(TransactionError::LedgerNotSupported(format!(
"{} 'get_one_sided_metadata_signature' was called. ({})",
LEDGER_NOT_SUPPORTED, ledger
)))
}

#[cfg(feature = "ledger")]
Expand Down
1 change: 1 addition & 0 deletions base_layer/core/src/transactions/key_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mod initializer;
pub use initializer::TransactionKeyManagerInitializer;

mod inner;
pub use inner::LEDGER_NOT_SUPPORTED;
/// This is a memory database implementation of the `TransactionKeyManager` trait.
mod memory_db_key_manager;
pub use inner::TransactionKeyManagerInner;
Expand Down
5 changes: 2 additions & 3 deletions base_layer/wallet/src/output_manager_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ use tari_core::{
},
};
use tari_crypto::ristretto::pedersen::PedersenCommitment;
use tari_key_manager::key_manager_service::SerializedKeyString;
use tari_key_manager::key_manager_service::{KeyAndId, KeyId};
use tari_key_manager::key_manager_service::{KeyAndId, KeyId, SerializedKeyString};
use tari_script::{
inputs,
push_pubkey_script,
Expand Down Expand Up @@ -1395,7 +1394,7 @@ where
stp.change_recipient_sender_offset_private_key(
self.resources
.key_manager
.get_next_key(TransactionKeyManagerBranch::SenderOffsetLedger.get_branch_key())
.get_next_key(TransactionKeyManagerBranch::OneSidedSenderOffset.get_branch_key())
.await?
.key_id,
)?;
Expand Down
5 changes: 1 addition & 4 deletions base_layer/wallet/src/transaction_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ use tari_core::{
consensus::ConsensusManager,
covenants::Covenant,
mempool::FeePerGramStat,
one_sided::{
shared_secret_to_output_encryption_key,
shared_secret_to_output_spending_key,
},
one_sided::{shared_secret_to_output_encryption_key, shared_secret_to_output_spending_key},
proto::{base_node as base_node_proto, base_node::FetchMatchingUtxos},
transactions::{
key_manager::TransactionKeyManagerInterface,
Expand Down

0 comments on commit 8fdb9fd

Please sign in to comment.