Skip to content

Commit 931e814

Browse files
authored
Web client: make block_hash optional arg of query fn (#4904)
Backport of #4905 ## Motivation In previous PRs we introduced an option to query app's state at a specific block (hash). It made the `query` method NOT backwards compatible b/c it required the new argument to be present. ## Proposal Make argument optional. This allows `wasm-bindgen` to generate a code that does not fail when argument is not passed in. ## Test Plan Manual. I tested the metamask demo – which doesn't supply the argument – and it worked. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent fe799f8 commit 931e814

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

examples/counter/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting chain…</code>
103103
});
104104

105105
incrementButton.addEventListener('click', () => {
106-
counter.query('{ "query": "mutation { increment(value: 1) }" }', '');
106+
counter.query('{ "query": "mutation { increment(value: 1) }" }');
107107
});
108108
}
109109

linera-web/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,13 @@ impl Application {
477477
#[wasm_bindgen]
478478
// TODO(#14) allow passing bytes here rather than just strings
479479
// TODO(#15) a lot of this logic is shared with `linera_service::node_service`
480-
pub async fn query(&self, query: &str, block_hash: &str) -> JsResult<String> {
480+
pub async fn query(&self, query: &str, block_hash: Option<String>) -> JsResult<String> {
481481
tracing::debug!("querying application: {query}");
482482
let chain_client = self.client.default_chain_client().await?;
483-
let block_hash = if block_hash.is_empty() {
484-
None
483+
let block_hash = if let Some(hash) = block_hash {
484+
Some(hash.as_str().parse()?)
485485
} else {
486-
Some(block_hash.parse()?)
486+
None
487487
};
488488
let linera_execution::QueryOutcome {
489489
response: linera_execution::QueryResponse::User(response),

0 commit comments

Comments
 (0)