Skip to content
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
38 changes: 38 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions neptune-core-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tarpc = { version = "^0.34", features = [
] }
tokio = { version = "1.41", features = ["full", "tracing"] }
bech32 = ">=0.9, <0.10"
dialoguer = "0.12.0"

[dev-dependencies]
arbitrary = "1.4.2"
Expand Down
40 changes: 23 additions & 17 deletions neptune-core-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use clap::CommandFactory;
use clap::Parser;
use clap_complete::generate;
use clap_complete::Shell;
use dialoguer::theme::ColorfulTheme;
use dialoguer::Select;
use itertools::Itertools;
use neptune_cash::api::export::TransactionKernelId;
use neptune_cash::api::tx_initiation::builder::tx_output_list_builder::OutputFormat;
Expand Down Expand Up @@ -188,7 +190,7 @@ enum Command {
max_num_blocks: Option<usize>,
},

/// Show smallest block interval in the specified range.
/// Show the smallest block interval in the specified range.
MinBlockInterval {
last_block: BlockSelector,
max_num_blocks: Option<usize>,
Expand All @@ -200,7 +202,7 @@ enum Command {
max_num_blocks: Option<usize>,
},

/// Show largest difficulty in the specified range.
/// Show the largest difficulty in the specified range.
MaxBlockDifficulty {
last_block: BlockSelector,
max_num_blocks: Option<usize>,
Expand Down Expand Up @@ -297,7 +299,7 @@ enum Command {
/// block proposals, and new transactions from being received.
Freeze,

/// If state updates have been paused, resumes them. Otherwise does nothing.
/// If state updates have been paused, resumes them. Otherwise, does nothing.
Unfreeze,

/// pause mining
Expand Down Expand Up @@ -549,12 +551,12 @@ async fn main() -> Result<()> {

// prompt user for all shares
let mut shares = vec![];
let capture_integers = Regex::new(r"^(\d+)\/(\d+)$").unwrap();
let capture_integers = Regex::new(r"^(\d+)\/(\d+)$")?;
while shares.len() != *t {
println!("Enter share index (\"i/n\"): ");

let mut buffer = "".to_string();
std::io::stdin()
io::stdin()
.read_line(&mut buffer)
.expect("Cannot accept user input.");
let buffer = buffer.trim();
Expand Down Expand Up @@ -722,7 +724,7 @@ async fn main() -> Result<()> {
}

// all other operations need a connection to the server
let server_socket = SocketAddr::new(std::net::IpAddr::V4(Ipv4Addr::LOCALHOST), args.port);
let server_socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), args.port);
let Ok(transport) = tarpc::serde_transport::tcp::connect(server_socket, Json::default).await
else {
eprintln!("This command requires a connection to `neptune-core`, but that connection could not be established. Is `neptune-core` running?");
Expand Down Expand Up @@ -1332,8 +1334,8 @@ async fn main() -> Result<()> {
//
// Otherwise, we call cookie_hint() RPC to obtain data-dir.
// But the API might be disabled, which we detect and fallback to the default data-dir.
async fn get_cookie_hint(client: &RPCClient, args: &Config) -> anyhow::Result<auth::CookieHint> {
async fn fallback(client: &RPCClient, args: &Config) -> anyhow::Result<auth::CookieHint> {
async fn get_cookie_hint(client: &RPCClient, args: &Config) -> Result<auth::CookieHint> {
async fn fallback(client: &RPCClient, args: &Config) -> Result<auth::CookieHint> {
let network = client.network(context::current()).await??;
let data_directory = DataDirectory::get(args.data_dir.clone(), network)?;
Ok(auth::CookieHint {
Expand Down Expand Up @@ -1416,7 +1418,7 @@ fn process_utxo_notifications(
network: Network,
private_notifications: Vec<PrivateNotificationData>,
receiver_tag: Option<String>,
) -> anyhow::Result<()> {
) -> Result<()> {
let data_dir = root_data_dir.utxo_transfer_directory_path();

if !private_notifications.is_empty() {
Expand All @@ -1428,10 +1430,7 @@ fn process_utxo_notifications(

// TODO: It would be better if this timestamp was read from the created
// transaction.
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis();
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis();

// write out one UtxoTransferEntry in a json file, per output
let mut wrote_file_cnt = 0usize;
Expand Down Expand Up @@ -1461,7 +1460,7 @@ fn process_utxo_notifications(
let file_path = file_dir.join(&file_name);
println!("creating file: {}", file_path.display());
let file = std::fs::File::create_new(&file_path)?;
let mut writer = std::io::BufWriter::new(file);
let mut writer = io::BufWriter::new(file);
serde_json::to_writer_pretty(&mut writer, &entry)?;
writer.flush()?;

Expand Down Expand Up @@ -1491,13 +1490,20 @@ or use equivalent claim functionality of your chosen wallet software.
}

fn enter_seed_phrase_dialog() -> Result<SecretKeyMaterial> {
let mnemonic_length_list = [18, 24];
let selection = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Choose your mnemonic length")
.default(0)
.items(mnemonic_length_list)
.interact()?;
let mnemonic_length = mnemonic_length_list[selection];
let mut phrase = vec![];
let mut i = 1;
loop {
print!("{i}. ");
io::stdout().flush()?;
stdout().flush()?;
let mut buffer = "".to_string();
std::io::stdin()
io::stdin()
.read_line(&mut buffer)
.expect("Cannot accept user input.");
let word = buffer.trim();
Expand All @@ -1508,7 +1514,7 @@ fn enter_seed_phrase_dialog() -> Result<SecretKeyMaterial> {
{
phrase.push(word.to_string());
i += 1;
if i > 18 {
if i > mnemonic_length {
break;
}
} else {
Expand Down
11 changes: 5 additions & 6 deletions neptune-core/src/state/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ mod tests {
use tasm_lib::prelude::Digest;
use tasm_lib::prelude::Tip5;
use tasm_lib::triton_vm::prelude::BFieldElement;
use tasm_lib::triton_vm::prelude::XFieldElement;
use tasm_lib::twenty_first::math::x_field_element::EXTENSION_DEGREE;
use tracing_test::traced_test;
use unlocked_utxo::UnlockedUtxo;

Expand All @@ -61,6 +59,7 @@ mod tests {
use crate::state::transaction::tx_creation_config::TxCreationConfig;
use crate::state::transaction::tx_proving_capability::TxProvingCapability;
use crate::state::wallet::expected_utxo::UtxoNotifier;
use crate::state::wallet::secret_key_material::BField32Bytes;
use crate::state::wallet::secret_key_material::SecretKeyMaterial;
use crate::state::wallet::transaction_output::TxOutput;
use crate::state::wallet::transaction_output::TxOutputList;
Expand Down Expand Up @@ -1151,18 +1150,18 @@ mod tests {
proptest::proptest! {
#[test]
fn master_seed_is_not_sender_randomness(
secret in proptest_arbitrary_interop::arb::<XFieldElement>()
secret in proptest_arbitrary_interop::arb::<BField32Bytes>()
) {
let secret_as_digest = Digest::new(
[
secret.coefficients.to_vec(),
vec![BFieldElement::new(0); Digest::LEN - EXTENSION_DEGREE],
secret.0.to_vec(),
vec![BFieldElement::new(0); Digest::LEN - 4],
]
.concat()
.try_into()
.unwrap(),
);
let wallet = WalletEntropy::new(SecretKeyMaterial(secret));
let wallet = WalletEntropy::new(SecretKeyMaterial::V1(secret));
assert_ne!(
wallet.generate_sender_randomness(BlockHeight::genesis(), random()),
secret_as_digest
Expand Down
Loading
Loading