Skip to content

Commit

Permalink
Merge pull request #43 from mwcproject/5.3.100
Browse files Browse the repository at this point in the history
5.3.100
  • Loading branch information
bayk authored Oct 3, 2024
2 parents 4401638 + 96952b3 commit 0aa096d
Show file tree
Hide file tree
Showing 20 changed files with 1,073 additions and 237 deletions.
328 changes: 161 additions & 167 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mwc_wallet"
version = "5.3.2"
version = "5.3.3"
authors = ["Grin Developers <[email protected]>"]
description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format."
license = "Apache-2.0"
Expand Down Expand Up @@ -36,12 +36,12 @@ funty = "=1.1.0"
uuid = { version = "0.8", features = ["serde", "v4"] }
shlex = "1.3.0"

grin_wallet_api = { path = "./api", version = "5.3.2" }
grin_wallet_impls = { path = "./impls", version = "5.3.2" }
grin_wallet_libwallet = { path = "./libwallet", version = "5.3.2" }
grin_wallet_controller = { path = "./controller", version = "5.3.2" }
grin_wallet_config = { path = "./config", version = "5.3.2" }
grin_wallet_util = { path = "./util", version = "5.3.2" }
grin_wallet_api = { path = "./api", version = "5.3.3" }
grin_wallet_impls = { path = "./impls", version = "5.3.3" }
grin_wallet_libwallet = { path = "./libwallet", version = "5.3.3" }
grin_wallet_controller = { path = "./controller", version = "5.3.3" }
grin_wallet_config = { path = "./config", version = "5.3.3" }
grin_wallet_util = { path = "./util", version = "5.3.3" }

[build-dependencies]
built = { version = "0.4", features = ["git2"]}
Expand Down
10 changes: 5 additions & 5 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_api"
version = "5.3.2"
version = "5.3.3"
authors = ["Grin Developers <[email protected]>"]
description = "Grin Wallet API"
license = "Apache-2.0"
Expand All @@ -24,10 +24,10 @@ ed25519-dalek = "1.0.0-pre.4"
colored = "1.6"
x25519-dalek = "0.6"

grin_wallet_libwallet = { path = "../libwallet", version = "5.3.2" }
grin_wallet_config = { path = "../config", version = "5.3.2" }
grin_wallet_impls = { path = "../impls", version = "5.3.2" }
grin_wallet_util = { path = "../util", version = "5.3.2" }
grin_wallet_libwallet = { path = "../libwallet", version = "5.3.3" }
grin_wallet_config = { path = "../config", version = "5.3.3" }
grin_wallet_impls = { path = "../impls", version = "5.3.3" }
grin_wallet_util = { path = "../util", version = "5.3.3" }

[dev-dependencies]
serde_json = "1"
Expand Down
50 changes: 49 additions & 1 deletion api/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::util::secp::key::SecretKey;
use crate::util::{from_hex, Mutex, ZeroingString};
use grin_wallet_util::grin_util::secp::key::PublicKey;
use grin_wallet_util::grin_util::static_secp_instance;
use libwallet::RetrieveTxQueryArgs;
use libwallet::{OwnershipProof, OwnershipProofValidation, RetrieveTxQueryArgs};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Sender};
use std::sync::Arc;
Expand Down Expand Up @@ -2435,6 +2435,31 @@ where
owner::verify_payment_proof(self.wallet_inst.clone(), keychain_mask, proof)
}

pub fn retrieve_ownership_proof(
&self,
keychain_mask: Option<&SecretKey>,
message: String,
include_public_root_key: bool,
include_tor_address: bool,
include_mqs_address: bool,
) -> Result<OwnershipProof, Error> {
owner::generate_ownership_proof(
self.wallet_inst.clone(),
keychain_mask,
message,
include_public_root_key,
include_tor_address,
include_mqs_address,
)
}

pub fn validate_ownership_proof(
&self,
proof: OwnershipProof,
) -> Result<OwnershipProofValidation, Error> {
owner::validate_ownership_proof(proof)
}

/// Start swap trade process. Return SwapID that can be used to check the status or perform further action.
pub fn swap_start(
&self,
Expand Down Expand Up @@ -2796,3 +2821,26 @@ macro_rules! doctest_helper_setup_doc_env {
let mut $wallet = Arc::new(Mutex::new(wallet));
};
}

