Skip to content

Commit

Permalink
feat: add submit_with_prover to web client
Browse files Browse the repository at this point in the history
fix: test

docs: update changelog
  • Loading branch information
SantiagoPittella committed Jan 16, 2025
1 parent 4da9b05 commit 8947948
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Added support for unauthenticated notes consumption in the CLI (#609).
* [BREAKING] Added foreign procedure invocation support for private accounts (#619).
* [BREAKING] Added support for specifying map storage slots for FPI (#645)
* Added per transaction prover support to the web client (#674).

### 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.

1 change: 1 addition & 0 deletions crates/web-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ miden-client = { version = "0.6", path = "../rust-client", default-features = fa
miden-lib = { workspace = true }
miden-objects = { workspace = true }
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 Down
2 changes: 2 additions & 0 deletions crates/web-client/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
NoteType,
OutputNote,
OutputNotesArray,
ProverWrapper,
Rpo256,
TestUtils,
TransactionFilter,
Expand Down Expand Up @@ -72,6 +73,7 @@ export {
NoteType,
OutputNote,
OutputNotesArray,
ProverWrapper,
Rpo256,
TestUtils,
TransactionFilter,
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 @@ -29,6 +29,7 @@ export {
NoteType,
OutputNote,
OutputNotesArray,
ProverWrapper,
Rpo256,
SerializedAccountHeader,
TestUtils,
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
32 changes: 32 additions & 0 deletions crates/web-client/src/models/provers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use alloc::sync::Arc;
use miden_remote_provers::RemoteTransactionProver;
use miden_tx::{LocalTransactionProver, TransactionProver};
use wasm_bindgen::prelude::*;

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

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

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

impl ProverWrapper {
pub fn get_prover(&self) -> Arc<dyn TransactionProver> {
self.prover.clone()
}
}
30 changes: 25 additions & 5 deletions crates/web-client/src/new_transactions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use miden_client::{
notes::get_input_note_with_id_prefix,
transactions::{
PaymentTransactionData, SwapTransactionData,
TransactionRequestBuilder as NativeTransactionRequestBuilder,
TransactionResult as NativeTransactionResult,
PaymentTransactionData, SwapTransactionData, TransactionRequestBuilder as NativeTransactionRequestBuilder, TransactionResult as NativeTransactionResult
},
};
use miden_lib::notes::utils::build_swap_tag;
Expand All @@ -12,8 +10,7 @@ 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::ProverWrapper, transaction_request::TransactionRequest, transaction_result::TransactionResult, transactions::NewSwapTransactionResult
},
WebClient,
};
Expand Down Expand Up @@ -71,6 +68,29 @@ impl WebClient {
}
}

pub async fn submit_transaction_with_prover(
&mut self,
transaction_result: &TransactionResult,
prover: ProverWrapper,
) -> 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
2 changes: 2 additions & 0 deletions crates/web-client/test/mocha.global.setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ before(async () => {
OutputNote,
OutputNotesArray,
Rpo256,
ProverWrapper,
TestUtils,
TransactionFilter,
TransactionRequest,
Expand Down Expand Up @@ -124,6 +125,7 @@ before(async () => {
window.OutputNote = OutputNote;
window.OutputNotesArray = OutputNotesArray;
window.Rpo256 = Rpo256;
window.ProverWrapper = ProverWrapper;
window.TestUtils = TestUtils;
window.TransactionFilter = TransactionFilter;
window.TransactionRequest = TransactionRequest;
Expand Down
5 changes: 4 additions & 1 deletion crates/web-client/test/new_transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ export const customTransaction = async (
faucetAccount.id(),
transaction_request
);
await client.submit_transaction(transaction_result);

let prover = window.ProverWrapper.new_local_prover();

await client.submit_transaction_with_prover(transaction_result, prover);
await window.helpers.waitForTransaction(
transaction_result.executed_transaction().id().to_hex()
);
Expand Down

0 comments on commit 8947948

Please sign in to comment.