-
Notifications
You must be signed in to change notification settings - Fork 45
zwi syncs, benchmarks #1983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
zwi syncs, benchmarks #1983
Changes from 38 commits
637b44b
c07de6f
5b2380a
0fff891
07560b9
9caba82
bfb8a08
ac87e61
e238e8f
2cdad13
27aa034
70da31f
dabbe56
455534e
a4344a1
58f146b
084016d
a3abe35
007189f
c35b84c
c6e92c4
54ed4f3
2cab819
d78a99a
1caaaad
e2de5e3
e7b7780
7ee15f6
fdcfe37
dd4c8e8
5ed3c6d
6af65f2
587a62e
37d8489
d40bb1d
2c5d4ae
b458256
30256ee
69776f3
0630319
3a69b31
4036661
80be91f
705c907
7437678
7464cb8
a5ed051
7a0c455
7b12ecf
d6ca1ea
152e07b
76cc285
1a0a3f4
64b1476
4bdaf3d
ef3baef
4076e86
675d544
fd2be7a
bcf585f
9199736
e42ad63
5144bb7
f3675a9
6507cd3
93ac585
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| [package] | ||
| name = "zingo_wallet" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [dependencies] | ||
| zingolib = { workspace = true } | ||
| pepper-sync.workspace = true | ||
|
|
||
| zcash_wallet_interface = { git = "https://github.com/zingolabs/zcash_wallet_interface.git", branch = "dev" } | ||
|
|
||
| zingo_netutils.workspace = true | ||
| zingo_common_components.workspace = true | ||
|
|
||
| bip0039.workspace = true | ||
| zcash_client_backend.workspace = true | ||
| zcash_primitives.workspace = true | ||
|
|
||
| tonic.workspace = true | ||
| http.workspace = true | ||
| rustls.workspace = true | ||
| tempfile.workspace = true | ||
|
|
||
| thiserror.workspace = true | ||
| tracing.workspace = true | ||
| tracing-subscriber.workspace = true | ||
|
|
||
| [dev-dependencies] | ||
| tokio.workspace = true | ||
| zingo_test_vectors = { git = "https://github.com/zingolabs/infrastructure.git", branch = "dev" } | ||
| test-group.workspace = true | ||
| test-log.workspace = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| use http::Uri; | ||
| use zcash_wallet_interface::BlockHeight; | ||
|
|
||
| use crate::ZingoWallet; | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum AddServerError { | ||
| #[error( | ||
| "Zingo currently can only connect to a lightwallet if it has exactly one key. Try calling add_key." | ||
| )] | ||
| NeedsSingleSeed, | ||
| #[error("URI parse from string '{0}' failed with >{1}<.")] | ||
| ParseUri(String, http::uri::InvalidUri), | ||
| #[error("Creating network-client connected to '{0}' failed with >{1}<.")] | ||
| CreateNetworkClient(Uri, zingo_netutils::GetClientError), | ||
| #[error("Server call returned unexpected result: >{0}<.")] | ||
| Callback(#[from] tonic::Status), | ||
| #[error("Server reported unusable chain: >{0}<.")] | ||
| Chain(#[from] zingolib::config::ChainFromStringError), | ||
| #[error("Server reported overflow block height: >{0}<.")] | ||
| BlockHeight(#[from] std::num::TryFromIntError), | ||
| #[error("Seed parse from string '{0}' failed with >{1}<.")] | ||
| ParseSeed(String, bip0039::Error), | ||
| #[error("Wallet creation failed with >{0}<.")] | ||
| CreateLightWallet(#[from] zingolib::wallet::error::WalletError), | ||
| #[error("Temporary data dir creation failed with >{0}<.")] | ||
| CreateDataDir(#[from] std::io::Error), | ||
| #[error("Wallet creation failed with >{0}<.")] | ||
| CreateLightClient(#[from] zingolib::lightclient::error::LightClientError), | ||
| #[error("Wallet creation failed with >{0}<.")] | ||
| StartSync(zingolib::lightclient::error::LightClientError), | ||
| } | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum GetMaxScannedHeightError { | ||
| #[error("Todo")] | ||
zancas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NoServer, //TODO | ||
| #[error("Todo")] | ||
| NoHeightFoundForServer, //TODO | ||
| #[error("Todo")] | ||
| WalletError(zingolib::wallet::error::WalletError), | ||
| } | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum AddKeyError { | ||
| #[error("Todo")] | ||
| AlreadyHasKey, //TODO | ||
| } | ||
|
|
||
| impl zcash_wallet_interface::Wallet for ZingoWallet { | ||
| fn user_agent_id() -> zcash_wallet_interface::UserAgentId { | ||
| const PARADIGM: &str = "zingo_wallet"; | ||
| const VERSION: &str = "0.0.1"; | ||
zancas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| zcash_wallet_interface::UserAgentId { | ||
| paradigm: PARADIGM.to_string(), | ||
| version: VERSION.to_string(), | ||
| } | ||
| } | ||
|
|
||
| async fn new_wallet() -> Self { | ||
| // we cannot instantiate the current version of the `LightClient` yet | ||
| // without assumptions about keys and servers | ||
| // which would violate principles of the interface | ||
| // so we dont | ||
| ZingoWallet { | ||
| keys: Vec::new(), | ||
| lightclient: None, | ||
| } | ||
| } | ||
|
|
||
| type AddServerError = AddServerError; | ||
|
|
||
| async fn add_server(&mut self, server_address: String) -> Result<(), Self::AddServerError> { | ||
| use std::num::NonZeroU32; | ||
|
|
||
| use std::str::FromStr as _; | ||
|
|
||
| use zingolib::config::ChainType; | ||
| use zingolib::config::SyncConfig; | ||
| use zingolib::config::TransparentAddressDiscovery; | ||
|
|
||
| use zingolib::config::ZingoConfigBuilder; | ||
| use zingolib::config::chain_from_str; | ||
| use zingolib::lightclient::LightClient; | ||
| use zingolib::wallet::LightWallet; | ||
| use zingolib::wallet::WalletSettings; | ||
| if self.keys.len() == 1 | ||
| && let Some(key) = self.keys.first() | ||
| { | ||
| let server_uri = Uri::from_str(server_address.as_str()) | ||
| .map_err(|invalid_uri| AddServerError::ParseUri(server_address, invalid_uri))?; | ||
|
|
||
| let (chain_type, birthday) = { | ||
| // we need to ask the indexer for this information | ||
|
|
||
| let mut client = { | ||
| // global configuration must be manually set *somewhere* | ||
| rustls::crypto::ring::default_provider().install_default(); | ||
|
Check failure on line 99 in zingo_wallet/src/interface.rs
|
||
|
||
| zingolib::grpc_client::get_zcb_client(server_uri.clone()) | ||
| .await | ||
| .map_err(|e| AddServerError::CreateNetworkClient(server_uri.clone(), e))? | ||
| }; | ||
|
|
||
| let lightd_info = client | ||
| .get_lightd_info(tonic::Request::new( | ||
zancas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| zcash_client_backend::proto::service::Empty {}, | ||
| )) | ||
| .await? | ||
| .into_inner(); | ||
|
|
||
| let chain_name = &lightd_info.chain_name; | ||
| let chain_type: ChainType = chain_from_str(chain_name)?; | ||
|
|
||
| let birthday: zcash_primitives::consensus::BlockHeight = | ||
| lightd_info.block_height.try_into()?; | ||
| (chain_type, birthday) | ||
| }; | ||
zancas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // this seems like a lot of set up. Do we really need all this right here?? | ||
zancas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let no_of_accounts = NonZeroU32::try_from(1).expect("hard-coded integer"); // seems like this should default. Also why are we stringing it in in two places?? | ||
|
|
||
| let wallet_base = zingolib::wallet::WalletBase::Mnemonic { | ||
| mnemonic: bip0039::Mnemonic::from_phrase(key) | ||
| .map_err(|e| AddServerError::ParseSeed(key.clone(), e))?, | ||
| no_of_accounts, | ||
| }; | ||
|
|
||
| let wallet_settings = WalletSettings { | ||
| sync_config: SyncConfig { | ||
| transparent_address_discovery: TransparentAddressDiscovery::minimal(), | ||
| performance_level: pepper_sync::config::PerformanceLevel::High, | ||
| }, | ||
| min_confirmations: NonZeroU32::try_from(1).expect("1 aint 0"), | ||
| }; // maybe this could be defaulted | ||
| let wallet = | ||
| LightWallet::new(chain_type, wallet_base, birthday, wallet_settings.clone()) | ||
| .map_err(AddServerError::CreateLightWallet)?; | ||
| // ZingoConfig allows a save-director of None, but crashes if that value is used. | ||
| let save_dir = tempfile::TempDir::new()?; | ||
| let config = { | ||
| ZingoConfigBuilder::default() | ||
| .set_lightwalletd_uri(server_uri) | ||
| .set_wallet_settings(wallet_settings) | ||
| .set_no_of_accounts(no_of_accounts) | ||
| .set_wallet_dir(save_dir.path().to_path_buf()) | ||
| .create() | ||
| }; | ||
| let overwrite = false; | ||
| let mut lightclient = LightClient::create_from_wallet(wallet, config, overwrite)?; | ||
| lightclient | ||
| .sync() | ||
| .await | ||
| .map_err(AddServerError::StartSync)?; | ||
| self.lightclient = Some(lightclient); | ||
| Ok(()) | ||
| } else { | ||
| Err(AddServerError::NeedsSingleSeed) | ||
| } | ||
| } | ||
|
|
||
| type AddKeyError = AddKeyError; | ||
|
|
||
| async fn add_key(&mut self, key_string: String) -> Result<(), Self::AddKeyError> { | ||
| if self.keys.is_empty() { | ||
| self.keys.push(key_string); | ||
| Ok(()) | ||
| } else { | ||
| Err(AddKeyError::AlreadyHasKey) | ||
| } | ||
| } | ||
|
|
||
| type GetMaxScannedHeightError = GetMaxScannedHeightError; | ||
|
|
||
| async fn get_max_scanned_height_for_server( | ||
| &mut self, | ||
| _server: String, | ||
| ) -> Result<zcash_wallet_interface::BlockHeight, Self::GetMaxScannedHeightError> { | ||
| use zcash_client_backend::data_api::WalletRead; | ||
|
|
||
| match &self.lightclient { | ||
| Some(client) => Ok(client | ||
| .wallet | ||
| .read() | ||
| .await | ||
| .chain_height() | ||
| .map_err(GetMaxScannedHeightError::WalletError)? | ||
| .map(|h| zcash_wallet_interface::BlockHeight(h.into())) | ||
| .unwrap_or(BlockHeight(0))), | ||
| None => Err(GetMaxScannedHeightError::NoServer), | ||
| } | ||
| } | ||
|
|
||
| type PayError = (); | ||
|
|
||
| async fn pay( | ||
| &mut self, | ||
| payments: Vec<zcash_wallet_interface::Payment>, | ||
|
Check failure on line 198 in zingo_wallet/src/interface.rs
|
||
| ) -> Result<(), Self::PayError> { | ||
| todo!() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pub mod interface; | ||
|
|
||
| pub struct ZingoWallet { | ||
| keys: Vec<String>, //todo parsing and keyring | ||
| lightclient: Option<zingolib::lightclient::LightClient>, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| //! A mod that will include common stuff to tests. Once they exist. |
Uh oh!
There was an error while loading. Please reload this page.