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:
parent
48de0cb469
commit
6a8ce5b5c0
@ -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"]
|
||||
|
17
rust/trezor-client/examples/solana.rs
Normal file
17
rust/trezor-client/examples/solana.rs
Normal 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()
|
||||
}
|
@ -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::*;
|
||||
|
||||
|
15
rust/trezor-client/src/client/solana.rs
Normal file
15
rust/trezor-client/src/client/solana.rs
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user