Skip to content

Commit

Permalink
Add WebStore to miden-client (#402)
Browse files Browse the repository at this point in the history
* Add WebStore to miden-client

* Rebased off latest next

* Rust docs command fix

---------

Co-authored-by: Dennis Garcia <[email protected]>
  • Loading branch information
dagarcia7 and Dennis Garcia authored Jul 2, 2024
1 parent 146a076 commit d0a0741
Show file tree
Hide file tree
Showing 33 changed files with 3,889 additions and 5 deletions.
5 changes: 5 additions & 0 deletions crates/rust-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ crate-type = ["lib"]
async = ["miden-tx/async"]
concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-tx/concurrent", "std"]
default = ["std"]
idxdb = ["async", "dep:base64", "dep:serde-wasm-bindgen", "dep:wasm-bindgen", "dep:wasm-bindgen-futures"]
integration = ["concurrent", "testing", "std", "sqlite", "tonic"]
sqlite = ["dep:rusqlite", "dep:rusqlite_migration", "dep:lazy_static"]
std = ["miden-objects/std"]
testing = ["miden-objects/testing", "miden-lib/testing"]
tonic = ["dep:hex", "dep:prost","dep:tonic"]

[dependencies]
base64 = { version = "0.13", optional = true }
chrono = { version = "0.4", optional = false }
hex = { version = "0.4" , optional = true}
lazy_static = { version = "1.4", optional = true }
Expand All @@ -37,10 +39,13 @@ rusqlite = { version = "0.30", features = ["vtab", "array", "bundled"], optional
rusqlite_migration = { version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
serde-wasm-bindgen = { version = "0.6", optional = true }
thiserror = { version = "1.0", optional = true }
tokio = { workspace = true , optional = true }
tonic = { version = "0.11", optional = true }
tracing = { workspace = true }
wasm-bindgen = { version = "0.2", features = ["serde-serialize"], optional = true }
wasm-bindgen-futures = { version = "0.4", optional = true }
winter-maybe-async = "0.10.0"

[target.'wasm32-unknown-unknown'.dependencies]
Expand Down
8 changes: 6 additions & 2 deletions crates/rust-client/src/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator> Client
let tracked_note = tracked_note?;

// TODO: Join these calls to one method that updates both fields with one query (issue #404)
self.store.update_note_inclusion_proof(tracked_note.id(), inclusion_proof)?;
self.store.update_note_metadata(tracked_note.id(), *note_details.metadata())?;
maybe_await!(self
.store
.update_note_inclusion_proof(tracked_note.id(), inclusion_proof))?;
maybe_await!(self
.store
.update_note_metadata(tracked_note.id(), *note_details.metadata()))?;

return Ok(tracked_note.id());
}
Expand Down
5 changes: 5 additions & 0 deletions crates/rust-client/src/rpc/tonic_client/generated/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub struct GetBlockInputsRequest {
/// Array of nullifiers for all notes consumed by a transaction.
#[prost(message, repeated, tag = "2")]
pub nullifiers: ::prost::alloc::vec::Vec<super::digest::Digest>,
/// Array of note IDs to be checked for existence in the database.
#[prost(message, repeated, tag = "3")]
pub unauthenticated_notes: ::prost::alloc::vec::Vec<super::digest::Digest>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand All @@ -78,6 +81,8 @@ pub struct GetTransactionInputsRequest {
pub account_id: ::core::option::Option<super::account::AccountId>,
#[prost(message, repeated, tag = "2")]
pub nullifiers: ::prost::alloc::vec::Vec<super::digest::Digest>,
#[prost(message, repeated, tag = "3")]
pub unauthenticated_notes: ::prost::alloc::vec::Vec<super::digest::Digest>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct GetBlockInputsResponse {
/// The latest block header
#[prost(message, optional, tag = "1")]
pub block_header: ::core::option::Option<super::block_header::BlockHeader>,
/// Peaks of the above block's mmr, The `forest` value is equal to the block number.
/// Peaks of the above block's mmr, The `forest` value is equal to the block number
#[prost(message, repeated, tag = "2")]
pub mmr_peaks: ::prost::alloc::vec::Vec<super::digest::Digest>,
/// The hashes of the requested accounts and their authentication paths
Expand All @@ -91,6 +91,9 @@ pub struct GetBlockInputsResponse {
/// The requested nullifiers and their authentication paths
#[prost(message, repeated, tag = "4")]
pub nullifiers: ::prost::alloc::vec::Vec<NullifierBlockInputRecord>,
/// The list of requested notes which were found in the database
#[prost(message, repeated, tag = "5")]
pub found_unauthenticated_notes: ::prost::alloc::vec::Vec<super::digest::Digest>,
}
/// An account returned as a response to the GetTransactionInputs
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down Expand Up @@ -119,6 +122,8 @@ pub struct GetTransactionInputsResponse {
pub account_state: ::core::option::Option<AccountTransactionInputRecord>,
#[prost(message, repeated, tag = "2")]
pub nullifiers: ::prost::alloc::vec::Vec<NullifierTransactionInputRecord>,
#[prost(message, repeated, tag = "3")]
pub missing_unauthenticated_notes: ::prost::alloc::vec::Vec<super::digest::Digest>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
5 changes: 5 additions & 0 deletions crates/rust-client/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub mod data_store;
#[cfg(feature = "sqlite")]
pub mod sqlite_store;

#[cfg(feature = "idxdb")]
pub mod web_store;

mod note_record;
pub use note_record::{InputNoteRecord, NoteRecordDetails, NoteStatus, OutputNoteRecord};

Expand Down Expand Up @@ -119,13 +122,15 @@ pub trait Store {
#[maybe_async]
fn insert_input_note(&self, note: InputNoteRecord) -> Result<(), StoreError>;

#[maybe_async]
/// Updates the inclusion proof of the input note with the provided ID
fn update_note_inclusion_proof(
&self,
note_id: NoteId,
inclusion_proof: NoteInclusionProof,
) -> Result<(), StoreError>;

#[maybe_async]
/// Updates the metadata of the input note with the provided ID
fn update_note_metadata(
&self,
Expand Down
2 changes: 2 additions & 0 deletions crates/rust-client/src/store/sqlite_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ impl Store for SqliteStore {
self.get_unspent_input_note_nullifiers()
}

#[maybe_async]
fn update_note_inclusion_proof(
&self,
note_id: miden_objects::notes::NoteId,
Expand All @@ -272,6 +273,7 @@ impl Store for SqliteStore {
self.update_note_inclusion_proof(note_id, inclusion_proof)
}

#[maybe_async]
fn update_note_metadata(
&self,
note_id: miden_objects::notes::NoteId,
Expand Down
72 changes: 72 additions & 0 deletions crates/rust-client/src/store/web_store/accounts/js_bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::*;

// Account IndexedDB Operations
#[wasm_bindgen(module = "/src/store/web_store/js/accounts.js")]
extern "C" {
// GETS
// ================================================================================================
#[wasm_bindgen(js_name = getAccountIds)]
pub fn idxdb_get_account_ids() -> js_sys::Promise;

#[wasm_bindgen(js_name = getAllAccountStubs)]
pub fn idxdb_get_account_stubs() -> js_sys::Promise;

#[wasm_bindgen(js_name = getAccountStub)]
pub fn idxdb_get_account_stub(account_id: String) -> js_sys::Promise;

#[wasm_bindgen(js_name = getAccountCode)]
pub fn idxdb_get_account_code(code_root: String) -> js_sys::Promise;

#[wasm_bindgen(js_name = getAccountStorage)]
pub fn idxdb_get_account_storage(storage_root: String) -> js_sys::Promise;

#[wasm_bindgen(js_name = getAccountAssetVault)]
pub fn idxdb_get_account_asset_vault(vault_root: String) -> js_sys::Promise;

#[wasm_bindgen(js_name = getAccountAuth)]
pub fn idxdb_get_account_auth(account_id: String) -> js_sys::Promise;

#[wasm_bindgen(js_name = getAccountAuthByPubKey)]
pub fn idxdb_get_account_auth_by_pub_key(pub_key: Vec<u8>) -> JsValue;

#[wasm_bindgen(js_name = fetchAndCacheAccountAuthByPubKey)]
pub fn idxdb_fetch_and_cache_account_auth_by_pub_key(account_id: String) -> js_sys::Promise;

// INSERTS
// ================================================================================================

#[wasm_bindgen(js_name = insertAccountCode)]
pub fn idxdb_insert_account_code(
code_root: String,
code: String,
module: Vec<u8>,
) -> js_sys::Promise;

#[wasm_bindgen(js_name = insertAccountStorage)]
pub fn idxdb_insert_account_storage(
storage_root: String,
storage_slots: Vec<u8>,
) -> js_sys::Promise;

#[wasm_bindgen(js_name = insertAccountAssetVault)]
pub fn idxdb_insert_account_asset_vault(vault_root: String, assets: String) -> js_sys::Promise;

#[wasm_bindgen(js_name = insertAccountRecord)]
pub fn idxdb_insert_account_record(
id: String,
code_root: String,
storage_root: String,
vault_root: String,
nonce: String,
committed: bool,
account_seed: Option<Vec<u8>>,
) -> js_sys::Promise;

#[wasm_bindgen(js_name = insertAccountAuth)]
pub fn idxdb_insert_account_auth(
id: String,
auth_info: Vec<u8>,
pub_key: Vec<u8>,
) -> js_sys::Promise;
}
Loading

0 comments on commit d0a0741

Please sign in to comment.