Skip to content

Commit 4c7fa06

Browse files
committed
trying to get web wallet working still
1 parent d9c48b9 commit 4c7fa06

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

src/bindgen/wallet.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use tonic_web_wasm_client::Client;
77

88
use zcash_address::ZcashAddress;
99
use zcash_client_memory::MemoryWalletDb;
10-
use zcash_primitives::consensus::{self, BlockHeight};
10+
use zcash_keys::keys::UnifiedFullViewingKey;
11+
use zcash_primitives::consensus::{self, BlockHeight, NetworkConstants, MAIN_NETWORK};
1112

1213
use crate::error::Error;
1314
use crate::{BlockRange, MemoryWallet, Wallet, PRUNING_DEPTH};
@@ -84,6 +85,21 @@ impl WebWallet {
8485
.await
8586
}
8687

88+
pub async fn import_ufvk(
89+
&mut self,
90+
key: &str,
91+
birthday_height: Option<u32>,
92+
) -> Result<String, Error> {
93+
let s = zcash_keys::encoding::decode_extended_full_viewing_key(
94+
MAIN_NETWORK.hrp_sapling_extended_full_viewing_key(),
95+
&key.trim(),
96+
)
97+
.unwrap();
98+
let ufvk = UnifiedFullViewingKey::from_sapling_extended_full_viewing_key(s).unwrap();
99+
100+
self.inner.import_ufvk(ufvk, birthday_height).await
101+
}
102+
87103
pub fn suggest_scan_ranges(&self) -> Result<Vec<BlockRange>, Error> {
88104
self.inner.suggest_scan_ranges()
89105
}

src/wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ where
192192

193193
let _account = self
194194
.db
195-
.import_account_ufvk(&ufvk, &birthday, AccountPurpose::Spending)?;
195+
.import_account_ufvk(&ufvk, &birthday, AccountPurpose::ViewOnly)?;
196196

197197
Ok("0".to_string())
198198
}

tests/tests.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
33

44
use webz_core::{bindgen::wallet::WebWallet, Wallet};
55
use zcash_address::ZcashAddress;
6-
use zcash_primitives::consensus::Network;
6+
use zcash_keys::keys::UnifiedFullViewingKey;
7+
use zcash_primitives::{
8+
consensus::{MainNetwork, Network},
9+
constants,
10+
};
711

812
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";
913
const HD_INDEX: u32 = 0;
@@ -17,14 +21,23 @@ pub fn initialize() {
1721
webz_core::init::start();
1822
});
1923
}
24+
const key_str: &'static str = "zxviews1q0duytgcqqqqpqre26wkl45gvwwwd706xw608hucmvfalr759ejwf7qshjf5r9aa7323zulvz6plhttp5mltqcgs9t039cx2d09mgq05ts63n8u35hyv6h9nc9ctqqtue2u7cer2mqegunuulq2luhq3ywjcz35yyljewa4mgkgjzyfwh6fr6jd0dzd44ghk0nxdv2hnv4j5nxfwv24rwdmgllhe0p8568sgqt9ckt02v2kxf5ahtql6s0ltjpkckw8gtymxtxuu9gcr0swvz";
2025

2126
#[wasm_bindgen_test]
2227
async fn test_get_and_scan_range() {
2328
initialize();
2429

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

27-
let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap();
32+
// let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap();
33+
let s = zcash_keys::encoding::decode_extended_full_viewing_key(
34+
constants::mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
35+
&key_str.trim(),
36+
)
37+
.unwrap();
38+
39+
let id = w.import_ufvk(&key_str, Some(2477329)).await.unwrap();
40+
2841
tracing::info!("Created account with id: {}", id);
2942

3043
tracing::info!("Syncing wallet");
@@ -126,8 +139,6 @@ async fn test_get_and_scan_range_native() {
126139
#[cfg(feature = "native")]
127140
#[tokio::test]
128141
async fn test_post_board() {
129-
let key_str = "zxviews1q0duytgcqqqqpqre26wkl45gvwwwd706xw608hucmvfalr759ejwf7qshjf5r9aa7323zulvz6plhttp5mltqcgs9t039cx2d09mgq05ts63n8u35hyv6h9nc9ctqqtue2u7cer2mqegunuulq2luhq3ywjcz35yyljewa4mgkgjzyfwh6fr6jd0dzd44ghk0nxdv2hnv4j5nxfwv24rwdmgllhe0p8568sgqt9ckt02v2kxf5ahtql6s0ltjpkckw8gtymxtxuu9gcr0swvz";
130-
131142
use zcash_keys::keys::UnifiedFullViewingKey;
132143
use zcash_primitives::{consensus, constants};
133144
let db_cache = tempfile::tempdir().unwrap();

0 commit comments

Comments
 (0)