Skip to content

Commit

Permalink
chore: Update web-client API; remove off-chain and on-chain reference…
Browse files Browse the repository at this point in the history
…s everywhere
  • Loading branch information
igamigo committed Jan 22, 2025
1 parent cf9d274 commit 7357286
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [BREAKING] Removed the `testing` feature from the CLI (#670).
* Added per transaction prover support to the web client (#674).
* [BREAKING] Added `BlockNumber` structure (#677).
* [BREAKING] Made `idxdb` only usable on WASM targets (#685).

### Fixes

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl NodeRpcClient for MockRpcApi {
}

async fn get_notes_by_id(&mut self, note_ids: &[NoteId]) -> Result<Vec<NetworkNote>, 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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-client/src/rpc/tonic_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,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
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-client/src/rpc/web_tonic_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions crates/rust-client/src/store/web_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use crate::{
transactions::{TransactionRecord, TransactionStoreUpdate},
};

#[cfg(not(target_arch = "wasm32"))]
compile_error!("The `idxdb` feature is only supported when targeting wasm32.")

pub mod accounts;
pub mod chain_data;
pub mod notes;
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-client/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl<R: FeltRng> Client<R> {
.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 =
Expand Down
68 changes: 40 additions & 28 deletions crates/web-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.

<label for="noteFileInput" class="custom-file-upload">
Choose Note File
Expand Down Expand Up @@ -186,7 +186,7 @@ console.log("testExportNote started");
let webClient = await createMidenWebClient();

// Create a faucet and mint a mint transaction
let faucetId = await createNewFaucet(webClient, "OffChain", false, "DEN", "10", "1000000");
let faucetId = await createNewFaucet(webClient, "Private", false, "DEN", "10", "1000000");
await syncState(webClient);
await new Promise(r => setTimeout(r, 20000)); // Artificial delays to ensure sync is processed on remote node before continuing

Expand Down Expand Up @@ -234,11 +234,15 @@ let webClient = await createMidenWebClient();

/**
* get_input_notes takes a filter to retrieve notes based on a specific status. The options are the following:
* "All"
* "Consumed"
* "Committed"
* "Expected"
* "Processing"
* "All",
* "Consumed",
* "Committed",
* "Expected",
* "Processing",
* "List",
* "Unique",
* "Nullifiers",
* "Unverified",
*/
const notes = await webClient.get_input_notes("All")
```
Expand Down Expand Up @@ -391,11 +395,15 @@ new_swap_transaction(sender_account_id: string, offered_asset_faucet_id: string,
* @returns {Promise<any>}
*
* Examples of valid filters:
* "All"
* "Consumed"
* "Committed"
* "Expected"
* "Processing"
* "All",
* "Consumed",
* "Committed",
* "Expected",
* "Processing",
* "List",
* "Unique",
* "Nullifiers",
* "Unverified",
*/
get_input_notes(filter: any): Promise<any>;

Expand All @@ -408,19 +416,23 @@ get_input_note(note_id: string): Promise<any>;
/**
* @param {any} filter
* @returns {Promise<any>}
*
* Examples of valid filters:
* "All",
* "Consumed",
* "Committed",
* "Expected",
* "Processing",
* "List",
* "Unique",
* "Nullifiers",
* "Unverified",
*/
get_output_notes(filter: any): Promise<any>;

/**
* @param {string} note_id
* @returns {Promise<any>}
*
* Examples of valid filters:
* "All"
* "Consumed"
* "Committed"
* "Expected"
* "Processing"
*/
get_output_note(note_id: string): Promise<any>;

Expand Down

0 comments on commit 7357286

Please sign in to comment.