|
1 | 1 | use anyhow::Result; |
2 | 2 | use sapling_crypto::keys::FullViewingKey; |
| 3 | +use zcash_transparent::address::TransparentAddress; |
| 4 | +use sqlx::SqliteConnection; |
3 | 5 |
|
4 | | -use crate::{api::coin::Network, db::LEDGER_CODE}; |
| 6 | +use crate::{api::{coin::{Coin, Network}, pay::{PcztPackage, SigningEvent}}, frb_generated::StreamSink}; |
5 | 7 |
|
6 | 8 | cfg_if::cfg_if! { |
7 | 9 | if #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] { |
8 | 10 | pub(crate) async fn get_hw_fvk(_network: &Network, ledger_code: u32, aindex: u32) -> Result<FullViewingKey> { |
9 | | - assert_eq!(ledger_code, LEDGER_CODE); |
| 11 | + assert_eq!(ledger_code, crate::db::LEDGER_CODE); |
10 | 12 | let ledger = crate::ledger::connect_ledger().await?; |
11 | 13 | let fvk = crate::ledger::fvk::get_fvk(&ledger, aindex).await?; |
12 | 14 | Ok(fvk) |
13 | 15 | } |
| 16 | + |
| 17 | + pub(crate) async fn get_hw_sapling_address( |
| 18 | + network: &Network, |
| 19 | + aindex: u32, |
| 20 | + ) -> Result<String> { |
| 21 | + let ledger = crate::ledger::connect_ledger().await?; |
| 22 | + let address = crate::ledger::fvk::get_hw_sapling_address(&ledger, network, aindex).await?; |
| 23 | + Ok(address) |
| 24 | + } |
| 25 | + |
| 26 | + pub(crate) async fn get_hw_transparent_address( |
| 27 | + network: &Network, |
| 28 | + aindex: u32, |
| 29 | + scope: u32, |
| 30 | + dindex: u32, |
| 31 | + ) -> Result<(Vec<u8>, TransparentAddress)> { |
| 32 | + let ledger = crate::ledger::connect_ledger().await?; |
| 33 | + let (pk, address) = crate::ledger::fvk::get_hw_transparent_address(&ledger, network, aindex, scope, dindex).await?; |
| 34 | + Ok((pk, address)) |
| 35 | + } |
| 36 | + |
| 37 | + pub(crate) async fn get_hw_next_diversifier_address( |
| 38 | + network: &Network, |
| 39 | + aindex: u32, |
| 40 | + dindex: u32, |
| 41 | + ) -> Result<(u32, String)> { |
| 42 | + let ledger = crate::ledger::connect_ledger().await?; |
| 43 | + let (dindex, address) = crate::ledger::fvk::get_hw_next_diversifier_address(&ledger, network, aindex, dindex).await?; |
| 44 | + Ok((dindex, address)) |
| 45 | + } |
| 46 | + |
| 47 | + pub(crate) async fn show_sapling_address(network: &Network, connection: &mut SqliteConnection, account: u32) -> Result<String> { |
| 48 | + let address = crate::ledger::fvk::show_sapling_address(network, connection, account).await?; |
| 49 | + Ok(address) |
| 50 | + } |
| 51 | + |
| 52 | + pub(crate) async fn show_transparent_address(network: &Network, connection: &mut SqliteConnection, account: u32) -> Result<String> { |
| 53 | + let address = crate::ledger::fvk::show_transparent_address(network, connection, account).await?; |
| 54 | + Ok(address) |
| 55 | + } |
| 56 | + |
| 57 | + pub async fn sign_ledger_transaction( |
| 58 | + sink: StreamSink<SigningEvent>, |
| 59 | + package: PcztPackage, |
| 60 | + c: &Coin, |
| 61 | + ) -> Result<()> { |
| 62 | + let connection = c.get_connection().await?; |
| 63 | + crate::ledger::builder::sign_ledger_transaction(c.network(), sink, connection, c.account, package).await?; |
| 64 | + Ok(()) |
| 65 | + } |
14 | 66 | } |
15 | 67 | else { |
16 | | - pub(crate) async fn get_hw_fvk(_network: &Network, ledger_code: u32, aindex: u32) -> Result<FullViewingKey> { |
17 | | - crate::no_ledger!() |
| 68 | +#[macro_export] |
| 69 | + macro_rules! no_ledger { |
| 70 | + () => { |
| 71 | + Err(anyhow::anyhow!("Ledger not supported on this platform")) |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + pub(crate) async fn get_hw_fvk(_network: &Network, _ledger_code: u32, _aindex: u32) -> Result<FullViewingKey> { |
| 76 | + no_ledger!() |
| 77 | + } |
| 78 | + |
| 79 | + pub(crate) async fn get_hw_sapling_address( |
| 80 | + _network: &Network, |
| 81 | + _aindex: u32, |
| 82 | + ) -> Result<String> { |
| 83 | + no_ledger!() |
| 84 | + } |
| 85 | + |
| 86 | + pub(crate) async fn get_hw_transparent_address( |
| 87 | + _network: &Network, |
| 88 | + _aindex: u32, |
| 89 | + _scope: u32, |
| 90 | + _dindex: u32, |
| 91 | + ) -> Result<(Vec<u8>, TransparentAddress)> { |
| 92 | + no_ledger!() |
| 93 | + } |
| 94 | + |
| 95 | + pub(crate) async fn get_hw_next_diversifier_address( |
| 96 | + _network: &Network, |
| 97 | + _aindex: u32, |
| 98 | + _dindex: u32, |
| 99 | + ) -> Result<(u32, String)> { |
| 100 | + no_ledger!() |
| 101 | + } |
| 102 | + |
| 103 | + pub(crate) async fn show_sapling_address(_network: &Network, _connection: &mut SqliteConnection, _account: u32) -> Result<String> { |
| 104 | + no_ledger!() |
| 105 | + } |
| 106 | + |
| 107 | + pub(crate) async fn show_transparent_address(_network: &Network, _connection: &mut SqliteConnection, _account: u32) -> Result<String> { |
| 108 | + no_ledger!() |
18 | 109 | } |
19 | 110 |
|
20 | | - pub async fn show_ledger_sapling_address() -> Result<String> { |
21 | | - Err(anyhow::anyhow!("Ledger is not supported on mobile devices")) |
| 111 | + pub async fn sign_ledger_transaction( |
| 112 | + _sink: StreamSink<SigningEvent>, |
| 113 | + _package: PcztPackage, |
| 114 | + _c: &Coin, |
| 115 | + ) -> Result<()> { |
| 116 | + no_ledger!() |
22 | 117 | } |
23 | 118 | } |
24 | 119 | } |
0 commit comments