/*#[test]
#[allow(unused_mut)]
fn test_api() {
use crate as grin_wallet_api;
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
let mut api_owner = Owner::new(wallet.clone(), None, None);
let proof = api_owner.retrieve_ownership_proof(None,
"my message to sign".to_string(),
true,
true,
true).unwrap();
let valiation = api_owner.validate_ownership_proof(proof).unwrap();
assert_eq!(valiation.network, "floonet");
assert_eq!(valiation.message, "my message to sign".to_string());
assert!(valiation.viewing_key.is_some());
assert!(valiation.tor_address.is_some());
assert!(valiation.mqs_address.is_some());
}*/
4 changes: 2 additions & 2 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_config"
version = "5.3.2"
version = "5.3.3"
authors = ["Grin Developers <[email protected]>"]
description = "Configuration for grin wallet , a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format."
license = "Apache-2.0"
Expand All @@ -17,7 +17,7 @@ toml = "0.5"
serde_derive = "1"
thiserror = "1"

grin_wallet_util = { path = "../util", version = "5.3.2" }
grin_wallet_util = { path = "../util", version = "5.3.3" }

[dev-dependencies]
pretty_assertions = "0.6"
12 changes: 6 additions & 6 deletions controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_controller"
version = "5.3.2"
version = "5.3.3"
authors = ["Grin Developers <[email protected]>"]
description = "Controllers for grin wallet instantiation"
license = "Apache-2.0"
Expand Down Expand Up @@ -36,11 +36,11 @@ wagyu-ethereum = { git = "https://github.com/mwcproject/wagyu-ethereum", branch
libp2p = { git = "https://github.com/mwcproject/rust-libp2p", branch = "master", default-features = false, features = [ "noise", "yamux", "mplex", "dns", "tcp-tokio", "ping", "gossipsub"] }
#libp2p = { path = "../../rust-libp2p", default-features = false, features = [ "noise", "yamux", "mplex", "dns", "tcp-tokio", "ping", "gossipsub"] }

grin_wallet_util = { path = "../util", version = "5.3.2" }
grin_wallet_api = { path = "../api", version = "5.3.2" }
grin_wallet_impls = { path = "../impls", version = "5.3.2" }
grin_wallet_libwallet = { path = "../libwallet", version = "5.3.2" }
grin_wallet_config = { path = "../config", version = "5.3.2" }
grin_wallet_util = { path = "../util", version = "5.3.3" }
grin_wallet_api = { path = "../api", version = "5.3.3" }
grin_wallet_impls = { path = "../impls", version = "5.3.3" }
grin_wallet_libwallet = { path = "../libwallet", version = "5.3.3" }
grin_wallet_config = { path = "../config", version = "5.3.3" }

[dev-dependencies]
remove_dir_all = "0.7"
173 changes: 155 additions & 18 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use grin_wallet_libwallet::swap::fsm::state::StateId;
use grin_wallet_libwallet::swap::trades;
use grin_wallet_libwallet::swap::types::Action;
use grin_wallet_libwallet::swap::{message, Swap};
use grin_wallet_libwallet::{Slate, TxLogEntry, WalletInst};
use grin_wallet_libwallet::{OwnershipProof, Slate, StatusMessage, TxLogEntry, WalletInst};
use grin_wallet_util::grin_core::consensus::MWC_BASE;
use grin_wallet_util::grin_core::core::{amount_to_hr_string, Transaction};
use grin_wallet_util::grin_core::global::{FLOONET_DNS_SEEDS, MAINNET_DNS_SEEDS};
Expand All @@ -67,8 +67,11 @@ use std::io;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::sync::mpsc::Sender;
use std::sync::Arc;
use std::thread;
use std::thread::JoinHandle;
use std::time::Duration;
use uuid::Uuid;

Expand Down Expand Up @@ -152,6 +155,7 @@ where
pub fn rewind_hash<'a, L, C, K>(
owner_api: &mut Owner<L, C, K>,
keychain_mask: Option<&SecretKey>,
mwc713print: bool,
) -> Result<(), Error>
where
L: WalletLCProvider<'static, C, K>,
Expand All @@ -160,11 +164,91 @@ where
{
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| {
let rewind_hash = api.get_rewind_hash(m)?;
println!();
println!("Wallet Rewind Hash");
println!("-------------------------------------");
println!("{}", rewind_hash);
println!();
if mwc713print {
println!("Wallet Rewind Hash: {}", rewind_hash);
} else {
println!();
println!("Wallet Rewind Hash");
println!("-------------------------------------");
println!("{}", rewind_hash);
println!();
}
Ok(())
})?;
Ok(())
}

/// Arguments for generate_ownership_proof command
pub struct GenerateOwnershipProofArgs {
/// Message to sign
pub message: String,
/// does need to include public root key
pub include_public_root_key: bool,
/// does need to include tor address
pub include_tor_address: bool,
/// does need to include MQS address
pub include_mqs_address: bool,
}

