From 8d55ed4363d3606131c3095b4875cbde99eecd6b Mon Sep 17 00:00:00 2001 From: igamigo Date: Thu, 23 Jan 2025 15:33:34 -0300 Subject: [PATCH] chore: Update web-client API and remove off/on chain references (#685) * chore: Update web-client API; remove off-chain and on-chain references everywhere --- CHANGELOG.md | 1 + crates/rust-client/src/mock.rs | 2 +- .../rust-client/src/rpc/tonic_client/mod.rs | 4 +- .../src/rpc/web_tonic_client/mod.rs | 4 +- crates/rust-client/src/store/web_store/mod.rs | 3 + crates/rust-client/src/sync/mod.rs | 2 +- crates/web-client/README.md | 68 +++++++++++-------- 7 files changed, 50 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d7af9cf9..3838c52a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * [BREAKING] Added `BlockNumber` structure (#677). * Created functions for creating standard notes and note scripts easily on the web client (#686). * [BREAKING] Renamed plural modules to singular (#687). +* [BREAKING] Made `idxdb` only usable on WASM targets (#685). ### Fixes diff --git a/crates/rust-client/src/mock.rs b/crates/rust-client/src/mock.rs index 90be267a9..c0b82b6d4 100644 --- a/crates/rust-client/src/mock.rs +++ b/crates/rust-client/src/mock.rs @@ -262,7 +262,7 @@ impl NodeRpcClient for MockRpcApi { } async fn get_notes_by_id(&mut self, note_ids: &[NoteId]) -> Result, RpcError> { - // assume all off-chain notes for now + // assume all private notes for now let hit_notes = note_ids.iter().filter_map(|id| self.notes.get(id)); let mut return_notes = vec![]; for note in hit_notes { diff --git a/crates/rust-client/src/rpc/tonic_client/mod.rs b/crates/rust-client/src/rpc/tonic_client/mod.rs index b57228789..65814f1a1 100644 --- a/crates/rust-client/src/rpc/tonic_client/mod.rs +++ b/crates/rust-client/src/rpc/tonic_client/mod.rs @@ -171,13 +171,13 @@ impl NodeRpcClient for TonicRpcClient { }; let note = match note.details { - // On-chain notes include details + // Public notes include details Some(details) => { let note = Note::read_from_bytes(&details)?; NetworkNote::Public(note, inclusion_details) }, - // Off-chain notes do not have details + // Private notes do not have details None => { let note_metadata = note .metadata diff --git a/crates/rust-client/src/rpc/web_tonic_client/mod.rs b/crates/rust-client/src/rpc/web_tonic_client/mod.rs index 2b7ad8ba2..a0618da3b 100644 --- a/crates/rust-client/src/rpc/web_tonic_client/mod.rs +++ b/crates/rust-client/src/rpc/web_tonic_client/mod.rs @@ -150,13 +150,13 @@ impl NodeRpcClient for WebTonicRpcClient { }; let note = match note.details { - // On-chain notes include details + // Public notes include details Some(details) => { let note = Note::read_from_bytes(&details)?; NetworkNote::Public(note, inclusion_details) }, - // Off-chain notes do not have details + // Private notes do not have details None => { let note_metadata = note .metadata diff --git a/crates/rust-client/src/store/web_store/mod.rs b/crates/rust-client/src/store/web_store/mod.rs index 694e7e2b0..53444fc59 100644 --- a/crates/rust-client/src/store/web_store/mod.rs +++ b/crates/rust-client/src/store/web_store/mod.rs @@ -20,6 +20,9 @@ use crate::{ transaction::{TransactionRecord, TransactionStoreUpdate}, }; +#[cfg(not(target_arch = "wasm32"))] +compile_error!("The `idxdb` feature is only supported when targeting wasm32."); + pub mod account; pub mod chain_data; pub mod note; diff --git a/crates/rust-client/src/sync/mod.rs b/crates/rust-client/src/sync/mod.rs index 6d88b6423..0a52054a0 100644 --- a/crates/rust-client/src/sync/mod.rs +++ b/crates/rust-client/src/sync/mod.rs @@ -596,7 +596,7 @@ impl Client { .iter() .find(|acc| *remote_account_id == acc.id() && *remote_account_hash != acc.hash()); - // OffChain accounts should always have the latest known state. If we receive a stale + // Private accounts should always have the latest known state. If we receive a stale // update we ignore it. if mismatched_account.is_some() { let account_by_hash = diff --git a/crates/web-client/README.md b/crates/web-client/README.md index 634329623..e810a7148 100644 --- a/crates/web-client/README.md +++ b/crates/web-client/README.md @@ -22,8 +22,8 @@ const webClient = new WebClient(); await webClient.create_client(); // Use WebClient to create accounts, notes, transactions, etc. -// This will create a mutable, off-chain account and store it in IndexedDB -const accountId = await webClient.new_wallet("OffChain", true); +// This will create a mutable, private account and store it in IndexedDB +const accountId = await webClient.new_wallet("Private", true); ``` ## Examples @@ -56,23 +56,23 @@ await webClient.create_client(); /** * Creates a new wallet account. * - * @param storage_mode String. Either "OffChain" or "OnChain". + * @param storage_mode String. Either "Private" or "Public". * @param mutable Boolean. Whether the wallet code is mutable or not * * Returns: Wallet Id */ -const walletId = await webClient.new_wallet("OffChain", true); +const walletId = await webClient.new_wallet("Private", true); /** * Creates a new faucet account. * - * @param storage_mode String. Either "OffChain" or "OnChain". + * @param storage_mode String. Either "Private" or "Public". * @param non_fungible Boolean. Whether the faucet is non_fungible or not. NOTE: Non-fungible faucets are not supported yet * @param token_symbol String. Token symbol of the token the faucet creates * @param decimals String. Decimal precision of token. * @param max_supply String. Maximum token supply */ -const faucetId = await webClient.new_faucet("OffChain", true, "TOK", 6, 1_000_000) +const faucetId = await webClient.new_faucet("Private", true, "TOK", 6, 1_000_000) /** * Returns all accounts. Both wallets and faucets. Returns the following object per account @@ -119,8 +119,8 @@ Let's mint some tokens for our wallet from our faucet: ```typescript const webClient = new WebClient(); await webClient.create_client(); -const walletId = await webClient.new_wallet("OffChain", true); -const faucetId = await webClient.new_faucet("OffChain", true, "TOK", 6, 1_000_000); +const walletId = await webClient.new_wallet("Private", true); +const faucetId = await webClient.new_faucet("Private", true, "TOK", 6, 1_000_000); // Syncs web client with node state. await webClient.sync_state(); @@ -153,8 +153,8 @@ You can use the WebClient to query for existing notes, export notes, and import Here is an example of how to import a note from a file (generated, say, from the faucet at https://testnet.miden.io/ for a given account). This code exposes a simple button on an HTML page for a user to select a file. A listener is setup to capture this event, serialize the note file, and import it. ```typescript let webClient = await createMidenWebClient(); -let walletAccount = await webClient.new_wallet("OffChain", true); -console.log(walletAccount); // Prints the id that can be used to plug in to the deployed Miden faucet +let walletAccount = await webClient.new_wallet("Private", true); // The second argument defines that the wallet has mutable code. +console.log(walletAccount); // Prints the id that can be used to plug in to the deployed Miden faucet.