Skip to content

Commit

Permalink
Merge pull request #52 from bithyve/fix-accounts
Browse files Browse the repository at this point in the history
Fix getting accounts from device
  • Loading branch information
ben-kaufman authored Nov 26, 2024
2 parents a9ec053 + 6836cac commit 576c1b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src-tauri/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pub enum ScriptType {
P2TR,
}

pub fn get_xpubs(hwi_state: &HWIClientState, account: u32) -> Result<serde_json::Value, HWIError> {
pub fn get_xpubs(
hwi_state: &HWIClientState,
account: usize,
) -> Result<serde_json::Value, HWIError> {
let ss_path = get_derivation_path(ScriptType::P2WPKH, hwi_state.network, account);
let ms_path = get_derivation_path(ScriptType::P2WSH, hwi_state.network, account);
let tr_path = get_derivation_path(ScriptType::P2TR, hwi_state.network, account);
Expand All @@ -37,14 +40,18 @@ pub fn get_xpubs(hwi_state: &HWIClientState, account: u32) -> Result<serde_json:
}))
}

fn get_derivation_path(script_type: ScriptType, network: Network, account: u32) -> DerivationPath {
fn get_derivation_path(
script_type: ScriptType,
network: Network,
account: usize,
) -> DerivationPath {
let network_num = match network {
Network::Bitcoin => 0,
Network::Testnet | Network::Signet | Network::Regtest => 1,
_ => panic!("Unsupported Network"),
};
match script_type {
ScriptType::P2WPKH => format!("m/84'/{}'/{}'/", network_num, account)
ScriptType::P2WPKH => format!("m/84'/{}'/{}'", network_num, account)
.parse()
.unwrap(),
ScriptType::P2WSH => format!("m/48'/{}'/{}'/2'", network_num, account)
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn set_hwi_client(
}

#[tauri::command]
async fn hwi_get_xpubs(state: State<'_, AppState>, account: u32) -> Result<Value, String> {
async fn hwi_get_xpubs(state: State<'_, AppState>, account: usize) -> Result<Value, String> {
let state = state.lock().await;
let hwi_state = state.hwi.as_ref().ok_or("HWI client not initialized")?;
let xpub_data = get_xpubs(hwi_state, account).map_err(|e| e.to_string())?;
Expand All @@ -155,7 +155,7 @@ async fn hwi_get_xpubs(state: State<'_, AppState>, account: u32) -> Result<Value
}

#[tauri::command]
async fn hwi_healthcheck(state: State<'_, AppState>, account: u32) -> Result<Value, String> {
async fn hwi_healthcheck(state: State<'_, AppState>, account: usize) -> Result<Value, String> {
let state = state.lock().await;
let hwi_state = state.hwi.as_ref().ok_or("HWI client not initialized")?;
let xpub_data = get_xpubs(hwi_state, account).map_err(|e| e.to_string())?;
Expand Down

0 comments on commit 576c1b9

Please sign in to comment.