pub fn generate_ownership_proof<'a, L, C, K>(
owner_api: &mut Owner<L, C, K>,
keychain_mask: Option<&SecretKey>,
args: GenerateOwnershipProofArgs,
) -> Result<(), Error>
where
L: WalletLCProvider<'static, C, K>,
C: NodeClient + 'static,
K: keychain::Keychain + 'static,
{
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| {
let proof = api.retrieve_ownership_proof(
m,
args.message,
args.include_public_root_key,
args.include_tor_address,
args.include_mqs_address,
)?;

let proof_json = serde_json::to_string(&proof).map_err(|e| {
Error::GenericError(format!("Failed convert proof result into json, {}", e))
})?;

println!("Ownership Proof: {}", proof_json);
Ok(())
})?;
Ok(())
}

pub fn validate_ownership_proof<'a, L, C, K>(
owner_api: &mut Owner<L, C, K>,
keychain_mask: Option<&SecretKey>,
proof: &str,
) -> Result<(), Error>
where
L: WalletLCProvider<'static, C, K>,
C: NodeClient + 'static,
K: keychain::Keychain + 'static,
{
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, _m| {
let proof = serde_json::from_str::<OwnershipProof>(proof).map_err(|e| {
Error::ArgumentError(format!("Unable to decode proof from json, {}", e))
})?;

let validation = api.validate_ownership_proof(proof)?;
println!("Network: {}", validation.network);
println!("Message: {}", validation.message);
println!(
"Viewing Key: {}",
validation.viewing_key.unwrap_or("Not provided".to_string())
);
println!(
"Tor Address: {}",
validation.tor_address.unwrap_or("Not provided".to_string())
);
println!(
"MWCMQS Address: {}",
validation.mqs_address.unwrap_or("Not provided".to_string())
);
Ok(())
})?;
Ok(())
Expand All @@ -181,6 +265,7 @@ pub fn scan_rewind_hash<L, C, K>(
owner_api: &mut Owner<L, C, K>,
args: ViewWalletScanArgs,
dark_scheme: bool,
show_progress: bool,
) -> Result<(), Error>
where
L: WalletLCProvider<'static, C, K> + 'static,
Expand All @@ -201,21 +286,73 @@ where
"Starting view wallet output scan from height {} ...",
start_height
);
let result = api.scan_rewind_hash(rewind_hash, Some(start_height));

let mut status_send_channel: Option<Sender<StatusMessage>> = None;
let running = Arc::new(AtomicBool::new(true));
let mut updater: Option<JoinHandle<()>> = None;
if show_progress {
let (tx, rx) = mpsc::channel();
// Starting printing to console thread.
updater = Some(
grin_wallet_libwallet::api_impl::owner_updater::start_updater_console_thread(
rx,
running.clone(),
)?,
);
status_send_channel = Some(tx);
}

let result = owner::scan_rewind_hash(
api.wallet_inst.clone(),
rewind_hash,
Some(start_height),
&status_send_channel,
);

let deci_sec = time::Duration::from_millis(100);
thread::sleep(deci_sec);
match result {
Ok(res) => {
warn!("View wallet check complete");
if res.total_balance != 0 {
display::view_wallet_output(res.clone(), tip_height, dark_scheme)?;
if show_progress {
running.store(false, Ordering::Relaxed);
let _ = updater.unwrap().join();
// Printing for parser
match result {
Ok(res) => {
println!("View wallet check complete");
for m in res.output_result {
println!(
"ViewOutput: {},{},{},{},{},{},{}",
m.commit,
m.mmr_index,
m.height,
m.lock_height,
m.is_coinbase,
m.num_confirmations(tip_height),
m.value
);
}
println!("ViewTotal: {}", res.total_balance);
Ok(())
}
Err(e) => {
println!("View wallet check failed: {}", e);
Err(e.into())
}
display::view_wallet_balance(res.clone(), tip_height, dark_scheme);
Ok(())
}
Err(e) => {
error!("View wallet check failed: {}", e);
Err(e.into())
} else {
// nice printing
thread::sleep(deci_sec);
match result {
Ok(res) => {
warn!("View wallet check complete");
if res.total_balance != 0 {
display::view_wallet_output(res.clone(), tip_height, dark_scheme)?;
}
display::view_wallet_balance(res.clone(), tip_height, dark_scheme);
Ok(())
}
Err(e) => {
error!("View wallet check failed: {}", e);
Err(e.into())
}
}
}
})?;
Expand Down
Loading

0 comments on commit 0aa096d

Please sign in to comment.