Skip to content

Commit

Permalink
Merge branch 'next' into igamigo-block-num
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo authored Jan 20, 2025
2 parents 2dbe955 + 5f455b8 commit f69fdf5
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 174 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [BREAKING] Added support for specifying map storage slots for FPI (#645)
* Limited the number of decimals that an asset can have (#666).
* [BREAKING] Removed the `testing` feature from the CLI (#670).
* Added per transaction prover support to the web client (#674).
* [BREAKING] Added `BlockNumber` structure (#677).

### Fixes
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/web-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ miden-client = { version = "0.6", path = "../rust-client", default-features = fa
miden-lib = { workspace = true }
miden-objects = { workspace = true }
miden-proving-service-client = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["tx-prover"] }
miden-remote-provers = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["tx-prover"] }
miden-tx = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
serde-wasm-bindgen = { version = "0.6" }
Expand All @@ -34,4 +36,5 @@ console_error_panic_hook = "0.1"
miden-client = { path = "../rust-client", default-features = false, features = ["idxdb", "web-tonic", "testing"] }
miden-lib = { workspace = true, default-features = false, features = ["testing"] }
miden-objects = { workspace = true, default-features = false, features = ["testing"] }
miden-tx = { workspace = true, features = ["testing"] }
web-sys = { version = "0.3", features = ["console"]}
2 changes: 2 additions & 0 deletions crates/web-client/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const {
Rpo256,
TestUtils,
TransactionFilter,
TransactionProver,
TransactionRequest,
TransactionRequestBuilder,
TransactionScriptInputPair,
Expand Down Expand Up @@ -76,6 +77,7 @@ export {
Rpo256,
TestUtils,
TransactionFilter,
TransactionProver,
TransactionRequest,
TransactionRequestBuilder,
TransactionScriptInputPair,
Expand Down
1 change: 1 addition & 0 deletions crates/web-client/js/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export {
SerializedAccountHeader,
TestUtils,
TransactionFilter,
TransactionProver,
TransactionRequest,
TransactionRequestBuilder,
TransactionScriptInputPair,
Expand Down
1 change: 1 addition & 0 deletions crates/web-client/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub mod note_type;
pub mod output_note;
pub mod output_notes;
pub mod partial_note;
pub mod provers;
pub mod rpo256;
pub mod rpo_digest;
pub mod sync_summary;
Expand Down
29 changes: 29 additions & 0 deletions crates/web-client/src/models/provers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use alloc::sync::Arc;

use miden_remote_provers::RemoteTransactionProver;
use miden_tx::{LocalTransactionProver, TransactionProver as TransactionProverTrait};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub struct TransactionProver {
prover: Arc<dyn TransactionProverTrait>,
}

#[wasm_bindgen]
impl TransactionProver {
pub fn new_local_prover() -> TransactionProver {
let local_prover = LocalTransactionProver::new(Default::default());
TransactionProver { prover: Arc::new(local_prover) }
}

pub fn new_remote_prover(endpoint: &str) -> TransactionProver {
let remote_prover = RemoteTransactionProver::new(endpoint);
TransactionProver { prover: Arc::new(remote_prover) }
}
}

impl TransactionProver {
pub fn get_prover(&self) -> Arc<dyn TransactionProverTrait> {
self.prover.clone()
}
}
25 changes: 23 additions & 2 deletions crates/web-client/src/new_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use wasm_bindgen::prelude::*;

use crate::{
models::{
account_id::AccountId, note_type::NoteType, transaction_request::TransactionRequest,
transaction_result::TransactionResult, transactions::NewSwapTransactionResult,
account_id::AccountId, note_type::NoteType, provers::TransactionProver,
transaction_request::TransactionRequest, transaction_result::TransactionResult,
transactions::NewSwapTransactionResult,
},
WebClient,
};
Expand Down Expand Up @@ -71,6 +72,26 @@ impl WebClient {
}
}

pub async fn submit_transaction_with_prover(
&mut self,
transaction_result: &TransactionResult,
prover: TransactionProver,
) -> Result<(), JsValue> {
if let Some(client) = self.get_mut_inner() {
let native_transaction_result: NativeTransactionResult = transaction_result.into();
client
.submit_transaction_with_prover(native_transaction_result, prover.get_prover())
.await
.map_err(|err| {
JsValue::from_str(&format!("Failed to submit Transaction: {}", err))
})?;

Ok(())
} else {
Err(JsValue::from_str("Client not initialized"))
}
}

pub async fn new_mint_transaction(
&mut self,
target_account_id: &AccountId,
Expand Down
3 changes: 3 additions & 0 deletions crates/web-client/test/global.test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
Rpo256,
TestUtils,
TransactionFilter,
TransactionProver,
TransactionRequest,
TransactionRequestBuilder,
TransactionScriptInputPair,
Expand All @@ -40,6 +41,7 @@ import {
declare global {
interface Window {
client: WebClient;
remote_prover_url: string;
Account: typeof Account;
AccountHeader: typeof AccountHeader;
AccountId: typeof AccountId;
Expand Down Expand Up @@ -69,6 +71,7 @@ declare global {
Rpo256: typeof Rpo256;
TestUtils: typeof TestUtils;
TransactionFilter: typeof TransactionFilter;
TransactionProver: typeof TransactionProver;
TransactionRequest: typeof TransactionRequest;
TransactionRequestBuilder: typeof TransactionRequestBuilder;
TransactionScriptInputPair: typeof TransactionScriptInputPair;
Expand Down
5 changes: 5 additions & 0 deletions crates/web-client/test/mocha.global.setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ before(async () => {
Rpo256,
TestUtils,
TransactionFilter,
TransactionProver,
TransactionRequest,
TransactionRequestBuilder,
TransactionScriptInputPair,
Expand Down Expand Up @@ -127,6 +128,7 @@ before(async () => {
window.Rpo256 = Rpo256;
window.TestUtils = TestUtils;
window.TransactionFilter = TransactionFilter;
window.TransactionProver = TransactionProver;
window.TransactionRequest = TransactionRequest;
window.TransactionRequestBuilder = TransactionRequestBuilder;
window.TransactionScriptInputPair = TransactionScriptInputPair;
Expand All @@ -136,6 +138,9 @@ before(async () => {
// Create a namespace for helper functions
window.helpers = window.helpers || {};

// Add the remote prover url to window
window.remote_prover_url = prover_url;

window.helpers.waitForTransaction = async (
transactionId,
maxWaitTime = 20000,
Expand Down
Loading

0 comments on commit f69fdf5

Please sign in to comment.