2026-04-17 19:08:45 -04:00
|
|
|
use anyhow::Result;
|
|
|
|
|
use clap::Subcommand;
|
|
|
|
|
use pyo3::prelude::*;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
WalletCore,
|
|
|
|
|
cli::{SubcommandReturnValue, WalletSubcommand, keycard_wallet::KeycardWallet, python_path},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Represents generic chain CLI subcommand.
|
|
|
|
|
#[derive(Subcommand, Debug, Clone)]
|
|
|
|
|
pub enum KeycardSubcommand {
|
|
|
|
|
Available,
|
2026-04-23 09:47:09 -04:00
|
|
|
Load {
|
2026-04-17 19:08:45 -04:00
|
|
|
#[arg(
|
|
|
|
|
short,
|
|
|
|
|
long,
|
|
|
|
|
)]
|
2026-04-23 09:47:09 -04:00
|
|
|
mnemonic: Option<String>,
|
2026-04-17 19:08:45 -04:00
|
|
|
#[arg(
|
|
|
|
|
short,
|
|
|
|
|
long,
|
|
|
|
|
)]
|
2026-04-23 09:47:09 -04:00
|
|
|
pin: Option<String>
|
2026-04-17 19:08:45 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl WalletSubcommand for KeycardSubcommand {
|
|
|
|
|
#[expect(clippy::cognitive_complexity, reason = "TODO: fix later")]
|
|
|
|
|
async fn handle_subcommand(
|
|
|
|
|
self,
|
|
|
|
|
_wallet_core: &mut WalletCore,
|
|
|
|
|
) -> Result<SubcommandReturnValue> {
|
|
|
|
|
match self {
|
|
|
|
|
Self::Available => {
|
|
|
|
|
Python::with_gil(|py| {
|
|
|
|
|
python_path::add_python_path(py).expect("keycard_wallet.py not found");
|
|
|
|
|
|
|
|
|
|
let wallet = KeycardWallet::new(py).expect("Expect keycard wallet");
|
2026-04-21 18:27:14 -04:00
|
|
|
let available = wallet.is_unpaired_keycard_available(py).expect("Expect a Boolean.");
|
2026-04-17 19:08:45 -04:00
|
|
|
|
2026-04-21 18:27:14 -04:00
|
|
|
if available {
|
|
|
|
|
println!("\u{2705} Keycard is available.");
|
|
|
|
|
} else {
|
|
|
|
|
println!("\u{274c} Keycard is not available.");
|
|
|
|
|
}
|
2026-04-17 19:08:45 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Ok(SubcommandReturnValue::Empty)
|
2026-04-23 09:47:09 -04:00
|
|
|
},/*
|
2026-04-17 19:08:45 -04:00
|
|
|
Self::Connect { pin } => {
|
|
|
|
|
// TODO This should be persistent.
|
|
|
|
|
Python::with_gil(|py| {
|
|
|
|
|
python_path::add_python_path(py).expect("keycard_wallet.py not found");
|
|
|
|
|
|
|
|
|
|
let wallet = KeycardWallet::new(py).expect("Expect keycard wallet");
|
|
|
|
|
|
2026-04-21 18:27:14 -04:00
|
|
|
let is_connected = wallet.setup_communication(py, pin.expect("TODO")).expect("Expect a Boolean.");
|
|
|
|
|
|
|
|
|
|
if is_connected {
|
|
|
|
|
println!("\u{2705} Keycard is now connected to wallet.");
|
|
|
|
|
} else {
|
|
|
|
|
println!("\u{274c} Keycard is not connected to wallet.");
|
|
|
|
|
}
|
2026-04-17 19:08:45 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Ok(SubcommandReturnValue::Empty)
|
2026-04-23 09:47:09 -04:00
|
|
|
},*/
|
|
|
|
|
Self::Load { mnemonic, pin } => {
|
2026-04-17 19:08:45 -04:00
|
|
|
Python::with_gil(|py| {
|
|
|
|
|
python_path::add_python_path(py).expect("keycard_wallet.py not found");
|
|
|
|
|
|
|
|
|
|
let wallet = KeycardWallet::new(py).expect("Expect keycard wallet");
|
|
|
|
|
|
2026-04-23 09:47:09 -04:00
|
|
|
let is_connected = wallet.setup_communication(py, pin.expect("TODO")).expect("Expect a Boolean.");
|
2026-04-17 19:08:45 -04:00
|
|
|
|
2026-04-23 09:47:09 -04:00
|
|
|
if is_connected {
|
|
|
|
|
println!("\u{2705} Keycard is now connected to wallet.");
|
|
|
|
|
} else {
|
|
|
|
|
println!("\u{274c} Keycard is not connected to wallet.");
|
|
|
|
|
}
|
2026-04-17 19:08:45 -04:00
|
|
|
|
2026-04-23 09:47:09 -04:00
|
|
|
let _ = wallet.load_mnemonic(py, &mnemonic.expect("TODO"));
|
2026-04-17 19:08:45 -04:00
|
|
|
|
2026-04-23 09:47:09 -04:00
|
|
|
let _ = wallet.disconnect(py);
|
2026-04-17 19:08:45 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Ok(SubcommandReturnValue::Empty)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|