Skip to content

Commit 4cb1f78

Browse files
authored
Web client: make block_hash optional arg of query fn (#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 - Backport to TestNet branch - 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 f7d51f1 commit 4cb1f78

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
@@ -101,7 +101,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting chain…</code>
101101
});
102102

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

web/@linera/client/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,13 @@ impl Application {
465465
#[wasm_bindgen]
466466
// TODO(#14) allow passing bytes here rather than just strings
467467
// TODO(#15) a lot of this logic is shared with `linera_service::node_service`
468-
pub async fn query(&self, query: &str, block_hash: &str) -> JsResult<String> {
468+
pub async fn query(&self, query: &str, block_hash: Option<String>) -> JsResult<String> {
469469
tracing::debug!("querying application: {query}");
470470
let chain_client = self.client.default_chain_client().await?;
471-
let block_hash = if block_hash.is_empty() {
472-
None
471+
let block_hash = if let Some(hash) = block_hash {
472+
Some(hash.as_str().parse()?)
473473
} else {
474-
Some(block_hash.parse()?)
474+
None
475475
};
476476
let linera_execution::QueryOutcome {
477477
response: linera_execution::QueryResponse::User(response),

0 commit comments

Comments
 (0)