mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-14 03:59:30 +00:00
73 lines
2.3 KiB
Rust
73 lines
2.3 KiB
Rust
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,
|
|
Load {
|
|
#[arg(short, long)]
|
|
mnemonic: Option<String>,
|
|
#[arg(short, long)]
|
|
pin: Option<String>,
|
|
},
|
|
}
|
|
|
|
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");
|
|
let available = wallet
|
|
.is_unpaired_keycard_available(py)
|
|
.expect("Expect a Boolean.");
|
|
|
|
if available {
|
|
println!("\u{2705} Keycard is available.");
|
|
} else {
|
|
println!("\u{274c} Keycard is not available.");
|
|
}
|
|
});
|
|
|
|
Ok(SubcommandReturnValue::Empty)
|
|
}
|
|
Self::Load { mnemonic, pin } => {
|
|
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");
|
|
|
|
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.");
|
|
}
|
|
|
|
let _ = wallet.load_mnemonic(py, &mnemonic.expect("TODO"));
|
|
|
|
let _ = wallet.disconnect(py);
|
|
});
|
|
|
|
Ok(SubcommandReturnValue::Empty)
|
|
}
|
|
}
|
|
}
|
|
}
|