Skip to content

Commit

Permalink
trying to get web wallet working still
Browse files Browse the repository at this point in the history
  • Loading branch information
ec2 committed Sep 16, 2024
1 parent d9c48b9 commit 4c7fa06
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
18 changes: 17 additions & 1 deletion src/bindgen/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use tonic_web_wasm_client::Client;

use zcash_address::ZcashAddress;
use zcash_client_memory::MemoryWalletDb;
use zcash_primitives::consensus::{self, BlockHeight};
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_primitives::consensus::{self, BlockHeight, NetworkConstants, MAIN_NETWORK};

use crate::error::Error;
use crate::{BlockRange, MemoryWallet, Wallet, PRUNING_DEPTH};
Expand Down Expand Up @@ -84,6 +85,21 @@ impl WebWallet {
.await
}

pub async fn import_ufvk(
&mut self,
key: &str,
birthday_height: Option<u32>,
) -> Result<String, Error> {
let s = zcash_keys::encoding::decode_extended_full_viewing_key(
MAIN_NETWORK.hrp_sapling_extended_full_viewing_key(),
&key.trim(),
)
.unwrap();
let ufvk = UnifiedFullViewingKey::from_sapling_extended_full_viewing_key(s).unwrap();

self.inner.import_ufvk(ufvk, birthday_height).await
}

pub fn suggest_scan_ranges(&self) -> Result<Vec<BlockRange>, Error> {
self.inner.suggest_scan_ranges()
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ where

let _account = self
.db
.import_account_ufvk(&ufvk, &birthday, AccountPurpose::Spending)?;
.import_account_ufvk(&ufvk, &birthday, AccountPurpose::ViewOnly)?;

Ok("0".to_string())
}
Expand Down
19 changes: 15 additions & 4 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

use webz_core::{bindgen::wallet::WebWallet, Wallet};
use zcash_address::ZcashAddress;
use zcash_primitives::consensus::Network;
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_primitives::{
consensus::{MainNetwork, Network},
constants,
};

const SEED: &str = "visit armed kite pen cradle toward reward clay marble oil write dove blind oyster silk oyster original message skate bench tone enable stadium element";
const HD_INDEX: u32 = 0;
Expand All @@ -17,14 +21,23 @@ pub fn initialize() {
webz_core::init::start();
});
}
const key_str: &'static str = "zxviews1q0duytgcqqqqpqre26wkl45gvwwwd706xw608hucmvfalr759ejwf7qshjf5r9aa7323zulvz6plhttp5mltqcgs9t039cx2d09mgq05ts63n8u35hyv6h9nc9ctqqtue2u7cer2mqegunuulq2luhq3ywjcz35yyljewa4mgkgjzyfwh6fr6jd0dzd44ghk0nxdv2hnv4j5nxfwv24rwdmgllhe0p8568sgqt9ckt02v2kxf5ahtql6s0ltjpkckw8gtymxtxuu9gcr0swvz";

#[wasm_bindgen_test]
async fn test_get_and_scan_range() {
initialize();

let mut w = WebWallet::new("test", "https://zcash-testnet.chainsafe.dev", 1).unwrap();

let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap();
// let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap();
let s = zcash_keys::encoding::decode_extended_full_viewing_key(
constants::mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
&key_str.trim(),
)
.unwrap();

let id = w.import_ufvk(&key_str, Some(2477329)).await.unwrap();

tracing::info!("Created account with id: {}", id);

tracing::info!("Syncing wallet");
Expand Down Expand Up @@ -126,8 +139,6 @@ async fn test_get_and_scan_range_native() {
#[cfg(feature = "native")]
#[tokio::test]
async fn test_post_board() {
let key_str = "zxviews1q0duytgcqqqqpqre26wkl45gvwwwd706xw608hucmvfalr759ejwf7qshjf5r9aa7323zulvz6plhttp5mltqcgs9t039cx2d09mgq05ts63n8u35hyv6h9nc9ctqqtue2u7cer2mqegunuulq2luhq3ywjcz35yyljewa4mgkgjzyfwh6fr6jd0dzd44ghk0nxdv2hnv4j5nxfwv24rwdmgllhe0p8568sgqt9ckt02v2kxf5ahtql6s0ltjpkckw8gtymxtxuu9gcr0swvz";

use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_primitives::{consensus, constants};
let db_cache = tempfile::tempdir().unwrap();
Expand Down

0 comments on commit 4c7fa06

Please sign in to comment.