1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-21 13:58:08 +00:00

feat(rust/trezor_client): add solana_get_address example

This commit is contained in:
stevenbooke 2024-03-07 12:34:27 -08:00 committed by Martin Milata
parent 48de0cb469
commit 6a8ce5b5c0
4 changed files with 38 additions and 1 deletions

View File

@ -49,7 +49,7 @@ tracing-subscriber = "0.3"
serial_test = "2.0.0"
[features]
default = ["bitcoin", "ethereum"]
default = ["bitcoin", "ethereum", "solana"]
# Client implementations
bitcoin = ["dep:bitcoin", "unicode-normalization"]

View File

@ -0,0 +1,17 @@
use std::str::FromStr;
use bitcoin::bip32::DerivationPath;
use trezor_client::utils::convert_path;
fn do_main() -> Result<(), trezor_client::Error> {
let mut trezor = trezor_client::unique(false)?;
trezor.init_device(None)?;
let path = DerivationPath::from_str("m/44'/501'/0'/0'").expect("Hardended Derivation Path");
let solana_address = trezor.solana_get_address(convert_path(&path))?;
println!("solana address: {:?}", solana_address);
Ok(())
}
fn main() {
do_main().unwrap()
}

View File

@ -8,6 +8,11 @@ mod ethereum;
#[cfg(feature = "ethereum")]
pub use ethereum::*;
#[cfg(feature = "solana")]
mod solana;
#[cfg(feature = "solana")]
pub use solana::*;
pub mod common;
pub use common::*;

View File

@ -0,0 +1,15 @@
use super::{handle_interaction, Trezor};
use crate::{error::Result, protos};
impl Trezor {
// SOLANA
pub fn solana_get_address(&mut self, path: Vec<u32>) -> Result<String> {
let mut req = protos::SolanaGetAddress::new();
req.address_n = path;
req.show_display = Some(true);
let address = handle_interaction(
self.call(req, Box::new(|_, m: protos::SolanaAddress| Ok(m.address().into())))?,
)?;
Ok(address)
}
}