@@ -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
0 commit comments