Skip to content

Commit

Permalink
Web Client Submit Transaction Fix (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
dagarcia7 authored Feb 26, 2025
1 parent 4247bfc commit 4b72656
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Changelog

## 0.7.2 (TBD)

* Web Client: Exposed `InputNotes` iterator and `Note` `assets` property

## 0.7.1 (2025-02-19)
## 0.7.1 (TBD)

* [BREAKING] Added Initial Web Workers Implementation to Web Client (#720).
* Web Client Fix: Handled Case Where Web Workers are Not Available (#743).
* Web Client: Exposed `InputNotes` iterator and `Note` `assets` property (#757).
* Web Client Submit Transaction Fix: Typescript Typings Now Match Underlying Client Call (#760).

## 0.7.0 (2025-01-28)

Expand Down
2 changes: 1 addition & 1 deletion crates/web-client/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export class WebClient {
}
}

async submit_transaction(transactionResult, prover = null) {
async submit_transaction(transactionResult, prover = undefined) {
try {
if (!this.worker) {
return await this.wasmWebClient.submit_transaction(
Expand Down
13 changes: 4 additions & 9 deletions crates/web-client/js/workers/web-client-methods-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ const methodHandlers = {
new Uint8Array(serializedTransactionResult)
);

let prover = undefined;
if (serializedProver) {
// A prover was provided, so determine which one it is.
let prover;
if (serializedProver.startsWith("remote:")) {
// For a remote prover, extract the endpoint.
// For example, "remote:https://my-custom-endpoint.com" becomes "https://my-custom-endpoint.com"
Expand All @@ -161,14 +160,10 @@ const methodHandlers = {
} else {
throw new Error("Invalid prover tag received in worker");
}
await wasmWebClient.submit_transaction_with_prover(
transactionResult,
prover
);
} else {
// No prover was passed, so submit the transaction without one.
await wasmWebClient.submit_transaction(transactionResult);
}

// Call the unified submit_transaction method with an optional prover.
await wasmWebClient.submit_transaction(transactionResult, prover);
return;
},
[MethodName.SYNC_STATE]: async () => {
Expand Down
2 changes: 1 addition & 1 deletion crates/web-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@demox-labs/miden-sdk",
"version": "0.7.0",
"version": "0.7.2",
"description": "Polygon Miden Wasm SDK",
"collaborators": [
"Polygon Miden",
Expand Down
42 changes: 19 additions & 23 deletions crates/web-client/src/new_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,28 @@ impl WebClient {
pub async fn submit_transaction(
&mut self,
transaction_result: &TransactionResult,
prover: Option<TransactionProver>,
) -> Result<(), JsValue> {
if let Some(client) = self.get_mut_inner() {
let native_transaction_result: NativeTransactionResult = transaction_result.into();
client.submit_transaction(native_transaction_result).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 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))
})?;

match prover {
Some(p) => {
client
.submit_transaction_with_prover(native_transaction_result, p.get_prover())
.await
.map_err(|err| {
JsValue::from_str(&format!(
"Failed to submit Transaction with prover: {}",
err
))
})?;
},
None => {
client.submit_transaction(native_transaction_result).await.map_err(|err| {
JsValue::from_str(&format!("Failed to submit Transaction: {}", err))
})?;
},
}
Ok(())
} else {
Err(JsValue::from_str("Client not initialized"))
Expand Down

0 comments on commit 4b72656

Please sign in to comment.