Skip to content

Commit ab0cddf

Browse files
authored
Bump linera-protocol (#37)
* Bump `linera-protocol` * Update counter example to remove `mutate_application`.
1 parent 8038aa8 commit ab0cddf

File tree

5 files changed

+124
-58
lines changed

5 files changed

+124
-58
lines changed

client/Cargo.lock

Lines changed: 108 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ features = ["web", "wasmer"]
5050

5151
[dependencies.linera-execution]
5252
path = "../linera-protocol/linera-execution"
53-
features = ["web", "wasmer", "test"]
53+
features = ["web", "wasmer"]
5454

5555
[dependencies.linera-rpc]
5656
path = "../linera-protocol/linera-rpc"

client/src/lib.rs

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub const OPTIONS: ClientOptions = ClientOptions {
5656
blanket_message_policy: linera_core::client::BlanketMessagePolicy::Accept,
5757
restrict_chain_ids_to: None,
5858
long_lived_services: false,
59+
blob_download_timeout: std::time::Duration::from_millis(1000),
60+
grace_period: linera_core::DEFAULT_GRACE_PERIOD,
5961

6062
// TODO(linera-protocol#2944): separate these out from the
6163
// `ClientOptions` struct, since they apply only to the CLI/native
@@ -257,75 +259,33 @@ impl Frontend {
257259
query: &str,
258260
) -> Result<String, JsError> {
259261
let chain_client = self.0.default_chain_client().await?;
260-
let response = chain_client
262+
let linera_execution::QueryOutcome {
263+
response: linera_execution::QueryResponse::User(response),
264+
operations,
265+
} = chain_client
261266
.query_application(linera_execution::Query::User {
262267
application_id: application_id.parse()?,
263268
bytes: query.as_bytes().to_vec(),
264269
})
265-
.await?;
266-
let linera_execution::Response::User(response) = response else {
267-
panic!("system response to user query")
268-
};
269-
Ok(String::from_utf8(response)?)
270-
}
271-
272-
/// Mutate an application's state with the given mutation.
273-
///
274-
/// # Errors
275-
/// If the application ID or mutation is invalid.
276-
///
277-
/// # Panics
278-
/// If the response from the service is not a GraphQL response
279-
/// containing operations to execute.
280-
#[wasm_bindgen]
281-
// TODO(linera-protocol#2911) this function assumes GraphQL service output
282-
pub async fn mutate_application(
283-
&self,
284-
application_id: &str,
285-
mutation: &str,
286-
) -> Result<(), JsError> {
287-
fn array_to_bytes(array: &[serde_json::Value]) -> Vec<u8> {
288-
array
289-
.iter()
290-
.map(|value| value.as_u64().unwrap().try_into().unwrap())
291-
.collect()
292-
}
293-
294-
let chain_client = self.0.default_chain_client().await?;
295-
let application_id = application_id.parse()?;
296-
let response = chain_client
297-
.query_application(linera_execution::Query::User {
298-
application_id,
299-
bytes: mutation.as_bytes().to_vec(),
300-
})
301-
.await?;
302-
let linera_execution::Response::User(response) = response else {
270+
.await?
271+
else {
303272
panic!("system response to user query")
304273
};
305-
let response: serde_json::Value = serde_json::from_slice(&response)?;
306-
let data = &response["data"];
307-
tracing::info!("data: {data:?}");
308-
let operations: Vec<_> = data
309-
.as_object()
310-
.unwrap()
311-
.values()
312-
.map(|value| linera_execution::Operation::User {
313-
application_id,
314-
bytes: array_to_bytes(value.as_array().unwrap()),
315-
})
316-
.collect();
317274

318275
let _hash = loop {
319276
use linera_core::data_types::ClientOutcome::{Committed, WaitForTimeout};
320-
let timeout = match chain_client.execute_operations(operations.clone()).await? {
277+
let timeout = match chain_client
278+
.execute_operations(operations.clone(), vec![])
279+
.await?
280+
{
321281
Committed(certificate) => break certificate.value().hash(),
322282
WaitForTimeout(timeout) => timeout,
323283
};
324284
let mut stream = chain_client.subscribe().await?;
325285
linera_client::util::wait_for_next_round(&mut stream, timeout).await;
326286
};
327287

328-
Ok(())
288+
Ok(String::from_utf8(response)?)
329289
}
330290
}
331291

examples/counter/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h2>Counter</h2>
3131

3232
async function incrementCount() {
3333
await linera.callClientFunction(
34-
'mutate_application',
34+
'query_application',
3535
COUNTER_APP_ID,
3636
'{ "query": "mutation { increment(value: 1) }" }',
3737
);

linera-protocol

Submodule linera-protocol updated 398 files

0 commit comments

Comments
 (0)